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
31 Module: $RCSfile: creawxVTKRenderWindowInteractor.cxx,v $
33 Date: $Date: 2012/11/15 10:43:26 $
34 Version: $Revision: 1.11 $
36 This software is distributed WITHOUT ANY WARRANTY; without even
37 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
38 PURPOSE. See the above copyright notice for more information.
40 =========================================================================*/
47 #include "creawxVTKRenderWindowInteractor.h"
49 //This is needed for vtk 3.1 :
50 #ifndef VTK_MAJOR_VERSION
51 # include "vtkVersion.h"
54 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
55 # include "vtkCommand.h"
57 # include "vtkInteractorStyle.h"
59 #include "vtkDebugLeaks.h"
63 #include "vtkCocoaRenderWindow.h"
65 #include "vtkCarbonRenderWindow.h"
70 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
71 #if (!wxCHECK_VERSION(2, 4, 0))
72 wxWindow* wxGetTopLevelParent(wxWindow *win)
74 while ( win && !win->IsTopLevel() )
75 win = win->GetParent();
80 // To access objc calls on cocoa
83 #import <Cocoa/Cocoa.h>
84 // This trick is no longer need in VTK CVS, should get rid of that:
87 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
88 #endif //VTK_USE_COCOA
92 # include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
93 # include "gdk/gdkprivate.h"
94 #if wxCHECK_VERSION(2, 8, 0)
96 #include <wx/gtk/win_gtk.h>
98 #include <wx/gtk1/win_gtk.h>
101 #include <wx/gtk/win_gtk.h>
103 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
104 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
105 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
109 #include "wx/x11/privx.h"
110 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
114 //For more info on this class please go to:
115 //http://wxvtk.sf.net
116 //This hack is for some buggy wxGTK version:
117 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
118 # define WX_USE_X_CAPTURE 0
120 # define WX_USE_X_CAPTURE 1
123 #define ID_creawxVTKRenderWindowInteractor_TIMER 1001
128 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
129 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxGLCanvas)
132 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxWindow)
135 //---------------------------------------------------------------------------
136 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
137 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxGLCanvas)
139 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxWindow)
141 //refresh window by doing a Render
142 EVT_PAINT (creawxVTKRenderWindowInteractor::OnPaint)
143 EVT_ERASE_BACKGROUND(creawxVTKRenderWindowInteractor::OnEraseBackground)
144 EVT_MOTION (creawxVTKRenderWindowInteractor::OnMotion)
146 //Bind the events to the event converters
147 EVT_LEFT_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
148 EVT_MIDDLE_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
149 EVT_RIGHT_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
150 EVT_LEFT_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
151 EVT_MIDDLE_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
152 EVT_RIGHT_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
153 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
154 EVT_ENTER_WINDOW(creawxVTKRenderWindowInteractor::OnEnter)
155 EVT_LEAVE_WINDOW(creawxVTKRenderWindowInteractor::OnLeave)
156 EVT_MOUSEWHEEL (creawxVTKRenderWindowInteractor::OnMouseWheel)
157 EVT_KEY_DOWN (creawxVTKRenderWindowInteractor::OnKeyDown)
158 EVT_KEY_UP (creawxVTKRenderWindowInteractor::OnKeyUp)
159 EVT_CHAR (creawxVTKRenderWindowInteractor::OnChar)
161 EVT_TIMER (ID_creawxVTKRenderWindowInteractor_TIMER, creawxVTKRenderWindowInteractor::OnTimer)
162 EVT_SIZE (creawxVTKRenderWindowInteractor::OnSize)
165 //EED win Compilation why??: vtkCxxRevisionMacro(creawxVTKRenderWindowInteractor, "$Revision: 1.11 $")
166 vtkInstantiatorNewMacro(creawxVTKRenderWindowInteractor)
168 //---------------------------------------------------------------------------
169 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
170 #if (wxCHECK_VERSION(2, 8, 0))
171 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
173 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
176 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
178 , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
179 , ActiveButton(wxEVT_NULL)
184 , RenderWhenDisabled(1)
187 #ifdef VTK_DEBUG_LEAKS
188 vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
190 this->RenderWindow = NULL;
191 this->SetRenderWindow(vtkRenderWindow::New());
192 this->RenderWindow->Delete();
194 //---------------------------------------------------------------------------
195 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *parent,
200 const wxString &name)
201 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
202 : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
204 : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
206 , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
207 , ActiveButton(wxEVT_NULL)
212 , RenderWhenDisabled(1)
215 #ifdef VTK_DEBUG_LEAKS
216 vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
218 this->RenderWindow = NULL;
219 this->SetRenderWindow(vtkRenderWindow::New());
220 this->RenderWindow->Delete();
222 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
223 // so we update the size information of the interactor/renderwindow here
224 this->UpdateSize(size.x, size.y);
227 //---------------------------------------------------------------------------
228 creawxVTKRenderWindowInteractor::~creawxVTKRenderWindowInteractor()
230 SetRenderWindow(NULL);
231 SetInteractorStyle(NULL);
233 //---------------------------------------------------------------------------
234 creawxVTKRenderWindowInteractor * creawxVTKRenderWindowInteractor::New()
236 // we don't make use of the objectfactory, because we're not registered
237 return new creawxVTKRenderWindowInteractor;
239 //---------------------------------------------------------------------------
240 void creawxVTKRenderWindowInteractor::Initialize()
242 int *size = RenderWindow->GetSize();
243 // enable everything and start rendering
245 //RenderWindow->Start();
247 // set the size in the render window interactor
251 // this is initialized
254 //---------------------------------------------------------------------------
255 void creawxVTKRenderWindowInteractor::Enable()
257 // if already enabled then done
263 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
268 //---------------------------------------------------------------------------
269 bool creawxVTKRenderWindowInteractor::Enable(bool enable)
271 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
272 return wxGLCanvas::Enable(enable);
274 return wxWindow::Enable(enable);
277 //---------------------------------------------------------------------------
278 void creawxVTKRenderWindowInteractor::Disable()
280 // if already disabled then done
284 // that's it (we can't remove the event handler like it should be...)
288 //---------------------------------------------------------------------------
289 void creawxVTKRenderWindowInteractor::Start()
291 // the interactor cannot control the event loop
292 vtkErrorMacro( << "creawxVTKRenderWindowInteractor::Start() "
293 "interactor cannot control event loop.");
295 //---------------------------------------------------------------------------
296 void creawxVTKRenderWindowInteractor::UpdateSize(int x, int y)
300 // if the size changed tell render window
301 if ( x != Size[0] || y != Size[1] )
303 // adjust our (vtkRenderWindowInteractor size)
306 // and our RenderWindow's size
307 RenderWindow->SetSize(x, y);
311 //---------------------------------------------------------------------------
312 int creawxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
314 // it's a one shot timer
315 if (!timer.Start(10, TRUE))
321 //---------------------------------------------------------------------------
322 int creawxVTKRenderWindowInteractor::DestroyTimer()
327 //---------------------------------------------------------------------------
328 void creawxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
333 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
335 InvokeEvent(vtkCommand::TimerEvent, NULL);
338 InteractorStyle->OnTimer();
342 //---------------------------------------------------------------------------
343 // NOTE on implementation:
344 // Bad luck you ended up in the only tricky place of this code.
345 // A few note, wxWidgets still refuse to provide such convenient method
346 // so I have to maintain it myself, eventhough this is completely integrated
348 // Anyway if this happen to break for you then compare to a recent version of wxPython
349 // and look for the function long wxPyGetWinHandle(wxWindow* win)
350 // in wxPython/src/helpers.cpp
351 long creawxVTKRenderWindowInteractor::GetHandleHack()
353 //helper function to hide the MSW vs GTK stuff
356 // __WXMSW__ is for Win32
357 //__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)
358 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
359 #if defined(__WXMSW__) || defined(__WXMAC__)
360 handle_tmp = (long)this->GetHandle();
363 //__WXCOCOA__ stands for using the objective-c Cocoa API
365 // Here is how to find the NSWindow
366 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
367 wxGetTopLevelParent( this ) );
368 if (toplevel != NULL )
370 handle_tmp = (long)toplevel->GetNSWindow();
372 // The NSView will be deducted from
373 // [(NSWindow*)Handle contentView]
374 // if only I knew how to write that in c++
377 // Find and return the actual X-Window.
378 #if defined(__WXGTK__) || defined(__WXX11__)
379 return (long)GetXWindow(this);
383 // handle_tmp = (long)this->GetXWindow();
388 //---------------------------------------------------------------------------
389 void creawxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
391 //must always be here
394 //do it here rather than in the cstor: this is safer.
397 Handle = GetHandleHack();
398 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
400 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
403 // get vtk to render to the wxWindows
408 vtkCocoaRenderWindow* rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
411 rwin->UpdateContext();
414 // This solves a problem with repainting after a window resize
415 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
416 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
419 rwin->UpdateGLRegion();
425 //---------------------------------------------------------------------------
426 void creawxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
428 //turn off background erase to reduce flickering on MSW
431 //---------------------------------------------------------------------------
432 void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
435 GetClientSize(&w, &h);
443 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
444 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
446 //this will check for Handle
449 //---------------------------------------------------------------------------
450 void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
456 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
457 SetEventInformationFlipY(event.GetX(), event.GetY(),
458 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
460 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
462 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
463 event.GetX(), Size[1] - event.GetY() - 1);
466 //---------------------------------------------------------------------------
467 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
468 void creawxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
475 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
477 SetEventInformationFlipY(event.GetX(), event.GetY(),
478 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
480 InvokeEvent(vtkCommand::EnterEvent, NULL);
483 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
484 event.GetX(), Size[1] - event.GetY() - 1);
487 //---------------------------------------------------------------------------
488 void creawxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
495 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
497 SetEventInformationFlipY(event.GetX(), event.GetY(),
498 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
500 InvokeEvent(vtkCommand::LeaveEvent, NULL);
503 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
504 event.GetX(), Size[1] - event.GetY() - 1);
507 //---------------------------------------------------------------------------
508 void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
515 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
517 int keycode = event.GetKeyCode();
519 if (((unsigned int)keycode) < 256)
521 // TODO: Unicode in non-Unicode mode ??
525 // we don't get a valid mouse position inside the key event on every platform
526 // so we retrieve the mouse position explicitly and pass it along
527 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
528 SetEventInformationFlipY(mousePos.x, mousePos.y,
529 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
530 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
532 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
533 event.GetKeyCode(), 1);
537 //---------------------------------------------------------------------------
538 void creawxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
545 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
547 int keycode = event.GetKeyCode();
549 if (((unsigned int)keycode) < 256)
551 // TODO: Unicode in non-Unicode mode ??
555 // we don't get a valid mouse position inside the key event on every platform
556 // so we retrieve the mouse position explicitly and pass it along
557 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
558 SetEventInformationFlipY(mousePos.x, mousePos.y,
559 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
560 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
562 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
563 event.GetKeyCode(), 1);
567 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
568 //---------------------------------------------------------------------------
569 void creawxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
576 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
578 int keycode = event.GetKeyCode();
580 if (((unsigned int)keycode) < 256)
582 // TODO: Unicode in non-Unicode mode ??
586 // we don't get a valid mouse position inside the key event on every platform
587 // so we retrieve the mouse position explicitly and pass it along
588 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
589 SetEventInformationFlipY(mousePos.x, mousePos.y,
590 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
591 InvokeEvent(vtkCommand::CharEvent, NULL);
595 //---------------------------------------------------------------------------
596 void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
598 if (!Enabled || (ActiveButton != wxEVT_NULL))
602 ActiveButton = event.GetEventType();
604 // On Mac (Carbon) and Windows we don't automatically get the focus when
605 // you click inside the window
606 // we therefore set the focus explicitly
607 // Apparently we need that on linux (GTK) too:
610 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
611 SetEventInformationFlipY(event.GetX(), event.GetY(),
612 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
615 if(event.RightDown())
617 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
619 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
622 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
623 event.GetX(), Size[1] - event.GetY() - 1);
626 else if(event.LeftDown())
628 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
630 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
633 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
634 event.GetX(), Size[1] - event.GetY() - 1);
637 else if(event.MiddleDown())
639 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
641 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
644 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
645 event.GetX(), Size[1] - event.GetY() - 1);
648 //save the button and capture mouse until the button is released
650 //1. it is possible (WX_USE_X_CAPTURE)
651 //2. user decided to.
652 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
657 //---------------------------------------------------------------------------
658 void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
660 //EVT_xxx_DOWN == EVT_xxx_UP - 1
661 //This is only needed if two mouse buttons are pressed at the same time.
662 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
663 //wxEVT_COMMAND_RIGHT_CLICK
664 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
669 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
670 SetEventInformationFlipY(event.GetX(), event.GetY(),
671 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
674 if(ActiveButton == wxEVT_RIGHT_DOWN)
676 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
678 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
681 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
682 event.GetX(), Size[1] - event.GetY() - 1);
685 else if(ActiveButton == wxEVT_LEFT_DOWN)
687 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
689 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
692 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
693 event.GetX(), Size[1] - event.GetY() - 1);
696 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
698 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
700 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
703 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
704 event.GetX(), Size[1] - event.GetY() - 1);
707 //if the ActiveButton is realeased, then release mouse capture
708 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
712 ActiveButton = wxEVT_NULL;
714 //---------------------------------------------------------------------------
715 void creawxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
717 // Mouse wheel was only added after VTK 4.4 (I think...)
718 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
720 //Set vtk event information ... The numebr of wheel rotations is stored in
721 //the x varible. y varible is zero
722 SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
723 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
724 if(event.GetWheelRotation() > 0)
727 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
732 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
738 //---------------------------------------------------------------------------
739 void creawxVTKRenderWindowInteractor::Render()
742 if (!RenderWhenDisabled)
744 //the user doesn't want us to render when the toplevel frame
745 //is disabled - first find the top level parent
746 wxWindow *topParent = wxGetTopLevelParent(this);
749 //if it exists, check whether it's enabled
750 //if it's not enabeld, RenderAllowed will be false
751 RenderAllowed = topParent->IsEnabled();
757 if(Handle && (Handle == GetHandleHack()) )
759 RenderWindow->Render();
761 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
762 else if(GetHandleHack())
764 //this means the user has reparented us; let's adapt to the
765 //new situation by doing the WindowRemap dance
766 //store the new situation
767 Handle = GetHandleHack();
768 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
769 RenderWindow->WindowRemap();
770 RenderWindow->Render();
775 //---------------------------------------------------------------------------
776 void creawxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
778 //Change value of __RenderWhenDisabled ivar.
779 //If __RenderWhenDisabled is false (the default), this widget will not
780 //call Render() on the RenderWindow if the top level frame (i.e. the
781 //containing frame) has been disabled.
783 //This prevents recursive rendering during wxSafeYield() calls.
784 //wxSafeYield() can be called during the ProgressMethod() callback of
785 //a VTK object to have progress bars and other GUI elements updated -
786 //it does this by disabling all windows (disallowing user-input to
787 //prevent re-entrancy of code) and then handling all outstanding
790 //However, this often triggers an OnPaint() method for wxVTKRWIs,
791 //resulting in a Render(), resulting in Update() being called whilst
794 RenderWhenDisabled = newValue != 0;
796 //---------------------------------------------------------------------------
798 // Set the variable that indicates that we want a stereo capable window
799 // be created. This method can only be called before a window is realized.
801 void creawxVTKRenderWindowInteractor::SetStereo(int capable)
803 if (Stereo != capable)
806 RenderWindow->StereoCapableWindowOn();
807 RenderWindow->SetStereoTypeToCrystalEyes();
812 //---------------------------------------------------------------------------
815 void creawxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
817 this->Superclass::PrintSelf(os, indent);
824 //=======================================================================