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