Opencascade is an open source code and powerful 3D modeling and simulation tool. The following is the basic process for setting up and creating opencascade programs in vs2005.
I. Environment Settings
Start vs2005 and select the VC ++ directories item under tools/options.../Projects & Solutions,
Add the header file to the opencascade directory:
C:/opencascade6.3.0/ROs/Inc is my installation directory.
The library file is also added to the opencascade directory:
C:/opencascade6.3.0/ROs/Win32/lib is my installation directory.
Ii. Generation vs project and Setup
Create a VC ++ single-document project, and keep the default properties for others.
Add the opencascade header file to the stdafx. h header file:
//////////////////////////////////////// /// // <Br/> # pragma warning (Disable: 4244) // Issue warning 4244 <br/> # pragma warning (Disable: 4312) // Issue warning 4312 <br/> # pragma warning (Disable: 4267) // Issue warning 4312 <br/> # include "standard_shortreal.hxx" <br/> # pragma warning (default: 4244) // Issue warning 4244 </P> <p> # include <v2d_viewer.hxx> <br/> # include <v2d_view.hxx> <br/> # include <ais2d_interactivecontext.hxx> <br/> # include <wn_wdriver.hxx> </P> <p> # include <standard. hxx> <br/> # include <ais_interactivecontext.hxx> <br/> # include <ais_shape.hxx> <br/> # include <strong> <br/> # include <v3d_viewer.hxx> <br /># include <v3d_view.hxx> <br/> # include <wn_window.hxx> </P> <p> # include <ais2d_interactiveobject.hxx> <br/> # include <graphic2d_setofcurves.hxx> <br/> # include <geom2d_trimmedcurve.hxx> <br/> # include <prs2d_aspectline.hxx> <br/> # include <strong> <br/> # include <graphic2d_polyline.hxx> <br/> # include <graphic2d_text.hxx> </P> <p> # include <prs3d_drawer.hxx> <br/> # include <prs3d_isoaspect.hxx> <br/> # include <strong> </P> <p> # include <strong> <br/> # include <ais_drawer.hxx> <br/> # include <stdprs_shadedshape.hxx> <br/> # include <stdprs_hlrpolyshape.hxx> <br/> # include <strong> <br/> # include <stdprs_wfdeflectionshape.hxx> <br/> # include <topexp_assumer.hxx> <br/> # include <brep_tool.hxx> <br/> # include <topods. hxx> <br/> # include <geom_surface.hxx> <br/> # include <geom_plane.hxx> </P> <p> # include <toptools_hsequenceofshape.hxx> <br/> # include <breptools. hxx> </P> <p> # include <strong> <br/> # include <aspect_polygonoffsetmode.hxx> <br/> # include <graphic3d_group.hxx>
Open project properties, and in the Link/input tab, select additional dependencies Zhongtian opencascade Library File
Tkml. lib <br/> tkstl. lib <br/> tkbrep. lib <br/> tkiges. lib <br/> tkshhealing. lib <br/> tkstep. lib <br/> tkxsbase. lib <br/> tkshapeschema. lib <br/> fwosplugin. lib <br/> ptkernel. lib <br/> tkbool. lib <br/> tkcaf. lib <br/> tkcdf. lib <br/> tkdraw. lib <br/> tkernel. lib <br/> tkfeat. lib <br/> tkfillet. lib <br/> tkg2d. lib <br/> tkg3d. lib <br/> tkgeomalgo. lib <br/> tkgeombase. lib <br/> tkhlr. lib <br/> tkmath. lib <br/> tkoffset. lib <br/> tkpcaf. lib <br/> tkprim. lib <br/> tkpshape. lib <br/> tkservice. lib <br/> tktopalgo. lib <br/> tkmesh. lib <br/> tkv2d. lib <br/> tkv3d. lib
3. Add and set environment variables for opencascade graphics devices in the app class
Add the standard macro definition and Windows Graphics Device header file to the app header file:
# Include <standard_macro.hxx> <br/> # include <wn_graphicdevice.hxx>
Add member variables and reference methods to the class.
Protected: <br/> handle_wn_graphicdevice m_graphicdevice; <br/> Public: <br/> handle_wn_graphicdevice & getgraphicdevice () <br/>{< br/> return m_graphicdevice; <br/>}< br/>
In the app's source file, the constructor generates and initializes the device environment:
Try <br/>{< br/> m_graphicdevice = new wn_graphicdevice (); <br/>}< br/> catch (standard_failure) <br/>{< br/> exitprocess (1); <br/>}< br/>
The following error message is displayed during compilation:
Error c2661: 'standard _ transient: Operator new': No overloaded function takes 3 arguments
The reason is that opencascade reloads the new operator and conflicts with the definition in vs. The following code can be used to block the file.
// # Ifdef _ debug <br/> // # define new debug_new <br/> // # endif <br/>
The new operator must be used in opencascade. For more information, see the following link on the opencascade Official Website:
Http://www.opencascade.org/org/forum/thread_14858/
Iv. Add the opencascade indirect device environment and graphical interface to the document class
Add opencascade member variables and reference methods to the doc header file
Protected: <br/> handle_ais2d_interactivecontext m_aisinteractivecontext2d; <br/> handle_v2d_viewer m_2dviewer; </P> <p> Public: <br/> handle_v2d_viewer get2dviewer () <br/>{< br/> return m_2dviewer; <br/>}< br/>
Opencasca variable initialization settings in the constructor in the doc source file
Handle (wn_graphicdevice) & hgd = (cocmfcsdi1app *) afxgetapp ()-> getgraphicdevice (); <br/> tcollection_extendedstring strname ("2D viewer "); <br/> tcollection_asciistring strdomain ("My domain"); </P> <p> m_2dviewer = new v2d_viewer (hgd, strname. toextstring (), strdomain. tocstring (); </P> <p> m_2dviewer-> setcirculargridvalues (0, 0, 10, 8, 0); <br/> m_2dviewer-> setrectangulargridvalues (0, 0, 10, 10, 0); </P> <p> m_aisinteractivecontext2d = new ais2d_interactivecontext (m_2dviewer); <br/>
Don't forget to block the previous new code ^_^
5. View opencascade variable settings and Graphic Display Settings
Add the opencascade variable to the view header file
PRIVATE: <br/> handle_v2d_view m_2dview; <br/>
Add the oninitialupdate virtual function to set opencascade display. Add the following code to the oninitialupdate function:
Handle (wn_window) hwindow; <br/> hwindow = new wn_window (cocmfcsdi1app *) afxgetapp ()-> getgraphicdevice (), getsafehwnd ()); <br/> hwindow-> setbackground (quantity_noc_slateblue2); </P> <p> handle (wn_wdriver) hdriver = new wn_wdriver (hwindow ); <br/> m_2dview = new v2d_view (hdriver, getdocument ()-> get2dviewer (), 0, 0, 50); </P> <p> standard_integer nwidth = 100, nheight = 100; <br/> hwindow-> size (nwidth, nheight); </P> <p>: postmessage (getsafehwnd (), wm_size, size_restored, nwidth + nheight * 65536); <br/>
Delete the opencascade viewer in the view destructor to clear the memory.
Handle (v2d_viewer) viewer2d = m_2dview-> Viewer (); <br/> viewer2d-> removeview (m_2dview); <br/>
The new Code Section is also blocked.
Vi. Operation observation
So far, the initialization and setting of opencascade have been completed. When you run the program, you can see the purple interface of opencascade.