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>
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( referencedObject() );
140 txt = entry( object() );
143 txt = ior( referencedObject() );
147 txt = entry( referencedObject() );
153 /*!Get color value for one of entity:
156 *\li Higlighted text color
158 QColor SalomeApp_DataObject::color( const ColorRole cr ) const
166 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
167 clr = QColor( 255, 0, 0 );
169 clr = QColor( 200, 200, 200 );
173 _PTR(GenericAttribute) anAttr;
174 if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
176 _PTR(AttributeTextColor) aColAttr = anAttr;
177 clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
184 if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
185 clr = QColor( 255, 0, 0 );
187 clr = QColor( 200, 200, 200 );
190 case HighlightedText:
192 clr = QColor( 255, 255, 255 );
199 QString SalomeApp_DataObject::toolTip() const
201 //return object()->Name();
202 return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
205 /*!Get component type.*/
206 QString SalomeApp_DataObject::componentDataType() const
208 // if ( myCompDataType.isEmpty() ) {
209 const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
210 if ( compObj && compObj->object() )
212 _PTR(SComponent) aComp( compObj->object() );
214 SalomeApp_DataObject* that = (SalomeApp_DataObject*)this;
215 that->myCompDataType = aComp->ComponentDataType().c_str();
219 return myCompDataType;
223 _PTR(SObject) SalomeApp_DataObject::object() const
228 /*!Checks: Is object reference.*/
229 bool SalomeApp_DataObject::isReference() const
234 _PTR(SObject) refObj;
235 isRef = myObject->ReferencedObject( refObj );
240 /*!Gets reference object.*/
241 _PTR(SObject) SalomeApp_DataObject::referencedObject() const
243 _PTR(SObject) refObj;
244 _PTR(SObject) obj = myObject;
245 while ( obj && obj->ReferencedObject( refObj ) )
252 QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
257 _PTR(GenericAttribute) attr;
258 if ( obj->FindAttribute( attr, "AttributeIOR" ) )
260 _PTR(AttributeIOR) iorAttr = attr;
263 std::string str = iorAttr->Value();
264 txt = QString( str.c_str() );
272 QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
277 std::string str = obj->GetID();
278 txt = QString( str.c_str() );
284 QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
287 return QString::null;
290 _PTR(GenericAttribute) attr;
292 if ( obj->FindAttribute( attr, "AttributeInteger" ) )
294 _PTR(AttributeInteger) intAttr = attr;
296 val = QString::number( intAttr->Value() );
298 else if ( obj->FindAttribute( attr, "AttributeReal" ) )
300 _PTR(AttributeReal) realAttr = attr;
302 val = QString::number( realAttr->Value() );
304 else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
306 _PTR(AttributeTableOfInteger) tableAttr = attr;
307 std::string title = tableAttr->GetTitle();
308 val = QString( title.c_str() );
309 if ( !val.isEmpty() )
310 val += QString( " " );
311 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
313 else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
315 _PTR(AttributeTableOfReal) tableAttr = attr;
316 std::string title = tableAttr->GetTitle();
317 val = QString( title.c_str() );
318 if ( !val.isEmpty() )
319 val += QString( " " );
320 val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
322 else if ( obj->FindAttribute( attr, "AttributeComment") )
324 _PTR(AttributeComment) comm = attr;
325 std::string str = comm->Value();
326 val = QString( str.c_str() );
336 /*!Constructor.Initialize by \a parent.*/
337 SalomeApp_ModuleObject::SalomeApp_ModuleObject( SUIT_DataObject* parent )
338 : SalomeApp_DataObject( parent ),
339 CAM_RootObject( parent ),
340 CAM_DataObject( parent )
344 /*!Constructor.Initialize by \a parent and SObject.*/
345 SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent )
346 : SalomeApp_DataObject( sobj, parent ),
347 CAM_RootObject( 0, parent ),
348 CAM_DataObject( parent )
352 /*!Constructor.Initialize by \a parent and CAM_DataModel.*/
353 SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm, const _PTR(SObject)& sobj, SUIT_DataObject* parent )
354 : SalomeApp_DataObject( sobj, parent ),
355 CAM_RootObject( dm, parent ),
356 CAM_DataObject( parent )
360 /*!Destructor. Do nothing.*/
361 SalomeApp_ModuleObject::~SalomeApp_ModuleObject()
365 /*!Returns module name */
366 QString SalomeApp_ModuleObject::name() const
368 return SalomeApp_DataObject::name();
374 /*!Constructor.Initialize by \a parent.*/
375 SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* _parent, const int id, SalomeApp_Study* study )
376 : LightApp_DataObject( _parent ), CAM_DataObject( _parent ), // IMPORTANT TO CALL ALL VIRTUAL CONSTRUCTORS!
382 /*!Destructor. Do nothing.*/
383 SalomeApp_SavePointObject::~SalomeApp_SavePointObject()
387 /*!Returns save points ID */
388 int SalomeApp_SavePointObject::getId() const
393 /*!Returns "invalid" entry, which does not correspond to any object in data structure
394 but indicates that it is a save point object */
395 QString SalomeApp_SavePointObject::entry() const
397 return QObject::tr( "SAVE_POINT_DEF_NAME" ) + QString::number( myId );
400 /*!Returns displayed name of object */
401 QString SalomeApp_SavePointObject::name() const
403 return myStudy->getNameOfSavePoint( myId );
406 /*!Gets icon picture of object.*/
407 QPixmap SalomeApp_SavePointObject::icon() const
413 QString SalomeApp_SavePointObject::toolTip() const
415 return QObject::tr( "SAVE_POINT_OBJECT_TOOLTIP" ).arg( name() );