Salome HOME
Calculation Case Creation dialog is refactored. It is now a two-page wizard.
[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
29 #include <QMap>
30 #include <LightApp_DataModel.h>
31
32 #include <SUIT_TreeModel.h>
33
34 class CAM_DataObject;
35 class SUIT_DataObject;
36 class HYDROGUI_DataObject;
37
38 /**
39  * \class HYDROGUI_DataModel
40  * \brief The class representing the HYDROGUI data model
41  */
42 class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
43 {
44 public:
45   /**
46    * Constructor.
47    * \param theModule module object
48    */
49   HYDROGUI_DataModel( CAM_Module* theModule );
50   virtual ~HYDROGUI_DataModel();
51
52   /**
53    * Open the document into the data model. Reimplemented.
54    * \param theURL opened study path
55    * \param theStudy object study
56    * \param theFileList list of opened files for this model.
57    */
58   virtual bool open( const QString& theURL,
59                      CAM_Study* theStudy,
60                      QStringList theFileList );
61
62   /**
63    * Saves the document. Reimplemented.
64    * \param returned theFileList list of saved files of this model.
65    */
66   virtual bool save( QStringList& theFileList );
67
68   /**
69    * Saves as the document. Reimplemented.
70    * \param theURL saved study path
71    * \param theStudy object study
72    * \param returned theFileList list of saved files of this model.
73    */
74   virtual bool saveAs( const QString& theURL,
75                        CAM_Study* theStudy,
76                        QStringList& theFileList );
77
78   /**
79    * Close the model and remove data. Reimplemented.
80    */
81   virtual bool close();
82
83   /**
84    * Dump study data to Python script. Reimplemented.
85    */
86   virtual bool                        dumpPython( const QString& theURL,
87                                                   CAM_Study*     theStudy,
88                                                   bool           isMultiFile,
89                                                   QStringList&   theListOfFiles );
90
91   /**
92    * Returns modification status. Reimplemented.
93    * \return boolean value of modification status
94    */
95   virtual bool isModified() const;
96
97   /**
98    * Returns saving status. Reimplemented.
99    * \return true if document has saved files on disc.
100    */
101   virtual bool isSaved() const;
102
103   /**
104    * Updates the internal structure of data object tree.
105    * \param theStudyId study identifier
106    */
107   virtual void update( const int theStudyId );
108
109   /**
110    * Returns data object corresponding to the model object.
111    * \param the data model object
112    * \return the only one object referenced to the given data model object, or null if not found
113    */
114   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Entity)& theModelObject );
115
116   /**
117    * Returns a data object referenced to the given data object.
118    * \param the data object
119    * \return the object referenced to the given object, or null if not found
120    */
121   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
122
123   /**
124    * Finds the object by entry
125    * \param theEntry an object entry
126    */
127   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
128
129   /**
130    * Updates the internal structure of data object tree starting from specified data object \a obj.
131    * \param theObject start data object
132    * \param theStudy study object
133    */
134   virtual void update( LightApp_DataObject* theObject = 0,
135                        LightApp_Study* theStudy = 0 );
136
137   /**
138    * Creates a module object and set is a root for the model
139    */
140   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
141
142   /**
143    * Correct an internal model object according to the current document mode
144    */
145   void updateModel();
146
147   /**
148    * Find a data object by the specified entry and kind
149    */
150   Handle(HYDROData_Entity) objectByEntry( const QString& theEntry,
151                                           const ObjectKind theObjectKind = KIND_UNKNOWN );
152
153   /**
154    * Check if it is possible to perform 'undo' operation
155    */
156   bool canUndo() const;
157
158   /**
159    * Check if it is possible to perform 'redo' operation
160    */
161   bool canRedo() const;
162
163   /**
164    * Returns the list of names of available 'undo' actions
165    */
166   QStringList undoNames() const;
167
168   /**
169    * Returns the list of names of available 'redo' actions
170    */
171   QStringList redoNames() const;
172
173   /**
174    * Clear the list of stored 'undo' actions
175    */
176   void clearUndos();
177
178   /**
179    * Clear the list of stored 'redo' actions
180    */
181   void clearRedos();
182
183   /**
184    * Perform the 'undo' operation
185    */
186   bool undo();
187
188   /**
189    * Perform the 'redo' operation
190    */
191   bool redo();
192
193   /**
194    * Check if it is possible to perform 'copy' operation
195    */
196   bool canCopy();
197
198   /**
199    * Check if it is possible to perform 'paste' operation
200    */
201   bool canPaste();
202
203   /**
204    * Perform the 'copy' operation
205    */
206   bool copy();
207
208   /**
209    * Perform the 'paste' operation
210    */
211   bool paste();
212
213   /**
214    * Update the sequence of the objects to be copied
215    */
216   static void changeCopyingObjects( const HYDROData_SequenceOfObjects& );
217
218   /**
219    * Returns name of the partition containing the objects of the specified kind
220    * \param theObjectKind kind of objects
221    * \return partition name
222    */
223   static QString partitionName( const ObjectKind theObjectKind );
224
225   /**
226    * Returns the document for the current study
227    */
228   Handle(HYDROData_Document) getDocument() const;
229
230   /**
231    * Creates the GUI data object according to the model object.
232    * \param theParent a created object will be appended as a child of this object
233    * \param theModelObject model object
234    * \param theParentEntry entry of parent object
235    */
236   LightApp_DataObject* createObject( SUIT_DataObject*         theParent,
237                                      Handle(HYDROData_Entity) theModelObject,
238                                      const QString&           theParentEntry = QString(),
239                                      const bool               theIsBuildTree = true );
240
241 protected:
242   /**
243    * Creates the GUI data object without corresponding model object: just by name
244    * \param theParent a created object will be appended as a child of this object
245    * \param theName name of this object
246    * \param theParentEntry entry of parent object
247    */
248   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
249                                      const QString&   theName,
250                                      const QString&   theParentEntry = QString() );
251
252   /**
253    * Build tree of model object.
254    * \param theParent a created object will be appended as a child of this object
255    * \param theObject gui object for which the tree will be build
256    * \param theParentEntry entry of parent object
257    */
258   void                 buildObjectTree( SUIT_DataObject* theParent,
259                                         SUIT_DataObject* theObject,
260                                         const QString&   theParentEntry = QString() );
261
262   /**
263    * Removes data object from the tree.
264    * \param theParent an object will be removed from this parent.
265    * \param theChild the removed object.
266    */
267   void removeChild( SUIT_DataObject* theParent,
268                     SUIT_DataObject* theChild );
269
270   /**
271    * Returns the first child of the object with the specified name
272    * \param theFather object that contain the searched object in children
273    * \param theName name f the searched data object
274    * \returns NULL if not found
275    */
276   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
277                                            const QString& theName );
278
279 protected:
280   QString myStudyURL; ///< the saved/opened document URL
281 };
282
283 #endif