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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef HYDROGUI_DATAMODEL_H
21 #define HYDROGUI_DATAMODEL_H
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>
31 #include <LightApp_DataModel.h>
33 #include <SUIT_TreeModel.h>
36 class SUIT_DataObject;
37 class HYDROGUI_DataObject;
41 * \class HYDROGUI_DataModel
42 * \brief The class representing the HYDROGUI data model
44 class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
49 * \param theModule module object
51 HYDROGUI_DataModel( CAM_Module* theModule );
52 virtual ~HYDROGUI_DataModel();
55 * Creates the document into the data model. Reimplemented.
57 virtual bool create( CAM_Study* );
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.
65 virtual bool open( const QString& theURL,
67 QStringList theFileList );
70 * Saves the document. Reimplemented.
71 * \param returned theFileList list of saved files of this model.
73 virtual bool save( QStringList& theFileList );
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.
81 virtual bool saveAs( const QString& theURL,
83 QStringList& theFileList );
86 * Close the model and remove data. Reimplemented.
91 * Dump study data to Python script. Reimplemented.
93 virtual bool dumpPython( const QString& theURL,
96 QStringList& theListOfFiles );
99 * Returns modification status. Reimplemented.
100 * \return boolean value of modification status
102 virtual bool isModified() const;
105 * Returns saving status. Reimplemented.
106 * \return true if document has saved files on disc.
108 virtual bool isSaved() const;
111 * Updates the internal structure of data object tree.
112 * \param theStudyId study identifier
114 virtual void update( const int theStudyId );
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
121 virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
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
128 virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
131 * Finds the object by entry
132 * \param theEntry an object entry
134 virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
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
141 virtual void update( LightApp_DataObject* theObject = 0,
142 LightApp_Study* theStudy = 0 );
145 * Creates a module object and set is a root for the model
147 CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
150 * Create a new region in the given calculation case containing given zones.
152 bool createNewRegion( Handle(HYDROData_CalculationCase) theCase,
153 const QList<HYDROGUI_Zone*>& theZonesList );
156 * Correct an internal model object according to the current document mode
161 * Find a data object by the specified entry and kind
163 Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
164 const ObjectKind theObjectKind = KIND_UNKNOWN );
167 * Check if it is possible to perform 'undo' operation
169 bool canUndo() const;
172 * Check if it is possible to perform 'redo' operation
174 bool canRedo() const;
177 * Returns the list of names of available 'undo' actions
179 QStringList undoNames() const;
182 * Returns the list of names of available 'redo' actions
184 QStringList redoNames() const;
187 * Clear the list of stored 'undo' actions
192 * Clear the list of stored 'redo' actions
197 * Perform the 'undo' operation
202 * Perform the 'redo' operation
207 * Check if it is possible to perform 'copy' operation
212 * Check if it is possible to perform 'paste' operation
217 * Perform the 'copy' operation
222 * Perform the 'paste' operation
229 bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
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
237 void buildCaseTree( SUIT_DataObject* theParent,
238 Handle(HYDROData_CalculationCase) theCase );
241 * Updates the object subtree.
242 * \param theObj the data model entity
244 void updateObjectTree( Handle(HYDROData_Entity)& theObj );
247 * Update the sequence of the objects to be copied
249 static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
252 * Returns name of the partition containing the objects of the specified kind
253 * \param theObjectKind kind of objects
254 * \return partition name
256 static QString partitionName( const ObjectKind theObjectKind );
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
263 void createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
264 LightApp_DataObject* theParent );
268 * Returns the document for the current study
270 Handle(HYDROData_Document) getDocument() const;
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
278 LightApp_DataObject* createObject( SUIT_DataObject* theParent,
279 Handle(HYDROData_Entity) theModelObject,
280 const QString& theParentEntry = QString(),
281 const bool theIsBuildTree = true );
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
289 LightApp_DataObject* createObject( SUIT_DataObject* theParent,
290 const QString& theName,
291 const QString& theParentEntry = QString() );
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
302 LightApp_DataObject* buildObject( SUIT_DataObject* theParent,
303 HYDROGUI_DataObject* theObject,
304 const QString& theParentEntry,
305 const bool theIsBuildTree,
306 const bool theIsInOperation = false );
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
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 );
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
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 );
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
342 void buildObjectPartition( SUIT_DataObject* theObject,
343 const HYDROData_SequenceOfObjects& theObjects,
344 const QString& thePartName,
345 const bool theIsCreateEmpty );
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
354 void buildObjectTree( SUIT_DataObject* theParent,
355 SUIT_DataObject* theObject,
356 const QString& theParentEntry = QString(),
357 const bool theIsInOperation = false );
360 * Removes data object from the tree.
361 * \param theParent an object will be removed from this parent.
362 * \param theChild the removed object.
364 void removeChild( SUIT_DataObject* theParent,
365 SUIT_DataObject* theChild );
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
373 static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
374 const QString& theName );
376 void updateDocument();
379 * Set object visibility state.
380 * \param theModelObject the data model object
381 * \param theDataObject the GUI object
383 void setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
384 HYDROGUI_DataObject* theObject );
388 QString myStudyURL; ///< the saved/opened document URL