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