1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "SalomeApp_DataObject.h"
21 #include "SalomeApp_Study.h"
22 #include "LightApp_RootObject.h"
24 #include <SUIT_Application.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_DataObjectKey.h>
30 #include <SALOMEDSClient_AttributeReal.hxx>
31 #include <SALOMEDSClient_AttributeInteger.hxx>
32 #include <SALOMEDSClient_AttributeComment.hxx>
33 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
34 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
37 Class: SalomeApp_DataObject
40 /*!Constructor. Initialize by \a parent*/
41 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
42 : LightApp_DataObject( parent ),
43 CAM_DataObject( parent )
47 /*!Constructor. Initialize by \a parent and SObject*/
48 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
49 : LightApp_DataObject( parent ),
50 CAM_DataObject( parent )
55 /*!Destructor. Do nothing.*/
56 SalomeApp_DataObject::~SalomeApp_DataObject()
63 QString SalomeApp_DataObject::entry() const
66 return myObject->GetID().c_str();
70 /*!Gets name of object.*/
71 QString SalomeApp_DataObject::name() const
76 str = myObject->GetName().c_str();
80 _PTR(SObject) refObj = referencedObject();
82 str = refObj->GetName().c_str();
87 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
88 str = QString( "* " ) + str;
90 str = QString( "<Invalid Reference>" );
96 /*!Gets icon picture of object.*/
97 QPixmap SalomeApp_DataObject::icon() const
99 _PTR(GenericAttribute) anAttr;
100 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
101 _PTR(AttributePixMap) aPixAttr ( anAttr );
102 if ( aPixAttr->HasPixMap() ){
103 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
104 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
105 if ( aRoot && aRoot->study() ) {
106 QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false );
114 /*!Gets text value for one of entity:
115 *\li Value (id = SalomeApp_DataObject::CT_Value)
116 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
117 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
118 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
120 QString SalomeApp_DataObject::text( const int id ) const
127 if ( componentObject() != this )
129 if ( componentObject() != (SUIT_DataObject*)this )
131 txt = value( referencedObject() );
134 txt = entry( object() );
137 txt = ior( referencedObject() );
141 txt = entry( referencedObject() );
147 /*!Get color value for one of entity:
150 *\li Higlighted text color
152 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
160 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
161 clr = QColor( 255, 0, 0 );
163 clr = QColor( 200, 200, 200 );
167 _PTR(GenericAttribute) anAttr;
168 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
170 _PTR(AttributeTextColor) aColAttr = anAttr;
171 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
178 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
179 clr = QColor( 255, 0, 0 );
181 clr = QColor( 200, 200, 200 );
184 case HighlightedText:
186 clr = QColor( 255, 255, 255 );
193 QString SalomeApp_DataObject::toolTip() const
195 //return object()->Name();
196 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
199 /*!Get component type.*/
200 QString SalomeApp_DataObject::componentDataType() const
202 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
203 if ( compObj && compObj->object() )
205 _PTR(SComponent) aComp( compObj->object() );
207 return aComp->ComponentDataType().c_str();
214 _PTR(SObject) SalomeApp_DataObject::object() const
219 /*!Checks: Is object reference.*/
220 bool SalomeApp_DataObject::isReference() const
225 _PTR(SObject) refObj;
226 isRef = myObject->ReferencedObject( refObj );
231 /*!Gets reference object.*/
232 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
234 _PTR(SObject) refObj;
235 _PTR(SObject) obj = myObject;
236 while ( obj && obj->ReferencedObject( refObj ) )
243 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
248 _PTR(GenericAttribute) attr;
249 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
251 _PTR(AttributeIOR) iorAttr = attr;
254 std::string str = iorAttr->Value();
255 txt = QString( str.c_str() );
263 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
268 std::string str = obj->GetID();
269 txt = QString( str.c_str() );
275 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
278 return QString::null;
281 _PTR(GenericAttribute) attr;
283 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
285 _PTR(AttributeInteger) intAttr = attr;
287 val = QString::number( intAttr->Value() );
289 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
291 _PTR(AttributeReal) realAttr = attr;
293 val = QString::number( realAttr->Value() );
295 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
297 _PTR(AttributeTableOfInteger) tableAttr = attr;
298 std::string title = tableAttr->GetTitle();
299 val = QString( title.c_str() );
300 if ( !val.isEmpty() )
301 val += QString( " " );
302 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
304 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
306 _PTR(AttributeTableOfReal) tableAttr = attr;
307 std::string title = tableAttr->GetTitle();
308 val = QString( title.c_str() );
309 if ( !val.isEmpty() )
310 val += QString( " " );
311 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
313 else if ( obj->FindAttribute( attr, "AttributeComment") )
315 _PTR(AttributeComment) comm = attr;
316 std::string str = comm->Value();
317 val = QString( str.c_str() );
324 Class: SalomeApp_ModuleObject
328 /*!Constructor.Initialize by \a parent.*/
329 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
330 : SalomeApp_DataObject( parent ),
331 CAM_RootObject( parent ),
332 CAM_DataObject( parent )
336 /*!Constructor.Initialize by \a parent and SObject.*/
337 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
338 : SalomeApp_DataObject( sobj, parent ),
339 CAM_RootObject( 0, parent ),
340 CAM_DataObject( parent )
344 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
345 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
346 : SalomeApp_DataObject( sobj, parent ),
347 CAM_RootObject( dm, parent ),
348 CAM_DataObject( parent )
352 /*!Destructor. Do nothing.*/
353 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()
357 /*!Returns module name */
358 QString SalomeApp_ModuleObject::name() const
360 return SalomeApp_DataObject::name();