2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */
25 /*=========================================================================
27 Program: Visualization Toolkit
28 Module: $RCSfile: creawxVTKRenderWindowInteractor.cxx,v $
30 Date: $Date: 2012/11/15 09:07:32 $
31 Version: $Revision: 1.10 $
33 This software is distributed WITHOUT ANY WARRANTY; without even
34 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
35 PURPOSE. See the above copyright notice for more information.
37 =========================================================================*/
44 #include "creawxVTKRenderWindowInteractor.h"
46 //This is needed for vtk 3.1 :
47 #ifndef VTK_MAJOR_VERSION
48 # include "vtkVersion.h"
51 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
52 # include "vtkCommand.h"
54 # include "vtkInteractorStyle.h"
56 #include "vtkDebugLeaks.h"
60 #include "vtkCocoaRenderWindow.h"
62 #include "vtkCarbonRenderWindow.h"
67 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
68 #if (!wxCHECK_VERSION(2, 4, 0))
69 wxWindow* wxGetTopLevelParent(wxWindow *win)
71 while ( win && !win->IsTopLevel() )
72 win = win->GetParent();
77 // To access objc calls on cocoa
80 #import <Cocoa/Cocoa.h>
81 // This trick is no longer need in VTK CVS, should get rid of that:
84 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
85 #endif //VTK_USE_COCOA
89 # include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
90 # include "gdk/gdkprivate.h"
91 #if wxCHECK_VERSION(2, 8, 0)
93 #include <wx/gtk/win_gtk.h>
95 #include <wx/gtk1/win_gtk.h>
98 #include <wx/gtk/win_gtk.h>
100 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
101 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
102 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
106 #include "wx/x11/privx.h"
107 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
111 //For more info on this class please go to:
112 //http://wxvtk.sf.net
113 //This hack is for some buggy wxGTK version:
114 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
115 # define WX_USE_X_CAPTURE 0
117 # define WX_USE_X_CAPTURE 1
120 #define ID_creawxVTKRenderWindowInteractor_TIMER 1001
125 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
126 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxGLCanvas)
129 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxWindow)
132 //---------------------------------------------------------------------------
133 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
134 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxGLCanvas)
136 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxWindow)
138 //refresh window by doing a Render
139 EVT_PAINT (creawxVTKRenderWindowInteractor::OnPaint)
140 EVT_ERASE_BACKGROUND(creawxVTKRenderWindowInteractor::OnEraseBackground)
141 EVT_MOTION (creawxVTKRenderWindowInteractor::OnMotion)
143 //Bind the events to the event converters
144 EVT_LEFT_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
145 EVT_MIDDLE_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
146 EVT_RIGHT_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
147 EVT_LEFT_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
148 EVT_MIDDLE_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
149 EVT_RIGHT_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
150 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
151 EVT_ENTER_WINDOW(creawxVTKRenderWindowInteractor::OnEnter)
152 EVT_LEAVE_WINDOW(creawxVTKRenderWindowInteractor::OnLeave)
153 EVT_MOUSEWHEEL (creawxVTKRenderWindowInteractor::OnMouseWheel)
154 EVT_KEY_DOWN (creawxVTKRenderWindowInteractor::OnKeyDown)
155 EVT_KEY_UP (creawxVTKRenderWindowInteractor::OnKeyUp)
156 EVT_CHAR (creawxVTKRenderWindowInteractor::OnChar)
158 EVT_TIMER (ID_creawxVTKRenderWindowInteractor_TIMER, creawxVTKRenderWindowInteractor::OnTimer)
159 EVT_SIZE (creawxVTKRenderWindowInteractor::OnSize)
162 //EED win Compilation why??: vtkCxxRevisionMacro(creawxVTKRenderWindowInteractor, "$Revision: 1.10 $")
163 vtkInstantiatorNewMacro(creawxVTKRenderWindowInteractor)
165 //---------------------------------------------------------------------------
166 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
167 #if (wxCHECK_VERSION(2, 8, 0))
168 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
170 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
173 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
175 , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
176 , ActiveButton(wxEVT_NULL)
181 , RenderWhenDisabled(1)
184 #ifdef VTK_DEBUG_LEAKS
185 vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
187 this->RenderWindow = NULL;
188 this->SetRenderWindow(vtkRenderWindow::New());
189 this->RenderWindow->Delete();
191 //---------------------------------------------------------------------------
192 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *parent,
197 const wxString &name)
198 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
199 : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
201 : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
203 , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
204 , ActiveButton(wxEVT_NULL)
209 , RenderWhenDisabled(1)
212 #ifdef VTK_DEBUG_LEAKS
213 vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
215 this->RenderWindow = NULL;
216 this->SetRenderWindow(vtkRenderWindow::New());
217 this->RenderWindow->Delete();
219 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
220 // so we update the size information of the interactor/renderwindow here
221 this->UpdateSize(size.x, size.y);
224 //---------------------------------------------------------------------------
225 creawxVTKRenderWindowInteractor::~creawxVTKRenderWindowInteractor()
227 SetRenderWindow(NULL);
228 SetInteractorStyle(NULL);
230 //---------------------------------------------------------------------------
231 creawxVTKRenderWindowInteractor * creawxVTKRenderWindowInteractor::New()
233 // we don't make use of the objectfactory, because we're not registered
234 return new creawxVTKRenderWindowInteractor;
236 //---------------------------------------------------------------------------
237 void creawxVTKRenderWindowInteractor::Initialize()
239 int *size = RenderWindow->GetSize();
240 // enable everything and start rendering
242 //RenderWindow->Start();
244 // set the size in the render window interactor
248 // this is initialized
251 //---------------------------------------------------------------------------
252 void creawxVTKRenderWindowInteractor::Enable()
254 // if already enabled then done
260 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
265 //---------------------------------------------------------------------------
266 bool creawxVTKRenderWindowInteractor::Enable(bool enable)
268 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
269 return wxGLCanvas::Enable(enable);
271 return wxWindow::Enable(enable);
274 //---------------------------------------------------------------------------
275 void creawxVTKRenderWindowInteractor::Disable()
277 // if already disabled then done
281 // that's it (we can't remove the event handler like it should be...)
285 //---------------------------------------------------------------------------
286 void creawxVTKRenderWindowInteractor::Start()
288 // the interactor cannot control the event loop
289 vtkErrorMacro( << "creawxVTKRenderWindowInteractor::Start() "
290 "interactor cannot control event loop.");
292 //---------------------------------------------------------------------------
293 void creawxVTKRenderWindowInteractor::UpdateSize(int x, int y)
297 // if the size changed tell render window
298 if ( x != Size[0] || y != Size[1] )
300 // adjust our (vtkRenderWindowInteractor size)
303 // and our RenderWindow's size
304 RenderWindow->SetSize(x, y);
308 //---------------------------------------------------------------------------
309 int creawxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
311 // it's a one shot timer
312 if (!timer.Start(10, TRUE))
318 //---------------------------------------------------------------------------
319 int creawxVTKRenderWindowInteractor::DestroyTimer()
324 //---------------------------------------------------------------------------
325 void creawxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
330 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
332 InvokeEvent(vtkCommand::TimerEvent, NULL);
335 InteractorStyle->OnTimer();
339 //---------------------------------------------------------------------------
340 // NOTE on implementation:
341 // Bad luck you ended up in the only tricky place of this code.
342 // A few note, wxWidgets still refuse to provide such convenient method
343 // so I have to maintain it myself, eventhough this is completely integrated
345 // Anyway if this happen to break for you then compare to a recent version of wxPython
346 // and look for the function long wxPyGetWinHandle(wxWindow* win)
347 // in wxPython/src/helpers.cpp
348 long creawxVTKRenderWindowInteractor::GetHandleHack()
350 //helper function to hide the MSW vs GTK stuff
353 // __WXMSW__ is for Win32
354 //__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)
355 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
356 #if defined(__WXMSW__) || defined(__WXMAC__)
357 handle_tmp = (long)this->GetHandle();
360 //__WXCOCOA__ stands for using the objective-c Cocoa API
362 // Here is how to find the NSWindow
363 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
364 wxGetTopLevelParent( this ) );
365 if (toplevel != NULL )
367 handle_tmp = (long)toplevel->GetNSWindow();
369 // The NSView will be deducted from
370 // [(NSWindow*)Handle contentView]
371 // if only I knew how to write that in c++
374 // Find and return the actual X-Window.
375 #if defined(__WXGTK__) || defined(__WXX11__)
376 return (long)GetXWindow(this);
380 // handle_tmp = (long)this->GetXWindow();
385 //---------------------------------------------------------------------------
386 void creawxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
388 //must always be here
391 //do it here rather than in the cstor: this is safer.
394 Handle = GetHandleHack();
395 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
397 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
400 // get vtk to render to the wxWindows
405 vtkCocoaRenderWindow* rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
408 rwin->UpdateContext();
411 // This solves a problem with repainting after a window resize
412 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
413 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
416 rwin->UpdateGLRegion();
422 //---------------------------------------------------------------------------
423 void creawxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
425 //turn off background erase to reduce flickering on MSW
428 //---------------------------------------------------------------------------
429 void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
432 GetClientSize(&w, &h);
440 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
441 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
443 //this will check for Handle
446 //---------------------------------------------------------------------------
447 void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
453 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
454 SetEventInformationFlipY(event.GetX(), event.GetY(),
455 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
457 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
459 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
460 event.GetX(), Size[1] - event.GetY() - 1);
463 //---------------------------------------------------------------------------
464 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
465 void creawxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
472 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
474 SetEventInformationFlipY(event.GetX(), event.GetY(),
475 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
477 InvokeEvent(vtkCommand::EnterEvent, NULL);
480 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
481 event.GetX(), Size[1] - event.GetY() - 1);
484 //---------------------------------------------------------------------------
485 void creawxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
492 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
494 SetEventInformationFlipY(event.GetX(), event.GetY(),
495 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
497 InvokeEvent(vtkCommand::LeaveEvent, NULL);
500 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
501 event.GetX(), Size[1] - event.GetY() - 1);
504 //---------------------------------------------------------------------------
505 void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
512 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
514 int keycode = event.GetKeyCode();
516 if (((unsigned int)keycode) < 256)
518 // TODO: Unicode in non-Unicode mode ??
522 // we don't get a valid mouse position inside the key event on every platform
523 // so we retrieve the mouse position explicitly and pass it along
524 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
525 SetEventInformationFlipY(mousePos.x, mousePos.y,
526 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
527 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
529 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
530 event.GetKeyCode(), 1);
534 //---------------------------------------------------------------------------
535 void creawxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
542 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
544 int keycode = event.GetKeyCode();
546 if (((unsigned int)keycode) < 256)
548 // TODO: Unicode in non-Unicode mode ??
552 // we don't get a valid mouse position inside the key event on every platform
553 // so we retrieve the mouse position explicitly and pass it along
554 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
555 SetEventInformationFlipY(mousePos.x, mousePos.y,
556 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
557 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
559 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
560 event.GetKeyCode(), 1);
564 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
565 //---------------------------------------------------------------------------
566 void creawxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
573 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
575 int keycode = event.GetKeyCode();
577 if (((unsigned int)keycode) < 256)
579 // TODO: Unicode in non-Unicode mode ??
583 // we don't get a valid mouse position inside the key event on every platform
584 // so we retrieve the mouse position explicitly and pass it along
585 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
586 SetEventInformationFlipY(mousePos.x, mousePos.y,
587 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
588 InvokeEvent(vtkCommand::CharEvent, NULL);
592 //---------------------------------------------------------------------------
593 void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
595 if (!Enabled || (ActiveButton != wxEVT_NULL))
599 ActiveButton = event.GetEventType();
601 // On Mac (Carbon) and Windows we don't automatically get the focus when
602 // you click inside the window
603 // we therefore set the focus explicitly
604 // Apparently we need that on linux (GTK) too:
607 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
608 SetEventInformationFlipY(event.GetX(), event.GetY(),
609 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
612 if(event.RightDown())
614 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
616 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
619 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
620 event.GetX(), Size[1] - event.GetY() - 1);
623 else if(event.LeftDown())
625 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
627 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
630 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
631 event.GetX(), Size[1] - event.GetY() - 1);
634 else if(event.MiddleDown())
636 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
638 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
641 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
642 event.GetX(), Size[1] - event.GetY() - 1);
645 //save the button and capture mouse until the button is released
647 //1. it is possible (WX_USE_X_CAPTURE)
648 //2. user decided to.
649 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
654 //---------------------------------------------------------------------------
655 void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
657 //EVT_xxx_DOWN == EVT_xxx_UP - 1
658 //This is only needed if two mouse buttons are pressed at the same time.
659 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
660 //wxEVT_COMMAND_RIGHT_CLICK
661 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
666 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
667 SetEventInformationFlipY(event.GetX(), event.GetY(),
668 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
671 if(ActiveButton == wxEVT_RIGHT_DOWN)
673 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
675 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
678 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
679 event.GetX(), Size[1] - event.GetY() - 1);
682 else if(ActiveButton == wxEVT_LEFT_DOWN)
684 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
686 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
689 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
690 event.GetX(), Size[1] - event.GetY() - 1);
693 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
695 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
697 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
700 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
701 event.GetX(), Size[1] - event.GetY() - 1);
704 //if the ActiveButton is realeased, then release mouse capture
705 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
709 ActiveButton = wxEVT_NULL;
711 //---------------------------------------------------------------------------
712 void creawxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
714 // Mouse wheel was only added after VTK 4.4 (I think...)
715 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
717 //Set vtk event information ... The numebr of wheel rotations is stored in
718 //the x varible. y varible is zero
719 SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
720 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
721 if(event.GetWheelRotation() > 0)
724 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
729 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
735 //---------------------------------------------------------------------------
736 void creawxVTKRenderWindowInteractor::Render()
739 if (!RenderWhenDisabled)
741 //the user doesn't want us to render when the toplevel frame
742 //is disabled - first find the top level parent
743 wxWindow *topParent = wxGetTopLevelParent(this);
746 //if it exists, check whether it's enabled
747 //if it's not enabeld, RenderAllowed will be false
748 RenderAllowed = topParent->IsEnabled();
754 if(Handle && (Handle == GetHandleHack()) )
756 RenderWindow->Render();
758 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
759 else if(GetHandleHack())
761 //this means the user has reparented us; let's adapt to the
762 //new situation by doing the WindowRemap dance
763 //store the new situation
764 Handle = GetHandleHack();
765 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
766 RenderWindow->WindowRemap();
767 RenderWindow->Render();
772 //---------------------------------------------------------------------------
773 void creawxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
775 //Change value of __RenderWhenDisabled ivar.
776 //If __RenderWhenDisabled is false (the default), this widget will not
777 //call Render() on the RenderWindow if the top level frame (i.e. the
778 //containing frame) has been disabled.
780 //This prevents recursive rendering during wxSafeYield() calls.
781 //wxSafeYield() can be called during the ProgressMethod() callback of
782 //a VTK object to have progress bars and other GUI elements updated -
783 //it does this by disabling all windows (disallowing user-input to
784 //prevent re-entrancy of code) and then handling all outstanding
787 //However, this often triggers an OnPaint() method for wxVTKRWIs,
788 //resulting in a Render(), resulting in Update() being called whilst
791 RenderWhenDisabled = (bool)newValue;
793 //---------------------------------------------------------------------------
795 // Set the variable that indicates that we want a stereo capable window
796 // be created. This method can only be called before a window is realized.
798 void creawxVTKRenderWindowInteractor::SetStereo(int capable)
800 if (Stereo != capable)
803 RenderWindow->StereoCapableWindowOn();
804 RenderWindow->SetStereoTypeToCrystalEyes();
809 //---------------------------------------------------------------------------
812 void creawxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
814 this->Superclass::PrintSelf(os, indent);
821 //=======================================================================