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"
56 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
57 # include "vtkCommand.h"
59 # include "vtkInteractorStyle.h"
61 #include "vtkDebugLeaks.h"
63 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
64 #ifdef __WXOSX_COCOA__
65 #import <Cocoa/Cocoa.h>
69 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
70 // ControlDown has been changed to mean Command key down
71 #define ControlDown RawControlDown
76 #include "vtkCocoaRenderWindow.h"
78 #include "vtkCarbonRenderWindow.h"
84 // #import "vtkTDxMacDevice.h"
85 #import "/Users/davila/Creatis/C11/tpli/include/vtk-8.2/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
111 // This trick is no longer need in VTK CVS, should get rid of that:
114 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
115 #endif //VTK_USE_COCOA
118 #if wxMAJOR_VERSION <= 2
120 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
121 #include "gdk/gdkprivate.h"
122 #if wxCHECK_VERSION(2, 9, 0)
123 // thanks to: http://thomasfischer.biz/?p=382
124 #include <gtk/gtkfixed.h>
125 #include <gtk/gtkwidget.h>
126 #include <wx/gtk/private/win_gtk.h>
127 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
128 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
129 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
130 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
132 #if wxCHECK_VERSION(2, 8, 0)
134 #include <wx/gtk/win_gtk.h>
136 #include <wx/gtk1/win_gtk.h>
139 #include <wx/gtk/win_gtk.h>
142 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
143 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
144 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
150 #include <gdk/gdkx.h>
152 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
153 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
154 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
159 #include "wx/x11/privx.h"
160 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
163 //For more info on this class please go to:
164 //http://wxvtk.sf.net
165 //This hack is for some buggy wxGTK version:
166 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
167 # define WX_USE_X_CAPTURE 0
169 # define WX_USE_X_CAPTURE 1
172 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
174 //=======================================================================
175 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
179 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
183 //---------------------------------------------------------------------------
184 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
185 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
186 #if wxMAJOR_VERSION <= 2
187 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
188 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
190 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
191 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
194 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
195 #if wxMAJOR_VERSION <= 2
196 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
197 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
199 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
200 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
203 //refresh window by doing a Render
204 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
205 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
206 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
208 //Bind the events to the event converters
209 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
210 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
211 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
212 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
213 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
214 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
215 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
216 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
217 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
218 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
219 #if wxCHECK_VERSION(2, 8, 0)
220 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
222 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
223 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
224 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
226 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
227 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
230 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
233 #if VTK_MAJOR_VERSION < 8
234 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
237 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
238 static int wxvtk_attributes[]={
247 //---------------------------------------------------------------------------
248 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
250 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
251 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
252 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
254 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
260 vtkRenderWindowInteractor()
261 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
262 , ActiveButton(wxEVT_NULL)
266 , RenderWhenDisabled(1)
269 #ifdef VTK_DEBUG_LEAKS
270 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
272 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
273 this->context = new wxGLContext(this);
275 this->RenderWindow = NULL;
276 this->SetRenderWindow(vtkRenderWindow::New());
277 this->RenderWindow->Delete();
280 this->Device=vtkTDxMacDevice::New();
285 //---------------------------------------------------------------------------
286 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
291 const wxString &name)
292 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
293 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
294 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
296 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
299 : wxWindow(parent, id, pos, size, style, name)
301 , vtkRenderWindowInteractor()
302 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
303 , ActiveButton(wxEVT_NULL)
307 , RenderWhenDisabled(1)
310 #ifdef VTK_DEBUG_LEAKS
311 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
313 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
314 this->context = new wxGLContext(this);
316 this->RenderWindow = NULL;
317 this->SetRenderWindow(vtkRenderWindow::New());
318 this->RenderWindow->Delete();
320 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
321 // so we update the size information of the interactor/renderwindow here
322 this->UpdateSize(size.x, size.y);
327 this->Device=vtkTDxMacDevice::New();
332 //---------------------------------------------------------------------------
333 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
335 SetRenderWindow(NULL);
336 SetInteractorStyle(NULL);
337 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
338 delete this->context;
342 this->Device->Delete();
346 //---------------------------------------------------------------------------
347 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
349 // we don't make use of the objectfactory, because we're not registered
350 return new wxVTKRenderWindowInteractor;
352 //---------------------------------------------------------------------------
353 void wxVTKRenderWindowInteractor::Initialize()
355 int *size = RenderWindow->GetSize();
356 // enable everything and start rendering
358 //RenderWindow->Start();
360 // set the size in the render window interactor
364 // this is initialized
367 //---------------------------------------------------------------------------
368 void wxVTKRenderWindowInteractor::Enable()
370 // if already enabled then done
376 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
377 wxGLCanvas::SetCurrent(*this->context);
384 this->Device->SetInteractor(this);
385 this->Device->Initialize();
393 //---------------------------------------------------------------------------
394 bool wxVTKRenderWindowInteractor::Enable(bool enable)
400 this->Device->SetInteractor(this);
401 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
421 if(this->Device->GetInitialized())
423 this->Device->Close();
428 // that's it (we can't remove the event handler like it should be...)
432 //---------------------------------------------------------------------------
433 void wxVTKRenderWindowInteractor::Start()
435 // the interactor cannot control the event loop
436 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
437 "interactor cannot control event loop.");
439 //---------------------------------------------------------------------------
440 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
444 // if the size changed tell render window
445 if ( x != Size[0] || y != Size[1] )
447 // adjust our (vtkRenderWindowInteractor size)
450 // and our RenderWindow's size
455 #endif //VTK_USE_COCOA
457 RenderWindow->SetSize(x, y);
460 #if defined(__WXMSW__)
466 //---------------------------------------------------------------------------
467 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
469 // it's a one shot timer
470 if (!timer.Start(10, TRUE))
476 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
477 //------------------------------------------------------------------
478 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
479 unsigned long duration)
481 if (!timer.Start(duration, timerType == OneShotTimer))
484 return ID_wxVTKRenderWindowInteractor_TIMER;
486 //------------------------------------------------------------------
487 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
493 //---------------------------------------------------------------------------
494 int wxVTKRenderWindowInteractor::DestroyTimer()
499 //---------------------------------------------------------------------------
500 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
505 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
507 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
508 // pass the right timer id
509 int timerId = this->GetCurrentTimerId();
510 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
512 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
516 InteractorStyle->OnTimer();
520 //---------------------------------------------------------------------------
521 // NOTE on implementation:
522 // Bad luck you ended up in the only tricky place of this code.
523 // A few note, wxWidgets still refuse to provide such convenient method
524 // so I have to maintain it myself, eventhough this is completely integrated
526 // Anyway if this happen to break for you then compare to a recent version of wxPython
527 // and look for the function long wxPyGetWinHandle(wxWindow* win)
528 // in wxPython/src/helpers.cpp
529 long wxVTKRenderWindowInteractor::GetHandleHack()
531 //helper function to hide the MSW vs GTK stuff
534 // __WXMSW__ is for Win32
535 // __WXMAC__ is for Carbon or Cocoa builds
536 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
537 #if defined(__WXMSW__) || defined(__WXMAC__)
538 handle_tmp = (long)this->GetHandle();
541 // using above GetHandle() works fine with wxOSX 2.9.x
542 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
543 // Here is how to find the NSWindow
544 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
545 if (toplevel != NULL )
547 handle_tmp = (long)toplevel->GetNSWindow();
549 // The NSView will be deducted from
550 // [(NSWindow*)Handle contentView]
551 // if only I knew how to write that in c++
552 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
554 // Find and return the actual X-Window.
555 #if defined(__WXGTK__) || defined(__WXX11__)
556 return (long)GetXWindow(this);
560 // handle_tmp = (long)this->GetXWindow();
565 //---------------------------------------------------------------------------
566 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
568 //must always be here
575 //do it here rather than in the cstor: this is safer.
578 Handle = GetHandleHack();
581 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
582 NSView *nvsview = (NSView* )Handle;
583 NSWindow *nswindow = nvsview.window;
584 rwin->SetRootWindow( nswindow );
585 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
587 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
591 // this->GetNSView() <-> DisplayId
592 // this->GetTopLevel()->GetNSWindow() <-> WindowId
594 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
597 // This is another hack to prevent the VTK Render Window from closing the display.
598 // If VTK closes the display, ~wxContext chashes while trying to destroy its
599 // glContext (because the display is closed). The Get -> Set makes this VTK
600 // object think someone else is responsible for the display.
602 // avoid "Method not implemented" messages in Console
604 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
607 // get vtk to render to the wxWindows
610 // This solves a problem with repainting after a window resize
611 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
613 #if !wxCHECK_VERSION(2, 9, 0)
614 // this doesn't seem necessary with wxOSX 2.9.x
615 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
618 rwin->UpdateContext();
622 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
625 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
626 // Must be somewhere after VTK 4.4
627 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();
986 } // if renderAllowed && !RenderWhenDisabled
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();
1009 } // if renderAllowed
1011 //---------------------------------------------------------------------------
1012 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
1014 //Change value of __RenderWhenDisabled ivar.
1015 //If __RenderWhenDisabled is false (the default), this widget will not
1016 //call Render() on the RenderWindow if the top level frame (i.e. the
1017 //containing frame) has been disabled.
1019 //This prevents recursive rendering during wxSafeYield() calls.
1020 //wxSafeYield() can be called during the ProgressMethod() callback of
1021 //a VTK object to have progress bars and other GUI elements updated -
1022 //it does this by disabling all windows (disallowing user-input to
1023 //prevent re-entrancy of code) and then handling all outstanding
1026 //However, this often triggers an OnPaint() method for wxVTKRWIs,
1027 //resulting in a Render(), resulting in Update() being called whilst
1028 //still in progress.
1030 RenderWhenDisabled = (bool)newValue;
1032 //---------------------------------------------------------------------------
1034 // Set the variable that indicates that we want a stereo capable window
1035 // be created. This method can only be called before a window is realized.
1037 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1039 if (Stereo != capable)
1042 RenderWindow->StereoCapableWindowOn();
1043 RenderWindow->SetStereoTypeToCrystalEyes();
1048 //---------------------------------------------------------------------------
1051 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1053 this->Superclass::PrintSelf(os, indent);
1058 // LG : EO namespace bbwxvtk
1059 //=======================================================================