1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /*=========================================================================
28 Program: Visualization Toolkit
29 Module: $RCSfile: wxVTKRenderWindowInteractor.cxx,v $
31 Date: $Date: 2012/11/15 14:14:35 $
32 Version: $Revision: 1.7 $
34 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
36 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
38 This software is distributed WITHOUT ANY WARRANTY; without even
39 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
40 PURPOSE. See the above copyright notice for more information.
42 =========================================================================*/
46 #include "wxVTKRenderWindowInteractor.h"
48 //This is needed for vtk 3.1 :
49 #ifndef VTK_MAJOR_VERSION
50 # include "vtkVersion.h"
53 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
54 # include "vtkCommand.h"
56 # include "vtkInteractorStyle.h"
58 #include "vtkDebugLeaks.h"
61 #include "vtkCarbonRenderWindow.h"
64 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
65 #if (!wxCHECK_VERSION(2, 4, 0))
66 wxWindow* wxGetTopLevelParent(wxWindow *win)
68 while ( win && !win->IsTopLevel() )
69 win = win->GetParent();
74 // To access objc calls on cocoa
77 #import <Cocoa/Cocoa.h>
78 // This trick is no longer need in VTK CVS, should get rid of that:
81 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
82 #endif //VTK_USE_COCOA
86 # include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
87 # include "gdk/gdkprivate.h"
88 #if wxCHECK_VERSION(2, 8, 0)
90 #include <wx/gtk/win_gtk.h>
92 #include <wx/gtk1/win_gtk.h>
95 #include <wx/gtk/win_gtk.h>
97 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
98 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
99 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
103 #include "wx/x11/privx.h"
104 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
108 //For more info on this class please go to:
109 //http://wxvtk.sf.net
110 //This hack is for some buggy wxGTK version:
111 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
112 # define WX_USE_X_CAPTURE 0
114 # define WX_USE_X_CAPTURE 1
117 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
119 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
120 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
122 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
125 //---------------------------------------------------------------------------
126 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
127 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
129 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
131 //refresh window by doing a Render
132 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
133 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
134 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
136 //Bind the events to the event converters
137 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
138 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
139 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
140 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
141 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
142 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
143 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
144 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
145 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
146 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
147 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
148 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
149 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
151 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
152 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
155 //EED 2017-01-01 Migration VTK7
156 #if VTK_MAJOR_VERSION <= 5
157 vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision: 1.7 $")
161 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
163 //---------------------------------------------------------------------------
164 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
165 #if (wxCHECK_VERSION(2, 8, 0))
166 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
168 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
171 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
173 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
174 , ActiveButton(wxEVT_NULL)
179 , RenderWhenDisabled(1)
182 #ifdef VTK_DEBUG_LEAKS
183 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
185 this->RenderWindow = NULL;
186 this->SetRenderWindow(vtkRenderWindow::New());
187 this->RenderWindow->Delete();
189 //---------------------------------------------------------------------------
190 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
195 const wxString &name)
196 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
197 : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
199 : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
201 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
202 , ActiveButton(wxEVT_NULL)
207 , RenderWhenDisabled(1)
210 #ifdef VTK_DEBUG_LEAKS
211 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
213 this->RenderWindow = NULL;
214 this->SetRenderWindow(vtkRenderWindow::New());
215 this->RenderWindow->Delete();
217 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
218 // so we update the size information of the interactor/renderwindow here
219 this->UpdateSize(size.x, size.y);
222 //---------------------------------------------------------------------------
223 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
225 SetRenderWindow(NULL);
226 SetInteractorStyle(NULL);
228 //---------------------------------------------------------------------------
229 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
231 // we don't make use of the objectfactory, because we're not registered
232 return new wxVTKRenderWindowInteractor;
234 //---------------------------------------------------------------------------
235 void wxVTKRenderWindowInteractor::Initialize()
237 int *size = RenderWindow->GetSize();
238 // enable everything and start rendering
240 //RenderWindow->Start();
242 // set the size in the render window interactor
246 // this is initialized
249 //---------------------------------------------------------------------------
250 void wxVTKRenderWindowInteractor::Enable()
252 // if already enabled then done
258 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
263 //---------------------------------------------------------------------------
264 bool wxVTKRenderWindowInteractor::Enable(bool enable)
266 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
267 return wxGLCanvas::Enable(enable);
269 return wxWindow::Enable(enable);
272 //---------------------------------------------------------------------------
273 void wxVTKRenderWindowInteractor::Disable()
275 // if already disabled then done
279 // that's it (we can't remove the event handler like it should be...)
283 //---------------------------------------------------------------------------
284 void wxVTKRenderWindowInteractor::Start()
286 // the interactor cannot control the event loop
287 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
288 "interactor cannot control event loop.");
290 //---------------------------------------------------------------------------
291 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
295 // if the size changed tell render window
296 if ( x != Size[0] || y != Size[1] )
298 // adjust our (vtkRenderWindowInteractor size)
301 // and our RenderWindow's size
302 RenderWindow->SetSize(x, y);
306 //---------------------------------------------------------------------------
307 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
309 // it's a one shot timer
310 if (!timer.Start(10, TRUE))
316 //---------------------------------------------------------------------------
317 int wxVTKRenderWindowInteractor::DestroyTimer()
322 //---------------------------------------------------------------------------
323 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
328 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
330 InvokeEvent(vtkCommand::TimerEvent, NULL);
333 InteractorStyle->OnTimer();
337 //---------------------------------------------------------------------------
338 // NOTE on implementation:
339 // Bad luck you ended up in the only tricky place of this code.
340 // A few note, wxWidgets still refuse to provide such convenient method
341 // so I have to maintain it myself, eventhough this is completely integrated
343 // Anyway if this happen to break for you then compare to a recent version of wxPython
344 // and look for the function long wxPyGetWinHandle(wxWindow* win)
345 // in wxPython/src/helpers.cpp
346 long wxVTKRenderWindowInteractor::GetHandleHack()
348 //helper function to hide the MSW vs GTK stuff
351 // __WXMSW__ is for Win32
352 //__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)
353 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
354 #if defined(__WXMSW__) || defined(__WXMAC__)
355 handle_tmp = (long)this->GetHandle();
358 //__WXCOCOA__ stands for using the objective-c Cocoa API
360 // Here is how to find the NSWindow
361 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
362 wxGetTopLevelParent( this ) );
363 if (toplevel != NULL )
365 handle_tmp = (long)toplevel->GetNSWindow();
367 // The NSView will be deducted from
368 // [(NSWindow*)Handle contentView]
369 // if only I knew how to write that in c++
372 // Find and return the actual X-Window.
373 #if defined(__WXGTK__) || defined(__WXX11__)
374 return (long)GetXWindow(this);
378 // handle_tmp = (long)this->GetXWindow();
383 //---------------------------------------------------------------------------
384 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
386 //must always be here
389 //do it here rather than in the cstor: this is safer.
392 Handle = GetHandleHack();
393 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
395 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
398 // get vtk to render to the wxWindows
401 // This solves a problem with repainting after a window resize
402 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
403 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
406 rwin->UpdateGLRegion();
410 //---------------------------------------------------------------------------
411 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
413 //turn off background erase to reduce flickering on MSW
416 //---------------------------------------------------------------------------
417 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
420 GetClientSize(&w, &h);
428 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
429 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
431 //this will check for Handle
434 //---------------------------------------------------------------------------
435 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
441 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
442 SetEventInformationFlipY(event.GetX(), event.GetY(),
443 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
445 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
447 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
448 event.GetX(), Size[1] - event.GetY() - 1);
451 //---------------------------------------------------------------------------
452 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
453 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
460 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
462 SetEventInformationFlipY(event.GetX(), event.GetY(),
463 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
465 InvokeEvent(vtkCommand::EnterEvent, NULL);
468 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
469 event.GetX(), Size[1] - event.GetY() - 1);
472 //---------------------------------------------------------------------------
473 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
480 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
482 SetEventInformationFlipY(event.GetX(), event.GetY(),
483 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
485 InvokeEvent(vtkCommand::LeaveEvent, NULL);
488 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
489 event.GetX(), Size[1] - event.GetY() - 1);
492 //---------------------------------------------------------------------------
493 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
500 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
502 int keycode = event.GetKeyCode();
504 if (((unsigned int)keycode) < 256)
506 // TODO: Unicode in non-Unicode mode ??
510 // we don't get a valid mouse position inside the key event on every platform
511 // so we retrieve the mouse position explicitly and pass it along
512 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
513 SetEventInformationFlipY(mousePos.x, mousePos.y,
514 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
515 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
517 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
518 event.GetKeyCode(), 1);
522 //---------------------------------------------------------------------------
523 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
530 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
532 int keycode = event.GetKeyCode();
534 if (((unsigned int)keycode) < 256)
536 // TODO: Unicode in non-Unicode mode ??
540 // we don't get a valid mouse position inside the key event on every platform
541 // so we retrieve the mouse position explicitly and pass it along
542 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
543 SetEventInformationFlipY(mousePos.x, mousePos.y,
544 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
545 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
547 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
548 event.GetKeyCode(), 1);
552 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
553 //---------------------------------------------------------------------------
554 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
561 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
563 int keycode = event.GetKeyCode();
565 if (((unsigned int)keycode) < 256)
567 // TODO: Unicode in non-Unicode mode ??
571 // we don't get a valid mouse position inside the key event on every platform
572 // so we retrieve the mouse position explicitly and pass it along
573 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
574 SetEventInformationFlipY(mousePos.x, mousePos.y,
575 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
576 InvokeEvent(vtkCommand::CharEvent, NULL);
580 //---------------------------------------------------------------------------
581 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
583 if (!Enabled || (ActiveButton != wxEVT_NULL))
587 ActiveButton = event.GetEventType();
589 // On Mac (Carbon) and Windows we don't automatically get the focus when
590 // you click inside the window
591 // we therefore set the focus explicitly
592 // Apparently we need that on linux (GTK) too:
595 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
596 SetEventInformationFlipY(event.GetX(), event.GetY(),
597 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
600 if(event.RightDown())
602 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
604 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
607 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
608 event.GetX(), Size[1] - event.GetY() - 1);
611 else if(event.LeftDown())
613 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
615 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
618 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
619 event.GetX(), Size[1] - event.GetY() - 1);
622 else if(event.MiddleDown())
624 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
626 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
629 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
630 event.GetX(), Size[1] - event.GetY() - 1);
633 //save the button and capture mouse until the button is released
635 //1. it is possible (WX_USE_X_CAPTURE)
636 //2. user decided to.
637 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
642 //---------------------------------------------------------------------------
643 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
645 //EVT_xxx_DOWN == EVT_xxx_UP - 1
646 //This is only needed if two mouse buttons are pressed at the same time.
647 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
648 //wxEVT_COMMAND_RIGHT_CLICK
649 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
654 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
655 SetEventInformationFlipY(event.GetX(), event.GetY(),
656 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
659 if(ActiveButton == wxEVT_RIGHT_DOWN)
661 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
663 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
666 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
667 event.GetX(), Size[1] - event.GetY() - 1);
670 else if(ActiveButton == wxEVT_LEFT_DOWN)
672 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
674 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
677 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
678 event.GetX(), Size[1] - event.GetY() - 1);
681 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
683 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
685 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
688 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
689 event.GetX(), Size[1] - event.GetY() - 1);
692 //if the ActiveButton is realeased, then release mouse capture
693 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
697 ActiveButton = wxEVT_NULL;
699 //---------------------------------------------------------------------------
700 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
702 // Mouse wheel was only added after VTK 4.4 (I think...)
703 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
705 //Set vtk event information ... The numebr of wheel rotations is stored in
706 //the x varible. y varible is zero
707 SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
708 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
709 if(event.GetWheelRotation() > 0)
712 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
717 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
723 //---------------------------------------------------------------------------
724 void wxVTKRenderWindowInteractor::Render()
727 if (!RenderWhenDisabled)
729 //the user doesn't want us to render when the toplevel frame
730 //is disabled - first find the top level parent
731 wxWindow *topParent = wxGetTopLevelParent(this);
734 //if it exists, check whether it's enabled
735 //if it's not enabeld, RenderAllowed will be false
736 RenderAllowed = topParent->IsEnabled();
742 if(Handle && (Handle == GetHandleHack()) )
744 RenderWindow->Render();
746 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
747 else if(GetHandleHack())
749 //this means the user has reparented us; let's adapt to the
750 //new situation by doing the WindowRemap dance
751 //store the new situation
752 Handle = GetHandleHack();
753 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
754 RenderWindow->WindowRemap();
755 RenderWindow->Render();
760 //---------------------------------------------------------------------------
761 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
763 //Change value of __RenderWhenDisabled ivar.
764 //If __RenderWhenDisabled is false (the default), this widget will not
765 //call Render() on the RenderWindow if the top level frame (i.e. the
766 //containing frame) has been disabled.
768 //This prevents recursive rendering during wxSafeYield() calls.
769 //wxSafeYield() can be called during the ProgressMethod() callback of
770 //a VTK object to have progress bars and other GUI elements updated -
771 //it does this by disabling all windows (disallowing user-input to
772 //prevent re-entrancy of code) and then handling all outstanding
775 //However, this often triggers an OnPaint() method for wxVTKRWIs,
776 //resulting in a Render(), resulting in Update() being called whilst
779 RenderWhenDisabled = (bool)newValue;
781 //---------------------------------------------------------------------------
783 // Set the variable that indicates that we want a stereo capable window
784 // be created. This method can only be called before a window is realized.
786 void wxVTKRenderWindowInteractor::SetStereo(int capable)
788 if (Stereo != capable)
791 RenderWindow->StereoCapableWindowOn();
792 RenderWindow->SetStereoTypeToCrystalEyes();
797 //---------------------------------------------------------------------------
800 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
802 this->Superclass::PrintSelf(os, indent);