wxWindows

Hi

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's picture

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

self.view.SetBackgroundColor(Quantity_NOC_MIDNIGHTBLUE)

You can create a view using V3d_Viewer's CreateView() function.

Regards,

Sandor

Andras's picture

Many thanks,

Maybe it will help me. Anyway I have no experience in python, but what a hack:=)

Sandor Racz's picture

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 Mueller's picture

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.

Greets,

Patrik

Andras's picture

See the following links
http://www.opencascade.com/community/forum/thread_5491/
http://www.opencascade.com/community/forum/thread_3985/
I posted two requests but no answer. Maybe you will have more luck.

Andras

Canuck's picture

The following are the basic 3 MSVC++ files for starting a wxWindows & OCC project. Do a find & replace of the 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

# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe

!IF "$(CFG)" == "Your_file_name - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /GX /O1 /Ob2 /I "../../include" /I "../../contrib/include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "WNT" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 wx.lib png.lib zlib.lib jpeg.lib tiff.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib TKOffset.lib TKPCAF.lib TKPrim.lib TKPShape.lib TKService.lib TKTopAlgo.lib TKV2d.lib TKV3d.lib TKBRep.lib TKG2d.lib TKG3d.lib TKGeomBase.lib FWOSPlugin.lib PTKernel.lib TKBool.lib TKCAF.lib TKCDF.lib TKDraw.lib TKernel.lib TKFeat.lib TKFillet.lib TKGeomAlgo.lib TKHLR.lib TKMath.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libci.lib" /nodefaultlib:"msvcrtd.lib" /libpath:"../../lib" /libpath:"../../contrib/lib"

!ELSEIF "$(CFG)" == "Your_file_name - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../include" /I "../../contrib/include" /D "_DEBUG" /D DEBUG=1 /D "__WXDEBUG__" /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "WNT" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /Yu"wx/wxprec.h" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 wxd.lib xpmd.lib pngd.lib zlibd.lib jpegd.lib tiffd.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib TKOffset.lib TKPCAF.lib TKPrim.lib TKPShape.lib TKService.lib TKTopAlgo.lib TKV2d.lib TKV3d.lib TKBRep.lib TKG2d.lib TKG3d.lib TKGeomBase.lib FWOSPlugin.lib PTKernel.lib TKBool.lib TKCAF.lib TKCDF.lib TKDraw.lib TKernel.lib TKFeat.lib TKFillet.lib TKGeomAlgo.lib TKHLR.lib TKMath.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrt.lib" /pdbtype:sept /libpath:"../../lib" /libpath:"../../contrib/lib"

!ELSEIF "$(CFG)" == "Your_file_name - Win32 Debug DLL"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "DebugDLL"
# PROP BASE Intermediate_Dir "DebugDLL"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "DebugDLL"
# PROP Intermediate_Dir "DebugDLL"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../include" /I "../../contrib/include" /D "_DEBUG" /D DEBUG=1 /D "__WXDEBUG__" /D WXUSINGDLL=1 /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "WNT" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /Yu"wx/wxprec.h" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 wxmsw24d.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib TKOffset.lib TKPCAF.lib TKPrim.lib TKPShape.lib TKService.lib TKTopAlgo.lib TKV2d.lib TKV3d.lib TKBRep.lib TKG2d.lib TKG3d.lib TKGeomBase.lib FWOSPlugin.lib PTKernel.lib TKBool.lib TKCAF.lib TKCDF.lib TKDraw.lib TKernel.lib TKFeat.lib TKFillet.lib TKGeomAlgo.lib TKHLR.lib TKMath.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /pdbtype:sept /libpath:"../../lib" /libpath:"../../contrib/lib"

!ELSEIF "$(CFG)" == "Your_file_name - Win32 Release DLL"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "ReleaseDLL"
# PROP BASE Intermediate_Dir "ReleaseDLL"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "ReleaseDLL"
# PROP Intermediate_Dir "ReleaseDLL"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /GX /O1 /Ob2 /I "../../include" /I "../../contrib/include" /D "NDEBUG" /D WXUSINGDLL=1 /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "WNT" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 wxmsw24.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib winmm.lib TKOffset.lib TKPCAF.lib TKPrim.lib TKPShape.lib TKService.lib TKTopAlgo.lib TKV2d.lib TKV3d.lib TKBRep.lib TKG2d.lib TKG3d.lib TKGeomBase.lib FWOSPlugin.lib PTKernel.lib TKBool.lib TKCAF.lib TKCDF.lib TKDraw.lib TKernel.lib TKFeat.lib TKFillet.lib TKGeomAlgo.lib TKHLR.lib TKMath.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libc.lib" /nodefaultlib:"libci.lib" /libpath:"../../lib" /libpath:"../../contrib/lib"

!ENDIF

# Begin Target

# Name "Your_file_name - Win32 Release"
# Name "Your_file_name - Win32 Debug"
# Name "Your_file_name - Win32 Debug DLL"
# Name "Your_file_name - Win32 Release DLL"
# Begin Source File

SOURCE=.\Your_file_name.rc
# ADD BASE RSC /l 0x809
# ADD RSC /l 0x809 /i "../../include" /i "../../contrib/include"
# End Source File
# End Target
# End Project

3. Your_file_name.dsp

Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!

###############################################################################

Project: "Your_file_name"=".\Your_file_name.dsp" - Package Owner=<4>

Package=<5>
{{{
}}}

Package=<4>
{{{
}}}

###############################################################################

Global:

Package=<5>
{{{
}}}

Package=<3>
{{{
}}}

###############################################################################

Canuck's picture

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's picture

Thank's a lot. I will keep you informed next week.
Andras.

Canuck's picture

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
////////////////////////////////////////////////////////////

enum
{
HELP_ABOUT = 10000,
ZOOM_VIEW,
ROTATE_VIEW,
FIT_VIEW,
PAN_VIEW,
HIDDEN_OFF_VIEW,
HIDDEN_ON_VIEW,
WIREFRAME_VIEW,
RENDER_VIEW
};

class wxDocManager;

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////wxApp Class///////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
//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
////////////////////////////////////////////////////////////

class MyApp: public wxApp
{
public:

//////////////////////////wxWindows///////////////////////////

MyApp(void);

////////////////////////////////////////////////////////////
//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.
////////////////////////////////////////////////////////////

wxMDIChildFrame *CreateChildFrame(wxDocument *doc,
wxView *view,
bool isCanvas);

wxDocManager* m_docManager;

////////////////////////////Cascade/////////////////////////////

////////////////////////////////////////////////////////////////
//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
////////////////////////////////////////////////////////////////

Handle(Graphic3d_WNTGraphicDevice) myGraphicDevice;

Handle(Graphic3d_WNTGraphicDevice) GetGraphicDevice() const
{ return myGraphicDevice; } ;

};

DECLARE_APP(MyApp)

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////MyFrame Class/////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

class MyCanvas;

////////////////////////////////////////////////////////////
//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
////////////////////////////////////////////////////////////

class MyFrame: public wxDocMDIParentFrame
{

//////////////////////////wxWindows///////////////////////////

DECLARE_CLASS(MyFrame)

public:

MyFrame(wxDocManager *manager,
wxFrame *frame,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long type);

void OnAbout(wxCommandEvent& event);

////////////////////////////////////////////////////////////
//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.
////////////////////////////////////////////////////////////

MyCanvas *CreateCanvas(wxView *view,
wxFrame *parent);

DECLARE_EVENT_TABLE()

};

extern MyFrame *GetMainFrame(void);

#endif

////////////////////////////////////////////////////////////////
// Name: myapp.cpp
// Purpose: The wxApp & wxDocMDIParent Class
////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "myapp.h"
#include "mydoc.h"
#include "mycanvas.h"

MyFrame* frame = (MyFrame*) NULL;

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////wxApp Class///////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

IMPLEMENT_APP(MyApp)

MyApp::MyApp(void)
{
m_docManager = (wxDocManager*) NULL;

////////////////////////////Cascade/////////////////////////////

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");}

}

bool MyApp::OnInit(void)
{

//////////////////////////wxWindows///////////////////////////

m_docManager = new wxDocManager;

(void) new wxDocTemplate((wxDocManager *) m_docManager,
"Drawing",
"*.drw",
"",
"drw",
"Drawing Doc",
"Drawing View",
CLASSINFO(MyDoc),
CLASSINFO(MyView));

frame = new MyFrame((wxDocManager*) m_docManager,
(wxFrame*) NULL,
(const wxString) "wxFEA",
wxPoint(0, 0),
wxSize(500, 400),
wxDEFAULT_FRAME_STYLE);

frame->SetIcon(wxIcon("wxFEA"));

wxMenu* file_menu = new wxMenu;

file_menu->Append(wxID_NEW, "&New...\tCtrl-N");

file_menu->Append(wxID_OPEN, "&Open...\tCtrl-X");

file_menu->AppendSeparator();

file_menu->Append(wxID_EXIT, "E&xit\tAlt-X");

m_docManager->FileHistoryUseMenu(file_menu);

wxMenu* help_menu = new wxMenu;

help_menu->Append(HELP_ABOUT, "&About\tF1");

wxMenuBar* menu_bar = new wxMenuBar;

menu_bar->Append(file_menu, "&File");

menu_bar->Append(help_menu, "&Help");

frame->SetMenuBar(menu_bar);

frame->Centre(wxBOTH);

frame->Show(TRUE);

frame->Maximize(TRUE);

SetTopWindow(frame);

return TRUE;
}

