GD&T values can not be get in .stp file

Hi,team.
I`ve tried to get gd&t informations through the code below:
STEPCAFControl_Reader cafReader;
cafReader.SetNameMode(true);
cafReader.SetGDTMode(true);
IFSelect_ReturnStatus status = cafReader.ReadFile(srcPath);

if (1 != status)
return false;

Handle(TDocStd_Document) doc = new TDocStd_Document("MDTV-XCAF");
if (cafReader.Transfer(doc))
{
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
Handle(XCAFDoc_DimTolTool) gdtTool = XCAFDoc_DocumentTool::DimTolTool(doc->Main());
//XCAFDoc_DimTolTool::GetGDTPresentations();
TDF_LabelSequence labels_datums, label_geoms, label_dims, label_dimTols;
gdtTool->GetDatumLabels(labels_datums);
gdtTool->GetDimensionLabels(label_dims);
gdtTool->GetGeomToleranceLabels(label_geoms);
}

And for the file I opened,I got 9 Dimension Labels.But I can`t get any values from them.I really got no clue.
Best regard,Ji.

Dmitrii Pasukhin's picture

Hello,

The type (31 - DimensionPresentation) means pure tesselation object. In that case there are no semantic information, only lines(pure pre-tessalated object).

Best regards, Dmitrii.

onkarp12's picture

I am also seeing similar issue with my file for which I have started writing code to get GD&T information. I have used similar code to get the GD&T information , here in this case I am only getting linear dimension and not the datum frame object. Any idea ?

Also I have not seen any code example(everyone is using different approach) to get the complete information about GD&T(any type) from STEP file. I have observed everyone is trying different approach. What is the correct approach to get the all GD&T Information required for visualizing same in web (e.g. using Three JS) Any help is appreciated! Thanks in advance!!
PS: Not able to attach STEP file, hence copied content in txt file. Attached expected result.
====Sample code to Read GDT================================
TDF_LabelSequence labels_datums, label_geoms, label_dims, label_dimTols;
gdtTool->GetDatumLabels(labels_datums);
gdtTool->GetDimensionLabels(label_dims);
gdtTool->GetGeomToleranceLabels(label_geoms);
int datumSize = labels_datums.Length();
int dimSize = label_dims.Length();
int geomSize = label_geoms.Length();

// Dimensional Tolerances
for (int i = 1; i <= dimSize; ++i)
{
const TDF_Label& label_dim = label_dims.Value(i);

Handle(XCAFDoc_Dimension) aDimAttr;
label_dim.FindAttribute(XCAFDoc_Dimension::GetID(), aDimAttr);

if (!aDimAttr.IsNull())
{
Handle(XCAFDimTolObjects_DimensionObject) aDimObject = aDimAttr->GetObject();
Handle(TCollection_HAsciiString) name = aDimObject->GetPresentationName();

if (!name)
name = aDimObject->GetSemanticName();

double val = aDimObject->GetValue();
gp_Pnt point1 = aDimObject->GetPoint();
gp_Pnt point2 = aDimObject->GetPoint2();
TopoDS_Shape shape = aDimObject->GetPresentation();
TopoDS_Edge edge= aDimObject->GetPath();
gp_Pnt point3= aDimObject->GetPointTextAttach();
Handle(TCollection_HAsciiString) pname=aDimObject->GetPresentationName();

double lowerTolVal = aDimObject->GetLowerTolValue();
double lowerBoundVal = aDimObject->GetLowerBound();
double upperTolVal = aDimObject->GetUpperTolValue();
double upperBound = aDimObject->GetUpperBound();
XCAFDimTolObjects_DimensionType dimType = aDimObject->GetType();
XCAFDimTolObjects_DimensionQualifier dimQualifier = aDimObject->GetQualifier();

Handle(TColStd_HArray1OfReal) vals = aDimObject->GetValues();
//int valSize = vals->Size();

Handle(TCollection_HAsciiString) ascHSemNameStr = aDimObject->GetSemanticName();
TCollection_AsciiString ascSemNameStr = ascHSemNameStr->String();

if (name)
{
TCollection_AsciiString ascNameStr = name->String();
wstring nameStr = StrTool::str2wstr(ascNameStr.ToCString());

// Get shape
TDF_LabelSequence fir, sec;
gdtTool->GetRefShapeLabel(label_dim, fir, sec);

GDT_Item* gdt = nullptr;
if (!(gdt = model->GetGDTByName(nameStr)))
{
gdt = new GDT_Item(nameStr);
model->AddGDT(gdt);
}

for (int j = 1; j <= fir.Length(); ++j)
{
const TDF_Label& label_shape = fir.Value(1);
const TopoDS_Shape& shape = m_shapeTool->GetShape(label_shape);

gdt->AddShape(shape);
}

for (int j = 1; j <= sec.Length(); ++j)
{
const TDF_Label& label_shape = sec.Value(1);
const TopoDS_Shape& shape = m_shapeTool->GetShape(label_shape);

gdt->AddShape(shape);
}

const TopoDS_Shape& pptShape = aDimObject->GetPresentation();

if (!pptShape.IsNull())
gdt->AddShape(pptShape);
}
}
}

