0026855: Draw commands to debug Boolean Operations Algorithm
[occt.git] / src / BOPTest / BOPTest_BOPCommands.cxx
index 1724253..068c2cb 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BOPTest.ixx>
 
-#include <stdio.h>
-
-#include <TCollection_AsciiString.hxx>
-
-#include <DBRep.hxx>
-#include <DrawTrSurf.hxx>
-#include <Draw_Color.hxx>
-#include <Draw.hxx>
-
-#include <NCollection_BaseAllocator.hxx>
-#include <NCollection_IncAllocator.hxx>
-
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Compound.hxx>
-#include <TopoDS_Iterator.hxx>
-//
-#include <BRep_Builder.hxx>
-
-#include <IntTools_FaceFace.hxx>
-#include <IntTools_Curve.hxx>
-
-#include <BOPCol_ListOfShape.hxx>
-
-#include <BOPDS_DS.hxx>
-
-#include <BOPAlgo_PaveFiller.hxx>
-#include <BOPAlgo_Operation.hxx>
 #include <BOPAlgo_BOP.hxx>
 #include <BOPAlgo_MakerVolume.hxx>
+#include <BOPAlgo_Operation.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
 #include <BOPAlgo_Section.hxx>
-
+#include <BOPCol_ListOfShape.hxx>
+#include <BOPDS_DS.hxx>
+#include <BOPTest.hxx>
+#include <BOPTest_Objects.hxx>
+#include <BRep_Builder.hxx>
 #include <BRepAlgoAPI_BooleanOperation.hxx>
 #include <BRepAlgoAPI_Common.hxx>
-#include <BRepAlgoAPI_Fuse.hxx>
 #include <BRepAlgoAPI_Cut.hxx>
+#include <BRepAlgoAPI_Fuse.hxx>
 #include <BRepAlgoAPI_Section.hxx>
+#include <DBRep.hxx>
+#include <Draw.hxx>
+#include <DrawTrSurf.hxx>
+#include <Geom2d_Curve.hxx>
+#include <Geom_Curve.hxx>
+#include <IntTools_Curve.hxx>
+#include <IntTools_FaceFace.hxx>
+#include <IntTools_PntOn2Faces.hxx>
+#include <NCollection_BaseAllocator.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_Compound.hxx>
+#include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
 
-#include <BOPTest_DrawableShape.hxx>
-#include <BOPTest_Objects.hxx>
-
+#include <stdio.h>
+//
 //
 static BOPAlgo_PaveFiller* pPF=NULL;
 //
@@ -85,7 +75,6 @@ static Standard_Integer bfuse     (Draw_Interpretor&, Standard_Integer, const ch
 static Standard_Integer bcommon   (Draw_Interpretor&, Standard_Integer, const char**);
 //
 static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**);
-static Standard_Integer bopnews   (Draw_Interpretor&, Standard_Integer, const char**);
 static Standard_Integer mkvolume   (Draw_Interpretor&, Standard_Integer, const char**);
 
 //=======================================================================
@@ -115,8 +104,8 @@ static Standard_Integer mkvolume   (Draw_Interpretor&, Standard_Integer, const c
   theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]", 
                                                       __FILE__, bsection, g);
   //
-  theCommands.Add("bopcurves", "use  bopcurves F1 F2 [-2d]", __FILE__, bopcurves, g);
-  theCommands.Add("bopnews"  , "use  bopnews -v[e,f]"      , __FILE__, bopnews, g);
+  theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2]",
+                                                      __FILE__, bopcurves, g);
   theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni]", 
                   __FILE__, mkvolume , g);
 }
@@ -159,7 +148,8 @@ Standard_Integer bop(Draw_Interpretor& di,
     delete pPF;
     pPF=NULL;
   }
-  Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
+  Handle(NCollection_BaseAllocator)aAL=
+    NCollection_BaseAllocator::CommonBaseAllocator();
   pPF=new BOPAlgo_PaveFiller(aAL);
   //
   pPF->SetArguments(aLC);
