Bladeren bron

Simplified parsing of CLI XML descriptions + cleanup.

Sascha Zelzer 13 jaren geleden
bovenliggende
commit
22aeb5ec2d
26 gewijzigde bestanden met toevoegingen van 703 en 2863 verwijderingen
  1. 3 15
      Libs/ModuleDescription/CMakeLists.txt
  2. 0 0
      Libs/ModuleDescription/README
  3. 0 16
      Libs/ModuleDescription/ctkModuleDescription.cpp
  4. 0 3
      Libs/ModuleDescription/ctkModuleDescription.h
  5. 0 38
      Libs/ModuleDescription/ctkModuleDescriptionConverter.cpp
  6. 0 50
      Libs/ModuleDescription/ctkModuleDescriptionConverter.h
  7. 0 54
      Libs/ModuleDescription/ctkModuleDescriptionConverterInterface.h
  8. 0 38
      Libs/ModuleDescription/ctkModuleDescriptionExecution.cpp
  9. 0 50
      Libs/ModuleDescription/ctkModuleDescriptionExecution.h
  10. 0 49
      Libs/ModuleDescription/ctkModuleDescriptionExecutionInterface.h
  11. 321 0
      Libs/ModuleDescription/ctkModuleDescriptionParser.cpp
  12. 0 1852
      Libs/ModuleDescription/ctkModuleDescriptionReader.cpp
  13. 0 54
      Libs/ModuleDescription/ctkModuleDescriptionReader.h
  14. 59 45
      Libs/ModuleDescription/ctkModuleParameter.cpp
  15. 14 13
      Libs/ModuleDescription/ctkModuleParameter.h
  16. 4 4
      Libs/ModuleDescription/ctkModuleParameterGroup.cpp
  17. 2 2
      Libs/ModuleDescription/ctkModuleParameterGroup.h
  18. 0 50
      Libs/ModuleDescription/ctkModuleParameterGroupValue.cpp
  19. 0 48
      Libs/ModuleDescription/ctkModuleParameterGroupValue.h
  20. 300 0
      Libs/ModuleDescription/ctkModuleParameterParsers_p.h
  21. 0 73
      Libs/ModuleDescription/ctkModuleParameterValue.cpp
  22. 0 56
      Libs/ModuleDescription/ctkModuleParameterValue.h
  23. 0 63
      Libs/ModuleDescription/ctkModuleValues.cpp
  24. 0 67
      Libs/ModuleDescription/ctkModuleValues.h
  25. 0 158
      Libs/ModuleDescription/ctkSlicerModuleStringConverter.cpp
  26. 0 65
      Libs/ModuleDescription/ctkSlicerModuleStringConverter.h

+ 3 - 15
Libs/ModuleDescription/CMakeLists.txt

