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 bool HYDROData_Object::SetAltitudeObject(
136 const Handle(HYDROData_IAltitudeObject)& theAltitude )
138 if ( theAltitude.IsNull() )
141 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
142 if ( IsEqual( aPrevAltitude, theAltitude ) )
145 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
147 // Indicate model of the need to update object
153 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
155 return Handle(HYDROData_IAltitudeObject)::DownCast(
156 GetReferenceObject( DataTag_AltitudeObject ) );
159 void HYDROData_Object::RemoveAltitudeObject()
161 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
162 if ( aPrevAltitude.IsNull() )
165 ClearReferenceObjects( DataTag_AltitudeObject );
167 // Indicate model of the need to update object
171 void HYDROData_Object::SetFillingColor( const QColor& theColor )
173 SetColor( theColor, DataTag_FillingColor );
176 QColor HYDROData_Object::GetFillingColor() const
178 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
181 void HYDROData_Object::SetBorderColor( const QColor& theColor )
183 SetColor( theColor, DataTag_BorderColor );
186 QColor HYDROData_Object::GetBorderColor() const
188 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
191 QColor HYDROData_Object::DefaultFillingColor()
193 return QColor( Qt::yellow );
196 QColor HYDROData_Object::DefaultBorderColor()
198 return QColor( Qt::transparent );
201 QColor HYDROData_Object::getDefaultFillingColor() const
203 return DefaultFillingColor();
206 QColor HYDROData_Object::getDefaultBorderColor() const
208 return DefaultBorderColor();
211 ObjectKind HYDROData_Object::getAltitudeObjectType() const
216 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
218 Handle(HYDROData_IAltitudeObject) anObject;
220 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
221 if ( !aLabel.IsNull() )
223 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
224 if ( !aChildLabel.IsNull() )
226 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
227 HYDROData_Iterator::Object( aChildLabel ) );
234 void HYDROData_Object::checkAndSetAltitudeObject()
236 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
238 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
239 if ( anAltitudeObjectType == KIND_UNKNOWN )
240 return; // No need to create altitude object
242 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
243 if ( !aLabel.IsNull() )
246 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
248 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
249 Handle(HYDROData_IAltitudeObject)::DownCast(
250 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
252 QString anAltitudePref = GetName() + "_Altitude";
253 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
254 anAltitudeObject->SetName( anAltitudeName );
256 SetAltitudeObject( anAltitudeObject );
259 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
261 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
263 Handle(HYDROData_ShapesGroup) aNewGroup =
264 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
265 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
270 void HYDROData_Object::createGroupObjects()
274 void HYDROData_Object::removeGroupObjects()
276 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
277 if ( !aLabel.IsNull() )
278 aLabel.ForgetAllAttributes();
281 TopoDS_Shape HYDROData_Object::getTopShape() const
283 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
284 if ( !aLabel.IsNull() )
286 Handle(TNaming_NamedShape) aNamedShape;
287 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
288 return aNamedShape->Get();
291 return TopoDS_Shape();
294 void HYDROData_Object::removeTopShape()
296 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
297 if ( !aLabel.IsNull() )
298 aLabel.ForgetAllAttributes();
301 TopoDS_Shape HYDROData_Object::getShape3D() const
303 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
304 if ( !aLabel.IsNull() )
306 Handle(TNaming_NamedShape) aNamedShape;
307 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
308 return aNamedShape->Get();
311 return TopoDS_Shape();
314 void HYDROData_Object::removeShape3D()
316 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
317 if ( !aLabel.IsNull() )
318 aLabel.ForgetAllAttributes();