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 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
90 #if wxMAJOR_VERSION <= 2
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 <gdk/gdkx.h>
117 #include "wx/x11/privx.h"
118 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
122 //For more info on this class please go to:
123 //http://wxvtk.sf.net
124 //This hack is for some buggy wxGTK version:
125 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
126 # define WX_USE_X_CAPTURE 0
128 # define WX_USE_X_CAPTURE 1
131 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
133 //=======================================================================
134 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
138 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
139 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
141 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
144 //---------------------------------------------------------------------------
145 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
146 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
148 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
150 //refresh window by doing a Render
151 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
152 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
153 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
155 //Bind the events to the event converters
156 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
157 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
158 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
159 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
160 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
161 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
162 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
163 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
164 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
165 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
166 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
167 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
168 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
170 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
171 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
174 vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision: 1.5 $")
175 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
177 //---------------------------------------------------------------------------
178 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
179 #if (wxCHECK_VERSION(2, 8, 0))
180 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
182 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
185 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
187 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
188 , ActiveButton(wxEVT_NULL)
193 , RenderWhenDisabled(1)
196 #ifdef VTK_DEBUG_LEAKS
197 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
199 this->RenderWindow = NULL;
200 this->SetRenderWindow(vtkRenderWindow::New());
201 this->RenderWindow->Delete();
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);
236 //---------------------------------------------------------------------------
237 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
239 SetRenderWindow(NULL);
240 SetInteractorStyle(NULL);
242 //---------------------------------------------------------------------------
243 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
245 // we don't make use of the objectfactory, because we're not registered
246 return new wxVTKRenderWindowInteractor;
248 //---------------------------------------------------------------------------
249 void wxVTKRenderWindowInteractor::Initialize()
251 int *size = RenderWindow->GetSize();
252 // enable everything and start rendering
254 //RenderWindow->Start();
256 // set the size in the render window interactor
260 // this is initialized
263 //---------------------------------------------------------------------------
264 void wxVTKRenderWindowInteractor::Enable()
266 // if already enabled then done
272 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
277 //---------------------------------------------------------------------------
278 bool wxVTKRenderWindowInteractor::Enable(bool enable)
280 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
281 return wxGLCanvas::Enable(enable);
283 return wxWindow::Enable(enable);
286 //---------------------------------------------------------------------------
287 void wxVTKRenderWindowInteractor::Disable()
289 // if already disabled then done
293 // that's it (we can't remove the event handler like it should be...)
297 //---------------------------------------------------------------------------
298 void wxVTKRenderWindowInteractor::Start()
300 // the interactor cannot control the event loop
301 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
302 "interactor cannot control event loop.");
304 //---------------------------------------------------------------------------
305 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
309 // if the size changed tell render window
310 if ( x != Size[0] || y != Size[1] )
312 // adjust our (vtkRenderWindowInteractor size)
315 // and our RenderWindow's size
316 RenderWindow->SetSize(x, y);
320 //---------------------------------------------------------------------------
321 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
323 // it's a one shot timer
324 if (!timer.Start(10, TRUE))
330 //---------------------------------------------------------------------------
331 int wxVTKRenderWindowInteractor::DestroyTimer()
336 //---------------------------------------------------------------------------
337 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
342 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
344 InvokeEvent(vtkCommand::TimerEvent, NULL);
347 InteractorStyle->OnTimer();
351 //---------------------------------------------------------------------------
352 // NOTE on implementation:
353 // Bad luck you ended up in the only tricky place of this code.
354 // A few note, wxWidgets still refuse to provide such convenient method
355 // so I have to maintain it myself, eventhough this is completely integrated
357 // Anyway if this happen to break for you then compare to a recent version of wxPython
358 // and look for the function long wxPyGetWinHandle(wxWindow* win)
359 // in wxPython/src/helpers.cpp
360 long wxVTKRenderWindowInteractor::GetHandleHack()
362 //helper function to hide the MSW vs GTK stuff
365 // __WXMSW__ is for Win32
366 //__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)
367 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
368 #if defined(__WXMSW__) || defined(__WXMAC__)
369 handle_tmp = (long)this->GetHandle();
372 //__WXCOCOA__ stands for using the objective-c Cocoa API
374 // Here is how to find the NSWindow
375 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
376 wxGetTopLevelParent( this ) );
377 if (toplevel != NULL )
379 handle_tmp = (long)toplevel->GetNSWindow();
381 // The NSView will be deducted from
382 // [(NSWindow*)Handle contentView]
383 // if only I knew how to write that in c++
386 // Find and return the actual X-Window.
387 #if defined(__WXGTK__) || defined(__WXX11__)
389 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
390 #if wxMAJOR_VERSION <= 2
391 return (long)GetXWindow(this);
393 GdkWindow* Win = gtk_widget_get_window( (GtkWidget *) GetHandle() );
394 return (long int)GDK_WINDOW_XDISPLAY(Win);
400 // handle_tmp = (long)this->GetXWindow();
405 //---------------------------------------------------------------------------
406 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
408 //must always be here
411 //do it here rather than in the cstor: this is safer.
414 Handle = GetHandleHack();
415 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
417 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
420 // get vtk to render to the wxWindows
423 // This solves a problem with repainting after a window resize
424 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
425 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
428 rwin->UpdateGLRegion();
432 //---------------------------------------------------------------------------
433 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
435 //turn off background erase to reduce flickering on MSW
438 //---------------------------------------------------------------------------
439 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
442 GetClientSize(&w, &h);
450 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
451 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
453 //this will check for Handle
456 //---------------------------------------------------------------------------
457 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
463 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
464 SetEventInformationFlipY(event.GetX(), event.GetY(),
465 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
467 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
469 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
470 event.GetX(), Size[1] - event.GetY() - 1);
473 //---------------------------------------------------------------------------
474 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
475 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
482 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
484 SetEventInformationFlipY(event.GetX(), event.GetY(),
485 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
487 InvokeEvent(vtkCommand::EnterEvent, NULL);
490 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
491 event.GetX(), Size[1] - event.GetY() - 1);
494 //---------------------------------------------------------------------------
495 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
502 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
504 SetEventInformationFlipY(event.GetX(), event.GetY(),
505 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
507 InvokeEvent(vtkCommand::LeaveEvent, NULL);
510 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
511 event.GetX(), Size[1] - event.GetY() - 1);
514 //---------------------------------------------------------------------------
515 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
522 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
524 int keycode = event.GetKeyCode();
526 if (((unsigned int)keycode) < 256)
528 // TODO: Unicode in non-Unicode mode ??
532 // we don't get a valid mouse position inside the key event on every platform
533 // so we retrieve the mouse position explicitly and pass it along
534 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
535 SetEventInformationFlipY(mousePos.x, mousePos.y,
536 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
537 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
539 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
540 event.GetKeyCode(), 1);
544 //---------------------------------------------------------------------------
545 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
552 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
554 int keycode = event.GetKeyCode();
556 if (((unsigned int)keycode) < 256)
558 // TODO: Unicode in non-Unicode mode ??
562 // we don't get a valid mouse position inside the key event on every platform
563 // so we retrieve the mouse position explicitly and pass it along
564 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
565 SetEventInformationFlipY(mousePos.x, mousePos.y,
566 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
567 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
569 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
570 event.GetKeyCode(), 1);
574 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
575 //---------------------------------------------------------------------------
576 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
583 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
585 int keycode = event.GetKeyCode();
587 if (((unsigned int)keycode) < 256)
589 // TODO: Unicode in non-Unicode mode ??
593 // we don't get a valid mouse position inside the key event on every platform
594 // so we retrieve the mouse position explicitly and pass it along
595 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
596 SetEventInformationFlipY(mousePos.x, mousePos.y,
597 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
598 InvokeEvent(vtkCommand::CharEvent, NULL);
602 //---------------------------------------------------------------------------
603 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
605 if (!Enabled || (ActiveButton != wxEVT_NULL))
609 ActiveButton = event.GetEventType();
611 // On Mac (Carbon) and Windows we don't automatically get the focus when
612 // you click inside the window
613 // we therefore set the focus explicitly
614 // Apparently we need that on linux (GTK) too:
617 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
618 SetEventInformationFlipY(event.GetX(), event.GetY(),
619 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
622 if(event.RightDown())
624 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
626 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
629 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
630 event.GetX(), Size[1] - event.GetY() - 1);
633 else if(event.LeftDown())
635 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
637 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
640 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
641 event.GetX(), Size[1] - event.GetY() - 1);
644 else if(event.MiddleDown())
646 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
648 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
651 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
652 event.GetX(), Size[1] - event.GetY() - 1);
655 //save the button and capture mouse until the button is released
657 //1. it is possible (WX_USE_X_CAPTURE)
658 //2. user decided to.
659 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
664 //---------------------------------------------------------------------------
665 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
667 //EVT_xxx_DOWN == EVT_xxx_UP - 1
668 //This is only needed if two mouse buttons are pressed at the same time.
669 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
670 //wxEVT_COMMAND_RIGHT_CLICK
671 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
676 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
677 SetEventInformationFlipY(event.GetX(), event.GetY(),
678 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
681 if(ActiveButton == wxEVT_RIGHT_DOWN)
683 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
685 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
688 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
689 event.GetX(), Size[1] - event.GetY() - 1);
692 else if(ActiveButton == wxEVT_LEFT_DOWN)
694 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
696 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
699 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
700 event.GetX(), Size[1] - event.GetY() - 1);
703 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
705 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
707 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
710 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
711 event.GetX(), Size[1] - event.GetY() - 1);
714 //if the ActiveButton is realeased, then release mouse capture
715 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
719 ActiveButton = wxEVT_NULL;
721 //---------------------------------------------------------------------------
722 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
724 // Mouse wheel was only added after VTK 4.4 (I think...)
725 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
727 //Set vtk event information ... The numebr of wheel rotations is stored in
728 //the x varible. y varible is zero
729 SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
730 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
731 if(event.GetWheelRotation() > 0)
734 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
739 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
745 //---------------------------------------------------------------------------
746 void wxVTKRenderWindowInteractor::Render()
749 if (!RenderWhenDisabled)
751 //the user doesn't want us to render when the toplevel frame
752 //is disabled - first find the top level parent
753 wxWindow *topParent = wxGetTopLevelParent(this);
756 //if it exists, check whether it's enabled
757 //if it's not enabeld, RenderAllowed will be false
758 RenderAllowed = topParent->IsEnabled();
764 if(Handle && (Handle == GetHandleHack()) )
766 RenderWindow->Render();
768 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
769 else if(GetHandleHack())
771 //this means the user has reparented us; let's adapt to the
772 //new situation by doing the WindowRemap dance
773 //store the new situation
774 Handle = GetHandleHack();
775 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
776 RenderWindow->WindowRemap();
777 RenderWindow->Render();
782 //---------------------------------------------------------------------------
783 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
785 //Change value of __RenderWhenDisabled ivar.
786 //If __RenderWhenDisabled is false (the default), this widget will not
787 //call Render() on the RenderWindow if the top level frame (i.e. the
788 //containing frame) has been disabled.
790 //This prevents recursive rendering during wxSafeYield() calls.
791 //wxSafeYield() can be called during the ProgressMethod() callback of
792 //a VTK object to have progress bars and other GUI elements updated -
793 //it does this by disabling all windows (disallowing user-input to
794 //prevent re-entrancy of code) and then handling all outstanding
797 //However, this often triggers an OnPaint() method for wxVTKRWIs,
798 //resulting in a Render(), resulting in Update() being called whilst
801 RenderWhenDisabled = (bool)newValue;
803 //---------------------------------------------------------------------------
805 // Set the variable that indicates that we want a stereo capable window
806 // be created. This method can only be called before a window is realized.
808 void wxVTKRenderWindowInteractor::SetStereo(int capable)
810 if (Stereo != capable)
813 RenderWindow->StereoCapableWindowOn();
814 RenderWindow->SetStereoTypeToCrystalEyes();
819 //---------------------------------------------------------------------------
822 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
824 this->Superclass::PrintSelf(os, indent);
829 // LG : EO namespace bbwxvtk
830 //=======================================================================