Преглед изворни кода

The "channel" element is now optionally allowed for all parameters.

Previously, it was not possible to set the channel to "output" for
simple parameter types. Now, channel is optional for all types and
defaults to "input" (when parsing the XML description). Trying to do
a "restriction" on the minOccurs attribute of the channel element in
derived schema types turned out to be too complicated.
Sascha Zelzer пре 12 година
родитељ
комит
5ea71602fa

+ 14 - 27
Libs/CommandLineModules/Core/Resources/ctkCmdLineModule.xsd

@@ -58,7 +58,7 @@
         <xsd:element name="float-enumeration" type="enumerationType"/>
         <xsd:element name="double-enumeration" type="enumerationType"/>
         <xsd:element name="file" type="fileType"/>
-        <xsd:element name="directory" type="channelType"/>
+        <xsd:element name="directory" type="multipleType"/>
         <xsd:element name="image" type="imageType"/>
         <xsd:element name="geometry" type="geometryType"/>
         <!--
@@ -104,7 +104,17 @@
       <xsd:element name="description" type="xsd:string"/>
       <xsd:element name="label" type="xsd:string"/>
       <xsd:element minOccurs="0" name="default" type="xsd:string"/>
-
+      
+      <!-- the 'channel' element is optional -->
+      <xsd:element minOccurs="0" maxOccurs="1" name="channel">
+        <xsd:simpleType>
+          <xsd:restriction base="xsd:string">
+            <xsd:enumeration value="input"/>
+            <xsd:enumeration value="output"/>
+          </xsd:restriction>
+        </xsd:simpleType>
+      </xsd:element>
+      
     </xsd:sequence>
     
     <!-- parameter attributes -->
@@ -216,29 +226,6 @@
       </xsd:extension>
     </xsd:complexContent>
   </xsd:complexType>
-
-  <!--
-  ===================================================================
-    CHANNEL PARAMETER 
-      Extends multipleType for parameters with input/output semantics (directory, file, image).
-  ===================================================================
-  -->
-  <xsd:complexType name="channelType">
-    <xsd:complexContent>
-      <xsd:extension base="multipleType">
-        <xsd:sequence>
-          <xsd:element maxOccurs="1" name="channel">
-            <xsd:simpleType>
-              <xsd:restriction base="xsd:string">
-                <xsd:enumeration value="input"/>
-                <xsd:enumeration value="output"/>
-              </xsd:restriction>
-            </xsd:simpleType>
-          </xsd:element>
-        </xsd:sequence>
-      </xsd:extension>
-    </xsd:complexContent>
-  </xsd:complexType>
   
   <!--
   ===================================================================
@@ -249,7 +236,7 @@
   -->
   <xsd:complexType name="fileType">
     <xsd:complexContent>
-      <xsd:extension base="channelType">
+      <xsd:extension base="multipleType">
         <xsd:attribute name="fileExtensions" type="xsd:string"/>
       </xsd:extension>
     </xsd:complexContent>
@@ -282,7 +269,7 @@
   
   <!--
   ===================================================================
-                                                                *****  UTILITY TYPES  *****
+                     *****  UTILITY TYPES  *****
   ===================================================================
   -->
   

+ 1 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleParameter.cpp

@@ -27,7 +27,7 @@ limitations under the License.
 
 //----------------------------------------------------------------------------
 ctkCmdLineModuleParameterPrivate::ctkCmdLineModuleParameterPrivate()
-  : Hidden(false), Constraints(false), Index(-1), Multiple(false)
+  : Hidden(false), Constraints(false), Channel("input"), Index(-1), Multiple(false)
 {}
 
 //----------------------------------------------------------------------------

+ 8 - 25
Libs/CommandLineModules/Core/ctkCmdLineModuleParameterParsers_p.h

@@ -115,6 +115,10 @@ protected:
     {
       moduleParamPrivate->Index = xmlReader.readElementText().toInt();
     }
+    else if (name.compare("channel", Qt::CaseInsensitive) == 0)
+    {
+      moduleParamPrivate->Channel = xmlReader.readElementText().trimmed();
+    }
     else
     {
       xmlReader.skipCurrentElement();
@@ -237,35 +241,14 @@ protected:
   }
 };
 
