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
23 class SalomeApp_DataObject::Key : public SUIT_DataObjectKey
26 Key( const QString& );
29 virtual bool isLess( const SUIT_DataObjectKey* ) const;
30 virtual bool isEqual( const SUIT_DataObjectKey* ) const;
36 SalomeApp_DataObject::Key::Key( const QString& entry )
37 : SUIT_DataObjectKey(),
42 SalomeApp_DataObject::Key::~Key()
46 bool SalomeApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const
48 Key* that = (Key*)other;
49 return myEntry < that->myEntry;
52 bool SalomeApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const
54 Key* that = (Key*)other;
55 return myEntry == that->myEntry;
59 Class: SalomeApp_DataObject
63 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
64 : CAM_DataObject( parent )
68 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
69 : CAM_DataObject( parent )
74 SalomeApp_DataObject::~SalomeApp_DataObject()
78 QString SalomeApp_DataObject::entry() const
81 return myObject->GetID().c_str();
85 SUIT_DataObjectKey* SalomeApp_DataObject::key() const
87 QString str = entry();
88 return new Key( str );
91 QString SalomeApp_DataObject::name() const
96 str = myObject->GetName().c_str();
99 str = QString( "* " ) + str;
104 QPixmap SalomeApp_DataObject::icon() const
106 _PTR(GenericAttribute) anAttr;
107 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
108 _PTR(AttributePixMap) aPixAttr ( anAttr );
109 if ( aPixAttr->HasPixMap() ){
110 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
111 SalomeApp_RootObject* aRoot = dynamic_cast<SalomeApp_RootObject*>( root() );
112 if ( aRoot && aRoot->study() ) {
113 QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName );
121 QColor SalomeApp_DataObject::color() const
123 _PTR(GenericAttribute) anAttr;
124 if ( myObject && myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
126 _PTR(AttributeTextColor) aColAttr( anAttr );
127 QColor color( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
133 QString SalomeApp_DataObject::text( const int id ) const
139 if ( componentObject() != this )
140 txt = value( referencedObject() );
143 txt = entry( referencedObject() );
146 txt = ior( referencedObject() );
150 txt = entry( object() );
156 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
164 _PTR(GenericAttribute) anAttr;
165 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
167 _PTR(AttributeTextColor) aColAttr = anAttr;
168 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
174 clr = QColor( 255, 0, 0 );
176 case HighlightedText:
178 clr = QColor( 255, 255, 255 );
184 QString SalomeApp_DataObject::toolTip() const
186 //return object()->Name();
187 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
190 SUIT_DataObject* SalomeApp_DataObject::componentObject() const
192 SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT)
194 if ( parent() && parent() == root() )
195 compObj = (SUIT_DataObject*)this; // for component-level objects
198 compObj = parent(); // for lower level objects
199 while ( compObj && compObj->parent() != root() )
200 compObj = compObj->parent();
206 QString SalomeApp_DataObject::componentDataType() const
208 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
209 if ( compObj && compObj->object() )
211 _PTR(SComponent) aComp( compObj->object() );
213 return aComp->ComponentDataType().c_str();
219 _PTR(SObject) SalomeApp_DataObject::object() const
224 bool SalomeApp_DataObject::isReference() const
229 _PTR(SObject) refObj;
230 isRef = myObject->ReferencedObject( refObj );
235 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
237 _PTR(SObject) refObj;
238 _PTR(SObject) obj = myObject;
239 while ( obj && obj->ReferencedObject( refObj ) )
245 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
250 _PTR(GenericAttribute) attr;
251 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
253 _PTR(AttributeIOR) iorAttr = attr;
256 std::string str = iorAttr->Value();
257 txt = QString( str.c_str() );
264 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
269 std::string str = obj->GetID();
270 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 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
329 : SalomeApp_DataObject( parent ),
330 CAM_RootObject( parent ),
331 CAM_DataObject( parent )
335 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
336 : SalomeApp_DataObject( sobj, parent ),
337 CAM_RootObject( 0, parent ),
338 CAM_DataObject( parent )
342 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
343 : SalomeApp_DataObject( sobj, parent ),
344 CAM_RootObject( dm, parent ),
345 CAM_DataObject( parent )
349 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()