]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMAlgo/GEOMAlgo_WireSplitter.cxx
Salome HOME
0021672: [CEA 565] Dump Study from script
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WireSplitter.cxx
index ddfe74f806d32d58eff267bac99e89dc5dd570b8..b9a452053e4232a9bf3e480275c99dea4f53bc3b 100755 (executable)
@@ -1,30 +1,29 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// File:       GEOMAlgo_WireSplitter.cxx
-// Created:    
-// Author:     Peter KURNEV
-//             <pkv@irinox>
-//
-#include <GEOMAlgo_WireSplitter.ixx>
+
+// File:        GEOMAlgo_WireSplitter.cxx
+// Author:      Peter KURNEV
+
+#include <GEOMAlgo_WireSplitter.hxx>
 
 #include <TColStd_SequenceOfReal.hxx>
 #include <Precision.hxx>
@@ -45,7 +44,6 @@
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Iterator.hxx>
 
-
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
 #include <BRepAdaptor_Curve2d.hxx>
@@ -53,8 +51,6 @@
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 
-
-
 #include <TopTools_SequenceOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
 static
   void Path (const GeomAdaptor_Surface& aGAS,
-            const TopoDS_Face& myFace,
-            const TopoDS_Vertex& aVa,
-            const TopoDS_Edge& aEOuta,
-            BOP_EdgeInfo& anEdgeInfo,
-            TopTools_SequenceOfShape& aLS,
-            TopTools_SequenceOfShape& aVertVa,
-            TColgp_SequenceOfPnt2d& aCoordVa,
-            BOPTColStd_ListOfListOfShape& myShapes,
-            BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap);
+             const TopoDS_Face& myFace,
+             const TopoDS_Vertex& aVa,
+             const TopoDS_Edge& aEOuta,
+             BOP_EdgeInfo& anEdgeInfo,
+             TopTools_SequenceOfShape& aLS,
+             TopTools_SequenceOfShape& aVertVa,
+             TColgp_SequenceOfPnt2d& aCoordVa,
+             BOPTColStd_ListOfListOfShape& myShapes,
+             BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap);
 
 
 static
@@ -90,40 +86,45 @@ static
 
 static
   void GetNextVertex(const TopoDS_Vertex& aV,
-                    const TopoDS_Edge& aE,
-                    TopoDS_Vertex& aV1);
+                     const TopoDS_Edge& aE,
+                     TopoDS_Vertex& aV1);
 static
   Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
-                              const Standard_Real aAngleOut);
+                               const Standard_Real aAngleOut);
 
 static
   Standard_Real AngleIn(const TopoDS_Edge& aEIn,
-                       const BOP_ListOfEdgeInfo& aLEInfo);
+                        const BOP_ListOfEdgeInfo& aLEInfo);
 
 static
   Standard_Real Angle2D (const TopoDS_Vertex& aV,
-                        const TopoDS_Edge& anEdge,
-                        const TopoDS_Face& myFace,
-                        const GeomAdaptor_Surface& aGAS,
-                        const Standard_Boolean aFlag);
+                         const TopoDS_Edge& anEdge,
+                         const TopoDS_Face& myFace,
+                         const GeomAdaptor_Surface& aGAS,
+                         const Standard_Boolean aFlag);
 static
   gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
-                   const TopoDS_Edge& aE1,
-                   const TopoDS_Face& aF);
+                    const TopoDS_Edge& aE1,
+                    const TopoDS_Face& aF);
 static
   gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
-                     const TopoDS_Face& aF);
+                      const TopoDS_Face& aF);
 static
   Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
-                           const GeomAdaptor_Surface& aGAS);   
+                            const GeomAdaptor_Surface& aGAS);
+
 
+//modified by NIZNHY-PKV Thu Apr 19 09:04:59 2012f
 static
-  Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& );
-//
+  Standard_Integer NbWaysOut(const TopoDS_Edge& aEOuta,
+                            const BOP_ListOfEdgeInfo& aLEInfo);
+//static
+//  Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& );
+//modified by NIZNHY-PKV Thu Apr 19 09:04:53 2012t
 
 //=======================================================================
