0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / BRepBuilderAPI / BRepBuilderAPI_Sewing.cxx
index cd5f655..58dd718 100644 (file)
@@ -41,7 +41,6 @@
 
 #define TEST 1
 
-#include <BRepBuilderAPI_Sewing.ixx>
 
 #include <Bnd_Box.hxx>
 #include <Bnd_Box2d.hxx>
 #include <BndLib_Add2dCurve.hxx>
 #include <BndLib_Add3dCurve.hxx>
 #include <BRep_Builder.hxx>
+#include <BRep_ListOfPointRepresentation.hxx>
+#include <BRep_PointOnCurve.hxx>
 #include <BRep_Tool.hxx>
+#include <BRep_TVertex.hxx>
+#include <BRepBuilderAPI_BndBoxTreeSelector.hxx>
+#include <BRepBuilderAPI_CellFilter.hxx>
+#include <BRepBuilderAPI_Sewing.hxx>
+#include <BRepBuilderAPI_VertexInspector.hxx>
 #include <BRepLib.hxx>
+#include <BRepTools.hxx>
 #include <BRepTools_Quilt.hxx>
+#include <BRepTools_ReShape.hxx>
 #include <BSplCLib.hxx>
 #include <Extrema_ExtPC.hxx>
 #include <GCPnts_AbscissaPoint.hxx>
 #include <Geom_BSplineCurve.hxx>
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
+#include <Geom_OffsetSurface.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
 #include <Geom_Surface.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <GeomAdaptor_Surface.hxx>
 #include <GeomLib.hxx>
 #include <gp_Pnt.hxx>
 #include <gp_Vec.hxx>
-//#include <LocalAnalysis_SurfaceContinuity.hxx>
+#include <Message_ProgressIndicator.hxx>
+#include <Message_ProgressSentry.hxx>
+#include <NCollection_UBTreeFiller.hxx>
 #include <Precision.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <Standard_Type.hxx>
 #include <TColgp_Array1OfVec.hxx>
 #include <TColgp_SequenceOfPnt.hxx>
 #include <TColStd_Array1OfInteger.hxx>
 #include <TColStd_Array1OfReal.hxx>
+#include <TColStd_Array2OfReal.hxx>
 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <TColStd_ListOfInteger.hxx>
+#include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_SequenceOfReal.hxx>
 #include <TopAbs.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopLoc_Location.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Compound.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS_Wire.hxx>
-#include <TopoDS_Shell.hxx>
 #include <TopTools_Array1OfShape.hxx>
 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
 #include <TopTools_MapIteratorOfMapOfShape.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_SequenceOfShape.hxx>
-#include <TopoDS_Compound.hxx>
-#include <TColStd_Array2OfReal.hxx>
-#include <TColStd_MapIteratorOfMapOfInteger.hxx>
-#include <BRepTools.hxx>
-#include <Geom_RectangularTrimmedSurface.hxx>
-#include <Geom_OffsetSurface.hxx>
-#include <BRep_PointOnCurve.hxx>
-#include <BRep_ListOfPointRepresentation.hxx>
-#include <BRep_TVertex.hxx>
-#include <Message_ProgressSentry.hxx>
-#include <BRepBuilderAPI_VertexInspector.hxx>
-#include <BRepBuilderAPI_CellFilter.hxx>
-#include <BRepBuilderAPI_BndBoxTreeSelector.hxx>
-#include <NCollection_UBTreeFiller.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(BRepBuilderAPI_Sewing,MMgt_TShared)
+
+//#include <LocalAnalysis_SurfaceContinuity.hxx>
 //=======================================================================
 //function : SameRange
 //purpose  : 
 //=======================================================================
