]> OCCT Git - occt.git/commitdiff
* 0033273: Data Exchange, GDT - Getting number of multiple elements with the same...
authorika <ika@opencascade.com>
Tue, 14 May 2024 14:26:59 +0000 (15:26 +0100)
committerika <ika@opencascade.com>
Tue, 14 May 2024 14:26:59 +0000 (15:26 +0100)
Updated DimTolTool API to get number of multiple elements with the same measure.

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

index 4ad3778ed6f263461991f54531dbaaa112cdaa87..ca43e4a557f42127d0d0ea1b82bc0902a6e5446f 100644 (file)
@@ -13,6 +13,8 @@
 
 #include <XCAFDoc_DimTolTool.hxx>
 
+#include <Bnd_Box.hxx>
+#include <BRepBndLib.hxx>
 #include <Standard_Type.hxx>
 #include <TColStd_MapOfAsciiString.hxx>
 #include <TDataStd_Name.hxx>
@@ -1058,6 +1060,51 @@ void XCAFDoc_DimTolTool::SetGDTPresentations(NCollection_IndexedDataMap<TDF_Labe
   }
 }
 
+//=======================================================================
+//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 : DumpJson
 //purpose  : 
index ea4b34436f50dbde7f2b89700b1bd5395e43fbf8..40e0e081812c644f72e2c6eb98964cd3e8a49a44 100644 (file)
@@ -229,6 +229,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;