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/ or email : webmaster.salome@opencascade.com
19 #include "SalomeApp_DataObject.h"
21 #include "SalomeApp_Study.h"
22 #include "LightApp_RootObject.h"
24 #include <CAM_DataObject.h>
26 #include <SUIT_Application.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_DataObjectKey.h>
32 #include <SALOMEDSClient_AttributeReal.hxx>
33 #include <SALOMEDSClient_AttributeInteger.hxx>
34 #include <SALOMEDSClient_AttributeComment.hxx>
35 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
36 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
38 /*!Constructor. Initialize by \a parent*/
39 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
40 : LightApp_DataObject( parent ),
41 CAM_DataObject( parent ),
47 /*!Constructor. Initialize by \a parent and SObject*/
48 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
49 : LightApp_DataObject( parent ),
50 CAM_DataObject( parent ),
54 myEntry = myObject->GetID().c_str();
57 /*!Destructor. Do nothing.*/
58 SalomeApp_DataObject::~SalomeApp_DataObject()
65 QString SalomeApp_DataObject::entry() const
68 return myObject->GetID().c_str();
73 /*!Gets name of object.*/
74 QString SalomeApp_DataObject::name() const
76 //if ( myName.isEmpty() )
80 str = myObject->GetName().c_str();
84 _PTR(SObject) refObj = referencedObject();
86 str = refObj->GetName().c_str();
91 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
92 str = QString( "* " ) + str;
94 str = QString( "<Invalid Reference>" );
96 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
102 /*!Gets icon picture of object.*/
103 QPixmap SalomeApp_DataObject::icon() const
105 _PTR(GenericAttribute) anAttr;
106 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
107 _PTR(AttributePixMap) aPixAttr ( anAttr );
108 if ( aPixAttr->HasPixMap() ){
109 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
110 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
111 if ( aRoot && aRoot->study() ) {
112 SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr();
113 return mgr->loadPixmap( componentDataType(), pixmapName, false );
120 /*!Gets text value for one of entity:
121 *\li Value (id = SalomeApp_DataObject::CT_Value)
122 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
123 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
124 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
126 QString SalomeApp_DataObject::text( const int id ) const
133 if ( componentObject() != this )
135 if ( componentObject() != (SUIT_DataObject*)this )
137 txt = value( object() );
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 );
193 _PTR(GenericAttribute) anAttr;
194 if( myObject->FindAttribute ( anAttr, "AttributeTextHighlightColor") )
196 _PTR(AttributeTextHighlightColor) aHighColAttr = anAttr;
197 clr = QColor( (int)(aHighColAttr->TextHighlightColor().R),
198 (int)(aHighColAttr->TextHighlightColor().G),
199 (int)(aHighColAttr->TextHighlightColor().B));
203 case HighlightedText:
205 clr = QColor( 255, 255, 255 );
212 QString SalomeApp_DataObject::toolTip() const
214 //return object()->Name();
215 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
218 /*!Get component type.*/
219 QString SalomeApp_DataObject::componentDataType() const
221 // if ( myCompDataType.isEmpty() ) {
222 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
223 if ( compObj && compObj->object() )
225 _PTR(SComponent) aComp( compObj->object() );
227 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
228 that->myCompDataType = aComp->ComponentDataType().c_str();
232 return myCompDataType;
236 _PTR(SObject) SalomeApp_DataObject::object() const
241 /*!Checks: Is object reference.*/
242 bool SalomeApp_DataObject::isReference() const
247 _PTR(SObject) refObj;
248 isRef = myObject->ReferencedObject( refObj );
253 /*!Gets reference object.*/
254 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
256 _PTR(SObject) refObj;
257 _PTR(SObject) obj = myObject;
258 while ( obj && obj->ReferencedObject( refObj ) )
265 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
270 _PTR(GenericAttribute) attr;
271 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
273 _PTR(AttributeIOR) iorAttr = attr;
276 std::string str = iorAttr->Value();
277 txt = QString( str.c_str() );
285 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
290 std::string str = obj->GetID();
291 txt = QString( str.c_str() );
297 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
300 return QString::null;
303 _PTR(GenericAttribute) attr;
305 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
307 _PTR(AttributeInteger) intAttr = attr;
309 val = QString::number( intAttr->Value() );
311 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
313 _PTR(AttributeReal) realAttr = attr;
315 val = QString::number( realAttr->Value() );
317 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
319 _PTR(AttributeTableOfInteger) tableAttr = attr;
320 std::string title = tableAttr->GetTitle();
321 val = QString( title.c_str() );
322 if ( !val.isEmpty() )
323 val += QString( " " );
324 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
326 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
328 _PTR(AttributeTableOfReal) tableAttr = attr;
329 std::string title = tableAttr->GetTitle();
330 val = QString( title.c_str() );
331 if ( !val.isEmpty() )
332 val += QString( " " );
333 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
335 else if ( obj->FindAttribute( attr, "AttributeComment") )
337 _PTR(AttributeComment) comm = attr;
338 std::string str = comm->Value();
339 val = QString( str.c_str() );
349 /*!Constructor.Initialize by \a parent.*/
350 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
351 : SalomeApp_DataObject( parent ),
352 CAM_RootObject( parent ),
353 CAM_DataObject( parent )
357 /*!Constructor.Initialize by \a parent and SObject.*/
358 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
359 : SalomeApp_DataObject( sobj, parent ),
360 CAM_RootObject( 0, parent ),
361 CAM_DataObject( parent )
365 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
366 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
367 : SalomeApp_DataObject( sobj, parent ),
368 CAM_RootObject( dm, parent ),
369 CAM_DataObject( parent )
373 /*!Destructor. Do nothing.*/
374 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()
378 /*!Returns module name */
379 QString SalomeApp_ModuleObject::name() const
381 return SalomeApp_DataObject::name();
387 /*!Constructor.Initialize by \a parent.*/
388 SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* _parent, const int id, SalomeApp_Study* study )
389 : LightApp_DataObject( _parent ), CAM_DataObject( _parent ), // IMPORTANT TO CALL ALL VIRTUAL CONSTRUCTORS!
395 /*!Destructor. Do nothing.*/
396 SalomeApp_SavePointObject::~SalomeApp_SavePointObject()
400 /*!Returns save points ID */
401 int SalomeApp_SavePointObject::getId() const
406 /*!Returns "invalid" entry, which does not correspond to any object in data structure
407 but indicates that it is a save point object */
408 QString SalomeApp_SavePointObject::entry() const
410 return QObject::tr( "SAVE_POINT_DEF_NAME" ) + QString::number( myId );
413 /*!Returns displayed name of object */
414 QString SalomeApp_SavePointObject::name() const
416 return myStudy->getNameOfSavePoint( myId );
419 /*!Gets icon picture of object.*/
420 QPixmap SalomeApp_SavePointObject::icon() const
426 QString SalomeApp_SavePointObject::toolTip() const
428 return QObject::tr( "SAVE_POINT_OBJECT_TOOLTIP" ).arg( name() );