Skip to content

Commit

Permalink
[processing] allow optional in all getAsScriptCode
Browse files Browse the repository at this point in the history
  • Loading branch information
mbernasocchi authored and m-kuhn committed Jun 3, 2016
1 parent ebf41f0 commit 2dea7c8
Showing 1 changed file with 70 additions and 15 deletions.
85 changes: 70 additions & 15 deletions python/plugins/processing/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ def setValue(self, value):
return True

def getAsScriptCode(self):
return '##' + self.name + '=boolean ' + str(self.default)
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'boolean '
return '##' + self.name + '=' + param_type + str(self.default)


class ParameterCrs(Parameter):
Expand All @@ -167,7 +171,11 @@ def getValueAsCommandLineParameter(self):
return '"' + unicode(self.value) + '"'

def getAsScriptCode(self):
return '##' + self.name + '=crs ' + str(self.default)
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'crs '
return '##' + self.name + '=' + param_type + str(self.default)


class ParameterDataObject(Parameter):
Expand Down Expand Up @@ -213,7 +221,12 @@ def getValueAsCommandLineParameter(self):
return '"' + unicode(self.value) + '"'

def getAsScriptCode(self):
return '##' + self.name + '=extent'
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'extent'
return '##' + self.name + '=' + param_type



class ParameterPoint(Parameter):
Expand Down Expand Up @@ -244,7 +257,11 @@ def getValueAsCommandLineParameter(self):
return '"' + unicode(self.value) + '"'

def getAsScriptCode(self):
return '##' + self.name + '=point'
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'point'
return '##' + self.name + '=' + param_type


class ParameterFile(Parameter):
Expand Down Expand Up @@ -276,10 +293,14 @@ def typeName(self):
return 'file'

def getAsScriptCode(self):
param_type = ''
if self.optional:
param_type += 'optional '
if self.isFolder:
return '##' + self.name + '=folder'
param_type += 'folder'
else:
return '##' + self.name + '=file'
param_type += 'file'
return '##' + self.name + '=' + param_type


class ParameterFixedTable(Parameter):
Expand Down Expand Up @@ -501,12 +522,16 @@ def dataType(self):
return 'any vectors'

def getAsScriptCode(self):
param_type = ''
if self.optional:
param_type += 'optional '
if self.datatype == self.TYPE_RASTER:
return '##' + self.name + '=multiple raster'
param_type += 'multiple raster'
if self.datatype == self.TYPE_FILE:
return '##' + self.name + '=multiple file'
param_type += 'multiple file'
else:
return '##' + self.name + '=multiple vector'
param_type += 'multiple vector'
return '##' + self.name + '=' + param_type


class ParameterNumber(Parameter):
Expand Down Expand Up @@ -559,7 +584,11 @@ def setValue(self, n):
return False

def getAsScriptCode(self):
return '##' + self.name + '=number ' + str(self.default)
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'number'
return '##' + self.name + '=' + param_type + str(self.default)


class ParameterRange(Parameter):
Expand Down Expand Up @@ -657,7 +686,11 @@ def getFileFilter(self):
return ';;'.join(exts)

def getAsScriptCode(self):
return '##' + self.name + '=raster'
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'raster'
return '##' + self.name + '=' + param_type


class ParameterSelection(Parameter):
Expand Down Expand Up @@ -733,7 +766,11 @@ def getValueAsCommandLineParameter(self):
if self.value is not None else unicode(None))

def getAsScriptCode(self):
return '##' + self.name + '=string ' + self.default
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'string'
return '##' + self.name + '=' + param_type + self.default


class ParameterTable(ParameterDataObject):
Expand Down Expand Up @@ -801,10 +838,20 @@ def getFileFilter(self):
return ';;'.join(exts)

def getAsScriptCode(self):
return '##' + self.name + '=table'
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'table'
return '##' + self.name + '=' + param_type


class ParameterTableField(Parameter):
"""A parameter representing a table field.
Its value is a string that represents the name of the field.
In a script you can use it with
##Field=[optional] field [number|string] Parentinput
"""

DATA_TYPE_NUMBER = 0
DATA_TYPE_STRING = 1
Expand Down Expand Up @@ -844,7 +891,11 @@ def dataType(self):
return 'any'

def getAsScriptCode(self):
return '##' + self.name + '=field ' + self.parent
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'field'
return '##' + self.name + '=' + param_type + self.parent


class ParameterVector(ParameterDataObject):
Expand Down Expand Up @@ -932,7 +983,11 @@ def dataType(self):
return types[:-2]

def getAsScriptCode(self):
return '##' + self.name + '=vector'
param_type = ''
if self.optional:
param_type += 'optional '
param_type += 'vector'
return '##' + self.name + '=' + param_type


class ParameterGeometryPredicate(Parameter):
Expand Down

0 comments on commit 2dea7c8

Please sign in to comment.