@@ -16,25 +16,13 @@ set(KIT_export_directive "CTK_MODULDESC_EXPORT")
 set(KIT_SRCS
   ctkModuleDescription.h
   ctkModuleDescription.cpp
-  #ctkModuleDescriptionReader.h
-  ctkModuleDescriptionReader.cpp
+  ctkModuleDescriptionParser.cpp
   ctkModuleParameter.h
   ctkModuleParameter.cpp
   ctkModuleParameterGroup.h
   ctkModuleParameterGroup.cpp
-  #ctkModuleParameterGroupValue.h
-  #ctkModuleParameterGroupValue.cpp
-  #ctkModuleParameterValue.h
-  #ctkModuleParameterValue.cpp
-  #ctkModuleDescriptionConverterInterface.h
-  #ctkModuleDescriptionConverter.h
-  #ctkModuleDescriptionConverter.cpp
-  #ctkModuleDescriptionExecutionInterface.h
-  #ctkModuleDescriptionExecution.h
-  #ctkModuleDescriptionExecution.cpp
-  #ctkModuleValues.h
-  #ctkModuleValues.cpp
-  )
+  ctkModuleParameterParsers_p.h
+ )
 
 # Headers that should run through moc
 set(KIT_MOC_SRCS

+ 0 - 0
Libs/ModuleDescription/README


+ 0 - 16
Libs/ModuleDescription/ctkModuleDescription.cpp

@@ -32,7 +32,6 @@ struct ctkModuleDescriptionPrivate
 
   QString Title;
   QString Category;
-  QString Index;
   QString Description;
   QString Version;
   QString DocumentationURL;
@@ -81,20 +80,6 @@ QString ctkModuleDescription::category() const
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleDescription::setIndex(const QString& ind)
-{
-  Q_D(ctkModuleDescription);
-  d->Index = ind;
-}
-
-//----------------------------------------------------------------------------
-QString ctkModuleDescription::index() const
-{
-  Q_D(const ctkModuleDescription);
-  return d->Index;
-}
-
-//----------------------------------------------------------------------------
 void ctkModuleDescription::setTitle(const QString& title)
 {
   Q_D(ctkModuleDescription);
@@ -367,7 +352,6 @@ QTextStream & operator<<(QTextStream &os, const ctkModuleDescription &module)
 {
   os << "Title: " << module.title() << '\n';
   os << "Category: " << module.category() << '\n';
-  os << "Index: " << module.index() << '\n';
   os << "Description: " << module.description() << '\n';
   os << "Version: " << module.version() << '\n';
   os << "DocumentationURL: " << module.documentationURL() << '\n';

+ 0 - 3
Libs/ModuleDescription/ctkModuleDescription.h

@@ -51,9 +51,6 @@ public:
   void setCategory(const QString& cat);
   QString category() const;
 
-  void setIndex(const QString& ind);
-  QString index() const;
-
   void setTitle(const QString& title);
   QString title() const;
 

+ 0 - 38
Libs/ModuleDescription/ctkModuleDescriptionConverter.cpp

@@ -1,38 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universitat Pompeu Fabra
-
-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 "ctkModuleDescriptionConverter.h"
-
-ctkModuleDescriptionConverter::ctkModuleDescriptionConverter() 
-{
-
-}
-
-ctkModuleDescriptionConverter::~ctkModuleDescriptionConverter()
-{
-
-}
-
-void ctkModuleDescriptionConverter::setModuleDescription( const ctkModuleDescription &val )
-{
-  this->ModuleDescription = val;
-}
-

+ 0 - 50
Libs/ModuleDescription/ctkModuleDescriptionConverter.h

@@ -1,50 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universitat Pompeu Fabra
-
-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 __ctkModuleDescriptionConverter_h
-#define __ctkModuleDescriptionConverter_h
-
-#include <QString>
-
-#include "ctkModuleDescriptionExport.h"
-#include "ctkModuleDescriptionConverterInterface.h"
-
-/** 
- * \brief Base Reader of ModuleDescription
- *
- * This is the base interface
- */
-class CTK_MODULDESC_EXPORT ctkModuleDescriptionConverter :
-  virtual public ctkModuleDescriptionConverterInterface
-{
-  Q_OBJECT
-public:
-  ctkModuleDescriptionConverter();
-  ~ctkModuleDescriptionConverter();
-
-  ///
-  virtual void setModuleDescription(const ctkModuleDescription &val);
-
-protected:
-  ///
-  ctkModuleDescription ModuleDescription;
-};
-
-#endif

+ 0 - 54
Libs/ModuleDescription/ctkModuleDescriptionConverterInterface.h

@@ -1,54 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universitat Pompeu Fabra
-
-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 __ctkModuleDescriptionConverterInterface_h
-#define __ctkModuleDescriptionConverterInterface_h
-
-#include <QVariant>
-
-#include "ctkModuleDescriptionExport.h"
-#include "ctkModuleDescription.h"
-
-/** 
- * \brief Interface of ModuleDescription converter
- *
- * A converter can be a Automated GUI generator that converts
- * ctkModuleDescription into a Qt window. A converter can also be
- * a command line generator that creates a command line string to 
- * execute an application
- */
-class CTK_MODULDESC_EXPORT ctkModuleDescriptionConverterInterface : public QObject
-{
-    Q_OBJECT
-public:
-  ctkModuleDescriptionConverterInterface(){};
-  ~ctkModuleDescriptionConverterInterface(){};
-
-  //! Set input Module Description
-  virtual void setModuleDescription(const ctkModuleDescription &val) = 0;
-
-  //!
-  virtual void update( ) = 0;
-
-  //!
-  virtual const QVariant GetOutput( ) = 0;
-};
-
-#endif

+ 0 - 38
Libs/ModuleDescription/ctkModuleDescriptionExecution.cpp

@@ -1,38 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universitat Pompeu Fabra
-
-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 "ctkModuleDescriptionExecution.h"
-
-ctkModuleDescriptionExecution::ctkModuleDescriptionExecution() 
-{
-
-}
-
-ctkModuleDescriptionExecution::~ctkModuleDescriptionExecution()
-{
-
-}
-
-void ctkModuleDescriptionExecution::setModuleDescription( const ctkModuleDescription &val )
-{
-  this->ModuleDescription = val;
-}
-

+ 0 - 50
Libs/ModuleDescription/ctkModuleDescriptionExecution.h

@@ -1,50 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universitat Pompeu Fabra
-
-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 __ctkModuleDescriptionExecution_h
-#define __ctkModuleDescriptionExecution_h
-
-#include <QString>
-
-#include "ctkModuleDescriptionExport.h"
-#include "ctkModuleDescriptionExecutionInterface.h"
-
-/** 
- * \brief Base Reader of ModuleDescription
- *
- * This is the base interface
- */
-class CTK_MODULDESC_EXPORT ctkModuleDescriptionExecution :
-  virtual public ctkModuleDescriptionExecutionInterface
-{
-  Q_OBJECT
-public:
-  ctkModuleDescriptionExecution();
-  ~ctkModuleDescriptionExecution();
-
-  ///
-  virtual void setModuleDescription(const ctkModuleDescription &val);
-
-protected:
-  ///
-  ctkModuleDescription ModuleDescription;
-};
-
-#endif

+ 0 - 49
Libs/ModuleDescription/ctkModuleDescriptionExecutionInterface.h

@@ -1,49 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universitat Pompeu Fabra
-
-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 __ctkModuleDescriptionExecutionInterface_h
-#define __ctkModuleDescriptionExecutionInterface_h
-
-#include <QVariant>
-
-#include "ctkModuleDescriptionExport.h"
-#include "ctkModuleDescription.h"
-
-/** 
- * \brief Interface of ModuleDescription execution
- *
- * This allows to execute a filter using an executable application
- * or a DLL Command Line Plugin
- */
-class CTK_MODULDESC_EXPORT ctkModuleDescriptionExecutionInterface : public QObject
-{
-    Q_OBJECT
-public:
-  ctkModuleDescriptionExecutionInterface(){};
-  ~ctkModuleDescriptionExecutionInterface(){};
-
-  //! Set input Module Description
-  virtual void setModuleDescription(const ctkModuleDescription &val) = 0;
-
-  //!
-  virtual void Update( ) = 0;
-};
-
-#endif

+ 321 - 0
Libs/ModuleDescription/ctkModuleDescriptionParser.cpp

@@ -0,0 +1,321 @@
+/*=============================================================================
+
+Library: CTK
+
+Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
+
+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.
+
+=============================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QXmlSchema>
+#include <QXmlSchemaValidator>
+#include <QAbstractMessageHandler>
+#include <QXmlStreamReader>
+
+// CTK includes
+#include "ctkModuleDescription.h"
+#include "ctkModuleParameterParsers_p.h"
+
+// STD includes
+#include <stdexcept>
+
+class ctkModuleDescriptionParser
+{
+public:
+
+  ctkModuleDescriptionParser(QIODevice* device, ctkModuleDescription* md);
+  ~ctkModuleDescriptionParser();
+
+  void validate();
+  void doParse();
+
+  void handleExecutableElement();
+  void handleParametersElement();
+  ctkModuleParameter* handleParameterElement();
+
+private:
+
+  QIODevice* const _device;
+  ctkModuleDescription* _md;
+  QXmlStreamReader _xmlReader;
+  QHash<QString, ctkModuleParameterParser*> _paramParsers;
+};
+
+namespace {
+
+static const QString DESCRIPTION = "description";
+
+}
+
+
+// ----------------------------------------------------------------------------
+ctkModuleDescriptionParser::ctkModuleDescriptionParser(QIODevice* device,
+                                                       ctkModuleDescription* md)
+  : _device(device), _md(md)
+{
+  _paramParsers["integer"] = new ctkModuleScalarParameterParser; // type="scalarType"/>
+  _paramParsers["integer-vector"] = new ctkModuleScalarVectorParameterParser; // type="scalarVectorType"/>
+  _paramParsers["boolean"] = new ctkModuleParameterParser; // type="paramType"/>
+  _paramParsers["float"] = new ctkModuleScalarParameterParser; // type="scalarType"/>
+  _paramParsers["float-vector"] = new ctkModuleScalarVectorParameterParser; // type="scalarVectorType"/>
+  _paramParsers["double"] = new ctkModuleScalarParameterParser; // type="scalarType"/>
+  _paramParsers["double-vector"] = new ctkModuleScalarVectorParameterParser; // type="scalarVectorType"/>
+  _paramParsers["string"] = new ctkModuleMultipleParameterParser; // type="multipleType"/>
+  _paramParsers["string-vector"] = new ctkModuleParameterParser; // type="paramType"/>
+  _paramParsers["point"] = new ctkModulePointParameterParser; // type="pointType"/>
+  _paramParsers["region"] = new ctkModulePointParameterParser; // type="pointType"/>
+  _paramParsers["string-enumeration"] = new ctkModuleEnumerationParameterParser; // type="enumerationType"/>
+  _paramParsers["integer-enumeration"] = new ctkModuleEnumerationParameterParser; // type="enumerationType"/>
+  _paramParsers["float-enumeration"] = new ctkModuleEnumerationParameterParser; // type="enumerationType"/>
+  _paramParsers["double-enumeration"] = new ctkModuleEnumerationParameterParser; // type="enumerationType"/>
+  _paramParsers["file"] = new ctkModuleFileParameterParser; // type="fileType"/>
+  _paramParsers["directory"] = new ctkModuleChannelParameterParser; // type="channelType"/>
+  _paramParsers["image"] = new ctkModuleImageParameterParser; // type="imageType"/>
+  _paramParsers["geometry"] = new ctkModuleGeometryParameterParser; // type="geometryType"/>
+}
+
+// ----------------------------------------------------------------------------
+ctkModuleDescriptionParser::~ctkModuleDescriptionParser()
+{
+  qDeleteAll(_paramParsers.values());
+}
+
+// ----------------------------------------------------------------------------
+void ctkModuleDescriptionParser::validate()
+{
+  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;
+  };
+  _MessageHandler errorHandler;
+
+  QXmlSchema schema;
+  schema.setMessageHandler(&errorHandler);
+  schema.load(QUrl::fromLocalFile(":ctkModuleDescription.xsd"));
+
+  bool res = schema.isValid();
+  if (!res)
+  {
+    QString msg("Invalid Schema at line %1, column %2: %3");
+    msg = msg.arg(errorHandler.line()).arg(errorHandler.column()).arg(errorHandler.statusMessage());
+    throw std::runtime_error(msg.toStdString());
+  }
+
+  QXmlSchemaValidator validator(schema);
+  _device->open(QIODevice::ReadOnly);
+  res = validator.validate(_device);
+  _device->close();
+
+  if (!res)
+  {
+    QString msg("Error validating XML description, at line %1, column %2: %3");
+    throw std::runtime_error(msg.arg(errorHandler.line())
+                             .arg(errorHandler.column())
+                             .arg(errorHandler.statusMessage()).toStdString());
+  }
+
+}
+
+// ----------------------------------------------------------------------------
+void ctkModuleDescriptionParser::doParse()
+{
+  _xmlReader.clear();
+  _xmlReader.setDevice(_device);
+  _device->open(QIODevice::ReadOnly);
+
+  _xmlReader.readNextStartElement();
+  this->handleExecutableElement();
+
+  if (_xmlReader.hasError())
+  {
+    QString msg("Error parsing module description at line %1, column %2: %3");
+    throw std::runtime_error(msg.arg(_xmlReader.lineNumber()).arg(_xmlReader.columnNumber())
+                             .arg(_xmlReader.errorString()).toStdString());
+  }
+}
+
+// ----------------------------------------------------------------------------
+void ctkModuleDescriptionParser::handleExecutableElement()
+{
+  while(_xmlReader.readNextStartElement())
+  {
+    QStringRef name = _xmlReader.name();
+
+    if (name.compare("category", Qt::CaseInsensitive) == 0)
+    {
+      _md->setCategory(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("title", Qt::CaseInsensitive) == 0)
+    {
+      _md->setTitle(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("version", Qt::CaseInsensitive) == 0)
+    {
+      _md->setVersion(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("documentation-url", Qt::CaseInsensitive) == 0)
+    {
+      _md->setDocumentationURL(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("license", Qt::CaseInsensitive) == 0)
+    {
+      _md->setLicense(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("acknowledgements", Qt::CaseInsensitive) == 0)
+    {
+      _md->setAcknowledgements(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("contributor", Qt::CaseInsensitive) == 0)
+    {
+      _md->setContributor(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("description", Qt::CaseInsensitive) == 0)
+    {
+      _md->setDescription(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("parameters", Qt::CaseInsensitive) == 0)
+    {
+      this->handleParametersElement();
+    }
+    else
+    {
+      qCritical() << "Unknown element" << name << "encountered at line"
+                  << _xmlReader.lineNumber() << ", column" << _xmlReader.columnNumber() << ".";
+      _xmlReader.skipCurrentElement();
+    }
+  }
+}
+
+// ----------------------------------------------------------------------------
+void ctkModuleDescriptionParser::handleParametersElement()
+{
+  ctkModuleParameterGroup* group = new ctkModuleParameterGroup();
+
+  group->setAdvanced(parseBooleanAttribute(_xmlReader.attributes().value("advanced")));
+
+  while(_xmlReader.readNextStartElement())
+  {
+    QStringRef name = _xmlReader.name();
+
+    if (name.compare("label", Qt::CaseInsensitive) == 0)
+    {
+      group->setLabel(_xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("description", Qt::CaseInsensitive) == 0)
+    {
+      group->setDescription(_xmlReader.readElementText().trimmed());
+    }
+    else
+    {
+      ctkModuleParameter* parameter = this->handleParameterElement();
+      if (parameter)
+      {
+        group->addParameter(parameter);
+      }
+    }
+  }
+
+  _md->addParameterGroup(group);
+}
+
+// ----------------------------------------------------------------------------
+ctkModuleParameter* ctkModuleDescriptionParser::handleParameterElement()
+{
+  QString paramTag = _xmlReader.name().toString().toLower();
+  ctkModuleParameterParser* paramParser = _paramParsers[paramTag];
+  if (paramParser == 0)
+  {
+    _xmlReader.skipCurrentElement();
+    qCritical() << "No parser for element" << paramTag << "available, line"
+                << _xmlReader.lineNumber() << ", column" << _xmlReader.columnNumber();
+    return 0;
+  }
+  else
+  {
+    ctkModuleParameter* moduleParam = paramParser->parse(_xmlReader);
+    moduleParam->setTag(paramTag);
+    return moduleParam;
+  }
+}
+
+// ----------------------------------------------------------------------------
+ctkModuleDescription* ctkModuleDescription::parse(QIODevice* device)
+{
+  ctkModuleDescription* moduleDescription = new ctkModuleDescription();
+  ctkModuleDescriptionParser parser(device, moduleDescription);
+
+  try
+  {
+    // Verify the xml is correct
+    parser.validate();
+
+    parser.doParse();
+  }
+  catch(...)
+  {
+    delete moduleDescription;
+    throw;
+  }
+
+  return moduleDescription;
+}

File diff suppressed because it is too large
+ 0 - 1852
Libs/ModuleDescription/ctkModuleDescriptionReader.cpp


+ 0 - 54
Libs/ModuleDescription/ctkModuleDescriptionReader.h

@@ -1,54 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-  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 __ctkSlicerModuleReader_h
-#define __ctkSlicerModuleReader_h
-
-// Qt includes
-#include <QRegExp>
-#include <QStack>
-#include <QXmlAttributes>
-#include <QXmlDefaultHandler>
-
-// CTK includes
-#include <ctkModuleDescriptionExport.h>
-
-/**
- * Reader of default module XML description
- * Freely inspired from 
- * Slicer/Libs/SlicerExecutionModel/ModuleDescriptionParser/ModuleDescriptionParser.cxx
- */
-class CTK_MODULDESC_EXPORT ctkModuleDescriptionParser
-{
-
-public:
-
-  void setInput(QIODevice* input);
-
-  void parseDescription();
-
-  ctkModuleDescription* moduleDescription() const;
-
-protected:
-
-  virtual bool validate() const;
-};
-
-#endif

+ 59 - 45
Libs/ModuleDescription/ctkModuleParameter.cpp

@@ -24,29 +24,29 @@ limitations under the License.
 struct ctkModuleParameterPrivate
 {
   ctkModuleParameterPrivate()
-    : Multiple("false"), Aggregate("false")
+    : Hidden(false), Constraints(false), Index(-1), Multiple(false), Aggregate("false")
   {}
 
   QString Tag;
   QString Name;
   QString Description;
   QString Label;
-  QString CPPType;
+  //QString CPPType;
   QString Type;
   QString Reference;
-  QString Hidden;
+  bool Hidden;
   QString ArgType;
-  QString StringToType;
+  //QString StringToType;
   QString Default;
   QString Flag;
   QString LongFlag;
-  QString Constraints;
+  bool Constraints;
   QString Minimum;
   QString Maximum;
   QString Step;
   QString Channel;
-  QString Index;
-  QString Multiple;
+  int Index;
+  int Multiple;
   QString Aggregate;
   QString FileExtensionsAsString;
   QStringList FileExtensions;
@@ -101,19 +101,19 @@ QString ctkModuleParameter::tag() const
   return d->Tag;
 }
 
-//----------------------------------------------------------------------------
-void ctkModuleParameter::setCPPType(const QString& type)
-{
-  Q_D(ctkModuleParameter);
-  d->CPPType = type;
-}
+////----------------------------------------------------------------------------
+//void ctkModuleParameter::setCPPType(const QString& type)
+//{
+//  Q_D(ctkModuleParameter);
+//  d->CPPType = type;
+//}
 
-//----------------------------------------------------------------------------
-QString ctkModuleParameter::cppType() const
-{
-  Q_D(const ctkModuleParameter);
-  return d->CPPType;
-}
+////----------------------------------------------------------------------------
+//QString ctkModuleParameter::cppType() const
+//{
+//  Q_D(const ctkModuleParameter);
+//  return d->CPPType;
+//}
 
 //----------------------------------------------------------------------------
 void ctkModuleParameter::setType(const QString& type)
@@ -144,14 +144,14 @@ QString ctkModuleParameter::reference() const
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleParameter::setHidden(const QString& hidden)
+void ctkModuleParameter::setHidden(bool hidden)
 {
   Q_D(ctkModuleParameter);
   d->Hidden = hidden;
 }
 
 //----------------------------------------------------------------------------
-QString ctkModuleParameter::hidden() const
+bool ctkModuleParameter::hidden() const
 {
   Q_D(const ctkModuleParameter);
   return d->Hidden;
@@ -181,7 +181,7 @@ bool ctkModuleParameter::isFlagParameter() const
 bool ctkModuleParameter::isIndexParameter() const
 {
   Q_D(const ctkModuleParameter);
-  return (d->Index != "");
+  return (d->Index > -1);
 }
 
 //----------------------------------------------------------------------------
@@ -198,19 +198,19 @@ QString ctkModuleParameter::argType() const
   return d->ArgType;
 }
 
-//----------------------------------------------------------------------------
-void ctkModuleParameter::setStringToType(const QString& stringToType)
-{
-  Q_D(ctkModuleParameter);
-  d->StringToType = stringToType;
-}
+////----------------------------------------------------------------------------
+//void ctkModuleParameter::setStringToType(const QString& stringToType)
+//{
+//  Q_D(ctkModuleParameter);
+//  d->StringToType = stringToType;
+//}
 
-//----------------------------------------------------------------------------
-QString ctkModuleParameter::stringToType() const
-{
-  Q_D(const ctkModuleParameter);
-  return d->StringToType;
-}
+////----------------------------------------------------------------------------
+//QString ctkModuleParameter::stringToType() const
+//{
+//  Q_D(const ctkModuleParameter);
+//  return d->StringToType;
+//}
 
 //----------------------------------------------------------------------------
 void ctkModuleParameter::setName(const QString& name)
@@ -299,14 +299,14 @@ QString ctkModuleParameter::label() const
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleParameter::setConstraints(const QString& constraints)
+void ctkModuleParameter::setConstraints(bool constraints)
 {
   Q_D(ctkModuleParameter);
   d->Constraints = constraints;
 }
 
 //----------------------------------------------------------------------------
-QString ctkModuleParameter::constraints() const
+bool ctkModuleParameter::constraints() const
 {
   Q_D(const ctkModuleParameter);
   return d->Constraints;
@@ -383,14 +383,14 @@ QString ctkModuleParameter::channel() const
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleParameter::setIndex(const QString& index)
+void ctkModuleParameter::setIndex(int index)
 {
   Q_D(ctkModuleParameter);
   d->Index = index;
 }
 
 //----------------------------------------------------------------------------
-QString ctkModuleParameter::index() const
+int ctkModuleParameter::index() const
 {
   Q_D(const ctkModuleParameter);
   return d->Index;
@@ -469,14 +469,14 @@ QStringList ctkModuleParameter::deprecatedFlagAliases() const
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleParameter::setMultiple(const QString& multiple)
+void ctkModuleParameter::setMultiple(bool multiple)
 {
   Q_D(ctkModuleParameter);
   d->Multiple = multiple;
 }
 
 //----------------------------------------------------------------------------
-QString ctkModuleParameter::multiple() const
+bool ctkModuleParameter::multiple() const
 {
   Q_D(const ctkModuleParameter);
   return d->Multiple;
@@ -533,6 +533,20 @@ QString ctkModuleParameter::coordinateSystem() const
 }
 
 //----------------------------------------------------------------------------
+void ctkModuleParameter::addElement(const QString &elem)
+{
+  Q_D(ctkModuleParameter);
+  d->Elements.push_back(elem);
+}
+
+//----------------------------------------------------------------------------
+void ctkModuleParameter::setElements(const QStringList& elems)
+{
+  Q_D(ctkModuleParameter);
+  d->Elements = elems;
+}
+
+//----------------------------------------------------------------------------
 QStringList ctkModuleParameter::elements() const
 {
   Q_D(const ctkModuleParameter);
@@ -555,13 +569,13 @@ QTextStream& operator<<(QTextStream& os, const ctkModuleParameter& parameter)
   os << "      " << "Label: " << parameter.label() << '\n';
   os << "      " << "Type: " << parameter.type() << '\n';
   os << "      " << "Reference: " << parameter.reference() << '\n';
-  os << "      " << "Hidden: " << parameter.hidden() << '\n';
-  os << "      " << "CPPType: " << parameter.cppType() << '\n';
+  os << "      " << "Hidden: " << (parameter.hidden() ? "true" : "false") << '\n';
+  //os << "      " << "CPPType: " << parameter.cppType() << '\n';
   os << "      " << "ArgType: " << parameter.argType() << '\n';
-  os << "      " << "StringToType: " << parameter.stringToType() << '\n';
+  //os << "      " << "StringToType: " << parameter.stringToType() << '\n';
   os << "      " << "Default: " << parameter.defaultValue() << '\n';
   os << "      " << "Elements: " << parameter.elements().join(", ") << '\n';
-  os << "      " << "Constraints: " << parameter.constraints() << '\n';
+  os << "      " << "Constraints: " << (parameter.constraints() ? "true" : "false") << '\n';
   os << "      " << "Minimum: " << parameter.minimum() << '\n';
   os << "      " << "Maximum: " << parameter.maximum() << '\n';
   os << "      " << "Step: " << parameter.step() << '\n';
@@ -573,7 +587,7 @@ QTextStream& operator<<(QTextStream& os, const ctkModuleParameter& parameter)
   os << "      " << "Deprecated LongFlag aliases: " << parameter.deprecatedLongFlagAliasesAsString() << '\n';
   os << "      " << "Channel: " << parameter.channel() << '\n';
   os << "      " << "Index: " << parameter.index() << '\n';
-  os << "      " << "Multiple: " << parameter.multiple() << '\n';
+  os << "      " << "Multiple: " << (parameter.multiple() ? "true" : "false") << '\n';
   os << "      " << "Aggregate: " << parameter.aggregate() << '\n';
   os << "      " << "FileExtensions: " << parameter.fileExtensionsAsString() << '\n';
   os << "      " << "CoordinateSystem: " << parameter.coordinateSystem() << '\n';

+ 14 - 13
Libs/ModuleDescription/ctkModuleParameter.h

@@ -48,8 +48,8 @@ public:
   void setTag(const QString& tag);
   QString tag() const;
 
-  void setCPPType(const QString& type);
-  QString cppType() const;
+//  void setCPPType(const QString& type);
+//  QString cppType() const;
 
   void setType(const QString& type);
   QString type() const;
@@ -57,8 +57,8 @@ public:
   void setReference(const QString& ref);
   QString reference() const;
 
-  void setHidden(const QString& hidden);
-  QString hidden() const;
+  void setHidden(bool hidden);
+  bool hidden() const;
 
   // Simple return types are parameters on output channel with no
   // flags and without a specified index
@@ -73,8 +73,8 @@ public:
   void setArgType(const QString& argType);
   QString argType() const;
 
-  void setStringToType(const QString& stringToType);
-  QString stringToType() const;
+  //void setStringToType(const QString& stringToType);
+  //QString stringToType() const;
 
   void setName(const QString& name);
   QString name() const;
@@ -93,8 +93,8 @@ public:
   void setLabel(const QString& label);
   QString label() const;
 
-  void setConstraints(const QString& constraints);
-  QString constraints() const;
+  void setConstraints(bool constraints);
+  bool constraints() const;
 
   void setMaximum(const QString& maximum);
   QString maximum() const;
@@ -111,8 +111,8 @@ public:
   void setChannel(const QString& channel);
   QString channel() const;
 
-  void setIndex(const QString& index);
-  QString index() const;
+  void setIndex(int index);
+  int index() const;
 
   void setDefaultValue(const QString& def);
   QString defaultValue() const;
@@ -128,8 +128,8 @@ public:
   QString deprecatedFlagAliasesAsString() const;
   QStringList deprecatedFlagAliases() const;
 
-  void setMultiple(const QString& multiple);
-  QString multiple() const;
+  void setMultiple(bool multiple);
+  bool multiple() const;
 
   void setAggregate(const QString& aggregate);
   QString aggregate() const;
@@ -141,8 +141,9 @@ public:
   void setCoordinateSystem(const QString& coordinateSystem);
   QString coordinateSystem() const;
 
+  void addElement(const QString& elem);
+  void setElements(const QStringList& elems);
   QStringList elements() const;
-  //QStringList& elements();
 
 private:
 

+ 4 - 4
Libs/ModuleDescription/ctkModuleParameterGroup.cpp

@@ -29,7 +29,7 @@ struct ctkModuleParameterGroupPrivate
 
   QString Label;
   QString Description;
-  QString Advanced;
+  bool Advanced;
   QList<ctkModuleParameter*> Parameters;
 };
 
@@ -74,14 +74,14 @@ QString ctkModuleParameterGroup::description() const
 }
 
 //----------------------------------------------------------------------------
-void ctkModuleParameterGroup::setAdvanced(const QString& advanced)
+void ctkModuleParameterGroup::setAdvanced(bool advanced)
 {
   Q_D(ctkModuleParameterGroup);
   d->Advanced = advanced;
 }
 
 //----------------------------------------------------------------------------
-QString ctkModuleParameterGroup::advanced() const
+bool ctkModuleParameterGroup::advanced() const
 {
   Q_D(const ctkModuleParameterGroup);
   return d->Advanced;
@@ -162,7 +162,7 @@ bool ctkModuleParameterGroup::writeParameterFile(QTextStream& in, bool withHandl
 //----------------------------------------------------------------------------
 QTextStream & operator<<(QTextStream &os, const ctkModuleParameterGroup &group)
 { 
-  os << "  Advanced: " << group.advanced() << '\n';
+  os << "  Advanced: " << (group.advanced() ? "true" : "false") << '\n';
   os << "  Label: " << group.label() << '\n';
   os << "  Description: " << group.description() << '\n';
   os << "  Parameters: " << '\n';

+ 2 - 2
Libs/ModuleDescription/ctkModuleParameterGroup.h

@@ -44,8 +44,8 @@ public:
   void setDescription(const QString& description);
   QString description() const;
 
-  void setAdvanced(const QString& advanced);
-  QString advanced() const;
+  void setAdvanced(bool advanced);
+  bool advanced() const;
 
   void addParameter(ctkModuleParameter* parameter);
   QList<ctkModuleParameter*> parameters() const;

+ 0 - 50
Libs/ModuleDescription/ctkModuleParameterGroupValue.cpp

@@ -1,50 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-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 "ctkModuleParameterGroupValue.h"
-
-//----------------------------------------------------------------------------
-ctkModuleParameterGroupValue::~ctkModuleParameterGroupValue()
-{
-  foreach(ctkModuleParameterValue* value, this->Values)
-    {
-    delete value;
-    }
-  this->Values.clear();
-}
-
-//----------------------------------------------------------------------------
-const QVector<ctkModuleParameterValue*>& ctkModuleParameterGroupValue::values() const
-{
-	return this->Values;
-}
-
-//----------------------------------------------------------------------------
-ctkModuleParameterValue* ctkModuleParameterGroupValue::value( const QString& parameterName )const
-{
-  foreach(ctkModuleParameterValue* value, this->Values)
-    {
-    if (value->parameter()["Name"] == parameterName)
-      {
-      return value;
-      }
-    }
-  return 0;
-}

+ 0 - 48
Libs/ModuleDescription/ctkModuleParameterGroupValue.h

@@ -1,48 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-  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 __ctkModuleParameterGroupValue_h
-#define __ctkModuleParameterGroupValue_h
-
-#include "ctkModuleParameterValue.h"
-
-#include <QVector>
-
-/** 
-*  \brief Group of parameters value
-*
-*/
-class CTK_MODULDESC_EXPORT ctkModuleParameterGroupValue
-{
-public:
-  virtual ~ctkModuleParameterGroupValue();
-  
-  /// Takes ownership of parameter
-  const QVector<ctkModuleParameterValue*>& values() const;
-
-  /// Returns 0 if not found.
-  ctkModuleParameterValue* value(const QString& parameterName)const;
-  
-private:
-  ///
-  QVector<ctkModuleParameterValue*> Values;
-};
-
-#endif

+ 300 - 0
Libs/ModuleDescription/ctkModuleParameterParsers_p.h

@@ -0,0 +1,300 @@
+/*=============================================================================
+  
+  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 CTKMODULEPARAMETERPARSERS_P_H
+#define CTKMODULEPARAMETERPARSERS_P_H
+
+#include <QXmlStreamReader>
+
+#include "ctkModuleParameter.h"
+
+namespace {
+
+static bool parseBooleanAttribute(const QStringRef& attrValue)
+{
+  if (attrValue.compare("true", Qt::CaseInsensitive) == 0 ||
+      attrValue.compare("1") == 0)
+  {
+    return true;
+  }
+  return false;
+}
+
+}
+
+struct ctkModuleParameterParser
+{
+public:
+
+  virtual ~ctkModuleParameterParser() {}
+
+  virtual ctkModuleParameter* parse(QXmlStreamReader &xmlReader)
+  {
+    ctkModuleParameter* moduleParam = this->createModuleParameter();
+
+    this->handleAttributes(moduleParam, xmlReader);
+
+    while(xmlReader.readNextStartElement())
+    {
+      this->handleSubElement(moduleParam, xmlReader);
+    }
+
+    return moduleParam;
+  }
+
+protected:
+
+  virtual ctkModuleParameter* createModuleParameter()
+  {
+    return new ctkModuleParameter;
+  }
+
+  virtual void handleAttributes(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    // handle common attributes
+    moduleParam->setHidden(parseBooleanAttribute(xmlReader.attributes().value("hidden")));
+  }
+
+  virtual bool handleSubElement(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    // handle common sub-elements
+
+    QStringRef name = xmlReader.name();
+
+    if (name.compare("name", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->setName(xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("description", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->setDescription(xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("label", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->setLabel(xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("default", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->setDefaultValue(xmlReader.readElementText().trimmed());
+    }
+    else if (name.compare("flag", Qt::CaseInsensitive) == 0)
+    {
+      QString flag = xmlReader.readElementText().trimmed();
+      if (flag.startsWith('-')) flag = flag.remove(0, 1);
+      moduleParam->setFlag(flag);
+      moduleParam->setFlagAliasesAsString(xmlReader.attributes().value("alias").toString());
+      moduleParam->setDeprecatedFlagAliasesAsString(xmlReader.attributes().value("deprecatedalias").toString());
+    }
+    else if (name.compare("longflag", Qt::CaseInsensitive) == 0)
+    {
+      QString longFlag = xmlReader.readElementText().trimmed();
+      if (longFlag.startsWith('-')) longFlag = longFlag.remove(0, 1);
+      moduleParam->setLongFlag(longFlag);
+      moduleParam->setLongFlagAliasesAsString(xmlReader.attributes().value("alias").toString());
+      moduleParam->setDeprecatedLongFlagAliasesAsString(xmlReader.attributes().value("deprecatedalias").toString());
+    }
+    else if (name.compare("index", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->setIndex(xmlReader.readElementText().toInt());
+    }
+    else
+    {
+      xmlReader.skipCurrentElement();
+      return false;
+    }
+
+    return true;
+  }
+
+  bool handleConstraintsElement(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    moduleParam->setConstraints(true);
+    while(xmlReader.readNextStartElement())
+    {
+      QStringRef constraintElem = xmlReader.name();
+      if (constraintElem.compare("minimum", Qt::CaseInsensitive) == 0)
+      {
+        moduleParam->setMinimum(xmlReader.readElementText().trimmed());
+      }
+      else if (constraintElem.compare("maximum", Qt::CaseInsensitive) == 0)
+      {
+        moduleParam->setMaximum(xmlReader.readElementText().trimmed());
+      }
+      else if (constraintElem.compare("step", Qt::CaseInsensitive) == 0)
+      {
+        moduleParam->setStep(xmlReader.readElementText().trimmed());
+      }
+      else
+      {
+        xmlReader.skipCurrentElement();
+        return false;
+      }
+    }
+    return true;
+  }
+};
+
+class ctkModuleMultipleParameterParser : public ctkModuleParameterParser
+{
+
+protected:
+
+  void handleAttributes(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    ctkModuleParameterParser::handleAttributes(moduleParam, xmlReader);
+    moduleParam->setHidden(parseBooleanAttribute(xmlReader.attributes().value("multiple")));
+  }
+};
+
+class ctkModuleScalarVectorParameterParser : public ctkModuleParameterParser
+{
+
+protected:
+
+  bool handleSubElement(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    QStringRef name = xmlReader.name();
+
+    if (name.compare("constraints", Qt::CaseInsensitive) == 0)
+    {
+      return handleConstraintsElement(moduleParam, xmlReader);
+    }
+    else
+    {
+      return ctkModuleParameterParser::handleSubElement(moduleParam, xmlReader);
+    }
+  }
+};
+
+class ctkModuleScalarParameterParser : public ctkModuleMultipleParameterParser
+{
+
+protected:
+
+  bool handleSubElement(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    QStringRef name = xmlReader.name();
+
+    if (name.compare("constraints", Qt::CaseInsensitive) == 0)
+    {
+      return handleConstraintsElement(moduleParam, xmlReader);
+    }
+    else
+    {
+      return ctkModuleMultipleParameterParser::handleSubElement(moduleParam, xmlReader);
+    }
+  }
+};
+
+class ctkModuleEnumerationParameterParser : public ctkModuleParameterParser
+{
+
+protected:
+
+  bool handleSubElement(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    QStringRef name = xmlReader.name();
+
+    if (name.compare("element", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->addElement(xmlReader.readElementText().trimmed());
+      return true;
+    }
+    else
+    {
+      return ctkModuleParameterParser::handleSubElement(moduleParam, xmlReader);
+    }
+  }
+};
+
+class ctkModulePointParameterParser : public ctkModuleMultipleParameterParser
+{
+
+protected:
+
+  void handleAttributes(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    ctkModuleMultipleParameterParser::handleAttributes(moduleParam, xmlReader);
+    moduleParam->setCoordinateSystem(xmlReader.attributes().value("coordinateSystem").toString().trimmed());
+  }
+};
+
+class ctkModuleChannelParameterParser : public ctkModuleMultipleParameterParser
+{
+
+protected:
+
+  bool handleSubElement(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    QStringRef name = xmlReader.name();
+
+    if (name.compare("channel", Qt::CaseInsensitive) == 0)
+    {
+      moduleParam->setChannel(xmlReader.readElementText().trimmed());
+      return true;
+    }
+    else
+    {
+      return ctkModuleMultipleParameterParser::handleSubElement(moduleParam, xmlReader);
+    }
+  }
+};
+
+class ctkModuleFileParameterParser : public ctkModuleChannelParameterParser
+{
+
+protected:
+
+  void handleAttributes(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    ctkModuleChannelParameterParser::handleAttributes(moduleParam, xmlReader);
+    moduleParam->setFileExtensionsAsString(xmlReader.attributes().value("fileExtensions").toString().trimmed());
+  }
+};
+
+class ctkModuleGeometryParameterParser : public ctkModuleMultipleParameterParser
+{
+
+protected:
+
+  void handleAttributes(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    ctkModuleMultipleParameterParser::handleAttributes(moduleParam, xmlReader);
+    moduleParam->setFileExtensionsAsString(xmlReader.attributes().value("fileExtensions").toString().trimmed());
+    moduleParam->setType(xmlReader.attributes().value("type").toString().trimmed());
+  }
+};
+
+class ctkModuleImageParameterParser : public ctkModuleChannelParameterParser
+{
+
+protected:
+
+  void handleAttributes(ctkModuleParameter* moduleParam, QXmlStreamReader& xmlReader)
+  {
+    ctkModuleChannelParameterParser::handleAttributes(moduleParam, xmlReader);
+    moduleParam->setFileExtensionsAsString(xmlReader.attributes().value("fileExtensions").toString().trimmed());
+    moduleParam->setType(xmlReader.attributes().value("type").toString().trimmed());
+  }
+};
+
+
+#endif // CTKMODULEPARAMETERPARSERS_P_H

+ 0 - 73
Libs/ModuleDescription/ctkModuleParameterValue.cpp

@@ -1,73 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-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 "ctkModuleParameterValue.h"
-
-#include <QDebug>
-
-//----------------------------------------------------------------------------
-ctkModuleParameterValue::ctkModuleParameterValue( const ctkModuleParameter& param)
-: Parameter( param )
-{
-}
-
-//----------------------------------------------------------------------------
-void ctkModuleParameterValue::setValue( const QVariant& val)
-{
-  value = val;
-}
-
-//----------------------------------------------------------------------------
-const QVariant& ctkModuleParameterValue::getValue() const
-{
-  return value;
-}
-
-//----------------------------------------------------------------------------
-const ctkModuleParameter& ctkModuleParameterValue::parameter() const
-{
-  return Parameter;
-}
-
-void ctkModuleParameterValue::setDefaultValue()
-{
-  QVariant::Type type = value.type();
-  if (type == QVariant::Bool)
-    {
-      value = (Parameter["Default"].compare("true", Qt::CaseInsensitive) == 0);
-    }
-  else if (type == QVariant::Int)
-    {
-      value = Parameter["Default"].toInt();
-    }
-  else if (type == QVariant::Double)
-    {
-      value = Parameter["Default"].toDouble();
-    }
-  else if (type == QVariant::String)
-    {
-      value = Parameter["Default"];
-    }
-  else
-    {
-    qDebug() << "Unknown widget value type:" << type;
-    }
-
-}

+ 0 - 56
Libs/ModuleDescription/ctkModuleParameterValue.h

@@ -1,56 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-  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 __ctkModuleParameterValue_h
-#define __ctkModuleParameterValue_h
-
-#include "ctkModuleDescriptionExport.h"
-#include "ctkModuleParameter.h"
-
-#include <QVariant>
-
-/** 
- *  \brief Single parameter value to a module, like a threshold of a filter.
- *
- * ctkModuleParameterValue describes a single parameter value to a
- * module. Information on the parameter type, name, flag, label,
- * description, channel, index, default, and constraints can be
- * stored.
- *
- */
-class CTK_MODULDESC_EXPORT ctkModuleParameterValue
-{
-public:
-  // constructor
-  ctkModuleParameterValue( const ctkModuleParameter& param );
-  // set the value
-  void setValue( const QVariant& value );
-  // set the value to the defaut one
-  void setDefaultValue();
-  // get the value
-  const QVariant& getValue() const;
-  // get the associated ctkModuleParameter
-  const ctkModuleParameter& parameter() const;
-private:
-  QVariant value;
-  const ctkModuleParameter& Parameter;
-};
-
-#endif

+ 0 - 63
Libs/ModuleDescription/ctkModuleValues.cpp

@@ -1,63 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-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 "ctkModuleValues.h"
-#include "ctkModuleParameterGroup.h"
-
-#include <iostream>
-
-#include <QFile>
-#include <QTextStream>
-
-//----------------------------------------------------------------------------
-const QVector<ctkModuleParameterGroupValue*>& ctkModuleValues::valueGroups() const
-{
-  return this->ValueGroups;
-}
-
-//----------------------------------------------------------------------------
-ctkModuleParameterGroupValue* ctkModuleValues::valueGroup(const QString& parameterName)const
-{
-  // iterate over each parameter group
-  foreach( ctkModuleParameterGroupValue* group, this->ValueGroups)
-    {
-    ctkModuleParameterValue* value = group->value(parameterName);
-    if (value)
-      {
-      return group;
-      }    
-    }
-  return 0;
-}
-
-//----------------------------------------------------------------------------
-ctkModuleParameterValue* ctkModuleValues::value(const QString& parameterName)const
-{
-  // iterate over each parameter group
-  foreach( const ctkModuleParameterGroupValue* group, this->ValueGroups)
-    {
-    ctkModuleParameterValue* value = group->value(parameterName);
-    if (value)
-      {
-      return value;
-      }    
-    }
-  return 0;
-}

+ 0 - 67
Libs/ModuleDescription/ctkModuleValues.h

@@ -1,67 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
-
-  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 __ctkModuleValues_h
-#define __ctkModuleValues_h
-
-// Qt includes
-#include <QVector>
-
-// Module parameter
-#include "ctkModuleParameterGroupValue.h"
-
-/**
-* Description of the parameters values of a module
-*
-* The parameters can be used for automated GUI generation or execution
-* of the module.
-*
-* For example:
-* - Target: This is the entry point for a shared object module and the full 
-* command (with path) for an executable.
-* - Type: Unknown, SharedObjectModule, CommandLineModule
-* - AlternativeTarget: This is the entry
-* point for a shared object module and the full command (with path)
-* for an executable. The alternative target is used for a second version
-* of a module (whose type differs from the primary target,
-* executable verses shared object).
-* - Location: This is path to the file (shared
-* object or executable) for the module
-* - AlternativeLocation: This is path to the
-* file (shared object or executable) for a second version of the
-* module (usually a different type from the primary).
-*/
-class CTK_MODULDESC_EXPORT ctkModuleValues
-{
-public:
-
-  const QVector<ctkModuleParameterGroupValue*>& valueGroups() const;
-  
-  // Return the group that contain the parameter value associated to the name
-  ctkModuleParameterGroupValue* valueGroup(const QString& parameterName) const;
-  // Return the first parameter value corresponding to the name from any group
-  ctkModuleParameterValue* value(const QString& parameterName) const;
-  
-private:
-  /// Groups of parameters
-  QVector<ctkModuleParameterGroupValue*> ValueGroups;
-};
-
-#endif

+ 0 - 158
Libs/ModuleDescription/ctkSlicerModuleStringConverter.cpp

@@ -1,158 +0,0 @@
-/*=============================================================================
-
-Library: CTK
-
-Copyright (c) 2010 CISTIB - Universtitat Pompeu Fabra
-
-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 "ctkSlicerModuleStringConverter.h"
-#include <QVector>
-
-
-void ctkSlicerModuleStringConverter::update()
-{
-  SetTarget( );
-
-  SetAllParameters( );
-}
-
-const QVariant ctkSlicerModuleStringConverter::GetOutput()
-{
-  return this->CommandLineAsString;
-}
-
-void ctkSlicerModuleStringConverter::SetAllParameters()
-{
-  foreach( const ctkModuleParameterGroup* itGroup, this->ModuleDescription.parameterGroups())
-  {
-    foreach( const ctkModuleParameter* itParam, itGroup->parameters())
-    {
-      SetParameterValue( *itParam );
-    }
-  }
-}
-
-void ctkSlicerModuleStringConverter::SetParameterValue( const ctkModuleParameter &param )
-{
-  QString prefix;
-  QString flag;
-  bool hasFlag = false;
-
-  if ( param["LongFlag"] != "")
-  {
-    prefix = "--";
-    flag = param["LongFlag"];
-    hasFlag = true;
-  }
-  else if (param["Flag"] != "")
-  {
-    prefix = "-";
-    flag = param["Flag"];
-    hasFlag = true;
-  }
-
-
-  if (hasFlag)
-  {
-    if (   param["Tag"] != "boolean"
-      && param["Tag"] != "file" 
-      && param["Tag"] != "directory"
-      && param["Tag"] != "string"
-      && param["Tag"] != "integer-vector"
-      && param["Tag"] != "float-vector"
-      && param["Tag"] != "double-vector"
-      && param["Tag"] != "string-vector"
-      && param["Tag"] != "image"
-      && param["Tag"] != "point"
-      && param["Tag"] != "region"
-      && param["Tag"] != "transform"
-      && param["Tag"] != "geometry"
-      && param["Tag"] != "table"
-      && param["Tag"] != "measurement")
-    {
-      // simple parameter, write flag and value
-      this->CommandLineAsString.push_back(prefix + flag);
-      this->CommandLineAsString.push_back(param["Default"]);
-    }
-    else if (param["Tag"] == "boolean" && param["Default"] == "true")
-    {
-      this->CommandLineAsString.push_back(prefix + flag);
-    }
-    else if (param["Tag"] == "file" 
-      || param["Tag"] == "directory"
-      || param["Tag"] == "string"
-      || param["Tag"] == "integer-vector"
-      || param["Tag"] == "float-vector"
-      || param["Tag"] == "double-vector"
-      || param["Tag"] == "string-vector")
-    {
-      // Only write out the flag if value is not empty
-      if ( param["Default"] != "")
-      {
-        this->CommandLineAsString.push_back(prefix + flag);
-        this->CommandLineAsString.push_back( param["Default"] );
-      }
-    }
-    // data passed as parameter
-    else if ( param["Tag"] == "image" 
-      || param["Tag"] == "geometry"
-      || param["Tag"] == "transform" 
-      || param["Tag"] == "table" 
-      || param["Tag"] == "measurement" )
-    {
-      if ( param["Default"] != "")
-      {
-        this->CommandLineAsString.push_back(prefix + flag);
-        this->CommandLineAsString.push_back(param["Default"]);
-      }
-    }
-    else if ( param["Tag"] == "region" )
-    {
-      this->CommandLineAsString.push_back(prefix + flag);
-      this->CommandLineAsString.push_back( param["Default"] );
-    }
-    else if ( param["Tag"] == "point" )
-    {
-      QStringList points = param["Default"].split( ";");
-      foreach ( const QString &it, points )
-      {
-        this->CommandLineAsString.push_back(prefix + flag);
-        this->CommandLineAsString.push_back( it );
-      }
-    }
-
-  }
-
-  // If index is not empty -> It's a command line argument arg0, arg1, ... without flag prefix
-  if ( param["Index"] != "")
-  {
-    this->CommandLineAsString.push_back( param["Default"] );
-  }
-}
-
-void ctkSlicerModuleStringConverter::SetTarget()
-{
-  this->CommandLineAsString.clear();
-
-  if (!this->ModuleDescription["Location"].isEmpty() && 
-    this->ModuleDescription["Location"] != this->ModuleDescription["Target"])
-  {
-    this->CommandLineAsString.push_back(this->ModuleDescription["Location"]);
-  }
-  this->CommandLineAsString.push_back( this->ModuleDescription["Target"] );
-}
-
-

+ 0 - 65
Libs/ModuleDescription/ctkSlicerModuleStringConverter.h

@@ -1,65 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) 2010 CISTIB - Universtitat Pompeu Fabra
-
-  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 __ctkSlicerModuleStringConverter_h
-#define __ctkSlicerModuleStringConverter_h
-
-#include <string>
-
-#include "ctkModuleDescriptionConverter.h"
-
-class ModuleDescription;
-class ModuleParameterGroup;
-
-
-/**
- * Convert Slicer Module description to command line string QStringList
- *
- */
-class ctkSlicerModuleStringConverter : public ctkModuleDescriptionConverter
-{
-  Q_OBJECT
-public:
-  ctkSlicerModuleStringConverter() {};
-  ~ctkSlicerModuleStringConverter() {};
-
-  ///
-  void update( );
-
-  ///
-  virtual const QVariant GetOutput( );
-
-protected:
-
-  //!
-  void SetAllParameters();
-
-  //!
-  void SetParameterValue( const ctkModuleParameter &param );
-
-  ///
-  void SetTarget();
-
-protected:
-
-  QStringList CommandLineAsString;
-};
-
-#endif