]> Creatis software - crea.git/blobdiff - src/creawxVTKRenderWindowInteractor.mm
#3389 Stuck Render macOS
[crea.git] / src / creawxVTKRenderWindowInteractor.mm
index 6efc47c4c9f94e5b745522a9f7c5ac279d0b3a50..4f63d149db47ddebd16e61c7adf75752cad4cd24 100644 (file)
@@ -43,7 +43,6 @@
 
 =========================================================================*/
 
-#import <Cocoa/Cocoa.h>
 
 #include <assert.h>
 
@@ -63,7 +62,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"
+#import "/Users/davila/Creatis/C11/tpli/include/vtk-8.2/vtkTDxMacDevice.h"
+#endif
+
+
 //=======================================================================
 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
 namespace crea
@@ -102,7 +108,6 @@ wxWindow* wxGetTopLevelParent(wxWindow *win)
 // To access objc calls on cocoa
 #ifdef __WXCOCOA__
 #ifdef VTK_USE_COCOA
-//EED #import <Cocoa/Cocoa.h>
 // This trick is no longer need in VTK CVS, should get rid of that:
 #define id Id
 #else
@@ -111,7 +116,6 @@ wxWindow* wxGetTopLevelParent(wxWindow *win)
 #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"
@@ -271,6 +275,12 @@ 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,
@@ -311,6 +321,13 @@ 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()
@@ -320,6 +337,11 @@ wxVTKRenderWindowInteractor::~wxVTKRenderWindowInteractor()
 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
   delete this->context;
 #endif
+    
+#ifdef VTK_USE_TDX
+  this->Device->Delete();
+#endif
+
 }
 //---------------------------------------------------------------------------
 wxVTKRenderWindowInteractor * wxVTKRenderWindowInteractor::New()
@@ -354,11 +376,34 @@ 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
@@ -372,6 +417,14 @@ void wxVTKRenderWindowInteractor::Disable()
   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();
@@ -386,6 +439,7 @@ void wxVTKRenderWindowInteractor::Start()
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
 {
+//printf("EED wxVTKRenderWindowInteractor::UpdateSize Start\n");
   if( RenderWindow )
   {
     // if the size changed tell render window
@@ -395,12 +449,21 @@ void wxVTKRenderWindowInteractor::UpdateSize(int x, int y)
       Size[0] = x;
       Size[1] = y;
       // and our RenderWindow's size
+
+#ifdef __WXCOCOA__
+  #ifdef VTK_USE_COCOA
+  #else
+  #endif //VTK_USE_COCOA
+#else
       RenderWindow->SetSize(x, y);
+#endif //__WXCOCOA__
+      
 #if defined(__WXMSW__)
       this->Refresh();
 #endif //__WXMSW__
-    }
-  }
+    } // if x y
+  } // if RenderWindow
+printf("EED wxVTKRenderWindowInteractor::UpdateSize End\n");
 }
 //---------------------------------------------------------------------------
 int wxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
@@ -467,7 +530,6 @@ void wxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
 // in wxPython/src/helpers.cpp
 long wxVTKRenderWindowInteractor::GetHandleHack()
 {
-printf("EED  wxVTKRenderWindowInteractor::GetHandleHack start \n");
   //helper function to hide the MSW vs GTK stuff
   long handle_tmp = 0;
 
@@ -493,8 +555,6 @@ printf("EED  wxVTKRenderWindowInteractor::GetHandleHack start \n");
 
     // Find and return the actual X-Window.
 #if defined(__WXGTK__) || defined(__WXX11__)
-printf("EED  wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n", handle_tmp);
-printf("EED  wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \n",  (long)GetXWindow(this));
     return (long)GetXWindow(this);
 #endif
 
@@ -502,14 +562,19 @@ printf("EED  wxVTKRenderWindowInteractor::GetHandleHack End AAA handle_tmp %ld \
 //    handle_tmp = (long)this->GetXWindow();
 //#endif
 
-printf("EED  wxVTKRenderWindowInteractor::GetHandleHack End BBB handle_tmp %ld \n", handle_tmp);
   return handle_tmp;
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
+printf("EED wxVTKRenderWindowInteractor::OnPaint Start\n");
+
   //must always be here
-  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)
@@ -525,8 +590,6 @@ void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
 #else  
     RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
 #endif
-
-               
        
 // Cocoa
 // this->GetNSView() <-> DisplayId
@@ -570,6 +633,8 @@ void wxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
   }
 #endif
 #endif
