Skip to content
Permalink
Browse files
[processing] fixed issue in modeler with hidden params
  • Loading branch information
volaya committed May 21, 2014
1 parent 28659b6 commit 1e4d6a9a736b739f8f9c1aa3c474feba904e8971
@@ -176,40 +176,42 @@ def openModel(self, filename):
# parsing this
pass
for param in alg.parameters:
line = lines.readline().strip('\n').strip('\r')
if line == str(None):
algParams[param.name] = None
else:
tokens = line.split('|')
algParams[param.name] = \
AlgorithmAndParameter(int(tokens[0]),
tokens[1])
if not param.hidden:
line = lines.readline().strip('\n').strip('\r')
if line == str(None):
algParams[param.name] = None
else:
tokens = line.split('|')
algParams[param.name] = \
AlgorithmAndParameter(int(tokens[0]),
tokens[1])
outputPos = {}
for out in alg.outputs:
line = lines.readline().strip('\n').strip('\r')
if str(None) != line:
if '|' in line:
tokens = line.split('|')
name = tokens[0]
tokens = tokens[1].split(',')
outputPos[out.name] = QtCore.QPointF(
float(tokens[0]), float(tokens[1]))
if not out.hidden:
line = lines.readline().strip('\n').strip('\r')
if str(None) != line:
if '|' in line:
tokens = line.split('|')
name = tokens[0]
tokens = tokens[1].split(',')
outputPos[out.name] = QtCore.QPointF(
float(tokens[0]), float(tokens[1]))
else:
name = line
outputPos[out.name] = None
algOutputs[out.name] = name

# We add the output to the algorithm,
# with a name indicating where it comes
# from that guarantees that the name is
# unique
output = copy.deepcopy(out)
output.description = name
output.name = self.getSafeNameForOutput(iAlg,
output)
self.addOutput(output)
else:
name = line
outputPos[out.name] = None
algOutputs[out.name] = name

# We add the output to the algorithm,
# with a name indicating where it comes
# from that guarantees that the name is
# unique
output = copy.deepcopy(out)
output.description = name
output.name = self.getSafeNameForOutput(iAlg,
output)
self.addOutput(output)
else:
algOutputs[out.name] = None
algOutputs[out.name] = None
self.outputPos.append(outputPos)
self.algOutputs.append(algOutputs)
self.algParameters.append(algParams)
@@ -467,18 +469,20 @@ def serialize(self):
else:
s += str(None) + '\n'
for param in alg.parameters:
value = self.algParameters[i][param.name]
if value:
s += value.serialize() + '\n'
else:
s += str(None) + '\n'
if not param.hidden:
value = self.algParameters[i][param.name]
if value:
s += value.serialize() + '\n'
else:
s += str(None) + '\n'
for out in alg.outputs:
value = self.algOutputs[i][out.name]
s += unicode(value)
if value is not None:
pt = self.outputPos[i][out.name]
s += '|' + str(pt.x()) + ',' + str(pt.y())
s += '\n'
if not out.hidden:
value = self.algOutputs[i][out.name]
s += unicode(value)
if value is not None:
pt = self.outputPos[i][out.name]
s += '|' + str(pt.x()) + ',' + str(pt.y())
s += '\n'

return s

@@ -489,42 +493,44 @@ def setPositions(self, paramPos, algPos, outputPos):

def prepareAlgorithm(self, alg, iAlg):
for param in alg.parameters:
aap = self.algParameters[iAlg][param.name]
if aap is None:
if isinstance(param, ParameterExtent):
value = self.getMinCoveringExtent()
if not param.setValue(value):
raise GeoAlgorithmExecutionException('Wrong value: '
+ str(value))
if not param.hidden:
aap = self.algParameters[iAlg][param.name]
if aap is None:
if isinstance(param, ParameterExtent):
value = self.getMinCoveringExtent()
if not param.setValue(value):
raise GeoAlgorithmExecutionException('Wrong value: '
+ str(value))
else:
param.setValue(None)
continue
if isinstance(param, ParameterMultipleInput):
value = self.getValueFromAlgorithmAndParameter(aap)
tokens = value.split(';')
layerslist = []
for token in tokens:
(i, paramname) = token.split('|')
aap = AlgorithmAndParameter(int(i), paramname)
value = self.getValueFromAlgorithmAndParameter(aap)
layerslist.append(str(value))
value = ';'.join(layerslist)
else:
param.setValue(None)
continue
if isinstance(param, ParameterMultipleInput):
value = self.getValueFromAlgorithmAndParameter(aap)
tokens = value.split(';')
layerslist = []
for token in tokens:
(i, paramname) = token.split('|')
aap = AlgorithmAndParameter(int(i), paramname)
value = self.getValueFromAlgorithmAndParameter(aap)
layerslist.append(str(value))
value = ';'.join(layerslist)
else:
value = self.getValueFromAlgorithmAndParameter(aap)

# We allow unexistent filepaths, since that allows
# algorithms to skip some conversion routines
if not param.setValue(value) and not isinstance(param,
ParameterDataObject):
raise GeoAlgorithmExecutionException('Wrong value: '
+ str(value))

