Is there anybody who is using OCC in combination with wxWindows? I mean without MFC and Qt. I desperately need some advices how to start combine these two toolkits. I posted two requests on two different threads on the forum but I didn't receive any answer. The idea is the OCC officially doesn't support wxWindows but I know that it is possible. I know that Serge Bakka posted a project on sf.net but I couldn’t find it.
Many thanks in advance
Andras
Sandor Racz
2004/03/24 04:29
Andras,
It should be possible, I used wxPython with OCC but in C++ obviously the situation is the same. I think the point is to create a WNT_Window. In the constructor the first parameter can be a Graphic3d_WNTGraphicDevice. The second parameter that is really important, that should be a window handle. As far as I remember you can get it using a GetHandle() function in wxWindows.
I pasted here the relevant Python code, it might help you:
def Initialize(self):
if self.IsInitialized():
return
self.aWNTWindow = WNT_Window(self.gd,self.GetHandle())
self.aWNTWindow.SetBackground(Quantity_NOC_MIDNIGHTBLUE)
self.view.SetWindow(self.aWNTWindow)
if not self.aWNTWindow.IsMapped():
self.aWNTWindow.Map()
self.aWNTWindow.Size(1200,1200)
self.initialized = 1
You can create a view using V3d_Viewer's CreateView() function.
Regards,
Sandor
Andras
2004/03/24 11:11
Many thanks,
Maybe it will help me. Anyway I have no experience in python, but what a hack:=)
Sandor Racz
2004/03/24 15:15
Python's syntax is very similar to that of C++'s. You might take one of the wxWindows sample application like that one that can be used to draw/paint something so contains some widgets and even handling. If you download the sample Python code from my site (www.pythonizer.org) it should contain the logic of this kind of applications at least in OCC context.
Patrik Müller
2004/03/24 08:01
Hi,
I haven't heard anything from Serge. I'm a newbie for wxWindows - so I think I still need some time for building my first OCC application with wxWindows.
The following are the basic 3 MSVC++ files for starting a wxWindows & OCC project. Do a find & replace of the <Your_file_name> to give it a more meaningful name. Make sure you've done all your settings in MSVC for the paths to the libs, etc of both wxWin & OCC. Create files of everything listed under the file names below, till the next file starts. Will email some more information in another posting otherwise this one's going to get too long.
1. Your_file_name.rc
#include "wx/msw/wx.rc"
2. Your_file_name.dsp
# Microsoft Developer Studio Project File - Name="Your_file_name" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Your_file_name - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Your_file_name.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Your_file_name.mak" CFG="Your_file_name - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Your_file_name - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Your_file_name - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE "Your_file_name - Win32 Debug DLL" (based on "Win32 (x86) Application")
!MESSAGE "Your_file_name - Win32 Release DLL" (based on "Win32 (x86) Application")
!MESSAGE
If you're already familiar with creating wxWindows (BTW it's now called wxWidgets, thanks to MS strong-arm tactics), then in OnInit function of your class deriving from wxApp, you'll have to set up the stuff as illustrated below. BTW, I've used any Try & Catch blocks for any exceptions arising from creating the view, it's just for illustrative purposes.
bool myApp::OnInit()
{
TopFrame = new wxFrame(NULL, -1, "View3d" );
///////OpenCascade///////////////
Handle(Graphic3d_WNTGraphicDevice) graphicDevice= new Graphic3d_WNTGraphicDevice; // handles the hardware color management
Handle(WNT_Window) aWNTWindow= new WNT_Window(graphicDevice, (HWND*)TopFrame->GetHandle()); // is a framework for Windoze NT
viewer = new V3d_Viewer(graphicDevice, (short* const)"viewer"); // manages views
view = viewer->CreateView(); // view is the orientation, mapping etc of your actual display
view->SetWindow(aWNTWindow); // attach the view to the window
Handle(AIS_InteractiveContext) context = new AIS_InteractiveContext(viewer); // for selection management i.e neutral point or open local context
viewer->SetDefaultLights(); // makes everything come alive
viewer->SetLightOn(); // makes everything come alive
TopFrame->Show(TRUE);
SetTopWindow(TopFrame);
////code a simple primitive for display
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.);
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape());
context->SetColor(anAISShape,Quantity_NOC_AZURE);
context->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC);
context->SetDisplayMode(anAISShape,1);
context->Display(anAISShape);
return true;
}
Andras
2004/03/27 13:32
Thank's a lot. I will keep you informed next week.
Andras.
Canuck
2004/03/27 16:27
Below are a couple of files you could use to get an idea of getting the basics going for any app, i.e. pan, zoom, rotate, blah, blah. Each file name has header e.g as below "myapp.h", copy & paste everything below it till you come to another file header e.g "myapp.cpp". Eat like a cow, take the grass and leave the twigs, I'm a rookie too.
////////////////////////////////////////////////////////////////
// Name: myapp.h
// Purpose: The wxApp & wxDocMDIParent Class
////////////////////////////////////////////////////////////////
#ifndef __MYAPP__
#define __MYAPP__
#include "wx/docmdi.h"
#include "cascade.h"
////////////////////////////////////////////////////////////
//Name : enum
//Usage : To give human readable names to integer values
// of Menu ID's
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : MyApp
//Usage : Every application in wxWindows must have a
// class derived from wxApp. Your application is
// an instance of this class object. It also is
// the starting point of the application
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : OnInit
//Usage : The OnInit function has to be over-ridden.
// The code for creating the application's manin
// window is placed here.
////////////////////////////////////////////////////////////
bool OnInit(void);
int OnExit(void);
////////////////////////////////////////////////////////////
//Name : CreateChildFrame
//Usage : Member funciton of MyApp. It is called by the
// constructor of the MyView class to create the
// child window in which the CAD modeling is done.
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//Name : myGraphicDevice
//Usage : Only one instance of the Graphic3d_WNTGraphicDevice
// exists in the application and is instantiatiated
// in the MyApp constructor. It is used in setting
// up the view where the CAD objects are displayed
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : MyFrame
//Usage : An instance of this object is created in the
// OnInit function of MyApp to create the main
// window displayed when the program is started
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : CreateCanvas
//Usage : Member funciton of MyFrame. It is called by the
// constructor of the MyView class to create the
// canvas window which will hold the view object
// in which the CAD modeling is done.
////////////////////////////////////////////////////////////
try
{myGraphicDevice = new Graphic3d_WNTGraphicDevice();}
catch(Standard_Failure)
{wxMessageDialog(NULL, "Fatal Error During Graphic Initialisation");}
// Set the local system units
try
{UnitsAPI::SetLocalSystem(UnitsAPI_MDTV);}
catch(Standard_Failure)
{wxMessageDialog(NULL,"Fatal Error During Units Initialisation");}
////////////////////////////////////////////////////////////
//Name : MyCanvas
//Usage : This is the main window which will display CAD
// objects. For the user to work with the mouse,
// the window must be able to receive mouse events,
// this is possible because wxScrolledWindow is
// derived from wxWindow, which receives mouse evts
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : MyCanvas
//Usage : Constructor. Initializes the wxScrolledWindow
// from which it is derived
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : OnDraw
//Usage : This function is called whenever the window is
// invalidated e.g if a window on top of it is moved
////////////////////////////////////////////////////////////
Handle(V3d_View) cView; // CAD objects are displayed
// in this object
MyDoc* GetDocument();
//////////////////////////////////////////////
// Begin*
// Following variables are used in functions
// that respond to the mouse events pan,
// rotate, zoom, select
//////////////////////////////////////////////
//////////////////////////////////////////////
// Begin**
// Mouse related Functions for pan, rotate,
// zoom, select
//////////////////////////////////////////////
void CurMove(long& xcoord, //makes the Cascade AIS objects
long& ycoord); // alive to mouse movements
void CtrlZoom(long x1, // Ctrl +Left mouse down
long y1, // for zooming
long x2,
long y2);
void CtrlRotate(long& xcoord, // Ctrl+Right mouse down
long& ycoord); // for rotating
void ZoomWnd(); // zooming with rubber-band
void DrawRectangle(long initX, // general purpose rubber-band display
long initY, // during zoom or selection window
long finalX,
long finalY,
bool Draw);
void DynRotate(); // rotating with the mouse
void DynPan(); // panning with the mouse
void ShiftSelectObject (const Standard_Integer flag) ; // for selecting CAD objects
// by using Shift a new object
// will be added to those already
// selected
void SelectObject(const Standard_Integer flag); // for selecting CAD objects
// by dragging a rubber-band
// window or left mouse selection
////////////////////////////////////////////////////////////
//Name : MyView
//Usage : Part of the Doc/View Architecture. An object of
// class is automatically instantiated by the
// DocTemplate when File->New is selected
// The view class calls the functions for
// instantiating a MyCanvas object and a
// wxDocMDIChild frame to contain the MyCanvas
////////////////////////////////////////////////////////////
Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,(HWND*)this->GetHandle());
cView->SetWindow(aWNTWindow); // display the view in the specifed window
}
MyCanvas::~MyCanvas()
{
cView->Remove();
}
////////////////////////////////////////////////////////////
//Name : OnDraw
//Usage : This function is called whenever the window is
// invalidated e.g if a window on top of it is moved
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : OnSize
//Usage : This function is called whenever the window is
// resized by the user
////////////////////////////////////////////////////////////
void MyCanvas::OnSize(wxSizeEvent& event)
{
if (!cView.IsNull())
cView->MustBeResized(); // if the user changes the window size
// this will re-center the Cascade View
}
//////////////////////////////////////////////
// Begin**
// Mouse related event handlers for pan,
// rotate, zoom, select
//////////////////////////////////////////////
if (event.m_shiftDown)
ShiftSelectObject(1); // add objects to current selection by Shift + Left Mouse Click
else
SelectObject(1); // select object by left mouse down
break;
////// note - the "if" & "else if" are used here for mutually exclusive events
if (event.Dragging() && CurMode == CurAction3d_Nothing && !event.m_controlDown && !event.m_rightDown)
{
SetCapture((HWND)(this->GetHandle())); // capture mouse movements
// event if it moves out of window
if (event.m_shiftDown) // add to currently selected objects those
ShiftSelectObject(0); // included in the rubber-band window
else
SelectObject(0); // select objects by rubber-band window
DrawRectangle(myXmin,myYmin,xMouse,yMouse, true);
}
else if (event.Moving() && CurMode == CurAction3d_Nothing && !event.m_controlDown && !event.m_rightDown) // no buttons pressed, mouse moving
CurMove(xMouse,yMouse); // makes the AIS objects come alive !!
////// end note on mutually exclusive events
if(event.LeftIsDown() && event.Dragging() && event.m_controlDown)
CtrlZoom(myXmax,myYmax,xMouse,yMouse); // zoom with ctrl & left mouse button
if(event.RightIsDown() && event.Dragging() && event.m_controlDown)
CtrlRotate(xMouse,yMouse); // rotate with ctrl & right mouse down
else if(event.RightIsDown() && event.Dragging())
wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));
if(event.LeftIsDown() && event.Dragging() && CurMode == CurAction3d_WindowZooming)
{
SetCapture((HWND)(this->GetHandle())); // capture mouse movements
// event if it moves out of window
if(event.LeftIsDown() && event.Dragging() && CurMode == CurAction3d_DynamicRotation)
DynRotate(); // rotating with the mouse
if(event.LeftIsDown() && event.Dragging() && CurMode == CurAction3d_DynamicPanning)
DynPan(); // panning with the mouse
}
/////////
//End**//
/////////
/////////////////////////////////////////////////
// Begin***
// These are the functions that do the actual
// work for pan, rotate, zoom, select and are
// called by the mouse event handlers
/////////////////////////////////////////////////
void MyCanvas::CurMove(long& xcoord, long& ycoord)
{
GetDocument()->myAISContext->MoveTo(xcoord, ycoord,cView); // makes the CAD objects
// come alive
}
void MyCanvas::CtrlZoom(long x1, long y1, long x2, long y2)
{
wxWindow::SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
if (flag == 0)
GetDocument()->myAISContext->Select(myXmin, myYmin, xMouse, yMouse, cView);
if (flag == 1)
GetDocument()->myAISContext->Select();
}
//////////
//End***//
//////////
////////////////////////////////////////////////////////////
//Name : DrawRectangle
//Usage : This is just a cosmetic rectangle display for
// the user while selecting or zooming by
// stretching a rubber-band window.
// It is actually not straight-forward to get it
// to work correctly !
////////////////////////////////////////////////////////////
void MyCanvas::DrawRectangle(long initX, long initY, long finalX, long finalY, bool Draw)
{
static long storedInitX, storedInitY, storedFinalX, storedFinalY;
////////////////////////////////////////////////////////////
//Name : OnKeyBoard
//Usage : This is enable the user to use the keyboard to
// do rotate, pan or zoom
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// Name: mydoc.h
// Purpose: The wxDoc Class
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//Name : MyDoc
//Usage : To use the Doc/View architecture of wxWindows
// derive a class from wxDoc. All the data will be
// stored in this class as well as the operations
// upon the data.
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//Name : cViewer
//Usage : Only one instance of the V3d_Viewer exists in the
// application and is instantiatiated in the MyDoc
// constructor. It is used to manage the Cascade
// view object that displays the CAD objects.
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//Name : myAISContext
//Usage : Only one instance of the AIS_InteractiveContext
// exists in the application and is instantiatiated in
// the MyDoc constructor. For any selectable object to
// be displayed in the view object it must be displayed
// using the Display member function of this object.
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// Name: mydoc.cpp
// Purpose: The wxDoc Class
////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
////code a simple primite for use in testing zoom,pan features
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.);
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape());
myAISContext->SetColor(anAISShape,Quantity_NOC_AZURE);
myAISContext->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC);
myAISContext->SetDisplayMode(anAISShape,1);
myAISContext->Display(anAISShape);
}
///////////////////////////////////////////////////////////////
// Name: cascade.h
// Purpose: Standard Cascade common Includes
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// Name: cascade.cpp
// Purpose: Standard Cascade common Includes
////////////////////////////////////////////////////////////////
#include "cascade.h"
Canuck
2004/03/27 16:41
It would appear that the cascade.h file got corrupt in the posting, because all the includes are without any file names, here's the list of files that you'd have to include. Use the <> brackets to include them.
In the myapp.cpp file delete this line frame->SetIcon(wxIcon("wxFEA")); or your application won't compile.
If you'd like to give a custom icon to your application, create a small icon your_name.ico. In your_file_name.rc include this line
your_name ICON "your_name.ico"
and then you can keep the frame->SetIcon line but change the name to frame->SetIcon(wxIcon("your_name"))
The same applies for the line "subframe->SetIcon(wxString("wxFEA"));" either delete it or use "your_name"
Patrik Müller
2004/03/29 12:43
Cool,
that were the hints I missed for creating my first wxWindows version.
Many thanks for these good hints!!!!!!!
Best regards,
Patrik
Andras
2004/03/27 15:00
Thank's again! It works. I will write you later my ideas. I want to make an MDI skeleton in the same way using wx FL.