Salome HOME
Icons are shown in the object browser tree.
[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   /**
54    * Constructor.
55    * \param theParent parent data object
56    * \param theData reference to the corresponding object from data structure
57    * \param theParentEntry entry of the parent data object (for reference objects)
58    */
59   HYDROGUI_DataObject( SUIT_DataObject* theParent,
60                        Handle(HYDROData_Entity) theData,
61                        const QString& theParentEntry );
62     
63   /**
64    * Returns the unique object identifier string.
65    */
66   virtual QString entry() const;
67
68   /**
69    * Returns the entry of the referenced object.
70    */
71   virtual QString refEntry() const;
72
73   /**
74    * Returns the name of object.
75    */
76   virtual QString name() const;
77
78   /**
79    * Returns the font of displayed object name.
80    */
81   virtual QFont font( const int = SUIT_DataObject::NameId ) const;
82
83   /**
84    * Returns the object color.
85    */
86   virtual QColor color( const ColorRole, const int = NameId ) const;
87
88   /**
89    * Returns the object icon.
90    */
91   virtual QPixmap icon( const int = NameId ) const;
92
93   /**
94    * Returns the model data object.
95    */
96   const Handle(HYDROData_Entity)& modelObject() const { return myData; }
97
98   /**
99    * Redefines the object.
100    */
101   void setObject( const Handle(HYDROData_Entity)& theObject ) { myData = theObject; }
102
103   /**
104    * Returns the entry prefix for all HYDRO data objects.
105    */
106   static QString entryPrefix() { return QString( "HYDRO:" ); }
107
108   /**
109    * Returns the full entry for the specified data object.
110    */
111   static QString dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
112                                   const bool theWithPrefix = true );
113   /**
114    * Sets the validity flag: if object is valid or not.
115    * \param theIsValid is true for valid objects, false for invalid
116    */
117   void setIsValid( const bool theIsValid );
118
119   /**
120    * Returns the validity flag: is object valid or not
121    * \returns false if object is not valid
122    */
123   bool isValid() const;
124
125 protected:
126   Handle(HYDROData_Entity) myData; ///< object from data model
127   QString myParentEntry;
128   bool myIsValid; ///< indicates if the object is valid
129   QPixmap myIcon;
130 };
131
132 /**
133  * \class HYDROGUI_NamedObject
134  * \brief Module data object, used for object browser tree creation.
135  *
136  * It contains only name inside, without additional data: it is just information
137  * or grouping object in the Object Browser.
138  * This class inherits CAM_DataObject virtually, so it is necessary to call in the class
139  * constructor the CAM object constructor manually for the correct initialization
140  */
141 class HYDROGUI_NamedObject : public virtual LightApp_DataObject
142 {
143 public:
144   /**
145    * Constructor.
146    * \param theParent parent data object
147    * \param theName displayed name
148    */
149   HYDROGUI_NamedObject( SUIT_DataObject* theParent,
150                         const QString& theName,
151                         const QString& theParentEntry  );
152     
153   /**
154    * Returns the unique object identifier string.
155    */
156   virtual QString entry() const;
157
158   /**
159    * Returns the name of object.
160    */
161   virtual QString name() const;
162
163   /**
164    * Returns the object icon.
165    */
166   virtual QPixmap icon( const int = NameId ) const;
167
168 private:
169   QString myName; ///< name in the OB
170   QString myParentEntry;
171   QPixmap myIcon;
172 };
173
174 /**
175  * \brief Module data object, used for dropping items in the object browser.
176  *
177  * It inherits NamedObject with only difference - it accepts dropping.
178  */
179 class HYDROGUI_DropTargetObject : public HYDROGUI_NamedObject
180 {
181 public:
182   /**
183    * Constructor.
184    * \param theParent parent data object
185    * \param theName displayed name
186    */
187   HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
188                              const QString& theName,
189                              const QString& theParentEntry  );
190     
191   bool isDropAccepted() const { return true; }
192 };
193
194 #endif