Browse Source

Merge branch 'cli-module-support' into dah

Ivo Wolf 13 years ago
parent
commit
9ddcc60d3c

+ 26 - 8
Applications/ctkSimplePythonShell/CMakeLists.txt

@@ -3,7 +3,10 @@ project(ctkSimplePythonShell)
 #
 # 3rd party dependencies
 #
-include(${VTK_USE_FILE})
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  find_package(VTK REQUIRED)
+  include(${VTK_USE_FILE})
+endif()
 
 #
 # See CTK/CMake/ctkMacroBuildApp.cmake for details
@@ -19,7 +22,7 @@ set(KIT_SRCS
   ctkTestWrappedSlot.h
 )
 
-if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
   list(APPEND KIT_SRCS
     ctkTestWrappedQListOfVTKObject.h
     ctkTestWrappedVTKObserver.h
@@ -37,7 +40,7 @@ set(KIT_MOC_SRCS
   ctkTestWrappedSlot.h
   )
 
-if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
   list(APPEND KIT_MOC_SRCS
     ctkTestWrappedQListOfVTKObject.h
     ctkTestWrappedVTKObserver.h
@@ -48,22 +51,36 @@ endif()
 
 # UI files
 set(KIT_UI_FORMS
-)
+  )
 
 # Resources
 set(KIT_resources
-)
+  )
+
+set(KIT_INCLUDE_DIRECTORIES
+  )
 
