http://www.opencascade.org/getocc/download/loadocc/
http://www.opencascade.org/getocc/download/loadocc/
OpenCASCADExxx.exe > C:\OpenCASCADEx.x.x
OCCTDocumentationxxx.exe > C:\OCCTDocumentationx.x.x
双击 C:\OpenCASCADE6.5.4\ros\env.bat 重启电脑
C:\OpenCASCADEx.x.x\ros\inc 中所有文件复制到:X:\Program Files\Microsoft Visual Studio xx.0\VC\include
C:\OpenCASCADEx.x.x\ros\win32\vc9\lib 中所有文件复制到:C:\Program Files\Microsoft Visual Studio xx.0\VC\lib
C:\OpenCASCADEx.x.x\ros\win32\vc9\bin 中所有文件复制到:C:\Windows\System32
说明:用复制的方法可以省略VS中的部分配置工作,在OpenCASCADE版本升级之后要重新手动覆盖
VS20xx新建MFC 单文档工程MyOcc。
(VS2012)工程右键 > 属性 > 配置属性 > C/C++ > 命令行 > 输入:/DWNT
(VS2008)工程右键 > 属性 > 配置属性 > Linker > Input > Additional Dependencies > 输入:
(VS2012)工程右键 > 属性 > 配置属性 > 链接器 > 输入 > 附加依赖项 > 输入:
DRAWEXE.lib
FWOSPlugin.lib
PTKernel.lib
TKAdvTools.lib
TKBin.lib
TKBinL.lib
TKBinTObj.lib
TKBinXCAF.lib
TKBO.lib
TKBool.lib
TKBRep.lib
TKCAF.lib
TKCDF.lib
TKDCAF.lib
TKDraw.lib
TKernel.lib
TKFeat.lib
TKFillet.lib
TKG2d.lib
TKG3d.lib
TKGeomAlgo.lib
TKGeomBase.lib
TKHLR.lib
TKIGES.lib
TKLCAF.lib
TKMath.lib
TKMesh.lib
TKMeshVS.lib
TKNIS.lib
TKOffset.lib
TKOpenGl.lib
TKPCAF.lib
TKPLCAF.lib
TKPrim.lib
TKPShape.lib
TKQADraw.lib
TKService.lib
TKShapeSchema.lib
TKShHealing.lib
TKStdLSchema.lib
TKStdSchema.lib
TKSTEP.lib
TKSTEP209.lib
TKSTEPAttr.lib
TKSTEPBase.lib
TKSTL.lib
TKTObj.lib
TKTObjDRAW.lib
TKTopAlgo.lib
TKTopTest.lib
TKV2d.lib
TKV3d.lib
TKViewerTest.lib
TKVoxel.lib
TKVRML.lib
TKXCAF.lib
TKXCAFSchema.lib
TKXDEDRAW.lib
TKXDEIGES.lib
TKXDESTEP.lib
TKXMesh.lib
TKXml.lib
TKXmlL.lib
TKXmlTObj.lib
TKXmlXCAF.lib
TKXSBase.lib
TKXSDRAW.lib
说明:这里是C:\OpenCASCADE6.5.4\ros\win32\vc9\lib下的所有文件列表
//
#pragma warning( disable : 4244 ) // Issue warning 4244
#pragma warning( disable : 4312 ) // Issue warning 4312
#pragma warning( disable : 4267 ) // Issue warning 4312
#include "Standard_ShortReal.hxx"
#pragma warning( default : 4244 ) // Issue warning 4244
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
4.4.1. 在App头文件中添加标准宏定义和Windows图形设备头文件:
#include
#include
4.4.2. 在类中添加成员变量和引用方法:
protected:
Handle_WNT_GraphicDevice m_GraphicDevice;
public:
Handle_WNT_GraphicDevice& GetGraphicDevice()
{
return m_GraphicDevice;
}
try
{
m_GraphicDevice = new WNT_GraphicDevice();
}
catch (Standard_Failure)
{
ExitProcess(1);
}
4.4.4. 屏蔽#define new DEBUG_NEW
此时编译提示错误信息:
error C2661: 'Standard_Transient::operator new' : no overloaded function takes 3 arguments
原因是因为OpenCascade对New操作符进行了重载,与VS中的定义存在冲突,屏蔽文件前面的以下代码就可以解决了:
// #ifdef _DEBUG
// #define new DEBUG_NEW
// #endif
说明:后面OpenCascade使用new操作符的地方,都需同样的方法解决,不再赘述。具体可以参考OpenCascade官方放站的以下链接,有详细说明: http://www.opencascade.org/org/forum/thread_14858/
protected:
Handle_AIS2D_InteractiveContext m_AISInteractiveContext2D;
Handle_V2d_Viewer m_2dViewer;
public:
Handle_V2d_Viewer Get2dViewer()
{
return m_2dViewer;
}
Handle(WNT_GraphicDevice)& hGD = ((CMyOccApp*)AfxGetApp())->GetGraphicDevice();
TCollection_ExtendedString strName("2D Viewer");
TCollection_AsciiString strDomain("My Domain");
m_2dViewer = new V2d_Viewer(hGD, strName.ToExtString(), strDomain.ToCString());
m_2dViewer->SetCircularGridValues(0, 0, 10, 8, 0);
m_2dViewer->SetRectangularGridValues(0, 0, 10, 10, 0);
m_AISInteractiveContext2D = new AIS2D_InteractiveContext(m_2dViewer);
private:
Handle_V2d_View m_2dView;
4.6.2. 添加OnInitialUpdate虚函数设置OpenCascade显示,在OnInitialUpdate函数中添加以下代码:
Handle(WNT_Window) hWindow;
hWindow = new WNT_Window(((CMyOccApp*)AfxGetApp())->GetGraphicDevice(), GetSafeHwnd());
hWindow->SetBackground(Quantity_NOC_SLATEBLUE2);
Handle(WNT_WDriver) hDriver = new WNT_WDriver(hWindow);
m_2dView = new V2d_View(hDriver, GetDocument()->Get2dViewer(), 0, 0, 50);
Standard_Integer nWidth = 100, nHeight = 100;
hWindow->Size(nWidth, nHeight);
::PostMessage(GetSafeHwnd(), WM_SIZE, SIZE_RESTORED, nWidth + nHeight * 65536);
Handle(V2d_Viewer) viewer2D = m_2dView->Viewer();
viewer2D->RemoveView(m_2dView);
call ../../ros/env.bat
call %~dp0env.bat
start "C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" "All-vc10.sln"
然后双击open.bat,就可以载入环境变量后打开示例程序了。 try
{
...
}
catch(Standard_Failure sf)
{
const char* str = sf.GetMessageString();
wchar_t msg[5000];
MultiByteToWideChar(CP_ACP, 0, str,strlen(str)+1, msg, 5000/sizeof(msg[0]) );
MessageBox(msg);
}