Salome HOME
Feature #233: Export of groups.
[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_ShapesGroup.h"
7 #include "HYDROData_Iterator.h"
8
9 #include <TNaming_Builder.hxx>
10 #include <TNaming_NamedShape.hxx>
11
12 #include <TopoDS_Shape.hxx>
13
14 #include <QColor>
15
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
18
19 HYDROData_Object::HYDROData_Object()
20 : HYDROData_Entity()
21 {
22 }
23
24 HYDROData_Object::~HYDROData_Object()
25 {
26 }
27
28 void HYDROData_Object::Update()
29 {
30   HYDROData_Entity::Update();
31   removeTopShape();
32   removeShape3D();
33   removeGroupObjects();
34 }
35
36 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
37 {
38   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
39
40   Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
41   if ( !aRefBathymetry.IsNull() )
42     aResSeq.Append( aRefBathymetry );
43
44   return aResSeq;
45 }
46
47 void HYDROData_Object::SetToUpdate( bool theFlag )
48 {
49   HYDROData_Entity::SetToUpdate( theFlag );
50
51   Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
52   if ( !anObject3D.IsNull() )
53     anObject3D->SetToUpdate( theFlag );
54 }
55
56 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
57 {
58   TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
59   aBuilder.Generated( theShape );
60 }
61
62 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
63 {
64   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
65   aBuilder.Generated( theShape );
66   
67   // Check the object 3D existance
68   checkAndSetObject3D();
69 }
70
71 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
72 {
73   Handle(HYDROData_DummyObject3D) anObject;
74   
75   TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
76   if ( !aLabel.IsNull() )
77   {
78     TDF_Label aChildLabel = aLabel.FindChild( 0, false );
79     if ( !aChildLabel.IsNull() )
80     {
81       anObject = Handle(HYDROData_DummyObject3D)::DownCast(
82         HYDROData_Iterator::Object( aChildLabel ) );
83     }
84   }
85
86   return anObject;
87 }
88
89 void HYDROData_Object::checkAndSetObject3D()
90 {
91   TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
92   if ( !aLabel.IsNull() )
93     return;
94
95   TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
96   HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
97 }
98
99 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
100 {
101   return GetReferenceObjects( DataTag_EdgesGroup );
102 }
103
104 bool HYDROData_Object::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
105 {
106   if ( theBathymetry.IsNull() )
107     return false;
108   
109   Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
110   if ( IsEqual( aPrevBathymetry, theBathymetry ) )
111     return true;
112
113   SetReferenceObject( theBathymetry, DataTag_Bathymetry );
114
115   // Indicate model of the need to update object
116   SetToUpdate( true );
117
118   return true;
119 }
120
121
122 Handle(HYDROData_Bathymetry) HYDROData_Object::GetBathymetry() const
123 {
124   return Handle(HYDROData_Bathymetry)::DownCast( 
125            GetReferenceObject( DataTag_Bathymetry ) );
126 }
127
128 void HYDROData_Object::RemoveBathymetry()
129 {
130   Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
131   if ( aPrevBathymetry.IsNull() )
132     return;
133
134   ClearReferenceObjects( DataTag_Bathymetry );
135
136   // Indicate model of the need to update object
137   SetToUpdate( true );
138 }
139
140 void HYDROData_Object::SetFillingColor( const QColor& theColor )
141 {
142   SetColor( theColor, DataTag_FillingColor );
143 }
144
145 QColor HYDROData_Object::GetFillingColor() const
146 {
147   return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
148 }
149
150 void HYDROData_Object::SetBorderColor( const QColor& theColor )
151 {
152   SetColor( theColor, DataTag_BorderColor );
153 }
154
155 QColor HYDROData_Object::GetBorderColor() const
156 {
157   return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
158 }
159
160 QColor HYDROData_Object::DefaultFillingColor()
161 {
162   return QColor( Qt::yellow );
163 }
164
165 QColor HYDROData_Object::DefaultBorderColor()
166 {
167   return QColor( Qt::transparent );
168 }
169
170 QColor HYDROData_Object::getDefaultFillingColor() const
171 {
172   return DefaultFillingColor();
173 }
174
175 QColor HYDROData_Object::getDefaultBorderColor() const
176 {
177   return DefaultBorderColor();
178 }
179
180 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
181 {
182   TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
183
184   Handle(HYDROData_ShapesGroup) aNewGroup =
185     Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
186   AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
187
188   return aNewGroup;
189 }
190
191 void HYDROData_Object::createGroupObjects()
192 {
193 }
194
195 void HYDROData_Object::removeGroupObjects()
196 {
197   TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
198   if ( !aLabel.IsNull() )
199     aLabel.ForgetAllAttributes();
200 }
201
202 TopoDS_Shape HYDROData_Object::getTopShape() const
203 {
204   TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
205   if ( !aLabel.IsNull() )
206   {
207     Handle(TNaming_NamedShape) aNamedShape;
208     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
209       return aNamedShape->Get();
210   }
211
212   return TopoDS_Shape();
213 }
214
215 void HYDROData_Object::removeTopShape()
216 {
217   TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
218   if ( !aLabel.IsNull() )
219     aLabel.ForgetAllAttributes();
220 }
221
222 TopoDS_Shape HYDROData_Object::getShape3D() const
223 {
224   TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
225   if ( !aLabel.IsNull() )
226   {
227     Handle(TNaming_NamedShape) aNamedShape;
228     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
229       return aNamedShape->Get();
230   }
231
232   return TopoDS_Shape();
233 }
234
235 void HYDROData_Object::removeShape3D()
236 {
237   TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
238   if ( !aLabel.IsNull() )
239     aLabel.ForgetAllAttributes();
240 }
241