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 <HYDROData_DummyObject3D.h>
26 #include <HYDROData_Object.h>
28 #include <TDF_Tool.hxx>
30 #include <SUIT_DataObject.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
36 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
37 Handle(HYDROData_Entity) theData,
38 const QString& theParentEntry )
39 : CAM_DataObject( theParent ),
40 LightApp_DataObject( theParent ),
42 myParentEntry( theParentEntry ),
47 QString HYDROGUI_DataObject::entry() const
49 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
51 anEntry.prepend( myParentEntry + "_" );
55 QString HYDROGUI_DataObject::refEntry() const
57 if( !myParentEntry.isEmpty() )
58 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
62 QString HYDROGUI_DataObject::name() const
64 if( !myData.IsNull() )
65 return myData->GetName();
69 QFont HYDROGUI_DataObject::font( const int theId ) const
71 QFont aFont = LightApp_DataObject::font( theId );
74 Handle(HYDROData_Entity) aDataObject = modelObject();
75 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
77 aFont.setItalic( true );
78 aFont.setBold( true );
84 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
94 aColor = Qt::red; // red
97 // text color for the highlighted item
98 aColor = Qt::white; // white
106 if ( !aColor.isValid() )
108 Handle(HYDROData_Entity) aDataObject = modelObject();
109 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
116 aColor = Qt::blue; // color for objects which need updating
118 case HighlightedText:
119 // text color for the highlighted item
120 aColor = Qt::white; // white
129 if ( !aColor.isValid() ) {
130 aColor = LightApp_DataObject::color( theRole, theId );
136 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
138 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
139 if ( theId == NameId )
142 Handle(HYDROData_Entity) aDataObject = modelObject();
143 if( aDataObject.IsNull() )
145 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
149 QString aNeedUpdate( aDataObject->IsMustBeUpdated() ? "M_" : "" );
151 int anObjectKind = (int)aDataObject->GetKind();
152 if ( anObjectKind == KIND_DUMMY_3D )
154 Handle(HYDROData_DummyObject3D) anObject3D =
155 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
157 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
158 if ( !aFatherObj.IsNull() )
159 anObjectKind = aFatherObj->GetKind();
162 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toAscii() );
165 return aResMgr->loadPixmap( "HYDRO", anIcon );
167 return LightApp_DataObject::icon( theId );
170 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
171 const bool theWithPrefix )
173 QString aEntryStr = QString::null;
174 if( !theObject.IsNull() )
176 TCollection_AsciiString aLabEntr;
177 TDF_Tool::Entry( theObject->Label(), aLabEntr );
178 aEntryStr = aLabEntr.ToCString();
180 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
185 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
187 myIsValid = theIsValid;
190 bool HYDROGUI_DataObject::isValid() const
195 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
196 const QString& theName,
197 const QString& theParentEntry )
198 : CAM_DataObject( theParent ),
199 LightApp_DataObject( theParent ),
201 myParentEntry( theParentEntry )
205 QString HYDROGUI_NamedObject::entry() const
207 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
208 if( !myParentEntry.isEmpty() )
209 anEntry.prepend( myParentEntry + "_" );
213 QString HYDROGUI_NamedObject::name() const
218 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
220 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
221 if ( theId == NameId )
223 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
225 return LightApp_DataObject::icon( theId );
228 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
229 const QString& theName,
230 const QString& theParentEntry )
231 : HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent )