本文主要是介绍OCC笔记:选择TopoDS_Shape顶点、边、面等等,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、通过AIS_InteractiveContext的函数访问当前选择的图形
hAISContext->InitSelected();
hAISContext->MoreSelected();
hAISContext->NextSelected();
hAISContext->SelectedShape();
其中hAISContext->SelectedShape()通过StdSelect_BrepOwner来获取TopoDS_Shape,具体的参看源码即可
2、示例
-
绘制一个box,并激活box的顶点、边、面的选择模式
//create box for testBRepPrimAPI_MakeBox mkBox(gp_Pnt(0, 0, 0), 10, 20, 30);TopoDS_Shape aShpae = mkBox.Shape();Handle(AIS_Shape) hBoxShape = new AIS_Shape(aShpae);myAISContext->Display(hBoxShape, Standard_True);myAISContext->Deactivate(hBoxShape);myAISContext->Activate(hBoxShape, AIS_Shape::SelectionMode(TopAbs_FACE));myAISContext->Activate(hBoxShape, AIS_Shape::SelectionMode(TopAbs_EDGE));myAISContext->Activate(hBoxShape, AIS_Shape::SelectionMode(TopAbs_VERTEX));
-
选择的处理
void COCTView::OnBtnTestSelect() {auto hAISContext = GetDocument()->GetAISContext();if (!hAISContext){return;}for (hAISContext->InitSelected(); hAISContext->MoreSelected();hAISContext->NextSelected()){TopoDS_Shape aShape = hAISContext->SelectedShape();if (aShape.IsNull()) continue;switch (aShape.ShapeType()){case TopAbs_ShapeEnum::TopAbs_VERTEX:{TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);AfxMessageBox(_T("选中一个点"));break;}case TopAbs_ShapeEnum::TopAbs_EDGE:{AfxMessageBox(_T("选中一条边"));break;}case TopAbs_ShapeEnum::TopAbs_FACE:{AfxMessageBox(_T("选中一个面"));break;}//其他略}} }
3、演示
这篇关于OCC笔记:选择TopoDS_Shape顶点、边、面等等的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!