0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / ChFi3d / ChFi3d_Builder_2.cxx
old mode 100755 (executable)
new mode 100644 (file)
index f516fa1..3fb0194
 // Created on: 1993-12-15
 // Created by: Isabelle GRIGNON
 // Copyright (c) 1993-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// 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.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 
-#include <ChFi3d_Builder.jxx>
-
-#include <Precision.hxx>
-
-#include <Standard_NotImplemented.hxx>
-#include <TColStd_Array1OfReal.hxx>
-#include <TColStd_Array1OfInteger.hxx>
-#include <TColStd_ListOfInteger.hxx>
-
-#include <math_Vector.hxx>
-#include <gp_Pnt.hxx>
-#include <gp_XYZ.hxx>
-#include <gp_Vec.hxx>
-#include <gp_Pnt2d.hxx>
-#include <gp_Pln.hxx>
-#include <TColgp_Array1OfPnt.hxx>
-#include <TColgp_Array1OfVec.hxx>
-#include <ElCLib.hxx>
-
-#include <Geom_BSplineCurve.hxx>
-#include <Geom_Line.hxx>
-#include <Geom_Plane.hxx>
-#include <Geom2d_Curve.hxx>
-#include <GeomAPI_ProjectPointOnCurve.hxx>
-
-#include <TopoDS.hxx>
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Wire.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Vertex.hxx>
-
-#include <GeomAdaptor_Surface.hxx>
-#include <GeomAdaptor_HSurface.hxx>
-#include <GeomAdaptor_HCurve.hxx>
-
+#include <Adaptor2d_HCurve2d.hxx>
+#include <Adaptor3d_HSurface.hxx>
+#include <Adaptor3d_TopolTool.hxx>
+#include <AppBlend_Approx.hxx>
+#include <Blend_CurvPointFuncInv.hxx>
+#include <Blend_FuncInv.hxx>
+#include <Blend_Function.hxx>
+#include <Blend_RstRstFunction.hxx>
+#include <Blend_SurfCurvFuncInv.hxx>
+#include <Blend_SurfPointFuncInv.hxx>
+#include <Blend_SurfRstFunction.hxx>
+#include <BRep_Tool.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_HCurve.hxx>
-#include <BRepAdaptor_Surface.hxx>
+#include <BRepAdaptor_HCurve2d.hxx>
 #include <BRepAdaptor_HSurface.hxx>
-#include <BRepTopAdaptor_TopolTool.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <BRepBlend_Line.hxx>
+#include <BRepLib_MakeFace.hxx>
 #include <BRepLProp_SLProps.hxx>
-#include <Adaptor3d_TopolTool.hxx>
-
-#include <TopAbs.hxx>
-#include <TopAbs_ShapeEnum.hxx>
-#include <TopAbs_Orientation.hxx>
-#include <BRep_Tool.hxx>
 #include <BRepTools.hxx>
 #include <BRepTools_WireExplorer.hxx>
-#include <BRepLib_MakeFace.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-
-#include <Extrema_ExtPC.hxx>
-#include <Extrema_LocateExtPC.hxx>
-#include <Extrema_POnCurv.hxx>
-
-#include <ChFiDS_ErrorStatus.hxx>
-#include <ChFiDS_State.hxx>
-#include <ChFiDS_SurfData.hxx>
+#include <BRepTopAdaptor_TopolTool.hxx>
+#include <ChFi3d.hxx>
+#include <ChFi3d_Builder.hxx>
+#include <ChFi3d_Builder_0.hxx>
+#include <ChFiDS_ChamfSpine.hxx>
 #include <ChFiDS_CommonPoint.hxx>
+#include <ChFiDS_ElSpine.hxx>
+#include <ChFiDS_ErrorStatus.hxx>
 #include <ChFiDS_FaceInterference.hxx>
-#include <ChFiDS_Spine.hxx>
 #include <ChFiDS_FilSpine.hxx>
-#include <ChFiDS_ChamfSpine.hxx>
-#include <ChFiDS_SequenceOfSurfData.hxx>
-#include <ChFiDS_Stripe.hxx>
 #include <ChFiDS_HData.hxx>
-#include <ChFiDS_ElSpine.hxx>
-#include <ChFiDS_ListOfHElSpine.hxx>
+#include <ChFiDS_HElSpine.hxx>
 #include <ChFiDS_ListIteratorOfListOfHElSpine.hxx>
-#include <Extrema_ExtPS.hxx>
+#include <ChFiDS_ListOfHElSpine.hxx>
+#include <ChFiDS_SequenceOfSurfData.hxx>
+#include <ChFiDS_Spine.hxx>
+#include <ChFiDS_State.hxx>
+#include <ChFiDS_Stripe.hxx>
+#include <ChFiDS_SurfData.hxx>
 #include <ChFiKPart_ComputeData.hxx>
