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() )
72 aFont.setItalic( true );
73 aFont.setBold( true );
79 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
89 aColor = Qt::red; // red
92 // text color for the highlighted item
93 aColor = Qt::white; // white
101 if ( !aColor.isValid() )
103 Handle(HYDROData_Entity) aDataObject = modelObject();
104 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
111 aColor = Qt::blue; // color for objects which need updating
113 case HighlightedText:
114 // text color for the highlighted item
115 aColor = Qt::white; // white
124 if ( !aColor.isValid() ) {
125 aColor = LightApp_DataObject::color( theRole, theId );
131 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
133 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
134 if ( theId == NameId )
137 Handle(HYDROData_Entity) aDataObject = modelObject();
138 if( aDataObject.IsNull() )
140 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
144 QString aNeedUpdate = "";
145 if ( aDataObject->IsMustBeUpdated() )
149 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( (int)aDataObject->GetKind() ).toAscii() );
152 return aResMgr->loadPixmap( "HYDRO", anIcon );
154 return LightApp_DataObject::icon( theId );
157 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
158 const bool theWithPrefix )
160 QString aEntryStr = QString::null;
161 if( !theObject.IsNull() )
163 TCollection_AsciiString aLabEntr;
164 TDF_Tool::Entry( theObject->Label(), aLabEntr );
165 aEntryStr = aLabEntr.ToCString();
167 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
172 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
174 myIsValid = theIsValid;
177 bool HYDROGUI_DataObject::isValid() const
182 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
183 const QString& theName,
184 const QString& theParentEntry )
185 : CAM_DataObject( theParent ),
186 LightApp_DataObject( theParent ),
188 myParentEntry( theParentEntry )
192 QString HYDROGUI_NamedObject::entry() const
194 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
195 if( !myParentEntry.isEmpty() )
196 anEntry.prepend( myParentEntry + "_" );
200 QString HYDROGUI_NamedObject::name() const
205 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
207 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
208 if ( theId == NameId )
210 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
212 return LightApp_DataObject::icon( theId );
215 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
216 const QString& theName,
217 const QString& theParentEntry )
218 : HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )