1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_DataObject.h"
25 #include <SUIT_DataObject.h>
26 #include <TDF_Tool.hxx>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_Session.h>
31 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
32 Handle(HYDROData_Entity) theData,
33 const QString& theParentEntry )
34 : CAM_DataObject( theParent ),
35 LightApp_DataObject( theParent ),
37 myParentEntry( theParentEntry ),
42 QString HYDROGUI_DataObject::entry() const
44 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
46 anEntry.prepend( myParentEntry + "_" );
50 QString HYDROGUI_DataObject::refEntry() const
52 if( !myParentEntry.isEmpty() )
53 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
57 QString HYDROGUI_DataObject::name() const
59 if( !myData.IsNull() )
60 return myData->GetName();
64 QFont HYDROGUI_DataObject::font( const int theId ) const
66 QFont aFont = LightApp_DataObject::font( theId );
69 Handle(HYDROData_Entity) aDataObject = modelObject();
70 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
71 aFont.setItalic( true );
76 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
86 aColor = QColor( 255, 0, 0 ); // red
89 // text color for the highlighted item
90 aColor = QColor( 255, 255, 255 ); // white
98 if ( !aColor.isValid() ) {
99 aColor = LightApp_DataObject::color( theRole, theId );
105 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
107 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
108 if ( theId == NameId )
111 Handle(HYDROData_Entity) aDataObject = modelObject();
112 if( aDataObject.IsNull() )
114 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
118 anIcon = QObject::tr( QString("HYDRO_TYPE%1_ICO").arg( (int)aDataObject->GetKind() ).toAscii() );
121 return aResMgr->loadPixmap( "HYDRO", anIcon );
123 return LightApp_DataObject::icon( theId );
126 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
127 const bool theWithPrefix )
129 QString aEntryStr = QString::null;
130 if( !theObject.IsNull() )
132 TCollection_AsciiString aLabEntr;
133 TDF_Tool::Entry( theObject->Label(), aLabEntr );
134 aEntryStr = aLabEntr.ToCString();
136 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
141 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
143 myIsValid = theIsValid;
146 bool HYDROGUI_DataObject::isValid() const
151 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
152 const QString& theName,
153 const QString& theParentEntry )
154 : CAM_DataObject( theParent ),
155 LightApp_DataObject( theParent ),
157 myParentEntry( theParentEntry )
161 QString HYDROGUI_NamedObject::entry() const
163 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
164 if( !myParentEntry.isEmpty() )
165 anEntry.prepend( myParentEntry + "_" );
169 QString HYDROGUI_NamedObject::name() const
174 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
176 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
177 if ( theId == NameId )
179 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
181 return LightApp_DataObject::icon( theId );
184 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
185 const QString& theName,
186 const QString& theParentEntry )
187 : HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )