1 #include "SalomeApp_DataObject.h"
3 #include "SalomeApp_Study.h"
4 #include "LightApp_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
22 /*!Constructor. Initialize by \a parent*/
23 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
24 : LightApp_DataObject( parent ),
25 CAM_DataObject( parent )
29 /*!Constructor. Initialize by \a parent and SObject*/
30 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
31 : LightApp_DataObject( parent ),
32 CAM_DataObject( parent )
37 /*!Destructor. Do nothing.*/
38 SalomeApp_DataObject::~SalomeApp_DataObject()
45 QString SalomeApp_DataObject::entry() const
48 return myObject->GetID().c_str();
52 /*!Gets name of object.*/
53 QString SalomeApp_DataObject::name() const
58 str = myObject->GetName().c_str();
62 _PTR(SObject) refObj = referencedObject();
64 str = refObj->GetName().c_str();
69 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
70 str = QString( "* " ) + str;
72 str = QString( "<Invalid Reference>" );
78 /*!Gets icon picture of object.*/
79 QPixmap SalomeApp_DataObject::icon() const
81 _PTR(GenericAttribute) anAttr;
82 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
83 _PTR(AttributePixMap) aPixAttr ( anAttr );
84 if ( aPixAttr->HasPixMap() ){
85 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
86 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
87 if ( aRoot && aRoot->study() ) {
88 QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false );
96 /*!Gets text value for one of entity:
97 *\li Value (id = SalomeApp_DataObject::CT_Value)
98 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
99 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
100 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
102 QString SalomeApp_DataObject::text( const int id ) const
109 if ( componentObject() != this )
111 if ( componentObject() != (SUIT_DataObject*)this )
113 txt = value( referencedObject() );
116 txt = entry( referencedObject() );
119 txt = ior( referencedObject() );
123 txt = entry( object() );
129 /*!Get color value for one of entity:
132 *\li Higlighted text color
134 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
142 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
143 clr = QColor( 255, 0, 0 );
145 clr = QColor( 200, 200, 200 );
149 _PTR(GenericAttribute) anAttr;
150 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
152 _PTR(AttributeTextColor) aColAttr = anAttr;
153 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
160 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
161 clr = QColor( 255, 0, 0 );
163 clr = QColor( 200, 200, 200 );
166 case HighlightedText:
168 clr = QColor( 255, 255, 255 );
175 QString SalomeApp_DataObject::toolTip() const
177 //return object()->Name();
178 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
181 /*!Get component type.*/
182 QString SalomeApp_DataObject::componentDataType() const
184 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
185 if ( compObj && compObj->object() )
187 _PTR(SComponent) aComp( compObj->object() );
189 return aComp->ComponentDataType().c_str();
196 _PTR(SObject) SalomeApp_DataObject::object() const
201 /*!Checks: Is object reference.*/
202 bool SalomeApp_DataObject::isReference() const
207 _PTR(SObject) refObj;
208 isRef = myObject->ReferencedObject( refObj );
213 /*!Gets reference object.*/
214 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
216 _PTR(SObject) refObj;
217 _PTR(SObject) obj = myObject;
218 while ( obj && obj->ReferencedObject( refObj ) )
225 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
230 _PTR(GenericAttribute) attr;
231 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
233 _PTR(AttributeIOR) iorAttr = attr;
236 std::string str = iorAttr->Value();
237 txt = QString( str.c_str() );
245 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
250 std::string str = obj->GetID();
251 txt = QString( str.c_str() );
257 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
260 return QString::null;
263 _PTR(GenericAttribute) attr;
265 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
267 _PTR(AttributeInteger) intAttr = attr;
269 val = QString::number( intAttr->Value() );
271 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
273 _PTR(AttributeReal) realAttr = attr;
275 val = QString::number( realAttr->Value() );
277 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
279 _PTR(AttributeTableOfInteger) tableAttr = attr;
280 std::string title = tableAttr->GetTitle();
281 val = QString( title.c_str() );
282 if ( !val.isEmpty() )
283 val += QString( " " );
284 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
286 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
288 _PTR(AttributeTableOfReal) tableAttr = attr;
289 std::string title = tableAttr->GetTitle();
290 val = QString( title.c_str() );
291 if ( !val.isEmpty() )
292 val += QString( " " );
293 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
295 else if ( obj->FindAttribute( attr, "AttributeComment") )
297 _PTR(AttributeComment) comm = attr;
298 std::string str = comm->Value();
299 val = QString( str.c_str() );
306 Class: SalomeApp_ModuleObject
310 /*!Constructor.Initialize by \a parent.*/
311 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
312 : SalomeApp_DataObject( parent ),
313 CAM_RootObject( parent ),
314 CAM_DataObject( parent )
318 /*!Constructor.Initialize by \a parent and SObject.*/
319 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
320 : SalomeApp_DataObject( sobj, parent ),
321 CAM_RootObject( 0, parent ),
322 CAM_DataObject( parent )
326 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
327 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
328 : SalomeApp_DataObject( sobj, parent ),
329 CAM_RootObject( dm, parent ),
330 CAM_DataObject( parent )
334 /*!Destructor. Do nothing.*/
335 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()