0026150: BRepOffsetAPI_ThruSections doesn't implement history method Generated().
[occt.git] / src / BRepFill / BRepFill_CompatibleWires.cxx
index 12f6770..26c7318 100644 (file)
@@ -5,8 +5,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BRepFill_CompatibleWires.ixx>
 
+#include <Bnd_Box.hxx>
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
 #include <BRepAdaptor_Curve.hxx>
-
+#include <BRepBndLib.hxx>
+#include <BRepCheck_Wire.hxx>
+#include <BRepExtrema_DistShapeShape.hxx>
 #include <BRepFill.hxx>
+#include <BRepFill_CompatibleWires.hxx>
+#include <BRepGProp.hxx>
 #include <BRepLib.hxx>
 #include <BRepLib_FindSurface.hxx>
-#include <BRepLib_MakeWire.hxx>
 #include <BRepLib_MakeEdge.hxx>
-#include <BRepCheck_Wire.hxx>
-#include <BRepExtrema_DistShapeShape.hxx>
-#include <Bnd_Box.hxx>
-#include <BRepBndLib.hxx>
-#include <BRep_Builder.hxx>
-#include <BRep_Tool.hxx>
-#include <BRepTools_WireExplorer.hxx>
+#include <BRepLib_MakeWire.hxx>
 #include <BRepLProp.hxx>
-#include <BRepGProp.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_Surface.hxx>
+#include <gp.hxx>
+#include <gp_Ax2.hxx>
+#include <gp_Circ.hxx>
+#include <gp_Elips.hxx>
+#include <gp_Pln.hxx>
+#include <gp_Vec.hxx>
 #include <GProp_GProps.hxx>
 #include <GProp_PrincipalProps.hxx>
-#include <Geom_Surface.hxx>
-#include <Geom_Plane.hxx>
 #include <Precision.hxx>
-#include <TopAbs.hxx> 
+#include <Standard_ConstructionError.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <TColgp_HArray1OfVec.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TColStd_MapOfInteger.hxx>
+#include <TColStd_SequenceOfReal.hxx>
+#include <TopAbs.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopTools_DataMapOfShapeListOfShape.hxx>
-#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
+#include <TopTools_DataMapOfShapeListOfShape.hxx>
+#include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
 #include <TopTools_HSequenceOfShape.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
 #include <TopTools_SequenceOfShape.hxx>
-#include <TopTools_ListOfShape.hxx>    
-
-#include <gp.hxx>
-#include <gp_Vec.hxx>
-#include <gp_Ax2.hxx>
-#include <gp_Pln.hxx>
-#include <gp_Circ.hxx>
-#include <gp_Elips.hxx>
-#include <TColgp_HArray1OfVec.hxx>
-#include <TColgp_HArray1OfPnt.hxx>
-
-#include <TColStd_Array1OfInteger.hxx>
-#include <TColStd_Array1OfReal.hxx>
-#include <TColStd_SequenceOfReal.hxx>
 