int MyApp::OnExit(void)
{
delete m_docManager;

return 0;
}

wxMDIChildFrame* MyApp::CreateChildFrame(wxDocument* doc, wxView* view, bool isCanvas)
{

wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame(doc,
view,
GetMainFrame(),
-1,
"",
wxPoint(10, 10),
wxSize(600, 400),
wxDEFAULT_FRAME_STYLE);

subframe->SetIcon(wxString("wxFEA"));

wxMenu* file_menu = new wxMenu;

file_menu->Append(wxID_NEW, "&New...");

file_menu->Append(wxID_OPEN, "&Open...");

file_menu->Append(wxID_CLOSE, "&Close");

file_menu->Append(wxID_SAVE, "&Save");

file_menu->Append(wxID_SAVEAS, "Save &As...");

if (isCanvas)
{
file_menu->AppendSeparator();

file_menu->Append(wxID_PRINT, "&Print...");

file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");

file_menu->Append(wxID_PREVIEW, "Print Pre&view");
}

file_menu->AppendSeparator();

file_menu->Append(wxID_EXIT, "E&xit");

wxMenu* help_menu = new wxMenu;

help_menu->Append(HELP_ABOUT, "&About");

wxMenuBar* menu_bar = new wxMenuBar;

menu_bar->Append(file_menu, "&File");

menu_bar->Append(help_menu, "&Help");

subframe->SetMenuBar(menu_bar);

return subframe;
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////MyFrame Class/////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

IMPLEMENT_CLASS(MyFrame, wxDocMDIParentFrame)

BEGIN_EVENT_TABLE(MyFrame, wxDocMDIParentFrame)
EVT_MENU(HELP_ABOUT, MyFrame::OnAbout)
END_EVENT_TABLE()

MyFrame::MyFrame(wxDocManager* manager,
wxFrame* frame,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long type)
: wxDocMDIParentFrame(manager, frame, -1, title, pos, size, type, "myFrame")
{

}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
{
(void)wxMessageBox("wxFEA - (c) LISA-FET", "About wxFEA");
}

MyCanvas* MyFrame::CreateCanvas(wxView* view, wxFrame* parent)
{
int width, height;

parent->GetClientSize(&width, &height);

MyCanvas* canvas = new MyCanvas(view,
parent,
wxPoint(0, 0),
wxSize(width, height),
0);

canvas->SetCursor(wxCursor(wxCURSOR_ARROW));

return canvas;
}

MyFrame* GetMainFrame(void)
{
return frame;
}

////////////////////////////////////////////////////////////////
// Name: mycanvas.h
// Purpose: The wxView & wxScrolledWindow Class
////////////////////////////////////////////////////////////////

#ifndef __MYVIEW__
#define __MYVIEW__

#include "wx/docview.h"
#include "cascade.h"

////////////////////////////////////////////////////////////
//Name : enum CurAction3d
//Usage : flags for filtering mouse events to execute the
// appropriate zoom, pan, rotate, select functions
////////////////////////////////////////////////////////////

enum CurAction3d {
CurAction3d_Nothing,
CurAction3d_WindowZooming,
CurAction3d_DynamicPanning,
CurAction3d_DynamicRotation
};

////////////////////////////////////////////////////////////
//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
////////////////////////////////////////////////////////////

class MyCanvas: public wxScrolledWindow
{
public:

//////////////////////////wxWindows///////////////////////////

wxView *view;

////////////////////////////////////////////////////////////
//Name : MyCanvas
//Usage : Constructor. Initializes the wxScrolledWindow
// from which it is derived
////////////////////////////////////////////////////////////

MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style);

~MyCanvas();

////////////////////////////////////////////////////////////
//Name : OnDraw
//Usage : This function is called whenever the window is
// invalidated e.g if a window on top of it is moved
////////////////////////////////////////////////////////////

virtual void OnDraw(wxDC& dc);

////////////////////////////Cascade/////////////////////////////

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
//////////////////////////////////////////////

CurAction3d CurMode;

long myXmin;

long myYmin;

long myXmax;

long myYmax;

long xMouse;

long yMouse;

////////
//End*//
////////

/////////////////////Event-Table Functions///////////////////////

void OnSize(wxSizeEvent& event);

void OnLeftDown(wxMouseEvent& event);

void OnLeftUp(wxMouseEvent& event);

void OnMotion(wxMouseEvent& event);

void OnRightDown(wxMouseEvent& event);

void OnRightUp(wxMouseEvent& event);

void OnKeyboard(wxKeyEvent& event);

/////////////////////End Event-Table Functions////////////////////

//////////////////////////////////////////////
// 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

/////////
//End**//
/////////

void Erase();

private:

DECLARE_EVENT_TABLE()

};

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////wxView Class//////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
//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
////////////////////////////////////////////////////////////

