0026621: Boolean Cut does not work on two solids
[occt.git] / src / IntPatch / IntPatch_WLine.cxx
index 6faaf18..0a8094d 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 <IntPatch_WLine.ixx>
+
+#include <Adaptor2d_HCurve2d.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Pnt2d.hxx>
+#include <IntPatch_Point.hxx>
+#include <IntPatch_WLine.hxx>
+#include <IntSurf_LineOn2S.hxx>
+#include <IntSurf_PntOn2S.hxx>
+#include <Standard_DomainError.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <Standard_Type.hxx>
 
 #define DEBUG 0
 #define DEBUGV 0
@@ -28,7 +38,7 @@ IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
                                 const Standard_Boolean Tang,
                                 const IntSurf_TypeTrans Trans1,
                                 const IntSurf_TypeTrans Trans2) :
-  IntPatch_Line(Tang,Trans1,Trans2),fipt(Standard_False),lapt(Standard_False),
+  IntPatch_PointLine(Tang,Trans1,Trans2),fipt(Standard_False),lapt(Standard_False),
   hasArcOnS1(Standard_False),hasArcOnS2(Standard_False)
 {
   typ = IntPatch_Walking;
@@ -44,7 +54,7 @@ IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
                                 const Standard_Boolean Tang,
                                 const IntSurf_Situation Situ1,
                                 const IntSurf_Situation Situ2) :
-  IntPatch_Line(Tang,Situ1,Situ2),fipt(Standard_False),lapt(Standard_False),
+  IntPatch_PointLine(Tang,Situ1,Situ2),fipt(Standard_False),lapt(Standard_False),
   hasArcOnS1(Standard_False),hasArcOnS2(Standard_False)
 {
   typ = IntPatch_Walking;
@@ -58,7 +68,7 @@ IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
 
 IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
                                 const Standard_Boolean Tang) :
