OpenCasCade(OCC) Select 3D model

1. Select the face of the imported model to define the mouse event in the message of XXXView.cpp
2. You need to slightly change the display mode of the imported model

//在导入模型时显示的状态有所更改
//其中 1 代表 不是线框模式
//其中 3 代表 TopAbs_Solid	
anAIScontext->Display(ais,1,3,Standard_True,Standard_True,AIS_DS_Displayed);

3. First, you need to realize the display of the mouse to the model

//OnMouseMove中的部分代码
//获取上下文的对象
	Handle(AIS_InteractiveContext) ais = GetDocument()->GetIC();
//使得对象在移动的时候,选中
	ais->MoveTo(point.x,point.y,myView,Standard_True);
//选中后的显示状态的更改
	Handle(Prs3d_Drawer) t_hilight_style = ais->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); // 设置透明度
	ais->SetSelectionStyle(t_hilight_style);

4. Secondly, to define the event of the left mouse button press, the selected stay can be realized

//OnLButtonDown中的部分代码
	Handle(AIS_InteractiveContext) ais = GetDocument()->GetIC();
	ais->Select(Standard_True);//实现单选的功能

Guess you like

Origin blog.csdn.net/qq_40247982/article/details/106128471