]> OCCT Git - occt.git/commitdiff
0033273: Data Exchange, GDT - Getting number of multiple elements with the same measure
authordpasukhi <dpasukhi@opencascade.com>
Fri, 16 Dec 2022 12:03:23 +0000 (12:03 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Fri, 16 Dec 2022 12:03:23 +0000 (12:03 +0000)
Updated DimTolTool API to get number of multiple elements with the same measure.

src/XCAFDoc/XCAFDoc_DimTolTool.cxx
src/XCAFDoc/XCAFDoc_DimTolTool.hxx

index 8a5da13d174549e824e336c34c85c5ed91a54007..a6a16c527ad8aeec4f10bc8539763af380fa9bb0 100644 (file)
@@ -13,6 +13,8 @@
 
 #include <XCAFDoc_DimTolTool.hxx>
 
+#include <Bnd_Box.hxx>
+#include <BRepBndLib.hxx>
 #include <Precision.hxx>
 #include <Standard_GUID.hxx>
 #include <Standard_Type.hxx>
@@ -617,6 +619,51 @@ Standard_Boolean XCAFDoc_DimTolTool::GetRefDatumLabel(const TDF_Label& theShapeL
   return Standard_True;
 }
 
+//=======================================================================
+//function : GetNumberOfPlaces
+//purpose  :
+//=======================================================================
+Standard_Integer XCAFDoc_DimTolTool::GetNumberOfPlaces(const TDF_Label& theLabel)
+{
+  TDF_LabelSequence aFirstShapes, aSecondShapes;
+  GetRefShapeLabel(theLabel, aFirstShapes, aSecondShapes);
+
+  NCollection_Sequence<Bnd_Box> aBoxes;
+  for (Standard_Integer anI = 1; anI <= aFirstShapes.Size(); anI++)
+  {
+    Bnd_Box aBox;
+    BRepBndLib::Add(ShapeTool()->GetShape(aFirstShapes(anI)), aBox, Standard_True);
+    aBoxes.Append(aBox);
+  }
+
+  // Fill bounded boxes of number of places - this will exclude duplications
+  NCollection_Sequence<Bnd_Box> aPlaces;
+  for (Standard_Integer anI = 1; anI <= aBoxes.Size(); anI++)
+  {
+    Standard_Boolean toAddPlace = Standard_True;
+    Standard_Integer aBoxesIndex = 1;
+    for (Standard_Integer aJ = 1; aJ <= aPlaces.Size(); aJ++)
+    {
+      if (!aPlaces(aJ).IsOut(aBoxes(anI)))
+      {
+        toAddPlace = Standard_False;
+        aBoxesIndex = aJ;
+        break;
+      }
+    }
+
+    if (toAddPlace)
+    {
+      aPlaces.Append(aBoxes(anI));
+    }
+    else
+    {
+      aPlaces.ChangeValue(aBoxesIndex).Add(aBoxes(anI));
+    }
+  }
+  return aPlaces.Size();
+}
+
 //=======================================================================
 //function : GetDimTol
 //purpose  : 
index ae511ab318c8ae31159a6d23283ffccf22f7adad..e6de6f96ed1b3074a4d8cc6a857e29b0846f1f79 100644 (file)
@@ -232,6 +232,10 @@ public:
   Standard_EXPORT Standard_Boolean GetRefDatumLabel (const TDF_Label& theShapeL, 
                                                      TDF_LabelSequence& theDatum)  const;
 
+  //! @param theLabel [in] geometrical tolerance TDF label.
+  //! @return Number Of Places corresponding to the Geometrical Tolerance or Dimensional Tolerance TDF label.
+  Standard_EXPORT Standard_Integer GetNumberOfPlaces (const TDF_Label& theLabel);
+
   //! Returns true if the given GDT is marked as locked.
   Standard_EXPORT Standard_Boolean IsLocked(const TDF_Label& theViewL) const;