基于OpenCASCADE自制三维建模软件(九)选择物体

编程入门 行业动态 更新时间:2024-10-09 16:24:28

基于OpenCASCADE自制三维<a href=https://www.elefans.com/category/jswz/34/1769748.html style=建模软件(九)选择物体"/>

基于OpenCASCADE自制三维建模软件(九)选择物体

文章目录

  • 一、检测模型
  • 二、选择模型
  • 项目仓库

OpenCASECADE提供模型选择的方法,在AIS_InteractiveContext中,MoveTo方法让鼠标检测到的模型高亮,Select方法实现选择模型,ShiftSelect方法实现多个模型的选择。

一、检测模型

MoveTo方法的定义(AIS_InteractiveContext.hxx):

  Standard_EXPORT AIS_StatusOfDetection MoveTo (const Standard_Integer  theXPix,const Standard_Integer  theYPix,const Handle(V3d_View)& theView,const Standard_Boolean  theToRedrawOnUpdate);

MoveTo方法将鼠标位置(theXPix,theYPix以像素为单位)传递给AIS_InteractiveContex 。这是由视图theView完成的,它将这个位置传递给主查看器并更新它,最后使鼠标检测到的模型实现高亮。

在程序中mouseMoveEvent事件加入MoveTo方法,实现鼠标移动同时检测模型,并且让模型高亮:

void C3DWidget::mouseMoveEvent(QMouseEvent *event)
{// 鼠标移动到模型时,模型高亮显示m_context->MoveTo(event->x(),event->y(),m_view,true);......
}

程序效果:

更新:修改高亮风格
通过获取并修改 AIS_InteractiveContext 对象的 SelectionStyle ,可以配置检测到模型时的高亮风格

        // 设置模型高亮的风格Handle(Prs3d_Drawer) t_hilight_style = m_context->HighlightStyle(); // 获取高亮风格t_hilight_style->SetMethod(Aspect_TOHM_COLOR);  // 颜色显示方式t_hilight_style->SetColor(Quantity_NOC_LIGHTYELLOW);    // 设置高亮颜色t_hilight_style->SetDisplayMode(1); // 整体高亮t_hilight_style->SetTransparency(0.2f); // 设置透明度

鼠标移动到模型的位置,模型高亮显示淡黄色:

二、选择模型

Select方法有三种形式(AIS_InteractiveContext.hxx):

  1. 选择视图中由像素最大最小值(XPMin、YPMin、XPMax和YPMax)定义的边框中找到的所选模型。检测到的对象被传递给主查看器,然后更新主查看器。
  Standard_EXPORT AIS_StatusOfPick Select (const Standard_Integer  theXPMin,const Standard_Integer  theYPMin,const Standard_Integer  theXPMax,const Standard_Integer  theYPMax,const Handle(V3d_View)& theView,const Standard_Boolean  theToUpdateViewer);
  1. 多段线的选择,或清除以前选择的列表。
  Standard_EXPORT AIS_StatusOfPick Select (const TColgp_Array1OfPnt2d& thePolyline,const Handle(V3d_View)&     theView,const Standard_Boolean      theToUpdateViewer);
  1. 通过MoveTo检测到的对象进行选择,或清除之前的选择
  Standard_EXPORT AIS_StatusOfPick Select (const Standard_Boolean theToUpdateViewer);

ShiftSelect方法将最后检测到的添加到先前选择的列表中,如果最后检测到的模型已被选择,则将取消该模型的选择。类似地ShiftSelect方法也有三种形式(AIS_InteractiveContext.hxx):

  Standard_EXPORT AIS_StatusOfPick ShiftSelect (const Standard_Integer  theXPMin,const Standard_Integer  theYPMin,const Standard_Integer  theXPMax,const Standard_Integer  theYPMax,const Handle(V3d_View)& theView,const Standard_Boolean  theToUpdateViewer);Standard_EXPORT void FitSelected (const Handle(V3d_View)& theView,const Standard_Real     theMargin,const Standard_Boolean  theToUpdate);Standard_EXPORT void FitSelected (const Handle(V3d_View)& theView);

在程序中mousePressEvent事件加入Select和ShiftSelect方法,实现鼠标对模型选择或取消选择:

void C3DWidget::mousePressEvent(QMouseEvent *event)
{......else if(event->buttons() & Qt::LeftButton)  //鼠标左键选择模型{// 按下Shift键点击鼠标左键实现多选if(qApp->keyboardModifiers() == Qt::ShiftModifier){m_context->ShiftSelect(true);}else{m_context->Select(true);    // 单选模型}}......
}

程序效果:

更新:修改选择风格
通过获取并修改 AIS_InteractiveContext 对象的 SelectionStyle,可以配置模型选择后的显示风格

        // 设置选择模型的风格Handle(Prs3d_Drawer) t_select_style = m_context->SelectionStyle();  // 获取选择风格t_select_style->SetMethod(Aspect_TOHM_COLOR);  // 颜色显示方式t_select_style->SetColor(Quantity_NOC_LIGHTSEAGREEN);   // 设置选择后颜色t_select_style->SetDisplayMode(1); // 整体高亮t_select_style->SetTransparency(0.4f); // 设置透明度

模型被点击选择后,显示浅海绿色,并有一定的透明度

项目仓库

更多推荐

基于OpenCASCADE自制三维建模软件(九)选择物体

本文发布于:2024-03-07 16:40:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718350.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:建模   物体   软件   OpenCASCADE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!