Salome HOME
Final version of "Profile interpolation".
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataObject.h
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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
24 #ifndef HYDROGUI_DATAOBJECT_H
25 #define HYDROGUI_DATAOBJECT_H
26
27 #include <HYDROData_Entity.h>
28
29 #ifdef WIN32
30   #pragma warning( disable: 4250 )
31   #pragma warning( disable: 4251 )
32 #endif
33
34 #include <LightApp_DataObject.h>
35 #include <QString>
36 #include <QMap>
37 #include <QPixmap>
38 #include <QColor>
39
40 #ifdef WIN32
41   #pragma warning( disable: 4250 )
42   #pragma warning( disable: 4251 )
43 #endif
44
45 /**
46  * \class HYDROGUI_DataObject
47  * \brief Module data object, used for object browser tree creation.
48  *
49  * This is an Object Browser object that contains reference to data structure 
50  * element inside.
51  * This class inherits CAM_DataObject virtually, so it is necessary to call in the class
52  * constructor the CAM object constructor manually for the correct initialization
53  */
54 class HYDROGUI_DataObject : public LightApp_DataObject
55 {
56 public:
57   //! Column id
58   enum { 
59     RefObjectId = RefEntryId + 1,    //!< Ref.Object column
60     AltitudeObjId                    //!< Altitude column
61   };
62
63   //! Role
64   enum {
65     IsInOperationRole = Qtx::AppropriateRole + 100 //!< Filter value role
66   };
67
68   /**
69    * Constructor.
70    * \param theParent parent data object
71    * \param theData reference to the corresponding object from data structure
72    * \param theParentEntry entry of the parent data object (for reference objects)
73    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
74    */
75   HYDROGUI_DataObject( SUIT_DataObject*         theParent,
76                        Handle(HYDROData_Entity) theData,
77                        const QString&           theParentEntry,
78                        const bool               theIsInOperation = false );
79     
80   /**
81    * Returns the unique object identifier string.
82    */
83   virtual QString entry() const;
84
85   /**
86    * Returns the entry of the referenced object.
87    */
88   virtual QString refEntry() const;
89
90   /**
91    * Returns the name of object.
92    */
93   virtual QString name() const;
94
95   /**
96    * Returns the font of displayed object name.
97    */
98   virtual QFont font( const int = SUIT_DataObject::NameId ) const;
99
100   /**
101    * Returns the object color.
102    */
103   virtual QColor color( const ColorRole, const int = NameId ) const;
104
105   /**
106    * Returns the object icon.
107    */
108   virtual QPixmap icon( const int = NameId ) const;
109
110   /**
111    * Returns true if renaming is allowed for the object.
112    */
113   virtual bool    renameAllowed( const int = NameId ) const;
114
115   /**
116    * Returns the model data object.
117    */
118   const Handle(HYDROData_Entity)& modelObject() const { return myData; }
119
120   /**
121    * Redefines the object.
122    */
123   void setObject( const Handle(HYDROData_Entity)& theObject ) { myData = theObject; }
124
125   /**
126    * Returns the entry prefix for all HYDRO data objects.
127    */
128   static QString entryPrefix() { return QString( "HYDRO:" ); }
129
130   /**
131    * Returns the full entry for the specified data object.
132    */
133   static QString dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
134                                   const bool theWithPrefix = true );
135   /**
136    * Sets the validity flag: if object is valid or not.
137    * \param theIsValid is true for valid objects, false for invalid
138    */
139   void setIsValid( const bool theIsValid );
140
141   /**
142    * Returns the validity flag: is object valid or not
143    * \return false if object is not valid
144    */
145   bool isValid() const;
146
147   /**
148    * Returns the usage within active operation flag: 
149    * is the object is used in the local tree of an active operation dialog or not.
150    * \return false if the object is used in the main object browser tree
151    */
152   bool isInOperation() const { return myIsInOperation; }
153
154   void updateBy( SUIT_DataObject* );
155
156 protected:
157   Handle(HYDROData_Entity) myData; ///< object from data model
158   QString myParentEntry;
159   bool myIsValid; ///< indicates if the object is valid
160   bool myIsInOperation; ///< indicates if the object is used within an active operation
161   QPixmap myIcon;
162 };
163
164 /**
165  * \class HYDROGUI_NamedObject
166  * \brief Module data object, used for object browser tree creation.
167  *
168  * It contains only name inside, without additional data: it is just information
169  * or grouping object in the Object Browser.
170  * This class inherits CAM_DataObject virtually, so it is necessary to call in the class
171  * constructor the CAM object constructor manually for the correct initialization
172  */
173 class HYDROGUI_NamedObject : public virtual LightApp_DataObject
174 {
175 public:
176   /**
177    * Constructor.
178    * \param theParent parent data object
179    * \param theName displayed name
180    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
181    */
182   HYDROGUI_NamedObject( SUIT_DataObject* theParent,
183                         const QString&   theName,
184                         const QString&   theParentEntry,
185                         const bool       theIsInOperation = false );
186     
187   /**
188    * Returns the unique object identifier string.
189    */
190   virtual QString entry() const;
191
192   /**
193    * Returns the name of object.
194    */
195   virtual QString name() const;
196
197   /**
198    * Returns the font of displayed object name.
199    */
200   virtual QFont font( const int = SUIT_DataObject::NameId ) const;
201
202   /**
203    * Returns the object icon.
204    */
205   virtual QPixmap icon( const int = NameId ) const;
206
207   /**
208    * Returns the usage within active operation flag: 
209    * is the object is used in the local tree of an active operation dialog or not.
210    * \return false if the object is used in the main object browser tree
211    */
212   bool isInOperation() const { return myIsInOperation; }
213
214   void updateBy( SUIT_DataObject* );
215
216 private:
217   QString myName; ///< name in the OB
218   QString myParentEntry;
219   QPixmap myIcon;
220   bool myIsInOperation; ///< indicates if the object is used within an active operation
221 };
222
223 /**
224  * \brief Module data object, used for dropping items in the object browser.
225  *
226  * It inherits NamedObject with only difference - it accepts dropping.
227  */
228 class HYDROGUI_DropTargetObject : public HYDROGUI_NamedObject
229 {
230 public:
231   /**
232    * Constructor.
233    * \param theParent parent data object
234    * \param theName displayed name
235    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
236    */
237   HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
238                              const QString&   theName,
239                              const QString&   theParentEntry,
240                              const bool       theIsInOperation = false );
241     
242   bool isDropAccepted() const { return true; }
243 };
244
245 #endif