open cascade 显示窗口及绘制简图基本步骤
2013-09-19 10:01阅读:
1、建立MFC SDI文档。
在stdafx.h 中加入以下头文件引用
#if !defined(WNT)
#error WNT precompiler directive is mandatory for
CasCade
#endif
#include <V3d_View.hxx>
//V3d_View
#include <WNT_Window.hxx>
//Handle_WNT_Window
#include <Graphic3d.hxx>
//Graphic3d/InitGraphicDriver
#include <AIS_InteractiveContext.hxx>
//AIS_InteractiveContext
#include <AIS_Shape.hxx>
//Handle_AIS_Shape
一、在
C**App 类中初始化一个设备对象的类
myGraphicDriver
该类可以调用TKOpenGl.dll
管理图形设备
2、在 C**App class .h 头文件中加入:
Handle(Aspect_DisplayConnection)
myDisplayConnection;
Handle(Graphic3d_GraphicDriver) myGraphicDriver;
Handle(Graphic3d_GraphicDriver) GetGraphicDriver()
const {return myGraphicDriver;
}//为C**App提供调用接口函数
3、在 C**App class .cpp
源文件中构造函数加入:
try
{ myGraphicDriver = Graphic3d::InitGraphicDriver
(myDisplayConnection); } catch(Standard_Failure)
{ AfxMessageBox ('Fatal error during graphic
initialization', MB_ICONSTOP); ExitProcess (1);
}
二、在C**Doc类中声明V3d_Viewer
和
AIS_InteractiveContext两个类
V3d_Viewer
是一个 V3d_View (
3d
视图)的管理器,支持多视图。
AIS_InteractiveContext
类派生于AIS_InteractiveObject类实现可交互的图形对象,可实
现对象的显示、选择、高亮显示等功能。
实现时Context将图形对象添加到Viewer对象中进行显示。
4、在 C**Doc class .h 头文件中加入:
Handle_V3d_Viewer myViewer;
Handle_AIS_InteractiveContext myAISContext;
Handle(V3d_Viewer) GetViewer() { return myViewer;
}
Handle(AIS_InteractiveContext)& GetAISContext() { return
myAISContext; }
5、在 C**Doc class .cpp 源文件中加入:
Handle(Graphic3d_GraphicDriver) theGraphicDriver =
((C**App*)AfxGetApp())->GetGraphicDriver();
myViewer = new V3d_Viewer(theGraphicDriver,(short *)
'Visu3D');
myViewer->SetDefaultLights();
myViewer->SetLightOn();
myAISContext = new AIS_InteractiveContext
(myViewer);
三、在C**View类中声明V3d_View
类的对象并初始化,生成一个3d视图,实现视图的旋转、缩放、平移,灯光等功能
6、在 C**View class .h 头文件中加入:
Handle_V3d_View myView;
7、在 C**View class .cpp 源文件中加入:
::OnInitialUpdate()中加入
myView = GetDocument()
->GetViewer()->CreateView();
myHlrModeIsOn =
Standard_False;
myView->SetComputedMode(myHlrModeIsOn);
Handle(Graphic3d_GraphicDriver)
theGraphicDriver =
((C**App*)AfxGetApp())->GetGraphicDriver();
Handle(WNT_Window) aWNTWindow = new
WNT_Window(GetSafeHwnd());//,Quantity_NOC_MATRAGRAY);
myView->SetWindow(aWNTWindow);
//if(!aWNTWindow->IsMapped())
aWNTWindow->Map();
8、在 ~C**View class .cpp 源文件:
::OnDraw(CDC* )中加入
gp_Lin aGpLin (gp_Pnt (0., 0., 0.), gp_Dir(1., 0.,
0.));
Handle(Geom_Line) aGeomLin = new Geom_Line
(aGpLin);
Handle(AIS_Line) anAISLine = new AIS_Line
(aGeomLin);
pDoc->myAISContext->Display(anAISLine);
到此为止,就可以显示一条直线了.
9、在 ~C**View class .cpp 源文件析构函数中加入:
if(myView)
myView->Remove();
清理内存。