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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_Zone.h"
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>
30 #include "HYDRO_trace.hxx"
32 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
35 HYDROData_Zone::HYDROData_Zone()
36 : HYDROData_Entity( Geom_2d )
38 myInterpolator = NULL;
41 HYDROData_Zone::~HYDROData_Zone()
45 bool HYDROData_Zone::CanBeUpdated() const
50 bool HYDROData_Zone::IsHas2dPrs() const
55 bool HYDROData_Zone::CanRemove()
60 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
62 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
64 HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
65 aResSeq.Append( aSeqOfObjects );
70 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
72 HYDROData_Entity::SetShape( DataTag_Shape, theShape );
75 TopoDS_Shape HYDROData_Zone::GetShape() const
77 return HYDROData_Entity::GetShape( DataTag_Shape );
80 bool HYDROData_Zone::IsMergingNeed() const
82 // Zones based on geometry objects (compare altitudes)
83 Handle(HYDROData_IAltitudeObject) aRefAltitude;
85 HYDROData_SequenceOfObjects anObjects = GetObjects();
86 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
87 for ( ; anObjsIter.More(); anObjsIter.Next() )
89 Handle(HYDROData_Object) aRefGeomObj =
90 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
91 if ( aRefGeomObj.IsNull() )
94 Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
95 if ( anObjAltitude.IsNull() )
98 if ( aRefAltitude.IsNull() )
100 aRefAltitude = anObjAltitude;
104 if ( !IsEqual( aRefAltitude, anObjAltitude ) )
111 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
113 myInterpolator = theInter;
116 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
118 return myInterpolator;
121 void HYDROData_Zone::SetMergeType( const MergeType& theType )
123 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
124 anAttr->SetID(TDataStd_Integer::GetID());
127 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
129 MergeType aMergeType = Merge_UNKNOWN;
131 TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
132 if ( !aLabel.IsNull() )
134 Handle(TDataStd_Integer) anInt;
135 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
136 aMergeType = (MergeType)anInt->Get();
142 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
144 //DEBTRACE("HYDROData_Zone::SetMergeObject");
145 SetReferenceObject( theObject, DataTag_MergeObject );
148 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
150 return GetReferenceObject( DataTag_MergeObject );
153 void HYDROData_Zone::RemoveMergeObject()
155 ClearReferenceObjects( DataTag_MergeObject );
158 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
160 if ( theObject.IsNull() )
163 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
164 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
165 return false; // Wrong type of object
167 if ( HasReference( theObject, DataTag_Object ) )
168 return false; // Object is already in reference list
170 AddReferenceObject( theObject, DataTag_Object );
175 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
177 return GetReferenceObjects( DataTag_Object );
180 void HYDROData_Zone::RemoveObjects()
182 ClearReferenceObjects( DataTag_Object );
185 bool HYDROData_Zone::IsSubmersible() const
187 HYDROData_SequenceOfObjects anObjects = GetObjects();
188 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
189 for ( ; anObjsIter.More(); anObjsIter.Next() )
191 Handle(HYDROData_Object) aRefGeomObj =
192 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
193 if ( aRefGeomObj.IsNull() )
196 if( !aRefGeomObj->IsSubmersible() )
197 return false; //if one of geometry objects is not submersible the zone is considered as not submersible