-#ifdef DEB_EFV
+#ifdef OCCT_DEBUG_EFV
 static void EdgesFromVertex (const TopoDS_Wire&   W,
                             const TopoDS_Vertex& V, 
                             TopoDS_Edge& E1, 
@@ -115,6 +117,30 @@ static void EdgesFromVertex (const TopoDS_Wire&   W,
 }
                                      
 #endif
+
+//=======================================================================
+//function : AddNewEdge
+//purpose  : for <theEdge> find all newest edges
+//           in <theEdgeNewEdges> recursively
+//=======================================================================
+
+static void AddNewEdge(const TopoDS_Shape& theEdge,
+                       const TopTools_DataMapOfShapeSequenceOfShape& theEdgeNewEdges,
+                       TopTools_ListOfShape& ListNewEdges)
+{
+  if (theEdgeNewEdges.IsBound(theEdge))
+  {
+    const TopTools_SequenceOfShape& NewEdges = theEdgeNewEdges(theEdge);
+    for (Standard_Integer i = 1; i <= NewEdges.Length(); i++)
+    {
+      TopoDS_Shape anEdge = NewEdges(i);
+      AddNewEdge(anEdge, theEdgeNewEdges, ListNewEdges);
+    }
+  }
+  else
+    ListNewEdges.Append(theEdge);
+}
+
 static void SeqOfVertices (const TopoDS_Wire&   W,
                           TopTools_SequenceOfShape& S)
 {
@@ -138,42 +164,61 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P)
   BRepLib_FindSurface findPlanarSurf;
   Handle(Geom_Surface) S;
   TopLoc_Location      L;
-  
+
   GProp_GProps GP;
-  BRepGProp::LinearProperties(W,GP);
-  gp_Pnt Bary = GP.CentreOfMass();
+  gp_Pnt Bary;
+  Standard_Boolean isBaryDefined = Standard_False;
 
 // shielding for particular cases : only one edge circle or ellipse
 // on a closed wire !
-  Standard_Integer nbEdges = 0;
-  BRepTools_WireExplorer anExp;
-  anExp.Init(W);
+
   Standard_Boolean wClosed = W.Closed();
-  if (!wClosed) {
+  if (!wClosed)
+  {
     // it is checked if the vertices are the same.
     TopoDS_Vertex V1, V2;
     TopExp::Vertices(W,V1,V2);
     if ( V1.IsSame(V2)) wClosed = Standard_True;
   }
-  TopoDS_Edge Edge = TopoDS::Edge(anExp.Current());
-  Standard_Real first, last;
-  Handle(Geom_Curve) curv = BRep_Tool::Curve(Edge, first, last);
-  if (wClosed) {
-    GeomAdaptor_Curve AdC;
-    AdC.Load(curv);
-    for(; anExp.More(); anExp.Next()) {
+
+  if (wClosed)
+  {
+    Standard_Integer nbEdges = 0;
+    TopoDS_Iterator anIter;
+    anIter.Initialize(W);
+    for(; anIter.More(); anIter.Next())
       nbEdges ++;
+
+    if(nbEdges == 1)
+    {
+      GeomAdaptor_Curve AdC;
+      Standard_Real first, last;
+      anIter.Initialize(W);
+      AdC.Load(BRep_Tool::Curve(TopoDS::Edge(anIter.Value()), first, last));
+
+      if (AdC.GetType() == GeomAbs_Circle)
+      {
+        Bary = AdC.Circle().Location();
+        isBaryDefined = Standard_True;
+      }
+
+      if (AdC.GetType() == GeomAbs_Ellipse)
+      {
+        Bary = AdC.Ellipse().Location();
+        isBaryDefined = Standard_True;
+      }
     }
-    if ( nbEdges==1 && AdC.GetType() == GeomAbs_Circle ) {
-      Bary = AdC.Circle().Location();
-    }
-    if ( nbEdges==1 && AdC.GetType() == GeomAbs_Ellipse ) {
-      Bary = AdC.Ellipse().Location();
-    }
+  }
+
+  if (!isBaryDefined)
+  {
+    BRepGProp::LinearProperties(W,GP);
+    Bary = GP.CentreOfMass();
   }
 
   findPlanarSurf.Init(W, -1, Standard_True);
-  if ( findPlanarSurf.Found()) {
+  if ( findPlanarSurf.Found())
+  {
     S = findPlanarSurf.Surface();
     L = findPlanarSurf.Location();
     if (!L.IsIdentity()) S = Handle(Geom_Surface)::
@@ -181,7 +226,8 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P)
     P = (Handle(Geom_Plane)::DownCast(S))->Pln();
     P.SetLocation(Bary);
   }
-  else {
+  else
+  {
     // wire not plane !
     GProp_PrincipalProps Pp  = GP.PrincipalProperties();
     gp_Vec Vec;
@@ -189,28 +235,35 @@ static Standard_Boolean PlaneOfWire (const TopoDS_Wire& W, gp_Pln& P)
     Pp.RadiusOfGyration(R1,R2,R3);
     Standard_Real RMax = Max(Max(R1,R2),R3);
     if ( ( Abs(RMax-R1)<Tol && Abs(RMax-R2)<Tol )
-       || ( Abs(RMax-R1)<Tol && Abs(RMax-R3)<Tol ) 
-       || ( Abs(RMax-R2)<Tol && Abs(RMax-R3)<Tol ) )
+      || ( Abs(RMax-R1)<Tol && Abs(RMax-R3)<Tol ) 
+      || ( Abs(RMax-R2)<Tol && Abs(RMax-R3)<Tol ) )
       isplane = Standard_False;
-    else {
-      if (R1>=R2 && R1>=R3) {
-       Vec = Pp.FirstAxisOfInertia();
+    else
+    {
+      if (R1>=R2 && R1>=R3)
+      {
+        Vec = Pp.FirstAxisOfInertia();
       }
-      else if (R2>=R1 && R2>=R3) {
-       Vec = Pp.SecondAxisOfInertia();
+      else if (R2>=R1 && R2>=R3)
+      {
+        Vec = Pp.SecondAxisOfInertia();
       }
-      else if (R3>=R1 && R3>=R2) {
-       Vec = Pp.ThirdAxisOfInertia();
+      else if (R3>=R1 && R3>=R2)
+      {
+        Vec = Pp.ThirdAxisOfInertia();
       }
       gp_Dir NDir(Vec);
-      if (R3<=R2 && R3<=R1) {
-       Vec = Pp.ThirdAxisOfInertia();
+      if (R3<=R2 && R3<=R1)
+      {
+        Vec = Pp.ThirdAxisOfInertia();
       }
-      else if (R2<=R1 && R2<=R3) {
-       Vec = Pp.SecondAxisOfInertia();
+      else if (R2<=R1 && R2<=R3)
+      {
+        Vec = Pp.SecondAxisOfInertia();
       }
-      else if (R1<=R2 && R1<=R3) {
-       Vec = Pp.FirstAxisOfInertia();
+      else if (R1<=R2 && R1<=R3)
+      {
+        Vec = Pp.FirstAxisOfInertia();
       }
       gp_Dir XDir(Vec);
       gp_Ax3 repere(Bary,NDir,XDir);
@@ -402,7 +455,8 @@ static Standard_Boolean EdgeIntersectOnWire (const gp_Pnt& P1,
                                             const TopTools_DataMapOfShapeListOfShape& Map,
                                             const TopoDS_Wire&   W,
                                             TopoDS_Vertex& Vsol,
-                                            TopoDS_Wire&   newW)
+                                            TopoDS_Wire&   newW,
+                                             TopTools_DataMapOfShapeSequenceOfShape& theEdgeNewEdges)
 {
 
   BRepTools_WireExplorer anExp;
@@ -434,23 +488,24 @@ static Standard_Boolean EdgeIntersectOnWire (const gp_Pnt& P1,
   if (DSS.IsDone()) {
     // choose the solution closest to P2
     Standard_Integer isol = 1;
-    Standard_Real dss = P2.Distance(DSS.PointOnShape2(isol));
+    gp_Pnt Psol = DSS.PointOnShape2(isol);
+    Standard_Real dss = P2.Distance(Psol);
     for (Standard_Integer iss=2; iss<=DSS.NbSolution(); iss++) {
-      if (dss>P2.Distance(DSS.PointOnShape2(iss))) {
-       dss = P2.Distance(DSS.PointOnShape2(iss));
-       isol = iss;
+      gp_Pnt Pss = DSS.PointOnShape2(iss);
+      Standard_Real aDist = P2.Distance(Pss);
+      if (dss > aDist) {
+        dss = aDist;
+        isol = iss;
+#ifdef OCCT_DEBUG
+        Psol = Pss;
+#endif
       }
     }
-#ifdef DEB
-    gp_Pnt Psol = 
-#endif
-      DSS.PointOnShape2(isol);
+
     // is the solution a new vertex ?
     NewVertex = (DSS.SupportTypeShape2(isol) != BRepExtrema_IsVertex);
     if (NewVertex) {
-      TopoDS_Shape aLocalShape = DSS.SupportOnShape2(isol);
-      TopoDS_Edge E = TopoDS::Edge(aLocalShape);
-//      TopoDS_Edge E = TopoDS::Edge(DSS.SupportOnShape2(isol));
+      TopoDS_Edge E = TopoDS::Edge(DSS.SupportOnShape2(isol));
       Standard_Real tol = Precision::PConfusion();
       Standard_Real first,last,param;
       BRep_Tool::Range(E,first,last);
@@ -481,6 +536,8 @@ static Standard_Boolean EdgeIntersectOnWire (const gp_Pnt& P1,
       TopoDS_Shape aLocalShape = DSS.SupportOnShape2(isol);
       TopoDS_Edge E = TopoDS::Edge(aLocalShape);
 //      TopoDS_Edge E = TopoDS::Edge(DSS.SupportOnShape2(isol));
+      TopTools_SequenceOfShape EmptySeq;
+      theEdgeNewEdges.Bind(E, EmptySeq);
       Standard_Real first,last,param;
       DSS.ParOnEdgeS2(isol,param);
       BRep_Tool::Range(E,first,last);
@@ -495,6 +552,7 @@ static Standard_Boolean EdgeIntersectOnWire (const gp_Pnt& P1,
          SR.Clear();
          SR.Append(param);
          TrimEdge(E,SR,first,last,SO,SE);
+          theEdgeNewEdges(E) = SE;
          TopoDS_Vertex VV1,VV2;
          TopExp::Vertices(TopoDS::Edge(SE.Value(1)),VV1,VV2);
          if (TopExp::FirstVertex(E).IsSame(VV1)
@@ -687,6 +745,24 @@ const TopTools_ListOfShape& BRepFill_CompatibleWires::GeneratedShapes
   }
 }
 
+//==========================================================================
+//function : IsDegeneratedFirstSection
+//purpose  : 
+//==========================================================================
+Standard_Boolean BRepFill_CompatibleWires::IsDegeneratedFirstSection() const
+{
+  return myDegen1;
+}
+
+//=========================================================================
+//function : IsDegeneratedLastSection
+//purpose  : 
+//=========================================================================
+Standard_Boolean BRepFill_CompatibleWires::IsDegeneratedLastSection() const
+{
+  return myDegen2;
+}
+
 
 //=======================================================================
 //function : Perform
@@ -793,7 +869,7 @@ void BRepFill_CompatibleWires::Perform (const Standard_Boolean WithRotation)
   else {
     // There are open and closed sections :
     // not processed
-    Standard_DomainError::Raise("Sections must be all closed or all open");
+    throw Standard_DomainError("Sections must be all closed or all open");
   }
   
 }
@@ -824,17 +900,18 @@ void BRepFill_CompatibleWires::
   // initialisation 
   Standard_Integer NbSects=myWork.Length();
   BRepTools_WireExplorer anExp;
-  TopoDS_Vertex V1, V2;
-  
+  TopTools_DataMapOfShapeSequenceOfShape EdgeNewEdges;
+
   Standard_Boolean allClosed = Standard_True;
   Standard_Integer i,ii,ideb=1,ifin=NbSects;
+
   for (i=1; i<=NbSects; i++) {
     Handle(BRepCheck_Wire) Checker = new BRepCheck_Wire(TopoDS::Wire(myWork(i)));
     allClosed = (allClosed && (Checker->Closed() == BRepCheck_NoError));
     //allClosed = (allClosed && myWork(i).Closed());
   }
   if (!allClosed)
-    Standard_NoSuchObject::Raise("BRepFill_CompatibleWires::SameNumberByPolarMethod : the wires must be closed");
+    throw Standard_NoSuchObject("BRepFill_CompatibleWires::SameNumberByPolarMethod : the wires must be closed");
   
   // sections ponctuelles, sections bouclantes ?
   if (myDegen1) ideb++;
@@ -915,10 +992,8 @@ void BRepFill_CompatibleWires::
     // sequence of vertices of the first wire
     SeqOfVertices(wire1,SeqV);
     if (SeqV.Length()>NbMaxV) 
-      Standard_NoSuchObject::Raise("BRepFill::SameNumberByPolarMethod failed");
+      throw Standard_NoSuchObject("BRepFill::SameNumberByPolarMethod failed");
     
-    // extremity of the first wire
-    V1 = TopoDS::Vertex(SeqV.Value(1));        
     // loop on vertices of wire1
     for (ii=1;ii<=SeqV.Length();ii++) {
       
@@ -946,8 +1021,8 @@ void BRepFill_CompatibleWires::
       if (Pnew.Distance(Pos->Value(i-1))>Precision::Confusion()) {
        Standard_Real percent = myPercent;
        NewVertex = EdgeIntersectOnWire(Pos->Value(i-1),Pnew,percent,
-                                   RMap,TopoDS::Wire(myWork(i-1)),
-                                   Vsol,newwire);
+                                        RMap,TopoDS::Wire(myWork(i-1)),
+                                        Vsol,newwire,EdgeNewEdges);
        if (NewVertex) myWork(i-1) = newwire;
        RMap(Vi).Append(Vsol);
       }
@@ -992,10 +1067,8 @@ void BRepFill_CompatibleWires::
     // sequence of vertices of the first wire
     SeqOfVertices(wire1,SeqV);
     if ( SeqV.Length()>NbMaxV || SeqV.Length()>SizeMap ) 
-      Standard_NoSuchObject::Raise("BRepFill::SameNumberByPolarMethod failed");
+      throw Standard_NoSuchObject("BRepFill::SameNumberByPolarMethod failed");
     
-    // extremity of the first wire
-    V1 = TopoDS::Vertex(SeqV.Value(1));
 
     // next wire 
     const TopoDS_Wire& wire2 = TopoDS::Wire(myWork(i+1));
@@ -1032,8 +1105,8 @@ void BRepFill_CompatibleWires::
        if (Pnew.Distance(Pos->Value(i+1))>Precision::Confusion()) {
          Standard_Real percent = myPercent;
          NewVertex = EdgeIntersectOnWire(Pos->Value(i+1),Pnew,percent,
-                                     MapVLV,TopoDS::Wire(myWork(i+1)),
-                                     Vsol,newwire);
+                                          MapVLV,TopoDS::Wire(myWork(i+1)),
+                                          Vsol,newwire,EdgeNewEdges);
          MapVLV(VRoot).Append(Vsol);
          if (NewVertex) myWork(i+1) = newwire;
        }
@@ -1082,11 +1155,11 @@ void BRepFill_CompatibleWires::
        // parse candidate edges
        Standard_Real scal1,scal2;
        if ( (V1.IsSame(VVF)&&V2.IsSame(VVL)) || (V2.IsSame(VVF)&&V1.IsSame(VVL)) ) {
-         Standard_Real U1 = BRep_Tool::Parameter(VVF,E);
-         Standard_Real U2 = BRep_Tool::Parameter(VVL,E);
-         BRepAdaptor_Curve Curve(E);
-         gp_Pnt PP1 = Curve.Value(0.1*(U1+9*U2));
-         gp_Pnt PP2 = Curve.Value(0.1*(9*U1+U2));
+         Standard_Real U1param = BRep_Tool::Parameter(VVF,E);
+         Standard_Real U2param = BRep_Tool::Parameter(VVL,E);
+         BRepAdaptor_Curve CurveE(E);
+         gp_Pnt PP1 = CurveE.Value(0.1*(U1param +9* U2param));
+         gp_Pnt PP2 = CurveE.Value(0.1*(9* U1param + U2param));
   
          for (rang=i;rang>ideb;rang--) {
            Transform(WithRotation, PP1,
@@ -1115,6 +1188,8 @@ void BRepFill_CompatibleWires::
          }
        }
       } //end of for(; itW.More(); itW.Next())
+    if (Esol.IsNull())
+      throw Standard_ConstructionError("BRepFill :: profiles are inconsistent");
     MW.Add(Esol);
 
     TopTools_ListOfShape ConnectedEdges;
@@ -1166,7 +1241,22 @@ void BRepFill_CompatibleWires::
   }
   
   // blocking sections?
-  if (vClosed) myWork(myWork.Length()) = myWork(1);
+  if (vClosed)
+  {
+    TopoDS_Iterator iter1(myWork(myWork.Length())), iter2(myWork(1));
+    for (; iter1.More(); iter1.Next(), iter2.Next())
+    {
+      const TopoDS_Shape& anEdge = iter1.Value();
+      const TopoDS_Shape& aNewEdge = iter2.Value();
+      if (!anEdge.IsSame(aNewEdge))
+      {
+        TopTools_SequenceOfShape aSeq;
+        aSeq.Append(aNewEdge);
+        EdgeNewEdges.Bind(anEdge, aSeq);
+      }
+    }
+    myWork(myWork.Length()) = myWork(1);
+  }
 
   // check the number of edges for debug
   Standard_Integer nbmax=0, nbmin=0;
@@ -1180,9 +1270,22 @@ void BRepFill_CompatibleWires::
     if (nbmin>nbEdges) nbmin = nbEdges;
   }
   if (nbmin!=nbmax) {
-    Standard_NoSuchObject::Raise("BRepFill_CompatibleWires::SameNumberByPolarMethod failed");
+    throw Standard_NoSuchObject("BRepFill_CompatibleWires::SameNumberByPolarMethod failed");
   }
 
+  //Fill <myMap>
+  TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap(myMap);
+  for (; itmap.More(); itmap.Next())
+  {
+    TopoDS_Shape anEdge = itmap.Key();
+    TopTools_ListOfShape ListOfNewEdges;
+
+    //for each edge of <myMap> find all newest edges
+    //in <EdgeNewEdges> recursively
+    AddNewEdge(anEdge, EdgeNewEdges, ListOfNewEdges);
+    
+    myMap(anEdge) = ListOfNewEdges;
+  }
 }
 
 //=======================================================================
@@ -1221,10 +1324,12 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
     if (report || nbmin<nbmax) {
       // insertion of cuts
       Standard_Integer nbdec=(nbmax-1)*nbSects+1;
-      Standard_Real tol = 0.01;
       TColStd_Array1OfReal dec(1,nbdec);
       dec.Init(0);
       dec(2)=1;
+
+      TColStd_Array1OfReal WireLen(1, nbSects);
+      
       // calculate the table of cuts
       Standard_Integer j,k,l;
       for (i=1; i<=nbSects; i++) {
@@ -1238,6 +1343,7 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
        TColStd_Array1OfReal ACR(0,nbE);
        ACR.Init(0);
        BRepFill::ComputeACR(wire1, ACR);
+        WireLen(i) = ACR(0);
        // insertion of ACR of the wire in the table of cuts
        for (j=1; j<ACR.Length()-1; j++) {
          k=1;
@@ -1245,7 +1351,7 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
            k++;
            if (k>nbdec) break;
          }
-         if (dec(k-1)+tol<ACR(j)&& ACR(j)+tol<dec(k)) {
+         if (dec(k-1)<ACR(j)&& ACR(j)<dec(k)) {
            for (l=nbdec-1;l>=k;l--) {
              dec(l+1)=dec(l);
            }
@@ -1266,10 +1372,38 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
        dec2(k) = dec(k);
       }
       
+      //Check of cuts: are all the new edges long enouph or not
+      TColStd_MapOfInteger CutsToRemove;
+      for (k = 1; k <= nbdec; k++)
+      {
+        Standard_Real Knot1 = dec2(k);
+        Standard_Real Knot2 = (k == nbdec)? 1. : dec2(k+1);
+        Standard_Real AllLengthsNull = Standard_True;
+        for (i = 1; i <= nbSects; i++)
+        {
+          Standard_Real EdgeLen = (Knot2 - Knot1) * WireLen(i);
+          if (EdgeLen > Precision::Confusion())
+          {
+            AllLengthsNull = Standard_False;
+            break;
+          }
+        }
+        if (AllLengthsNull)
+          CutsToRemove.Add(k);
+      }
+      Standard_Integer NewNbDec = nbdec - CutsToRemove.Extent();
+      TColStd_Array1OfReal dec3(1, NewNbDec);
+      i = 1;
+      for (k = 1; k <= nbdec; k++)
+        if (!CutsToRemove.Contains(k))
+          dec3(i++) = dec2(k);
+      ///////////////////
+      
       // insertion of cuts in each wire
       for (i=1; i<=nbSects; i++) {
        const TopoDS_Wire& oldwire = TopoDS::Wire(myWork(i));
-       TopoDS_Wire newwire = BRepFill::InsertACR(oldwire, dec2, tol);
+        Standard_Real tol = Precision::Confusion() / WireLen(i);
+       TopoDS_Wire newwire = BRepFill::InsertACR(oldwire, dec3, tol);
        BRepTools_WireExplorer anExp1,anExp2;
        anExp1.Init(oldwire);
        anExp2.Init(newwire);
@@ -1341,7 +1475,8 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
   }
   
   // blocking sections ?
-  if (vClosed) myWork(myWork.Length()) = myWork(1);
+  if (vClosed)
+    myWork(myWork.Length()) = myWork(1);
 
   // check the number of edges for debug
   nbmax = 0;
@@ -1355,7 +1490,7 @@ void BRepFill_CompatibleWires::SameNumberByACR(const  Standard_Boolean  report)
     if (nbmin>nbEdges(i)) nbmin = nbEdges(i);
   }
   if (nbmax!=nbmin) 
-    Standard_NoSuchObject::Raise("BRepFill_CompatibleWires::SameNumberByACR failed");
+    throw Standard_NoSuchObject("BRepFill_CompatibleWires::SameNumberByACR failed");
 }
 
 //=======================================================================
@@ -1400,7 +1535,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
   }
 */
   if (!allClosed) 
-    Standard_NoSuchObject::Raise("BRepFill_CompatibleWires::ComputeOrigin : the wires must be closed");
+    throw Standard_NoSuchObject("BRepFill_CompatibleWires::ComputeOrigin : the wires must be closed");
 
 /*  
   // Max number of possible cuts
@@ -1457,12 +1592,12 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
   gp_Vec NormalOfFirstPlane = FirstPlane.Axis().Direction();
   for (i = ideb+1; i <= ifin; i++)
     {
-      const TopoDS_Wire& wire = TopoDS::Wire(myWork(i));
+      const TopoDS_Wire& aWire = TopoDS::Wire(myWork(i));
 
       //Compute offset vector as current bary center projected on first plane
       //to first bary center
       gp_Pln CurPlane;
-      PlaneOfWire(wire, CurPlane);
+      PlaneOfWire(aWire, CurPlane);
       gp_Pnt CurBary = CurPlane.Location();
       gp_Vec aVec(FirstBary, CurBary);
       gp_Vec anOffsetProj = (aVec * NormalOfFirstPlane) * NormalOfFirstPlane;
@@ -1474,7 +1609,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
       BB.MakeWire(newwire);
       
       TopTools_SequenceOfShape SeqVertices, SeqEdges;
-      for (anExp.Init(wire); anExp.More(); anExp.Next())
+      for (anExp.Init(aWire); anExp.More(); anExp.Next())
        {
          SeqVertices.Append( anExp.CurrentVertex() );
          SeqEdges.Append( anExp.Current() );
@@ -1673,7 +1808,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
       newwire.Orientation( TopAbs_FORWARD );
       myWork(i) = newwire;
     }
-#ifdef DEB_EFV
+#ifdef OCCT_DEBUG_EFV
 
   for ( i=ideb; i<=myWork.Length(); i++) {
     
@@ -1735,7 +1870,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
       gp_Pnt Pmini,P1,P2;
       SeqOfVertices(wire,SeqV);
       if (SeqV.Length()>NbMaxV) 
-       Standard_NoSuchObject::Raise("BRepFill::ComputeOrigin failed");
+       throw Standard_NoSuchObject("BRepFill::ComputeOrigin failed");
       if (!polar) {
        // choix du vertex le plus proche comme origine
        distmini = Precision::Infinite();
@@ -1825,7 +1960,7 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
        EdgesFromVertex(wire,Vmini,E1,E2);
        
        TopExp::Vertices(E1,V1,V2,Standard_True);
-#ifndef DEB
+#ifndef OCCT_DEBUG
        Standard_Real U1=0, U2=0;
 #else
        Standard_Real U1, U2;
@@ -1927,7 +2062,8 @@ void BRepFill_CompatibleWires::ComputeOrigin(const  Standard_Boolean /*polar*/ )
 #endif
   
   // blocking sections ?
-  if (vClosed) myWork(myWork.Length()) = myWork(1);
+  if (vClosed)
+    myWork(myWork.Length()) = myWork(1);
 }
 
 //=======================================================================
@@ -1959,7 +2095,7 @@ void BRepFill_CompatibleWires::SearchOrigin()
     allOpen = (allOpen && !myWork(i).Closed());
   }
   if (!allOpen)
-    Standard_NoSuchObject::Raise("BRepFill_CompatibleWires::SearchOrigin : the wires must be open");
+    throw Standard_NoSuchObject("BRepFill_CompatibleWires::SearchOrigin : the wires must be open");
 
   // init
 
@@ -2089,5 +2225,6 @@ void BRepFill_CompatibleWires::SearchOrigin()
   }
   
   // blocking sections ?
-  if (vClosed) myWork(myWork.Length()) = myWork(1);
+  if (vClosed)
+    myWork(myWork.Length()) = myWork(1);
 }