class MyView: public wxView
{

//////////////////////////wxWindows///////////////////////////

public:
wxFrame *frame;

MyCanvas *canvas;

MyView() { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; }

~MyView() {}

bool OnCreate(wxDocument *doc, long flags);

void OnDraw(wxDC *dc);

void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);

bool OnClose(bool deleteWindow = TRUE);

/////////////////////Event-Table Functions///////////////////////

void OnZoom(wxCommandEvent& event);

void OnFit(wxCommandEvent& event);

void OnRotate(wxCommandEvent& event);

void OnPan(wxCommandEvent& event);

void OnHiddenOn(wxCommandEvent& event);

void OnHiddenOff(wxCommandEvent& event);

void OnWireframe(wxCommandEvent& event);

void OnRender(wxCommandEvent& event);

private:
DECLARE_DYNAMIC_CLASS(MyView)

DECLARE_EVENT_TABLE()
};

#endif

////////////////////////////////////////////////////////////////
// Name: mycanvas.cpp
// Purpose: The wxView & wxScrolledWindow Class
////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "myapp.h"
#include "mydoc.h"
#include "mycanvas.h"

BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_SIZE(MyCanvas::OnSize)
EVT_LEFT_DOWN(MyCanvas::OnLeftDown)
EVT_LEFT_UP(MyCanvas::OnLeftUp)
EVT_MOTION(MyCanvas::OnMotion)
EVT_RIGHT_DOWN(MyCanvas::OnRightDown)
EVT_RIGHT_UP(MyCanvas::OnRightUp)
END_EVENT_TABLE()

MyCanvas::MyCanvas(wxView *v,
wxFrame *frame,
const wxPoint& pos,
const wxSize& size,
long style)
: wxScrolledWindow(frame, -1, pos, size, style)
{
view = v;

////////////////////////////Cascade/////////////////////////////

myXmin = 0;

myYmin = 0;

myXmax = 0;

myYmax = 0;

xMouse = 0;

yMouse = 0;

CurMode = CurAction3d_Nothing;

cView = GetDocument()->GetViewer()->CreateView(); // create the view

Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = ((MyApp&)wxGetApp()).GetGraphicDevice();

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
////////////////////////////////////////////////////////////

void MyCanvas::OnDraw(wxDC& dc)
{
cView->Redraw();
}

////////////////////////////Cascade/////////////////////////////

MyDoc* MyCanvas::GetDocument()
{
return (MyDoc*) ((MyApp&)wxGetApp()).m_docManager->GetCurrentDocument();
}

////////////////////////////////////////////////////////////
//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
//////////////////////////////////////////////

void MyCanvas::OnLeftDown(wxMouseEvent& event)
{
event.GetPosition(&xMouse,&yMouse);

myXmin = xMouse;

myXmax = xMouse;

myYmax = yMouse;

myYmin = yMouse;

switch (CurMode)
{
case CurAction3d_Nothing :

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;

case CurAction3d_WindowZooming :

break;

case CurAction3d_DynamicPanning :

break;

case CurAction3d_DynamicRotation :

cView->StartRotation(xMouse,yMouse);

break;

} // end switch (CurMode)

}

void MyCanvas::OnLeftUp(wxMouseEvent& event)
{

event.GetPosition(&xMouse,&yMouse);

myXmax = xMouse;

myYmax = yMouse;

if(CurMode == CurAction3d_Nothing)
wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));

if (CurMode == CurAction3d_WindowZooming)
{
DrawRectangle(myXmin,myYmin,xMouse,yMouse, false);

ZoomWnd(); // zooming by rubber-banding zoom area

ReleaseCapture();// ask window to no longer give us events even if outside the view

}

