Fri, 09/22/2023 - 00:57
Forums:
I am having trouble figuring out how to get the TDF_Label from the selected object.
I am trying to display the label when a user selects a shape in the viewer.
TopoDS_Shape selectedshape = myContext->SelectedShape();
Gets the selected shape but I cannot figure out how to get the label from the TopoDS_Shape.
I've also tried to iterate over the labels and get the shape from there. Unfortunately the TDF_Label doesn't seem to tie to the displayed ais_interactiveobjects in a way that I can determine.
TDF_LabelSequence aLabels;
aShapeTool->getShapes(aLabels);
for (standard_integer aLabIter = 1; aLabIter <= aLabels.Length(); ++aLabIter) {
// Check if matching shape is found
const TDF_Label& aLabel = aLabels.Value(aLabIter);
TopoDS_Shape shape;
aShapeTool->GetShape(aLabel, shape);
//check if same - no match found here
if (shape.IsSame(selectedshape)) {
std::cout << "Selected shape matches.\n";
}
// Get node name
Handle(TDataStd_Name) aNodeName;
TCollection_AsciiString aName;
{
if (aLabel.FindAttribute(TDataStd_Name::GetID(), aNodeName)) {
aName = aNodeName->Get();
}
if (aName.IsEmpty()) {
TDF_Label aRefLabel;
if (XCAFDoc_ShapeTool::GetReferredShape(aLabel, aRefLabel) && aRefLabel.FindAttribute(TDataStd_Name::GetID(), aNodeName)) {
aName = aNodeName->Get();
}
}
}
// Check if we found our matching label we were trying to print out
if (aName.IsEqual("TableLeg") {
std::cout << "Found matching TableLeg label \n";
}
}
Can someone please help me figure out how to get a label from a selected object?
Thank you
Fri, 09/22/2023 - 01:21
Looking at it from the reverse, trying to get the TDF_Label from a AIS_InteractiveObject, I am not having any luck being able to map these two pieces.
Below I can iterate through all the interactive objects on the screen and it will highlight them but I am not able to check their labels or find the label
This highlights everything but dumping the data or using any functions on the AIS_InteractiveObject I can't see how to just get the one TDF_Label I want to highlight.
Any thoughts?
Tue, 01/23/2024 - 11:15
there is no method get TDF_Label from shape