Commit cc00952e authored by Flavien Bridault's avatar Flavien Bridault
Browse files

Refresh patches for new upstream version

parent a6dbfed8
Loading
Loading
Loading
Loading
+33 −355
Original line number Diff line number Diff line
@@ -5,84 +5,53 @@ Description: Revert QVTKOpenGLWidget usage that do no exist in VTK 6.3
 index b8916f5..71e3ed3 100644
--- sight.orig/Bundles/visu/visuVTKQt/include/visuVTKQt/Plugin.hpp
+++ sight/Bundles/visu/visuVTKQt/include/visuVTKQt/Plugin.hpp
@@ -23,19 +23,20 @@
 #ifndef __VISUVTKQT_PLUGIN_HPP__
 #define __VISUVTKQT_PLUGIN_HPP__
 
-#include "visuVTKQt/config.hpp"
-
 #include <fwRuntime/Plugin.hpp>
 
+#include "visuVTKQt/config.hpp"
+
 namespace visuVTKQt
 {
 /**
  * @brief   This class is started when the bundles is loaded.
+ * @class   Plugin
+ *
+ * @date    2009.
@@ -34,13 +34,6 @@
  */
 struct VISUVTKQT_CLASS_API Plugin : public ::fwRuntime::Plugin
 {
-    Plugin() noexcept;
-
     /**
      * @brief   destructor
      */
-    /**
-     * @brief   destructor
-     */
-    ~Plugin() noexcept;
-
     // Overrides
     VISUVTKQT_API void start();
 
--- sight.orig/Bundles/visu/visuVTKQt/include/visuVTKQt/VtkRenderWindowInteractorManager.hpp
+++ sight/Bundles/visu/visuVTKQt/include/visuVTKQt/VtkRenderWindowInteractorManager.hpp
@@ -25,14 +25,19 @@
 
 #include "visuVTKQt/config.hpp"
 
+#include <fwCore/base.hpp>
+
+#include <fwGui/container/fwContainer.hpp>
+
 #include <fwRenderVTK/IVtkRenderWindowInteractorManager.hpp>
 
-#include <QPointer>
+#include <string>
+
 
@@ -31,7 +31,7 @@
 class vtkRenderWindowInteractor;
 
 QT_BEGIN_NAMESPACE
-class QVTKOpenGLWidget;
-class QVTKOpenGLNativeWidget;
+class QVTKWidget;
 QT_END_NAMESPACE
 
 namespace fwGuiQt
@@ -72,7 +77,7 @@
@@ -71,7 +71,7 @@
 
 private:
 
-    QPointer<QVTKOpenGLWidget> m_QVTKOpenGLWidget;
+    QPointer<QVTKWidget> m_qVTKWidget;
-    QPointer<QVTKOpenGLNativeWidget> m_QVTKOpenGLWidget;
+    QPointer<QVTKWidget> m_QVTKOpenGLWidget;
 
     vtkRenderWindowInteractor* m_interactor;
 
@@ -84,3 +89,4 @@
 
 #endif // __VISUVTKQT_VTKRENDERWINDOWINTERACTORMANAGER_HPP__
 
+
--- sight.orig/Bundles/visu/visuVTKQt/src/visuVTKQt/Plugin.cpp
+++ sight/Bundles/visu/visuVTKQt/src/visuVTKQt/Plugin.cpp
@@ -26,11 +26,6 @@
@@ -26,9 +26,6 @@
 
 #include <fwRuntime/utils/GenericExecutableFactoryRegistrar.hpp>
 
-#include <QApplication>
-#include <QSurfaceFormat>
-#include <QVTKOpenGLWidget.h>
-#include <vtkGenericOpenGLRenderWindow.h>
-
 namespace visuVTKQt
 {
-#include <QVTKOpenGLNativeWidget.h>
 #include <vtkGenericOpenGLRenderWindow.h>
 
@@ -40,22 +35,6 @@
 namespace visuVTKQt
@@ -40,28 +37,6 @@
 
 //-----------------------------------------------------------------------------
 
@@ -97,313 +66,23 @@ Description: Revert QVTKOpenGLWidget usage that do no exist in VTK 6.3
-                qApp == nullptr );
-
-    vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(0);
-    QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
-    QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
-}
-
-//-----------------------------------------------------------------------------
-
-Plugin::~Plugin() noexcept
-{
-}
-
-//-----------------------------------------------------------------------------
-
 Plugin::~Plugin() noexcept
 void Plugin::start()
 {
 }
     SLM_TRACE_FUNC();
--- sight.orig/Bundles/visu/visuVTKQt/src/visuVTKQt/VtkRenderWindowInteractorManager.cpp
+++ sight/Bundles/visu/visuVTKQt/src/visuVTKQt/VtkRenderWindowInteractorManager.cpp
@@ -20,30 +20,279 @@
  *
  ***********************************************************************/
 
-#include "visuVTKQt/VtkRenderWindowInteractorManager.hpp"
+#include <QVBoxLayout>
+#include <QEvent>
+#include <QDropEvent>
 
-#include <fwCom/Signal.hpp>
-#include <fwCom/Signal.hxx>
+#include <QVTKWidget.h>
+
+#include <QMimeData>
+
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
 
 #include <fwData/String.hpp>
 
-#include <fwGuiQt/container/QtContainer.hpp>
+#include <fwTools/UUID.hpp>
+
+#include <fwCom/Signal.hpp>
+#include <fwCom/Signal.hxx>
 
-#include <fwRenderVTK/registry/macros.hpp>
 #include <fwRenderVTK/SRender.hpp>
+#include <fwRenderVTK/registry/macros.hpp>
+#include <fwGuiQt/container/QtContainer.hpp>
 
-#include <fwTools/UUID.hpp>
+#include "visuVTKQt/VtkRenderWindowInteractorManager.hpp"
 
-#include <QDropEvent>
-#include <QEvent>
-#include <QMimeData>
-#include <QSurfaceFormat>
-#include <QVBoxLayout>
-#include <QVTKOpenGLWidget.h>
-#include <vtkGenericOpenGLRenderWindow.h>
-#include <vtkRenderer.h>
-#include <vtkRenderWindow.h>
-#include <vtkRenderWindowInteractor.h>
+#ifdef __APPLE__
+// XXX Retinhack
+// hack to fix vtk render windows on mac retina screen, until fixed
+// by vtk
+#include <QWindow>
+#include <QScreen>
+#include <QVTKInteractor.h>
+#include <vtkCocoaRenderWindow.h>
+#include <vtkObjectFactory.h>
+#include <vtkSmartPointer.h>
+#include <vtkInteractorStyleTrackballCamera.h>
+#include <QMetaEnum>
+
+class RetinHackRWI : public QVTKInteractor
+{
+protected:
+    RetinHackRWI() :
+        QVTKInteractor()
+    {
+    }
+
+public:
+
+    static RetinHackRWI* New();
+
+    //------------------------------------------------------------------------------
+
+    virtual int* GetLastEventPosition ()
+    {
+        auto LastPos = this->QVTKInteractor::GetLastEventPosition();
+        const auto r = this->Ratio;
+
+        LastRetinaPos[0] = LastPos[0]*r;
+        LastRetinaPos[1] = LastPos[1]*r;
+
+        return LastRetinaPos;
+    }
+
+    //------------------------------------------------------------------------------
+
+    virtual void GetLastEventPosition (int& x, int& y)
+    {
+        auto LastPos = this->QVTKInteractor::GetLastEventPosition();
+        const auto r = this->Ratio;
+
+        x = LastPos[0]*r;
+        y = LastPos[1]*r;
+    }
+
+    //------------------------------------------------------------------------------
+
+    virtual void GetLastEventPosition (int xy[2])
+    {
+        auto LastPos = this->QVTKInteractor::GetLastEventPosition();
+        const auto r = this->Ratio;
+
+        xy[0] = LastPos[0]*r;
+        xy[1] = LastPos[1]*r;
+    }
+
+    //------------------------------------------------------------------------------
+
+    virtual int* GetEventPosition ()
+    {
+        auto Pos     = this->QVTKInteractor::GetEventPosition();
+        const auto r = this->Ratio;
+
+        RetinaPos[0] = Pos[0]*r;
+        RetinaPos[1] = Pos[1]*r;
+
+        return RetinaPos;
+    }
+
+    //------------------------------------------------------------------------------
+
+    virtual void GetEventPosition (int& x, int& y)
+    {
+        auto Pos     = this->QVTKInteractor::GetEventPosition();
+        const auto r = this->Ratio;
+
+        x = Pos[0]*r;
+        y = Pos[1]*r;
+    }
+
+    //------------------------------------------------------------------------------
+
+    virtual void GetEventPosition (int xy[2])
+    {
+        auto Pos     = this->QVTKInteractor::GetEventPosition();
+        const auto r = this->Ratio;
+
+        xy[0] = Pos[0]*r;
+        xy[1] = Pos[1]*r;
+    }
+
+    //------------------------------------------------------------------------------
+
+    void SetDevicePixelRatio(int r)
+    {
+        this->Ratio = r;
+    }
+
+private:
+    int RetinaPos[2];
+    int LastRetinaPos[2];
+
+    int Ratio = 2;
+
+};
+
+vtkStandardNewMacro(RetinHackRWI);
+
+class RetinhackRenderWindow : public vtkCocoaRenderWindow
+{
+protected:
+    RetinhackRenderWindow() :
+        vtkCocoaRenderWindow()
+    {
+    }
+
+public:
+
+    static RetinhackRenderWindow* New();
+
+    //------------------------------------------------------------------------------
+
+    int* GetSize()
+    {
+        this->vtkCocoaRenderWindow::GetSize();
+
+        this->RetinaSize[0] = this->Size[0] * this->Ratio;
+        this->RetinaSize[1] = this->Size[1] * this->Ratio;
+
+        return this->RetinaSize;
+    }
+
+    //------------------------------------------------------------------------------
+
+    int* GetScreenSize()
+    {
+        this->vtkCocoaRenderWindow::GetScreenSize();
+
+        this->RetinaSize[0] = this->Size[0] * this->Ratio;
+        this->RetinaSize[1] = this->Size[1] * this->Ratio;
+
+        return this->RetinaSize;
+    }
+
+    //------------------------------------------------------------------------------
+
+    vtkRenderWindowInteractor* MakeRenderWindowInteractor()
+    {
+        this->Interactor = RetinHackRWI::New();
+        this->Interactor->SetRenderWindow(this);
+        return this->Interactor;
+    }
+
+    //------------------------------------------------------------------------------
+
+    void SetDevicePixelRatio(int r)
+    {
+        this->Ratio = r;
+        static_cast< RetinHackRWI* >( this->Interactor )->SetDevicePixelRatio(r);
+    }
+
+private:
+    int RetinaSize[2] = {600, 600};
+    int Ratio         = 2;
+};
+
+vtkStandardNewMacro(RetinhackRenderWindow);
+
+class RetinhackVtkWidget : public QVTKWidget
+{
+public:
+    RetinhackVtkWidget(QWidget* container = nullptr) :
+        QVTKWidget(container)
+    {
+        vtkSmartPointer< vtkInteractorStyleTrackballCamera > interactorStyle
+            = vtkInteractorStyleTrackballCamera::New();
+        vtkSmartPointer< RetinhackRenderWindow > renderWindow = RetinhackRenderWindow::New();
+        vtkSmartPointer< RetinHackRWI > rwi                   = RetinHackRWI::New();
+
+        rwi->Initialize();
+        rwi->SetInteractorStyle(interactorStyle);
+        rwi->SetRenderWindow(renderWindow);
+        renderWindow->SetInteractor(rwi);
+
+        this->SetRenderWindow(renderWindow);
+
+    }
+
+    //------------------------------------------------------------------------------
+
+    bool event(QEvent* e)
+    {
+        auto ratio = this->devicePixelRatio();
+        if (m_ratio != ratio )
+        {
+            SLM_ASSERT( "Render window shall be a RetinhackRenderWindow",
+                        dynamic_cast< RetinhackRenderWindow* >( this->mRenWin ));
+            static_cast< RetinhackRenderWindow* >( this->mRenWin )->SetDevicePixelRatio(ratio);
+            m_ratio = ratio;
+        }
+
+        if(e->type() == QEvent::ShowToParent)
+        {
+            QObject::disconnect(m_renderConnection);
+            QPointer<RetinhackVtkWidget> widget(this);
+            m_renderConnection = QObject::connect(this->window()->windowHandle(), &QWindow::screenChanged, [ = ] ()
+            {
+                if(!widget)
+                {
+                    return;
+                }
+                auto ratio = widget->devicePixelRatio();
+                SLM_ASSERT( "Render window shall be a RetinhackRenderWindow",
+                            dynamic_cast< RetinhackRenderWindow* >( widget->mRenWin ));
+                static_cast< RetinhackRenderWindow* >( widget->mRenWin )->SetDevicePixelRatio(ratio);
+                widget->mRenWin->Render();
+            });
+        }
+
+        return QVTKWidget::event(e);
+    }
+
+    //------------------------------------------------------------------------------
+
+    virtual void SetRenderWindow(vtkRenderWindow* rw)
+    {
+        QVTKWidget::SetRenderWindow(rw);
+
+        auto ratio = this->devicePixelRatio();
+
+        SLM_ASSERT( "Render window shall be a RetinhackRenderWindow",
+                    dynamic_cast< RetinhackRenderWindow* >( this->mRenWin ));
+        static_cast< RetinhackRenderWindow* >( this->mRenWin )->SetDevicePixelRatio(ratio);
+    }
+
+protected:
+    int m_ratio = -1;
+
+    QMetaObject::Connection m_renderConnection;
+};
+
+#define QVTKWidget RetinhackVtkWidget
+
+#endif //__APPLE__
 
 class DropFilter : public QObject
 {
@@ -119,25 +368,22 @@
@@ -119,25 +119,22 @@
     SLM_ASSERT("Invalid parent.", _parent );
     m_parentContainer = ::fwGuiQt::container::QtContainer::dynamicCast( _parent );
 
@@ -415,19 +94,18 @@ Description: Revert QVTKOpenGLWidget usage that do no exist in VTK 6.3
-
-    // Create the render window and the associated QVTKOpenGLWidget
-    vtkNew<vtkGenericOpenGLRenderWindow> window;
-    m_QVTKOpenGLWidget = new QVTKOpenGLWidget(m_parentContainer->getQtContainer());
-    m_QVTKOpenGLWidget = new QVTKOpenGLNativeWidget(m_parentContainer->getQtContainer());
-    m_QVTKOpenGLWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    layout->addWidget(m_QVTKOpenGLWidget);
-    m_QVTKOpenGLWidget->SetRenderWindow(window.Get());
 
     // Install Drop filter
-    if(auto locked = m_renderService.lock())
+    if(m_renderService.lock())
     if(auto locked = m_renderService.lock())
     {
-        m_QVTKOpenGLWidget->setAcceptDrops(true);
-        m_QVTKOpenGLWidget->installEventFilter(new DropFilter(locked));
+        m_qVTKWidget->setAcceptDrops(true);
+        m_qVTKWidget->installEventFilter(new DropFilter(m_renderService.lock()));
+        m_qVTKWidget->installEventFilter(new DropFilter(locked));
     }
 
-    m_interactor = window->GetInteractor();
@@ -438,7 +116,7 @@ Description: Revert QVTKOpenGLWidget usage that do no exist in VTK 6.3
 }
 
 //-----------------------------------------------------------------------------
@@ -146,8 +392,8 @@
@@ -146,8 +143,8 @@
 {
     m_interactor = nullptr;
 
+31 −60
Original line number Diff line number Diff line
--- sight.orig/CMake/install/linux_install.cmake
+++ sight/CMake/install/linux_install.cmake
@@ -20,7 +20,7 @@
 #Linux install
 macro(linux_install PRJ_NAME)
 
-    if(NOT USE_SYSTEM_LIB AND NOT BUILD_SDK AND NOT USE_CONAN)
+    if(NOT USE_SYSTEM_LIB AND NOT BUILD_SDK AND NOT USE_CONAN AND NOT FW_BUILD_EXTERNAL)
         findExtLibDir(EXTERNAL_LIBRARIES_DIRECTORIES)
     endif()
     set(CPACK_GENERATOR TGZ)
@@ -73,28 +73,30 @@
         endif()
@@ -49,24 +49,26 @@
         install_qt_plugins()
     endif()
 
-    if(NOT BUILD_SDK OR (BUILD_SDK AND ${PRJ_NAME} STREQUAL "sight") )
-    if(${PRJ_NAME} STREQUAL "sight")
-        # Needed for fixup_bundle first argument
-        set(LAUNCHER_PATH "bin/fwlauncher-${fwlauncher_VERSION}")
+    if(NOT USE_SYSTEM_LIB)
+        if(NOT BUILD_SDK OR (BUILD_SDK AND ${PRJ_NAME} STREQUAL "sight") )
+        if(${PRJ_NAME} STREQUAL "sight")
+            # Needed for fixup_bundle first argument
+            set(LAUNCHER_PATH "bin/fwlauncher-${fwlauncher_VERSION}")
+        endif()
+
+            if(NOT BUILD_SDK)
+        configure_file(${FWCMAKE_RESOURCE_PATH}/install/linux/linux_fixup.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/linux_fixup.cmake @ONLY)
+        install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/linux_fixup.cmake)
+            else()
+                installConanDepsForSDK()
+            endif()
+
+        set(CPACK_OUTPUT_FILE_PREFIX packages)
+        set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_INSTALL_PREFIX};.") #look inside install dir for packaging
+
+        execute_process( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
+
+            set(CPACK_PACKAGE_FILE_NAME "${PRJ_NAME}-${VERSION}-linux_${ARCHITECTURE}")
+        set(CPACK_PACKAGE_FILE_NAME "${PRJ_NAME}-${VERSION}-linux_${ARCHITECTURE}-Sight_${GIT_TAG}")
+        set(CPACK_PACKAGE_VENDOR "IRCAD-IHU")
+        set(CPACK_PACKAGE_NAME "${PRJ_NAME}")
+        set(CPACK_PACKAGE_VERSION "${VERSION}")
     endif()
-
-        if(NOT BUILD_SDK)
 
-    configure_file(${FWCMAKE_RESOURCE_PATH}/install/linux/linux_fixup.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/linux_fixup.cmake @ONLY)
-    install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/linux_fixup.cmake)
-        else()
-            installConanDepsForSDK()
-        endif()
-
-    set(CPACK_OUTPUT_FILE_PREFIX packages)
-    set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_INSTALL_PREFIX};.") #look inside install dir for packaging
-
-    execute_process( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
-
-        set(CPACK_PACKAGE_FILE_NAME "${PRJ_NAME}-${VERSION}-linux_${ARCHITECTURE}")
-    set(CPACK_PACKAGE_FILE_NAME "${PRJ_NAME}-${VERSION}-linux_${ARCHITECTURE}-Sight_${GIT_TAG}")
-    set(CPACK_PACKAGE_VENDOR "IRCAD-IHU")
-    set(CPACK_PACKAGE_NAME "${PRJ_NAME}")
-    set(CPACK_PACKAGE_VERSION "${VERSION}")
     endif()
 
-
     if("${${PRJ_NAME}_TYPE}" STREQUAL  "APP")
--- sight.orig/CMake/build/SightConfig.cmake.in
+++ sight/CMake/build/SightConfig.cmake.in
@@ -11,7 +11,7 @@
         add_definitions(${CONAN_DEFINES})
         set(FW_CONAN_CONFIGURED 1)
     endif()
-else()
+elif(NOT USE_SYSTEM_LIB)
     set(EXTERNAL_LIBRARIES CACHE PATH "External libraries location (if not at a default location like /usr on Linux)")
 
     file(TO_CMAKE_PATH ${EXTERNAL_LIBRARIES} FWEXTERNAL_LIBRARIES)
         string(TOLOWER ${PRJ_NAME} APP_NAME)
         configure_file(${FWCMAKE_RESOURCE_PATH}/install/linux/template.sh.in ${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME} @ONLY)