-// function: 
-// purpose: 
+// function:
+// purpose:
 //=======================================================================
   GEOMAlgo_WireSplitter::GEOMAlgo_WireSplitter()
 :
@@ -133,14 +134,14 @@ static
 }
 //=======================================================================
 // function: ~
-// purpose: 
+// purpose:
 //=======================================================================
   GEOMAlgo_WireSplitter::~GEOMAlgo_WireSplitter()
 {
 }
 //=======================================================================
 // function: SetFace
-// purpose: 
+// purpose:
 //=======================================================================
   void GEOMAlgo_WireSplitter::SetFace(const TopoDS_Face& aFace)
 {
@@ -148,7 +149,7 @@ static
 }
 //=======================================================================
 // function: Face
-// purpose: 
+// purpose:
 //=======================================================================
   const TopoDS_Face& GEOMAlgo_WireSplitter::Face()const
 {
@@ -156,7 +157,7 @@ static
 }
 //=======================================================================
 // function: SetEdges
-// purpose: 
+// purpose:
 //=======================================================================
   void GEOMAlgo_WireSplitter::SetEdges(const TopTools_ListOfShape& aLE)
 {
@@ -176,7 +177,7 @@ static
 }
 //=======================================================================
 // function: Edges
-// purpose: 
+// purpose:
 //=======================================================================
   const TopTools_ListOfShape& GEOMAlgo_WireSplitter::Edges()const
 {
@@ -184,7 +185,7 @@ static
 }
 //=======================================================================
 // function: IsNothingToDo
-// purpose: 
+// purpose:
 //=======================================================================
   Standard_Boolean GEOMAlgo_WireSplitter::IsNothingToDo()const
 {
@@ -192,7 +193,7 @@ static
 }
 //=======================================================================
 // function: Shapes
-// purpose: 
+// purpose:
 //=======================================================================
   const BOPTColStd_ListOfListOfShape& GEOMAlgo_WireSplitter::Shapes()const
 {
@@ -200,7 +201,7 @@ static
 }
 //=======================================================================
 // function: Perform
