1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_DataObject.h"
25 #include <HYDROData_DummyObject3D.h>
26 #include <HYDROData_Object.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>
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 ),
45 LightApp_DataObject( theParent ),
47 myParentEntry( theParentEntry ),
49 myIsInOperation( theIsInOperation )
53 QString HYDROGUI_DataObject::entry() const
55 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
57 anEntry.prepend( myParentEntry + "_" );
61 QString HYDROGUI_DataObject::refEntry() const
63 if( !myParentEntry.isEmpty() )
64 return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
68 QString HYDROGUI_DataObject::name() const
70 if( !myData.IsNull() )
71 return myData->GetName();
75 QFont HYDROGUI_DataObject::font( const int theId ) const
77 QFont aFont = LightApp_DataObject::font( theId );
80 Handle(HYDROData_Entity) aDataObject = modelObject();
81 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
83 aFont.setItalic( true );
84 aFont.setBold( true );
90 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
100 aColor = Qt::red; // red
102 case HighlightedText:
103 // text color for the highlighted item
104 aColor = Qt::white; // white
112 if ( !aColor.isValid() )
114 Handle(HYDROData_Entity) aDataObject = modelObject();
115 if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated() )
122 aColor = Qt::blue; // color for objects which need updating
124 case HighlightedText:
125 // text color for the highlighted item
126 aColor = Qt::white; // white
135 if ( !aColor.isValid() ) {
136 aColor = LightApp_DataObject::color( theRole, theId );
142 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
144 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
145 if ( theId == NameId )
148 Handle(HYDROData_Entity) aDataObject = modelObject();
149 if( aDataObject.IsNull() )
151 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
155 QString aNeedUpdate( aDataObject->IsMustBeUpdated() ? "M_" : "" );
157 int anObjectKind = (int)aDataObject->GetKind();
158 if ( anObjectKind == KIND_DUMMY_3D )
160 Handle(HYDROData_DummyObject3D) anObject3D =
161 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
163 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
164 if ( !aFatherObj.IsNull() )
165 anObjectKind = aFatherObj->GetKind();
168 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toAscii() );
171 return aResMgr->loadPixmap( "HYDRO", anIcon );
173 return LightApp_DataObject::icon( theId );
176 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
177 const bool theWithPrefix )
179 QString aEntryStr = QString::null;
180 if( !theObject.IsNull() )
182 TCollection_AsciiString aLabEntr;
183 TDF_Tool::Entry( theObject->Label(), aLabEntr );
184 aEntryStr = aLabEntr.ToCString();
186 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
191 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
193 myIsValid = theIsValid;
196 bool HYDROGUI_DataObject::isValid() const
201 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
204 if ( theColumnId == NameId && module())
206 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
207 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
209 aRes = isInOperation();
218 aRes = LightApp_DataObject::renameAllowed( theColumnId );
223 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
225 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
229 myData = aDataObj->myData;
230 myParentEntry = aDataObj->myParentEntry;
231 myIsValid = aDataObj->myIsValid;
232 myIsInOperation = aDataObj->myIsInOperation;
233 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 )