Removed MultipleExternalInput parameter and made it a subtype of MultipleInput

This commit is contained in:
Victor Olaya 2014-04-13 12:47:34 +02:00
parent 54ce9a0ec3
commit 674fee73b1
10 changed files with 45 additions and 161 deletions

View File

@ -54,7 +54,6 @@ from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterCrs import ParameterCrs
from processing.parameters.ParameterExtent import ParameterExtent
from processing.parameters.ParameterString import ParameterString
from processing.parameters.ParameterMultipleExternalInput import ParameterMultipleExternalInput
from processing.outputs.OutputRaster import OutputRaster
from processing.outputs.OutputVector import OutputVector
from processing.outputs.OutputTable import OutputTable
@ -194,17 +193,14 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
return param.setValue(None)
return param.setValue(widget.currentText())
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers()
else:
options = dataobjects.getRasterLayers()
value = []
for index in widget.selectedoptions:
value.append(options[index])
return param.setValue(value)
elif isinstance(param, ParameterMultipleExternalInput):
value = widget.selectedoptions
return param.setValue(value)
if param.datatype == ParameterMultipleInput.TYPE_FILE:
return param.setValue(widget.selectedoptions)
else:
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers()
else:
options = dataobjects.getRasterLayers()
return param.setValue([options[i] for i in widget.selectedoptions])
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs,
ParameterExtent)):
return param.setValue(widget.getValue())

View File

@ -30,7 +30,8 @@ __revision__ = '$Format:%H$'
from PyQt4 import QtCore, QtGui
import os
class MultipleExternalInputDialog(QtGui.QDialog):
class MultipleFileInputDialog(QtGui.QDialog):
def __init__(self, selectedoptions):
self.selectedoptions = selectedoptions
self.options=selectedoptions
@ -68,7 +69,6 @@ class MultipleExternalInputDialog(QtGui.QDialog):
QtCore.QMetaObject.connectSlotsByName(self)
def setTableContent(self):
# "self.options :", ['/temp/confmat1-1.csv', '/temp/confmat2-1.csv']
self.table.setRowCount(len(self.options))
for i in range(len(self.options)):
item = QtGui.QLabel()
@ -78,7 +78,6 @@ class MultipleExternalInputDialog(QtGui.QDialog):
def okPressed(self):
self.selectedoptions = []
self.selectedoptions = self.options
# "self.selectedoptions :", ['/temp/confmat1-1.csv', '/temp/confmat2-1.csv']
self.close()
def cancelPressed(self):

View File

