Quellcode durchsuchen

Merge branch '487-standardise-fileExtension'

* 487-standardise-fileExtension:
  Tidy up widget tour, image type not necessary here, asterisks not valid as examples.
  Asterisk no longer allowed in file extension
  Define fileExtensions as attribute with restriction
  Make GUI label more verbose
  Add fileExtensionsType to xsd for CLI
  Cope with leading asterisk, and missing dot
  Add asterisk when generating nameFilters
  Give labels more useful explanation
  Add image type, fix formatting
  Remove incorrect examples, except ctkCmdLineModuleTour which is deliberate
  Provide all file/image/geometry types in ctkCmdLineModuleTour with correct/incorrect file extensions
Sascha Zelzer vor 11 Jahren
Ursprung
Commit
52f671742e

+ 24 - 10
Libs/CommandLineModules/Core/Resources/ctkCmdLineModule.xsd

@@ -389,6 +389,28 @@
   
   <!--
   ===================================================================
+    #487: Definition of 'fileExtensions'.
+
+    Before issue #487: 'A comma separated list of allowed file extensions'.
+
+    Slicer uses extensions with dots, but no leading asterisk.
+    i.e. ".nii,.nrrd,.mha"
+
+    In CTK, the leading dot is optional. Any preceding asterisk is forbidden.
+
+  ===================================================================
+  -->
+
+  <xsd:attribute name="fileExtensions">
+    <xsd:simpleType>
+      <xsd:restriction base="xsd:string">
+        <xsd:pattern value="(?:(?:\.[^,\s]|[^,\.\s\*])[^,\s]*)(?:,\s*(?:\.[^,\s]|[^,\.\s\*])[^,\s]*)*"/>
+      </xsd:restriction>
+    </xsd:simpleType>
+  </xsd:attribute>
+
+  <!--
+  ===================================================================
     GEOMETRY PARAMETER 
       Extends multipleType for geometry parameters (geometry).
   ===================================================================
@@ -396,11 +418,7 @@
   <xsd:complexType name="geometryType">
     <xsd:complexContent>
       <xsd:extension base="multipleType">
-        <xsd:attribute name="fileExtensions" type="xsd:string">
-          <xsd:annotation>
-            <xsd:documentation>A comma separated list of allowed file extensions.</xsd:documentation>
-          </xsd:annotation>
-        </xsd:attribute>
+        <xsd:attribute ref="fileExtensions"/>
         <xsd:attribute name="type">
           <xsd:annotation>
             <xsd:documentation>Optionally specifies the allowed geometry type.</xsd:documentation>
@@ -426,11 +444,7 @@
   <xsd:complexType name="fileType">
     <xsd:complexContent>
       <xsd:extension base="multipleType">
-        <xsd:attribute name="fileExtensions" type="xsd:string">
-          <xsd:annotation>
-            <xsd:documentation>A comma separated list of allowed file extensions (e.g. "nrrd,mhd").</xsd:documentation>
-          </xsd:annotation>
-        </xsd:attribute>
+      <xsd:attribute ref="fileExtensions"/>
       </xsd:extension>
     </xsd:complexContent>
   </xsd:complexType>

+ 7 - 1
Libs/CommandLineModules/Frontend/QtGui/Resources/ctkCmdLineModuleXmlToQtUi.xsl

@@ -246,7 +246,13 @@
     <property name="nameFilters">
       <stringlist>
       <xsl:for-each select="tokenize(@fileExtensions, ',')">
-        <string><xsl:value-of select="normalize-space(.)"/></string>
+        <string>
+        <xsl:choose>
+          <xsl:when test="starts-with(normalize-space(.), '.')">*</xsl:when>
+          <xsl:otherwise>*.</xsl:otherwise>
+        </xsl:choose>
+        <xsl:value-of select="normalize-space(.)"/>
+        </string>
       </xsl:for-each>
       </stringlist>
     </property>

+ 13 - 5
Libs/CommandLineModules/Testing/Modules/Blur2dImage/ctkCmdLineModuleBlur2dImage.xml

@@ -49,12 +49,20 @@ Blur a 2d image.
     <default>/home</default>
     <channel>output</channel>
     </directory>
-    <geometry fileExtensions="*.jpg, *.txt">
-    <name>geomVar</name>
-    <index>7</index>
-    <description>Some geom</description>
-    <label>Some geom</label>
+    <geometry fileExtensions=".vtk,.vtp">
+      <name>geomVar</name>
+      <index>7</index>
+      <description>Some geom</description>
+      <label>Some geom</label>
+      <channel>output</channel>
     </geometry>
+    <image fileExtensions=".nii,.nrrd">
+      <name>imageVar</name>
+      <index>8</index>
+      <description>Some image</description>
+      <label>Some image</label>
+      <channel>input</channel>
+    </image>
     <double>
       <name>doubleVariable</name>
       <flag>d</flag>

+ 119 - 22
Libs/CommandLineModules/Testing/Modules/Tour/ctkCmdLineModuleTour.xml

@@ -33,28 +33,6 @@
       </description>
       <label>Boolean Parameter</label>
     </boolean>
-    <file>
-    <name>fileVar</name>
-    <index>3</index>
-    <description>Some file</description>
-    <label>Some file</label>
-    <default>bla</default>
-    <channel>input</channel>
-    </file>
-    <directory>
-    <name>dirVar</name>
-    <index>6</index>
-    <description>Some dir</description>
-        <label>Some dir</label>
-    <default>/home</default>
-    <channel>output</channel>
-    </directory>
-    <geometry fileExtensions="*.jpg, *.txt">
-    <name>geomVar</name>
-    <index>7</index>
-    <description>Some geom</description>
-    <label>Some geom</label>
-    </geometry>
     <double>
       <name>doubleVariable</name>
       <flag>d</flag>
