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