-// purpose: 
+// purpose:
 //=======================================================================
   void GEOMAlgo_WireSplitter::Perform()
 {
@@ -210,7 +211,7 @@ static
   Standard_Integer index, i, aNb, aCntIn, aCntOut;
   Standard_Boolean anIsIn;
   Standard_Real anAngle;
-  
+
   BOP_ListOfEdgeInfo emptyInfo;
   TopTools_ListIteratorOfListOfShape anItList;
   //
@@ -231,22 +232,22 @@ static
 
       index = mySmartMap.FindIndex(aVertex);
       if (!index) {
-       index=mySmartMap.Add(aVertex, emptyInfo);
+        index=mySmartMap.Add(aVertex, emptyInfo);
       }
-      
+
       BOP_ListOfEdgeInfo& aListOfEInfo=mySmartMap(index);
 
       BOP_EdgeInfo aEInfo;
       aEInfo.SetEdge(anEdge);
-      
+
       TopAbs_Orientation anOr=aVertex.Orientation();
 
       if (anOr==TopAbs_FORWARD) {
-       aEInfo.SetInFlag(Standard_False);
+        aEInfo.SetInFlag(Standard_False);
       }
 
       else if (anOr==TopAbs_REVERSED) {
-       aEInfo.SetInFlag(Standard_True);
+        aEInfo.SetInFlag(Standard_True);
       }
 
       aListOfEInfo.Append(aEInfo);
@@ -255,9 +256,9 @@ static
   //
   aNb=mySmartMap.Extent();
   //
-  // 2. myNothingToDo 
+  // 2. myNothingToDo
   myNothingToDo=Standard_True;
-  
+
   for (i=1; i<=aNb; i++) {
     aCntIn=0;
     aCntOut=0;
@@ -267,10 +268,10 @@ static
       const BOP_EdgeInfo& anEdgeInfo=anIt.Value();
       anIsIn=anEdgeInfo.IsIn();
       if (anIsIn) {
-       aCntIn++;
+        aCntIn++;
       }
       else {
-       aCntOut++;
+        aCntOut++;
       }
     }
     if (aCntIn!=1 || aCntOut!=1) {
@@ -282,27 +283,27 @@ static
   // Each vertex has one edge In and one - Out. Good. But it is not enought
   // to consider that nothing to do with this. We must check edges on TShape
   // coinsidence. If there are such edges there is something to do with.
-  // 
+  //
   if (myNothingToDo) {
     Standard_Integer aNbE, aNbMapEE;
     TopTools_IndexedDataMapOfShapeListOfShape aMapEE;
     aNbE=myEdges.Extent();
-    
+
     anItList.Initialize(myEdges);
     for (; anItList.More(); anItList.Next()) {
       const TopoDS_Shape& aE = anItList.Value();
-      
+
       if (!aMapEE.Contains(aE)) {
-       TopTools_ListOfShape aLEx;
-       aLEx.Append(aE);
-       aMapEE.Add(aE, aLEx);
+        TopTools_ListOfShape aLEx;
+        aLEx.Append(aE);
+        aMapEE.Add(aE, aLEx);
       }
       else {
-       TopTools_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
-       aLEx.Append(aE);
+        TopTools_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
+        aLEx.Append(aE);
       }
     }
-    
+
     Standard_Boolean bFlag;
     bFlag=Standard_True;
     aNbMapEE=aMapEE.Extent();
@@ -310,25 +311,25 @@ static
       const TopTools_ListOfShape& aLEx=aMapEE(i);
       aNbE=aLEx.Extent();
       if (aNbE==1) {
-       // usual case
-       continue;
+        // usual case
+        continue;
       }
       else if (aNbE==2){
-       const TopoDS_Shape& aE1=aLEx.First();
-       const TopoDS_Shape& aE2=aLEx.Last();
-       if (aE1.IsSame(aE2)) {
-         bFlag=Standard_False;
-         break;
-       }
+        const TopoDS_Shape& aE1=aLEx.First();
+        const TopoDS_Shape& aE2=aLEx.Last();
+        if (aE1.IsSame(aE2)) {
+          bFlag=Standard_False;
+          break;
+        }
       }
       else {
-       bFlag=Standard_False;
-       break;
+        bFlag=Standard_False;
+        break;
       }
     }
     myNothingToDo=myNothingToDo && bFlag;
   }
-  // 
+  //
   //
   if (myNothingToDo) {
     myErrorStatus=0;
@@ -351,50 +352,50 @@ static
       //
       anIsIn=anEdgeInfo.IsIn();
       if (anIsIn) {
-       //
-       aVV.Orientation(TopAbs_REVERSED);
-       anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_True);
+        //
+        aVV.Orientation(TopAbs_REVERSED);
+        anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_True);
       }
-      // 
+      //
       else { // OUT
-       //
-       aVV.Orientation(TopAbs_FORWARD);
-       anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_False);
+        //
+        aVV.Orientation(TopAbs_FORWARD);
+        anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_False);
       }
       anEdgeInfo.SetAngle(anAngle);
-      
+
     }
   }
   //
   // 4. Do
   //
   Standard_Boolean anIsOut, anIsNotPassed;
-  
+
   TopTools_SequenceOfShape aLS, aVertVa;
   TColgp_SequenceOfPnt2d aCoordVa;
-  
+
   BOP_ListIteratorOfListOfEdgeInfo anIt;
 
   for (i=1; i<=aNb; i++) {
     const TopoDS_Vertex aVa=TopoDS::Vertex (mySmartMap.FindKey(i));
     const BOP_ListOfEdgeInfo& aLEInfo=mySmartMap(i);
-    
+
     anIt.Initialize(aLEInfo);
     for (; anIt.More(); anIt.Next()) {
       BOP_EdgeInfo& anEdgeInfo=anIt.Value();
       const TopoDS_Edge& aEOuta=anEdgeInfo.Edge();
-      
+
       anIsOut=!anEdgeInfo.IsIn();
       anIsNotPassed=!anEdgeInfo.Passed();
-      
+
       if (anIsOut && anIsNotPassed) {
-       //
-       aLS.Clear();
-       aVertVa.Clear();
-       aCoordVa.Clear();
-       //
-       Path(aGAS, myFace, aVa, aEOuta, anEdgeInfo, aLS, 
-            aVertVa, aCoordVa, myShapes, mySmartMap);
+        //
+        aLS.Clear();
+        aVertVa.Clear();
+        aCoordVa.Clear();
+        //
+        Path(aGAS, myFace, aVa, aEOuta, anEdgeInfo, aLS,
+             aVertVa, aCoordVa, myShapes, mySmartMap);
       }
     }
   }
