MFC VS2010 Open CASCADE新建自己的工程

最近磕磕绊绊的去尝试用open cascade建立自己需要的工程文件,终于成功了,一直从网上获取方法,今天自己写一点心得,分享给大家。

 

一、准备:

1、安装 open cascade , 我安装后目录是: C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0 (注意这个是64bit的库),如果是其它目录,请在后续操作,做出对应调整。后面会用到的是lib、inc、src, 安装方法很简单,下载官网的安装包,直接安装就好,安装好后目录内容如下:

 

2、IDE使用的是:VS2010

 

二、建立MFC工程

建立工程可以参考这个网友的方法和流程:

http://www.zyh1690.org/used-in-the-mfc-opencascade-example/

2.1  点击VS的 文件 - 新建 - 项目, 输入工程名字“myBottle111”, 如下图

 

2.2 点确定后, 在弹出的界面, 点下一步,  选择单文档,  选择MFC标准, 然后点完成即可

 

2.3 设置工程为x64, 因为使用的lib和dll都是64位的, 点击VS的 项目 - 属性, 在弹出界面的右上角点击 “配置管理器”, 在弹出的界面,按照下图,点击“新建”

 

 

 

 

 

2.4 在弹出界面, 点击 确定

 

设置成功后,变成下图界面

 

2.5配置包含路径,  点击VS的项目 - 属性,  点右边的 配置属性 下一级的 “VC++目录”, 分别编辑 “包含目录”、“库目录”、“源目录”

依次各增加一个路径

“C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\inc”

“C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\win64\vc10\lib”

“C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\src”

 

 

三、编辑工程

3.1 在工程,解决方案视图,找到“stdafx.h” , 打开后, 添加以下头文件 


#pragma warning(  disable : 4244 )        // Issue warning 4244
#include "Standard_ShortReal.hxx"
#pragma warning(  default : 4244 )        // Issue warning 4244

#include <Standard.hxx>

#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Point.hxx>
#include <AIS_TextLabel.hxx>
#include <Aspect_Grid.hxx>
#include <Aspect_Window.hxx>
#include <Aspect_Background.hxx>

#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepAlgo.hxx>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepLib.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRepTools.hxx>
#include <Bnd_Box2d.hxx>
#include <BndLib.hxx>
#include <BndLib_Add2dCurve.hxx>
#include <BndLib_Add3dCurve.hxx>
#include <BndLib_AddSurface.hxx>   
#include <BRep_Tool.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepOffsetAPI_MakeThickSolid.hxx>

#include <BRepAlgoAPI_BuilderAlgo.hxx>

#include <Standard_NotImplemented.hxx>


#include <DsgPrs_LengthPresentation.hxx>
#include <FairCurve_Batten.hxx>
#include <FairCurve_MinimalVariation.hxx>

#include <GC_MakeCircle.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <GC_MakeTranslation.hxx>
#include <GC_MakeSegment.hxx>
#include <GC_MakeConicalSurface.hxx>
#include <Geom_ConicalSurface.hxx>
#include <GC_MakePlane.hxx>
#include <GC_MakeEllipse.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <GccAna_Circ2d2TanRad.hxx>
#include <GccAna_Lin2d2Tan.hxx>
#include <GccAna_Pnt2dBisec.hxx>
#include <GccEnt.hxx>
#include <GccEnt_QualifiedCirc.hxx>
#include <GccEnt_QualifiedLin.hxx>
#include <gce_MakeCirc2d.hxx>
#include <gce_MakeLin2d.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <GCE2d_MakeParabola.hxx>
#include <GCE2d_MakeEllipse.hxx>
#include <GCE2d_MakeArcOfCircle.hxx>
#include <GCE2d_MakeArcOfEllipse.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_CartesianPoint.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Line.hxx>
#include <Geom_Plane.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_Surface.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_Transformation.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_OffsetSurface.h

要在Visual Studio 2017中使用Open CASCADE(OCC)加载和显示STP文件,可按以下步骤操作: ### 1. 安装Open CASCADE 从OCC官网下载7.3.0的安装包,例如“opencascade-7.3.0-vc14-64.exe”。若官网下载慢且需注册,可直接找相应的资源包下载[^3]。 ### 2. 创建项目 打开VS2017,新建项目,选择MFC应用(若没有该选项,使用左下VS安装程序下载MFC板块),确定后选择单文档模式,完成项目创建。注意安装位置需为英文路径[^4]。 ### 3. 配置项目属性 - **包含目录**:在项目属性的“配置属性” -> “C/C++” -> “常规” -> “附加包含目录”中,添加Open CASCADE的头文件目录,如“C:\OpenCASCADE-7.3.0-vc14-64\opencascade-7.3.0\inc”。 - **库目录**:在“配置属性” -> “链接器” -> “常规” -> “附加库目录”中,添加Open CASCADE的库文件目录,如“C:\OpenCASCADE-7.3.0-vc14-64\opencascade-7.3.0\win64\vc14\lib”。 - **附加依赖项**:在“配置属性” -> “链接器” -> “输入” -> “附加依赖项”中,添加所需的Open CASCADE库文件,如“TKernel.lib”、“TKMath.lib”、“TKG2d.lib”、“TKG3d.lib”、“TKGeomBase.lib”、“TKTopAlgo.lib”、“TKSTEP.lib”等。 ### 4. 编写代码加载和显示STP文件 以下是一个简单的示例代码,用于加载和显示STP文件: ```cpp #include <Standard_Stream.hxx> #include <STEPControl_Reader.hxx> #include <TopoDS_Shape.hxx> #include <V3d_Viewer.hxx> #include <V3d_View.hxx> #include <AIS_Shape.hxx> #include <AIS_InteractiveContext.hxx> #include <WNT_Window.hxx> #include <Aspect_DisplayConnection.hxx> int main() { // 创建显示连接 Handle(Aspect_DisplayConnection) displayConnection = new Aspect_DisplayConnection(); // 创建查看器 Handle(V3d_Viewer) viewer = new V3d_Viewer(displayConnection); viewer->SetDefaultLights(); viewer->SetLightOn(); // 创建视图 Handle(V3d_View) view = viewer->CreateView(); view->SetBackgroundColor(Quantity_NOC_BLACK); // 创建交互式上下文 Handle(AIS_InteractiveContext) context = new AIS_InteractiveContext(viewer); // 读取STP文件 STEPControl_Reader reader; Standard_Integer status = reader.ReadFile("path_to_your_stp_file.stp"); if (status == IFSelect_RetDone) { reader.TransferRoots(); TopoDS_Shape shape = reader.OneShape(); // 创建AIS形状 Handle(AIS_Shape) aisShape = new AIS_Shape(shape); // 将形状添加到交互式上下文 context->Display(aisShape, Standard_True); } // 显示视图 view->FitAll(); view->Redraw(); // 进入消息循环 while (true) { view->Redraw(); } return 0; } ``` ### 5. 运行程序 将上述代码保存为`.cpp`文件,编译并运行程序,即可加载和显示指定的STP文件。
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值