2 #include "HYDROData_Object.h"
4 #include "HYDROData_DummyObject3D.h"
5 #include "HYDROData_ShapesGroup.h"
6 #include "HYDROData_Tool.h"
7 #include "HYDROData_Iterator.h"
8 #include "HYDROData_IAltitudeObject.h"
10 #include <TNaming_Builder.hxx>
11 #include <TNaming_NamedShape.hxx>
13 #include <TopoDS_Shape.hxx>
17 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
18 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
20 HYDROData_Object::HYDROData_Object()
25 HYDROData_Object::~HYDROData_Object()
29 void HYDROData_Object::SetName( const QString& theName )
31 QString anOldObjName = GetName();
32 if ( anOldObjName != theName )
34 HYDROData_SequenceOfObjects aGroups = GetGroups();
35 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
36 for ( ; anIter.More(); anIter.Next() )
38 Handle(HYDROData_ShapesGroup) aGroup =
39 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
40 if ( aGroup.IsNull() )
43 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
46 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
47 if ( !anObject3D.IsNull() )
48 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
50 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
51 if ( !anAltitudeObj.IsNull() )
52 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
55 HYDROData_Entity::SetName( theName );
58 void HYDROData_Object::Update()
63 checkAndSetAltitudeObject();
64 HYDROData_Entity::Update();
67 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
69 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
71 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
72 if ( !aRefAltitude.IsNull() )
73 aResSeq.Append( aRefAltitude );
78 void HYDROData_Object::SetToUpdate( bool theFlag )
80 HYDROData_Entity::SetToUpdate( theFlag );
82 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
83 if ( !anObject3D.IsNull() )
84 anObject3D->SetToUpdate( theFlag );
87 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
89 TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
90 aBuilder.Generated( theShape );
93 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
95 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
96 aBuilder.Generated( theShape );
98 // Check the object 3D existance
99 checkAndSetObject3D();
102 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
104 Handle(HYDROData_DummyObject3D) anObject;
106 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
107 if ( !aLabel.IsNull() )
109 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
110 if ( !aChildLabel.IsNull() )
112 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
113 HYDROData_Iterator::Object( aChildLabel ) );
120 void HYDROData_Object::checkAndSetObject3D()
122 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
123 if ( !aLabel.IsNull() )
126 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
127 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
130 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
132 return GetReferenceObjects( DataTag_EdgesGroup );
135 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
137 Handle(HYDROData_ShapesGroup) aResGroup;
139 HYDROData_SequenceOfObjects aGroups = GetGroups();
140 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
143 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
148 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
152 HYDROData_SequenceOfObjects aGroups = GetGroups();
153 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
155 Handle(HYDROData_ShapesGroup) aGroup =
156 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
157 if ( IsEqual( theGroup, aGroup ) )
167 bool HYDROData_Object::SetAltitudeObject(
168 const Handle(HYDROData_IAltitudeObject)& theAltitude )
170 if ( theAltitude.IsNull() )
173 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
174 if ( IsEqual( aPrevAltitude, theAltitude ) )
177 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
179 // Indicate model of the need to update object
185 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
187 return Handle(HYDROData_IAltitudeObject)::DownCast(
188 GetReferenceObject( DataTag_AltitudeObject ) );
191 void HYDROData_Object::RemoveAltitudeObject()
193 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
194 if ( aPrevAltitude.IsNull() )
197 ClearReferenceObjects( DataTag_AltitudeObject );
199 // Indicate model of the need to update object
203 void HYDROData_Object::SetFillingColor( const QColor& theColor )
205 SetColor( theColor, DataTag_FillingColor );
208 QColor HYDROData_Object::GetFillingColor() const
210 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
213 void HYDROData_Object::SetBorderColor( const QColor& theColor )
215 SetColor( theColor, DataTag_BorderColor );
218 QColor HYDROData_Object::GetBorderColor() const
220 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
223 QColor HYDROData_Object::getDefaultFillingColor() const
225 return QColor( Qt::yellow );
228 QColor HYDROData_Object::getDefaultBorderColor() const
230 return QColor( Qt::transparent );
233 ObjectKind HYDROData_Object::getAltitudeObjectType() const
238 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
240 Handle(HYDROData_IAltitudeObject) anObject;
242 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
243 if ( !aLabel.IsNull() )
245 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
246 if ( !aChildLabel.IsNull() )
248 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
249 HYDROData_Iterator::Object( aChildLabel ) );
256 void HYDROData_Object::checkAndSetAltitudeObject()
258 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
260 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
261 if ( anAltitudeObjectType == KIND_UNKNOWN )
262 return; // No need to create altitude object
264 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
265 if ( !aLabel.IsNull() )
268 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
270 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
271 Handle(HYDROData_IAltitudeObject)::DownCast(
272 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
274 QString anAltitudePref = GetName() + "_Altitude";
275 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
276 anAltitudeObject->SetName( anAltitudeName );
278 SetAltitudeObject( anAltitudeObject );
281 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
283 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
285 Handle(HYDROData_ShapesGroup) aNewGroup =
286 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
287 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
292 void HYDROData_Object::removeGroupObjects()
294 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
295 if ( !aLabel.IsNull() )
296 aLabel.ForgetAllAttributes();
299 TopoDS_Shape HYDROData_Object::getTopShape() const
301 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
302 if ( !aLabel.IsNull() )
304 Handle(TNaming_NamedShape) aNamedShape;
305 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
306 return aNamedShape->Get();
309 return TopoDS_Shape();
312 void HYDROData_Object::removeTopShape()
314 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
315 if ( !aLabel.IsNull() )
316 aLabel.ForgetAllAttributes();
319 TopoDS_Shape HYDROData_Object::getShape3D() const
321 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
322 if ( !aLabel.IsNull() )
324 Handle(TNaming_NamedShape) aNamedShape;
325 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
326 return aNamedShape->Get();
329 return TopoDS_Shape();
332 void HYDROData_Object::removeShape3D()
334 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
335 if ( !aLabel.IsNull() )
336 aLabel.ForgetAllAttributes();