@@ -404,22 +405,22 @@ static
     TopoDS_Vertex aV1, aV2;
     BOPTColStd_ListOfListOfShape aShapes;
     BOPTColStd_ListIteratorOfListOfListOfShape anItW(myShapes);
-    
+
     for (; anItW.More(); anItW.Next()) {
       TopTools_IndexedMapOfShape aMV, aME;
       const TopTools_ListOfShape& aLE=anItW.Value();
       TopTools_ListIteratorOfListOfShape anItE(aLE);
       for (; anItE.More(); anItE.Next()) {
-       const TopoDS_Edge& aE=TopoDS::Edge(anItE.Value());
-       aME.Add(aE);
-       TopExp::Vertices(aE, aV1, aV2);
-       aMV.Add(aV1);
-       aMV.Add(aV2);
+        const TopoDS_Edge& aE=TopoDS::Edge(anItE.Value());
+        aME.Add(aE);
+        TopExp::Vertices(aE, aV1, aV2);
+        aMV.Add(aV1);
+        aMV.Add(aV2);
       }
       aNbV=aMV.Extent();
       aNbE=aME.Extent();
       if (aNbV<=aNbE) {
-       aShapes.Append(aLE);
+        aShapes.Append(aLE);
       }
     }
     //
@@ -435,24 +436,23 @@ static
 }
 //=======================================================================
 // function: Path