// Datums
for (int i = 1; i <= datumSize; ++i)
{
const TDF_Label& label_datum = labels_datums.Value(i);

TDF_LabelSequence labels_views;
m_viewTool->GetViewLabelsForGDT(label_datum, labels_views);
int viewSize = labels_views.Length();

Handle(XCAFDoc_Datum) aDatumAttr;
label_datum.FindAttribute(XCAFDoc_Datum::GetID(), aDatumAttr);

if (!aDatumAttr.IsNull())
{
Handle(XCAFDimTolObjects_DatumObject) aDatumObject = aDatumAttr->GetObject();
Handle(TCollection_HAsciiString) name = aDatumObject->GetPresentationName();

if (!name)
name = aDatumObject->GetSemanticName();

const TopoDS_Shape& targetShape = aDatumObject->GetDatumTarget();
double targetLength = aDatumObject->GetDatumTargetLength();
double targetWidth = aDatumObject->GetDatumTargetWidth();

int targetNum = aDatumObject->GetDatumTargetNumber();

XCAFDimTolObjects_DatumTargetType targetType = aDatumObject->GetDatumTargetType();
gp_Ax2 axis = aDatumObject->GetDatumTargetAxis();

//TDF_LabelSequence geomTols;
//gdtTool->GetTolerOfDatumLabels(label_datum, geomTols);

//Handle(TCollection_HAsciiString) ascHSemNameStr = aDatumObject->GetSemanticName();
//TCollection_AsciiString ascSemNameStr = ascHSemNameStr->String();

if (name)
{
TCollection_AsciiString ascNameStr = name->String();
wstring nameStr = StrTool::str2wstr(ascNameStr.ToCString());

// Get shape
TDF_LabelSequence fir, sec;
gdtTool->GetRefShapeLabel(label_datum, fir, sec);

GDT_Item* gdt = nullptr;
if (!(gdt = model->GetGDTByName(nameStr)))
{
gdt = new GDT_Item(nameStr);
model->AddGDT(gdt);
}

for (int j = 1; j <= fir.Length(); ++j)
{
const TDF_Label& label_shape = fir.Value(1);
const TopoDS_Shape& shape = m_shapeTool->GetShape(label_shape);

gdt->AddShape(shape);
}

for (int j = 1; j <= sec.Length(); ++j)
{
const TDF_Label& label_shape = sec.Value(1);
const TopoDS_Shape& shape = m_shapeTool->GetShape(label_shape);

gdt->AddShape(shape);
}

//const TopoDS_Shape& pptShape = aDatumObject->GetPresentation();

//if (!pptShape.IsNull())
// gdt->AddShape(pptShape);
}
}
}
=====Sample code ends=============================

Attachments: