Salome HOME
Merge remote-tracking branch 'remotes/origin/BR_2017' into HEAD
[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
90   /**
91    * Dump study data to Python script. Reimplemented.
92    */
93   virtual bool                        dumpPython( const QString& theURL,
94                                                   CAM_Study*     theStudy,
95                                                   bool           isMultiFile,
96                                                   QStringList&   theListOfFiles );
97
98   /**
99    * Returns modification status. Reimplemented.
100    * \return boolean value of modification status
101    */
102   virtual bool isModified() const;
103
104   /**
105    * Returns saving status. Reimplemented.
106    * \return true if document has saved files on disc.
107    */
108   virtual bool isSaved() const;
109
110   /**
111    * Updates the internal structure of data object tree.
112    * \param theStudyId study identifier
113    */
114   virtual void update( const int theStudyId );
115
116   /**
117    * Returns data object corresponding to the model object.
118    * \param the data model object
119    * \return the only one object referenced to the given data model object, or null if not found
120    */
121   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
122
123   /**
124    * Returns a data object referenced to the given data object.
125    * \param the data object
126    * \return the object referenced to the given object, or null if not found
127    */
128   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
129
130   /**
131    * Finds the object by entry
132    * \param theEntry an object entry
133    */
134   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
135
136   /**
137    * Updates the internal structure of data object tree starting from specified data object \a obj.
138    * \param theObject start data object
139    * \param theStudy study object
140    */
141   virtual void update( LightApp_DataObject* theObject = 0,
142                        LightApp_Study* theStudy = 0 );
143
144   /**
145    * Creates a module object and set is a root for the model
146    */
147   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
148
149   /**
150    * Create a new region in the given calculation case containing given zones. 
151    */
152   bool createNewRegion( Handle(HYDROData_CalculationCase) theCase,
153                         const QList<HYDROGUI_Zone*>& theZonesList );
154
155   /**
156    * Correct an internal model object according to the current document mode
157    */
158   void updateModel();
159
160   /**
161    * Find a data object by the specified entry and kind
162    */
163   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
164                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
165
166   /**
167    * Check if it is possible to perform 'undo' operation
168    */
169   bool canUndo() const;
170
171   /**
172    * Check if it is possible to perform 'redo' operation
173    */
174   bool canRedo() const;
175
176   /**
177    * Returns the list of names of available 'undo' actions
178    */
179   QStringList undoNames() const;
180
181   /**
182    * Returns the list of names of available 'redo' actions
183    */
184   QStringList redoNames() const;
185
186   /**
187    * Clear the list of stored 'undo' actions
188    */
189   void clearUndos();
190
191   /**
192    * Clear the list of stored 'redo' actions
193    */
194   void clearRedos();
195
196   /**
197    * Perform the 'undo' operation
198    */
199   bool undo();
200
201   /**
202    * Perform the 'redo' operation
203    */
204   bool redo();
205
206   /**
207    * Check if it is possible to perform 'copy' operation
208    */
209   bool canCopy();
210
211   /**
212    * Check if it is possible to perform 'paste' operation
213    */
214   bool canPaste();
215
216   /**
217    * Perform the 'copy' operation
218    */
219   bool copy();
220
221   /**
222    * Perform the 'paste' operation
223    */
224   bool paste();
225
226   /**
227    * Rename the object
228    */
229   bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
230
231   /**
232    * Creates the Calculation Case subtree for usage within an operation dialog.
233    * \param theParent a created object will be appended as a child of this GUI object
234    * \param theCase the calculation case model object
235    * \param theLandCover if true - land cover regions will be represented in the tree
236    */
237   void buildCaseTree( SUIT_DataObject*                  theParent,
238                       Handle(HYDROData_CalculationCase) theCase );
239
240   /**
241    * Updates the object subtree.
242    * \param theObj the data model entity
243    */
244   void updateObjectTree( Handle(HYDROData_Entity)& theObj );
245
246   /**
247    * Update the sequence of the objects to be copied
248    */
249   static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
250
251   /**
252    * Returns name of the partition containing the objects of the specified kind
253    * \param theObjectKind kind of objects
254    * \return partition name
255    */
256   static QString partitionName( const ObjectKind theObjectKind );
257
258   /**
259    * Creates the default Strickler table object: both GUI data object and corresponding model object
260    * \param theDocument a document into which created object will be added
261    * \param theParent a created object will be appended as a child of this GUI object
262    */
263   void                 createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
264                                                     LightApp_DataObject*              theParent );
265
266 protected:
267   /**
268    * Returns the document for the current study
269    */
270   Handle(HYDROData_Document) getDocument() const;
271
272   /**
273    * Creates the GUI data object according to the model object.
274    * \param theParent a created object will be appended as a child of this object
275    * \param theModelObject model object
276    * \param theParentEntry entry of parent object
277    */
278   LightApp_DataObject* createObject( SUIT_DataObject*         theParent,
279                                      Handle(HYDROData_Entity) theModelObject,
280                                      const QString&           theParentEntry = QString(),
281                                      const bool               theIsBuildTree = true );
282
283   /**
284    * Creates the GUI data object without corresponding model object: just by name
285    * \param theParent a created object will be appended as a child of this object
286    * \param theName name of this object
287    * \param theParentEntry entry of parent object
288    */
289   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
290                                      const QString&   theName,
291                                      const QString&   theParentEntry = QString() );
292
293   /**
294    * Build object tree if the flag theIsBuildTree is true. 
295    * This is a conditional wrapper for buildObjectTree method.
296    * \param theParent a created object will be appended as a child of this object
297    * \param theObject the GUI object
298    * \param theParentEntry the entry of parent object
299    * \param theIsBuildTree if true then build the subtree of the GUI object
300    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
301    */
302   LightApp_DataObject* buildObject( SUIT_DataObject*     theParent,
303                                     HYDROGUI_DataObject* theObject,
304                                     const QString&       theParentEntry,
305                                     const bool           theIsBuildTree,
306                                     const bool           theIsInOperation = false );
307
308   /**
309    * Build object tree if the flag theIsBuildTree is true. 
310    * \param theParent a created object will be appended as a child of this GUI object
311    * \param theModelObject the data model zone object
312    * \param theParentEntry the entry of parent object
313    * \param theIsBuildTree if true then build the subtree of the GUI object
314    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
315    */
316   LightApp_DataObject* createZone( SUIT_DataObject*       theParent,
317                                    Handle(HYDROData_Zone) theModelObject,
318                                    const QString&         theParentEntry,
319                                    const bool             theIsBuildTree ,
320                                    const bool             theIsInOperation = false  );
321
322   /**
323    * Build object tree if the flag theIsBuildTree is true. 
324    * \param theParent a created object will be appended as a child of this GUI object
325    * \param theModelObject the data model region object
326    * \param theParentEntry the entry of parent object
327    * \param theIsBuildTree if true then build the subtree of the GUI object
328    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
329    */
330   LightApp_DataObject* createRegion( SUIT_DataObject*         theParent,
331                                      Handle(HYDROData_Region) theModelObject,
332                                      const QString&           theParentEntry,
333                                      const bool               theIsBuildTree ,
334                                      const bool               theIsInOperation = false );
335   /**
336    * Build partition for object.
337    * \param theObject gui object for which the partition will be build
338    * \param theObjects sequence of builded objects
339    * \param thePartName name of created partition
340    * \param theIsCreateEmpty if true then partition will be created in any case
341    */
342   void                 buildObjectPartition( SUIT_DataObject*                   theObject,
343                                              const HYDROData_SequenceOfObjects& theObjects,
344                                              const QString&                     thePartName,
345                                              const bool                         theIsCreateEmpty );
346
347   /**
348    * Build tree of a model object.
349    * \param theParent a created object will be appended as a child of this object
350    * \param theObject gui object for which the tree will be build
351    * \param theParentEntry entry of parent object
352    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
353    */
354   void                 buildObjectTree( SUIT_DataObject* theParent,
355                                         SUIT_DataObject* theObject,
356                                         const QString&   theParentEntry = QString(),
357                                         const bool       theIsInOperation = false );
358
359   /**
360    * Removes data object from the tree.
361    * \param theParent an object will be removed from this parent.
362    * \param theChild the removed object.
363    */
364   void removeChild( SUIT_DataObject* theParent,
365                     SUIT_DataObject* theChild );
366
367   /**
368    * Returns the first child of the object with the specified name
369    * \param theFather object that contain the searched object in children
370    * \param theName name f the searched data object
371    * \returns NULL if not found
372    */
373   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
374                                            const QString& theName );
375
376   void updateDocument();
377
378   /**
379    * Set object visibility state.
380    * \param theModelObject the data model object
381    * \param theDataObject the GUI object
382    */
383   void setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
384                                  HYDROGUI_DataObject* theObject );
385                                  
386
387 protected:
388   QString myStudyURL; ///< the saved/opened document URL
389   QByteArray myStates;
390 };
391
392 #endif