-#include <ChFi3d.hxx>
-#include <ChFi3d_Builder_0.hxx>
+#include <ElCLib.hxx>
+#include <Extrema_ExtPC.hxx>
+#include <Extrema_ExtPS.hxx>
+#include <Extrema_LocateExtPC.hxx>
+#include <Extrema_POnCurv.hxx>
+#include <Geom2d_Curve.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_Surface.hxx>
+#include <GeomAdaptor_HCurve.hxx>
+#include <GeomAdaptor_HSurface.hxx>
+#include <GeomAdaptor_Surface.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <gp_Pln.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Pnt2d.hxx>
+#include <gp_Vec.hxx>
+#include <gp_XYZ.hxx>
+#include <math_Vector.hxx>
+#include <Precision.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <Standard_NotImplemented.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColgp_Array1OfVec.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TColStd_ListOfInteger.hxx>
+#include <TopAbs.hxx>
+#include <TopAbs_Orientation.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopOpeBRepBuild_HBuilder.hxx>
+#include <TopOpeBRepDS_HDataStructure.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
-#ifdef DEB
+#ifdef OCCT_DEBUG
 #ifdef DRAW
 #include <DrawTrSurf.hxx>
 #endif
 #include <OSD_Chronometer.hxx>
-//Standard_IMPORT extern Standard_Real  t_perfsetofkpart,t_perfsetofkgen,
-Standard_IMPORT Standard_Real  t_perfsetofkpart,t_perfsetofkgen,
-t_makextremities,t_performsurf,t_startsol;
-//Standard_IMPORT extern Standard_Boolean ChFi3d_GettraceCHRON();
-Standard_IMPORT Standard_Boolean ChFi3d_GettraceCHRON();
-//Standard_IMPORT extern void ChFi3d_InitChron(OSD_Chronometer& ch);
-Standard_IMPORT void ChFi3d_InitChron(OSD_Chronometer& ch);
-//Standard_IMPORT extern void ChFi3d_ResultChron(OSD_Chronometer & ch,
-Standard_IMPORT void ChFi3d_ResultChron(OSD_Chronometer & ch,
-                                              Standard_Real& time);
+extern Standard_Real  t_perfsetofkpart,t_perfsetofkgen,t_makextremities,t_performsurf,t_startsol;
+extern Standard_Boolean ChFi3d_GettraceCHRON();
+extern void ChFi3d_InitChron(OSD_Chronometer& ch);
+extern void ChFi3d_ResultChron(OSD_Chronometer & ch, Standard_Real& time);
 #endif
 
-//  Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 Begin
-Standard_Boolean isTangentFaces(const TopoDS_Edge &theEdge,
-                               const TopoDS_Face &theFace1,
-                               const TopoDS_Face &theFace2);
-//  Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 End
 
 //===================================================================
 //   Definition by a plane   
