基于VS2015的openCANSCADE的开发环境的搭建

基于VS2015的openCANSCADE的开发环境的搭建

一、准备工作

1.软件的下载

下载opencascade:链接:https://pan.baidu.com/s/1_AEKIqh7dNydOO7SsCIQXA
提取码:dukl(建议安装在VS文件夹中),安装完成后是这样的。在这里插入图片描述VS2015可以微信中软件管家中下载按着步骤安装破解,VS2015:链接:https://pan.baidu.com/s/1CYSjQTO4Ifjy4X3NYFojuQ
提取码:eixm

2.配置OpenCASCADE系统环境

方法一:将安装的OpenCASCADE中所有的bin文件夹都添加到环境变量里(准确的说把有.dll文件存在的文件夹都添加进去,最好一个一个文件夹)
在这里插入图片描述
然后在将bin文件夹内的dll文件全部复制一份放在C:\Windows\SysWOW64里(注意我这里是64位的)你们32就放32里
方法二:将所有的 .dll文件复制到一个文件夹中将这个文件夹添加到环境变量,像我这样一个文件夹即可(推荐)
在这里插入图片描述
设置完毕后对电脑进行重启!!!!!!!!!!!!

二、开始建工程啦

在VS2015中创建一个单文档MFC项目,我的命名是OCCmfc(这个名字你可以自己设置)
项目->属性按照我给的红箭的地方进行更改(看图)
在这里插入图片描述
然后在连接器->输入->附加依赖项里添加下面这些Lib文件名:
在这里插入图片描述

TKBin.lib
TKBinL.lib
TKBinTObj.lib
TKBinXCAF.lib
TKBO.lib
TKBool.lib
TKBRep.lib
TKCAF.lib
TKCDF.lib
TKD3DHost.lib
TKDCAF.lib
TKDFBrowser.lib
TKDraw.lib
TKernel.lib
TKFeat.lib
TKFillet.lib
TKG2d.lib
TKG3d.lib
TKGeomAlgo.lib
TKGeomBase.lib
TKHLR.lib
TKIGES.lib
TKIVtk.lib
TKIVtkDraw.lib
TKLCAF.lib
TKMath.lib
TKMesh.lib
TKMeshVS.lib
TKOffset.lib
TKOpenGl.lib
TKPrim.lib
TKQADraw.lib
TKRWMesh.lib
TKService.lib
TKShapeView.lib
TKShHealing.lib
TKStd.lib
TKStdL.lib
TKSTEP.lib
TKSTEP209.lib
TKSTEPAttr.lib
TKSTEPBase.lib
TKSTL.lib
TKTInspector.lib
TKTInspectorAPI.lib
TKTObj.lib
TKTObjDRAW.lib
TKToolsDraw.lib
TKTopAlgo.lib
TKTopTest.lib
TKTreeModel.lib
TKV3d.lib
TKVCAF.lib
TKView.lib
TKViewerTest.lib
TKVInspector.lib
TKVRML.lib
TKXCAF.lib
TKXDEDRAW.lib
TKXDEIGES.lib
TKXDESTEP.lib
TKXMesh.lib
TKXml.lib
TKXmlL.lib
TKXmlTObj.lib
TKXmlXCAF.lib
TKXSBase.lib
TKXSDRAW.lib

如果你们版本跟我的不一样 那么可以在cmd里打开到这个文件夹然后输入命令 dir /b>libName.txt(可以试试 我当时没有成功)

然后打开这个文件,复制lib的名字就行了

然后打开项目后在stdafx.h中添加这些要用到的头文件:

