OpenCASCADE(OCC) 实现模型线框和实体显示模式的切换以及视角的自由切换——工具栏按钮版(线框显示、实体显示、上、下、左、右、前、后 的切换)

添加按钮事件

找到*****View类,右击属性,添加之前定义好的按钮命令函数(add Command):

 逐个添加完命令之后,*****View.h中会出现这几个消息函数:

 分别对它们进行实现;

//模型切换为线框模式
void COCCmfcMDIView::OnButtonWire()
{
	// TODO: 在此添加命令处理程序代码
	//AfxMessageBox(_T("您按下了 ButtonWire 按钮"));
	COCCmfcMDIDoc* pDoc = GetDocument();
	pDoc->myAISContext->SetDisplayMode(AIS_WireFrame, true);  //设置显示模式为网状体
}


//模型切换为实体模式
void COCCmfcMDIView::OnButtonShape()
{
	// TODO: 在此添加命令处理程序代码
	//AfxMessageBox(_T("您按下了 ButtonShape 按钮"));
	COCCmfcMDIDoc* pDoc = GetDocument();
	pDoc->myAISContext->SetDisplayMode(AIS_Shaded, true);   //设置显示模式为实体
}


//切换为模型的上部视角
void COCCmfcMDIView::OnButtonUp()
{
	// TODO: 在此添加命令处理程序代码
	myView->SetProj(V3d_Zpos);
	myView->FitAll();
}

//切换为模型的底部视角
void COCCmfcMDIView::OnButtonBottom()
{
	// TODO: 在此添加命令处理程序代码
	myView->SetProj(V3d_Zneg);
	myView->FitAll();

}

//切换为模型的左侧视角
void COCCmfcMDIView::OnButtonLeft()
{
	// TODO: 在此添加命令处理程序代码
	myView->SetProj(V3d_Xneg);
	myView->FitAll();

}

//切换为模型的右侧视角
void COCCmfcMDIView::OnButtonRight()
{
	// TODO: 在此添加命令处理程序代码
	myView->SetProj(V3d_Xpos);
	myView->FitAll();

}

//切换为模型的前面视角
void COCCmfcMDIView::OnButtonFront()
{
	// TODO: 在此添加命令处理程序代码
	myView->SetProj(V3d_Yneg);
	myView->FitAll();

}

//切换为模型的后面视角
void COCCmfcMDIView::OnButtonBack()
{
	// TODO: 在此添加命令处理程序代码
	myView->SetProj(V3d_Ypos);
	myView->FitAll();
}

运行结果》》

 

 

 

 

 

 

 

 

至此,我自定义的八个工具栏按钮功能全部实现,并且亲测成果!!!!

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要加载并显示 OCC 模型,您需要使用 OpenSceneGraph(OSG)和 OpenCASCADEOCC),并将它们集成在一起。以下是加载 OCC 模型并在 OSG 中显示的基本步骤: 1. 安装 OSG 和 OCC 并将其设置为您的项目依赖项。 2. 使用 OCC API 加载模型并将其转换为 OSG 几何体。 ```cpp #include <OpenCASCADE/TopoDS.hxx> #include <OpenCASCADE/BRepTools.hxx> #include <OpenCASCADE/IGESControl_Reader.hxx> #include <osg/Geometry> #include <osg/Geode> osg::ref_ptr<osg::Node> loadOCCModel(const std::string& fileName) { // Step 1: Load the model using OCC API TopoDS_Shape shape; IGESControl_Reader reader; reader.ReadFile(fileName.c_str()); reader.TransferRoots(); shape = reader.OneShape(); // Step 2: Convert the OCC geometry to OSG geometry osg::ref_ptr<osg::Geode> geode = new osg::Geode; BRepTools::Clean(shape); BRepTools::Update(shape); TopExp_Explorer exp(shape, TopAbs_FACE); while (exp.More()) { TopoDS_Face face = TopoDS::Face(exp.Current()); Handle(Geom_Surface) surface = BRep_Tool::Surface(face); if (!surface.IsNull()) { // Create OSG geometry from OCC surface osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; // Add vertices to the geometry // ... // Add primitives to the geometry // ... geode->addDrawable(geom); } exp.Next(); } return geode; } ``` 3. 将 OSG 几何体添加到场景图中并显示。 ```cpp #include <osgViewer/Viewer> int main(int argc, char** argv) { // Create the viewer osgViewer::Viewer viewer; // Load the model and add it to the scene osg::ref_ptr<osg::Node> model = loadOCCModel("model.igs"); viewer.setSceneData(model); // Start the viewer return viewer.run(); } ``` 这只是一个基本示例,您可能需要根据您的要求进行适当的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值