]> Creatis software - creaVtk.git/blob - lib/creaVtk/MeshManagerModel.h
#3527 Deformation Undo-Redo fixes
[creaVtk.git] / lib / creaVtk / MeshManagerModel.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27 #include <vtkPolyData.h>
28 #include <deque>
29 #include <memory>
30
31 template<class StateType>
32 class HistoryHandler{
33 public:
34         HistoryHandler(int maxElements);
35         ~HistoryHandler();
36         void            CleanHistory();
37         StateType*      Undo(StateType* State);
38         StateType*      UndoKeepCurrent();
39         StateType*      Redo(StateType* State);
40         StateType*      RedoKeepCurrent();
41         void            Save(StateType* State);
42         StateType*      GetPrevious();
43         StateType*      GetNext();
44         int             UndoSize();
45         int             RedoSize();
46         
47 private:
48         std::deque<StateType*>  undoStack;
49         std::deque<StateType*>  redoStack;
50         int                                     maxElements;
51 };
52
53 class MeshModel{
54
55 public:
56         MeshModel(int id);
57         MeshModel(vtkPolyData* mesh, int id);
58         MeshModel(MeshModel* meshModel);
59         ~MeshModel();
60         
61         void                    SetMeshBase(vtkPolyData* mesh);
62     void                        SetMeshMemoryMode(vtkPolyData* mesh);
63     void                        CopySetMeshBase(vtkPolyData* mesh);
64     void                        ResetMeshTemp();
65     void                        ResetMeshTemp_();
66     vtkPolyData*        GetMeshBase();
67     vtkPolyData*        GetMeshTemp();
68     int                         GetId();
69     std::string         GetName();
70     
71
72 protected:
73
74 private:
75         vtkPolyData     *_meshBase;
76     vtkPolyData         *_meshTemp;
77     int                         _meshId;
78     std::string         _name;
79 };
80
81 #ifndef _MESHMANAGERMODEL_H_
82 #define _MESHMANAGERMODEL_H_
83
84 //---------------------------------------------
85 // Class Name: MeshManagerModel
86 // [classdescription]
87 //---------------------------------------------
88
89 class MeshManagerModel
90 {
91
92 //---------------------------------------------
93 //Methods and attributes exposed to other classes
94 //---------------------------------------------
95 public :
96   MeshManagerModel();
97   MeshManagerModel(std::vector<vtkPolyData*> meshList);
98   ~MeshManagerModel();
99
100         void SetHistory(int maxCapacity);
101         void ResetHistory();
102         void ResetAll();
103         
104         void SetReferencePoint(std::vector<double> point);
105         std::vector<double> GetReferencePoint();
106         
107     void SetMeshBase(vtkPolyData* mesh);
108     void SetMeshMemoryMode(vtkPolyData* mesh);
109         void MeshMemoryModeOn();
110     void MeshMemoryModeOff();
111     void CopySetMeshBase(vtkPolyData* mesh);
112     void ResetMeshTemp();
113     //void ResetMeshTemp_();
114     vtkPolyData* GetMeshBase();
115     vtkPolyData* GetMeshTemp();
116     
117     virtual void RefreshOutputs(bool signalBox);
118     
119     std::shared_ptr<MeshModel> GetMeshModel();
120     int GetNumberOfMeshes();
121     
122     void AddMesh_(vtkPolyData* mesh);
123     void AddMesh(vtkPolyData* mesh);
124     
125     void AddEmptyMesh_();
126     void AddEmptyMesh();
127     
128     void AddMeshes(std::vector<vtkPolyData*> meshList);
129     void AddMeshes_(std::vector<vtkPolyData*> meshList);
130     
131     void InsertMeshesAtCurrent_(std::vector<vtkPolyData*> meshList);
132     void InsertMeshesAtCurrent(std::vector<vtkPolyData*> meshList);
133     
134     void InsertMeshModels_(std::vector<MeshModel*> meshModelList);
135         void InsertMeshModels(std::vector<MeshModel*> meshModelList);
136     
137     void SelectMesh(int i);
138     void SelectMeshByName(std::string meshName);
139     
140     void DeleteMesh_(int position);
141     void DeleteMesh(int position);
142     void DeleteMeshByName(std::string meshName);
143     void DeleteCurrentMesh();
144     
145     void DeleteAll_();
146     void DeleteAll();
147     
148     void ReplaceMesh(std::vector<vtkPolyData*> meshList);
149     
150     void NextMesh();
151     void PreviousMesh();
152     
153     void SaveMemoryMode();
154     void Undo();
155     void Redo();
156     
157     std::vector<std::string> GetMeshNames();
158     std::vector<vtkPolyData*> GetAllPolyDatas();
159     int  GetCurrentMesh();
160
161 //--Method template----------------------------
162 //  void FunctionName(int& parameterA);
163
164 //---------------------------------------------
165 //Methods and attributes exposed only to classes
166 //that are derived from this class
167 //---------------------------------------------
168 protected:
169
170 //---------------------------------------------
171 //Methods and attributes only visible by this class
172 //---------------------------------------------
173 private:
174     
175     std::vector<std::shared_ptr<MeshModel>> _meshes;
176     int                                                                         currentMesh;
177     int                                                                         meshId;
178     int                                                                         lastModified;
179     bool                                                                        memoryMode;
180     std::vector<double>                                         referencePoint;
181     
182     class ManagerState{
183         public:
184                 ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId, std::vector<double> refPoint);
185                 ~ManagerState();
186                 std::vector<std::shared_ptr<MeshModel>>& GetMeshes();
187                 int GetMeshId();
188                 int GetModifiedPos();
189                 std::vector<double>& GetReferencePoint();
190         private:
191                 std::vector<std::shared_ptr<MeshModel>> savedMeshes;
192                 int savedModifiedPos;
193                 int savedId;
194                 std::vector<double> referencePoint;
195     };
196     
197     void                                                        Save();
198     void                                                        RestoreState(ManagerState* state);
199     void                                                        RestoreStateMemoryMode(ManagerState* state);
200     
201     HistoryHandler<ManagerState>        *history;
202     
203     
204 };
205
206 //-end of _MESHMANAGERMODEL_H_------------------------------------------------------
207 #endif