@@ -255,7 +250,7 @@ static Standard_Boolean BonVoisin(const gp_Pnt& Point,
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:12:48 2001 Begin
 //         Standard_Boolean istg = 
 //           BRep_Tool::Continuity(ecur,ff,F) != GeomAbs_C0;
-           Standard_Boolean istg = isTangentFaces(ecur,ff,F);
+           Standard_Boolean istg = ChFi3d_isTangentFaces(ecur,ff,F);
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:12:51 2001 End
            if((!issame || (issame && isreallyclosed)) && istg) {
              found = 1;
@@ -461,7 +456,7 @@ Standard_Boolean IsG1(const ChFiDS_Map&         TheMap,
       FVoi = TopoDS::Face(It.Value());
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:09:32 2001 Begin
 //    if (BRep_Tool::Continuity(E,FRef,FVoi) != GeomAbs_C0) {
-      if (isTangentFaces(E,FRef,FVoi)) {
+      if (ChFi3d_isTangentFaces(E,FRef,FVoi)) {
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:09:33 2001 End
        return Standard_True;
       }
@@ -471,11 +466,7 @@ Standard_Boolean IsG1(const ChFiDS_Map&         TheMap,
   // in which case FVoi = FRef is returned (less frequent case).
   TopExp_Explorer Ex;
   Standard_Boolean orset = Standard_False;
-#ifndef DEB
   TopAbs_Orientation orient = TopAbs_FORWARD ;
-#else
-  TopAbs_Orientation orient;
-#endif
   TopoDS_Edge ed;
   for(Ex.Init(FRef,TopAbs_EDGE); Ex.More(); Ex.Next()){
     ed = TopoDS::Edge(Ex.Current());
@@ -485,7 +476,7 @@ Standard_Boolean IsG1(const ChFiDS_Map&         TheMap,
        FVoi = FRef;
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:15:12 2001 Begin
 //     if (BRep_Tool::Continuity(E,FRef,FRef) >= GeomAbs_G1) {   
-       if (isTangentFaces(E,FRef,FRef)) {
+       if (ChFi3d_isTangentFaces(E,FRef,FRef)) {
 //  Modified by Sergey KHROMOV - Fri Dec 21 17:15:16 2001 End
          return Standard_True;
        }
@@ -601,12 +592,12 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
                const Handle(BRepAdaptor_HSurface)& HS3,
                const gp_Pnt2d&                     pp1,
                const gp_Pnt2d&                     pp3,
-               Handle(Adaptor3d_TopolTool)&          It1,
+               const Handle(Adaptor3d_TopolTool)&          It1,
                const Handle(BRepAdaptor_HSurface)& HS2,
                const Handle(BRepAdaptor_HSurface)& HS4,
                const gp_Pnt2d&                     pp2,
                const gp_Pnt2d&                     pp4,
-               Handle(Adaptor3d_TopolTool)&          It2,
+               const Handle(Adaptor3d_TopolTool)&          It2,
                const Standard_Real                 MaxStep,
                const Standard_Real                 Fleche,
                const Standard_Real                 /*TolGuide*/,
@@ -618,20 +609,20 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
                const Standard_Boolean              RecOnS1,
                const Standard_Boolean              RecOnS2,
                math_Vector&                        Soldep,
-               Standard_Boolean&                   intf,
-               Standard_Boolean&                   intl,
+               Standard_Integer&                   intf,
+               Standard_Integer&                   intl,
                 Handle(BRepAdaptor_HSurface)&       Surf1,
                Handle(BRepAdaptor_HSurface)&       Surf2) 
 {
-#ifdef DEB   
+#ifdef OCCT_DEBUG
   OSD_Chronometer ch1;
 #endif 
   Handle(BRepAdaptor_HSurface) HSon1, HSon2;
   HSon1 = HS1;
   HSon2 = HS2;
   // Definition of the domain of path It1, It2
-  It1->Initialize(HS1);
-  It2->Initialize(HS2);
+  It1->Initialize((const Handle(Adaptor3d_HSurface)&)HSon1);
+  It2->Initialize((const Handle(Adaptor3d_HSurface)&)HSon2);
 
 
   TopAbs_Orientation Or1 = HS1->ChangeSurface().Face().Orientation();
@@ -653,7 +644,7 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
   }
   else{
        
-#ifdef DEB  
+#ifdef OCCT_DEBUG
     ChFi3d_InitChron(ch1);//initial perform for PerformSurf
 #endif
        
@@ -661,7 +652,7 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
                          MaxStep,Fleche,tolesp,
                          First,Last,Inside,Inside,forward,
                          RecOnS1,RecOnS2,Soldep,intf,intl);
-#ifdef DEB   
+#ifdef OCCT_DEBUG
     ChFi3d_ResultChron(ch1,t_performsurf);// result perf for PerformSurf   
 #endif
   }
@@ -673,14 +664,14 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
    Standard_Boolean reprise = Standard_False;
    if (! HS3.IsNull()) {
      HSon1 = HS3;
-     It1->Initialize(HS3); 
+     It1->Initialize((const Handle(Adaptor3d_HSurface)&)HS3); 
      Or1 = HS3->ChangeSurface().Face().Orientation();
      Soldep(1) = pp3.X(); Soldep(2) = pp3.Y();
      reprise = Standard_True;
    }
    else if (! HS4.IsNull()) {
      HSon2 = HS4;
-     It2->Initialize(HS4); 
+     It2->Initialize((const Handle(Adaptor3d_HSurface)&)HS4); 
      Or2 = HS4->ChangeSurface().Face().Orientation();
      Soldep(3) = pp4.X(); Soldep(4) = pp4.Y();
      reprise = Standard_True;
@@ -699,7 +690,7 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
      }
      else{
        
-#ifdef DEB  
+#ifdef OCCT_DEBUG
        ChFi3d_InitChron(ch1);//init perf for PerformSurf
 #endif
        
@@ -707,7 +698,7 @@ CallPerformSurf(Handle(ChFiDS_Stripe)&              Stripe,
                             MaxStep,Fleche,tolesp,
                             First,Last,Inside,Inside,forward,
                             RecOnS1,RecOnS2,Soldep,intf,intl);
-#ifdef DEB   
+#ifdef OCCT_DEBUG
        ChFi3d_ResultChron(ch1,t_performsurf);// result perf for PerformSurf   
 #endif
      }
@@ -810,11 +801,7 @@ void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)&      Stripe,
   Standard_Real wl = 0.9973 * Spine->LastParameter(nbed) +
     0.0027 * Spine->FirstParameter(nbed);
 
-#ifndef DEB
   Standard_Real TolE = 1.0e-7;
-#else
-  Standard_Real TolE;
-#endif
   BRepAdaptor_Surface AS;  
 
   Standard_Integer nbessai;
@@ -825,11 +812,7 @@ void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)&      Stripe,
   TopoDS_Edge cured;
   TopoDS_Face f1,f2;
   TopAbs_Orientation Or1,Or2;
-#ifndef DEB
   Standard_Integer Choix = 0;
-#else
-  Standard_Integer Choix;
-#endif
   math_Vector SolDep(1,4);
   Handle(Geom2d_Curve) PC;
   Extrema_ExtPC PExt;
@@ -864,7 +847,7 @@ void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)&      Stripe,
     f1forward.Orientation(TopAbs_FORWARD);
     f2forward.Orientation(TopAbs_FORWARD);
     PC = BRep_Tool::CurveOnSurface(cured,f1forward,Uf,Ul);
-    I1->Initialize(HS1);
+    I1->Initialize((const Handle(Adaptor3d_HSurface)&)HS1);
     PC->D1(woned, P1, derive);
     // There are ponts on the border, and internal points are found
     if (derive.Magnitude() > Precision::PConfusion()) {
@@ -888,7 +871,8 @@ void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)&      Stripe,
     if(f1.IsSame(f2)) cured.Orientation(TopAbs_REVERSED);
     PC = BRep_Tool::CurveOnSurface(cured,f2forward,Uf,Ul);
     P2 = PC->Value(woned);
-    I2->Initialize(HS2);
+    const Handle(Adaptor3d_HSurface)& HSon2 = HS2; // to avoid ambiguity
+    I2->Initialize(HSon2);
 
     SolDep(1) = P1.X(); SolDep(2) = P1.Y();
     SolDep(3) = P2.X(); SolDep(4) = P2.Y();
@@ -930,8 +914,10 @@ void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)&      Stripe,
     P1 = PC->Value(woned);
     PC = BRep_Tool::CurveOnSurface(cured,f2forward,Uf,Ul);
     P2 = PC->Value(woned);
-    I1->Initialize(HS1);
-    I2->Initialize(HS2);
+    const Handle(Adaptor3d_HSurface)& HSon1 = HS1; // to avoid ambiguity
+    const Handle(Adaptor3d_HSurface)& HSon2 = HS2; // to avoid ambiguity
+    I1->Initialize(HSon1);
+    I2->Initialize(HSon2);
     SolDep(1) = P1.X(); SolDep(2) = P1.Y();
     SolDep(3) = P2.X(); SolDep(4) = P2.Y();
     const BRepAdaptor_Curve& Ced = Spine->CurrentElementarySpine(iedge);
@@ -969,8 +955,10 @@ void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)&      Stripe,
                                   Stripe->OrientationOnFace1(),
                                   Stripe->OrientationOnFace2(),
                                   RC);
