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 ),
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( HYDROData_Entity::Geom_All ) )
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( HYDROData_Entity::Geom_All ) )
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 Handle(HYDROData_Object) anObject;
150 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aDataObject);
151 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aDataObject);
153 if (!anAObject.IsNull())
154 anObject = anAObject;
155 if (!aNObject.IsNull())
158 if( aDataObject.IsNull() )
160 anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
164 QString aNeedUpdate( aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) ? "M_" : "" );
166 int anObjectKind = (int)aDataObject->GetKind();
167 bool IsUnsImmZone = false;
168 if ( anObjectKind == KIND_DUMMY_3D )
170 Handle(HYDROData_DummyObject3D) anObject3D =
171 Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
173 Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
174 if ( !aFatherObj.IsNull() )
175 anObjectKind = aFatherObj->GetKind();
177 else if ( !anObject.IsNull() )
179 bool IsSubm = anObject->IsSubmersible();
180 QString anIcon1 = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
183 anIcon2 = QObject::tr( QString("HYDRO_SUBMERSIBLE16_ICO").toLatin1());
185 anIcon2 = QObject::tr( QString("HYDRO_UNSUBMERSIBLE16_ICO").toLatin1());
187 QPixmap qpm1 = aResMgr->loadPixmap( "HYDRO", anIcon1 );
188 QPixmap qpm2 = aResMgr->loadPixmap( "HYDRO", anIcon2 );
190 qpmD.fill(QColor(0,0,0));
192 painter.begin(&qpmD);
193 painter.drawPixmap(0, 0, qpm1);
194 painter.drawPixmap(16, 0, qpm2);
199 anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
202 return aResMgr->loadPixmap( "HYDRO", anIcon );
204 return LightApp_DataObject::icon( theId );
207 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
208 const bool theWithPrefix )
210 QString aEntryStr = QString::null;
211 if( !theObject.IsNull() )
213 TCollection_AsciiString aLabEntr;
214 TDF_Tool::Entry( theObject->Label(), aLabEntr );
215 aEntryStr = aLabEntr.ToCString();
217 aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
222 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
224 myIsValid = theIsValid;
227 bool HYDROGUI_DataObject::isValid() const
232 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
235 if ( theColumnId == NameId && module())
237 SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
238 if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
240 aRes = isInOperation();
249 aRes = LightApp_DataObject::renameAllowed( theColumnId );
254 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
256 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
260 myData = aDataObj->myData;
261 myParentEntry = aDataObj->myParentEntry;
262 myIsValid = aDataObj->myIsValid;
263 myIsInOperation = aDataObj->myIsInOperation;
264 myIcon = aDataObj->myIcon;
268 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
269 const QString& theName,
270 const QString& theParentEntry,
271 const bool theIsInOperation )
272 : CAM_DataObject( theParent ),
273 LightApp_DataObject( theParent ),
275 myParentEntry( theParentEntry ),
276 myIsInOperation( theIsInOperation )
280 QString HYDROGUI_NamedObject::entry() const
282 QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
283 if( !myParentEntry.isEmpty() )
284 anEntry.prepend( myParentEntry + "_" );
288 QString HYDROGUI_NamedObject::name() const
290 return myName.toUpper();
293 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
295 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
296 if ( theId == NameId )
298 return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
300 return LightApp_DataObject::icon( theId );
303 QFont HYDROGUI_NamedObject::font( const int theId ) const
305 QFont aFont = LightApp_DataObject::font( theId );
306 if( theId == NameId )
308 if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
310 aFont.setBold( true );
316 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
318 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
322 myName = aNamedObj->myName;
323 myParentEntry = aNamedObj->myParentEntry;
324 myIcon = aNamedObj->myIcon;
325 myIsInOperation = aNamedObj->myIsInOperation;
334 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
335 const QString& theName,
336 const QString& theParentEntry,
337 const bool theIsInOperation )
338 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ),
339 CAM_DataObject( theParent )