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
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__)
470 handle_tmp = (long)this->GetHandle();
473 // using above GetHandle() works fine with wxOSX 2.9.x
474 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
475 // Here is how to find the NSWindow
476 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
477 if (toplevel != NULL )
479 handle_tmp = (long)toplevel->GetNSWindow();
481 // The NSView will be deducted from
482 // [(NSWindow*)Handle contentView]
483 // if only I knew how to write that in c++
484 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
486 // Find and return the actual X-Window.
487 #if defined(__WXGTK__) || defined(__WXX11__)
488 return (long)GetXWindow(this);
492 // handle_tmp = (long)this->GetXWindow();
497 //---------------------------------------------------------------------------
498 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
500 //must always be here
503 //do it here rather than in the cstor: this is safer.
506 Handle = GetHandleHack();
507 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
509 // this->GetNSView() <-> DisplayId
510 // this->GetTopLevel()->GetNSWindow() <-> WindowId
512 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
515 // This is another hack to prevent the VTK Render Window from closing the display.
516 // If VTK closes the display, ~wxContext chashes while trying to destroy its
517 // glContext (because the display is closed). The Get -> Set makes this VTK
518 // object think someone else is responsible for the display.
520 // avoid "Method not implemented" messages in Console
522 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
525 // get vtk to render to the wxWindows
528 // This solves a problem with repainting after a window resize
529 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
531 #if !wxCHECK_VERSION(2, 9, 0)
532 // this doesn't seem necessary with wxOSX 2.9.x
533 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
536 rwin->UpdateContext();
540 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
543 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
544 // Must be somewhere after VTK 4.4
545 rwin->UpdateGLRegion();
551 //---------------------------------------------------------------------------
552 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
554 //turn off background erase to reduce flickering on MSW
557 //---------------------------------------------------------------------------
558 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
561 GetClientSize(&w, &h);
569 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
570 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
572 //this will check for Handle
575 //---------------------------------------------------------------------------
576 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
582 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
583 SetEventInformationFlipY(event.GetX(), event.GetY(),
584 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
586 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
588 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
589 event.GetX(), Size[1] - event.GetY() - 1);
592 //---------------------------------------------------------------------------
593 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
594 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
601 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
603 SetEventInformationFlipY(event.GetX(), event.GetY(),
604 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
606 InvokeEvent(vtkCommand::EnterEvent, NULL);
609 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
610 event.GetX(), Size[1] - event.GetY() - 1);
613 //---------------------------------------------------------------------------
614 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
621 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
623 SetEventInformationFlipY(event.GetX(), event.GetY(),
624 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
626 InvokeEvent(vtkCommand::LeaveEvent, NULL);
629 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
630 event.GetX(), Size[1] - event.GetY() - 1);
633 //---------------------------------------------------------------------------
634 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
641 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
643 int keycode = event.GetKeyCode();
645 if (((unsigned int)keycode) < 256)
647 // TODO: Unicode in non-Unicode mode ??
651 // we don't get a valid mouse position inside the key event on every platform
652 // so we retrieve the mouse position explicitly and pass it along
653 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
654 SetEventInformationFlipY(mousePos.x, mousePos.y,
655 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
656 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
658 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
659 event.GetKeyCode(), 1);
663 //---------------------------------------------------------------------------
664 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
671 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
673 int keycode = event.GetKeyCode();
675 if (((unsigned int)keycode) < 256)
677 // TODO: Unicode in non-Unicode mode ??
681 // we don't get a valid mouse position inside the key event on every platform
682 // so we retrieve the mouse position explicitly and pass it along
683 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
684 SetEventInformationFlipY(mousePos.x, mousePos.y,
685 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
686 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
688 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
689 event.GetKeyCode(), 1);
693 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
694 //---------------------------------------------------------------------------
695 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
702 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
704 int keycode = event.GetKeyCode();
706 if (((unsigned int)keycode) < 256)
708 // TODO: Unicode in non-Unicode mode ??
712 // we don't get a valid mouse position inside the key event on every platform
713 // so we retrieve the mouse position explicitly and pass it along
714 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
715 SetEventInformationFlipY(mousePos.x, mousePos.y,
716 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
717 InvokeEvent(vtkCommand::CharEvent, NULL);
721 //---------------------------------------------------------------------------
722 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
724 if (!Enabled || (ActiveButton != wxEVT_NULL))
728 ActiveButton = event.GetEventType();
730 // On Mac (Carbon) and Windows we don't automatically get the focus when
731 // you click inside the window
732 // we therefore set the focus explicitly
733 // Apparently we need that on linux (GTK) too:
736 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
737 SetEventInformationFlipY(event.GetX(), event.GetY(),
738 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
741 if(event.RightDown())
743 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
745 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
748 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
749 event.GetX(), Size[1] - event.GetY() - 1);
752 else if(event.LeftDown())
754 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
756 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
759 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
760 event.GetX(), Size[1] - event.GetY() - 1);
763 else if(event.MiddleDown())
765 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
767 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
770 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
771 event.GetX(), Size[1] - event.GetY() - 1);
774 //save the button and capture mouse until the button is released
776 //1. it is possible (WX_USE_X_CAPTURE)
777 //2. user decided to.
778 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
783 //---------------------------------------------------------------------------
784 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
786 //EVT_xxx_DOWN == EVT_xxx_UP - 1
787 //This is only needed if two mouse buttons are pressed at the same time.
788 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
789 //wxEVT_COMMAND_RIGHT_CLICK
790 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
795 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
798 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
799 SetEventInformationFlipY(event.GetX(), event.GetY(),
800 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
803 if(ActiveButton == wxEVT_RIGHT_DOWN)
805 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
807 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
810 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
811 event.GetX(), Size[1] - event.GetY() - 1);
814 else if(ActiveButton == wxEVT_LEFT_DOWN)
816 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
818 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
821 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
822 event.GetX(), Size[1] - event.GetY() - 1);
825 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
827 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
829 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
832 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
833 event.GetX(), Size[1] - event.GetY() - 1);
836 //if the ActiveButton is realeased, then release mouse capture
837 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
841 ActiveButton = wxEVT_NULL;
843 //---------------------------------------------------------------------------
844 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
846 // Mouse wheel was only added after VTK 4.4 (I think...)
847 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
849 //Set vtk event information ... The numebr of wheel rotations is stored in
850 //the x varible. y varible is zero
851 SetEventInformationFlipY(event.GetX() , event.GetY(),
852 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
853 if(event.GetWheelRotation() > 0)
856 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
861 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
867 //---------------------------------------------------------------------------
868 #if wxCHECK_VERSION(2, 8, 0)
869 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
871 if (ActiveButton != wxEVT_NULL)
873 //Maybe also invoke the button release event here
875 // Reset ActiveButton so that
876 // 1. we do not process mouse button up events any more,
877 // 2. the next button down event will be processed and call CaptureMouse().
878 // Otherwise ReleaseMouse() will be called
879 // without a previous CaptureMouse().
880 ActiveButton = wxEVT_NULL;
884 //---------------------------------------------------------------------------
885 void wxVTKRenderWindowInteractor::Render()
887 #if wxCHECK_VERSION(2, 8, 0)
888 int renderAllowed = !IsFrozen();
890 int renderAllowed = 1;
892 if (renderAllowed && !RenderWhenDisabled)
894 //the user doesn't want us to render when the toplevel frame
895 //is disabled - first find the top level parent
896 wxWindow *topParent = wxGetTopLevelParent(this);
899 //if it exists, check whether it's enabled
900 //if it's not enabeld, renderAllowed will be false
901 renderAllowed = topParent->IsEnabled();
907 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
908 wxGLCanvas::SetCurrent(*(this->context));
910 if(Handle && (Handle == GetHandleHack()) )
912 RenderWindow->Render();
914 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
915 else if(GetHandleHack())
917 //this means the user has reparented us; let's adapt to the
918 //new situation by doing the WindowRemap dance
919 //store the new situation
920 Handle = GetHandleHack();
921 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
922 RenderWindow->WindowRemap();
923 RenderWindow->Render();
928 //---------------------------------------------------------------------------
929 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
931 //Change value of __RenderWhenDisabled ivar.
932 //If __RenderWhenDisabled is false (the default), this widget will not
933 //call Render() on the RenderWindow if the top level frame (i.e. the
934 //containing frame) has been disabled.
936 //This prevents recursive rendering during wxSafeYield() calls.
937 //wxSafeYield() can be called during the ProgressMethod() callback of
938 //a VTK object to have progress bars and other GUI elements updated -
939 //it does this by disabling all windows (disallowing user-input to
940 //prevent re-entrancy of code) and then handling all outstanding
943 //However, this often triggers an OnPaint() method for wxVTKRWIs,
944 //resulting in a Render(), resulting in Update() being called whilst
947 RenderWhenDisabled = (bool)newValue;
949 //---------------------------------------------------------------------------
951 // Set the variable that indicates that we want a stereo capable window
952 // be created. This method can only be called before a window is realized.
954 void wxVTKRenderWindowInteractor::SetStereo(int capable)
956 if (Stereo != capable)
959 RenderWindow->StereoCapableWindowOn();
960 RenderWindow->SetStereoTypeToCrystalEyes();
965 //---------------------------------------------------------------------------
968 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
970 this->Superclass::PrintSelf(os, indent);
975 // LG : EO namespace bbwxvtk
976 //=======================================================================