@@ -111,5 +89,124 @@
     <default>0.5,-34.2,43</default>
       </point>
   </parameters>
+
+  <parameters advanced="true">
+    <label>Directory I/O Parameters</label>
+    <description>Various Directory I/O parameters.</description>
+    <directory>
+      <name>dirVar</name>
+      <longflag>dirVar</longflag>
+      <description>Some dir</description>
+      <label>Some dir</label>
+      <default>/home</default>
+    </directory>
+  </parameters>
+
+  <parameters advanced="true">
+    <label>File I/O Parameters</label>
+    <description>Various File I/O parameters.</description>
+    <file>
+      <name>inputFileVarNoFileExtensions</name>
+      <longflag>if1</longflag>
+      <description>Input file, with no file extensions specified, so all files selectable.</description>
+      <label>Input file, no extensions specified.</label>
+      <default>bla</default>
+      <channel>input</channel>
+    </file>
+    <file fileExtensions=".txt,.mat">
+      <name>inputFileVarListCommaSeparated</name>
+      <longflag>if2</longflag>
+      <description>Input file, where a correct comma separated list of .txt and .mat are specified, which should include the first dot, but should not include any asterisks.</description>
+      <label>Input file, .txt or .mat file specified using leading dot.</label>
+      <default>bla.txt</default>
+      <channel>input</channel>
+    </file>
+    <file fileExtensions="txt,mat">
+      <name>inputFileVarListCommaSeparatedWithMissingFirstDot</name>
+      <longflag>if3</longflag>
+      <description>Input file, where the XML has missed the first dot of the file extensions.</description>
+      <label>Input file, .txt or .mat file specified without leading dot.</label>
+      <default>bla3.txt</default>
+      <channel>input</channel>
+    </file>
+    <file>
+      <name>outputFileVarNoFileExtensions</name>
+      <longflag>of1</longflag>
+      <description>Output file, with no file extensions specified, so all files selectable.</description>
+      <label>Output file, no extensions specified.</label>
+      <default>bla</default>
+      <channel>output</channel>
+    </file>
+    <file fileExtensions=".txt,.mat">
+      <name>outputFileVarListCommaSeparated</name>
+      <longflag>of2</longflag>
+      <description>Output file, where a comma separated list of .txt and .mat are specified, which should include the first dot, but should not include any asterisks.</description>
+      <label>Output file, .txt or .mat file specified using leading dot.</label>
+      <default>bla.txt</default>
+      <channel>output</channel>
+    </file>
+    <file fileExtensions="txt,mat">
+      <name>outputFileVarListCommaSeparatedWithMissingFirstDot</name>
+      <longflag>of3</longflag>
+      <description>Output file, where the XML has missed the first dot of the file extensions.</description>
+      <label>Output file, .txt or .mat file specified without leading dot.</label>
+      <default>bla3.txt</default>
+      <channel>output</channel>
+    </file>
+  </parameters>
+
+  <parameters advanced="true">
+    <label>Geometry I/O Parameters</label>
+    <description>Various Geometry I/O parameters, which are for things like vtkPolyData.</description>
+    <geometry>
+      <name>inputGeometryVarNoFileExtensions</name>
+      <longflag>ig1</longflag>
+      <description>Input geometry, with no file extensions specified, so all files selectable.</description>
+      <label>Input geometry, no extensions specified.</label>
+      <default>bla</default>
+      <channel>input</channel>
+    </geometry>
+    <geometry fileExtensions=".vtk,.vtp">
+      <name>inputGeometryVarListCommaSeparated</name>
+      <longflag>ig2</longflag>
+      <description>Input geometry, where a comma separated list is specified, which should include the first dot, but should not include any asterisks.</description>
+      <label>Input geometry, .vtk or .vtp file specified with a leading dot.</label>
+      <default>bla.vtk</default>
+      <channel>input</channel>
+    </geometry>
+    <geometry fileExtensions=".vtk,.vtp">
+      <name>inputGeometryVarListCommaSeparatedWithMissingFirstDot</name>
+      <longflag>ig3</longflag>
+      <description>Input geometry, where the XML has incorrectly missed the first dot of the file extensions.</description>
+      <label>Input geometry, .vtk or .vtp file specified without a leading dot.</label>
+      <default>bla3.vtk</default>
+      <channel>input</channel>
+    </geometry>
+    <geometry>
+      <name>outputGeometryVarNoFileExtensions</name>
+      <longflag>og1</longflag>
+      <description>Output geometry, with no file extensions specified, so all files selectable.</description>
+      <label>Output geometry, no extensions specified.</label>
+      <default>bla</default>
+      <channel>output</channel>
+    </geometry>
+    <geometry fileExtensions=".vtk,.vtp">
+      <name>outputGeometryVarListCommaSeparated</name>
+      <longflag>og2</longflag>
+      <description>Output geometry, where a comma separated list is specified, which should include the first dot, but should not include any asterisks.</description>
+      <label>Output geometry, .vtk or .vtp file specified with a leading dot.</label>
+      <default>bla.vtk</default>
+      <channel>output</channel>
+    </geometry>
+    <geometry fileExtensions=".vtk,.vtp">
+      <name>outputGeometryVarListCommaSeparatedWithMissingFirstDot</name>
+      <longflag>og3</longflag>
+      <description>Output geometry, where the XML has incorrectly missed the first dot of the file extensions.</description>
+      <label>Output geometry, .vtk or .vtp file specified without a leading dot.</label>
+      <default>bla3.vtk</default>
+      <channel>output</channel>
+    </geometry>
+  </parameters>
+
 </executable>