Salome HOME
Merge remote-tracking branch 'origin/BR_LAND_COVER_MAP' into BR_LAND_COVER_REMOVING
[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 <QStringList>
26 #include <TDataStd_Integer.hxx>
27 #include <TopoDS_Shape.hxx>
28
29 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
30 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
31
32
33 HYDROData_Zone::HYDROData_Zone()
34 : HYDROData_Entity( Geom_2d )
35 {
36   myInterpolator = NULL;
37 }
38
39 HYDROData_Zone::~HYDROData_Zone()
40 {
41 }
42
43 bool HYDROData_Zone::CanBeUpdated() const
44 {
45   return false;
46 }
47
48 bool HYDROData_Zone::IsHas2dPrs() const
49 {
50   return true;
51 }
52
53 bool HYDROData_Zone::CanRemove()
54 {
55   return false;
56 }
57
58 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
59 {
60   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
61
62   HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
63   aResSeq.Append( aSeqOfObjects );
64
65   return aResSeq;
66 }
67
68 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
69 {
70   HYDROData_Entity::SetShape( DataTag_Shape, theShape );
71 }
72
73 TopoDS_Shape HYDROData_Zone::GetShape() const
74 {
75   return HYDROData_Entity::GetShape( DataTag_Shape );
76 }
77
78 bool HYDROData_Zone::IsMergingNeed() const
79 {
80   // Zones based on geometry objects (compare altitudes)
81   Handle(HYDROData_IAltitudeObject) aRefAltitude;
82
83   HYDROData_SequenceOfObjects anObjects = GetObjects();
84   HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
85   for ( ; anObjsIter.More(); anObjsIter.Next() )
86   {
87     Handle(HYDROData_Object) aRefGeomObj =
88       Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
89     if ( aRefGeomObj.IsNull() )
90       continue;
91
92     Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
93     if ( anObjAltitude.IsNull() )
94       continue;
95
96     if ( aRefAltitude.IsNull() )
97     {
98       aRefAltitude = anObjAltitude;
99       continue;
100     }
101
102     if ( !IsEqual( aRefAltitude, anObjAltitude ) )
103       return true;
104   }
105
106   return false;
107 }
108
109 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
110 {
111   myInterpolator = theInter;
112 }
113
114 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
115 {
116   return myInterpolator;
117 }
118
119 void HYDROData_Zone::SetMergeType( const MergeType& theType )
120 {
121   TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
122 }
123
124 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
125 {
126   MergeType aMergeType = Merge_UNKNOWN;
127   
128   TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
129   if ( !aLabel.IsNull() )
130   {
131     Handle(TDataStd_Integer) anInt;
132     if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
133       aMergeType = (MergeType)anInt->Get();
134   }
135
136   return aMergeType;
137 }
138
139 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
140 {
141   SetReferenceObject( theObject, DataTag_MergeObject );
142 }
143
144 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
145 {
146   return Handle(HYDROData_Entity)::DownCast( 
147            GetReferenceObject( DataTag_MergeObject ) );
148 }
149
150 void HYDROData_Zone::RemoveMergeObject()
151 {
152   ClearReferenceObjects( DataTag_MergeObject );
153 }
154
155 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
156 {
157   if ( theObject.IsNull() )
158     return false;
159   
160   if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
161        !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
162     return false; // Wrong type of object
163
164   if ( HasReference( theObject, DataTag_Object ) )
165     return false; // Object is already in reference list
166
167   AddReferenceObject( theObject, DataTag_Object );
168
169   return true;
170 }
171
172 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
173 {
174   return GetReferenceObjects( DataTag_Object );
175 }
176
177 void HYDROData_Zone::RemoveObjects()
178 {
179   ClearReferenceObjects( DataTag_Object );
180 }
181
182 bool HYDROData_Zone::IsSubmersible() const
183 {
184   HYDROData_SequenceOfObjects anObjects = GetObjects();
185   HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
186   for ( ; anObjsIter.More(); anObjsIter.Next() )
187   {
188     Handle(HYDROData_Object) aRefGeomObj =
189       Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
190     if ( aRefGeomObj.IsNull() )
191       continue;
192
193     if( !aRefGeomObj->IsSubmersible() )
194       return false; //if one of geometry objects is not submersible the zone is considered as not submersible
195   }
196   return true;
197 }
198