Salome HOME
Merge branch 'BR_MULTI_BATHS' into HEAD
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataObject.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19
20 #ifndef HYDROGUI_DATAOBJECT_H
21 #define HYDROGUI_DATAOBJECT_H
22
23 #include <HYDROData_Entity.h>
24
25 #ifdef WIN32
26   #pragma warning( disable: 4250 )
27   #pragma warning( disable: 4251 )
28 #endif
29
30 #include <LightApp_DataObject.h>
31 #include <QString>
32 #include <QMap>
33 #include <QPixmap>
34 #include <QColor>
35
36 #ifdef WIN32
37   #pragma warning( default: 4250 )
38   #pragma warning( default: 4251 )
39 #endif
40
41 /**
42  * \class HYDROGUI_DataObject
43  * \brief Module data object, used for object browser tree creation.
44  *
45  * This is an Object Browser object that contains reference to data structure 
46  * element inside.
47  * This class inherits CAM_DataObject virtually, so it is necessary to call in the class
48  * constructor the CAM object constructor manually for the correct initialization
49  */
50 class HYDROGUI_DataObject : public LightApp_DataObject
51 {
52 public:
53   //! Column id
54   enum { 
55     RefObjectId = RefEntryId + 1,    //!< Ref.Object column
56     AltitudeObjId                    //!< Altitude column
57   };
58
59   //! Role
60   enum {
61     IsInOperationRole = Qtx::AppropriateRole + 100 //!< Filter value role
62   };
63
64   /**
65    * Constructor.
66    * \param theParent parent data object
67    * \param theData reference to the corresponding object from data structure
68    * \param theParentEntry entry of the parent data object (for reference objects)
69    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
70    */
71   HYDROGUI_DataObject( SUIT_DataObject*         theParent,
72                        Handle(HYDROData_Entity) theData,
73                        const QString&           theParentEntry,
74                        const bool               theIsInOperation = false );
75     
76   /**
77    * Returns the unique object identifier string.
78    */
79   virtual QString entry() const;
80
81   /**
82    * Returns the entry of the referenced object.
83    */
84   virtual QString refEntry() const;
85
86   /**
87    * Returns the name of object.
88    */
89   virtual QString name() const;
90
91   /**
92    * Returns the font of displayed object name.
93    */
94   virtual QFont font( const int = SUIT_DataObject::NameId ) const;
95
96   /**
97    * Returns the object color.
98    */
99   virtual QColor color( const ColorRole, const int = NameId ) const;
100
101   /**
102    * Returns the object icon.
103    */
104   virtual QPixmap icon( const int = NameId ) const;
105
106   /**
107    * Returns true if renaming is allowed for the object.
108    */
109   virtual bool    renameAllowed( const int = NameId ) const;
110
111   /**
112    * Returns the model data object.
113    */
114   const Handle(HYDROData_Entity)& modelObject() const { return myData; }
115
116   /**
117    * Redefines the object.
118    */
119   void setObject( const Handle(HYDROData_Entity)& theObject ) { myData = theObject; }
120
121   /**
122    * Returns the entry prefix for all HYDRO data objects.
123    */
124   static QString entryPrefix() { return QString( "HYDRO:" ); }
125
126   /**
127    * Returns the full entry for the specified data object.
128    */
129   static QString dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
130                                   const bool theWithPrefix = true );
131   /**
132    * Sets the validity flag: if object is valid or not.
133    * \param theIsValid is true for valid objects, false for invalid
134    */
135   void setIsValid( const bool theIsValid );
136
137   /**
138    * Returns the validity flag: is object valid or not
139    * \return false if object is not valid
140    */
141   bool isValid() const;
142
143   /**
144    * Returns the usage within active operation flag: 
145    * is the object is used in the local tree of an active operation dialog or not.
146    * \return false if the object is used in the main object browser tree
147    */
148   bool isInOperation() const { return myIsInOperation; }
149
150   void updateBy( SUIT_DataObject* );
151
152 protected:
153   Handle(HYDROData_Entity) myData; ///< object from data model
154   QString myParentEntry;
155   bool myIsValid; ///< indicates if the object is valid
156   bool myIsInOperation; ///< indicates if the object is used within an active operation
157   QPixmap myIcon;
158 };
159
160 /**
161  * \class HYDROGUI_NamedObject
162  * \brief Module data object, used for object browser tree creation.
163  *
164  * It contains only name inside, without additional data: it is just information
165  * or grouping object in the Object Browser.
166  * This class inherits CAM_DataObject virtually, so it is necessary to call in the class
167  * constructor the CAM object constructor manually for the correct initialization
168  */
169 class HYDROGUI_NamedObject : public virtual LightApp_DataObject
170 {
171 public:
172   /**
173    * Constructor.
174    * \param theParent parent data object
175    * \param theName displayed name
176    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
177    */
178   HYDROGUI_NamedObject( SUIT_DataObject* theParent,
179                         const QString&   theName,
180                         const QString&   theParentEntry,
181                         const bool       theIsInOperation = false );
182     
183   /**
184    * Returns the unique object identifier string.
185    */
186   virtual QString entry() const;
187
188   /**
189    * Returns the name of object.
190    */
191   virtual QString name() const;
192
193   /**
194    * Returns the font of displayed object name.
195    */
196   virtual QFont font( const int = SUIT_DataObject::NameId ) const;
197
198   /**
199    * Returns the object icon.
200    */
201   virtual QPixmap icon( const int = NameId ) const;
202
203   /**
204    * Returns the usage within active operation flag: 
205    * is the object is used in the local tree of an active operation dialog or not.
206    * \return false if the object is used in the main object browser tree
207    */
208   bool isInOperation() const { return myIsInOperation; }
209
210   void updateBy( SUIT_DataObject* );
211
212 private:
213   QString myName; ///< name in the OB
214   QString myParentEntry;
215   QPixmap myIcon;
216   bool myIsInOperation; ///< indicates if the object is used within an active operation
217 };
218
219 /**
220  * \brief Module data object, used for dropping items in the object browser.
221  *
222  * It inherits NamedObject with only difference - it accepts dropping.
223  */
224 class HYDROGUI_DropTargetObject : public HYDROGUI_NamedObject
225 {
226 public:
227   /**
228    * Constructor.
229    * \param theParent parent data object
230    * \param theName displayed name
231    * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default
232    */
233   HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
234                              const QString&   theName,
235                              const QString&   theParentEntry,
236                              const bool       theIsInOperation = false );
237     
238   bool isDropAccepted() const { return true; }
239 };
240
241 #endif