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 <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>
39 Class: SalomeApp_DataObject
42 /*!Constructor. Initialize by \a parent*/
43 SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent )
44 : LightApp_DataObject( parent ),
45 CAM_DataObject( parent ),
51 /*!Constructor. Initialize by \a parent and SObject*/
52 SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
53 : LightApp_DataObject( parent ),
54 CAM_DataObject( parent ),
58 myEntry = myObject->GetID().c_str();
61 /*!Destructor. Do nothing.*/
62 SalomeApp_DataObject::~SalomeApp_DataObject()
69 QString SalomeApp_DataObject::entry() const
72 return myObject->GetID().c_str();
77 /*!Gets name of object.*/
78 QString SalomeApp_DataObject::name() const
80 //if ( myName.isEmpty() )
84 str = myObject->GetName().c_str();
88 _PTR(SObject) refObj = referencedObject();
90 str = refObj->GetName().c_str();
95 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
96 str = QString( "* " ) + str;
98 str = QString( "<Invalid Reference>" );
100 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
106 /*!Gets icon picture of object.*/
107 QPixmap SalomeApp_DataObject::icon() const
109 _PTR(GenericAttribute) anAttr;
110 if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
111 _PTR(AttributePixMap) aPixAttr ( anAttr );
112 if ( aPixAttr->HasPixMap() ){
113 QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() );
114 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
115 if ( aRoot && aRoot->study() ) {
116 SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr();
117 return mgr->loadPixmap( componentDataType(), pixmapName, false );
124 /*!Gets text value for one of entity:
125 *\li Value (id = SalomeApp_DataObject::CT_Value)
126 *\li Entry (id = SalomeApp_DataObject::CT_Entry)
127 *\li IOR (id = SalomeApp_DataObject::CT_IOR)
128 *\li Reference entry (id = SalomeApp_DataObject::CT_RefEntry)
130 QString SalomeApp_DataObject::text( const int id ) const
137 if ( componentObject() != this )
139 if ( componentObject() != (SUIT_DataObject*)this )
141 txt = value( referencedObject() );
144 txt = entry( object() );
147 txt = ior( referencedObject() );
151 txt = entry( referencedObject() );
157 /*!Get color value for one of entity:
160 *\li Higlighted text color
162 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
170 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
171 clr = QColor( 255, 0, 0 );
173 clr = QColor( 200, 200, 200 );
177 _PTR(GenericAttribute) anAttr;
178 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
180 _PTR(AttributeTextColor) aColAttr = anAttr;
181 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
188 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
189 clr = QColor( 255, 0, 0 );
191 clr = QColor( 200, 200, 200 );
194 case HighlightedText:
196 clr = QColor( 255, 255, 255 );
203 QString SalomeApp_DataObject::toolTip() const
205 //return object()->Name();
206 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
209 /*!Get component type.*/
210 QString SalomeApp_DataObject::componentDataType() const
212 // if ( myCompDataType.isEmpty() ) {
213 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
214 if ( compObj && compObj->object() )
216 _PTR(SComponent) aComp( compObj->object() );
218 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
219 that->myCompDataType = aComp->ComponentDataType().c_str();
223 return myCompDataType;
227 _PTR(SObject) SalomeApp_DataObject::object() const
232 /*!Checks: Is object reference.*/
233 bool SalomeApp_DataObject::isReference() const
238 _PTR(SObject) refObj;
239 isRef = myObject->ReferencedObject( refObj );
244 /*!Gets reference object.*/
245 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
247 _PTR(SObject) refObj;
248 _PTR(SObject) obj = myObject;
249 while ( obj && obj->ReferencedObject( refObj ) )
256 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
261 _PTR(GenericAttribute) attr;
262 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
264 _PTR(AttributeIOR) iorAttr = attr;
267 std::string str = iorAttr->Value();
268 txt = QString( str.c_str() );
276 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
281 std::string str = obj->GetID();
282 txt = QString( str.c_str() );
288 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
291 return QString::null;
294 _PTR(GenericAttribute) attr;
296 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
298 _PTR(AttributeInteger) intAttr = attr;
300 val = QString::number( intAttr->Value() );
302 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
304 _PTR(AttributeReal) realAttr = attr;
306 val = QString::number( realAttr->Value() );
308 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
310 _PTR(AttributeTableOfInteger) tableAttr = attr;
311 std::string title = tableAttr->GetTitle();
312 val = QString( title.c_str() );
313 if ( !val.isEmpty() )
314 val += QString( " " );
315 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
317 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
319 _PTR(AttributeTableOfReal) 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, "AttributeComment") )
328 _PTR(AttributeComment) comm = attr;
329 std::string str = comm->Value();
330 val = QString( str.c_str() );
337 Class: SalomeApp_ModuleObject
341 /*!Constructor.Initialize by \a parent.*/
342 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
343 : SalomeApp_DataObject( parent ),
344 CAM_RootObject( parent ),
345 CAM_DataObject( parent )
349 /*!Constructor.Initialize by \a parent and SObject.*/
350 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
351 : SalomeApp_DataObject( sobj, parent ),
352 CAM_RootObject( 0, parent ),
353 CAM_DataObject( parent )
357 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
358 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
359 : SalomeApp_DataObject( sobj, parent ),
360 CAM_RootObject( dm, parent ),
361 CAM_DataObject( parent )
365 /*!Destructor. Do nothing.*/
366 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()
370 /*!Returns module name */
371 QString SalomeApp_ModuleObject::name() const
373 return SalomeApp_DataObject::name();
377 Class: SalomeApp_SavePointObject
381 /*!Constructor.Initialize by \a parent.*/
382 SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* _parent, const int id, SalomeApp_Study* study )
383 : LightApp_DataObject( _parent ), CAM_DataObject( _parent ), // IMPORTANT TO CALL ALL VIRTUAL CONSTRUCTORS!
389 /*!Destructor. Do nothing.*/
390 SalomeApp_SavePointObject::~SalomeApp_SavePointObject()
394 /*!Returns save points ID */
395 int SalomeApp_SavePointObject::getId() const
400 /*!Returns "invalid" entry, which does not correspond to any object in data structure
401 but indicates that it is a save point object */
402 QString SalomeApp_SavePointObject::entry() const
404 return QObject::tr( "SAVE_POINT_DEF_NAME" ) + QString::number( myId );
407 /*!Returns displayed name of object */
408 QString SalomeApp_SavePointObject::name() const
410 return myStudy->getNameOfSavePoint( myId );
413 QPixmap SalomeApp_SavePointObject::icon() const
418 QString SalomeApp_SavePointObject::toolTip() const
420 return QObject::tr( "SAVE_POINT_OBJECT_TOOLTIP" ).arg( name() );