Salome HOME
e1a4a7cadb5016b1e8e8899417b64366ff7d6585
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19
20 #ifndef HYDROGUI_DATAMODEL_H
21 #define HYDROGUI_DATAMODEL_H
22
23 #include <HYDROData_Document.h>
24 #include <HYDROData_Entity.h>
25 #include <HYDROData_Zone.h>
26 #include <HYDROData_Region.h>
27 #include <HYDROData_CalculationCase.h>
28
29 #include <QMap>
30 #include <QList>
31 #include <LightApp_DataModel.h>
32
33 #include <SUIT_TreeModel.h>
34
35 class CAM_DataObject;
36 class SUIT_DataObject;
37 class HYDROGUI_DataObject;
38 class HYDROGUI_Zone;
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    * Creates the document into the data model. Reimplemented.
56    */
57   virtual bool create( CAM_Study* );
58
59   /**
60    * Open the document into the data model. Reimplemented.
61    * \param theURL opened study path
62    * \param theStudy object study
63    * \param theFileList list of opened files for this model.
64    */
65   virtual bool open( const QString& theURL,
66                      CAM_Study* theStudy,
67                      QStringList theFileList );
68
69   /**
70    * Saves the document. Reimplemented.
71    * \param returned theFileList list of saved files of this model.
72    */
73   virtual bool save( QStringList& theFileList );
74
75   /**
76    * Saves as the document. Reimplemented.
77    * \param theURL saved study path
78    * \param theStudy object study
79    * \param returned theFileList list of saved files of this model.
80    */
81   virtual bool saveAs( const QString& theURL,
82                        CAM_Study* theStudy,
83                        QStringList& theFileList );
84
85   /**
86    * Close the model and remove data. Reimplemented.
87    */
88   virtual bool close();
89   virtual bool isAboutToClose();
90
91   /**
92    * Dump study data to Python script. Reimplemented.
93    */
94   virtual bool                        dumpPython( const QString& theURL,
95                                                   CAM_Study*     theStudy,
96                                                   bool           isMultiFile,
97                                                   QStringList&   theListOfFiles );
98
99   /**
100    * Returns modification status. Reimplemented.
101    * \return boolean value of modification status
102    */
103   virtual bool isModified() const;
104
105   /**
106    * Returns saving status. Reimplemented.
107    * \return true if document has saved files on disc.
108    */
109   virtual bool isSaved() const;
110
111   /**
112    * Updates the internal structure of data object tree.
113    * \param theStudyId study identifier
114    */
115   virtual void update( const int theStudyId );
116
117   /**
118    * Returns data object corresponding to the model object.
119    * \param the data model object
120    * \return the only one object referenced to the given data model object, or null if not found
121    */
122   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
123
124   /**
125    * Returns a data object referenced to the given data object.
126    * \param the data object
127    * \return the object referenced to the given object, or null if not found
128    */
129   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
130
131   /**
132    * Finds the object by entry
133    * \param theEntry an object entry
134    */
135   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
136
137   /**
138    * Updates the internal structure of data object tree starting from specified data object \a obj.
139    * \param theObject start data object
140    * \param theStudy study object
141    */
142   virtual void update( LightApp_DataObject* theObject = 0,
143                        LightApp_Study* theStudy = 0 );
144
145   /**
146    * Creates a module object and set is a root for the model
147    */
148   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
149
150   /**
151    * Create a new region in the given calculation case containing given zones. 
152    */
153   bool createNewRegion( Handle(HYDROData_CalculationCase) theCase,
154                         const QList<HYDROGUI_Zone*>& theZonesList );
155
156   /**
157    * Correct an internal model object according to the current document mode
158    */
159   void updateModel();
160
161   /**
162    * Find a data object by the specified entry and kind
163    */
164   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
165                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
166
167   /**
168    * Check if it is possible to perform 'undo' operation
169    */
170   bool canUndo() const;
171
172   /**
173    * Check if it is possible to perform 'redo' operation
174    */
175   bool canRedo() const;
176
177   /**
178    * Returns the list of names of available 'undo' actions
179    */
180   QStringList undoNames() const;
181
182   /**
183    * Returns the list of names of available 'redo' actions
184    */
185   QStringList redoNames() const;
186
187   /**
188    * Clear the list of stored 'undo' actions
189    */
190   void clearUndos();
191
192   /**
193    * Clear the list of stored 'redo' actions
194    */
195   void clearRedos();
196
197   /**
198    * Perform the 'undo' operation
199    */
200   bool undo();
201
202   /**
203    * Perform the 'redo' operation
204    */
205   bool redo();
206
207   /**
208    * Check if it is possible to perform 'copy' operation
209    */
210   bool canCopy();
211
212   /**
213    * Check if it is possible to perform 'paste' operation
214    */
215   bool canPaste();
216
217   /**
218    * Perform the 'copy' operation
219    */
220   bool copy();
221
222   /**
223    * Perform the 'paste' operation
224    */
225   bool paste();
226
227   /**
228    * Rename the object
229    */
230   bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
231
232   /**
233    * Creates the Calculation Case subtree for usage within an operation dialog.
234    * \param theParent a created object will be appended as a child of this GUI object
235    * \param theCase the calculation case model object
236    * \param theLandCover if true - land cover regions will be represented in the tree
237    */
238   void buildCaseTree( SUIT_DataObject*                  theParent,
239                       Handle(HYDROData_CalculationCase) theCase );
240
241   /**
242    * Updates the object subtree.
243    * \param theObj the data model entity
244    */
245   void updateObjectTree( Handle(HYDROData_Entity)& theObj );
246
247   /**
248    * Update the sequence of the objects to be copied
249    */
250   static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
251
252   /**
253    * Returns name of the partition containing the objects of the specified kind
254    * \param theObjectKind kind of objects
255    * \return partition name
256    */
257   static QString partitionName( const ObjectKind theObjectKind );
258
259   /**
260    * Creates the default Strickler table object: both GUI data object and corresponding model object
261    * \param theDocument a document into which created object will be added
262    * \param theParent a created object will be appended as a child of this GUI object
263    */
264   void                 createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
265                                                     LightApp_DataObject*              theParent );
266
267 protected:
268   /**
269    * Returns the document for the current study
270    */
271   Handle(HYDROData_Document) getDocument() const;
272
273   /**
274    * Creates the GUI data object according to the model object.
275    * \param theParent a created object will be appended as a child of this object
276    * \param theModelObject model object
277    * \param theParentEntry entry of parent object
278    */
279   LightApp_DataObject* createObject( SUIT_DataObject*         theParent,
280                                      Handle(HYDROData_Entity) theModelObject,
281                                      const QString&           theParentEntry = QString(),
282                                      const bool               theIsBuildTree = true );
283
284   /**
285    * Creates the GUI data object without corresponding model object: just by name
286    * \param theParent a created object will be appended as a child of this object
287    * \param theName name of this object
288    * \param theParentEntry entry of parent object
289    */
290   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
291                                      const QString&   theName,
292                                      const QString&   theParentEntry = QString() );
293
294   /**
295    * Build object tree if the flag theIsBuildTree is true. 
296    * This is a conditional wrapper for buildObjectTree method.
297    * \param theParent a created object will be appended as a child of this object
298    * \param theObject the GUI object
299    * \param theParentEntry the entry of parent object
300    * \param theIsBuildTree if true then build the subtree of the GUI object
301    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
302    */
303   LightApp_DataObject* buildObject( SUIT_DataObject*     theParent,
304                                     HYDROGUI_DataObject* theObject,
305                                     const QString&       theParentEntry,
306                                     const bool           theIsBuildTree,
307                                     const bool           theIsInOperation = false );
308
309   /**
310    * Build object tree if the flag theIsBuildTree is true. 
311    * \param theParent a created object will be appended as a child of this GUI object
312    * \param theModelObject the data model zone object
313    * \param theParentEntry the entry of parent object
314    * \param theIsBuildTree if true then build the subtree of the GUI object
315    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
316    */
317   LightApp_DataObject* createZone( SUIT_DataObject*       theParent,
318                                    Handle(HYDROData_Zone) theModelObject,
319                                    const QString&         theParentEntry,
320                                    const bool             theIsBuildTree ,
321                                    const bool             theIsInOperation = false  );
322
323   /**
324    * Build object tree if the flag theIsBuildTree is true. 
325    * \param theParent a created object will be appended as a child of this GUI object
326    * \param theModelObject the data model region object
327    * \param theParentEntry the entry of parent object
328    * \param theIsBuildTree if true then build the subtree of the GUI object
329    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
330    */
331   LightApp_DataObject* createRegion( SUIT_DataObject*         theParent,
332                                      Handle(HYDROData_Region) theModelObject,
333                                      const QString&           theParentEntry,
334                                      const bool               theIsBuildTree ,
335                                      const bool               theIsInOperation = false );
336   /**
337    * Build partition for object.
338    * \param theObject gui object for which the partition will be build
339    * \param theObjects sequence of builded objects
340    * \param thePartName name of created partition
341    * \param theIsCreateEmpty if true then partition will be created in any case
342    */
343   void                 buildObjectPartition( SUIT_DataObject*                   theObject,
344                                              const HYDROData_SequenceOfObjects& theObjects,
345                                              const QString&                     thePartName,
346                                              const bool                         theIsCreateEmpty );
347
348   /**
349    * Build tree of a model object.
350    * \param theParent a created object will be appended as a child of this object
351    * \param theObject gui object for which the tree will be build
352    * \param theParentEntry entry of parent object
353    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
354    */
355   void                 buildObjectTree( SUIT_DataObject* theParent,
356                                         SUIT_DataObject* theObject,
357                                         const QString&   theParentEntry = QString(),
358                                         const bool       theIsInOperation = false );
359
360   /**
361    * Removes data object from the tree.
362    * \param theParent an object will be removed from this parent.
363    * \param theChild the removed object.
364    */
365   void removeChild( SUIT_DataObject* theParent,
366                     SUIT_DataObject* theChild );
367
368   /**
369    * Returns the first child of the object with the specified name
370    * \param theFather object that contain the searched object in children
371    * \param theName name f the searched data object
372    * \returns NULL if not found
373    */
374   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
375                                            const QString& theName );
376
377   void updateDocument();
378
379   /**
380    * Set object visibility state.
381    * \param theModelObject the data model object
382    * \param theDataObject the GUI object
383    */
384   void setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
385                                  HYDROGUI_DataObject* theObject );
386                                  
387
388 protected:
389   QString myStudyURL; ///< the saved/opened document URL
390   QByteArray myStates;
391   bool myIsAboutToClose;
392 };
393
394 #endif