-
 Handle(Geom2d_Curve) BRepBuilderAPI_Sewing::SameRange(const Handle(Geom2d_Curve)& CurvePtr,
                                                const Standard_Real FirstOnCurve,
                                                const Standard_Real LastOnCurve,
@@ -335,7 +342,7 @@ void BRepBuilderAPI_Sewing::SameParameter(const TopoDS_Edge& edge) const
 
 TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Shape& edge,
                                               const TopTools_SequenceOfShape& seqEdges,
-                                              const TColStd_SequenceOfInteger& seqForward,
+                                              const TColStd_SequenceOfBoolean& seqForward,
                                               TopTools_MapOfShape& mapMerged,
                                               const Handle(BRepTools_ReShape)& locReShape)
 {
@@ -398,8 +405,8 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Shape& edge,
       if (locReShape != myReShape) Edge2 = TopoDS::Edge(aTmpShape);
 
       // Calculate relative orientation
-      Standard_Integer Orientation = seqForward(i);
-      if (!isForward) Orientation = (Orientation? 0 : 1);
+      Standard_Boolean Orientation = seqForward(i);
+      if (!isForward) Orientation = !Orientation;
 
       // Retrieve faces information for the second edge
       TopoDS_Shape bnd2 = oedge2;
@@ -492,10 +499,85 @@ static Standard_Boolean findNMVertices(const TopoDS_Edge& theEdge,
   return Standard_True;
 }
 
-static inline Standard_Real ComputeToleranceVertex(const Standard_Real dist, const Standard_Real Tol1, const Standard_Real Tol2)
+static void ComputeToleranceVertex(TopoDS_Vertex theV1, TopoDS_Vertex theV2,
+                                   TopoDS_Vertex& theNewV)
 {
-  return (dist * 0.5 + Tol1 + Tol2);
+  Standard_Integer m, n;
+  Standard_Real aR[2], dR, aD, aEps;
+  TopoDS_Vertex aV[2];
+  gp_Pnt aP[2];
+  BRep_Builder aBB;
+  //
+  aEps = RealEpsilon();
+  aV[0] = theV1;
+  aV[1] = theV2;
+  for (m = 0; m < 2; ++m) {
+    aP[m] = BRep_Tool::Pnt(aV[m]);
+    aR[m] = BRep_Tool::Tolerance(aV[m]);
+    }  
+    //
+  m=0; // max R
+  n=1; // min R
+  if (aR[0] < aR[1]) {
+    m=1;
+    n=0;
+  }
+  //
+  dR = aR[m] - aR[n]; // dR >= 0.
+  gp_Vec aVD(aP[m], aP[n]);
+  aD = aVD.Magnitude();
+  //
+  if (aD <= dR || aD < aEps) { 
+    aBB.MakeVertex (theNewV, aP[m], aR[m]);
+  }
+  else {
+    Standard_Real aRr;
+    gp_XYZ aXYZr;
+    gp_Pnt aPr;
+    //
+    aRr = 0.5 * (aR[m] + aR[n] + aD);
+    aXYZr = 0.5 * (aP[m].XYZ() + aP[n].XYZ() - aVD.XYZ() * (dR/aD));
+    aPr.SetXYZ(aXYZr);
+    //
+    aBB.MakeVertex (theNewV, aPr, aRr);
+  }
+  return;
 }
+
+static void ComputeToleranceVertex(TopoDS_Vertex theV1, TopoDS_Vertex theV2,
+                                   TopoDS_Vertex theV3, TopoDS_Vertex& theNewV)
+{
+  Standard_Real aDi, aDmax;
+  gp_Pnt aCenter;
+  gp_Pnt aP[3];
+  Standard_Real aR[3];
+  TopoDS_Vertex aV[3];
+  gp_XYZ aXYZ(0.,0.,0.);
+  aV[0] = theV1;
+  aV[1] = theV2;
+  aV[2] = theV3;
+  for (Standard_Integer i = 0; i < 3; ++i) {
+    aP[i] = BRep_Tool::Pnt(aV[i]);
+    aR[i] = BRep_Tool::Tolerance(aV[i]);
+    aXYZ = aXYZ + aP[i].XYZ();
+  }
+  //
+  aXYZ.Divide(3.0);
+  aCenter.SetXYZ(aXYZ);
+  //
+  aDmax=-1.;
+  for ( Standard_Integer i = 0; i < 3; ++i) {
+    aDi = aCenter.Distance(aP[i]);
+    aDi += aR[i];
+    if (aDi > aDmax)
+      aDmax = aDi;
+  }
+
+  BRep_Builder aBB;
+  aBB.MakeVertex (theNewV, aCenter, aDmax);
+  return;
+}
+
 TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirst,
                                               const TopoDS_Edge& edgeLast,
                                               const TopTools_ListOfShape& listFacesFirst,
@@ -604,111 +686,54 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
     //V21 = TopoDS::Vertex(myReShape->Apply(V21));
     //V22 = TopoDS::Vertex(myReShape->Apply(V22));
 
-    gp_Pnt p11 = BRep_Tool::Pnt(V11);
-    gp_Pnt p12 = BRep_Tool::Pnt(V12);
-    gp_Pnt p21 = BRep_Tool::Pnt(V21); 
-    gp_Pnt p22 = BRep_Tool::Pnt(V22);
-
-    
-
     //Standard_Boolean isRev = Standard_False;
-    gp_Pnt pfirst;
-    Standard_Real Tol1 = 0.;
     if (isClosed1 || isClosed2) {
       // at least one of the edges is closed
       if (isClosed1 && isClosed2) {
         // both edges are closed
-        pfirst.SetXYZ(0.5*(p11.XYZ() + p21.XYZ()));
-        gp_Vec v1 =  p21.XYZ() - p11.XYZ();
-        Standard_Real d1 = v1.Magnitude();
-        Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V21));
-        //Tol1 = Max(pfirst.Distance(p11),pfirst.Distance(p21));
+        ComputeToleranceVertex(V11, V21, V1New);
       }
       else if (isClosed1) {
         // only first edge is closed
-        gp_XYZ pt =0.5*(p21.XYZ()+ p22.XYZ());
-        pfirst.SetXYZ(0.5*(p11.XYZ() + pt));
-        gp_Vec v1 =  p22.XYZ() - p21.XYZ();
-        Standard_Real d1 = v1.Magnitude();
-        Tol1= ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V22),BRep_Tool::Tolerance(V21));
-        gp_Vec v2 =  p11.XYZ() - pt;
-        Standard_Real d2 = v2.Magnitude();
-        Tol1= ComputeToleranceVertex(d2,Tol1,BRep_Tool::Tolerance(V11));
-        //Tol1 = Max(pfirst.Distance(p21),pfirst.Distance(p22));
-        //Tol1 = Max(pfirst.Distance(p11),Tol1);
+        ComputeToleranceVertex(V22, V21, V11, V1New);
       }
       else {
         // only second edge is closed
-        gp_XYZ pt = 0.5*(p11.XYZ()+ p12.XYZ());
-        pfirst.SetXYZ(0.5*(p21.XYZ() + pt));
-        gp_Vec v1 =  p11.XYZ() - p12.XYZ();
-        Standard_Real d1 = v1.Magnitude();
-        Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V12));
-        gp_Vec v2 =  p21.XYZ() - pt;
-        Standard_Real d2 = v2.Magnitude();
-        Tol1 = ComputeToleranceVertex(d2,Tol1,BRep_Tool::Tolerance(V21));
-        //Tol1 = Max(pfirst.Distance(p11),pfirst.Distance(p12));
-        //Tol1 = Max(pfirst.Distance(p21),Tol1);
+        ComputeToleranceVertex(V11, V12, V21, V1New);
       }
