- TopoDS_Face aResultFace = TopoDS_Face();
-
- if( !aPolyline.IsNull() )
- {
- TopoDS_Shape aPolylineShape = aPolyline->GetShape();
- TopTools_ListOfShape aWiresList;
-
- if ( !aPolylineShape.IsNull() &&
- aPolylineShape.ShapeType() == TopAbs_WIRE ) {
- const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
- if ( !aPolylineWire.IsNull() ) {
- BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
- aMakeFace.Build();
- if( aMakeFace.IsDone() ) {
- aResultFace = aMakeFace.Face();
- }
- }
- } else {
- TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
- for ( ; anExp.More(); anExp.Next() ) {
- if(!anExp.Current().IsNull()) {
- const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
- aWiresList.Append( aWire );
- }
- }
- if(aWiresList.IsEmpty())
- return aResultFace;
-
- BRepAlgo_FaceRestrictor aFR;
- TopoDS_Face aRefFace;
- TopoDS_Shape aS = aWiresList.First();
- BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
- aMakeFace.Build();
- if( aMakeFace.IsDone() ) {
- aRefFace = aMakeFace.Face();
- }
- if(aRefFace.IsNull())
- return aResultFace;
-
- aFR.Init(aRefFace,Standard_False, Standard_True);
- TopTools_ListIteratorOfListOfShape anIt( aWiresList );
- for ( ; anIt.More(); anIt.Next() ) {
- TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
- if ( aWire.IsNull() )
- continue;
- aFR.Add(aWire);
- }
- aFR.Perform();
- if (aFR.IsDone()) {
- for (; aFR.More(); aFR.Next()) {
- aResultFace = aFR.Current();
- break;
- }
- }
- }
- }
-
- if( aResultFace.IsNull() )
- return aResultFace;
-
- BRepCheck_Analyzer anAnalyzer( aResultFace );
- if( anAnalyzer.IsValid() && aResultFace.ShapeType()==TopAbs_FACE )
- return aResultFace;
- else
- return TopoDS_Face();