]> Creatis software - creaVtk.git/commitdiff
#3527 Deformation Undo-Redo fixes
authorPablo Garzon <gapablo2001@gmail.com>
Mon, 24 Jul 2023 10:39:31 +0000 (12:39 +0200)
committerPablo Garzon <gapablo2001@gmail.com>
Mon, 24 Jul 2023 10:39:31 +0000 (12:39 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkMeshManager_tool.h
bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkPlaneWidget_Base.h
lib/creaVtk/MeshManagerModel.cpp
lib/creaVtk/MeshManagerModel.h

index 1be40ffb74bc0dbe960e7b41d1d6f712894d8d4e..c089676c87390307eaadedb0acd7185219a57577 100644 (file)
@@ -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<double> point = {bbGetInputDoubleParams()[0], bbGetInputDoubleParams()[1], bbGetInputDoubleParams()[2]};
+                               bbGetInputMeshManagerModel()->SetReferencePoint(point);
                        bbGetInputMeshManagerModel()->SaveMemoryMode();
-                   //  cout << bbGetInputStringParam() << endl;
                }
         }
         if (bbGetInputTool()==32)  // Copy and Set
index 76ba719e2999fcfa98dac4f41064d16033f40883..54b6d48fd92cd9f40ced723c4f0c1abedf4b0b45 100644 (file)
@@ -26,7 +26,8 @@ class bbcreaVtk_EXPORT MeshManager_tool
     BBTK_DECLARE_INPUT(MeshManagerModel,MeshManagerModel*);
     BBTK_DECLARE_INPUT(Meshes,std::vector<vtkPolyData*>);
     BBTK_DECLARE_INPUT(StringParam, std::string);
-//  BBTK_DECLARE_OUTPUT(Out,double);
+    BBTK_DECLARE_INPUT(DoubleParams, std::vector<double>);
+       BBTK_DECLARE_OUTPUT(Out,std::vector<double>);
   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<vtkPolyData*>,"");
   BBTK_INPUT(MeshManager_tool,StringParam,"String input",std::string,"");
+  BBTK_INPUT(MeshManager_tool,DoubleParams,"Double Vector input",std::vector<double>,"");
   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<double>,"");
+
 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)
index 79f86395404a3561dff4458c5785dfbbbeacb365..cbc406fde2965d1acd56b9d524c01857b73c42d7 100644 (file)
@@ -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
 }
 
 //===== 
index f7d0aef35aa96e991b4aa044ace398341ffe2875..5d8616b1c35c5d30291457bcb53a4ce9fa68a031 100644 (file)
@@ -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<double> );
   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<double> ,"");
 //  BBTK_OUTPUT(PlaneWidget_Base,Out,"First output",double,"");
 BBTK_END_DESCRIBE_BLACK_BOX(PlaneWidget_Base);
 //===== 
index ddf25583551f299a25eeff842c0151f02dacce49..1f0ce15a3f5a61a7209e86574d9a5428a08b80ff 100644 (file)
@@ -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<ManagerState>(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<double> point)
+{
+       referencePoint = point;
+}
+
+std::vector<double> 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<std::shared_ptr<MeshModel>> savedMesh;
                savedMesh.push_back(std::make_shared<MeshModel>(_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<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedPos)
+MeshManagerModel::ManagerState::ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedPos, std::vector<double> refPoint)
 {
        savedMeshes = meshesToSave;
        savedId = meshId;
        savedModifiedPos = modifiedPos;
+       referencePoint = refPoint;
 }
 
 MeshManagerModel::ManagerState::~ManagerState()
@@ -788,3 +801,7 @@ int MeshManagerModel::ManagerState::GetModifiedPos()
        return savedModifiedPos;
 }
 
+std::vector<double>& MeshManagerModel::ManagerState::GetReferencePoint()
+{
+       return referencePoint;
+}
index b74204c20a3010df654b1c07fbcda1ec97e6c5b2..a32867f73ea399d2955302a46b64092c5b9a2b79 100644 (file)
@@ -101,6 +101,9 @@ public :
        void ResetHistory();
        void ResetAll();
        
+       void SetReferencePoint(std::vector<double> point);
+       std::vector<double> GetReferencePoint();
+       
     void SetMeshBase(vtkPolyData* mesh);
     void SetMeshMemoryMode(vtkPolyData* mesh);
        void MeshMemoryModeOn();
@@ -174,18 +177,21 @@ private:
     int                                                                                meshId;
     int                                                                                lastModified;
     bool                                                                       memoryMode;
+    std::vector<double>                                                referencePoint;
     
     class ManagerState{
        public:
-               ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId);
+               ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId, std::vector<double> refPoint);
                ~ManagerState();
                std::vector<std::shared_ptr<MeshModel>>& GetMeshes();
                int GetMeshId();
                int GetModifiedPos();
+               std::vector<double>& GetReferencePoint();
        private:
                std::vector<std::shared_ptr<MeshModel>> savedMeshes;
                int savedModifiedPos;
                int savedId;
+               std::vector<double> referencePoint;
     };
     
     void                                                       Save();