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
163 _PTR(GenericAttribute) anAttr;
164 if ( myObject && myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
166 _PTR(AttributeTextColor) aColAttr( anAttr );
167 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
173 clr = QColor( 255, 0, 0 );
175 case HighlightedText:
177 clr = QColor( 255, 255, 255 );
183 QString SalomeApp_DataObject::toolTip() const
185 //return object()->Name();
186 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
189 SUIT_DataObject* SalomeApp_DataObject::componentObject() const
191 SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT)
193 if ( parent() && parent() == root() )
194 compObj = (SUIT_DataObject*)this; // for component-level objects
197 compObj = parent(); // for lower level objects
198 while ( compObj && compObj->parent() != root() )
199 compObj = compObj->parent();
205 QString SalomeApp_DataObject::componentDataType() const
207 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
208 if ( compObj && compObj->object() )
210 _PTR(SComponent) aComp( compObj->object() );
212 return aComp->ComponentDataType().c_str();
218 _PTR(SObject) SalomeApp_DataObject::object() const
223 bool SalomeApp_DataObject::isReference() const
228 _PTR(SObject) refObj;
229 isRef = myObject->ReferencedObject( refObj );
234 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
236 _PTR(SObject) refObj;
237 _PTR(SObject) obj = myObject;
238 while ( obj && obj->ReferencedObject( refObj ) )
244 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
249 _PTR(GenericAttribute) attr;
250 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
252 _PTR(AttributeIOR) iorAttr = attr;
255 std::string str = iorAttr->Value();
256 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() );
274 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
277 return QString::null;
280 _PTR(GenericAttribute) attr;
282 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
284 _PTR(AttributeInteger) intAttr = attr;
286 val = QString::number( intAttr->Value() );
288 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
290 _PTR(AttributeReal) realAttr = attr;
292 val = QString::number( realAttr->Value() );
294 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
296 _PTR(AttributeTableOfInteger) tableAttr = attr;
297 std::string title = tableAttr->GetTitle();
298 val = QString( title.c_str() );
299 if ( !val.isEmpty() )
300 val += QString( " " );
301 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
303 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
305 _PTR(AttributeTableOfReal) tableAttr = attr;
306 std::string title = tableAttr->GetTitle();
307 val = QString( title.c_str() );
308 if ( !val.isEmpty() )
309 val += QString( " " );
310 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
312 else if ( obj->FindAttribute( attr, "AttributeComment") )
314 _PTR(AttributeComment) comm = attr;
315 std::string str = comm->Value();
316 val = QString( str.c_str() );
323 Class: SalomeApp_ModuleObject
327 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
328 : SalomeApp_DataObject( parent ),
329 CAM_RootObject( parent ),
330 CAM_DataObject( parent )
334 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
335 : SalomeApp_DataObject( sobj, parent ),
336 CAM_RootObject( 0, parent ),
337 CAM_DataObject( parent )
341 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
342 : SalomeApp_DataObject( sobj, parent ),
343 CAM_RootObject( dm, parent ),
344 CAM_DataObject( parent )
348 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()