1 #include "SalomeApp_DataObject.h"
3 #include "SalomeApp_Study.h"
4 #include "SalomeApp_RootObject.h"
6 #include <SUIT_Application.h>
7 #include <SUIT_ResourceMgr.h>
8 #include <SUIT_DataObjectKey.h>
12 #include <SALOMEDSClient_AttributeReal.hxx>
13 #include <SALOMEDSClient_AttributeInteger.hxx>
14 #include <SALOMEDSClient_AttributeComment.hxx>
15 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
16 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
19 Class: SalomeApp_DataObject::Key
22 class SalomeApp_DataObject::Key : public SUIT_DataObjectKey
25 Key( const QString& );
28 virtual bool isLess( const SUIT_DataObjectKey* ) const;
29 virtual bool isEqual( const SUIT_DataObjectKey* ) const;
35 /*!Constructor. Initialize by \a entry.*/
36 SalomeApp_DataObject::Key::Key( const QString& entry )
37 : SUIT_DataObjectKey(),
42 /*!Destructor. Do nothing.*/
43 SalomeApp_DataObject::Key::~Key()
47 /*!Checks: Is current key less than \a other.*/
48 bool SalomeApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const
50 Key* that = (Key*)other;
51 return myEntry < that->myEntry;
54 /*!Checks: Is current key equal with \a other.*/
55 bool SalomeApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const
57 Key* that = (Key*)other;
58 return myEntry == that->myEntry;
62 Class: SalomeApp_DataObject
65 /*!Constructor. Initialize by \a parent*/
66 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
67 : CAM_DataObject( parent )
71 /*!Constructor. Initialize by \a parent and SObject*/
72 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
73 : CAM_DataObject( parent )
78 /*!Destructor. Do nothing.*/
79 SalomeApp_DataObject::~SalomeApp_DataObject()
86 QString SalomeApp_DataObject::entry() const
89 return myObject->GetID().c_str();
93 /*!Create and return new key object.*/
94 SUIT_DataObjectKey* SalomeApp_DataObject::key() const
96 QString str = entry();
97 return new Key( str );
100 /*!Gets name of object.*/
101 QString SalomeApp_DataObject::name() const
106 str = myObject->GetName().c_str();
110 _PTR(SObject) refObj = referencedObject();
112 str = refObj->GetName().c_str();
117 if ( !(QString(referencedObject()->GetName()).isEmpty()) )
118 str = QString( "* " ) + str;
120 str = QString( "<Invalid Reference>" );
126 /*!Gets icon picture of object.*/
127 QPixmap SalomeApp_DataObject::icon() const
129 _PTR(GenericAttribute) anAttr;
130 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
131 _PTR(AttributePixMap) aPixAttr ( anAttr );
132 if ( aPixAttr->HasPixMap() ){
133 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
134 SalomeApp_RootObject* aRoot = dynamic_cast<SalomeApp_RootObject*>( root() );
135 if ( aRoot && aRoot->study() ) {
136 QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false );
144 /*!Gets text value for one of entity:
145 *\li Value (id = SalomeApp_DataObject::CT_Value)
146 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
147 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
148 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
150 QString SalomeApp_DataObject::text( const int id ) const
157 if ( componentObject() != this )
159 if ( componentObject() != (SUIT_DataObject*)this )
161 txt = value( referencedObject() );
164 txt = entry( referencedObject() );
167 txt = ior( referencedObject() );
171 txt = entry( object() );
177 /*!Get color value for one of entity:
180 *\li Higlighted text color
182 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
190 if ( !(QString(referencedObject()->GetName()).isEmpty()) )
191 clr = QColor( 255, 0, 0 );
193 clr = QColor( 200, 200, 200 );
197 _PTR(GenericAttribute) anAttr;
198 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
200 _PTR(AttributeTextColor) aColAttr = anAttr;
201 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
208 if ( !(QString(referencedObject()->GetName()).isEmpty()) )
209 clr = QColor( 255, 0, 0 );
211 clr = QColor( 200, 200, 200 );
214 case HighlightedText:
216 clr = QColor( 255, 255, 255 );
223 QString SalomeApp_DataObject::toolTip() const
225 //return object()->Name();
226 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
229 /*!Gets component object.
230 *\retval SUIT_DataObject.
232 SUIT_DataObject* SalomeApp_DataObject::componentObject() const
234 SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT)
236 if ( parent() && parent() == root() )
237 compObj = (SUIT_DataObject*)this; // for component-level objects
240 compObj = parent(); // for lower level objects
241 while ( compObj && compObj->parent() != root() )
242 compObj = compObj->parent();
248 /*!Get component type.*/
249 QString SalomeApp_DataObject::componentDataType() const
251 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
252 if ( compObj && compObj->object() )
254 _PTR(SComponent) aComp( compObj->object() );
256 return aComp->ComponentDataType().c_str();
263 _PTR(SObject) SalomeApp_DataObject::object() const
268 /*!Checks: Is object reference.*/
269 bool SalomeApp_DataObject::isReference() const
274 _PTR(SObject) refObj;
275 isRef = myObject->ReferencedObject( refObj );
280 /*!Gets reference object.*/
281 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
283 _PTR(SObject) refObj;
284 _PTR(SObject) obj = myObject;
285 while ( obj && obj->ReferencedObject( refObj ) )
292 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
297 _PTR(GenericAttribute) attr;
298 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
300 _PTR(AttributeIOR) iorAttr = attr;
303 std::string str = iorAttr->Value();
304 txt = QString( str.c_str() );
312 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
317 std::string str = obj->GetID();
318 txt = QString( str.c_str() );
324 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
327 return QString::null;
330 _PTR(GenericAttribute) attr;
332 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
334 _PTR(AttributeInteger) intAttr = attr;
336 val = QString::number( intAttr->Value() );
338 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
340 _PTR(AttributeReal) realAttr = attr;
342 val = QString::number( realAttr->Value() );
344 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
346 _PTR(AttributeTableOfInteger) tableAttr = attr;
347 std::string title = tableAttr->GetTitle();
348 val = QString( title.c_str() );
349 if ( !val.isEmpty() )
350 val += QString( " " );
351 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
353 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
355 _PTR(AttributeTableOfReal) tableAttr = attr;
356 std::string title = tableAttr->GetTitle();
357 val = QString( title.c_str() );
358 if ( !val.isEmpty() )
359 val += QString( " " );
360 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
362 else if ( obj->FindAttribute( attr, "AttributeComment") )
364 _PTR(AttributeComment) comm = attr;
365 std::string str = comm->Value();
366 val = QString( str.c_str() );
373 Class: SalomeApp_ModuleObject
377 /*!Constructor.Initialize by \a parent.*/
378 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
379 : SalomeApp_DataObject( parent ),
380 CAM_RootObject( parent ),
381 CAM_DataObject( parent )
385 /*!Constructor.Initialize by \a parent and SObject.*/
386 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
387 : SalomeApp_DataObject( sobj, parent ),
388 CAM_RootObject( 0, parent ),
389 CAM_DataObject( parent )
393 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
394 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
395 : SalomeApp_DataObject( sobj, parent ),
396 CAM_RootObject( dm, parent ),
397 CAM_DataObject( parent )
401 /*!Destructor. Do nothing.*/
402 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()