From 23e9509fe3c71033515d60b110a84f2310d8f082 Mon Sep 17 00:00:00 2001 From: Eduardo Davila Date: Thu, 17 Feb 2011 11:02:07 +0000 Subject: [PATCH] eduardo --- cmake/CREAMacro_FindAndUseVTK.cmake | 12 ++ src/creawxVTKRenderWindowInteractor.cxx | 270 ++++++++++++++---------- src/creawxVTKRenderWindowInteractor.h | 37 ++-- 3 files changed, 186 insertions(+), 133 deletions(-) diff --git a/cmake/CREAMacro_FindAndUseVTK.cmake b/cmake/CREAMacro_FindAndUseVTK.cmake index 50dfe5b..751426a 100644 --- a/cmake/CREAMacro_FindAndUseVTK.cmake +++ b/cmake/CREAMacro_FindAndUseVTK.cmake @@ -13,6 +13,18 @@ MACRO(CREA_FIND_AND_USE_VTK) SET(VTK_BUILD_SETTINGS_FILE OFF) INCLUDE(${VTK_USE_FILE}) + IF(VTK_USE_GL2PS) + add_definitions(-DUSE_WXGLCANVAS) + # CMake 2.6: + # technically those packages are not required since one can still use the Motif/X11 version and not the gtk one: + FIND_PACKAGE(PkgConfig) + pkg_check_modules (GTK2 gtk+-2.0) + #MESSAGE("${GTK2_INCLUDE_DIRS}") + INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS}) + LINK_LIBRARIES(${GTK2_LIBRARIES}) + # Can I require all my user to have the gl lib on linux, even if they do not really need it... + SET(WXGLCANVASLIBS "gl") + ENDIF(VTK_USE_GL2PS) CREA_DEFINE( USE_VTK ) CREA_DEFINE( _USE_VTK_ ) diff --git a/src/creawxVTKRenderWindowInteractor.cxx b/src/creawxVTKRenderWindowInteractor.cxx index 4f6a0bb..3c8bc80 100644 --- a/src/creawxVTKRenderWindowInteractor.cxx +++ b/src/creawxVTKRenderWindowInteractor.cxx @@ -3,21 +3,24 @@ Program: Visualization Toolkit Module: $RCSfile: creawxVTKRenderWindowInteractor.cxx,v $ Language: C++ - Date: $Date: 2009/10/05 19:41:56 $ - Version: $Revision: 1.5 $ + Date: $Date: 2011/02/17 11:02:08 $ + Version: $Revision: 1.6 $ - Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen + Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ + #ifdef USE_WXWIDGETS #ifdef USE_VTK +#include + #include "creawxVTKRenderWindowInteractor.h" //This is needed for vtk 3.1 : @@ -25,26 +28,27 @@ # include "vtkVersion.h" #endif -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) # include "vtkCommand.h" #else # include "vtkInteractorStyle.h" #endif +#include "vtkDebugLeaks.h" +#ifdef __WXMAC__ +#include "vtkCarbonRenderWindow.h" +#endif - - //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0 +//Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0 #if (!wxCHECK_VERSION(2, 4, 0)) - wxWindow* wxGetTopLevelParent(wxWindow *win) - { +wxWindow* wxGetTopLevelParent(wxWindow *win) +{ while ( win && !win->IsTopLevel() ) - win = win->GetParent(); + win = win->GetParent(); return win; - } +} #endif -//======================================================================= - // To access objc calls on cocoa #ifdef __WXCOCOA__ #ifdef VTK_USE_COCOA @@ -59,11 +63,15 @@ #ifdef __WXGTK__ # include // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0 # include "gdk/gdkprivate.h" +#if wxCHECK_VERSION(2, 8, 0) #ifdef __WXGTK20__ #include #else #include #endif +#else +#include +#endif #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \ GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \ GDK_WINDOW_XWINDOW((wxwin)->m_widget->window) @@ -91,6 +99,7 @@ namespace crea #if defined(__WXGTK__) && defined(USE_WXGLCANVAS) IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxGLCanvas) + #else IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxWindow) #endif //__WXGTK__ @@ -117,22 +126,26 @@ BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxWindow) EVT_ENTER_WINDOW(creawxVTKRenderWindowInteractor::OnEnter) EVT_LEAVE_WINDOW(creawxVTKRenderWindowInteractor::OnLeave) EVT_MOUSEWHEEL (creawxVTKRenderWindowInteractor::OnMouseWheel) -// If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions -// of all characters are always returned. EVT_CHAR also performs -// other necessary keyboard-dependent translations. - //EVT_KEY_DOWN (creawxVTKRenderWindowInteractor::OnKeyDown) - EVT_CHAR (creawxVTKRenderWindowInteractor::OnKeyDown) + EVT_KEY_DOWN (creawxVTKRenderWindowInteractor::OnKeyDown) EVT_KEY_UP (creawxVTKRenderWindowInteractor::OnKeyUp) + EVT_CHAR (creawxVTKRenderWindowInteractor::OnChar) #endif EVT_TIMER (ID_creawxVTKRenderWindowInteractor_TIMER, creawxVTKRenderWindowInteractor::OnTimer) EVT_SIZE (creawxVTKRenderWindowInteractor::OnSize) END_EVENT_TABLE() +vtkCxxRevisionMacro(creawxVTKRenderWindowInteractor, "$Revision: 1.6 $") +vtkInstantiatorNewMacro(creawxVTKRenderWindowInteractor) + //--------------------------------------------------------------------------- #if defined(__WXGTK__) && defined(USE_WXGLCANVAS) -creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxGLCanvas() +#if (wxCHECK_VERSION(2, 8, 0)) +creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor() #else -creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxWindow() +creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor() +#endif +#else +creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor() #endif //__WXGTK__ , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER) , ActiveButton(wxEVT_NULL) @@ -143,12 +156,12 @@ creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : vtkRenderWi , RenderWhenDisabled(1) , UseCaptureMouse(0) { - +#ifdef VTK_DEBUG_LEAKS + vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor"); +#endif this->RenderWindow = NULL; this->SetRenderWindow(vtkRenderWindow::New()); this->RenderWindow->Delete(); - - //this->SetBackgroundColour( wxColour(255,0,255) ); } //--------------------------------------------------------------------------- creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *parent, @@ -158,7 +171,7 @@ creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *paren long style, const wxString &name) #if defined(__WXGTK__) && defined(USE_WXGLCANVAS) - : vtkRenderWindowInteractor(), wxGLCanvas(parent, id, pos, size, style, name) + : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor() #else : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor() #endif //__WXGTK__ @@ -171,19 +184,23 @@ creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *paren , RenderWhenDisabled(1) , UseCaptureMouse(0) { - +#ifdef VTK_DEBUG_LEAKS + vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor"); +#endif this->RenderWindow = NULL; this->SetRenderWindow(vtkRenderWindow::New()); this->RenderWindow->Delete(); - - // this->SetBackgroundColour( wxColour(255,0,0) ); +#ifdef __WXMAC__ + // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event, + // so we update the size information of the interactor/renderwindow here + this->UpdateSize(size.x, size.y); +#endif } //--------------------------------------------------------------------------- creawxVTKRenderWindowInteractor::~creawxVTKRenderWindowInteractor() -{ - // LG : trompe la mort ! +{ SetRenderWindow(NULL); - SetReferenceCount(0); + SetInteractorStyle(NULL); } //--------------------------------------------------------------------------- creawxVTKRenderWindowInteractor * creawxVTKRenderWindowInteractor::New() @@ -271,7 +288,7 @@ int creawxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype)) assert(false); return 1; - + } //--------------------------------------------------------------------------- int creawxVTKRenderWindowInteractor::DestroyTimer() @@ -284,8 +301,8 @@ void creawxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event)) { if (!Enabled) return; - -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::TimerEvent, NULL); #else @@ -309,7 +326,7 @@ long creawxVTKRenderWindowInteractor::GetHandleHack() long handle_tmp = 0; // __WXMSW__ is for Win32 -//__WXMAX__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available) +//__WXMAC__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available) // __WXGTK__ is for both gtk 1.2.x and gtk 2.x #if defined(__WXMSW__) || defined(__WXMAC__) handle_tmp = (long)this->GetHandle(); @@ -320,11 +337,11 @@ long creawxVTKRenderWindowInteractor::GetHandleHack() // Here is how to find the NSWindow wxTopLevelWindow* toplevel = dynamic_cast( wxGetTopLevelParent( this ) ); - if (toplevel != NULL ) + if (toplevel != NULL ) { handle_tmp = (long)toplevel->GetNSWindow(); } - // The NSView will be deducted from + // The NSView will be deducted from // [(NSWindow*)Handle contentView] // if only I knew how to write that in c++ #endif //__WXCOCOA__ @@ -343,7 +360,6 @@ long creawxVTKRenderWindowInteractor::GetHandleHack() //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event)) { - //must always be here wxPaintDC pDC(this); @@ -357,21 +373,20 @@ void creawxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event)) #endif //__WXMSW__ } // get vtk to render to the wxWindows - //bbtkDebugMessage("Wx",9,"creawxVTKRenderWindowInteractor::OnPaint"<UpdateGLRegion(); + } +#endif } //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event) { - //printf("EED creawxVTKRenderWindowInteractor::OnEraseBackground \n"); //turn off background erase to reduce flickering on MSW event.Skip(false); } @@ -382,12 +397,12 @@ void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event)) GetClientSize(&w, &h); UpdateSize(w, h); - if (!Enabled) + if (!Enabled) { return; } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) InvokeEvent(vtkCommand::ConfigureEvent, NULL); #endif //this will check for Handle @@ -396,13 +411,12 @@ void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event)) //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event) { - if (!Enabled) + if (!Enabled) { - return; + return; } - -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) - SetEventInformationFlipY(event.GetX(), event.GetY(), +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); InvokeEvent(vtkCommand::MouseMoveEvent, NULL); @@ -415,68 +429,69 @@ void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event) #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) void creawxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event) { - if (!Enabled) + if (!Enabled) { return; } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style - SetEventInformationFlipY(event.GetX(), event.GetY(), + SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); InvokeEvent(vtkCommand::EnterEvent, NULL); #else // old style InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(), - event.GetX(), Size[1] - event.GetY() - 1); + event.GetX(), Size[1] - event.GetY() - 1); #endif } //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event) { - if (!Enabled) + if (!Enabled) { return; } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style - SetEventInformationFlipY(event.GetX(), event.GetY(), + SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); InvokeEvent(vtkCommand::LeaveEvent, NULL); #else // old style InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(), - event.GetX(), Size[1] - event.GetY() - 1); + event.GetX(), Size[1] - event.GetY() - 1); #endif } //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event) { - if (!Enabled) + if (!Enabled) { return; } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style int keycode = event.GetKeyCode(); char key = '\0'; - if (keycode < 256) + if (((unsigned int)keycode) < 256) { // TODO: Unicode in non-Unicode mode ?? key = (char)keycode; } - SetEventInformationFlipY(event.GetX(), event.GetY(), - event.ControlDown(), event.ShiftDown(), key, 0, NULL); - + // we don't get a valid mouse position inside the key event on every platform + // so we retrieve the mouse position explicitly and pass it along + wxPoint mousePos = ScreenToClient(wxGetMousePosition()); + SetEventInformationFlipY(mousePos.x, mousePos.y, + event.ControlDown(), event.ShiftDown(), key, 0, NULL); InvokeEvent(vtkCommand::KeyPressEvent, NULL); - InvokeEvent(vtkCommand::CharEvent, NULL); #else - InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), + InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), event.GetKeyCode(), 1); #endif event.Skip(); @@ -484,31 +499,61 @@ void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event) //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event) { - if (!Enabled) + if (!Enabled) { return; } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style int keycode = event.GetKeyCode(); char key = '\0'; - if (keycode < 256) + if (((unsigned int)keycode) < 256) { // TODO: Unicode in non-Unicode mode ?? key = (char)keycode; } - SetEventInformationFlipY(event.GetX(), event.GetY(), - event.ControlDown(), event.ShiftDown(), key, 0, NULL); + // we don't get a valid mouse position inside the key event on every platform + // so we retrieve the mouse position explicitly and pass it along + wxPoint mousePos = ScreenToClient(wxGetMousePosition()); + SetEventInformationFlipY(mousePos.x, mousePos.y, + event.ControlDown(), event.ShiftDown(), key, 0, NULL); InvokeEvent(vtkCommand::KeyReleaseEvent, NULL); #else - InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), + InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), event.GetKeyCode(), 1); #endif event.Skip(); } #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1) + //--------------------------------------------------------------------------- +void creawxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event) +{ + if (!Enabled) + { + return; + } + +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + // new style + int keycode = event.GetKeyCode(); + char key = '\0'; + if (((unsigned int)keycode) < 256) + { + // TODO: Unicode in non-Unicode mode ?? + key = (char)keycode; + } + + // we don't get a valid mouse position inside the key event on every platform + // so we retrieve the mouse position explicitly and pass it along + wxPoint mousePos = ScreenToClient(wxGetMousePosition()); + SetEventInformationFlipY(mousePos.x, mousePos.y, + event.ControlDown(), event.ShiftDown(), key, 0, NULL); + InvokeEvent(vtkCommand::CharEvent, NULL); +#endif + event.Skip(); +} //--------------------------------------------------------------------------- void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event) { @@ -518,17 +563,23 @@ void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event) } ActiveButton = event.GetEventType(); -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) - SetEventInformationFlipY(event.GetX(), event.GetY(), + // On Mac (Carbon) and Windows we don't automatically get the focus when + // you click inside the window + // we therefore set the focus explicitly + // Apparently we need that on linux (GTK) too: + this->SetFocus(); + +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); #endif if(event.RightDown()) { -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::RightButtonPressEvent, NULL); -#else +#else // old style InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1); @@ -536,10 +587,10 @@ void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event) } else if(event.LeftDown()) { -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL); -#else +#else // old style InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1); @@ -547,10 +598,10 @@ void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event) } else if(event.MiddleDown()) { -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL); -#else +#else // old style InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1); @@ -570,24 +621,24 @@ void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event) { //EVT_xxx_DOWN == EVT_xxx_UP - 1 //This is only needed if two mouse buttons are pressed at the same time. - //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or + //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or //wxEVT_COMMAND_RIGHT_CLICK - if (!Enabled || (ActiveButton != (event.GetEventType()-1))) + if (!Enabled || (ActiveButton != (event.GetEventType()-1))) { return; } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) - SetEventInformationFlipY(event.GetX(), event.GetY(), +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) + SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); #endif - + if(ActiveButton == wxEVT_RIGHT_DOWN) { -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL); -#else +#else // old style InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1); @@ -595,10 +646,10 @@ void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event) } else if(ActiveButton == wxEVT_LEFT_DOWN) { -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL); -#else +#else // old style InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1); @@ -606,10 +657,10 @@ void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event) } else if(ActiveButton == wxEVT_MIDDLE_DOWN) { -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0) // new style InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL); -#else +#else // old style InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1); @@ -626,26 +677,24 @@ void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event) void creawxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event) { // Mouse wheel was only added after VTK 4.4 (I think...) -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) // new style //Set vtk event information ... The numebr of wheel rotations is stored in //the x varible. y varible is zero - SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0, + SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0, event.ControlDown(), event.ShiftDown(), '\0', 0, NULL); if(event.GetWheelRotation() > 0) { //Send event to VTK -// EED -// InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL); + InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL); } else { //Send event to VTK -// EED -// InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL); + InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL); } #endif - + } //--------------------------------------------------------------------------- @@ -671,7 +720,7 @@ void creawxVTKRenderWindowInteractor::Render() { RenderWindow->Render(); } -#if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) +#if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2) else if(GetHandleHack()) { //this means the user has reparented us; let's adapt to the @@ -699,12 +748,12 @@ void creawxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue) //it does this by disabling all windows (disallowing user-input to //prevent re-entrancy of code) and then handling all outstanding //GUI events. - - //However, this often triggers an OnPaint() method for creawxVTKRWIs, + + //However, this often triggers an OnPaint() method for wxVTKRWIs, //resulting in a Render(), resulting in Update() being called whilst //still in progress. - RenderWhenDisabled = (bool)(newValue!=0); + RenderWhenDisabled = (bool)newValue; } //--------------------------------------------------------------------------- // @@ -731,16 +780,11 @@ void creawxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) } -#if defined(_WIN32) -const char * creawxVTKRenderWindowInteractor::GetClassName() const -{ - return "creawxVTKRenderWindowInteractor"; -} -#endif //_WIN32 } // LG : EO namespace //======================================================================= + #endif // USE_WX #endif // USE_VTK diff --git a/src/creawxVTKRenderWindowInteractor.h b/src/creawxVTKRenderWindowInteractor.h index d0b90df..db0187d 100644 --- a/src/creawxVTKRenderWindowInteractor.h +++ b/src/creawxVTKRenderWindowInteractor.h @@ -3,8 +3,8 @@ Program: Visualization Toolkit Module: $RCSfile: creawxVTKRenderWindowInteractor.h,v $ Language: C++ - Date: $Date: 2010/01/22 19:16:54 $ - Version: $Revision: 1.3 $ + Date: $Date: 2011/02/17 11:02:08 $ + Version: $Revision: 1.4 $ Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. @@ -32,7 +32,7 @@ // - This class might not be easily readable as it tried to work with VTK 3.2 // and 4.x. This class doesn't support reparenting with VTK 4.2 and earlier. // .SECTION see also -// creawxVTKRenderWindowInteractor.py creawxVTKRenderWindow.py +// creawxVTKRenderWindowInteractor.py wxVTKRenderWindow.py #ifndef _creawxVTKRenderWindowInteractor_h_ #define _creawxVTKRenderWindowInteractor_h_ @@ -40,10 +40,7 @@ #ifdef USE_WXWIDGETS #ifdef USE_VTK -#include -#include -/* // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -54,7 +51,7 @@ #ifndef WX_PRECOMP #include #endif -*/ + #include #include @@ -64,17 +61,19 @@ // Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any // other port): +// MM: tested on 2008/04/08: experienced some heavy flickering with wx-widget 2.6.0 +// using a wxWindow instead of wxGLCanvas fixed the symptoms +//#if (!wxCHECK_VERSION(2, 6, 0)) #if (!wxCHECK_VERSION(2, 8, 0)) #define USE_WXGLCANVAS #endif - #if defined(__WXGTK__) && defined(USE_WXGLCANVAS) -# if wxUSE_GLCANVAS +# if wxUSE_GLCANVAS # include -# else +# else # error "problem of wxGLCanvas, you need to build wxWidgets with opengl" -# endif //wxUSE_GLCANVAS +# endif //wxUSE_GLCANVAS #endif //__WXGTK__ // Motif version (renamed into wxX11 for wxWindow 2.4 and newer) @@ -82,7 +81,6 @@ # error This GUI is not supported by creawxVTKRenderWindowInteractor for now #endif - // wx forward declarations class wxPaintEvent; class wxMouseEvent; @@ -97,9 +95,9 @@ namespace crea #if defined(__WXGTK__) && defined(USE_WXGLCANVAS) -class CREA_EXPORT creawxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor +class creawxVTKRenderWindowInteractor : public wxGLCanvas, public vtkRenderWindowInteractor #else -class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWindowInteractor, public wxWindow +class creawxVTKRenderWindowInteractor : public wxWindow, public vtkRenderWindowInteractor #endif //__WXGTK__ { DECLARE_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor) @@ -114,18 +112,13 @@ class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWind const wxSize &size = wxDefaultSize, long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE, const wxString &name = wxPanelNameStr); - //vtk ::New() + vtkTypeRevisionMacro(creawxVTKRenderWindowInteractor,vtkRenderWindowInteractor); static creawxVTKRenderWindowInteractor * New(); void PrintSelf(ostream& os, vtkIndent indent); //destructor ~creawxVTKRenderWindowInteractor(); -#if defined(_WIN32) - const char * creawxVTKRenderWindowInteractor::GetClassName() const; -#endif //_WIN32 - - // vtkRenderWindowInteractor overrides void Initialize(); void Enable(); @@ -149,6 +142,7 @@ class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWind void OnLeave(wxMouseEvent &event); void OnKeyDown(wxKeyEvent &event); void OnKeyUp(wxKeyEvent &event); + void OnChar(wxKeyEvent &event); #endif void OnTimer(wxTimerEvent &event); void OnSize(wxSizeEvent &event); @@ -187,10 +181,13 @@ class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWind DECLARE_EVENT_TABLE() }; + } // LG : EO namespace crea //====================================================================== #endif // USE_WX #endif // USE_VTK + + #endif //_creawxVTKRenderWindowInteractor_h_ -- 2.45.1