From 6cf1e39c6672a85f56a7341bc0f2107e09de8523 Mon Sep 17 00:00:00 2001 From: Pablo Garzon Date: Mon, 24 Jul 2023 12:39:31 +0200 Subject: [PATCH] #3527 Deformation Undo-Redo fixes --- .../src/bbcreaVtkMeshManager_tool.cxx | 10 +++---- .../src/bbcreaVtkMeshManager_tool.h | 9 ++++-- .../src/bbcreaVtkPlaneWidget_Base.cxx | 12 ++++++++ .../src/bbcreaVtkPlaneWidget_Base.h | 4 ++- lib/creaVtk/MeshManagerModel.cpp | 29 +++++++++++++++---- lib/creaVtk/MeshManagerModel.h | 8 ++++- 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx index 1be40ff..c089676 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx @@ -32,13 +32,13 @@ void MeshManager_tool::Process() if (bbGetInputTool()==10) // Undo { bbGetInputMeshManagerModel()->Undo(); - //printf("EED Warning! MeshManager_tool Undo Not implemented.\n"); + bbSetOutputOut(bbGetInputMeshManagerModel()->GetReferencePoint()); } // if Tool 10 Undo if (bbGetInputTool()==20) // Redo { bbGetInputMeshManagerModel()->Redo(); - //printf("EED Warning! MeshManager_tool Redo Not implemented.\n"); + bbSetOutputOut(bbGetInputMeshManagerModel()->GetReferencePoint()); } // if Tool 20 Redo if (bbGetInputTool()==30) // Set @@ -58,10 +58,10 @@ void MeshManager_tool::Process() } // if Tool 35 Set memory mode if(bbGetInputTool() == 37) // Save State Memory Mode { - if(bbGetInputStringParam().length() > 0){ - cout << " MeshManager_tool : MeshManagerModel Executed tool 37" << endl;//bGetInputMeshManagerModel()->Save(); + if(bbGetInputDoubleParams().size() == 5){ + std::vector point = {bbGetInputDoubleParams()[0], bbGetInputDoubleParams()[1], bbGetInputDoubleParams()[2]}; + bbGetInputMeshManagerModel()->SetReferencePoint(point); bbGetInputMeshManagerModel()->SaveMemoryMode(); - // cout << bbGetInputStringParam() << endl; } } if (bbGetInputTool()==32) // Copy and Set diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h index 76ba719..54b6d48 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h @@ -26,7 +26,8 @@ class bbcreaVtk_EXPORT MeshManager_tool BBTK_DECLARE_INPUT(MeshManagerModel,MeshManagerModel*); BBTK_DECLARE_INPUT(Meshes,std::vector); BBTK_DECLARE_INPUT(StringParam, std::string); -// BBTK_DECLARE_OUTPUT(Out,double); + BBTK_DECLARE_INPUT(DoubleParams, std::vector); + BBTK_DECLARE_OUTPUT(Out,std::vector); BBTK_PROCESS(Process); void Process(); //===== @@ -40,13 +41,15 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(MeshManager_tool,bbtk::AtomicBlackBox); BBTK_DESCRIPTION("No Description."); BBTK_CATEGORY("empty"); - BBTK_INPUT(MeshManager_tool,Tool,"(default 0) 0:Nothing 10:Undo 20:ReDo 30:Set 32:Copy and Set 35:Set memory mode 40:ResetMeshTemp 50: Set Array of meshes 60:Select mesh by name 70:Delete current mesh",int,""); + BBTK_INPUT(MeshManager_tool,Tool,"(default 0) 0:Nothing 10:Undo 20:ReDo 30:Set 32:Copy and Set 35:Set memory mode 37:Save state memory mode 40:ResetMeshTemp 50: Set Array of meshes 60:Select mesh by name 70:Delete current mesh",int,""); BBTK_INPUT(MeshManager_tool,Mesh,"Mesh",vtkPolyData*,""); BBTK_INPUT(MeshManager_tool,Meshes,"Input meshes, required for tool 50",std::vector,""); BBTK_INPUT(MeshManager_tool,StringParam,"String input",std::string,""); + BBTK_INPUT(MeshManager_tool,DoubleParams,"Double Vector input",std::vector,""); BBTK_INPUT(MeshManager_tool,MeshManagerModel,"Mesh Manager Model",MeshManagerModel*,""); -// BBTK_OUTPUT(MeshManager_tool,Out,"First output",double,""); + BBTK_OUTPUT(MeshManager_tool,Out,"Output",std::vector,""); + BBTK_END_DESCRIBE_BLACK_BOX(MeshManager_tool); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx index 79f8639..cbc406f 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx @@ -41,6 +41,18 @@ void PlaneWidget_Base::Process() bbGetInputIn()->Process(); bbGetInputIn()->Execute(); } // if Type == 1 + if((bbGetInputType()==2) && (bbGetInputIn()!=NULL) && (bbGetInputParamVector().size() == 3)) + { + bbGetInputIn()->SetNormalIn(bbGetInputParamVector()); + bbGetInputIn()->Process(); + bbGetInputIn()->Execute(); + } // if Type == 2 + if((bbGetInputType()==3) && (bbGetInputIn()!=NULL) && (bbGetInputParamVector().size() == 3)) + { + bbGetInputIn()->SetOrigin(bbGetInputParamVector()); + bbGetInputIn()->Process(); + bbGetInputIn()->Execute(); + } // if Type == 3 } //===== diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.h b/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.h index f7d0aef..5d8616b 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.h @@ -24,6 +24,7 @@ class bbcreaVtk_EXPORT PlaneWidget_Base BBTK_DECLARE_INPUT(In, creaVtkPlaneWidget* ); BBTK_DECLARE_INPUT(Type, int ); BBTK_DECLARE_INPUT(Param, double ); + BBTK_DECLARE_INPUT(ParamVector, std::vector ); BBTK_DECLARE_OUTPUT(Out,double); BBTK_PROCESS(Process); void Process(); @@ -38,8 +39,9 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(PlaneWidget_Base,bbtk::AtomicBlackBox); BBTK_DESCRIPTION("No Description."); BBTK_CATEGORY("empty"); BBTK_INPUT(PlaneWidget_Base,In,"Base creaVtkPlaneWidget ", creaVtkPlaneWidget* ,""); - BBTK_INPUT(PlaneWidget_Base,Type,"(default 0) 0:nothing 1:Move Normal Direction (Param=step) ", int ,""); + BBTK_INPUT(PlaneWidget_Base,Type,"(default 0) 0:nothing 1:Move Normal Direction (Param=step) 2:Set Normal (ParamVector=Normal) 3:Set Origin (ParamVector=Origin)", int ,""); BBTK_INPUT(PlaneWidget_Base,Param,"Type=1 step ", double ,""); + BBTK_INPUT(PlaneWidget_Base,ParamVector,"Type=2 Set normal, Type=3 Set origin", std::vector ,""); // BBTK_OUTPUT(PlaneWidget_Base,Out,"First output",double,""); BBTK_END_DESCRIBE_BLACK_BOX(PlaneWidget_Base); //===== diff --git a/lib/creaVtk/MeshManagerModel.cpp b/lib/creaVtk/MeshManagerModel.cpp index ddf2558..1f0ce15 100644 --- a/lib/creaVtk/MeshManagerModel.cpp +++ b/lib/creaVtk/MeshManagerModel.cpp @@ -200,7 +200,7 @@ MeshModel::MeshModel(vtkPolyData* mesh, int id) { if(mesh != NULL) { - _meshBase = vtkPolyData::New();//mesh; + _meshBase = vtkPolyData::New(); _meshBase->DeepCopy(mesh); _meshTemp = vtkPolyData::New(); _meshTemp->DeepCopy(_meshBase); @@ -329,6 +329,7 @@ MeshManagerModel::MeshManagerModel() history = new HistoryHandler(15); lastModified = 0; memoryMode = false; + referencePoint = {0, 0, 0}; } MeshManagerModel::~MeshManagerModel() @@ -356,6 +357,16 @@ void MeshManagerModel::ResetHistory() history->CleanHistory(); } +void MeshManagerModel::SetReferencePoint(std::vector point) +{ + referencePoint = point; +} + +std::vector MeshManagerModel::GetReferencePoint() +{ + return referencePoint; +} + int MeshManagerModel::GetNumberOfMeshes() { return _meshes.size(); @@ -690,7 +701,7 @@ void MeshManagerModel::Undo() if(history->UndoSize() > 0) { if(memoryMode == false){ - RestoreState(history->Undo(new ManagerState(_meshes, meshId, lastModified))); + RestoreState(history->Undo(new ManagerState(_meshes, meshId, lastModified, referencePoint))); RefreshOutputs(true); } else if(history->UndoSize() > 1){ @@ -704,7 +715,7 @@ void MeshManagerModel::Redo() if(history->RedoSize() > 0) { if(memoryMode == false){ - RestoreState(history->Redo(new ManagerState(_meshes, meshId, lastModified))); + RestoreState(history->Redo(new ManagerState(_meshes, meshId, lastModified, referencePoint))); RefreshOutputs(true); } else{ @@ -715,7 +726,7 @@ void MeshManagerModel::Redo() void MeshManagerModel::Save() { - history->Save(new ManagerState(_meshes, meshId, currentMesh)); + history->Save(new ManagerState(_meshes, meshId, currentMesh, referencePoint)); } void MeshManagerModel::SaveMemoryMode() @@ -724,7 +735,7 @@ void MeshManagerModel::SaveMemoryMode() { std::vector> savedMesh; savedMesh.push_back(std::make_shared(_meshes.at(0).get())); - history->Save(new ManagerState(savedMesh, meshId, 0)); + history->Save(new ManagerState(savedMesh, meshId, 0, referencePoint)); } else{ printf("PG MeshManagerModel::SaveMemoryMode WARNING Mesh vector has invalid size or memoryMode is not set \n"); @@ -754,6 +765,7 @@ void MeshManagerModel::RestoreStateMemoryMode(ManagerState* state){ _meshes.at(0)->GetMeshBase()->SetPoints(statePoints); _meshes.at(0)->GetMeshBase()->GetPoints()->Modified(); _meshes.at(0)->GetMeshBase()->Modified(); + referencePoint = state->GetReferencePoint(); }else{ printf("PG MeshManagerModel::RestoreStateMemoryMode WARNING Mesh vector has invalid size or state is NULL\n"); } @@ -762,11 +774,12 @@ void MeshManagerModel::RestoreStateMemoryMode(ManagerState* state){ // //Manager State // -MeshManagerModel::ManagerState::ManagerState(std::vector> meshesToSave, int meshId, int modifiedPos) +MeshManagerModel::ManagerState::ManagerState(std::vector> meshesToSave, int meshId, int modifiedPos, std::vector refPoint) { savedMeshes = meshesToSave; savedId = meshId; savedModifiedPos = modifiedPos; + referencePoint = refPoint; } MeshManagerModel::ManagerState::~ManagerState() @@ -788,3 +801,7 @@ int MeshManagerModel::ManagerState::GetModifiedPos() return savedModifiedPos; } +std::vector& MeshManagerModel::ManagerState::GetReferencePoint() +{ + return referencePoint; +} diff --git a/lib/creaVtk/MeshManagerModel.h b/lib/creaVtk/MeshManagerModel.h index b74204c..a32867f 100644 --- a/lib/creaVtk/MeshManagerModel.h +++ b/lib/creaVtk/MeshManagerModel.h @@ -101,6 +101,9 @@ public : void ResetHistory(); void ResetAll(); + void SetReferencePoint(std::vector point); + std::vector GetReferencePoint(); + void SetMeshBase(vtkPolyData* mesh); void SetMeshMemoryMode(vtkPolyData* mesh); void MeshMemoryModeOn(); @@ -174,18 +177,21 @@ private: int meshId; int lastModified; bool memoryMode; + std::vector referencePoint; class ManagerState{ public: - ManagerState(std::vector> meshesToSave, int meshId, int modifiedId); + ManagerState(std::vector> meshesToSave, int meshId, int modifiedId, std::vector refPoint); ~ManagerState(); std::vector>& GetMeshes(); int GetMeshId(); int GetModifiedPos(); + std::vector& GetReferencePoint(); private: std::vector> savedMeshes; int savedModifiedPos; int savedId; + std::vector referencePoint; }; void Save(); -- 2.47.1