]> Creatis software - crea.git/blobdiff - src/creawxVTKRenderWindowInteractor.mm
#3394 wxwidgets 3.2 macOS
[crea.git] / src / creawxVTKRenderWindowInteractor.mm
index 3047c9397e9c54ec980e4edfa0b30ad39ef665b9..33f4e84002409d8f58ae5eb0f438765da9699652 100644 (file)
 
 =========================================================================*/
 
-//#import <Cocoa/Cocoa.h>
 
 #include <assert.h>
 
 #include "creawxVTKRenderWindowInteractor.h"
 
-#include <wx/display.h>
-
-
 //This is needed for vtk 3.1 :
 #ifndef VTK_MAJOR_VERSION
 #  include "vtkVersion.h"
 #endif
 
+
 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
 #  include "vtkCommand.h"
 #else
@@ -66,7 +63,8 @@
 
 // AKT: wxOSX 2.9.x defines __WXOSX_COCOA__ rather than __WXCOCOA__
 #ifdef __WXOSX_COCOA__
-#define __WXCOCOA__
+   #import <Cocoa/Cocoa.h>
+   #define __WXCOCOA__
 #endif
 
 #if defined(__WXMAC__) && wxCHECK_VERSION(2,9,0)
 #endif
 
 
+#ifdef VTK_USE_TDX
+#import "vtkTDxMacDevice.h"
+#endif
+
+
 //=======================================================================
 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
 namespace crea
@@ -104,17 +107,19 @@ wxWindow* wxGetTopLevelParent(wxWindow *win)
 
 // To access objc calls on cocoa
 #ifdef __WXCOCOA__
-#ifdef VTK_USE_COCOA
-#import <Cocoa/Cocoa.h>
-// This trick is no longer need in VTK CVS, should get rid of that:
+
 #define id Id
-#else
-#error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
-#endif //VTK_USE_COCOA
+
+// #ifdef VTK_USE_COCOA
+// // This trick is no longer need in VTK CVS, should get rid of that:
+// #define id Id
+// #else
+// #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
+// #endif //VTK_USE_COCOA
+
 #endif //__WXCOCOA__
 
 #if wxMAJOR_VERSION <= 2
-
        #ifdef __WXGTK__
         #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
         #include "gdk/gdkprivate.h"
@@ -265,6 +270,7 @@ wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
       , RenderWhenDisabled(1)
       , UseCaptureMouse(0)
 {
+    
 #ifdef VTK_DEBUG_LEAKS
   vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
 #endif
@@ -274,6 +280,11 @@ wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor()
   this->RenderWindow = NULL;
   this->SetRenderWindow(vtkRenderWindow::New());
   this->RenderWindow->Delete();
+    
+#ifdef VTK_USE_TDX
+    this->Device=vtkTDxMacDevice::New();
+#endif
+
 }
 //---------------------------------------------------------------------------
 wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
