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