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