1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "SalomeApp_DataObject.h"
21 #include "SalomeApp_Study.h"
22 #include "LightApp_RootObject.h"
24 #include <SUIT_Application.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_DataObjectKey.h>
30 #include <SALOMEDSClient_AttributeReal.hxx>
31 #include <SALOMEDSClient_AttributeInteger.hxx>
32 #include <SALOMEDSClient_AttributeComment.hxx>
33 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
34 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
37 Class: SalomeApp_DataObject
40 /*!Constructor. Initialize by \a parent*/
41 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
42 : LightApp_DataObject( parent ),
43 CAM_DataObject( parent ),
49 /*!Constructor. Initialize by \a parent and SObject*/
50 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
51 : LightApp_DataObject( parent ),
52 CAM_DataObject( parent ),
56 myEntry = myObject->GetID().c_str();
59 /*!Destructor. Do nothing.*/
60 SalomeApp_DataObject::~SalomeApp_DataObject()
67 QString SalomeApp_DataObject::entry() const
70 return myObject->GetID().c_str();
75 /*!Gets name of object.*/
76 QString SalomeApp_DataObject::name() const
78 //if ( myName.isEmpty() )
82 str = myObject->GetName().c_str();
86 _PTR(SObject) refObj = referencedObject();
88 str = refObj->GetName().c_str();
93 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
94 str = QString( "* " ) + str;
96 str = QString( "<Invalid Reference>" );
98 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
104 /*!Gets icon picture of object.*/
105 QPixmap SalomeApp_DataObject::icon() const
107 _PTR(GenericAttribute) anAttr;
108 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
109 _PTR(AttributePixMap) aPixAttr ( anAttr );
110 if ( aPixAttr->HasPixMap() ){
111 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
112 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
113 if ( aRoot && aRoot->study() ) {
114 SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr();
115 return mgr->loadPixmap( componentDataType(), pixmapName, false );
122 /*!Gets text value for one of entity:
123 *\li Value (id = SalomeApp_DataObject::CT_Value)
124 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
125 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
126 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
128 QString SalomeApp_DataObject::text( const int id ) const
135 if ( componentObject() != this )
137 if ( componentObject() != (SUIT_DataObject*)this )
139 txt = value( referencedObject() );
142 txt = entry( object() );
145 txt = ior( referencedObject() );
149 txt = entry( referencedObject() );
155 /*!Get color value for one of entity:
158 *\li Higlighted text color
160 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
168 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
169 clr = QColor( 255, 0, 0 );
171 clr = QColor( 200, 200, 200 );
175 _PTR(GenericAttribute) anAttr;
176 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
178 _PTR(AttributeTextColor) aColAttr = anAttr;
179 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
186 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
187 clr = QColor( 255, 0, 0 );
189 clr = QColor( 200, 200, 200 );
192 case HighlightedText:
194 clr = QColor( 255, 255, 255 );
201 QString SalomeApp_DataObject::toolTip() const
203 //return object()->Name();
204 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
207 /*!Get component type.*/
208 QString SalomeApp_DataObject::componentDataType() const
210 // if ( myCompDataType.isEmpty() ) {
211 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
212 if ( compObj && compObj->object() )
214 _PTR(SComponent) aComp( compObj->object() );
216 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
217 that->myCompDataType = aComp->ComponentDataType().c_str();
221 return myCompDataType;
225 _PTR(SObject) SalomeApp_DataObject::object() const
230 /*!Checks: Is object reference.*/
231 bool SalomeApp_DataObject::isReference() const
236 _PTR(SObject) refObj;
237 isRef = myObject->ReferencedObject( refObj );
242 /*!Gets reference object.*/
243 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
245 _PTR(SObject) refObj;
246 _PTR(SObject) obj = myObject;
247 while ( obj && obj->ReferencedObject( refObj ) )
254 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
259 _PTR(GenericAttribute) attr;
260 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
262 _PTR(AttributeIOR) iorAttr = attr;
265 std::string str = iorAttr->Value();
266 txt = QString( str.c_str() );
274 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
279 std::string str = obj->GetID();
280 txt = QString( str.c_str() );
286 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
289 return QString::null;
292 _PTR(GenericAttribute) attr;
294 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
296 _PTR(AttributeInteger) intAttr = attr;
298 val = QString::number( intAttr->Value() );
300 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
302 _PTR(AttributeReal) realAttr = attr;
304 val = QString::number( realAttr->Value() );
306 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
308 _PTR(AttributeTableOfInteger) tableAttr = attr;
309 std::string title = tableAttr->GetTitle();
310 val = QString( title.c_str() );
311 if ( !val.isEmpty() )
312 val += QString( " " );
313 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
315 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
317 _PTR(AttributeTableOfReal) tableAttr = attr;
318 std::string title = tableAttr->GetTitle();
319 val = QString( title.c_str() );
320 if ( !val.isEmpty() )
321 val += QString( " " );
322 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
324 else if ( obj->FindAttribute( attr, "AttributeComment") )
326 _PTR(AttributeComment) comm = attr;
327 std::string str = comm->Value();
328 val = QString( str.c_str() );
335 Class: SalomeApp_ModuleObject
339 /*!Constructor.Initialize by \a parent.*/
340 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
341 : SalomeApp_DataObject( parent ),
342 CAM_RootObject( parent ),
343 CAM_DataObject( parent )
347 /*!Constructor.Initialize by \a parent and SObject.*/
348 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
349 : SalomeApp_DataObject( sobj, parent ),
350 CAM_RootObject( 0, parent ),
351 CAM_DataObject( parent )
355 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
356 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
357 : SalomeApp_DataObject( sobj, parent ),
358 CAM_RootObject( dm, parent ),
359 CAM_DataObject( parent )
363 /*!Destructor. Do nothing.*/
364 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()
368 /*!Returns module name */
369 QString SalomeApp_ModuleObject::name() const
371 return SalomeApp_DataObject::name();