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 "HYDROData_Object.h"
21 #include "HYDROData_DummyObject3D.h"
22 #include "HYDROData_ShapesGroup.h"
23 #include "HYDROData_Tool.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_IAltitudeObject.h"
26 #include <TopoDS_Shape.hxx>
27 #include <TDataStd_Integer.hxx>
31 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
32 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
34 HYDROData_Object::HYDROData_Object( Geometry theGeometry )
35 : HYDROData_Entity( theGeometry )
39 HYDROData_Object::~HYDROData_Object()
43 void HYDROData_Object::SetName( const QString& theName )
45 QString anOldObjName = GetName();
46 if ( anOldObjName != theName )
48 HYDROData_SequenceOfObjects aGroups = GetGroups();
49 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
50 for ( ; anIter.More(); anIter.Next() )
52 Handle(HYDROData_ShapesGroup) aGroup =
53 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
54 if ( aGroup.IsNull() )
57 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
60 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
61 if ( !anObject3D.IsNull() )
62 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
64 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
65 if ( !anAltitudeObj.IsNull() )
66 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
69 HYDROData_Entity::SetName( theName );
72 void HYDROData_Object::Update()
74 if( IsMustBeUpdated( Geom_2d ) )
79 if( IsMustBeUpdated( Geom_3d ) )
82 checkAndSetAltitudeObject();
83 HYDROData_Entity::Update();
86 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
88 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
90 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
91 if ( !aRefAltitude.IsNull() )
92 aResSeq.Append( aRefAltitude );
97 void HYDROData_Object::Changed( Geometry theChangedGeometry )
99 HYDROData_Entity::Changed( theChangedGeometry );
101 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
102 if ( !anObject3D.IsNull() )
103 anObject3D->Changed( theChangedGeometry );
106 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
108 HYDROData_Entity::SetShape( DataTag_TopShape, theShape );
111 TopoDS_Shape HYDROData_Object::GetTopShape() const
113 return HYDROData_Entity::GetShape( DataTag_TopShape );
116 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
118 HYDROData_Entity::SetShape( DataTag_Shape3D, theShape );
119 // Check the object 3D existance
120 checkAndSetObject3D();
123 TopoDS_Shape HYDROData_Object::GetShape3D() const
125 return HYDROData_Entity::GetShape( DataTag_Shape3D );
128 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
130 Handle(HYDROData_DummyObject3D) anObject;
132 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
133 if ( !aLabel.IsNull() )
135 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
136 if ( !aChildLabel.IsNull() )
138 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
139 HYDROData_Iterator::Object( aChildLabel ) );
146 void HYDROData_Object::checkAndSetObject3D()
148 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
149 if ( !aLabel.IsNull() )
152 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
153 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
156 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
158 return GetReferenceObjects( DataTag_EdgesGroup );
161 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
163 Handle(HYDROData_ShapesGroup) aResGroup;
165 HYDROData_SequenceOfObjects aGroups = GetGroups();
166 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
169 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
174 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
178 HYDROData_SequenceOfObjects aGroups = GetGroups();
179 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
181 Handle(HYDROData_ShapesGroup) aGroup =
182 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
183 if ( IsEqual( theGroup, aGroup ) )
193 bool HYDROData_Object::SetAltitudeObject(
194 const Handle(HYDROData_IAltitudeObject)& theAltitude )
196 if ( theAltitude.IsNull() )
199 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
200 if ( IsEqual( aPrevAltitude, theAltitude ) )
203 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
205 // #636: In the case of the altitude object change the geometry of the main object is not changed,
206 // to the object should not be marked as updated
207 //SetToUpdate( true );
212 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
214 return Handle(HYDROData_IAltitudeObject)::DownCast(
215 GetReferenceObject( DataTag_AltitudeObject ) );
218 void HYDROData_Object::RemoveAltitudeObject()
220 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
221 if ( aPrevAltitude.IsNull() )
224 ClearReferenceObjects( DataTag_AltitudeObject );
226 // #636: In the case of the altitude object change the geometry of the main object is not changed,
227 // to the object should not be marked as updated
228 //SetToUpdate( true );
231 void HYDROData_Object::SetFillingColor( const QColor& theColor )
233 SetColor( theColor, DataTag_FillingColor );
236 QColor HYDROData_Object::GetFillingColor() const
238 return GetColor( DefaultFillingColor(), DataTag_FillingColor );
241 void HYDROData_Object::SetBorderColor( const QColor& theColor )
243 SetColor( theColor, DataTag_BorderColor );
246 QColor HYDROData_Object::GetBorderColor() const
248 return GetColor( DefaultBorderColor(), DataTag_BorderColor );
251 QColor HYDROData_Object::DefaultFillingColor() const
253 return QColor( Qt::yellow );
256 QColor HYDROData_Object::DefaultBorderColor() const
258 return QColor( Qt::transparent );
261 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
263 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
264 if ( aResList.isEmpty() )
265 return aResList; //Object was not created
267 QStringList aColorsDef;
269 QColor aFillingColor = GetFillingColor();
270 setPythonObjectColor( aColorsDef, aFillingColor, DefaultFillingColor(), "SetFillingColor" );
272 QColor aBorderColor = GetBorderColor();
273 setPythonObjectColor( aColorsDef, aBorderColor, DefaultBorderColor(), "SetBorderColor" );
275 if ( !aColorsDef.isEmpty() )
277 aResList << aColorsDef;
278 aResList << QString( "" );
284 ObjectKind HYDROData_Object::getAltitudeObjectType() const
289 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
291 Handle(HYDROData_IAltitudeObject) anObject;
293 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
294 if ( !aLabel.IsNull() )
296 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
297 if ( !aChildLabel.IsNull() )
299 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
300 HYDROData_Iterator::Object( aChildLabel ) );
307 void HYDROData_Object::checkAndSetAltitudeObject()
309 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
311 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
312 if ( anAltitudeObjectType == KIND_UNKNOWN )
313 return; // No need to create altitude object
315 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
316 if ( !aLabel.IsNull() )
319 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
321 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
322 Handle(HYDROData_IAltitudeObject)::DownCast(
323 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
325 QString anAltitudePref = GetName() + "_Altitude";
326 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
327 anAltitudeObject->SetName( anAltitudeName );
329 SetAltitudeObject( anAltitudeObject );
332 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
334 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
336 Handle(HYDROData_ShapesGroup) aNewGroup =
337 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
338 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
343 void HYDROData_Object::RemoveGroupObjects()
345 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
346 if ( !aLabel.IsNull() )
347 aLabel.ForgetAllAttributes();
350 void HYDROData_Object::RemoveTopShape()
352 HYDROData_Entity::SetShape( DataTag_TopShape, TopoDS_Shape() );
355 void HYDROData_Object::RemoveShape3D()
357 HYDROData_Entity::SetShape( DataTag_Shape3D, TopoDS_Shape() );
360 bool HYDROData_Object::IsSubmersible() const
362 Handle(TDataStd_Integer) aSubMersibleAttr;
364 bool isSubmersible = true; //default
365 if( myLab.FindAttribute(TDataStd_Integer::GetID(), aSubMersibleAttr ) )
367 int aValue = aSubMersibleAttr->Get();
368 isSubmersible = ( aValue != 0 );
370 return isSubmersible;
373 void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const
375 TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 );
378 void HYDROData_Object::GetBoundaries( QList<TopoDS_Shape>& theBoundShapes,
379 QStringList& theBoundNames ) const
381 HYDROData_SequenceOfObjects aGroups = GetGroups();
382 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
383 for ( ; anIter.More(); anIter.Next() )
385 Handle(HYDROData_ShapesGroup) aGroup =
386 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
387 if( aGroup.IsNull() )
390 QString aName = aGroup->GetName();
391 TopTools_SequenceOfShape aShapes;
392 aGroup->GetShapes( aShapes );
393 for( int i=1, n=aShapes.Length(); i<=n; i++ )
395 theBoundShapes.append( aShapes( i ) );
396 theBoundNames.append( aName );