Salome HOME
refs #430: incorrect coordinates in dump polyline
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
1
2 #include "HYDROData_Zone.h"
3
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_IAltitudeObject.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_NaturalObject.h"
8
9 #include <TNaming_Builder.hxx>
10 #include <TNaming_NamedShape.hxx>
11
12 #include <TopoDS_Shape.hxx>
13
14 #include <QStringList>
15
16 #include <TDataStd_Integer.hxx>
17
18 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
19 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
20
21
22 HYDROData_Zone::HYDROData_Zone()
23 : HYDROData_Entity()
24 {
25   myInterpolator = NULL;
26 }
27
28 HYDROData_Zone::~HYDROData_Zone()
29 {
30 }
31
32 bool HYDROData_Zone::CanBeUpdated() const
33 {
34   return false;
35 }
36
37 bool HYDROData_Zone::IsHas2dPrs() const
38 {
39   return true;
40 }
41
42 bool HYDROData_Zone::CanRemove()
43 {
44   return false;
45 }
46
47 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
48 {
49   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
50
51   HYDROData_SequenceOfObjects aSeqOfGeomObjects = GetGeometryObjects();
52   aResSeq.Append( aSeqOfGeomObjects );
53
54   return aResSeq;
55 }
56
57 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
58 {
59   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
60   aBuilder.Generated( theShape );
61 }
62
63 TopoDS_Shape HYDROData_Zone::GetShape() const
64 {
65   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
66   if ( !aLabel.IsNull() )
67   {
68     Handle(TNaming_NamedShape) aNamedShape;
69     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
70       return aNamedShape->Get();
71   }
72
73   return TopoDS_Shape();
74 }
75
76 bool HYDROData_Zone::IsMergingNeed() const
77 {
78   Handle(HYDROData_IAltitudeObject) aRefAltitude;
79
80   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
81   HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
82   for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
83   {
84     Handle(HYDROData_Object) aRefGeomObj =
85       Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
86     if ( aRefGeomObj.IsNull() )
87       continue;
88
89     Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
90     if ( anObjAltitude.IsNull() )
91       continue;
92
93     if ( aRefAltitude.IsNull() )
94     {
95       aRefAltitude = anObjAltitude;
96       continue;
97     }
98
99     if ( !IsEqual( aRefAltitude, anObjAltitude ) )
100       return true;
101   }
102
103   return false;
104 }
105
106 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
107 {
108   myInterpolator = theInter;
109 }
110
111 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
112 {
113   return myInterpolator;
114 }
115
116 void HYDROData_Zone::SetMergeType( const MergeAltitudesType& theType )
117 {
118   TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
119 }
120
121 HYDROData_Zone::MergeAltitudesType HYDROData_Zone::GetMergeType() const
122 {
123   MergeAltitudesType aMergeType = Merge_UNKNOWN;
124   
125   TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
126   if ( !aLabel.IsNull() )
127   {
128     Handle(TDataStd_Integer) anInt;
129     if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
130       aMergeType = (MergeAltitudesType)anInt->Get();
131   }
132
133   return aMergeType;
134 }
135
136 void HYDROData_Zone::SetMergeAltitude( const Handle(HYDROData_IAltitudeObject)& theAltitude )
137 {
138   SetReferenceObject( theAltitude, DataTag_MergeAltitude );
139 }
140
141 Handle(HYDROData_IAltitudeObject) HYDROData_Zone::GetMergeAltitude() const
142 {
143   return Handle(HYDROData_IAltitudeObject)::DownCast( 
144            GetReferenceObject( DataTag_MergeAltitude ) );
145 }
146
147 void HYDROData_Zone::RemoveMergeAltitude()
148 {
149   ClearReferenceObjects( DataTag_MergeAltitude );
150 }
151
152 bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
153 {
154   if ( theObject.IsNull() )
155     return false;
156   
157   if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
158        !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
159     return false; // Wrong type of object
160
161   if ( HasReference( theObject, DataTag_GeometryObject ) )
162     return false; // Object is already in reference list
163
164   AddReferenceObject( theObject, DataTag_GeometryObject );
165
166   return true;
167 }
168
169 HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
170 {
171   return GetReferenceObjects( DataTag_GeometryObject );
172 }
173
174 void HYDROData_Zone::RemoveGeometryObjects()
175 {
176   ClearReferenceObjects( DataTag_GeometryObject );
177 }
178
179
180