]> Creatis software - crea.git/blob - src/creawxVTKRenderWindowInteractor.cxx
re indent
[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/22 17:42:59 $
7   Version:   $Revision: 1.9 $
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.9 $")
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
400 #endif
401 }
402 //---------------------------------------------------------------------------
403 void creawxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
404 {
405   //turn off background erase to reduce flickering on MSW
406   event.Skip(false);
407 }
408 //---------------------------------------------------------------------------
409 void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
410 {
411   int w, h;
412   GetClientSize(&w, &h);
413   UpdateSize(w, h);
414
415   if (!Enabled)
416     {
417     return;
418     }
419
420 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
421   InvokeEvent(vtkCommand::ConfigureEvent, NULL);
422 #endif
423   //this will check for Handle
424   //Render();
425 }
426 //---------------------------------------------------------------------------
427 void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
428 {
429  if (!Enabled)
430     {
431     return;
432     }
433 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
434   SetEventInformationFlipY(event.GetX(), event.GetY(),
435     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
436
437   InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
438 #else
439   InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
440     event.GetX(), Size[1] - event.GetY() - 1);
441 #endif
442 }
443 //---------------------------------------------------------------------------
444 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
445 void creawxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
446 {
447   if (!Enabled)
448     {
449     return;
450     }
451
452 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
453     // new style
454   SetEventInformationFlipY(event.GetX(), event.GetY(),
455       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
456
457   InvokeEvent(vtkCommand::EnterEvent, NULL);
458 #else
459     // old style
460   InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
461       event.GetX(), Size[1] - event.GetY() - 1);
462 #endif
463 }
464 //---------------------------------------------------------------------------
465 void creawxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
466 {
467   if (!Enabled)
468     {
469     return;
470     }
471
472 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
473     // new style
474   SetEventInformationFlipY(event.GetX(), event.GetY(),
475       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
476
477   InvokeEvent(vtkCommand::LeaveEvent, NULL);
478 #else
479     // old style
480   InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
481       event.GetX(), Size[1] - event.GetY() - 1);
482 #endif
483 }
484 //---------------------------------------------------------------------------
485 void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
486 {
487   if (!Enabled)
488     {
489     return;
490     }
491
492 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
493     // new style
494   int keycode = event.GetKeyCode();
495   char key = '\0';
496   if (((unsigned int)keycode) < 256)
497   {
498     // TODO: Unicode in non-Unicode mode ??
499     key = (char)keycode;
500   }
501
502   // we don't get a valid mouse position inside the key event on every platform
503   // so we retrieve the mouse position explicitly and pass it along
504   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
505   SetEventInformationFlipY(mousePos.x, mousePos.y,
506                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
507   InvokeEvent(vtkCommand::KeyPressEvent, NULL);
508 #else
509   InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
510     event.GetKeyCode(), 1);
511 #endif
512   event.Skip();
513 }
514 //---------------------------------------------------------------------------
515 void creawxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
516 {
517   if (!Enabled)
518     {
519     return;
520     }
521
522 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
523     // new style
524   int keycode = event.GetKeyCode();
525   char key = '\0';
526   if (((unsigned int)keycode) < 256)
527   {
528     // TODO: Unicode in non-Unicode mode ??
529     key = (char)keycode;
530   }
531
532   // we don't get a valid mouse position inside the key event on every platform
533   // so we retrieve the mouse position explicitly and pass it along
534   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
535   SetEventInformationFlipY(mousePos.x, mousePos.y,
536                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
537   InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
538 #else
539   InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
540     event.GetKeyCode(), 1);
541 #endif
542   event.Skip();
543 }
544 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
545  //---------------------------------------------------------------------------
546 void creawxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
547 {
548   if (!Enabled)
549     {
550     return;
551     }
552
553 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
554   // new style
555   int keycode = event.GetKeyCode();
556   char key = '\0';
557   if (((unsigned int)keycode) < 256)
558     {
559     // TODO: Unicode in non-Unicode mode ??
560     key = (char)keycode;
561     }
562
563   // we don't get a valid mouse position inside the key event on every platform
564   // so we retrieve the mouse position explicitly and pass it along
565   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
566   SetEventInformationFlipY(mousePos.x, mousePos.y,
567                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
568   InvokeEvent(vtkCommand::CharEvent, NULL);
569 #endif
570   event.Skip();
571 }
572 //---------------------------------------------------------------------------
573 void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
574 {
575   if (!Enabled || (ActiveButton != wxEVT_NULL))
576     {
577     return;
578     }
579   ActiveButton = event.GetEventType();
580
581     // On Mac (Carbon) and Windows we don't automatically get the focus when
582     // you click inside the window
583     // we therefore set the focus explicitly
584     // Apparently we need that on linux (GTK) too:
585     this->SetFocus();
586
587 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
588   SetEventInformationFlipY(event.GetX(), event.GetY(),
589     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
590 #endif
591
592   if(event.RightDown())
593   {
594 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
595     // new style
596     InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
597 #else
598     // old style
599     InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
600       event.GetX(), Size[1] - event.GetY() - 1);
601 #endif
602   }
603   else if(event.LeftDown())
604   {
605 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
606     // new style
607     InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
608 #else
609     // old style
610     InteractorStyle->OnLeftButtonDown(event.ControlDown(),  event.ShiftDown(),
611       event.GetX(), Size[1] - event.GetY() - 1);
612 #endif
613   }
614   else if(event.MiddleDown())
615   {
616 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
617     // new style
618     InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
619 #else
620     // old style
621     InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
622       event.GetX(), Size[1] - event.GetY() - 1);
623 #endif
624   }
625   //save the button and capture mouse until the button is released
626   //Only if :
627   //1. it is possible (WX_USE_X_CAPTURE)
628   //2. user decided to.
629   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
630   {
631     CaptureMouse();
632   }
633 }
634 //---------------------------------------------------------------------------
635 void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
636 {
637   //EVT_xxx_DOWN == EVT_xxx_UP - 1
638   //This is only needed if two mouse buttons are pressed at the same time.
639   //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
640   //wxEVT_COMMAND_RIGHT_CLICK
641   if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
642     {
643     return;
644     }
645
646 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
647   SetEventInformationFlipY(event.GetX(), event.GetY(),
648     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
649 #endif
650
651   if(ActiveButton == wxEVT_RIGHT_DOWN)
652   {
653 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
654     // new style
655     InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
656 #else
657     // old style
658     InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
659       event.GetX(), Size[1] - event.GetY() - 1);
660 #endif
661   }
662   else if(ActiveButton == wxEVT_LEFT_DOWN)
663   {
664 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
665     // new style
666     InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
667 #else
668     // old style
669     InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
670       event.GetX(), Size[1] - event.GetY() - 1);
671 #endif
672   }
673   else if(ActiveButton == wxEVT_MIDDLE_DOWN)
674   {
675 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
676     // new style
677     InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
678 #else
679     // old style
680     InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
681       event.GetX(), Size[1] - event.GetY() - 1);
682 #endif
683   }
684   //if the ActiveButton is realeased, then release mouse capture
685   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
686   {
687     ReleaseMouse();
688   }
689   ActiveButton = wxEVT_NULL;
690 }
691 //---------------------------------------------------------------------------
692 void creawxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
693 {
694 // Mouse wheel was only added after VTK 4.4 (I think...)
695 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
696   // new style
697   //Set vtk event information ... The numebr of wheel rotations is stored in
698   //the x varible.  y varible is zero
699   SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
700                            event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
701   if(event.GetWheelRotation() > 0)
702     {
703       //Send event to VTK
704       InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
705     }
706   else
707     {
708       //Send event to VTK
709       InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
710     }
711 #endif
712
713 }
714
715 //---------------------------------------------------------------------------
716 void creawxVTKRenderWindowInteractor::Render()
717 {
718   RenderAllowed = 1;
719   if (!RenderWhenDisabled)
720     {
721     //the user doesn't want us to render when the toplevel frame
722     //is disabled - first find the top level parent
723     wxWindow *topParent = wxGetTopLevelParent(this);
724     if (topParent)
725       {
726       //if it exists, check whether it's enabled
727       //if it's not enabeld, RenderAllowed will be false
728       RenderAllowed = topParent->IsEnabled();
729       }
730     }
731
732   if (RenderAllowed)
733     {
734     if(Handle && (Handle == GetHandleHack()) )
735       {
736       RenderWindow->Render();
737       }
738 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
739     else if(GetHandleHack())
740       {
741       //this means the user has reparented us; let's adapt to the
742       //new situation by doing the WindowRemap dance
743       //store the new situation
744       Handle = GetHandleHack();
745       RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
746       RenderWindow->WindowRemap();
747       RenderWindow->Render();
748       }
749 #endif
750     }
751 }
752 //---------------------------------------------------------------------------
753 void creawxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
754 {
755   //Change value of __RenderWhenDisabled ivar.
756   //If __RenderWhenDisabled is false (the default), this widget will not
757   //call Render() on the RenderWindow if the top level frame (i.e. the
758   //containing frame) has been disabled.
759
760   //This prevents recursive rendering during wxSafeYield() calls.
761   //wxSafeYield() can be called during the ProgressMethod() callback of
762   //a VTK object to have progress bars and other GUI elements updated -
763   //it does this by disabling all windows (disallowing user-input to
764   //prevent re-entrancy of code) and then handling all outstanding
765   //GUI events.
766
767   //However, this often triggers an OnPaint() method for wxVTKRWIs,
768   //resulting in a Render(), resulting in Update() being called whilst
769   //still in progress.
770
771   RenderWhenDisabled = (bool)newValue;
772 }
773 //---------------------------------------------------------------------------
774 //
775 // Set the variable that indicates that we want a stereo capable window
776 // be created. This method can only be called before a window is realized.
777 //
778 void creawxVTKRenderWindowInteractor::SetStereo(int capable)
779 {
780   if (Stereo != capable)
781     {
782     Stereo = capable;
783     RenderWindow->StereoCapableWindowOn();
784     RenderWindow->SetStereoTypeToCrystalEyes();
785     Modified();
786     }
787 }
788
789 //---------------------------------------------------------------------------
790 //
791 //
792 void creawxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
793 {
794   this->Superclass::PrintSelf(os, indent);
795 }
796
797
798
799 }
800 // LG : EO namespace 
801 //=======================================================================
802
803
804 #endif // USE_WX
805 #endif // USE_VTK