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_RTTIEXT(HYDROData_Object,HYDROData_Entity)
37 HYDROData_Object::HYDROData_Object( Geometry theGeometry )
38 : HYDROData_Entity( theGeometry )
42 HYDROData_Object::~HYDROData_Object()
46 void HYDROData_Object::SetName( const QString& theName )
48 QString anOldObjName = GetName();
49 if ( anOldObjName != theName )
51 HYDROData_SequenceOfObjects aGroups = GetGroups();
52 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
53 for ( ; anIter.More(); anIter.Next() )
55 Handle(HYDROData_ShapesGroup) aGroup =
56 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
57 if ( aGroup.IsNull() )
60 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
63 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
64 if ( !anObject3D.IsNull() )
65 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
67 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
68 if ( !anAltitudeObj.IsNull() )
69 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
72 HYDROData_Entity::SetName( theName );
75 void HYDROData_Object::Update()
77 if( IsMustBeUpdated( Geom_2d ) )
82 if( IsMustBeUpdated( Geom_3d ) )
85 checkAndSetAltitudeObject();
86 HYDROData_Entity::Update();
89 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
91 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
93 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
94 if ( !aRefAltitude.IsNull() )
95 aResSeq.Append( aRefAltitude );
100 void HYDROData_Object::Changed( Geometry theChangedGeometry )
102 HYDROData_Entity::Changed( theChangedGeometry );
104 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
105 if ( !anObject3D.IsNull() )
106 anObject3D->Changed( theChangedGeometry );
109 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
111 HYDROData_Entity::SetShape( DataTag_TopShape, theShape );
114 TopoDS_Shape HYDROData_Object::GetTopShape() const
116 return HYDROData_Entity::GetShape( DataTag_TopShape );
119 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
121 HYDROData_Entity::SetShape( DataTag_Shape3D, theShape );
122 // Check the object 3D existance
123 checkAndSetObject3D();
126 TopoDS_Shape HYDROData_Object::GetShape3D() const
128 return HYDROData_Entity::GetShape( DataTag_Shape3D );
131 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
133 Handle(HYDROData_DummyObject3D) anObject;
135 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
136 if ( !aLabel.IsNull() )
138 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
139 if ( !aChildLabel.IsNull() )
141 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
142 HYDROData_Iterator::Object( aChildLabel ) );
149 void HYDROData_Object::checkAndSetObject3D()
151 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
152 if ( !aLabel.IsNull() )
155 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
156 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
159 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
161 return GetReferenceObjects( DataTag_EdgesGroup );
164 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
166 Handle(HYDROData_ShapesGroup) aResGroup;
168 HYDROData_SequenceOfObjects aGroups = GetGroups();
169 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
172 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
177 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
181 HYDROData_SequenceOfObjects aGroups = GetGroups();
182 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
184 Handle(HYDROData_ShapesGroup) aGroup =
185 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
186 if ( theGroup->CompareLabels ( aGroup ) )
196 bool HYDROData_Object::SetAltitudeObject(
197 const Handle(HYDROData_IAltitudeObject)& theAltitude )
199 if ( theAltitude.IsNull() )
202 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
203 if ( IsEqual( aPrevAltitude, theAltitude ) )
206 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
208 // #636: In the case of the altitude object change the geometry of the main object is not changed,
209 // to the object should not be marked as updated
210 //SetToUpdate( true );
215 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
217 return Handle(HYDROData_IAltitudeObject)::DownCast(
218 GetReferenceObject( DataTag_AltitudeObject ) );
221 void HYDROData_Object::RemoveAltitudeObject()
223 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
224 if ( aPrevAltitude.IsNull() )
227 ClearReferenceObjects( DataTag_AltitudeObject );
229 // #636: In the case of the altitude object change the geometry of the main object is not changed,
230 // to the object should not be marked as updated
231 //SetToUpdate( true );
234 void HYDROData_Object::SetFillingColor( const QColor& theColor )
236 SetColor( theColor, DataTag_FillingColor );
239 QColor HYDROData_Object::GetFillingColor() const
241 return GetColor( DefaultFillingColor(), DataTag_FillingColor );
244 void HYDROData_Object::SetBorderColor( const QColor& theColor )
246 SetColor( theColor, DataTag_BorderColor );
249 QColor HYDROData_Object::GetBorderColor() const
251 return GetColor( DefaultBorderColor(), DataTag_BorderColor );
254 QColor HYDROData_Object::DefaultFillingColor() const
256 return QColor( Qt::yellow );
259 QColor HYDROData_Object::DefaultBorderColor() const
261 return QColor( Qt::transparent );
264 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
266 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
267 if ( aResList.isEmpty() )
268 return aResList; //Object was not created
270 QStringList aColorsDef;
272 QColor aFillingColor = GetFillingColor();
273 setPythonObjectColor( aColorsDef, aFillingColor, DefaultFillingColor(), "SetFillingColor" );
275 QColor aBorderColor = GetBorderColor();
276 setPythonObjectColor( aColorsDef, aBorderColor, DefaultBorderColor(), "SetBorderColor" );
278 if ( !aColorsDef.isEmpty() )
280 aResList << aColorsDef;
281 aResList << QString( "" );
287 ObjectKind HYDROData_Object::getAltitudeObjectType() const
292 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
294 Handle(HYDROData_IAltitudeObject) anObject;
296 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
297 if ( !aLabel.IsNull() )
299 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
300 if ( !aChildLabel.IsNull() )
302 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
303 HYDROData_Iterator::Object( aChildLabel ) );
310 void HYDROData_Object::checkAndSetAltitudeObject()
312 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
314 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
315 //DEBTRACE("HYDROData_Object::checkAndSetAltitudeObject anAltitudeObjectType="<< anAltitudeObjectType);
316 if ( anAltitudeObjectType == KIND_UNKNOWN )
317 return; // No need to create altitude object
319 Handle(HYDROData_IAltitudeObject) altObject = GetAltitudeObject();
320 if( !altObject.IsNull() && altObject->GetKind()==anAltitudeObjectType )
323 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
325 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
326 Handle(HYDROData_IAltitudeObject)::DownCast(
327 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
329 QString anAltitudePref = GetName() + "_Altitude";
330 //DEBTRACE("anAltitudePref " << anAltitudePref.toStdString());
331 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
332 anAltitudeObject->SetName( anAltitudeName );
334 SetAltitudeObject( anAltitudeObject );
337 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
339 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
341 Handle(HYDROData_ShapesGroup) aNewGroup =
342 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
343 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
348 void HYDROData_Object::RemoveGroupObjects()
350 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
351 if ( !aLabel.IsNull() )
352 aLabel.ForgetAllAttributes();
355 void HYDROData_Object::RemoveTopShape()
357 HYDROData_Entity::SetShape( DataTag_TopShape, TopoDS_Shape() );
360 void HYDROData_Object::RemoveShape3D()
362 HYDROData_Entity::SetShape( DataTag_Shape3D, TopoDS_Shape() );
365 bool HYDROData_Object::IsSubmersible() const
367 Handle(TDataStd_Integer) aSubMersibleAttr;
369 bool isSubmersible = true; //default
370 if( myLab.FindAttribute(TDataStd_Integer::GetID(), aSubMersibleAttr ) )
372 int aValue = aSubMersibleAttr->Get();
373 isSubmersible = ( aValue != 0 );
375 return isSubmersible;
378 void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const
380 TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 );
383 void HYDROData_Object::GetBoundaries( QList<TopoDS_Shape>& theBoundShapes,
384 QStringList& theBoundNames ) const
386 HYDROData_SequenceOfObjects aGroups = GetGroups();
387 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
388 for ( ; anIter.More(); anIter.Next() )
390 Handle(HYDROData_ShapesGroup) aGroup =
391 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
392 if( aGroup.IsNull() )
395 QString aName = aGroup->GetName();
396 TopTools_SequenceOfShape aShapes;
397 aGroup->GetShapes( aShapes );
398 for( int i=1, n=aShapes.Length(); i<=n; i++ )
400 theBoundShapes.append( aShapes( i ) );
401 theBoundNames.append( aName );