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