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