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();
116 str = QString( "* " ) + str;
121 /*!Gets icon picture of object.*/
122 QPixmap SalomeApp_DataObject::icon() const
124 _PTR(GenericAttribute) anAttr;
125 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
126 _PTR(AttributePixMap) aPixAttr ( anAttr );
127 if ( aPixAttr->HasPixMap() ){
128 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
129 SalomeApp_RootObject* aRoot = dynamic_cast<SalomeApp_RootObject*>( root() );
130 if ( aRoot && aRoot->study() ) {
131 QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false );
139 /*!Gets text value for one of entity:
140 *\li Value (id = SalomeApp_DataObject::CT_Value)
141 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
142 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
143 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
145 QString SalomeApp_DataObject::text( const int id ) const
152 if ( componentObject() != this )
154 if ( componentObject() != (SUIT_DataObject*)this )
156 txt = value( referencedObject() );
159 txt = entry( referencedObject() );
162 txt = ior( referencedObject() );
166 txt = entry( object() );
172 /*!Get color value for one of entity:
175 *\li Higlighted text color
177 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
184 clr = QColor( 255, 0, 0 );
187 _PTR(GenericAttribute) anAttr;
188 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
190 _PTR(AttributeTextColor) aColAttr = anAttr;
191 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
197 clr = QColor( 255, 0, 0 );
199 case HighlightedText:
201 clr = QColor( 255, 255, 255 );
208 QString SalomeApp_DataObject::toolTip() const
210 //return object()->Name();
211 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
214 /*!Gets component object.
215 *\retval SUIT_DataObject.
217 SUIT_DataObject* SalomeApp_DataObject::componentObject() const
219 SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT)
221 if ( parent() && parent() == root() )
222 compObj = (SUIT_DataObject*)this; // for component-level objects
225 compObj = parent(); // for lower level objects
226 while ( compObj && compObj->parent() != root() )
227 compObj = compObj->parent();
233 /*!Get component type.*/
234 QString SalomeApp_DataObject::componentDataType() const
236 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
237 if ( compObj && compObj->object() )
239 _PTR(SComponent) aComp( compObj->object() );
241 return aComp->ComponentDataType().c_str();
248 _PTR(SObject) SalomeApp_DataObject::object() const
253 /*!Checks: Is object reference.*/
254 bool SalomeApp_DataObject::isReference() const
259 _PTR(SObject) refObj;
260 isRef = myObject->ReferencedObject( refObj );
265 /*!Gets reference object.*/
266 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
268 _PTR(SObject) refObj;
269 _PTR(SObject) obj = myObject;
270 while ( obj && obj->ReferencedObject( refObj ) )
277 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
282 _PTR(GenericAttribute) attr;
283 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
285 _PTR(AttributeIOR) iorAttr = attr;
288 std::string str = iorAttr->Value();
289 txt = QString( str.c_str() );
297 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
302 std::string str = obj->GetID();
303 txt = QString( str.c_str() );
309 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
312 return QString::null;
315 _PTR(GenericAttribute) attr;
317 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
319 _PTR(AttributeInteger) intAttr = attr;
321 val = QString::number( intAttr->Value() );
323 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
325 _PTR(AttributeReal) realAttr = attr;
327 val = QString::number( realAttr->Value() );
329 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
331 _PTR(AttributeTableOfInteger) tableAttr = attr;
332 std::string title = tableAttr->GetTitle();
333 val = QString( title.c_str() );
334 if ( !val.isEmpty() )
335 val += QString( " " );
336 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
338 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
340 _PTR(AttributeTableOfReal) tableAttr = attr;
341 std::string title = tableAttr->GetTitle();
342 val = QString( title.c_str() );
343 if ( !val.isEmpty() )
344 val += QString( " " );
345 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
347 else if ( obj->FindAttribute( attr, "AttributeComment") )
349 _PTR(AttributeComment) comm = attr;
350 std::string str = comm->Value();
351 val = QString( str.c_str() );
358 Class: SalomeApp_ModuleObject
362 /*!Constructor.Initialize by \a parent.*/
363 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
364 : SalomeApp_DataObject( parent ),
365 CAM_RootObject( parent ),
366 CAM_DataObject( parent )
370 /*!Constructor.Initialize by \a parent and SObject.*/
371 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
372 : SalomeApp_DataObject( sobj, parent ),
373 CAM_RootObject( 0, parent ),
374 CAM_DataObject( parent )
378 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
379 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
380 : SalomeApp_DataObject( sobj, parent ),
381 CAM_RootObject( dm, parent ),
382 CAM_DataObject( parent )
386 /*!Destructor. Do nothing.*/
387 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()