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_Object.h>
24 #include <TDF_Tool.hxx>
26 #include <SUIT_DataObject.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_Operation.h>
30 #include <CAM_Module.h>
31 #include <CAM_Application.h>
32 #include <SUIT_Study.h>
36 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
37 Handle(HYDROData_Entity) theData,
38 const QString& theParentEntry,
39 const bool theIsInOperation )
40 : CAM_DataObject( theParent ),
41 LightApp_DataObject( theParent ),
43 myParentEntry( theParentEntry ),
45 myIsInOperation( theIsInOperation )
49 QString HYDROGUI_DataObject::entry() const
51 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
53 anEntry.prepend( myParentEntry + "_" );
57 QString HYDROGUI_DataObject::refEntry() const
59 if( !myParentEntry.isEmpty() )
60 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
64 QString HYDROGUI_DataObject::name() const
66 if( !myData.IsNull() )
67 return myData->GetName();
71 QFont HYDROGUI_DataObject::font( const int theId ) const
73 QFont aFont = LightApp_DataObject::font( theId );
76 Handle(HYDROData_Entity) aDataObject = modelObject();
77 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
79 aFont.setItalic( true );
80 aFont.setBold( true );
86 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
96 aColor = Qt::red; // red
99 // text color for the highlighted item
100 aColor = Qt::white; // white
108 if ( !aColor.isValid() )
110 Handle(HYDROData_Entity) aDataObject = modelObject();
111 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
118 aColor = Qt::blue; // color for objects which need updating
120 case HighlightedText:
121 // text color for the highlighted item
122 aColor = Qt::white; // white
131 if ( !aColor.isValid() ) {
132 aColor = LightApp_DataObject::color( theRole, theId );
138 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
140 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
141 if ( theId == NameId )
144 Handle(HYDROData_Entity) aDataObject = modelObject();
145 if( aDataObject.IsNull() )
147 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
151 QString aNeedUpdate( aDataObject->IsMustBeUpdated() ? "M_" : "" );
153 int anObjectKind = (int)aDataObject->GetKind();
154 if ( anObjectKind == KIND_DUMMY_3D )
156 Handle(HYDROData_DummyObject3D) anObject3D =
157 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
159 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
160 if ( !aFatherObj.IsNull() )
161 anObjectKind = aFatherObj->GetKind();
164 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toAscii() );
167 return aResMgr->loadPixmap( "HYDRO", anIcon );
169 return LightApp_DataObject::icon( theId );
172 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
173 const bool theWithPrefix )
175 QString aEntryStr = QString::null;
176 if( !theObject.IsNull() )
178 TCollection_AsciiString aLabEntr;
179 TDF_Tool::Entry( theObject->Label(), aLabEntr );
180 aEntryStr = aLabEntr.ToCString();
182 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
187 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
189 myIsValid = theIsValid;
192 bool HYDROGUI_DataObject::isValid() const
197 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
200 if ( theColumnId == NameId && module())
202 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
203 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
205 aRes = isInOperation();
214 aRes = LightApp_DataObject::renameAllowed( theColumnId );
219 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
221 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
225 myData = aDataObj->myData;
226 myParentEntry = aDataObj->myParentEntry;
227 myIsValid = aDataObj->myIsValid;
228 myIsInOperation = aDataObj->myIsInOperation;
229 myIcon = aDataObj->myIcon;
233 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
234 const QString& theName,
235 const QString& theParentEntry,
236 const bool theIsInOperation )
237 : CAM_DataObject( theParent ),
238 LightApp_DataObject( theParent ),
240 myParentEntry( theParentEntry ),
241 myIsInOperation( theIsInOperation )
245 QString HYDROGUI_NamedObject::entry() const
247 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
248 if( !myParentEntry.isEmpty() )
249 anEntry.prepend( myParentEntry + "_" );
253 QString HYDROGUI_NamedObject::name() const
255 return myName.toUpper();
258 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
260 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
261 if ( theId == NameId )
263 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
265 return LightApp_DataObject::icon( theId );
268 QFont HYDROGUI_NamedObject::font( const int theId ) const
270 QFont aFont = LightApp_DataObject::font( theId );
271 if( theId == NameId )
273 if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
275 aFont.setBold( true );
281 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
283 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
287 myName = aNamedObj->myName;
288 myParentEntry = aNamedObj->myParentEntry;
289 myIcon = aNamedObj->myIcon;
290 myIsInOperation = aNamedObj->myIsInOperation;
299 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
300 const QString& theName,
301 const QString& theParentEntry,
302 const bool theIsInOperation )
303 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ),
304 CAM_DataObject( theParent )