Bläddra i källkod

CLI API prototype with a new separate QtGui dependent library.

Sascha Zelzer 13 år sedan
förälder
incheckning
e7e7ed23d9
67 ändrade filer med 1149 tillägg och 623 borttagningar
  1. 21 81
      Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.cpp
  2. 6 5
      Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.h
  3. 4 32
      Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp
  4. 1 1
      Applications/ctkCommandLineModuleExplorer/target_libraries.cmake
  5. 5 2
      CMakeLists.txt
  6. 9 4
      Libs/CommandLineModules/CMakeLists.txt
  7. 0 0
      Libs/CommandLineModules/Core/Resources/QtDesigner.xsd
  8. 0 0
      Libs/CommandLineModules/Core/Resources/ctkCmdLineModule.xsd
  9. 0 0
      Libs/CommandLineModules/Core/Resources/ctkCmdLineModuleXmlToQtUi.xsl
  10. 0 0
      Libs/CommandLineModules/Core/Resources/ctkCmdLineModules.qrc
  11. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/CMakeLists.txt
  12. 2 0
      Libs/CommandLineModules/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.cpp
  13. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.qrc
  14. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.xml
  15. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/CMakeLists.txt
  16. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/Tour/CMakeLists.txt
  17. 2 0
      Libs/CommandLineModules/Testing/CLIModules/Tour/ctkCLIModuleTour.cpp
  18. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/Tour/ctkCLIModuleTour.qrc
  19. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/Tour/ctkCLIModuleTour.xml
  20. 0 0
      Libs/CommandLineModules/Core/Testing/CLIModules/ctkCLIModuleBlur2dImage.xml
  21. 0 0
      Libs/CommandLineModules/Core/Testing/CMakeLists.txt
  22. 0 0
      Libs/CommandLineModules/Core/Testing/Cpp/CMakeLists.txt
  23. 0 0
      Libs/CommandLineModules/Core/Testing/Cpp/ctkModuleDescriptionTest.cpp
  24. 13 0
      Libs/CommandLineModules/ctkCmdLineModuleDescription.cpp
  25. 7 3
      Libs/CommandLineModules/ctkCmdLineModuleDescription.h
  26. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleDescriptionPrivate.h
  27. 88 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.cpp
  28. 18 18
      Libs/CommandLineModules/ctkCmdLineModuleReferencePrivate.cpp
  29. 26 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleInstanceFactory.cpp
  30. 37 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleInstanceFactory.h
  31. 55 65
      Libs/CommandLineModules/ctkCmdLineModuleManager.cpp
  32. 81 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h
  33. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleObjectHierarchyReader.cpp
  34. 2 2
      Libs/CommandLineModules/ctkCmdLineModuleObjectHierarchyReader.h
  35. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameter.cpp
  36. 3 3
      Libs/CommandLineModules/ctkCmdLineModuleParameter.h
  37. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameterGroup.cpp
  38. 3 3
      Libs/CommandLineModules/ctkCmdLineModuleParameterGroup.h
  39. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameterGroupPrivate.h
  40. 0 1
      Libs/CommandLineModules/ctkCmdLineModuleParameterParsers_p.h
  41. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameterPrivate.cpp
  42. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleParameterPrivate.h
  43. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.cpp
  44. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.h
  45. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessFuture.cpp
  46. 2 2
      Libs/CommandLineModules/ctkCmdLineModuleProcessFuture.h
  47. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner.cpp
  48. 0 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner_p.h
  49. 7 19
      Libs/CommandLineModules/ctkCmdLineModuleReference.cpp
  50. 7 11
      Libs/CommandLineModules/ctkCmdLineModuleReference.h
  51. 8 27
      Libs/CommandLineModules/ctkCmdLineModuleReferencePrivate.h
  52. 76 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXmlMsgHandler.cpp
  53. 49 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXmlMsgHandler_p.h
  54. 2 1
      Libs/CommandLineModules/ctkCmdLineModuleXmlParser.cpp
  55. 104 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXmlValidator.cpp
  56. 9 17
      Libs/CommandLineModules/ctkCmdLineModuleXmlValidator.h
  57. 169 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.cpp
  58. 70 0
      Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.h
  59. 0 0
      Libs/CommandLineModules/Core/target_libraries.cmake
  60. 68 0
      Libs/CommandLineModules/QtGui/CMakeLists.txt
  61. 29 0
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceFactoryQtGui.cpp
  62. 38 0
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceFactoryQtGui.h
  63. 69 0
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui.cpp
  64. 50 0
      Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui_p.h
  65. 9 0
      Libs/CommandLineModules/QtGui/target_libraries.cmake
  66. 0 67
      Libs/CommandLineModules/ctkCmdLineModuleManager.h
  67. 0 259
      Libs/CommandLineModules/ctkCmdLineModuleXmlValidator.cpp

+ 21 - 81
Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.cpp

@@ -24,66 +24,15 @@
 
 #include <ctkCmdLineModuleXmlValidator.h>
 #include <ctkCmdLineModuleManager.h>
+#include <ctkCmdLineModuleInstance.h>
+#include <ctkCmdLineModuleInstanceFactoryQtGui.h>
 #include <ctkCmdLineModuleProcessFuture.h>
 
-#include <QFile>
-#include <QBuffer>
-#include <QUiLoader>
-#include <QDebug>
-
-class ctkCmdLineModuleDescriptionDefaultFactory : public ctkCmdLineModuleDescriptionFactory
-{
-public:
-
-  QObject* createObjectRepresentationFromXML(const QByteArray &xmlDescription)
-  {
-    return cachedObjectTree(xmlDescription);
-  }
-
-  QObject* createGUIFromXML(const QByteArray &xmlDescription)
-  {
-    return cachedObjectTree(xmlDescription);
-  }
-
-private:
-
-  QObject* cachedObjectTree(const QByteArray& xmlDescription)
-  {
-    QObject* root = cache[xmlDescription];
-    if (root != 0) return root;
-
-    QBuffer input;
-    input.setData(xmlDescription);
-    input.open(QIODevice::ReadOnly);
-
-    ctkCmdLineModuleXmlValidator validator(&input);
-    if (!validator.validateXSLTOutput())
-    {
-      qCritical() << validator.errorString();
-      return 0;
-    }
-
-    QUiLoader uiLoader;
-    QByteArray uiBlob;
-    uiBlob.append(validator.output());
-    qDebug() << validator.output();
-    QBuffer uiForm(&uiBlob);
-
-    root = uiLoader.load(&uiForm);
-    cache[xmlDescription] = root;
-    return root;
-  }
-
-  // TODO: remove entry if QObject was deleted
-  QHash<QByteArray, QObject*> cache;
-};
-
 
 ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
   QMainWindow(parent),
   ui(new Ui::ctkCLModuleExplorerMainWindow),
-  factory(new ctkCmdLineModuleDescriptionDefaultFactory),
-  moduleManager(factory)
+  moduleManager(new ctkCmdLineModuleInstanceFactoryQtGui())
 {
   ui->setupUi(this);
 }
@@ -91,55 +40,46 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
 ctkCLModuleExplorerMainWindow::~ctkCLModuleExplorerMainWindow()
 {
   delete ui;
-  delete factory;
 }
 
 void ctkCLModuleExplorerMainWindow::addModuleTab(const ctkCmdLineModuleReference& moduleRef)
 {
-  if (moduleRef.widgetTree() == 0) return;
+  ctkCmdLineModuleInstance* moduleInstance = moduleManager.createModuleInstance(moduleRef);
+  if (!moduleInstance) return;
+
+  QObject* guiHandle = moduleInstance->guiHandle();
 
-  QWidget* widget = qobject_cast<QWidget*>(moduleRef.widgetTree());
+  QWidget* widget = qobject_cast<QWidget*>(guiHandle);
   int tabIndex = ui->mainTabWidget->addTab(widget, widget->objectName());
   mapTabToModuleRef[tabIndex] = moduleRef;
 }
 
 void ctkCLModuleExplorerMainWindow::addModule(const QString &location)
 {
-  ctkCmdLineModuleReference ref = moduleManager.addModule(location);
-  if (ref.isValid())
+  ctkCmdLineModuleReference ref = moduleManager.registerModule(location);
+  if (ref)
   {
     addModuleTab(ref);
   }
 }
 
-void ctkCLModuleExplorerMainWindow::testModuleXML(const QByteArray &xml)
-{
-  QObject* root = factory->createGUIFromXML(xml);
-  if (root)
-  {
-    QWidget* widget = qobject_cast<QWidget*>(root);
-    int tabIndex = ui->mainTabWidget->addTab(widget, widget->objectName());
-    //mapTabToModuleRef[tabIndex] = moduleRef;
-  }
-}
-
 void ctkCLModuleExplorerMainWindow::on_actionRun_triggered()
 {
   qDebug() << "Creating module command line...";
 
-  QStringList cmdLineArgs = ctkCmdLineModuleManager::createCommandLineArgs(ui->mainTabWidget->currentWidget());
-  qDebug() << cmdLineArgs;
+//  QStringList cmdLineArgs = ctkCmdLineModuleManager::createCommandLineArgs(ui->mainTabWidget->currentWidget());
+//  qDebug() << cmdLineArgs;
 
-  ctkCmdLineModuleReference moduleRef = mapTabToModuleRef[ui->mainTabWidget->currentIndex()];
-  if (!moduleRef.isValid())
-  {
-    qWarning() << "Invalid module reference";
-    return;
-  }
+//  ctkCmdLineModuleReference moduleRef = mapTabToModuleRef[ui->mainTabWidget->currentIndex()];
+//  if (!moduleRef.isValid())
+//  {
+//    qWarning() << "Invalid module reference";
+//    return;
+//  }
 
-  connect(&futureWatcher, SIGNAL(finished()), this, SLOT(futureFinished()));
-  ctkCmdLineModuleProcessFuture future = moduleManager.run(moduleRef);
-  futureWatcher.setFuture(future);
+//  connect(&futureWatcher, SIGNAL(finished()), this, SLOT(futureFinished()));
+//  ctkCmdLineModuleProcessFuture future = moduleManager.run(moduleRef);
+//  futureWatcher.setFuture(future);
 }
 
 void ctkCLModuleExplorerMainWindow::futureFinished()

