Sun, 05/14/2023 - 00:00
Forums:
Hello. I have managed to dispatch when selection occurs. I have have also managed to iterate of objects of class AIS_InteractiveObject
. My final step would be obtaining geometric parameters of my selection - for example - coordinates of points. Here is my code:
void GlfwOcctView::OnSelectionChanged(const Handle(AIS_InteractiveContext)& theCtx, const Handle(V3d_View)& theView)
{
// on selection changed handler.
// see \opencascade-7.7.0\samples\qt\Common\src\ApplicationCommon.cxx, OnSelectionChanged
int selectedItemsCount = theCtx->NbSelected();
selectionDescriptor = "SELECTION INFO. ITEMS: ";
selectionDescriptor.append(std::to_string(selectedItemsCount));
if (selectedItemsCount) {
for (theCtx->InitSelected(); theCtx->MoreSelected(); theCtx->NextSelected()) {
opencascade::handle<AIS_InteractiveObject> obbjj = theCtx->SelectedInteractive();
if (obbjj->Type() == AIS_KindOfInteractive_Shape) {
opencascade::handle<AIS_Shape> shapeFromSelection = opencascade::handle<AIS_Shape>::DownCast(obbjj);
if (shapeFromSelection->Type() == AIS_KindOfInteractive_Shape) {
// LET'S SAY, only points are selectable
TopoDS_Shape shapeGeometric = shapeFromSelection->Shape();
// So, how do I get coordinates of that selected point?
}
}
}
}
}
Unfortunately, I am not able to cast TopoDS_Shape to TopoDS_Vertex - compiler won't allow me to do this for some reason. And even if I could - all subclasses of TopoDS_Shape do not contain geometrical data, as I have seen on manual. I think, I have really lost here.
how do I get coordinates of that selected point on object on scene?
Sun, 05/14/2023 - 18:32
Hello, there are should not be any problem with getting TopoDS_Vertex if aShape.ShapeType() == TopAbs_Vertex. Please make a look into https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling...
There a small example
Best regards, Dmitrii.
Sun, 05/14/2023 - 01:06
Thank you for a quick answer - but seems like that the problem is somewhat different. I do select VERTICES by mouse in my program, but instead selected data is viewed as SOLID. Vertices are definitely components of SOLID, but actual selected vertice data is more useful.
How may I get those selected vertices?
Sun, 05/14/2023 - 16:29
Sometimes solid have no vertices (solid of tessellated faces).
You be able to iterate throught choosen shape to get only Vertives use the next documentation:https://dev.opencascade.org/doc/overview/html/occt_user_guides__modeling...
But it looks like you need to choose a little different way to recieve a mouse click position.
Best regards, Dmitrii.
Sun, 05/14/2023 - 18:01
You get Interactive Object here (
AIS_InteractiveContext::SelectedInteractive()
), while you need working with selection Owners (AIS_InteractiveContext::SelectedOwner()
) after activating sub-shape selection modes. ThenStdSelect_BRepOwner
will bring you a pickedTopoDS_Vertex
, if this is what you are looking for.From
AIS_InteractiveContext::SelectedShape()
documentation:Sun, 05/14/2023 - 22:24
Thanks a lot for your answers. They were super helpful Here is a complete code which I managed to make. It combines information about selected entities into std::string
Mon, 05/15/2023 - 01:25
Please use "BRep_Tool::Pnt(TopoDS::Vertex (theShape));" to get vertex position.
I'm not sure, but maybe you need to use gkv311 n's sample to move shape to the correct position before getting gp_Pnt:
Best regards, Dmitrii.
Mon, 05/15/2023 - 10:25
> Please use "BRep_Tool::Pnt(TopoDS::Vertex (theShape));" to get vertex position
Is it just to make shorter chain of calls and to eliminate transition to TShape?
> I'm not sure, but maybe you need to use gkv311 n's sample to move shape to the correct position before getting gp_Pnt
Why? Do you assume that `StdSelect_BRepOwner` and corresponding `TopoDS_Shape` may have different geometrical placement? That seems somewhat confusing
Mon, 05/15/2023 - 12:06
It is because TShape classes are (internal) implementation details, that are not expected to be directly used in application code - hence,
BRepTools
and similar tools exist.Take into account that Interactive Object might have its own location, apart from shape location - e.g. moved by
AIS_Manipulator
or programically.