@ -2,7 +2,7 @@
"""
***************************************************************************
MultipleExternalInputPanel.py
MultipleFileInputPanel.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
@ -27,13 +27,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from PyQt4 import QtCore, QtGui
from processing.gui.MultipleExternalInputDialog import MultipleExternalInputDialog
from PyQt4 import QtGui
from processing.gui.MultipleFileInputDialog import MultipleFileInputDialog
class MultipleExternalInputPanel(QtGui.QWidget):
class MultipleFileInputPanel(QtGui.QWidget):
def __init__(self, parent = None):
super(MultipleExternalInputPanel, self).__init__(parent)
super(MultipleFileInputPanel, self).__init__(parent)
self.selectedoptions = []
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
@ -54,21 +54,7 @@ class MultipleExternalInputPanel(QtGui.QWidget):
self.label.setText(str(len(self.selectedoptions)) + " elements selected")
def showSelectionDialog(self):
#=======================================================================
# #If there is a datatype, we use it to create the list of options
# if self.datatype is not None:
# if self.datatype == ParameterMultipleInput.TYPE_RASTER:
# options = QGisLayers.getRasterLayers()
# elif self.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
# options = QGisLayers.getVectorLayers()
# else:
# options = QGisLayers.getVectorLayers(self.datatype)
# opts = []
# for opt in options:
# opts.append(opt.name())
# self.options = opts
#=======================================================================
dlg = MultipleExternalInputDialog(self.selectedoptions)
dlg = MultipleFileInputDialog(self.selectedoptions)
dlg.exec_()
if dlg.selectedoptions != None:
self.selectedoptions = dlg.selectedoptions

View File

@ -46,8 +46,7 @@ from processing.gui.NumberInputPanel import NumberInputPanel
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
from processing.gui.FileSelectionPanel import FileSelectionPanel
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
from processing.gui.MultipleExternalInputPanel import MultipleExternalInputPanel
from processing.gui.MultipleFileInputPanel import MultipleFileInputPanel
from processing.parameters.ParameterRaster import ParameterRaster
from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterTable import ParameterTable
@ -62,8 +61,6 @@ from processing.parameters.ParameterExtent import ParameterExtent
from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterCrs import ParameterCrs
from processing.parameters.ParameterString import ParameterString
from processing.parameters.ParameterMultipleExternalInput import ParameterMultipleExternalInput
from processing.outputs.OutputRaster import OutputRaster
from processing.outputs.OutputTable import OutputTable
from processing.outputs.OutputVector import OutputVector
@ -282,18 +279,19 @@ class ParametersPanel(QtGui.QWidget):
elif isinstance(param, ParameterFile):
item = FileSelectionPanel(param.isFolder)
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = dataobjects.getRasterLayers()
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers()
if param.datatype == ParameterMultipleInput.TYPE_FILE:
item = MultipleFileInputPanel()
else:
options = dataobjects.getVectorLayers([param.datatype])
opts = []
for opt in options:
opts.append(self.getExtendedLayerName(opt))
item = MultipleInputPanel(opts)
elif isinstance(param, ParameterMultipleExternalInput):
item = MultipleExternalInputPanel()
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = dataobjects.getRasterLayers()
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = dataobjects.getVectorLayers()
else:
options = dataobjects.getVectorLayers([param.datatype])
opts = []
for opt in options:
opts.append(self.getExtendedLayerName(opt))
item = MultipleInputPanel(opts)
elif isinstance(param, ParameterNumber):
item = NumberInputPanel(param.default, param.min, param.max,
param.isInteger)
@ -356,7 +354,7 @@ class ParametersPanel(QtGui.QWidget):
def setTableContent(self):
params = [parm for parm in self.alg.parameters if not parm.hidden]
outputs = [output for output in self.alg.outputs if not output.hidden]
numParams = len(parms)
numParams = len(params)
numOutputs = len(outputs)
self.tableWidget.setRowCount(numParams + numOutputs)

View File

@ -88,6 +88,8 @@ class OTBAlgorithm(GeoAlgorithm):
if a_list[0] in ["ParameterVector", "ParameterMultipleInput"]:
if c_list[0] == "ParameterType_InputImageList":
a_list[3] = 3
elif c_list[0] == "ParameterType_InputFilenameList":
a_list[3] = 4
else:
a_list[3] = -1

View File

@ -25,10 +25,11 @@
<default>0</default>
</parameter>
<parameter>
<parameter_type source_parameter_type="ParameterType_InputFilenameList">ParameterMultipleExternalInput</parameter_type>
<parameter_type source_parameter_type="ParameterType_InputFilenameList">ParameterMultipleInput</parameter_type>
<key>method.dempstershafer.cmfl</key>
<name>Confusion Matrices</name>
<description>A list of confusion matrix files (*.CSV format) to define the masses of belief and the class labels. Each file should be formatted the following way: the first line, beginning with a '#' symbol, should be a list of the class labels present in the corresponding input classification image, organized in the same order as the confusion matrix rows/columns.</description>
<datatype />
<optional>False</optional>
</parameter>
<parameter>

View File

@ -146,7 +146,7 @@ def get_inverted_parameters():
inverted_parameters_clone['ParameterType_RAM'] = 'ParameterNumber'
inverted_parameters_clone['ParameterType_InputProcessXML'] = 'ParameterFile'
inverted_parameters_clone['ParameterType_OutputProcessXML'] = 'ParameterFile'
inverted_parameters_clone['ParameterType_InputFilenameList'] = 'ParameterMultipleExternalInput' # 'ParameterString'
inverted_parameters_clone['ParameterType_InputFilenameList'] = 'ParameterMultipleInput' # 'ParameterString'
return inverted_parameters_clone

View File

@ -43,8 +43,6 @@ from processing.parameters.ParameterFixedTable import ParameterFixedTable
from processing.parameters.ParameterExtent import ParameterExtent
from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterCrs import ParameterCrs
from processing.parameters.ParameterMultipleExternalInput import ParameterMultipleExternalInput
class ParameterFactory:
@ -68,8 +66,7 @@ class ParameterFactory:
ParameterFixedTable,
ParameterExtent,
ParameterFile,
ParameterCrs,
ParameterMultipleExternalInput
ParameterCrs
]
for clazz in classes:
if s.startswith(clazz().parameterName()):

View File

@ -1,104 +0,0 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
ParameterMultipleExternalInput.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
(C) 2013 by CS Systemes d'information (CS SI)
Email : volayaf at gmail dot com
otb at c-s dot fr (CS SI)
Contributors : Victor Olaya - basis from ParameterMultipleInput
Alexia Mondot (CS SI) - managing the new parameter ParameterMultipleExternalInput
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from processing.parameters.ParameterDataObject import ParameterDataObject
from qgis.core import *
class ParameterMultipleExternalInput(ParameterDataObject):
'''A parameter representing several data objects.
Its value is a string with substrings separated by semicolons, each of which
represents the data source location of each element'''
exported = None
def __init__(self, name="", description="", optional = False):
ParameterDataObject.__init__(self, name, description)
self.datatype = None # to delete
self.optional = optional
self.value = None
self.exported = None
self.default=""
def setValue(self, obj):
if isinstance(obj, list):
if len(obj) == 0:
if self.optional:
return True
else:
return False
s = ""
idx = 0
for filename in obj:
s += filename
if idx < len(obj) - 1:
s+=" "
idx=idx+1;
self.value = s;
return True
def getSafeExportedLayers(self):
'''Returns not the value entered by the user, but a string with semicolon-separated filenames
which contains the data of the selected layers, but saved in a standard format (currently
shapefiles for vector layers and GeoTiff for raster) so that they can be opened by most
external applications.
If there is a selection and QGIS is configured to use just the selection, if exports
the layer even if it is already in a suitable format.
Works only if the layer represented by the parameter value is currently loaded in QGIS.
Otherwise, it will not perform any export and return the current value string.
If the current value represents a layer in a suitable format, it does no export at all
and returns that value.
Currently, it works just for vector layer. In the case of raster layers, it returns the
parameter value.
The layers are exported just the first time the method is called. The method can be called
several times and it will always return the same string, performing the export only the first time.'''
if self.exported:
return self.exported
self.exported = self.value
layers = self.value.split(";")
if layers == None or len(layers) == 0:
return self.value
return layers
def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description + "|" + str(self.optional)
def deserialize(self, s):
"""
in : string : ParameterNumber|-nodatalabel|Label for the NoData class|None|None|0
returns the current class object from extracted information from s
"""
tokens = s.split("|")
return ParameterMultipleExternalInput(tokens[1], tokens[2], tokens[3] == str(True))
def getAsScriptCode(self):
return "##" + self.name

View File

@ -44,6 +44,7 @@ class ParameterMultipleInput(ParameterDataObject):
TYPE_VECTOR_LINE = 1
TYPE_VECTOR_POLYGON = 2
TYPE_RASTER = 3
TYPE_FILE = 4
def __init__(self, name='', description='', datatype=-1, optional=False):
ParameterDataObject.__init__(self, name, description)
@ -120,6 +121,8 @@ class ParameterMultipleInput(ParameterDataObject):
filename = dataobjects.exportRasterLayer(layer)
self.exported = self.exported.replace(layerfile, filename)
return self.exported
elif self.datatype == ParameterMultipleInput.TYPE_FILE:
return self.value
else:
for layerfile in layers:
layer = dataobjects.getObjectFromUri(layerfile, False)
@ -139,6 +142,8 @@ class ParameterMultipleInput(ParameterDataObject):
if layer.name() == s:
return unicode(layer.dataProvider().dataSourceUri())
return s
if self.datatype == ParameterMultipleInput.TYPE_FILE:
return unicode(value)
else:
if isinstance(value, QgsVectorLayer):
return unicode(value.source())
@ -153,6 +158,8 @@ class ParameterMultipleInput(ParameterDataObject):
def getFileFilter(self):
if self.datatype == ParameterMultipleInput.TYPE_RASTER:
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
elif self.datatype == ParameterMultipleInput.TYPE_FILE:
return "All files (*.*)"
else:
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
for i in range(len(exts)):
@ -172,5 +179,7 @@ class ParameterMultipleInput(ParameterDataObject):
def getAsScriptCode(self):
if self.datatype == ParameterMultipleInput.TYPE_RASTER:
return '##' + self.name + '=multiple raster'
if self.datatype == ParameterMultipleInput.TYPE_FILE:
return '##' + self.name + '=multiple file'
else:
return '##' + self.name + '=multiple vector'