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