-# Set VTK_LIBRARIES variable
 set(VTK_LIBRARIES
-  vtkCommon
-  vtkFiltering
   )
 
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  list(APPEND KIT_INCLUDE_DIRECTORIES
+    ${CTKVisualizationVTKCore_BINARY_DIR}
+    ${CTKVisualizationVTKCore_SOURCE_DIR}
+    )
+endif()
+
 # Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
 # The following macro will read the target libraries from the file 'target_libraries.cmake'
 ctkFunctionGetTargetLibraries(KIT_target_libraries)
 
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  list(APPEND KIT_target_libraries
+    CTKVisualizationVTKCore
+    vtkFiltering
+    )
+endif()
+
 # Configure file will be configured using CTK_WRAP_PYTHONQT_{LIGHT, FULL} and
 # CTK_BUILD_SHARED_LIBS variables
 configure_file(
@@ -123,6 +140,7 @@ ctkMacroBuildApp(
   SRCS ${KIT_SRCS}
   MOC_SRCS ${KIT_MOC_SRCS}
   UI_FORMS ${KIT_UI_FORMS}
+  INCLUDE_DIRECTORIES ${KIT_INCLUDE_DIRECTORIES}
   TARGET_LIBRARIES ${KIT_target_libraries}
   RESOURCES ${KIT_resources}
   )

+ 8 - 1
Applications/ctkSimplePythonShell/ctkSimplePythonManager.cpp.in

@@ -10,8 +10,11 @@
 // CTK includes
 #include "ctkSimplePythonManager.h"
 #include "ctkSimplePythonQtDecorators.h"
+#include "ctkSimplePythonShellConfigure.h" // For CTK_WRAP_PYTHONQT_{LIGHT, FULL}, CTK_WRAP_PYTHONQT_USE_VTK and CTK_BUILD_SHARED_LIBS
+#ifdef CTK_WRAP_PYTHONQT_USE_VTK
+# include "ctkVTKPythonQtWrapperFactory.h"
+#endif
 
-#include "ctkSimplePythonShellConfigure.h" // For CTK_WRAP_PYTHONQT_{LIGHT, FULL} and CTK_BUILD_SHARED_LIBS
 
 #if defined(CTK_WRAP_PYTHONQT_LIGHT) || defined(CTK_WRAP_PYTHONQT_FULL)
 # ifndef CTK_BUILD_SHARED_LIBS
@@ -97,6 +100,10 @@ void ctkSimplePythonManager::preInitialization()
 # endif
 #endif
 
+#ifdef CTK_WRAP_PYTHONQT_USE_VTK
+  this->addWrapperFactory(new ctkVTKPythonQtWrapperFactory);
+#endif
+
   // Register decorators
   this->registerPythonQtDecorator(new ctkSimplePythonQtDecorators(this));
 

+ 0 - 1
Applications/ctkSimplePythonShell/target_libraries.cmake

@@ -5,6 +5,5 @@
 # 
 
 set(target_libraries
-  VTK_LIBRARIES
   CTKScriptingPythonWidgets
   )

+ 0 - 12
CMake/ctkMacroBuildLibWrapper.cmake

@@ -78,18 +78,6 @@ macro(ctkMacroBuildLibWrapper)
   # these ones to avoid complaints of MSVC
   # Note: "LINK_DIRECTORIES" has to be invoked before "ADD_LIBRARY"
   set(my_EXTRA_PYTHON_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
-  # Should we link against VTK
-  #if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  #  list(APPEND my_EXTRA_PYTHON_LIBRARIES vtkCommon vtkPythonCore)
-  #endif()
-
-  # The current library might not be wrapped. Nevertheless, if one of its dependent library
-  # is linked using vtkCommon or vtkPythonCore, VTK_LIBRARY_DIRS should be added
-  # as a link directories.
-  #if(NOT CTK_BUILD_SHARED_LIBS
-  #   AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  #  link_directories(${VTK_LIBRARY_DIRS})
-  #endif()
 
   # Does a header having the expected filename exists ?
   string(REGEX REPLACE "^CTK" "ctk" lib_name_lc_ctk ${lib_name})

+ 1 - 3
CMakeExternals/PythonQt.cmake

@@ -30,9 +30,7 @@ if(${add_project})
       # Should PythonQt use VTK
       if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
         list(APPEND proj_DEPENDENCIES VTK)
-        list(APPEND ep_PythonQt_args -DVTK_DIR:PATH=${VTK_DIR})
       endif()
-      list(APPEND ep_PythonQt_args -DPythonQt_USE_VTK:BOOL=${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK})
 
       # Enable Qt libraries PythonQt wrapping if required
       foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)
@@ -46,7 +44,7 @@ if(${add_project})
         message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
       endif()
 
-      set(revision_tag 5935f29978deed892a13ddef02cb14c205c6124d)
+      set(revision_tag 9104fa924859f4a865016f2138c06ec856f449d4)
       if(${proj}_REVISION_TAG)
         set(revision_tag ${${proj}_REVISION_TAG})
       endif()

+ 2 - 1
CMakeExternals/VTK.cmake

@@ -37,7 +37,7 @@ if(${add_project} OR CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
 
     if(NOT DEFINED VTK_DIR)
 
-      set(revision_tag f0766a470edcc6b84a779b45ba11feee40ac3bdb)
+      set(revision_tag v5.10.0)
       if(${proj}_REVISION_TAG)
         set(revision_tag ${${proj}_REVISION_TAG})
       endif()
@@ -74,6 +74,7 @@ if(${add_project} OR CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
           -DVTK_USE_GUISUPPORT:BOOL=ON
           -DVTK_USE_QVTK_QTOPENGL:BOOL=ON
           -DVTK_USE_QT:BOOL=ON
+          -DVTK_LEGACY_REMOVE:BOOL=ON
           -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
         DEPENDS
           ${proj_DEPENDENCIES}

+ 8 - 5
CMakeLists.txt

@@ -685,6 +685,14 @@ if((${logical_expr}) AND NOT CTK_LIB_Scripting/Python/Core)
   message("Enabling [CTK_LIB_Scripting/Python/Core] because of [${enabling_msg}] evaluates to True")
 endif()
 
+set(logical_expr CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+if(${logical_expr} AND NOT CTK_LIB_Visualization/VTK/Core)
+  set(CTK_LIB_Visualization/VTK/Core ON CACHE BOOL "Build the VTK Core library" FORCE)
+  set(enabling_msg)
+  ctk_option_logical_expression_to_message(enabling_msg "${logical_expr}")
+  message("Enabling [CTK_LIB_Visualization/VTK/Core] because of [${enabling_msg}] evaluates to True")
+endif()
+
 # Check if dependencies are satisfied
 if(CTK_LIB_Scripting/Python/Core)
   find_package(PythonInterp)
@@ -810,11 +818,6 @@ foreach(_external_target ${EXTERNAL_TARGETS})
   endif()
 endforeach()
 
-# Since PYTHONQT_USE_VTK library option can be enabled independently of
-# Visualization/VTK/Core, let's make sure VTK has been properly discovered
-if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  find_package(VTK REQUIRED)
-endif()
 set(CTK_WRAP_PYTHONQT_USE_VTK ${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK})
 
 #-----------------------------------------------------------------------------

+ 7 - 41
Libs/CommandLineModules/Core/Resources/ctkCmdLineModuleXmlToQtUi.xsl

@@ -28,25 +28,8 @@
     </xsl:choose>
   </xsl:function>
 
-  <!-- Map xml parameter element names (types) to C++ types. -->
-  <xsl:function name="ctk:mapTypeToCpp">
-    <xsl:param name="cliType"/>
-    <xsl:choose>
-      <xsl:when test="$cliType=('integer', 'integer-enumeration')">int</xsl:when>
-      <xsl:when test="$cliType='boolean'">bool</xsl:when>
-      <xsl:when test="$cliType=('string', 'string-enumeration', 'image', 'file', 'directory', 'geometry')">std::string</xsl:when>
-      <xsl:when test="$cliType='integer-vector'">std::vector&lt;int&gt;</xsl:when>
-      <xsl:when test="$cliType=('double-vector', 'point', 'region')">std::vector&lt;double&gt;</xsl:when>
-      <xsl:when test="$cliType='float-vector'">std::vector&lt;float&gt;</xsl:when>
-      <xsl:when test="$cliType='string-vector'">std::vector&lt;std::string&gt;</xsl:when>
-      <xsl:when test="$cliType='float-enumeration'">float</xsl:when>
-      <xsl:when test="$cliType='double-enumeration'">double</xsl:when>
-      <xsl:otherwise><xsl:value-of select="$cliType"/></xsl:otherwise>
-    </xsl:choose>
-  </xsl:function>
-
   <!-- Map xml parameter element names (types) to the Qt widget property containing
-       the current value. The property type should match the Qt C++ type above
+       the current value. The property value type should match the (Qt) C++ type
        (or be convertible to it). -->
   <xsl:function name="ctk:mapTypeToQtValueProperty">
     <xsl:param name="cliType"/>
@@ -75,9 +58,6 @@
   <!-- suppress elements not covered in "signals" mode -->
   <xsl:template match="*" mode="signals"/>
 
-  <!-- This guarantees that elements that don't match the dynamicProperties mode don't get output -->
-  <xsl:template match="*" mode="dynamicProperties"/>
-
   <!--
   ===================================================================
     Templates for generating connections between generated widgets
@@ -154,18 +134,6 @@
     </item>
   </xsl:template>
 
-  <!-- General template for adding dynamic Qt properties to widgets -->
-  <xsl:template match="*" mode="dynamicProperty">
-    <property  name="parameter:{name()}">
-      <string><xsl:value-of select="text()"/></string>
-    </property>
-  </xsl:template>
-
-  <!-- Exclude certain elements from the set of dynamic properties -->
-  <xsl:template match="*[not(name()=('name', 'constraints'))]" mode="dynamicProperties">
-    <xsl:apply-templates select="." mode="dynamicProperty"/>
-  </xsl:template>
-
   <!-- A named template for adding properties common to all Qt widgets -->
   <xsl:template name="commonWidgetProperties">
     <xsl:apply-templates select="description"/> <!-- tooltip -->
@@ -174,17 +142,12 @@
         <bool>false</bool>
       </property>
     </xsl:if>
-    <property  name="parameter:cppType">
-      <string><xsl:value-of select="ctk:mapTypeToCpp(name())"/></string>
-    </property>
-    <property name="parameter:valueProperty">
+    <property name="parameter:valueProperty"> <!-- property name containing current value -->
       <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name())"/></string>
     </property>
 
     <!-- add additional (optional) information as properties -->
     <xsl:apply-templates select="default"/>
-    <xsl:apply-templates select="constraints"/>
-    <xsl:apply-templates select="./child::*" mode="dynamicProperties"/>
   </xsl:template>
   
   <!-- A named template for creating a QtDesigner stringlist property -->
@@ -369,6 +332,9 @@
           <widget class="ctkPathLineEdit"  name="parameter:{name}">
             <xsl:call-template name="commonWidgetProperties"/>
             <xsl:call-template name="createQtDesignerStringListProperty"/>
+            <property name="filters">
+              <set>ctkPathLineEdit::Files</set>
+            </property>
           </widget>
         </item>
         <item>
@@ -395,8 +361,8 @@
         <item>
           <widget class="ctkPathLineEdit"  name="parameter:{name}">
             <xsl:call-template name="commonWidgetProperties"/>
-            <property name="options">
-              <set>ctkPathLineEdit::ShowDirsOnly</set>
+            <property name="filters">
+              <set>ctkPathLineEdit::Dirs</set>
             </property>
           </widget>
         </item>

+ 1 - 1
Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.xml

@@ -51,7 +51,7 @@ Blur a 2d image.
     </directory>
     <geometry fileExtensions="*.jpg, *.txt">
     <name>geomVar</name>
-    <index>3</index>
+    <index>7</index>
     <description>Some geom</description>
     <label>Some geom</label>
     </geometry>

+ 1 - 1
Libs/CommandLineModules/Core/Testing/CLIModules/Tour/ctkCLIModuleTour.xml

@@ -51,7 +51,7 @@
     </directory>
     <geometry fileExtensions="*.jpg, *.txt">
     <name>geomVar</name>
-    <index>3</index>
+    <index>7</index>
     <description>Some geom</description>
     <label>Some geom</label>
     </geometry>

+ 41 - 15
Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.cpp

@@ -32,13 +32,18 @@
 #include <QDebug>
 
 
-ctkCmdLineModuleXslTransform::ctkCmdLineModuleXslTransform(QIODevice *input)
+ctkCmdLineModuleXslTransform::ctkCmdLineModuleXslTransform(QIODevice *input, QIODevice *output)
   : ctkCmdLineModuleXmlValidator(input),
-    OutputSchema(0), Transformation(0)
+    Validate(false), OutputSchema(0), Transformation(0), Output(output)
 {
 }
 
-QString ctkCmdLineModuleXslTransform::output() const
+void ctkCmdLineModuleXslTransform::setOutput(QIODevice* output)
+{
+  Output = output;
+}
+
+QIODevice* ctkCmdLineModuleXslTransform::output() const
 {
   return Output;
 }
@@ -50,6 +55,12 @@ void ctkCmdLineModuleXslTransform::setOutputSchema(QIODevice *output)
 
 bool ctkCmdLineModuleXslTransform::transform()
 {
+  if (!Output)
+  {
+    ErrorStr = "No output device set";
+    return false;
+  }
+
   QIODevice* inputDevice = input();
   if (!inputDevice)
   {
@@ -82,15 +93,34 @@ bool ctkCmdLineModuleXslTransform::transform()
   }
   xslTransform.setQuery(transformation);
 
-  if (!xslTransform.evaluateTo(&Output))
+  bool closeOutput = false;
+  if (!(Output->openMode() & QIODevice::WriteOnly))
+  {
+    Output->open(QIODevice::WriteOnly);
+    closeOutput = true;
+  }
+
+  if (!xslTransform.evaluateTo(Output))
   {
-    Output.clear();
     QString msg("Error transforming XML input, at line %1, column %2: %3");
     ErrorStr = msg.arg(msgHandler.line()).arg(msgHandler.column())
         .arg(msgHandler.statusMessage());
     return false;
   }
 
+  if (closeOutput)
+  {
+    Output->close();
+  }
+  else
+  {
+    Output->reset();
+  }
+
+  if (Validate)
+  {
+    return validateOutput();
+  }
   return true;
 }
 
@@ -99,16 +129,15 @@ void ctkCmdLineModuleXslTransform::setXslTransformation(QIODevice *transformatio
   Transformation = transformation;
 }
 
+void ctkCmdLineModuleXslTransform::setValidateOutput(bool validate)
+{
+  Validate = validate;
+}
+
 bool ctkCmdLineModuleXslTransform::validateOutput()
 {
   ErrorStr.clear();
 
-  if (Output.isEmpty())
-  {
-    // nothing to validate
-    return true;
-  }
-
   QIODevice* outputSchema = OutputSchema;
 
   // If there is no custom schema for validating the output, we just return.
@@ -139,10 +168,7 @@ bool ctkCmdLineModuleXslTransform::validateOutput()
   QXmlSchemaValidator validator(schema);
   validator.setMessageHandler(&msgHandler);
 
-  QByteArray outputData;
-  outputData.append(Output);
-
-  if (!validator.validate(outputData))
+  if (!validator.validate(Output))
   {
     QString msg("Error validating transformed XML input, at line %1, column %2: %3");
     ErrorStr = msg.arg(msgHandler.line()).arg(msgHandler.column())

+ 10 - 5
Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.h

@@ -38,7 +38,10 @@ class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXslTransform
 
 public:
 
-  ctkCmdLineModuleXslTransform(QIODevice* input = 0);
+  ctkCmdLineModuleXslTransform(QIODevice* input = 0, QIODevice* output = 0);
+
+  void setOutput(QIODevice* output);
+  QIODevice* output() const;
 
   void setOutputSchema(QIODevice* output);
 
@@ -52,21 +55,23 @@ public:
    */
   bool transform();
 
-  QString output() const;
-
   void setXslTransformation(QIODevice* transformation);
 
-  bool validateOutput();
+  void setValidateOutput(bool validate);
 
   bool error() const;
   QString errorString() const;
 
 private:
 
+  bool validateOutput();
+
+  bool Validate;
+
   QIODevice* OutputSchema;
   QIODevice* Transformation;
 
-  QString Output;
+  QIODevice* Output;
   QString ErrorStr;
 };
 

+ 3 - 5
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui.cpp

@@ -44,7 +44,9 @@ QObject* ctkCmdLineModuleInstanceQtGui::guiHandle() const
   QBuffer input;
   input.setData(moduleReference().rawXmlDescription());
 
-  ctkCmdLineModuleXslTransform xslTransform(&input);
+  QBuffer uiForm;
+  uiForm.open(QIODevice::ReadWrite);
+  ctkCmdLineModuleXslTransform xslTransform(&input, &uiForm);
   if (!xslTransform.transform())
   {
     // maybe throw an exception
@@ -53,10 +55,6 @@ QObject* ctkCmdLineModuleInstanceQtGui::guiHandle() const
   }
 
   QUiLoader uiLoader;
-  QByteArray uiBlob;
-  uiBlob.append(xslTransform.output());
-
-  QBuffer uiForm(&uiBlob);
   WidgetTree = uiLoader.load(&uiForm);
   return WidgetTree;
 }

+ 0 - 13
Libs/Scripting/Python/Core/CMakeLists.txt

@@ -1,19 +1,11 @@
 project(CTKScriptingPythonCore)
 
 #
-# 3rd party dependencies
-#
-if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  include(${VTK_USE_FILE})
-endif()
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 
 set(KIT_export_directive "CTK_SCRIPTING_PYTHON_CORE_EXPORT")
 
-
 # Source files
 set(KIT_SRCS
   ctkAbstractPythonManager.cpp
@@ -50,11 +42,6 @@ configure_file(
 # The following macro will read the target libraries from the file 'target_libraries.cmake'
 ctkFunctionGetTargetLibraries(KIT_target_libraries)
 
-# Link against vtkPython if required
-if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  list(APPEND KIT_target_libraries vtkPythonCore)
-endif()
-
 ctkMacroBuildLib(
   NAME ${PROJECT_NAME}
   EXPORT_DIRECTIVE ${KIT_export_directive}

+ 0 - 4
Libs/Scripting/Python/Core/Python/CMakeLists.txt

@@ -3,10 +3,6 @@
 set(KIT_PYTHON_SCRIPTS
   qt/__init__
   )
-  
-#if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-#  list(APPEND KIT_PYTHON_SCRIPTS ctkvtk/__init__)
-#endif()
 
 # If it applies, the variable CTK_PYTHON_WRAPPED_LIBRARIES will contain
 # the comma separated list of package to load

+ 6 - 0
Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp

@@ -363,6 +363,12 @@ void ctkAbstractPythonManager::addObjectToPythonMain(const QString& name, QObjec
 }
 
 //-----------------------------------------------------------------------------
+void ctkAbstractPythonManager::addWrapperFactory(PythonQtForeignWrapperFactory* factory)
+{
+  PythonQt::self()->addWrapperFactory(factory);
+}
+
+//-----------------------------------------------------------------------------
 QVariant ctkAbstractPythonManager::getVariable(const QString& name)
 {
   PythonQtObjectPtr main = ctkAbstractPythonManager::mainContext();

+ 2 - 0
Libs/Scripting/Python/Core/ctkAbstractPythonManager.h

@@ -30,6 +30,7 @@
 #include "ctkScriptingPythonCoreExport.h"
 
 class ctkAbstractPythonManagerPrivate;
+class PythonQtForeignWrapperFactory;
 class PythonQtObjectPtr;
 
 /// \ingroup Scripting_Python_Core
@@ -62,6 +63,7 @@ public:
   PythonQtObjectPtr mainContext();
 
   void addObjectToPythonMain(const QString& name, QObject* obj);
+  void addWrapperFactory(PythonQtForeignWrapperFactory* factory);
   void registerPythonQtDecorator(QObject* decorator);
   void registerClassForPythonQt(const QMetaObject* metaobject);
   void registerCPPClassForPythonQt(const char* name);

+ 0 - 7
Libs/Scripting/Python/Widgets/CMakeLists.txt

@@ -1,13 +1,6 @@
 project(CTKScriptingPythonWidgets)
 
 #
-# 3rd party dependencies
-#
-if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
-  include(${VTK_USE_FILE})
-endif()
-
-#
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 

+ 1 - 1
Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

@@ -355,7 +355,7 @@ void ctkPythonConsole::initialize(ctkAbstractPythonManager* newPythonManager)
   this->connect(PythonQt::self(), SIGNAL(pythonStdErr(QString)),
                 d, SLOT(printErrorMessage(QString)));
 
-  PythonQt::self()->setRedirectStdInCallBack(
+  PythonQt::self()->setRedirectStdInCallback(
         ctkConsole::stdInRedirectCallBack, reinterpret_cast<void*>(this));
 
   // Set primary and secondary prompt

+ 31 - 2
Libs/Visualization/VTK/Core/CMakeLists.txt

@@ -5,6 +5,10 @@ project(CTKVisualizationVTKCore)
 #
 include(${VTK_USE_FILE})
 
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  find_package(PythonQt REQUIRED)
+endif()
+
 #
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
@@ -48,11 +52,26 @@ set(KIT_MOC_SRCS
 
 # UI files
 set(KIT_UI_FORMS
-)
+  )
 
 # Resources
 set(KIT_resources
-)
+  )
+
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  list(APPEND KIT_SRCS
+    ctkVTKPythonQtWrapperFactory.cpp
+    )
+endif()
+
+set(KIT_INCLUDE_DIRECTORIES )
+
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  list(APPEND KIT_INCLUDE_DIRECTORIES
+    ${PYTHON_INCLUDE_DIRS}
+    ${PYTHONQT_INCLUDE_DIR}
+    )
+endif()
 
 # Set VTK_LIBRARIES variable
 set(VTK_LIBRARIES
@@ -62,6 +81,15 @@ set(VTK_LIBRARIES
   vtkHybrid
   )
 
+if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  list(APPEND VTK_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
+  if(${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR} VERSION_GREATER 5.6)
+    list(APPEND VTK_LIBRARIES vtkPythonCore)
+  else()
+    list(APPEND VTK_LIBRARIES vtkCommonPythonD)
+  endif()
+endif()
+
 if(Q_WS_X11)
   # If the faster 'gold' linker is used, to avoid complaints about undefined symbol
   # 'XGetWindowAttributes', 'XCreateWindow', ..., let's link against X11 libraries.
@@ -79,6 +107,7 @@ ctkMacroBuildLib(
   SRCS ${KIT_SRCS}
   MOC_SRCS ${KIT_MOC_SRCS}
   UI_FORMS ${KIT_UI_FORMS}
+  INCLUDE_DIRECTORIES ${KIT_INCLUDE_DIRECTORIES}
   TARGET_LIBRARIES ${KIT_target_libraries}
   RESOURCES ${KIT_resources}
   LIBRARY_TYPE ${CTK_LIBRARY_MODE}

+ 45 - 0
Libs/Visualization/VTK/Core/ctkVTKPythonQtWrapperFactory.cpp

@@ -0,0 +1,45 @@
+
+/// CTK includes
+#include "ctkVTKPythonQtWrapperFactory.h"
+
+/// VTK includes
+#include <vtkPythonUtil.h>
+#include <vtkObject.h>
+
+//-----------------------------------------------------------------------------
+ctkVTKPythonQtWrapperFactory::ctkVTKPythonQtWrapperFactory():Superclass()
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKPythonQtWrapperFactory::~ctkVTKPythonQtWrapperFactory()
+{
+}
+
+//-----------------------------------------------------------------------------
+PyObject* ctkVTKPythonQtWrapperFactory::wrap(const QByteArray& classname, void *ptr)
+{
+  if (classname.startsWith("vtk"))
+    {
+#if (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION <= 6) || VTK_MAJOR_VERSION < 5
+    return vtkPythonGetObjectFromPointer(reinterpret_cast<vtkObjectBase*>(ptr));
+#else
+    return vtkPythonUtil::GetObjectFromPointer(reinterpret_cast<vtkObjectBase*>(ptr));
+#endif
+    }
+  return NULL;
+}
+
+//-----------------------------------------------------------------------------
+void* ctkVTKPythonQtWrapperFactory::unwrap(const QByteArray& classname, PyObject* object)
+{
+  if (classname.startsWith("vtk"))
+    {
+#if (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION <= 6) || VTK_MAJOR_VERSION < 5
+    return vtkPythonGetPointerFromObject(object, classname.data());
+#else
+    return vtkPythonUtil::GetPointerFromObject(object, classname.data());
+#endif
+    }
+  return NULL;
+}

+ 43 - 0
Libs/Visualization/VTK/Core/ctkVTKPythonQtWrapperFactory.h

@@ -0,0 +1,43 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkVTKPythonQtWrapperFactory_h
+#define __ctkVTKPythonQtWrapperFactory_h
+
+// PythonQt includes
+#include <PythonQtCppWrapperFactory.h>
+
+// CTK includes
+#include "ctkVisualizationVTKCoreExport.h"
+
+/// \ingroup Visualization_VTK_Core
+/// VTK PythonQt wrapper factory
+class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKPythonQtWrapperFactory : public PythonQtForeignWrapperFactory
+{
+public:
+  typedef PythonQtForeignWrapperFactory Superclass;
+  ctkVTKPythonQtWrapperFactory();
+  virtual ~ctkVTKPythonQtWrapperFactory();
+  virtual PyObject* wrap(const QByteArray& classname, void *ptr);
+  virtual void* unwrap(const QByteArray& classname, PyObject* object);
+};
+
+#endif
+