Update source code
[occt.git] / src / QABugs / QABugs_19.cxx
old mode 100644 (file)
new mode 100755 (executable)
index b11142a..fa6efb0
@@ -47,7 +47,7 @@
 #include <BRepPrimAPI_MakeSphere.hxx>
 #include <BRepAlgo_Cut.hxx>
 
-//static Standard_Integer OCC230 (Draw_Interpretor& /*di*/, Standard_Integer /*argc*/, const char ** /*argv*/)
+
 static Standard_Integer OCC230 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
 {
   if ( argc != 4) {
@@ -148,13 +148,504 @@ static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*
   return 0;
 }
 
+#ifdef HAVE_TBB
+
+#include <Standard_Atomic.hxx>
+#include <tbb/blocked_range.h>
+#include <tbb/parallel_for.h>
+
+class IncrementerDecrementer
+{
+public:
+    IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive)
+    {}
+    void operator() (const tbb::blocked_range<size_t>& r) const
+    {
+        if (myPositive)
+            for (size_t i = r.begin(); i != r.end(); ++i)
+                Standard_Atomic_Increment (myVal);
+        else
+            for (size_t i = r.begin(); i != r.end(); ++i)
+                Standard_Atomic_Decrement (myVal);
+    }
+private:
+    Standard_Integer*   myVal;
+    Standard_Boolean   myPositive;
+};
+#endif
+
+#define QCOMPARE(val1, val2) \
+  di << "Checking " #val1 " == " #val2 << \
+        ((val1) == (val2) ? ": OK\n" : ": Error\n")
+
+#ifdef HAVE_TBB
+static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
+{
+  int aSum = 0;
+
+  //check returned value
+  QCOMPARE (Standard_Atomic_Decrement (&aSum), -1);
+  QCOMPARE (Standard_Atomic_Increment (&aSum), 0);
+  QCOMPARE (Standard_Atomic_Increment (&aSum), 1);
+  QCOMPARE (Standard_Atomic_Increment (&aSum), 2);
+//  QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 0);
+//  QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 1);
+
+  //check atomicity 
+  aSum = 0;
+  const int N = 1 << 24; //big enough to ensure concurrency
+
+  //increment
+  tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, true));
+  QCOMPARE (aSum, N);
+
+  //decrement
+  tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, false));
+  QCOMPARE (aSum, 0);
+
+  return 0;
+}
+
+#else /* HAVE_TBB */
+
+static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv)
+{
+  di << "Test skipped: command " << argv[0] << " requires TBB library\n";
+  return 0;
+}
+
+#endif /* HAVE_TBB */
+
+#include <TDocStd_Application.hxx>
+#include <XCAFApp_Application.hxx>
+#include <TDocStd_Document.hxx>
+#include <XCAFDoc_ShapeTool.hxx>
+#include <XCAFDoc_DocumentTool.hxx>
+#include <TDF_Label.hxx>
+#include <TDataStd_Name.hxx>
+
+static Standard_Integer OCC23595 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv)
+{
+  const Handle(TDocStd_Application)& anApp = XCAFApp_Application::GetApplication();
+  Handle(TDocStd_Document) aDoc;
+  anApp->NewDocument ("XmlXCAF", aDoc);
+  QCOMPARE (!aDoc.IsNull(), Standard_True);
+
+  Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
+
+  //check default value
+  Standard_Boolean aValue = XCAFDoc_ShapeTool::AutoNaming();
+  QCOMPARE (aValue, Standard_True);
+
+  //true
+  XCAFDoc_ShapeTool::SetAutoNaming (Standard_True);
+  TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100., 200., 300.).Shape();
+  TDF_Label aLabel = aShTool->AddShape (aShape);
+  Handle(TDataStd_Name) anAttr;
+  QCOMPARE (aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
+
+  //false
+  XCAFDoc_ShapeTool::SetAutoNaming (Standard_False);
+  aShape = BRepPrimAPI_MakeBox (300., 200., 100.).Shape();
+  aLabel = aShTool->AddShape (aShape);
+  QCOMPARE (!aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
+
+  //restore
+  XCAFDoc_ShapeTool::SetAutoNaming (aValue);
+
+  return 0;
+}
+
+#include <ExprIntrp_GenExp.hxx>
+Standard_Integer OCC22611 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+
+  if (argc != 3) {
+    di << "Usage : " << argv[0] << " string nb\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aToken = argv[1];
+  Standard_Integer aNb = atoi(argv[2]);
+
+  Handle(ExprIntrp_GenExp) aGen = ExprIntrp_GenExp::Create();
+  for (Standard_Integer i=0; i < aNb; i++)
+  {
+    aGen->Process(aToken);
+    Handle(Expr_GeneralExpression) aExpr = aGen->Expression();
+  }
+
+  return 0;
+}
+
+Standard_Integer OCC22595 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+  gp_Mat M0;
+  di << "M0 = "
+  << " {" << M0(1,1) << "} {" << M0(1,2) << "} {" << M0(1,3) <<"}"
+  << " {" << M0(2,1) << "} {" << M0(2,2) << "} {" << M0(2,3) <<"}"
+  << " {" << M0(1,1) << "} {" << M0(1,2) << "} {" << M0(1,3) <<"}";
+  return 0;
+}
+
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
+#include <BRepExtrema_DistShapeShape.hxx>
+#include <BRepTools.hxx>
+
+Standard_Boolean static OCC23774Test(const TopoDS_Face& grossPlateFace, const TopoDS_Shape& originalWire, Draw_Interpretor& di)
+{
+  BRepExtrema_DistShapeShape distShapeShape(grossPlateFace,originalWire,Extrema_ExtFlag_MIN);
+  if(!distShapeShape.IsDone()) {
+    di <<"Distance ShapeShape is Not Done\n";
+    return Standard_False;
+  }
+
+  if(distShapeShape.Value() > 0.01) {
+    di << "Wrong Dist = " <<distShapeShape.Value() << "\n";
+    return Standard_False;
+  } else
+    di << "Dist0 = " <<distShapeShape.Value() <<"\n";
+
+  //////////////////////////////////////////////////////////////////////////
+  /// First Flip Y
+  const gp_Pnt2d axis1P1(1474.8199035519228,1249.9995745636970);
+  const gp_Pnt2d axis1P2(1474.8199035519228,1250.9995745636970);
+
+  gp_Vec2d mirrorVector1(axis1P1,axis1P2);
+
+  gp_Trsf2d mirror1;
+  mirror1.SetMirror(gp_Ax2d(axis1P1,mirrorVector1));
+
+  BRepBuilderAPI_Transform transformer1(mirror1);
+  transformer1.Perform(originalWire);
+  if(!transformer1.IsDone()) {
+    di << "Not Done1 " << "\n";
+    return Standard_False;
+  }
+  const TopoDS_Shape& step1ModifiedShape = transformer1.ModifiedShape(originalWire);
+  
+  BRepExtrema_DistShapeShape distShapeShape1(grossPlateFace,step1ModifiedShape,Extrema_ExtFlag_MIN);
+  if(!distShapeShape1.IsDone())
+    return Standard_False;
+  if(distShapeShape1.Value() > 0.01) {
+    di << "Dist = " <<distShapeShape1.Value() <<"\n";
+    return Standard_False;
+  } else
+    di << "Dist1 = " <<distShapeShape1.Value() <<"\n";
+
+  //////////////////////////////////////////////////////////////////////////
+  /// Second flip Y
+  transformer1.Perform(step1ModifiedShape);
+  if(!transformer1.IsDone()) {
+    di << "Not Done1 \n";
+    return Standard_False;
+  }
+  const TopoDS_Shape& step2ModifiedShape = transformer1.ModifiedShape(step1ModifiedShape);
+
+  //This is identity matrix for values but for type is gp_Rotation ?!
+  gp_Trsf2d mirror11 = mirror1;
+  mirror11.PreMultiply(mirror1);
+
+  BRepExtrema_DistShapeShape distShapeShape2(grossPlateFace,step2ModifiedShape);//,Extrema_ExtFlag_MIN);
+  if(!distShapeShape2.IsDone())
+    return Standard_False;
+
+  //This last test case give error (the value is 1008.8822038689706)
+  if(distShapeShape2.Value() > 0.01) {
+    di  << "Wrong Dist2 = " <<distShapeShape2.Value() <<"\n";
+    Standard_Integer N = distShapeShape2.NbSolution();
+    di << "Nb = " <<N <<"\n";
+    for (Standard_Integer i=1;i <= N;i++)
+        di <<"Sol(" <<i<<") = " <<distShapeShape2.PointOnShape1(i).Distance(distShapeShape2.PointOnShape2(i)) <<"\n";
+    return Standard_False;
+  }
+  di << "Distance2 = " <<distShapeShape2.Value() <<"\n";
+  return Standard_True;
+}
+static Standard_Integer OCC23774(Draw_Interpretor& di, Standard_Integer n, const char** a)
+{ 
+
+  if (n != 3) {
+       di <<"OCC23774: invalid number of input parameters\n";
+       return 1;
+  }
+
+  const char *ns1 = (a[1]), *ns2 = (a[2]);
+  TopoDS_Shape S1(DBRep::Get(ns1)), S2(DBRep::Get(ns2));
+  if (S1.IsNull() || S2.IsNull()) {
+       di <<"OCC23774: Null input shapes\n";
+       return 1;
+  }
+  const TopoDS_Face& aFace  = TopoDS::Face(S1);
+  if(!OCC23774Test(aFace, S2, di))
+       di << "Something is wrong\n";
+
+ return 0;
+}
+
+#include <GeomConvert_ApproxSurface.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Draw.hxx>
+#include <OSD_Thread.hxx>
+static void GeomConvertTest (Draw_Interpretor& di, Standard_Integer theTargetNbUPoles, Standard_CString theFileName)
+{
+       Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(theFileName);
+       GeomConvert_ApproxSurface aGAS (aSurf, 1e-4, GeomAbs_C1, GeomAbs_C1, 9, 9, 100, 1);
+       if (!aGAS.IsDone()) {
+               di << "ApproxSurface is not done!" << "\n";
+               return;
+       }
+       const Handle(Geom_BSplineSurface)& aBSurf = aGAS.Surface();
+       if (aBSurf.IsNull()) {
+               di << "BSplineSurface is not created!" << "\n";
+               return;
+       }
+       di << "Number of UPoles:" << aBSurf->NbUPoles() << "\n";
+       QCOMPARE (aBSurf->NbUPoles(), theTargetNbUPoles);
+}
+
+struct aData {
+       Draw_Interpretor* di;
+       Standard_Integer nbupoles;
+       Standard_CString filename;
+};
+
+Standard_EXPORT Standard_Address convert(Standard_Address data)
+{
+       aData* info = (aData*) data;
+       GeomConvertTest(*(info->di),info->nbupoles,info->filename);
+       return NULL;
+}
+
+static Standard_Integer OCC23952sweep (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+       if (argc != 3) {
+               di << "Usage: " << argv[0] << " invalid number of arguments" << "\n";
+               return 1;
+       }
+       struct aData aStorage;
+       aStorage.di = &di;
+       aStorage.nbupoles = Draw::Atoi(argv[1]); 
+       aStorage.filename = argv[2];
+
+       OSD_Thread aThread1(convert);
+       aThread1.Run(&aStorage);
+       GeomConvertTest(di,aStorage.nbupoles,aStorage.filename);
+
+       return 0;
+}
+
+#include <GeomInt_IntSS.hxx>
+static void GeomIntSSTest (Draw_Interpretor& di, Standard_Integer theNbSol, Standard_CString theFileName1, Standard_CString theFileName2)
+{
+       Handle(Geom_Surface) aSurf1 = DrawTrSurf::GetSurface(theFileName1);
+       Handle(Geom_Surface) aSurf2 = DrawTrSurf::GetSurface(theFileName2);
+       GeomInt_IntSS anInter;
+       anInter.Perform(aSurf1, aSurf2, Precision::Confusion(), Standard_True);
+       if (!anInter.IsDone()) {
+               di << "An intersection is not done!" << "\n";
+               return;
+       }
+
+       di << "Number of Lines:" << anInter.NbLines() << "\n";
+       QCOMPARE (anInter.NbLines(), theNbSol);
+}
+
+struct aNewData {
+       Draw_Interpretor* di;
+       Standard_Integer nbsol;
+       Standard_CString filename1;
+       Standard_CString filename2;
+};
+Standard_EXPORT Standard_Address convert_inter(Standard_Address data)
+{
+       aNewData* info = (aNewData*) data;
+       GeomIntSSTest(*(info->di),info->nbsol,info->filename1,info->filename2);
+       return NULL;
+}
+
+static Standard_Integer OCC23952intersect (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+       if (argc != 4) {
+               di << "Usage: " << argv[0] << " invalid number of arguments" << "\n";
+               return 1;
+       }
+       struct aNewData aStorage;
+       aStorage.di = &di;
+       aStorage.nbsol = Draw::Atoi(argv[1]); 
+       aStorage.filename1 = argv[2];
+       aStorage.filename2 = argv[3];
+
+       OSD_Thread aThread1(convert_inter);
+       aThread1.Run(&aStorage);
+       GeomIntSSTest(di,aStorage.nbsol,aStorage.filename1,aStorage.filename2);
+
+       return 0;
+}
+
+#include <Geom_SurfaceOfRevolution.hxx> 
+static Standard_Integer OCC23683 (Draw_Interpretor& di, Standard_Integer argc,const char ** argv)
+{
+  if (argc < 2) {
+    di<<"Usage: " << argv[0] << " invalid number of arguments"<<"\n";
+    return 1;
+  }
+
+  Standard_Integer ucontinuity = 1;
+  Standard_Integer vcontinuity = 1;
+  Standard_Boolean iscnu = false;
+  Standard_Boolean iscnv = false;
+  
+  Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(argv[1]);
+
+  QCOMPARE (aSurf->IsCNu (ucontinuity), iscnu);
+  QCOMPARE (aSurf->IsCNv (vcontinuity), iscnv);
+
+  return 0;
+}
+
+#include <gp_Ax1.hxx>
+#include <gp_Ax22d.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom2d_Circle.hxx>
+#include <Geom2d_TrimmedCurve.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepPrimAPI_MakeRevol.hxx>
+#include <Geom2d_OffsetCurve.hxx>
+
+static int test_offset(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+  // Check the command arguments
+  if ( argc != 1 )
+  {
+    di << "Error: " << argv[0] << " - invalid number of arguments" << "\n";
+    di << "Usage: type help " << argv[0] << "\n";
+    return 1; // TCL_ERROR
+  }
+
+  gp_Ax1 RotoAx( gp::Origin(), gp::DZ() );
+  gp_Ax22d Ax2( gp::Origin2d(), gp::DY2d(), gp::DX2d() );
+  Handle(Geom_Surface) Plane = new Geom_Plane( gp::YOZ() );
+
+  di << "<<<< Preparing sample surface of revolution based on trimmed curve >>>>" << "\n";
+  di << "-----------------------------------------------------------------------" << "\n";
+
+  Handle(Geom2d_Circle) C2d1 = new Geom2d_Circle(Ax2, 1.0);
+  Handle(Geom2d_TrimmedCurve) C2d1Trimmed = new Geom2d_TrimmedCurve(C2d1, 0.0, M_PI/2.0);
+  TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(C2d1Trimmed, Plane);
+
+  DBRep::Set("e1", E1);
+
+  BRepPrimAPI_MakeRevol aRevolBuilder1(E1, RotoAx);
+  TopoDS_Face F1 = TopoDS::Face( aRevolBuilder1.Shape() );
+
+  DBRep::Set("f1", F1);
+
+  di << "Result: f1" << "\n";
+
+  di << "<<<< Preparing sample surface of revolution based on offset curve  >>>>" << "\n";
+  di << "-----------------------------------------------------------------------" << "\n";
+
+  Handle(Geom2d_OffsetCurve) C2d2Offset = new Geom2d_OffsetCurve(C2d1Trimmed, -0.5);
+  TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(C2d2Offset, Plane);
+
+  DBRep::Set("e2", E2);
+
+  BRepPrimAPI_MakeRevol aRevolBuilder2(E2, RotoAx);
+  TopoDS_Face F2 = TopoDS::Face( aRevolBuilder2.Shape() );
+
+  DBRep::Set("f2", F2);
+
+  di << "Result: f2" << "\n";
+
+  return 0;
+}
+
+#include <GeomAdaptor_Surface.hxx>
+#include <Draw.hxx>
+//=======================================================================
+//function : OCC23945
+//purpose  : 
+//=======================================================================
+
+static Standard_Integer OCC23945 (Draw_Interpretor& di,Standard_Integer n, const char** a)
+{
+  if (n < 5) return 1;
+
+  Handle(Geom_Surface) aS = DrawTrSurf::GetSurface(a[1]);
+  if (aS.IsNull()) return 1;
+
+  GeomAdaptor_Surface GS(aS);
+
+  Standard_Real U = Draw::Atof(a[2]);
+  Standard_Real V = Draw::Atof(a[3]);
+
+  Standard_Boolean DrawPoint = ( n%3 == 2);
+  if ( DrawPoint) n--;
+
+  gp_Pnt P;
+  if (n >= 13) {
+    gp_Vec DU,DV;
+    if (n >= 22) {
+      gp_Vec D2U,D2V,D2UV;
+      GS.D2(U,V,P,DU,DV,D2U,D2V,D2UV);
+      Draw::Set(a[13],D2U.X());
+      Draw::Set(a[14],D2U.Y());
+      Draw::Set(a[15],D2U.Z());
+      Draw::Set(a[16],D2V.X());
+      Draw::Set(a[17],D2V.Y());
+      Draw::Set(a[18],D2V.Z());
+      Draw::Set(a[19],D2UV.X());
+      Draw::Set(a[20],D2UV.Y());
+      Draw::Set(a[21],D2UV.Z());
+    }
+    else
+      GS.D1(U,V,P,DU,DV);
+
+    Draw::Set(a[7],DU.X());
+    Draw::Set(a[8],DU.Y());
+    Draw::Set(a[9],DU.Z());
+    Draw::Set(a[10],DV.X());
+    Draw::Set(a[11],DV.Y());
+    Draw::Set(a[12],DV.Z());
+  }
+  else 
+    GS.D0(U,V,P);
+
+  if ( n > 6) {
+    Draw::Set(a[4],P.X());
+    Draw::Set(a[5],P.Y());
+    Draw::Set(a[6],P.Z());
+  }
+  if ( DrawPoint) {
+    DrawTrSurf::Set(a[n],P);
+  }
+
+  return 0;
+}
+
 void QABugs::Commands_19(Draw_Interpretor& theCommands) {
-  char *group = "QABugs";
+  const char *group = "QABugs";
 
   theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group);
   theCommands.Add ("OCC142", "OCC142", __FILE__, OCC142, group);
   theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group);
