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 * 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.
60 virtual bool open( const QString& theURL,
62 QStringList theFileList );
65 * Saves the document. Reimplemented.
66 * \param returned theFileList list of saved files of this model.
68 virtual bool save( QStringList& theFileList );
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.
76 virtual bool saveAs( const QString& theURL,
78 QStringList& theFileList );
81 * Close the model and remove data. Reimplemented.
86 * Dump study data to Python script. Reimplemented.
88 virtual bool dumpPython( const QString& theURL,
91 QStringList& theListOfFiles );
94 * Returns modification status. Reimplemented.
95 * \return boolean value of modification status
97 virtual bool isModified() const;
100 * Returns saving status. Reimplemented.
101 * \return true if document has saved files on disc.
103 virtual bool isSaved() const;
106 * Updates the internal structure of data object tree.
107 * \param theStudyId study identifier
109 virtual void update( const int theStudyId );
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
116 virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
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
123 virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
126 * Finds the object by entry
127 * \param theEntry an object entry
129 virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
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
136 virtual void update( LightApp_DataObject* theObject = 0,
137 LightApp_Study* theStudy = 0 );
140 * Creates a module object and set is a root for the model
142 CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
145 * Create a new region in the given calculation case containing given zones.
147 bool createNewRegion( Handle(HYDROData_CalculationCase) theCase, const QList<HYDROGUI_Zone*>& theZonesList );
150 * Correct an internal model object according to the current document mode
155 * Find a data object by the specified entry and kind
157 Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
158 const ObjectKind theObjectKind = KIND_UNKNOWN );
161 * Check if it is possible to perform 'undo' operation
163 bool canUndo() const;
166 * Check if it is possible to perform 'redo' operation
168 bool canRedo() const;
171 * Returns the list of names of available 'undo' actions
173 QStringList undoNames() const;
176 * Returns the list of names of available 'redo' actions
178 QStringList redoNames() const;
181 * Clear the list of stored 'undo' actions
186 * Clear the list of stored 'redo' actions
191 * Perform the 'undo' operation
196 * Perform the 'redo' operation
201 * Check if it is possible to perform 'copy' operation
206 * Check if it is possible to perform 'paste' operation
211 * Perform the 'copy' operation
216 * Perform the 'paste' operation
223 bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
226 * Creates the Calculation Case subtree for usage within an operation dialog.
227 * \param theParent a created object will be appended as a child of this GUI object
228 * \param theCase the calculation case model object
230 void buildCaseTree( SUIT_DataObject* theParent,
231 Handle(HYDROData_CalculationCase) theCase );
234 * Updates the object subtree.
235 * \param theObj the data model entity
237 void updateObjectTree( Handle(HYDROData_Entity)& theObj );
240 * Update the sequence of the objects to be copied
242 static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
245 * Returns name of the partition containing the objects of the specified kind
246 * \param theObjectKind kind of objects
247 * \return partition name
249 static QString partitionName( const ObjectKind theObjectKind );
253 * Returns the document for the current study
255 Handle(HYDROData_Document) getDocument() const;
258 * Creates the GUI data object according to the model object.
259 * \param theParent a created object will be appended as a child of this object
260 * \param theModelObject model object
261 * \param theParentEntry entry of parent object
263 LightApp_DataObject* createObject( SUIT_DataObject* theParent,
264 Handle(HYDROData_Entity) theModelObject,
265 const QString& theParentEntry = QString(),
266 const bool theIsBuildTree = true );
269 * Creates the GUI data object without corresponding model object: just by name
270 * \param theParent a created object will be appended as a child of this object
271 * \param theName name of this object
272 * \param theParentEntry entry of parent object
274 LightApp_DataObject* createObject( SUIT_DataObject* theParent,
275 const QString& theName,
276 const QString& theParentEntry = QString() );
279 * Build object tree if the flag theIsBuildTree is true.
280 * This is a conditional wrapper for buildObjectTree method.
281 * \param theParent a created object will be appended as a child of this object
282 * \param theObject the GUI object
283 * \param theParentEntry the entry of parent object
284 * \param theIsBuildTree if true then build the subtree of the GUI object
285 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
287 LightApp_DataObject* buildObject( SUIT_DataObject* theParent,
288 HYDROGUI_DataObject* theObject,
289 const QString& theParentEntry,
290 const bool theIsBuildTree,
291 const bool theIsInOperation = false );
294 * Build object tree if the flag theIsBuildTree is true.
295 * \param theParent a created object will be appended as a child of this GUI object
296 * \param theModelObject the data model zone object
297 * \param theParentEntry the entry of parent object
298 * \param theIsBuildTree if true then build the subtree of the GUI object
299 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
301 LightApp_DataObject* createZone( SUIT_DataObject* theParent,
302 Handle(HYDROData_Zone) theModelObject,
303 const QString& theParentEntry,
304 const bool theIsBuildTree ,
305 const bool theIsInOperation = false );
308 * Build object tree if the flag theIsBuildTree is true.
309 * \param theParent a created object will be appended as a child of this GUI object
310 * \param theModelObject the data model region object
311 * \param theParentEntry the entry of parent object
312 * \param theIsBuildTree if true then build the subtree of the GUI object
313 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
315 LightApp_DataObject* createRegion( SUIT_DataObject* theParent,
316 Handle(HYDROData_Region) theModelObject,
317 const QString& theParentEntry,
318 const bool theIsBuildTree ,
319 const bool theIsInOperation = false );
321 * Creates the default Strickler table object: both GUI data object and corresponding model object
322 * \param theDocument a document into which created object will be added
323 * \param theParent a created object will be appended as a child of this GUI object
325 void createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument,
326 LightApp_DataObject* theParent );
328 * Build partition for object.
329 * \param theObject gui object for which the partition will be build
330 * \param theObjects sequence of builded objects
331 * \param thePartName name of created partition
332 * \param theIsCreateEmpty if true then partition will be created in any case
334 void buildObjectPartition( SUIT_DataObject* theObject,
335 const HYDROData_SequenceOfObjects& theObjects,
336 const QString& thePartName,
337 const bool theIsCreateEmpty );
340 * Build tree of a model object.
341 * \param theParent a created object will be appended as a child of this object
342 * \param theObject gui object for which the tree will be build
343 * \param theParentEntry entry of parent object
344 * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
346 void buildObjectTree( SUIT_DataObject* theParent,
347 SUIT_DataObject* theObject,
348 const QString& theParentEntry = QString(),
349 const bool theIsInOperation = false );
352 * Removes data object from the tree.
353 * \param theParent an object will be removed from this parent.
354 * \param theChild the removed object.
356 void removeChild( SUIT_DataObject* theParent,
357 SUIT_DataObject* theChild );
360 * Returns the first child of the object with the specified name
361 * \param theFather object that contain the searched object in children
362 * \param theName name f the searched data object
363 * \returns NULL if not found
365 static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
366 const QString& theName );
369 * Set object visibility state.
370 * \param theModelObject the data model object
371 * \param theDataObject the GUI object
373 void setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject,
374 HYDROGUI_DataObject* theObject );
378 QString myStudyURL; ///< the saved/opened document URL