-// purpose: 
+// purpose:
 //=======================================================================
   void Path (const GeomAdaptor_Surface& aGAS,
-            const TopoDS_Face& myFace,
-            const TopoDS_Vertex& aVa,
-            const TopoDS_Edge& aEOuta,
-            BOP_EdgeInfo& anEdgeInfo,
-            TopTools_SequenceOfShape& aLS,
-            TopTools_SequenceOfShape& aVertVa,
-            TColgp_SequenceOfPnt2d& aCoordVa,
-            BOPTColStd_ListOfListOfShape& myShapes,
-            BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap)
-                              
+             const TopoDS_Face& myFace,
+             const TopoDS_Vertex& aVa,
+             const TopoDS_Edge& aEOuta,
+             BOP_EdgeInfo& anEdgeInfo,
+             TopTools_SequenceOfShape& aLS,
+             TopTools_SequenceOfShape& aVertVa,
+             TColgp_SequenceOfPnt2d& aCoordVa,
+             BOPTColStd_ListOfListOfShape& myShapes,
+             BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap)
 {
-  Standard_Integer i,j, aNb, aNbj;
+  Standard_Integer i,j, aNb, aNbj, iCnt;
   Standard_Real aTol, anAngleIn, anAngleOut, anAngle, aMinAngle;
   Standard_Real aTol2D, aTol2D2;
-  Standard_Real aTol2, aD2;//, aTolUVb, aTolVVb;  
+  Standard_Real aTol2, aD2;
   Standard_Boolean anIsSameV2d, anIsSameV, anIsFound, anIsOut, anIsNotPassed;
   BOP_ListIteratorOfListOfEdgeInfo anIt;
   TopoDS_Vertex aVb;
@@ -462,7 +462,7 @@ static
   //
   // append block
   //
-  // Do not escape through edge from which you enter 
+  // Do not escape through edge from which you enter
   aNb=aLS.Length();
   if (aNb==1) {
     const TopoDS_Shape& anEPrev=aLS(aNb);
@@ -475,17 +475,15 @@ static
   anEdgeInfo.SetPassed(Standard_True);
   aLS.Append(aEOuta);
   aVertVa.Append(aVa);
-  
+
   TopoDS_Vertex pVa=aVa;
   pVa.Orientation(TopAbs_FORWARD);
   gp_Pnt2d aPa=Coord2d(pVa, aEOuta, myFace);
   aCoordVa.Append(aPa);
-  
+
   GetNextVertex (pVa, aEOuta, aVb);
 
   gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace);
-
-  //const BOP_ListOfEdgeInfo& aLEInfoVb=mySmartMap.FindFromKey(aVb);
   //
   aTol=2.*Tolerance2D(aVb, aGAS);
   aTol2=10.*aTol*aTol;
@@ -506,45 +504,45 @@ static
       anIsSameV2d=Standard_False;
 
       if (anIsSameV) {
-       anIsSameV2d = Standard_True;
-       //
-       aD2=aPaPrev.SquareDistance(aPb);
-       anIsSameV2d =aD2<aTol2;
+        anIsSameV2d = Standard_True;
+        //
+        aD2=aPaPrev.SquareDistance(aPb);
+        anIsSameV2d =aD2<aTol2;
       }//if (anIsSameV) {
       //
       if (anIsSameV && anIsSameV2d) {
-       myShapes.Append(aBuf);
-       //
-       TopTools_SequenceOfShape aLSt, aVertVat;
-       TColgp_SequenceOfPnt2d aCoordVat;
-       //
-       aNbj=i-1;
-       if (aNbj<1) {
-         //
-         aLS.Clear();
-         aVertVa.Clear();
-         aCoordVa.Clear();
-         //
-         return;
-       }
-
-       aVb=TopoDS::Vertex(aVertVa(i));
-
-       for (j=1; j<=aNbj; j++) {
-         aLSt.Append(aLS(j));
-         aVertVat.Append(aVertVa(j));
-         aCoordVat.Append(aCoordVa(j));
-       }
-       //
-       aLS.Clear();
-       aVertVa.Clear();
-       aCoordVa.Clear();
-
-       aLS=aLSt;
-       aVertVa=aVertVat;
-       aCoordVa=aCoordVat;
-       //
-       break;
+        myShapes.Append(aBuf);
+        //
+        TopTools_SequenceOfShape aLSt, aVertVat;
+        TColgp_SequenceOfPnt2d aCoordVat;
+        //
+        aNbj=i-1;
+        if (aNbj<1) {
+          //
+          aLS.Clear();
+          aVertVa.Clear();
+          aCoordVa.Clear();
+          //
+          return;
+        }
+
+        aVb=TopoDS::Vertex(aVertVa(i));
+
+        for (j=1; j<=aNbj; j++) {
+          aLSt.Append(aLS(j));
+          aVertVat.Append(aVertVa(j));
+          aCoordVat.Append(aCoordVa(j));
+        }
+        //
+        aLS.Clear();
+        aVertVa.Clear();
+        aCoordVa.Clear();
+
+        aLS=aLSt;
+        aVertVa=aVertVat;
+        aCoordVa=aCoordVat;
+        //
+        break;
       }
     }
   }
@@ -562,34 +560,32 @@ static
 
   aMinAngle=100.;
   anIsFound=Standard_False;
-
-  Standard_Integer aCurIndexE = 0;
-
+  //
+  //modified by NIZNHY-PKV Thu Apr 19 09:05:09 2012f
+  iCnt=NbWaysOut (aEOuta, aLEInfo); 
+  //iCnt=NbWaysOut (aLEInfo); 
+  //modified by NIZNHY-PKV Thu Apr 19 09:05:12 2012t
+  if (!iCnt) { // no way to go . (Error)
+    return ;
+  }
+  //
   anIt.Initialize(aLEInfo);
   for (; anIt.More(); anIt.Next()) {
     BOP_EdgeInfo& anEI=anIt.Value();
     const TopoDS_Edge& aE=anEI.Edge();
     anIsOut=!anEI.IsIn();
     anIsNotPassed=!anEI.Passed();
-    
+    //
     if (anIsOut && anIsNotPassed) {
-      aCurIndexE++;
-      //
-      // Is there one way to go out of the vertex 
-      // we have to use it only.
-      Standard_Integer iCnt;
-      iCnt=NbWaysOut (aLEInfo);
-      //
-      if (!iCnt) {
-       // no way to go . (Error)
-       return ;
+      if (aE.IsSame(aEOuta)) {
+       continue;
       }
       //
       if (iCnt==1) {
-       // the one and only way to go out .
-       pEdgeInfo=&anEI;
-       anIsFound=Standard_True;
-       break;
+        // the one and only way to go out .
+        pEdgeInfo=&anEI;
+        anIsFound=Standard_True;
+        break;
       }
       //
       // Look for minimal angle and make the choice.
@@ -599,37 +595,36 @@ static
       //
       aD2=aP2Dx.SquareDistance(aPb);
       if (aD2 > aTol2D2){
-       continue;
+        continue;
       }
       //
-      //
       anAngleOut=anEI.Angle();
       //
       anAngle=ClockWiseAngle(anAngleIn, anAngleOut);
       if (anAngle < aMinAngle) {
-       aMinAngle=anAngle;
-       pEdgeInfo=&anEI;
-       anIsFound=Standard_True;
+        aMinAngle=anAngle;
+        pEdgeInfo=&anEI;
+        anIsFound=Standard_True;
       }
     }
-  } // for (; anIt.More(); anIt.Next()) 
+  } // for (; anIt.More(); anIt.Next())
   //
   if (!anIsFound) {
     // no way to go . (Error)
     return;
   }