#include <BRepTools.hxx>  
#include <Standard_DefineHandle.hxx>  
#include <DsgPrs_LengthPresentation.hxx>  
#include <GCPnts_TangentialDeflection.hxx>  
#include <Geom_Axis2Placement.hxx>  
#include <Geom_CartesianPoint.hxx>  
#include <Geom_Line.hxx>  
#include <Geom_Surface.hxx>  
#include <BRepAdaptor_Surface.hxx>  
#include <GeomAbs_CurveType.hxx>  
#include <GeomAdaptor_Curve.hxx>  
#include <GeomTools_Curve2dSet.hxx>  
#include <gp_Vec.hxx>  
#include <Graphic3d_NameOfMaterial.hxx>  
#include <MMgt_TShared.hxx>  
#include <OSD_Environment.hxx>  
#include <Precision.hxx>  
#include <Prs3d_IsoAspect.hxx>  
#include <Prs3d_LineAspect.hxx>  
#include <Prs3d_Projector.hxx>  
#include <Prs3d_Text.hxx>  
#include <Quantity_Factor.hxx>  
#include <Quantity_Length.hxx>  
#include <Quantity_NameOfColor.hxx>  
#include <Quantity_PhysicalQuantity.hxx>  
#include <Quantity_PlaneAngle.hxx>  
#include <Quantity_TypeOfColor.hxx>  
#include <SelectMgr_EntityOwner.hxx>  
#include <SelectMgr_SelectableObject.hxx>  
#include <SelectMgr_Selection.hxx>  
#include <SelectMgr_SelectionManager.hxx>  
#include <SelectMgr_ListOfFilter.hxx>  
#include <SelectMgr_Filter.hxx>  
#include <StdSelect_EdgeFilter.hxx>  
#include <StdSelect_ShapeTypeFilter.hxx>  
#include <Standard_Boolean.hxx>  
#include <Standard_CString.hxx>  
#include <Standard_ErrorHandler.hxx>  
#include <Standard_Integer.hxx>  
#include <Standard_IStream.hxx>  
#include <Standard_Macro.hxx>  
#include <Standard_NotImplemented.hxx>  
#include <Standard_OStream.hxx>  
#include <Standard_Real.hxx>  
#include <StdPrs_Curve.hxx>  
#include <StdPrs_Point.hxx>  
#include <StdPrs_PoleCurve.hxx>  
#include <TCollection_AsciiString.hxx>  
#include <TColgp_Array1OfPnt2d.hxx>  
#include <TColgp_HArray1OfPnt2d.hxx>  
#include <TCollection_AsciiString.hxx>  
#include <TColStd_HSequenceOfTransient.hxx>  
#include <TColStd_MapIteratorOfMapOfTransient.hxx>  
#include <TColStd_MapOfTransient.hxx>  
#include <TopExp_Explorer.hxx>  
#include <TopoDS.hxx>  
#include <TopoDS_Compound.hxx>  
#include <TopoDS_Shape.hxx>  
#include <TopoDS_Solid.hxx>  
#include <TopoDS_Vertex.hxx>  
#include <TopExp.hxx>  
#include <TopTools_HSequenceOfShape.hxx>  
#include <UnitsAPI.hxx>  
#include <V3d_View.hxx>  
#include <V3d_Viewer.hxx>  
#include <WNT_Window.hxx>  
#include <Prs3d_PointAspect.hxx>  
#include <AIS_Point.hxx>  
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <BRep_Tool.hxx>  
#include <BRepAlgoAPI_Fuse.hxx>  
#include <BRepBuilderAPI_MakeEdge.hxx>  
#include <BRepBuilderAPI_MakeFace.hxx>  
#include <BRepBuilderAPI_MakeWire.hxx>  
#include <BRepBuilderAPI_MakeVertex.hxx>  
#include <BRepBuilderAPI_Transform.hxx>  
#include <BRepPrimAPI_MakeCone.hxx>  
#include <BRepPrimAPI_MakeRevol.hxx>  
#include <BRepFilletAPI_MakeFillet.hxx>  
#include <BRepBuilderAPI_Copy.hxx>  
#include <BRepBuilderAPI_MakePolygon.hxx>  
#include <BRepLib.hxx>  
#include <BRepOffsetAPI_MakeThickSolid.hxx>  
#include <BRepOffsetAPI_ThruSections.hxx>  
#include <BRepPrimAPI_MakeCylinder.hxx>  
#include <BRepPrimAPI_MakePrism.hxx>  
#include <BRepPrimAPI_MakeTorus.hxx>  
#include <BRepAlgoAPI_Section.hxx>  
#include <BRepPrimAPI_MakeSphere.hxx>  
#include <BRepFeat_SplitShape.hxx>  
#include <TColgp_HArray1OfPnt.hxx>  
#include <GeomAPI_Interpolate.hxx>  
#include <GC_MakeArcOfCircle.hxx>  
#include <GC_MakeSegment.hxx>  
#include <GC_MakeCircle.hxx>  
#include <GCE2d_MakeSegment.hxx>  
#include <gp.hxx>  
#include <gp_Ax1.hxx>  
#include <gp_Ax2.hxx>  
#include <gp_Ax2d.hxx>  
#include <gp_Dir.hxx>  
#include <gp_Dir2d.hxx>  
#include <gp_Pnt.hxx>  
#include <gp_Pnt2d.hxx>  
#include <gp_Trsf.hxx>  
#include <gp_Vec.hxx>  
#include <Geom_CylindricalSurface.hxx>  
#include <Geom_Plane.hxx>  
#include <Geom_Surface.hxx>  
#include <Geom_TrimmedCurve.hxx>  
#include <Geom2d_Ellipse.hxx>  
#include <Geom2d_TrimmedCurve.hxx>  
#include <TopExp_Explorer.hxx>  
#include <TopoDS.hxx>  
#include <TopoDS_Edge.hxx>  
#include <TopoDS_Face.hxx>  
#include <TopoDS_Wire.hxx>  
#include <TopoDS_Shape.hxx>  
#include <TopoDS_Compound.hxx>  
#include <GCPnts_AbscissaPoint.hxx>  
#include <BRepAdaptor_Curve.hxx>  
#include <GeomLib.hxx>  
#include <GeomConvert_CompCurveToBSplineCurve.hxx>  
#include <TopTools_ListOfShape.hxx>  
#include <TopTools_ListIteratorOfListOfShape.hxx>  
#include <TopTools_DataMapOfShapeInteger.hxx>  
#include <TopTools_DataMapOfShapeReal.hxx>  
#include <TopTools_IndexedDataMapOfShapeAddress.hxx>  
#include <V3d_PositionalLight.hxx>  
#include <V3d_DirectionalLight.hxx>  
#include <V3d_AmbientLight.hxx>  
#include <IGESControl_Controller.hxx>  
#include <IGESControl_Writer.hxx>  
#include <Interface_Static.hxx>  
#include <OpenGl_GraphicDriver.hxx>  
#include <Graphic3d_GraphicDriver.hxx>

