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