-  IntPatch_Line(Tang),fipt(Standard_False),lapt(Standard_False),
+  IntPatch_PointLine(Tang),fipt(Standard_False),lapt(Standard_False),
   hasArcOnS1(Standard_False),hasArcOnS2(Standard_False)
 {
   typ = IntPatch_Walking;
@@ -119,8 +129,10 @@ static void RecadreMemePeriode(IntSurf_PntOn2S& POn2S,const IntSurf_PntOn2S& Ref
   POn2S.SetValue(u1,v1,u2,v2);
 }
 
-static Standard_Boolean CompareVertexAndPoint(const gp_Pnt& V,const gp_Pnt& P,const Standard_Real& Tol) { 
-  return(V.Distance(P)<=Tol);
+static Standard_Boolean CompareVertexAndPoint(const gp_Pnt& V, const gp_Pnt& P, const Standard_Real& Tol) { 
+  const Standard_Real aSQDist = V.SquareDistance(P);
+  const Standard_Real aSQTol = Tol*Tol;
+  return (aSQDist <= aSQTol);
 }
 
 void IntPatch_WLine::SetPeriod(const Standard_Real pu1,
@@ -238,8 +250,9 @@ inline Standard_Boolean CompareVerticesOnS2(const IntPatch_Point& vtx1, const In
 {return CompareVerticesOnSurf (vtx1, vtx2, Standard_False);}
 
 
-void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) { 
-
+void IntPatch_WLine::ComputeVertexParameters( const Standard_Real RTol,
+                                              const Standard_Boolean hasBeenAdded)
+{
   // MSV Oct 15, 2001: use tolerance of vertex instead of RTol where 
   //                   it is possible
 
@@ -247,9 +260,6 @@ void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
   Standard_Integer indicevertexonline;
   Standard_Real    indicevertex;
 
-  Standard_Real ParamMinOnLine,ParamMaxOnLine;
-  if(fipt) { ParamMinOnLine = Vertex(indf).ParameterOnLine(); } else { ParamMinOnLine = -100000.0; } 
-  if(lapt) { ParamMaxOnLine = Vertex(indl).ParameterOnLine(); } else { ParamMaxOnLine =  100000.0; } 
   Standard_Boolean APointDeleted = Standard_False;
   //----------------------------------------------------------
   //--     F i l t r e   s u r   r e s t r i c t i o n s   --
@@ -466,9 +476,9 @@ void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
   Standard_Real dmini = Precision::Confusion();
   dmini*=dmini;
   for(i=2; i<=nbponline; i++) { 
-    //const IntSurf_PntOn2S& aPntOn2S1=curv->Value(i-1);
-    //const IntSurf_PntOn2S& aPntOn2S2=curv->Value(i);
-    Standard_Real d = (curv->Value(i-1).Value()).SquareDistance((curv->Value(i).Value()));
+    const IntSurf_PntOn2S& aPnt1=curv->Value(i-1);
+    const IntSurf_PntOn2S& aPnt2=curv->Value(i);
+    Standard_Real d = (aPnt1.Value()).SquareDistance((aPnt2.Value()));
     if(d < dmini) { 
       curv->RemovePoint(i);
       nbponline--;
@@ -476,10 +486,10 @@ void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
       //-- On recadre les Vertex si besoin 
       //-- 
       for(j=1; j<=nbvtx; j++) { 
-       indicevertex = svtx.Value(j).ParameterOnLine();
-       if(indicevertex >= i) {
-         svtx.ChangeValue(j).SetParameter(indicevertex-1.0);
-       }
+        indicevertex = svtx.Value(j).ParameterOnLine();
+        if(indicevertex >= i) {
+          svtx.ChangeValue(j).SetParameter(indicevertex-1.0);
+        }
       }
       //modified by NIZNHY-PKV Mon Feb 11 09:28:02 2002 f
       i--;
@@ -490,7 +500,30 @@ void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
   for(i=1; i<=nbvtx; i++) {
     const gp_Pnt& P    = svtx.Value(i).Value();
     Standard_Real vTol = svtx.Value(i).Tolerance();
-    indicevertex = svtx.Value(i).ParameterOnLine();
+    
+    if(hasBeenAdded)
+    {
+      if(nbvtx == 2)
+      {
+        if(i == nbvtx)
+        {
+          indicevertex = curv->NbPoints();
+        }
+        else
+        {
+          indicevertex = svtx.Value(i).ParameterOnLine();
+        }
+      }
+      else
+      {
+        indicevertex = svtx.Value(i).ParameterOnLine();
+      }
+    }
+    else
+    {
+      indicevertex = svtx.Value(i).ParameterOnLine();
+    }
+    
     indicevertexonline = (Standard_Integer)indicevertex;
     //--------------------------------------------------
     //-- On Compare le vertex avec les points de la ligne
@@ -749,8 +782,9 @@ void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
     for(i=1;
        (vtxfound==Standard_False) && (i<=nbvtx);i++) { 
       const IntPatch_Point&  V = svtx.Value(i);
-      Standard_Real vTol = V.Tolerance();
-      if(CompareVertexAndPoint(V.Value(),curv->Value(1).Value(),vTol)) { 
+      //jgv: to avoid loops
+      //Standard_Real vTol = V.Tolerance();
+      if(CompareVertexAndPoint(V.Value(), curv->Value(1).Value(), Precision::Confusion()/*vTol*/)) { 
        vtx = V;
        vtx.SetParameters(pu1,pv1,pu2,pv2);
        vtxfound = Standard_True;
@@ -773,8 +807,9 @@ void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
     for(i=1;
        (vtxfound==Standard_False) && (i<=nbvtx);i++) { 
       const IntPatch_Point&  V = svtx.Value(i);
-      Standard_Real vTol = V.Tolerance();
-      if(CompareVertexAndPoint(V.Value(),curv->Value(nbponline).Value(),vTol)) { 
+      //jgv: to avoid loops
+      //Standard_Real vTol = V.Tolerance();
+      if(CompareVertexAndPoint(V.Value(), curv->Value(nbponline).Value(), Precision::Confusion()/*vTol*/)) { 
        vtx = V;
        vtx.SetParameters(pu1,pv1,pu2,pv2);
        vtxfound = Standard_True;
@@ -1038,40 +1073,70 @@ const Handle(Adaptor2d_HCurve2d)& IntPatch_WLine::GetArcOnS2() const  {
 }
 
 
-void IntPatch_WLine::Dump() const { 
-  
-  cout<<" ----------- D u m p    I n t P a t c h  _  W L i n e  --------------"<<endl;
-  Standard_Integer i;
-  Standard_Integer nbp = NbPnts();
-  printf("Num    [X  Y  Z]     [U1  V1]   [U2  V2]\n");
-//  for(Standard_Integer i=1;i<=nbp;i++) { 
-  for(i=1;i<=nbp;i++) {
-    Standard_Real u1,v1,u2,v2;
-    Point(i).Parameters(u1,v1,u2,v2);
-    printf("%4d  [%+5.8e %+5.8e %+5.8e]  [%+5.8e %+5.8e]  [%+5.8e %+5.8e]\n",
-          i,
-          Point(i).Value().X(),
-          Point(i).Value().Y(),
-          Point(i).Value().Z(),
-          u1,v1,u2,v2);
-    
+void IntPatch_WLine::Dump(const Standard_Integer theMode) const
+{ 
+  cout<<" ----------- D u m p    I n t P a t c h  _  W L i n e  -(begin)------"<<endl;
+  const Standard_Integer aNbPoints = NbPnts();
+  const Standard_Integer aNbVertex = NbVertex();
+
+  switch(theMode)
+  {
+  case 0:
+    printf("Num    [X  Y  Z]     [U1  V1]   [U2  V2]\n");
+    for(Standard_Integer i=1; i<=aNbPoints; i++)
+    {
+      Standard_Real u1,v1,u2,v2;
+      Point(i).Parameters(u1,v1,u2,v2);
+      printf("%4d  [%+10.20f %+10.20f %+10.20f]  [%+10.20f %+10.20f]  [%+10.20f %+10.20f]\n",
+              i,Point(i).Value().X(),Point(i).Value().Y(),Point(i).Value().Z(),
+              u1,v1,u2,v2);
+    }
     
-    //cout<<"IntSurf_PntOn2S : "<<i<<"  Pnt ("<<curv->Value(i).Value().X()
-    //  <<","<<curv->Value(i).Value().Y()
-    //  <<","<<curv->Value(i).Value().Z()<<")"<<endl;
-    //cout<<"                :   u1("<<u1<<")   v1("<<v1<<")   u2("<<u2<<")   v2("<<v2<<")"<<endl; 
-  }
-  nbp = NbVertex();
-  for(i=1;i<=nbp;i++) { 
-    Vertex(i).Dump();
-    Standard_Real  polr = Vertex(i).ParameterOnLine();
-    Standard_Integer pol = (Standard_Integer)polr;
-    if(pol>=1 && pol<=nbp) { 
-      cout<<"----> IntSurf_PntOn2S : "<<polr<<"  Pnt ("<<Vertex(pol).Value().X()
-       <<","<<Vertex(pol).Value().Y()
-         <<","<<Vertex(pol).Value().Z()<<")"<<endl;
+    for(Standard_Integer i=1;i<=aNbVertex;i++)
+    {
+      Vertex(i).Dump();
+      Standard_Real  polr = Vertex(i).ParameterOnLine();
+      Standard_Integer pol = static_cast<Standard_Integer>(polr);
+
+      if(pol>=1 && pol<=aNbVertex)
+      {
+        cout<<"----> IntSurf_PntOn2S : "<<
+                      polr <<", Pnt (" << Vertex(pol).Value().X() << "," <<
+                                          Vertex(pol).Value().Y() << "," <<
+                                          Vertex(pol).Value().Z() <<")" <<endl;
+      }
     }
+
+    break;
+  case 1:
+    for(Standard_Integer i = 1; i <= aNbPoints; i++)
+    {
+      Standard_Real u1,v1,u2,v2;
+      Point(i).Parameters(u1,v1,u2,v2);
+      printf("point p%d %+10.20f %+10.20f %+10.20f\n",
+              i,Point(i).Value().X(),Point(i).Value().Y(),Point(i).Value().Z());
+    }
+
+    break;
+  case 2:
+    for(Standard_Integer i = 1; i <= aNbPoints; i++)
+    {
+      Standard_Real u1,v1,u2,v2;
+      Point(i).Parameters(u1,v1,u2,v2);
+      printf("point p%d %+10.20f %+10.20f\n", i, u1, v1);
+    }
+
+    break;
+  default:
+    for(Standard_Integer i = 1; i <= aNbPoints; i++)
+    {
+      Standard_Real u1,v1,u2,v2;
+      Point(i).Parameters(u1,v1,u2,v2);
+      printf("point p%d %+10.20f %+10.20f\n", i, u2, v2);
+    }
+
+    break;
   }
-  cout<<"\n----------------------------------------------------------"<<endl;  
+  cout<<"\n--------------------------------------------------- (end) -------"<<endl;  
 }