wxVTKRenderWindowInteractor.cpp

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

Generated on Wed Jan 24 15:56:26 2007 for MechSys by  doxygen 1.4.7