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