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