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"
26 #include <TNaming_Builder.hxx>
27 #include <TNaming_NamedShape.hxx>
29 #include <TopoDS_Shape.hxx>
31 #include <QStringList>
33 #include <TDataStd_Integer.hxx>
35 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
39 HYDROData_Zone::HYDROData_Zone()
42 myInterpolator = NULL;
45 HYDROData_Zone::~HYDROData_Zone()
49 bool HYDROData_Zone::CanBeUpdated() const
54 bool HYDROData_Zone::IsHas2dPrs() const
59 bool HYDROData_Zone::CanRemove()
64 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
66 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
68 HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
69 aResSeq.Append( aSeqOfObjects );
74 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
76 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
77 aBuilder.Generated( theShape );
80 TopoDS_Shape HYDROData_Zone::GetShape() const
82 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
83 if ( !aLabel.IsNull() )
85 Handle(TNaming_NamedShape) aNamedShape;
86 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
87 return aNamedShape->Get();
90 return TopoDS_Shape();
93 bool HYDROData_Zone::IsMergingNeed() const
95 // Zones based on geometry objects (compare altitudes)
96 Handle(HYDROData_IAltitudeObject) aRefAltitude;
98 HYDROData_SequenceOfObjects anObjects = GetObjects();
99 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
100 for ( ; anObjsIter.More(); anObjsIter.Next() )
102 Handle(HYDROData_Object) aRefGeomObj =
103 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
104 if ( aRefGeomObj.IsNull() )
107 Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
108 if ( anObjAltitude.IsNull() )
111 if ( aRefAltitude.IsNull() )
113 aRefAltitude = anObjAltitude;
117 if ( !IsEqual( aRefAltitude, anObjAltitude ) )
124 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
126 myInterpolator = theInter;
129 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
131 return myInterpolator;
134 void HYDROData_Zone::SetMergeType( const MergeType& theType )
136 TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
139 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
141 MergeType aMergeType = Merge_UNKNOWN;
143 TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
144 if ( !aLabel.IsNull() )
146 Handle(TDataStd_Integer) anInt;
147 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
148 aMergeType = (MergeType)anInt->Get();
154 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
156 SetReferenceObject( theObject, DataTag_MergeObject );
159 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
161 return Handle(HYDROData_Entity)::DownCast(
162 GetReferenceObject( DataTag_MergeObject ) );
165 void HYDROData_Zone::RemoveMergeObject()
167 ClearReferenceObjects( DataTag_MergeObject );
170 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
172 if ( theObject.IsNull() )
175 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
176 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
177 return false; // Wrong type of object
179 if ( HasReference( theObject, DataTag_Object ) )
180 return false; // Object is already in reference list
182 AddReferenceObject( theObject, DataTag_Object );
187 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
189 return GetReferenceObjects( DataTag_Object );
192 void HYDROData_Zone::RemoveObjects()
194 ClearReferenceObjects( DataTag_Object );
197 bool HYDROData_Zone::IsSubmersible() const
199 HYDROData_SequenceOfObjects anObjects = GetObjects();
200 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
201 for ( ; anObjsIter.More(); anObjsIter.Next() )
203 Handle(HYDROData_Object) aRefGeomObj =
204 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
205 if ( aRefGeomObj.IsNull() )
208 if( !aRefGeomObj->IsSubmersible() )
209 return false; //if one of geometry objects is not submersible the zone is considered as not submersible