]> Creatis software - crea.git/blob - src/creawxVTKRenderWindowInteractor.cxx
#3125 crea Feature New Normal - branch changeWx28to30 compilation with wxWidgets3
[crea.git] / src / creawxVTKRenderWindowInteractor.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
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
9 #
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.
16 #
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
21 #  liability. 
22 #
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 # ------------------------------------------------------------------------ 
26 */ 
27
28 /*=========================================================================
29
30   Program:   Visualization Toolkit
31   Module:    $RCSfile: creawxVTKRenderWindowInteractor.cxx,v $
32   Language:  C++
33   Date:      $Date: 2012/11/15 10:43:26 $
34   Version:   $Revision: 1.11 $
35
36      This software is distributed WITHOUT ANY WARRANTY; without even
37      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
38      PURPOSE.  See the above copyright notice for more information.
39
40 =========================================================================*/
41
42 #ifdef USE_WXWIDGETS
43 #ifdef USE_VTK
44
45 #include <assert.h>
46
47 #include "creawxVTKRenderWindowInteractor.h"
48
49 //This is needed for vtk 3.1 :
50 #ifndef VTK_MAJOR_VERSION
51 #  include "vtkVersion.h"
52 #endif
53
54 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
55 #  include "vtkCommand.h"
56 #else
57 #  include "vtkInteractorStyle.h"
58 #endif
59 #include "vtkDebugLeaks.h"
60
61 #ifdef __WXMAC__
62 #ifdef VTK_USE_COCOA 
63         #include "vtkCocoaRenderWindow.h"
64 #else
65         #include "vtkCarbonRenderWindow.h"
66 #endif
67
68 #endif
69
70 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
71 #if (!wxCHECK_VERSION(2, 4, 0))
72 wxWindow* wxGetTopLevelParent(wxWindow *win)
73 {
74     while ( win && !win->IsTopLevel() )
75          win = win->GetParent();
76     return win;
77 }
78 #endif
79
80 // To access objc calls on cocoa
81 #ifdef __WXCOCOA__
82 #ifdef VTK_USE_COCOA
83 #import <Cocoa/Cocoa.h>
84 // This trick is no longer need in VTK CVS, should get rid of that:
85 #define id Id
86 #else
87 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
88 #endif //VTK_USE_COCOA
89 #endif //__WXCOCOA__
90
91
92 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
93 #if wxMAJOR_VERSION <= 2
94         #ifdef __WXGTK__
95                 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
96                 #include "gdk/gdkprivate.h"
97                 #if wxCHECK_VERSION(2, 8, 0)
98                         #ifdef __WXGTK20__
99                                 #include <wx/gtk/win_gtk.h>
100                         #else
101                                 #include <wx/gtk1/win_gtk.h>
102                         #endif
103                 #else
104                         #include <wx/gtk/win_gtk.h>
105                 #endif
106                 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
107                                   GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
108                                   GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
109         #endif
110 #else
111         #ifdef __WXGTK__
112             #include <gdk/gdkx.h>
113             #include <gtk/gtk.h>
114         #endif
115 #endif
116
117
118
119 #ifdef __WXX11__
120 #include "wx/x11/privx.h"
121 #define GetXWindow(wxwin)   ((Window)(wxwin)->GetHandle())
122 #endif
123
124
125 //For more info on this class please go to:
126 //http://wxvtk.sf.net
127 //This hack is for some buggy wxGTK version:
128 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
129 #  define WX_USE_X_CAPTURE 0
130 #else
131 #  define WX_USE_X_CAPTURE 1
132 #endif
133
134 #define ID_creawxVTKRenderWindowInteractor_TIMER 1001
135
136 namespace crea
137 {
138
139 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
140 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxGLCanvas)
141
142 #else
143 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxWindow)
144 #endif  //__WXGTK__
145
146 //---------------------------------------------------------------------------
147 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
148 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxGLCanvas)
149 #else
150 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxWindow)
151 #endif //__WXGTK__
152   //refresh window by doing a Render
153   EVT_PAINT       (creawxVTKRenderWindowInteractor::OnPaint)
154   EVT_ERASE_BACKGROUND(creawxVTKRenderWindowInteractor::OnEraseBackground)
155   EVT_MOTION      (creawxVTKRenderWindowInteractor::OnMotion)
156
157   //Bind the events to the event converters
158   EVT_LEFT_DOWN   (creawxVTKRenderWindowInteractor::OnButtonDown)
159   EVT_MIDDLE_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
160   EVT_RIGHT_DOWN  (creawxVTKRenderWindowInteractor::OnButtonDown)
161   EVT_LEFT_UP     (creawxVTKRenderWindowInteractor::OnButtonUp)
162   EVT_MIDDLE_UP   (creawxVTKRenderWindowInteractor::OnButtonUp)
163   EVT_RIGHT_UP    (creawxVTKRenderWindowInteractor::OnButtonUp)
164 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
165   EVT_ENTER_WINDOW(creawxVTKRenderWindowInteractor::OnEnter)
166   EVT_LEAVE_WINDOW(creawxVTKRenderWindowInteractor::OnLeave)
167   EVT_MOUSEWHEEL  (creawxVTKRenderWindowInteractor::OnMouseWheel)
168   EVT_KEY_DOWN    (creawxVTKRenderWindowInteractor::OnKeyDown)
169   EVT_KEY_UP      (creawxVTKRenderWindowInteractor::OnKeyUp)
170   EVT_CHAR        (creawxVTKRenderWindowInteractor::OnChar)
171 #endif
172   EVT_TIMER       (ID_creawxVTKRenderWindowInteractor_TIMER, creawxVTKRenderWindowInteractor::OnTimer)
173   EVT_SIZE        (creawxVTKRenderWindowInteractor::OnSize)
174 END_EVENT_TABLE()
175
176 //EED win Compilation why??: vtkCxxRevisionMacro(creawxVTKRenderWindowInteractor, "$Revision: 1.11 $")
177 vtkInstantiatorNewMacro(creawxVTKRenderWindowInteractor)
178
179 //---------------------------------------------------------------------------
180 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
181 #if (wxCHECK_VERSION(2, 8, 0))
182 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
183 #else
184 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
185 #endif
186 #else
187 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
188 #endif //__WXGTK__
189       , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
190       , ActiveButton(wxEVT_NULL)
191       , RenderAllowed(0)
192       , Stereo(0)
193       , Handle(0)
194       , Created(true)
195       , RenderWhenDisabled(1)
196       , UseCaptureMouse(0)
197 {
198 #ifdef VTK_DEBUG_LEAKS
199   vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
200 #endif
201   this->RenderWindow = NULL;
202   this->SetRenderWindow(vtkRenderWindow::New());
203   this->RenderWindow->Delete();
204 }
205 //---------------------------------------------------------------------------
206 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *parent,
207                                                          wxWindowID id,
208                                                          const wxPoint &pos,
209                                                          const wxSize &size,
210                                                          long style,
211                                                          const wxString &name)
212 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
213       : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
214 #else
215       : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
216 #endif //__WXGTK__
217       , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
218       , ActiveButton(wxEVT_NULL)
219       , RenderAllowed(0)
220       , Stereo(0)
221       , Handle(0)
222       , Created(true)
223       , RenderWhenDisabled(1)
224       , UseCaptureMouse(0)
225 {
226 #ifdef VTK_DEBUG_LEAKS
227   vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
228 #endif
229   this->RenderWindow = NULL;
230   this->SetRenderWindow(vtkRenderWindow::New());
231   this->RenderWindow->Delete();
232 #ifdef __WXMAC__
233   // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
234   // so we update the size information of the interactor/renderwindow here
235   this->UpdateSize(size.x, size.y);
236 #endif
237 }
238 //---------------------------------------------------------------------------
239 creawxVTKRenderWindowInteractor::~creawxVTKRenderWindowInteractor()
240 {
241   SetRenderWindow(NULL);
242   SetInteractorStyle(NULL);
243 }
244 //---------------------------------------------------------------------------
245 creawxVTKRenderWindowInteractor * creawxVTKRenderWindowInteractor::New()
246 {
247   // we don't make use of the objectfactory, because we're not registered
248   return new creawxVTKRenderWindowInteractor;
249 }
250 //---------------------------------------------------------------------------
251 void creawxVTKRenderWindowInteractor::Initialize()
252 {
253   int *size = RenderWindow->GetSize();
254   // enable everything and start rendering
255   Enable();
256   //RenderWindow->Start();
257
258   // set the size in the render window interactor
259   Size[0] = size[0];
260   Size[1] = size[1];
261
262   // this is initialized
263   Initialized = 1;
264 }
265 //---------------------------------------------------------------------------
266 void creawxVTKRenderWindowInteractor::Enable()
267 {
268   // if already enabled then done
269   if (Enabled)
270     return;
271
272   // that's it
273   Enabled = 1;
274 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
275   SetCurrent();
276 #endif
277   Modified();
278 }
279 //---------------------------------------------------------------------------
280 bool creawxVTKRenderWindowInteractor::Enable(bool enable)
281 {
282 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
283   return wxGLCanvas::Enable(enable);
284 #else
285   return wxWindow::Enable(enable);
286 #endif
287 }
288 //---------------------------------------------------------------------------
289 void creawxVTKRenderWindowInteractor::Disable()
290 {
291   // if already disabled then done
292   if (!Enabled)
293     return;
294
295   // that's it (we can't remove the event handler like it should be...)
296   Enabled = 0;
297   Modified();
298 }
299 //---------------------------------------------------------------------------
300 void creawxVTKRenderWindowInteractor::Start()
301 {
302   // the interactor cannot control the event loop
303   vtkErrorMacro( << "creawxVTKRenderWindowInteractor::Start() "
304     "interactor cannot control event loop.");
305 }
306 //---------------------------------------------------------------------------
307 void creawxVTKRenderWindowInteractor::UpdateSize(int x, int y)
308 {
309   if( RenderWindow )
310   {
311     // if the size changed tell render window
312     if ( x != Size[0] || y != Size[1] )
313     {
314       // adjust our (vtkRenderWindowInteractor size)
315       Size[0] = x;
316       Size[1] = y;
317       // and our RenderWindow's size
318       RenderWindow->SetSize(x, y);
319     }
320   }
321 }
322 //---------------------------------------------------------------------------
323 int creawxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
324 {
325   // it's a one shot timer
326   if (!timer.Start(10, TRUE))
327     assert(false);
328
329   return 1;
330
331 }
332 //---------------------------------------------------------------------------
333 int creawxVTKRenderWindowInteractor::DestroyTimer()
334 {
335   // do nothing
336   return 1;
337 }
338 //---------------------------------------------------------------------------
339 void creawxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
340 {
341   if (!Enabled)
342     return;
343
344 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
345     // new style
346     InvokeEvent(vtkCommand::TimerEvent, NULL);
347 #else
348     // old style
349     InteractorStyle->OnTimer();
350 #endif
351 }
352
353 //---------------------------------------------------------------------------
354 // NOTE on implementation:
355 // Bad luck you ended up in the only tricky place of this code.
356 // A few note, wxWidgets still refuse to provide such convenient method
357 // so I have to maintain it myself, eventhough this is completely integrated
358 // in wxPython...
359 // Anyway if this happen to break for you then compare to a recent version of wxPython
360 // and look for the function long wxPyGetWinHandle(wxWindow* win)
361 // in wxPython/src/helpers.cpp
362 long creawxVTKRenderWindowInteractor::GetHandleHack()
363 {
364   //helper function to hide the MSW vs GTK stuff
365   long handle_tmp = 0;
366
367 // __WXMSW__ is for Win32
368 //__WXMAC__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available)
369 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
370 #if defined(__WXMSW__) || defined(__WXMAC__)
371     handle_tmp = (long)this->GetHandle();
372 #endif //__WXMSW__
373
374 //__WXCOCOA__ stands for using the objective-c Cocoa API
375 #ifdef __WXCOCOA__
376    // Here is how to find the NSWindow
377    wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
378      wxGetTopLevelParent( this ) );
379    if (toplevel != NULL )
380    {
381      handle_tmp = (long)toplevel->GetNSWindow();
382    }
383    // The NSView will be deducted from
384    // [(NSWindow*)Handle contentView]
385    // if only I knew how to write that in c++
386 #endif //__WXCOCOA__
387
388     // Find and return the actual X-Window.
389 #if defined(__WXGTK__) || defined(__WXX11__)
390
391         //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
392         #if wxMAJOR_VERSION <= 2
393                 return (long)GetXWindow(this);
394         #else
395                 GdkWindow* Win = gtk_widget_get_window( (GtkWidget *) GetHandle() );
396                 return (long int)GDK_WINDOW_XDISPLAY(Win);
397         #endif
398
399 #endif
400
401 //#ifdef __WXMOTIF__
402 //    handle_tmp = (long)this->GetXWindow();
403 //#endif
404
405   return handle_tmp;
406 }
407 //---------------------------------------------------------------------------
408 void creawxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
409 {
410   //must always be here
411   wxPaintDC pDC(this);
412
413   //do it here rather than in the cstor: this is safer.
414   if(!Handle)
415   {
416     Handle = GetHandleHack();
417     RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
418 #ifdef __WXMSW__
419     RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
420 #endif //__WXMSW__
421   }
422   // get vtk to render to the wxWindows
423   Render();
424 #ifdef __WXMAC__
425
426 #ifdef VTK_USE_COCOA
427   vtkCocoaRenderWindow* rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
428   if( rwin )
429   {
430     rwin->UpdateContext();
431   }
432 #else
433   // This solves a problem with repainting after a window resize
434   // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
435   vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
436   if( rwin )
437   {
438     rwin->UpdateGLRegion();
439   }
440 #endif
441
442 #endif
443 }
444 //---------------------------------------------------------------------------
445 void creawxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
446 {
447   //turn off background erase to reduce flickering on MSW
448   event.Skip(false);
449 }
450 //---------------------------------------------------------------------------
451 void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
452 {
453   int w, h;
454   GetClientSize(&w, &h);
455   UpdateSize(w, h);
456
457   if (!Enabled)
458     {
459     return;
460     }
461
462 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
463   InvokeEvent(vtkCommand::ConfigureEvent, NULL);
464 #endif
465   //this will check for Handle
466   //Render();
467 }
468 //---------------------------------------------------------------------------
469 void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
470 {
471  if (!Enabled)
472     {
473     return;
474     }
475 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
476   SetEventInformationFlipY(event.GetX(), event.GetY(),
477     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
478
479   InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
480 #else
481   InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
482     event.GetX(), Size[1] - event.GetY() - 1);
483 #endif
484 }
485 //---------------------------------------------------------------------------
486 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
487 void creawxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
488 {
489   if (!Enabled)
490     {
491     return;
492     }
493
494 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
495     // new style
496   SetEventInformationFlipY(event.GetX(), event.GetY(),
497       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
498
499   InvokeEvent(vtkCommand::EnterEvent, NULL);
500 #else
501     // old style
502   InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
503       event.GetX(), Size[1] - event.GetY() - 1);
504 #endif
505 }
506 //---------------------------------------------------------------------------
507 void creawxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
508 {
509   if (!Enabled)
510     {
511     return;
512     }
513
514 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
515     // new style
516   SetEventInformationFlipY(event.GetX(), event.GetY(),
517       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
518
519   InvokeEvent(vtkCommand::LeaveEvent, NULL);
520 #else
521     // old style
522   InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
523       event.GetX(), Size[1] - event.GetY() - 1);
524 #endif
525 }
526 //---------------------------------------------------------------------------
527 void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
528 {
529   if (!Enabled)
530     {
531     return;
532     }
533
534 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
535     // new style
536   int keycode = event.GetKeyCode();
537   char key = '\0';
538   if (((unsigned int)keycode) < 256)
539   {
540     // TODO: Unicode in non-Unicode mode ??
541     key = (char)keycode;
542   }
543
544   // we don't get a valid mouse position inside the key event on every platform
545   // so we retrieve the mouse position explicitly and pass it along
546   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
547   SetEventInformationFlipY(mousePos.x, mousePos.y,
548                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
549   InvokeEvent(vtkCommand::KeyPressEvent, NULL);
550 #else
551   InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
552     event.GetKeyCode(), 1);
553 #endif
554   event.Skip();
555 }
556 //---------------------------------------------------------------------------
557 void creawxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
558 {
559   if (!Enabled)
560     {
561     return;
562     }
563
564 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
565     // new style
566   int keycode = event.GetKeyCode();
567   char key = '\0';
568   if (((unsigned int)keycode) < 256)
569   {
570     // TODO: Unicode in non-Unicode mode ??
571     key = (char)keycode;
572   }
573
574   // we don't get a valid mouse position inside the key event on every platform
575   // so we retrieve the mouse position explicitly and pass it along
576   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
577   SetEventInformationFlipY(mousePos.x, mousePos.y,
578                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
579   InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
580 #else
581   InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
582     event.GetKeyCode(), 1);
583 #endif
584   event.Skip();
585 }
586 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
587  //---------------------------------------------------------------------------
588 void creawxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
589 {
590   if (!Enabled)
591     {
592     return;
593     }
594
595 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
596   // new style
597   int keycode = event.GetKeyCode();
598   char key = '\0';
599   if (((unsigned int)keycode) < 256)
600     {
601     // TODO: Unicode in non-Unicode mode ??
602     key = (char)keycode;
603     }
604
605   // we don't get a valid mouse position inside the key event on every platform
606   // so we retrieve the mouse position explicitly and pass it along
607   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
608   SetEventInformationFlipY(mousePos.x, mousePos.y,
609                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
610   InvokeEvent(vtkCommand::CharEvent, NULL);
611 #endif
612   event.Skip();
613 }
614 //---------------------------------------------------------------------------
615 void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
616 {
617   if (!Enabled || (ActiveButton != wxEVT_NULL))
618     {
619     return;
620     }
621   ActiveButton = event.GetEventType();
622
623     // On Mac (Carbon) and Windows we don't automatically get the focus when
624     // you click inside the window
625     // we therefore set the focus explicitly
626     // Apparently we need that on linux (GTK) too:
627     this->SetFocus();
628
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);
632 #endif
633
634   if(event.RightDown())
635   {
636 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
637     // new style
638     InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
639 #else
640     // old style
641     InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
642       event.GetX(), Size[1] - event.GetY() - 1);
643 #endif
644   }
645   else if(event.LeftDown())
646   {
647 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
648     // new style
649     InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
650 #else
651     // old style
652     InteractorStyle->OnLeftButtonDown(event.ControlDown(),  event.ShiftDown(),
653       event.GetX(), Size[1] - event.GetY() - 1);
654 #endif
655   }
656   else if(event.MiddleDown())
657   {
658 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
659     // new style
660     InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
661 #else
662     // old style
663     InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
664       event.GetX(), Size[1] - event.GetY() - 1);
665 #endif
666   }
667   //save the button and capture mouse until the button is released
668   //Only if :
669   //1. it is possible (WX_USE_X_CAPTURE)
670   //2. user decided to.
671   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
672   {
673     CaptureMouse();
674   }
675 }
676 //---------------------------------------------------------------------------
677 void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
678 {
679   //EVT_xxx_DOWN == EVT_xxx_UP - 1
680   //This is only needed if two mouse buttons are pressed at the same time.
681   //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
682   //wxEVT_COMMAND_RIGHT_CLICK
683   if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
684     {
685     return;
686     }
687
688 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
689   SetEventInformationFlipY(event.GetX(), event.GetY(),
690     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
691 #endif
692
693   if(ActiveButton == wxEVT_RIGHT_DOWN)
694   {
695 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
696     // new style
697     InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
698 #else
699     // old style
700     InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
701       event.GetX(), Size[1] - event.GetY() - 1);
702 #endif
703   }
704   else if(ActiveButton == wxEVT_LEFT_DOWN)
705   {
706 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
707     // new style
708     InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
709 #else
710     // old style
711     InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
712       event.GetX(), Size[1] - event.GetY() - 1);
713 #endif
714   }
715   else if(ActiveButton == wxEVT_MIDDLE_DOWN)
716   {
717 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
718     // new style
719     InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
720 #else
721     // old style
722     InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
723       event.GetX(), Size[1] - event.GetY() - 1);
724 #endif
725   }
726   //if the ActiveButton is realeased, then release mouse capture
727   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
728   {
729     ReleaseMouse();
730   }
731   ActiveButton = wxEVT_NULL;
732 }
733 //---------------------------------------------------------------------------
734 void creawxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
735 {
736 // Mouse wheel was only added after VTK 4.4 (I think...)
737 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
738   // new style
739   //Set vtk event information ... The numebr of wheel rotations is stored in
740   //the x varible.  y varible is zero
741   SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
742                            event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
743   if(event.GetWheelRotation() > 0)
744     {
745       //Send event to VTK
746       InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
747     }
748   else
749     {
750       //Send event to VTK
751       InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
752     }
753 #endif
754
755 }
756
757 //---------------------------------------------------------------------------
758 void creawxVTKRenderWindowInteractor::Render()
759 {
760   RenderAllowed = 1;
761   if (!RenderWhenDisabled)
762     {
763     //the user doesn't want us to render when the toplevel frame
764     //is disabled - first find the top level parent
765     wxWindow *topParent = wxGetTopLevelParent(this);
766     if (topParent)
767       {
768       //if it exists, check whether it's enabled
769       //if it's not enabeld, RenderAllowed will be false
770       RenderAllowed = topParent->IsEnabled();
771       }
772     }
773
774   if (RenderAllowed)
775     {
776     if(Handle && (Handle == GetHandleHack()) )
777       {
778       RenderWindow->Render();
779       }
780 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
781     else if(GetHandleHack())
782       {
783       //this means the user has reparented us; let's adapt to the
784       //new situation by doing the WindowRemap dance
785       //store the new situation
786       Handle = GetHandleHack();
787       RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
788       RenderWindow->WindowRemap();
789       RenderWindow->Render();
790       }
791 #endif
792     }
793 }
794 //---------------------------------------------------------------------------
795 void creawxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
796 {
797   //Change value of __RenderWhenDisabled ivar.
798   //If __RenderWhenDisabled is false (the default), this widget will not
799   //call Render() on the RenderWindow if the top level frame (i.e. the
800   //containing frame) has been disabled.
801
802   //This prevents recursive rendering during wxSafeYield() calls.
803   //wxSafeYield() can be called during the ProgressMethod() callback of
804   //a VTK object to have progress bars and other GUI elements updated -
805   //it does this by disabling all windows (disallowing user-input to
806   //prevent re-entrancy of code) and then handling all outstanding
807   //GUI events.
808
809   //However, this often triggers an OnPaint() method for wxVTKRWIs,
810   //resulting in a Render(), resulting in Update() being called whilst
811   //still in progress.
812
813   RenderWhenDisabled = newValue != 0;
814 }
815 //---------------------------------------------------------------------------
816 //
817 // Set the variable that indicates that we want a stereo capable window
818 // be created. This method can only be called before a window is realized.
819 //
820 void creawxVTKRenderWindowInteractor::SetStereo(int capable)
821 {
822   if (Stereo != capable)
823     {
824     Stereo = capable;
825     RenderWindow->StereoCapableWindowOn();
826     RenderWindow->SetStereoTypeToCrystalEyes();
827     Modified();
828     }
829 }
830
831 //---------------------------------------------------------------------------
832 //
833 //
834 void creawxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
835 {
836   this->Superclass::PrintSelf(os, indent);
837 }
838
839
840
841 }
842 // LG : EO namespace 
843 //=======================================================================
844
845
846 #endif // USE_WX
847 #endif // USE_VTK