if (CurMode == CurAction3d_Nothing)
{
DrawRectangle(myXmin,myYmin,xMouse,yMouse, false);

ReleaseCapture();// ask window to no longer give us events even if outside the view
}

}

void MyCanvas::OnRightDown(wxMouseEvent& event)
{
event.GetPosition(&xMouse,&yMouse);

myXmax = xMouse;

myYmax = yMouse;

if (event.m_controlDown)
{

cView->StartRotation(xMouse,yMouse); // for CtrlRotate

} // end if (event.m_controlDown)

switch (CurMode)
{
case CurAction3d_Nothing :

if(!event.m_controlDown)
wxMessageBox("Your Pop-up Menu here","wxWindow::PopupMenu()");

break;

case CurAction3d_WindowZooming :

wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));

CurMode = CurAction3d_Nothing;

break;

case CurAction3d_DynamicPanning :

wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));

CurMode = CurAction3d_Nothing;

break;

case CurAction3d_DynamicRotation :

wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));

CurMode = CurAction3d_Nothing;

break;

} // end switch (CurMode)
}

void MyCanvas::OnRightUp(wxMouseEvent& WXUNUSED(event))
{
wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));
}

void MyCanvas::OnMotion(wxMouseEvent& event)
{

event.GetPosition(&xMouse,&yMouse);

////// 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

wxWindow::SetCursor(wxCursor(wxCURSOR_ARROW));

DrawRectangle(myXmin,myYmin,xMouse,yMouse, false);

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

DrawRectangle(myXmin,myYmin,xMouse,yMouse,false);
DrawRectangle(myXmin,myYmin,xMouse,yMouse,true);
}

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));

CurMode = CurAction3d_Nothing;

cView->Zoom(x1,y1,x2,y2);

myXmax = x2;

myYmax = y2;
}

void MyCanvas::CtrlRotate(long& xcoord, long& ycoord)
{
wxWindow::SetCursor(wxCursor(wxCURSOR_BULLSEYE));

CurMode = CurAction3d_Nothing;

cView->Rotation(xcoord, ycoord);
}

void MyCanvas::ZoomWnd()
{
if ((abs(myXmin-myXmax)>1) || (abs(myYmin-myYmax)>1))
{
cView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);

}
}

void MyCanvas::DynRotate()
{
cView->Rotation(xMouse,yMouse);

cView->Redraw();
}

void MyCanvas::DynPan()
{
cView->Pan(xMouse-myXmax,myYmax-yMouse);

myXmax = xMouse;

myYmax = yMouse;
}

void MyCanvas::ShiftSelectObject ( const Standard_Integer flag)
{

if (flag == 0)
GetDocument()->myAISContext->ShiftSelect(myXmin, myYmin, xMouse, yMouse, cView);

if (flag == 1)
GetDocument()->myAISContext->ShiftSelect();
}

void MyCanvas::SelectObject(const Standard_Integer flag)
{

// flag == 1 button down
// flag == 0 move

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;

static bool flag;

wxClientDC dc(this);

wxPen thePen("black",1,wxSHORT_DASH);

dc.SetPen(thePen);

dc.SetBrush(*wxTRANSPARENT_BRUSH);

dc.SetLogicalFunction(wxINVERT);

if(flag && !Draw)
{

dc.DrawLine(storedInitX,storedInitY,storedFinalX,storedInitY);

dc.DrawLine(storedInitX,storedInitY,storedInitX,storedFinalY);

dc.DrawLine(storedFinalX,storedInitY,storedFinalX,storedFinalY);

dc.DrawLine(storedInitX,storedFinalY,storedFinalX,storedFinalY);

flag = false;

} // end if(flag && !Draw)

storedInitX = min (initX, finalX);

storedInitY = min (initY, finalY);

storedFinalX = max (initX, finalX);

storedFinalY = max (initY, finalY);

if (Draw)
{

dc.DrawLine(storedInitX,storedInitY,storedFinalX,storedInitY);

dc.DrawLine(storedInitX,storedInitY,storedInitX,storedFinalY);

dc.DrawLine(storedFinalX,storedInitY,storedFinalX,storedFinalY);

dc.DrawLine(storedInitX,storedFinalY,storedFinalX,storedFinalY);

flag = true;

} // end if (Draw)

dc.SetPen(wxNullPen);

dc.SetBrush(wxNullBrush);
}

