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>
28 #include <TDataStd_Real.hxx>
33 #include "HYDRO_trace.hxx"
35 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
38 HYDROData_Object::HYDROData_Object( Geometry theGeometry )
39 : HYDROData_Entity( theGeometry )
43 HYDROData_Object::~HYDROData_Object()
47 void HYDROData_Object::SetName( const QString& theName )
49 QString anOldObjName = GetName();
50 if ( anOldObjName != theName )
52 HYDROData_SequenceOfObjects aGroups = GetGroups();
53 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
54 for ( ; anIter.More(); anIter.Next() )
56 Handle(HYDROData_ShapesGroup) aGroup =
57 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
58 if ( aGroup.IsNull() )
61 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
64 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
65 if ( !anObject3D.IsNull() )
66 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
68 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
69 if ( !anAltitudeObj.IsNull() )
70 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
73 HYDROData_Entity::SetName( theName );
76 void HYDROData_Object::Update()
78 if( IsMustBeUpdated( Geom_2d ) )
83 if( IsMustBeUpdated( Geom_3d ) )
86 checkAndSetAltitudeObject();
87 HYDROData_Entity::Update();
90 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
92 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
94 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
95 if ( !aRefAltitude.IsNull() )
96 aResSeq.Append( aRefAltitude );
101 void HYDROData_Object::Changed( Geometry theChangedGeometry )
103 HYDROData_Entity::Changed( theChangedGeometry );
105 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
106 if ( !anObject3D.IsNull() )
107 anObject3D->Changed( theChangedGeometry );
110 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
112 HYDROData_Entity::SetShape( DataTag_TopShape, theShape );
115 TopoDS_Shape HYDROData_Object::GetTopShape() const
117 return HYDROData_Entity::GetShape( DataTag_TopShape );
120 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
122 HYDROData_Entity::SetShape( DataTag_Shape3D, theShape );
123 // Check the object 3D existance
124 checkAndSetObject3D();
127 TopoDS_Shape HYDROData_Object::GetShape3D() const
129 return HYDROData_Entity::GetShape( DataTag_Shape3D );
132 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
134 Handle(HYDROData_DummyObject3D) anObject;
136 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
137 if ( !aLabel.IsNull() )
139 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
140 if ( !aChildLabel.IsNull() )
142 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
143 HYDROData_Iterator::Object( aChildLabel ) );
150 void HYDROData_Object::checkAndSetObject3D()
152 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
153 if ( !aLabel.IsNull() )
156 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
157 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
160 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
162 return GetReferenceObjects( DataTag_EdgesGroup );
165 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
167 Handle(HYDROData_ShapesGroup) aResGroup;
169 HYDROData_SequenceOfObjects aGroups = GetGroups();
170 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
173 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
178 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
182 HYDROData_SequenceOfObjects aGroups = GetGroups();
183 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
185 Handle(HYDROData_ShapesGroup) aGroup =
186 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
187 if ( IsEqual( theGroup, aGroup ) )
197 bool HYDROData_Object::SetAltitudeObject(
198 const Handle(HYDROData_IAltitudeObject)& theAltitude )
200 if ( theAltitude.IsNull() )
203 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
204 if ( IsEqual( aPrevAltitude, theAltitude ) )
207 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
209 // #636: In the case of the altitude object change the geometry of the main object is not changed,
210 // to the object should not be marked as updated
211 //SetToUpdate( true );
216 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
218 return Handle(HYDROData_IAltitudeObject)::DownCast(
219 GetReferenceObject( DataTag_AltitudeObject ) );
222 void HYDROData_Object::RemoveAltitudeObject()
224 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
225 if ( aPrevAltitude.IsNull() )
228 ClearReferenceObjects( DataTag_AltitudeObject );
230 // #636: In the case of the altitude object change the geometry of the main object is not changed,
231 // to the object should not be marked as updated
232 //SetToUpdate( true );
235 void HYDROData_Object::SetFillingColor( const QColor& theColor )
237 SetColor( theColor, DataTag_FillingColor );
240 QColor HYDROData_Object::GetFillingColor() const
242 return GetColor( DefaultFillingColor(), DataTag_FillingColor );
245 void HYDROData_Object::SetBorderColor( const QColor& theColor )
247 SetColor( theColor, DataTag_BorderColor );
250 QColor HYDROData_Object::GetBorderColor() const
252 return GetColor( DefaultBorderColor(), DataTag_BorderColor );
255 QColor HYDROData_Object::DefaultFillingColor() const
257 return QColor( Qt::yellow );
260 QColor HYDROData_Object::DefaultBorderColor() const
262 return QColor( Qt::transparent );
265 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
267 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
268 if ( aResList.isEmpty() )
269 return aResList; //Object was not created
271 QStringList aColorsDef;
273 QColor aFillingColor = GetFillingColor();
274 setPythonObjectColor( aColorsDef, aFillingColor, DefaultFillingColor(), "SetFillingColor" );
276 QColor aBorderColor = GetBorderColor();
277 setPythonObjectColor( aColorsDef, aBorderColor, DefaultBorderColor(), "SetBorderColor" );
279 if ( !aColorsDef.isEmpty() )
281 aResList << aColorsDef;
282 aResList << QString( "" );
288 ObjectKind HYDROData_Object::getAltitudeObjectType() const
293 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
295 Handle(HYDROData_IAltitudeObject) anObject;
297 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
298 if ( !aLabel.IsNull() )
300 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
301 if ( !aChildLabel.IsNull() )
303 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
304 HYDROData_Iterator::Object( aChildLabel ) );
311 void HYDROData_Object::checkAndSetAltitudeObject()
313 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
315 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
316 //DEBTRACE("HYDROData_Object::checkAndSetAltitudeObject anAltitudeObjectType="<< anAltitudeObjectType);
317 if ( anAltitudeObjectType == KIND_UNKNOWN )
318 return; // No need to create altitude object
320 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
321 if ( !aLabel.IsNull() )
324 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
326 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
327 Handle(HYDROData_IAltitudeObject)::DownCast(
328 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
330 QString anAltitudePref = GetName() + "_Altitude";
331 DEBTRACE("anAltitudePref " << anAltitudePref.toStdString());
332 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
333 anAltitudeObject->SetName( anAltitudeName );
335 SetAltitudeObject( anAltitudeObject );
338 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
340 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
342 Handle(HYDROData_ShapesGroup) aNewGroup =
343 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
344 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
349 void HYDROData_Object::RemoveGroupObjects()
351 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
352 if ( !aLabel.IsNull() )
353 aLabel.ForgetAllAttributes();
356 void HYDROData_Object::RemoveTopShape()
358 HYDROData_Entity::SetShape( DataTag_TopShape, TopoDS_Shape() );
361 void HYDROData_Object::RemoveShape3D()
363 HYDROData_Entity::SetShape( DataTag_Shape3D, TopoDS_Shape() );
366 bool HYDROData_Object::IsSubmersible() const
368 Handle(TDataStd_Integer) aSubMersibleAttr;
370 bool isSubmersible = true; //default
371 if( myLab.FindAttribute(TDataStd_Integer::GetID(), aSubMersibleAttr ) )
373 int aValue = aSubMersibleAttr->Get();
374 isSubmersible = ( aValue != 0 );
376 return isSubmersible;
379 void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const
381 TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 );
384 void HYDROData_Object::GetBoundaries( QList<TopoDS_Shape>& theBoundShapes,
385 QStringList& theBoundNames ) const
387 HYDROData_SequenceOfObjects aGroups = GetGroups();
388 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
389 for ( ; anIter.More(); anIter.Next() )
391 Handle(HYDROData_ShapesGroup) aGroup =
392 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
393 if( aGroup.IsNull() )
396 QString aName = aGroup->GetName();
397 TopTools_SequenceOfShape aShapes;
398 aGroup->GetShapes( aShapes );
399 for( int i=1, n=aShapes.Length(); i<=n; i++ )
401 theBoundShapes.append( aShapes( i ) );
402 theBoundNames.append( aName );