0029412: Huge Memory leak since I upgraded to OC 6.9.0
[occt.git] / src / QABugs / QABugs_19.cxx
index f432d89..88ad638 100644 (file)
@@ -17,8 +17,8 @@
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_LocalContext.hxx>
-#include <AIS_TexturedShape.hxx>
-#include <BRepAlgo_Cut.hxx>
+#include <AIS_Shape.hxx>
+#include <BRepAlgoAPI_Cut.hxx>
 #include <BRepOffsetAPI_MakePipe.hxx>
 #include <BRepPrimAPI_MakeBox.hxx>
 #include <BRepPrimAPI_MakeSphere.hxx>
@@ -53,6 +53,8 @@
 #include <ViewerTest.hxx>
 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
 #include <XmlDrivers_DocumentStorageDriver.hxx>
+#include <TDataStd_Real.hxx>
+#include <Standard_Atomic.hxx>
 
 #include <cstdio>
 #include <cmath>
@@ -125,7 +127,7 @@ static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*
     // do some operation that will take considerable time compared with time of starting / stopping timers
     BRepPrimAPI_MakeBox aBox (10., 10., 10.);
     BRepPrimAPI_MakeSphere aSphere (10.);
-    BRepAlgo_Cut aCutter (aBox.Shape(), aSphere.Shape());
+    BRepAlgoAPI_Cut aCutter (aBox.Shape(), aSphere.Shape());
 
     aTM.Stop();
     aPM.Stop();
@@ -1285,8 +1287,8 @@ static Standard_Integer OCC24012 (Draw_Interpretor& di, Standard_Integer argc, c
     {
         TopoDS_Shape rshape = anormpro.Projection();
                Handle(AIS_InteractiveObject) myShape = new AIS_Shape (rshape);
-               myAISContext->SetColor(myShape, Quantity_Color(Quantity_NOC_YELLOW));
-               myAISContext->Display(myShape, Standard_True);
+               myAISContext->SetColor (myShape, Quantity_Color(Quantity_NOC_YELLOW), Standard_False);
+               myAISContext->Display (myShape, Standard_True);
     }
 
        return 0;
@@ -1774,6 +1776,7 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c
   TDataStd_Name::Set(labelA0, "ASSEMBLY");
 
   TDF_Label component01 = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->AddComponent (labelA0, lab1, location0);
+  XCAFDoc_DocumentTool::ShapeTool (aDoc->Main ())->UpdateAssemblies();
 
   Quantity_Color yellow(1,1,0, Quantity_TOC_RGB);
   XCAFDoc_DocumentTool::ColorTool (labelA0)->SetColor (component01, yellow, XCAFDoc_ColorGen);
@@ -1791,65 +1794,6 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c
   return 0;
 }
 
-//=======================================================================
-//function : OCC24622
-//purpose  : The command tests sourcing Image_PixMap to AIS_TexturedShape
-//=======================================================================
-static Standard_Integer OCC24622 (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNb, const char** theArgVec)
-{
-  if (theArgNb != 2)
-  {
-    std::cout << "Usage : " << theArgVec[0] << " texture={1D|2D}";
-    return 1;
-  }
-
-  const Handle(AIS_InteractiveContext)& anAISContext = ViewerTest::GetAISContext();
-  if (anAISContext.IsNull())
-  {
-    std::cout << "Please initialize view with \"vinit\".\n";
-    return 1;
-  }
-
-  Handle(Image_PixMap) anImage = new Image_PixMap();
-
-  static const Image_ColorRGB aBitmap[8] =
-  {
-    {{255,   0, 0}}, {{0,  148, 255}}, {{ 0, 148, 255}}, {{255,  94, 0}},
-    {{255, 121, 0}}, {{76, 255,   0}}, {{76, 255,   0}}, {{255, 202, 0}}
-  };
-
-  TCollection_AsciiString aTextureTypeArg (theArgVec[1]);
-  aTextureTypeArg.UpperCase();
-  if (aTextureTypeArg == "1D")
-  {
-    anImage->InitWrapper (Image_PixMap::ImgRGB, (Standard_Byte*)aBitmap, 8, 1);
-  }
-  else if (aTextureTypeArg == "2D")
-  {
-    anImage->InitTrash (Image_PixMap::ImgRGB, 8, 8);
-    for (Standard_Integer aRow = 0; aRow < 8; ++aRow)
-    {
-      for (Standard_Integer aCol = 0; aCol < 8; ++aCol)
-      {
-        anImage->ChangeValue<Image_ColorRGB> (aRow, aCol) = aBitmap[aRow];
-      }
-    }
-  }
-  else
-  {
-    std::cout << "Please specify type of texture to test {1D|2D}.\n";
-    return 1;
-  }
-
-  TopoDS_Shape aBlankShape = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
-
-  Handle(AIS_TexturedShape) aTexturedShape = new AIS_TexturedShape (aBlankShape);
-  aTexturedShape->SetTexturePixMap (anImage);
-  anAISContext->Display (aTexturedShape, 3, 0);
-
-  return 0;
-}
-
 //=======================================================================
 //function : OCC24667
 //purpose  : 
