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 =========================================================================*/
48 #include "creawxVTKRenderWindowInteractor.h"
50 //This is needed for vtk 3.1 :
51 #ifndef VTK_MAJOR_VERSION
52 # include "vtkVersion.h"
55 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
56 # include "vtkCommand.h"
58 # include "vtkInteractorStyle.h"
60 #include "vtkDebugLeaks.h"
62 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
63 #ifdef __WXOSX_COCOA__
67 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
68 // ControlDown has been changed to mean Command key down
69 #define ControlDown RawControlDown
74 #include "vtkCocoaRenderWindow.h"
76 #include "vtkCarbonRenderWindow.h"
80 //=======================================================================
81 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
86 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
87 #if (!wxCHECK_VERSION(2, 4, 0))
88 wxWindow* wxGetTopLevelParent(wxWindow *win)
90 while ( win && !win->IsTopLevel() )
91 win = win->GetParent();
96 // LG : EO namespace bbwxvtk
97 //=======================================================================
99 // To access objc calls on cocoa
102 #import <Cocoa/Cocoa.h>
103 // This trick is no longer need in VTK CVS, should get rid of that:
106 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
107 #endif //VTK_USE_COCOA
110 #if wxMAJOR_VERSION <= 2
113 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
114 #include "gdk/gdkprivate.h"
115 #if wxCHECK_VERSION(2, 9, 0)
116 // thanks to: http://thomasfischer.biz/?p=382
117 #include <gtk/gtkfixed.h>
118 #include <gtk/gtkwidget.h>
119 #include <wx/gtk/private/win_gtk.h>
120 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
121 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
122 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
123 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
125 #if wxCHECK_VERSION(2, 8, 0)
127 #include <wx/gtk/win_gtk.h>
129 #include <wx/gtk1/win_gtk.h>
132 #include <wx/gtk/win_gtk.h>
135 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
136 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
137 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
143 #include <gdk/gdkx.h>
145 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
146 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
147 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
152 #include "wx/x11/privx.h"
153 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
156 //For more info on this class please go to:
157 //http://wxvtk.sf.net
158 //This hack is for some buggy wxGTK version:
159 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
160 # define WX_USE_X_CAPTURE 0
162 # define WX_USE_X_CAPTURE 1
165 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
167 //=======================================================================
168 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
172 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
176 //---------------------------------------------------------------------------
177 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
178 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
179 #if wxMAJOR_VERSION <= 2
180 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
181 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
183 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
184 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
187 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
188 #if wxMAJOR_VERSION <= 2
189 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
190 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
192 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
193 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
196 //refresh window by doing a Render
197 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
198 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
199 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
201 //Bind the events to the event converters
202 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
203 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
204 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
205 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
206 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
207 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
208 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
209 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
210 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
211 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
212 #if wxCHECK_VERSION(2, 8, 0)
213 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
215 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
216 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
217 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
219 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
220 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
223 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
224 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
226 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
227 static int wxvtk_attributes[]={
236 //---------------------------------------------------------------------------
237 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
239 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
240 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
241 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
243 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
249 vtkRenderWindowInteractor()
250 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
251 , ActiveButton(wxEVT_NULL)
255 , RenderWhenDisabled(1)
258 #ifdef VTK_DEBUG_LEAKS
259 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
261 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
262 this->context = new wxGLContext(this);
264 this->RenderWindow = NULL;
265 this->SetRenderWindow(vtkRenderWindow::New());
266 this->RenderWindow->Delete();
268 //---------------------------------------------------------------------------
269 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
274 const wxString &name)
275 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
276 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
277 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
279 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
282 : wxWindow(parent, id, pos, size, style, name)
284 , vtkRenderWindowInteractor()
285 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
286 , ActiveButton(wxEVT_NULL)
290 , RenderWhenDisabled(1)
293 #ifdef VTK_DEBUG_LEAKS
294 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
296 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
297 this->context = new wxGLContext(this);
299 this->RenderWindow = NULL;
300 this->SetRenderWindow(vtkRenderWindow::New());
301 this->RenderWindow->Delete();
303 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
304 // so we update the size information of the interactor/renderwindow here
305 this->UpdateSize(size.x, size.y);
308 //---------------------------------------------------------------------------
309 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
311 SetRenderWindow(NULL);
312 SetInteractorStyle(NULL);
313 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
314 delete this->context;
317 //---------------------------------------------------------------------------
318 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
320 // we don't make use of the objectfactory, because we're not registered
321 return new wxVTKRenderWindowInteractor;
323 //---------------------------------------------------------------------------
324 void wxVTKRenderWindowInteractor::Initialize()
326 int *size = RenderWindow->GetSize();
327 // enable everything and start rendering
329 //RenderWindow->Start();
331 // set the size in the render window interactor
335 // this is initialized
338 //---------------------------------------------------------------------------
339 void wxVTKRenderWindowInteractor::Enable()
341 // if already enabled then done
347 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
348 wxGLCanvas::SetCurrent(*this->context);
352 //---------------------------------------------------------------------------
353 bool wxVTKRenderWindowInteractor::Enable(bool enable)
355 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
356 return wxGLCanvas::Enable(enable);
358 return wxWindow::Enable(enable);
361 //---------------------------------------------------------------------------
362 void wxVTKRenderWindowInteractor::Disable()
364 // if already disabled then done
368 // that's it (we can't remove the event handler like it should be...)
372 //---------------------------------------------------------------------------
373 void wxVTKRenderWindowInteractor::Start()
375 // the interactor cannot control the event loop
376 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
377 "interactor cannot control event loop.");
379 //---------------------------------------------------------------------------
380 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
384 // if the size changed tell render window
385 if ( x != Size[0] || y != Size[1] )
387 // adjust our (vtkRenderWindowInteractor size)
390 // and our RenderWindow's size
391 RenderWindow->SetSize(x, y);
392 #if defined(__WXMSW__)
398 //---------------------------------------------------------------------------
399 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
401 // it's a one shot timer
402 if (!timer.Start(10, TRUE))
408 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
409 //------------------------------------------------------------------
410 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
411 unsigned long duration)
413 if (!timer.Start(duration, timerType == OneShotTimer))
416 return ID_wxVTKRenderWindowInteractor_TIMER;
418 //------------------------------------------------------------------
419 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
425 //---------------------------------------------------------------------------
426 int wxVTKRenderWindowInteractor::DestroyTimer()
431 //---------------------------------------------------------------------------
432 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
437 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
439 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
440 // pass the right timer id
441 int timerId = this->GetCurrentTimerId();
442 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
444 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
448 InteractorStyle->OnTimer();
452 //---------------------------------------------------------------------------
453 // NOTE on implementation:
454 // Bad luck you ended up in the only tricky place of this code.
455 // A few note, wxWidgets still refuse to provide such convenient method
456 // so I have to maintain it myself, eventhough this is completely integrated
458 // Anyway if this happen to break for you then compare to a recent version of wxPython
459 // and look for the function long wxPyGetWinHandle(wxWindow* win)
460 // in wxPython/src/helpers.cpp
461 long wxVTKRenderWindowInteractor::GetHandleHack()
463 //helper function to hide the MSW vs GTK stuff
464 long int handle_tmp = 0;
466 // __WXMSW__ is for Win32
467 // __WXMAC__ is for Carbon or Cocoa builds
468 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
469 #if defined(__WXMSW__) || defined(__WXMAC__)
471 // handle_tmp = (long)this->GetHandle();
472 handle_tmp = (long long)this->GetHandle();
475 // using above GetHandle() works fine with wxOSX 2.9.x
476 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
477 // Here is how to find the NSWindow
478 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
479 if (toplevel != NULL )
481 handle_tmp = (long)toplevel->GetNSWindow();
483 // The NSView will be deducted from
484 // [(NSWindow*)Handle contentView]
485 // if only I knew how to write that in c++
486 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
488 // Find and return the actual X-Window.
489 #if defined(__WXGTK__) || defined(__WXX11__)
490 return (long)GetXWindow(this);
494 // handle_tmp = (long)this->GetXWindow();
499 //---------------------------------------------------------------------------
500 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
502 //must always be here
505 //do it here rather than in the cstor: this is safer.
507 Handle = GetHandleHack();
509 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
512 // this->GetNSView() <-> DisplayId
513 // this->GetTopLevel()->GetNSWindow() <-> WindowId
515 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
518 // This is another hack to prevent the VTK Render Window from closing the display.
519 // If VTK closes the display, ~wxContext chashes while trying to destroy its
520 // glContext (because the display is closed). The Get -> Set makes this VTK
521 // object think someone else is responsible for the display.
523 // avoid "Method not implemented" messages in Console
525 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
528 // get vtk to render to the wxWindows
531 // This solves a problem with repainting after a window resize
532 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
534 #if !wxCHECK_VERSION(2, 9, 0)
535 // this doesn't seem necessary with wxOSX 2.9.x
536 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
539 rwin->UpdateContext();
543 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
546 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
547 // Must be somewhere after VTK 4.4
548 rwin->UpdateGLRegion();
554 //---------------------------------------------------------------------------
555 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
557 //turn off background erase to reduce flickering on MSW
560 //---------------------------------------------------------------------------
561 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
564 GetClientSize(&w, &h);
572 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
573 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
575 //this will check for Handle
578 //---------------------------------------------------------------------------
579 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
585 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
586 SetEventInformationFlipY(event.GetX(), event.GetY(),
587 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
589 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
591 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
592 event.GetX(), Size[1] - event.GetY() - 1);
595 //---------------------------------------------------------------------------
596 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
597 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
604 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
606 SetEventInformationFlipY(event.GetX(), event.GetY(),
607 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
609 InvokeEvent(vtkCommand::EnterEvent, NULL);
612 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
613 event.GetX(), Size[1] - event.GetY() - 1);
616 //---------------------------------------------------------------------------
617 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
624 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
626 SetEventInformationFlipY(event.GetX(), event.GetY(),
627 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
629 InvokeEvent(vtkCommand::LeaveEvent, NULL);
632 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
633 event.GetX(), Size[1] - event.GetY() - 1);
636 //---------------------------------------------------------------------------
637 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
644 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
646 int keycode = event.GetKeyCode();
648 if (((unsigned int)keycode) < 256)
650 // TODO: Unicode in non-Unicode mode ??
654 // we don't get a valid mouse position inside the key event on every platform
655 // so we retrieve the mouse position explicitly and pass it along
656 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
657 SetEventInformationFlipY(mousePos.x, mousePos.y,
658 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
659 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
661 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
662 event.GetKeyCode(), 1);
666 //---------------------------------------------------------------------------
667 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
674 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
676 int keycode = event.GetKeyCode();
678 if (((unsigned int)keycode) < 256)
680 // TODO: Unicode in non-Unicode mode ??
684 // we don't get a valid mouse position inside the key event on every platform
685 // so we retrieve the mouse position explicitly and pass it along
686 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
687 SetEventInformationFlipY(mousePos.x, mousePos.y,
688 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
689 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
691 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
692 event.GetKeyCode(), 1);
696 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
697 //---------------------------------------------------------------------------
698 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
705 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
707 int keycode = event.GetKeyCode();
709 if (((unsigned int)keycode) < 256)
711 // TODO: Unicode in non-Unicode mode ??
715 // we don't get a valid mouse position inside the key event on every platform
716 // so we retrieve the mouse position explicitly and pass it along
717 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
718 SetEventInformationFlipY(mousePos.x, mousePos.y,
719 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
720 InvokeEvent(vtkCommand::CharEvent, NULL);
724 //---------------------------------------------------------------------------
725 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
727 if (!Enabled || (ActiveButton != wxEVT_NULL))
731 ActiveButton = event.GetEventType();
733 // On Mac (Carbon) and Windows we don't automatically get the focus when
734 // you click inside the window
735 // we therefore set the focus explicitly
736 // Apparently we need that on linux (GTK) too:
739 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
740 SetEventInformationFlipY(event.GetX(), event.GetY(),
741 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
744 if(event.RightDown())
746 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
748 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
751 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
752 event.GetX(), Size[1] - event.GetY() - 1);
755 else if(event.LeftDown())
757 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
759 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
762 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
763 event.GetX(), Size[1] - event.GetY() - 1);
766 else if(event.MiddleDown())
768 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
770 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
773 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
774 event.GetX(), Size[1] - event.GetY() - 1);
777 //save the button and capture mouse until the button is released
779 //1. it is possible (WX_USE_X_CAPTURE)
780 //2. user decided to.
781 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
786 //---------------------------------------------------------------------------
787 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
789 //EVT_xxx_DOWN == EVT_xxx_UP - 1
790 //This is only needed if two mouse buttons are pressed at the same time.
791 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
792 //wxEVT_COMMAND_RIGHT_CLICK
793 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
798 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
801 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
802 SetEventInformationFlipY(event.GetX(), event.GetY(),
803 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
806 if(ActiveButton == wxEVT_RIGHT_DOWN)
808 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
810 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
813 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
814 event.GetX(), Size[1] - event.GetY() - 1);
817 else if(ActiveButton == wxEVT_LEFT_DOWN)
819 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
821 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
824 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
825 event.GetX(), Size[1] - event.GetY() - 1);
828 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
830 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
832 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
835 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
836 event.GetX(), Size[1] - event.GetY() - 1);
839 //if the ActiveButton is realeased, then release mouse capture
840 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
844 ActiveButton = wxEVT_NULL;
846 //---------------------------------------------------------------------------
847 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
849 // Mouse wheel was only added after VTK 4.4 (I think...)
850 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
852 //Set vtk event information ... The numebr of wheel rotations is stored in
853 //the x varible. y varible is zero
854 SetEventInformationFlipY(event.GetX() , event.GetY(),
855 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
856 if(event.GetWheelRotation() > 0)
859 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
864 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
870 //---------------------------------------------------------------------------
871 #if wxCHECK_VERSION(2, 8, 0)
872 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
874 if (ActiveButton != wxEVT_NULL)
876 //Maybe also invoke the button release event here
878 // Reset ActiveButton so that
879 // 1. we do not process mouse button up events any more,
880 // 2. the next button down event will be processed and call CaptureMouse().
881 // Otherwise ReleaseMouse() will be called
882 // without a previous CaptureMouse().
883 ActiveButton = wxEVT_NULL;
887 //---------------------------------------------------------------------------
888 void wxVTKRenderWindowInteractor::Render()
890 #if wxCHECK_VERSION(2, 8, 0)
891 int renderAllowed = !IsFrozen();
893 int renderAllowed = 1;
895 if (renderAllowed && !RenderWhenDisabled)
897 //the user doesn't want us to render when the toplevel frame
898 //is disabled - first find the top level parent
899 wxWindow *topParent = wxGetTopLevelParent(this);
902 //if it exists, check whether it's enabled
903 //if it's not enabeld, renderAllowed will be false
904 renderAllowed = topParent->IsEnabled();
910 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
911 wxGLCanvas::SetCurrent(*(this->context));
913 if(Handle && (Handle == GetHandleHack()) )
915 RenderWindow->Render();
917 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
918 else if(GetHandleHack())
920 //this means the user has reparented us; let's adapt to the
921 //new situation by doing the WindowRemap dance
922 //store the new situation
923 Handle = GetHandleHack();
924 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
925 RenderWindow->WindowRemap();
926 RenderWindow->Render();
931 //---------------------------------------------------------------------------
932 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
934 //Change value of __RenderWhenDisabled ivar.
935 //If __RenderWhenDisabled is false (the default), this widget will not
936 //call Render() on the RenderWindow if the top level frame (i.e. the
937 //containing frame) has been disabled.
939 //This prevents recursive rendering during wxSafeYield() calls.
940 //wxSafeYield() can be called during the ProgressMethod() callback of
941 //a VTK object to have progress bars and other GUI elements updated -
942 //it does this by disabling all windows (disallowing user-input to
943 //prevent re-entrancy of code) and then handling all outstanding
946 //However, this often triggers an OnPaint() method for wxVTKRWIs,
947 //resulting in a Render(), resulting in Update() being called whilst
950 RenderWhenDisabled = (bool)newValue;
952 //---------------------------------------------------------------------------
954 // Set the variable that indicates that we want a stereo capable window
955 // be created. This method can only be called before a window is realized.
957 void wxVTKRenderWindowInteractor::SetStereo(int capable)
959 if (Stereo != capable)
962 RenderWindow->StereoCapableWindowOn();
963 RenderWindow->SetStereoTypeToCrystalEyes();
968 //---------------------------------------------------------------------------
971 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
973 this->Superclass::PrintSelf(os, indent);
978 // LG : EO namespace bbwxvtk
979 //=======================================================================