0024585: Wrong pcurve of the section curve
[occt.git] / src / BOPTest / BOPTest_BOPCommands.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 8331f75..bcd8aa1
@@ -1,22 +1,17 @@
 // Created on: 2000-03-16
 // Created by: Peter KURNEV
-// Copyright (c) 2000-2012 OPEN CASCADE SAS
+// Copyright (c) 2000-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 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 <BOPTest.ixx>
 
@@ -108,7 +103,7 @@ static Standard_Integer bopnews   (Draw_Interpretor&, Standard_Integer, const ch
   theCommands.Add("bsection", "Use >bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]", 
                                                       __FILE__, bsection, g);
   //
-  theCommands.Add("bopcurves", "use  bopcurves F1 F2", __FILE__, bopcurves, g);
+  theCommands.Add("bopcurves", "use  bopcurves F1 F2 [-2d]", __FILE__, bopcurves, g);
   theCommands.Add("bopnews", "use  bopnews -v[e,f]"  , __FILE__, bopnews, g);
 }
 
@@ -139,11 +134,12 @@ Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
   aLC.Append(aS1);
   aLC.Append(aS2);
   //
-  if (!pPF) {
+  if (pPF!=NULL) {
     delete pPF;
-    Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
-    pPF=new BOPAlgo_PaveFiller(aAL);
+    pPF=NULL;
   }
+  Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
+  pPF=new BOPAlgo_PaveFiller(aAL);
   //
   pPF->SetArguments(aLC);
   //
@@ -324,19 +320,11 @@ Standard_Integer  bsection(Draw_Interpretor& di,
     const char* key2 = (n > 5) ? a[5] : NULL;
     const char* pcurveconf = NULL;
 
-#ifdef WNT
     if (key1 && (!strcasecmp(key1,"-n2d") || !strcasecmp(key1,"-n2d1") || !strcasecmp(key1,"-n2d2"))) {
-#else 
-    if (key1 && (!strncasecmp(key1,"-n2d", 4) || !strncasecmp(key1,"-n2d1", 5) || !strncasecmp(key1,"-n2d2", 5))) {
-#endif
       pcurveconf = key1;
     }
     else {
-#ifdef WNT
       if (!strcasecmp(key1,"-na")) {
-#else 
-      if(!strncasecmp(key1,"-na", 3)) {
-#endif
         bApp = Standard_False;
       }
       else {
@@ -344,11 +332,7 @@ Standard_Integer  bsection(Draw_Interpretor& di,
       }
     }
     if (key2) {
-#ifdef WNT
       if(!strcasecmp(key2,"-na")) {
-#else 
-      if (!strncasecmp(key2,"-na", 3)) {
-#endif
         bApp = Standard_False;
       }
       else {
@@ -357,27 +341,15 @@ Standard_Integer  bsection(Draw_Interpretor& di,
     }
 
     if(!isbadparameter && pcurveconf) {      
-#ifdef WNT
       if (!strcasecmp(pcurveconf, "-n2d1")) {
-#else 
-      if (!strncasecmp(pcurveconf, "-n2d1", 5)) {
-#endif
         bPC1 = Standard_False;
       }
       else {
-#ifdef WNT
         if (!strcasecmp(pcurveconf, "-n2d2")) {
-#else 
-        if (!strncasecmp(pcurveconf, "-n2d2", 5)) {
-#endif
           bPC2 = Standard_False;
         }
         else {
-#ifdef WNT
           if (!strcasecmp(pcurveconf, "-n2d")) {
-#else 
-          if (!strncasecmp(pcurveconf, "-n2d", 4)) {
-#endif
             bPC1 = Standard_False;
             bPC2 = Standard_False;
           }
@@ -415,7 +387,6 @@ Standard_Integer  bsection(Draw_Interpretor& di,
     di << usage;
     return 1;
   }
-  return 0;
 }
 //=======================================================================
 //function : bsmt
@@ -570,7 +541,7 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
                             const char** a)
 {
   if (n<3) {
-    di << " use bopcurves F1 F2\n";
+    di << " use bopcurves F1 F2 [-2d]\n";
     return 1;
   }
 
@@ -598,14 +569,25 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
   const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
   const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
 
-  Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
+  Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone, bMake2dCurves;
   Standard_Integer i, aNbCurves;
   Standard_Real anAppTol, aTolR;
   TCollection_AsciiString aNm("c_");
 
-  aToApproxC3d=Standard_True;
-  aToApproxC2dOnS1=Standard_False;
-  aToApproxC2dOnS2=Standard_False;
+  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";
+      return 1;
+    }
+  }
+  //
+
+  aToApproxC3d = Standard_True;
+  aToApproxC2dOnS1 = bMake2dCurves;
+  aToApproxC2dOnS2 = bMake2dCurves;
   anAppTol=0.0000001;
 
 
@@ -624,7 +606,7 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
     return 1;
   }
 
-  aFF.PrepareLines3D();
+  aFF.PrepareLines3D(Standard_False);
   const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
 
   //
@@ -636,22 +618,68 @@ Standard_Integer bopcurves (Draw_Interpretor& di,
     di << " has no 3d curve\n";
     return 1;
   }
+  else
+  {
+    di << aNbCurves << " curve(s) found.\n";
+  }
 
   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 << "%d\n";
+      di << " has Null 3d curve# " << i << "\n";
       continue;
     }
 
     TCollection_AsciiString anIndx(i), aNmx;
-    aNmx=aNm+anIndx;
-    Standard_CString name= aNmx.ToCString();
-    DrawTrSurf::Set(name, aC3D);
-    di << name << " ";
+    aNmx = aNm + anIndx;
+
+    Standard_CString nameC = aNmx.ToCString();
+
+    DrawTrSurf::Set(nameC, aC3D);
+    di << nameC << " ";
+    //
+    if (bMake2dCurves) {
+      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();
+        //
+        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();
+        //
+        DrawTrSurf::Set(nameC2d1, aPC1);
+        di << "(" << nameC2d1;
+      }
+      //
+      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 << ") ";
+      }
+    }
   }
 
   di << "\n";