2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Program: Visualization Toolkit
36 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
38 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
40 This software is distributed WITHOUT ANY WARRANTY; without even
41 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42 PURPOSE. See the above copyright notice for more information.
44 =========================================================================*/
49 #include "creawxVTKRenderWindowInteractor.h"
51 //This is needed for vtk 3.1 :
52 #ifndef VTK_MAJOR_VERSION
53 # include "vtkVersion.h"
56 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
57 # include "vtkCommand.h"
59 # include "vtkInteractorStyle.h"
61 #include "vtkDebugLeaks.h"
63 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
64 #ifdef __WXOSX_COCOA__
65 #import <Cocoa/Cocoa.h>
69 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
70 // ControlDown has been changed to mean Command key down
71 #define ControlDown RawControlDown
76 #include "vtkCocoaRenderWindow.h"
78 #include "vtkCarbonRenderWindow.h"
84 #import "vtkTDxMacDevice.h"
88 //=======================================================================
89 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
94 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
95 #if (!wxCHECK_VERSION(2, 4, 0))
96 wxWindow* wxGetTopLevelParent(wxWindow *win)
98 while ( win && !win->IsTopLevel() )
99 win = win->GetParent();
104 // LG : EO namespace bbwxvtk
105 //=======================================================================
107 // To access objc calls on cocoa
110 // This trick is no longer need in VTK CVS, should get rid of that:
113 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
114 #endif //VTK_USE_COCOA
117 #if wxMAJOR_VERSION <= 2
119 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
120 #include "gdk/gdkprivate.h"
121 #if wxCHECK_VERSION(2, 9, 0)
122 // thanks to: http://thomasfischer.biz/?p=382
123 #include <gtk/gtkfixed.h>
124 #include <gtk/gtkwidget.h>
125 #include <wx/gtk/private/win_gtk.h>
126 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
127 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
128 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
129 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
131 #if wxCHECK_VERSION(2, 8, 0)
133 #include <wx/gtk/win_gtk.h>
135 #include <wx/gtk1/win_gtk.h>
138 #include <wx/gtk/win_gtk.h>
141 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
142 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
143 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
149 #include <gdk/gdkx.h>
151 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
152 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
153 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
158 #include "wx/x11/privx.h"
159 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
162 //For more info on this class please go to:
163 //http://wxvtk.sf.net
164 //This hack is for some buggy wxGTK version:
165 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
166 # define WX_USE_X_CAPTURE 0
168 # define WX_USE_X_CAPTURE 1
171 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
173 //=======================================================================
174 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
178 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
182 //---------------------------------------------------------------------------
183 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
184 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
185 #if wxMAJOR_VERSION <= 2
186 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
187 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
189 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
190 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
193 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
194 #if wxMAJOR_VERSION <= 2
195 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
196 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
198 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
199 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
202 //refresh window by doing a Render
203 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
204 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
205 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
207 //Bind the events to the event converters
208 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
209 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
210 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
211 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
212 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
213 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
214 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
215 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
216 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
217 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
218 #if wxCHECK_VERSION(2, 8, 0)
219 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
221 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
222 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
223 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
225 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
226 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
229 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
232 #if VTK_MAJOR_VERSION < 8
233 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
236 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
237 static int wxvtk_attributes[]={
246 //---------------------------------------------------------------------------
247 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
249 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
250 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
251 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
253 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
259 vtkRenderWindowInteractor()
260 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
261 , ActiveButton(wxEVT_NULL)
265 , RenderWhenDisabled(1)
268 #ifdef VTK_DEBUG_LEAKS
269 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
271 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
272 this->context = new wxGLContext(this);
274 this->RenderWindow = NULL;
275 this->SetRenderWindow(vtkRenderWindow::New());
276 this->RenderWindow->Delete();
279 this->Device=vtkTDxMacDevice::New();
284 //---------------------------------------------------------------------------
285 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
290 const wxString &name)
291 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
292 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
293 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
295 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
298 : wxWindow(parent, id, pos, size, style, name)
300 , vtkRenderWindowInteractor()
301 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
302 , ActiveButton(wxEVT_NULL)
306 , RenderWhenDisabled(1)
309 #ifdef VTK_DEBUG_LEAKS
310 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
312 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
313 this->context = new wxGLContext(this);
315 this->RenderWindow = NULL;
316 this->SetRenderWindow(vtkRenderWindow::New());
317 this->RenderWindow->Delete();
319 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
320 // so we update the size information of the interactor/renderwindow here
321 this->UpdateSize(size.x, size.y);
326 this->Device=vtkTDxMacDevice::New();
331 //---------------------------------------------------------------------------
332 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
334 SetRenderWindow(NULL);
335 SetInteractorStyle(NULL);
336 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
337 delete this->context;
341 this->Device->Delete();
345 //---------------------------------------------------------------------------
346 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
348 // we don't make use of the objectfactory, because we're not registered
349 return new wxVTKRenderWindowInteractor;
351 //---------------------------------------------------------------------------
352 void wxVTKRenderWindowInteractor::Initialize()
354 int *size = RenderWindow->GetSize();
355 // enable everything and start rendering
357 //RenderWindow->Start();
359 // set the size in the render window interactor
363 // this is initialized
366 //---------------------------------------------------------------------------
367 void wxVTKRenderWindowInteractor::Enable()
369 // if already enabled then done
375 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
376 wxGLCanvas::SetCurrent(*this->context);
383 this->Device->SetInteractor(this);
384 this->Device->Initialize();
392 //---------------------------------------------------------------------------
393 bool wxVTKRenderWindowInteractor::Enable(bool enable)
399 this->Device->SetInteractor(this);
400 this->Device->Initialize();
406 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
407 return wxGLCanvas::Enable(enable);
409 return wxWindow::Enable(enable);
412 //---------------------------------------------------------------------------
413 void wxVTKRenderWindowInteractor::Disable()
415 // if already disabled then done
420 if(this->Device->GetInitialized())
422 this->Device->Close();
427 // that's it (we can't remove the event handler like it should be...)
431 //---------------------------------------------------------------------------
432 void wxVTKRenderWindowInteractor::Start()
434 // the interactor cannot control the event loop
435 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
436 "interactor cannot control event loop.");
438 //---------------------------------------------------------------------------
439 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
443 // if the size changed tell render window
444 if ( x != Size[0] || y != Size[1] )
446 // adjust our (vtkRenderWindowInteractor size)
449 // and our RenderWindow's size
454 #endif //VTK_USE_COCOA
456 RenderWindow->SetSize(x, y);
459 #if defined(__WXMSW__)
465 //---------------------------------------------------------------------------
466 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
468 // it's a one shot timer
469 if (!timer.Start(10, TRUE))
475 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
476 //------------------------------------------------------------------
477 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
478 unsigned long duration)
480 if (!timer.Start(duration, timerType == OneShotTimer))
483 return ID_wxVTKRenderWindowInteractor_TIMER;
485 //------------------------------------------------------------------
486 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
492 //---------------------------------------------------------------------------
493 int wxVTKRenderWindowInteractor::DestroyTimer()
498 //---------------------------------------------------------------------------
499 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
504 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
506 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
507 // pass the right timer id
508 int timerId = this->GetCurrentTimerId();
509 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
511 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
515 InteractorStyle->OnTimer();
519 //---------------------------------------------------------------------------
520 // NOTE on implementation:
521 // Bad luck you ended up in the only tricky place of this code.
522 // A few note, wxWidgets still refuse to provide such convenient method
523 // so I have to maintain it myself, eventhough this is completely integrated
525 // Anyway if this happen to break for you then compare to a recent version of wxPython
526 // and look for the function long wxPyGetWinHandle(wxWindow* win)
527 // in wxPython/src/helpers.cpp
528 long wxVTKRenderWindowInteractor::GetHandleHack()
530 //helper function to hide the MSW vs GTK stuff
533 // __WXMSW__ is for Win32
534 // __WXMAC__ is for Carbon or Cocoa builds
535 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
536 #if defined(__WXMSW__) || defined(__WXMAC__)
537 handle_tmp = (long)this->GetHandle();
540 // using above GetHandle() works fine with wxOSX 2.9.x
541 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
542 // Here is how to find the NSWindow
543 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
544 if (toplevel != NULL )
546 handle_tmp = (long)toplevel->GetNSWindow();
548 // The NSView will be deducted from
549 // [(NSWindow*)Handle contentView]
550 // if only I knew how to write that in c++
551 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
553 // Find and return the actual X-Window.
554 #if defined(__WXGTK__) || defined(__WXX11__)
555 return (long)GetXWindow(this);
559 // handle_tmp = (long)this->GetXWindow();
564 //---------------------------------------------------------------------------
565 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
567 //must always be here
574 //do it here rather than in the cstor: this is safer.
577 Handle = GetHandleHack();
580 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
581 NSView *nvsview = (NSView* )Handle;
582 NSWindow *nswindow = nvsview.window;
583 rwin->SetRootWindow( nswindow );
584 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
586 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
590 // this->GetNSView() <-> DisplayId
591 // this->GetTopLevel()->GetNSWindow() <-> WindowId
593 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
596 // This is another hack to prevent the VTK Render Window from closing the display.
597 // If VTK closes the display, ~wxContext chashes while trying to destroy its
598 // glContext (because the display is closed). The Get -> Set makes this VTK
599 // object think someone else is responsible for the display.
601 // avoid "Method not implemented" messages in Console
603 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
606 // get vtk to render to the wxWindows
609 // This solves a problem with repainting after a window resize
610 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
612 #if !wxCHECK_VERSION(2, 9, 0)
613 // this doesn't seem necessary with wxOSX 2.9.x
614 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
617 rwin->UpdateContext();
621 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
624 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
625 // Must be somewhere after VTK 4.4
626 rwin->UpdateGLRegion();
633 //---------------------------------------------------------------------------
634 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
636 //turn off background erase to reduce flickering on MSW
639 //---------------------------------------------------------------------------
640 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
643 GetClientSize(&w, &h);
651 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
652 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
654 //this will check for Handle
657 //---------------------------------------------------------------------------
658 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
664 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
665 SetEventInformationFlipY(event.GetX(), event.GetY(),
666 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
668 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
670 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
671 event.GetX(), Size[1] - event.GetY() - 1);
674 //---------------------------------------------------------------------------
675 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
676 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
683 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
685 SetEventInformationFlipY(event.GetX(), event.GetY(),
686 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
688 InvokeEvent(vtkCommand::EnterEvent, NULL);
691 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
692 event.GetX(), Size[1] - event.GetY() - 1);
695 //---------------------------------------------------------------------------
696 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
703 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
705 SetEventInformationFlipY(event.GetX(), event.GetY(),
706 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
708 InvokeEvent(vtkCommand::LeaveEvent, NULL);
711 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
712 event.GetX(), Size[1] - event.GetY() - 1);
715 //---------------------------------------------------------------------------
716 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
723 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
725 int keycode = event.GetKeyCode();
727 if (((unsigned int)keycode) < 256)
729 // TODO: Unicode in non-Unicode mode ??
733 // we don't get a valid mouse position inside the key event on every platform
734 // so we retrieve the mouse position explicitly and pass it along
735 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
736 SetEventInformationFlipY(mousePos.x, mousePos.y,
737 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
738 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
740 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
741 event.GetKeyCode(), 1);
745 //---------------------------------------------------------------------------
746 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
753 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
755 int keycode = event.GetKeyCode();
757 if (((unsigned int)keycode) < 256)
759 // TODO: Unicode in non-Unicode mode ??
763 // we don't get a valid mouse position inside the key event on every platform
764 // so we retrieve the mouse position explicitly and pass it along
765 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
766 SetEventInformationFlipY(mousePos.x, mousePos.y,
767 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
768 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
770 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
771 event.GetKeyCode(), 1);
775 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
776 //---------------------------------------------------------------------------
777 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
784 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
786 int keycode = event.GetKeyCode();
788 if (((unsigned int)keycode) < 256)
790 // TODO: Unicode in non-Unicode mode ??
794 // we don't get a valid mouse position inside the key event on every platform
795 // so we retrieve the mouse position explicitly and pass it along
796 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
797 SetEventInformationFlipY(mousePos.x, mousePos.y,
798 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
799 InvokeEvent(vtkCommand::CharEvent, NULL);
803 //---------------------------------------------------------------------------
804 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
806 if (!Enabled || (ActiveButton != wxEVT_NULL))
810 ActiveButton = event.GetEventType();
812 // On Mac (Carbon) and Windows we don't automatically get the focus when
813 // you click inside the window
814 // we therefore set the focus explicitly
815 // Apparently we need that on linux (GTK) too:
818 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
819 SetEventInformationFlipY(event.GetX(), event.GetY(),
820 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
823 if(event.RightDown())
825 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
827 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
830 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
831 event.GetX(), Size[1] - event.GetY() - 1);
834 else if(event.LeftDown())
836 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
838 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
841 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
842 event.GetX(), Size[1] - event.GetY() - 1);
845 else if(event.MiddleDown())
847 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
849 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
852 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
853 event.GetX(), Size[1] - event.GetY() - 1);
856 //save the button and capture mouse until the button is released
858 //1. it is possible (WX_USE_X_CAPTURE)
859 //2. user decided to.
860 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
865 //---------------------------------------------------------------------------
866 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
868 //EVT_xxx_DOWN == EVT_xxx_UP - 1
869 //This is only needed if two mouse buttons are pressed at the same time.
870 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
871 //wxEVT_COMMAND_RIGHT_CLICK
872 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
877 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
880 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
881 SetEventInformationFlipY(event.GetX(), event.GetY(),
882 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
885 if(ActiveButton == wxEVT_RIGHT_DOWN)
887 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
889 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
892 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
893 event.GetX(), Size[1] - event.GetY() - 1);
896 else if(ActiveButton == wxEVT_LEFT_DOWN)
898 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
900 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
903 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
904 event.GetX(), Size[1] - event.GetY() - 1);
907 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
909 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
911 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
914 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
915 event.GetX(), Size[1] - event.GetY() - 1);
918 //if the ActiveButton is realeased, then release mouse capture
919 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
923 ActiveButton = wxEVT_NULL;
925 //---------------------------------------------------------------------------
926 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
928 // Mouse wheel was only added after VTK 4.4 (I think...)
929 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
931 //Set vtk event information ... The numebr of wheel rotations is stored in
932 //the x varible. y varible is zero
933 SetEventInformationFlipY(event.GetX() , event.GetY(),
934 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
935 if(event.GetWheelRotation() > 0)
938 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
943 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
949 //---------------------------------------------------------------------------
950 #if wxCHECK_VERSION(2, 8, 0)
951 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
953 if (ActiveButton != wxEVT_NULL)
955 //Maybe also invoke the button release event here
957 // Reset ActiveButton so that
958 // 1. we do not process mouse button up events any more,
959 // 2. the next button down event will be processed and call CaptureMouse().
960 // Otherwise ReleaseMouse() will be called
961 // without a previous CaptureMouse().
962 ActiveButton = wxEVT_NULL;
966 //---------------------------------------------------------------------------
967 void wxVTKRenderWindowInteractor::Render()
969 #if wxCHECK_VERSION(2, 8, 0)
970 int renderAllowed = !IsFrozen();
972 int renderAllowed = 1;
974 if (renderAllowed && !RenderWhenDisabled)
976 //the user doesn't want us to render when the toplevel frame
977 //is disabled - first find the top level parent
978 wxWindow *topParent = wxGetTopLevelParent(this);
981 //if it exists, check whether it's enabled
982 //if it's not enabeld, renderAllowed will be false
983 renderAllowed = topParent->IsEnabled();
985 } // if renderAllowed && !RenderWhenDisabled
989 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
990 wxGLCanvas::SetCurrent(*(this->context));
992 if(Handle && (Handle == GetHandleHack()) )
994 RenderWindow->Render();
996 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
997 else if(GetHandleHack())
999 //this means the user has reparented us; let's adapt to the
1000 //new situation by doing the WindowRemap dance
1001 //store the new situation
1002 Handle = GetHandleHack();
1003 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
1004 RenderWindow->WindowRemap();
1005 RenderWindow->Render();
1008 } // if renderAllowed
1010 //---------------------------------------------------------------------------
1011 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
1013 //Change value of __RenderWhenDisabled ivar.
1014 //If __RenderWhenDisabled is false (the default), this widget will not
1015 //call Render() on the RenderWindow if the top level frame (i.e. the
1016 //containing frame) has been disabled.
1018 //This prevents recursive rendering during wxSafeYield() calls.
1019 //wxSafeYield() can be called during the ProgressMethod() callback of
1020 //a VTK object to have progress bars and other GUI elements updated -
1021 //it does this by disabling all windows (disallowing user-input to
1022 //prevent re-entrancy of code) and then handling all outstanding
1025 //However, this often triggers an OnPaint() method for wxVTKRWIs,
1026 //resulting in a Render(), resulting in Update() being called whilst
1027 //still in progress.
1029 RenderWhenDisabled = (bool)newValue;
1031 //---------------------------------------------------------------------------
1033 // Set the variable that indicates that we want a stereo capable window
1034 // be created. This method can only be called before a window is realized.
1036 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1038 if (Stereo != capable)
1041 RenderWindow->StereoCapableWindowOn();
1042 RenderWindow->SetStereoTypeToCrystalEyes();
1047 //---------------------------------------------------------------------------
1050 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1052 this->Superclass::PrintSelf(os, indent);
1057 // LG : EO namespace bbwxvtk
1058 //=======================================================================