-         I1->Initialize(HS1);
-         I2->Initialize(HS2);
+          const Handle(Adaptor3d_HSurface)& HSon1new = HS1; // to avoid ambiguity
+          const Handle(Adaptor3d_HSurface)& HSon2new = HS2; // to avoid ambiguity
+         I1->Initialize(HSon1new);
+         I2->Initialize(HSon2new);
          if(PerformFirstSection(Spine,HGuide,Choix,HS1,HS2,
                                 I1,I2,w,SolDep,Pos1,Pos2)){
            P1.SetCoord(SolDep(1),SolDep(2));
@@ -1350,7 +1338,7 @@ Standard_Boolean  ChFi3d_Builder::SearchFace
   TopoDS_Edge E;
   if (Pc.IsVertex()){
     // attention it is necessary to analyze all faces that turn around of the vertex
-#if DEB
+#ifdef OCCT_DEBUG
     cout<<"Commonpoint on vertex, the process hangs up"<<endl;
 #endif
     if (Pc.HasVector()) { //General processing
@@ -1395,7 +1383,7 @@ Standard_Boolean  ChFi3d_Builder::SearchFace
          FindFace = Standard_False;
          if (Spine.IsNull()) {
            //La Spine peut etre nulle (ThreeCorner)
-#if DEB
+#ifdef OCCT_DEBUG
            cout << "FindFace sur vertex avec spine nulle! QUEZAKO ?" << endl;
 #endif
            return Standard_False;
@@ -1615,7 +1603,7 @@ static void ChFi3d_MakeExtremities(Handle(ChFiDS_Stripe)&      Stripe,
       if (CV1.IsVertex()) { 
        ChFi3d_SingularExtremity(Stripe, DStr, CV1.Vertex(), tol3d, tol2d);
       }
-# if DEB
+# if CHFI3D_DEB
       else { cout << "MakeExtremities : Singularity out of Vertex !!" << endl; }
 # endif
     }
@@ -1680,7 +1668,7 @@ static void ChFi3d_MakeExtremities(Handle(ChFiDS_Stripe)&      Stripe,
       if (cpdeb1.IsVertex()) { 
        ChFi3d_SingularExtremity(Stripe, DStr, cpdeb1.Vertex(), tol3d, tol2d);
       }
-# if DEB
+# if CHFI3D_DEB
       else { cout << "MakeExtremities : Singularity out of Vertex !!" << endl; }
 # endif
     }
@@ -1742,7 +1730,7 @@ static void ChFi3d_MakeExtremities(Handle(ChFiDS_Stripe)&      Stripe,
       if (cpfin1.IsVertex()) { 
        ChFi3d_SingularExtremity(Stripe, DStr, cpfin1.Vertex(), tol3d, tol2d);
       }
-# if DEB
+# if CHFI3D_DEB
       else { cout << "MakeExtremities : Singularity out of Vertex !!" << endl; }
 # endif
     }
@@ -1759,14 +1747,14 @@ static void ChFi3d_Purge (Handle(ChFiDS_Stripe)&    Stripe,
                          const ChFiDS_CommonPoint& VRef,
                          const Standard_Boolean    isfirst,
                          const Standard_Integer    ons,
-                         Standard_Boolean&         intf,
-                         Standard_Boolean&         intl)
+                         Standard_Integer&         intf,
+                         Standard_Integer&         intl)
 {
   if (isfirst) intf = 1; else intl = 1; // End.
   Standard_Integer opp = 3-ons;
   if (!SD->Vertex(isfirst,opp).IsOnArc() || 
       SD->TwistOnS1() || SD->TwistOnS2() ) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout<<"ChFi3d_Purge : No output on extension."<<endl;
 #endif
     ChFiDS_SequenceOfSurfData& Seq = 
@@ -1876,7 +1864,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
  Handle(BRepTopAdaptor_TopolTool)& It2,
  const Standard_Boolean            Simul)
 { 
-#ifdef DEB   
+#ifdef OCCT_DEBUG
   OSD_Chronometer ch1;
 #endif 
   
@@ -1885,10 +1873,13 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
   Standard_Real wl = Guide.LastParameter();
   Standard_Real locfleche = (wl - wf) * fleche;
   Standard_Real wfsav = wf, wlsav = wl;
-  //Now the ElSpine is artificially extended to help rsnld.
-  Standard_Real prab = 0.01;
-  Guide.FirstParameter(wf-prab*(wl-wf));
-  Guide.LastParameter (wl+prab*(wl-wf));
+  if (!Guide.IsPeriodic())
+  {
+    //Now the ElSpine is artificially extended to help rsnld.
+    Standard_Real prab = 0.01;
+    Guide.FirstParameter(wf-prab*(wl-wf));
+    Guide.LastParameter (wl+prab*(wl-wf));
+  }
   Handle(ChFiDS_Spine)&  Spine = Stripe->ChangeSpine();
   Standard_Integer ii, nbed = Spine->NbEdges();
   Standard_Real lastedlastp = Spine->LastParameter(nbed);
@@ -1908,11 +1899,11 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
   Handle(BRepAdaptor_HCurve2d) HC1,HC2;
   Handle(BRepAdaptor_HCurve2d) HCref1 = new BRepAdaptor_HCurve2d();
   Handle(BRepAdaptor_HCurve2d) HCref2 = new BRepAdaptor_HCurve2d();
-  Standard_Boolean decroch1 = 0, decroch2 = 0;
-  Standard_Boolean RecP1 = 0, RecS1 = 0, RecRst1 = 0, obstacleon1 = 0;
-  Standard_Boolean RecP2 = 0, RecS2 = 0, RecRst2 = 0, obstacleon2 = 0;
+  Standard_Boolean decroch1 = Standard_False, decroch2 = Standard_False;
+  Standard_Boolean RecP1 = Standard_False, RecS1 = Standard_False, RecRst1 = Standard_False, obstacleon1 = Standard_False;
+  Standard_Boolean RecP2 = Standard_False, RecS2 = Standard_False, RecRst2 = Standard_False, obstacleon2 = Standard_False;
   gp_Pnt2d pp1,pp2,pp3,pp4;
-  Standard_Real w1,w2;
+  Standard_Real w1 = 0.,w2 = 0.;
   math_Vector Soldep(1,4);
   math_Vector SoldepCS(1,3);
   math_Vector SoldepCC(1,2);
@@ -1930,20 +1921,22 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
     //sinon solution approchee.
     Inside = Standard_True;
     
-#ifdef DEB  
+#ifdef OCCT_DEBUG
     ChFi3d_InitChron(ch1);// init perf for StartSol 
 #endif
     
     StartSol(Stripe,HGuide,HS1,HS2,It1,It2,pp1,pp2,First);
     
-#ifdef DEB 
+#ifdef OCCT_DEBUG
     ChFi3d_ResultChron(ch1,t_startsol); // result perf for StartSol  
 #endif 
     
     Last = wf;
     if(Guide.IsPeriodic()) {
       Last = First - Guide.Period();
+      Guide.SaveFirstParameter();
       Guide.FirstParameter(Last);
+      Guide.SaveLastParameter();
       Guide.LastParameter (First * 1.1);//Extension to help rsnld.
     }
   }
@@ -1960,7 +1953,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
       First = wl; Last = Guide.FirstParameter();
     }
     
-#ifdef DEB  
+#ifdef OCCT_DEBUG
     ChFi3d_InitChron(ch1);// init perf for startsol 
 #endif
     
@@ -1974,7 +1967,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
     HC1.Nullify(); 
     HC2.Nullify();
     
-#ifdef DEB   
+#ifdef OCCT_DEBUG
     ChFi3d_ResultChron(ch1,t_startsol); // result perf for startsol  
 #endif
     
@@ -2006,12 +1999,8 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
     }   
   }
   Standard_Real         MaxStep  = (bidl-bidf)*0.05/nbed;
