Salome HOME
Minor changes.
[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_Object.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    * Returns modification status. Reimplemented.
85    * \return boolean value of modification status
86    */
87   virtual bool isModified() const;
88
89   /**
90    * Returns saving status. Reimplemented.
91    * \return true if document has saved files on disc.
92    */
93   virtual bool isSaved() const;
94
95   /**
96    * Updates the internal structure of data object tree.
97    * \param theStudyId study identifier
98    */
99   virtual void update( const int theStudyId );
100
101   /**
102    * Returns data object corresponding to the model object.
103    * \param the data model object
104    * \returns the only one object referenced to the given data model object, or null if not found
105    */
106   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Object)& theModelObject );
107
108   /**
109    * Returns a data object referenced to the given data object.
110    * \param the data object
111    * \returns the object referenced to the given object, or null if not found
112    */
113   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
114
115   /**
116    * Finds the object by entry
117    * \param theEntry an object entry
118    */
119   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
120
121   /**
122    * Updates the internal structure of data object tree starting from specified data object \a obj.
123    * \param theObject start data object
124    * \param theStudy study object
125    */
126   virtual void update( LightApp_DataObject* theObject = 0,
127                        LightApp_Study* theStudy = 0 );
128
129   /**
130    * Creates a module object and set is a root for the model
131    */
132   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
133
134   /**
135    * Correct an internal model object according to the current document mode
136    */
137   void updateModel();
138
139   /**
140    * Find a data object by the specified entry and kind
141    */
142   Handle(HYDROData_Object) objectByEntry( const QString& theEntry,
143                                           const ObjectKind theObjectKind );
144
145   /**
146    * Check if it is possible to perform 'undo' operation
147    */
148   bool canUndo() const;
149
150   /**
151    * Check if it is possible to perform 'redo' operation
152    */
153   bool canRedo() const;
154
155   /**
156    * Returns the list of names of available 'undo' actions
157    */
158   QStringList undoNames() const;
159
160   /**
161    * Returns the list of names of available 'redo' actions
162    */
163   QStringList redoNames() const;
164
165   /**
166    * Clear the list of stored 'undo' actions
167    */
168   void clearUndos();
169
170   /**
171    * Clear the list of stored 'redo' actions
172    */
173   void clearRedos();
174
175   /**
176    * Perform the 'undo' operation
177    */
178   bool undo();
179
180   /**
181    * Perform the 'redo' operation
182    */
183   bool redo();
184
185 protected:
186   /**
187    * Returns the document for the current study
188    */
189   Handle(HYDROData_Document) getDocument() const;
190
191   /**
192    * Creates the GUI data object according to the model object.
193    * \param theParent a created object will be appended as a child of this object
194    * \param theObject model object
195    */
196   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
197                                      Handle(HYDROData_Object) theModelObject );
198
199   /**
200    * Creates the GUI data object without corresponding model object: just by name
201    * \param theParent a created object will be appended as a child of this object
202    * \param theName name of this object
203    */
204   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
205                                      const QString& theName );
206
207   /**
208    * Removes data object from the tree.
209    * \param theParent an object will be removed from this parent.
210    * \param theChild the removed object.
211    */
212   void removeChild( SUIT_DataObject* theParent,
213                     SUIT_DataObject* theChild );
214
215   /**
216    * Returns the first child of the object with the specified name
217    * \param theFather object that contain the searched object in children
218    * \param theName name f the searched data object
219    * \returns NULL if not found
220    */
221   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
222                                            const QString& theName );
223
224 protected:
225   QString myStudyURL; ///< the saved/opened document URL
226 };
227
228 #endif