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>
26 #include <HYDROData_BCPolygon.h>
28 #include <TDF_Tool.hxx>
30 #include <SUIT_DataObject.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_Operation.h>
34 #include <CAM_Module.h>
35 #include <CAM_Application.h>
36 #include <SUIT_Study.h>
41 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
42 Handle(HYDROData_Entity) theData,
43 const QString& theParentEntry,
44 const bool theIsInOperation )
45 : CAM_DataObject( theParent ),
47 LightApp_DataObject( theParent ),
50 myParentEntry( theParentEntry ),
52 myIsInOperation( theIsInOperation )
56 QString HYDROGUI_DataObject::entry() const
58 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
59 if( !refEntry().isEmpty() )
60 anEntry.prepend( myParentEntry + "_" );
64 QString HYDROGUI_DataObject::refEntry() const
66 if( !myParentEntry.isEmpty() )
67 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
71 QString HYDROGUI_DataObject::name() const
73 if( !myData.IsNull() )
74 return myData->GetName();
78 QFont HYDROGUI_DataObject::font( const int theId ) const
80 QFont aFont = PARENT::font( theId );
83 Handle(HYDROData_Entity) aDataObject = modelObject();
84 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
86 aFont.setItalic( true );
87 aFont.setBold( true );
93 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
103 aColor = Qt::red; // red
105 case HighlightedText:
106 // text color for the highlighted item
107 aColor = Qt::white; // white
115 if ( !aColor.isValid() )
117 Handle(HYDROData_Entity) aDataObject = modelObject();
118 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
125 aColor = Qt::blue; // color for objects which need updating
127 case HighlightedText:
128 // text color for the highlighted item
129 aColor = Qt::white; // white
138 if ( !aColor.isValid() ) {
139 aColor = PARENT::color( theRole, theId );
145 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
147 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
148 if ( theId == NameId )
151 Handle(HYDROData_Entity) aDataObject = modelObject();
152 Handle(HYDROData_Object) anObject;
153 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aDataObject);
154 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aDataObject);
156 if (!anAObject.IsNull())
157 anObject = anAObject;
158 if (!aNObject.IsNull())
161 if( aDataObject.IsNull() )
163 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
167 QString aNeedUpdate( aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) ? "M_" : "" );
169 int anObjectKind = (int)aDataObject->GetKind();
170 bool IsUnsImmZone = false;
171 if ( anObjectKind == KIND_DUMMY_3D )
173 Handle(HYDROData_DummyObject3D) anObject3D =
174 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
176 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
177 if ( !aFatherObj.IsNull() )
178 anObjectKind = aFatherObj->GetKind();
179 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
181 else if ( !anObject.IsNull() )
183 bool IsSubm = anObject->IsSubmersible();
184 QString anIcon1 = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
187 anIcon2 = QObject::tr( QString("HYDRO_SUBMERSIBLE16_ICO").toLatin1());
189 anIcon2 = QObject::tr( QString("HYDRO_UNSUBMERSIBLE16_ICO").toLatin1());
191 QPixmap qpm1 = aResMgr->loadPixmap( "HYDRO", anIcon1 );
192 QPixmap qpm2 = aResMgr->loadPixmap( "HYDRO", anIcon2 );
194 qpmD.fill(QColor(0,0,0));
196 painter.begin(&qpmD);
197 painter.drawPixmap(0, 0, qpm1);
198 painter.drawPixmap(16, 0, qpm2);
202 else if (anObjectKind == KIND_BC_POLYGON)
204 Handle(HYDROData_BCPolygon) aBCObj = Handle(HYDROData_BCPolygon)::DownCast( aDataObject );
205 int aBT = aBCObj->GetBoundaryType();
207 anIcon = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE1_ICO").toLatin1());
209 anIcon = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE2_ICO").toLatin1());
211 anIcon = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE3_ICO").toLatin1());
213 anIcon = QObject::tr( QString("HYDRO_BC_POLYGON_TYPE_UNDEF_ICO").toLatin1());
216 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
219 return aResMgr->loadPixmap( "HYDRO", anIcon );
221 return PARENT::icon( theId );
224 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
225 const bool theWithPrefix )
227 QString aEntryStr = QString::null;
228 if( !theObject.IsNull() )
230 TCollection_AsciiString aLabEntr;
231 TDF_Tool::Entry( theObject->Label(), aLabEntr );
232 aEntryStr = aLabEntr.ToCString();
234 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
239 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
241 myIsValid = theIsValid;
244 bool HYDROGUI_DataObject::isValid() const
249 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
252 if ( theColumnId == NameId && module())
254 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
255 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
257 aRes = isInOperation();
266 aRes = PARENT::renameAllowed( theColumnId );
271 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
273 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
277 myData = aDataObj->myData;
278 myParentEntry = aDataObj->myParentEntry;
279 myIsValid = aDataObj->myIsValid;
280 myIsInOperation = aDataObj->myIsInOperation;
281 myIcon = aDataObj->myIcon;
285 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
286 const QString& theName,
287 const QString& theParentEntry,
288 const bool theIsInOperation )
289 : CAM_DataObject( theParent ),
291 LightApp_DataObject( theParent ),
294 myParentEntry( theParentEntry ),
295 myIsInOperation( theIsInOperation )
299 QString HYDROGUI_NamedObject::entry() const
301 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
302 if( !myParentEntry.isEmpty() )
303 anEntry.prepend( myParentEntry + "_" );
307 QString HYDROGUI_NamedObject::name() const
309 return myName.toUpper();
312 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
314 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
315 if ( theId == NameId )
317 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
319 return PARENT::icon( theId );
322 QFont HYDROGUI_NamedObject::font( const int theId ) const
324 QFont aFont = PARENT::font( theId );
325 if( theId == NameId )
327 if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
329 aFont.setBold( true );
335 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
337 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
341 myName = aNamedObj->myName;
342 myParentEntry = aNamedObj->myParentEntry;
343 myIcon = aNamedObj->myIcon;
344 myIsInOperation = aNamedObj->myIsInOperation;
353 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
354 const QString& theName,
355 const QString& theParentEntry,
356 const bool theIsInOperation )
357 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ),
358 CAM_DataObject( theParent )