Salome HOME
ce02f9d93f3e93caeaba8695522ede2d4e42aab3
[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 bool HYDROData_Object::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
98 {
99   if ( theBathymetry.IsNull() )
100     return false;
101   
102   Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
103   if ( IsEqual( aPrevBathymetry, theBathymetry ) )
104     return true;
105
106   SetReferenceObject( theBathymetry, DataTag_Bathymetry );
107
108   // Indicate model of the need to update object
109   SetToUpdate( true );
110
111   return true;
112 }
113
114
115 Handle(HYDROData_Bathymetry) HYDROData_Object::GetBathymetry() const
116 {
117   return Handle(HYDROData_Bathymetry)::DownCast( 
118            GetReferenceObject( DataTag_Bathymetry ) );
119 }
120
121 void HYDROData_Object::RemoveBathymetry()
122 {
123   Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
124   if ( aPrevBathymetry.IsNull() )
125     return;
126
127   ClearReferenceObjects( DataTag_Bathymetry );
128
129   // Indicate model of the need to update object
130   SetToUpdate( true );
131 }
132
133 TopoDS_Shape HYDROData_Object::getTopShape() const
134 {
135   TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
136   if ( !aLabel.IsNull() )
137   {
138     Handle(TNaming_NamedShape) aNamedShape;
139     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
140       return aNamedShape->Get();
141   }
142
143   return TopoDS_Shape();
144 }
145
146 void HYDROData_Object::removeTopShape()
147 {
148   TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
149   if ( !aLabel.IsNull() )
150     aLabel.ForgetAllAttributes();
151 }
152
153 TopoDS_Shape HYDROData_Object::getShape3D() const
154 {
155   TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
156   if ( !aLabel.IsNull() )
157   {
158     Handle(TNaming_NamedShape) aNamedShape;
159     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
160       return aNamedShape->Get();
161   }
162
163   return TopoDS_Shape();
164 }
165
166 void HYDROData_Object::removeShape3D()
167 {
168   TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
169   if ( !aLabel.IsNull() )
170     aLabel.ForgetAllAttributes();
171 }
172
173 void HYDROData_Object::SetFillingColor( const QColor& theColor )
174 {
175   SetColor( theColor, DataTag_FillingColor );
176 }
177
178 QColor HYDROData_Object::GetFillingColor() const
179 {
180   return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
181 }
182
183 void HYDROData_Object::SetBorderColor( const QColor& theColor )
184 {
185   SetColor( theColor, DataTag_BorderColor );
186 }
187
188 QColor HYDROData_Object::GetBorderColor() const
189 {
190   return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
191 }
192
193 QColor HYDROData_Object::DefaultFillingColor()
194 {
195   return QColor( Qt::yellow );
196 }
197
198 QColor HYDROData_Object::DefaultBorderColor()
199 {
200   return QColor( Qt::transparent );
201 }
202
203 QColor HYDROData_Object::getDefaultFillingColor() const
204 {
205   return DefaultFillingColor();
206 }
207
208 QColor HYDROData_Object::getDefaultBorderColor() const
209 {
210   return DefaultBorderColor();
211 }
212