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>
25 #include <TDF_Tool.hxx>
27 #include <SUIT_DataObject.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_Operation.h>
31 #include <CAM_Module.h>
32 #include <CAM_Application.h>
33 #include <SUIT_Study.h>
37 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
38 Handle(HYDROData_Entity) theData,
39 const QString& theParentEntry,
40 const bool theIsInOperation )
41 : CAM_DataObject( theParent ),
42 LightApp_DataObject( theParent ),
44 myParentEntry( theParentEntry ),
46 myIsInOperation( theIsInOperation )
50 QString HYDROGUI_DataObject::entry() const
52 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
54 anEntry.prepend( myParentEntry + "_" );
58 QString HYDROGUI_DataObject::refEntry() const
60 if( !myParentEntry.isEmpty() )
61 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
65 QString HYDROGUI_DataObject::name() const
67 if( !myData.IsNull() )
68 return myData->GetName();
72 QFont HYDROGUI_DataObject::font( const int theId ) const
74 QFont aFont = LightApp_DataObject::font( theId );
77 Handle(HYDROData_Entity) aDataObject = modelObject();
78 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
80 aFont.setItalic( true );
81 aFont.setBold( true );
87 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
97 aColor = Qt::red; // red
100 // text color for the highlighted item
101 aColor = Qt::white; // white
109 if ( !aColor.isValid() )
111 Handle(HYDROData_Entity) aDataObject = modelObject();
112 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
119 aColor = Qt::blue; // color for objects which need updating
121 case HighlightedText:
122 // text color for the highlighted item
123 aColor = Qt::white; // white
132 if ( !aColor.isValid() ) {
133 aColor = LightApp_DataObject::color( theRole, theId );
139 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
141 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
142 if ( theId == NameId )
145 Handle(HYDROData_Entity) aDataObject = modelObject();
146 if( aDataObject.IsNull() )
148 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
152 QString aNeedUpdate( aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) ? "M_" : "" );
154 int anObjectKind = (int)aDataObject->GetKind();
155 bool IsUnsImmZone = false;
156 if ( anObjectKind == KIND_DUMMY_3D )
158 Handle(HYDROData_DummyObject3D) anObject3D =
159 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
161 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
162 if ( !aFatherObj.IsNull() )
163 anObjectKind = aFatherObj->GetKind();
165 else if ( anObjectKind == 5 )
167 Handle(HYDROData_ImmersibleZone) anImmZone = Handle(HYDROData_ImmersibleZone)::DownCast( aDataObject );
168 IsUnsImmZone = !anImmZone->IsSubmersible();
171 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
173 anIcon = QObject::tr( QString("HYDRO_%1TYPE5U_ICO").arg( aNeedUpdate ).toLatin1() ); //icon fot unsumb imm zone
176 return aResMgr->loadPixmap( "HYDRO", anIcon );
178 return LightApp_DataObject::icon( theId );
181 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
182 const bool theWithPrefix )
184 QString aEntryStr = QString::null;
185 if( !theObject.IsNull() )
187 TCollection_AsciiString aLabEntr;
188 TDF_Tool::Entry( theObject->Label(), aLabEntr );
189 aEntryStr = aLabEntr.ToCString();
191 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
196 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
198 myIsValid = theIsValid;
201 bool HYDROGUI_DataObject::isValid() const
206 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
209 if ( theColumnId == NameId && module())
211 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
212 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
214 aRes = isInOperation();
223 aRes = LightApp_DataObject::renameAllowed( theColumnId );
228 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
230 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
234 myData = aDataObj->myData;
235 myParentEntry = aDataObj->myParentEntry;
236 myIsValid = aDataObj->myIsValid;
237 myIsInOperation = aDataObj->myIsInOperation;
238 myIcon = aDataObj->myIcon;
242 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
243 const QString& theName,
244 const QString& theParentEntry,
245 const bool theIsInOperation )
246 : CAM_DataObject( theParent ),
247 LightApp_DataObject( theParent ),
249 myParentEntry( theParentEntry ),
250 myIsInOperation( theIsInOperation )
254 QString HYDROGUI_NamedObject::entry() const
256 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
257 if( !myParentEntry.isEmpty() )
258 anEntry.prepend( myParentEntry + "_" );
262 QString HYDROGUI_NamedObject::name() const
264 return myName.toUpper();
267 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
269 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
270 if ( theId == NameId )
272 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
274 return LightApp_DataObject::icon( theId );
277 QFont HYDROGUI_NamedObject::font( const int theId ) const
279 QFont aFont = LightApp_DataObject::font( theId );
280 if( theId == NameId )
282 if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
284 aFont.setBold( true );
290 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
292 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
296 myName = aNamedObj->myName;
297 myParentEntry = aNamedObj->myParentEntry;
298 myIcon = aNamedObj->myIcon;
299 myIsInOperation = aNamedObj->myIsInOperation;
308 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
309 const QString& theName,
310 const QString& theParentEntry,
311 const bool theIsInOperation )
312 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ),
313 CAM_DataObject( theParent )