Salome HOME
Debug features for object groups.
[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 #include <HYDROData_CalculationCase.h>
31
32 #include <QMap>
33 #include <QList>
34 #include <LightApp_DataModel.h>
35
36 #include <SUIT_TreeModel.h>
37
38 class CAM_DataObject;
39 class SUIT_DataObject;
40 class HYDROGUI_DataObject;
41 class HYDROGUI_Zone;
42
43 /**
44  * \class HYDROGUI_DataModel
45  * \brief The class representing the HYDROGUI data model
46  */
47 class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
48 {
49 public:
50   /**
51    * Constructor.
52    * \param theModule module object
53    */
54   HYDROGUI_DataModel( CAM_Module* theModule );
55   virtual ~HYDROGUI_DataModel();
56
57   /**
58    * Open the document into the data model. Reimplemented.
59    * \param theURL opened study path
60    * \param theStudy object study
61    * \param theFileList list of opened files for this model.
62    */
63   virtual bool open( const QString& theURL,
64                      CAM_Study* theStudy,
65                      QStringList theFileList );
66
67   /**
68    * Saves the document. Reimplemented.
69    * \param returned theFileList list of saved files of this model.
70    */
71   virtual bool save( QStringList& theFileList );
72
73   /**
74    * Saves as the document. Reimplemented.
75    * \param theURL saved study path
76    * \param theStudy object study
77    * \param returned theFileList list of saved files of this model.
78    */
79   virtual bool saveAs( const QString& theURL,
80                        CAM_Study* theStudy,
81                        QStringList& theFileList );
82
83   /**
84    * Close the model and remove data. Reimplemented.
85    */
86   virtual bool close();
87
88   /**
89    * Dump study data to Python script. Reimplemented.
90    */
91   virtual bool                        dumpPython( const QString& theURL,
92                                                   CAM_Study*     theStudy,
93                                                   bool           isMultiFile,
94                                                   QStringList&   theListOfFiles );
95
96   /**
97    * Returns modification status. Reimplemented.
98    * \return boolean value of modification status
99    */
100   virtual bool isModified() const;
101
102   /**
103    * Returns saving status. Reimplemented.
104    * \return true if document has saved files on disc.
105    */
106   virtual bool isSaved() const;
107
108   /**
109    * Updates the internal structure of data object tree.
110    * \param theStudyId study identifier
111    */
112   virtual void update( const int theStudyId );
113
114   /**
115    * Returns data object corresponding to the model object.
116    * \param the data model object
117    * \return the only one object referenced to the given data model object, or null if not found
118    */
119   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
120
121   /**
122    * Returns a data object referenced to the given data object.
123    * \param the data object
124    * \return the object referenced to the given object, or null if not found
125    */
126   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
127
128   /**
129    * Finds the object by entry
130    * \param theEntry an object entry
131    */
132   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
133
134   /**
135    * Updates the internal structure of data object tree starting from specified data object \a obj.
136    * \param theObject start data object
137    * \param theStudy study object
138    */
139   virtual void update( LightApp_DataObject* theObject = 0,
140                        LightApp_Study* theStudy = 0 );
141
142   /**
143    * Creates a module object and set is a root for the model
144    */
145   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
146
147   /**
148    * Create a new region in the given calculation case containing given zones. 
149    */
150   bool createNewRegion( Handle(HYDROData_CalculationCase) theCase, const QList<HYDROGUI_Zone*>& theZonesList );
151
152   /**
153    * Correct an internal model object according to the current document mode
154    */
155   void updateModel();
156
157   /**
158    * Find a data object by the specified entry and kind
159    */
160   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
161                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
162
163   /**
164    * Check if it is possible to perform 'undo' operation
165    */
166   bool canUndo() const;
167
168   /**
169    * Check if it is possible to perform 'redo' operation
170    */
171   bool canRedo() const;
172
173   /**
174    * Returns the list of names of available 'undo' actions
175    */
176   QStringList undoNames() const;
177
178   /**
179    * Returns the list of names of available 'redo' actions
180    */
181   QStringList redoNames() const;
182
183   /**
184    * Clear the list of stored 'undo' actions
185    */
186   void clearUndos();
187
188   /**
189    * Clear the list of stored 'redo' actions
190    */
191   void clearRedos();
192
193   /**
194    * Perform the 'undo' operation
195    */
196   bool undo();
197
198   /**
199    * Perform the 'redo' operation
200    */
201   bool redo();
202
203   /**
204    * Check if it is possible to perform 'copy' operation
205    */
206   bool canCopy();
207
208   /**
209    * Check if it is possible to perform 'paste' operation
210    */
211   bool canPaste();
212
213   /**
214    * Perform the 'copy' operation
215    */
216   bool copy();
217
218   /**
219    * Perform the 'paste' operation
220    */
221   bool paste();
222
223   /**
224    * Rename the object
225    */
226   bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
227
228   /**
229    * Creates the Calculation Case subtree for usage within an operation dialog.
230    * \param theParent a created object will be appended as a child of this GUI object
231    * \param theCase the calculation case model object
232    */
233   void buildCaseTree( SUIT_DataObject*                  theParent,
234                       Handle(HYDROData_CalculationCase) theCase );
235
236   /**
237    * Updates the object subtree.
238    * \param theObj the data model entity
239    */
240   void updateObjectTree( Handle(HYDROData_Entity)& theObj );
241
242   /**
243    * Update the sequence of the objects to be copied
244    */
245   static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
246
247   /**
248    * Returns name of the partition containing the objects of the specified kind
249    * \param theObjectKind kind of objects
250    * \return partition name
251    */
252   static QString partitionName( const ObjectKind theObjectKind );
253
254 protected:
255   /**
256    * Returns the document for the current study
257    */
258   Handle(HYDROData_Document) getDocument() const;
259
260   /**
261    * Creates the GUI data object according to the model object.
262    * \param theParent a created object will be appended as a child of this object
263    * \param theModelObject model object
264    * \param theParentEntry entry of parent object
265    */
266   LightApp_DataObject* createObject( SUIT_DataObject*         theParent,
267                                      Handle(HYDROData_Entity) theModelObject,
268                                      const QString&           theParentEntry = QString(),
269                                      const bool               theIsBuildTree = true );
270
271   /**
272    * Creates the GUI data object without corresponding model object: just by name
273    * \param theParent a created object will be appended as a child of this object
274    * \param theName name of this object
275    * \param theParentEntry entry of parent object
276    */
277   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
278                                      const QString&   theName,
279                                      const QString&   theParentEntry = QString() );
280
281   /**
282    * Build object tree if the flag theIsBuildTree is true. 
283    * This is a conditional wrapper for buildObjectTree method.
284    * \param theParent a created object will be appended as a child of this object
285    * \param theObject the GUI object
286    * \param theParentEntry the entry of parent object
287    * \param theIsBuildTree if true then build the subtree of the GUI object
288    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
289    */
290   LightApp_DataObject* buildObject( SUIT_DataObject*     theParent,
291                                     HYDROGUI_DataObject* theObject,
292                                     const QString&       theParentEntry,
293                                     const bool           theIsBuildTree,
294                                     const bool           theIsInOperation = false );
295
296   /**
297    * Build object tree if the flag theIsBuildTree is true. 
298    * \param theParent a created object will be appended as a child of this GUI object
299    * \param theModelObject the data model zone object
300    * \param theParentEntry the entry of parent object
301    * \param theIsBuildTree if true then build the subtree of the GUI object
302    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
303    */
304   LightApp_DataObject* createZone( SUIT_DataObject*       theParent,
305                                    Handle(HYDROData_Zone) theModelObject,
306                                    const QString&         theParentEntry,
307                                    const bool             theIsBuildTree ,
308                                    const bool             theIsInOperation = false  );
309
310   /**
311    * Build object tree if the flag theIsBuildTree is true. 
312    * \param theParent a created object will be appended as a child of this GUI object
313    * \param theModelObject the data model region object
314    * \param theParentEntry the entry of parent object
315    * \param theIsBuildTree if true then build the subtree of the GUI object
316    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
317    */
318   LightApp_DataObject* createRegion( SUIT_DataObject*         theParent,
319                                      Handle(HYDROData_Region) theModelObject,
320                                      const QString&           theParentEntry,
321                                      const bool               theIsBuildTree ,
322                                      const bool               theIsInOperation = false );
323   /**
324    * Build partition for object.
325    * \param theObject gui object for which the partition will be build
326    * \param theObjects sequence of builded objects
327    * \param thePartName name of created partition
328    * \param theIsCreateEmpty if true then partition will be created in any case
329    */
330   void                 buildObjectPartition( SUIT_DataObject*                   theObject,
331                                              const HYDROData_SequenceOfObjects& theObjects,
332                                              const QString&                     thePartName,
333                                              const bool                         theIsCreateEmpty );
334
335   /**
336    * Build tree of a model object.
337    * \param theParent a created object will be appended as a child of this object
338    * \param theObject gui object for which the tree will be build
339    * \param theParentEntry entry of parent object
340    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
341    */
342   void                 buildObjectTree( SUIT_DataObject* theParent,
343                                         SUIT_DataObject* theObject,
344                                         const QString&   theParentEntry = QString(),
345                                         const bool       theIsInOperation = false );
346
347   /**
348    * Removes data object from the tree.
349    * \param theParent an object will be removed from this parent.
350    * \param theChild the removed object.
351    */
352   void removeChild( SUIT_DataObject* theParent,
353                     SUIT_DataObject* theChild );
354
355   /**
356    * Returns the first child of the object with the specified name
357    * \param theFather object that contain the searched object in children
358    * \param theName name f the searched data object
359    * \returns NULL if not found
360    */
361   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
362                                            const QString& theName );
363
364 protected:
365   QString myStudyURL; ///< the saved/opened document URL
366 };
367
368 #endif