-      aBuilder.MakeVertex(V1New,pfirst,Tol1);
       V2New = V1New;
     }
     else {
       // both edges are open
-      gp_Pnt plast;
-      Standard_Real Tol2 = 0.;
       Standard_Boolean isOldFirst = ( secForward ? V11.IsSame(V21) :  V11.IsSame(V22) );
       Standard_Boolean isOldLast = ( secForward ? V12.IsSame(V22) : V12.IsSame(V21)) ;
       if (secForward) {
         //case if vertices already sewed
         if(!isOldFirst)
         {
-          pfirst.SetXYZ(0.5*(p11.XYZ() + p21.XYZ()));
-          gp_Vec v1 =  p21.XYZ() - p11.XYZ();
-          Standard_Real d1 = v1.Magnitude();
-          Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V21));
+          ComputeToleranceVertex(V11, V21, V1New);
         }
         if(!isOldLast)
         {
-          plast.SetXYZ(0.5*(p12.XYZ() + p22.XYZ()));
-
-          gp_Vec v2 =  p22.XYZ() - p12.XYZ();
-          Standard_Real d2 = v2.Magnitude();
-
-          Tol2 = ComputeToleranceVertex(d2,BRep_Tool::Tolerance(V12),BRep_Tool::Tolerance(V22));
+          ComputeToleranceVertex(V12, V22, V2New);
         }