////////////////////////////////////////////////////////////
//Name : OnKeyBoard
//Usage : This is enable the user to use the keyboard to
// do rotate, pan or zoom
////////////////////////////////////////////////////////////

void MyCanvas::OnKeyboard(wxKeyEvent& event)
{

static Standard_Real rotate1(0), rotate2(0);

Standard_Real pan1(0), pan2(0);

static Standard_Real zoomX1(0), zoomY1(0), zoomX2(0), zoomY2(0) ;

cView->StartRotation(rotate1,rotate2);

if(event.GetKeyCode()==WXK_LEFT)
{

if(event.m_controlDown)
{
if(event.m_shiftDown)
pan1 -= 30;
else
pan1 -= 5;

cView->Pan(pan1,0);

return;
}

if(event.m_shiftDown)
rotate1 -= 30;
else
rotate1 -= 15;

cView->Rotation(rotate1,rotate2);

}

else if(event.GetKeyCode()==WXK_RIGHT)
{
if(event.m_controlDown)
{
if(event.m_shiftDown)
pan1 += 30;
else
pan1 += 5;

cView->Pan(pan1,0);

return;
}

if(event.m_shiftDown)
rotate1 += 30;
else
rotate1 += 15;

cView->Rotation(rotate1,rotate2);

}

else if(event.GetKeyCode()==WXK_UP)
{
if(event.m_controlDown)
{
if(event.m_shiftDown)
pan2 += 30;
else
pan2 += 5;

cView->Pan(0,pan2);

return;
}

if(event.m_shiftDown)
rotate2 -= 30;
else
rotate2 -= 15;

cView->Rotation(rotate1,rotate2);

}

else if(event.GetKeyCode()==WXK_DOWN)
{
if(event.m_controlDown)
{
if(event.m_shiftDown)
pan2 -= 30;
else
pan2 -= 5;

cView->Pan(0,pan2);

return;
}

if(event.m_shiftDown)
rotate2 += 30;
else
rotate2 += 15;

cView->Rotation(rotate1,rotate2);

}

else if(event.GetKeyCode()==WXK_PRIOR)
{
zoomX1 -= 5;

zoomY1 -= 5;

cView->Zoom(zoomX1,zoomY1,zoomX2,zoomY2);

zoomX2 = zoomX1;

zoomY2 = zoomY1;

}

else if(event.GetKeyCode()==WXK_NEXT)
{
zoomX1 += 5;

zoomY1 += 5;

cView->Zoom(zoomX1,zoomY1,zoomX2,zoomY2);

zoomX2 = zoomX1;

zoomY2 = zoomY1;
}

else if(event.GetKeyCode()==WXK_DELETE)
Erase();
}

