Salome HOME
33a7cd2fc782af07c0afb5b1c4c43965987b1811
[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 aSeqOfObjects = GetObjects();
69   aResSeq.Append( aSeqOfObjects );
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   // Zones based on geometry objects (compare altitudes)
96   Handle(HYDROData_IAltitudeObject) aRefAltitude;
97
98   HYDROData_SequenceOfObjects anObjects = GetObjects();
99   HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
100   for ( ; anObjsIter.More(); anObjsIter.Next() )
101   {
102     Handle(HYDROData_Object) aRefGeomObj =
103       Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
104     if ( aRefGeomObj.IsNull() )
105       continue;
106
107     Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
108     if ( anObjAltitude.IsNull() )
109       continue;
110
111     if ( aRefAltitude.IsNull() )
112     {
113       aRefAltitude = anObjAltitude;
114       continue;
115     }
116
117     if ( !IsEqual( aRefAltitude, anObjAltitude ) )
118       return true;
119   }
120
121   return false;
122 }
123
124 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
125 {
126   myInterpolator = theInter;
127 }
128
129 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
130 {
131   return myInterpolator;
132 }
133
134 void HYDROData_Zone::SetMergeType( const MergeType& theType )
135 {
136   TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
137 }
138
139 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
140 {
141   MergeType aMergeType = Merge_UNKNOWN;
142   
143   TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
144   if ( !aLabel.IsNull() )
145   {
146     Handle(TDataStd_Integer) anInt;
147     if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
148       aMergeType = (MergeType)anInt->Get();
149   }
150
151   return aMergeType;
152 }
153
154 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
155 {
156   SetReferenceObject( theObject, DataTag_MergeObject );
157 }
158
159 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
160 {
161   return Handle(HYDROData_Entity)::DownCast( 
162            GetReferenceObject( DataTag_MergeObject ) );
163 }
164
165 void HYDROData_Zone::RemoveMergeObject()
166 {
167   ClearReferenceObjects( DataTag_MergeObject );
168 }
169
170 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
171 {
172   if ( theObject.IsNull() )
173     return false;
174   
175   if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
176        !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
177     return false; // Wrong type of object
178
179   if ( HasReference( theObject, DataTag_Object ) )
180     return false; // Object is already in reference list
181
182   AddReferenceObject( theObject, DataTag_Object );
183
184   return true;
185 }
186
187 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
188 {
189   return GetReferenceObjects( DataTag_Object );
190 }
191
192 void HYDROData_Zone::RemoveObjects()
193 {
194   ClearReferenceObjects( DataTag_Object );
195 }
196
197 bool HYDROData_Zone::IsSubmersible() const
198 {
199   HYDROData_SequenceOfObjects anObjects = GetObjects();
200   HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
201   for ( ; anObjsIter.More(); anObjsIter.Next() )
202   {
203     Handle(HYDROData_Object) aRefGeomObj =
204       Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
205     if ( aRefGeomObj.IsNull() )
206       continue;
207
208     if( !aRefGeomObj->IsSubmersible() )
209       return false; //if one of geometry objects is not submersible the zone is considered as not submersible
210   }
211   return true;
212 }
213