-
OpenCASCADE Connecting ViewProgramming 2011. 5. 24. 14:52
OCC – Connecting the View(with Microsoft Foundation Classes Project)
1. Create the MFC Project
Create MFC Application Project
MDI project, Tab Document
Next, Next, Next!
(I selected the Ribbon bar Type)
2. Build!
빌드시에 "Wrong compiler options has been detected. Add /DWNT option for proper compilation!!!!!"
와 같은 메시지가 발생한다면
프로젝트 속성-> C/C++ -> 명령줄-> 추가옵션에 /DWNT를 써준다
종속 파일들에 대한 경로와
종속성 라이브러리 추가는 필수
TKVrml.lib;TKStl.lib;TKBrep.lib;TKIGES.lib;TKShHealing.lib;TKStep.lib;
TKXSBase.lib;TKShapeSchema.lib;FWOSPlugin.lib;PTKernel.lib;TKBool.lib;
TKCAF.lib;TKCDF.lib;TKDraw.lib;TKernel.lib;TKFeat.lib;TKFillet.lib;
TKG2d.lib;TKG3d.lib;TKGeomAlgo.lib;TKGeomBase.lib;TKHLR.lib;TKMath.lib;
TKOffset.lib;TKPCAF.lib;TKPrim.lib;TKPShape.lib;TKService.lib;TKTopAlgo.lib;
TKMesh.lib;TKV2d.lib;TKV3d.lib;TKLCAF.lib;
3. Add the Code!
0) In stdafx.h,
#include <Standard.hxx>
#include <Standard_Version.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#include <Handle_Graphic3d_WNTGraphicDevice.hxx>
#include <Standard_Macro.hxx>
#include <TDocStd_Application.hxx>
#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <Visual3d_View.hxx>
#include <WNT_Window.hxx>
1) In the App Class(ProjectName.h) header file, Add the following code
#if _MSC_VER > 1000//(This number is your IDE Version)
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
And Add the function and Protected Member
Handle_TDocStd_Application GetApp() const {return myApp;}
Handle_Graphic3d_WNTGraphicDevice GetGraphicDevice() const { return myGraphicDevice; }
Handle_Graphic3d_WNTGraphicDevice myGraphicDevice;
Handle(TDocStd_Application) myApp;
2) Next, App Class Source file, Add the following code
//error C2661: 'Standard_Transient::operator new' : 오버로드된 함수에서 3개의 매개 변수를 사용하지 않습니다.을 해결하기 위해 심어보란 포럼의 조언
//안됨...
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#endif
//위처럼 써야만 가능함
3) In the App Constructor
try
{
myGraphicDevice = new Graphic3d_WNTGraphicDevice();
}
catch(Standard_Failure)
{
AfxMessageBox(_T("Fatal error during graphic initialization"),MB_ICONSTOP);
ExitProcess(1);
}
4) In Doc Header,
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
…..
Add This Funstions
Handle_AIS_InteractiveContext& GetAISContext(){ return myAISContext; };
Handle_V3d_Viewer GetViewer() { return myViewer; };
Handle_AIS_InteractiveContext GetView(){return myAISContext;}
Handle_TDocStd_Document GetDocData() {return m_DataDoc;};
Add This Members
Handle_V3d_Viewer myViewer;
Handle_AIS_InteractiveContext myAISContext;
Handle_TDocStd_Document m_DataDoc;
5) Doc cpp file,
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]= __FILE__;
//#define new DEBUG_NEW
#endif
…………….
In constructor,
AfxInitRichEdit();
Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
((C+ProjectNameApp*)AfxGetApp())->GetGraphicDevice();
myViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D");
myViewer->SetDefaultLights();
myViewer->SetLightOn();
myAISContext =new AIS_InteractiveContext(myViewer);
6) In View Header,
Handle_V3d_View& GetView() { return myView; }
virtual void OnInitialUpdate();
Handle_Graphic3d_GraphicDriver myGraphicDriver;
Handle_V3d_View myView;
Standard_Integer myWidth;
Standard_Integer myHeight;
Standard_Boolean myDegenerateModeIsOn;
View cpp,
Add following code
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]= __FILE__;
//#define new DEBUG_NEW
#endif
In the Constructor,
myGraphicDriver = Handle(Graphic3d_GraphicDriver)::DownCast(
((C+ProjectName+App*)AfxGetApp())->GetGraphicDevice()->GraphicDriver() );
Modify OnDraw Function,
void C+ProjectName+View::OnDraw(CDC* /*pDC*/)
{
C+ProjectName+Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect aRect;
GetWindowRect(aRect);
if(myWidth != aRect.Width() || myHeight != aRect.Height()) {
myWidth = aRect.Width();
myHeight = aRect.Height();
::PostMessage ( GetSafeHwnd () , WM_SIZE , SW_SHOW , myWidth + myHeight*65536 );
}
if(!myView.IsNull())
{
myView->ZBufferTriedronSetup(Quantity_NOC_RED, Quantity_NOC_GREEN, Quantity_NOC_BLUE1, 0.8, 0.05, 12);
myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_BLUE1, 0.1);
myView->Redraw();
}
}
Add OnInitialUpdate Function,
void C+ProjectName+View::OnInitialUpdate()
{
CView::OnInitialUpdate();
myView = GetDocument()->GetViewer()->CreateView();
// set the default mode in wireframe ( not hidden line ! )
myView->SetDegenerateModeOn();
// store for restore state after rotation (witch is in Degenerated mode)
myDegenerateModeIsOn = Standard_True;
Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
((C+ProjectName+App*)AfxGetApp())->GetGraphicDevice();
Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,GetSafeHwnd ());
myView->SetWindow(aWNTWindow);
if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
// store the mode ( nothing , dynamic zooming, dynamic ... )
myView->ZBufferTriedronSetup(Quantity_NOC_RED, Quantity_NOC_GREEN, Quantity_NOC_BLUE1, 0.8, 0.05, 12);
myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_BLUE1, 0.1);
/*CjCADDoc* pDoc= GetDocument();
pDoc->OnCylinder();*/
}
Add Onsize function, add this code
Void C+ProjectName+View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (!myView.IsNull())
myView->MustBeResized();
}
위의 모든 과정을 마친 후에 MDI의 문서가 OCC View로 바뀐 것을 볼 수 있다.
(출처: OpenCASCADE 예제 참조 및 직접 작성)
'Programming' 카테고리의 다른 글
QT 정리1- QT소개, QT시작 (0) 2011.06.30 6.5 설치 및 샘플 재 빌드 (6) 2011.06.27 OpenCASCADE 6.5 릴리즈! (2) 2011.04.12 OpenScnenGraph 설치 (0) 2011.01.18 <0> XML (0) 2011.01.17