1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_DataObject.h"
21 #include <HYDROData_DummyObject3D.h>
22 #include <HYDROData_ImmersibleZone.h>
23 #include <HYDROData_Object.h>
24 #include <HYDROData_ArtificialObject.h>
25 #include <HYDROData_NaturalObject.h>
27 #include <TDF_Tool.hxx>
29 #include <SUIT_DataObject.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Operation.h>
33 #include <CAM_Module.h>
34 #include <CAM_Application.h>
35 #include <SUIT_Study.h>
40 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
41 Handle(HYDROData_Entity) theData,
42 const QString& theParentEntry,
43 const bool theIsInOperation )
44 : CAM_DataObject( theParent ),
46 LightApp_DataObject( theParent ),
49 myParentEntry( theParentEntry ),
51 myIsInOperation( theIsInOperation )
55 QString HYDROGUI_DataObject::entry() const
57 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
58 if( !refEntry().isEmpty() )
59 anEntry.prepend( myParentEntry + "_" );
63 QString HYDROGUI_DataObject::refEntry() const
65 if( !myParentEntry.isEmpty() )
66 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
70 QString HYDROGUI_DataObject::name() const
72 if( !myData.IsNull() )
73 return myData->GetName();
77 QFont HYDROGUI_DataObject::font( const int theId ) const
79 QFont aFont = PARENT::font( theId );
82 Handle(HYDROData_Entity) aDataObject = modelObject();
83 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
85 aFont.setItalic( true );
86 aFont.setBold( true );
92 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
102 aColor = Qt::red; // red
104 case HighlightedText:
105 // text color for the highlighted item
106 aColor = Qt::white; // white
114 if ( !aColor.isValid() )
116 Handle(HYDROData_Entity) aDataObject = modelObject();
117 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
124 aColor = Qt::blue; // color for objects which need updating
126 case HighlightedText:
127 // text color for the highlighted item
128 aColor = Qt::white; // white
137 if ( !aColor.isValid() ) {
138 aColor = PARENT::color( theRole, theId );
144 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
146 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
147 if ( theId == NameId )
150 Handle(HYDROData_Entity) aDataObject = modelObject();
151 Handle(HYDROData_Object) anObject;
152 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aDataObject);
153 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aDataObject);
155 if (!anAObject.IsNull())
156 anObject = anAObject;
157 if (!aNObject.IsNull())
160 if( aDataObject.IsNull() )
162 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
166 QString aNeedUpdate( aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) ? "M_" : "" );
168 int anObjectKind = (int)aDataObject->GetKind();
169 bool IsUnsImmZone = false;
170 if ( anObjectKind == KIND_DUMMY_3D )
172 Handle(HYDROData_DummyObject3D) anObject3D =
173 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
175 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
176 if ( !aFatherObj.IsNull() )
177 anObjectKind = aFatherObj->GetKind();
178 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
180 else if ( !anObject.IsNull() )
182 bool IsSubm = anObject->IsSubmersible();
183 QString anIcon1 = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
186 anIcon2 = QObject::tr( QString("HYDRO_SUBMERSIBLE16_ICO").toLatin1());
188 anIcon2 = QObject::tr( QString("HYDRO_UNSUBMERSIBLE16_ICO").toLatin1());
190 QPixmap qpm1 = aResMgr->loadPixmap( "HYDRO", anIcon1 );
191 QPixmap qpm2 = aResMgr->loadPixmap( "HYDRO", anIcon2 );
193 qpmD.fill(QColor(0,0,0));
195 painter.begin(&qpmD);
196 painter.drawPixmap(0, 0, qpm1);
197 painter.drawPixmap(16, 0, qpm2);
202 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
205 return aResMgr->loadPixmap( "HYDRO", anIcon );
207 return PARENT::icon( theId );
210 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
211 const bool theWithPrefix )
213 QString aEntryStr = QString::null;
214 if( !theObject.IsNull() )
216 TCollection_AsciiString aLabEntr;
217 TDF_Tool::Entry( theObject->Label(), aLabEntr );
218 aEntryStr = aLabEntr.ToCString();
220 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
225 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
227 myIsValid = theIsValid;
230 bool HYDROGUI_DataObject::isValid() const
235 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
238 if ( theColumnId == NameId && module())
240 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
241 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
243 aRes = isInOperation();
252 aRes = PARENT::renameAllowed( theColumnId );
257 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
259 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
263 myData = aDataObj->myData;
264 myParentEntry = aDataObj->myParentEntry;
265 myIsValid = aDataObj->myIsValid;
266 myIsInOperation = aDataObj->myIsInOperation;
267 myIcon = aDataObj->myIcon;
271 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
272 const QString& theName,
273 const QString& theParentEntry,
274 const bool theIsInOperation )
275 : CAM_DataObject( theParent ),
277 LightApp_DataObject( theParent ),
280 myParentEntry( theParentEntry ),
281 myIsInOperation( theIsInOperation )
285 QString HYDROGUI_NamedObject::entry() const
287 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
288 if( !myParentEntry.isEmpty() )
289 anEntry.prepend( myParentEntry + "_" );
293 QString HYDROGUI_NamedObject::name() const
295 return myName.toUpper();
298 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
300 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
301 if ( theId == NameId )
303 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
305 return PARENT::icon( theId );
308 QFont HYDROGUI_NamedObject::font( const int theId ) const
310 QFont aFont = PARENT::font( theId );
311 if( theId == NameId )
313 if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
315 aFont.setBold( true );
321 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
323 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
327 myName = aNamedObj->myName;
328 myParentEntry = aNamedObj->myParentEntry;
329 myIcon = aNamedObj->myIcon;
330 myIsInOperation = aNamedObj->myIsInOperation;
339 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
340 const QString& theName,
341 const QString& theParentEntry,
342 const bool theIsInOperation )
343 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ),
344 CAM_DataObject( theParent )