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: wxVTKRenderWindowInteractor.cxx,v $
33 Date: $Date: 2012/11/16 08:52:36 $
34 Version: $Revision: 1.5 $
36 =========================================================================*/
40 #include "wxVTKRenderWindowInteractor.h"
42 //This is needed for vtk 3.1 :
43 #ifndef VTK_MAJOR_VERSION
44 # include "vtkVersion.h"
47 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
48 # include "vtkCommand.h"
50 # include "vtkInteractorStyle.h"
52 #include "vtkDebugLeaks.h"
55 #include "vtkCarbonRenderWindow.h"
58 //=======================================================================
59 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
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 // LG : EO namespace bbwxvtk
75 //=======================================================================
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_wxVTKRenderWindowInteractor_TIMER 1001
122 //=======================================================================
123 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
127 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
128 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
130 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
133 //---------------------------------------------------------------------------
134 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
135 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
137 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
139 //refresh window by doing a Render
140 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
141 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
142 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
144 //Bind the events to the event converters
145 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
146 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
147 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
148 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
149 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
150 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
151 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
152 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
153 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
154 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
155 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
156 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
157 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
159 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
160 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
165 //EED 2017-01-01 Migration VTK7
166 #if VTK_MAJOR_VERSION <= 5
167 vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision: 1.5 $")
172 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
174 //---------------------------------------------------------------------------
175 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
176 #if (wxCHECK_VERSION(2, 8, 0))
177 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
179 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
182 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
184 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
185 , ActiveButton(wxEVT_NULL)
190 , RenderWhenDisabled(1)
193 #ifdef VTK_DEBUG_LEAKS
194 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
197 this->RenderWindow = NULL;
198 this->SetRenderWindow(vtkRenderWindow::New());
199 this->RenderWindow->Delete();
200 this->SetBackgroundStyle( wxBG_STYLE_COLOUR );
201 this->SetBackgroundColour( wxColor(0,0,0,0) );
203 //---------------------------------------------------------------------------
204 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
209 const wxString &name)
210 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
211 : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
213 : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
215 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
216 , ActiveButton(wxEVT_NULL)
221 , RenderWhenDisabled(1)
224 #ifdef VTK_DEBUG_LEAKS
225 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
227 this->RenderWindow = NULL;
228 this->SetRenderWindow(vtkRenderWindow::New());
229 this->RenderWindow->Delete();
231 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
232 // so we update the size information of the interactor/renderwindow here
233 this->UpdateSize(size.x, size.y);
235 this->SetBackgroundStyle( wxBG_STYLE_COLOUR );
236 this->SetBackgroundColour( wxColor(0,0,0,0) );
238 //---------------------------------------------------------------------------
239 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
241 SetRenderWindow(NULL);
242 SetInteractorStyle(NULL);
244 //---------------------------------------------------------------------------
245 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
247 // we don't make use of the objectfactory, because we're not registered
248 return new wxVTKRenderWindowInteractor;
250 //---------------------------------------------------------------------------
251 void wxVTKRenderWindowInteractor::Initialize()
253 int *size = RenderWindow->GetSize();
254 // enable everything and start rendering
256 //RenderWindow->Start();
258 // set the size in the render window interactor
262 // this is initialized
265 //---------------------------------------------------------------------------
266 void wxVTKRenderWindowInteractor::Enable()
268 // if already enabled then done
274 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
279 //---------------------------------------------------------------------------
280 bool wxVTKRenderWindowInteractor::Enable(bool enable)
282 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
283 return wxGLCanvas::Enable(enable);
285 return wxWindow::Enable(enable);
288 //---------------------------------------------------------------------------
289 void wxVTKRenderWindowInteractor::Disable()
291 // if already disabled then done
295 // that's it (we can't remove the event handler like it should be...)
299 //---------------------------------------------------------------------------
300 void wxVTKRenderWindowInteractor::Start()
302 // the interactor cannot control the event loop
303 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
304 "interactor cannot control event loop.");
306 //---------------------------------------------------------------------------
307 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
311 // if the size changed tell render window
312 if ( x != Size[0] || y != Size[1] )
314 // adjust our (vtkRenderWindowInteractor size)
317 // and our RenderWindow's size
318 RenderWindow->SetSize(x, y);
322 //---------------------------------------------------------------------------
323 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
325 // it's a one shot timer
326 if (!timer.Start(10, TRUE))
334 //---------------------------------------------------------------------------
335 int wxVTKRenderWindowInteractor::DestroyTimer()
340 //---------------------------------------------------------------------------
341 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
348 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
350 InvokeEvent(vtkCommand::TimerEvent, NULL);
353 InteractorStyle->OnTimer();
357 //---------------------------------------------------------------------------
358 // NOTE on implementation:
359 // Bad luck you ended up in the only tricky place of this code.
360 // A few note, wxWidgets still refuse to provide such convenient method
361 // so I have to maintain it myself, eventhough this is completely integrated
363 // Anyway if this happen to break for you then compare to a recent version of wxPython
364 // and look for the function long wxPyGetWinHandle(wxWindow* win)
365 // in wxPython/src/helpers.cpp
366 long wxVTKRenderWindowInteractor::GetHandleHack()
368 //helper function to hide the MSW vs GTK stuff
371 // __WXMSW__ is for Win32
372 //__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)
373 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
374 #if defined(__WXMSW__) || defined(__WXMAC__)
375 handle_tmp = (long)this->GetHandle();
378 //__WXCOCOA__ stands for using the objective-c Cocoa API
380 // Here is how to find the NSWindow
381 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
382 wxGetTopLevelParent( this ) );
383 if (toplevel != NULL )
385 handle_tmp = (long)toplevel->GetNSWindow();
387 // The NSView will be deducted from
388 // [(NSWindow*)Handle contentView]
389 // if only I knew how to write that in c++
392 // Find and return the actual X-Window.
393 #if defined(__WXGTK__) || defined(__WXX11__)
394 return (long)GetXWindow(this);
398 // handle_tmp = (long)this->GetXWindow();
403 //---------------------------------------------------------------------------
404 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
406 //must always be here
409 //do it here rather than in the cstor: this is safer.
412 Handle = GetHandleHack();
413 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
415 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
418 // get vtk to render to the wxWindows
421 // This solves a problem with repainting after a window resize
422 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
423 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
426 rwin->UpdateGLRegion();
431 //---------------------------------------------------------------------------
432 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
434 //turn off background erase to reduce flickering on MSW
437 //---------------------------------------------------------------------------
438 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
441 GetClientSize(&w, &h);
449 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
450 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
452 //this will check for Handle
455 //---------------------------------------------------------------------------
456 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
464 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
465 SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
466 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
468 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1);
471 //---------------------------------------------------------------------------
472 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
473 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
480 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
482 SetEventInformationFlipY(event.GetX(), event.GetY(), event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
483 InvokeEvent(vtkCommand::EnterEvent, NULL);
486 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(), event.GetX(), Size[1] - event.GetY() - 1);
489 //---------------------------------------------------------------------------
490 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
497 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
499 SetEventInformationFlipY(event.GetX(), event.GetY(),
500 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
502 InvokeEvent(vtkCommand::LeaveEvent, NULL);
505 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
506 event.GetX(), Size[1] - event.GetY() - 1);
509 //---------------------------------------------------------------------------
510 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
517 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
519 int keycode = event.GetKeyCode();
521 if (((unsigned int)keycode) < 256)
523 // TODO: Unicode in non-Unicode mode ??
527 // we don't get a valid mouse position inside the key event on every platform
528 // so we retrieve the mouse position explicitly and pass it along
529 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
530 SetEventInformationFlipY(mousePos.x, mousePos.y,
531 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
532 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
534 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
535 event.GetKeyCode(), 1);
539 //---------------------------------------------------------------------------
540 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
547 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
549 int keycode = event.GetKeyCode();
551 if (((unsigned int)keycode) < 256)
553 // TODO: Unicode in non-Unicode mode ??
557 // we don't get a valid mouse position inside the key event on every platform
558 // so we retrieve the mouse position explicitly and pass it along
559 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
560 SetEventInformationFlipY(mousePos.x, mousePos.y,
561 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
562 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
564 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
565 event.GetKeyCode(), 1);
569 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
570 //---------------------------------------------------------------------------
571 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
578 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
580 int keycode = event.GetKeyCode();
582 if (((unsigned int)keycode) < 256)
584 // TODO: Unicode in non-Unicode mode ??
588 // we don't get a valid mouse position inside the key event on every platform
589 // so we retrieve the mouse position explicitly and pass it along
590 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
591 SetEventInformationFlipY(mousePos.x, mousePos.y,
592 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
593 InvokeEvent(vtkCommand::CharEvent, NULL);
597 //---------------------------------------------------------------------------
598 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
600 if (!Enabled || (ActiveButton != wxEVT_NULL))
604 ActiveButton = event.GetEventType();
606 // On Mac (Carbon) and Windows we don't automatically get the focus when
607 // you click inside the window
608 // we therefore set the focus explicitly
609 // Apparently we need that on linux (GTK) too:
612 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
613 SetEventInformationFlipY(event.GetX(), event.GetY(),
614 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
617 if(event.RightDown())
619 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
621 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
624 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
625 event.GetX(), Size[1] - event.GetY() - 1);
628 else if(event.LeftDown())
630 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
632 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
635 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
636 event.GetX(), Size[1] - event.GetY() - 1);
639 else if(event.MiddleDown())
641 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
643 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
646 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
647 event.GetX(), Size[1] - event.GetY() - 1);
650 //save the button and capture mouse until the button is released
652 //1. it is possible (WX_USE_X_CAPTURE)
653 //2. user decided to.
654 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
659 //---------------------------------------------------------------------------
660 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
662 //EVT_xxx_DOWN == EVT_xxx_UP - 1
663 //This is only needed if two mouse buttons are pressed at the same time.
664 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
665 //wxEVT_COMMAND_RIGHT_CLICK
666 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
671 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
672 SetEventInformationFlipY(event.GetX(), event.GetY(),
673 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
676 if(ActiveButton == wxEVT_RIGHT_DOWN)
678 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
680 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
683 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
684 event.GetX(), Size[1] - event.GetY() - 1);
687 else if(ActiveButton == wxEVT_LEFT_DOWN)
689 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
691 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
694 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
695 event.GetX(), Size[1] - event.GetY() - 1);
698 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
700 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
702 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
705 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
706 event.GetX(), Size[1] - event.GetY() - 1);
709 //if the ActiveButton is realeased, then release mouse capture
710 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
714 ActiveButton = wxEVT_NULL;
716 //---------------------------------------------------------------------------
717 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
719 // Mouse wheel was only added after VTK 4.4 (I think...)
720 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
722 //Set vtk event information ... The numebr of wheel rotations is stored in
723 //the x varible. y varible is zero
724 SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
725 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
726 if(event.GetWheelRotation() > 0)
729 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
734 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
740 //---------------------------------------------------------------------------
741 void wxVTKRenderWindowInteractor::Render()
744 if (!RenderWhenDisabled)
746 //the user doesn't want us to render when the toplevel frame
747 //is disabled - first find the top level parent
748 wxWindow *topParent = wxGetTopLevelParent(this);
751 //if it exists, check whether it's enabled
752 //if it's not enabeld, RenderAllowed will be false
753 RenderAllowed = topParent->IsEnabled();
759 if(Handle && (Handle == GetHandleHack()) )
761 RenderWindow->Render();
763 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
764 else if(GetHandleHack())
766 //this means the user has reparented us; let's adapt to the
767 //new situation by doing the WindowRemap dance
768 //store the new situation
769 Handle = GetHandleHack();
770 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
771 RenderWindow->WindowRemap();
772 RenderWindow->Render();
777 //---------------------------------------------------------------------------
778 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
780 //Change value of __RenderWhenDisabled ivar.
781 //If __RenderWhenDisabled is false (the default), this widget will not
782 //call Render() on the RenderWindow if the top level frame (i.e. the
783 //containing frame) has been disabled.
785 //This prevents recursive rendering during wxSafeYield() calls.
786 //wxSafeYield() can be called during the ProgressMethod() callback of
787 //a VTK object to have progress bars and other GUI elements updated -
788 //it does this by disabling all windows (disallowing user-input to
789 //prevent re-entrancy of code) and then handling all outstanding
792 //However, this often triggers an OnPaint() method for wxVTKRWIs,
793 //resulting in a Render(), resulting in Update() being called whilst
796 RenderWhenDisabled = (bool)newValue;
798 //---------------------------------------------------------------------------
800 // Set the variable that indicates that we want a stereo capable window
801 // be created. This method can only be called before a window is realized.
803 void wxVTKRenderWindowInteractor::SetStereo(int capable)
805 if (Stereo != capable)
808 RenderWindow->StereoCapableWindowOn();
809 RenderWindow->SetStereoTypeToCrystalEyes();
814 //---------------------------------------------------------------------------
817 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
819 this->Superclass::PrintSelf(os, indent);
824 // LG : EO namespace bbwxvtk
825 //=======================================================================