用鼠标选择顶点、边和面(OpenCASCADE)

发布于 2025-01-13 22:16:53 字数 1501 浏览 5 评论 0原文

我想根据选择模式在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷雨优美回忆 2025-01-20 22:16:54

您应该实现一个鼠标事件

::onLeftButtonUp()

,在其中检索光标当前的 x,y 位置
(应启用鼠标跟踪)。
然后您应该使用:

myContext->moveTo(x, y, ...);

[请参阅此调用的文档]

然后检索您选择的所有者:

const Handle(SelectMgr_EntityOwner) &anOwnerOfDetection = myContext->DetectedOwner();

然后

//! downcast to a BRepOwner
const Handle(StdSelect_BRepOwner) &aBRepOwnerOfSelection  = Handle(StdSelect_BRepOwner)::DownCast(anOwnerOfSelection);

//! retrieve the shape of the owner
const TopoDS_Shape &selectedShape = aBRepOwnerOfDetection->Shape();

const TopoDS_Shape &shape = detectedShape.Located(aBRepOwnerOfDetection->Location() * detectedShape.Location());

确定:形状(最后一次调用)是您选择的:如果您激活了面部选择模式,则形状是 TopoDS_Face。
如果您激活了顶点选择模式,则您的形状就是一个顶点。

最后(假设我们正在处理顶点选择)

//! retrieve geometry
const gp_Pnt& P = BRep_Tool::Pnt(TopoDS::Vertex(shape));

// plot coordinates
cout<<"____("<<P.X()<<", "<<P.Y()<<", "<<P.Z()<<"____"<<endl;

希望这有帮助
乔万尼

you should implement a mouse event

::onLeftButtonUp()

in which you retrieve the current x,y position of the cursor
(mouse tracking should be enabled).
Then you should use:

myContext->moveTo(x, y, ...);

[see documentation for this call]

Then retrieve the owner of your selection:

const Handle(SelectMgr_EntityOwner) &anOwnerOfDetection = myContext->DetectedOwner();

Then

//! downcast to a BRepOwner
const Handle(StdSelect_BRepOwner) &aBRepOwnerOfSelection  = Handle(StdSelect_BRepOwner)::DownCast(anOwnerOfSelection);

//! retrieve the shape of the owner
const TopoDS_Shape &selectedShape = aBRepOwnerOfDetection->Shape();

const TopoDS_Shape &shape = detectedShape.Located(aBRepOwnerOfDetection->Location() * detectedShape.Location());

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)

//! retrieve geometry
const gp_Pnt& P = BRep_Tool::Pnt(TopoDS::Vertex(shape));

// plot coordinates
cout<<"____("<<P.X()<<", "<<P.Y()<<", "<<P.Z()<<"____"<<endl;

Hope this helps
Giovanni

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文