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 =========================================================================*/
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__
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"
84 //=======================================================================
85 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
90 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
91 #if (!wxCHECK_VERSION(2, 4, 0))
92 wxWindow* wxGetTopLevelParent(wxWindow *win)
94 while ( win && !win->IsTopLevel() )
95 win = win->GetParent();
100 // LG : EO namespace bbwxvtk
101 //=======================================================================
103 // To access objc calls on cocoa
106 //EED #import <Cocoa/Cocoa.h>
107 // This trick is no longer need in VTK CVS, should get rid of that:
110 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
111 #endif //VTK_USE_COCOA
114 #if wxMAJOR_VERSION <= 2
117 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
118 #include "gdk/gdkprivate.h"
119 #if wxCHECK_VERSION(2, 9, 0)
120 // thanks to: http://thomasfischer.biz/?p=382
121 #include <gtk/gtkfixed.h>
122 #include <gtk/gtkwidget.h>
123 #include <wx/gtk/private/win_gtk.h>
124 #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
125 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
126 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
127 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
129 #if wxCHECK_VERSION(2, 8, 0)
131 #include <wx/gtk/win_gtk.h>
133 #include <wx/gtk1/win_gtk.h>
136 #include <wx/gtk/win_gtk.h>
139 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
140 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
141 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
147 #include <gdk/gdkx.h>
149 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
150 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) : \
151 GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
156 #include "wx/x11/privx.h"
157 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
160 //For more info on this class please go to:
161 //http://wxvtk.sf.net
162 //This hack is for some buggy wxGTK version:
163 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
164 # define WX_USE_X_CAPTURE 0
166 # define WX_USE_X_CAPTURE 1
169 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
171 //=======================================================================
172 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
176 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
180 //---------------------------------------------------------------------------
181 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
182 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
183 #if wxMAJOR_VERSION <= 2
184 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
185 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
187 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
188 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
191 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
192 #if wxMAJOR_VERSION <= 2
193 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
194 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
196 wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
197 wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
200 //refresh window by doing a Render
201 EVT_PAINT (wxVTKRenderWindowInteractor::OnPaint)
202 EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
203 EVT_MOTION (wxVTKRenderWindowInteractor::OnMotion)
205 //Bind the events to the event converters
206 EVT_LEFT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
207 EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
208 EVT_RIGHT_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
209 EVT_LEFT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
210 EVT_MIDDLE_UP (wxVTKRenderWindowInteractor::OnButtonUp)
211 EVT_RIGHT_UP (wxVTKRenderWindowInteractor::OnButtonUp)
212 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
213 EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
214 EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
215 EVT_MOUSEWHEEL (wxVTKRenderWindowInteractor::OnMouseWheel)
216 #if wxCHECK_VERSION(2, 8, 0)
217 EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
219 EVT_KEY_DOWN (wxVTKRenderWindowInteractor::OnKeyDown)
220 EVT_KEY_UP (wxVTKRenderWindowInteractor::OnKeyUp)
221 EVT_CHAR (wxVTKRenderWindowInteractor::OnChar)
223 EVT_TIMER (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
224 EVT_SIZE (wxVTKRenderWindowInteractor::OnSize)
227 //EED win Compilation why??: vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
228 vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
230 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
231 static int wxvtk_attributes[]={
240 //---------------------------------------------------------------------------
241 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
243 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
244 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
245 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")),
247 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes),
253 vtkRenderWindowInteractor()
254 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
255 , ActiveButton(wxEVT_NULL)
259 , RenderWhenDisabled(1)
262 #ifdef VTK_DEBUG_LEAKS
263 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
265 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
266 this->context = new wxGLContext(this);
268 this->RenderWindow = NULL;
269 this->SetRenderWindow(vtkRenderWindow::New());
270 this->RenderWindow->Delete();
272 //---------------------------------------------------------------------------
273 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
278 const wxString &name)
279 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
280 #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
281 : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
283 : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
286 : wxWindow(parent, id, pos, size, style, name)
288 , vtkRenderWindowInteractor()
289 , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
290 , ActiveButton(wxEVT_NULL)
294 , RenderWhenDisabled(1)
297 #ifdef VTK_DEBUG_LEAKS
298 vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
300 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
301 this->context = new wxGLContext(this);
303 this->RenderWindow = NULL;
304 this->SetRenderWindow(vtkRenderWindow::New());
305 this->RenderWindow->Delete();
307 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
308 // so we update the size information of the interactor/renderwindow here
309 this->UpdateSize(size.x, size.y);
312 //---------------------------------------------------------------------------
313 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
315 SetRenderWindow(NULL);
316 SetInteractorStyle(NULL);
317 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
318 delete this->context;
321 //---------------------------------------------------------------------------
322 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
324 // we don't make use of the objectfactory, because we're not registered
325 return new wxVTKRenderWindowInteractor;
327 //---------------------------------------------------------------------------
328 void wxVTKRenderWindowInteractor::Initialize()
330 int *size = RenderWindow->GetSize();
331 // enable everything and start rendering
333 //RenderWindow->Start();
335 // set the size in the render window interactor
339 // this is initialized
342 //---------------------------------------------------------------------------
343 void wxVTKRenderWindowInteractor::Enable()
345 // if already enabled then done
351 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
352 wxGLCanvas::SetCurrent(*this->context);
356 //---------------------------------------------------------------------------
357 bool wxVTKRenderWindowInteractor::Enable(bool enable)
359 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
360 return wxGLCanvas::Enable(enable);
362 return wxWindow::Enable(enable);
365 //---------------------------------------------------------------------------
366 void wxVTKRenderWindowInteractor::Disable()
368 // if already disabled then done
372 // that's it (we can't remove the event handler like it should be...)
376 //---------------------------------------------------------------------------
377 void wxVTKRenderWindowInteractor::Start()
379 // the interactor cannot control the event loop
380 vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
381 "interactor cannot control event loop.");
383 //---------------------------------------------------------------------------
384 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
388 // if the size changed tell render window
389 if ( x != Size[0] || y != Size[1] )
391 // adjust our (vtkRenderWindowInteractor size)
394 // and our RenderWindow's size
395 RenderWindow->SetSize(x, y);
396 #if defined(__WXMSW__)
402 //---------------------------------------------------------------------------
403 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
405 // it's a one shot timer
406 if (!timer.Start(10, TRUE))
412 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
413 //------------------------------------------------------------------
414 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
415 unsigned long duration)
417 if (!timer.Start(duration, timerType == OneShotTimer))
420 return ID_wxVTKRenderWindowInteractor_TIMER;
422 //------------------------------------------------------------------
423 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
429 //---------------------------------------------------------------------------
430 int wxVTKRenderWindowInteractor::DestroyTimer()
435 //---------------------------------------------------------------------------
436 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
441 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
443 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
444 // pass the right timer id
445 int timerId = this->GetCurrentTimerId();
446 this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
448 this->InvokeEvent(vtkCommand::TimerEvent, NULL);
452 InteractorStyle->OnTimer();
456 //---------------------------------------------------------------------------
457 // NOTE on implementation:
458 // Bad luck you ended up in the only tricky place of this code.
459 // A few note, wxWidgets still refuse to provide such convenient method
460 // so I have to maintain it myself, eventhough this is completely integrated
462 // Anyway if this happen to break for you then compare to a recent version of wxPython
463 // and look for the function long wxPyGetWinHandle(wxWindow* win)
464 // in wxPython/src/helpers.cpp
465 long wxVTKRenderWindowInteractor::GetHandleHack()
467 printf("EED wxVTKRenderWindowInteractor::GetHandleHack start \n");
468 //helper function to hide the MSW vs GTK stuff
471 // __WXMSW__ is for Win32
472 // __WXMAC__ is for Carbon or Cocoa builds
473 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
474 #if defined(__WXMSW__) || defined(__WXMAC__)
475 handle_tmp = (long)this->GetHandle();
478 // using above GetHandle() works fine with wxOSX 2.9.x
479 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
480 // Here is how to find the NSWindow
481 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
482 if (toplevel != NULL )
484 handle_tmp = (long)toplevel->GetNSWindow();
486 // The NSView will be deducted from
487 // [(NSWindow*)Handle contentView]
488 // if only I knew how to write that in c++
489 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
491 // Find and return the actual X-Window.
492 #if defined(__WXGTK__) || defined(__WXX11__)
493 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", handle_tmp);
494 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", (long)GetXWindow(this));
495 return (long)GetXWindow(this);
499 // handle_tmp = (long)this->GetXWindow();
502 printf("EED wxVTKRenderWindowInteractor::GetHandleHack End BBB handle_tmp %d \n", handle_tmp);
505 //---------------------------------------------------------------------------
506 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
508 //must always be here
511 //do it here rather than in the cstor: this is safer.
514 Handle = GetHandleHack();
517 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
518 NSView *nvsview = (NSView* )Handle;
519 NSWindow *nswindow = nvsview.window;
520 rwin->SetRootWindow( nswindow );
521 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
523 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
529 // this->GetNSView() <-> DisplayId
530 // this->GetTopLevel()->GetNSWindow() <-> WindowId
532 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
535 // This is another hack to prevent the VTK Render Window from closing the display.
536 // If VTK closes the display, ~wxContext chashes while trying to destroy its
537 // glContext (because the display is closed). The Get -> Set makes this VTK
538 // object think someone else is responsible for the display.
540 // avoid "Method not implemented" messages in Console
542 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
545 // get vtk to render to the wxWindows
548 // This solves a problem with repainting after a window resize
549 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
551 #if !wxCHECK_VERSION(2, 9, 0)
552 // this doesn't seem necessary with wxOSX 2.9.x
553 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
556 rwin->UpdateContext();
560 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
563 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
564 // Must be somewhere after VTK 4.4
565 rwin->UpdateGLRegion();
571 //---------------------------------------------------------------------------
572 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
574 //turn off background erase to reduce flickering on MSW
577 //---------------------------------------------------------------------------
578 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
581 GetClientSize(&w, &h);
589 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
590 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
592 //this will check for Handle
595 //---------------------------------------------------------------------------
596 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
602 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
603 SetEventInformationFlipY(event.GetX(), event.GetY(),
604 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
606 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
608 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
609 event.GetX(), Size[1] - event.GetY() - 1);
612 //---------------------------------------------------------------------------
613 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
614 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
621 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
623 SetEventInformationFlipY(event.GetX(), event.GetY(),
624 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
626 InvokeEvent(vtkCommand::EnterEvent, NULL);
629 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
630 event.GetX(), Size[1] - event.GetY() - 1);
633 //---------------------------------------------------------------------------
634 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
641 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
643 SetEventInformationFlipY(event.GetX(), event.GetY(),
644 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
646 InvokeEvent(vtkCommand::LeaveEvent, NULL);
649 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
650 event.GetX(), Size[1] - event.GetY() - 1);
653 //---------------------------------------------------------------------------
654 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
661 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
663 int keycode = event.GetKeyCode();
665 if (((unsigned int)keycode) < 256)
667 // TODO: Unicode in non-Unicode mode ??
671 // we don't get a valid mouse position inside the key event on every platform
672 // so we retrieve the mouse position explicitly and pass it along
673 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
674 SetEventInformationFlipY(mousePos.x, mousePos.y,
675 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
676 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
678 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
679 event.GetKeyCode(), 1);
683 //---------------------------------------------------------------------------
684 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
691 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
693 int keycode = event.GetKeyCode();
695 if (((unsigned int)keycode) < 256)
697 // TODO: Unicode in non-Unicode mode ??
701 // we don't get a valid mouse position inside the key event on every platform
702 // so we retrieve the mouse position explicitly and pass it along
703 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
704 SetEventInformationFlipY(mousePos.x, mousePos.y,
705 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
706 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
708 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
709 event.GetKeyCode(), 1);
713 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
714 //---------------------------------------------------------------------------
715 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
722 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
724 int keycode = event.GetKeyCode();
726 if (((unsigned int)keycode) < 256)
728 // TODO: Unicode in non-Unicode mode ??
732 // we don't get a valid mouse position inside the key event on every platform
733 // so we retrieve the mouse position explicitly and pass it along
734 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
735 SetEventInformationFlipY(mousePos.x, mousePos.y,
736 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
737 InvokeEvent(vtkCommand::CharEvent, NULL);
741 //---------------------------------------------------------------------------
742 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
744 if (!Enabled || (ActiveButton != wxEVT_NULL))
748 ActiveButton = event.GetEventType();
750 // On Mac (Carbon) and Windows we don't automatically get the focus when
751 // you click inside the window
752 // we therefore set the focus explicitly
753 // Apparently we need that on linux (GTK) too:
756 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
757 SetEventInformationFlipY(event.GetX(), event.GetY(),
758 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
761 if(event.RightDown())
763 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
765 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
768 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
769 event.GetX(), Size[1] - event.GetY() - 1);
772 else if(event.LeftDown())
774 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
776 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
779 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
780 event.GetX(), Size[1] - event.GetY() - 1);
783 else if(event.MiddleDown())
785 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
787 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
790 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
791 event.GetX(), Size[1] - event.GetY() - 1);
794 //save the button and capture mouse until the button is released
796 //1. it is possible (WX_USE_X_CAPTURE)
797 //2. user decided to.
798 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
803 //---------------------------------------------------------------------------
804 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
806 //EVT_xxx_DOWN == EVT_xxx_UP - 1
807 //This is only needed if two mouse buttons are pressed at the same time.
808 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
809 //wxEVT_COMMAND_RIGHT_CLICK
810 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
815 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
818 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
819 SetEventInformationFlipY(event.GetX(), event.GetY(),
820 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
823 if(ActiveButton == wxEVT_RIGHT_DOWN)
825 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
827 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
830 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
831 event.GetX(), Size[1] - event.GetY() - 1);
834 else if(ActiveButton == wxEVT_LEFT_DOWN)
836 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
838 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
841 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
842 event.GetX(), Size[1] - event.GetY() - 1);
845 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
847 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
849 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
852 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
853 event.GetX(), Size[1] - event.GetY() - 1);
856 //if the ActiveButton is realeased, then release mouse capture
857 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
861 ActiveButton = wxEVT_NULL;
863 //---------------------------------------------------------------------------
864 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
866 // Mouse wheel was only added after VTK 4.4 (I think...)
867 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
869 //Set vtk event information ... The numebr of wheel rotations is stored in
870 //the x varible. y varible is zero
871 SetEventInformationFlipY(event.GetX() , event.GetY(),
872 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
873 if(event.GetWheelRotation() > 0)
876 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
881 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
887 //---------------------------------------------------------------------------
888 #if wxCHECK_VERSION(2, 8, 0)
889 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
891 if (ActiveButton != wxEVT_NULL)
893 //Maybe also invoke the button release event here
895 // Reset ActiveButton so that
896 // 1. we do not process mouse button up events any more,
897 // 2. the next button down event will be processed and call CaptureMouse().
898 // Otherwise ReleaseMouse() will be called
899 // without a previous CaptureMouse().
900 ActiveButton = wxEVT_NULL;
904 //---------------------------------------------------------------------------
905 void wxVTKRenderWindowInteractor::Render()
907 printf("EED wxVTKRenderWindowInteractor::Render Start \n");
908 #if wxCHECK_VERSION(2, 8, 0)
909 int renderAllowed = !IsFrozen();
911 int renderAllowed = 1;
913 if (renderAllowed && !RenderWhenDisabled)
915 //the user doesn't want us to render when the toplevel frame
916 //is disabled - first find the top level parent
917 wxWindow *topParent = wxGetTopLevelParent(this);
920 //if it exists, check whether it's enabled
921 //if it's not enabeld, renderAllowed will be false
922 renderAllowed = topParent->IsEnabled();
928 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
929 wxGLCanvas::SetCurrent(*(this->context));
931 if(Handle && (Handle == GetHandleHack()) )
933 printf("EED wxVTKRenderWindowInteractor::Render 1 \n");
934 RenderWindow->Render();
935 printf("EED wxVTKRenderWindowInteractor::Render 2 \n");
937 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
938 else if(GetHandleHack())
940 //this means the user has reparented us; let's adapt to the
941 //new situation by doing the WindowRemap dance
942 //store the new situation
943 Handle = GetHandleHack();
944 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
945 RenderWindow->WindowRemap();
946 RenderWindow->Render();
950 printf("EED wxVTKRenderWindowInteractor::Render End \n");
954 //---------------------------------------------------------------------------
955 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
957 //Change value of __RenderWhenDisabled ivar.
958 //If __RenderWhenDisabled is false (the default), this widget will not
959 //call Render() on the RenderWindow if the top level frame (i.e. the
960 //containing frame) has been disabled.
962 //This prevents recursive rendering during wxSafeYield() calls.
963 //wxSafeYield() can be called during the ProgressMethod() callback of
964 //a VTK object to have progress bars and other GUI elements updated -
965 //it does this by disabling all windows (disallowing user-input to
966 //prevent re-entrancy of code) and then handling all outstanding
969 //However, this often triggers an OnPaint() method for wxVTKRWIs,
970 //resulting in a Render(), resulting in Update() being called whilst
973 RenderWhenDisabled = (bool)newValue;
975 //---------------------------------------------------------------------------
977 // Set the variable that indicates that we want a stereo capable window
978 // be created. This method can only be called before a window is realized.
980 void wxVTKRenderWindowInteractor::SetStereo(int capable)
982 if (Stereo != capable)
985 RenderWindow->StereoCapableWindowOn();
986 RenderWindow->SetStereoTypeToCrystalEyes();
991 //---------------------------------------------------------------------------
994 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
996 this->Superclass::PrintSelf(os, indent);
1001 // LG : EO namespace bbwxvtk
1002 //=======================================================================