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,
154 const bool theLandCover );
157 * Correct an internal model object according to the current document mode
162 * Find a data object by the specified entry and kind
164 Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
165 const ObjectKind theObjectKind = KIND_UNKNOWN );
168 * Check if it is possible to perform 'undo' operation
170 bool canUndo() const;
173 * Check if it is possible to perform 'redo' operation
175 bool canRedo() const;
178 * Returns the list of names of available 'undo' actions
180 QStringList undoNames() const;
183 * Returns the list of names of available 'redo' actions
185 QStringList redoNames() const;
188 * Clear the list of stored 'undo' actions
193 * Clear the list of stored 'redo' actions
198 * Perform the 'undo' operation
203 * Perform the 'redo' operation
208 * Check if it is possible to perform 'copy' operation
213 * Check if it is possible to perform 'paste' operation
218 * Perform the 'copy' operation
223 * Perform the 'paste' operation
230 bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
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
238 void buildCaseTree( SUIT_DataObject* theParent,
239 Handle(HYDROData_CalculationCase) theCase,
240 const bool theLandCover );
243 * Updates the object subtree.
244 * \param theObj the data model entity
246 void updateObjectTree( Handle(HYDROData_Entity)& theObj );
249 * Update the sequence of the objects to be copied
251 static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
254 * Returns name of the partition containing the objects of the specified kind
255 * \param theObjectKind kind of objects
256 * \return partition name
258 static QString partitionName( const ObjectKind theObjectKind );
262 * Returns the document for the current study
264 Handle(HYDROData_Document) getDocument() const;
267 * Creates the GUI data object according to the model object.
268 * \param theParent a created object will be appended as a child of this object
269 * \param theModelObject model object
270 * \param theParentEntry entry of parent object
272 LightApp_DataObject* createObject( SUIT_DataObject* theParent,
273 Handle(HYDROData_Entity) theModelObject,
274 const QString& theParentEntry = QString(),
275 const bool theIsBuildTree = true );
278 * Creates the GUI data object without corresponding model object: just by name
279 * \param theParent a created object will be appended as a child of this object
280 * \param theName name of this object
281 * \param theParentEntry entry of parent object
283 LightApp_DataObject* createObject( SUIT_DataObject* theParent,
284 const QString& theName,
285 const QString& theParentEntry = QString() );
288 * Build object tree if the flag theIsBuildTree is true.
289 * This is a conditional wrapper for buildObjectTree method.
290 * \param theParent a created object will be appended as a child of this object
291 * \param theObject the GUI object
292 * \param theParentEntry the entry of parent object
293 * \param theIsBuildTree if true then build the subtree of the GUI object
294 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
296 LightApp_DataObject* buildObject( SUIT_DataObject* theParent,
297 HYDROGUI_DataObject* theObject,
298 const QString& theParentEntry,
299 const bool theIsBuildTree,
300 const bool theIsInOperation = false );
303 * Build object tree if the flag theIsBuildTree is true.
304 * \param theParent a created object will be appended as a child of this GUI object
305 * \param theModelObject the data model zone object
306 * \param theParentEntry the entry of parent object
307 * \param theIsBuildTree if true then build the subtree of the GUI object
308 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
310 LightApp_DataObject* createZone( SUIT_DataObject* theParent,
311 Handle(HYDROData_Zone) theModelObject,
312 const QString& theParentEntry,
313 const bool theIsBuildTree ,
314 const bool theIsInOperation = false );
317 * Build object tree if the flag theIsBuildTree is true.
318 * \param theParent a created object will be appended as a child of this GUI object
319 * \param theModelObject the data model region object
320 * \param theParentEntry the entry of parent object
321 * \param theIsBuildTree if true then build the subtree of the GUI object
322 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
324 LightApp_DataObject* createRegion( SUIT_DataObject* theParent,
325 Handle(HYDROData_Region) theModelObject,
326 const QString& theParentEntry,
327 const bool theIsBuildTree ,
328 const bool theIsInOperation = false );
330 * Creates the default Strickler table object: both GUI data object and corresponding model object
331 * \param theDocument a document into which created object will be added
332 * \param theParent a created object will be appended as a child of this GUI object
334 void createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
335 LightApp_DataObject* theParent );
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
343 void buildObjectPartition( SUIT_DataObject* theObject,
344 const HYDROData_SequenceOfObjects& theObjects,
345 const QString& thePartName,
346 const bool theIsCreateEmpty );
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
355 void buildObjectTree( SUIT_DataObject* theParent,
356 SUIT_DataObject* theObject,
357 const QString& theParentEntry = QString(),
358 const bool theIsInOperation = false );
361 * Removes data object from the tree.
362 * \param theParent an object will be removed from this parent.
363 * \param theChild the removed object.
365 void removeChild( SUIT_DataObject* theParent,
366 SUIT_DataObject* theChild );
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
374 static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
375 const QString& theName );
377 void updateDocument();
380 QString myStudyURL; ///< the saved/opened document URL