Mon, 02/28/2022 - 10:36
Forums:
Hi everyone,
I want to have vertex, edge, face or full body selection on AIS_Shape according to selection mode. Actually, if the vertex that I want to go from is selected, I need to obtain the coordinates of the vertex. If edge is selected I need to calculate the length. Surface area even if face is selected...
I can highlight with my command.
myViewerWidget->getContext()->Activate(TopAbs_FACE, Standard_True);
But when the shape is clicked it returns me all of its vertices or surfaces.
My code in the mouse click event is as follows;
if (theEvent->button() == Qt::LeftButton) {
qDebug() << "Left click pressed.";
if(!myContext->DetectedOwner().IsNull()){
Handle(AIS_InteractiveObject) picked;
myContext->InitSelected();
picked = myContext->DetectedInteractive();
Handle(AIS_Shape) aShape=Handle(AIS_Shape)::DownCast(picked);
TopoDS_Shape topShape = aShape->Shape();
// Vertex
for(TopExp_Explorer vertEx(topShape, TopAbs_VERTEX); vertEx.More(); vertEx.Next()) {
TopoDS_Vertex aVertex = TopoDS::Vertex(vertEx.Current());
gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
qDebug() << "Vertex: " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z();
}
// Face
for(TopExp_Explorer vertEx(topShape, TopAbs_FACE); vertEx.More(); vertEx.Next()) {
TopoDS_Face aVertex = TopoDS::Face(vertEx.Current());
GProp_GProps System;
BRepGProp::SurfaceProperties(aVertex, System);
Standard_Real Area = System.Mass();
qDebug() << "Area: " << Area;
}
}
}How can I have only one corner or edge of any AIS_Shape that I want? What am I missing?
Thanks, Hakan.
Mon, 02/28/2022 - 11:26
Your code retrieves the shape from AIS_Shape, which would be entire shape of this presentation. To get picking results you should work with Owner objects instead.
Mon, 02/28/2022 - 13:16
Thanks for your answer Kirill. I know I'm tiring you but when I do as you say I can't catch any TopoDS_Shape.
My code:
Handle(SelectMgr_EntityOwner) aSelOwner = myContext->SelectedOwner(); Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (aSelOwner); if (!aBRepOwner.IsNull()) { qDebug() << "Shape is live."; TopoDS_Shape aSubShape = aBRepOwner->Shape(); for (TopExp_Explorer wExpl(aSubShape, TopAbs_VERTEX); wExpl.More(); wExpl.Next()) { const TopoDS_Vertex &curVertex = TopoDS::Vertex(wExpl.Current()); const gp_Pnt curVertexPos = BRep_Tool::Pnt(curVertex); qDebug() << "Vertex: " << curVertexPos.X() << " " << curVertexPos.Y() << " " << curVertexPos.Z(); } }This is how I set the viewer content. Could there be an issue with that?