-
       }
       else {
         if(!isOldFirst)
         {
-          pfirst.SetXYZ(0.5*(p11.XYZ() + p22.XYZ()));
-          gp_Vec v1 =  p22.XYZ() - p11.XYZ();
-          Standard_Real d1 = v1.Magnitude();
-          Tol1 = ComputeToleranceVertex(d1,BRep_Tool::Tolerance(V11),BRep_Tool::Tolerance(V22));
+          ComputeToleranceVertex(V11, V22, V1New);
         }
         if(!isOldLast)
         {
-          plast.SetXYZ(0.5*(p12.XYZ() + p21.XYZ()));
-          gp_Vec v2 =  p21.XYZ() - p12.XYZ();
-          Standard_Real d2 = v2.Magnitude();
-          Tol2 = ComputeToleranceVertex(d2,BRep_Tool::Tolerance(V12),BRep_Tool::Tolerance(V21));
+          ComputeToleranceVertex(V12, V21, V2New);
         }
-
       }
-      if(!isOldFirst)
-        aBuilder.MakeVertex(V1New,pfirst,Tol1);
-      else
+      if(isOldFirst)
         V1New = V11;
-       
 
-      if(!isOldLast)
-        aBuilder.MakeVertex(V2New,plast,Tol2);
-      else
+      if(isOldLast)
         V2New = V12;
-
     }
-
     // Add the vertices in the good sense
     TopoDS_Shape anEdge = edge.Oriented(TopAbs_FORWARD);
     TopoDS_Shape aLocalEdge = V1New.Oriented(TopAbs_FORWARD); //(listNode.First()).Oriented(TopAbs_FORWARD);
@@ -870,15 +895,23 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
   }
   Standard_Real tolReached = Precision::Infinite();
   Standard_Boolean isSamePar = Standard_False; 
-  if( isResEdge)
+  try
   {
-    SameParameter(edge);
+    if( isResEdge)
+      SameParameter(edge);
+    
+
     if( BRep_Tool::SameParameter(edge))
     {
       isSamePar = Standard_True;
       tolReached = BRep_Tool::Tolerance(edge);
     }
   }
