Extracting Dimension Data From Step File

Hello Dmitrii! Hope you are well.

I have recently started to extract dimension data from steps files. I am able to get the data but not everything I need. Mainly I am trying to just get the primary data about the dimension i.e.
- Attach Point(s)
- Value

I noticed that depending on the export type STP_214 with all exported data selected, I am unable to get the value and attach points

{"className": "XCAFDimTolObjects_DimensionObject", "Type": 30, "Qualifier": 0, "IsHole": 0, "FormVariance": 0, "Grade": 0, "L": 0, "R": 0, "Dir": {"gp_Dir": [1, 0, 0]}, "Plane": {"Location": [4.81748e-12, 0, 253.878], "Direction": [0, 0, -1], "XDirection": [-1, 0, 0], "YDirection": [0, 1, 0]}, "Presentation": {"className": "TopoDS_Shape", "TShape": {"className": "TopoDS_TShape", "this": "0x20C3749CA00", "ShapeType": 0, "NbChildren": 1, "Flags": 3, "Free": 1, "Free": 1, "Locked": 0, "Modified": 1, "Checked": 0, "Orientable": 0, "Closed": 0, "Infinite": 0, "Convex": 0}, "Location": {"className": "TopLoc_Location", "Transformation": {"Location": [0, 0, 0], "Matrix": [1, 0, 0, 0, 1, 0, 0, 0, 1], "shape": 0, "scale": 1}, "IsIdentity": 1}, "Orient": 0}, "SemanticName": "DGT:Common_label", "PresentationName": "ad8"}

When exporting STP_242 with extra data, I am getting the value. But the attach points seem to be elusive still.

{"className": "XCAFDimTolObjects_DimensionObject", "Type": 14, "Value": 180, "Qualifier": 0, "IsHole": 0, "FormVariance": 0, "Grade": 0, "L": 0, "R": 0, "Dir": {"gp_Dir": [1, 0, 0]}, "Plane": {"Location": [-2032, 0, 2540], "Direction": [0, 0, 1], "XDirection": [1, 0, -0], "YDirection": [-0, 1, 0]}, "PntText": {"gp_Pnt": [-2032, 0, 2540]}, "Presentation": {"className": "TopoDS_Shape", "TShape": {"className": "TopoDS_TShape", "this": "0x2944EF79F90", "ShapeType": 0, "NbChildren": 1, "Flags": 3, "Free": 1, "Free": 1, "Locked": 0, "Modified": 1, "Checked": 0, "Orientable": 0, "Closed": 0, "Infinite": 0, "Convex": 0}, "Location": {"className": "TopLoc_Location", "Transformation": {"Location": [0, 0, 0], "Matrix": [1, 0, 0, 0, 1, 0, 0, 0, 1], "shape": 0, "scale": 1}, "IsIdentity": 1}, "Orient": 0}, "SemanticName": "curve length", "PresentationName": "dd_2"}

Am I going about this the wrong way? I also looked at this post: https://dev.opencascade.org/content/get-dimensions-data-stepap242

I am using the following:

TDF_LabelSequence aRootDimensionLabels;   
aDimTolTool->GetDimensionLabels(aRootDimensionLabels);   
 for (TDF_LabelSequence::Iterator aRootIter(aRootDimensionLabels); aRootIter.More(); aRootIter.Next())   
 {   
    const TDF_Label& aRootLabel = aRootIter.Value();   
    Handle(XCAFDoc_Dimension) aDimAttr;   
    aRootLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimAttr);   
    Handle(XCAFDimTolObjects_DimensionObject) aDimObject = aDimAttr->GetObject()   
    aDimObject->DumpJson(std::cout);   
}

Regards, Jonathyn

Attachments: 
Dmitrii Pasukhin's picture

Hi, everything is correct. AP214 mostly based on pre-tessellated geometry (31 type). AP242 usually extend this data with semantic. According STEP ISO GDT can be attached to Topology or supplemental geometry. Attachment point is a supplemental geometry. But the most part of step files have attached to Topology, that means you have no options to extract attachments point, they need to be calculated based on related topology and axis(it is complicated task).

Best regards, Dmitrii.

Jonathyn Major's picture

Any pointers on where to start with this complicated task?

My thought would be to use the dimension place axis' (i.e. front facing dimension would be x,y) and find the bounding box for the dimension edge, exclude the non planer axis (in this case z). Does that sound like the right direction to you?

Dmitrii Pasukhin's picture

Yes, the base thing is exract TopoDS_Shape from first and second connection(optional) and plane of PMI and text location. For single attachment point it is much easy, you can find any closest points. For 2 attachment points you need to find points that parallel each other on different shapes from text location. As first solution you can ignore plane of label and find just most comfortable points. But the latest solutions needs to take as a recommendation a PMI label plane and create a points in that plane if possible.

I'm not sure that there are any open source solutions for that :(

Best regards, Dmitrii.

Jonathyn Major's picture

Hello Dmitrii,
My thought was, I only need the bounds of the dimension to consider where the attach points are. Based on other articles I was thinking of using
XCAFDoc_DimTolTool::GetGDTPresentations

Does this seem right to you?

Additionally when I try to use GetGDTPresentation, It requires the TDF_LabelMapHasher.hxx library which doesn't seem to be in 7.8.0 release. Any thoughts?

Thanks!

Jonathyn Major's picture

Hello, Just to follow up. I used this method (looks like the hasher was not required)

   NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape> theGDTLabelToShape;   
   aDimTolTool->GetGDTPresentations(theGDTLabelToShape);   
   NCollection_IndexedDataMap<TDF_Label, TopoDS_Shape>::Iterator iterator(theGDTLabelToShape);   
   for (iterator; iterator.More(); iterator.Next()) {   
       TopoDS_Shape dimShape = iterator.Value();   
       TDF_Label dimLabel = iterator.Key();   
       std::cout << "Dim Label: " << "\n";   
       dimLabel.Dump(std::cout);   
       std::cout << "\n";   


       double Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;   
       Bnd_Box Bound;   
       BRepBndLib::Add(dimShape, Bound);   
       Bound.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);   
       std::cout << "Xmin: " << Xmin << "\n";   
       std::cout << "Ymin: " << Ymin << "\n";   
       std::cout << "Zmin: " << Zmin << "\n";   
       std::cout << "Xmax: " << Xmax << "\n";   
       std::cout << "Ymax: " << Ymax << "\n";   
       std::cout << "Zmax: " << Zmax << "\n";   

   }   

It seems to be working. I just want to make sure there wasn't a more straight forward way to get this data. Any input is useful.

Thanks!

Dmitrii Pasukhin's picture

You solutions looks like you want to extract attachments points based on pre-tessellated version. That is great idea. Mostly dimShape represented by Edge with Geom_Polylind as geometry. You be able to extract the bound points of each Polyline and find points that lying on related shapes(firstRel and SecRel, see GetRefShapeLabel).

Connected shapes can be extracted by XCAFDoc_DimTolTool::GetRefShapeLabel You need to find point on that TopoDS_Shape. It will be attachment point.

Best regards, Dmitrii.