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 =========================================================================*/
46 //#import <Cocoa/Cocoa.h>
50 #include "creawxVTKRenderWindowInteractor.h"
52 #include <wx/display.h>
55 //This is needed for vtk 3.1 :
56 #ifndef VTK_MAJOR_VERSION
57 # include "vtkVersion.h"
60 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
61 # include "vtkCommand.h"
63 # include "vtkInteractorStyle.h"
65 #include "vtkDebugLeaks.h"
67 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
68 #ifdef __WXOSX_COCOA__
72 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
73 // ControlDown has been changed to mean Command key down
74 #define ControlDown RawControlDown
79 #include "vtkCocoaRenderWindow.h"
81 #include "vtkCarbonRenderWindow.h"
86 //=======================================================================
87 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
92 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
93 #if (!wxCHECK_VERSION(2, 4, 0))
94 wxWindow* wxGetTopLevelParent(wxWindow *win)
96 while ( win && !win->IsTopLevel() )
97 win = win->GetParent();
102 // LG : EO namespace bbwxvtk
103 //=======================================================================
105 // To access objc calls on cocoa
108 #import <Cocoa/Cocoa.h>
109 // This trick is no longer need in VTK CVS, should get rid of that:
112 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
113 #endif //VTK_USE_COCOA
116 #if wxMAJOR_VERSION <= 2
119 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
120 #include "gdk/gdkprivate.h"
121 #if wxCHECK_VERSION(2, 9, 0)
122 // thanks to: http://thomasfischer.biz/?p=382
123 #include <gtk/gtkfixed.h>
124 #include <gtk/gtkwidget.h>
125 #include <wx/gtk/private/win_gtk.h>
126 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
127 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
128 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
129 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
131 #if wxCHECK_VERSION(2, 8, 0)
133 #include <wx/gtk/win_gtk.h>
135 #include <wx/gtk1/win_gtk.h>
138 #include <wx/gtk/win_gtk.h>
141 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
142 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
143 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
149 #include <gdk/gdkx.h>
151 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
152 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
153 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
158 #include "wx/x11/privx.h"
159 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
162 //For more info on this class please go to:
163 //http://wxvtk.sf.net
164 //This hack is for some buggy wxGTK version:
165 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
166 # define WX_USE_X_CAPTURE 0
168 # define WX_USE_X_CAPTURE 1
171 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
173 //=======================================================================
174 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
178 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
182 //---------------------------------------------------------------------------
183 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
184 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
185 #if wxMAJOR_VERSION <= 2
186 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
187 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
189 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
190 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
193 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
194 #if wxMAJOR_VERSION <= 2
195 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
196 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
198 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
199 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
202 //refresh window by doing a Render
203 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
204 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
205 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
207 //Bind the events to the event converters
208 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
209 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
210 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
211 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
212 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
213 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
214 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
215 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
216 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
217 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
218 #if wxCHECK_VERSION(2, 8, 0)
219 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
221 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
222 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
223 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
225 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
226 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
229 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
232 #if VTK_MAJOR_VERSION < 8
233 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
236 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
237 static int wxvtk_attributes[]={
246 //---------------------------------------------------------------------------
247 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
249 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
250 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
251 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
253 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
259 vtkRenderWindowInteractor()
260 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
261 , ActiveButton(wxEVT_NULL)
265 , RenderWhenDisabled(1)
268 #ifdef VTK_DEBUG_LEAKS
269 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
271 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
272 this->context = new wxGLContext(this);
274 this->RenderWindow = NULL;
275 this->SetRenderWindow(vtkRenderWindow::New());
276 this->RenderWindow->Delete();
278 //---------------------------------------------------------------------------
279 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
284 const wxString &name)
285 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
286 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
287 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
289 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
292 : wxWindow(parent, id, pos, size, style, name)
294 , vtkRenderWindowInteractor()
295 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
296 , ActiveButton(wxEVT_NULL)
300 , RenderWhenDisabled(1)
303 #ifdef VTK_DEBUG_LEAKS
304 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
306 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
307 this->context = new wxGLContext(this);
309 this->RenderWindow = NULL;
310 this->SetRenderWindow(vtkRenderWindow::New());
311 this->RenderWindow->Delete();
313 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
314 // so we update the size information of the interactor/renderwindow here
315 this->UpdateSize(size.x, size.y);
318 //---------------------------------------------------------------------------
319 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
321 SetRenderWindow(NULL);
322 SetInteractorStyle(NULL);
323 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
324 delete this->context;
327 //---------------------------------------------------------------------------
328 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
330 // we don't make use of the objectfactory, because we're not registered
331 return new wxVTKRenderWindowInteractor;
333 //---------------------------------------------------------------------------
334 void wxVTKRenderWindowInteractor::Initialize()
336 int *size = RenderWindow->GetSize();
337 // enable everything and start rendering
339 //RenderWindow->Start();
341 // set the size in the render window interactor
345 // this is initialized
348 //---------------------------------------------------------------------------
349 void wxVTKRenderWindowInteractor::Enable()
351 // if already enabled then done
357 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
358 wxGLCanvas::SetCurrent(*this->context);
362 //---------------------------------------------------------------------------
363 bool wxVTKRenderWindowInteractor::Enable(bool enable)
365 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
366 return wxGLCanvas::Enable(enable);
368 return wxWindow::Enable(enable);
371 //---------------------------------------------------------------------------
372 void wxVTKRenderWindowInteractor::Disable()
374 // if already disabled then done
378 // that's it (we can't remove the event handler like it should be...)
382 //---------------------------------------------------------------------------
383 void wxVTKRenderWindowInteractor::Start()
385 // the interactor cannot control the event loop
386 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
387 "interactor cannot control event loop.");
389 //---------------------------------------------------------------------------
390 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
394 // if the size changed tell render window
395 if ( x != Size[0] || y != Size[1] )
397 // adjust our (vtkRenderWindowInteractor size)
400 // and our RenderWindow's size
405 #endif //VTK_USE_COCOA
407 RenderWindow->SetSize(x, y);
410 #if defined(__WXMSW__)
416 //---------------------------------------------------------------------------
417 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
419 // it's a one shot timer
420 if (!timer.Start(10, TRUE))
426 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
427 //------------------------------------------------------------------
428 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
429 unsigned long duration)
431 if (!timer.Start(duration, timerType == OneShotTimer))
434 return ID_wxVTKRenderWindowInteractor_TIMER;
436 //------------------------------------------------------------------
437 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
443 //---------------------------------------------------------------------------
444 int wxVTKRenderWindowInteractor::DestroyTimer()
449 //---------------------------------------------------------------------------
450 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
455 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
457 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
458 // pass the right timer id
459 int timerId = this->GetCurrentTimerId();
460 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
462 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
466 InteractorStyle->OnTimer();
470 //---------------------------------------------------------------------------
471 // NOTE on implementation:
472 // Bad luck you ended up in the only tricky place of this code.
473 // A few note, wxWidgets still refuse to provide such convenient method
474 // so I have to maintain it myself, eventhough this is completely integrated
476 // Anyway if this happen to break for you then compare to a recent version of wxPython
477 // and look for the function long wxPyGetWinHandle(wxWindow* win)
478 // in wxPython/src/helpers.cpp
479 long wxVTKRenderWindowInteractor::GetHandleHack()
481 //helper function to hide the MSW vs GTK stuff
484 // __WXMSW__ is for Win32
485 // __WXMAC__ is for Carbon or Cocoa builds
486 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
487 #if defined(__WXMSW__) || defined(__WXMAC__)
488 handle_tmp = (long)this->GetHandle();
491 // using above GetHandle() works fine with wxOSX 2.9.x
492 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
493 // Here is how to find the NSWindow
494 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
495 if (toplevel != NULL )
497 handle_tmp = (long)toplevel->GetNSWindow();
499 // The NSView will be deducted from
500 // [(NSWindow*)Handle contentView]
501 // if only I knew how to write that in c++
502 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
504 // Find and return the actual X-Window.
505 #if defined(__WXGTK__) || defined(__WXX11__)
506 return (long)GetXWindow(this);
510 // handle_tmp = (long)this->GetXWindow();
515 //---------------------------------------------------------------------------
516 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
519 //must always be here
520 //EED2021-08-26 wxPaintDC pDC(this);
522 //do it here rather than in the cstor: this is safer.
525 Handle = GetHandleHack();
528 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
530 // rwin->SetWantsBestResolution(true);
532 NSView *nvsview = (NSView* )Handle;
533 NSWindow *nswindow = nvsview.window;
534 rwin->SetRootWindow( nswindow );
535 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
537 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
541 // this->GetNSView() <-> DisplayId
542 // this->GetTopLevel()->GetNSWindow() <-> WindowId
544 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
547 // This is another hack to prevent the VTK Render Window from closing the display.
548 // If VTK closes the display, ~wxContext chashes while trying to destroy its
549 // glContext (because the display is closed). The Get -> Set makes this VTK
550 // object think someone else is responsible for the display.
552 // avoid "Method not implemented" messages in Console
554 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
557 // get vtk to render to the wxWindows
561 // This solves a problem with repainting after a window resize
562 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
564 #if !wxCHECK_VERSION(2, 9, 0)
565 // this doesn't seem necessary with wxOSX 2.9.x
566 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
569 rwin->UpdateContext();
574 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
577 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
578 // Must be somewhere after VTK 4.4
579 rwin->UpdateGLRegion();
586 //---------------------------------------------------------------------------
587 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
589 //turn off background erase to reduce flickering on MSW
592 //---------------------------------------------------------------------------
593 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
596 GetClientSize(&w, &h);
604 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
605 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
607 //this will check for Handle
612 //---------------------------------------------------------------------------
613 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
619 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
621 SetEventInformationFlipY(event.GetX(), event.GetY(),
622 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
624 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
626 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
627 event.GetX(), Size[1] - event.GetY() - 1);
630 //---------------------------------------------------------------------------
631 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
632 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
639 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
641 SetEventInformationFlipY(event.GetX(), event.GetY(),
642 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
644 InvokeEvent(vtkCommand::EnterEvent, NULL);
647 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
648 event.GetX(), Size[1] - event.GetY() - 1);
651 //---------------------------------------------------------------------------
652 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
659 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
661 SetEventInformationFlipY(event.GetX(), event.GetY(),
662 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
664 InvokeEvent(vtkCommand::LeaveEvent, NULL);
667 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
668 event.GetX(), Size[1] - event.GetY() - 1);
671 //---------------------------------------------------------------------------
672 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
679 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
681 int keycode = event.GetKeyCode();
683 if (((unsigned int)keycode) < 256)
685 // TODO: Unicode in non-Unicode mode ??
689 // we don't get a valid mouse position inside the key event on every platform
690 // so we retrieve the mouse position explicitly and pass it along
691 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
692 SetEventInformationFlipY(mousePos.x, mousePos.y,
693 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
694 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
696 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
697 event.GetKeyCode(), 1);
701 //---------------------------------------------------------------------------
702 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
709 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
711 int keycode = event.GetKeyCode();
713 if (((unsigned int)keycode) < 256)
715 // TODO: Unicode in non-Unicode mode ??
719 // we don't get a valid mouse position inside the key event on every platform
720 // so we retrieve the mouse position explicitly and pass it along
721 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
722 SetEventInformationFlipY(mousePos.x, mousePos.y,
723 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
724 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
726 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
727 event.GetKeyCode(), 1);
731 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
732 //---------------------------------------------------------------------------
733 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
740 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
742 int keycode = event.GetKeyCode();
744 if (((unsigned int)keycode) < 256)
746 // TODO: Unicode in non-Unicode mode ??
750 // we don't get a valid mouse position inside the key event on every platform
751 // so we retrieve the mouse position explicitly and pass it along
752 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
753 SetEventInformationFlipY(mousePos.x, mousePos.y,
754 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
755 InvokeEvent(vtkCommand::CharEvent, NULL);
759 //---------------------------------------------------------------------------
760 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
762 if (!Enabled || (ActiveButton != wxEVT_NULL))
766 ActiveButton = event.GetEventType();
768 // On Mac (Carbon) and Windows we don't automatically get the focus when
769 // you click inside the window
770 // we therefore set the focus explicitly
771 // Apparently we need that on linux (GTK) too:
774 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
775 SetEventInformationFlipY(event.GetX(), event.GetY(),
776 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
779 if(event.RightDown())
781 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
783 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
786 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
787 event.GetX(), Size[1] - event.GetY() - 1);
790 else if(event.LeftDown())
792 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
794 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
797 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
798 event.GetX(), Size[1] - event.GetY() - 1);
801 else if(event.MiddleDown())
803 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
805 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
808 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
809 event.GetX(), Size[1] - event.GetY() - 1);
812 //save the button and capture mouse until the button is released
814 //1. it is possible (WX_USE_X_CAPTURE)
815 //2. user decided to.
816 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
821 //---------------------------------------------------------------------------
822 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
824 //EVT_xxx_DOWN == EVT_xxx_UP - 1
825 //This is only needed if two mouse buttons are pressed at the same time.
826 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
827 //wxEVT_COMMAND_RIGHT_CLICK
828 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
833 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
836 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
837 SetEventInformationFlipY(event.GetX(), event.GetY(),
838 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
841 if(ActiveButton == wxEVT_RIGHT_DOWN)
843 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
845 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
848 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
849 event.GetX(), Size[1] - event.GetY() - 1);
852 else if(ActiveButton == wxEVT_LEFT_DOWN)
854 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
856 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
859 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
860 event.GetX(), Size[1] - event.GetY() - 1);
863 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
865 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
867 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
870 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
871 event.GetX(), Size[1] - event.GetY() - 1);
874 //if the ActiveButton is realeased, then release mouse capture
875 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
879 ActiveButton = wxEVT_NULL;
881 //---------------------------------------------------------------------------
882 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
884 // Mouse wheel was only added after VTK 4.4 (I think...)
885 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
887 //Set vtk event information ... The numebr of wheel rotations is stored in
888 //the x varible. y varible is zero
889 SetEventInformationFlipY(event.GetX() , event.GetY(),
890 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
891 if(event.GetWheelRotation() > 0)
894 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
899 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
905 //---------------------------------------------------------------------------
906 #if wxCHECK_VERSION(2, 8, 0)
907 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
909 if (ActiveButton != wxEVT_NULL)
911 //Maybe also invoke the button release event here
913 // Reset ActiveButton so that
914 // 1. we do not process mouse button up events any more,
915 // 2. the next button down event will be processed and call CaptureMouse().
916 // Otherwise ReleaseMouse() will be called
917 // without a previous CaptureMouse().
918 ActiveButton = wxEVT_NULL;
922 //---------------------------------------------------------------------------
923 void wxVTKRenderWindowInteractor::Render()
925 #if wxCHECK_VERSION(2, 8, 0)
926 int renderAllowed = !IsFrozen();
928 int renderAllowed = 1;
930 if (renderAllowed && !RenderWhenDisabled)
932 //the user doesn't want us to render when the toplevel frame
933 //is disabled - first find the top level parent
934 wxWindow *topParent = wxGetTopLevelParent(this);
937 //if it exists, check whether it's enabled
938 //if it's not enabeld, renderAllowed will be false
939 renderAllowed = topParent->IsEnabled();
945 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
946 wxGLCanvas::SetCurrent(*(this->context));
948 if(Handle && (Handle == GetHandleHack()) )
950 RenderWindow->Render();
952 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
953 else if(GetHandleHack())
955 //this means the user has reparented us; let's adapt to the
956 //new situation by doing the WindowRemap dance
957 //store the new situation
958 Handle = GetHandleHack();
959 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
960 RenderWindow->WindowRemap();
961 RenderWindow->Render();
967 //---------------------------------------------------------------------------
968 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
970 //Change value of __RenderWhenDisabled ivar.
971 //If __RenderWhenDisabled is false (the default), this widget will not
972 //call Render() on the RenderWindow if the top level frame (i.e. the
973 //containing frame) has been disabled.
975 //This prevents recursive rendering during wxSafeYield() calls.
976 //wxSafeYield() can be called during the ProgressMethod() callback of
977 //a VTK object to have progress bars and other GUI elements updated -
978 //it does this by disabling all windows (disallowing user-input to
979 //prevent re-entrancy of code) and then handling all outstanding
982 //However, this often triggers an OnPaint() method for wxVTKRWIs,
983 //resulting in a Render(), resulting in Update() being called whilst
986 RenderWhenDisabled = (bool)newValue;
988 //---------------------------------------------------------------------------
990 // Set the variable that indicates that we want a stereo capable window
991 // be created. This method can only be called before a window is realized.
993 void wxVTKRenderWindowInteractor::SetStereo(int capable)
995 if (Stereo != capable)
998 RenderWindow->StereoCapableWindowOn();
999 RenderWindow->SetStereoTypeToCrystalEyes();
1004 //---------------------------------------------------------------------------
1007 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1009 this->Superclass::PrintSelf(os, indent);
1014 // LG : EO namespace bbwxvtk
1015 //=======================================================================