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))
512 printf("EED wxVTKRenderWindowInteractor::OnPaint Start \n");
513 //must always be here
514 //EED2021-08-26 wxPaintDC pDC(this);
516 printf("EED wxVTKRenderWindowInteractor::OnPaint 1 \n");
518 //do it here rather than in the cstor: this is safer.
521 printf("EED wxVTKRenderWindowInteractor::OnPaint 2 \n");
522 Handle = GetHandleHack();
525 printf("EED wxVTKRenderWindowInteractor::OnPaint 3 \n");
526 vtkCocoaRenderWindow *rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
527 NSView *nvsview = (NSView* )Handle;
528 NSWindow *nswindow = nvsview.window;
529 rwin->SetRootWindow( nswindow );
530 rwin->SetWindowId( reinterpret_cast<void *>(nvsview) );
532 printf("EED wxVTKRenderWindowInteractor::OnPaint 4 \n");
533 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
537 printf("EED wxVTKRenderWindowInteractor::OnPaint 5 \n");
540 // this->GetNSView() <-> DisplayId
541 // this->GetTopLevel()->GetNSWindow() <-> WindowId
543 printf("EED wxVTKRenderWindowInteractor::OnPaint 6 \n");
544 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
547 // This is another hack to prevent the VTK Render Window from closing the display.
548 // If VTK closes the display, ~wxContext chashes while trying to destroy its
549 // glContext (because the display is closed). The Get -> Set makes this VTK
550 // object think someone else is responsible for the display.
552 // avoid "Method not implemented" messages in Console
554 this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
557 // get vtk to render to the wxWindows
559 printf("EED wxVTKRenderWindowInteractor::OnPaint 7 \n");
563 printf("EED wxVTKRenderWindowInteractor::OnPaint 8 \n");
564 // This solves a problem with repainting after a window resize
565 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
567 printf("EED wxVTKRenderWindowInteractor::OnPaint 9 \n");
568 #if !wxCHECK_VERSION(2, 9, 0)
569 // this doesn't seem necessary with wxOSX 2.9.x
570 printf("EED wxVTKRenderWindowInteractor::OnPaint 10 \n");
571 vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
574 printf("EED wxVTKRenderWindowInteractor::OnPaint 11 \n");
575 rwin->UpdateContext();
579 printf("EED wxVTKRenderWindowInteractor::OnPaint 12 \n");
580 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
583 printf("EED wxVTKRenderWindowInteractor::OnPaint 13 \n");
584 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
585 // Must be somewhere after VTK 4.4
586 printf("EED wxVTKRenderWindowInteractor::OnPaint 14 \n");
587 rwin->UpdateGLRegion();
593 printf("EED wxVTKRenderWindowInteractor::OnPaint 15 \n");
595 printf("EED wxVTKRenderWindowInteractor::OnPaint End \n");
598 //---------------------------------------------------------------------------
599 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
601 //turn off background erase to reduce flickering on MSW
604 //---------------------------------------------------------------------------
605 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
608 GetClientSize(&w, &h);
616 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
617 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
619 //this will check for Handle
622 //---------------------------------------------------------------------------
623 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
629 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
630 SetEventInformationFlipY(event.GetX(), event.GetY(),
631 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
633 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
635 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
636 event.GetX(), Size[1] - event.GetY() - 1);
639 //---------------------------------------------------------------------------
640 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
641 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
648 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
650 SetEventInformationFlipY(event.GetX(), event.GetY(),
651 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
653 InvokeEvent(vtkCommand::EnterEvent, NULL);
656 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
657 event.GetX(), Size[1] - event.GetY() - 1);
660 //---------------------------------------------------------------------------
661 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
668 #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::LeaveEvent, NULL);
676 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
677 event.GetX(), Size[1] - event.GetY() - 1);
680 //---------------------------------------------------------------------------
681 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
688 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
690 int keycode = event.GetKeyCode();
692 if (((unsigned int)keycode) < 256)
694 // TODO: Unicode in non-Unicode mode ??
698 // we don't get a valid mouse position inside the key event on every platform
699 // so we retrieve the mouse position explicitly and pass it along
700 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
701 SetEventInformationFlipY(mousePos.x, mousePos.y,
702 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
703 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
705 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
706 event.GetKeyCode(), 1);
710 //---------------------------------------------------------------------------
711 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
718 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
720 int keycode = event.GetKeyCode();
722 if (((unsigned int)keycode) < 256)
724 // TODO: Unicode in non-Unicode mode ??
728 // we don't get a valid mouse position inside the key event on every platform
729 // so we retrieve the mouse position explicitly and pass it along
730 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
731 SetEventInformationFlipY(mousePos.x, mousePos.y,
732 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
733 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
735 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
736 event.GetKeyCode(), 1);
740 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
741 //---------------------------------------------------------------------------
742 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
749 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
751 int keycode = event.GetKeyCode();
753 if (((unsigned int)keycode) < 256)
755 // TODO: Unicode in non-Unicode mode ??
759 // we don't get a valid mouse position inside the key event on every platform
760 // so we retrieve the mouse position explicitly and pass it along
761 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
762 SetEventInformationFlipY(mousePos.x, mousePos.y,
763 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
764 InvokeEvent(vtkCommand::CharEvent, NULL);
768 //---------------------------------------------------------------------------
769 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
771 if (!Enabled || (ActiveButton != wxEVT_NULL))
775 ActiveButton = event.GetEventType();
777 // On Mac (Carbon) and Windows we don't automatically get the focus when
778 // you click inside the window
779 // we therefore set the focus explicitly
780 // Apparently we need that on linux (GTK) too:
783 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
784 SetEventInformationFlipY(event.GetX(), event.GetY(),
785 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
788 if(event.RightDown())
790 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
792 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
795 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
796 event.GetX(), Size[1] - event.GetY() - 1);
799 else if(event.LeftDown())
801 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
803 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
806 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
807 event.GetX(), Size[1] - event.GetY() - 1);
810 else if(event.MiddleDown())
812 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
814 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
817 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
818 event.GetX(), Size[1] - event.GetY() - 1);
821 //save the button and capture mouse until the button is released
823 //1. it is possible (WX_USE_X_CAPTURE)
824 //2. user decided to.
825 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
830 //---------------------------------------------------------------------------
831 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
833 //EVT_xxx_DOWN == EVT_xxx_UP - 1
834 //This is only needed if two mouse buttons are pressed at the same time.
835 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
836 //wxEVT_COMMAND_RIGHT_CLICK
837 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
842 // See report by Shang Mu / Kerry Loux on wxVTK mailing list
845 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
846 SetEventInformationFlipY(event.GetX(), event.GetY(),
847 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
850 if(ActiveButton == wxEVT_RIGHT_DOWN)
852 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
854 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
857 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
858 event.GetX(), Size[1] - event.GetY() - 1);
861 else if(ActiveButton == wxEVT_LEFT_DOWN)
863 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
865 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
868 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
869 event.GetX(), Size[1] - event.GetY() - 1);
872 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
874 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
876 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
879 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
880 event.GetX(), Size[1] - event.GetY() - 1);
883 //if the ActiveButton is realeased, then release mouse capture
884 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
888 ActiveButton = wxEVT_NULL;
890 //---------------------------------------------------------------------------
891 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
893 // Mouse wheel was only added after VTK 4.4 (I think...)
894 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
896 //Set vtk event information ... The numebr of wheel rotations is stored in
897 //the x varible. y varible is zero
898 SetEventInformationFlipY(event.GetX() , event.GetY(),
899 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
900 if(event.GetWheelRotation() > 0)
903 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
908 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
914 //---------------------------------------------------------------------------
915 #if wxCHECK_VERSION(2, 8, 0)
916 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
918 if (ActiveButton != wxEVT_NULL)
920 //Maybe also invoke the button release event here
922 // Reset ActiveButton so that
923 // 1. we do not process mouse button up events any more,
924 // 2. the next button down event will be processed and call CaptureMouse().
925 // Otherwise ReleaseMouse() will be called
926 // without a previous CaptureMouse().
927 ActiveButton = wxEVT_NULL;
931 //---------------------------------------------------------------------------
932 void wxVTKRenderWindowInteractor::Render()
934 printf("EED wxVTKRenderWindowInteractor::Render Start \n");
935 #if wxCHECK_VERSION(2, 8, 0)
936 int renderAllowed = !IsFrozen();
938 int renderAllowed = 1;
940 if (renderAllowed && !RenderWhenDisabled)
942 //the user doesn't want us to render when the toplevel frame
943 //is disabled - first find the top level parent
944 wxWindow *topParent = wxGetTopLevelParent(this);
947 //if it exists, check whether it's enabled
948 //if it's not enabeld, renderAllowed will be false
949 renderAllowed = topParent->IsEnabled();
955 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
956 wxGLCanvas::SetCurrent(*(this->context));
958 if(Handle && (Handle == GetHandleHack()) )
960 printf("EED wxVTKRenderWindowInteractor::Render 1 \n");
961 RenderWindow->Render();
962 printf("EED wxVTKRenderWindowInteractor::Render 2 \n");
964 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
965 else if(GetHandleHack())
967 //this means the user has reparented us; let's adapt to the
968 //new situation by doing the WindowRemap dance
969 //store the new situation
970 Handle = GetHandleHack();
971 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
972 RenderWindow->WindowRemap();
973 RenderWindow->Render();
977 printf("EED wxVTKRenderWindowInteractor::Render End \n");
981 //---------------------------------------------------------------------------
982 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
984 //Change value of __RenderWhenDisabled ivar.
985 //If __RenderWhenDisabled is false (the default), this widget will not
986 //call Render() on the RenderWindow if the top level frame (i.e. the
987 //containing frame) has been disabled.
989 //This prevents recursive rendering during wxSafeYield() calls.
990 //wxSafeYield() can be called during the ProgressMethod() callback of
991 //a VTK object to have progress bars and other GUI elements updated -
992 //it does this by disabling all windows (disallowing user-input to
993 //prevent re-entrancy of code) and then handling all outstanding
996 //However, this often triggers an OnPaint() method for wxVTKRWIs,
997 //resulting in a Render(), resulting in Update() being called whilst
1000 RenderWhenDisabled = (bool)newValue;
1002 //---------------------------------------------------------------------------
1004 // Set the variable that indicates that we want a stereo capable window
1005 // be created. This method can only be called before a window is realized.
1007 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1009 if (Stereo != capable)
1012 RenderWindow->StereoCapableWindowOn();
1013 RenderWindow->SetStereoTypeToCrystalEyes();
1018 //---------------------------------------------------------------------------
1021 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1023 this->Superclass::PrintSelf(os, indent);
1028 // LG : EO namespace bbwxvtk
1029 //=======================================================================