Salome HOME
29563ef8ad38d65495262877c6fc55481677124d
[modules/gui.git] / src / CAM / CAM_DataObject.cxx
1 //  Copyright (C) 2007-2008  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 #include "CAM_DataObject.h"
23
24 #include "CAM_Module.h"
25 #include "CAM_DataModel.h"
26
27 #include <Qtx.h>
28
29 /*!
30   \class CAM_DataObject
31   \brief CAM-based implementation of the data object.
32   
33   In addition to base implementation provides integration
34   with CAM_DataModel.
35 */
36
37 /*!
38   \brief Constructor.
39   \param parent parent data object
40 */
41 CAM_DataObject::CAM_DataObject( SUIT_DataObject* parent )
42 : SUIT_DataObject( parent )
43 {
44 }
45
46 /*!
47   \brief Destructor.
48
49   Does nothing.
50 */
51 CAM_DataObject::~CAM_DataObject()
52 {
53 }
54
55 /*!
56   \brief Get CAM module.
57   \return parent module object pointer
58 */
59 CAM_Module* CAM_DataObject::module() const
60
61   CAM_DataModel* dm = dataModel();
62   return dm ? dm->module() : 0;
63 }
64
65 /*!
66   \brief Get CAM data model.
67   \return data model or 0 if it is not set
68   \sa CAM_ModuleObject class
69 */
70 CAM_DataModel* CAM_DataObject::dataModel() const
71 {
72   CAM_DataObject* parentObj = dynamic_cast<CAM_DataObject*>( parent() );
73   return parentObj ? parentObj->dataModel() : 0;
74 }
75
76 /*!
77   \class CAM_ModuleObject
78   \brief CAM data model root object.
79   
80   This class is intended for optimized access to CAM_DataModel instance
81   from CAM_DataObject instances.
82
83   To take advantage of this class in a specific application, 
84   custom data model root object class should be derived from both CAM_ModuleObject
85   and application-specific DataObject implementation using virtual inheritance.
86 */
87
88 /*!
89   \brief Constructor.
90   \param parent parent data object
91 */
92 CAM_ModuleObject::CAM_ModuleObject( SUIT_DataObject* parent )
93 : CAM_DataObject( parent ),
94   myDataModel( 0 )
95 {
96 }
97
98 /*!
99   \brief Constructor.
100   \param data data model
101   \param parent parent data object
102 */
103 CAM_ModuleObject::CAM_ModuleObject( CAM_DataModel* data, SUIT_DataObject* parent )
104 : CAM_DataObject( parent ),
105   myDataModel( data )
106 {
107 }
108
109 /*!
110   \brief Destructor.
111
112   Does nothing.
113 */
114 CAM_ModuleObject::~CAM_ModuleObject()
115 {
116 }
117
118 /*!
119   \brief Get root object name.
120
121   If the data model is set, this method returns module name.
122   Otherwise returns empty string.
123
124   \return root object name
125 */
126 QString CAM_ModuleObject::name() const
127 {
128   return myDataModel ? myDataModel->module()->moduleName() : QString();
129 }
130
131 /*!
132   \brief Get data object icon for the specified column.
133
134   The parameter \a id specifies the column identificator
135
136   \param id column id
137   \return object icon for the specified column
138 */
139 QPixmap CAM_ModuleObject::icon( const int id ) const
140 {
141   QPixmap p;
142   // show icon only for the "Name" column
143   if ( id == NameId && dataModel() && dataModel()->module() )
144     p = dataModel()->module()->moduleIcon();
145   if ( !p.isNull() )
146     p = Qtx::scaleIcon( p, 16 );
147   return p;
148 }
149
150 /*!
151   \brief Get data object tooltip for the specified column.
152
153   The parameter \a id specifies the column identificator
154
155   \param id column id
156   \return object tooltip for the specified column
157 */
158 QString CAM_ModuleObject::toolTip( const int /*id*/ ) const
159 {
160   // show the same tooltip for all columns
161   QString tip;
162   if ( dataModel() && dataModel()->module() )
163     tip = QObject::tr( "MODULE_ROOT_OBJECT_TOOLTIP" ).arg( dataModel()->module()->moduleName() );
164   return tip;
165 }
166
167 /*!
168   \brief Get data model.
169   \return data model pointer or 0 if it is not set
170 */
171 CAM_DataModel* CAM_ModuleObject::dataModel() const
172 {
173   return myDataModel;
174 }
175
176 /*!
177   \brief Set data model.
178   \param dm data model
179 */
180 void CAM_ModuleObject::setDataModel( CAM_DataModel* dm )
181 {
182   myDataModel = dm;
183 }