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 =========================================================================*/
50 #include "creawxVTKRenderWindowInteractor.h"
52 //This is needed for vtk 3.1 :
53 #ifndef VTK_MAJOR_VERSION
54 # include "vtkVersion.h"
57 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
58 # include "vtkCommand.h"
60 # include "vtkInteractorStyle.h"
62 #include "vtkDebugLeaks.h"
64 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
65 #ifdef __WXOSX_COCOA__
66 #import <Cocoa/Cocoa.h>
70 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
71 // ControlDown has been changed to mean Command key down
72 #define ControlDown RawControlDown
77 #include "vtkCocoaRenderWindow.h"
79 #include "vtkCarbonRenderWindow.h"
84 //=======================================================================
85 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
90 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
91 #if (!wxCHECK_VERSION(2, 4, 0))
92 wxWindow* wxGetTopLevelParent(wxWindow *win)
94 while ( win && !win->IsTopLevel() )
95 win = win->GetParent();
100 // LG : EO namespace bbwxvtk
101 //=======================================================================
103 // To access objc calls on cocoa
106 //EED #import <Cocoa/Cocoa.h>
107 // This trick is no longer need in VTK CVS, should get rid of that:
110 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
111 #endif //VTK_USE_COCOA
114 #if wxMAJOR_VERSION <= 2
117 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
118 #include "gdk/gdkprivate.h"
119 #if wxCHECK_VERSION(2, 9, 0)
120 // thanks to: http://thomasfischer.biz/?p=382
121 #include <gtk/gtkfixed.h>
122 #include <gtk/gtkwidget.h>
123 #include <wx/gtk/private/win_gtk.h>
124 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
125 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
126 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
127 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
129 #if wxCHECK_VERSION(2, 8, 0)
131 #include <wx/gtk/win_gtk.h>
133 #include <wx/gtk1/win_gtk.h>
136 #include <wx/gtk/win_gtk.h>
139 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
140 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
141 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
147 #include <gdk/gdkx.h>
149 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
150 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
151 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
156 #include "wx/x11/privx.h"
157 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
160 //For more info on this class please go to:
161 //http://wxvtk.sf.net
162 //This hack is for some buggy wxGTK version:
163 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
164 # define WX_USE_X_CAPTURE 0
166 # define WX_USE_X_CAPTURE 1
169 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
171 //=======================================================================
172 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
176 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
180 //---------------------------------------------------------------------------
181 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
182 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
183 #if wxMAJOR_VERSION <= 2
184 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
185 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
187 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
188 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
191 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
192 #if wxMAJOR_VERSION <= 2
193 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
194 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
196 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
197 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
200 //refresh window by doing a Render
201 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
202 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
203 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
205 //Bind the events to the event converters
206 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
207 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
208 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
209 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
210 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
211 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
212 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
213 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
214 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
215 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
216 #if wxCHECK_VERSION(2, 8, 0)
217 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
219 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
220 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
221 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
223 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
224 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
227 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
228 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
230 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
231 static int wxvtk_attributes[]={
240 //---------------------------------------------------------------------------
241 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
243 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
244 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
245 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
247 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
253 vtkRenderWindowInteractor()
254 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
255 , ActiveButton(wxEVT_NULL)
259 , RenderWhenDisabled(1)
262 #ifdef VTK_DEBUG_LEAKS
263 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
265 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
266 this->context = new wxGLContext(this);
268 this->RenderWindow = NULL;
269 this->SetRenderWindow(vtkRenderWindow::New());
270 this->RenderWindow->Delete();
272 //---------------------------------------------------------------------------
273 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
278 const wxString &name)
279 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
280 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
281 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
283 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
286 : wxWindow(parent, id, pos, size, style, name)
288 , vtkRenderWindowInteractor()
289 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
290 , ActiveButton(wxEVT_NULL)
294 , RenderWhenDisabled(1)
297 #ifdef VTK_DEBUG_LEAKS
298 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
300 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
301 this->context = new wxGLContext(this);
303 this->RenderWindow = NULL;
304 this->SetRenderWindow(vtkRenderWindow::New());
305 this->RenderWindow->Delete();
307 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
308 // so we update the size information of the interactor/renderwindow here
309 this->UpdateSize(size.x, size.y);
312 //---------------------------------------------------------------------------
313 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
315 SetRenderWindow(NULL);
316 SetInteractorStyle(NULL);
317 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
318 delete this->context;
321 //---------------------------------------------------------------------------
322 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
324 // we don't make use of the objectfactory, because we're not registered
325 return new wxVTKRenderWindowInteractor;
327 //---------------------------------------------------------------------------
328 void wxVTKRenderWindowInteractor::Initialize()
330 int *size = RenderWindow->GetSize();
331 // enable everything and start rendering
333 //RenderWindow->Start();
335 // set the size in the render window interactor
339 // this is initialized
342 //---------------------------------------------------------------------------
343 void wxVTKRenderWindowInteractor::Enable()
345 // if already enabled then done
351 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
352 wxGLCanvas::SetCurrent(*this->context);
356 //---------------------------------------------------------------------------
357 bool wxVTKRenderWindowInteractor::Enable(bool enable)
359 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
360 return wxGLCanvas::Enable(enable);
362 return wxWindow::Enable(enable);
365 //---------------------------------------------------------------------------
366 void wxVTKRenderWindowInteractor::Disable()
368 // if already disabled then done
372 // that's it (we can't remove the event handler like it should be...)
376 //---------------------------------------------------------------------------
377 void wxVTKRenderWindowInteractor::Start()
379 // the interactor cannot control the event loop
380 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
381 "interactor cannot control event loop.");
383 //---------------------------------------------------------------------------
384 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
388 // if the size changed tell render window
389 if ( x != Size[0] || y != Size[1] )
391 // adjust our (vtkRenderWindowInteractor size)
394 // and our RenderWindow's size
395 RenderWindow->SetSize(x, y);
396 #if defined(__WXMSW__)
402 //---------------------------------------------------------------------------
403 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
405 // it's a one shot timer
406 if (!timer.Start(10, TRUE))
412 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
413 //------------------------------------------------------------------
414 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
415 unsigned long duration)
417 if (!timer.Start(duration, timerType == OneShotTimer))
420 return ID_wxVTKRenderWindowInteractor_TIMER;
422 //------------------------------------------------------------------
423 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
429 //---------------------------------------------------------------------------
430 int wxVTKRenderWindowInteractor::DestroyTimer()
435 //---------------------------------------------------------------------------
436 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
441 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
443 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
444 // pass the right timer id
445 int timerId = this->GetCurrentTimerId();
446 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
448 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
452 InteractorStyle->OnTimer();
456 //---------------------------------------------------------------------------
457 // NOTE on implementation:
458 // Bad luck you ended up in the only tricky place of this code.
459 // A few note, wxWidgets still refuse to provide such convenient method
460 // so I have to maintain it myself, eventhough this is completely integrated
462 // Anyway if this happen to break for you then compare to a recent version of wxPython
463 // and look for the function long wxPyGetWinHandle(wxWindow* win)
464 // in wxPython/src/helpers.cpp
465 long wxVTKRenderWindowInteractor::GetHandleHack()
467 //helper function to hide the MSW vs GTK stuff
470 // __WXMSW__ is for Win32
471 // __WXMAC__ is for Carbon or Cocoa builds
472 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
473 #if defined(__WXMSW__) || defined(__WXMAC__)
474 handle_tmp = (long)this->GetHandle();
477 // using above GetHandle() works fine with wxOSX 2.9.x
478 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
479 // Here is how to find the NSWindow
480 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
481 if (toplevel != NULL )
483 handle_tmp = (long)toplevel->GetNSWindow();
485 // The NSView will be deducted from
486 // [(NSWindow*)Handle contentView]
487 // if only I knew how to write that in c++
488 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
490 // Find and return the actual X-Window.
491 #if defined(__WXGTK__) || defined(__WXX11__)
492 return (long)GetXWindow(this);
496 // handle_tmp = (long)this->GetXWindow();
501 //---------------------------------------------------------------------------
502 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
504 //must always be here
507 //do it here rather than in the cstor: this is safer.
510 Handle = GetHandleHack();
513 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
514 NSView *nvsview = (NSView* )Handle;
515 NSWindow *nswindow = nvsview.window;
516 rwin->SetRootWindow( nswindow );
517 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
519 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
525 // this->GetNSView() <-> DisplayId
526 // this->GetTopLevel()->GetNSWindow() <-> WindowId
528 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
531 // This is another hack to prevent the VTK Render Window from closing the display.
532 // If VTK closes the display, ~wxContext chashes while trying to destroy its
533 // glContext (because the display is closed). The Get -> Set makes this VTK
534 // object think someone else is responsible for the display.
536 // avoid "Method not implemented" messages in Console
538 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
541 // get vtk to render to the wxWindows
544 // This solves a problem with repainting after a window resize
545 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
547 #if !wxCHECK_VERSION(2, 9, 0)
548 // this doesn't seem necessary with wxOSX 2.9.x
549 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
552 rwin->UpdateContext();
556 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
559 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
560 // Must be somewhere after VTK 4.4
561 rwin->UpdateGLRegion();
567 //---------------------------------------------------------------------------
568 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
570 //turn off background erase to reduce flickering on MSW
573 //---------------------------------------------------------------------------
574 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
577 GetClientSize(&w, &h);
585 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
586 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
588 //this will check for Handle
591 //---------------------------------------------------------------------------
592 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
598 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
599 SetEventInformationFlipY(event.GetX(), event.GetY(),
600 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
602 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
604 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
605 event.GetX(), Size[1] - event.GetY() - 1);
608 //---------------------------------------------------------------------------
609 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
610 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
617 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
619 SetEventInformationFlipY(event.GetX(), event.GetY(),
620 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
622 InvokeEvent(vtkCommand::EnterEvent, NULL);
625 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
626 event.GetX(), Size[1] - event.GetY() - 1);
629 //---------------------------------------------------------------------------
630 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
637 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
639 SetEventInformationFlipY(event.GetX(), event.GetY(),
640 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
642 InvokeEvent(vtkCommand::LeaveEvent, NULL);
645 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
646 event.GetX(), Size[1] - event.GetY() - 1);
649 //---------------------------------------------------------------------------
650 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
657 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
659 int keycode = event.GetKeyCode();
661 if (((unsigned int)keycode) < 256)
663 // TODO: Unicode in non-Unicode mode ??
667 // we don't get a valid mouse position inside the key event on every platform
668 // so we retrieve the mouse position explicitly and pass it along
669 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
670 SetEventInformationFlipY(mousePos.x, mousePos.y,
671 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
672 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
674 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
675 event.GetKeyCode(), 1);
679 //---------------------------------------------------------------------------
680 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
687 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
689 int keycode = event.GetKeyCode();
691 if (((unsigned int)keycode) < 256)
693 // TODO: Unicode in non-Unicode mode ??
697 // we don't get a valid mouse position inside the key event on every platform
698 // so we retrieve the mouse position explicitly and pass it along
699 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
700 SetEventInformationFlipY(mousePos.x, mousePos.y,
701 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
702 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
704 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
705 event.GetKeyCode(), 1);
709 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
710 //---------------------------------------------------------------------------
711 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
718 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
720 int keycode = event.GetKeyCode();
722 if (((unsigned int)keycode) < 256)
724 // TODO: Unicode in non-Unicode mode ??
728 // we don't get a valid mouse position inside the key event on every platform
729 // so we retrieve the mouse position explicitly and pass it along
730 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
731 SetEventInformationFlipY(mousePos.x, mousePos.y,
732 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
733 InvokeEvent(vtkCommand::CharEvent, NULL);
737 //---------------------------------------------------------------------------
738 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
740 if (!Enabled || (ActiveButton != wxEVT_NULL))
744 ActiveButton = event.GetEventType();
746 // On Mac (Carbon) and Windows we don't automatically get the focus when
747 // you click inside the window
748 // we therefore set the focus explicitly
749 // Apparently we need that on linux (GTK) too:
752 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
753 SetEventInformationFlipY(event.GetX(), event.GetY(),
754 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
757 if(event.RightDown())
759 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
761 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
764 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
765 event.GetX(), Size[1] - event.GetY() - 1);
768 else if(event.LeftDown())
770 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
772 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
775 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
776 event.GetX(), Size[1] - event.GetY() - 1);
779 else if(event.MiddleDown())
781 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
783 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
786 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
787 event.GetX(), Size[1] - event.GetY() - 1);
790 //save the button and capture mouse until the button is released
792 //1. it is possible (WX_USE_X_CAPTURE)
793 //2. user decided to.
794 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
799 //---------------------------------------------------------------------------
800 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
802 //EVT_xxx_DOWN == EVT_xxx_UP - 1
803 //This is only needed if two mouse buttons are pressed at the same time.
804 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
805 //wxEVT_COMMAND_RIGHT_CLICK
806 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
811 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
814 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
815 SetEventInformationFlipY(event.GetX(), event.GetY(),
816 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
819 if(ActiveButton == wxEVT_RIGHT_DOWN)
821 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
823 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
826 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
827 event.GetX(), Size[1] - event.GetY() - 1);
830 else if(ActiveButton == wxEVT_LEFT_DOWN)
832 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
834 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
837 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
838 event.GetX(), Size[1] - event.GetY() - 1);
841 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
843 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
845 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
848 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
849 event.GetX(), Size[1] - event.GetY() - 1);
852 //if the ActiveButton is realeased, then release mouse capture
853 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
857 ActiveButton = wxEVT_NULL;
859 //---------------------------------------------------------------------------
860 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
862 // Mouse wheel was only added after VTK 4.4 (I think...)
863 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
865 //Set vtk event information ... The numebr of wheel rotations is stored in
866 //the x varible. y varible is zero
867 SetEventInformationFlipY(event.GetX() , event.GetY(),
868 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
869 if(event.GetWheelRotation() > 0)
872 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
877 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
883 //---------------------------------------------------------------------------
884 #if wxCHECK_VERSION(2, 8, 0)
885 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
887 if (ActiveButton != wxEVT_NULL)
889 //Maybe also invoke the button release event here
891 // Reset ActiveButton so that
892 // 1. we do not process mouse button up events any more,
893 // 2. the next button down event will be processed and call CaptureMouse().
894 // Otherwise ReleaseMouse() will be called
895 // without a previous CaptureMouse().
896 ActiveButton = wxEVT_NULL;
900 //---------------------------------------------------------------------------
901 void wxVTKRenderWindowInteractor::Render()
903 #if wxCHECK_VERSION(2, 8, 0)
904 int renderAllowed = !IsFrozen();
906 int renderAllowed = 1;
908 if (renderAllowed && !RenderWhenDisabled)
910 //the user doesn't want us to render when the toplevel frame
911 //is disabled - first find the top level parent
912 wxWindow *topParent = wxGetTopLevelParent(this);
915 //if it exists, check whether it's enabled
916 //if it's not enabeld, renderAllowed will be false
917 renderAllowed = topParent->IsEnabled();
923 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
924 wxGLCanvas::SetCurrent(*(this->context));
926 if(Handle && (Handle == GetHandleHack()) )
928 RenderWindow->Render();
930 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
931 else if(GetHandleHack())
933 //this means the user has reparented us; let's adapt to the
934 //new situation by doing the WindowRemap dance
935 //store the new situation
936 Handle = GetHandleHack();
937 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
938 RenderWindow->WindowRemap();
939 RenderWindow->Render();
945 //---------------------------------------------------------------------------
946 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
948 //Change value of __RenderWhenDisabled ivar.
949 //If __RenderWhenDisabled is false (the default), this widget will not
950 //call Render() on the RenderWindow if the top level frame (i.e. the
951 //containing frame) has been disabled.
953 //This prevents recursive rendering during wxSafeYield() calls.
954 //wxSafeYield() can be called during the ProgressMethod() callback of
955 //a VTK object to have progress bars and other GUI elements updated -
956 //it does this by disabling all windows (disallowing user-input to
957 //prevent re-entrancy of code) and then handling all outstanding
960 //However, this often triggers an OnPaint() method for wxVTKRWIs,
961 //resulting in a Render(), resulting in Update() being called whilst
964 RenderWhenDisabled = (bool)newValue;
966 //---------------------------------------------------------------------------
968 // Set the variable that indicates that we want a stereo capable window
969 // be created. This method can only be called before a window is realized.
971 void wxVTKRenderWindowInteractor::SetStereo(int capable)
973 if (Stereo != capable)
976 RenderWindow->StereoCapableWindowOn();
977 RenderWindow->SetStereoTypeToCrystalEyes();
982 //---------------------------------------------------------------------------
985 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
987 this->Superclass::PrintSelf(os, indent);
992 // LG : EO namespace bbwxvtk
993 //=======================================================================