-#ifndef DEB
   Standard_Real         Firstsov = 0.;
-#else
-  Standard_Real         Firstsov;
-#endif
-  Standard_Boolean      intf = 0, intl = 0;
+  Standard_Integer      intf = 0, intl = 0;
   while(!fini){
     // are these the ends (no extension on periodic).
     Ok1 = 1,Ok2 = 1;
@@ -2037,7 +2026,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
     if(intl && forward) Vref = Spine->LastVertex();
     if(!ref.IsNull()){
       
-#ifdef DEB  
+#ifdef OCCT_DEBUG
       ChFi3d_InitChron(ch1);// init perf for StartSol 
 #endif
       
@@ -2048,7 +2037,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
                     HSref2,HCref2, RecP2,RecS2,RecRst2,obstacleon2,
                     HS4,pp4,decroch2,Vref);
       
-#ifdef DEB   
+#ifdef OCCT_DEBUG
       ChFi3d_ResultChron(ch1,t_startsol); // result perf for StartSol  
 #endif 
       
@@ -2068,9 +2057,11 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
       else Standard_Failure::Raise("PerformSetOfSurfOnElSpine : Chaining is impossible.");
     }
     
-    // Definition of the domain of path It1, It2
-    It1->Initialize(HS1);
-    It2->Initialize(HS2);
+    // Definition of the domain of patch It1, It2
+    const Handle(Adaptor3d_HSurface)& HSon1 = HS1; // to avoid ambiguity
+    const Handle(Adaptor3d_HSurface)& HSon2 = HS2; // to avoid ambiguity
+    It1->Initialize(HSon1);
+    It2->Initialize(HSon2);
     
     // Calculate one (several if singularity) SurfaData
     SD = new ChFiDS_SurfData();
