]> Creatis software - creaVtk.git/blob - lib/creaVtk/MeshManagerModel.h
#3517 Adjustments Undo - Redo for deformation
[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         void SetReferenceNormal(std::vector<double> normal);
107         std::vector<double> GetReferenceNormal();
108         
109     void SetMeshBase(vtkPolyData* mesh);
110     void SetMeshMemoryMode(vtkPolyData* mesh);
111         void MeshMemoryModeOn();
112     void MeshMemoryModeOff();
113     void CopySetMeshBase(vtkPolyData* mesh);
114     void ResetMeshTemp();
115     //void ResetMeshTemp_();
116     vtkPolyData* GetMeshBase();
117     vtkPolyData* GetMeshTemp();
118     
119     virtual void RefreshOutputs(bool signalBox);
120     
121     std::shared_ptr<MeshModel> GetMeshModel();
122     int GetNumberOfMeshes();
123     
124     void AddMesh_(vtkPolyData* mesh);
125     void AddMesh(vtkPolyData* mesh);
126     
127     void AddEmptyMesh_();
128     void AddEmptyMesh();
129     
130     void AddMeshes(std::vector<vtkPolyData*> meshList);
131     void AddMeshes_(std::vector<vtkPolyData*> meshList);
132     
133     void InsertMeshesAtCurrent_(std::vector<vtkPolyData*> meshList);
134     void InsertMeshesAtCurrent(std::vector<vtkPolyData*> meshList);
135     
136     void InsertMeshModels_(std::vector<MeshModel*> meshModelList);
137         void InsertMeshModels(std::vector<MeshModel*> meshModelList);
138     
139     void SelectMesh(int i);
140     void SelectMeshByName(std::string meshName);
141     
142     void DeleteMesh_(int position);
143     void DeleteMesh(int position);
144     void DeleteMeshByName(std::string meshName);
145     void DeleteCurrentMesh();
146     
147     void DeleteAll_();
148     void DeleteAll();
149     
150     void ReplaceMesh(std::vector<vtkPolyData*> meshList);
151     
152     void NextMesh();
153     void PreviousMesh();
154     
155     void SaveMemoryMode();
156     void Undo();
157     void Redo();
158     
159     std::vector<std::string> GetMeshNames();
160     std::vector<vtkPolyData*> GetAllPolyDatas();
161     int  GetCurrentMesh();
162
163 //--Method template----------------------------
164 //  void FunctionName(int& parameterA);
165
166 //---------------------------------------------
167 //Methods and attributes exposed only to classes
168 //that are derived from this class
169 //---------------------------------------------
170 protected:
171
172 //---------------------------------------------
173 //Methods and attributes only visible by this class
174 //---------------------------------------------
175 private:
176     
177     std::vector<std::shared_ptr<MeshModel>> _meshes;
178     int                                                                         currentMesh;
179     int                                                                         meshId;
180     int                                                                         lastModified;
181     bool                                                                        memoryMode;
182     std::vector<double>                                         referencePoint;
183     std::vector<double>                                         referenceNormal;
184     
185     class ManagerState{
186         public:
187                 ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId);
188                 ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int modifiedId, std::vector<double> refPoint, std::vector<double> refNormal);
189                 ~ManagerState();
190                 std::vector<std::shared_ptr<MeshModel>>& GetMeshes();
191                 int GetMeshId();
192                 int GetModifiedPos();
193                 std::vector<double>& GetReferencePoint();
194
195                 std::vector<std::shared_ptr<MeshModel>> savedMeshes;
196                 int savedModifiedPos;
197                 int savedId;
198                 std::vector<double> referencePoint;
199                 std::vector<double> referenceNormal;
200     };
201     
202     void                                                        Save();
203     void                                                        RestoreState(ManagerState* state);
204     void                                                        RestoreStateMemoryMode(ManagerState* state);
205     
206     HistoryHandler<ManagerState>        *history;
207     
208     
209 };
210
211 //-end of _MESHMANAGERMODEL_H_------------------------------------------------------
212 #endif