0031499: Boolean Operations - Custom fuzzy value corrupts the result of CUT
[occt.git] / src / BOPTest / BOPTest_BOPCommands.cxx
index e48dd62..edf1741 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 <DBRep.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 <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 <BOPDS_DS.hxx>
-#include <BOPTest_DrawableShape.hxx>
-#include <BOPCol_ListOfShape.hxx>
-
-#include <TCollection_AsciiString.hxx>
-#include <IntTools_FaceFace.hxx>
-#include <IntTools_Curve.hxx>
-#include <DrawTrSurf.hxx>
-#include <Draw_Color.hxx>
-#include <Draw.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 <BOPAlgo_Section.hxx>
+#include <BRepTest_Objects.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 <TopTools_ListOfShape.hxx>
 
+#include <stdio.h>
+//
 //
 static BOPAlgo_PaveFiller* pPF=NULL;
 //
@@ -58,6 +55,7 @@ static
                           Standard_Integer n,
                           const char** a,
                           const BOPAlgo_Operation aOp);
+//
 static
   Standard_Integer bsmt (Draw_Interpretor& di, 
                        Standard_Integer n, 
@@ -78,10 +76,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 bparallelmode(Draw_Interpretor&, Standard_Integer, const char**);
-//
 static Standard_Integer mkvolume   (Draw_Interpretor&, Standard_Integer, const char**);
 
 //=======================================================================
@@ -94,28 +88,30 @@ static Standard_Integer mkvolume   (Draw_Interpretor&, Standard_Integer, const c
   if (done) return;
   done = Standard_True;
   // Chapter's name
-  const char* g = "BOP commands";
+  const char* g = "BOPTest commands";
   // Commands
   
-  theCommands.Add("bop"       , "use bop s1 s2 [tol]" , __FILE__, bop, g);
+  theCommands.Add("bop"       , "use bop s1 s2" , __FILE__, bop, g);
   theCommands.Add("bopcommon" , "use bopcommon r"     , __FILE__, bopcommon, g);
   theCommands.Add("bopfuse"   , "use bopfuse r"       , __FILE__,bopfuse, g);
   theCommands.Add("bopcut"    , "use bopcut r"        , __FILE__,bopcut, g);
   theCommands.Add("boptuc"    , "use boptuc r"        , __FILE__,boptuc, g);
   theCommands.Add("bopsection", "use bopsection r"    , __FILE__,bopsection, g);
   //
-  theCommands.Add("bcommon" , "use bcommon r s1 s2 [tol]" , __FILE__,bcommon, g);
-  theCommands.Add("bfuse"   , "use bfuse r s1 s2 [tol]"   , __FILE__,bfuse, g);
-  theCommands.Add("bcut"    , "use bcut r s1 s2 [tol]"    , __FILE__,bcut, g);
-  theCommands.Add("btuc"    , "use btuc r s1 s2 [tol]"    , __FILE__,btuc, g);
-  theCommands.Add("bsection", "Use >bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]", 
+  theCommands.Add("bcommon" , "use bcommon r s1 s2" , __FILE__,bcommon, g);
+  theCommands.Add("bfuse"   , "use bfuse r s1 s2"   , __FILE__,bfuse, g);
+  theCommands.Add("bcut"    , "use bcut r s1 s2"    , __FILE__,bcut, g);
+  theCommands.Add("btuc"    , "use btuc r s1 s2"    , __FILE__,btuc, g);
+  theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]"
+                               "Builds section between shapes. Options:\n"
+                               "-n2d/-n2d1/-n2d2 - disable the PCurve construction;\n"
+                               "-na - disables the approximation of the section curves.\n",
                                                       __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("bparallelmode", "bparallelmode [1/0] : show / set parallel mode for boolean operations", 
-                  __FILE__, bparallelmode, g);
-  theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-s] [tol]", 
+  theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2] "
+                               "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]",
+                                                      __FILE__, bopcurves, g);
+  theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-ai]",
                   __FILE__, mkvolume , g);
 }
 
