2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Program: Visualization Toolkit
36 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
38 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
40 This software is distributed WITHOUT ANY WARRANTY; without even
41 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42 PURPOSE. See the above copyright notice for more information.
44 =========================================================================*/
49 #include "creawxVTKRenderWindowInteractor.h"
51 //This is needed for vtk 3.1 :
52 #ifndef VTK_MAJOR_VERSION
53 # include "vtkVersion.h"
57 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
58 # include "vtkCommand.h"
60 # include "vtkInteractorStyle.h"
62 #include "vtkDebugLeaks.h"
64 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
65 #ifdef __WXOSX_COCOA__
66 #import <Cocoa/Cocoa.h>
70 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
71 // ControlDown has been changed to mean Command key down
72 #define ControlDown RawControlDown
77 #include "vtkCocoaRenderWindow.h"
79 #include "vtkCarbonRenderWindow.h"
85 #import "vtkTDxMacDevice.h"
89 //=======================================================================
90 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
95 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
96 #if (!wxCHECK_VERSION(2, 4, 0))
97 wxWindow* wxGetTopLevelParent(wxWindow *win)
99 while ( win && !win->IsTopLevel() )
100 win = win->GetParent();
105 // LG : EO namespace bbwxvtk
106 //=======================================================================
108 // To access objc calls on cocoa
113 // #ifdef VTK_USE_COCOA
114 // // This trick is no longer need in VTK CVS, should get rid of that:
117 // #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
118 // #endif //VTK_USE_COCOA
122 #if wxMAJOR_VERSION <= 2
124 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
125 #include "gdk/gdkprivate.h"
126 #if wxCHECK_VERSION(2, 9, 0)
127 // thanks to: http://thomasfischer.biz/?p=382
128 #include <gtk/gtkfixed.h>
129 #include <gtk/gtkwidget.h>
130 #include <wx/gtk/private/win_gtk.h>
131 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
132 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
133 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
134 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
136 #if wxCHECK_VERSION(2, 8, 0)
138 #include <wx/gtk/win_gtk.h>
140 #include <wx/gtk1/win_gtk.h>
143 #include <wx/gtk/win_gtk.h>
146 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
147 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
148 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
154 #include <gdk/gdkx.h>
156 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
157 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
158 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
163 #include "wx/x11/privx.h"
164 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
167 //For more info on this class please go to:
168 //http://wxvtk.sf.net
169 //This hack is for some buggy wxGTK version:
170 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
171 # define WX_USE_X_CAPTURE 0
173 # define WX_USE_X_CAPTURE 1
176 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
178 //=======================================================================
179 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
183 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
187 //---------------------------------------------------------------------------
188 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
189 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
190 #if wxMAJOR_VERSION <= 2
191 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
192 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
194 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
195 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
198 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
199 #if wxMAJOR_VERSION <= 2
200 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
201 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
203 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
204 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
207 //refresh window by doing a Render
208 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
209 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
210 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
212 //Bind the events to the event converters
213 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
214 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
215 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
216 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
217 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
218 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
219 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
220 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
221 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
222 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
223 #if wxCHECK_VERSION(2, 8, 0)
224 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
226 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
227 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
228 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
230 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
231 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
234 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
237 #if VTK_MAJOR_VERSION < 8
238 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
241 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
242 static int wxvtk_attributes[]={
251 //---------------------------------------------------------------------------
252 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
254 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
255 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
256 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
258 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
264 vtkRenderWindowInteractor()
265 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
266 , ActiveButton(wxEVT_NULL)
270 , RenderWhenDisabled(1)
273 #ifdef VTK_DEBUG_LEAKS
274 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
276 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
277 this->context = new wxGLContext(this);
279 this->RenderWindow = NULL;
280 this->SetRenderWindow(vtkRenderWindow::New());
281 this->RenderWindow->Delete();
284 this->Device=vtkTDxMacDevice::New();
289 //---------------------------------------------------------------------------
290 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
295 const wxString &name)
296 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
297 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
298 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
300 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
303 : wxWindow(parent, id, pos, size, style, name)
305 , vtkRenderWindowInteractor()
306 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
307 , ActiveButton(wxEVT_NULL)
311 , RenderWhenDisabled(1)
314 #ifdef VTK_DEBUG_LEAKS
315 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
317 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
318 this->context = new wxGLContext(this);
320 this->RenderWindow = NULL;
321 this->SetRenderWindow(vtkRenderWindow::New());
322 this->RenderWindow->Delete();
324 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
325 // so we update the size information of the interactor/renderwindow here
326 this->UpdateSize(size.x, size.y);
331 this->Device=vtkTDxMacDevice::New();
336 //---------------------------------------------------------------------------
337 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
339 SetRenderWindow(NULL);
340 SetInteractorStyle(NULL);
341 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
342 delete this->context;
346 this->Device->Delete();
350 //---------------------------------------------------------------------------
351 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
353 // we don't make use of the objectfactory, because we're not registered
354 return new wxVTKRenderWindowInteractor;
356 //---------------------------------------------------------------------------
357 void wxVTKRenderWindowInteractor::Initialize()
359 int *size = RenderWindow->GetSize();
360 // enable everything and start rendering
362 //RenderWindow->Start();
364 // set the size in the render window interactor
368 // this is initialized
371 //---------------------------------------------------------------------------
372 void wxVTKRenderWindowInteractor::Enable()
374 // if already enabled then done
380 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
381 wxGLCanvas::SetCurrent(*this->context);
388 this->Device->SetInteractor(this);
389 this->Device->Initialize();
397 //---------------------------------------------------------------------------
398 bool wxVTKRenderWindowInteractor::Enable(bool enable)
404 this->Device->SetInteractor(this);
405 this->Device->Initialize();
411 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
412 return wxGLCanvas::Enable(enable);
414 return wxWindow::Enable(enable);
417 //---------------------------------------------------------------------------
418 void wxVTKRenderWindowInteractor::Disable()
420 // if already disabled then done
425 if(this->Device->GetInitialized())
427 this->Device->Close();
432 // that's it (we can't remove the event handler like it should be...)
436 //---------------------------------------------------------------------------
437 void wxVTKRenderWindowInteractor::Start()
439 // the interactor cannot control the event loop
440 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
441 "interactor cannot control event loop.");
443 //---------------------------------------------------------------------------
444 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
448 // if the size changed tell render window
449 if ( x != Size[0] || y != Size[1] )
451 // adjust our (vtkRenderWindowInteractor size)
454 // and our RenderWindow's size
457 // #ifdef VTK_USE_COCOA
459 // #endif //VTK_USE_COCOA
461 RenderWindow->SetSize(x, y);
464 #if defined(__WXMSW__)
470 //---------------------------------------------------------------------------
471 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
473 // it's a one shot timer
474 if (!timer.Start(10, TRUE))
480 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
481 //------------------------------------------------------------------
482 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
483 unsigned long duration)
485 if (!timer.Start(duration, timerType == OneShotTimer))
488 return ID_wxVTKRenderWindowInteractor_TIMER;
490 //------------------------------------------------------------------
491 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
497 //---------------------------------------------------------------------------
498 int wxVTKRenderWindowInteractor::DestroyTimer()
503 //---------------------------------------------------------------------------
504 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
509 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
511 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
512 // pass the right timer id
513 int timerId = this->GetCurrentTimerId();
514 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
516 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
520 InteractorStyle->OnTimer();
524 //---------------------------------------------------------------------------
525 // NOTE on implementation:
526 // Bad luck you ended up in the only tricky place of this code.
527 // A few note, wxWidgets still refuse to provide such convenient method
528 // so I have to maintain it myself, eventhough this is completely integrated
530 // Anyway if this happen to break for you then compare to a recent version of wxPython
531 // and look for the function long wxPyGetWinHandle(wxWindow* win)
532 // in wxPython/src/helpers.cpp
533 long wxVTKRenderWindowInteractor::GetHandleHack()
535 //helper function to hide the MSW vs GTK stuff
538 // __WXMSW__ is for Win32
539 // __WXMAC__ is for Carbon or Cocoa builds
540 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
541 #if defined(__WXMSW__) || defined(__WXMAC__)
542 handle_tmp = (long)this->GetHandle();
545 // using above GetHandle() works fine with wxOSX 2.9.x
546 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
547 // Here is how to find the NSWindow
548 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
549 if (toplevel != NULL )
551 handle_tmp = (long)toplevel->GetNSWindow();
553 // The NSView will be deducted from
554 // [(NSWindow*)Handle contentView]
555 // if only I knew how to write that in c++
556 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
558 // Find and return the actual X-Window.
559 #if defined(__WXGTK__) || defined(__WXX11__)
560 return (long)GetXWindow(this);
564 // handle_tmp = (long)this->GetXWindow();
569 //---------------------------------------------------------------------------
570 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
572 //must always be here
579 //do it here rather than in the cstor: this is safer.
582 Handle = GetHandleHack();
585 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
586 NSView *nvsview = (NSView* )Handle;
587 NSWindow *nswindow = nvsview.window;
588 rwin->SetRootWindow( nswindow );
589 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
591 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
595 // this->GetNSView() <-> DisplayId
596 // this->GetTopLevel()->GetNSWindow() <-> WindowId
598 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
601 // This is another hack to prevent the VTK Render Window from closing the display.
602 // If VTK closes the display, ~wxContext chashes while trying to destroy its
603 // glContext (because the display is closed). The Get -> Set makes this VTK
604 // object think someone else is responsible for the display.
606 // avoid "Method not implemented" messages in Console
608 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
611 // get vtk to render to the wxWindows
614 // This solves a problem with repainting after a window resize
615 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
617 #if !wxCHECK_VERSION(2, 9, 0)
618 // this doesn't seem necessary with wxOSX 2.9.x
619 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
622 rwin->UpdateContext();
626 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
629 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
630 // Must be somewhere after VTK 4.4
631 rwin->UpdateGLRegion();
638 //---------------------------------------------------------------------------
639 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
641 //turn off background erase to reduce flickering on MSW
644 //---------------------------------------------------------------------------
645 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
648 GetClientSize(&w, &h);
656 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
657 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
659 //this will check for Handle
662 //---------------------------------------------------------------------------
663 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
669 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
670 SetEventInformationFlipY(event.GetX(), event.GetY(),
671 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
673 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
675 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
676 event.GetX(), Size[1] - event.GetY() - 1);
679 //---------------------------------------------------------------------------
680 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
681 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
688 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
690 SetEventInformationFlipY(event.GetX(), event.GetY(),
691 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
693 InvokeEvent(vtkCommand::EnterEvent, NULL);
696 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
697 event.GetX(), Size[1] - event.GetY() - 1);
700 //---------------------------------------------------------------------------
701 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
708 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
710 SetEventInformationFlipY(event.GetX(), event.GetY(),
711 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
713 InvokeEvent(vtkCommand::LeaveEvent, NULL);
716 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
717 event.GetX(), Size[1] - event.GetY() - 1);
720 //---------------------------------------------------------------------------
721 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
728 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
730 int keycode = event.GetKeyCode();
732 if (((unsigned int)keycode) < 256)
734 // TODO: Unicode in non-Unicode mode ??
738 // we don't get a valid mouse position inside the key event on every platform
739 // so we retrieve the mouse position explicitly and pass it along
740 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
741 SetEventInformationFlipY(mousePos.x, mousePos.y,
742 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
743 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
745 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
746 event.GetKeyCode(), 1);
750 //---------------------------------------------------------------------------
751 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
758 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
760 int keycode = event.GetKeyCode();
762 if (((unsigned int)keycode) < 256)
764 // TODO: Unicode in non-Unicode mode ??
768 // we don't get a valid mouse position inside the key event on every platform
769 // so we retrieve the mouse position explicitly and pass it along
770 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
771 SetEventInformationFlipY(mousePos.x, mousePos.y,
772 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
773 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
775 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
776 event.GetKeyCode(), 1);
780 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
781 //---------------------------------------------------------------------------
782 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
789 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
791 int keycode = event.GetKeyCode();
793 if (((unsigned int)keycode) < 256)
795 // TODO: Unicode in non-Unicode mode ??
799 // we don't get a valid mouse position inside the key event on every platform
800 // so we retrieve the mouse position explicitly and pass it along
801 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
802 SetEventInformationFlipY(mousePos.x, mousePos.y,
803 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
804 InvokeEvent(vtkCommand::CharEvent, NULL);
808 //---------------------------------------------------------------------------
809 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
811 if (!Enabled || (ActiveButton != wxEVT_NULL))
815 ActiveButton = event.GetEventType();
817 // On Mac (Carbon) and Windows we don't automatically get the focus when
818 // you click inside the window
819 // we therefore set the focus explicitly
820 // Apparently we need that on linux (GTK) too:
823 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
824 SetEventInformationFlipY(event.GetX(), event.GetY(),
825 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
828 if(event.RightDown())
830 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
832 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
835 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
836 event.GetX(), Size[1] - event.GetY() - 1);
839 else if(event.LeftDown())
841 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
843 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
846 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
847 event.GetX(), Size[1] - event.GetY() - 1);
850 else if(event.MiddleDown())
852 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
854 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
857 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
858 event.GetX(), Size[1] - event.GetY() - 1);
861 //save the button and capture mouse until the button is released
863 //1. it is possible (WX_USE_X_CAPTURE)
864 //2. user decided to.
865 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
870 //---------------------------------------------------------------------------
871 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
873 //EVT_xxx_DOWN == EVT_xxx_UP - 1
874 //This is only needed if two mouse buttons are pressed at the same time.
875 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
876 //wxEVT_COMMAND_RIGHT_CLICK
877 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
882 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
885 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
886 SetEventInformationFlipY(event.GetX(), event.GetY(),
887 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
890 if(ActiveButton == wxEVT_RIGHT_DOWN)
892 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
894 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
897 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
898 event.GetX(), Size[1] - event.GetY() - 1);
901 else if(ActiveButton == wxEVT_LEFT_DOWN)
903 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
905 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
908 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
909 event.GetX(), Size[1] - event.GetY() - 1);
912 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
914 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
916 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
919 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
920 event.GetX(), Size[1] - event.GetY() - 1);
923 //if the ActiveButton is realeased, then release mouse capture
924 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
928 ActiveButton = wxEVT_NULL;
930 //---------------------------------------------------------------------------
931 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
933 // Mouse wheel was only added after VTK 4.4 (I think...)
934 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
936 //Set vtk event information ... The numebr of wheel rotations is stored in
937 //the x varible. y varible is zero
938 SetEventInformationFlipY(event.GetX() , event.GetY(),
939 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
940 if(event.GetWheelRotation() > 0)
943 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
948 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
954 //---------------------------------------------------------------------------
955 #if wxCHECK_VERSION(2, 8, 0)
956 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
958 if (ActiveButton != wxEVT_NULL)
960 //Maybe also invoke the button release event here
962 // Reset ActiveButton so that
963 // 1. we do not process mouse button up events any more,
964 // 2. the next button down event will be processed and call CaptureMouse().
965 // Otherwise ReleaseMouse() will be called
966 // without a previous CaptureMouse().
967 ActiveButton = wxEVT_NULL;
971 //---------------------------------------------------------------------------
972 void wxVTKRenderWindowInteractor::Render()
974 #if wxCHECK_VERSION(2, 8, 0)
975 int renderAllowed = !IsFrozen();
977 int renderAllowed = 1;
979 if (renderAllowed && !RenderWhenDisabled)
981 //the user doesn't want us to render when the toplevel frame
982 //is disabled - first find the top level parent
983 wxWindow *topParent = wxGetTopLevelParent(this);
986 //if it exists, check whether it's enabled
987 //if it's not enabeld, renderAllowed will be false
988 renderAllowed = topParent->IsEnabled();
990 } // if renderAllowed && !RenderWhenDisabled
994 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
995 wxGLCanvas::SetCurrent(*(this->context));
997 if(Handle && (Handle == GetHandleHack()) )
999 RenderWindow->Render();
1001 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
1002 else if(GetHandleHack())
1004 //this means the user has reparented us; let's adapt to the
1005 //new situation by doing the WindowRemap dance
1006 //store the new situation
1007 Handle = GetHandleHack();
1008 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
1009 RenderWindow->WindowRemap();
1010 RenderWindow->Render();
1013 } // if renderAllowed
1015 //---------------------------------------------------------------------------
1016 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
1018 //Change value of __RenderWhenDisabled ivar.
1019 //If __RenderWhenDisabled is false (the default), this widget will not
1020 //call Render() on the RenderWindow if the top level frame (i.e. the
1021 //containing frame) has been disabled.
1023 //This prevents recursive rendering during wxSafeYield() calls.
1024 //wxSafeYield() can be called during the ProgressMethod() callback of
1025 //a VTK object to have progress bars and other GUI elements updated -
1026 //it does this by disabling all windows (disallowing user-input to
1027 //prevent re-entrancy of code) and then handling all outstanding
1030 //However, this often triggers an OnPaint() method for wxVTKRWIs,
1031 //resulting in a Render(), resulting in Update() being called whilst
1032 //still in progress.
1034 RenderWhenDisabled = (bool)newValue;
1036 //---------------------------------------------------------------------------
1038 // Set the variable that indicates that we want a stereo capable window
1039 // be created. This method can only be called before a window is realized.
1041 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1043 if (Stereo != capable)
1046 RenderWindow->StereoCapableWindowOn();
1047 RenderWindow->SetStereoTypeToCrystalEyes();
1052 //---------------------------------------------------------------------------
1055 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1057 this->Superclass::PrintSelf(os, indent);
1062 // LG : EO namespace bbwxvtk
1063 //=======================================================================