void MyCanvas::Erase()
{
// Get the selected interactive object
GetDocument()->myAISContext->InitCurrent();

Handle(AIS_InteractiveObject) curAISObject = GetDocument()->myAISContext->Current();

if(!GetDocument()->myAISContext->IsCurrent(curAISObject)) //myAISContext->NbCurrents()!=1)
{
wxMessageBox("Select an Object","Edit");
return;
}
GetDocument()->myAISContext->EraseSelected();
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////wxView Class//////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC_CLASS(MyView, wxView)

BEGIN_EVENT_TABLE(MyView, wxView)
EVT_MENU(ZOOM_VIEW, MyView::OnZoom)
EVT_MENU(FIT_VIEW, MyView::OnFit)
EVT_MENU(ROTATE_VIEW, MyView::OnRotate)
EVT_MENU(PAN_VIEW, MyView::OnPan)
EVT_MENU(HIDDEN_ON_VIEW, MyView::OnHiddenOn)
EVT_MENU(HIDDEN_OFF_VIEW, MyView::OnHiddenOff)
EVT_MENU(WIREFRAME_VIEW, MyView::OnWireframe)
EVT_MENU(RENDER_VIEW, MyView::OnRender)
END_EVENT_TABLE()

bool MyView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{

//////////////////////////wxWindows///////////////////////////

///// Menu Creation /////

wxMenu* file_menu = new wxMenu;

file_menu->Append(wxID_NEW, "&New...\tCtrl-N");

file_menu->Append(wxID_OPEN, "&Open...\tCtrl-X");

file_menu->AppendSeparator();

file_menu->Append(wxID_EXIT, "E&xit\tAlt-X");

wxGetApp().m_docManager->FileHistoryUseMenu(file_menu);

wxMenu* view_menu = new wxMenu;

view_menu->Append(ZOOM_VIEW, "&Zoom");

view_menu->Append(ROTATE_VIEW, "&Rotate");

view_menu->Append(PAN_VIEW, "&Pan");

view_menu->Append(FIT_VIEW, "&Fit");

view_menu->Append(HIDDEN_ON_VIEW, "Hidden &On");

view_menu->Append(HIDDEN_OFF_VIEW, "&Hidden Off");

view_menu->Append(WIREFRAME_VIEW, "&Wireframe");

view_menu->Append(RENDER_VIEW, "&Render");

wxMenu* help_menu = new wxMenu;

help_menu->Append(HELP_ABOUT, "&About\tF1");

wxMenuBar* menu_bar = new wxMenuBar;

menu_bar->Append(file_menu, "&File");

menu_bar->Append(view_menu, "&View");

menu_bar->Append(help_menu, "&Help");

///// Menu Creation End //////

frame = wxGetApp().CreateChildFrame(doc, this, TRUE);

frame->SetTitle("");

frame->SetMenuBar(menu_bar);

frame->Centre(wxBOTH);

canvas = GetMainFrame()->CreateCanvas(this, frame);

#ifdef __X__
// X seems to require a forced resize
int x, y;
frame->GetSize(&x, &y);
frame->SetSize(-1, -1, x, y);
#endif

frame->Show(TRUE);

Activate(TRUE);

return TRUE;
}

void MyView::OnDraw(wxDC *dc)
{

}

void MyView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{
if (canvas)

canvas->Refresh();

}

// Clean up windows used for displaying the view.
bool MyView::OnClose(bool deleteWindow)
{
if (!GetDocument()->Close())
return FALSE;

canvas->Clear();

canvas->view = (wxView *) NULL;

canvas = (MyCanvas *) NULL;

wxString s(wxTheApp->GetAppName());

if (frame)
frame->SetTitle(s);

SetFrame((wxFrame*)NULL);

Activate(FALSE);

if (deleteWindow)
{
delete frame;

return TRUE;
}

return TRUE;
}

/////////////////////////////////////////////
// Begin****
// Menu related event handlers
/////////////////////////////////////////////

void MyView::OnZoom(wxCommandEvent& WXUNUSED(event))
{
canvas->SetCursor(wxCursor(wxCURSOR_MAGNIFIER));

canvas->CurMode = CurAction3d_WindowZooming;
}

void MyView::OnFit(wxCommandEvent& WXUNUSED(event))
{
canvas->cView->FitAll();

canvas->cView->ZFitAll();
}

void MyView::OnRotate(wxCommandEvent& WXUNUSED(event))
{
canvas->SetCursor(wxCursor(wxCURSOR_BULLSEYE));

canvas->CurMode = CurAction3d_DynamicRotation;
}

void MyView::OnPan(wxCommandEvent& WXUNUSED(event))
{
canvas->SetCursor(wxCursor(wxCURSOR_HAND));

canvas->CurMode = CurAction3d_DynamicPanning;
}

void MyView::OnHiddenOff(wxCommandEvent& WXUNUSED(event))
{
canvas->cView->SetDegenerateModeOn();
}

void MyView::OnHiddenOn(wxCommandEvent& WXUNUSED(event))
{
canvas->cView->SetDegenerateModeOff();
}

void MyView::OnWireframe(wxCommandEvent& WXUNUSED(event))
{
int width;

int height;

canvas->GetClientSize(&width, &height);

canvas->GetDocument()->myAISContext->Select (0,0,width,height,canvas->cView);

for(canvas->GetDocument()->myAISContext->InitCurrent();
canvas->GetDocument()->myAISContext->MoreCurrent();
canvas->GetDocument()->myAISContext->NextCurrent())

canvas->GetDocument()->myAISContext->SetDisplayMode(canvas->GetDocument()->myAISContext->Current(),0);
}

void MyView::OnRender(wxCommandEvent& WXUNUSED(event))
{
canvas->cView->SetDegenerateModeOn();

int width;

int height;

canvas->GetClientSize(&width, &height);

canvas->GetDocument()->myAISContext->Select (0,0,width,height,canvas->cView);

for(canvas->GetDocument()->myAISContext->InitCurrent();
canvas->GetDocument()->myAISContext->MoreCurrent();
canvas->GetDocument()->myAISContext->NextCurrent())

canvas->GetDocument()->myAISContext->SetDisplayMode(canvas->GetDocument()->myAISContext->Current(),1);
}

///////////
//End****//
///////////

////////////////////////////////////////////////////////////////
// Name: mydoc.h
// Purpose: The wxDoc Class
////////////////////////////////////////////////////////////////

#ifndef __MYDOC__
#define __MYDOC__

#include "wx/docview.h"
#include "cascade.h"

class MyCanvas; // forward declaration

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////MyDoc 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.
////////////////////////////////////////////////////////////

class MyDoc : public wxDocument
{

public :

//////////////////////////wxWindows///////////////////////////

MyDoc(void);

~MyDoc(void);

virtual bool OnSaveDocument(const wxString& filename);

virtual bool OnOpenDocument(const wxString& filename);

MyCanvas* GetCanvas(); // handle to canvas associated with document

////////////////////////////Cascade/////////////////////////////

////////////////////////////////////////////////////////////////
//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.
////////////////////////////////////////////////////////////////

Handle(V3d_Viewer) cViewer;

Handle(V3d_Viewer) GetViewer() { return cViewer; };

////////////////////////////////////////////////////////////////
//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.
////////////////////////////////////////////////////////////////

Handle(AIS_InteractiveContext) myAISContext;

Handle(AIS_InteractiveContext) GetAISContext()
{ return myAISContext; };

private:

DECLARE_DYNAMIC_CLASS(MyDoc)

DECLARE_EVENT_TABLE()

};

#endif

////////////////////////////////////////////////////////////////
// Name: mydoc.cpp
// Purpose: The wxDoc Class
////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "mydoc.h"
#include "mycanvas.h"
#include "myapp.h"

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////MyDoc Class///////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC_CLASS(MyDoc, wxDocument)

BEGIN_EVENT_TABLE (MyDoc, wxDocument)

END_EVENT_TABLE()

MyDoc::MyDoc()
{
////////////////////////////Cascade/////////////////////////////

Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice = ((MyApp&)wxGetApp()).GetGraphicDevice();

cViewer = new V3d_Viewer(theGraphicDevice,(short *) "Visu3D"); // instantiating 3DViewer

cViewer->SetDefaultLights();

cViewer->SetLightOn();

myAISContext =new AIS_InteractiveContext(cViewer); // instantiating an AIS_InteractiveContext object

//////Create and display a trihedron in the viewer////

Handle(AIS_Trihedron) aTrihedron;

Handle(Geom_Axis2Placement) anAxis=new Geom_Axis2Placement(gp::XOY());

aTrihedron=new AIS_Trihedron(anAxis);

myAISContext->Display(aTrihedron);

////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);
}

MyCanvas* MyDoc::GetCanvas()
{
return ((MyView*) ((MyApp&)wxGetApp()).m_docManager->GetCurrentView())->canvas;
}

MyDoc::~MyDoc()
{
}

bool MyDoc::OnSaveDocument(const wxString& filename)
{
return TRUE;
}

bool MyDoc::OnOpenDocument(const wxString& filename)
{
return TRUE;
}

///////////////////////////////////////////////////////////////
// Name: cascade.h
// Purpose: Standard Cascade common Includes
////////////////////////////////////////////////////////////////

#ifndef CASCADE_H
#define CASCADE_H

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#endif

////////////////////////////////////////////////////////////////
// Name: cascade.cpp
// Purpose: Standard Cascade common Includes
////////////////////////////////////////////////////////////////

#include "cascade.h"

Canuck's picture

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.

AIS_InteractiveContext.hxx
AIS_Shape.hxx
Graphic3d_WNTGraphicDevice.hxx
V3d_Viewer.hxx
V3d_View.hxx
WNT_Window.hxx
Standard_ErrorHandler.hxx
Geom_Circle.hxx
AIS_Circle.hxx
GC_MakeCircle.hxx
BRepPrimAPI_MakeSphere.hxx
BRepPrimAPI_MakeCylinder.hxx
StdPrs_WFDeflectionShape.hxx
StdPrs_ShadedShape.hxx
TopExp_Explorer.hxx
BRep_Tool.hxx
Geom_Plane.hxx
AIS_Drawer.hxx
TopoDS.hxx
Prs3d_ShadingAspect.hxx
StdSelect_BRepSelectionTool.hxx
gp_Pnt.hxx
gp_Dir.hxx
gp_Lin.hxx
Geom_Line.hxx
AIS_Line.hxx
AIS_Trihedron.hxx
Geom_Axis2Placement.hxx
gp.hxx
UnitsAPI.hxx

Canuck's picture

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 Mueller's picture

Cool,

that were the hints I missed for creating my first wxWindows version.
Many thanks for these good hints!!!!!!!

Best regards,

Patrik

Andras's picture

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.

Andras.