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