选择鼠标(OpenCascade)的顶点,边缘和脸部

问题描述 投票:0回答:2

我希望根据选择模式在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中只有一个角或边缘?我想念什么?
    

您应该实施鼠标事件

c++ qt qt5 opencascade
2个回答
2
投票

在您检索光标的当前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());
ok:shape(最后一个呼叫)是您选择的:如果您激活面部的选择模式,则形状为topods_face。
如果您激活了顶点的选择模式,则形状为顶点。
the末端(假设我们正在处理顶点选择)

//! retrieve geometry const gp_Pnt& P = BRep_Tool::Pnt(TopoDS::Vertex(shape)); // plot coordinates cout<<"____("<<P.X()<<", "<<P.Y()<<", "<<P.Z()<<"____"<<endl;
希望这有帮助
Giovanni

即使有一个同样的问题
myViewerWidget->getContext()->MoveTo(...);

在鼠标移动事件中被称为


0
投票

在单击事件中被称为,单个边缘没有正确地进行或选择。

是由于预设过滤器允许优先选择的全身选择。为了解决它,我打电话给停用以清除所有过滤器,然后设置我的过滤器,然后像魅力一样工作:
myViewerWidget->getContext()->Deactivate();    
myViewerWidget->getContext()->Activate(TopAbs_FACE, Standard_True);
myViewerWidget->getContext()->Activate(TopAbs_EDGE, Standard_True);
myViewerWidget->getContext()->Activate(TopAbs_VERTEX, Standard_True);

只是指出,这只有在已经显示的拓扑结构上有效,因此请确保您每次在拓扑后的每次设置过滤器。
希望它能帮助某人。
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.