Skip to content

Commit

Permalink
[sextante] model outputs are now shown in canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed May 5, 2013
1 parent d3f9dd5 commit 945bc60
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 95 deletions.
Binary file added python/plugins/sextante/images/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 43 additions & 8 deletions python/plugins/sextante/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand Down Expand Up @@ -93,7 +92,8 @@ def __init__(self):

#position of items in canvas
self.algPos = []
self.paramPos = []
self.paramPos = []
self.outputPos = [] #same structure as algOutputs

#deactivated algorithms that should not be executed
self.deactivated = []
Expand All @@ -106,6 +106,7 @@ def getIcon(self):
def openModel(self, filename):
self.algPos = []
self.paramPos = []
self.outputOutputs = []
self.algs = []
self.algParameters = []
self.algOutputs = []
Expand Down Expand Up @@ -153,18 +154,27 @@ def openModel(self, filename):
try:
dependencies.append(int(index))
except:
pass #a quick fix fwhile I figure out how to solve problems when parsing this
pass #a quick fix while I figure out how to solve problems when parsing this
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])
outputPos = {}
for out in alg.outputs:
line = lines.readline().strip("\n").strip("\r")
if str(None)!=line:
algOutputs[out.name] = 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)
Expand All @@ -173,6 +183,7 @@ def openModel(self, filename):
self.addOutput(output)
else:
algOutputs[out.name] = None
self.outputPos.append(outputPos)
self.algOutputs.append(algOutputs)
self.algParameters.append(algParams)
self.dependencies.append(dependencies)
Expand Down Expand Up @@ -201,7 +212,15 @@ def addAlgorithm(self, alg, parametersMap, valuesMap, outputsMap, dependencies):
self.dependencies.append(dependencies)
for value in valuesMap.keys():
self.paramValues[value] = valuesMap[value]
self.algPos.append(self.getPositionForAlgorithmItem())
algPos = self.getPositionForAlgorithmItem()
self.algPos.append(algPos)
pos = {}
i = 0
from sextante.modeler.ModelerGraphicItem import ModelerGraphicItem
for out in outputsMap:
pos[out] = algPos + QtCore.QPointF(ModelerGraphicItem.BOX_WIDTH, i * ModelerGraphicItem.BOX_HEIGHT)
i+=1
self.outputPos.append(pos)

def updateAlgorithm(self, algIndex, parametersMap, valuesMap, outputsMap, dependencies):
self.algParameters[algIndex] = parametersMap
Expand All @@ -210,6 +229,14 @@ def updateAlgorithm(self, algIndex, parametersMap, valuesMap, outputsMap, depend
for value in valuesMap.keys():
self.paramValues[value] = valuesMap[value]
self.updateModelerView()
algPos = self.algPos[algIndex]
pos = {}
i = 0
from sextante.modeler.ModelerGraphicItem import ModelerGraphicItem
for out in outputsMap:
pos[out] = algPos + QtCore.QPointF(ModelerGraphicItem.BOX_WIDTH, i * ModelerGraphicItem.BOX_HEIGHT)
i+=1
self.outputPos[algIndex] = pos


def removeAlgorithm(self, index):
Expand All @@ -225,6 +252,7 @@ def removeAlgorithm(self, index):
del self.algParameters[index]
del self.algOutputs[index]
del self.algPos[index]
del self.outputPos[index]

i = -1
for paramValues in self.algParameters:
Expand Down Expand Up @@ -395,14 +423,21 @@ def serialize(self):
s+=value.serialize() + "\n"
else:
s+=str(None) + "\n"
for out in alg.outputs:
s+=unicode(self.algOutputs[i][out.name]) + "\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"

return s


def setPositions(self, paramPos,algPos):
def setPositions(self, paramPos, algPos, outputPos):
self.paramPos = paramPos
self.algPos = algPos
self.outputPos = outputPos


def prepareAlgorithm(self, alg, iAlg):
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/sextante/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def saveModel(self, saveAs):
self.tr("Please enter group and model names before saving")
)
return
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions())
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions(), self.scene.getOutputPositions())
self.alg.name = unicode(self.textName.text())
self.alg.group = unicode(self.textGroup.text())
if self.alg.descriptionFile != None and not saveAs:
Expand Down Expand Up @@ -240,7 +240,7 @@ def addInput(self):
dlg = ModelerParameterDefinitionDialog(self.alg, paramType)
dlg.exec_()
if dlg.param != None:
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions())
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions(), self.scene.getOutputPositions())
self.alg.addParameter(dlg.param)
self.repaintModel()
self.view.ensureVisible(self.scene.getLastParameterItem())
Expand All @@ -265,7 +265,7 @@ def addAlgorithm(self):
dlg = ModelerParametersDialog(alg, self.alg)
dlg.exec_()
if dlg.params != None:
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions())
self.alg.setPositions(self.scene.getParameterPositions(), self.scene.getAlgorithmPositions(), self.scene.getOutputPositions())
self.alg.addAlgorithm(alg, dlg.params, dlg.values, dlg.outputs, dlg.dependencies)
self.repaintModel()
self.view.ensureVisible(self.scene.getLastAlgorithmItem())
Expand Down
Loading

0 comments on commit 945bc60

Please sign in to comment.