-//=======================================================================
-//function : getOrderedEdges
-//purpose : return nb wires and a list of oredered edges
-//=======================================================================
-
-static int getOrderedEdges (const TopoDS_Face& theFace,
- const TopoDS_Vertex& theFirstVertex,
- list< TopoDS_Edge >& theEdges,
- list< int > & theNbVertexInWires)
-{
- // put wires in a list, so that an outer wire comes first
- list<TopoDS_Wire> aWireList;
- TopoDS_Wire anOuterWire = BRepTools::OuterWire( theFace );
- aWireList.push_back( anOuterWire );
- for ( TopoDS_Iterator wIt (theFace); wIt.More(); wIt.Next() )
- if ( !anOuterWire.IsSame( wIt.Value() ))
- aWireList.push_back( TopoDS::Wire( wIt.Value() ));
-
- // loop on edges of wires
- theNbVertexInWires.clear();
- list<TopoDS_Wire>::iterator wlIt = aWireList.begin();
- for ( ; wlIt != aWireList.end(); wlIt++ )
- {
- int iE;
- BRepTools_WireExplorer wExp( *wlIt, theFace );
- for ( iE = 0; wExp.More(); wExp.Next(), iE++ )
- {
- TopoDS_Edge edge = wExp.Current();
- edge = TopoDS::Edge( edge.Oriented( wExp.Orientation() ));
- theEdges.push_back( edge );
- }
- theNbVertexInWires.push_back( iE );
- iE = 0;
- if ( wlIt == aWireList.begin() && theEdges.size() > 1 ) { // the outer wire
- // orient closed edges
- list< TopoDS_Edge >::iterator eIt, eIt2;
- for ( eIt = theEdges.begin(); eIt != theEdges.end(); eIt++ )
- {
- TopoDS_Edge& edge = *eIt;
- if ( TopExp::FirstVertex( edge ).IsSame( TopExp::LastVertex( edge ) ))
- {
- eIt2 = eIt;
- bool isNext = ( eIt2 == theEdges.begin() );
- TopoDS_Edge edge2 = isNext ? *(++eIt2) : *(--eIt2);
- double f1,l1,f2,l2;
- Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface( edge, theFace, f1,l1 );
- Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface( edge2, theFace, f2,l2 );
- gp_Pnt2d pf = c1->Value( edge.Orientation() == TopAbs_FORWARD ? f1 : l1 );
- gp_Pnt2d pl = c1->Value( edge.Orientation() == TopAbs_FORWARD ? l1 : f1 );
- bool isFirst = ( edge2.Orientation() == TopAbs_FORWARD ? isNext : !isNext );
- gp_Pnt2d p2 = c2->Value( isFirst ? f2 : l2 );
- isFirst = ( p2.SquareDistance( pf ) < p2.SquareDistance( pl ));
- if ( isNext ? isFirst : !isFirst )
- edge.Reverse();
- }
- }
- // rotate theEdges until it begins from theFirstVertex
- if ( ! theFirstVertex.IsNull() )
- while ( !theFirstVertex.IsSame( TopExp::FirstVertex( theEdges.front(), true )))
- {
- theEdges.splice(theEdges.end(), theEdges,
- theEdges.begin(), ++ theEdges.begin());
- if ( iE++ > theNbVertexInWires.back() )
- break; // break infinite loop
- }
- }
- }
-
- return aWireList.size();
-}
-