Salome HOME
merge BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_Zone.h"
20
21 #include "HYDROData_ArtificialObject.h"
22 #include "HYDROData_IAltitudeObject.h"
23 #include "HYDROData_Document.h"
24 #include "HYDROData_NaturalObject.h"
25 #include "HYDROData_LandCover.h"
26
27 #include <TNaming_Builder.hxx>
28 #include <TNaming_NamedShape.hxx>
29
30 #include <TopoDS_Shape.hxx>
31
32 #include <QStringList>
33
34 #include <TDataStd_Integer.hxx>
35
36 #define _DEVDEBUG_
37 #include "HYDRO_trace.hxx"
38
39 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
40 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
41
42
43 HYDROData_Zone::HYDROData_Zone()
44 : HYDROData_Entity( Geom_2d )
45 {
46   myInterpolator = NULL;
47 }
48
49 HYDROData_Zone::~HYDROData_Zone()
50 {
51 }
52
53 bool HYDROData_Zone::CanBeUpdated() const
54 {
55   return false;
56 }
57
58 bool HYDROData_Zone::IsHas2dPrs() const
59 {
60   return true;
61 }
62
63 bool HYDROData_Zone::CanRemove()
64 {
65   return false;
66 }
67
68 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
69 {
70   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
71
72   HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
73   aResSeq.Append( aSeqOfObjects );
74
75   return aResSeq;
76 }
77
78 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
79 {
80   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
81   aBuilder.Generated( theShape );
82 }
83
84 TopoDS_Shape HYDROData_Zone::GetShape() const
85 {
86   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
87   if ( !aLabel.IsNull() )
88   {
89     Handle(TNaming_NamedShape) aNamedShape;
90     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
91       return aNamedShape->Get();
92   }
93
94   return TopoDS_Shape();
95 }
96
97 bool HYDROData_Zone::IsMergingNeed() const
98 {
99   // Zones based on geometry objects (compare altitudes)
100   Handle(HYDROData_IAltitudeObject) aRefAltitude;
101
102   HYDROData_SequenceOfObjects anObjects = GetObjects();
103   HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
104   for ( ; anObjsIter.More(); anObjsIter.Next() )
105   {
106     Handle(HYDROData_Object) aRefGeomObj =
107       Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
108     if ( aRefGeomObj.IsNull() )
109       continue;
110
111     Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
112     if ( anObjAltitude.IsNull() )
113       continue;
114
115     if ( aRefAltitude.IsNull() )
116     {
117       aRefAltitude = anObjAltitude;
118       continue;
119     }
120
121     if ( !IsEqual( aRefAltitude, anObjAltitude ) )
122       return true;
123   }
124
125   // Zones based on land cover objects (compare Strickler types)
126   QString aRefStricklerType;
127
128   anObjsIter.Init( anObjects );
129   for ( ; anObjsIter.More(); anObjsIter.Next() )
130   {
131     Handle(HYDROData_LandCover) aRefLandCoverObj =
132       Handle(HYDROData_LandCover)::DownCast( anObjsIter.Value() );
133     if ( aRefLandCoverObj.IsNull() )
134       continue;
135
136     QString aStricklerType = aRefLandCoverObj->GetStricklerType();
137     
138     if ( aRefStricklerType.isNull() )
139     {
140       aRefStricklerType = aStricklerType;
141       continue;
142     }
143
144     if ( aRefStricklerType != aStricklerType )
145       return true;
146   }
147
148
149   return false;
150 }
151
152 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
153 {
154   myInterpolator = theInter;
155 }
156
157 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
158 {
159   return myInterpolator;
160 }
161
162 void HYDROData_Zone::SetMergeType( const MergeType& theType )
163 {
164   TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
165 }
166
167 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
168 {
169   MergeType aMergeType = Merge_UNKNOWN;
170   
171   TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
172   if ( !aLabel.IsNull() )
173   {
174     Handle(TDataStd_Integer) anInt;
175     if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
176       aMergeType = (MergeType)anInt->Get();
177   }
178
179   return aMergeType;
180 }
181
182 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
183 {
184   //DEBTRACE("HYDROData_Zone::SetMergeObject");
185   SetReferenceObject( theObject, DataTag_MergeObject );
186 }
187
188 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
189 {
190   return Handle(HYDROData_Entity)::DownCast( 
191            GetReferenceObject( DataTag_MergeObject ) );
192 }
193
194 void HYDROData_Zone::RemoveMergeObject()
195 {
196   ClearReferenceObjects( DataTag_MergeObject );
197 }
198
199 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
200 {
201   if ( theObject.IsNull() )
202     return false;
203   
204   if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
205        !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) && 
206        !theObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) )
207     return false; // Wrong type of object
208
209   if ( HasReference( theObject, DataTag_Object ) )
210     return false; // Object is already in reference list
211
212   AddReferenceObject( theObject, DataTag_Object );
213
214   return true;
215 }
216
217 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
218 {
219   return GetReferenceObjects( DataTag_Object );
220 }
221
222 void HYDROData_Zone::RemoveObjects()
223 {
224   ClearReferenceObjects( DataTag_Object );
225 }
226
227 bool HYDROData_Zone::IsSubmersible() const
228 {
229   HYDROData_SequenceOfObjects anObjects = GetObjects();
230   HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
231   for ( ; anObjsIter.More(); anObjsIter.Next() )
232   {
233     Handle(HYDROData_Object) aRefGeomObj =
234       Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
235     if ( aRefGeomObj.IsNull() )
236       continue;
237
238     if( !aRefGeomObj->IsSubmersible() )
239       return false; //if one of geometry objects is not submersible the zone is considered as not submersible
240   }
241   return true;
242 }
243