Salome HOME
524916fcef7ebc3d450f9a587fa4e9182b607208
[modules/hydro.git] / src / HYDROData / HYDROData_Object.cxx
1
2 #include "HYDROData_Object.h"
3
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_DummyObject3D.h"
6 #include "HYDROData_Iterator.h"
7
8 #include <TNaming_Builder.hxx>
9 #include <TNaming_NamedShape.hxx>
10
11 #include <TopoDS_Shape.hxx>
12
13 #include <QColor>
14
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
17
18 HYDROData_Object::HYDROData_Object()
19 : HYDROData_Entity()
20 {
21 }
22
23 HYDROData_Object::~HYDROData_Object()
24 {
25 }
26
27 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
28 {
29   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
30
31   Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
32   if ( !aRefBathymetry.IsNull() )
33     aResSeq.Append( aRefBathymetry );
34
35   return aResSeq;
36 }
37
38 void HYDROData_Object::SetToUpdate( bool theFlag )
39 {
40   HYDROData_Entity::SetToUpdate( theFlag );
41
42   Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
43   if ( !anObject3D.IsNull() )
44     anObject3D->SetToUpdate( theFlag );
45 }
46
47 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
48 {
49   TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
50   aBuilder.Generated( theShape );
51 }
52
53 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
54 {
55   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
56   aBuilder.Generated( theShape );
57   
58   // Check the object 3D existance
59   checkAndSetObject3D();
60 }
61
62 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
63 {
64   Handle(HYDROData_DummyObject3D) anObject;
65   
66   TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
67   if ( !aLabel.IsNull() )
68   {
69     TDF_Label aChildLabel = aLabel.FindChild( 0, false );
70     if ( !aChildLabel.IsNull() )
71     {
72       anObject = Handle(HYDROData_DummyObject3D)::DownCast(
73         HYDROData_Iterator::Object( aChildLabel ) );
74     }
75   }
76
77   return anObject;
78 }
79
80 void HYDROData_Object::checkAndSetObject3D()
81 {
82   TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
83   if ( !aLabel.IsNull() )
84     return;
85
86   TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
87   HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
88 }
89
90 void HYDROData_Object::Update()
91 {
92   HYDROData_Entity::Update();
93   removeTopShape();
94   removeShape3D();
95 }
96
97 void HYDROData_Object::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
98 {
99   SetReferenceObject( theBathymetry, DataTag_Bathymetry );
100   SetToUpdate( true );
101 }
102
103 Handle(HYDROData_Bathymetry) HYDROData_Object::GetBathymetry() const
104 {
105   return Handle(HYDROData_Bathymetry)::DownCast( 
106            GetReferenceObject( DataTag_Bathymetry ) );
107 }
108
109 void HYDROData_Object::RemoveBathymetry()
110 {
111   ClearReferenceObjects( DataTag_Bathymetry );
112   SetToUpdate( true );
113 }
114
115 TopoDS_Shape HYDROData_Object::getTopShape() const
116 {
117   TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
118   if ( !aLabel.IsNull() )
119   {
120     Handle(TNaming_NamedShape) aNamedShape;
121     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
122       return aNamedShape->Get();
123   }
124
125   return TopoDS_Shape();
126 }
127
128 void HYDROData_Object::removeTopShape()
129 {
130   TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
131   if ( !aLabel.IsNull() )
132     aLabel.ForgetAllAttributes();
133 }
134
135 TopoDS_Shape HYDROData_Object::getShape3D() const
136 {
137   TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
138   if ( !aLabel.IsNull() )
139   {
140     Handle(TNaming_NamedShape) aNamedShape;
141     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
142       return aNamedShape->Get();
143   }
144
145   return TopoDS_Shape();
146 }
147
148 void HYDROData_Object::removeShape3D()
149 {
150   TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
151   if ( !aLabel.IsNull() )
152     aLabel.ForgetAllAttributes();
153 }
154
155 void HYDROData_Object::SetFillingColor( const QColor& theColor )
156 {
157   SetColor( theColor, DataTag_FillingColor );
158 }
159
160 QColor HYDROData_Object::GetFillingColor() const
161 {
162   return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
163 }
164
165 void HYDROData_Object::SetBorderColor( const QColor& theColor )
166 {
167   SetColor( theColor, DataTag_BorderColor );
168 }
169
170 QColor HYDROData_Object::GetBorderColor() const
171 {
172   return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
173 }
174
175 QColor HYDROData_Object::DefaultFillingColor()
176 {
177   return QColor( Qt::yellow );
178 }
179
180 QColor HYDROData_Object::DefaultBorderColor()
181 {
182   return QColor( Qt::transparent );
183 }
184
185 QColor HYDROData_Object::getDefaultFillingColor() const
186 {
187   return DefaultFillingColor();
188 }
189
190 QColor HYDROData_Object::getDefaultBorderColor() const
191 {
192   return DefaultBorderColor();
193 }
194