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 <BRepBuilderAPI_MakeFace.hxx>
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>
36 #include <BRep_Builder.hxx>
37 #include <BRepAlgo_FaceRestrictor.hxx>
38 #include <BRepCheck_Analyzer.hxx>
40 #include <ShapeAnalysis.hxx>
43 #include <QStringList>
45 //#define HYDRODATA_IMZONE_DEB 1
47 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
48 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
51 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
52 : HYDROData_NaturalObject( Geom_2d )
56 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
60 QStringList HYDROData_ImmersibleZone::DumpToPython( const QString& thePyScriptPath,
61 MapOfTreatedObjects& theTreatedObjects ) const
63 QStringList aResList = dumpObjectCreation( theTreatedObjects );
65 QString aZoneName = GetObjPyName();
67 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
68 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" );
70 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
71 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
73 aResList << QString( "" );
75 aResList << QString( "%1.Update()" ).arg( aZoneName );
76 aResList << QString( "" );
81 HYDROData_SequenceOfObjects HYDROData_ImmersibleZone::GetAllReferenceObjects() const
83 HYDROData_SequenceOfObjects aResSeq = HYDROData_NaturalObject::GetAllReferenceObjects();
85 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
86 if ( !aRefPolyline.IsNull() )
87 aResSeq.Append( aRefPolyline );
92 void HYDROData_ImmersibleZone::Update()
94 HYDROData_NaturalObject::Update();
96 TopoDS_Shape aResShape = generateTopShape();
97 SetTopShape( aResShape );
102 bool HYDROData_ImmersibleZone::IsHas2dPrs() const
107 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape() const
109 return generateTopShape( GetPolyline() );
112 TopoDS_Shape HYDROData_ImmersibleZone::generateTopShape( const Handle(HYDROData_PolylineXY)& aPolyline )
114 TopoDS_Face aResultFace = TopoDS_Face();
116 if( !aPolyline.IsNull() )
118 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
119 TopTools_ListOfShape aWiresList;
121 if ( !aPolylineShape.IsNull() &&
122 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
123 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
124 if ( !aPolylineWire.IsNull() ) {
125 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
127 if( aMakeFace.IsDone() ) {
128 aResultFace = aMakeFace.Face();
132 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
133 for ( ; anExp.More(); anExp.Next() ) {
134 if(!anExp.Current().IsNull()) {
135 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
136 aWiresList.Append( aWire );
139 if(aWiresList.IsEmpty())
142 BRepAlgo_FaceRestrictor aFR;
143 TopoDS_Face aRefFace;
144 TopoDS_Shape aS = aWiresList.First();
145 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
147 if( aMakeFace.IsDone() ) {
148 aRefFace = aMakeFace.Face();
150 if(aRefFace.IsNull())
153 aFR.Init(aRefFace,Standard_False, Standard_True);
154 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
155 for ( ; anIt.More(); anIt.Next() ) {
156 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
157 if ( aWire.IsNull() )
163 for (; aFR.More(); aFR.Next()) {
164 aResultFace = aFR.Current();
171 if( aResultFace.IsNull() )
174 BRepCheck_Analyzer anAnalyzer( aResultFace );
175 if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
178 return TopoDS_Face();
181 void HYDROData_ImmersibleZone::createGroupObjects()
183 TopoDS_Shape aZoneShape = GetTopShape();
185 // Temporary solution while the restriction for polylines is not implemented
186 // and shape for zone can be compound and not face only
187 if ( !aZoneShape.IsNull() && aZoneShape.ShapeType() != TopAbs_FACE )
189 TopExp_Explorer aZoneFaceExp( aZoneShape, TopAbs_FACE );
190 if ( aZoneFaceExp.More() )
191 aZoneShape = aZoneFaceExp.Current(); // Take only first face into account
194 if ( aZoneShape.IsNull() || aZoneShape.ShapeType() != TopAbs_FACE )
197 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
199 TopoDS_Wire aZoneOuterWire = ShapeAnalysis::OuterWire( aZoneFace );
201 // Create outer edges group
202 QString anOutWiresGroupName = GetName() + "_Outer";
204 Handle(HYDROData_ShapesGroup) anOutWiresGroup = createGroupObject();
205 anOutWiresGroup->SetName( anOutWiresGroupName );
207 TopTools_SequenceOfShape anOuterEdges;
208 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneOuterWire, TopAbs_EDGE, anOuterEdges );
209 anOutWiresGroup->SetShapes( anOuterEdges );
211 int anInnerCounter = 1;
212 TopExp_Explorer aZoneFaceExp( aZoneFace, TopAbs_WIRE );
213 for ( ; aZoneFaceExp.More(); aZoneFaceExp.Next() )
215 TopoDS_Wire aZoneWire = TopoDS::Wire( aZoneFaceExp.Current() );
216 if ( aZoneWire.IsEqual( aZoneOuterWire ) )
217 continue; // Skip the outer wire
219 TopTools_SequenceOfShape anInnerEdges;
220 HYDROData_ShapesTool::ExploreShapeToShapes( aZoneWire, TopAbs_EDGE, anInnerEdges );
221 if ( anInnerEdges.IsEmpty() )
224 QString anInWiresGroupName = GetName() + "_Inner_" + QString::number( anInnerCounter++ );
226 Handle(HYDROData_ShapesGroup) anInWiresGroup = createGroupObject();
227 anInWiresGroup->SetName( anInWiresGroupName );
229 anInWiresGroup->SetShapes( anInnerEdges );
233 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
235 return GetTopShape();
238 QColor HYDROData_ImmersibleZone::DefaultFillingColor() const
240 return QColor( Qt::darkBlue );
243 QColor HYDROData_ImmersibleZone::DefaultBorderColor() const
245 return QColor( Qt::transparent );
248 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
250 if( IsEqual( GetPolyline(), thePolyline ) )
253 SetReferenceObject( thePolyline, DataTag_Polyline );
257 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
259 return Handle(HYDROData_PolylineXY)::DownCast(
260 GetReferenceObject( DataTag_Polyline ) );
263 void HYDROData_ImmersibleZone::RemovePolyline()
265 ClearReferenceObjects( DataTag_Polyline );