-  
+  //
   aEOutb=pEdgeInfo->Edge();
   //
-  Path (aGAS, myFace, aVb, aEOutb, *pEdgeInfo, aLS, 
-       aVertVa, aCoordVa, myShapes, mySmartMap);
+  Path (aGAS, myFace, aVb, aEOutb, *pEdgeInfo, aLS,
+        aVertVa, aCoordVa, myShapes, mySmartMap);
 }
 //=======================================================================
 // function:  Coord2dVf
 // purpose:
 //=======================================================================
  gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
-                    const TopoDS_Face& aF)
+                     const TopoDS_Face& aF)
 {
   Standard_Real aCoord=99.;
   gp_Pnt2d aP2D1(aCoord, aCoord);
@@ -651,7 +646,7 @@ static
 // purpose:
 //=======================================================================
  Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
-                           const GeomAdaptor_Surface& aGAS)                 
+                            const GeomAdaptor_Surface& aGAS)
 {
   Standard_Real aTol2D, anUr, aVr, aTolV3D;
   GeomAbs_SurfaceType aType;
@@ -682,8 +677,8 @@ static
 // purpose:
 //=======================================================================
  gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
-                  const TopoDS_Edge& aE1,
-                  const TopoDS_Face& aF)
+                   const TopoDS_Edge& aE1,
+                   const TopoDS_Face& aF)
 {
   Standard_Real aT, aFirst, aLast;
   Handle(Geom2d_Curve) aC2D;
@@ -700,7 +695,7 @@ static
 // purpose:
 //=======================================================================
  Standard_Real AngleIn(const TopoDS_Edge& aEIn,
-                      const BOP_ListOfEdgeInfo& aLEInfo)
+                       const BOP_ListOfEdgeInfo& aLEInfo)
 {
   Standard_Real anAngleIn;
   Standard_Boolean anIsIn;
@@ -725,9 +720,9 @@ static
 // purpose:
 //=======================================================================
  Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
-                             const Standard_Real aAngleOut)
+                              const Standard_Real aAngleOut)
 {
-  Standard_Real aTwoPi=Standard_PI+Standard_PI;
+  Standard_Real aTwoPi = M_PI+M_PI;
   Standard_Real dA, A1, A2, AIn, AOut ;
 
   AIn=aAngleIn;
@@ -735,25 +730,27 @@ static
   if (AIn >= aTwoPi) {
     AIn=AIn-aTwoPi;
   }
-  
+
   if (AOut >= aTwoPi) {
     AOut=AOut-aTwoPi;
   }
 
-  A1=AIn+Standard_PI;
-  
+  A1 = AIn + M_PI;
+
   if (A1 >= aTwoPi) {
     A1=A1-aTwoPi;
   }
-  
+
   A2=AOut;
-  
+
   dA=A1-A2;
   if (dA <= 0.) {
     dA=aTwoPi+dA;
+    if (dA <= 1.e-14) {
+      dA=aTwoPi;
+    }
   }
   //xx
-  //else if (dA <= 1.e-15) {
   else if (dA <= 1.e-14) {
     dA=aTwoPi;
   }
@@ -761,11 +758,11 @@ static
 }
 //=======================================================================
 // function: GetNextVertex