然后在OCCmfc.h文件的类里添加:

Handle(Graphic3d_GraphicDriver) m_GraphicDriver;
Handle(Graphic3d_GraphicDriver) GetGraphicDriver() { return m_GraphicDriver; }
在这里插入图片描述
和头文件

#include <Standard_Macro.hxx>
#include <Graphic3d_GraphicDriver.hxx>
**在OCCmfc.cpp的构造函数里加上:

try {
        Handle(Aspect_DisplayConnection) aDisplayConnection;
        m_GraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
    }
    catch (Standard_Failure) {
        AfxMessageBox(L"(Error Ocured in Initializing the Opencascade graphic variable.)");
    }`**

注意!!!如果new字符报错,那么是因为opencascade对new进行了重载,我们将每个new报错文件顶部的:

#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif`   

注释了就行

接着在OCCmfcDoc.h文件类里添加:

Handle(AIS_InteractiveContext) myAISContext;  
Handle(V3d_Viewer) myViewer;  
Handle(V3d_Viewer) GetViewer(void) {return myViewer;}

欢迎使用Mardown编辑器

你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。
在这里插入图片描述

接着去实现文档OCCmfcDoc.cpp中类的构造函数中添加:

Handle(Graphic3d_GraphicDriver) theGraphicDriver = ((CmOCCTApp*)AfxGetApp())->GetGraphicDriver();

    myViewer = new V3d_Viewer(theGraphicDriver);
    myViewer->SetDefaultLights();
    myViewer->SetLightOn();

    myAISContext = new AIS_InteractiveContext(myViewer);

    myAISContext->SetDisplayMode(AIS_Shaded,true);
    myAISContext->SetAutomaticHilight(Standard_False);

在这里插入图片描述
然后去去OCCmfcView.h定义类里添加:

Handle(V3d_View) myView;

并添加这个函数

virtual void OnInitialUpdate();

在这里插入图片描述
然后去OCCmfcView.cpp文件里添加下面这个实现函数(随便添加在哪里):

void COCCmfcView::OnInitialUpdate()

{

    CView::OnInitialUpdate();



    myView = GetDocument()->GetViewer()->CreateView();
    myView->SetShadingModel(V3d_GOURAUD);
    Handle(Graphic3d_GraphicDriver) theGraphicDriver = ((COCCmfcApp*)AfxGetApp())->GetGraphicDriver();
    Aspect_Handle aWindowHandle = (Aspect_Handle)GetSafeHwnd();
    Handle(WNT_Window) aWntWindow = new WNT_Window(GetSafeHwnd());
    myView->SetWindow(aWntWindow);
    if (!aWntWindow->IsMapped()) {
        aWntWindow->Map();
    }
    Standard_Integer w = 100;
    Standard_Integer h = 100;
    aWntWindow->Size(w, h);
    ::PostMessage(GetSafeHwnd(), WM_SIZE, SIZE_RESTORED, w + h * 65536);
    myView->FitAll();

    myView->ZBufferTriedronSetup(Quantity_NOC_RED, Quantity_NOC_GREEN, Quantity_NOC_BLUE1, 0.8, 0.05, 12);
    myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.2, V3d_ZBUFFER);
}

然后在这个文件中的OnDraw()函数中添加:

myView->MustBeResized();  
myView->Update();  

在这里插入图片描述
编译运行:
在这里插入图片描述
想要绘制图形参考:https://www.cnblogs.com/DOMLX/p/12368154.html
若有错误请在评论区留言!!!!!!!!

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值