@@ -123,17 +119,18 @@ static Standard_Integer mkvolume   (Draw_Interpretor&, Standard_Integer, const c
 //function : bop
 //purpose  : 
 //=======================================================================
-Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bop(Draw_Interpretor& di, 
+                     Standard_Integer n, 
+                     const char** a)
 {
-  char buf[32];
-  Standard_Integer iErr;
+  Standard_Boolean bRunParallel, bNonDestructive;
   Standard_Real aTol;
   TopoDS_Shape aS1, aS2;
-  BOPCol_ListOfShape aLC;
+  TopTools_ListOfShape aLC;
   //
-  if (n < 3 || n > 4) {
-    di << " use bop Shape1 Shape2 [tol]\n";
-    return 1;
+  if (n != 3) {
+    di << " use bop s1 s2 \n";
+    return 0;
   }
   //
   aS1=DBRep::Get(a[1]);
@@ -141,13 +138,13 @@ Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
   //
   if (aS1.IsNull() || aS2.IsNull()) {
     di << " null shapes are not allowed \n";
-    return 1;
+    return 0;
   }
   //
-  aTol = 0.;
-  if (n == 4) {
-    aTol = Draw::Atof(a[3]);
-  }
+  aTol=BOPTest_Objects::FuzzyValue();
+  bRunParallel=BOPTest_Objects::RunParallel();
+  bNonDestructive = BOPTest_Objects::NonDestructive();
+  BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
   //
   aLC.Append(aS1);
   aLC.Append(aS2);
@@ -156,19 +153,19 @@ Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
     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);
   pPF->SetFuzzyValue(aTol);
+  pPF->SetRunParallel(bRunParallel);
+  pPF->SetNonDestructive(bNonDestructive);
+  pPF->SetGlue(aGlue);
+  pPF->SetUseOBB(BOPTest_Objects::UseOBB());
   //
   pPF->Perform();
-  iErr=pPF->ErrorStatus();
-  if (iErr) {
-    Sprintf(buf, " ErrorStatus : %d\n",  iErr);
-    di << buf;
-    return 0;
-  }
+  BOPTest::ReportAlerts(pPF->GetReport());
   //
   return 0;
 }
@@ -176,7 +173,9 @@ Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
 //function : bopcommon
 //purpose  : 
 //=======================================================================
-Standard_Integer bopcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bopcommon (Draw_Interpretor& di, 
+                            Standard_Integer n, 
+                            const char** a)
 {
   return bopsmt(di, n, a, BOPAlgo_COMMON);
 }
@@ -184,7 +183,9 @@ Standard_Integer bopcommon (Draw_Interpretor& di, Standard_Integer n, const char
 //function : bopfuse
 //purpose  : 
 //=======================================================================
-Standard_Integer bopfuse(Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bopfuse(Draw_Interpretor& di, 
+                         Standard_Integer n, 
+                         const char** a)
 {
   return bopsmt(di, n, a, BOPAlgo_FUSE);
 }
@@ -192,7 +193,9 @@ Standard_Integer bopfuse(Draw_Interpretor& di, Standard_Integer n, const char**
 //function : bopcut
 //purpose  : 
 //=======================================================================
-Standard_Integer bopcut(Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bopcut(Draw_Interpretor& di, 
+                        Standard_Integer n, 
+                        const char** a)
 {
   return bopsmt(di, n, a, BOPAlgo_CUT);
 }
@@ -200,7 +203,9 @@ Standard_Integer bopcut(Draw_Interpretor& di, Standard_Integer n, const char** a
 //function : boptuc
 //purpose  : 
 //=======================================================================
-Standard_Integer boptuc(Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer boptuc(Draw_Interpretor& di, 
+                        Standard_Integer n, 
+                        const char** a)
 {
   return bopsmt(di, n, a, BOPAlgo_CUT21);
 }
@@ -214,7 +219,7 @@ Standard_Integer bopsmt(Draw_Interpretor& di,
                         const BOPAlgo_Operation aOp)
 {
   if (n<2) {
-    di << " use bopsmt r\n [tol]";
+    di << " use bopsmt r\n";
     return 0;
   }
   //
@@ -223,22 +228,25 @@ Standard_Integer bopsmt(Draw_Interpretor& di,
     return 0;
   }
   //
-  if (pPF->ErrorStatus()) {
+  if (pPF->HasErrors()) {
     di << " PaveFiller has not been done\n";
     return 0;
   }
   //
   char buf[64];
-  Standard_Integer aNb, iErr;
+  Standard_Boolean bRunParallel;
+  Standard_Integer aNb;
   BOPAlgo_BOP aBOP;
   //
-  const BOPCol_ListOfShape& aLC=pPF->Arguments();
+  const TopTools_ListOfShape& aLC=pPF->Arguments();
   aNb=aLC.Extent();
   if (aNb!=2) {
     Sprintf (buf, " wrong number of arguments %s\n", aNb);
     di << buf;
     return 0;
   }
+  // 
+  bRunParallel=BOPTest_Objects::RunParallel();
   //
   const TopoDS_Shape& aS1=aLC.First();
   const TopoDS_Shape& aS2=aLC.Last();
@@ -246,12 +254,18 @@ Standard_Integer bopsmt(Draw_Interpretor& di,
   aBOP.AddArgument(aS1);
   aBOP.AddTool(aS2);
   aBOP.SetOperation(aOp);
+  aBOP.SetRunParallel (bRunParallel);
+  aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
+  aBOP.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
   //
   aBOP.PerformWithFiller(*pPF);
-  iErr=aBOP.ErrorStatus();
-  if (iErr) {
-    Sprintf(buf, " ErrorStatus : %d\n",  iErr);
-    di << buf;
+  BOPTest::ReportAlerts(aBOP.GetReport());
+
+  // Store the history of Boolean operation into the session
+  if (BRepTest_Objects::IsHistoryNeeded())
+    BRepTest_Objects::SetHistory(aBOP.History());
+
+  if (aBOP.HasErrors()) {
     return 0;
   }
   //
@@ -268,10 +282,12 @@ Standard_Integer bopsmt(Draw_Interpretor& di,
 //function : bopsection
 //purpose  : 
 //=======================================================================
-Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bopsection(Draw_Interpretor& di, 
+                            Standard_Integer n, 
+                            const char** a)
 {
   if (n<2) {
-    di << " use bopsmt r\n";
+    di << " use bopsection r\n";
     return 0;
   }
   //
@@ -280,16 +296,17 @@ Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char
     return 0;
   }
   //
-  if (pPF->ErrorStatus()) {
+  if (pPF->HasErrors()) {
     di << " PaveFiller has not been done\n";
     return 0;
   }
   //
   char buf[64];
-  Standard_Integer aNb, iErr;
+  Standard_Boolean bRunParallel;
+  Standard_Integer aNb;
   BOPAlgo_Section aBOP;
   //
-  const BOPCol_ListOfShape& aLC=pPF->Arguments();
+  const TopTools_ListOfShape& aLC=pPF->Arguments();
   aNb=aLC.Extent();
   if (aNb!=2) {
     Sprintf (buf, " wrong number of arguments %s\n", aNb);
@@ -297,17 +314,25 @@ Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char
     return 0;
   }
   //
+  bRunParallel=BOPTest_Objects::RunParallel();
+  //
   const TopoDS_Shape& aS1=aLC.First();
   const TopoDS_Shape& aS2=aLC.Last();
   //
   aBOP.AddArgument(aS1);
   aBOP.AddArgument(aS2);
+  aBOP.SetRunParallel (bRunParallel);
+  aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
+  aBOP.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
   //
   aBOP.PerformWithFiller(*pPF);
-  iErr=aBOP.ErrorStatus();
-  if (iErr) {
-    Sprintf(buf, " ErrorStatus : %d\n",  iErr);
-    di << buf;
+  BOPTest::ReportAlerts(aBOP.GetReport());
+
+  // Store the history of Section operation into the session
+  if (BRepTest_Objects::IsHistoryNeeded())
+    BRepTest_Objects::SetHistory(aBOP.History());
+
+  if (aBOP.HasErrors()) {
     return 0;
   }
   //
@@ -324,7 +349,9 @@ Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char
 //function : bcommon
 //purpose  : 
 //=======================================================================
-Standard_Integer bcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bcommon (Draw_Interpretor& di, 
+                          Standard_Integer n, 
+                          const char** a)
 {
   return bsmt(di, n, a, BOPAlgo_COMMON);
 }
@@ -332,7 +359,9 @@ Standard_Integer bcommon (Draw_Interpretor& di, Standard_Integer n, const char**
 //function : bfuse
 //purpose  : 
 //=======================================================================
-Standard_Integer bfuse (Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bfuse (Draw_Interpretor& di, 
+                        Standard_Integer n, 
+                        const char** a)
 {
   return bsmt(di, n, a, BOPAlgo_FUSE);
 }
@@ -340,7 +369,9 @@ Standard_Integer bfuse (Draw_Interpretor& di, Standard_Integer n, const char** a
 //function : bcut
 //purpose  : 
 //=======================================================================
-Standard_Integer bcut (Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer bcut (Draw_Interpretor& di, 
+                       Standard_Integer n, 
+                       const char** a)
 {
   return bsmt(di, n, a, BOPAlgo_CUT);
 }
@@ -348,7 +379,9 @@ Standard_Integer bcut (Draw_Interpretor& di, Standard_Integer n, const char** a)
 //function : btuc
 //purpose  : 
 //=======================================================================
-Standard_Integer btuc (Draw_Interpretor& di, Standard_Integer n, const char** a)
+Standard_Integer btuc (Draw_Interpretor& di, 
+                       Standard_Integer n, 
+                       const char** a)
 {
   return bsmt(di, n, a, BOPAlgo_CUT21);
 }
@@ -360,30 +393,32 @@ Standard_Integer  bsection(Draw_Interpretor& di,
                            Standard_Integer n, 
                            const char** a)
 {
-  const char* usage = " Usage: bsection Result s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n";
   if (n < 4) {
-    di << usage;
-    return 1;
+    di << "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n";
+    return 0;
   }
   //
-  TopoDS_Shape aS1 = DBRep::Get(a[2]);
-  TopoDS_Shape aS2 = DBRep::Get(a[3]);
+  TopoDS_Shape aS1, aS2;
   //
+  aS1=DBRep::Get(a[2]);
+  aS2=DBRep::Get(a[3]);
   if (aS1.IsNull() || aS2.IsNull()) {
     di << " Null shapes are not allowed \n";
-    return 1;
+    return 0;
   }
-  //
-  Standard_Boolean bApp, bPC1, bPC2;
-  Standard_Integer i;
+  // 
+  Standard_Boolean bRunParallel, bNonDestructive, bApp, bPC1, bPC2;
   Standard_Real aTol;
   //
   bApp = Standard_True;
   bPC1 = Standard_True;
   bPC2 = Standard_True;
-  aTol = 0.;
+  aTol = BOPTest_Objects::FuzzyValue(); 
+  bRunParallel = BOPTest_Objects::RunParallel();
+  bNonDestructive = BOPTest_Objects::NonDestructive();
+  BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
   //
-  for (i = 4; i < n; ++i) {
+  for (Standard_Integer i = 4; i < n; ++i) {
     if (!strcmp(a[i], "-n2d")) {
       bPC1 = Standard_False;
       bPC2 = Standard_False;
@@ -397,25 +432,37 @@ Standard_Integer  bsection(Draw_Interpretor& di,
     else if (!strcmp(a[i], "-na")) {
       bApp = Standard_False;
     }
-    else {
-      aTol = Draw::Atof(a[i]);
-    }
   }
   //
-  Standard_Integer iErr;
-  char buf[80];
-  //
   BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
+  //
   aSec.Approximation(bApp);
   aSec.ComputePCurveOn1(bPC1);
   aSec.ComputePCurveOn2(bPC2);
+  //
   aSec.SetFuzzyValue(aTol);
+  aSec.SetRunParallel(bRunParallel);
+  aSec.SetNonDestructive(bNonDestructive);
+  aSec.SetGlue(aGlue);
+  aSec.SetUseOBB(BOPTest_Objects::UseOBB());
   //
   aSec.Build();
-  iErr=aSec.ErrorStatus();
+
+  // Store the history of Section operation into the session
+  if (BRepTest_Objects::IsHistoryNeeded())
+    BRepTest_Objects::SetHistory(aSec.History());
+
+  //
+  if (aSec.HasWarnings()) {
+    Standard_SStream aSStream;
+    aSec.DumpWarnings(aSStream);
+    di << aSStream;
+  }
+  //
   if (!aSec.IsDone()) {
-    Sprintf(buf, " ErrorStatus : %d\n",  iErr);
-    di << buf;
+    Standard_SStream aSStream;
+    aSec.DumpErrors(aSStream);
+    di << aSStream;
     return 0;
   }
   //
@@ -427,7 +474,6 @@ Standard_Integer  bsection(Draw_Interpretor& di,
   DBRep::Set(a[1], aR);
   return 0;
 }
-
 //=======================================================================
 //function : bsmt
 //purpose  : 
@@ -437,15 +483,14 @@ Standard_Integer bsmt (Draw_Interpretor& di,
                        const char** a,
                        const BOPAlgo_Operation aOp)
 {
-  char buf[32];
-  Standard_Integer iErr;
+  Standard_Boolean bRunParallel, bNonDestructive;
   TopoDS_Shape aS1, aS2;
-  BOPCol_ListOfShape aLC;
+  TopTools_ListOfShape aLC;
   Standard_Real aTol;
   //
-  if (n < 4 || n > 5) {
-    di << " use bx r s1 s2 [tol]\n";
-    return 1;
+  if (n != 4) {
+    di << " use bx r s1 s2\n";
+    return 0;
   }
   //
   aS1=DBRep::Get(a[2]);
@@ -453,133 +498,64 @@ Standard_Integer bsmt (Draw_Interpretor& di,
   //
   if (aS1.IsNull() || aS2.IsNull()) {
     di << " null shapes are not allowed \n";
-    return 1;
-  }
-  //
-  aTol = 0.;
-  if (n == 5) {
-    aTol = Draw::Atof(a[4]);
+    return 0;
   }
-  //
   aLC.Append(aS1);
   aLC.Append(aS2);
+  // 
+  aTol=BOPTest_Objects::FuzzyValue();
+  bRunParallel = BOPTest_Objects::RunParallel();
+  bNonDestructive = BOPTest_Objects::NonDestructive();
+  BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
   //
-  Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
+  Handle(NCollection_BaseAllocator)aAL=
+    NCollection_BaseAllocator::CommonBaseAllocator();
+  //
+  //---------------------------------------------------------------
   BOPAlgo_PaveFiller aPF(aAL);
   //
   aPF.SetArguments(aLC);
-  aPF.SetFuzzyValue(aTol);
+  aPF.SetFuzzyValue(aTol); 
+  aPF.SetRunParallel(bRunParallel);
+  aPF.SetNonDestructive(bNonDestructive);
+  aPF.SetGlue(aGlue);
+  aPF.SetUseOBB(BOPTest_Objects::UseOBB());
   //
   aPF.Perform();
-  iErr=aPF.ErrorStatus();
-  if (iErr) {
-    Sprintf(buf, " ErrorStatus : %d\n",  iErr);
-    di << buf;
+  BOPTest::ReportAlerts(aPF.GetReport());
+  if (aPF.HasErrors()) {
     return 0;
   }
   //
-  BRepAlgoAPI_BooleanOperation* pBuilder=NULL;
-  // 
-  if (aOp==BOPAlgo_COMMON) {
-    pBuilder=new BRepAlgoAPI_Common(aS1, aS2, aPF);
-  }
-  else if (aOp==BOPAlgo_FUSE) {
-    pBuilder=new BRepAlgoAPI_Fuse(aS1, aS2, aPF);
-  }
-  else if (aOp==BOPAlgo_CUT) {
-    pBuilder=new BRepAlgoAPI_Cut (aS1, aS2, aPF);
-  }
-  else if (aOp==BOPAlgo_CUT21) {
-    pBuilder=new BRepAlgoAPI_Cut(aS1, aS2, aPF, Standard_False);
-  }
+  //---------------------------------------------------------------
+  BOPAlgo_BOP aBOP(aAL);
   //
-  iErr = pBuilder->ErrorStatus();
-  if (!pBuilder->IsDone()) {
-    Sprintf(buf, " ErrorStatus : %d\n",  iErr);
-    di << buf;
+  aBOP.AddArgument(aS1);
+  aBOP.AddTool(aS2);
+  aBOP.SetOperation(aOp);
+  aBOP.SetRunParallel(bRunParallel);
+  aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
+  aBOP.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
+  //
+  aBOP.PerformWithFiller(aPF);
+  BOPTest::ReportAlerts(aBOP.GetReport());
+
+  // Store the history of Boolean operation into the session
+  if (BRepTest_Objects::IsHistoryNeeded())
+    BRepTest_Objects::SetHistory(aPF.Arguments(), aBOP);
+
+  if (aBOP.HasErrors()) {
     return 0;
   }
-  const TopoDS_Shape& aR=pBuilder->Shape();
+  const TopoDS_Shape& aR=aBOP.Shape();
   if (aR.IsNull()) {
     di << " null shape\n";
     return 0;
   }
-  DBRep::Set(a[1], aR);
-  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";
-  }
   //
+  DBRep::Set(a[1], aR);
   return 0;
 }
-
 //=======================================================================
 //function : bopcurves
 //purpose  : 
@@ -589,19 +565,20 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
                             const char** a)
 {
   if (n<3) {
-    di << " use bopcurves F1 F2 [-2d]\n";
+    di << "Usage: bopcurves F1 F2 [-2d/-2d1/-2d2] "
+          "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]\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";
+    di << " Null shapes are not allowed \n";
     return 1;
   }
-
+  //
   aType=S1.ShapeType();
   if (aType != TopAbs_FACE) {
     di << " Type mismatch F1\n";
@@ -612,158 +589,181 @@ 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;
+  Standard_Integer aNbCurves, aNbPoints;
+  Standard_Real anAppTol;
+  IntSurf_ListOfPntOn2S aListOfPnts;
+  TCollection_AsciiString aNm("c_"), aNp("p_");
+  //
+  anAppTol = 0.0000001;
+  aToApproxC3d = Standard_True;
+  aToApproxC2dOnS1 = Standard_False;
+  aToApproxC2dOnS2 = Standard_False;
 
-  Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone, bMake2dCurves;
-  Standard_Integer i, aNbCurves;
-  Standard_Real anAppTol, aTolR;
-  TCollection_AsciiString aNm("c_");
-
-  bMake2dCurves = 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";
+  //
+  Standard_Boolean bExtOut = Standard_False;
+  for(Standard_Integer i = 3; i < n; i++)
+  {
+    if (!strcasecmp(a[i],"-2d")) {
+      aToApproxC2dOnS1 = Standard_True;
+      aToApproxC2dOnS2 = Standard_True;
+    } 
+    else if (!strcasecmp(a[i],"-2d1")) {
+      aToApproxC2dOnS1 = Standard_True;
+    }
+    else if (!strcasecmp(a[i],"-2d2")) {
+      aToApproxC2dOnS2 = Standard_True;
+    }
+    else if (!strcasecmp(a[i],"-p")) {
+      IntSurf_PntOn2S aPt;
+      const Standard_Real aU1 = Draw::Atof(a[++i]);
+      const Standard_Real aV1 = Draw::Atof(a[++i]);
+      const Standard_Real aU2 = Draw::Atof(a[++i]);
+      const Standard_Real aV2 = Draw::Atof(a[++i]);
+
+      aPt.SetValue(aU1, aV1, aU2, aV2);
+      aListOfPnts.Append(aPt);
+    }
+    else if (!strcasecmp(a[i],"-v")) {
+      bExtOut = Standard_True;
+    }
+    else {
+      di << "Wrong key.\n";
+      di << "To build 2d curves use one of the following keys: -2d/-2d1/-2d2\n";
+      di << "To add start points use the following key: -p u1 v1 u2 v2\n";
+      di << "For extended output use the following key: -v\n";
       return 1;
     }
   }
   //
-
-  aToApproxC3d = Standard_True;
-  aToApproxC2dOnS1 = bMake2dCurves;
-  aToApproxC2dOnS2 = bMake2dCurves;
-  anAppTol=0.0000001;
-
-
   IntTools_FaceFace aFF;
-  
+  //
   aFF.SetParameters (aToApproxC3d,
                      aToApproxC2dOnS1,
                      aToApproxC2dOnS2,
                      anAppTol);
-  
+  aFF.SetList(aListOfPnts);
+  aFF.SetFuzzyValue (BOPTest_Objects::FuzzyValue());
+  //
   aFF.Perform (aF1, aF2);
-  
+  //
   anIsDone=aFF.IsDone();
   if (!anIsDone) {
-    di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
-    return 1;
+    di << "Error: Intersection failed\n";
+    return 0;
   }
-
+  //
   aFF.PrepareLines3D(Standard_False);
   const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
-
+  const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
   //
-  aTolR=aFF.TolReached3d();
-  di << "Tolerance Reached=" << aTolR << "\n";
-
-  aNbCurves=aSCs.Length();
-  if (!aNbCurves) {
-    di << " has no 3d curve\n";
-    return 1;
+  aNbCurves = aSCs.Length();
+  aNbPoints = aSPs.Length();
+  if (!aNbCurves && !aNbPoints) {
+    di << " has no 3d curves\n";
+    di << " has no 3d points\n";
+    return 0;
   }
-  else
-  {
+  //
+  // curves
+  if (aNbCurves) {
+    Standard_Real aTolR = 0.;
+    if (!bExtOut) {
+      // find maximal tolerance
+      for (Standard_Integer i = 1; i <= aNbCurves; i++) {
+        const IntTools_Curve& anIC = aSCs(i);
+        if (aTolR < anIC.Tolerance()) {
+          aTolR = anIC.Tolerance();
+        }
+      }
+      di << "Tolerance Reached=" << aTolR << "\n";
+    }
+    //
     di << aNbCurves << " curve(s) found.\n";
-  }
-
-  for (i=1; i<=aNbCurves; i++) {
-    const IntTools_Curve& anIC=aSCs(i);
+    //
+    for (Standard_Integer 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 << ") ";
       }
       //
-      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 << ") ";
+      if (bExtOut) {
+        di << "\nTolerance: " << anIC.Tolerance() << "\n";
+        di << "Tangential tolerance: " << anIC.TangentialTolerance() << "\n";
+        di << "\n";
       }
     }
-  }
-
-  di << "\n";
-  
-  return 0;
-}
-
-//=======================================================================
-//function : bparallelmode
-//purpose  : 
-//=======================================================================
-Standard_Integer bparallelmode(Draw_Interpretor& di, Standard_Integer n, const char** a)
-{
-  if (n == 2)
-  {
-    Standard_Boolean isParallelOn = Draw::Atoi (a[1]) == 1;
-    if (isParallelOn == 1)
-    {
-      BOPAlgo_Algo::SetParallelMode(Standard_True);
-      di << "Parallel mode for boolean operations has been enabled";
-    }
-    else
-    {
-      BOPAlgo_Algo::SetParallelMode(Standard_False);
-      di << "Parallel mode for boolean operations has been disabled";
+    if (!bExtOut) {
+      di << "\n";
     }
   }
-  else
-  {
-    di << "Parallel mode state for boolean operations: "
-       << (BOPAlgo_Algo::GetParallelMode()? "enabled" : "disabled");
+  //
+  // points
+  if (aNbPoints) {
+    di << aNbPoints << " point(s) found.\n";
+    //
+    for (Standard_Integer i = 1; i <= aNbPoints; i++) {
+      const IntTools_PntOn2Faces& aPi = aSPs(i);
+      const gp_Pnt& aP = aPi.P1().Pnt();
+      //
+      TCollection_AsciiString anIndx(i), aNmx;
+      aNmx = aNp + anIndx;
+      Standard_CString nameP = aNmx.ToCString();
+      //
+      DrawTrSurf::Set(nameP, aP);
+      di << nameP << " ";
+    }
+    di << "\n";
   }
-
+  //
   return 0;
 }
-
 //=======================================================================
 //function : mkvolume
 //purpose  : 
@@ -771,28 +771,32 @@ Standard_Integer bparallelmode(Draw_Interpretor& di, Standard_Integer n, const c
 Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a) 
 {
   if (n < 3) {
-    di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-s] [tol]\n";
+    di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-ai]\n";
     di << "Options:\n";
     di << " -c  - use this option if the arguments are compounds\n";
     di << "       containing shapes that should be interfered;\n";
     di << " -ni - use this option if the arguments should not be interfered;\n";
-    di << " -s  - use this option to run the operation in non parallel mode;\n";
-    di << " tol - additional tolerance value (real).\n";
+    di << " -ai - use this option to avoid internal for solids shapes in the result.\n";
     return 1;
   }
   //
   const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
   //
-  Standard_Boolean bToIntersect, bRunParallel, bCompounds;
+  Standard_Boolean bToIntersect, bRunParallel, bNonDestructive;
+  Standard_Boolean bCompounds, bAvoidInternal;
   Standard_Integer i;
   Standard_Real aTol;
   TopoDS_Shape aS;
-  BOPCol_ListOfShape aLS;
+  TopTools_ListOfShape aLS;
+  //
+  aTol = BOPTest_Objects::FuzzyValue();
+  bRunParallel = BOPTest_Objects::RunParallel();
+  bNonDestructive = BOPTest_Objects::NonDestructive();
+  BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
   //
-  aTol = 0.;
   bToIntersect = Standard_True;
-  bRunParallel = Standard_True;
   bCompounds = Standard_False;
+  bAvoidInternal = Standard_False;
   //
   for (i = 2; i < n; ++i) {
     aS = DBRep::Get(a[i]);
@@ -806,11 +810,8 @@ Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char**
       else if (!strcmp(a[i], "-ni")) {
         bToIntersect = Standard_False;
       }
-      else if (!strcmp(a[i], "-s")) {
-        bRunParallel = Standard_False;
-      }
-      else {
-        aTol = Draw::Atof(a[i]);
+      else if (!strcmp(a[i], "-ai")) {
+        bAvoidInternal = Standard_True;
       }
     }
   }
@@ -823,8 +824,8 @@ Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char**
   //
   // treat list of arguments for the case of compounds
   if (bToIntersect && bCompounds) {
-    BOPCol_ListOfShape aLSx;
-    BOPCol_ListIteratorOfListOfShape aItLS;
+    TopTools_ListOfShape aLSx;
+    TopTools_ListIteratorOfListOfShape aItLS;
     //
     aItLS.Initialize(aLS);
     for (; aItLS.More(); aItLS.Next()) {
@@ -845,11 +846,21 @@ Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char**
   aMV.SetIntersect(bToIntersect);
   aMV.SetRunParallel(bRunParallel);
   aMV.SetFuzzyValue(aTol);
+  aMV.SetNonDestructive(bNonDestructive);
+  aMV.SetAvoidInternalShapes(bAvoidInternal);
+  aMV.SetGlue(aGlue);
+  aMV.SetUseOBB(BOPTest_Objects::UseOBB());
+  aMV.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
   //
   aMV.Perform();
-  if (aMV.ErrorStatus()) {
-    di << "Error status: " << aMV.ErrorStatus();
-    return 1;
+  BOPTest::ReportAlerts(aMV.GetReport());
+
+  // Store the history of Volume Maker into the session
+  if (BRepTest_Objects::IsHistoryNeeded())
+    BRepTest_Objects::SetHistory(aLS, aMV);
+
+  if (aMV.HasErrors()) {
+    return 0;
   }
   //
   const TopoDS_Shape& aR = aMV.Shape();