当前位置:网站首页>Occt learning 003 - MFC single document project
Occt learning 003 - MFC single document project
2022-07-29 05:26:00 【longlongway2012】
OCCT Study 003-----MFC Single document project creation
background
window Develop software under the platform , frequently-used c++ Interface development mainly uses MFC, Although it has been almost eliminated in recent years , But for traditional software companies , Still not abandoned . Rising star Qt It's also very popular , I'll study it later , Here first from MFC break the ice .
The development of preparation
- vs2010 development environment
- occt 7.2 edition
Abreast of the times vs It's already here 2019, The next version is estimated to be 2021 了 , But for the research mechanism , The difference is not great , Others can try .
Create project and environment configuration
establish MFC Single document project and running environment
Set project name :

Set the engineering interface style

Finally click Finish , Generated an empty MFC Single document framework program :

establish x64 Program

Set the library path

Fill in the dependency Library :

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;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.libestablish occ Running environment env.bat, You can refer to occ Medium custom.bat and evironment.bat
set OCC_ROOT=F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\opencascade-7.2.0 set path=%path%;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\opencascade-7.2.0\win64\vc10\bin;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\ffmpeg-3.3-lgpl-64\bin;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\freeimage-3.17.0-vc10-64\bin;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\freetype-2.5.5-vc10-64\bin;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\gl2ps-1.3.8-vc10-64\bin;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\tbb_2017.0.100\bin\intel64\vc10;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\tcltk-86-64\bin;F:\Project\occ\OpenCASCADE-7.2.0-vc10-64\vtk-6.1.0-vc10-64\binestablish visual studio The startup environment in which the command runs Start.bat:
call %~dp0\env.bat start "E:\Program Files (x86)\vs2010\Common7\IDE\devenv.exe" %~dp0\examples\OccEditor\OccEditor.slnRerun Start.bat start-up IDE.
build occ and MFC Framework combined with code
stay stdafx.h Add some header files in :
#pragma warning( disable : 4244 ) // Issue warning 4244 #include <Standard_ShortReal.hxx> #pragma warning( default : 4244 ) // Issue warning 4244 #include <Standard.hxx> #include <Aspect_DisplayConnection.hxx> #include <AIS_InteractiveContext.hxx> #include <AIS_Shape.hxx> #include <AIS_Point.hxx> #include <V3d_Viewer.hxx> #include <V3d_View.hxx> #include <OpenGl_GraphicDriver.hxx> #include <WNT_Window.hxx> #include <Standard_ErrorHandler.hxx>stay occEditor.h Define graphics device environment variables
public: Handle_Graphic3d_GraphicDriver GetGraphicDriver() const; private: Handle_Graphic3d_GraphicDriver m_hGraphicDriver;stay occEditor.cpp To implement functions in GetGraphicDriver() And initialization variables
Handle_Graphic3d_GraphicDriver COccEditorApp::GetGraphicDriver() const { return m_hGraphicDriver; }stay BOOL COccEditorApp::InitInstance() Initialization variables in :
// init occ try { Handle(Aspect_DisplayConnection) aDisplayConnection; m_hGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection); } catch(Standard_Failure) { AfxMessageBox (_T("Fatal error during graphic initialization"), MB_ICONSTOP); ExitProcess(1); }At this time, there may be errors in compilation :
1>OccEditor.cpp(115): error C2661: “Standard_Transient::operator new”: No overloaded function accepts 3 ParametersNeed to be in OccEditor.cpp Comment out the following New Overload declaration of , Other documents also need to be commented out .
//#ifdef _DEBUG //#define new DEBUG_NEW //#endifestablish Viewer object
stay occEditorDoc.h In a statement :
public:
Handle(V3d_Viewer) GetViewer(){ return m_hViewer;}
Handle(AIS_InteractiveContext) GetAISContext(){ return m_hAISContext;}BOOL InitOCC();private:
Handle(V3d_Viewer) m_hViewer;
Handle(AIS_InteractiveContext) m_hAISContext;In regard to cpp Implementation of relevant code in :
BOOL COccEditorDoc::InitOCC() { Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((COccEditorApp*)AfxGetApp())->GetGraphicDriver(); m_hViewer = new V3d_Viewer(aGraphicDriver); m_hViewer->SetDefaultLights(); m_hViewer->SetLightOn(); //myViewer->SetDefaultBackgroundColor(Quantity_NOC_BLUE1);// Change the background color m_hAISContext =new AIS_InteractiveContext(m_hViewer); // Create an interactive document //m_hAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(11); //m_hAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(11); // Here, set the display mode of the entity m_hAISContext->SetDisplayMode(AIS_Shaded,Standard_True); m_hAISContext->SetAutomaticHilight(Standard_False); return TRUE; }stay NewDocument Call in InitOcc() function
BOOL COccEditorDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; InitOCC(); return TRUE; }
stay COccEditorView Class to realize the creation of visual components
OccEditorView.h Declare variables in :
private: Handle_V3d_View m_hView; Standard_Boolean m_bHlrModeIsOn; public: virtual void OnInitialUpdate(); void FitAll();OccEditorView.cpp Initialization and creation FitAll function ,OnInitialUpdate function
void COccEditorView::OnInitialUpdate() { CView::OnInitialUpdate(); m_bHlrModeIsOn = Standard_False; m_hView = GetDocument()->GetViewer()->CreateView(); m_hView->SetComputedMode(m_bHlrModeIsOn); Handle(Graphic3d_GraphicDriver) graphicDriver = ((COccEditorApp*)AfxGetApp())->GetGraphicDriver(); Handle(WNT_Window) hWntWindow = new WNT_Window(GetSafeHwnd()); m_hView->SetWindow(hWntWindow); if (!hWntWindow->IsMapped()) { hWntWindow->Map(); } hWntWindow->SetBackground(Quantity_NOC_SLATEBLUE2); // structure OpenCaseCade Axis m_hView->ZBufferTriedronSetup(Quantity_NOC_RED, Quantity_NOC_GREEN, Quantity_NOC_BLUE1, 0.8, 0.05, 12); m_hView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.2, V3d_ZBUFFER); FitAll(); } void COccEditorView::FitAll() { if (!m_hView.IsNull()) m_hView->FitAll(); m_hView->ZFitAll(); }
thus , One of the simplest occ+MFC The framework has been built :
Draw simple geometry
add to MFC menu
Open Explorer Ribbon resources , Add a category , Add a panel named sphere The button
Add a message response
Right mouse button , stay COccEditorView Class to add message response code :void COccEditorView::OnSphere() { DrawSphere(6); }add to DrawSphere Draw function implementation code :
void COccEditorView::DrawSphere(float radius) { BRepPrimAPI_MakeSphere mkSphere(radius); TopoDS_Shape Sphere = mkSphere.Shape(); Handle(AIS_Shape) myAISSphere = new AIS_Shape(Sphere); GetDocument()->GetAISContext()->Display(myAISSphere, Standard_False); FitAll(); }Final effect

Other features
Add a mouse rotation scene
add to MFC Drag the event with the left mouse button :void COccEditorView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add message handler code and / Or call the default value CView::OnMouseMove(nFlags, point); if(nFlags && MK_LBUTTON){ //myView->Rotate(point.x,point.y); m_hView->Rotation(point.x,point.y); }The coordinate axis flashes
Add the code here , The normal coordinate axis flickers frequently , There is no good way to track the code , The reason is the mouse mosemove Event internal call view::Rotation, Every time the function calls the graphics refresh , In this method mousemove It is not advisable to call directly , Update applications will be triggered frequently , We'll solve it later .
Postscript
So far , It's just a occ Learning head , Read some information about the basic data organization , The creation is not in-depth . But learn with interest , It will improve day by day . Later, I hope to separate the interface from the upper functions , packing occ function , Realize data abstraction , otherwise , The code is written in MFC In the code , Too messy .
边栏推荐
猜你喜欢

MySQL的基础概念+数据库系统结构+拓展延申+基础命令学习

Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)

阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署

How mongodb inserts, deletes and updates documents

C语言函数实现输出I love you

Vs code的安装步骤及环境配置

C how to realize simple factory mode

C语言数组入门到精通(数组精讲)

Occt learning 001 - Introduction

如视技术副总裁杨永林:当传统产业遇到“数字空间”
随机推荐
Webrtc audio anti weak network technology (Part 2)
Why is Google's internal tools not suitable for you?
存储类别
Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team
C语言 一维数组
CMake 设置vs启动运行环境路径
Rimworld通过SteamCMD上传创意工坊的方法
指针
为啥谷歌的内部工具不适合你?
C语言连连看秒杀辅助
Helm chart for Kubernetes
QT learning: qdropevent drag event
vs2019编译cryengine失败问题处理
365 day challenge leetcode 1000 questions - day 042 array sequence number conversion + relative ranking discretization processing
Getting started with arfoundation tutorial 10- plane detection and placement
如视技术副总裁杨永林:当传统产业遇到“数字空间”
01-01-osg GL3 环境搭建
The latest tank battle 2022 - full development notes-3
D3d Shader Instruction
阿里云架构师细说游戏行业九大趋势