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_ImmersibleZone.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_PolylineXY.h"
25 #include "HYDROData_ShapesTool.h"
27 #include <HYDROData_Tool.h>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TopTools_HSequenceOfShape.hxx>
38 #include <ShapeAnalysis.hxx>
39 #include <ShapeAnalysis_FreeBounds.hxx>
43 #include <QStringList>
46 #include <BRepTools.hxx>
48 #include "HYDRO_trace.hxx"
50 //#define HYDRODATA_IMZONE_DEB 1
52 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
55 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
56 : HYDROData_NaturalObject( Geom_2d )
60 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
64 QStringList HYDROData_ImmersibleZone::DumpToPython( const QString& thePyScriptPath,
65 MapOfTreatedObjects& theTreatedObjects ) const
67 QStringList aResList = dumpObjectCreation( theTreatedObjects );
69 QString aZoneName = GetObjPyName();
71 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
72 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" );
74 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
75 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
77 if (!this->IsSubmersible())
79 aResList << QString( "%1.SetIsSubmersible(False)" ).arg( aZoneName );
82 aResList << QString( "" );
84 aResList << QString( "%1.Update()" ).arg( aZoneName );
85 aResList << QString( "" );
90 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
92 HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
94 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
95 if ( !aRefPolyline.IsNull() )
96 aResSeq.Append( aRefPolyline );
101 void HYDROData_ImmersibleZone::Update()
103 HYDROData_NaturalObject::Update();
105 RemoveGroupObjects();
106 TopoDS_Shape aResShape = generateTopShape();
107 SetTopShape( aResShape );
109 createGroupObjects();
112 bool HYDROData_ImmersibleZone::IsHas2dPrs() const
117 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
119 return generateTopShape( GetPolyline() );
122 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
124 return HYDROData_Tool::PolyXY2Face(aPolyline);
127 void HYDROData_ImmersibleZone::createGroupObjects()
129 TopoDS_Shape aZoneShape = GetTopShape();
131 // Temporary solution while the restriction for polylines is not implemented
132 // and shape for zone can be compound and not face only
133 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
135 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
136 if ( aZoneFaceExp.More() )
137 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
140 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
143 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
145 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
147 // Create outer edges group
148 QString anOutWiresGroupName = GetName() + "_Outer";
150 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
151 anOutWiresGroup->SetName( anOutWiresGroupName );
153 TopTools_SequenceOfShape anOuterEdges;
154 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
155 anOutWiresGroup->SetShapes( anOuterEdges );
157 int anInnerCounter = 1;
158 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
159 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
161 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
162 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
163 continue; // Skip the outer wire
165 TopTools_SequenceOfShape anInnerEdges;
166 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
167 if ( anInnerEdges.IsEmpty() )
170 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
172 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
173 anInWiresGroup->SetName( anInWiresGroupName );
175 anInWiresGroup->SetShapes( anInnerEdges );
179 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
181 return GetTopShape();
184 QColor HYDROData_ImmersibleZone::DefaultFillingColor() const
186 return QColor( Qt::darkBlue );
189 QColor HYDROData_ImmersibleZone::DefaultBorderColor() const
191 return QColor( Qt::transparent );
194 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
196 if( IsEqual( GetPolyline(), thePolyline ) )
199 SetReferenceObject( thePolyline, DataTag_Polyline );
203 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
205 return Handle(HYDROData_PolylineXY)::DownCast(
206 GetReferenceObject( DataTag_Polyline ) );
209 void HYDROData_ImmersibleZone::RemovePolyline()
211 ClearReferenceObjects( DataTag_Polyline );