+ 6 - 5
Applications/ctkCommandLineModuleExplorer/ctkCLModuleExplorerMainWindow.h

@@ -22,11 +22,14 @@
 #ifndef CTKCLIPLUGINEXPLORERMAINWINDOW_H
 #define CTKCLIPLUGINEXPLORERMAINWINDOW_H
 
-#include <QMainWindow>
-
 #include <ctkCmdLineModuleManager.h>
+#include <ctkCmdLineModuleReference.h>
+#include <ctkCmdLineModuleProcessFuture.h>
+
+#include <QMainWindow>
+#include <QHash>
 
-class ctkCmdLineModuleDescriptionDefaultFactory;
+class ctkCmdLineModuleReference;
 
 namespace Ui {
 class ctkCLModuleExplorerMainWindow;
@@ -41,7 +44,6 @@ public:
   ~ctkCLModuleExplorerMainWindow();
 
   void addModule(const QString& location);
-  void testModuleXML(const QByteArray& xml);
 
 protected Q_SLOTS:
 
@@ -58,7 +60,6 @@ protected:
 private:
   Ui::ctkCLModuleExplorerMainWindow *ui;
 
-  ctkCmdLineModuleDescriptionDefaultFactory* factory;
   ctkCmdLineModuleManager moduleManager;
 
   QHash<int, ctkCmdLineModuleReference> mapTabToModuleRef;

+ 4 - 32
Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp

@@ -44,7 +44,7 @@ int main(int argc, char** argv)
   cmdLineParser.setStrictModeEnabled(true);
 
   cmdLineParser.addArgument("module", "", QVariant::String, "Path to a CLI module (executable)");
-  cmdLineParser.addArgument("module-xml", "", QVariant::String, "Path to a CLI XML description.");
+  //cmdLineParser.addArgument("module-xml", "", QVariant::String, "Path to a CLI XML description.");
 
   cmdLineParser.addArgument("validate-module", "", QVariant::String, "Path to a CLI module");
   cmdLineParser.addArgument("validate-xml", "", QVariant::String, "Path to a CLI XML description.");
@@ -107,20 +107,12 @@ int main(int argc, char** argv)
     xmlInput.open(QIODevice::ReadOnly);
 
     ctkCmdLineModuleXmlValidator validator(&xmlInput);
-    if (!validator.validate())
+    if (!validator.validateInput())
     {
       qCritical() << validator.errorString();
       return EXIT_FAILURE;
     }
 
-    if (args.contains("verbose"))
-    {
-      qDebug() << "=================================================";
-      qDebug() << "****          Transformed input              ****";
-      qDebug() << "=================================================";
-      qDebug() << validator.output();
-    }
-
     return EXIT_SUCCESS;
   }
   else if (args.contains("validate-xml"))
@@ -134,19 +126,12 @@ int main(int argc, char** argv)
     input.open(QIODevice::ReadOnly);
 
     ctkCmdLineModuleXmlValidator validator(&input);
-    if (!validator.validate())
+    if (!validator.validateInput())
     {
       qCritical() << validator.errorString();
       return EXIT_FAILURE;
     }
 
-    if (args.contains("verbose"))
-    {
-      qDebug() << "=================================================";
-      qDebug() << "****          Transformed input              ****";
-      qDebug() << "=================================================";
-      qDebug() << validator.output();
-    }
     return EXIT_SUCCESS;
   }
 
@@ -155,20 +140,7 @@ int main(int argc, char** argv)
 
   ctkCLModuleExplorerMainWindow mainWindow;
 
-  if (args.contains("module-xml"))
-  {
-    QFile input(args["module-xml"].toString());
-    if (!input.exists())
-    {
-      qCritical() << "XML description does not exist:" << input.fileName();
-      return EXIT_FAILURE;
-    }
-    input.open(QIODevice::ReadOnly);
-    QByteArray xml = input.readAll();
-
-    mainWindow.testModuleXML(xml);
-  }
-  else if (args.contains("module"))
+  if (args.contains("module"))
   {
     mainWindow.addModule(args["module"].toString());
   }

+ 1 - 1
Applications/ctkCommandLineModuleExplorer/target_libraries.cmake

@@ -5,5 +5,5 @@
 # 
 
 set(target_libraries
-  CTKCommandLineModules
+  CTKCommandLineModulesQtGui
   )

+ 5 - 2
CMakeLists.txt

