wxVTKRenderWindowInteractor.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: wxVTKRenderWindowInteractor.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2009/05/14 13:54:35 $
00007   Version:   $Revision: 1.3 $
00008 
00009   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00010   All rights reserved.
00011   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00012 
00013      This software is distributed WITHOUT ANY WARRANTY; without even 
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015      PURPOSE.  See the above copyright notice for more information.
00016 
00017 =========================================================================*/
00018 
00019 #include "wxVTKRenderWindowInteractor.h"
00020 
00021 //This is needed for vtk 3.1 :
00022 #ifndef VTK_MAJOR_VERSION
00023 #  include "vtkVersion.h"
00024 #endif
00025 
00026 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00027 #  include "vtkCommand.h"
00028 #else
00029 #  include "vtkInteractorStyle.h"
00030 #endif
00031 
00032 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
00033 #if (!wxCHECK_VERSION(2, 4, 0))
00034 wxWindow* wxGetTopLevelParent(wxWindow *win)
00035 {
00036     while ( win && !win->IsTopLevel() )
00037          win = win->GetParent();
00038     return win;
00039 }
00040 #endif
00041 
00042 // To access objc calls on cocoa
00043 #ifdef __WXCOCOA__
00044 #ifdef VTK_USE_COCOA
00045 #import <Cocoa/Cocoa.h>
00046 // This trick is no longer need in VTK CVS, should get rid of that:
00047 #define id Id
00048 #else
00049 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
00050 #endif //VTK_USE_COCOA
00051 #endif //__WXCOCOA__
00052 
00053 #ifdef __WXGTK__
00054 #    include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
00055 #    include "gdk/gdkprivate.h"
00056 #ifdef __WXGTK20__
00057 #include <wx/gtk/win_gtk.h>
00058 #else
00059 #include <wx/gtk1/win_gtk.h>
00060 #endif
00061 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
00062                           GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
00063                           GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
00064 #endif
00065 
00066 #ifdef __WXX11__
00067 #include "wx/x11/privx.h"
00068 #define GetXWindow(wxwin)   ((Window)(wxwin)->GetHandle())
00069 #endif
00070 
00071 
00072 //For more info on this class please go to:
00073 //http://wxvtk.sf.net
00074 //This hack is for some buggy wxGTK version:
00075 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
00076 #  define WX_USE_X_CAPTURE 0
00077 #else
00078 #  define WX_USE_X_CAPTURE 1
00079 #endif
00080 
00081 #define ID_wxVTKRenderWindowInteractor_TIMER 1001
00082 
00083 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00084 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxGLCanvas)
00085 #else
00086 IMPLEMENT_DYNAMIC_CLASS(wxVTKRenderWindowInteractor, wxWindow)
00087 #endif  //__WXGTK__
00088 
00089 //---------------------------------------------------------------------------
00090 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00091 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxGLCanvas)
00092 #else
00093 BEGIN_EVENT_TABLE(wxVTKRenderWindowInteractor, wxWindow)
00094 #endif //__WXGTK__
00095   //refresh window by doing a Render
00096   EVT_PAINT       (wxVTKRenderWindowInteractor::OnPaint)
00097   EVT_ERASE_BACKGROUND(wxVTKRenderWindowInteractor::OnEraseBackground)
00098   EVT_MOTION      (wxVTKRenderWindowInteractor::OnMotion)
00099 
00100   //Bind the events to the event converters
00101   EVT_LEFT_DOWN   (wxVTKRenderWindowInteractor::OnButtonDown)
00102   EVT_MIDDLE_DOWN (wxVTKRenderWindowInteractor::OnButtonDown)
00103   EVT_RIGHT_DOWN  (wxVTKRenderWindowInteractor::OnButtonDown)
00104   EVT_LEFT_UP     (wxVTKRenderWindowInteractor::OnButtonUp)
00105   EVT_MIDDLE_UP   (wxVTKRenderWindowInteractor::OnButtonUp)
00106   EVT_RIGHT_UP    (wxVTKRenderWindowInteractor::OnButtonUp)
00107 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
00108   EVT_ENTER_WINDOW(wxVTKRenderWindowInteractor::OnEnter)
00109   EVT_LEAVE_WINDOW(wxVTKRenderWindowInteractor::OnLeave)
00110   EVT_MOUSEWHEEL  (wxVTKRenderWindowInteractor::OnMouseWheel)
00111 // If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions
00112 // of all characters are always returned.  EVT_CHAR also performs
00113 // other necessary keyboard-dependent translations.
00114   //EVT_KEY_DOWN    (wxVTKRenderWindowInteractor::OnKeyDown)
00115   EVT_CHAR        (wxVTKRenderWindowInteractor::OnKeyDown)
00116   EVT_KEY_UP      (wxVTKRenderWindowInteractor::OnKeyUp)
00117 #endif
00118   EVT_TIMER       (ID_wxVTKRenderWindowInteractor_TIMER, wxVTKRenderWindowInteractor::OnTimer)
00119   EVT_SIZE        (wxVTKRenderWindowInteractor::OnSize)
00120 END_EVENT_TABLE()
00121 
00122 //---------------------------------------------------------------------------
00123 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00124 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxGLCanvas()
00125 #else
00126 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor() : vtkRenderWindowInteractor(), wxWindow()
00127 #endif //__WXGTK__
00128       , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
00129       , ActiveButton(wxEVT_NULL)
00130       , RenderAllowed(0)
00131       , Stereo(0)
00132       , Handle(0)
00133       , Created(true)
00134       , RenderWhenDisabled(1)
00135       , UseCaptureMouse(0)
00136 {
00137   
00138   this->RenderWindow = NULL;
00139   this->SetRenderWindow(vtkRenderWindow::New());
00140   this->RenderWindow->Delete();
00141   
00142   //this->SetBackgroundColour( wxColour(255,0,255) );
00143 }
00144 //---------------------------------------------------------------------------
00145 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
00146                                                          wxWindowID id,
00147                                                          const wxPoint &pos,
00148                                                          const wxSize &size,
00149                                                          long style,
00150                                                          const wxString &name)
00151 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00152       : vtkRenderWindowInteractor(), wxGLCanvas(parent, id, pos, size, style, name)
00153 #else
00154       : vtkRenderWindowInteractor(), wxWindow(parent, id, pos, size, style, name)
00155 #endif //__WXGTK__
00156       , timer(this, ID_wxVTKRenderWindowInteractor_TIMER)
00157       , ActiveButton(wxEVT_NULL)
00158       , RenderAllowed(0)
00159       , Stereo(0)
00160       , Handle(0)
00161       , Created(true)
00162       , RenderWhenDisabled(1)
00163       , UseCaptureMouse(0)
00164 {
00165   
00166   this->RenderWindow = NULL;
00167   this->SetRenderWindow(vtkRenderWindow::New());
00168   this->RenderWindow->Delete();
00169   
00170   // this->SetBackgroundColour( wxColour(255,0,0) );
00171 }
00172 //---------------------------------------------------------------------------
00173 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
00174 {   
00175   // LG : trompe la mort !
00176   SetReferenceCount(0);
00177 }
00178 //---------------------------------------------------------------------------
00179 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
00180 {
00181   // we don't make use of the objectfactory, because we're not registered
00182   return new wxVTKRenderWindowInteractor;
00183 }
00184 //---------------------------------------------------------------------------
00185 void wxVTKRenderWindowInteractor::Initialize()
00186 {
00187   int *size = RenderWindow->GetSize();
00188   // enable everything and start rendering
00189   Enable();
00190   //RenderWindow->Start();
00191 
00192   // set the size in the render window interactor
00193   Size[0] = size[0];
00194   Size[1] = size[1];
00195 
00196   // this is initialized
00197   Initialized = 1;
00198 }
00199 //---------------------------------------------------------------------------
00200 void wxVTKRenderWindowInteractor::Enable()
00201 {
00202   // if already enabled then done
00203   if (Enabled)
00204     return;
00205 
00206   // that's it
00207   Enabled = 1;
00208 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00209   SetCurrent();
00210 #endif
00211   Modified();
00212 }
00213 //---------------------------------------------------------------------------
00214 bool wxVTKRenderWindowInteractor::Enable(bool enable)
00215 {
00216 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00217   return wxGLCanvas::Enable(enable);
00218 #else
00219   return wxWindow::Enable(enable);
00220 #endif
00221 }
00222 //---------------------------------------------------------------------------
00223 void wxVTKRenderWindowInteractor::Disable()
00224 {
00225   // if already disabled then done
00226   if (!Enabled)
00227     return;
00228 
00229   // that's it (we can't remove the event handler like it should be...)
00230   Enabled = 0;
00231   Modified();
00232 }
00233 //---------------------------------------------------------------------------
00234 void wxVTKRenderWindowInteractor::Start()
00235 {
00236   // the interactor cannot control the event loop
00237   vtkErrorMacro( << "wxVTKRenderWindowInteractor::Start() "
00238     "interactor cannot control event loop.");
00239 }
00240 //---------------------------------------------------------------------------
00241 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
00242 {
00243   if( RenderWindow )
00244   {
00245     // if the size changed tell render window
00246     if ( x != Size[0] || y != Size[1] )
00247     {
00248       // adjust our (vtkRenderWindowInteractor size)
00249       Size[0] = x;
00250       Size[1] = y;
00251       // and our RenderWindow's size
00252       RenderWindow->SetSize(x, y);
00253     }
00254   }
00255 }
00256 //---------------------------------------------------------------------------
00257 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
00258 {
00259   // it's a one shot timer
00260   if (!timer.Start(10, TRUE))
00261     assert(false);
00262 
00263   return 1;
00264   
00265 }
00266 //---------------------------------------------------------------------------
00267 int wxVTKRenderWindowInteractor::DestroyTimer()
00268 {
00269   // do nothing
00270   return 1;
00271 }
00272 //---------------------------------------------------------------------------
00273 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
00274 {
00275   if (!Enabled)
00276     return;
00277     
00278 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00279     // new style
00280     InvokeEvent(vtkCommand::TimerEvent, NULL);
00281 #else
00282     // old style
00283     InteractorStyle->OnTimer();
00284 #endif
00285 }
00286 
00287 //---------------------------------------------------------------------------
00288 // NOTE on implementation:
00289 // Bad luck you ended up in the only tricky place of this code.
00290 // A few note, wxWidgets still refuse to provide such convenient method
00291 // so I have to maintain it myself, eventhough this is completely integrated
00292 // in wxPython...
00293 // Anyway if this happen to break for you then compare to a recent version of wxPython
00294 // and look for the function long wxPyGetWinHandle(wxWindow* win)
00295 // in wxPython/src/helpers.cpp
00296 long wxVTKRenderWindowInteractor::GetHandleHack()
00297 {
00298   //helper function to hide the MSW vs GTK stuff
00299   long handle_tmp = 0;
00300 
00301 // __WXMSW__ is for Win32
00302 //__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)
00303 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
00304 #if defined(__WXMSW__) || defined(__WXMAC__)
00305     handle_tmp = (long)this->GetHandle();
00306 #endif //__WXMSW__
00307 
00308 //__WXCOCOA__ stands for using the objective-c Cocoa API
00309 #ifdef __WXCOCOA__
00310    // Here is how to find the NSWindow
00311    wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
00312      wxGetTopLevelParent( this ) );
00313    if (toplevel != NULL )    
00314    {
00315      handle_tmp = (long)toplevel->GetNSWindow();
00316    }
00317    // The NSView will be deducted from 
00318    // [(NSWindow*)Handle contentView]
00319    // if only I knew how to write that in c++
00320 #endif //__WXCOCOA__
00321 
00322     // Find and return the actual X-Window.
00323 #if defined(__WXGTK__) || defined(__WXX11__)
00324     return (long)GetXWindow(this);
00325 #endif
00326 
00327 //#ifdef __WXMOTIF__
00328 //    handle_tmp = (long)this->GetXWindow();
00329 //#endif
00330 
00331   return handle_tmp;
00332 }
00333 //---------------------------------------------------------------------------
00334 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
00335 {
00336 
00337   //must always be here
00338   wxPaintDC pDC(this);
00339 
00340   //do it here rather than in the cstor: this is safer.
00341   if(!Handle)
00342   {
00343     Handle = GetHandleHack();
00344     RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
00345 #ifdef __WXMSW__
00346     RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
00347 #endif //__WXMSW__
00348   }
00349   // get vtk to render to the wxWindows
00350   //bbtkDebugMessage("Wx",9,"wxVTKRenderWindowInteractor::OnPaint"<<std::endl);
00351   //std::cout << "wxVTKRenderWindowInteractor::OnPaint"<<std::endl;
00352   Render();
00353 
00354 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
00355   //  bbtkDebugMessage("Core",9,"wxVTKRenderWindowInteractor::OnPaint   public wxGLCanvas, virtual public vtkRenderWindowInteractor  \n");
00356 #else
00357   //  bbtkDebugMessage("Core",9,"wxVTKRenderWindowInteractor::OnPaint public wxWindow, virtual public vtkRenderWindowInteractor     \n");
00358 #endif //__WXGTK__
00359 
00360 }
00361 //---------------------------------------------------------------------------
00362 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
00363 {
00364   //printf("EED wxVTKRenderWindowInteractor::OnEraseBackground \n");
00365   //turn off background erase to reduce flickering on MSW
00366   event.Skip(false);
00367 }
00368 //---------------------------------------------------------------------------
00369 void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
00370 {
00371   int w, h;
00372   GetClientSize(&w, &h);
00373   UpdateSize(w, h);
00374 
00375   if (!Enabled) 
00376     {
00377     return;
00378     }
00379 
00380 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00381   InvokeEvent(vtkCommand::ConfigureEvent, NULL);
00382 #endif
00383   //this will check for Handle
00384   //Render();
00385 }
00386 //---------------------------------------------------------------------------
00387 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
00388 {
00389  if (!Enabled) 
00390     {
00391    return;
00392     }
00393 
00394 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00395   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00396     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
00397 
00398   InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
00399 #else
00400   InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
00401     event.GetX(), Size[1] - event.GetY() - 1);
00402 #endif
00403 }
00404 //---------------------------------------------------------------------------
00405 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
00406 void wxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
00407 {
00408         SetFocus();
00409   if (!Enabled) 
00410     {           
00411                 return; 
00412     }
00413 
00414 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00415     // new style
00416   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00417       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
00418 
00419   InvokeEvent(vtkCommand::EnterEvent, NULL);
00420 #else
00421     // old style
00422   InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
00423       event.GetX(), Size[1] - event.GetY() - 1);  
00424 #endif
00425 }
00426 //---------------------------------------------------------------------------
00427 void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
00428 {
00429   if (!Enabled) 
00430     {
00431     return;
00432     }
00433 
00434 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00435     // new style
00436   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00437       event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
00438 
00439   InvokeEvent(vtkCommand::LeaveEvent, NULL);
00440 #else
00441     // old style
00442   InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
00443       event.GetX(), Size[1] - event.GetY() - 1);  
00444 #endif
00445 }
00446 //---------------------------------------------------------------------------
00447 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
00448 {
00449   if (!Enabled) 
00450     {
00451     return;
00452     }
00453 
00454 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00455     // new style
00456   int keycode = event.GetKeyCode();
00457  
00458 
00459   char key = '\0';
00460   if ( keycode < 256 )
00461   {
00462     // TODO: Unicode in non-Unicode mode ??
00463     key = (char)keycode;
00464   }
00465   else//Dic 2007
00466   {
00467         if ( keycode==314 )//Real keyCode for Left ARROW and non-Unicode
00468         {       
00469                 key = 'L';//Left
00470         }
00471         else if( keycode==315 )//Real keyCode for Left ARROW and non-Unicode
00472         {
00473                 key = 'U';//Up
00474         }
00475         else if( keycode==316 )//Real keyCode for Left ARROW and non-Unicode
00476         {
00477                 key = 'R';//Right
00478         }
00479         else if( keycode==317 )//Real keyCode for Down ARROW and non-Unicode
00480         {
00481                 key = 'D';//Down
00482         }
00483         else if( keycode==312 )//Real keyCode for Diagonal left down ARROW and non-Unicode
00484         {
00485                 key = 'W';//Diagonal left down
00486         }
00487         else if( keycode==313 )//Real keyCode for Diagonal left up ARROW and non-Unicode
00488         {
00489                 key = 'Q';//Diagonal left up
00490         }
00491         else if( keycode==366 )//Real keyCode for Diagonal right up ARROW and non-Unicode
00492         {
00493                 key = 'P';//Diagonal right up
00494         }
00495         else if( keycode==367 )//Real keyCode for Diagonal right down ARROW and non-Unicode
00496         {
00497                 key = 'M';//Diagonal right down
00498         }
00499   }
00500 
00501   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00502     event.ControlDown(), event.ShiftDown(), key, 0, NULL);
00503 
00504   InvokeEvent(vtkCommand::KeyPressEvent, NULL);
00505   InvokeEvent(vtkCommand::CharEvent, NULL);
00506 #else
00507   InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(), 
00508     event.GetKeyCode(), 1);
00509 #endif
00510   event.Skip();
00511 }
00512 //---------------------------------------------------------------------------
00513 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
00514 {
00515   if (!Enabled) 
00516     {
00517     return;
00518     }
00519 
00520 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00521     // new style
00522   int keycode = event.GetKeyCode();
00523   char key = '\0';
00524   if (keycode < 256)
00525   {
00526     // TODO: Unicode in non-Unicode mode ??
00527     key = (char)keycode;
00528   }
00529 
00530   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00531     event.ControlDown(), event.ShiftDown(), key, 0, NULL);
00532   InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
00533 #else
00534   InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(), 
00535     event.GetKeyCode(), 1);
00536 #endif
00537   event.Skip();
00538 }
00539 #endif 
00540 //---------------------------------------------------------------------------
00541 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
00542 {
00543   if (!Enabled || (ActiveButton != wxEVT_NULL))
00544     {
00545     return;
00546     }
00547   ActiveButton = event.GetEventType();
00548 
00549 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00550   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00551     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
00552 #endif
00553 
00554   if(event.RightDown())
00555   {
00556 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00557     // new style
00558     InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
00559 #else            
00560     // old style
00561     InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
00562       event.GetX(), Size[1] - event.GetY() - 1);
00563 #endif
00564   }
00565   else if(event.LeftDown())
00566   {
00567 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00568     // new style
00569     InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
00570 #else            
00571     // old style
00572     InteractorStyle->OnLeftButtonDown(event.ControlDown(),  event.ShiftDown(),
00573       event.GetX(), Size[1] - event.GetY() - 1);
00574 #endif
00575   }
00576   else if(event.MiddleDown())
00577   {
00578 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00579     // new style
00580     InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
00581 #else            
00582     // old style
00583     InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
00584       event.GetX(), Size[1] - event.GetY() - 1);
00585 #endif
00586   }
00587   //save the button and capture mouse until the button is released
00588   //Only if :
00589   //1. it is possible (WX_USE_X_CAPTURE)
00590   //2. user decided to.
00591   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
00592   {
00593     CaptureMouse();
00594   }
00595 }
00596 //---------------------------------------------------------------------------
00597 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
00598 {
00599   //EVT_xxx_DOWN == EVT_xxx_UP - 1
00600   //This is only needed if two mouse buttons are pressed at the same time.
00601   //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or 
00602   //wxEVT_COMMAND_RIGHT_CLICK
00603   if (!Enabled || (ActiveButton != (event.GetEventType()-1))) 
00604     {
00605     return;
00606     }
00607 
00608 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00609   SetEventInformationFlipY(event.GetX(), event.GetY(), 
00610     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
00611 #endif
00612   
00613   if(ActiveButton == wxEVT_RIGHT_DOWN)
00614   {
00615 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00616     // new style
00617     InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
00618 #else            
00619     // old style
00620     InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
00621       event.GetX(), Size[1] - event.GetY() - 1);
00622 #endif
00623   }
00624   else if(ActiveButton == wxEVT_LEFT_DOWN)
00625   {
00626 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00627     // new style
00628     InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
00629 #else            
00630     // old style
00631     InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
00632       event.GetX(), Size[1] - event.GetY() - 1);
00633 #endif
00634   }
00635   else if(ActiveButton == wxEVT_MIDDLE_DOWN)
00636   {
00637 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
00638     // new style
00639     InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
00640 #else            
00641     // old style
00642     InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
00643       event.GetX(), Size[1] - event.GetY() - 1);
00644 #endif
00645   }
00646   //if the ActiveButton is realeased, then release mouse capture
00647   if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
00648   {
00649     ReleaseMouse();
00650   }
00651   ActiveButton = wxEVT_NULL;
00652 }
00653 //---------------------------------------------------------------------------
00654 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
00655 {
00656 // Mouse wheel was only added after VTK 4.4 (I think...)
00657 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
00658   // new style
00659   //Set vtk event information ... The numebr of wheel rotations is stored in
00660   //the x varible.  y varible is zero
00661   SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0, 
00662                            event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
00663   if(event.GetWheelRotation() > 0)
00664     {
00665       //Send event to VTK
00666 // EED
00667 //      InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
00668     }
00669   else
00670     {
00671       //Send event to VTK
00672 // EED
00673 //      InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
00674     }
00675 #endif
00676     
00677 }
00678 
00679 //---------------------------------------------------------------------------
00680 void wxVTKRenderWindowInteractor::Render() throw (char*)
00681 {
00682   RenderAllowed = 1;
00683   if (!RenderWhenDisabled)
00684     {
00685     //the user doesn't want us to render when the toplevel frame
00686     //is disabled - first find the top level parent
00687     wxWindow *topParent = wxGetTopLevelParent(this);
00688     if (topParent)
00689       {
00690       //if it exists, check whether it's enabled
00691       //if it's not enabeld, RenderAllowed will be false
00692       RenderAllowed = topParent->IsEnabled();
00693       }
00694     }
00695 
00696   if (RenderAllowed)
00697     {
00698     if(Handle && (Handle == GetHandleHack()) )
00699       {
00700                   if(RenderWindow!=NULL){
00701                         RenderWindow->Render();
00702                   }else{
00703                           throw "wxVTKRenderWindowInteractor::Render(){RenderWindow not set}";
00704                   }
00705       }
00706 #if VTK_MAJOR_VERSION == 5 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
00707     else if(GetHandleHack())
00708       {
00709       //this means the user has reparented us; let's adapt to the
00710       //new situation by doing the WindowRemap dance
00711       //store the new situation
00712                   if(RenderWindow!=NULL){
00713                         Handle = GetHandleHack();
00714                         RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
00715                         RenderWindow->WindowRemap();
00716                         RenderWindow->Render();
00717                   }
00718       }
00719 #endif
00720     }
00721 }
00722 //---------------------------------------------------------------------------
00723 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
00724 {
00725   //Change value of __RenderWhenDisabled ivar.
00726   //If __RenderWhenDisabled is false (the default), this widget will not
00727   //call Render() on the RenderWindow if the top level frame (i.e. the
00728   //containing frame) has been disabled.
00729 
00730   //This prevents recursive rendering during wxSafeYield() calls.
00731   //wxSafeYield() can be called during the ProgressMethod() callback of
00732   //a VTK object to have progress bars and other GUI elements updated -
00733   //it does this by disabling all windows (disallowing user-input to
00734   //prevent re-entrancy of code) and then handling all outstanding
00735   //GUI events.
00736         
00737   //However, this often triggers an OnPaint() method for wxVTKRWIs,
00738   //resulting in a Render(), resulting in Update() being called whilst
00739   //still in progress.
00740 
00741   RenderWhenDisabled = (bool)newValue;
00742 }
00743 //---------------------------------------------------------------------------
00744 //
00745 // Set the variable that indicates that we want a stereo capable window
00746 // be created. This method can only be called before a window is realized.
00747 //
00748 void wxVTKRenderWindowInteractor::SetStereo(int capable)
00749 {
00750   if (Stereo != capable)
00751     {
00752     Stereo = capable;
00753     RenderWindow->StereoCapableWindowOn();
00754     RenderWindow->SetStereoTypeToCrystalEyes();
00755     Modified();
00756     }
00757 }
00758 
00759 //---------------------------------------------------------------------------
00760 //
00761 //
00762 void wxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
00763 {
00764   this->Superclass::PrintSelf(os, indent);
00765 }
00766 
00767 
00768 #if defined(_WIN32)
00769 const char * wxVTKRenderWindowInteractor::GetClassName() const
00770 {
00771   return "wxVTKRenderWindowInteractor";
00772 }
00773 #endif //_WIN32
00774 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1