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