Skip to content

Commit

Permalink
[processing] support for output geometry types in scripts and modeler
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Sep 2, 2016
1 parent 7e26124 commit 12d6e15
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
31 changes: 25 additions & 6 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ def getAvailableValuesOfType(self, paramType, outType=None, dataType=None):
if alg.name not in dependent:
for out in alg.algorithm.outputs:
if isinstance(out, outType):
values.append(ValueFromOutput(alg.name, out.name))
if subType is not None and out.datatype in dataType:
values.append(ValueFromOutput(alg.name, out.name))
else:
values.append(ValueFromOutput(alg.name, out.name))

return values

Expand Down Expand Up @@ -350,11 +353,11 @@ def getWidgetFromParameter(self, param):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector)
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POINT:
options = self.getAvailableValuesOfType(ParameterVector, None, [ParameterVector.TYPE_VECTOR_POINT])
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_POINT, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_LINE:
options = self.getAvailableValuesOfType(ParameterVector, None, [ParameterVector.TYPE_VECTOR_LINE])
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_LINE, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POLYGON:
options = self.getAvailableValuesOfType(ParameterVector, None, [ParameterVector.TYPE_VECTOR_POLYGON])
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_POLYGON, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = self.getAvailableValuesOfType(ParameterRaster, OutputRaster)
else:
Expand Down Expand Up @@ -524,8 +527,16 @@ def setPreviousValues(self):
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector)
else:
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POINT:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_POINT, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_LINE:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_LINE, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POLYGON:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_POLYGON, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = self.getAvailableValuesOfType(ParameterRaster, OutputRaster)
else:
options = self.getAvailableValuesOfType(ParameterFile, OutputFile)
selected = []
for i, opt in enumerate(options):
if opt in value:
Expand Down Expand Up @@ -751,8 +762,16 @@ def setParamValue(self, alg, param, widget):
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector)
else:
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POINT:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_POINT, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_LINE:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_LINE, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POLYGON:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector, [OutputVector.TYPE_VECTOR_POLYGON, OutputVector.VECTOR_TYPE_ANY])
elif param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = self.getAvailableValuesOfType(ParameterRaster, OutputRaster)
else:
options = self.getAvailableValuesOfType(ParameterFile, OutputFile)
values = [options[i] for i in widget.selectedoptions]
if len(values) == 0 and not param.optional:
return False
Expand Down
8 changes: 7 additions & 1 deletion python/plugins/processing/script/ScriptAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,14 @@ def processOutputParameterToken(self, token):

if token.lower().strip().startswith('raster'):
out = OutputRaster()
elif token.lower().strip().startswith('vector'):
elif token.lower().strip() == 'vector':
out = OutputVector()
elif token.lower().strip() == 'vector point':
out = OutputVector(datatype=[OutputVector.VECTOR_TYPE_POINT])
elif token.lower().strip() == 'vector line':
out = OutputVector(datatype=[OutputVector.VECTOR_TYPE_LINE])
elif token.lower().strip() == 'vector polygon':
out = OutputVector(datatype=[OutputVector.VECTOR_TYPE_POLYGON])
elif token.lower().strip().startswith('table'):
out = OutputTable()
elif token.lower().strip().startswith('html'):
Expand Down

0 comments on commit 12d6e15

Please sign in to comment.