-// purpose: 
+// purpose:
 //=======================================================================
  void GetNextVertex(const TopoDS_Vertex& aV,
-                   const TopoDS_Edge& aE,
-                   TopoDS_Vertex& aV1)
+                    const TopoDS_Edge& aE,
+                    TopoDS_Vertex& aV1)
 {
   TopoDS_Iterator aIt;
   //
@@ -781,13 +778,13 @@ static
 }
 //=======================================================================
 // function: Angle2D
-// purpose: 
+// purpose:
 //=======================================================================
   Standard_Real Angle2D (const TopoDS_Vertex& aV,
-                        const TopoDS_Edge& anEdge,
-                        const TopoDS_Face& myFace,
-                        const GeomAdaptor_Surface& aGAS,
-                        const Standard_Boolean aFlag)
+                         const TopoDS_Edge& anEdge,
+                         const TopoDS_Face& myFace,
+                         const GeomAdaptor_Surface& aGAS,
+                         const Standard_Boolean aFlag)
 {
   Standard_Real aFirst, aLast, aToler, dt, aTV, aTV1, anAngle, aTX;
   gp_Pnt2d aPV, aPV1;
@@ -799,19 +796,16 @@ static
     return 0.;
   }
   //
-  BOPTools_Tools2D::CurveOnSurface (anEdge, myFace, aC2D, 
-                                   aFirst, aLast, aToler, Standard_True);
+  BOPTools_Tools2D::CurveOnSurface (anEdge, myFace, aC2D,
+                                    aFirst, aLast, aToler, Standard_True);
   //dt=1.e-7;
-  //modified by NIZNHY-PKV Wed Sep 10 14:06:04 2008f
-  //dt=Tolerance2D(aV, aGAS);
   dt=2.*Tolerance2D(aV, aGAS);
-  //modified by NIZNHY-PKV Wed Sep 10 14:06:07 2008t
   //
   aTX=0.25*(aLast - aFirst);
   if(dt > aTX) {
     // to save direction of the curve as much as it possible
     // in the case of big tolerances
-    dt = aTX; 
+    dt = aTX;
   }
   //
   if (fabs (aTV-aFirst) < fabs(aTV - aLast)) {
@@ -840,7 +834,7 @@ static
 }
 //=======================================================================
 // function: Angle
-// purpose: 
+// purpose:
 //=======================================================================
 Standard_Real Angle (const gp_Dir2d& aDir2D)
 {
@@ -848,14 +842,40 @@ Standard_Real Angle (const gp_Dir2d& aDir2D)
   Standard_Real anAngle = aRefDir.Angle(aDir2D);
 
   if (anAngle < 0.)
-    anAngle += Standard_PI + Standard_PI;
+    anAngle += M_PI + M_PI;
 
   return anAngle;
 }
-//
+//modified by NIZNHY-PKV Thu Apr 19 09:02:04 2012f
 //=======================================================================
 // function: NbWaysOut
-// purpose: 
+// purpose:
+//=======================================================================
+Standard_Integer NbWaysOut(const TopoDS_Edge& aEOuta,
+                          const BOP_ListOfEdgeInfo& aLEInfo)
+{
+  Standard_Boolean bIsOut, bIsNotPassed;
+  Standard_Integer iCnt=0;
+  BOP_ListIteratorOfListOfEdgeInfo anIt;
+  //
+  anIt.Initialize(aLEInfo);
+  for (; anIt.More(); anIt.Next()) {
+    BOP_EdgeInfo& aEI=anIt.Value();
+    const TopoDS_Edge& aE=aEI.Edge();
+    bIsOut=!aEI.IsIn();
+    bIsNotPassed=!aEI.Passed();
+    if (bIsOut && bIsNotPassed) {
+      if (!aE.IsSame(aEOuta)) {
+       iCnt++;
+      }
+    }
+  }
+  return iCnt;
+}
+/*
+//=======================================================================
+// function: NbWaysOut
+// purpose:
 //=======================================================================
 Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& aLEInfo)
 {
@@ -875,3 +895,5 @@ Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& aLEInfo)
   }
   return iCnt;
 }
+*/
+//modified by NIZNHY-PKV Thu Apr 19 09:01:57 2012t