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