#include <TopLoc_Location.hxx>
#include <Geom_Plane.hxx>
#include <NCollection_Array1.hxx>
+#include <BRepBndLib.hxx>
+#include <Bnd_Box.hxx>
#ifdef WIN32
#pragma warning( disable: 4996 )
BRep_Builder BB;
BB.MakeFace(F);
- NCollection_Sequence<NCollection_Sequence<TopoDS_Edge> > allEdges;
+ NCollection_Sequence<TopoDS_Wire> allWires;
TopTools_SequenceOfShape aWires;
for ( int i = 0 ; i < nParts ; i++ )
else
EndIndex = anObj->nVertices;
- NCollection_Sequence<TopoDS_Edge> EPerW;
+ TopoDS_Wire W;
+ BB.MakeWire(W);
//First point is same as the last point
int NbPnts = EndIndex - StartIndex - 1;
E = BRepLib_MakeEdge(aTC, VPoints.First(), VPoints.Value(VPoints.Upper() - 1)).Edge();
//Add edge to wire
//If SHP file is correct then the outer wire and the holes will have the correct orientations
-
- EPerW.Append(E);
+ W.Closed (Standard_True);
+ W.Orientation(TopAbs_FORWARD);
+ BB.Add(W, E);
}
- allEdges.Append(EPerW);
+ allWires.Append(W);
}
- for (int i = 1; i <= allEdges.Size(); i++)
+ int OutWIndex = -1;
+ if (allWires.Size() > 1)
+ {
+ NCollection_Sequence<Bnd_Box> BBs;
+ //try to find the largest bbox
+ for (int i = 1; i <= allWires.Size(); i++)
+ {
+ TopoDS_Wire W = allWires(i);
+ Bnd_Box BB;
+ BRepBndLib::AddClose(W, BB);
+ BBs.Append(BB);
+ }
+ for (int i = 1; i <= BBs.Size(); i++)
+ {
+ bool IsIn = false;
+ for (int j = 1; j <= BBs.Size(); j++)
+ {
+ if (i == j)
+ continue;
+ Standard_Real iXmax, iXmin, iYmax, iYmin, z0, z1;
+ Standard_Real jXmax, jXmin, jYmax, jYmin;
+ BBs(i).Get(iXmin, iYmin, z0, iXmax, iYmax, z1);
+ BBs(j).Get(jXmin, jYmin, z0, jXmax, jYmax, z1);
+ if (!(iXmin > jXmin &&
+ iYmin > jYmin &&
+ iXmax < jXmax &&
+ iYmax < jYmax))
+ IsIn = true;
+ }
+ if (IsIn)
+ {
+ OutWIndex = i;
+ break;
+ }
+ }
+ }
+ else
+ OutWIndex = 1; //one wire => no need to check
+
+ for (int i = 1; i <= allWires.Size(); i++)
{
- TopoDS_Wire W;
- BB.MakeWire(W);
- for (int j = 1; j <= allEdges(i).Size(); j++)
- BB.Add(W, allEdges(i)(j));
- W.Closed (Standard_True);
- W.Orientation(TopAbs_FORWARD);
- //check on the dummy face first
TopoDS_Face DF;
BB.MakeFace(DF);
+ TopoDS_Wire W = allWires(i);
BB.Add(DF, W);
BB.UpdateFace(DF, aPlaneSur, TopLoc_Location(), Precision::Confusion());
//
BRepTopAdaptor_FClass2d FClass(DF, Precision::PConfusion());
- if ( i == 1 && FClass.PerformInfinitePoint() != TopAbs_OUT)
+ if ( i == OutWIndex && FClass.PerformInfinitePoint() == TopAbs_IN)
W.Reverse();
- if ( i > 1 && FClass.PerformInfinitePoint() != TopAbs_IN)
+ if ( i != OutWIndex && FClass.PerformInfinitePoint() == TopAbs_OUT)
W.Reverse();
//
BB.Add(F, W);