-  theCommands.Add("OCC23237", "OCC23237", __FILE__, OCC23237, group); 
-
+  theCommands.Add ("OCC23237", "OCC23237", __FILE__, OCC23237, group); 
+  theCommands.Add ("OCC22980", "OCC22980", __FILE__, OCC22980, group);
+  theCommands.Add ("OCC23595", "OCC23595", __FILE__, OCC23595, group);
+  theCommands.Add ("OCC22611", "OCC22611 string nb", __FILE__, OCC22611, group);
+  theCommands.Add ("OCC22595", "OCC22595", __FILE__, OCC22595, group);
+  theCommands.Add ("OCC23774", "OCC23774 shape1 shape2", __FILE__, OCC23774, group);
+  theCommands.Add ("OCC23683", "OCC23683 shape", __FILE__, OCC23683, group);
+  theCommands.Add ("OCC23952sweep", "OCC23952sweep nbupoles shape", __FILE__, OCC23952sweep, group);
+  theCommands.Add ("OCC23952intersect", "OCC23952intersect nbsol shape1 shape2", __FILE__, OCC23952intersect, group);
+  theCommands.Add ("test_offset", "test_offset", __FILE__, test_offset, group);
+  theCommands.Add("OCC23945", "OCC23945 surfname U V X Y Z [DUX DUY DUZ DVX DVY DVZ [D2UX D2UY D2UZ D2VX D2VY D2VZ D2UVX D2UVY D2UVZ]]", __FILE__, OCC23945,group);
   return;
 }
+
+