@@ -490,7 +480,8 @@ Standard_Integer bsmt (Draw_Interpretor& di,
   aTol=BOPTest_Objects::FuzzyValue();
   bRunParallel = BOPTest_Objects::RunParallel();
   //
-  Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
+  Handle(NCollection_BaseAllocator)aAL=
+    NCollection_BaseAllocator::CommonBaseAllocator();
   //
   //---------------------------------------------------------------
   BOPAlgo_PaveFiller aPF(aAL);
@@ -533,77 +524,6 @@ Standard_Integer bsmt (Draw_Interpretor& di,
   return 0;
 }
 //=======================================================================
-//function : bopnews
-//purpose  : 
-//=======================================================================
-Standard_Integer bopnews (Draw_Interpretor& di, 
-                          Standard_Integer n, 
-                          const char** a)
-{
-  if (n!=2) {
-    di << " use bopnews -v[e,f]\n";
-    return 0;
-  }
-  //
-  if (pPF==NULL) {
-    di << " Prepare BOPAlgo_PaveFiller first >bop S1 S2\n";
-    return 0;
-  }
-  //
-  char buf[32];
-  Standard_CString aText;
-  Standard_Integer i, i1, i2, iFound;
-  Draw_Color aTextColor(Draw_cyan);
-  TopAbs_ShapeEnum aT;
-  Handle(BOPTest_DrawableShape) aDShape;
-  //
-  const BOPDS_PDS& pDS=pPF->PDS();
-  //
-  aT=TopAbs_SHAPE;
-  if (!strcmp (a[1], "-f")) {
-    aT=TopAbs_FACE;
-  }
-  else if (!strcmp (a[1], "-e")){
-    aT=TopAbs_EDGE;
-  }
-  else if (!strcmp (a[1], "-v")){
-    aT=TopAbs_VERTEX;
-  }
-  else {
-    di << " use bopnews -v[e,f]\n";
-    return 0;
-  }
-  //
-  iFound=0;
-  i1=pDS->NbSourceShapes();
-  i2=pDS->NbShapes();
-  for (i=i1; i<i2; ++i) {
-    const BOPDS_ShapeInfo& aSI=pDS->ShapeInfo(i);
-    if (aSI.ShapeType()==aT) {
-      const TopoDS_Shape& aS=aSI.Shape();
-      //
-      Sprintf (buf, "z%d", i);
-      aText=buf;
-      aDShape=new BOPTest_DrawableShape (aS, aText, aTextColor);
-      Draw::Set (aText, aDShape);
-      //
-      Sprintf (buf, " z%d", i);
-      di << buf;
-      //
-      iFound=1;
-    }
-  }
-  //
-  if (iFound) {
-    di << "\n";
-  }
-  else {
-    di << " not found\n";
-  }
-  //
-  return 0;
-}
-//=======================================================================
 //function : bopcurves
 //purpose  : 
 //=======================================================================
@@ -612,19 +532,19 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
                             const char** a)
 {
   if (n<3) {
-    di << " use bopcurves F1 F2 [-2d]\n";
+    di << " use bopcurves F1 F2 [-2d/-2d1/-2d2]\n";
     return 1;
   }
-
+  //
   TopoDS_Shape S1 = DBRep::Get(a[1]);
   TopoDS_Shape S2 = DBRep::Get(a[2]);
   TopAbs_ShapeEnum aType;
-
+  //
   if (S1.IsNull() || S2.IsNull()) {
     di << " Null shapes is not allowed \n";
     return 1;
   }
-
+  //
   aType=S1.ShapeType();
   if (aType != TopAbs_FACE) {
     di << " Type mismatch F1\n";
@@ -635,128 +555,140 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
     di << " Type mismatch F2\n";
     return 1;
   }
-
-
+  //
   const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
   const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
-
-  Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, 
-  aToApproxC2dOnS2, anIsDone, bMake2dCurves;
-  Standard_Integer i, aNbCurves;
+  //
+  Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
+  Standard_Integer i, aNbCurves, aNbPoints;
   Standard_Real anAppTol, aTolR;
-  TCollection_AsciiString aNm("c_");
-
-  bMake2dCurves = Standard_False;
+  TCollection_AsciiString aNm("c_"), aNp("p_");
+  //
+  anAppTol = 0.0000001;
+  aToApproxC3d = Standard_True;
+  aToApproxC2dOnS1 = Standard_False;
+  aToApproxC2dOnS2 = Standard_False;
+  //
   if (n > 3) {
     if (!strcasecmp(a[3],"-2d")) {
-      bMake2dCurves = Standard_True;
-    } else {
-      di << "Wrong key. To build 2d curves use: bopcurves F1 F2 -2d \n";
+      aToApproxC2dOnS1 = Standard_True;
+      aToApproxC2dOnS2 = Standard_True;
+    } 
+    else if (!strcasecmp(a[3],"-2d1")) {
+      aToApproxC2dOnS1 = Standard_True;
+    }
+    else if (!strcasecmp(a[3],"-2d2")) {
+      aToApproxC2dOnS2 = Standard_True;
+    }
+    else {
+      di << "Wrong key. To build 2d curves use: bopcurves F1 F2 -2d/-2d1/-2d2 \n";
       return 1;
     }
   }
   //
-
-  aToApproxC3d = Standard_True;
-  aToApproxC2dOnS1 = bMake2dCurves;
-  aToApproxC2dOnS2 = bMake2dCurves;
-  anAppTol=0.0000001;
-
-
   IntTools_FaceFace aFF;
-  
+  //
   aFF.SetParameters (aToApproxC3d,
                      aToApproxC2dOnS1,
                      aToApproxC2dOnS2,
                      anAppTol);
-  
+  //
   aFF.Perform (aF1, aF2);
-  
+  //
   anIsDone=aFF.IsDone();
   if (!anIsDone) {
-    di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
-    return 1;
+    di << "Error: anIsDone=" << (Standard_Integer) anIsDone << "\n";
+    return 0;
   }
-
+  //
   aFF.PrepareLines3D(Standard_False);
   const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
-
+  const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
+  //
+  aNbCurves = aSCs.Length();
+  aNbPoints = aSPs.Length();
+  if (!aNbCurves && !aNbPoints) {
+    di << " has no 3d curves\n";
+    di << " has no 3d points\n";
+    return 0;
+  }
   //
   aTolR=aFF.TolReached3d();
   di << "Tolerance Reached=" << aTolR << "\n";
-
-  aNbCurves=aSCs.Length();
-  if (!aNbCurves) {
-    di << " has no 3d curve\n";
-    return 1;
-  }
-  else  {
+  //
+  // curves
+  if (aNbCurves) {
     di << aNbCurves << " curve(s) found.\n";
-  }
-
-  for (i=1; i<=aNbCurves; i++) {
-    const IntTools_Curve& anIC=aSCs(i);
+    //
+    for (i=1; i<=aNbCurves; i++) {
+      const IntTools_Curve& anIC=aSCs(i);
 
-    Handle (Geom_Curve)  aC3D = anIC.Curve();
+      Handle (Geom_Curve)  aC3D = anIC.Curve();
 
-    if (aC3D.IsNull()) {
-      di << " has Null 3d curve# " << i << "\n";
-      continue;
-    }
+      if (aC3D.IsNull()) {
+        di << " has Null 3d curve# " << i << "\n";
+        continue;
+      }
 
-    TCollection_AsciiString anIndx(i), aNmx;
-    aNmx = aNm + anIndx;
+      TCollection_AsciiString anIndx(i), aNmx;
+      aNmx = aNm + anIndx;
 
-    Standard_CString nameC = aNmx.ToCString();
+      Standard_CString nameC = aNmx.ToCString();
 
-    DrawTrSurf::Set(nameC, aC3D);
-    di << nameC << " ";
-    //
-    if (bMake2dCurves) {
+      DrawTrSurf::Set(nameC, aC3D);
+      di << nameC << " ";
+      //
       Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
       Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
       //
-      if (aPC1.IsNull() && aPC2.IsNull()) {
-        di << " \n has Null 2d curves# " << i << "\n";
-        continue;
-      }
-      //
-      if (aPC1.IsNull()) {
-        TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
-        pc2Nx = pc2N + anIndx;
-        Standard_CString nameC2d2 = pc2Nx.ToCString();
+      if (!aPC1.IsNull() || !aPC2.IsNull()) {
+        di << "(";
         //
-        DrawTrSurf::Set(nameC2d2, aPC2);
-        di << "(" << nameC2d2 << ") ";
-        di << " \n Null first 2d curve of the curve #" << i << "\n";
-        continue;
-      } 
-      else {
-        TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
-        pc1Nx = pc1N + anIndx;
-        Standard_CString nameC2d1 = pc1Nx.ToCString();
+        if (!aPC1.IsNull()) {
+          TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
+          pc1Nx = pc1N + anIndx;
+          Standard_CString nameC2d1 = pc1Nx.ToCString();
+          //
+          DrawTrSurf::Set(nameC2d1, aPC1);
+          di << nameC2d1;
+        }
         //
-        DrawTrSurf::Set(nameC2d1, aPC1);
-        di << "(" << nameC2d1;
+        if (!aPC2.IsNull()) {
+          TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
+          pc2Nx = pc2N + anIndx;
+          Standard_CString nameC2d2 = pc2Nx.ToCString();
+          //
+          DrawTrSurf::Set(nameC2d2, aPC2);
+          //
+          if (!aPC1.IsNull()) {
+            di << ", ";
+          }
+          di << nameC2d2;
+        }
+        di << ") ";
       }
+    }
+    di << "\n";
+  }
+  //
+  // points
+  if (aNbPoints) {
+    di << aNbPoints << " point(s) found.\n";
+    //
+    for (i = 1; i <= aNbPoints; i++) {
+      const IntTools_PntOn2Faces& aPi = aSPs(i);
+      const gp_Pnt& aP = aPi.P1().Pnt();
       //
-      if (aPC2.IsNull()) {
-        di << ") \n Null second 2d curve of the curve #" << i << "\n";
-        continue;
-      } 
-      else {
-        TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
-        pc2Nx = pc2N + anIndx;
-        Standard_CString nameC2d2 = pc2Nx.ToCString();
-        //
-        DrawTrSurf::Set(nameC2d2, aPC2);
-        di << ", " << nameC2d2 << ") ";
-      }
+      TCollection_AsciiString anIndx(i), aNmx;
+      aNmx = aNp + anIndx;
+      Standard_CString nameP = aNmx.ToCString();
+      //
+      DrawTrSurf::Set(nameP, aP);
+      di << nameP << " ";
     }
+    di << "\n";
   }
-
-  di << "\n";
-  
+  //
   return 0;
 }
 //=======================================================================