-class ctkCmdLineModuleChannelParameterParser : public ctkCmdLineModuleMultipleParameterParser
-{
-
-protected:
-
-  bool handleSubElement(ctkCmdLineModuleParameterPrivate* moduleParamPrivate, QXmlStreamReader& xmlReader)
-  {
-    QStringRef name = xmlReader.name();
-
-    if (name.compare("channel", Qt::CaseInsensitive) == 0)
-    {
-      moduleParamPrivate->Channel = xmlReader.readElementText().trimmed();
-      return true;
-    }
-    else
-    {
-      return ctkCmdLineModuleMultipleParameterParser::handleSubElement(moduleParamPrivate, xmlReader);
-    }
-  }
-};
-
-class ctkCmdLineModuleFileParameterParser : public ctkCmdLineModuleChannelParameterParser
+class ctkCmdLineModuleFileParameterParser : public ctkCmdLineModuleMultipleParameterParser
 {
 
 protected:
 
   void handleAttributes(ctkCmdLineModuleParameterPrivate* moduleParamPrivate, QXmlStreamReader& xmlReader)
   {
-    ctkCmdLineModuleChannelParameterParser::handleAttributes(moduleParamPrivate, xmlReader);
+    ctkCmdLineModuleMultipleParameterParser::handleAttributes(moduleParamPrivate, xmlReader);
     moduleParamPrivate->FileExtensionsAsString =xmlReader.attributes().value("fileExtensions").toString().trimmed();
   }
 };
@@ -283,14 +266,14 @@ protected:
   }
 };
 
-class ctkCmdLineModuleImageParameterParser : public ctkCmdLineModuleChannelParameterParser
+class ctkCmdLineModuleImageParameterParser : public ctkCmdLineModuleMultipleParameterParser
 {
 
 protected:
 
   void handleAttributes(ctkCmdLineModuleParameterPrivate* moduleParamPrivate, QXmlStreamReader& xmlReader)
   {
-    ctkCmdLineModuleChannelParameterParser::handleAttributes(moduleParamPrivate, xmlReader);
+    ctkCmdLineModuleMultipleParameterParser::handleAttributes(moduleParamPrivate, xmlReader);
     moduleParamPrivate->setFileExtensionsAsString(xmlReader.attributes().value("fileExtensions").toString().trimmed());
     moduleParamPrivate->Type = xmlReader.attributes().value("type").toString().trimmed();
   }

+ 1 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlParser.cpp

@@ -67,7 +67,7 @@ ctkCmdLineModuleXmlParser::ctkCmdLineModuleXmlParser(QIODevice* device,
   _paramParsers["float-enumeration"] = new ctkCmdLineModuleEnumerationParameterParser; // type="enumerationType"/>
   _paramParsers["double-enumeration"] = new ctkCmdLineModuleEnumerationParameterParser; // type="enumerationType"/>
   _paramParsers["file"] = new ctkCmdLineModuleFileParameterParser; // type="fileType"/>
-  _paramParsers["directory"] = new ctkCmdLineModuleChannelParameterParser; // type="channelType"/>
+  _paramParsers["directory"] = new ctkCmdLineModuleMultipleParameterParser; // type="multipleType"/>
   _paramParsers["image"] = new ctkCmdLineModuleImageParameterParser; // type="imageType"/>
   _paramParsers["geometry"] = new ctkCmdLineModuleGeometryParameterParser; // type="geometryType"/>
 }

+ 6 - 0
Libs/CommandLineModules/Frontend/QtGui/Resources/ctkCmdLineModuleXmlToQtUi.xsl

@@ -142,6 +142,12 @@
         <bool>false</bool>
       </property>
     </xsl:if>
+    <!-- disable simple return parameter -->
+    <xsl:if test="index/text()='1000' and channel/text()='output' and $disableReturnParameter='true'">
+      <property name="enabled">
+        <bool>false</bool>
+      </property>
+    </xsl:if>
     <property name="parameter:valueProperty"> <!-- property name containing current value -->
       <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name())"/></string>
     </property>