@@ -2099,7 +2090,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
                  RecP1,RecRst1,RecP2,RecRst2,SoldepCC);
       }
       else{
-#ifdef DEB   
+#ifdef OCCT_DEBUG
        ChFi3d_InitChron(ch1); // init perf for PerformSurf 
 #endif
        PerformSurf(SeqSD,HGuide,Spine,Choix,
@@ -2107,7 +2098,7 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
                    HS2,It2,HC2,HSref2,HCref2,decroch2,Or2,
                    MaxStep,locfleche,tolesp,First,Last,Inside,Inside,forward,
                    RecP1,RecRst1,RecP2,RecRst2,SoldepCC);
-#ifdef DEB  
+#ifdef OCCT_DEBUG
        ChFi3d_ResultChron(ch1,t_performsurf); //result  perf for PerformSurf 
 #endif 
       }
@@ -2130,13 +2121,13 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
                  Inside,Inside,forward,RecP1,RecS2,RecRst1,SoldepCS);
       }
       else{
-#ifdef DEB  
+#ifdef OCCT_DEBUG
        ChFi3d_InitChron(ch1); // init perf for PerformSurf
 #endif
        PerformSurf(SeqSD,HGuide,Spine,Choix,HS1,It1,HC1,HSref1,HCref1,decroch1,
                    HS2,It2,Or2,MaxStep,locfleche,tolesp,First,Last,
                    Inside,Inside,forward,RecP1,RecS2,RecRst1,SoldepCS);
-#ifdef DEB  
+#ifdef OCCT_DEBUG
        ChFi3d_ResultChron(ch1,t_performsurf);//result  perf for PerformSurf  
 #endif 
       }
