Salome HOME
1) Data model draft.
[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 "HYDROGUI.h"
27
28 #include <HYDROData_Object.h>
29
30 #include <QMap>
31 #include <LightApp_DataModel.h>
32
33 #include <SUIT_TreeModel.h>
34
35 class CAM_DataObject;
36 class SUIT_DataObject;
37 class HYDROGUI_DataObject;
38
39 /*!
40  * \class HYDROGUI_DataModel
41  * \brief The class representing the HYDROGUI data model
42  */
43 class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
44 {
45 public:
46  /**
47   * Constructor.
48   * \param theModule module object
49   */
50   HYDROGUI_DataModel( CAM_Module* theModule );
51   virtual ~HYDROGUI_DataModel();
52
53   /**
54    * Open the document into the data model. Reimplemented.
55    * /param theURL opened study path
56    * /param theStudy object study
57    * /param theFileList list of opened files for this model.
58    */
59   virtual bool open( const QString& theURL,
60                      CAM_Study* theStudy,
61                      QStringList theFileList );
62
63   /**
64    * Saves the document. Reimplemented.
65    * /param returned theFileList list of saved files of this model.
66    */
67   virtual bool save( QStringList& theFileList );
68
69   /**
70    * Saves as the document. Reimplemented.
71    * /param theURL saved study path
72    * /param theStudy object study
73    * /param returned theFileList list of saved files of this model.
74    */
75   virtual bool saveAs( const QString& theURL,
76                        CAM_Study* theStudy,
77                        QStringList& theFileList );
78
79   /**
80    * Close the model and remove data. Reimplemented.
81    */
82   virtual bool close();
83
84   /**
85    * Returns modification status. Reimplemented.
86    * /return boolean value of modification status
87    */
88   virtual bool isModified() const;
89
90   /**
91    * Returns saving status. Reimplemented.
92    * \return true if document has saved files on disc.
93    */
94   virtual bool isSaved() const;
95
96   /**
97    * Updates the internal structure of data object tree.
98    * \param theStudyId study identifier
99    */
100   virtual void update( const int theStudyId );
101
102   /**
103    * Returns data object corresponding to the model object.
104    * \param the data model object
105    * \returns the only one object referenced to the given data model object, or null if not found
106    */
107   virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Object)& theModelObject );
108
109   /**
110    * Returns a data object referenced to the given data object.
111    * \param the data object
112    * \returns the object referenced to the given object, or null if not found
113    */
114   virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject );
115
116   /**
117    * Finds the object by entry
118    * \param theEntry an object entry
119    */
120   virtual SUIT_DataObject* findObject( const QString& theEntry ) const;
121
122   /**
123    * Updates the internal structure of data object tree starting from specified data object \a obj.
124    * /param theObject start data object
125    * /param theStudy study object
126    */
127   virtual void update( LightApp_DataObject* theObject = 0,
128                        LightApp_Study* theStudy = 0 );
129
130   /**
131    * Creates a module object and set is a root for the model
132    */
133   CAM_DataObject* createRootModuleObject( SUIT_DataObject* theParent );
134
135   /**
136    * Correct an internal model object according to the current document mode
137    */
138   void updateModel();
139
140 protected:
141   /**
142    * Creates the GUI data object according to the model object.
143    * \param theParent a created object will be appended as a child of this object
144    * \param theObject model object
145    */
146   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
147                                      Handle(HYDROData_Object) theModelObject );
148
149   /**
150    * Creates the GUI data object without corresponding model object: just by name
151    * \param theParent a created object will be appended as a child of this object
152    * \param theName name of this object
153    */
154   LightApp_DataObject* createObject( SUIT_DataObject* theParent,
155                                      const QString& theName );
156
157   /**
158    * Removes data object from the tree.
159    * \param theParent an object will be removed from this parent.
160    * \param theChild the removed object.
161    */
162   void removeChild( SUIT_DataObject* theParent,
163                     SUIT_DataObject* theChild );
164
165   /**
166    * Returns the first child of the object with the specified name
167    * \param theFather object that contain the searched object in children
168    * \param theName name f the searched data object
169    * \returns NULL if not found
170    */
171   static SUIT_DataObject* findChildByName( const SUIT_DataObject* theFather,
172                                            const QString& theName );
173
174 protected:
175   QString myStudyURL; ///< the saved/opened document URL
176 };
177
178 #endif