Salome HOME
- Zones drag and drop in the Calculation Case wizard is implemented.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROGUI_DATAMODEL_H
24 #define HYDROGUI_DATAMODEL_H
25
26 #include <HYDROData_Document.h>
27 #include <HYDROData_Entity.h>
28 #include <HYDROData_Zone.h>
29 #include <HYDROData_Region.h>
30 #include <HYDROData_CalculationCase.h>
31
32 #include <QMap>
33 #include <QList>
34 #include <LightApp_DataModel.h>
35
36 #include <SUIT_TreeModel.h>
37
38 class CAM_DataObject;
39 class SUIT_DataObject;
40 class HYDROGUI_DataObject;
41 class HYDROGUI_Zone;
42
43 /**
44  * \class HYDROGUI_DataModel
45  * \brief The class representing the HYDROGUI data model
46  */
47 class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
48 {
49 public:
50   /**
51    * Constructor.
52    * \param theModule module object
53    */
54   HYDROGUI_DataModel( CAM_Module* theModule );
55   virtual ~HYDROGUI_DataModel();
56
57   /**
58    * Open the document into the data model. Reimplemented.
59    * \param theURL opened study path
60    * \param theStudy object study
61    * \param theFileList list of opened files for this model.
62    */
63   virtual bool open( const QString& theURL,
64                      CAM_Study* theStudy,
65                      QStringList theFileList );
66
67   /**
68    * Saves the document. Reimplemented.
69    * \param returned theFileList list of saved files of this model.
70    */
71   virtual bool save( QStringList& theFileList );
72
73   /**
74    * Saves as the document. Reimplemented.
75    * \param theURL saved study path
76    * \param theStudy object study
77    * \param returned theFileList list of saved files of this model.
78    */
79   virtual bool saveAs( const QString& theURL,
80                        CAM_Study* theStudy,
81                        QStringList& theFileList );
82
83   /**
84    * Close the model and remove data. Reimplemented.
85    */
86   virtual bool close();
87
88   /**
89    * Dump study data to Python script. Reimplemented.
90    */
91   virtual bool                        dumpPython( const QString& theURL,
92                                                   CAM_Study*     theStudy,
93                                                   bool           isMultiFile,
94                                                   QStringList&   theListOfFiles );
95
96   /**
97    * Returns modification status. Reimplemented.
98    * \return boolean value of modification status
99    */
100   virtual bool isModified() const;
101
102   /**
103    * Returns saving status. Reimplemented.
104    * \return true if document has saved files on disc.
105    */
106   virtual bool isSaved() const;
107
108   /**
109    * Updates the internal structure of data object tree.
110    * \param theStudyId study identifier
111    */
112   virtual void update( const int theStudyId );
113
114   /**
115    * Returns data object corresponding to the model object.
116    * \param the data model object
117    * \return the only one object referenced to the given data model object, or null if not found
118    */
119   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
120
121   /**
122    * Returns a data object referenced to the given data object.
123    * \param the data object
124    * \return the object referenced to the given object, or null if not found
125    */
126   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
127
128   /**
129    * Finds the object by entry
130    * \param theEntry an object entry
131    */
132   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
133
134   /**
135    * Updates the internal structure of data object tree starting from specified data object \a obj.
136    * \param theObject start data object
137    * \param theStudy study object
138    */
139   virtual void update( LightApp_DataObject* theObject = 0,
140                        LightApp_Study* theStudy = 0 );
141
142   /**
143    * Creates a module object and set is a root for the model
144    */
145   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
146
147   /**
148    * Create a new region in the given calculation case containing given zones. 
149    */
150   bool createNewRegion( Handle(HYDROData_CalculationCase) theCase, const QList<HYDROGUI_Zone*>& theZonesList );
151
152   /**
153    * Correct an internal model object according to the current document mode
154    */
155   void updateModel();
156
157   /**
158    * Find a data object by the specified entry and kind
159    */
160   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
161                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
162
163   /**
164    * Check if it is possible to perform 'undo' operation
165    */
166   bool canUndo() const;
167
168   /**
169    * Check if it is possible to perform 'redo' operation
170    */
171   bool canRedo() const;
172
173   /**
174    * Returns the list of names of available 'undo' actions
175    */
176   QStringList undoNames() const;
177
178   /**
179    * Returns the list of names of available 'redo' actions
180    */
181   QStringList redoNames() const;
182
183   /**
184    * Clear the list of stored 'undo' actions
185    */
186   void clearUndos();
187
188   /**
189    * Clear the list of stored 'redo' actions
190    */
191   void clearRedos();
192
193   /**
194    * Perform the 'undo' operation
195    */
196   bool undo();
197
198   /**
199    * Perform the 'redo' operation
200    */
201   bool redo();
202
203   /**
204    * Check if it is possible to perform 'copy' operation
205    */
206   bool canCopy();
207
208   /**
209    * Check if it is possible to perform 'paste' operation
210    */
211   bool canPaste();
212
213   /**
214    * Perform the 'copy' operation
215    */
216   bool copy();
217
218   /**
219    * Perform the 'paste' operation
220    */
221   bool paste();
222
223   /**
224    * Creates the GUI data object according to the model object.
225    * \param theParent a created object will be appended as a child of this object
226    * \param theModelObject model object
227    * \param theParentEntry entry of parent object
228    */
229   void buildCaseTree( SUIT_DataObject*                  theParent,
230                       Handle(HYDROData_CalculationCase) theCase );
231
232   /**
233    * Update the sequence of the objects to be copied
234    */
235   static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
236
237   /**
238    * Returns name of the partition containing the objects of the specified kind
239    * \param theObjectKind kind of objects
240    * \return partition name
241    */
242   static QString partitionName( const ObjectKind theObjectKind );
243
244 protected:
245   /**
246    * Returns the document for the current study
247    */
248   Handle(HYDROData_Document) getDocument() const;
249
250   /**
251    * Creates the GUI data object according to the model object.
252    * \param theParent a created object will be appended as a child of this object
253    * \param theModelObject model object
254    * \param theParentEntry entry of parent object
255    */
256   LightApp_DataObject* createObject( SUIT_DataObject*         theParent,
257                                      Handle(HYDROData_Entity) theModelObject,
258                                      const QString&           theParentEntry = QString(),
259                                      const bool               theIsBuildTree = true );
260
261   /**
262    * Creates the GUI data object without corresponding model object: just by name
263    * \param theParent a created object will be appended as a child of this object
264    * \param theName name of this object
265    * \param theParentEntry entry of parent object
266    */
267   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
268                                      const QString&   theName,
269                                      const QString&   theParentEntry = QString() );
270
271   /**
272    * Build object tree if the flag theIsBuildTree is true. 
273    * This is a conditional wrapper for buildObjectTree method.
274    * \param theParent a created object will be appended as a child of this object
275    * \param theObject the GUI object
276    * \param theParentEntry the entry of parent object
277    * \param theIsBuildTree if true then build the subtree of the GUI object
278    */
279   LightApp_DataObject* buildObject( SUIT_DataObject*     theParent,
280                                     HYDROGUI_DataObject* theObject,
281                                     const QString&       theParentEntry,
282                                     const bool           theIsBuildTree );
283
284   LightApp_DataObject* createZone( SUIT_DataObject*       theParent,
285                                    Handle(HYDROData_Zone) theModelObject,
286                                    const QString&         theParentEntry,
287                                    const bool             theIsBuildTree );
288
289   LightApp_DataObject* createRegion( SUIT_DataObject*         theParent,
290                                      Handle(HYDROData_Region) theModelObject,
291                                      const QString&           theParentEntry,
292                                      const bool               theIsBuildTree );
293   /**
294    * Build tree of model object.
295    * \param theParent a created object will be appended as a child of this object
296    * \param theObject gui object for which the tree will be build
297    * \param theParentEntry entry of parent object
298    */
299   void                 buildObjectTree( SUIT_DataObject* theParent,
300                                         SUIT_DataObject* theObject,
301                                         const QString&   theParentEntry = QString() );
302
303   /**
304    * Removes data object from the tree.
305    * \param theParent an object will be removed from this parent.
306    * \param theChild the removed object.
307    */
308   void removeChild( SUIT_DataObject* theParent,
309                     SUIT_DataObject* theChild );
310
311   /**
312    * Returns the first child of the object with the specified name
313    * \param theFather object that contain the searched object in children
314    * \param theName name f the searched data object
315    * \returns NULL if not found
316    */
317   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
318                                            const QString& theName );
319
320 protected:
321   QString myStudyURL; ///< the saved/opened document URL
322 };
323
324 #endif