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();
179 else if ( !anObject.IsNull() )
181 bool IsSubm = anObject->IsSubmersible();
182 QString anIcon1 = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
185 anIcon2 = QObject::tr( QString("HYDRO_SUBMERSIBLE16_ICO").toLatin1());
187 anIcon2 = QObject::tr( QString("HYDRO_UNSUBMERSIBLE16_ICO").toLatin1());
189 QPixmap qpm1 = aResMgr->loadPixmap( "HYDRO", anIcon1 );
190 QPixmap qpm2 = aResMgr->loadPixmap( "HYDRO", anIcon2 );
192 qpmD.fill(QColor(0,0,0));
194 painter.begin(&qpmD);
195 painter.drawPixmap(0, 0, qpm1);
196 painter.drawPixmap(16, 0, qpm2);
201 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
204 return aResMgr->loadPixmap( "HYDRO", anIcon );
206 return PARENT::icon( theId );
209 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
210 const bool theWithPrefix )
212 QString aEntryStr = QString::null;
213 if( !theObject.IsNull() )
215 TCollection_AsciiString aLabEntr;
216 TDF_Tool::Entry( theObject->Label(), aLabEntr );
217 aEntryStr = aLabEntr.ToCString();
219 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
224 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
226 myIsValid = theIsValid;
229 bool HYDROGUI_DataObject::isValid() const
234 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
237 if ( theColumnId == NameId && module())
239 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
240 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
242 aRes = isInOperation();
251 aRes = PARENT::renameAllowed( theColumnId );
256 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
258 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
262 myData = aDataObj->myData;
263 myParentEntry = aDataObj->myParentEntry;
264 myIsValid = aDataObj->myIsValid;
265 myIsInOperation = aDataObj->myIsInOperation;
266 myIcon = aDataObj->myIcon;
270 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
271 const QString& theName,
272 const QString& theParentEntry,
273 const bool theIsInOperation )
274 : CAM_DataObject( theParent ),
276 LightApp_DataObject( theParent ),
279 myParentEntry( theParentEntry ),
280 myIsInOperation( theIsInOperation )
284 QString HYDROGUI_NamedObject::entry() const
286 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
287 if( !myParentEntry.isEmpty() )
288 anEntry.prepend( myParentEntry + "_" );
292 QString HYDROGUI_NamedObject::name() const
294 return myName.toUpper();
297 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
299 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
300 if ( theId == NameId )
302 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
304 return PARENT::icon( theId );
307 QFont HYDROGUI_NamedObject::font( const int theId ) const
309 QFont aFont = PARENT::font( theId );
310 if( theId == NameId )
312 if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
314 aFont.setBold( true );
320 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
322 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
326 myName = aNamedObj->myName;
327 myParentEntry = aNamedObj->myParentEntry;
328 myIcon = aNamedObj->myIcon;
329 myIsInOperation = aNamedObj->myIsInOperation;
338 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
339 const QString& theName,
340 const QString& theParentEntry,
341 const bool theIsInOperation )
342 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ),
343 CAM_DataObject( theParent )