From: mzn Date: Mon, 15 Jun 2015 09:19:05 +0000 (+0300) Subject: refs #567: change buildShape() method. X-Git-Tag: v1.4.1~3^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5b9c5a8093903fabc14eaeb65bd22de2f10a91f2;p=modules%2Fhydro.git refs #567: change buildShape() method. --- diff --git a/src/HYDROData/HYDROData_LandCover.cxx b/src/HYDROData/HYDROData_LandCover.cxx index 3680865c..b588c1fa 100644 --- a/src/HYDROData/HYDROData_LandCover.cxx +++ b/src/HYDROData/HYDROData_LandCover.cxx @@ -20,7 +20,9 @@ #include "HYDROData_PolylineXY.h" +#include #include +#include #include #include #include @@ -198,7 +200,70 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const { TopoDS_Shape aResShape; + BRepBuilderAPI_MakeWire aMakeWire; + + TopTools_ListOfShape aClosedWires; + + HYDROData_SequenceOfObjects aRefPolylines = GetPolylines(); + for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) { + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) ); + + if ( aPolyline.IsNull() ) { + continue; + } + + TopoDS_Shape aPolyShape = aPolyline->GetShape(); + if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) { + continue; + } + + const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape ); + if ( aPolylineWire.IsNull() ) { + continue; + } + + if ( aPolylineWire.Closed() ) { + aClosedWires.Append( aPolylineWire ); + } else { + aMakeWire.Add( aPolylineWire ); + aMakeWire.Build(); + if ( aMakeWire.IsDone() ) { + if ( aMakeWire.Wire().Closed() ) { + aClosedWires.Append( aMakeWire.Wire() ); + aMakeWire = BRepBuilderAPI_MakeWire(); + } + } + } + } + + if ( aClosedWires.Extent() == 1 ) { + // make face + BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aClosedWires.First() ) ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) { + aResShape = aMakeFace.Face(); + } + } else if ( aClosedWires.Extent() > 1 ) { + // make compound + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound( aCompound ); + + TopTools_ListIteratorOfListOfShape aWiresIter( aClosedWires ); + for ( ; aWiresIter.More(); aWiresIter.Next() ) { + BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aWiresIter.Value() ) ); + aMakeFace.Build(); + if( aMakeFace.IsDone() ) { + aBuilder.Add( aCompound, aMakeFace.Face() ); + } + } + + aResShape = aCompound; + } + ///< \TODO to be reimplemented + /* TopoDS_Shape anArgShape; TopTools_ListOfShape aToolShapes; @@ -263,6 +328,7 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const aResShape = aBOP.Shape(); } } + */ return aResShape; } \ No newline at end of file