Multiple views

Hi. I wrote a very simple program with multiple views. Once launched, it works well. But after a while views begin to be updated very slowly, one after another. Why?
Program:

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

class MyWindow;

class MyApp : public wxApp
{
Handle(Graphic3d_WNTGraphicDevice) TheGraphicDevice;
Handle(AIS_InteractiveContext) cAISContext;
Handle_V3d_Viewer cViewer;
public:
const Handle(Graphic3d_WNTGraphicDevice)& GetGD() const { return TheGraphicDevice; }
const Handle(AIS_InteractiveContext)& GetAISContext() const { return cAISContext; }
const Handle(V3d_Viewer)& GetViewer() const { return cViewer; }
virtual bool OnInit();
};

class MyFrame : public wxFrame
{
MyWindow *w1, *w2, *w3, *w4, *w5;
public:
MyFrame(const wxString& title);
~MyFrame();
private:
DECLARE_EVENT_TABLE()
};

class MyWindow : public wxWindow
{
Handle_V3d_View cView;
Handle_WNT_Window cWNTWindow;
public:
MyWindow(wxWindow* parent, const wxPoint& pos, const wxSize& size, const long style = 0);
~MyWindow();
void OnPaint(wxPaintEvent& event);
void OnMouseMove(wxMouseEvent& event);
void OnLeftDown(wxMouseEvent& event);
private:
DECLARE_EVENT_TABLE()
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
TheGraphicDevice = new Graphic3d_WNTGraphicDevice();
cViewer = new V3d_Viewer(TheGraphicDevice, (short*)"s3", "", 1000, V3d_XposYnegZpos, Quantity_NOC_BLACK, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT);
cViewer->Init();
cAISContext = new AIS_InteractiveContext(cViewer);
cAISContext->SetDisplayMode(AIS_Shaded);
/////////////////////////////////////////////////

TopoDS_Shape box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), gp_Pnt(10, 10, 10));
Handle_AIS_Shape s = new AIS_Shape(box);
s->SetWidth(2); s->SetColor(Quantity_NOC_BLUE1);
cAISContext->Display(s);
box = BRepPrimAPI_MakeBox(gp_Pnt(20, 20, 20), gp_Pnt(30, 30, 30));
s = new AIS_Shape(box);
s->SetWidth(2); s->SetColor(Quantity_NOC_RED1);
cAISContext->Display(s);
box = BRepPrimAPI_MakeBox(gp_Pnt(40, 40, 40), gp_Pnt(50, 50, 50));
s = new AIS_Shape(box);
s->SetWidth(2); s->SetColor(Quantity_NOC_YELLOW1);
cAISContext->Display(s);

/////////////////////////////////////////////////
MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"));
frame->SetSize(wxRect(0,0,800,600));
frame->Show(true);
return true;
}

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
END_EVENT_TABLE()

MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title)
{
w1 = new MyWindow(this, wxPoint(0, 0), wxSize(200, 200));
w2 = new MyWindow(this, wxPoint(200, 0), wxSize(400, 200));
w3 = new MyWindow(this, wxPoint(400, 0), wxSize(600, 200));
w4 = new MyWindow(this, wxPoint(600, 0), wxSize(800, 200));
w5 = new MyWindow(this, wxPoint(0, 200), wxSize(800, 600));
}

MyFrame::~MyFrame()
{
delete w1;
delete w2;
delete w3;
delete w4;
delete w5;
}

BEGIN_EVENT_TABLE(MyWindow, wxWindow)
EVT_PAINT(MyWindow::OnPaint)
EVT_LEFT_DOWN(MyWindow::OnLeftDown)
EVT_MOTION(MyWindow::OnMouseMove)
END_EVENT_TABLE()

MyWindow::MyWindow(wxWindow* parent, const wxPoint& pos, const wxSize& size, const long style) : wxWindow(parent, wxID_ANY, pos, size, style)
{
cWNTWindow = new WNT_Window(wxGetApp().GetGD(), GetHandle());
cView = wxGetApp().GetViewer()->CreateView();
cView->SetWindow(cWNTWindow);
cView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.2);
cView->FitAll(0.2);
}

MyWindow::~MyWindow()
{
cView->Remove();
}

void MyWindow::OnPaint(wxPaintEvent &event)
{
wxPaintDC dc(this);
cView->Redraw();
}

void MyWindow::OnLeftDown(wxMouseEvent &event)
{ wxGetApp().GetAISContext()->Select();
if (event.ControlDown())
cView->StartRotation(event.GetX(), event.GetY());
}

void MyWindow::OnMouseMove(wxMouseEvent& event)
{ wxGetApp().GetAISContext()->MoveTo(event.GetX(), event.GetY(), cView);
if (event.ControlDown() && event.LeftIsDown())
cView->Rotation(event.GetX(), event.GetY());
}

Paul Jimenez's picture

The problem is caused by not releasing some objects in one of OpenCASCADE methods. The problem is known, and the patch is here: http://www.opencascade.org/org/forum/thread_11016/

int's picture

Thank you very much!