@@ -449,8 +449,11 @@ ctk_lib_option(Visualization/VTK/Core
 ctk_lib_option(Visualization/VTK/Widgets
                "Build the VTK Widgets library" OFF)
                
-ctk_lib_option(CommandLineModules
-               "Build the Command Line Module support library" OFF)
+ctk_lib_option(CommandLineModules/Core
+               "Build the Command Line Module core library" OFF)
+
+ctk_lib_option(CommandLineModules/QtGui
+               "Build the QtGui based Command Line Module library" OFF)
 
 #ctk_lib_option(Visualization/XIP
 #               "Build the XIP library" OFF)

+ 9 - 4
Libs/CommandLineModules/CMakeLists.txt

@@ -1,4 +1,4 @@
-project(CTKCommandLineModules)
+project(CTKCommandLineModulesCore)
 
 #
 # 3rd party dependencies
@@ -8,7 +8,7 @@ project(CTKCommandLineModules)
 # See CTK/CMake/ctkMacroBuildLib.cmake for details
 #
 
-set(KIT_export_directive "CTK_CMDLINEMODULE_EXPORT")
+set(KIT_export_directive "CTK_CMDLINEMODULECORE_EXPORT")
 
 # Additional directories to include
 
@@ -16,6 +16,8 @@ set(KIT_export_directive "CTK_CMDLINEMODULE_EXPORT")
 set(KIT_SRCS
   ctkCmdLineModuleDescription.cpp
   ctkCmdLineModuleDescriptionPrivate.h
+  ctkCmdLineModuleInstance.cpp
+  ctkCmdLineModuleInstanceFactory.cpp
   ctkCmdLineModuleManager.cpp
   ctkCmdLineModuleObjectHierarchyReader.cpp
   ctkCmdLineModuleParameter.cpp
@@ -28,15 +30,18 @@ set(KIT_SRCS
   ctkCmdLineModuleProcessRunner.cpp
   ctkCmdLineModuleProcessRunner_p.h
   ctkCmdLineModuleReference.cpp
-  ctkCmdLineModuleReferencePrivate.cpp
+  ctkCmdLineModuleReferencePrivate.h
+  ctkCmdLineModuleXmlMsgHandler_p.h
+  ctkCmdLineModuleXmlMsgHandler.cpp
   ctkCmdLineModuleXmlParser.cpp
   ctkCmdLineModuleXmlValidator.cpp
+  ctkCmdLineModuleXslTransform.cpp
 )
 
 # Headers that should run through moc
 set(KIT_MOC_SRCS
+  ctkCmdLineModuleInstance.h
   ctkCmdLineModuleProcessRunner_p.h
-  ctkCmdLineModuleReferencePrivate.h
 )
 
 # UI files

Libs/CommandLineModules/Resources/QtDesigner.xsd → Libs/CommandLineModules/Core/Resources/QtDesigner.xsd


Libs/CommandLineModules/Resources/ctkCmdLineModule.xsd → Libs/CommandLineModules/Core/Resources/ctkCmdLineModule.xsd


Libs/CommandLineModules/Resources/ctkCmdLineModuleXmlToQtUi.xsl → Libs/CommandLineModules/Core/Resources/ctkCmdLineModuleXmlToQtUi.xsl


Libs/CommandLineModules/Resources/ctkCmdLineModules.qrc → Libs/CommandLineModules/Core/Resources/ctkCmdLineModules.qrc


Libs/CommandLineModules/Testing/CLIModules/Blur2dImage/CMakeLists.txt → Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/CMakeLists.txt


+ 2 - 0
Libs/CommandLineModules/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.cpp

@@ -25,6 +25,8 @@
 #include <QTextStream>
 #include <QFile>
 
+#include <cstdlib>
+
 int main(int argc, char* argv[])
 {
   QCoreApplication app(argc, argv);

Libs/CommandLineModules/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.qrc → Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.qrc


Libs/CommandLineModules/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.xml → Libs/CommandLineModules/Core/Testing/CLIModules/Blur2dImage/ctkCLIModuleBlur2dImage.xml


Libs/CommandLineModules/Testing/CLIModules/CMakeLists.txt → Libs/CommandLineModules/Core/Testing/CLIModules/CMakeLists.txt


Libs/CommandLineModules/Testing/CLIModules/Tour/CMakeLists.txt → Libs/CommandLineModules/Core/Testing/CLIModules/Tour/CMakeLists.txt


+ 2 - 0
Libs/CommandLineModules/Testing/CLIModules/Tour/ctkCLIModuleTour.cpp

@@ -25,6 +25,8 @@
 #include <QTextStream>
 #include <QFile>
 
+#include <cstdlib>
+
 int main(int argc, char* argv[])
 {
   QCoreApplication app(argc, argv);

Libs/CommandLineModules/Testing/CLIModules/Tour/ctkCLIModuleTour.qrc → Libs/CommandLineModules/Core/Testing/CLIModules/Tour/ctkCLIModuleTour.qrc


Libs/CommandLineModules/Testing/CLIModules/Tour/ctkCLIModuleTour.xml → Libs/CommandLineModules/Core/Testing/CLIModules/Tour/ctkCLIModuleTour.xml


Libs/CommandLineModules/Testing/CLIModules/ctkCLIModuleBlur2dImage.xml → Libs/CommandLineModules/Core/Testing/CLIModules/ctkCLIModuleBlur2dImage.xml


Libs/CommandLineModules/Testing/CMakeLists.txt → Libs/CommandLineModules/Core/Testing/CMakeLists.txt


Libs/CommandLineModules/Testing/Cpp/CMakeLists.txt → Libs/CommandLineModules/Core/Testing/Cpp/CMakeLists.txt


Libs/CommandLineModules/Testing/Cpp/ctkModuleDescriptionTest.cpp → Libs/CommandLineModules/Core/Testing/Cpp/ctkModuleDescriptionTest.cpp


+ 13 - 0
Libs/CommandLineModules/ctkCmdLineModuleDescription.cpp

@@ -36,11 +36,24 @@ ctkCmdLineModuleDescription::ctkCmdLineModuleDescription()
 }
 
 //----------------------------------------------------------------------------
+ctkCmdLineModuleDescription::ctkCmdLineModuleDescription(const ctkCmdLineModuleDescription &description)
+  : d(description.d)
+{
+}
+
+//----------------------------------------------------------------------------
 ctkCmdLineModuleDescription::~ctkCmdLineModuleDescription()
 {
 }
 
 //----------------------------------------------------------------------------
+ctkCmdLineModuleDescription &ctkCmdLineModuleDescription::operator =(const ctkCmdLineModuleDescription &other)
+{
+  d = other.d;
+  return *this;
+}
+
+//----------------------------------------------------------------------------
 QString ctkCmdLineModuleDescription::category() const
 {
   return d->Category;

+ 7 - 3
Libs/CommandLineModules/ctkCmdLineModuleDescription.h

@@ -21,7 +21,7 @@
 #ifndef __ctkCmdLineModuleDescription_h
 #define __ctkCmdLineModuleDescription_h
 
-#include <ctkCommandLineModulesExport.h>
+#include <ctkCommandLineModulesCoreExport.h>
 
 #include <QList>
 #include <QSharedDataPointer>
@@ -40,13 +40,16 @@ class ctkCmdLineModuleParameter;
  * The parameters can be used for automated GUI generation or execution
  * of the module.
  */
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleDescription
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleDescription
 {
 
 public:
 
+  ctkCmdLineModuleDescription(const ctkCmdLineModuleDescription& description);
   ~ctkCmdLineModuleDescription();
 
+  ctkCmdLineModuleDescription& operator=(const ctkCmdLineModuleDescription& other);
+
   static ctkCmdLineModuleDescription parse(QIODevice* input);
 
   QString category() const;
@@ -79,6 +82,7 @@ public:
 private:
 
   friend class ctkCmdLineModuleXmlParser;
+  friend class ctkCmdLineModuleReferencePrivate;
 
   ctkCmdLineModuleDescription();
 
@@ -86,6 +90,6 @@ private:
 
 };
 
-CTK_CMDLINEMODULE_EXPORT QTextStream & operator<<(QTextStream& os, const ctkCmdLineModuleDescription& module);
+CTK_CMDLINEMODULECORE_EXPORT QTextStream & operator<<(QTextStream& os, const ctkCmdLineModuleDescription& module);
 
 #endif

Libs/CommandLineModules/ctkCmdLineModuleDescriptionPrivate.h → Libs/CommandLineModules/Core/ctkCmdLineModuleDescriptionPrivate.h


+ 88 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.cpp

@@ -0,0 +1,88 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleInstance.h"
+#include "ctkCmdLineModuleObjectHierarchyReader.h"
+
+#include <QStringList>
+
+namespace {
+
+QString normalizeFlag(const QString& flag)
+{
+  return flag.trimmed().remove(QRegExp("^-*"));
+}
+
+}
+
+struct ctkCmdLineModuleInstancePrivate
+{
+  QStringList createCommandLineArgs(QObject *hierarchy)
+  {
+    ctkCmdLineModuleObjectHierarchyReader reader(hierarchy);
+
+    QStringList cmdLineArgs;
+    QHash<int, QString> indexedArgs;
+    while(reader.readNextParameter())
+    {
+      if (reader.index() > -1)
+      {
+        indexedArgs.insert(reader.index(), reader.value());
+      }
+      else
+      {
+        QString argFlag;
+        if (reader.longFlag().isEmpty())
+        {
+          argFlag = QString("-") + normalizeFlag(reader.flag());
+        }
+        else
+        {
+          argFlag = QString("--") + normalizeFlag(reader.longFlag());
+        }
+
+        QStringList args;
+        if (reader.isMultiple())
+        {
+          args = reader.value().split(',', QString::SkipEmptyParts);
+        }
+        else
+        {
+          args.push_back(reader.value());
+        }
+
+        foreach(QString arg, args)
+        {
+          cmdLineArgs << argFlag << arg;
+        }
+      }
+    }
+
+    QList<int> indexes = indexedArgs.keys();
+    qSort(indexes.begin(), indexes.end());
+    foreach(int index, indexes)
+    {
+      cmdLineArgs << indexedArgs[index];
+    }
+
+    return cmdLineArgs;
+  }
+};

+ 18 - 18
Libs/CommandLineModules/ctkCmdLineModuleReferencePrivate.cpp

@@ -19,26 +19,26 @@
   
 =============================================================================*/
 
-#include "ctkCmdLineModuleReferencePrivate.h"
+#ifndef CTKCMDLINEMODULEINSTANCE_H
+#define CTKCMDLINEMODULEINSTANCE_H
 
-ctkCmdLineModuleReferencePrivate::ctkCmdLineModuleReferencePrivate()
-  : objectRepresentation(0), ref(1), gui(0)
-{}
+#include <ctkCommandLineModulesCoreExport.h>
 
-ctkCmdLineModuleReferencePrivate::~ctkCmdLineModuleReferencePrivate()
-{
-  objectRepresentation->deleteLater();
-  if (gui) gui->deleteLater();
-}
+#include <QObject>
 
-void ctkCmdLineModuleReferencePrivate::setGUI(QObject* gui)
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleInstance : public QObject
 {
-  if (this->gui) disconnect(gui);
-  this->gui = gui;
-  connect(this->gui, SIGNAL(destroyed()), this, SLOT(guiDestroyed()));
-}
+  Q_OBJECT
 
-void ctkCmdLineModuleReferencePrivate::guiDestroyed()
-{
-  gui = 0;
-}
+public:
+
+  virtual QObject* guiHandle() const = 0;
+
+  virtual QVariant value(const QString& parameter) const = 0;
+  virtual void setValue(const QString& parameter, const QVariant& value) = 0;
+
+  Q_SIGNAL void valueChanged(const QString& parameter, const QVariant& value);
+
+};
+
+#endif // CTKCMDLINEMODULEINSTANCE_H

+ 26 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleInstanceFactory.cpp

@@ -0,0 +1,26 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleInstanceFactory.h"
+
+ctkCmdLineModuleInstanceFactory::~ctkCmdLineModuleInstanceFactory()
+{
+}

+ 37 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleInstanceFactory.h

@@ -0,0 +1,37 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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 CTKCMDLINEMODULEINSTANCEFACTORY_H
+#define CTKCMDLINEMODULEINSTANCEFACTORY_H
+
+#include "ctkCommandLineModulesCoreExport.h"
+
+class ctkCmdLineModuleInstance;
+class ctkCmdLineModuleReference;
+
+struct CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleInstanceFactory
+{
+  virtual ~ctkCmdLineModuleInstanceFactory();
+
+  virtual ctkCmdLineModuleInstance* create(const ctkCmdLineModuleReference& moduleInstance) = 0;
+};
+
+#endif // CTKCMDLINEMODULEINSTANCEFACTORY_H

+ 55 - 65
Libs/CommandLineModules/ctkCmdLineModuleManager.cpp

@@ -24,7 +24,11 @@
 #include "ctkCmdLineModuleXmlValidator.h"
 #include "ctkCmdLineModuleObjectHierarchyReader.h"
 #include "ctkCmdLineModuleProcessRunner_p.h"
+#include "ctkCmdLineModuleReference.h"
 #include "ctkCmdLineModuleReferencePrivate.h"
+#include "ctkCmdLineModuleInstanceFactory.h"
+
+#include <ctkException.h>
 
 #include <QStringList>
 #include <QBuffer>
@@ -32,75 +36,34 @@
 #include <QProcess>
 #include <QFuture>
 
-QString normalizeFlag(const QString& flag)
+struct ctkCmdLineModuleManagerPrivate
 {
-  return flag.trimmed().remove(QRegExp("^-*"));
-}
+  ctkCmdLineModuleInstanceFactory* InstanceFactory;
 
-ctkCmdLineModuleManager::ctkCmdLineModuleManager(ctkCmdLineModuleDescriptionFactory *descriptionFactory)
-  : descriptionFactory(descriptionFactory)
+  QHash<QString, ctkCmdLineModuleReference> Cache;
+};
+
+ctkCmdLineModuleManager::ctkCmdLineModuleManager(ctkCmdLineModuleInstanceFactory *instanceFactory,
+                                                 ValidationMode validationMode)
+  : d(new ctkCmdLineModuleManagerPrivate)
 {
+  d->InstanceFactory = instanceFactory;
 }
 
-QStringList ctkCmdLineModuleManager::createCommandLineArgs(QObject *hierarchy)
+ctkCmdLineModuleManager::~ctkCmdLineModuleManager()
 {
-  ctkCmdLineModuleObjectHierarchyReader reader(hierarchy);
-
-  QStringList cmdLineArgs;
-  QHash<int, QString> indexedArgs;
-  while(reader.readNextParameter())
-  {
-    if (reader.index() > -1)
-    {
-      indexedArgs.insert(reader.index(), reader.value());
-    }
-    else
-    {
-      QString argFlag;
-      if (reader.longFlag().isEmpty())
-      {
-        argFlag = QString("-") + normalizeFlag(reader.flag());
-      }
-      else
-      {
-        argFlag = QString("--") + normalizeFlag(reader.longFlag());
-      }
-
-      QStringList args;
-      if (reader.isMultiple())
-      {
-        args = reader.value().split(',', QString::SkipEmptyParts);
-      }
-      else
-      {
-        args.push_back(reader.value());
-      }
-
-      foreach(QString arg, args)
-      {
-        cmdLineArgs << argFlag << arg;
-      }
-    }
-  }
-
-  QList<int> indexes = indexedArgs.keys();
-  qSort(indexes.begin(), indexes.end());
-  foreach(int index, indexes)
-  {
-    cmdLineArgs << indexedArgs[index];
-  }
-
-  return cmdLineArgs;
+  delete d->InstanceFactory;
 }
 
-ctkCmdLineModuleReference ctkCmdLineModuleManager::addModule(const QString& location)
+ctkCmdLineModuleReference
+ctkCmdLineModuleManager::registerModule(const QString& location)
 {
   QProcess process;
   process.setReadChannel(QProcess::StandardOutput);
   process.start(location, QStringList("--xml"));
 
   ctkCmdLineModuleReference ref;
-  ref.d->loc = location;
+  ref.d->Location = location;
   if (!process.waitForFinished() || process.exitStatus() == QProcess::CrashExit ||
       process.error() != QProcess::UnknownError)
   {
@@ -118,24 +81,51 @@ ctkCmdLineModuleReference ctkCmdLineModuleManager::addModule(const QString& loca
   input.open(QIODevice::ReadOnly);
 
   ctkCmdLineModuleXmlValidator validator(&input);
-  if (!validator.validateXMLInput())
+  if (!validator.validateInput())
   {
     qCritical() << validator.errorString();
     return ref;
   }
 
-  ref.d->xml = xml;
-  ref.d->objectRepresentation = descriptionFactory->createObjectRepresentationFromXML(ref.d->xml);
-  ref.d->setGUI(descriptionFactory->createGUIFromXML(ref.d->xml));
+  ref.d->RawXmlDescription = xml;
+//  ref.d->objectRepresentation = descriptionFactory->createObjectRepresentationFromXML(ref.d->xml);
+//  ref.d->setGUI(descriptionFactory->createGUIFromXML(ref.d->xml));
 
-  cache[location] = ref;
+  d->Cache[location] = ref;
   return ref;
 }
 
-ctkCmdLineModuleProcessFuture ctkCmdLineModuleManager::run(const ctkCmdLineModuleReference& moduleRef)
+void ctkCmdLineModuleManager::unregisterModule(const ctkCmdLineModuleReference&)
 {
-  // TODO: manage memory
-  QStringList args = createCommandLineArgs(moduleRef.d->objectRepresentation);
-  ctkCmdLineModuleProcessRunner* moduleProcess = new ctkCmdLineModuleProcessRunner(moduleRef.location(), args);
-  return moduleProcess->start();
+  throw ctkException("not implemented yet");
 }
+
+ctkCmdLineModuleReference ctkCmdLineModuleManager::moduleReference(const QString& location) const
+{
+  throw ctkException("not implemented yet");
+}
+
+QList<ctkCmdLineModuleReference> ctkCmdLineModuleManager::moduleReferences() const
+{
+  throw ctkException("not implemented yet");
+}
+
+ctkCmdLineModuleInstance*
+ctkCmdLineModuleManager::createModuleInstance(const ctkCmdLineModuleReference& moduleRef)
+{
+  return d->InstanceFactory->create(moduleRef);
+}
+
+QList<ctkCmdLineModuleInstance*>
+ctkCmdLineModuleManager::moduleInstances(const ctkCmdLineModuleReference& moduleRef) const
+{
+  throw ctkException("not implemented yet");
+}
+
+//ctkCmdLineModuleProcessFuture ctkCmdLineModuleManager::run(const ctkCmdLineModuleReference& moduleRef)
+//{
+  // TODO: manage memory
+  //QStringList args = createCommandLineArgs(moduleRef.d->objectRepresentation);
+  //ctkCmdLineModuleProcessRunner* moduleProcess = new ctkCmdLineModuleProcessRunner(moduleRef.location(), args);
+  //return moduleProcess->start();
+//}

+ 81 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h

@@ -0,0 +1,81 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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 CTKCMDLINEMODULEMANAGER_H
+#define CTKCMDLINEMODULEMANAGER_H
+
+#include <ctkCommandLineModulesCoreExport.h>
+
+#include <QStringList>
+#include <QString>
+
+struct ctkCmdLineModuleInstanceFactory;
+
+class ctkCmdLineModuleInstance;
+class ctkCmdLineModuleReference;
+class ctkCmdLineModuleManagerPrivate;
+
+/// The methods in this class are for playing around... no API design yet
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleManager
+{
+
+public:
+
+  enum ValidationMode {
+    /** registerModule() will throw an exception if the XML is invalid */
+    STRICT_VALIDATION,
+    /** no XML schema validation at all */
+    SKIP_VALIDATION,
+    /**
+     * registerModule() will validate the XML description but proceed with
+     * registration on validation error.
+     */
+    WEAK_VALIDATION
+  };
+
+  ctkCmdLineModuleManager(ctkCmdLineModuleInstanceFactory* descriptionFactory,
+                          ValidationMode = STRICT_VALIDATION);
+
+  ~ctkCmdLineModuleManager();
+
+  ctkCmdLineModuleReference registerModule(const QString& location);
+  void unregisterModule(const ctkCmdLineModuleReference& moduleRef);
+
+  ctkCmdLineModuleReference moduleReference(const QString& location) const;
+  QList<ctkCmdLineModuleReference> moduleReferences() const;
+
+  ctkCmdLineModuleInstance* createModuleInstance(const ctkCmdLineModuleReference& moduleRef);
+
+  QList<ctkCmdLineModuleInstance*> moduleInstances(const ctkCmdLineModuleReference& moduleRef) const;
+
+  //static QStringList createCommandLineArgs(QObject* hierarchy);
+
+  //static ctkCmdLineModuleProcessFuture run(const ctkCmdLineModuleReference& moduleRef);
+
+private:
+
+  QScopedPointer<ctkCmdLineModuleManagerPrivate> d;
+
+  Q_DISABLE_COPY(ctkCmdLineModuleManager)
+
+};
+
+#endif // CTKCMDLINEMODULEMANAGER_H

Libs/CommandLineModules/ctkCmdLineModuleObjectHierarchyReader.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleObjectHierarchyReader.cpp


+ 2 - 2
Libs/CommandLineModules/ctkCmdLineModuleObjectHierarchyReader.h

@@ -26,13 +26,13 @@
 #include <QScopedPointer>
 #include <QVariant>
 
-#include <ctkCommandLineModulesExport.h>
+#include <ctkCommandLineModulesCoreExport.h>
 
 class QObject;
 
 class ctkCmdLineModuleObjectHierarchyReaderPrivate;
 
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleObjectHierarchyReader
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleObjectHierarchyReader
 {
 
 public:

Libs/CommandLineModules/ctkCmdLineModuleParameter.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleParameter.cpp


+ 3 - 3
Libs/CommandLineModules/ctkCmdLineModuleParameter.h

@@ -21,7 +21,7 @@
 #ifndef __ctkCmdLineModuleParameter_h
 #define __ctkCmdLineModuleParameter_h
 
-#include "ctkCommandLineModulesExport.h"
+#include "ctkCommandLineModulesCoreExport.h"
 
 #include <QSharedDataPointer>
 
@@ -39,7 +39,7 @@ class ctkCmdLineModuleParameterPrivate;
  * stored.
  *
  */
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleParameter
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleParameter
 {
 
 public:
@@ -131,6 +131,6 @@ private:
   QSharedDataPointer<ctkCmdLineModuleParameterPrivate> d;
 };
 
-CTK_CMDLINEMODULE_EXPORT QTextStream& operator<<(QTextStream& os, const ctkCmdLineModuleParameter& parameter);
+CTK_CMDLINEMODULECORE_EXPORT QTextStream& operator<<(QTextStream& os, const ctkCmdLineModuleParameter& parameter);
 
 #endif

Libs/CommandLineModules/ctkCmdLineModuleParameterGroup.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleParameterGroup.cpp


+ 3 - 3
Libs/CommandLineModules/ctkCmdLineModuleParameterGroup.h

@@ -21,7 +21,7 @@
 #ifndef __ctkCmdLineModuleParameterGroup_h
 #define __ctkCmdLineModuleParameterGroup_h
 
-#include "ctkCommandLineModulesExport.h"
+#include "ctkCommandLineModulesCoreExport.h"
 
 #include <QList>
 #include <QSharedDataPointer>
@@ -35,7 +35,7 @@ class ctkCmdLineModuleParameterGroupPrivate;
 *  \brief Group of parameters
 *
 */
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleParameterGroup
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleParameterGroup
 {
 
 public:
@@ -68,6 +68,6 @@ private:
   QSharedDataPointer<ctkCmdLineModuleParameterGroupPrivate> d;
 };
 
-CTK_CMDLINEMODULE_EXPORT QTextStream & operator<<(QTextStream &os, const ctkCmdLineModuleParameterGroup& group);
+CTK_CMDLINEMODULECORE_EXPORT QTextStream & operator<<(QTextStream &os, const ctkCmdLineModuleParameterGroup& group);
 
 #endif

Libs/CommandLineModules/ctkCmdLineModuleParameterGroupPrivate.h → Libs/CommandLineModules/Core/ctkCmdLineModuleParameterGroupPrivate.h


+ 0 - 1
Libs/CommandLineModules/ctkCmdLineModuleParameterParsers_p.h

@@ -50,7 +50,6 @@ public:
   virtual ctkCmdLineModuleParameter parse(QXmlStreamReader &xmlReader)
   {
     ctkCmdLineModuleParameter moduleParam = this->createModuleParameter();
-
     this->handleAttributes(moduleParam.d.data(), xmlReader);
 
     while(xmlReader.readNextStartElement())

Libs/CommandLineModules/ctkCmdLineModuleParameterPrivate.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleParameterPrivate.cpp


Libs/CommandLineModules/ctkCmdLineModuleParameterPrivate.h → Libs/CommandLineModules/Core/ctkCmdLineModuleParameterPrivate.h


Libs/CommandLineModules/ctkCmdLineModuleProcessException.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.cpp


Libs/CommandLineModules/ctkCmdLineModuleProcessException.h → Libs/CommandLineModules/Core/ctkCmdLineModuleProcessException.h


Libs/CommandLineModules/ctkCmdLineModuleProcessFuture.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleProcessFuture.cpp


+ 2 - 2
Libs/CommandLineModules/ctkCmdLineModuleProcessFuture.h

@@ -22,7 +22,7 @@
 #ifndef CTKCMDLINEMODULEPROCESSFUTURE_H
 #define CTKCMDLINEMODULEPROCESSFUTURE_H
 
-#include <ctkCommandLineModulesExport.h>
+#include <ctkCommandLineModulesCoreExport.h>
 
 #include <QFutureInterface>
 #include <QFutureWatcher>
@@ -35,7 +35,7 @@ typedef QFutureWatcher<ctkCmdLineModuleProcessDummy> ctkCmdLineModuleProcessFutu
 
 
 template<>
-class CTK_CMDLINEMODULE_EXPORT QFutureInterface<ctkCmdLineModuleProcessDummy> : public QFutureInterfaceBase
+class CTK_CMDLINEMODULECORE_EXPORT QFutureInterface<ctkCmdLineModuleProcessDummy> : public QFutureInterfaceBase
 {
 
 public:

Libs/CommandLineModules/ctkCmdLineModuleProcessRunner.cpp → Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner.cpp


Libs/CommandLineModules/ctkCmdLineModuleProcessRunner_p.h → Libs/CommandLineModules/Core/ctkCmdLineModuleProcessRunner_p.h


+ 7 - 19
Libs/CommandLineModules/ctkCmdLineModuleReference.cpp

@@ -23,52 +23,40 @@
 #include "ctkCmdLineModuleReferencePrivate.h"
 
 ctkCmdLineModuleReference::ctkCmdLineModuleReference()
-  : d(new ctkCmdLineModuleReferencePrivate)
+  : d(new ctkCmdLineModuleReferencePrivate())
 {}
 
 ctkCmdLineModuleReference::~ctkCmdLineModuleReference()
 {
-  if (!d->ref.deref()) delete d;
 }
 
 ctkCmdLineModuleReference::ctkCmdLineModuleReference(const ctkCmdLineModuleReference &ref)
   : d(ref.d)
 {
-  d->ref.ref();
 }
 
 ctkCmdLineModuleReference &ctkCmdLineModuleReference::operator =(const ctkCmdLineModuleReference &ref)
 {
-  ctkCmdLineModuleReferencePrivate* curr = d;
   d = ref.d;
-  d->ref.ref();
-
-  if (!curr->ref.deref()) delete curr;
-
   return *this;
 }
 
 ctkCmdLineModuleReference::operator bool()
 {
-  return isValid();
+  return d;
 }
 
-bool ctkCmdLineModuleReference::isValid()
+ctkCmdLineModuleDescription ctkCmdLineModuleReference::description() const
 {
-  return !(d->xml.isEmpty() || d->objectRepresentation == 0);
+  return d->Description;
 }
 
-QByteArray ctkCmdLineModuleReference::xmlDescription() const
+QByteArray ctkCmdLineModuleReference::rawXmlDescription() const
 {
-  return d->xml;
+  return d->RawXmlDescription;
 }
 
 QString ctkCmdLineModuleReference::location() const
 {
-  return d->loc;
-}
-
-QObject* ctkCmdLineModuleReference::widgetTree() const
-{
-  return d->gui;
+  return d->Location;
 }

+ 7 - 11
Libs/CommandLineModules/ctkCmdLineModuleReference.h

@@ -22,16 +22,14 @@
 #ifndef CTKCMDLINEMODULEREFERENCE_H
 #define CTKCMDLINEMODULEREFERENCE_H
 
-#include <ctkCommandLineModulesExport.h>
+#include <ctkCommandLineModulesCoreExport.h>
 
-#include <QByteArray>
-#include <QString>
-
-class QObject;
+#include <QSharedDataPointer>
 
+class ctkCmdLineModuleDescription;
 class ctkCmdLineModuleReferencePrivate;
 
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleReference
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleReference
 {
 public:
 
@@ -43,19 +41,17 @@ public:
 
   operator bool();
 
-  bool isValid();
+  ctkCmdLineModuleDescription description() const;
 
-  QByteArray xmlDescription() const;
+  QByteArray rawXmlDescription() const;
 
   QString location() const;
 
-  QObject* widgetTree() const;
-
 private:
 
   friend class ctkCmdLineModuleManager;
 
-  ctkCmdLineModuleReferencePrivate* d;
+  QSharedDataPointer<ctkCmdLineModuleReferencePrivate> d;
 
 };
 

+ 8 - 27
Libs/CommandLineModules/ctkCmdLineModuleReferencePrivate.h

@@ -22,36 +22,17 @@
 #ifndef CTKCMDLINEMODULEREFERENCEPRIVATE_H
 #define CTKCMDLINEMODULEREFERENCEPRIVATE_H
 
-#include <QByteArray>
-#include <QObject>
+#include <ctkCmdLineModuleDescription.h>
 
-class ctkCmdLineModuleReferencePrivate : public QObject
-{
-  Q_OBJECT
-
-public:
-
-  ctkCmdLineModuleReferencePrivate();
-
-  ~ctkCmdLineModuleReferencePrivate();
-
-  void setGUI(QObject* gui);
-
-  QByteArray xml;
-  QString loc;
-  QObject* objectRepresentation;
+#include <QSharedData>
+#include <QString>
 
-  QAtomicInt ref;
-
-private:
-
-  friend class ctkCmdLineModuleReference;
-
-  QObject* gui;
-
-private Q_SLOTS:
+struct ctkCmdLineModuleReferencePrivate : public QSharedData
+{
+  QString Location;
+  QByteArray RawXmlDescription;
 
-  void guiDestroyed();
+  ctkCmdLineModuleDescription Description;
 };
 
 #endif // CTKCMDLINEMODULEREFERENCEPRIVATE_H

+ 76 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlMsgHandler.cpp

@@ -0,0 +1,76 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleXmlMsgHandler_p.h"
+
+#include <QXmlStreamReader>
+
+QString ctkCmdLineModuleXmlMsgHandler::statusMessage() const
+{
+  return Description;
+}
+
+int ctkCmdLineModuleXmlMsgHandler::line() const
+{
+  return SourceLocation.line();
+}
+
+int ctkCmdLineModuleXmlMsgHandler::column() const
+{
+  return SourceLocation.column();
+}
+
+void ctkCmdLineModuleXmlMsgHandler::handleMessage(QtMsgType type, const QString& description,
+                                                  const QUrl& identifier, const QSourceLocation& sourceLocation)
+{
+  Q_UNUSED(identifier)
+
+  MessageType = type;
+  SourceLocation = sourceLocation;
+
+  QXmlStreamReader reader(description);
+  Description.clear();
+  Description.reserve(description.size());
+  while(!reader.atEnd())
+  {
+    reader.readNext();
+
+    switch(reader.tokenType())
+    {
+    case QXmlStreamReader::Characters:
+    {
+      Description.append(reader.text().toString());
+      continue;
+    }
+    case QXmlStreamReader::StartElement:
+      /* Fallthrough, */
+    case QXmlStreamReader::EndElement:
+      /* Fallthrough, */
+    case QXmlStreamReader::StartDocument:
+          /* Fallthrough, */
+    case QXmlStreamReader::EndDocument:
+      continue;
+    default:
+      Q_ASSERT_X(false, Q_FUNC_INFO,
+                 "Unexpected node.");
+    }
+  }
+}

+ 49 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlMsgHandler_p.h

@@ -0,0 +1,49 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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 CTKCMDLINEMODULEXMLMSGHANDLER_P_H
+#define CTKCMDLINEMODULEXMLMSGHANDLER_P_H
+
+#include <QAbstractMessageHandler>
+
+class ctkCmdLineModuleXmlMsgHandler : public QAbstractMessageHandler
+{
+
+public:
+
+  QString statusMessage() const;
+  int line() const;
+  int column() const;
+
+protected:
+
+  virtual void handleMessage(QtMsgType type, const QString& description,
+                             const QUrl& identifier, const QSourceLocation& sourceLocation);
+
+private:
+
+  QtMsgType MessageType;
+  QString Description;
+  QSourceLocation SourceLocation;
+
+};
+
+#endif // CTKCMDLINEMODULEXMLMSGHANDLER_P_H

+ 2 - 1
Libs/CommandLineModules/ctkCmdLineModuleXmlParser.cpp

@@ -68,7 +68,7 @@ static const QString DESCRIPTION = "description";
 
 // ----------------------------------------------------------------------------
 ctkCmdLineModuleXmlParser::ctkCmdLineModuleXmlParser(QIODevice* device,
-                                                       ctkCmdLineModuleDescription* md)
+                                                     ctkCmdLineModuleDescription* md)
   : _device(device), _md(md)
 {
   _paramParsers["integer"] = new ctkCmdLineModuleScalarParameterParser; // type="scalarType"/>
@@ -315,6 +315,7 @@ ctkCmdLineModuleDescription ctkCmdLineModuleDescription::parse(QIODevice* device
 
   // Verify the xml is correct
   parser.validate();
+
   parser.doParse();
 
   return moduleDescription;

+ 104 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlValidator.cpp

@@ -0,0 +1,104 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleXmlValidator.h"
+
+#include "ctkCmdLineModuleXmlMsgHandler_p.h"
+
+#include <QFile>
+#include <QBuffer>
+#include <QXmlSchema>
+#include <QXmlSchemaValidator>
+
+#include <QDebug>
+
+ctkCmdLineModuleXmlValidator::ctkCmdLineModuleXmlValidator(QIODevice *input)
+  : Input(input), InputSchema(0)
+{
+}
+
+void ctkCmdLineModuleXmlValidator::setInput(QIODevice *input)
+{
+  Input = input;
+}
+
+QIODevice* ctkCmdLineModuleXmlValidator::input() const
+{
+  return Input;
+}
+
+void ctkCmdLineModuleXmlValidator::setInputSchema(QIODevice *input)
+{
+  InputSchema = input;
+}
+
+bool ctkCmdLineModuleXmlValidator::validateInput()
+{
+  ErrorStr.clear();
+
+  if (!Input)
+  {
+    ErrorStr = "No input set for validation.";
+    return false;
+  }
+
+  QIODevice* inputSchema = InputSchema;
+  QScopedPointer<QIODevice> defaultInputSchema(new QFile(":/ctkCmdLineModule.xsd"));
+  if (!inputSchema)
+  {
+    inputSchema = defaultInputSchema.data();
+    inputSchema->open(QIODevice::ReadOnly);
+  }
+
+  ctkCmdLineModuleXmlMsgHandler errorHandler;
+
+  QXmlSchema schema;
+  schema.setMessageHandler(&errorHandler);
+
+  if (!schema.load(inputSchema))
+  {
+    QString msg("Invalid input schema at line %1, column %2: %3");
+    ErrorStr = msg.arg(errorHandler.line()).arg(errorHandler.column()).arg(errorHandler.statusMessage());
+    return false;
+  }
+
+  QXmlSchemaValidator validator(schema);
+
+  if (!validator.validate(Input))
+  {
+    QString msg("Error validating CLI XML description, at line %1, column %2: %3");
+    ErrorStr = msg.arg(errorHandler.line()).arg(errorHandler.column())
+                .arg(errorHandler.statusMessage());
+    return false;
+  }
+
+  return true;
+}
+
+bool ctkCmdLineModuleXmlValidator::error() const
+{
+  return !ErrorStr.isEmpty();
+}
+
+QString ctkCmdLineModuleXmlValidator::errorString() const
+{
+  return ErrorStr;
+}

+ 9 - 17
Libs/CommandLineModules/ctkCmdLineModuleXmlValidator.h

@@ -22,13 +22,13 @@
 #ifndef CTKCMDLINEMODULEXMLVALIDATOR_H
 #define CTKCMDLINEMODULEXMLVALIDATOR_H
 
-#include <ctkCommandLineModulesExport.h>
+#include <ctkCommandLineModulesCoreExport.h>
 
 #include <QString>
 
 class QIODevice;
 
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleXmlValidator
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXmlValidator
 {
 
 public:
@@ -36,29 +36,21 @@ public:
   ctkCmdLineModuleXmlValidator(QIODevice* input = 0);
 
   void setInput(QIODevice* input);
-  QString output();
+  QIODevice* input() const;
 
   void setInputSchema(QIODevice* input);
-  void setOutputSchema(QIODevice* output);
 
-  void setXSLTransformation(QIODevice* transformation);
+  virtual bool validateInput();
 
-  bool validate();
-  bool validateXMLInput();
-  bool validateXSLTOutput();
-
-  bool error() const;
-  QString errorString() const;
+  virtual bool error() const;
+  virtual QString errorString() const;
 
 private:
 
-  QIODevice* _input;
-  QIODevice* _inputSchema;
-  QIODevice* _outputSchema;
-  QIODevice* _transformation;
+  QIODevice* Input;
+  QIODevice* InputSchema;
 
-  QString _output;
-  QString _errorStr;
+  QString ErrorStr;
 };
 
 #endif // CTKCMDLINEMODULEXMLVALIDATOR_H

+ 169 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.cpp

@@ -0,0 +1,169 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleXslTransform.h"
+
+#include "ctkCmdLineModuleXmlMsgHandler_p.h"
+
+#include <QFile>
+#include <QBuffer>
+#include <QXmlSchema>
+#include <QXmlSchemaValidator>
+#include <QXmlQuery>
+
+#include <QDebug>
+
+
+ctkCmdLineModuleXslTransform::ctkCmdLineModuleXslTransform(QIODevice *input)
+  : ctkCmdLineModuleXmlValidator(input),
+    OutputSchema(0), Transformation(0)
+{
+}
+
+QString ctkCmdLineModuleXslTransform::output() const
+{
+  return Output;
+}
+
+void ctkCmdLineModuleXslTransform::setOutputSchema(QIODevice *output)
+{
+  OutputSchema = output;
+}
+
+bool ctkCmdLineModuleXslTransform::transform()
+{
+  QIODevice* inputDevice = input();
+  if (!inputDevice)
+  {
+    ErrorStr = "No input set for deriving an output.";
+    return false;
+  }
+  else if (!(inputDevice->openMode() & QIODevice::ReadOnly))
+  {
+    inputDevice->open(QIODevice::ReadOnly);
+  }
+  inputDevice->reset();
+
+  ctkCmdLineModuleXmlMsgHandler msgHandler;
+
+  QXmlQuery xslTransform(QXmlQuery::XSLT20);
+  xslTransform.setMessageHandler(&msgHandler);
+  if (!xslTransform.setFocus(inputDevice))
+  {
+    QString msg("Error transforming XML input: %1");
+    ErrorStr = msg.arg(msgHandler.statusMessage());
+    return false;
+  }
+
+  QIODevice* transformation = Transformation;
+  QScopedPointer<QIODevice> defaultTransform(new QFile(":/ctkCmdLineModuleXmlToQtUi.xsl"));
+  if (!transformation)
+  {
+    transformation = defaultTransform.data();
+    transformation->open(QIODevice::ReadOnly);
+  }
+  xslTransform.setQuery(transformation);
+
+  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;
+  }
+
+  return true;
+}
+
+void ctkCmdLineModuleXslTransform::setXslTransformation(QIODevice *transformation)
+{
+  Transformation = transformation;
+}
+
+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.
+  // The QtDesigner.xsd schema below (which should be the default) exhausts
+  // the memory during validation.
+  if (!outputSchema) return true;
+
+  QScopedPointer<QIODevice> defaultOutputSchema(new QFile(":/QtDesigner.xsd"));
+  if (!outputSchema)
+  {
+    outputSchema = defaultOutputSchema.data();
+    outputSchema->open(QIODevice::ReadOnly);
+  }
+  outputSchema->reset();
+
+  QXmlSchema schema;
+
+  ctkCmdLineModuleXmlMsgHandler msgHandler;
+  schema.setMessageHandler(&msgHandler);
+
+  if (!schema.load(outputSchema))
+  {
+    QString msg("Invalid output schema at line %1, column %2: %3");
+    ErrorStr = msg.arg(msgHandler.line()).arg(msgHandler.column()).arg(msgHandler.statusMessage());
+    return false;
+  }
+
+  QXmlSchemaValidator validator(schema);
+  validator.setMessageHandler(&msgHandler);
+
+  QByteArray outputData;
+  outputData.append(Output);
+
+  if (!validator.validate(outputData))
+  {
+    QString msg("Error validating transformed XML input, at line %1, column %2: %3");
+    ErrorStr = msg.arg(msgHandler.line()).arg(msgHandler.column())
+                .arg(msgHandler.statusMessage());
+    return false;
+  }
+
+  return true;
+}
+
+bool ctkCmdLineModuleXslTransform::error() const
+{
+  return ctkCmdLineModuleXmlValidator::error() || !ErrorStr.isEmpty();
+}
+
+QString ctkCmdLineModuleXslTransform::errorString() const
+{
+  QString errStr = ctkCmdLineModuleXmlValidator::errorString();
+  if (errStr.isEmpty())
+  {
+    return ErrorStr;
+  }
+  return errStr;
+}

+ 70 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleXslTransform.h

@@ -0,0 +1,70 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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 CTKCMDLINEMODULEXSLTRANSFORM_H
+#define CTKCMDLINEMODULEXSLTRANSFORM_H
+
+#include "ctkCommandLineModulesCoreExport.h"
+#include "ctkCmdLineModuleXmlValidator.h"
+
+#include <QString>
+
+class QIODevice;
+
+class CTK_CMDLINEMODULECORE_EXPORT ctkCmdLineModuleXslTransform
+    : public ctkCmdLineModuleXmlValidator
+{
+
+public:
+
+  ctkCmdLineModuleXslTransform(QIODevice* input = 0);
+
+  void setOutputSchema(QIODevice* output);
+
+  /**
+   * @brief Transforms an XML input via a XSL transformation.
+   *
+   * This method assumes that the input set via setInput() or supplied
+   * in the constructor is a valid XML fragment.
+   *
+   * @return
+   */
+  bool transform();
+
+  QString output() const;
+
+  void setXslTransformation(QIODevice* transformation);
+
+  bool validateOutput();
+
+  bool error() const;
+  QString errorString() const;
+
+private:
+
+  QIODevice* OutputSchema;
+  QIODevice* Transformation;
+
+  QString Output;
+  QString ErrorStr;
+};
+
+#endif // CTKCMDLINEMODULEXSLTRANSFORM_H

Libs/CommandLineModules/target_libraries.cmake → Libs/CommandLineModules/Core/target_libraries.cmake


+ 68 - 0
Libs/CommandLineModules/QtGui/CMakeLists.txt

@@ -0,0 +1,68 @@
+project(CTKCommandLineModulesQtGui)
+
+#
+# 3rd party dependencies
+#
+
+#
+# See CTK/CMake/ctkMacroBuildLib.cmake for details
+#
+
+set(KIT_export_directive "CTK_CMDLINEMODULEQTGUI_EXPORT")
+
+# Additional directories to include
+
+# Source files
+set(KIT_SRCS
+  ctkCmdLineModuleInstanceFactoryQtGui.cpp
+  ctkCmdLineModuleInstanceQtGui_p.h
+  ctkCmdLineModuleInstanceQtGui.cpp
+)
+
+# Headers that should run through moc
+set(KIT_MOC_SRCS
+  
+)
+
+# UI files
+set(KIT_UI_FORMS
+)
+
+# Resources
+set(KIT_resources
+  
+)
+
+set(QT_USE_QTUITOOLS 1)
+include(${QT_USE_FILE})
+
+# Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
+# The following macro will read the target libraries from the file 'target_libraries.cmake'
+ctkFunctionGetTargetLibraries(KIT_target_libraries)
+
+ctkMacroBuildLib(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${KIT_export_directive}
+  INCLUDE_DIRECTORIES ${KIT_include_directories}
+  SRCS ${KIT_SRCS}
+  MOC_SRCS ${KIT_MOC_SRCS}
+  UI_FORMS ${KIT_UI_FORMS}
+  TARGET_LIBRARIES ${KIT_target_libraries}
+  RESOURCES ${KIT_resources}
+  LIBRARY_TYPE ${CTK_LIBRARY_MODE}
+  )
+
+target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
+
+if(CTK_WRAP_PYTHONQT_FULL OR CTK_WRAP_PYTHONQT_LIGHT)
+  ctkMacroBuildLibWrapper(
+    TARGET ${PROJECT_NAME}
+    SRCS ${KIT_SRCS}
+    WRAPPER_LIBRARY_TYPE ${CTK_LIBRARY_MODE}
+    )
+endif()
+
+# Testing
+if(BUILD_TESTING)
+#  add_subdirectory(Testing)
+endif()

+ 29 - 0
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceFactoryQtGui.cpp

@@ -0,0 +1,29 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  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
+
+  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.
+
+=============================================================================*/
+
+#include "ctkCmdLineModuleInstanceFactoryQtGui.h"
+#include "ctkCmdLineModuleInstanceQtGui_p.h"
+
+ctkCmdLineModuleInstance*
+ctkCmdLineModuleInstanceFactoryQtGui::create(const ctkCmdLineModuleReference& moduleRef)
+{
+  return new ctkCmdLineModuleInstanceQtGui(moduleRef);
+}

+ 38 - 0
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceFactoryQtGui.h

@@ -0,0 +1,38 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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 CTKCMDLINEMODULEINSTANCEFACTORYQTGUI_H
+#define CTKCMDLINEMODULEINSTANCEFACTORYQTGUI_H
+
+#include "ctkCmdLineModuleInstanceFactory.h"
+
+#include "ctkCommandLineModulesQtGuiExport.h"
+
+class CTK_CMDLINEMODULEQTGUI_EXPORT ctkCmdLineModuleInstanceFactoryQtGui
+    : public ctkCmdLineModuleInstanceFactory
+{
+public:
+
+  ctkCmdLineModuleInstance* create(const ctkCmdLineModuleReference& moduleRef);
+
+};
+
+#endif // CTKCMDLINEMODULEINSTANCEFACTORYQTGUI_H

+ 69 - 0
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui.cpp

@@ -0,0 +1,69 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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.
+  
+=============================================================================*/
+
+#include "ctkCmdLineModuleInstanceQtGui_p.h"
+#include "ctkCmdLineModuleReference.h"
+#include "ctkCmdLineModuleXslTransform.h"
+
+#include <QBuffer>
+#include <QUiLoader>
+#include <QWidget>
+#include <QVariant>
+
+#include <QDebug>
+
+ctkCmdLineModuleInstanceQtGui::ctkCmdLineModuleInstanceQtGui(const ctkCmdLineModuleReference& moduleRef)
+  : WidgetTree(NULL), XmlDescription(moduleRef.rawXmlDescription())
+{
+}
+
+QObject* ctkCmdLineModuleInstanceQtGui::guiHandle() const
+{
+  if (WidgetTree) return WidgetTree;
+
+  QBuffer input;
+  input.setData(XmlDescription);
+
+  ctkCmdLineModuleXslTransform xslTransform(&input);
+  if (!xslTransform.transform())
+  {
+    // maybe throw an exception
+    qCritical() << xslTransform.errorString();
+    return 0;
+  }
+
+  QUiLoader uiLoader;
+  QByteArray uiBlob;
+  uiBlob.append(xslTransform.output());
+
+  QBuffer uiForm(&uiBlob);
+  return uiLoader.load(&uiForm);
+}
+
+QVariant ctkCmdLineModuleInstanceQtGui::value(const QString& parameter) const
+{
+  return QVariant();
+}
+
+void ctkCmdLineModuleInstanceQtGui::setValue(const QString& parameter, const QVariant& value)
+{
+
+}

+ 50 - 0
Libs/CommandLineModules/QtGui/ctkCmdLineModuleInstanceQtGui_p.h

@@ -0,0 +1,50 @@
+/*=============================================================================
+  
+  Library: CTK
+  
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+    
+  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
+    
+  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 CTKCMDLINEMODULEINSTANCEQTGUI_H
+#define CTKCMDLINEMODULEINSTANCEQTGUI_H
+
+#include <ctkCmdLineModuleInstance.h>
+
+class ctkCmdLineModuleReference;
+
+class ctkCmdLineModuleInstanceQtGui : public ctkCmdLineModuleInstance
+{
+
+public:
+
+  ctkCmdLineModuleInstanceQtGui(const ctkCmdLineModuleReference& moduleRef);
+
+  // ctkCmdLineModuleInstance overrides
+
+  virtual QObject* guiHandle() const;
+
+  virtual QVariant value(const QString& parameter) const;
+  virtual void setValue(const QString& parameter, const QVariant& value);
+
+private:
+
+  mutable QWidget* WidgetTree;
+
+  const QByteArray XmlDescription;
+};
+
+#endif // CTKCMDLINEMODULEINSTANCEQTGUI_H

+ 9 - 0
Libs/CommandLineModules/QtGui/target_libraries.cmake

@@ -0,0 +1,9 @@
+#
+# See CMake/ctkMacroGetTargetLibraries.cmake
+# 
+# This file should list the libraries required to build the current CTK libraries
+#
+
+set(target_libraries
+  CTKCommandLineModulesCore
+)

+ 0 - 67
Libs/CommandLineModules/ctkCmdLineModuleManager.h

@@ -1,67 +0,0 @@
-/*=============================================================================
-  
-  Library: CTK
-  
-  Copyright (c) German Cancer Research Center,
-    Division of Medical and Biological Informatics
-    
-  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
-    
-  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 CTKCMDLINEMODULEMANAGER_H
-#define CTKCMDLINEMODULEMANAGER_H
-
-#include <QStringList>
-#include <QString>
-
-#include <ctkCommandLineModulesExport.h>
-
-#include "ctkCmdLineModuleReference.h"
-#include "ctkCmdLineModuleProcessFuture.h"
-
-class QObject;
-
-struct ctkCmdLineModuleDescriptionFactory
-{
-  virtual ~ctkCmdLineModuleDescriptionFactory() {}
-
-  virtual QObject* createGUIFromXML(const QByteArray& xmlDescription)
-  {
-    Q_UNUSED(xmlDescription)
-    return 0;
-  }
-
-  virtual QObject* createObjectRepresentationFromXML(const QByteArray& xmlDescription) = 0;
-};
-
-/// The methods in this class are for playing around... no API design yet
-class CTK_CMDLINEMODULE_EXPORT ctkCmdLineModuleManager
-{
-public:
-  ctkCmdLineModuleManager(ctkCmdLineModuleDescriptionFactory* descriptionFactory);
-
-  ctkCmdLineModuleReference addModule(const QString& location);
-
-  static QStringList createCommandLineArgs(QObject* hierarchy);
-
-  static ctkCmdLineModuleProcessFuture run(const ctkCmdLineModuleReference& moduleRef);
-
-private:
-
-  ctkCmdLineModuleDescriptionFactory* descriptionFactory;
-
-  QHash<QString, ctkCmdLineModuleReference> cache;
-};
-
-#endif // CTKCMDLINEMODULEMANAGER_H

+ 0 - 259
Libs/CommandLineModules/ctkCmdLineModuleXmlValidator.cpp

@@ -1,259 +0,0 @@
-/*=============================================================================
-  
-  Library: CTK
-  
-  Copyright (c) German Cancer Research Center,
-    Division of Medical and Biological Informatics
-    
-  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
-    
-  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.
-  
-=============================================================================*/
-
-#include "ctkCmdLineModuleXmlValidator.h"
-
-#include <QFile>
-#include <QBuffer>
-#include <QXmlStreamReader>
-#include <QXmlSchema>
-#include <QXmlSchemaValidator>
-#include <QXmlQuery>
-#include <QAbstractMessageHandler>
-
-#include <QDebug>
-
-class _MessageHandler : public QAbstractMessageHandler
-{
-public:
-
-  QString statusMessage() const { return m_description; }
-  int line() const { return m_sourceLocation.line(); }
-  int column() const { return m_sourceLocation.column(); }
-
-protected:
-  virtual void handleMessage(QtMsgType type, const QString& description,
-                             const QUrl& identifier, const QSourceLocation& sourceLocation)
-  {
-    Q_UNUSED(identifier)
-
-    m_messageType = type;
-    m_sourceLocation = sourceLocation;
-
-    QXmlStreamReader reader(description);
-    m_description.clear();
-    m_description.reserve(description.size());
-    while(!reader.atEnd())
-    {
-      reader.readNext();
-
-      switch(reader.tokenType())
-      {
-      case QXmlStreamReader::Characters:
-      {
-        m_description.append(reader.text().toString());
-        continue;
-      }
-      case QXmlStreamReader::StartElement:
-        /* Fallthrough, */
-      case QXmlStreamReader::EndElement:
-        /* Fallthrough, */
-      case QXmlStreamReader::StartDocument:
-        /* Fallthrough, */
-      case QXmlStreamReader::EndDocument:
-        continue;
-      default:
-        Q_ASSERT_X(false, Q_FUNC_INFO,
-                   "Unexpected node.");
-      }
-    }
-  }
-
-private:
-  QtMsgType m_messageType;
-  QString m_description;
-  QSourceLocation m_sourceLocation;
-};
-
-ctkCmdLineModuleXmlValidator::ctkCmdLineModuleXmlValidator(QIODevice *input)
-  : _input(input), _inputSchema(0), _outputSchema(0), _transformation(0)
-{
-}
-
-void ctkCmdLineModuleXmlValidator::setInput(QIODevice *input)
-{
-  _input = input;
-}
-
-QString ctkCmdLineModuleXmlValidator::output()
-{
-  return _output;
-}
-
-void ctkCmdLineModuleXmlValidator::setInputSchema(QIODevice *input)
-{
-  _inputSchema = input;
-}
-
-void ctkCmdLineModuleXmlValidator::setOutputSchema(QIODevice *output)
-{
-  _outputSchema = output;
-}
-
-void ctkCmdLineModuleXmlValidator::setXSLTransformation(QIODevice *transformation)
-{
-  _transformation = transformation;
-}
-
-bool ctkCmdLineModuleXmlValidator::validate()
-{
-  return validateXMLInput() && validateXSLTOutput();
-}
-
-bool ctkCmdLineModuleXmlValidator::validateXMLInput()
-{
-  _errorStr.clear();
-
-  if (!_input)
-  {
-    _errorStr = "No input set for validation.";
-    return false;
-  }
-
-  QIODevice* inputSchema = _inputSchema;
-  QScopedPointer<QIODevice> defaultInputSchema(new QFile(":/ctkCmdLineModule.xsd"));
-  if (!inputSchema)
-  {
-    inputSchema = defaultInputSchema.data();
-    inputSchema->open(QIODevice::ReadOnly);
-  }
-
-  _MessageHandler errorHandler;
-
-  QXmlSchema schema;
-  schema.setMessageHandler(&errorHandler);
-
-  if (!schema.load(inputSchema))
-  {
-    QString msg("Invalid input schema at line %1, column %2: %3");
-    _errorStr = msg.arg(errorHandler.line()).arg(errorHandler.column()).arg(errorHandler.statusMessage());
-    return false;
-  }
-
-  QXmlSchemaValidator validator(schema);
-
-  if (!validator.validate(_input))
-  {
-    QString msg("Error validating CLI XML description, at line %1, column %2: %3");
-    _errorStr = msg.arg(errorHandler.line()).arg(errorHandler.column())
-                .arg(errorHandler.statusMessage());
-    return false;
-  }
-
-  return true;
-}
-
-bool ctkCmdLineModuleXmlValidator::validateXSLTOutput()
-{
-  _errorStr.clear();
-  _output.clear();
-
-  if (!_input)
-  {
-    _errorStr = "No input set for deriving an output.";
-    return false;
-  }
-  else if (!(_input->openMode() & QIODevice::ReadOnly))
-  {
-    _input->open(QIODevice::ReadOnly);
-  }
-  _input->reset();
-
-  _MessageHandler msgHandler;
-
-  QXmlQuery xslTransform(QXmlQuery::XSLT20);
-  xslTransform.setMessageHandler(&msgHandler);
-  if (!xslTransform.setFocus(_input))
-  {
-    QString msg("Error transforming CLI XML description: %1");
-    _errorStr = msg.arg(msgHandler.statusMessage());
-    return false;
-  }
-
-  QIODevice* transformation = _transformation;
-  QScopedPointer<QIODevice> defaultTransform(new QFile(":/ctkCmdLineModuleXmlToQtUi.xsl"));
-  if (!transformation)
-  {
-    transformation = defaultTransform.data();
-    transformation->open(QIODevice::ReadOnly);
-  }
-  xslTransform.setQuery(transformation);
-
-  if (!xslTransform.evaluateTo(&_output))
-  {
-    _output.clear();
-    QString msg("Error transforming CLI XML description, at line %1, column %2: %3");
-    _errorStr = msg.arg(msgHandler.line()).arg(msgHandler.column())
-                .arg(msgHandler.statusMessage());
-    return false;
-  }
-
-  QIODevice* outputSchema = _outputSchema;
-
-  // If there is no custom schema for validating the output, we just return.
-  // The QtDesigner.xsd schema below (which should be the default) exhausts
-  // the memory during validation.
-  if (!outputSchema) return true;
-
-  QScopedPointer<QIODevice> defaultOutputSchema(new QFile(":/QtDesigner.xsd"));
-  if (!outputSchema)
-  {
-    outputSchema = defaultOutputSchema.data();
-    outputSchema->open(QIODevice::ReadOnly);
-  }
-  outputSchema->reset();
-
-  QXmlSchema schema;
-  schema.setMessageHandler(&msgHandler);
-
-  if (!schema.load(outputSchema))
-  {
-    QString msg("Invalid output schema at line %1, column %2: %3");
-    _errorStr = msg.arg(msgHandler.line()).arg(msgHandler.column()).arg(msgHandler.statusMessage());
-    return false;
-  }
-
-  QXmlSchemaValidator validator(schema);
-  validator.setMessageHandler(&msgHandler);
-
-  QByteArray outputData;
-  outputData.append(_output);
-
-  if (!validator.validate(outputData))
-  {
-    QString msg("Error validating transformed CLI XML description, at line %1, column %2: %3");
-    _errorStr = msg.arg(msgHandler.line()).arg(msgHandler.column())
-                .arg(msgHandler.statusMessage());
-    return false;
-  }
-
-  return true;
-}
-
-bool ctkCmdLineModuleXmlValidator::error() const
-{
-  return !_errorStr.isEmpty();
-}
-
-QString ctkCmdLineModuleXmlValidator::errorString() const
-{
-  return _errorStr;
-}