+  
+  catch(Standard_Failure)
+  {
+    isSamePar = Standard_False;
+  }
  
  
   if (firstCall && ( !isResEdge || !isSamePar || tolReached > myTolerance)) {
@@ -905,10 +938,10 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
 
       // Discretize edge curve
       Standard_Integer i, j, nbp = 23;
-      Standard_Real deltaT = (last3d - first3d) / (nbp 1);
+      Standard_Real deltaT = (last3d - first3d) / (nbp -1);
       TColgp_Array1OfPnt c3dpnt(1,nbp);
       for (i = 1; i <= nbp; i++) 
-        c3dpnt(i) = c3dAdapt.Value(first3d + i*deltaT);
+        c3dpnt(i) = c3dAdapt.Value(first3d + (i-1)*deltaT);
 
       Standard_Real dist = 0., maxTol = -1.0;
       Standard_Boolean more = Standard_True;
@@ -924,9 +957,9 @@ TopoDS_Edge BRepBuilderAPI_Sewing::SameParameterEdge(const TopoDS_Edge& edgeFirs
             aS = Handle(Geom_Surface)::DownCast(surf2->Transformed ( loc2 ));
 
           Standard_Real dist2 = 0.;
-          deltaT = (last - first) / (nbp + 1);
+          deltaT = (last - first) / (nbp - 1);
           for (i = 1; i <= nbp; i++) {
-            gp_Pnt2d aP2d =  c2d2->Value(first + i*deltaT);
+            gp_Pnt2d aP2d =  c2d2->Value(first + (i -1)*deltaT);
             gp_Pnt aP2(0.,0.,0.);
             aS->D0(aP2d.X(),aP2d.Y(), aP2);
             gp_Pnt aP1 = c3dpnt(i);
@@ -1302,7 +1335,7 @@ Standard_Boolean BRepBuilderAPI_Sewing::IsMergedClosed(const TopoDS_Edge& Edge1,
 
 void BRepBuilderAPI_Sewing::AnalysisNearestEdges(const TopTools_SequenceOfShape& sequenceSec,
                                                  TColStd_SequenceOfInteger& seqIndCandidate,
-                                                 TColStd_SequenceOfInteger& seqOrientations,
+                                                 TColStd_SequenceOfBoolean& seqOrientations,
                                                  const Standard_Boolean evalDist)
 {
 
@@ -1432,7 +1465,7 @@ void BRepBuilderAPI_Sewing::AnalysisNearestEdges(const TopTools_SequenceOfShape&
 Standard_Boolean BRepBuilderAPI_Sewing::FindCandidates(TopTools_SequenceOfShape& seqSections,
                                                        TColStd_IndexedMapOfInteger& mapReference,
                                                        TColStd_SequenceOfInteger& seqCandidates,
-                                                       TColStd_SequenceOfInteger& seqOrientations)
+                                                       TColStd_SequenceOfBoolean& seqOrientations)
 {
   Standard_Integer i, nbSections = seqSections.Length();
   if(nbSections <= 1)
@@ -1488,8 +1521,8 @@ Standard_Boolean BRepBuilderAPI_Sewing::FindCandidates(TopTools_SequenceOfShape&
         
         // Reference section is connected to section #i
         Standard_Boolean isInserted = Standard_False;
-        Standard_Integer j, ori = (arrForward(i)? 1 : 0);
-        for (j = 1; (j <= seqCandidates.Length()) && !isInserted; j++) {
+        Standard_Boolean ori = arrForward(i);
+        for (Standard_Integer j = 1; (j <= seqCandidates.Length()) && !isInserted; j++) {
           Standard_Real aDelta = arrDistance(i) - arrDistance(seqCandidates.Value(j));
           
           if( aDelta < Precision::Confusion()) {
@@ -1525,9 +1558,9 @@ Standard_Boolean BRepBuilderAPI_Sewing::FindCandidates(TopTools_SequenceOfShape&
 
   if (myNonmanifold && nbCandidates >1) {
     TColStd_SequenceOfInteger seqNewCandidates;
-    TColStd_SequenceOfInteger seqOrientationsNew;
+    TColStd_SequenceOfBoolean seqOrientationsNew;
     seqCandidates.Prepend(1);
-    seqOrientations.Prepend(1);
+    seqOrientations.Prepend(Standard_True);
     for(Standard_Integer k = 1; k <= seqSections.Length() && seqCandidates.Length() > 1 ; k++) {
       AnalysisNearestEdges(seqSections,seqCandidates,seqOrientations,(k==1));
       if(k == 1 && !seqCandidates.Length()) return Standard_False;
@@ -1627,7 +1660,8 @@ Standard_Boolean BRepBuilderAPI_Sewing::FindCandidates(TopTools_SequenceOfShape&
       if (mapReference.Contains(indCandidate)) break;
       // Find candidates for candidate #indCandidate
       mapReference.Add(indCandidate); // Push candidate in the map
-      TColStd_SequenceOfInteger seqCandidates1, seqOrientations1;
+      TColStd_SequenceOfInteger seqCandidates1;
+      TColStd_SequenceOfBoolean seqOrientations1;
       Standard_Boolean isFound =
         FindCandidates(seqSections,mapReference,seqCandidates1,seqOrientations1);
       mapReference.RemoveLast(); // Pop candidate from the map
@@ -3152,7 +3186,7 @@ void BRepBuilderAPI_Sewing::Merging(const Standard_Boolean /* firstTime */,
     if (!isPrevSplit) {
       // Obtain sequence of edges merged with bound
       TopTools_SequenceOfShape seqMergedWithBound;
-      TColStd_SequenceOfInteger seqMergedWithBoundOri;
+      TColStd_SequenceOfBoolean seqMergedWithBoundOri;
       if (MergedNearestEdges(bound,seqMergedWithBound,seqMergedWithBoundOri)) {
         // Store bound in the map
         MergedWithBound.Bind(bound,bound);
@@ -3229,7 +3263,7 @@ void BRepBuilderAPI_Sewing::Merging(const Standard_Boolean /* firstTime */,
         if (!nbMerged) MergedWithBound.UnBind(bound);
       }
     }
-    Standard_Boolean isMerged = MergedWithBound.Extent();
+    const Standard_Boolean isMerged = !MergedWithBound.IsEmpty();
 
     // Merge with cutting sections
     Handle(BRepTools_ReShape) SectionsReShape = new BRepTools_ReShape;
@@ -3244,7 +3278,7 @@ void BRepBuilderAPI_Sewing::Merging(const Standard_Boolean /* firstTime */,
         if (myMergedEdges.Contains(section)) continue;
         // Merge cutting section
         TopTools_SequenceOfShape seqMergedWithSection;
-        TColStd_SequenceOfInteger seqMergedWithSectionOri;
+        TColStd_SequenceOfBoolean seqMergedWithSectionOri;
         if (MergedNearestEdges(section,seqMergedWithSection,seqMergedWithSectionOri)) {
           // Store section in the map
           MergedWithSections.Bind(section,section);
@@ -3330,7 +3364,7 @@ void BRepBuilderAPI_Sewing::Merging(const Standard_Boolean /* firstTime */,
         }
       }
     }
-    Standard_Boolean isMergedSplit = MergedWithSections.Extent();
+    const Standard_Boolean isMergedSplit = !MergedWithSections.IsEmpty();
 
     if (!isMerged && !isMergedSplit) {
       // Nothing was merged in this iteration
@@ -3431,7 +3465,7 @@ void BRepBuilderAPI_Sewing::Merging(const Standard_Boolean /* firstTime */,
 
 Standard_Boolean BRepBuilderAPI_Sewing::MergedNearestEdges(const TopoDS_Shape& edge,
                                                            TopTools_SequenceOfShape& SeqMergedEdge,
-                                                           TColStd_SequenceOfInteger& SeqMergedOri)
+                                                           TColStd_SequenceOfBoolean& SeqMergedOri)
 {
   // Retrieve edge nodes
   TopoDS_Vertex no1, no2;
@@ -3547,7 +3581,7 @@ Standard_Boolean BRepBuilderAPI_Sewing::MergedNearestEdges(const TopoDS_Shape& e
     }
 
     // Find merging candidates
-    TColStd_SequenceOfInteger seqForward;
+    TColStd_SequenceOfBoolean seqForward;
     TColStd_SequenceOfInteger seqCandidates;
     TColStd_IndexedMapOfInteger mapReference;
     mapReference.Add(indRef); // Add index of reference section
@@ -3557,12 +3591,12 @@ Standard_Boolean BRepBuilderAPI_Sewing::MergedNearestEdges(const TopoDS_Shape& e
       for (i = 1; i <= nbCandidates; i++) {
         // Retrieve merged edge
         TopoDS_Shape iedge = seqEdges(seqCandidates(i));
-        Standard_Integer ori = (seqForward(i))? 1 : 0;
+        Standard_Boolean ori = seqForward(i) != 0;
         SeqMergedEdge.Append(iedge);
         SeqMergedOri.Append(ori);
         if (!myNonmanifold) break;
       }
-      success = nbCandidates;
+      success = (nbCandidates != 0);
     }
   }
 
@@ -4090,7 +4124,6 @@ void BRepBuilderAPI_Sewing::CreateSewedShape()
           if (IndexMerged.Contains(i)) continue;
           TopoDS_Shell shell = TopoDS::Shell(OldShells.FindKey(i));
           if (NewShell.IsNull()) {
-            BRep_Builder aB;
             aB.MakeShell(NewShell);
             TopoDS_Iterator aItSS(shell) ;
             for( ; aItSS.More(); aItSS.Next())