【OCC新建一个单文档】opencascade-7.1.0 + VS2015 配置

1、下载OCC源码包+

动态库一般在:C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\win64\vc10\bin

 

2、打开VS2015,创建单文档,配置环境

 (1)C/C++->常规->附加包含目录,添加C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\src C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\inc

CCEX âÔfi XML sp€(p): nCASCADE7.1.o-vc10-64\o I. O-vcl 0-64\opencascade-7. I. O\src I. O-vcl 0-64\opencascade-7. I. nc ncascade-7. I nCAS

 

(2)链接器->常规->附加库目录,添加C:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\win64\vc10\libdC:\OpenCASCADE7.1.0-vc10-64\opencascade-7.1.0\win64\vc10\lib

3、在stdafx.h上添加OCC的头文件

#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 《V3d_Viewer.hxx》
#include 《V3d_View.hxx》
#include 《WNT_Window.hxx》
#include 《Standard_ErrorHandler.hxx》
#include 《BRepPrimAPI_MakeBox.hxx》
#include 《BRepPrimAPI_MakeCylinder.hxx》
#include 《BRepPrimAPI_MakeSphere.hxx》
#include 《BRepBuilderAPI_MakeVertex.hxx》
#include 《BRepPrimAPI_MakeCone.hxx》
#include 《BRepBuilderAPI_MakeEdge.hxx》
#include 《BRepBuilderAPI_MakeFace.hxx》
#include 《gp_Trsf.hxx》
#include 《gp_Dir.hxx》
#include 《gp_Pnt.hxx》
#include 《gp_Ax2.hxx》
#include 《ProjLib.hxx》
#include 《ElSLib.hxx》
#include 《gp_Pln.hxx》
#include 《V3d_Plane.hxx》
#include 《gp_Trsf.hxx》
#include 《UnitsAPI.hxx》
#include 《BRepBuilderAPI_NurbsConvert.hxx》
#include 《Aspect_PolygonOffsetMode.hxx》
#include 《AIS_ListOfInteractive.hxx》
#include 《AIS_ListIteratorOfListOfInteractive.hxx》
#include 《BRepFilletAPI_MakeFillet.hxx》
#include 《Geom_Circle.hxx》
#include 《AIS_Circle.hxx》
#include 《AIS_Line.hxx》
#include 《Geom_Line.hxx》
#include 《Prs3d_Drawer.hxx》
#include 《TopoDS.hxx》
#include 《Prs3d_IsoAspect.hxx》
#include 《Prs3d_ShadingAspect.hxx》
#include 《Geom_Surface.hxx》
#include 《Geom_Plane.hxx》
#include 《BRep_Tool.hxx》
#include 《Geom_TrimmedCurve.hxx》
#include 《GC_MakeArcOfCircle.hxx》
#include 《GC_MakeSegment.hxx》
#include 《BRepBuilderAPI_MakeWire.hxx》
#include 《BRepBuilderAPI_Transform.hxx》
#include 《BRepPrimAPI_MakePrism.hxx》
#include 《BRepOffsetAPI_ThruSections.hxx》
#include 《GCE2d_MakeSegment.hxx》
#include 《TopExp_Explorer.hxx》
#include 《BRepAlgoAPI_Fuse.hxx》
#include 《BRepOffsetAPI_MakeThickSolid.hxx》
#include 《Geom_CylindricalSurface.hxx》
#include 《BRepLib.hxx》
#include 《BRep_Tool.hxx》
#include 《BRepAlgoAPI_Fuse.hxx》
#include 《BRepBuilderAPI_MakeEdge.hxx》
#include 《BRepBuilderAPI_MakeFace.hxx》
#include 《BRepBuilderAPI_MakeWire.hxx》
#include 《BRepBuilderAPI_Transform.hxx》
#include 《BRepFilletAPI_MakeFillet.hxx》
#include 《BRepLib.hxx》
#include 《BRepOffsetAPI_MakeThickSolid.hxx》
#include 《BRepOffsetAPI_ThruSections.hxx》
#include 《BRepPrimAPI_MakeCylinder.hxx》
#include 《BRepPrimAPI_MakePrism.hxx》
#include 《GC_MakeArcOfCircle.hxx》
#include 《GC_MakeSegment.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 《TopTools_ListOfShape.hxx》

添加完以后,会报错“max”未申明。

扫描二维码关注公众号,回复: 1634990 查看本文章

将max改为std::max即可。

4、添加设置OpenCasCade的图形设备环境变量

1在APP类的头文件中


#include 《Standard_Macro.hxx》


#include 《Graphic3d_GraphicDriver.hxx》


 

Standard_Macro.hxx: This file is intended to be the first file #included to any Open CASCADE source. It defines platform-specific pre-processor macros necessary for correct compilation of Open CASCADE code.

Graphic3d_GraphicDriver.hxx:This class allows the definition of a graphic driver (currently only OpenGL driver is used).

 

来自 <</span>http://www.predream.org/show-113-1114-1.html>

 

public:

