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 //This is needed for vtk 3.1 :
53 #ifndef VTK_MAJOR_VERSION
54 # 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__
69 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
70 // ControlDown has been changed to mean Command key down
71 #define ControlDown RawControlDown
76 #include "vtkCocoaRenderWindow.h"
78 #include "vtkCarbonRenderWindow.h"
83 //=======================================================================
84 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
89 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
90 #if (!wxCHECK_VERSION(2, 4, 0))
91 wxWindow* wxGetTopLevelParent(wxWindow *win)
93 while ( win && !win->IsTopLevel() )
94 win = win->GetParent();
99 // LG : EO namespace bbwxvtk
100 //=======================================================================
102 // To access objc calls on cocoa
105 //EED #import <Cocoa/Cocoa.h>
106 // This trick is no longer need in VTK CVS, should get rid of that:
109 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
110 #endif //VTK_USE_COCOA
113 #if wxMAJOR_VERSION <= 2
116 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
117 #include "gdk/gdkprivate.h"
118 #if wxCHECK_VERSION(2, 9, 0)
119 // thanks to: http://thomasfischer.biz/?p=382
120 #include <gtk/gtkfixed.h>
121 #include <gtk/gtkwidget.h>
122 #include <wx/gtk/private/win_gtk.h>
123 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
124 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
125 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
126 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
128 #if wxCHECK_VERSION(2, 8, 0)
130 #include <wx/gtk/win_gtk.h>
132 #include <wx/gtk1/win_gtk.h>
135 #include <wx/gtk/win_gtk.h>
138 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
139 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
140 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
146 #include <gdk/gdkx.h>
148 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
149 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
150 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
155 #include "wx/x11/privx.h"
156 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
159 //For more info on this class please go to:
160 //http://wxvtk.sf.net
161 //This hack is for some buggy wxGTK version:
162 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
163 # define WX_USE_X_CAPTURE 0
165 # define WX_USE_X_CAPTURE 1
168 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
170 //=======================================================================
171 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
175 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
179 //---------------------------------------------------------------------------
180 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
181 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
182 #if wxMAJOR_VERSION <= 2
183 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
184 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
186 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
187 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
190 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
191 #if wxMAJOR_VERSION <= 2
192 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
193 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
195 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
196 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
199 //refresh window by doing a Render
200 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
201 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
202 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
204 //Bind the events to the event converters
205 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
206 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
207 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
208 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
209 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
210 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
211 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
212 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
213 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
214 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
215 #if wxCHECK_VERSION(2, 8, 0)
216 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
218 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
219 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
220 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
222 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
223 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
226 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
229 #if VTK_MAJOR_VERSION < 8
230 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
233 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
234 static int wxvtk_attributes[]={
243 //---------------------------------------------------------------------------
244 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
246 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
247 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
248 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
250 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
256 vtkRenderWindowInteractor()
257 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
258 , ActiveButton(wxEVT_NULL)
262 , RenderWhenDisabled(1)
265 #ifdef VTK_DEBUG_LEAKS
266 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
268 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
269 this->context = new wxGLContext(this);
271 this->RenderWindow = NULL;
272 this->SetRenderWindow(vtkRenderWindow::New());
273 this->RenderWindow->Delete();
275 //---------------------------------------------------------------------------
276 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
281 const wxString &name)
282 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
283 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
284 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
286 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
289 : wxWindow(parent, id, pos, size, style, name)
291 , vtkRenderWindowInteractor()
292 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
293 , ActiveButton(wxEVT_NULL)
297 , RenderWhenDisabled(1)
300 #ifdef VTK_DEBUG_LEAKS
301 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
303 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
304 this->context = new wxGLContext(this);
306 this->RenderWindow = NULL;
307 this->SetRenderWindow(vtkRenderWindow::New());
308 this->RenderWindow->Delete();
310 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
311 // so we update the size information of the interactor/renderwindow here
312 this->UpdateSize(size.x, size.y);
315 //---------------------------------------------------------------------------
316 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
318 SetRenderWindow(NULL);
319 SetInteractorStyle(NULL);
320 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
321 delete this->context;
324 //---------------------------------------------------------------------------
325 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
327 // we don't make use of the objectfactory, because we're not registered
328 return new wxVTKRenderWindowInteractor;
330 //---------------------------------------------------------------------------
331 void wxVTKRenderWindowInteractor::Initialize()
333 int *size = RenderWindow->GetSize();
334 // enable everything and start rendering
336 //RenderWindow->Start();
338 // set the size in the render window interactor
342 // this is initialized
345 //---------------------------------------------------------------------------
346 void wxVTKRenderWindowInteractor::Enable()
348 // if already enabled then done
354 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
355 wxGLCanvas::SetCurrent(*this->context);
359 //---------------------------------------------------------------------------
360 bool wxVTKRenderWindowInteractor::Enable(bool enable)
362 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
363 return wxGLCanvas::Enable(enable);
365 return wxWindow::Enable(enable);
368 //---------------------------------------------------------------------------
369 void wxVTKRenderWindowInteractor::Disable()
371 // if already disabled then done
375 // that's it (we can't remove the event handler like it should be...)
379 //---------------------------------------------------------------------------
380 void wxVTKRenderWindowInteractor::Start()
382 // the interactor cannot control the event loop
383 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
384 "interactor cannot control event loop.");
386 //---------------------------------------------------------------------------
387 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
391 // if the size changed tell render window
392 if ( x != Size[0] || y != Size[1] )
394 // adjust our (vtkRenderWindowInteractor size)
397 // and our RenderWindow's size
398 RenderWindow->SetSize(x, y);
399 #if defined(__WXMSW__)
405 //---------------------------------------------------------------------------
406 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
408 // it's a one shot timer
409 if (!timer.Start(10, TRUE))
415 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
416 //------------------------------------------------------------------
417 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
418 unsigned long duration)
420 if (!timer.Start(duration, timerType == OneShotTimer))
423 return ID_wxVTKRenderWindowInteractor_TIMER;
425 //------------------------------------------------------------------
426 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
432 //---------------------------------------------------------------------------
433 int wxVTKRenderWindowInteractor::DestroyTimer()
438 //---------------------------------------------------------------------------
439 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
444 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
446 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
447 // pass the right timer id
448 int timerId = this->GetCurrentTimerId();
449 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
451 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
455 InteractorStyle->OnTimer();
459 //---------------------------------------------------------------------------
460 // NOTE on implementation:
461 // Bad luck you ended up in the only tricky place of this code.
462 // A few note, wxWidgets still refuse to provide such convenient method
463 // so I have to maintain it myself, eventhough this is completely integrated
465 // Anyway if this happen to break for you then compare to a recent version of wxPython
466 // and look for the function long wxPyGetWinHandle(wxWindow* win)
467 // in wxPython/src/helpers.cpp
468 long wxVTKRenderWindowInteractor::GetHandleHack()
470 printf("EED wxVTKRenderWindowInteractor::GetHandleHack start \n");
471 //helper function to hide the MSW vs GTK stuff
474 // __WXMSW__ is for Win32
475 // __WXMAC__ is for Carbon or Cocoa builds
476 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
477 #if defined(__WXMSW__) || defined(__WXMAC__)
478 handle_tmp = (long)this->GetHandle();
481 // using above GetHandle() works fine with wxOSX 2.9.x
482 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
483 // Here is how to find the NSWindow
484 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
485 if (toplevel != NULL )
487 handle_tmp = (long)toplevel->GetNSWindow();
489 // The NSView will be deducted from
490 // [(NSWindow*)Handle contentView]
491 // if only I knew how to write that in c++
492 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
494 // Find and return the actual X-Window.
495 #if defined(__WXGTK__) || defined(__WXX11__)
496 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", handle_tmp);
497 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", (long)GetXWindow(this));
498 return (long)GetXWindow(this);
502 // handle_tmp = (long)this->GetXWindow();
505 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End BBB handle_tmp %ld \n", handle_tmp);
508 //---------------------------------------------------------------------------
509 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
511 //must always be here
514 //do it here rather than in the cstor: this is safer.
517 Handle = GetHandleHack();
520 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
521 NSView *nvsview = (NSView* )Handle;
522 NSWindow *nswindow = nvsview.window;
523 rwin->SetRootWindow( nswindow );
524 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
526 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
532 // this->GetNSView() <-> DisplayId
533 // this->GetTopLevel()->GetNSWindow() <-> WindowId
535 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
538 // This is another hack to prevent the VTK Render Window from closing the display.
539 // If VTK closes the display, ~wxContext chashes while trying to destroy its
540 // glContext (because the display is closed). The Get -> Set makes this VTK
541 // object think someone else is responsible for the display.
543 // avoid "Method not implemented" messages in Console
545 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
548 // get vtk to render to the wxWindows
551 // This solves a problem with repainting after a window resize
552 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
554 #if !wxCHECK_VERSION(2, 9, 0)
555 // this doesn't seem necessary with wxOSX 2.9.x
556 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
559 rwin->UpdateContext();
563 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
566 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
567 // Must be somewhere after VTK 4.4
568 rwin->UpdateGLRegion();
574 //---------------------------------------------------------------------------
575 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
577 //turn off background erase to reduce flickering on MSW
580 //---------------------------------------------------------------------------
581 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
584 GetClientSize(&w, &h);
592 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
593 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
595 //this will check for Handle
598 //---------------------------------------------------------------------------
599 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
605 #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::MouseMoveEvent, NULL);
611 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
612 event.GetX(), Size[1] - event.GetY() - 1);
615 //---------------------------------------------------------------------------
616 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
617 void wxVTKRenderWindowInteractor::OnEnter(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::EnterEvent, NULL);
632 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
633 event.GetX(), Size[1] - event.GetY() - 1);
636 //---------------------------------------------------------------------------
637 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
644 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
646 SetEventInformationFlipY(event.GetX(), event.GetY(),
647 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
649 InvokeEvent(vtkCommand::LeaveEvent, NULL);
652 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
653 event.GetX(), Size[1] - event.GetY() - 1);
656 //---------------------------------------------------------------------------
657 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
664 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
666 int keycode = event.GetKeyCode();
668 if (((unsigned int)keycode) < 256)
670 // TODO: Unicode in non-Unicode mode ??
674 // we don't get a valid mouse position inside the key event on every platform
675 // so we retrieve the mouse position explicitly and pass it along
676 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
677 SetEventInformationFlipY(mousePos.x, mousePos.y,
678 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
679 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
681 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
682 event.GetKeyCode(), 1);
686 //---------------------------------------------------------------------------
687 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
694 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
696 int keycode = event.GetKeyCode();
698 if (((unsigned int)keycode) < 256)
700 // TODO: Unicode in non-Unicode mode ??
704 // we don't get a valid mouse position inside the key event on every platform
705 // so we retrieve the mouse position explicitly and pass it along
706 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
707 SetEventInformationFlipY(mousePos.x, mousePos.y,
708 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
709 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
711 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
712 event.GetKeyCode(), 1);
716 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
717 //---------------------------------------------------------------------------
718 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
725 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
727 int keycode = event.GetKeyCode();
729 if (((unsigned int)keycode) < 256)
731 // TODO: Unicode in non-Unicode mode ??
735 // we don't get a valid mouse position inside the key event on every platform
736 // so we retrieve the mouse position explicitly and pass it along
737 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
738 SetEventInformationFlipY(mousePos.x, mousePos.y,
739 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
740 InvokeEvent(vtkCommand::CharEvent, NULL);
744 //---------------------------------------------------------------------------
745 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
747 if (!Enabled || (ActiveButton != wxEVT_NULL))
751 ActiveButton = event.GetEventType();
753 // On Mac (Carbon) and Windows we don't automatically get the focus when
754 // you click inside the window
755 // we therefore set the focus explicitly
756 // Apparently we need that on linux (GTK) too:
759 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
760 SetEventInformationFlipY(event.GetX(), event.GetY(),
761 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
764 if(event.RightDown())
766 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
768 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
771 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
772 event.GetX(), Size[1] - event.GetY() - 1);
775 else if(event.LeftDown())
777 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
779 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
782 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
783 event.GetX(), Size[1] - event.GetY() - 1);
786 else if(event.MiddleDown())
788 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
790 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
793 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
794 event.GetX(), Size[1] - event.GetY() - 1);
797 //save the button and capture mouse until the button is released
799 //1. it is possible (WX_USE_X_CAPTURE)
800 //2. user decided to.
801 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
806 //---------------------------------------------------------------------------
807 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
809 //EVT_xxx_DOWN == EVT_xxx_UP - 1
810 //This is only needed if two mouse buttons are pressed at the same time.
811 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
812 //wxEVT_COMMAND_RIGHT_CLICK
813 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
818 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
821 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
822 SetEventInformationFlipY(event.GetX(), event.GetY(),
823 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
826 if(ActiveButton == wxEVT_RIGHT_DOWN)
828 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
830 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
833 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
834 event.GetX(), Size[1] - event.GetY() - 1);
837 else if(ActiveButton == wxEVT_LEFT_DOWN)
839 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
841 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
844 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
845 event.GetX(), Size[1] - event.GetY() - 1);
848 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
850 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
852 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
855 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
856 event.GetX(), Size[1] - event.GetY() - 1);
859 //if the ActiveButton is realeased, then release mouse capture
860 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
864 ActiveButton = wxEVT_NULL;
866 //---------------------------------------------------------------------------
867 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
869 // Mouse wheel was only added after VTK 4.4 (I think...)
870 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
872 //Set vtk event information ... The numebr of wheel rotations is stored in
873 //the x varible. y varible is zero
874 SetEventInformationFlipY(event.GetX() , event.GetY(),
875 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
876 if(event.GetWheelRotation() > 0)
879 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
884 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
890 //---------------------------------------------------------------------------
891 #if wxCHECK_VERSION(2, 8, 0)
892 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
894 if (ActiveButton != wxEVT_NULL)
896 //Maybe also invoke the button release event here
898 // Reset ActiveButton so that
899 // 1. we do not process mouse button up events any more,
900 // 2. the next button down event will be processed and call CaptureMouse().
901 // Otherwise ReleaseMouse() will be called
902 // without a previous CaptureMouse().
903 ActiveButton = wxEVT_NULL;
907 //---------------------------------------------------------------------------
908 void wxVTKRenderWindowInteractor::Render()
910 printf("EED wxVTKRenderWindowInteractor::Render Start \n");
911 #if wxCHECK_VERSION(2, 8, 0)
912 int renderAllowed = !IsFrozen();
914 int renderAllowed = 1;
916 if (renderAllowed && !RenderWhenDisabled)
918 //the user doesn't want us to render when the toplevel frame
919 //is disabled - first find the top level parent
920 wxWindow *topParent = wxGetTopLevelParent(this);
923 //if it exists, check whether it's enabled
924 //if it's not enabeld, renderAllowed will be false
925 renderAllowed = topParent->IsEnabled();
931 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
932 wxGLCanvas::SetCurrent(*(this->context));
934 if(Handle && (Handle == GetHandleHack()) )
936 printf("EED wxVTKRenderWindowInteractor::Render 1 \n");
937 RenderWindow->Render();
938 printf("EED wxVTKRenderWindowInteractor::Render 2 \n");
940 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
941 else if(GetHandleHack())
943 //this means the user has reparented us; let's adapt to the
944 //new situation by doing the WindowRemap dance
945 //store the new situation
946 Handle = GetHandleHack();
947 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
948 RenderWindow->WindowRemap();
949 RenderWindow->Render();
953 printf("EED wxVTKRenderWindowInteractor::Render End \n");
957 //---------------------------------------------------------------------------
958 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
960 //Change value of __RenderWhenDisabled ivar.
961 //If __RenderWhenDisabled is false (the default), this widget will not
962 //call Render() on the RenderWindow if the top level frame (i.e. the
963 //containing frame) has been disabled.
965 //This prevents recursive rendering during wxSafeYield() calls.
966 //wxSafeYield() can be called during the ProgressMethod() callback of
967 //a VTK object to have progress bars and other GUI elements updated -
968 //it does this by disabling all windows (disallowing user-input to
969 //prevent re-entrancy of code) and then handling all outstanding
972 //However, this often triggers an OnPaint() method for wxVTKRWIs,
973 //resulting in a Render(), resulting in Update() being called whilst
976 RenderWhenDisabled = (bool)newValue;
978 //---------------------------------------------------------------------------
980 // Set the variable that indicates that we want a stereo capable window
981 // be created. This method can only be called before a window is realized.
983 void wxVTKRenderWindowInteractor::SetStereo(int capable)
985 if (Stereo != capable)
988 RenderWindow->StereoCapableWindowOn();
989 RenderWindow->SetStereoTypeToCrystalEyes();
994 //---------------------------------------------------------------------------
997 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
999 this->Superclass::PrintSelf(os, indent);
1004 // LG : EO namespace bbwxvtk
1005 //=======================================================================