]> 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();
38         StateType*      Redo();
39         void            Save(StateType* State);
40         int             UndoSize();
41         int             RedoSize();
42         
43 private:
44         std::deque<StateType*>  undoStack;
45         std::deque<StateType*>  redoStack;
46         int                                     maxElements;
47 };
48
49 class MeshModel{
50
51 public:
52         MeshModel(int id);
53         MeshModel(vtkPolyData* mesh, int id);
54         MeshModel(MeshModel* meshModel);
55         ~MeshModel();
56         
57         void                    SetMeshBase(vtkPolyData* mesh);
58     void                        SetMeshMemoryMode(vtkPolyData* mesh);
59     void                        CopySetMeshBase(vtkPolyData* mesh);
60     void                        ResetMeshTemp();
61     void                        ResetMeshTemp_();
62     vtkPolyData*        GetMeshBase();
63     vtkPolyData*        GetMeshTemp();
64     int                         GetId();
65     std::string         GetName();
66     
67
68 protected:
69
70 private:
71         vtkPolyData     *_meshBase;
72     vtkPolyData         *_meshTemp;
73     int                         _meshId;
74     std::string         _name;
75 };
76
77 #ifndef _MESHMANAGERMODEL_H_
78 #define _MESHMANAGERMODEL_H_
79
80 //---------------------------------------------
81 // Class Name: MeshManagerModel
82 // [classdescription]
83 //---------------------------------------------
84
85 class MeshManagerModel
86 {
87
88 //---------------------------------------------
89 //Methods and attributes exposed to other classes
90 //---------------------------------------------
91 public :
92   MeshManagerModel();
93   MeshManagerModel(std::vector<vtkPolyData*> meshList);
94   ~MeshManagerModel();
95
96         void ResetHistory();
97         void ResetAll();
98         
99         void UpdateMeshReference(vtkPolyData* mesh);
100     void SetMeshBase(vtkPolyData* mesh);
101     void SetMeshMemoryMode(vtkPolyData* mesh);
102     void CopySetMeshBase(vtkPolyData* mesh);
103     void ResetMeshTemp();
104     //void ResetMeshTemp_();
105     vtkPolyData* GetMeshBase();
106     vtkPolyData* GetMeshTemp();
107     
108     virtual void RefreshOutputs(bool signalBox);
109     
110     std::shared_ptr<MeshModel> GetMeshModel();
111     int GetNumberOfMeshes();
112     
113     void AddMesh_(vtkPolyData* mesh);
114     void AddMesh(vtkPolyData* mesh);
115     
116     void AddEmptyMesh_();
117     void AddEmptyMesh();
118     
119     void AddMeshes(std::vector<vtkPolyData*> meshList);
120     void AddMeshes_(std::vector<vtkPolyData*> meshList);
121     
122     void InsertMeshesAtCurrent_(std::vector<vtkPolyData*> meshList);
123     void InsertMeshesAtCurrent(std::vector<vtkPolyData*> meshList);
124     
125     void InsertMeshModels_(std::vector<MeshModel*> meshModelList);
126         void InsertMeshModels(std::vector<MeshModel*> meshModelList);
127     
128     void SelectMesh(int i);
129     void SelectMeshByName(std::string meshName);
130     
131     void DeleteMesh_(int position);
132     void DeleteMesh(int position);
133     void DeleteMeshByName(std::string meshName);
134     void DeleteCurrentMesh();
135     
136     void DeleteAll_();
137     void DeleteAll();
138     
139     void ReplaceMesh(std::vector<vtkPolyData*> meshList);
140     
141     void NextMesh();
142     void PreviousMesh();
143     
144     void Undo();
145     void Redo();
146     
147     std::vector<std::string> GetMeshNames();
148
149 //--Method template----------------------------
150 //  void FunctionName(int& parameterA);
151
152 //---------------------------------------------
153 //Methods and attributes exposed only to classes
154 //that are derived from this class
155 //---------------------------------------------
156 protected:
157
158 //---------------------------------------------
159 //Methods and attributes only visible by this class
160 //---------------------------------------------
161 private:
162     
163     std::vector<std::shared_ptr<MeshModel>> _meshes;
164     int                                                                         currentMesh;
165     int                                                                         meshId;
166     
167     class ManagerState{
168         public:
169                 ManagerState(std::vector<std::shared_ptr<MeshModel>> meshesToSave, int meshId, int currentMesh);
170                 ~ManagerState();
171                 std::vector<std::shared_ptr<MeshModel>>& GetMeshes();
172                 int GetMeshId();
173                 int GetCurrentMesh();
174         private:
175                 std::vector<std::shared_ptr<MeshModel>> savedMeshes;
176                 int savedCurrentMesh;
177                 int savedId;
178     };
179     
180     void                                                        Save();
181     void                                                        RestoreState(ManagerState* state);
182     
183     HistoryHandler<ManagerState>        *history;
184     
185     
186 };
187
188 //-end of _MESHMANAGERMODEL_H_------------------------------------------------------
189 #endif