# We allow unexistent filepaths, since that allows
# algorithms to skip some conversion routines
if not param.setValue(value) and not isinstance(param,
ParameterDataObject):
raise GeoAlgorithmExecutionException('Wrong value: '
+ str(value))
for out in alg.outputs:
val = self.algOutputs[iAlg][out.name]
if val:
name = self.getSafeNameForOutput(iAlg, out)
out.value = self.getOutputFromName(name).value
else:
out.value = None
if not out.hidden:
val = self.algOutputs[iAlg][out.name]
if val:
name = self.getSafeNameForOutput(iAlg, out)
out.value = self.getOutputFromName(name).value
else:
out.value = None

def getMinCoveringExtent(self):
first = True
@@ -29,13 +29,13 @@
import pickle
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.gui.HelpEditionDialog import HelpEditionDialog
from processing.gui.ParametersDialog import ParametersDialog
from processing.gui.AlgorithmClassification import AlgorithmDecorator
from processing.modeler.ModelerParameterDefinitionDialog import \
ModelerParameterDefinitionDialog
from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
from processing.modeler.ModelerUtils import ModelerUtils
@@ -54,7 +54,6 @@ class ModelerDialog(QDialog, Ui_DlgModeler):
def __init__(self, alg=None):
QDialog.__init__(self)

self.hasChanged = False
self.setupUi(self)

self.setWindowFlags(Qt.WindowMinimizeButtonHint |
@@ -162,15 +161,18 @@ def _mimeDataAlgorithm(items):
self.textGroup.setText(alg.group)
self.textName.setText(alg.name)
self.repaintModel()

else:
self.alg = ModelerAlgorithm()
self.alg = ModelerAlgorithm()

self.view.centerOn(0, 0)
self.alg.setModelerView(self)
self.help = None
# Indicates whether to update or not the toolbox after
# closing this dialog
self.update = False

self.hasChanged = False

def changeModel(self):
self.hasChanged = True
@@ -251,27 +251,29 @@ def paint(self, painter, option, widget=None):
i = 1
if not self.inputFolded:
for param in self.element.parameters:
text = self.getAdjustedText(param.description)
h = -(fm.height() * 1.2) * (i + 1)
h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
pt = QtCore.QPointF(-ModelerGraphicItem.BOX_WIDTH / 2
+ 33, h)
painter.drawText(pt, text)
i += 1
if not param.hidden:
text = self.getAdjustedText(param.description)
h = -(fm.height() * 1.2) * (i + 1)
h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
pt = QtCore.QPointF(-ModelerGraphicItem.BOX_WIDTH / 2
+ 33, h)
painter.drawText(pt, text)
i += 1
i = 1
h = fm.height() * 1.2
h = h + ModelerGraphicItem.BOX_HEIGHT / 2.0
pt = QtCore.QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + 25, h)
painter.drawText(pt, 'Out')
if not self.outputFolded:
for out in self.element.outputs:
text = self.getAdjustedText(out.description)
h = fm.height() * 1.2 * (i + 1)
h = h + ModelerGraphicItem.BOX_HEIGHT / 2.0
pt = QtCore.QPointF(-ModelerGraphicItem.BOX_WIDTH / 2
+ 33, h)
painter.drawText(pt, text)
i += 1
if not out.hidden:
text = self.getAdjustedText(out.description)
h = fm.height() * 1.2 * (i + 1)
h = h + ModelerGraphicItem.BOX_HEIGHT / 2.0
pt = QtCore.QPointF(-ModelerGraphicItem.BOX_WIDTH / 2
+ 33, h)
painter.drawText(pt, text)
i += 1
if self.pixmap:
painter.drawPixmap(-(ModelerGraphicItem.BOX_WIDTH / 2.0) + 3, -8,
self.pixmap)
@@ -295,7 +297,6 @@ def getXPositionForFoldButton(self):

def getLinkPointForOutput(self, outputIndex):
if isinstance(self.element, GeoAlgorithm):
numParams = 0
outputIndex = (outputIndex if not self.outputFolded else -1)
text = self.getAdjustedText(
self.element.outputs[outputIndex].description)
@@ -138,17 +138,15 @@ def paintModel(self, model):
params = model.algParameters[iAlg]
idx = 0
for parameter in alg.parameters:
param = params[parameter.name]
if param:
sourceItems = self.getItemsFromAAP(param,
isinstance(
alg.getParameterFromName(parameter.name),
ParameterMultipleInput))
for sourceItem in sourceItems:
arrow = ModelerArrowItem(sourceItem[0], sourceItem[1],
self.algItems[iAlg], idx)
self.addItem(arrow)
idx += 1
if not parameter.hidden:
param = params[parameter.name]
if param:
sourceItems = self.getItemsFromAAP(param,
isinstance(alg.getParameterFromName(parameter.name), ParameterMultipleInput))
for sourceItem in sourceItems:
arrow = ModelerArrowItem(sourceItem[0], sourceItem[1], self.algItems[iAlg], idx)
self.addItem(arrow)
idx += 1
for depend in model.dependencies[iAlg]:
arrow = ModelerArrowItem(self.algItems[depend], -1,
self.algItems[iAlg], -1)

0 comments on commit 1e4d6a9

Please sign in to comment.