@@ -300,6 +311,7 @@ wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
       , RenderWhenDisabled(1)
       , UseCaptureMouse(0)
 {
+        
 #ifdef VTK_DEBUG_LEAKS
   vtkDebugLeaks::ConstructClass("wxVTKRenderWindowInteractor");
 #endif
@@ -314,7 +326,14 @@ wxVTKRenderWindowInteractor::wxVTKRenderWindowInteractor(wxWindow *parent,
   // so we update the size information of the interactor/renderwindow here
   this->UpdateSize(size.x, size.y);
 #endif
+    
+
+#ifdef VTK_USE_TDX
+    this->Device=vtkTDxMacDevice::New();
+#endif
+
 }
+
 //---------------------------------------------------------------------------
 wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
 {
@@ -323,13 +342,19 @@ wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
   delete this->context;
 #endif
+    
+#ifdef VTK_USE_TDX
+  this->Device->Delete();
+#endif
 }
+
 //---------------------------------------------------------------------------
 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
 {
   // we don't make use of the objectfactory, because we're not registered
   return new wxVTKRenderWindowInteractor;
 }
+
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::Initialize()
 {
@@ -337,13 +362,11 @@ void wxVTKRenderWindowInteractor::Initialize()
   // enable everything and start rendering
   Enable();
   //RenderWindow->Start();
-
   // set the size in the render window interactor
   Size[0] = size[0];
   Size[1] = size[1];
-
   // this is initialized
-  Initialized = 1;
+    Initialized = 1;
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::Enable()
@@ -357,11 +380,30 @@ void wxVTKRenderWindowInteractor::Enable()
 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
   wxGLCanvas::SetCurrent(*this->context);
 #endif
+
+//EED 2010-10-14
+#ifdef VTK_USE_TDX
+  if(this->UseTDx)
+  {
+    this->Device->SetInteractor(this);
+    this->Device->Initialize();
+  }
+#endif
+
   Modified();
+    
 }
 //---------------------------------------------------------------------------
 bool wxVTKRenderWindowInteractor::Enable(bool enable)
 {
+#ifdef VTK_USE_TDX
+  if(this->UseTDx)
+  {
+    this->Device->SetInteractor(this);
+    this->Device->Initialize();
+  }
+#endif
+
 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
   return wxGLCanvas::Enable(enable);
 #else
@@ -373,8 +415,17 @@ void wxVTKRenderWindowInteractor::Disable()
 {
   // if already disabled then done
   if (!Enabled)
+  {
     return;
-
+  }
+#ifdef VTK_USE_TDX
+  if(this->Device->GetInitialized())
+  {
+    this->Device->Close();
+  }
+#endif
+    
+    
   // that's it (we can't remove the event handler like it should be...)
   Enabled = 0;
   Modified();
@@ -400,9 +451,9 @@ void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
       // and our RenderWindow's size
 
 #ifdef __WXCOCOA__
-  #ifdef VTK_USE_COCOA
-  #else
-  #endif //VTK_USE_COCOA
+//  #ifdef VTK_USE_COCOA
+//  #else
+//  #endif //VTK_USE_COCOA
 #else
       RenderWindow->SetSize(x, y);
 #endif //__WXCOCOA__
@@ -418,19 +469,21 @@ int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
 {
   // it's a one shot timer
   if (!timer.Start(10, TRUE))
+  {
     return 0;
-
+  }
   return 1;
-  
 }
+
 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
 //------------------------------------------------------------------
 int wxVTKRenderWindowInteractor::InternalCreateTimer(int timerId, int timerType,
                                                      unsigned long duration)
 {
   if (!timer.Start(duration, timerType == OneShotTimer))
+  {
     return 0;
-    
+  }
   return ID_wxVTKRenderWindowInteractor_TIMER;
 }
 //------------------------------------------------------------------
@@ -440,12 +493,14 @@ int wxVTKRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
   return 1;
 }
 #endif
+
 //---------------------------------------------------------------------------
 int wxVTKRenderWindowInteractor::DestroyTimer()
 {
   // do nothing
   return 1;
 }
+
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
 {
@@ -515,9 +570,12 @@ long wxVTKRenderWindowInteractor::GetHandleHack()
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
-
   //must always be here
-//EED2021-08-26  wxPaintDC pDC(this);
+//EED2021-08-26  
+#ifdef __WXCOCOA__
+#else
+       wxPaintDC pDC(this);
+#endif
 
   //do it here rather than in the cstor: this is safer.
   if(!Handle)
@@ -526,9 +584,6 @@ void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
        
 #ifdef __WXCOCOA__
        vtkCocoaRenderWindow    *rwin           = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
-//2021-08-30
-//      rwin->SetWantsBestResolution(true);
-      
     NSView                                     *nvsview        = (NSView* )Handle;
        NSWindow                                *nswindow       = nvsview.window;
     rwin->SetRootWindow( nswindow );
@@ -555,8 +610,7 @@ void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
     #endif
   }
   // get vtk to render to the wxWindows
-
-Render();
+  Render();
 #ifdef __WXMAC__
   // This solves a problem with repainting after a window resize
   // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
@@ -570,7 +624,6 @@ Render();
     }
   #endif
 #else
-    
   vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
   if( rwin )
   {
@@ -581,8 +634,8 @@ Render();
   }
 #endif
 #endif
+    
 }
-
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
 {
@@ -606,9 +659,7 @@ void wxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
 #endif
   //this will check for Handle
   //Render();
-
 }
-
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
 {
@@ -617,7 +668,6 @@ void wxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
     return;
     }
 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
-
   SetEventInformationFlipY(event.GetX(), event.GetY(), 
     event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
 
@@ -671,7 +721,7 @@ void wxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
 {
-  if (!Enabled) 
+  if (!Enabled)
     {
     return;
     }
@@ -701,7 +751,7 @@ void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
 {
-  if (!Enabled) 
+  if (!Enabled)
     {
     return;
     }
@@ -732,7 +782,7 @@ void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
  //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
 {
-  if (!Enabled) 
+  if (!Enabled)
     {
     return;
     }
@@ -899,7 +949,7 @@ void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
       InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
     }
 #endif
-    
+
 }
 
 //---------------------------------------------------------------------------
@@ -938,7 +988,7 @@ void wxVTKRenderWindowInteractor::Render()
       //if it's not enabeld, renderAllowed will be false
       renderAllowed = topParent->IsEnabled();
       }
-    }
+    } // if renderAllowed && !RenderWhenDisabled
 
   if (renderAllowed)
     {
@@ -961,8 +1011,7 @@ void wxVTKRenderWindowInteractor::Render()
       RenderWindow->Render();
       }
 #endif
-
-    }
+    } // if renderAllowed
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)