目录
实现鼠标左键点选模型的点、线、面并高亮显示,实现过程如下:
- //交互式上下文
- context = new AIS_InteractiveContext(viewer);
- context->SetDisplayMode(AIS_Shaded, Standard_True);
- //高亮颜色和模式
- context->HighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic)->SetColor(Quantity_NameOfColor::Quantity_NOC_RED);
- context->HighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic)->SetMethod(Aspect_TOHM_COLOR);
- context->HighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic)->SetDisplayMode(1);
- context->HighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic)->SetTransparency(0.5f);
-
- void Displaywin::selectMode(Handle(AIS_Shape) selectmode)
- {
- //激活将形状分解为Any
- context->Deactivate();
- const int aSubShapeSelMode = AIS_Shape::SelectionMode(TopAbs_FACE);
- context->Activate(selectmode, aSubShapeSelMode);
- context->Activate(selectmode, AIS_Shape::SelectionMode(TopAbs_SOLID));
- context->Activate(selectmode, AIS_Shape::SelectionMode(TopAbs_VERTEX));
- context->Activate(selectmode, AIS_Shape::SelectionMode(TopAbs_EDGE));
- }
-
- void Displaywin::mousePressEvent(QMouseEvent* event)
- {
- //平移 鼠标右键+shift
- if ((event->buttons() & Qt::RightButton))//&& (QApplication::keyboardModifiers() == Qt::ShiftModifier))
- {
- m_mode = Action3d_Panning;
- m_x = event->pos().x();
- m_y = event->pos().y();
- }
- else if (event->buttons() & Qt::LeftButton)//选择
- {
- context->MoveTo(event->pos().x(), event->pos().y(), view, true);
- }
- else if (event->buttons() & Qt::MidButton)//旋转
- {
- m_mode = Action3d_Rotation;
- //开始旋转视图围绕屏幕轴
- view->StartRotation(event->pos().x(), event->pos().y());
- }
- }
-
void Mainwin::trigerdrawbox(){ TopoDS_Shape box = occ.createBox(); Handle(AIS_Shape) aisBox = new AIS_Shape(box); Dui->GetInteractiveContext()->EraseAll(Standard_True); Dui->GetInteractiveContext()->Display(aisBox, Standard_True); Dui->GetView()->FitAll(); Dui->selectMode(aisBox); }


