当前位置: 首页 > news >正文

opencascade鼠标拖拽框选功能

1.首先在OccView中添加用于显示矩形框的类    

//! rubber rectangle for the mouse selection.Handle(AIS_RubberBand) mRectBand;

2.设置框选的属性

mRectBand = new AIS_RubberBand();
//设置属性
mRectBand->SetLineType(Aspect_TOL_SOLID); //设置变宽线型为实线
mRectBand->SetLineColor(Quantity_NOC_RED);

3.在鼠标移动的事件中添加新的事件

void OccView::mouseMoveEvent(QMouseEvent* theEvent)
{if ((theEvent->buttons() & Qt::LeftButton) && (theEvent->buttons() & Qt::RightButton)){//鼠标左右按键一起按,执行平移myView->Pan(theEvent->pos().x() - myXmax, myYmax - theEvent->pos().y());//沿视图投影的x和y轴平移视图中心,可用于交互式平移操作myXmax = theEvent->x();myYmax = theEvent->y();}else if (theEvent->buttons() & Qt::MiddleButton){//鼠标滚轮按键if (qApp->keyboardModifiers() == Qt::ShiftModifier) //且按下shift按键{//鼠标滚轮按键执行平移myView->Pan(theEvent->pos().x() - myXmax, myYmax - theEvent->pos().y());myXmax = theEvent->x();myYmax = theEvent->y();}else{myView->Rotation(theEvent->x(), theEvent->y());}}else if (theEvent->buttons() & Qt::LeftButton){//绘制选择框//获得视口尺寸int winViewWidth = 0;int winViewHeight = 0;myView->Window()->Size(winViewWidth, winViewHeight);//设置矩形边界mRectBand->SetRectangle(myXmax, winViewHeight - myYmax, theEvent->pos().x(), winViewHeight - theEvent->pos().y());//更新显示if (myContext->IsDisplayed(mRectBand)){myContext->Redisplay(mRectBand, true);}else{myContext->Display(mRectBand, true);}myContext->SelectRectangle(Graphic3d_Vec2i(myXmax, myYmax), Graphic3d_Vec2i(theEvent->pos().x(), theEvent->pos().y()), myView);}else{//将鼠标位置传递到交互环境myContext->MoveTo(theEvent->pos().x(), theEvent->pos().y(), myView, Standard_Boolean(true));}
}

4.在鼠标释放事件中清空框选

void OccView::mouseReleaseEvent(QMouseEvent* theEvent)
{std::cout << myContext->IsDisplayed(mRectBand) << std::endl;if (myContext->IsDisplayed(mRectBand)){myContext->Remove(mRectBand, Standard_True);myView->Update();}//将鼠标位置传递到交互环境myContext->MoveTo(theEvent->pos().x(), theEvent->pos().y(), myView, Standard_Boolean(true));
}

效果图:

http://www.lryc.cn/news/457108.html

相关文章:

  • docker 部署 postgres
  • 【重学 MySQL】五十、添加数据
  • 硬货!Zabbix监控AIX系统服务案例
  • python常见面试题
  • 低功耗接地故障控制器D4145
  • SpringMVC的处理流程
  • SpringBoot统一日志框架
  • vue-live2d看板娘集成方案设计使用教程
  • springboot接口如何支持400并发量
  • Verilog中的: `+:` 和 `-:`
  • 为何四次挥手要等待2MSL
  • C++——模拟实现list
  • React中useState、useReducer与useRef
  • ReGCL Rethinking Message Passingin Graph Contrastive Learning
  • ubutun安装ffmpeg
  • Vue的基本用法及模板语法
  • Redis数据库与GO完结篇:redis操作总结与GO使用redis
  • 《重生到现代之从零开始的C语言生活》—— 动态内存管理
  • 四、Spring Boot集成Spring Security之登录登出业务逻辑
  • pipe和pipefd
  • 无人机之飞控仿真技术篇
  • Tetra Pak利乐触摸屏维修beijer北尔触摸屏维修E1151
  • Python_网络编程(IP 端口 协议)
  • Adobe Acrobat提示“3D数据解析错误”
  • 红帽7—Mysql路由部署
  • LLM4Rec最新工作: 字节发布用于序列推荐的分层大模型HLLM
  • 怎么高效对接SaaS平台数据?
  • Spark算子使用-Map,FlatMap,Filter,diatinct,groupBy,sortBy
  • CSS响应式布局
  • AI大模型书籍丨掌握 LLM 和 RAG 技术,这本大模型小鸟书值得一看!