Salome HOME
bfc590e71b4a2d43df8b0b6ed87028ef311dbb51
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROGUI_DATAMODEL_H
24 #define HYDROGUI_DATAMODEL_H
25
26 #include <HYDROData_Document.h>
27 #include <HYDROData_Entity.h>
28 #include <HYDROData_Zone.h>
29 #include <HYDROData_Region.h>
30
31 #include <QMap>
32 #include <LightApp_DataModel.h>
33
34 #include <SUIT_TreeModel.h>
35
36 class CAM_DataObject;
37 class SUIT_DataObject;
38 class HYDROGUI_DataObject;
39
40 /**
41  * \class HYDROGUI_DataModel
42  * \brief The class representing the HYDROGUI data model
43  */
44 class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
45 {
46 public:
47   /**
48    * Constructor.
49    * \param theModule module object
50    */
51   HYDROGUI_DataModel( CAM_Module* theModule );
52   virtual ~HYDROGUI_DataModel();
53
54   /**
55    * Open the document into the data model. Reimplemented.
56    * \param theURL opened study path
57    * \param theStudy object study
58    * \param theFileList list of opened files for this model.
59    */
60   virtual bool open( const QString& theURL,
61                      CAM_Study* theStudy,
62                      QStringList theFileList );
63
64   /**
65    * Saves the document. Reimplemented.
66    * \param returned theFileList list of saved files of this model.
67    */
68   virtual bool save( QStringList& theFileList );
69
70   /**
71    * Saves as the document. Reimplemented.
72    * \param theURL saved study path
73    * \param theStudy object study
74    * \param returned theFileList list of saved files of this model.
75    */
76   virtual bool saveAs( const QString& theURL,
77                        CAM_Study* theStudy,
78                        QStringList& theFileList );
79
80   /**
81    * Close the model and remove data. Reimplemented.
82    */
83   virtual bool close();
84
85   /**
86    * Dump study data to Python script. Reimplemented.
87    */
88   virtual bool                        dumpPython( const QString& theURL,
89                                                   CAM_Study*     theStudy,
90                                                   bool           isMultiFile,
91                                                   QStringList&   theListOfFiles );
92
93   /**
94    * Returns modification status. Reimplemented.
95    * \return boolean value of modification status
96    */
97   virtual bool isModified() const;
98
99   /**
100    * Returns saving status. Reimplemented.
101    * \return true if document has saved files on disc.
102    */
103   virtual bool isSaved() const;
104
105   /**
106    * Updates the internal structure of data object tree.
107    * \param theStudyId study identifier
108    */
109   virtual void update( const int theStudyId );
110
111   /**
112    * Returns data object corresponding to the model object.
113    * \param the data model object
114    * \return the only one object referenced to the given data model object, or null if not found
115    */
116   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
117
118   /**
119    * Returns a data object referenced to the given data object.
120    * \param the data object
121    * \return the object referenced to the given object, or null if not found
122    */
123   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
124
125   /**
126    * Finds the object by entry
127    * \param theEntry an object entry
128    */
129   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
130
131   /**
132    * Updates the internal structure of data object tree starting from specified data object \a obj.
133    * \param theObject start data object
134    * \param theStudy study object
135    */
136   virtual void update( LightApp_DataObject* theObject = 0,
137                        LightApp_Study* theStudy = 0 );
138
139   /**
140    * Creates a module object and set is a root for the model
141    */
142   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
143
144   /**
145    * Correct an internal model object according to the current document mode
146    */
147   void updateModel();
148
149   /**
150    * Find a data object by the specified entry and kind
151    */
152   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
153                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
154
155   /**
156    * Check if it is possible to perform 'undo' operation
157    */
158   bool canUndo() const;
159
160   /**
161    * Check if it is possible to perform 'redo' operation
162    */
163   bool canRedo() const;
164
165   /**
166    * Returns the list of names of available 'undo' actions
167    */
168   QStringList undoNames() const;
169
170   /**
171    * Returns the list of names of available 'redo' actions
172    */
173   QStringList redoNames() const;
174
175   /**
176    * Clear the list of stored 'undo' actions
177    */
178   void clearUndos();
179
180   /**
181    * Clear the list of stored 'redo' actions
182    */
183   void clearRedos();
184
185   /**
186    * Perform the 'undo' operation
187    */
188   bool undo();
189
190   /**
191    * Perform the 'redo' operation
192    */
193   bool redo();
194
195   /**
196    * Check if it is possible to perform 'copy' operation
197    */
198   bool canCopy();
199
200   /**
201    * Check if it is possible to perform 'paste' operation
202    */
203   bool canPaste();
204
205   /**
206    * Perform the 'copy' operation
207    */
208   bool copy();
209
210   /**
211    * Perform the 'paste' operation
212    */
213   bool paste();
214
215   /**
216    * Update the sequence of the objects to be copied
217    */
218   static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
219
220   /**
221    * Returns name of the partition containing the objects of the specified kind
222    * \param theObjectKind kind of objects
223    * \return partition name
224    */
225   static QString partitionName( const ObjectKind theObjectKind );
226
227   /**
228    * Returns the document for the current study
229    */
230   Handle(HYDROData_Document) getDocument() const;
231
232   /**
233    * Creates the GUI data object according to the model object.
234    * \param theParent a created object will be appended as a child of this object
235    * \param theModelObject model object
236    * \param theParentEntry entry of parent object
237    */
238   LightApp_DataObject* createObject( SUIT_DataObject*         theParent,
239                                      Handle(HYDROData_Entity) theModelObject,
240                                      const QString&           theParentEntry = QString(),
241                                      const bool               theIsBuildTree = true );
242
243 protected:
244   /**
245    * Creates the GUI data object without corresponding model object: just by name
246    * \param theParent a created object will be appended as a child of this object
247    * \param theName name of this object
248    * \param theParentEntry entry of parent object
249    */
250   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
251                                      const QString&   theName,
252                                      const QString&   theParentEntry = QString() );
253
254   /**
255    * Build object tree if the flag theIsBuildTree is true. 
256    * This is a conditional wrapper for buildObjectTree method.
257    * \param theParent a created object will be appended as a child of this object
258    * \param theObject the GUI object
259    * \param theParentEntry the entry of parent object
260    * \param theIsBuildTree if true then build the subtree of the GUI object
261    */
262   LightApp_DataObject* buildObject( SUIT_DataObject*     theParent,
263                                     HYDROGUI_DataObject* theObject,
264                                     const QString&       theParentEntry,
265                                     const bool           theIsBuildTree );
266
267   LightApp_DataObject* createZone( SUIT_DataObject*       theParent,
268                                    Handle(HYDROData_Zone) theModelObject,
269                                    const QString&         theParentEntry,
270                                    const bool             theIsBuildTree );
271
272   LightApp_DataObject* createRegion( SUIT_DataObject*         theParent,
273                                      Handle(HYDROData_Region) theModelObject,
274                                      const QString&           theParentEntry,
275                                      const bool               theIsBuildTree );
276   /**
277    * Build tree of model object.
278    * \param theParent a created object will be appended as a child of this object
279    * \param theObject gui object for which the tree will be build
280    * \param theParentEntry entry of parent object
281    */
282   void                 buildObjectTree( SUIT_DataObject* theParent,
283                                         SUIT_DataObject* theObject,
284                                         const QString&   theParentEntry = QString() );
285
286   /**
287    * Removes data object from the tree.
288    * \param theParent an object will be removed from this parent.
289    * \param theChild the removed object.
290    */
291   void removeChild( SUIT_DataObject* theParent,
292                     SUIT_DataObject* theChild );
293
294   /**
295    * Returns the first child of the object with the specified name
296    * \param theFather object that contain the searched object in children
297    * \param theName name f the searched data object
298    * \returns NULL if not found
299    */
300   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
301                                            const QString& theName );
302
303 protected:
304   QString myStudyURL; ///< the saved/opened document URL
305 };
306
307 #endif