+    
+printf("EED wxVTKRenderWindowInteractor::OnPaint End\n");
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
@@ -686,7 +751,8 @@ void wxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
 {
-  if (!Enabled) 
+printf("EED wxVTKRenderWindowInteractor::OnKeyUp Start\n");
+  if (!Enabled)
     {
     return;
     }
@@ -712,11 +778,13 @@ void wxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
     event.GetKeyCode(), 1);
 #endif
   event.Skip();
+printf("EED wxVTKRenderWindowInteractor::OnKeyUp End\n");
 }
 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
  //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
 {
+printf("EED wxVTKRenderWindowInteractor::OnKeyUp Start\n");
   if (!Enabled) 
     {
     return;
@@ -740,10 +808,12 @@ void wxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
   InvokeEvent(vtkCommand::CharEvent, NULL);
 #endif
   event.Skip();
+printf("EED wxVTKRenderWindowInteractor::OnKeyUp End\n");
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
 {
+printf("EED wxVTKRenderWindowInteractor::OnButtonDown Start\n");
   if (!Enabled || (ActiveButton != wxEVT_NULL))
     {
     return;
@@ -802,10 +872,12 @@ void wxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
   {
     CaptureMouse();
   }
+printf("EED wxVTKRenderWindowInteractor::OnButtonDown End\n");
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
 {
+printf("EED wxVTKRenderWindowInteractor::OnButtonDown Start\n");
   //EVT_xxx_DOWN == EVT_xxx_UP - 1
   //This is only needed if two mouse buttons are pressed at the same time.
   //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or 
@@ -862,10 +934,12 @@ void wxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
     ReleaseMouse();
   }
   ActiveButton = wxEVT_NULL;
+printf("EED wxVTKRenderWindowInteractor::OnButtonDown End\n");
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
 {
+printf("EED wxVTKRenderWindowInteractor::OnMouseWheel Start\n");
 // Mouse wheel was only added after VTK 4.4 (I think...)
 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 4)
   // new style
@@ -884,7 +958,8 @@ void wxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
       InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
     }
 #endif
-    
+    printf("EED wxVTKRenderWindowInteractor::OnMouseWheel End\n");
+
 }
 
 //---------------------------------------------------------------------------
@@ -907,7 +982,7 @@ void wxVTKRenderWindowInteractor::OnMouseCaptureLost(wxMouseCaptureLostEvent& ev
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::Render()
 {
-printf("EED wxVTKRenderWindowInteractor::Render Start \n");
+printf("EED wxVTKRenderWindowInteractor::Render Start\n");
 #if wxCHECK_VERSION(2, 8, 0)
   int renderAllowed = !IsFrozen();
 #else
@@ -924,7 +999,7 @@ printf("EED wxVTKRenderWindowInteractor::Render Start \n");
       //if it's not enabeld, renderAllowed will be false
       renderAllowed = topParent->IsEnabled();
       }
-    }
+    } // if renderAllowed && !RenderWhenDisabled
 
   if (renderAllowed)
     {
@@ -933,9 +1008,7 @@ printf("EED wxVTKRenderWindowInteractor::Render Start \n");
 #endif
     if(Handle && (Handle == GetHandleHack()) )
       {
-printf("EED wxVTKRenderWindowInteractor::Render 1 \n");
       RenderWindow->Render();
-printf("EED wxVTKRenderWindowInteractor::Render 2 \n");
       }
 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
     else if(GetHandleHack())
@@ -949,10 +1022,8 @@ printf("EED wxVTKRenderWindowInteractor::Render 2 \n");
       RenderWindow->Render();
       }
 #endif
-
-printf("EED wxVTKRenderWindowInteractor::Render End \n");
-
-    }
+    } // if renderAllowed
+printf("EED wxVTKRenderWindowInteractor::Render Start\n");
 }
 //---------------------------------------------------------------------------
 void wxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)