Handle(Graphic3d_GraphicDriver) myGraphicDriver;

Handle(Graphic3d_GraphicDriver) GetGraphicDriver()const { return  myGraphicDriver; }

 

  afx_msg void OnStereo();

  afx_msg void OnUpdateStereo (CCmdUI* theCmdUI);

2在APP类的文件中

            在APP类的构造函数中完成对设备环境生成和初始化

  try

  {

    Handle(Aspect_DisplayConnection) aDisplayConnection;

    myGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);

  }

  catch(Standard_Failure)

  {

    AfxMessageBox (L"Fatal error during graphic initialization", MB_ICONSTOP);

    ExitProcess (1);

  }

 

遇到如下错误

try aDispIayConnection; myGraphicDriver z new ; catch (Standard _ Failure) error during graphic initialization', ExitProcess(I); MB ICONS

 

解决:在cpp中添加#include

 

后又出现

超过了 PCH 的虚拟内存范围;请使用“-Zm120”或更大的命令行选项重新编译

 

该错误是因为虚拟内存范围不够造成的,点击项目属性-》配置属性-c/c++-》命令行

右侧附加选项输入/Zm300.

 

再次出现错误:

 

error C2661: “Standard_Transient::operator new”: 没有重载函数接受 3 个参数

原因是因为OpenCascade对new操作符进行了重载,与VS中的定义存在冲突,屏蔽CPP文件前面的以下代码就可以解决了。

 

 

 

#ifdef _DEBUG

 

#endif

后面OpenCascade使用new操作符的地方,都需同样的方法解决。更多请阅读:http://www.opencascade.org/org/forum/thread_14858/?forum=3

 

 

5在Document类中添加OpenCasCade间接设备环境和图形接口

 

 

在Doc类的头文件中添加OpenCasCade成员变量和方法:

//OCC

public:

Handle(AIS_InteractiveContext)& GetAISContext() { return myAISContext; }

Handle(V3d_Viewer) GetViewer() { return myViewer; }

 

protected:

Handle(V3d_Viewer) myViewer;

Handle(AIS_InteractiveContext) myAISContext;

 

接着在Doc类的构造函数中完成对OpenCasCade变量初始化设置:

void COCCEXDoc::InitBackGround()

{

Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((COCCEXApp*)AfxGetApp())->GetGraphicDriver();

 

//TCollection_ExtendedString a3DName("Visu3D");

myViewer = new V3d_Viewer(aGraphicDriver);

 

myViewer->SetDefaultLights();

myViewer->SetLightOn();

//myViewer->SetDefaultBackgroundColor(Quantity_NOC_BLUE1);//改变背景颜色

 

myAISContext = new AIS_InteractiveContext(myViewer);   //创建一个交互文档

myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(11);

myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(11);

 

//这里设置实体的显示模式

myAISContext->SetDisplayMode(AIS_Shaded, Standard_False);

}

 

InitBackGround添加在构造函数中。

 

6View类中的OpenCasCade变量设置以及图形显示设置

 

CneedAVDoc::CneedAVDoc()

{

// TODO: 在此添加一次性构造代码

Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((CTest2App*)AfxGetApp())->GetGraphicDriver();

 

TCollection_ExtendedString a3DName("Visu3D");

myViewer = new V3d_Viewer(aGraphicDriver,a3DName.ToExtString());

 

myViewer->SetDefaultLights();

myViewer->SetLightOn();

//myViewer->SetDefaultBackgroundColor(Quantity_NOC_BLUE1);//改变背景颜色

 

myAISContext =new AIS_InteractiveContext(myViewer);  //创建一个交互文档(没有他无法显示图像)

myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(11);

myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(11);

 

//这里设置实体的显示模式

myAISContext->SetDisplayMode(AIS_Shaded,Standard_False);

}

 

第四步:View类中的OpenCasCade变量设置以及图形显示设置

添加变量:

1

2

3

private:

Handle_V3d_View myView;

Standard_Boolean myHlrModeIsOn;

重写 OnInitialUpdate() 函数,添加如下代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

void COCCEXView::OnInitialUpdate()

{

CView::OnInitialUpdate();

 

myView =((COCCEXDoc*)GetDocument())->GetViewer()->CreateView();

myHlrModeIsOn = Standard_False;

myView -> SetComputedMode(myHlrModeIsOn);

Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((CneedAVApp*)AfxGetApp())->GetGraphicDriver();

Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd());  

myView->SetWindow(aWNTWindow);

 

if (!aWNTWindow->IsMapped()) aWNTWindow->Map();

aWNTWindow->SetBackground(Quantity_NOC_SLATEBLUE2);

// TODO: 在此添加专用代码和/或调用基类

}

在OnDraw函数中添加OpenCasCade的重绘代码:

1

2

3

4

5

6

7

8

9

10

void COCCEXView::OnDraw(CDC* )

{

COCCEXDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

if (!pDoc)

return;

 

myView->Redraw();

// TODO: 在此处为本机数据添加绘制代码

}


猜你喜欢

转载自blog.csdn.net/eric_e/article/details/80721766