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"
85 // #import "vtkTDxMacDevice.h"
86 #import "/Users/davila/Creatis/C11/tpli/include/vtk-8.2/vtkTDxMacDevice.h"
90 //=======================================================================
91 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
96 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
97 #if (!wxCHECK_VERSION(2, 4, 0))
98 wxWindow* wxGetTopLevelParent(wxWindow *win)
100 while ( win && !win->IsTopLevel() )
101 win = win->GetParent();
106 // LG : EO namespace bbwxvtk
107 //=======================================================================
109 // To access objc calls on cocoa
112 // This trick is no longer need in VTK CVS, should get rid of that:
115 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
116 #endif //VTK_USE_COCOA
119 #if wxMAJOR_VERSION <= 2
121 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
122 #include "gdk/gdkprivate.h"
123 #if wxCHECK_VERSION(2, 9, 0)
124 // thanks to: http://thomasfischer.biz/?p=382
125 #include <gtk/gtkfixed.h>
126 #include <gtk/gtkwidget.h>
127 #include <wx/gtk/private/win_gtk.h>
128 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
129 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
130 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
131 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
133 #if wxCHECK_VERSION(2, 8, 0)
135 #include <wx/gtk/win_gtk.h>
137 #include <wx/gtk1/win_gtk.h>
140 #include <wx/gtk/win_gtk.h>
143 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
144 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
145 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
151 #include <gdk/gdkx.h>
153 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
154 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
155 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
160 #include "wx/x11/privx.h"
161 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
164 //For more info on this class please go to:
165 //http://wxvtk.sf.net
166 //This hack is for some buggy wxGTK version:
167 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
168 # define WX_USE_X_CAPTURE 0
170 # define WX_USE_X_CAPTURE 1
173 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
175 //=======================================================================
176 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
180 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
184 //---------------------------------------------------------------------------
185 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
186 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
187 #if wxMAJOR_VERSION <= 2
188 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
189 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
191 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
192 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
195 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
196 #if wxMAJOR_VERSION <= 2
197 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
198 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
200 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
201 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
204 //refresh window by doing a Render
205 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
206 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
207 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
209 //Bind the events to the event converters
210 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
211 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
212 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
213 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
214 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
215 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
216 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
217 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
218 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
219 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
220 #if wxCHECK_VERSION(2, 8, 0)
221 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
223 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
224 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
225 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
227 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
228 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
231 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
234 #if VTK_MAJOR_VERSION < 8
235 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
238 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
239 static int wxvtk_attributes[]={
248 //---------------------------------------------------------------------------
249 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
251 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
252 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
253 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
255 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
261 vtkRenderWindowInteractor()
262 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
263 , ActiveButton(wxEVT_NULL)
267 , RenderWhenDisabled(1)
270 #ifdef VTK_DEBUG_LEAKS
271 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
273 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
274 this->context = new wxGLContext(this);
276 this->RenderWindow = NULL;
277 this->SetRenderWindow(vtkRenderWindow::New());
278 this->RenderWindow->Delete();
281 this->Device=vtkTDxMacDevice::New();
286 //---------------------------------------------------------------------------
287 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
292 const wxString &name)
293 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
294 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
295 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
297 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
300 : wxWindow(parent, id, pos, size, style, name)
302 , vtkRenderWindowInteractor()
303 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
304 , ActiveButton(wxEVT_NULL)
308 , RenderWhenDisabled(1)
311 #ifdef VTK_DEBUG_LEAKS
312 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
314 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
315 this->context = new wxGLContext(this);
317 this->RenderWindow = NULL;
318 this->SetRenderWindow(vtkRenderWindow::New());
319 this->RenderWindow->Delete();
321 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
322 // so we update the size information of the interactor/renderwindow here
323 this->UpdateSize(size.x, size.y);
328 this->Device=vtkTDxMacDevice::New();
333 //---------------------------------------------------------------------------
334 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
336 SetRenderWindow(NULL);
337 SetInteractorStyle(NULL);
338 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
339 delete this->context;
343 this->Device->Delete();
347 //---------------------------------------------------------------------------
348 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
350 // we don't make use of the objectfactory, because we're not registered
351 return new wxVTKRenderWindowInteractor;
353 //---------------------------------------------------------------------------
354 void wxVTKRenderWindowInteractor::Initialize()
356 int *size = RenderWindow->GetSize();
357 // enable everything and start rendering
359 //RenderWindow->Start();
361 // set the size in the render window interactor
365 // this is initialized
368 //---------------------------------------------------------------------------
369 void wxVTKRenderWindowInteractor::Enable()
371 // if already enabled then done
377 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
378 wxGLCanvas::SetCurrent(*this->context);
385 this->Device->SetInteractor(this);
386 this->Device->Initialize();
394 //---------------------------------------------------------------------------
395 bool wxVTKRenderWindowInteractor::Enable(bool enable)
401 this->Device->SetInteractor(this);
402 this->Device->Initialize();
408 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
409 return wxGLCanvas::Enable(enable);
411 return wxWindow::Enable(enable);
414 //---------------------------------------------------------------------------
415 void wxVTKRenderWindowInteractor::Disable()
417 // if already disabled then done
422 if(this->Device->GetInitialized())
424 this->Device->Close();
429 // that's it (we can't remove the event handler like it should be...)
433 //---------------------------------------------------------------------------
434 void wxVTKRenderWindowInteractor::Start()
436 // the interactor cannot control the event loop
437 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
438 "interactor cannot control event loop.");
440 //---------------------------------------------------------------------------
441 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
445 // if the size changed tell render window
446 if ( x != Size[0] || y != Size[1] )
448 // adjust our (vtkRenderWindowInteractor size)
451 // and our RenderWindow's size
456 #endif //VTK_USE_COCOA
458 RenderWindow->SetSize(x, y);
461 #if defined(__WXMSW__)
467 //---------------------------------------------------------------------------
468 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
470 // it's a one shot timer
471 if (!timer.Start(10, TRUE))
477 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
478 //------------------------------------------------------------------
479 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
480 unsigned long duration)
482 if (!timer.Start(duration, timerType == OneShotTimer))
485 return ID_wxVTKRenderWindowInteractor_TIMER;
487 //------------------------------------------------------------------
488 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
494 //---------------------------------------------------------------------------
495 int wxVTKRenderWindowInteractor::DestroyTimer()
500 //---------------------------------------------------------------------------
501 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
506 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
508 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
509 // pass the right timer id
510 int timerId = this->GetCurrentTimerId();
511 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
513 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
517 InteractorStyle->OnTimer();
521 //---------------------------------------------------------------------------
522 // NOTE on implementation:
523 // Bad luck you ended up in the only tricky place of this code.
524 // A few note, wxWidgets still refuse to provide such convenient method
525 // so I have to maintain it myself, eventhough this is completely integrated
527 // Anyway if this happen to break for you then compare to a recent version of wxPython
528 // and look for the function long wxPyGetWinHandle(wxWindow* win)
529 // in wxPython/src/helpers.cpp
530 long wxVTKRenderWindowInteractor::GetHandleHack()
532 //helper function to hide the MSW vs GTK stuff
535 // __WXMSW__ is for Win32
536 // __WXMAC__ is for Carbon or Cocoa builds
537 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
538 #if defined(__WXMSW__) || defined(__WXMAC__)
539 handle_tmp = (long)this->GetHandle();
542 // using above GetHandle() works fine with wxOSX 2.9.x
543 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
544 // Here is how to find the NSWindow
545 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
546 if (toplevel != NULL )
548 handle_tmp = (long)toplevel->GetNSWindow();
550 // The NSView will be deducted from
551 // [(NSWindow*)Handle contentView]
552 // if only I knew how to write that in c++
553 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
555 // Find and return the actual X-Window.
556 #if defined(__WXGTK__) || defined(__WXX11__)
557 return (long)GetXWindow(this);
561 // handle_tmp = (long)this->GetXWindow();
566 //---------------------------------------------------------------------------
567 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
569 //must always be here
576 //do it here rather than in the cstor: this is safer.
579 Handle = GetHandleHack();
582 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
583 NSView *nvsview = (NSView* )Handle;
584 NSWindow *nswindow = nvsview.window;
585 rwin->SetRootWindow( nswindow );
586 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
588 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
592 // this->GetNSView() <-> DisplayId
593 // this->GetTopLevel()->GetNSWindow() <-> WindowId
595 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
598 // This is another hack to prevent the VTK Render Window from closing the display.
599 // If VTK closes the display, ~wxContext chashes while trying to destroy its
600 // glContext (because the display is closed). The Get -> Set makes this VTK
601 // object think someone else is responsible for the display.
603 // avoid "Method not implemented" messages in Console
605 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
608 // get vtk to render to the wxWindows
611 // This solves a problem with repainting after a window resize
612 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
614 #if !wxCHECK_VERSION(2, 9, 0)
615 // this doesn't seem necessary with wxOSX 2.9.x
616 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
619 rwin->UpdateContext();
623 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
626 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
627 // Must be somewhere after VTK 4.4
628 rwin->UpdateGLRegion();
634 //---------------------------------------------------------------------------
635 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
637 //turn off background erase to reduce flickering on MSW
640 //---------------------------------------------------------------------------
641 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
644 GetClientSize(&w, &h);
652 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
653 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
655 //this will check for Handle
658 //---------------------------------------------------------------------------
659 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
665 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
666 SetEventInformationFlipY(event.GetX(), event.GetY(),
667 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
669 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
671 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
672 event.GetX(), Size[1] - event.GetY() - 1);
675 //---------------------------------------------------------------------------
676 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
677 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
684 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
686 SetEventInformationFlipY(event.GetX(), event.GetY(),
687 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
689 InvokeEvent(vtkCommand::EnterEvent, NULL);
692 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
693 event.GetX(), Size[1] - event.GetY() - 1);
696 //---------------------------------------------------------------------------
697 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
704 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
706 SetEventInformationFlipY(event.GetX(), event.GetY(),
707 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
709 InvokeEvent(vtkCommand::LeaveEvent, NULL);
712 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
713 event.GetX(), Size[1] - event.GetY() - 1);
716 //---------------------------------------------------------------------------
717 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
724 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
726 int keycode = event.GetKeyCode();
728 if (((unsigned int)keycode) < 256)
730 // TODO: Unicode in non-Unicode mode ??
734 // we don't get a valid mouse position inside the key event on every platform
735 // so we retrieve the mouse position explicitly and pass it along
736 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
737 SetEventInformationFlipY(mousePos.x, mousePos.y,
738 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
739 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
741 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
742 event.GetKeyCode(), 1);
746 //---------------------------------------------------------------------------
747 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
754 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
756 int keycode = event.GetKeyCode();
758 if (((unsigned int)keycode) < 256)
760 // TODO: Unicode in non-Unicode mode ??
764 // we don't get a valid mouse position inside the key event on every platform
765 // so we retrieve the mouse position explicitly and pass it along
766 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
767 SetEventInformationFlipY(mousePos.x, mousePos.y,
768 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
769 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
771 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
772 event.GetKeyCode(), 1);
776 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
777 //---------------------------------------------------------------------------
778 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
785 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
787 int keycode = event.GetKeyCode();
789 if (((unsigned int)keycode) < 256)
791 // TODO: Unicode in non-Unicode mode ??
795 // we don't get a valid mouse position inside the key event on every platform
796 // so we retrieve the mouse position explicitly and pass it along
797 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
798 SetEventInformationFlipY(mousePos.x, mousePos.y,
799 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
800 InvokeEvent(vtkCommand::CharEvent, NULL);
804 //---------------------------------------------------------------------------
805 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
807 if (!Enabled || (ActiveButton != wxEVT_NULL))
811 ActiveButton = event.GetEventType();
813 // On Mac (Carbon) and Windows we don't automatically get the focus when
814 // you click inside the window
815 // we therefore set the focus explicitly
816 // Apparently we need that on linux (GTK) too:
819 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
820 SetEventInformationFlipY(event.GetX(), event.GetY(),
821 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
824 if(event.RightDown())
826 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
828 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
831 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
832 event.GetX(), Size[1] - event.GetY() - 1);
835 else if(event.LeftDown())
837 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
839 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
842 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
843 event.GetX(), Size[1] - event.GetY() - 1);
846 else if(event.MiddleDown())
848 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
850 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
853 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
854 event.GetX(), Size[1] - event.GetY() - 1);
857 //save the button and capture mouse until the button is released
859 //1. it is possible (WX_USE_X_CAPTURE)
860 //2. user decided to.
861 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
866 //---------------------------------------------------------------------------
867 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
869 //EVT_xxx_DOWN == EVT_xxx_UP - 1
870 //This is only needed if two mouse buttons are pressed at the same time.
871 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
872 //wxEVT_COMMAND_RIGHT_CLICK
873 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
878 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
881 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
882 SetEventInformationFlipY(event.GetX(), event.GetY(),
883 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
886 if(ActiveButton == wxEVT_RIGHT_DOWN)
888 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
890 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
893 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
894 event.GetX(), Size[1] - event.GetY() - 1);
897 else if(ActiveButton == wxEVT_LEFT_DOWN)
899 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
901 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
904 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
905 event.GetX(), Size[1] - event.GetY() - 1);
908 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
910 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
912 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
915 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
916 event.GetX(), Size[1] - event.GetY() - 1);
919 //if the ActiveButton is realeased, then release mouse capture
920 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
924 ActiveButton = wxEVT_NULL;
926 //---------------------------------------------------------------------------
927 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
929 // Mouse wheel was only added after VTK 4.4 (I think...)
930 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
932 //Set vtk event information ... The numebr of wheel rotations is stored in
933 //the x varible. y varible is zero
934 SetEventInformationFlipY(event.GetX() , event.GetY(),
935 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
936 if(event.GetWheelRotation() > 0)
939 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
944 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
950 //---------------------------------------------------------------------------
951 #if wxCHECK_VERSION(2, 8, 0)
952 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
954 if (ActiveButton != wxEVT_NULL)
956 //Maybe also invoke the button release event here
958 // Reset ActiveButton so that
959 // 1. we do not process mouse button up events any more,
960 // 2. the next button down event will be processed and call CaptureMouse().
961 // Otherwise ReleaseMouse() will be called
962 // without a previous CaptureMouse().
963 ActiveButton = wxEVT_NULL;
967 //---------------------------------------------------------------------------
968 void wxVTKRenderWindowInteractor::Render()
970 #if wxCHECK_VERSION(2, 8, 0)
971 int renderAllowed = !IsFrozen();
973 int renderAllowed = 1;
975 if (renderAllowed && !RenderWhenDisabled)
977 //the user doesn't want us to render when the toplevel frame
978 //is disabled - first find the top level parent
979 wxWindow *topParent = wxGetTopLevelParent(this);
982 //if it exists, check whether it's enabled
983 //if it's not enabeld, renderAllowed will be false
984 renderAllowed = topParent->IsEnabled();
990 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
991 wxGLCanvas::SetCurrent(*(this->context));
993 if(Handle && (Handle == GetHandleHack()) )
995 RenderWindow->Render();
997 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
998 else if(GetHandleHack())
1000 //this means the user has reparented us; let's adapt to the
1001 //new situation by doing the WindowRemap dance
1002 //store the new situation
1003 Handle = GetHandleHack();
1004 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
1005 RenderWindow->WindowRemap();
1006 RenderWindow->Render();
1012 //---------------------------------------------------------------------------
1013 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
1015 //Change value of __RenderWhenDisabled ivar.
1016 //If __RenderWhenDisabled is false (the default), this widget will not
1017 //call Render() on the RenderWindow if the top level frame (i.e. the
1018 //containing frame) has been disabled.
1020 //This prevents recursive rendering during wxSafeYield() calls.
1021 //wxSafeYield() can be called during the ProgressMethod() callback of
1022 //a VTK object to have progress bars and other GUI elements updated -
1023 //it does this by disabling all windows (disallowing user-input to
1024 //prevent re-entrancy of code) and then handling all outstanding
1027 //However, this often triggers an OnPaint() method for wxVTKRWIs,
1028 //resulting in a Render(), resulting in Update() being called whilst
1029 //still in progress.
1031 RenderWhenDisabled = (bool)newValue;
1033 //---------------------------------------------------------------------------
1035 // Set the variable that indicates that we want a stereo capable window
1036 // be created. This method can only be called before a window is realized.
1038 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1040 if (Stereo != capable)
1043 RenderWindow->StereoCapableWindowOn();
1044 RenderWindow->SetStereoTypeToCrystalEyes();
1049 //---------------------------------------------------------------------------
1052 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1054 this->Superclass::PrintSelf(os, indent);
1059 // LG : EO namespace bbwxvtk
1060 //=======================================================================