@@ -1982,15 +1926,22 @@ static Standard_Integer OCC24755 (Draw_Interpretor& di, Standard_Integer n, cons
   Handle(TDocStd_Document) aDoc;
   anApp->NewDocument ("BinOcaf", aDoc);
   TDF_Label aLab = aDoc->Main();
+  // Prepend an int value.
   TDataStd_Integer::Set (aLab, 0);
+  // Prepend a name.
   TDataStd_Name::Set (aLab, "test");
+  // Append a double value.
+  aLab.AddAttribute(new TDataStd_Real(), true/*append*/);
 
   TDF_AttributeIterator i (aLab);
   Handle(TDF_Attribute) anAttr = i.Value();
+  QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True);
+  i.Next();
+  anAttr = i.Value();
   QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Integer)), Standard_True);
   i.Next();
   anAttr = i.Value();
-  QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True);
+  QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Real)), Standard_True);
 
   return 0;
 }
@@ -2386,8 +2337,8 @@ static Standard_Integer OCC25043 (Draw_Interpretor& theDI,
     for (; anCheckIter.More(); anCheckIter.Next())
     {
       const BOPAlgo_CheckResult& aCurCheckRes = anCheckIter.Value();
-      const BOPCol_ListOfShape& aCurFaultyShapes = aCurCheckRes.GetFaultyShapes1();
-      BOPCol_ListIteratorOfListOfShape aFaultyIter(aCurFaultyShapes);
+      const TopTools_ListOfShape& aCurFaultyShapes = aCurCheckRes.GetFaultyShapes1();
+      TopTools_ListIteratorOfListOfShape aFaultyIter(aCurFaultyShapes);
       for (; aFaultyIter.More(); aFaultyIter.Next())
       {
         const TopoDS_Shape& aFaultyShape = aFaultyIter.Value();
@@ -2765,10 +2716,8 @@ static Standard_Integer OCC25413 (Draw_Interpretor& di, Standard_Integer narg ,
 #include <BRepAlgoAPI_Cut.hxx>
 #include <BRepAlgoAPI_Section.hxx>
 //
-#include <BOPTools.hxx>
-//
-#include <BOPCol_MapOfShape.hxx>
-#include <BOPCol_ListOfShape.hxx>
+#include <TopExp.hxx>
+#include <TopTools_MapOfShape.hxx>
 //=======================================================================
 //function : OCC25446
 //purpose  :
@@ -2805,7 +2754,7 @@ static Standard_Integer OCC25446 (Draw_Interpretor& theDI,
   aOp = (BOPAlgo_Operation)iOp;
   //
   Standard_Integer iErr;
-  BOPCol_ListOfShape aLS;
+  TopTools_ListOfShape aLS;
   BOPAlgo_PaveFiller aPF;
   //
   aLS.Append(aS1);
@@ -2813,7 +2762,7 @@ static Standard_Integer OCC25446 (Draw_Interpretor& theDI,
   aPF.SetArguments(aLS);
   //
   aPF.Perform();
-  iErr = aPF.ErrorStatus();
+  iErr = aPF.HasErrors();
   if (iErr) {
     theDI << "Intersection failed with error status: " << iErr << "\n";
     return 1;
@@ -2841,7 +2790,7 @@ static Standard_Integer OCC25446 (Draw_Interpretor& theDI,
     break;
   }
   //
-  iErr = pBuilder->ErrorStatus();
+  iErr = pBuilder->HasErrors();
   if (!pBuilder->IsDone()) {
     theDI << "BOP failed with error status: " << iErr << "\n";
     return 1;
@@ -2850,14 +2799,14 @@ static Standard_Integer OCC25446 (Draw_Interpretor& theDI,
   const TopoDS_Shape& aRes = pBuilder->Shape();
   DBRep::Set(argv[1], aRes);
   //
-  BOPCol_MapOfShape aMapArgs, aMapShape;
-  BOPCol_MapIteratorOfMapOfShape aIt;
+  TopTools_MapOfShape aMapArgs, aMapShape;
+  TopTools_MapIteratorOfMapOfShape aIt;
   Standard_Boolean bIsDeletedHist, bIsDeletedMap;
   TopAbs_ShapeEnum aType;
   //
-  BOPTools::MapShapes(aS1, aMapArgs);
-  BOPTools::MapShapes(aS2, aMapArgs);
-  BOPTools::MapShapes(aRes, aMapShape);
+  TopExp::MapShapes(aS1, aMapArgs);
+  TopExp::MapShapes(aS2, aMapArgs);
+  TopExp::MapShapes(aRes, aMapShape);
   //
   aIt.Initialize(aMapArgs);
   for (; aIt.More(); aIt.Next()) {
@@ -2914,19 +2863,19 @@ struct OCC25545_Functor
 //function : OCC25545
 //purpose  : Tests data race when concurrently accessing TopLoc_Location::Transformation()
 //=======================================================================
-#ifdef HAVE_TBB
+
 static Standard_Integer OCC25545 (Draw_Interpretor& di, 
                                   Standard_Integer, 
                                   const char **)
 {
   // Place vertices in a vector, giving the i-th vertex the
   // transformation that translates it on the vector (i,0,0) from the origin.
-  size_t n = 1000;
+  Standard_Integer n = 1000;
   std::vector<TopoDS_Shape> aShapeVec (n);
   std::vector<TopLoc_Location> aLocVec (n);
   TopoDS_Shape aShape = BRepBuilderAPI_MakeVertex (gp::Origin ());
   aShapeVec[0] = aShape;
-  for (size_t i = 1; i < n; ++i) {
+  for (Standard_Integer i = 1; i < n; ++i) {
     gp_Trsf aT;
     aT.SetTranslation (gp_Vec (1, 0, 0));
     aLocVec[i] = aLocVec[i - 1] * aT;
@@ -2937,20 +2886,12 @@ static Standard_Integer OCC25545 (Draw_Interpretor& di,
   // concurrently
   OCC25545_Functor aFunc(aShapeVec);
 
-  //concurrently process
-  tbb::parallel_for (size_t (0), n, aFunc, tbb::simple_partitioner ());
+  // concurrently process
+  OSD_Parallel::For (0, n, aFunc);
+
   QVERIFY (!aFunc.myIsRaceDetected);
   return 0;
 }
-#else
-static Standard_Integer OCC25545 (Draw_Interpretor&, 
-                                  Standard_Integer, 
-                                  const char **argv)
-{
-  cout << "Test skipped: command " << argv[0] << " requires TBB library" << endl;
-  return 0;
-}
-#endif
 
 //=======================================================================
 //function : OCC25547
@@ -3304,7 +3245,7 @@ static Standard_Integer OCC26172 (Draw_Interpretor& theDI, Standard_Integer theA
   BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
   Handle(AIS_Shape) aTestAISShape = new AIS_Shape (anEdge);
-  anAISContext->Display (aTestAISShape);
+  anAISContext->Display (aTestAISShape, Standard_True);
 
   // 2. activate it in selection modes
   TColStd_SequenceOfInteger aModes;
@@ -3398,16 +3339,17 @@ static Standard_Integer OCC26284 (Draw_Interpretor& theDI, Standard_Integer theA
 
   BRepPrimAPI_MakeSphere aSphereBuilder (gp_Pnt (0.0, 0.0, 0.0), 1.0);
   Handle(AIS_Shape) aSphere = new AIS_Shape (aSphereBuilder.Shape());
-  anAISContext->Display (aSphere);
+  anAISContext->Display (aSphere, Standard_False);
   for (Standard_Integer aChildIdx = 0; aChildIdx < 5; ++aChildIdx)
   {
     BRepPrimAPI_MakeSphere aBuilder (gp_Pnt (1.0 + aChildIdx, 1.0 + aChildIdx, 1.0 + aChildIdx), 1.0);
     Handle(AIS_Shape) aChild = new AIS_Shape (aBuilder.Shape());
     aSphere->AddChild (aChild);
-    anAISContext->Display (aChild);
+    anAISContext->Display (aChild, Standard_False);
   }
 
   anAISContext->RecomputeSelectionOnly (aSphere);
+  anAISContext->UpdateCurrentViewer();
 
   return 0;
 }
@@ -4170,16 +4112,16 @@ static Standard_Integer OCC26462 (Draw_Interpretor& theDI, Standard_Integer /*th
   Handle(AIS_InteractiveObject) aBox2 = new AIS_Shape (aBuilder2.Shape());
 
   const Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
-  aCtx->Display (aBox1, 0, 2);
-  aCtx->Display (aBox2, 0, 2);
+  aCtx->Display (aBox1, 0, 2, Standard_False);
+  aCtx->Display (aBox2, 0, 2, Standard_False);
   ViewerTest::CurrentView()->FitAll();
-  aCtx->SetWidth (aBox1, 3);
-  aCtx->SetWidth (aBox2, 3);
+  aCtx->SetWidth (aBox1, 3, Standard_False);
+  aCtx->SetWidth (aBox2, 3, Standard_False);
 
-  aCtx->MoveTo (305, 322, ViewerTest::CurrentView());
-  aCtx->ShiftSelect();
-  aCtx->MoveTo (103, 322, ViewerTest::CurrentView());
-  aCtx->ShiftSelect();
+  aCtx->MoveTo (305, 322, ViewerTest::CurrentView(), Standard_False);
+  aCtx->ShiftSelect (Standard_False);
+  aCtx->MoveTo (103, 322, ViewerTest::CurrentView(), Standard_False);
+  aCtx->ShiftSelect (Standard_False);
   if (aCtx->NbSelected() != 0)
   {
     theDI << "ERROR: no boxes must be selected!\n";
@@ -4188,15 +4130,15 @@ static Standard_Integer OCC26462 (Draw_Interpretor& theDI, Standard_Integer /*th
 
   aCtx->SetSelectionSensitivity (aBox1, 2, 5);
 
-  aCtx->MoveTo (305, 322, ViewerTest::CurrentView());
-  aCtx->ShiftSelect();
+  aCtx->MoveTo (305, 322, ViewerTest::CurrentView(), Standard_False);
+  aCtx->ShiftSelect (Standard_False);
   if (aCtx->NbSelected() != 1)
   {
     theDI << "ERROR: b1 was not selected\n";
     return 1;
   }
-  aCtx->MoveTo (103, 322, ViewerTest::CurrentView());
-  aCtx->ShiftSelect();
+  aCtx->MoveTo (103, 322, ViewerTest::CurrentView(), Standard_False);
+  aCtx->ShiftSelect (Standard_True);
   if (aCtx->NbSelected() != 1)
   {
     theDI << "ERROR: b2 is selected after b1's tolerance increased\n";
@@ -4885,8 +4827,8 @@ static Standard_Integer BUC26658 (Draw_Interpretor& theDI,
   Standard_Integer Xp,Yp;
   myV3dView->Convert(Xv,Yv,Xp,Yp);
 
-  aContext->MoveTo(Xp,Yp, myV3dView);
-  aContext->Select();
+  aContext->MoveTo (Xp, Yp, myV3dView, Standard_False);
+  aContext->Select (Standard_False);
   bool aHasSelected = false;
   for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected()) {
     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
@@ -4912,7 +4854,7 @@ static Standard_Integer BUC26658 (Draw_Interpretor& theDI,
   Standard_ENABLE_DEPRECATION_WARNINGS
 
   // check that there are no selected vertices
-  aContext->Select();
+  aContext->Select (Standard_True);
   aHasSelected = false;
   for (aContext->InitSelected(); aContext->MoreSelected() && !aHasSelected; aContext->NextSelected()) {
     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
@@ -5149,7 +5091,7 @@ static Standard_Integer OCC27523 (Draw_Interpretor& theDI, Standard_Integer theA
   BRepBuilderAPI_MakeEdge anEdgeBuilder (aStart, anEnd);
   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
   Handle(AIS_InteractiveObject) aTestAISShape = new AIS_Shape (anEdge);
-  anAISContext->Display (aTestAISShape);
+  anAISContext->Display (aTestAISShape, Standard_False);
 
   // activate it in selection modes
   TColStd_SequenceOfInteger aModes;
@@ -5171,7 +5113,7 @@ static Standard_Integer OCC27523 (Draw_Interpretor& theDI, Standard_Integer theA
   Handle(AIS_Shape)::DownCast (aTestAISShape)->Set (aVertexShape);
   aTestAISShape->Redisplay();
 
-  anAISContext->AddOrRemoveSelected (aTestAISShape);
+  anAISContext->AddOrRemoveSelected (aTestAISShape, Standard_True);
 
   bool aValidShapeType = false;
   for (anAISContext->InitSelected(); anAISContext->MoreSelected(); anAISContext->NextSelected())
@@ -5252,7 +5194,7 @@ static Standard_Integer OCC27700 (Draw_Interpretor& /*theDI*/, Standard_Integer
     return 1;
   }
   Handle(OCC27700_Text) aPresentation = new OCC27700_Text();
-  aContext->Display (aPresentation);
+  aContext->Display (aPresentation, Standard_True);
   return 0;
 }
 
@@ -5356,6 +5298,87 @@ static Standard_Integer OCC27893 (Draw_Interpretor& /*theDI*/, Standard_Integer
   return 0;
 }
 
+//========================================================================
+//function : OCC28310
+//purpose  : Tests validness of iterator in AIS_InteractiveContext after
+// an removing object from it
+//========================================================================
+static Standard_Integer OCC28310 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv)
+{
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n";
+    return 1;
+  }
+
+  TopoDS_Shape aBox = BRepPrimAPI_MakeBox (10.0, 10.0, 10.0).Shape();
+  Handle(AIS_InteractiveObject) aBoxObj = new AIS_Shape (aBox);
+  aCtx->Display (aBoxObj, AIS_Shaded, 0, Standard_False);
+  ViewerTest::CurrentView()->FitAll();
+  aCtx->MoveTo (200, 200, ViewerTest::CurrentView(), Standard_True);
+  aCtx->Select(Standard_True);
+
+  aCtx->Remove (aBoxObj, Standard_True);
+  // nullify the object explicitly to simulate situation in project,
+  // when ::Remove is called from another method and the object is destroyed
+  // before ::DetectedInteractive is called
+  aBoxObj.Nullify();
+
+  for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
+  {
+    Handle(AIS_InteractiveObject) anObj = aCtx->DetectedInteractive();
+  }
+
+  return 0;
+}
+
+// repetitive display and removal of multiple small objects in the viewer for 
+// test of memory leak in visualization (OCCT 6.9.0 - 7.0.0)
+static Standard_Integer OCC29412 (Draw_Interpretor& /*theDI*/, Standard_Integer theArgNb, const char** theArgVec)
+{
+  Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    std::cout << "Error: no active view.\n";
+    return 1;
+  }
+
+  const int aNbIters = (theArgNb <= 1 ? 10000 : Draw::Atoi (theArgVec[1]));
+  int aProgressPrev = -1;
+  for (int m_loopIndex = 0; m_loopIndex < aNbIters; m_loopIndex++)
+  {
+    gp_Pnt pos;
+    gp_Vec dir(0, 0,1);
+
+    gp_Ax2 center (pos, dir);
+    gp_Circ circle (center, 1);
+    Handle(AIS_Shape) feature;
+
+    BRepBuilderAPI_MakeEdge builder( circle );
+
+    if( builder.Error() == BRepBuilderAPI_EdgeDone )
+    {
+      TopoDS_Edge E1 = builder.Edge();
+      TopoDS_Shape W2 = BRepBuilderAPI_MakeWire(E1).Wire();
+      feature = new AIS_Shape(W2);
+      aCtx->Display (feature, true);
+    }
+
+    aCtx->CurrentViewer()->Update();
+    ViewerTest::CurrentView()->FitAll();
+    aCtx->Remove (feature, true);
+
+    const int aProgress = (m_loopIndex * 100) / aNbIters;
+    if (aProgress != aProgressPrev)
+    {
+      std::cerr << aProgress << "%\r";
+      aProgressPrev = aProgress;
+    }
+  }
+  return 0;
+}
+
 //========================================================================
 //function : Commands_19
 //purpose  :
@@ -5394,7 +5417,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC24533", "OCC24533", __FILE__, OCC24533, group);
   theCommands.Add ("OCC24012", "OCC24012 face edge", __FILE__, OCC24012, group);
   theCommands.Add ("OCC24086", "OCC24086 face wire", __FILE__, OCC24086, group);
-  theCommands.Add ("OCC24622", "OCC24622 texture={1D|2D}\n Tests sourcing of 1D/2D pixmaps for AIS_TexturedShape", __FILE__, OCC24622, group);
   theCommands.Add ("OCC24667", "OCC24667 result Wire_spine Profile [Mode [Approx]], no args to get help", __FILE__, OCC24667, group);
   theCommands.Add ("OCC24755", "OCC24755", __FILE__, OCC24755, group);
   theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group);
@@ -5492,5 +5514,9 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC27893",
                    "OCC27893: Creates a box and selects it via AIS_InteractiveContext API",
                    __FILE__, OCC27893, group);
+  theCommands.Add("OCC28310",
+                  "OCC28310: Tests validness of iterator in AIS_InteractiveContext after an removing object from it",
+                  __FILE__, OCC28310, group);
+  theCommands.Add("OCC29412", "OCC29412 [nb cycles]: test display / remove of many small objects", __FILE__, OCC29412, group);
   return;
 }