]> Creatis software - crea.git/blob - src/creawxVTKRenderWindowInteractor.mm
3388 TDx
[crea.git] / src / creawxVTKRenderWindowInteractor.mm
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29
30   Program:   Visualization Toolkit
31   Module:    $RCSfile$
32   Language:  C++
33   Date:      $Date$
34   Version:   $Revision$
35
36   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
37   All rights reserved.
38   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
39
40      This software is distributed WITHOUT ANY WARRANTY; without even 
41      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
42      PURPOSE.  See the above copyright notice for more information.
43
44 =========================================================================*/
45
46
47
48 #include <assert.h>
49
50 #include "creawxVTKRenderWindowInteractor.h"
51
52 //This is needed for vtk 3.1 :
53 #ifndef VTK_MAJOR_VERSION
54 #  include "vtkVersion.h"
55 #endif
56
57 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
58 #  include "vtkCommand.h"
59 #else
60 #  include "vtkInteractorStyle.h"
61 #endif
62 #include "vtkDebugLeaks.h"
63
64 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
65 #ifdef __WXOSX_COCOA__
66    #import <Cocoa/Cocoa.h>
67    #define __WXCOCOA__
68 #endif
69
70 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
71     // ControlDown has been changed to mean Command key down
72     #define ControlDown RawControlDown
73 #endif
74
75 #ifdef __WXMAC__
76 #ifdef __WXCOCOA__
77 #include "vtkCocoaRenderWindow.h"
78 #else
79 #include "vtkCarbonRenderWindow.h"
80 #endif
81 #endif
82
83
84 #ifdef VTK_USE_TDX
85 // #import "vtkTDxMacDevice.h"
86 #import "/Users/davila/Creatis/C11/tpli/include/vtk-8.2/vtkTDxMacDevice.h"
87 #endif
88
89
90 //=======================================================================
91 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
92 namespace crea
93 {
94
95
96 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
97 #if (!wxCHECK_VERSION(2, 4, 0))
98 wxWindow* wxGetTopLevelParent(wxWindow *win)
99 {
100     while ( win && !win->IsTopLevel() )
101          win = win->GetParent();
102     return win;
103 }
104 #endif
105 }
106 // LG : EO namespace bbwxvtk
107 //=======================================================================
108
109 // To access objc calls on cocoa
110 #ifdef __WXCOCOA__
111 #ifdef VTK_USE_COCOA
112 // This trick is no longer need in VTK CVS, should get rid of that:
113 #define id Id
114 #else
115 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
116 #endif //VTK_USE_COCOA
117 #endif //__WXCOCOA__
118
119 #if wxMAJOR_VERSION <= 2
120         #ifdef __WXGTK__
121          #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
122          #include "gdk/gdkprivate.h"
123          #if wxCHECK_VERSION(2, 9, 0)
124           // thanks to: http://thomasfischer.biz/?p=382
125           #include <gtk/gtkfixed.h>
126           #include <gtk/gtkwidget.h>
127           #include <wx/gtk/private/win_gtk.h>
128           #define piz(wxwin) WX_PIZZA((wxwin)->m_wxwindow)
129           #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
130                 GDK_WINDOW_XWINDOW(((GtkWidget*)piz(wxwin))->window) : \
131                 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
132          #else
133           #if wxCHECK_VERSION(2, 8, 0)
134            #ifdef __WXGTK20__
135             #include <wx/gtk/win_gtk.h>
136            #else
137             #include <wx/gtk1/win_gtk.h>
138            #endif
139           #else
140            #include <wx/gtk/win_gtk.h>
141           #endif
142          
143           #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
144                                   GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
145                                   GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
146          #endif
147         #endif
148
149 #else
150         #ifdef __WXGTK__
151             #include <gdk/gdkx.h>
152             #include <gtk/gtk.h>
153 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
154                           GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_wxwindow)) :  \
155                          GDK_WINDOW_XID(gtk_widget_get_window((wxwin)->m_widget))
156         #endif
157 #endif
158
159 #ifdef __WXX11__
160 #include "wx/x11/privx.h"
161 #define GetXWindow(wxwin)   ((Window)(wxwin)->GetHandle())
162 #endif
163
164 //For more info on this class please go to:
165 //http://wxvtk.sf.net
166 //This hack is for some buggy wxGTK version:
167 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
168 #  define WX_USE_X_CAPTURE 0
169 #else
170 #  define WX_USE_X_CAPTURE 1
171 #endif
172
173 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
174
175 //=======================================================================
176 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
177 namespace crea
178 {
179
180 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
181 #else
182 #endif  //__WXGTK__
183
184 //---------------------------------------------------------------------------
185 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
186                 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
187                 #if wxMAJOR_VERSION <= 2
188                         IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
189                         BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
190                 #else
191                         wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas);
192                         wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
193                 #endif
194 #else
195                 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
196                 #if wxMAJOR_VERSION <= 2
197                         IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
198                         BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
199                 #else
200                         wxIMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow);
201                         wxBEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
202                 #endif
203 #endif //__WXGTK__
204   //refresh window by doing a Render
205   EVT_PAINT       (wxVTKRenderWindowInteractor::OnPaint)
206   EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
207   EVT_MOTION      (wxVTKRenderWindowInteractor::OnMotion)
208
209   //Bind the events to the event converters
210   EVT_LEFT_DOWN   (wxVTKRenderWindowInteractor::OnButtonDown)
211   EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
212   EVT_RIGHT_DOWN  (wxVTKRenderWindowInteractor::OnButtonDown)
213   EVT_LEFT_UP     (wxVTKRenderWindowInteractor::OnButtonUp)
214   EVT_MIDDLE_UP   (wxVTKRenderWindowInteractor::OnButtonUp)
215   EVT_RIGHT_UP    (wxVTKRenderWindowInteractor::OnButtonUp)
216 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
217   EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
218   EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
219   EVT_MOUSEWHEEL  (wxVTKRenderWindowInteractor::OnMouseWheel)
220 #if wxCHECK_VERSION(2, 8, 0)
221   EVT_MOUSE_CAPTURE_LOST(wxVTKRenderWindowInteractor::OnMouseCaptureLost)
222 #endif
223   EVT_KEY_DOWN    (wxVTKRenderWindowInteractor::OnKeyDown)
224   EVT_KEY_UP      (wxVTKRenderWindowInteractor::OnKeyUp)
225   EVT_CHAR        (wxVTKRenderWindowInteractor::OnChar)
226 #endif
227   EVT_TIMER       (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
228   EVT_SIZE        (wxVTKRenderWindowInteractor::OnSize)
229 END_EVENT_TABLE()
230
231 //EED win Compilation why??:  vtkCxxRevisionMacro(wxVTKRenderWindowInteractor, "$Revision$")
232
233 //EED2020-04-10
234 #if VTK_MAJOR_VERSION < 8 
235     vtkInstantiatorNewMacro(wxVTKRenderWindowInteractor)
236 #endif
237
238 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
239 static int wxvtk_attributes[]={
240   WX_GL_DOUBLEBUFFER,
241   WX_GL_RGBA,
242   WX_GL_DEPTH_SIZE,
243   16,
244   0
245 };
246 #endif
247
248 //---------------------------------------------------------------------------
249 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() 
250
251 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
252     #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
253                 : wxGLCanvas(0, -1, wxvtk_attributes, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor")), 
254         #else
255                 : wxGLCanvas(0, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("wxVTKRenderWindowInteractor"), wxvtk_attributes), 
256         #endif
257 #else
258                 : wxWindow(), 
259 #endif //__WXGTK__
260
261           vtkRenderWindowInteractor()
262       , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
263       , ActiveButton(wxEVT_NULL)
264       , Stereo(0)
265       , Handle(0)
266       , Created(true)
267       , RenderWhenDisabled(1)
268       , UseCaptureMouse(0)
269 {
270 #ifdef VTK_DEBUG_LEAKS
271   vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
272 #endif
273 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
274   this->context = new wxGLContext(this);
275 #endif
276   this->RenderWindow = NULL;
277   this->SetRenderWindow(vtkRenderWindow::New());
278   this->RenderWindow->Delete();
279     
280 #ifdef VTK_USE_TDX
281     this->Device=vtkTDxMacDevice::New();
282 #endif
283
284     
285 }
286 //---------------------------------------------------------------------------
287 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
288                                                          wxWindowID id,
289                                                          const wxPoint &pos,
290                                                          const wxSize &size,
291                                                          long style,
292                                                          const wxString &name)
293 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
294     #if wxCHECK_VERSION(2, 9, 0) // the order of the parameters to wxGLCanvas::wxGLCanvas has changed
295       : wxGLCanvas(parent, id, wxvtk_attributes, pos, size, style, name)
296     #else
297       : wxGLCanvas(parent, id, pos, size, style, name, wxvtk_attributes)
298     #endif
299 #else
300       : wxWindow(parent, id, pos, size, style, name)
301 #endif //__WXGTK__
302           , vtkRenderWindowInteractor()
303       , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
304       , ActiveButton(wxEVT_NULL)
305       , Stereo(0)
306       , Handle(0)
307       , Created(true)
308       , RenderWhenDisabled(1)
309       , UseCaptureMouse(0)
310 {
311 #ifdef VTK_DEBUG_LEAKS
312   vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
313 #endif
314 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
315   this->context = new wxGLContext(this);
316 #endif
317   this->RenderWindow = NULL;
318   this->SetRenderWindow(vtkRenderWindow::New());
319   this->RenderWindow->Delete();
320 #ifdef __WXMAC__
321   // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
322   // so we update the size information of the interactor/renderwindow here
323   this->UpdateSize(size.x, size.y);
324 #endif
325     
326
327 #ifdef VTK_USE_TDX
328     this->Device=vtkTDxMacDevice::New();
329 #endif
330
331     
332 }
333 //---------------------------------------------------------------------------
334 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
335 {
336   SetRenderWindow(NULL);
337   SetInteractorStyle(NULL);
338 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
339   delete this->context;
340 #endif
341     
342 #ifdef VTK_USE_TDX
343   this->Device->Delete();
344 #endif
345
346 }
347 //---------------------------------------------------------------------------
348 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
349 {
350   // we don't make use of the objectfactory, because we're not registered
351   return new wxVTKRenderWindowInteractor;
352 }
353 //---------------------------------------------------------------------------
354 void wxVTKRenderWindowInteractor::Initialize()
355 {
356   int *size = RenderWindow->GetSize();
357   // enable everything and start rendering
358   Enable();
359   //RenderWindow->Start();
360
361   // set the size in the render window interactor
362   Size[0] = size[0];
363   Size[1] = size[1];
364
365   // this is initialized
366   Initialized = 1;
367 }
368 //---------------------------------------------------------------------------
369 void wxVTKRenderWindowInteractor::Enable()
370 {
371   // if already enabled then done
372   if (Enabled)
373     return;
374
375   // that's it
376   Enabled = 1;
377 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
378   wxGLCanvas::SetCurrent(*this->context);
379 #endif
380
381 //EED 2010-10-14
382 #ifdef VTK_USE_TDX
383   if(this->UseTDx)
384   {
385     this->Device->SetInteractor(this);
386     this->Device->Initialize();
387   }
388 #endif
389
390     
391     
392   Modified();
393 }
394 //---------------------------------------------------------------------------
395 bool wxVTKRenderWindowInteractor::Enable(bool enable)
396 {
397     
398 #ifdef VTK_USE_TDX
399   if(this->UseTDx)
400   {
401     this->Device->SetInteractor(this);
402     this->Device->Initialize();
403   }
404 #endif
405
406     
407     
408 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
409   return wxGLCanvas::Enable(enable);
410 #else
411   return wxWindow::Enable(enable);
412 #endif
413 }
414 //---------------------------------------------------------------------------
415 void wxVTKRenderWindowInteractor::Disable()
416 {
417   // if already disabled then done
418   if (!Enabled)
419     return;
420
421 #ifdef VTK_USE_TDX
422   if(this->Device->GetInitialized())
423   {
424     this->Device->Close();
425   }
426 #endif
427     
428     
429   // that's it (we can't remove the event handler like it should be...)
430   Enabled = 0;
431   Modified();
432 }
433 //---------------------------------------------------------------------------
434 void wxVTKRenderWindowInteractor::Start()
435 {
436   // the interactor cannot control the event loop
437   vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
438     "interactor cannot control event loop.");
439 }
440 //---------------------------------------------------------------------------
441 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
442 {
443   if( RenderWindow )
444   {
445     // if the size changed tell render window
446     if ( x != Size[0] || y != Size[1] )
447     {
448       // adjust our (vtkRenderWindowInteractor size)
449       Size[0] = x;
450       Size[1] = y;
451       // and our RenderWindow's size
452
453 #ifdef __WXCOCOA__
454   #ifdef VTK_USE_COCOA
455   #else
456   #endif //VTK_USE_COCOA
457 #else
458       RenderWindow->SetSize(x, y);
459 #endif //__WXCOCOA__
460       
461 #if defined(__WXMSW__)
462       this->Refresh();
463 #endif //__WXMSW__
464     } // if x y
465   } // if RenderWindow
466 }
467 //---------------------------------------------------------------------------
468 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
469 {
470   // it's a one shot timer
471   if (!timer.Start(10, TRUE))
472     return 0;
473
474   return 1;
475   
476 }
477 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
478 //------------------------------------------------------------------
479 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
480                                                      unsigned long duration)
481 {
482   if (!timer.Start(duration, timerType == OneShotTimer))
483     return 0;
484     
485   return ID_wxVTKRenderWindowInteractor_TIMER;
486 }
487 //------------------------------------------------------------------
488 int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
489 {
490   timer.Stop();
491   return 1;
492 }
493 #endif
494 //---------------------------------------------------------------------------
495 int wxVTKRenderWindowInteractor::DestroyTimer()
496 {
497   // do nothing
498   return 1;
499 }
500 //---------------------------------------------------------------------------
501 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
502 {
503   if (!Enabled)
504     return;
505     
506 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
507   // new style
508 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
509   // pass the right timer id
510   int timerId = this->GetCurrentTimerId();
511   this->InvokeEvent(vtkCommand::TimerEvent, &timerId);
512 #else
513   this->InvokeEvent(vtkCommand::TimerEvent, NULL);
514 #endif
515 #else
516   // old style
517   InteractorStyle->OnTimer();
518 #endif
519 }
520
521 //---------------------------------------------------------------------------
522 // NOTE on implementation:
523 // Bad luck you ended up in the only tricky place of this code.
524 // A few note, wxWidgets still refuse to provide such convenient method
525 // so I have to maintain it myself, eventhough this is completely integrated
526 // in wxPython...
527 // Anyway if this happen to break for you then compare to a recent version of wxPython
528 // and look for the function long wxPyGetWinHandle(wxWindow* win)
529 // in wxPython/src/helpers.cpp
530 long wxVTKRenderWindowInteractor::GetHandleHack()
531 {
532   //helper function to hide the MSW vs GTK stuff
533   long handle_tmp = 0;
534
535 // __WXMSW__ is for Win32
536 // __WXMAC__ is for Carbon or Cocoa builds
537 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
538 #if defined(__WXMSW__) || defined(__WXMAC__)
539     handle_tmp = (long)this->GetHandle();
540 #endif //__WXMSW__
541
542 // using above GetHandle() works fine with wxOSX 2.9.x
543 #if defined(__WXCOCOA__) && !wxCHECK_VERSION(2, 9, 0)
544    // Here is how to find the NSWindow
545    wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent( this ) );
546    if (toplevel != NULL )
547    {
548       handle_tmp = (long)toplevel->GetNSWindow();
549    }
550    // The NSView will be deducted from 
551    // [(NSWindow*)Handle contentView]
552    // if only I knew how to write that in c++
553 #endif //__WXCOCOA__ && !wxCHECK_VERSION(2, 9, 0)
554
555     // Find and return the actual X-Window.
556 #if defined(__WXGTK__) || defined(__WXX11__)
557     return (long)GetXWindow(this);
558 #endif
559
560 //#ifdef __WXMOTIF__
561 //    handle_tmp = (long)this->GetXWindow();
562 //#endif
563
564   return handle_tmp;
565 }
566 //---------------------------------------------------------------------------
567 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
568 {
569   //must always be here
570 //EED2021-08-26  
571 #ifdef __WXCOCOA__
572 #else
573         wxPaintDC pDC(this);
574 #endif
575
576   //do it here rather than in the cstor: this is safer.
577   if(!Handle)
578   {
579     Handle = GetHandleHack();
580         
581 #ifdef __WXCOCOA__
582         vtkCocoaRenderWindow    *rwin           = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
583     NSView                                      *nvsview        = (NSView* )Handle;
584         NSWindow                                *nswindow       = nvsview.window;
585     rwin->SetRootWindow( nswindow );
586     rwin->SetWindowId(  reinterpret_cast<void *>(nvsview) );
587 #else   
588     RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
589 #endif
590         
591 // Cocoa
592 // this->GetNSView() <-> DisplayId
593 // this->GetTopLevel()->GetNSWindow() <-> WindowId
594 #ifdef __WXMSW__
595     RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
596 #endif //__WXMSW__
597       
598     // This is another hack to prevent the VTK Render Window from closing the display.
599     // If VTK closes the display, ~wxContext chashes while trying to destroy its
600     // glContext (because the display is closed). The Get -> Set makes this VTK
601     // object think someone else is responsible for the display. 
602     #ifdef __WXCOCOA__
603       // avoid "Method not implemented" messages in Console
604     #else
605       this->RenderWindow->SetDisplayId(this->RenderWindow->GetGenericDisplayId());
606     #endif
607   }
608   // get vtk to render to the wxWindows
609   Render();
610 #ifdef __WXMAC__
611   // This solves a problem with repainting after a window resize
612   // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
613 #ifdef __WXCOCOA__
614   #if !wxCHECK_VERSION(2, 9, 0)
615     // this doesn't seem necessary with wxOSX 2.9.x
616     vtkCocoaRenderWindow * rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
617     if( rwin )
618     {
619       rwin->UpdateContext();
620     }
621   #endif
622 #else
623   vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
624   if( rwin )
625   {
626 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
627     // Must be somewhere after VTK 4.4
628     rwin->UpdateGLRegion();
629 #endif
630   }
631 #endif
632 #endif
633 }
634 //---------------------------------------------------------------------------
635 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
636 {
637   //turn off background erase to reduce flickering on MSW
638   event.Skip(false);
639 }
640 //---------------------------------------------------------------------------
641 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
642 {
643   int w, h;
644   GetClientSize(&w, &h);
645   UpdateSize(w, h);
646
647   if (!Enabled) 
648     {
649     return;
650     }
651
652 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
653   InvokeEvent(vtkCommand::ConfigureEvent, NULL);
654 #endif
655   //this will check for Handle
656   //Render();
657 }
658 //---------------------------------------------------------------------------
659 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
660 {
661  if (!Enabled) 
662     {
663     return;
664     }
665 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
666   SetEventInformationFlipY(event.GetX(), event.GetY(), 
667     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
668
669   InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
670 #else
671   InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
672     event.GetX(), Size[1] - event.GetY() - 1);
673 #endif
674 }
675 //---------------------------------------------------------------------------
676 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
677 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
678 {
679   if (!Enabled) 
680     {
681     return;
682     }
683
684 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
685     // new style
686   SetEventInformationFlipY(event.GetX(), event.GetY(), 
687       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
688
689   InvokeEvent(vtkCommand::EnterEvent, NULL);
690 #else
691     // old style
692   InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
693       event.GetX(), Size[1] - event.GetY() - 1);  
694 #endif
695 }
696 //---------------------------------------------------------------------------
697 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
698 {
699   if (!Enabled) 
700     {
701     return;
702     }
703
704 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
705     // new style
706   SetEventInformationFlipY(event.GetX(), event.GetY(), 
707       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
708
709   InvokeEvent(vtkCommand::LeaveEvent, NULL);
710 #else
711     // old style
712   InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
713       event.GetX(), Size[1] - event.GetY() - 1);  
714 #endif
715 }
716 //---------------------------------------------------------------------------
717 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
718 {
719   if (!Enabled) 
720     {
721     return;
722     }
723
724 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
725     // new style
726   int keycode = event.GetKeyCode();
727   char key = '\0';
728   if (((unsigned int)keycode) < 256)
729   {
730     // TODO: Unicode in non-Unicode mode ??
731     key = (char)keycode;
732   }
733
734   // we don't get a valid mouse position inside the key event on every platform
735   // so we retrieve the mouse position explicitly and pass it along
736   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
737   SetEventInformationFlipY(mousePos.x, mousePos.y, 
738                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
739   InvokeEvent(vtkCommand::KeyPressEvent, NULL);
740 #else
741   InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), 
742     event.GetKeyCode(), 1);
743 #endif
744   event.Skip();
745 }
746 //---------------------------------------------------------------------------
747 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
748 {
749   if (!Enabled) 
750     {
751     return;
752     }
753
754 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
755     // new style
756   int keycode = event.GetKeyCode();
757   char key = '\0';
758   if (((unsigned int)keycode) < 256)
759   {
760     // TODO: Unicode in non-Unicode mode ??
761     key = (char)keycode;
762   }
763
764   // we don't get a valid mouse position inside the key event on every platform
765   // so we retrieve the mouse position explicitly and pass it along
766   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
767   SetEventInformationFlipY(mousePos.x, mousePos.y, 
768                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
769   InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
770 #else
771   InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), 
772     event.GetKeyCode(), 1);
773 #endif
774   event.Skip();
775 }
776 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
777  //---------------------------------------------------------------------------
778 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
779 {
780   if (!Enabled) 
781     {
782     return;
783     }
784     
785 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
786   // new style
787   int keycode = event.GetKeyCode();
788   char key = '\0';
789   if (((unsigned int)keycode) < 256)
790     {
791     // TODO: Unicode in non-Unicode mode ??
792     key = (char)keycode;
793     }
794
795   // we don't get a valid mouse position inside the key event on every platform
796   // so we retrieve the mouse position explicitly and pass it along
797   wxPoint mousePos = ScreenToClient(wxGetMousePosition());
798   SetEventInformationFlipY(mousePos.x, mousePos.y, 
799                            event.ControlDown(), event.ShiftDown(), key, 0, NULL);
800   InvokeEvent(vtkCommand::CharEvent, NULL);
801 #endif
802   event.Skip();
803 }
804 //---------------------------------------------------------------------------
805 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
806 {
807   if (!Enabled || (ActiveButton != wxEVT_NULL))
808     {
809     return;
810     }
811   ActiveButton = event.GetEventType();
812
813     // On Mac (Carbon) and Windows we don't automatically get the focus when
814     // you click inside the window
815     // we therefore set the focus explicitly
816     // Apparently we need that on linux (GTK) too:
817     this->SetFocus();
818
819 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
820   SetEventInformationFlipY(event.GetX(), event.GetY(), 
821     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
822 #endif
823
824   if(event.RightDown())
825   {
826 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
827     // new style
828     InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
829 #else            
830     // old style
831     InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
832       event.GetX(), Size[1] - event.GetY() - 1);
833 #endif
834   }
835   else if(event.LeftDown())
836   {
837 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
838     // new style
839     InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
840 #else            
841     // old style
842     InteractorStyle->OnLeftButtonDown(event.ControlDown(),  event.ShiftDown(),
843       event.GetX(), Size[1] - event.GetY() - 1);
844 #endif
845   }
846   else if(event.MiddleDown())
847   {
848 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
849     // new style
850     InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
851 #else            
852     // old style
853     InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
854       event.GetX(), Size[1] - event.GetY() - 1);
855 #endif
856   }
857   //save the button and capture mouse until the button is released
858   //Only if :
859   //1. it is possible (WX_USE_X_CAPTURE)
860   //2. user decided to.
861   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
862   {
863     CaptureMouse();
864   }
865 }
866 //---------------------------------------------------------------------------
867 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
868 {
869   //EVT_xxx_DOWN == EVT_xxx_UP - 1
870   //This is only needed if two mouse buttons are pressed at the same time.
871   //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or 
872   //wxEVT_COMMAND_RIGHT_CLICK
873   if (!Enabled || (ActiveButton != (event.GetEventType()-1))) 
874     {
875     return;
876     }
877
878   // See report by Shang Mu / Kerry Loux on wxVTK mailing list
879     this->SetFocus();
880
881 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
882   SetEventInformationFlipY(event.GetX(), event.GetY(), 
883     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
884 #endif
885   
886   if(ActiveButton == wxEVT_RIGHT_DOWN)
887   {
888 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
889     // new style
890     InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
891 #else            
892     // old style
893     InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
894       event.GetX(), Size[1] - event.GetY() - 1);
895 #endif
896   }
897   else if(ActiveButton == wxEVT_LEFT_DOWN)
898   {
899 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
900     // new style
901     InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
902 #else            
903     // old style
904     InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
905       event.GetX(), Size[1] - event.GetY() - 1);
906 #endif
907   }
908   else if(ActiveButton == wxEVT_MIDDLE_DOWN)
909   {
910 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
911     // new style
912     InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
913 #else            
914     // old style
915     InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
916       event.GetX(), Size[1] - event.GetY() - 1);
917 #endif
918   }
919   //if the ActiveButton is realeased, then release mouse capture
920   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
921   {
922     ReleaseMouse();
923   }
924   ActiveButton = wxEVT_NULL;
925 }
926 //---------------------------------------------------------------------------
927 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
928 {
929 // Mouse wheel was only added after VTK 4.4 (I think...)
930 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
931   // new style
932   //Set vtk event information ... The numebr of wheel rotations is stored in
933   //the x varible.  y varible is zero
934   SetEventInformationFlipY(event.GetX() , event.GetY(), 
935                            event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
936   if(event.GetWheelRotation() > 0)
937     {
938       //Send event to VTK
939       InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
940     }
941   else
942     {
943       //Send event to VTK
944       InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
945     }
946 #endif
947     
948 }
949
950 //---------------------------------------------------------------------------
951 #if wxCHECK_VERSION(2, 8, 0)
952 void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& event)
953 {
954    if (ActiveButton != wxEVT_NULL)
955    {
956        //Maybe also invoke the button release event here
957    }
958    // Reset ActiveButton so that
959    // 1. we do not process mouse button up events any more,
960    // 2. the next button down event will be processed and call CaptureMouse().
961    // Otherwise ReleaseMouse() will be called
962    // without a previous CaptureMouse().
963    ActiveButton = wxEVT_NULL;
964 }
965 #endif
966
967 //---------------------------------------------------------------------------
968 void wxVTKRenderWindowInteractor::Render()
969 {
970 #if wxCHECK_VERSION(2, 8, 0)
971   int renderAllowed = !IsFrozen();
972 #else
973   int renderAllowed = 1;
974 #endif
975   if (renderAllowed && !RenderWhenDisabled)
976     {
977     //the user doesn't want us to render when the toplevel frame
978     //is disabled - first find the top level parent
979     wxWindow *topParent = wxGetTopLevelParent(this);
980     if (topParent)
981       {
982       //if it exists, check whether it's enabled
983       //if it's not enabeld, renderAllowed will be false
984       renderAllowed = topParent->IsEnabled();
985       }
986     }
987
988   if (renderAllowed)
989     {
990 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
991     wxGLCanvas::SetCurrent(*(this->context));
992 #endif
993     if(Handle && (Handle == GetHandleHack()) )
994       {
995       RenderWindow->Render();
996       }
997 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
998     else if(GetHandleHack())
999       {
1000       //this means the user has reparented us; let's adapt to the
1001       //new situation by doing the WindowRemap dance
1002       //store the new situation
1003       Handle = GetHandleHack();
1004       RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
1005       RenderWindow->WindowRemap();
1006       RenderWindow->Render();
1007       }
1008 #endif
1009
1010     }
1011 }
1012 //---------------------------------------------------------------------------
1013 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
1014 {
1015   //Change value of __RenderWhenDisabled ivar.
1016   //If __RenderWhenDisabled is false (the default), this widget will not
1017   //call Render() on the RenderWindow if the top level frame (i.e. the
1018   //containing frame) has been disabled.
1019
1020   //This prevents recursive rendering during wxSafeYield() calls.
1021   //wxSafeYield() can be called during the ProgressMethod() callback of
1022   //a VTK object to have progress bars and other GUI elements updated -
1023   //it does this by disabling all windows (disallowing user-input to
1024   //prevent re-entrancy of code) and then handling all outstanding
1025   //GUI events.
1026         
1027   //However, this often triggers an OnPaint() method for wxVTKRWIs,
1028   //resulting in a Render(), resulting in Update() being called whilst
1029   //still in progress.
1030
1031   RenderWhenDisabled = (bool)newValue;
1032 }
1033 //---------------------------------------------------------------------------
1034 //
1035 // Set the variable that indicates that we want a stereo capable window
1036 // be created. This method can only be called before a window is realized.
1037 //
1038 void wxVTKRenderWindowInteractor::SetStereo(int capable)
1039 {
1040   if (Stereo != capable)
1041     {
1042     Stereo = capable;
1043     RenderWindow->StereoCapableWindowOn();
1044     RenderWindow->SetStereoTypeToCrystalEyes();
1045     Modified();
1046     }
1047 }
1048
1049 //---------------------------------------------------------------------------
1050 //
1051 //
1052 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
1053 {
1054   this->Superclass::PrintSelf(os, indent);
1055 }
1056
1057
1058 }
1059 // LG : EO namespace bbwxvtk
1060 //=======================================================================
1061
1062