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 =========================================================================*/
49 #include "creawxVTKRenderWindowInteractor.h"
51 //This is needed for vtk 3.1 :
52 #ifndef VTK_MAJOR_VERSION
53 # 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"
89 //=======================================================================
90 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
95 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
96 #if (!wxCHECK_VERSION(2, 4, 0))
97 wxWindow* wxGetTopLevelParent(wxWindow *win)
99 while ( win && !win->IsTopLevel() )
100 win = win->GetParent();
105 // LG : EO namespace bbwxvtk
106 //=======================================================================
108 // To access objc calls on cocoa
113 // #ifdef VTK_USE_COCOA
114 // // This trick is no longer need in VTK CVS, should get rid of that:
117 // #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
118 // #endif //VTK_USE_COCOA
122 #if wxMAJOR_VERSION <= 2
124 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
125 #include "gdk/gdkprivate.h"
126 #if wxCHECK_VERSION(2, 9, 0)
127 // thanks to: http://thomasfischer.biz/?p=382
128 #include <gtk/gtkfixed.h>
129 #include <gtk/gtkwidget.h>
130 #include <wx/gtk/private/win_gtk.h>
131 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
132 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
133 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
134 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
136 #if wxCHECK_VERSION(2, 8, 0)
138 #include <wx/gtk/win_gtk.h>
140 #include <wx/gtk1/win_gtk.h>
143 #include <wx/gtk/win_gtk.h>
146 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
147 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
148 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
154 #include <gdk/gdkx.h>
156 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
157 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
158 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
163 #include "wx/x11/privx.h"
164 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
167 //For more info on this class please go to:
168 //http://wxvtk.sf.net
169 //This hack is for some buggy wxGTK version:
170 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
171 # define WX_USE_X_CAPTURE 0
173 # define WX_USE_X_CAPTURE 1
176 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
178 //=======================================================================
179 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
183 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
187 //---------------------------------------------------------------------------
188 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
189 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
190 #if wxMAJOR_VERSION <= 2
191 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
192 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
194 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
195 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
198 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
199 #if wxMAJOR_VERSION <= 2
200 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
201 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
203 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
204 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
207 //refresh window by doing a Render
208 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
209 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
210 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
212 //Bind the events to the event converters
213 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
214 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
215 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
216 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
217 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
218 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
219 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
220 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
221 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
222 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
223 #if wxCHECK_VERSION(2, 8, 0)
224 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
226 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
227 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
228 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
230 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
231 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
234 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
237 #if VTK_MAJOR_VERSION < 8
238 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
241 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
242 static int wxvtk_attributes[]={
251 //---------------------------------------------------------------------------
252 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
254 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
255 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
256 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
258 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
264 vtkRenderWindowInteractor()
265 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
266 , ActiveButton(wxEVT_NULL)
270 , RenderWhenDisabled(1)
274 #ifdef VTK_DEBUG_LEAKS
275 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
277 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
278 this->context = new wxGLContext(this);
280 this->RenderWindow = NULL;
281 this->SetRenderWindow(vtkRenderWindow::New());
282 this->RenderWindow->Delete();
285 this->Device=vtkTDxMacDevice::New();
289 //---------------------------------------------------------------------------
290 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
295 const wxString &name)
296 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
297 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
298 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
300 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
303 : wxWindow(parent, id, pos, size, style, name)
305 , vtkRenderWindowInteractor()
306 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
307 , ActiveButton(wxEVT_NULL)
311 , RenderWhenDisabled(1)
315 #ifdef VTK_DEBUG_LEAKS
316 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
318 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
319 this->context = new wxGLContext(this);
321 this->RenderWindow = NULL;
322 this->SetRenderWindow(vtkRenderWindow::New());
323 this->RenderWindow->Delete();
325 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
326 // so we update the size information of the interactor/renderwindow here
327 this->UpdateSize(size.x, size.y);
332 this->Device=vtkTDxMacDevice::New();
337 //---------------------------------------------------------------------------
338 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
340 SetRenderWindow(NULL);
341 SetInteractorStyle(NULL);
342 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
343 delete this->context;
347 this->Device->Delete();
351 //---------------------------------------------------------------------------
352 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
354 // we don't make use of the objectfactory, because we're not registered
355 return new wxVTKRenderWindowInteractor;
358 //---------------------------------------------------------------------------
359 void wxVTKRenderWindowInteractor::Initialize()
361 int *size = RenderWindow->GetSize();
362 // enable everything and start rendering
364 //RenderWindow->Start();
365 // set the size in the render window interactor
368 // this is initialized
371 //---------------------------------------------------------------------------
372 void wxVTKRenderWindowInteractor::Enable()
374 // if already enabled then done
380 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
381 wxGLCanvas::SetCurrent(*this->context);
388 this->Device->SetInteractor(this);
389 this->Device->Initialize();
396 //---------------------------------------------------------------------------
397 bool wxVTKRenderWindowInteractor::Enable(bool enable)
402 this->Device->SetInteractor(this);
403 this->Device->Initialize();
407 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
408 return wxGLCanvas::Enable(enable);
410 return wxWindow::Enable(enable);
413 //---------------------------------------------------------------------------
414 void wxVTKRenderWindowInteractor::Disable()
416 // 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
454 // #ifdef VTK_USE_COCOA
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))
478 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
479 //------------------------------------------------------------------
480 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
481 unsigned long duration)
483 if (!timer.Start(duration, timerType == OneShotTimer))
487 return ID_wxVTKRenderWindowInteractor_TIMER;
489 //------------------------------------------------------------------
490 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
497 //---------------------------------------------------------------------------
498 int wxVTKRenderWindowInteractor::DestroyTimer()
504 //---------------------------------------------------------------------------
505 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
510 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
512 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
513 // pass the right timer id
514 int timerId = this->GetCurrentTimerId();
515 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
517 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
521 InteractorStyle->OnTimer();
525 //---------------------------------------------------------------------------
526 // NOTE on implementation:
527 // Bad luck you ended up in the only tricky place of this code.
528 // A few note, wxWidgets still refuse to provide such convenient method
529 // so I have to maintain it myself, eventhough this is completely integrated
531 // Anyway if this happen to break for you then compare to a recent version of wxPython
532 // and look for the function long wxPyGetWinHandle(wxWindow* win)
533 // in wxPython/src/helpers.cpp
534 long wxVTKRenderWindowInteractor::GetHandleHack()
536 //helper function to hide the MSW vs GTK stuff
539 // __WXMSW__ is for Win32
540 // __WXMAC__ is for Carbon or Cocoa builds
541 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
542 #if defined(__WXMSW__) || defined(__WXMAC__)
543 handle_tmp = (long)this->GetHandle();
546 // using above GetHandle() works fine with wxOSX 2.9.x
547 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
548 // Here is how to find the NSWindow
549 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
550 if (toplevel != NULL )
552 handle_tmp = (long)toplevel->GetNSWindow();
554 // The NSView will be deducted from
555 // [(NSWindow*)Handle contentView]
556 // if only I knew how to write that in c++
557 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
559 // Find and return the actual X-Window.
560 #if defined(__WXGTK__) || defined(__WXX11__)
561 return (long)GetXWindow(this);
565 // handle_tmp = (long)this->GetXWindow();
570 //---------------------------------------------------------------------------
571 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
573 //must always be here
580 //do it here rather than in the cstor: this is safer.
583 Handle = GetHandleHack();
586 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
587 NSView *nvsview = (NSView* )Handle;
588 NSWindow *nswindow = nvsview.window;
589 rwin->SetRootWindow( nswindow );
590 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
592 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
596 // this->GetNSView() <-> DisplayId
597 // this->GetTopLevel()->GetNSWindow() <-> WindowId
599 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
602 // This is another hack to prevent the VTK Render Window from closing the display.
603 // If VTK closes the display, ~wxContext chashes while trying to destroy its
604 // glContext (because the display is closed). The Get -> Set makes this VTK
605 // object think someone else is responsible for the display.
607 // avoid "Method not implemented" messages in Console
609 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
612 // get vtk to render to the wxWindows
615 // This solves a problem with repainting after a window resize
616 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
618 #if !wxCHECK_VERSION(2, 9, 0)
619 // this doesn't seem necessary with wxOSX 2.9.x
620 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
623 rwin->UpdateContext();
627 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
630 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
631 // Must be somewhere after VTK 4.4
632 rwin->UpdateGLRegion();
639 //---------------------------------------------------------------------------
640 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
642 //turn off background erase to reduce flickering on MSW
645 //---------------------------------------------------------------------------
646 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
649 GetClientSize(&w, &h);
657 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
658 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
660 //this will check for Handle
663 //---------------------------------------------------------------------------
664 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
670 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
671 SetEventInformationFlipY(event.GetX(), event.GetY(),
672 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
674 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
676 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
677 event.GetX(), Size[1] - event.GetY() - 1);
680 //---------------------------------------------------------------------------
681 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
682 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
689 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
691 SetEventInformationFlipY(event.GetX(), event.GetY(),
692 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
694 InvokeEvent(vtkCommand::EnterEvent, NULL);
697 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
698 event.GetX(), Size[1] - event.GetY() - 1);
701 //---------------------------------------------------------------------------
702 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
709 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
711 SetEventInformationFlipY(event.GetX(), event.GetY(),
712 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
714 InvokeEvent(vtkCommand::LeaveEvent, NULL);
717 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
718 event.GetX(), Size[1] - event.GetY() - 1);
721 //---------------------------------------------------------------------------
722 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
729 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
731 int keycode = event.GetKeyCode();
733 if (((unsigned int)keycode) < 256)
735 // TODO: Unicode in non-Unicode mode ??
739 // we don't get a valid mouse position inside the key event on every platform
740 // so we retrieve the mouse position explicitly and pass it along
741 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
742 SetEventInformationFlipY(mousePos.x, mousePos.y,
743 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
744 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
746 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
747 event.GetKeyCode(), 1);
751 //---------------------------------------------------------------------------
752 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
759 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
761 int keycode = event.GetKeyCode();
763 if (((unsigned int)keycode) < 256)
765 // TODO: Unicode in non-Unicode mode ??
769 // we don't get a valid mouse position inside the key event on every platform
770 // so we retrieve the mouse position explicitly and pass it along
771 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
772 SetEventInformationFlipY(mousePos.x, mousePos.y,
773 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
774 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
776 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
777 event.GetKeyCode(), 1);
781 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
782 //---------------------------------------------------------------------------
783 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
790 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
792 int keycode = event.GetKeyCode();
794 if (((unsigned int)keycode) < 256)
796 // TODO: Unicode in non-Unicode mode ??
800 // we don't get a valid mouse position inside the key event on every platform
801 // so we retrieve the mouse position explicitly and pass it along
802 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
803 SetEventInformationFlipY(mousePos.x, mousePos.y,
804 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
805 InvokeEvent(vtkCommand::CharEvent, NULL);
809 //---------------------------------------------------------------------------
810 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
812 if (!Enabled || (ActiveButton != wxEVT_NULL))
816 ActiveButton = event.GetEventType();
818 // On Mac (Carbon) and Windows we don't automatically get the focus when
819 // you click inside the window
820 // we therefore set the focus explicitly
821 // Apparently we need that on linux (GTK) too:
824 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
825 SetEventInformationFlipY(event.GetX(), event.GetY(),
826 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
829 if(event.RightDown())
831 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
833 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
836 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
837 event.GetX(), Size[1] - event.GetY() - 1);
840 else if(event.LeftDown())
842 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
844 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
847 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
848 event.GetX(), Size[1] - event.GetY() - 1);
851 else if(event.MiddleDown())
853 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
855 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
858 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
859 event.GetX(), Size[1] - event.GetY() - 1);
862 //save the button and capture mouse until the button is released
864 //1. it is possible (WX_USE_X_CAPTURE)
865 //2. user decided to.
866 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
871 //---------------------------------------------------------------------------
872 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
874 //EVT_xxx_DOWN == EVT_xxx_UP - 1
875 //This is only needed if two mouse buttons are pressed at the same time.
876 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
877 //wxEVT_COMMAND_RIGHT_CLICK
878 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
883 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
886 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
887 SetEventInformationFlipY(event.GetX(), event.GetY(),
888 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
891 if(ActiveButton == wxEVT_RIGHT_DOWN)
893 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
895 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
898 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
899 event.GetX(), Size[1] - event.GetY() - 1);
902 else if(ActiveButton == wxEVT_LEFT_DOWN)
904 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
906 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
909 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
910 event.GetX(), Size[1] - event.GetY() - 1);
913 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
915 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
917 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
920 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
921 event.GetX(), Size[1] - event.GetY() - 1);
924 //if the ActiveButton is realeased, then release mouse capture
925 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
929 ActiveButton = wxEVT_NULL;
931 //---------------------------------------------------------------------------
932 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
934 // Mouse wheel was only added after VTK 4.4 (I think...)
935 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
937 //Set vtk event information ... The numebr of wheel rotations is stored in
938 //the x varible. y varible is zero
939 SetEventInformationFlipY(event.GetX() , event.GetY(),
940 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
941 if(event.GetWheelRotation() > 0)
944 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
949 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
955 //---------------------------------------------------------------------------
956 #if wxCHECK_VERSION(2, 8, 0)
957 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
959 if (ActiveButton != wxEVT_NULL)
961 //Maybe also invoke the button release event here
963 // Reset ActiveButton so that
964 // 1. we do not process mouse button up events any more,
965 // 2. the next button down event will be processed and call CaptureMouse().
966 // Otherwise ReleaseMouse() will be called
967 // without a previous CaptureMouse().
968 ActiveButton = wxEVT_NULL;
972 //---------------------------------------------------------------------------
973 void wxVTKRenderWindowInteractor::Render()
975 #if wxCHECK_VERSION(2, 8, 0)
976 int renderAllowed = !IsFrozen();
978 int renderAllowed = 1;
980 if (renderAllowed && !RenderWhenDisabled)
982 //the user doesn't want us to render when the toplevel frame
983 //is disabled - first find the top level parent
984 wxWindow *topParent = wxGetTopLevelParent(this);
987 //if it exists, check whether it's enabled
988 //if it's not enabeld, renderAllowed will be false
989 renderAllowed = topParent->IsEnabled();
991 } // if renderAllowed && !RenderWhenDisabled
995 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
996 wxGLCanvas::SetCurrent(*(this->context));
998 if(Handle && (Handle == GetHandleHack()) )
1000 RenderWindow->Render();
1002 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
1003 else if(GetHandleHack())
1005 //this means the user has reparented us; let's adapt to the
1006 //new situation by doing the WindowRemap dance
1007 //store the new situation
1008 Handle = GetHandleHack();
1009 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
1010 RenderWindow->WindowRemap();
1011 RenderWindow->Render();
1014 } // if renderAllowed
1016 //---------------------------------------------------------------------------
1017 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
1019 //Change value of __RenderWhenDisabled ivar.
1020 //If __RenderWhenDisabled is false (the default), this widget will not
1021 //call Render() on the RenderWindow if the top level frame (i.e. the
1022 //containing frame) has been disabled.
1024 //This prevents recursive rendering during wxSafeYield() calls.
1025 //wxSafeYield() can be called during the ProgressMethod() callback of
1026 //a VTK object to have progress bars and other GUI elements updated -
1027 //it does this by disabling all windows (disallowing user-input to
1028 //prevent re-entrancy of code) and then handling all outstanding
1031 //However, this often triggers an OnPaint() method for wxVTKRWIs,
1032 //resulting in a Render(), resulting in Update() being called whilst
1033 //still in progress.
1035 RenderWhenDisabled = (bool)newValue;
1037 //---------------------------------------------------------------------------
1039 // Set the variable that indicates that we want a stereo capable window
1040 // be created. This method can only be called before a window is realized.
1042 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1044 if (Stereo != capable)
1047 RenderWindow->StereoCapableWindowOn();
1048 RenderWindow->SetStereoTypeToCrystalEyes();
1053 //---------------------------------------------------------------------------
1056 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1058 this->Superclass::PrintSelf(os, indent);
1063 // LG : EO namespace bbwxvtk
1064 //=======================================================================