@@ -2158,13 +2149,13 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
                  First,Last,Inside,Inside,forward,RecP2,RecS1,RecRst2,SoldepCS);
       }
       else{
-#ifdef DEB   
+#ifdef OCCT_DEBUG
        ChFi3d_InitChron(ch1); // init perf for PerformSurf 
 #endif
        PerformSurf(SeqSD,HGuide,Spine,Choix,HS1,It1,Or1,
                    HS2,It2,HC2,HSref2,HCref2,decroch2,MaxStep,locfleche,tolesp,
                    First,Last,Inside,Inside,forward,RecP2,RecS1,RecRst2,SoldepCS);
-#ifdef DEB  
+#ifdef OCCT_DEBUG
        ChFi3d_ResultChron(ch1,t_performsurf); //result  perf for PerformSurf 
 #endif 
       }
@@ -2172,11 +2163,13 @@ void ChFi3d_Builder::PerformSetOfSurfOnElSpine
       SD->ChangeIndexOfS2(DStr.AddShape(HS2->ChangeSurface().Face()));
       decroch1 = 0;
     }
-    else{            
+    else{ 
+      const Handle(Adaptor3d_TopolTool)& aTT1 = It1; // to avoid ambiguity
+      const Handle(Adaptor3d_TopolTool)& aTT2 = It2; // to avoid ambiguity
       CallPerformSurf(Stripe, Simul, SeqSD, SD,
                      HGuide,Spine,
-                     HS1, HS3, pp1, pp3, It1,
-                     HS2, HS4, pp2, pp4, It2, 
+                     HS1, HS3, pp1, pp3, aTT1,
+                     HS2, HS4, pp2, pp4, aTT2, 
                      MaxStep,locfleche,tolesp,
                      First,Last,Inside,Inside,forward,
                      RecS1,RecS2,Soldep,intf,intl, 
@@ -2310,7 +2303,7 @@ void ChFi3d_Builder::PerformSetOfKPart(Handle(ChFiDS_Stripe)& Stripe,
   Handle(ChFiDS_Spine)&        Spine = Stripe->ChangeSpine();
   Handle(BRepAdaptor_HSurface) HS1,HS2;
   TopAbs_Orientation           Or1,Or2,RefOr1,RefOr2;
-  Standard_Integer             Choix,RefChoix;
+  Standard_Integer             RefChoix;
   
   // initialization of the stripe.
   Stripe->Reset();
@@ -2329,7 +2322,7 @@ void ChFi3d_Builder::PerformSetOfKPart(Handle(ChFiDS_Stripe)& Stripe,
   Standard_Real WFirst,WLast = 0.;
   gp_Vec TFirst,TLast,TEndPeriodic;
   gp_Pnt PFirst,PLast,PEndPeriodic;
-  Standard_Boolean intf = 0, intl = 0;
+  Standard_Boolean intf = Standard_False, intl = Standard_False;
   
   Handle(ChFiDS_HElSpine) CurrentHE = new ChFiDS_HElSpine();
   Spine->D1(Spine->FirstParameter(),PFirst,TFirst);
@@ -2354,20 +2347,22 @@ void ChFi3d_Builder::PerformSetOfKPart(Handle(ChFiDS_Stripe)& Stripe,
       intl = ((iedge == Spine->NbEdges()) && !Spine->IsPeriodic());
       Or1   = HS1->ChangeSurface().Face().Orientation();
       Or2   = HS2->ChangeSurface().Face().Orientation();
-      Choix = ChFi3d::NextSide(Or1,Or2,RefOr1,RefOr2,RefChoix);      
-      It1->Initialize(HS1);
-      It2->Initialize(HS2);
+      ChFi3d::NextSide(Or1,Or2,RefOr1,RefOr2,RefChoix);      
+      const Handle(Adaptor3d_HSurface)& HSon1 = HS1; // to avoid ambiguity
+      const Handle(Adaptor3d_HSurface)& HSon2 = HS2; // to avoid ambiguity
+      It1->Initialize(HSon1);
+      It2->Initialize(HSon2);
       
       Handle(ChFiDS_SurfData)   SD = new ChFiDS_SurfData();
       ChFiDS_SequenceOfSurfData LSD;
       
       if(!ChFiKPart_ComputeData::Compute(DStr,SD,HS1,HS2,Or1,Or2,Spine,iedge)){
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout<<"failed calculation KPart"<<endl;
 #endif
       }
       else if(!SplitKPart(SD,LSD,Spine,iedge,HS1,It1,HS2,It2,intf,intl)){
-#ifdef DEB
+#ifdef OCCT_DEBUG
        cout<<"failed calculation KPart"<<endl;
 #endif
        LSD.Clear();
@@ -2493,11 +2488,11 @@ void ChFi3d_Builder::PerformSetOfKPart(Handle(ChFiDS_Stripe)& Stripe,
   ChFiDS_ListOfHElSpine& ll = Spine->ChangeElSpines();
   ChFiDS_ListIteratorOfListOfHElSpine ILES(ll);
   for ( ; ILES.More(); ILES.Next()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     if(ChFi3d_GettraceCHRON()) elspine.Start();
 #endif
     ChFi3d_PerformElSpine(ILES.Value(),Spine,myConti,tolesp);
-#ifdef DEB
+#ifdef OCCT_DEBUG
     if(ChFi3d_GettraceCHRON()) { elspine.Stop(); }
 #endif
   }
@@ -2528,11 +2523,11 @@ void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
   ChFiDS_ListOfHElSpine& ll = Spine->ChangeElSpines();
   ChFiDS_ListIteratorOfListOfHElSpine ILES(ll);
   for ( ; ILES.More(); ILES.Next()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG
     if(ChFi3d_GettraceCHRON()) { chemine.Start(); }
 #endif
     PerformSetOfSurfOnElSpine(ILES.Value(),Stripe,It1,It2,Simul);
-#ifdef DEB
+#ifdef OCCT_DEBUG
     if(ChFi3d_GettraceCHRON()) chemine.Stop();
 #endif
   }
@@ -2770,7 +2765,7 @@ void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
       ChFi3d_ReparamPcurv(0.,1.,PC1);
       ChFi3d_ReparamPcurv(0.,1.,PC2);
       Handle(Geom_Surface) newsurf = fil.Surface();
-#ifdef DEB
+#ifdef OCCT_DEBUG
 #ifdef DRAW
       //POP for NT
       char* pops = "newsurf";
@@ -2901,7 +2896,7 @@ void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
       }
       else if(IF < IL){
        TColStd_Array1OfReal wv(IF,IL - 1);
-#ifdef  DEB
+#ifdef OCCT_DEBUG
        cout<<"length of the trajectory : "<<(WL-WF)<<endl;
 #endif
        for(i = IF; i < IL; i++){
@@ -2910,7 +2905,7 @@ void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
          Standard_Real wi = Spine->LastParameter(iloc);
          if(periodic) wi = ElCLib::InPeriod(wi,WF,WF+period);
          gp_Pnt pv = Spine->Value(wi);
-#ifdef DEB
+#ifdef OCCT_DEBUG
          gp_Pnt pelsapp = curels.Value(wi);
          Standard_Real distinit = pv.Distance(pelsapp);
          cout<<"distance psp/papp : "<<distinit<<endl;
@@ -2921,7 +2916,7 @@ void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
            wv(i) = ext.Point().Parameter(); 
          }
          else {
-#ifdef DEB
+#ifdef OCCT_DEBUG
            cout<<"fail of projection vertex ElSpine!!!"<<endl;
 #endif
          }
@@ -2931,11 +2926,7 @@ void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
          Standard_Real fp = cursd->FirstSpineParam();
          Standard_Real lp = cursd->LastSpineParam();
          Standard_Integer j;
-#ifndef DEB
          Standard_Integer jf = 0, jl = 0;
-#else
-         Standard_Integer jf,jl;
-#endif
          if(lp < WF+tolesp || fp > WL-tolesp) continue;
          for(j = IF; j < IL; j++){
            jf = j;
@@ -2971,7 +2962,7 @@ void ChFi3d_Builder::PerformSetOfSurf(Handle(ChFiDS_Stripe)& Stripe,
 {
   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
   
-#ifdef DEB   
+#ifdef OCCT_DEBUG
   OSD_Chronometer ch;
   ChFi3d_InitChron(ch);// init perf for PerformSetOfKPart
 #endif
@@ -2981,21 +2972,21 @@ void ChFi3d_Builder::PerformSetOfSurf(Handle(ChFiDS_Stripe)& Stripe,
   Stripe->SetSolidIndex(SI);
   if(!sp->SplitDone()) PerformSetOfKPart(Stripe,Simul);
   
-#ifdef DEB   
+#ifdef OCCT_DEBUG
   ChFi3d_ResultChron(ch ,t_perfsetofkpart); // result perf PerformSetOfKPart(
   ChFi3d_InitChron(ch); // init perf for  PerformSetOfKGen
 #endif
   
   PerformSetOfKGen(Stripe,Simul);
   
-#ifdef DEB   
+#ifdef OCCT_DEBUG
   ChFi3d_ResultChron(ch, t_perfsetofkgen);//result perf PerformSetOfKGen 
   ChFi3d_InitChron(ch); // init perf for ChFi3d_MakeExtremities
 #endif
   
   if(!Simul) ChFi3d_MakeExtremities(Stripe,DStr,myEFMap,tolesp,tol2d);
   
-#ifdef DEB   
+#ifdef OCCT_DEBUG
   ChFi3d_ResultChron(ch, t_makextremities); // result perf t_makextremities
 #endif
 }