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();
100 _PTR(SObject) refObj = referencedObject();
102 str = refObj->GetName().c_str();
106 str = QString( "* " ) + str;
111 QPixmap SalomeApp_DataObject::icon() const
113 _PTR(GenericAttribute) anAttr;
114 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
115 _PTR(AttributePixMap) aPixAttr ( anAttr );
116 if ( aPixAttr->HasPixMap() ){
117 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
118 SalomeApp_RootObject* aRoot = dynamic_cast<SalomeApp_RootObject*>( root() );
119 if ( aRoot && aRoot->study() ) {
120 QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName );
128 QString SalomeApp_DataObject::text( const int id ) const
134 if ( componentObject() != this )
135 txt = value( referencedObject() );
138 txt = entry( referencedObject() );
141 txt = ior( referencedObject() );
145 txt = entry( object() );
151 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
158 clr = QColor( 255, 0, 0 );
161 _PTR(GenericAttribute) anAttr;
162 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
164 _PTR(AttributeTextColor) aColAttr = anAttr;
165 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
171 clr = QColor( 255, 0, 0 );
173 case HighlightedText:
175 clr = QColor( 255, 255, 255 );
181 QString SalomeApp_DataObject::toolTip() const
183 //return object()->Name();
184 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
187 SUIT_DataObject* SalomeApp_DataObject::componentObject() const
189 SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT)
191 if ( parent() && parent() == root() )
192 compObj = (SUIT_DataObject*)this; // for component-level objects
195 compObj = parent(); // for lower level objects
196 while ( compObj && compObj->parent() != root() )
197 compObj = compObj->parent();
203 QString SalomeApp_DataObject::componentDataType() const
205 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
206 if ( compObj && compObj->object() )
208 _PTR(SComponent) aComp( compObj->object() );
210 return aComp->ComponentDataType().c_str();
216 _PTR(SObject) SalomeApp_DataObject::object() const
221 bool SalomeApp_DataObject::isReference() const
226 _PTR(SObject) refObj;
227 isRef = myObject->ReferencedObject( refObj );
232 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
234 _PTR(SObject) refObj;
235 _PTR(SObject) obj = myObject;
236 while ( obj && obj->ReferencedObject( refObj ) )
242 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
247 _PTR(GenericAttribute) attr;
248 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
250 _PTR(AttributeIOR) iorAttr = attr;
253 std::string str = iorAttr->Value();
254 txt = QString( str.c_str() );
261 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
266 std::string str = obj->GetID();
267 txt = QString( str.c_str() );
272 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
275 return QString::null;
278 _PTR(GenericAttribute) attr;
280 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
282 _PTR(AttributeInteger) intAttr = attr;
284 val = QString::number( intAttr->Value() );
286 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
288 _PTR(AttributeReal) realAttr = attr;
290 val = QString::number( realAttr->Value() );
292 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
294 _PTR(AttributeTableOfInteger) tableAttr = attr;
295 std::string title = tableAttr->GetTitle();
296 val = QString( title.c_str() );
297 if ( !val.isEmpty() )
298 val += QString( " " );
299 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
301 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
303 _PTR(AttributeTableOfReal) tableAttr = attr;
304 std::string title = tableAttr->GetTitle();
305 val = QString( title.c_str() );
306 if ( !val.isEmpty() )
307 val += QString( " " );
308 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
310 else if ( obj->FindAttribute( attr, "AttributeComment") )
312 _PTR(AttributeComment) comm = attr;
313 std::string str = comm->Value();
314 val = QString( str.c_str() );
321 Class: SalomeApp_ModuleObject
325 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
326 : SalomeApp_DataObject( parent ),
327 CAM_RootObject( parent ),
328 CAM_DataObject( parent )
332 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
333 : SalomeApp_DataObject( sobj, parent ),
334 CAM_RootObject( 0, parent ),
335 CAM_DataObject( parent )
339 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
340 : SalomeApp_DataObject( sobj, parent ),
341 CAM_RootObject( dm, parent ),
342 CAM_DataObject( parent )
346 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()