Mon, 02/06/2023 - 10:56
Forums:
I try to read step file with opencascade, there are several ways to display the bodies in step file, but when I use TPrsStd_AISPresentation, the location of bodies will go wrong some times. AND when I use method prs->GetAIS()->SetLocalTransformation(loc) to change the location of the AIS Object of TPrsStd_AISPresentation, it will not work too.
Here is my sample codes
//! this will generate wrong location
for (XCAFPrs_DocumentExplorer aLeafIter(d->doc, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
aLeafIter.More(); aLeafIter.Next())
{
const XCAFPrs_DocumentNode& aDocNode = aLeafIter.Current();
TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aDocNode.RefLabel);
if (!aShape.IsNull())
{
Handle(TPrsStd_AISPresentation) prs = TPrsStd_AISPresentation::Set(aDocNode.Label, XCAFPrs_Driver::GetID());
prs->Display(true);
}
}
//! this will generate right location
for (XCAFPrs_DocumentExplorer aLeafIter(d->doc, XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes);
aLeafIter.More(); aLeafIter.Next())
{
const XCAFPrs_DocumentNode& aDocNode = aLeafIter.Current();
TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(aDocNode.RefLabel);
if (!aShape.IsNull())
{
aShape.Location(aDocNode.Location);
Handle(AIS_Shape) ais = new AIS_Shape(aShape);
//mCtx->Display(ais, true);
}
}
I want to know why SetLocalTransformation Method does'work AND why the location was not right?
Does anyone can help, Thank You!
Attachments:
Tue, 02/07/2023 - 12:41
Please use 'insert code' in editor or Markdown syntax to make shared code readable.
Thu, 02/09/2023 - 07:09
sorry, I did't notice that
Tue, 02/07/2023 - 12:44
Why would you want using
TPrsStd_AISPresentation
instead of more straightforwardXCAFPrs_AISObject
?Wed, 02/08/2023 - 05:52
gkv:
Thank you for your reply!
Because I want to store the AIS Objects to ocaf. Before I use TPrsStd_AISPresentation, I have to use a map to keep the relationship of Label and AIS Object. I think may be that's not the best practice, so I want to try TPrsStd_AISPresentation.
Wed, 02/08/2023 - 05:53
gkv:
Thank you for your reply!
Because I want to store the AIS Objects to ocaf. Before I use TPrsStd_AISPresentation, I have to use a map to keep the relationship of Label and AIS Object. I think may be that's not the best practice, so I want to try TPrsStd_AISPresentation.
Fri, 02/10/2023 - 20:47
The code above works as expected, because you pass shape location from
XCAFPrs_DocumentExplorer
tool.XCAFPrs_DocumentExplorer
combines transformation of all parent nodes in XCAF tree and provides a final location that could be applied toaDocNode.RefLabel
to locate shape in the world space.This code doesn't use location accumulated by
XCAFPrs_DocumentExplorer
tool. Instead, it takesaDocNode.Label
(instead ofaDocNode.RefLabel
). These shape labels have no information about all parents nodes (in fact, shape label may be a child of several different parent nodes having different final location). So that displaying this presentation preserves only transformation of a child relative to a single parent, which is not what you are looking for.I'm not familiar with a proper way for setting location to
TPrsStd_AISPresentation
(overridingXCAFPrs_Driver::Update()
in a driver subclass?), but you need somehow passing this location information to interactive object (AIS_InteractiveContext::SetLocation()
) or to shape.Sun, 02/12/2023 - 09:54
Thank you very much for your explain!
I will try your suggestion.