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
36 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
38 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
40 This software is distributed WITHOUT ANY WARRANTY; without even
41 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42 PURPOSE. See the above copyright notice for more information.
44 =========================================================================*/
50 #include "creawxVTKRenderWindowInteractor.h"
52 //This is needed for vtk 3.1 :
53 #ifndef VTK_MAJOR_VERSION
54 # include "vtkVersion.h"
57 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
58 # include "vtkCommand.h"
60 # include "vtkInteractorStyle.h"
62 #include "vtkDebugLeaks.h"
64 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
65 #ifdef __WXOSX_COCOA__
66 #import <Cocoa/Cocoa.h>
70 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
71 // ControlDown has been changed to mean Command key down
72 #define ControlDown RawControlDown
77 #include "vtkCocoaRenderWindow.h"
79 #include "vtkCarbonRenderWindow.h"
84 //=======================================================================
85 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
90 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
91 #if (!wxCHECK_VERSION(2, 4, 0))
92 wxWindow* wxGetTopLevelParent(wxWindow *win)
94 while ( win && !win->IsTopLevel() )
95 win = win->GetParent();
100 // LG : EO namespace bbwxvtk
101 //=======================================================================
103 // To access objc calls on cocoa
106 //EED #import <Cocoa/Cocoa.h>
107 // This trick is no longer need in VTK CVS, should get rid of that:
110 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
111 #endif //VTK_USE_COCOA
114 #if wxMAJOR_VERSION <= 2
116 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
117 #include "gdk/gdkprivate.h"
118 #if wxCHECK_VERSION(2, 9, 0)
119 // thanks to: http://thomasfischer.biz/?p=382
120 #include <gtk/gtkfixed.h>
121 #include <gtk/gtkwidget.h>
122 #include <wx/gtk/private/win_gtk.h>
123 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
124 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
125 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
126 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
128 #if wxCHECK_VERSION(2, 8, 0)
130 #include <wx/gtk/win_gtk.h>
132 #include <wx/gtk1/win_gtk.h>
135 #include <wx/gtk/win_gtk.h>
138 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
139 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
140 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
146 #include <gdk/gdkx.h>
148 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
149 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
150 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
155 #include "wx/x11/privx.h"
156 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
159 //For more info on this class please go to:
160 //http://wxvtk.sf.net
161 //This hack is for some buggy wxGTK version:
162 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
163 # define WX_USE_X_CAPTURE 0
165 # define WX_USE_X_CAPTURE 1
168 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
170 //=======================================================================
171 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
175 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
179 //---------------------------------------------------------------------------
180 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
181 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
182 #if wxMAJOR_VERSION <= 2
183 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
184 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
186 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
187 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
190 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
191 #if wxMAJOR_VERSION <= 2
192 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
193 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
195 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
196 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
199 //refresh window by doing a Render
200 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
201 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
202 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
204 //Bind the events to the event converters
205 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
206 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
207 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
208 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
209 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
210 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
211 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
212 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
213 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
214 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
215 #if wxCHECK_VERSION(2, 8, 0)
216 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
218 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
219 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
220 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
222 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
223 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
226 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
227 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
229 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
230 static int wxvtk_attributes[]={
239 //---------------------------------------------------------------------------
240 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
242 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
243 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
244 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
246 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
252 vtkRenderWindowInteractor()
253 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
254 , ActiveButton(wxEVT_NULL)
258 , RenderWhenDisabled(1)
261 #ifdef VTK_DEBUG_LEAKS
262 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
264 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
265 this->context = new wxGLContext(this);
267 this->RenderWindow = NULL;
268 this->SetRenderWindow(vtkRenderWindow::New());
269 this->RenderWindow->Delete();
271 //---------------------------------------------------------------------------
272 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
277 const wxString &name)
278 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
279 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
280 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
282 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
285 : wxWindow(parent, id, pos, size, style, name)
287 , vtkRenderWindowInteractor()
288 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
289 , ActiveButton(wxEVT_NULL)
293 , RenderWhenDisabled(1)
296 #ifdef VTK_DEBUG_LEAKS
297 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
299 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
300 this->context = new wxGLContext(this);
302 this->RenderWindow = NULL;
303 this->SetRenderWindow(vtkRenderWindow::New());
304 this->RenderWindow->Delete();
306 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
307 // so we update the size information of the interactor/renderwindow here
308 this->UpdateSize(size.x, size.y);
311 //---------------------------------------------------------------------------
312 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
314 SetRenderWindow(NULL);
315 SetInteractorStyle(NULL);
316 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
317 delete this->context;
320 //---------------------------------------------------------------------------
321 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
323 // we don't make use of the objectfactory, because we're not registered
324 return new wxVTKRenderWindowInteractor;
326 //---------------------------------------------------------------------------
327 void wxVTKRenderWindowInteractor::Initialize()
329 int *size = RenderWindow->GetSize();
330 // enable everything and start rendering
332 //RenderWindow->Start();
334 // set the size in the render window interactor
338 // this is initialized
341 //---------------------------------------------------------------------------
342 void wxVTKRenderWindowInteractor::Enable()
344 // if already enabled then done
350 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
351 wxGLCanvas::SetCurrent(*this->context);
355 //---------------------------------------------------------------------------
356 bool wxVTKRenderWindowInteractor::Enable(bool enable)
358 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
359 return wxGLCanvas::Enable(enable);
361 return wxWindow::Enable(enable);
364 //---------------------------------------------------------------------------
365 void wxVTKRenderWindowInteractor::Disable()
367 // if already disabled then done
371 // that's it (we can't remove the event handler like it should be...)
375 //---------------------------------------------------------------------------
376 void wxVTKRenderWindowInteractor::Start()
378 // the interactor cannot control the event loop
379 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
380 "interactor cannot control event loop.");
382 //---------------------------------------------------------------------------
383 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
387 // if the size changed tell render window
388 if ( x != Size[0] || y != Size[1] )
390 // adjust our (vtkRenderWindowInteractor size)
393 // and our RenderWindow's size
394 RenderWindow->SetSize(x, y);
395 #if defined(__WXMSW__)
401 //---------------------------------------------------------------------------
402 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
404 // it's a one shot timer
405 if (!timer.Start(10, TRUE))
411 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
412 //------------------------------------------------------------------
413 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
414 unsigned long duration)
416 if (!timer.Start(duration, timerType == OneShotTimer))
419 return ID_wxVTKRenderWindowInteractor_TIMER;
421 //------------------------------------------------------------------
422 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
428 //---------------------------------------------------------------------------
429 int wxVTKRenderWindowInteractor::DestroyTimer()
434 //---------------------------------------------------------------------------
435 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
440 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
442 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
443 // pass the right timer id
444 int timerId = this->GetCurrentTimerId();
445 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
447 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
451 InteractorStyle->OnTimer();
455 //---------------------------------------------------------------------------
456 // NOTE on implementation:
457 // Bad luck you ended up in the only tricky place of this code.
458 // A few note, wxWidgets still refuse to provide such convenient method
459 // so I have to maintain it myself, eventhough this is completely integrated
461 // Anyway if this happen to break for you then compare to a recent version of wxPython
462 // and look for the function long wxPyGetWinHandle(wxWindow* win)
463 // in wxPython/src/helpers.cpp
464 long wxVTKRenderWindowInteractor::GetHandleHack()
466 //helper function to hide the MSW vs GTK stuff
469 // __WXMSW__ is for Win32
470 // __WXMAC__ is for Carbon or Cocoa builds
471 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
472 #if defined(__WXMSW__) || defined(__WXMAC__)
473 handle_tmp = (long)this->GetHandle();
476 // using above GetHandle() works fine with wxOSX 2.9.x
477 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
478 // Here is how to find the NSWindow
479 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
480 if (toplevel != NULL )
482 handle_tmp = (long)toplevel->GetNSWindow();
484 // The NSView will be deducted from
485 // [(NSWindow*)Handle contentView]
486 // if only I knew how to write that in c++
487 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
489 // Find and return the actual X-Window.
490 #if defined(__WXGTK__) || defined(__WXX11__)
491 return (long)GetXWindow(this);
495 // handle_tmp = (long)this->GetXWindow();
500 //---------------------------------------------------------------------------
501 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
503 //must always be here
506 //do it here rather than in the cstor: this is safer.
509 Handle = GetHandleHack();
512 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
513 NSView *nvsview = (NSView* )Handle;
514 NSWindow *nswindow = nvsview.window;
515 rwin->SetRootWindow( nswindow );
516 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
518 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
524 // this->GetNSView() <-> DisplayId
525 // this->GetTopLevel()->GetNSWindow() <-> WindowId
527 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
530 // This is another hack to prevent the VTK Render Window from closing the display.
531 // If VTK closes the display, ~wxContext chashes while trying to destroy its
532 // glContext (because the display is closed). The Get -> Set makes this VTK
533 // object think someone else is responsible for the display.
535 // avoid "Method not implemented" messages in Console
537 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
540 // get vtk to render to the wxWindows
543 // This solves a problem with repainting after a window resize
544 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
546 #if !wxCHECK_VERSION(2, 9, 0)
547 // this doesn't seem necessary with wxOSX 2.9.x
548 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
551 rwin->UpdateContext();
555 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
558 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
559 // Must be somewhere after VTK 4.4
560 rwin->UpdateGLRegion();
566 //---------------------------------------------------------------------------
567 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
569 //turn off background erase to reduce flickering on MSW
572 //---------------------------------------------------------------------------
573 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
576 GetClientSize(&w, &h);
584 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
585 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
587 //this will check for Handle
590 //---------------------------------------------------------------------------
591 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
597 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
598 SetEventInformationFlipY(event.GetX(), event.GetY(),
599 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
601 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
603 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
604 event.GetX(), Size[1] - event.GetY() - 1);
607 //---------------------------------------------------------------------------
608 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
609 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
616 #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);
621 InvokeEvent(vtkCommand::EnterEvent, NULL);
624 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
625 event.GetX(), Size[1] - event.GetY() - 1);
628 //---------------------------------------------------------------------------
629 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
636 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
638 SetEventInformationFlipY(event.GetX(), event.GetY(),
639 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
641 InvokeEvent(vtkCommand::LeaveEvent, NULL);
644 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
645 event.GetX(), Size[1] - event.GetY() - 1);
648 //---------------------------------------------------------------------------
649 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
656 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
658 int keycode = event.GetKeyCode();
660 if (((unsigned int)keycode) < 256)
662 // TODO: Unicode in non-Unicode mode ??
666 // we don't get a valid mouse position inside the key event on every platform
667 // so we retrieve the mouse position explicitly and pass it along
668 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
669 SetEventInformationFlipY(mousePos.x, mousePos.y,
670 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
671 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
673 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
674 event.GetKeyCode(), 1);
678 //---------------------------------------------------------------------------
679 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
686 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
688 int keycode = event.GetKeyCode();
690 if (((unsigned int)keycode) < 256)
692 // TODO: Unicode in non-Unicode mode ??
696 // we don't get a valid mouse position inside the key event on every platform
697 // so we retrieve the mouse position explicitly and pass it along
698 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
699 SetEventInformationFlipY(mousePos.x, mousePos.y,
700 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
701 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
703 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
704 event.GetKeyCode(), 1);
708 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
709 //---------------------------------------------------------------------------
710 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
717 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
719 int keycode = event.GetKeyCode();
721 if (((unsigned int)keycode) < 256)
723 // TODO: Unicode in non-Unicode mode ??
727 // we don't get a valid mouse position inside the key event on every platform
728 // so we retrieve the mouse position explicitly and pass it along
729 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
730 SetEventInformationFlipY(mousePos.x, mousePos.y,
731 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
732 InvokeEvent(vtkCommand::CharEvent, NULL);
736 //---------------------------------------------------------------------------
737 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
739 if (!Enabled || (ActiveButton != wxEVT_NULL))
743 ActiveButton = event.GetEventType();
745 // On Mac (Carbon) and Windows we don't automatically get the focus when
746 // you click inside the window
747 // we therefore set the focus explicitly
748 // Apparently we need that on linux (GTK) too:
751 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
752 SetEventInformationFlipY(event.GetX(), event.GetY(),
753 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
756 if(event.RightDown())
758 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
760 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
763 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
764 event.GetX(), Size[1] - event.GetY() - 1);
767 else if(event.LeftDown())
769 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
771 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
774 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
775 event.GetX(), Size[1] - event.GetY() - 1);
778 else if(event.MiddleDown())
780 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
782 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
785 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
786 event.GetX(), Size[1] - event.GetY() - 1);
789 //save the button and capture mouse until the button is released
791 //1. it is possible (WX_USE_X_CAPTURE)
792 //2. user decided to.
793 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
798 //---------------------------------------------------------------------------
799 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
801 //EVT_xxx_DOWN == EVT_xxx_UP - 1
802 //This is only needed if two mouse buttons are pressed at the same time.
803 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
804 //wxEVT_COMMAND_RIGHT_CLICK
805 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
810 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
813 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
814 SetEventInformationFlipY(event.GetX(), event.GetY(),
815 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
818 if(ActiveButton == wxEVT_RIGHT_DOWN)
820 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
822 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
825 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
826 event.GetX(), Size[1] - event.GetY() - 1);
829 else if(ActiveButton == wxEVT_LEFT_DOWN)
831 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
833 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
836 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
837 event.GetX(), Size[1] - event.GetY() - 1);
840 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
842 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
844 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
847 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
848 event.GetX(), Size[1] - event.GetY() - 1);
851 //if the ActiveButton is realeased, then release mouse capture
852 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
856 ActiveButton = wxEVT_NULL;
858 //---------------------------------------------------------------------------
859 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
861 // Mouse wheel was only added after VTK 4.4 (I think...)
862 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
864 //Set vtk event information ... The numebr of wheel rotations is stored in
865 //the x varible. y varible is zero
866 SetEventInformationFlipY(event.GetX() , event.GetY(),
867 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
868 if(event.GetWheelRotation() > 0)
871 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
876 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
882 //---------------------------------------------------------------------------
883 #if wxCHECK_VERSION(2, 8, 0)
884 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
886 if (ActiveButton != wxEVT_NULL)
888 //Maybe also invoke the button release event here
890 // Reset ActiveButton so that
891 // 1. we do not process mouse button up events any more,
892 // 2. the next button down event will be processed and call CaptureMouse().
893 // Otherwise ReleaseMouse() will be called
894 // without a previous CaptureMouse().
895 ActiveButton = wxEVT_NULL;
899 //---------------------------------------------------------------------------
900 void wxVTKRenderWindowInteractor::Render()
902 #if wxCHECK_VERSION(2, 8, 0)
903 int renderAllowed = !IsFrozen();
905 int renderAllowed = 1;
907 if (renderAllowed && !RenderWhenDisabled)
909 //the user doesn't want us to render when the toplevel frame
910 //is disabled - first find the top level parent
911 wxWindow *topParent = wxGetTopLevelParent(this);
914 //if it exists, check whether it's enabled
915 //if it's not enabeld, renderAllowed will be false
916 renderAllowed = topParent->IsEnabled();
922 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
923 wxGLCanvas::SetCurrent(*(this->context));
925 if(Handle && (Handle == GetHandleHack()) )
927 RenderWindow->Render();
929 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
930 else if(GetHandleHack())
932 //this means the user has reparented us; let's adapt to the
933 //new situation by doing the WindowRemap dance
934 //store the new situation
935 Handle = GetHandleHack();
936 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
937 RenderWindow->WindowRemap();
938 RenderWindow->Render();
944 //---------------------------------------------------------------------------
945 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
947 //Change value of __RenderWhenDisabled ivar.
948 //If __RenderWhenDisabled is false (the default), this widget will not
949 //call Render() on the RenderWindow if the top level frame (i.e. the
950 //containing frame) has been disabled.
952 //This prevents recursive rendering during wxSafeYield() calls.
953 //wxSafeYield() can be called during the ProgressMethod() callback of
954 //a VTK object to have progress bars and other GUI elements updated -
955 //it does this by disabling all windows (disallowing user-input to
956 //prevent re-entrancy of code) and then handling all outstanding
959 //However, this often triggers an OnPaint() method for wxVTKRWIs,
960 //resulting in a Render(), resulting in Update() being called whilst
963 RenderWhenDisabled = (bool)newValue;
965 //---------------------------------------------------------------------------
967 // Set the variable that indicates that we want a stereo capable window
968 // be created. This method can only be called before a window is realized.
970 void wxVTKRenderWindowInteractor::SetStereo(int capable)
972 if (Stereo != capable)
975 RenderWindow->StereoCapableWindowOn();
976 RenderWindow->SetStereoTypeToCrystalEyes();
981 //---------------------------------------------------------------------------
984 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
986 this->Superclass::PrintSelf(os, indent);
991 // LG : EO namespace bbwxvtk
992 //=======================================================================