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>
29 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
30 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
33 HYDROData_Zone::HYDROData_Zone()
34 : HYDROData_Entity( Geom_2d )
36 myInterpolator = NULL;
39 HYDROData_Zone::~HYDROData_Zone()
43 bool HYDROData_Zone::CanBeUpdated() const
48 bool HYDROData_Zone::IsHas2dPrs() const
53 bool HYDROData_Zone::CanRemove()
58 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
60 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
62 HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
63 aResSeq.Append( aSeqOfObjects );
68 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
70 HYDROData_Entity::SetShape( DataTag_Shape, theShape );
73 TopoDS_Shape HYDROData_Zone::GetShape() const
75 return HYDROData_Entity::GetShape( DataTag_Shape );
78 bool HYDROData_Zone::IsMergingNeed() const
80 // Zones based on geometry objects (compare altitudes)
81 Handle(HYDROData_IAltitudeObject) aRefAltitude;
83 HYDROData_SequenceOfObjects anObjects = GetObjects();
84 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
85 for ( ; anObjsIter.More(); anObjsIter.Next() )
87 Handle(HYDROData_Object) aRefGeomObj =
88 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
89 if ( aRefGeomObj.IsNull() )
92 Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
93 if ( anObjAltitude.IsNull() )
96 if ( aRefAltitude.IsNull() )
98 aRefAltitude = anObjAltitude;
102 if ( !IsEqual( aRefAltitude, anObjAltitude ) )
109 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
111 myInterpolator = theInter;
114 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
116 return myInterpolator;
119 void HYDROData_Zone::SetMergeType( const MergeType& theType )
121 TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
124 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
126 MergeType aMergeType = Merge_UNKNOWN;
128 TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
129 if ( !aLabel.IsNull() )
131 Handle(TDataStd_Integer) anInt;
132 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
133 aMergeType = (MergeType)anInt->Get();
139 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
141 SetReferenceObject( theObject, DataTag_MergeObject );
144 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
146 return Handle(HYDROData_Entity)::DownCast(
147 GetReferenceObject( DataTag_MergeObject ) );
150 void HYDROData_Zone::RemoveMergeObject()
152 ClearReferenceObjects( DataTag_MergeObject );
155 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
157 if ( theObject.IsNull() )
160 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
161 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
162 return false; // Wrong type of object
164 if ( HasReference( theObject, DataTag_Object ) )
165 return false; // Object is already in reference list
167 AddReferenceObject( theObject, DataTag_Object );
172 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
174 return GetReferenceObjects( DataTag_Object );
177 void HYDROData_Zone::RemoveObjects()
179 ClearReferenceObjects( DataTag_Object );
182 bool HYDROData_Zone::IsSubmersible() const
184 HYDROData_SequenceOfObjects anObjects = GetObjects();
185 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
186 for ( ; anObjsIter.More(); anObjsIter.Next() )
188 Handle(HYDROData_Object) aRefGeomObj =
189 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
190 if ( aRefGeomObj.IsNull() )
193 if( !aRefGeomObj->IsSubmersible() )
194 return false; //if one of geometry objects is not submersible the zone is considered as not submersible