Salome HOME
patch for crash in channel
[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::CanRemove()
38 {
39   return false;
40 }
41
42 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
43 {
44   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
45
46   HYDROData_SequenceOfObjects aSeqOfGeomObjects = GetGeometryObjects();
47   aResSeq.Append( aSeqOfGeomObjects );
48
49   return aResSeq;
50 }
51
52 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
53 {
54   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
55   aBuilder.Generated( theShape );
56 }
57
58 TopoDS_Shape HYDROData_Zone::GetShape() const
59 {
60   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
61   if ( !aLabel.IsNull() )
62   {
63     Handle(TNaming_NamedShape) aNamedShape;
64     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
65       return aNamedShape->Get();
66   }
67
68   return TopoDS_Shape();
69 }
70
71 bool HYDROData_Zone::IsMergingNeed() const
72 {
73   Handle(HYDROData_IAltitudeObject) aRefAltitude;
74
75   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
76   HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
77   for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
78   {
79     Handle(HYDROData_Object) aRefGeomObj =
80       Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
81     if ( aRefGeomObj.IsNull() )
82       continue;
83
84     Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
85     if ( anObjAltitude.IsNull() )
86       continue;
87
88     if ( aRefAltitude.IsNull() )
89     {
90       aRefAltitude = anObjAltitude;
91       continue;
92     }
93
94     if ( !IsEqual( aRefAltitude, anObjAltitude ) )
95       return true;
96   }
97
98   return false;
99 }
100
101 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
102 {
103   myInterpolator = theInter;
104 }
105
106 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
107 {
108   return myInterpolator;
109 }
110
111 void HYDROData_Zone::SetMergeType( const MergeAltitudesType& theType )
112 {
113   TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
114 }
115
116 HYDROData_Zone::MergeAltitudesType HYDROData_Zone::GetMergeType() const
117 {
118   MergeAltitudesType aMergeType = Merge_UNKNOWN;
119   
120   TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
121   if ( !aLabel.IsNull() )
122   {
123     Handle(TDataStd_Integer) anInt;
124     if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
125       aMergeType = (MergeAltitudesType)anInt->Get();
126   }
127
128   return aMergeType;
129 }
130
131 void HYDROData_Zone::SetMergeAltitude( const Handle(HYDROData_IAltitudeObject)& theAltitude )
132 {
133   SetReferenceObject( theAltitude, DataTag_MergeAltitude );
134 }
135
136 Handle(HYDROData_IAltitudeObject) HYDROData_Zone::GetMergeAltitude() const
137 {
138   return Handle(HYDROData_IAltitudeObject)::DownCast( 
139            GetReferenceObject( DataTag_MergeAltitude ) );
140 }
141
142 void HYDROData_Zone::RemoveMergeAltitude()
143 {
144   ClearReferenceObjects( DataTag_MergeAltitude );
145 }
146
147 bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
148 {
149   if ( theObject.IsNull() )
150     return false;
151   
152   if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
153        !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
154     return false; // Wrong type of object
155
156   if ( HasReference( theObject, DataTag_GeometryObject ) )
157     return false; // Object is already in reference list
158
159   AddReferenceObject( theObject, DataTag_GeometryObject );
160
161   return true;
162 }
163
164 HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
165 {
166   return GetReferenceObjects( DataTag_GeometryObject );
167 }
168
169 void HYDROData_Zone::RemoveGeometryObjects()
170 {
171   ClearReferenceObjects( DataTag_GeometryObject );
172 }
173
174
175