Salome HOME
Merge remote-tracking branch 'origin/BR_LAND_COVER' into BR_v14_rc
[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    * 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    * Create a new region in the given calculation case containing given zones. 
146    */
147   bool createNewRegion( Handle(HYDROData_CalculationCase) theCase,
148                         const QList<HYDROGUI_Zone*>& theZonesList,
149                         const bool theLandCover );
150
151   /**
152    * Correct an internal model object according to the current document mode
153    */
154   void updateModel();
155
156   /**
157    * Find a data object by the specified entry and kind
158    */
159   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
160                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
161
162   /**
163    * Check if it is possible to perform 'undo' operation
164    */
165   bool canUndo() const;
166
167   /**
168    * Check if it is possible to perform 'redo' operation
169    */
170   bool canRedo() const;
171
172   /**
173    * Returns the list of names of available 'undo' actions
174    */
175   QStringList undoNames() const;
176
177   /**
178    * Returns the list of names of available 'redo' actions
179    */
180   QStringList redoNames() const;
181
182   /**
183    * Clear the list of stored 'undo' actions
184    */
185   void clearUndos();
186
187   /**
188    * Clear the list of stored 'redo' actions
189    */
190   void clearRedos();
191
192   /**
193    * Perform the 'undo' operation
194    */
195   bool undo();
196
197   /**
198    * Perform the 'redo' operation
199    */
200   bool redo();
201
202   /**
203    * Check if it is possible to perform 'copy' operation
204    */
205   bool canCopy();
206
207   /**
208    * Check if it is possible to perform 'paste' operation
209    */
210   bool canPaste();
211
212   /**
213    * Perform the 'copy' operation
214    */
215   bool copy();
216
217   /**
218    * Perform the 'paste' operation
219    */
220   bool paste();
221
222   /**
223    * Rename the object
224    */
225   bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
226
227   /**
228    * Creates the Calculation Case subtree for usage within an operation dialog.
229    * \param theParent a created object will be appended as a child of this GUI object
230    * \param theCase the calculation case model object
231    * \param theLandCover if true - land cover regions will be represented in the tree
232    */
233   void buildCaseTree( SUIT_DataObject*                  theParent,
234                       Handle(HYDROData_CalculationCase) theCase,
235                       const bool theLandCover );
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    * Creates the default Strickler table object: both GUI data object and corresponding model object
326    * \param theDocument a document into which created object will be added
327    * \param theParent a created object will be appended as a child of this GUI object
328    */
329   void                 createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
330                                                     LightApp_DataObject*              theParent );
331   /**
332    * Build partition for object.
333    * \param theObject gui object for which the partition will be build
334    * \param theObjects sequence of builded objects
335    * \param thePartName name of created partition
336    * \param theIsCreateEmpty if true then partition will be created in any case
337    */
338   void                 buildObjectPartition( SUIT_DataObject*                   theObject,
339                                              const HYDROData_SequenceOfObjects& theObjects,
340                                              const QString&                     thePartName,
341                                              const bool                         theIsCreateEmpty );
342
343   /**
344    * Build tree of a model object.
345    * \param theParent a created object will be appended as a child of this object
346    * \param theObject gui object for which the tree will be build
347    * \param theParentEntry entry of parent object
348    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
349    */
350   void                 buildObjectTree( SUIT_DataObject* theParent,
351                                         SUIT_DataObject* theObject,
352                                         const QString&   theParentEntry = QString(),
353                                         const bool       theIsInOperation = false );
354
355   /**
356    * Removes data object from the tree.
357    * \param theParent an object will be removed from this parent.
358    * \param theChild the removed object.
359    */
360   void removeChild( SUIT_DataObject* theParent,
361                     SUIT_DataObject* theChild );
362
363   /**
364    * Returns the first child of the object with the specified name
365    * \param theFather object that contain the searched object in children
366    * \param theName name f the searched data object
367    * \returns NULL if not found
368    */
369   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
370                                            const QString& theName );
371
372   /**
373    * Set object visibility state.
374    * \param theModelObject the data model object
375    * \param theDataObject the GUI object
376    */
377   void setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
378                                  HYDROGUI_DataObject* theObject );
379                                  
380
381 protected:
382   QString myStudyURL; ///< the saved/opened document URL
383   QByteArray myStates;
384 };
385
386 #endif