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