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 =========================================================================*/
47 //#import <Cocoa/Cocoa.h>
52 #include "creawxVTKRenderWindowInteractor.h"
54 //This is needed for vtk 3.1 :
55 #ifndef VTK_MAJOR_VERSION
56 # include "vtkVersion.h"
59 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
60 # include "vtkCommand.h"
62 # include "vtkInteractorStyle.h"
64 #include "vtkDebugLeaks.h"
66 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
67 #ifdef __WXOSX_COCOA__
71 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
72 // ControlDown has been changed to mean Command key down
73 #define ControlDown RawControlDown
78 #include "vtkCocoaRenderWindow.h"
80 #include "vtkCarbonRenderWindow.h"
85 //=======================================================================
86 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
91 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
92 #if (!wxCHECK_VERSION(2, 4, 0))
93 wxWindow* wxGetTopLevelParent(wxWindow *win)
95 while ( win && !win->IsTopLevel() )
96 win = win->GetParent();
101 // LG : EO namespace bbwxvtk
102 //=======================================================================
104 // To access objc calls on cocoa
107 //EED #import <Cocoa/Cocoa.h>
108 // This trick is no longer need in VTK CVS, should get rid of that:
111 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
112 #endif //VTK_USE_COCOA
115 #if wxMAJOR_VERSION <= 2
118 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
119 #include "gdk/gdkprivate.h"
120 #if wxCHECK_VERSION(2, 9, 0)
121 // thanks to: http://thomasfischer.biz/?p=382
122 #include <gtk/gtkfixed.h>
123 #include <gtk/gtkwidget.h>
124 #include <wx/gtk/private/win_gtk.h>
125 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
126 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
127 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
128 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
130 #if wxCHECK_VERSION(2, 8, 0)
132 #include <wx/gtk/win_gtk.h>
134 #include <wx/gtk1/win_gtk.h>
137 #include <wx/gtk/win_gtk.h>
140 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
141 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
142 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
148 #include <gdk/gdkx.h>
150 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
151 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
152 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
157 #include "wx/x11/privx.h"
158 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
161 //For more info on this class please go to:
162 //http://wxvtk.sf.net
163 //This hack is for some buggy wxGTK version:
164 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
165 # define WX_USE_X_CAPTURE 0
167 # define WX_USE_X_CAPTURE 1
170 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
172 //=======================================================================
173 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
177 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
181 //---------------------------------------------------------------------------
182 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
183 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
184 #if wxMAJOR_VERSION <= 2
185 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
186 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
188 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
189 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
192 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
193 #if wxMAJOR_VERSION <= 2
194 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
195 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
197 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
198 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
201 //refresh window by doing a Render
202 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
203 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
204 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
206 //Bind the events to the event converters
207 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
208 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
209 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
210 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
211 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
212 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
213 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
214 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
215 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
216 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
217 #if wxCHECK_VERSION(2, 8, 0)
218 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
220 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
221 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
222 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
224 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
225 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
228 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
231 #if VTK_MAJOR_VERSION < 8
232 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
235 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
236 static int wxvtk_attributes[]={
245 //---------------------------------------------------------------------------
246 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
248 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
249 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
250 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
252 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
258 vtkRenderWindowInteractor()
259 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
260 , ActiveButton(wxEVT_NULL)
264 , RenderWhenDisabled(1)
267 #ifdef VTK_DEBUG_LEAKS
268 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
270 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
271 this->context = new wxGLContext(this);
273 this->RenderWindow = NULL;
274 this->SetRenderWindow(vtkRenderWindow::New());
275 this->RenderWindow->Delete();
277 //---------------------------------------------------------------------------
278 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
283 const wxString &name)
284 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
285 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
286 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
288 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
291 : wxWindow(parent, id, pos, size, style, name)
293 , vtkRenderWindowInteractor()
294 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
295 , ActiveButton(wxEVT_NULL)
299 , RenderWhenDisabled(1)
302 #ifdef VTK_DEBUG_LEAKS
303 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
305 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
306 this->context = new wxGLContext(this);
308 this->RenderWindow = NULL;
309 this->SetRenderWindow(vtkRenderWindow::New());
310 this->RenderWindow->Delete();
312 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
313 // so we update the size information of the interactor/renderwindow here
314 this->UpdateSize(size.x, size.y);
317 //---------------------------------------------------------------------------
318 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
320 SetRenderWindow(NULL);
321 SetInteractorStyle(NULL);
322 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
323 delete this->context;
326 //---------------------------------------------------------------------------
327 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
329 // we don't make use of the objectfactory, because we're not registered
330 return new wxVTKRenderWindowInteractor;
332 //---------------------------------------------------------------------------
333 void wxVTKRenderWindowInteractor::Initialize()
335 int *size = RenderWindow->GetSize();
336 // enable everything and start rendering
338 //RenderWindow->Start();
340 // set the size in the render window interactor
344 // this is initialized
347 //---------------------------------------------------------------------------
348 void wxVTKRenderWindowInteractor::Enable()
350 // if already enabled then done
356 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
357 wxGLCanvas::SetCurrent(*this->context);
361 //---------------------------------------------------------------------------
362 bool wxVTKRenderWindowInteractor::Enable(bool enable)
364 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
365 return wxGLCanvas::Enable(enable);
367 return wxWindow::Enable(enable);
370 //---------------------------------------------------------------------------
371 void wxVTKRenderWindowInteractor::Disable()
373 // if already disabled then done
377 // that's it (we can't remove the event handler like it should be...)
381 //---------------------------------------------------------------------------
382 void wxVTKRenderWindowInteractor::Start()
384 // the interactor cannot control the event loop
385 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
386 "interactor cannot control event loop.");
388 //---------------------------------------------------------------------------
389 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
393 // if the size changed tell render window
394 if ( x != Size[0] || y != Size[1] )
396 // adjust our (vtkRenderWindowInteractor size)
399 // and our RenderWindow's size
400 RenderWindow->SetSize(x, y);
401 #if defined(__WXMSW__)
407 //---------------------------------------------------------------------------
408 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
410 // it's a one shot timer
411 if (!timer.Start(10, TRUE))
417 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
418 //------------------------------------------------------------------
419 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
420 unsigned long duration)
422 if (!timer.Start(duration, timerType == OneShotTimer))
425 return ID_wxVTKRenderWindowInteractor_TIMER;
427 //------------------------------------------------------------------
428 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
434 //---------------------------------------------------------------------------
435 int wxVTKRenderWindowInteractor::DestroyTimer()
440 //---------------------------------------------------------------------------
441 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
446 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
448 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
449 // pass the right timer id
450 int timerId = this->GetCurrentTimerId();
451 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
453 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
457 InteractorStyle->OnTimer();
461 //---------------------------------------------------------------------------
462 // NOTE on implementation:
463 // Bad luck you ended up in the only tricky place of this code.
464 // A few note, wxWidgets still refuse to provide such convenient method
465 // so I have to maintain it myself, eventhough this is completely integrated
467 // Anyway if this happen to break for you then compare to a recent version of wxPython
468 // and look for the function long wxPyGetWinHandle(wxWindow* win)
469 // in wxPython/src/helpers.cpp
470 long wxVTKRenderWindowInteractor::GetHandleHack()
472 printf("EED wxVTKRenderWindowInteractor::GetHandleHack start \n");
473 //helper function to hide the MSW vs GTK stuff
476 // __WXMSW__ is for Win32
477 // __WXMAC__ is for Carbon or Cocoa builds
478 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
479 #if defined(__WXMSW__) || defined(__WXMAC__)
480 handle_tmp = (long)this->GetHandle();
483 // using above GetHandle() works fine with wxOSX 2.9.x
484 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
485 // Here is how to find the NSWindow
486 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
487 if (toplevel != NULL )
489 handle_tmp = (long)toplevel->GetNSWindow();
491 // The NSView will be deducted from
492 // [(NSWindow*)Handle contentView]
493 // if only I knew how to write that in c++
494 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
496 // Find and return the actual X-Window.
497 #if defined(__WXGTK__) || defined(__WXX11__)
498 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", handle_tmp);
499 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", (long)GetXWindow(this));
500 return (long)GetXWindow(this);
504 // handle_tmp = (long)this->GetXWindow();
507 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End BBB handle_tmp %ld \n", handle_tmp);
510 //---------------------------------------------------------------------------
511 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
513 //must always be here
516 //do it here rather than in the cstor: this is safer.
519 Handle = GetHandleHack();
522 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
523 NSView *nvsview = (NSView* )Handle;
524 NSWindow *nswindow = nvsview.window;
525 rwin->SetRootWindow( nswindow );
526 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
528 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
534 // this->GetNSView() <-> DisplayId
535 // this->GetTopLevel()->GetNSWindow() <-> WindowId
537 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
540 // This is another hack to prevent the VTK Render Window from closing the display.
541 // If VTK closes the display, ~wxContext chashes while trying to destroy its
542 // glContext (because the display is closed). The Get -> Set makes this VTK
543 // object think someone else is responsible for the display.
545 // avoid "Method not implemented" messages in Console
547 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
550 // get vtk to render to the wxWindows
553 // This solves a problem with repainting after a window resize
554 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
556 #if !wxCHECK_VERSION(2, 9, 0)
557 // this doesn't seem necessary with wxOSX 2.9.x
558 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
561 rwin->UpdateContext();
565 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
568 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
569 // Must be somewhere after VTK 4.4
570 rwin->UpdateGLRegion();
576 //---------------------------------------------------------------------------
577 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
579 //turn off background erase to reduce flickering on MSW
582 //---------------------------------------------------------------------------
583 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
586 GetClientSize(&w, &h);
594 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
595 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
597 //this will check for Handle
600 //---------------------------------------------------------------------------
601 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
607 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
608 SetEventInformationFlipY(event.GetX(), event.GetY(),
609 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
611 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
613 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
614 event.GetX(), Size[1] - event.GetY() - 1);
617 //---------------------------------------------------------------------------
618 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
619 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
626 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
628 SetEventInformationFlipY(event.GetX(), event.GetY(),
629 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
631 InvokeEvent(vtkCommand::EnterEvent, NULL);
634 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
635 event.GetX(), Size[1] - event.GetY() - 1);
638 //---------------------------------------------------------------------------
639 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
646 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
648 SetEventInformationFlipY(event.GetX(), event.GetY(),
649 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
651 InvokeEvent(vtkCommand::LeaveEvent, NULL);
654 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
655 event.GetX(), Size[1] - event.GetY() - 1);
658 //---------------------------------------------------------------------------
659 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
666 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
668 int keycode = event.GetKeyCode();
670 if (((unsigned int)keycode) < 256)
672 // TODO: Unicode in non-Unicode mode ??
676 // we don't get a valid mouse position inside the key event on every platform
677 // so we retrieve the mouse position explicitly and pass it along
678 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
679 SetEventInformationFlipY(mousePos.x, mousePos.y,
680 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
681 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
683 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
684 event.GetKeyCode(), 1);
688 //---------------------------------------------------------------------------
689 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
696 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
698 int keycode = event.GetKeyCode();
700 if (((unsigned int)keycode) < 256)
702 // TODO: Unicode in non-Unicode mode ??
706 // we don't get a valid mouse position inside the key event on every platform
707 // so we retrieve the mouse position explicitly and pass it along
708 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
709 SetEventInformationFlipY(mousePos.x, mousePos.y,
710 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
711 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
713 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
714 event.GetKeyCode(), 1);
718 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
719 //---------------------------------------------------------------------------
720 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
727 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
729 int keycode = event.GetKeyCode();
731 if (((unsigned int)keycode) < 256)
733 // TODO: Unicode in non-Unicode mode ??
737 // we don't get a valid mouse position inside the key event on every platform
738 // so we retrieve the mouse position explicitly and pass it along
739 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
740 SetEventInformationFlipY(mousePos.x, mousePos.y,
741 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
742 InvokeEvent(vtkCommand::CharEvent, NULL);
746 //---------------------------------------------------------------------------
747 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
749 if (!Enabled || (ActiveButton != wxEVT_NULL))
753 ActiveButton = event.GetEventType();
755 // On Mac (Carbon) and Windows we don't automatically get the focus when
756 // you click inside the window
757 // we therefore set the focus explicitly
758 // Apparently we need that on linux (GTK) too:
761 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
762 SetEventInformationFlipY(event.GetX(), event.GetY(),
763 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
766 if(event.RightDown())
768 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
770 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
773 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
774 event.GetX(), Size[1] - event.GetY() - 1);
777 else if(event.LeftDown())
779 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
781 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
784 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
785 event.GetX(), Size[1] - event.GetY() - 1);
788 else if(event.MiddleDown())
790 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
792 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
795 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
796 event.GetX(), Size[1] - event.GetY() - 1);
799 //save the button and capture mouse until the button is released
801 //1. it is possible (WX_USE_X_CAPTURE)
802 //2. user decided to.
803 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
808 //---------------------------------------------------------------------------
809 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
811 //EVT_xxx_DOWN == EVT_xxx_UP - 1
812 //This is only needed if two mouse buttons are pressed at the same time.
813 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
814 //wxEVT_COMMAND_RIGHT_CLICK
815 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
820 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
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(ActiveButton == wxEVT_RIGHT_DOWN)
830 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
832 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
835 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
836 event.GetX(), Size[1] - event.GetY() - 1);
839 else if(ActiveButton == wxEVT_LEFT_DOWN)
841 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
843 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
846 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
847 event.GetX(), Size[1] - event.GetY() - 1);
850 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
852 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
854 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
857 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
858 event.GetX(), Size[1] - event.GetY() - 1);
861 //if the ActiveButton is realeased, then release mouse capture
862 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
866 ActiveButton = wxEVT_NULL;
868 //---------------------------------------------------------------------------
869 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
871 // Mouse wheel was only added after VTK 4.4 (I think...)
872 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
874 //Set vtk event information ... The numebr of wheel rotations is stored in
875 //the x varible. y varible is zero
876 SetEventInformationFlipY(event.GetX() , event.GetY(),
877 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
878 if(event.GetWheelRotation() > 0)
881 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
886 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
892 //---------------------------------------------------------------------------
893 #if wxCHECK_VERSION(2, 8, 0)
894 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
896 if (ActiveButton != wxEVT_NULL)
898 //Maybe also invoke the button release event here
900 // Reset ActiveButton so that
901 // 1. we do not process mouse button up events any more,
902 // 2. the next button down event will be processed and call CaptureMouse().
903 // Otherwise ReleaseMouse() will be called
904 // without a previous CaptureMouse().
905 ActiveButton = wxEVT_NULL;
909 //---------------------------------------------------------------------------
910 void wxVTKRenderWindowInteractor::Render()
912 printf("EED wxVTKRenderWindowInteractor::Render Start \n");
913 #if wxCHECK_VERSION(2, 8, 0)
914 int renderAllowed = !IsFrozen();
916 int renderAllowed = 1;
918 if (renderAllowed && !RenderWhenDisabled)
920 //the user doesn't want us to render when the toplevel frame
921 //is disabled - first find the top level parent
922 wxWindow *topParent = wxGetTopLevelParent(this);
925 //if it exists, check whether it's enabled
926 //if it's not enabeld, renderAllowed will be false
927 renderAllowed = topParent->IsEnabled();
933 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
934 wxGLCanvas::SetCurrent(*(this->context));
936 if(Handle && (Handle == GetHandleHack()) )
938 printf("EED wxVTKRenderWindowInteractor::Render 1 \n");
939 RenderWindow->Render();
940 printf("EED wxVTKRenderWindowInteractor::Render 2 \n");
942 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
943 else if(GetHandleHack())
945 //this means the user has reparented us; let's adapt to the
946 //new situation by doing the WindowRemap dance
947 //store the new situation
948 Handle = GetHandleHack();
949 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
950 RenderWindow->WindowRemap();
951 RenderWindow->Render();
955 printf("EED wxVTKRenderWindowInteractor::Render End \n");
959 //---------------------------------------------------------------------------
960 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
962 //Change value of __RenderWhenDisabled ivar.
963 //If __RenderWhenDisabled is false (the default), this widget will not
964 //call Render() on the RenderWindow if the top level frame (i.e. the
965 //containing frame) has been disabled.
967 //This prevents recursive rendering during wxSafeYield() calls.
968 //wxSafeYield() can be called during the ProgressMethod() callback of
969 //a VTK object to have progress bars and other GUI elements updated -
970 //it does this by disabling all windows (disallowing user-input to
971 //prevent re-entrancy of code) and then handling all outstanding
974 //However, this often triggers an OnPaint() method for wxVTKRWIs,
975 //resulting in a Render(), resulting in Update() being called whilst
978 RenderWhenDisabled = (bool)newValue;
980 //---------------------------------------------------------------------------
982 // Set the variable that indicates that we want a stereo capable window
983 // be created. This method can only be called before a window is realized.
985 void wxVTKRenderWindowInteractor::SetStereo(int capable)
987 if (Stereo != capable)
990 RenderWindow->StereoCapableWindowOn();
991 RenderWindow->SetStereoTypeToCrystalEyes();
996 //---------------------------------------------------------------------------
999 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1001 this->Superclass::PrintSelf(os, indent);
1006 // LG : EO namespace bbwxvtk
1007 //=======================================================================