2 #include "HYDROData_Object.h"
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_DummyObject3D.h"
6 #include "HYDROData_ShapesGroup.h"
7 #include "HYDROData_Iterator.h"
9 #include <TNaming_Builder.hxx>
10 #include <TNaming_NamedShape.hxx>
12 #include <TopoDS_Shape.hxx>
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
19 HYDROData_Object::HYDROData_Object()
24 HYDROData_Object::~HYDROData_Object()
28 void HYDROData_Object::SetName( const QString& theName )
30 QString anOldObjName = GetName();
31 if ( anOldObjName != theName )
33 HYDROData_SequenceOfObjects aGroups = GetGroups();
34 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
35 for ( ; anIter.More(); anIter.Next() )
37 Handle(HYDROData_ShapesGroup) aGroup =
38 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
39 if ( aGroup.IsNull() )
42 QString aGroupName = aGroup->GetName();
43 if ( anOldObjName.isEmpty() )
44 aGroupName.prepend( theName + "_" );
45 else if ( aGroupName.startsWith( anOldObjName ) )
46 aGroupName.replace( anOldObjName, theName );
50 aGroup->SetName( aGroupName );
54 HYDROData_Entity::SetName( theName );
57 void HYDROData_Object::Update()
59 HYDROData_Entity::Update();
65 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
67 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
69 Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
70 if ( !aRefBathymetry.IsNull() )
71 aResSeq.Append( aRefBathymetry );
76 void HYDROData_Object::SetToUpdate( bool theFlag )
78 HYDROData_Entity::SetToUpdate( theFlag );
80 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
81 if ( !anObject3D.IsNull() )
82 anObject3D->SetToUpdate( theFlag );
85 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
87 TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
88 aBuilder.Generated( theShape );
91 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
93 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
94 aBuilder.Generated( theShape );
96 // Check the object 3D existance
97 checkAndSetObject3D();
100 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
102 Handle(HYDROData_DummyObject3D) anObject;
104 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
105 if ( !aLabel.IsNull() )
107 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
108 if ( !aChildLabel.IsNull() )
110 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
111 HYDROData_Iterator::Object( aChildLabel ) );
118 void HYDROData_Object::checkAndSetObject3D()
120 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
121 if ( !aLabel.IsNull() )
124 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
125 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
128 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
130 return GetReferenceObjects( DataTag_EdgesGroup );
133 bool HYDROData_Object::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
135 if ( theBathymetry.IsNull() )
138 Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
139 if ( IsEqual( aPrevBathymetry, theBathymetry ) )
142 SetReferenceObject( theBathymetry, DataTag_Bathymetry );
144 // Indicate model of the need to update object
151 Handle(HYDROData_Bathymetry) HYDROData_Object::GetBathymetry() const
153 return Handle(HYDROData_Bathymetry)::DownCast(
154 GetReferenceObject( DataTag_Bathymetry ) );
157 void HYDROData_Object::RemoveBathymetry()
159 Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
160 if ( aPrevBathymetry.IsNull() )
163 ClearReferenceObjects( DataTag_Bathymetry );
165 // Indicate model of the need to update object
169 void HYDROData_Object::SetFillingColor( const QColor& theColor )
171 SetColor( theColor, DataTag_FillingColor );
174 QColor HYDROData_Object::GetFillingColor() const
176 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
179 void HYDROData_Object::SetBorderColor( const QColor& theColor )
181 SetColor( theColor, DataTag_BorderColor );
184 QColor HYDROData_Object::GetBorderColor() const
186 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
189 QColor HYDROData_Object::DefaultFillingColor()
191 return QColor( Qt::yellow );
194 QColor HYDROData_Object::DefaultBorderColor()
196 return QColor( Qt::transparent );
199 QColor HYDROData_Object::getDefaultFillingColor() const
201 return DefaultFillingColor();
204 QColor HYDROData_Object::getDefaultBorderColor() const
206 return DefaultBorderColor();
209 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
211 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
213 Handle(HYDROData_ShapesGroup) aNewGroup =
214 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
215 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
220 void HYDROData_Object::createGroupObjects()
224 void HYDROData_Object::removeGroupObjects()
226 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
227 if ( !aLabel.IsNull() )
228 aLabel.ForgetAllAttributes();
231 TopoDS_Shape HYDROData_Object::getTopShape() const
233 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
234 if ( !aLabel.IsNull() )
236 Handle(TNaming_NamedShape) aNamedShape;
237 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
238 return aNamedShape->Get();
241 return TopoDS_Shape();
244 void HYDROData_Object::removeTopShape()
246 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
247 if ( !aLabel.IsNull() )
248 aLabel.ForgetAllAttributes();
251 TopoDS_Shape HYDROData_Object::getShape3D() const
253 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
254 if ( !aLabel.IsNull() )
256 Handle(TNaming_NamedShape) aNamedShape;
257 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
258 return aNamedShape->Get();
261 return TopoDS_Shape();
264 void HYDROData_Object::removeShape3D()
266 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
267 if ( !aLabel.IsNull() )
268 aLabel.ForgetAllAttributes();