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 "HYDROData_LandCover.h"
27 #include <TNaming_Builder.hxx>
28 #include <TNaming_NamedShape.hxx>
30 #include <TopoDS_Shape.hxx>
32 #include <QStringList>
34 #include <TDataStd_Integer.hxx>
36 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
37 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
40 HYDROData_Zone::HYDROData_Zone()
43 myInterpolator = NULL;
46 HYDROData_Zone::~HYDROData_Zone()
50 bool HYDROData_Zone::CanBeUpdated() const
55 bool HYDROData_Zone::IsHas2dPrs() const
60 bool HYDROData_Zone::CanRemove()
65 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
67 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
69 HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
70 aResSeq.Append( aSeqOfObjects );
75 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
77 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
78 aBuilder.Generated( theShape );
81 TopoDS_Shape HYDROData_Zone::GetShape() const
83 TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
84 if ( !aLabel.IsNull() )
86 Handle(TNaming_NamedShape) aNamedShape;
87 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
88 return aNamedShape->Get();
91 return TopoDS_Shape();
94 bool HYDROData_Zone::IsMergingNeed() const
96 // Zones based on geometry objects (compare altitudes)
97 Handle(HYDROData_IAltitudeObject) aRefAltitude;
99 HYDROData_SequenceOfObjects anObjects = GetObjects();
100 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
101 for ( ; anObjsIter.More(); anObjsIter.Next() )
103 Handle(HYDROData_Object) aRefGeomObj =
104 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
105 if ( aRefGeomObj.IsNull() )
108 Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
109 if ( anObjAltitude.IsNull() )
112 if ( aRefAltitude.IsNull() )
114 aRefAltitude = anObjAltitude;
118 if ( !IsEqual( aRefAltitude, anObjAltitude ) )
122 // Zones based on land cover objects (compare Strickler types)
123 QString aRefStricklerType;
125 anObjsIter.Init( anObjects );
126 for ( ; anObjsIter.More(); anObjsIter.Next() )
128 Handle(HYDROData_LandCover) aRefLandCoverObj =
129 Handle(HYDROData_LandCover)::DownCast( anObjsIter.Value() );
130 if ( aRefLandCoverObj.IsNull() )
133 QString aStricklerType = aRefLandCoverObj->GetStricklerType();
135 if ( aRefStricklerType.isNull() )
137 aRefStricklerType = aStricklerType;
141 if ( aRefStricklerType != aStricklerType )
149 void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
151 myInterpolator = theInter;
154 HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
156 return myInterpolator;
159 void HYDROData_Zone::SetMergeType( const MergeType& theType )
161 TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
164 HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
166 MergeType aMergeType = Merge_UNKNOWN;
168 TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
169 if ( !aLabel.IsNull() )
171 Handle(TDataStd_Integer) anInt;
172 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
173 aMergeType = (MergeType)anInt->Get();
179 void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
181 SetReferenceObject( theObject, DataTag_MergeObject );
184 Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
186 return Handle(HYDROData_Entity)::DownCast(
187 GetReferenceObject( DataTag_MergeObject ) );
190 void HYDROData_Zone::RemoveMergeObject()
192 ClearReferenceObjects( DataTag_MergeObject );
195 bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
197 if ( theObject.IsNull() )
200 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
201 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) &&
202 !theObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) )
203 return false; // Wrong type of object
205 if ( HasReference( theObject, DataTag_Object ) )
206 return false; // Object is already in reference list
208 AddReferenceObject( theObject, DataTag_Object );
213 HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
215 return GetReferenceObjects( DataTag_Object );
218 void HYDROData_Zone::RemoveObjects()
220 ClearReferenceObjects( DataTag_Object );
223 bool HYDROData_Zone::IsSubmersible() const
225 HYDROData_SequenceOfObjects anObjects = GetObjects();
226 HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
227 for ( ; anObjsIter.More(); anObjsIter.Next() )
229 Handle(HYDROData_Object) aRefGeomObj =
230 Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
231 if ( aRefGeomObj.IsNull() )
234 if( !aRefGeomObj->IsSubmersible() )
235 return false; //if one of geometry objects is not submersible the zone is considered as not submersible