用鼠标选择顶点、边和面(OpenCASCADE)
我想根据选择模式在 AIS_Shape 上进行顶点、边、面或全身选择。实际上,如果选择了我想要出发的顶点,我需要获取该顶点的坐标。如果选择边缘,我需要计算长度。即使选择了面部,表面积...
我可以用我的命令突出显示。
myViewerWidget->getContext()->Activate(TopAbs_FACE, Standard_True);
但是当单击该形状时,它会返回它的所有顶点或曲面。
我在鼠标点击事件中的代码如下;
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;
}
}
}
我怎样才能拥有我想要的任何 AIS_Shape 的一个角或边?我缺少什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该实现一个鼠标事件
,在其中检索光标当前的 x,y 位置
(应启用鼠标跟踪)。
然后您应该使用:
[请参阅此调用的文档]
然后检索您选择的所有者:
然后
确定:形状(最后一次调用)是您选择的:如果您激活了面部选择模式,则形状是 TopoDS_Face。
如果您激活了顶点选择模式,则您的形状就是一个顶点。
最后(假设我们正在处理顶点选择)
希望这有帮助
乔万尼
you should implement a mouse event
in which you retrieve the current x,y position of the cursor
(mouse tracking should be enabled).
Then you should use:
[see documentation for this call]
Then retrieve the owner of your selection:
Then
OK: shape (last call) is what you have picked: if you activated selection mode for faces, the shape is a TopoDS_Face.
If you activated the selection mode for vertexes, your shape is a vertex.
At the end (suppose we are dealing with vertex selection)
Hope this helps
Giovanni