Skip to content
Permalink
Browse files

[sextante] Fixed iterative execution

Some additional minor fixes
  • Loading branch information
volaya committed Apr 17, 2013
1 parent 1570240 commit d9277564f8b755f76f89a91ad3d3bfa1e9870fae
@@ -906,15 +906,12 @@ def processAlgorithm(self, progress):
i += 1
spokex = spokepoint.geometry().boundingBox().center().x()
spokey = spokepoint.geometry().boundingBox().center().y()
spokeid = unicode(spokepoint.attributeMap()[spokeindex].toString())
spokeid = unicode(spokepoint.attributes()[spokeindex].toString())
progress.setPercentage(float(i) / len(spokepoints) * 100)
# Scan hub points to find first matching hub
hubpoint = QgsFeature()
hublayer.dataProvider().select(hublayer.dataProvider().attributeIndexes())
hublayer.dataProvider().rewind()
# Scan hub points to find first matching hub
hubpoints = QGisLayers.features(hublayer)
for hubpoint in hubpoints:
hubid = unicode(hubpoint.attributeMap()[hubindex].toString())
hubid = unicode(hubpoint.attributes()[hubindex].toString())
if hubid == spokeid:
hubx = hubpoint.geometry().boundingBox().center().x()
huby = hubpoint.geometry().boundingBox().center().y()
@@ -213,36 +213,27 @@ def accept(self):
return
msg = self.alg.checkParameterValuesBeforeExecuting()
if msg:
#===============================================================
# if keepOpen or useThread:
# self.setInfo("Unable to execute algorithm: %s" % msg, True)
# self.tabWidget.setCurrentIndex(1) # log tab
# else:
#===============================================================
QMessageBox.critical(self, "Unable to execute algorithm", msg)
return
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(False)
buttons = self.paramTable.iterateButtons
iterateParam = None
self.iterateParam = None

for i in range(len(buttons.values())):
button = buttons.values()[i]
if button.isChecked():
iterateParam = buttons.keys()[i]
self.iterateParam = buttons.keys()[i]
break

self.progress.setMaximum(0)
self.progressLabel.setText("Processing algorithm...")
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if useThread:
if iterateParam:
self.algEx = AlgorithmExecutor(self.alg, iterateParam)
else:
command = self.alg.getAsCommand()
if command:
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
self.algEx = AlgorithmExecutor(self.alg)
if useThread and not self.iterateParam: #iterative execution on separate thread is still not working fine...
command = self.alg.getAsCommand()
if command:
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
self.algEx = AlgorithmExecutor(self.alg)
self.algEx.algExecuted.connect(self.finish)
self.algEx.error.connect(self.error)
self.algEx.percentageChanged.connect(self.setPercentage)
@@ -258,8 +249,8 @@ def accept(self):
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True)
else:
self.setInfo("<b>Algorithm %s starting...</b>" % self.alg.name)
if iterateParam:
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg, iterateParam, self):
if self.iterateParam:
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg, self.iterateParam, self):
self.finish()
else:
QApplication.restoreOverrideCursor()
@@ -294,7 +285,8 @@ def accept(self):
@pyqtSlot()
def finish(self):
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
SextantePostprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
if self.iterateParam is None:
SextantePostprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
self.executed = True
self.setInfo("Algorithm %s finished" % self.alg.name)
QApplication.restoreOverrideCursor()
@@ -306,8 +298,7 @@ def finish(self):
self.setInfo("HTML output has been generated by this algorithm.\nOpen the SEXTANTE results dialog to check it.")

@pyqtSlot(str)
def error(self, msg):
#self.algEx.finished.disconnect()
def error(self, msg):
QApplication.restoreOverrideCursor()
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
self.setInfo(msg, True)
@@ -316,7 +307,7 @@ def error(self, msg):
self.close()
else:
self.resetGUI()
self.setInfo(msg, True)
#self.setInfo(msg, True)
self.tabWidget.setCurrentIndex(1) # log tab

@pyqtSlot(int)
@@ -29,6 +29,9 @@
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteUtils import SextanteUtils
from sextante.tools.vector import getfeatures
from sextante.gui.SextantePostprocessing import SextantePostprocessing
import sextante
import sys

class AlgorithmExecutor(QThread):
@@ -74,11 +77,9 @@ def setConsoleInfo(self, info):
layerfile = alg.getParameterValue(self.parameterToIterate)
layer = QGisLayers.getObjectFromUri(layerfile, False)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
feat = QgsFeature()
features = getfeatures(layer)
self.filelist = []
while provider.nextFeature(feat):
for feat in features:
output = SextanteUtils.getTempFilename("shp")
self.filelist.append(output)
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() )
@@ -94,7 +95,8 @@ def raiseInternalError(self, error):
def runalg(self):
try:
self.algorithm.execute(self.progress)
self.algExecuted.emit()
if not self.parameterToIterate:
self.algExecuted.emit()
except GeoAlgorithmExecutionException, e :
self.error.emit(e.msg)
except BaseException, e:
@@ -123,8 +125,10 @@ def runalgIterating(self):
self.progress.setText("Executing iteration " + str(i) + "/" + str(len(self.filelist)) + "...")
self.progress.setPercentage((i * 100) / len(self.filelist))
self.runalg()
SextantePostprocessing.handleAlgorithmResults(self.algorithm, self.progress, False)
self.iterated.emit(i)
i += 1
self.algExecuted.emit()
except BaseException, e:
self.error.emit(str(e))
print "Error iterating " + str(e)
@@ -279,7 +279,7 @@ def fillTreeUsingCategories(self):
if (text != ""):
self.algorithmTree.expandAll()

def fillTreeUsingProviders(self):
def fillTreeUsingProviders(self):
self.algorithmTree.clear()
text = unicode(self.searchBox.text())
for providerName in Sextante.algs.keys():
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.tools.vector import getfeatures

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -55,17 +56,16 @@ def runalgIterating(alg,paramToIter,progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
layerfile = alg.getParameterValue(paramToIter)
layer = QGisLayers.getObjectFromUri(layerfile, False)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
layer = QGisLayers.getObjectFromUri(layerfile, False)
feat = QgsFeature()
filelist = []
outputs = {}
while provider.nextFeature(feat):
provider = layer.dataProvider()
features = getfeatures(layer)
for feat in features:
output = SextanteUtils.getTempFilename("shp")
filelist.append(output)
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() )
writer = QgsVectorFileWriter(output, systemEncoding, provider.fields(), provider.geometryType(), layer.crs() )
writer.addFeature(feat)
del writer

@@ -187,7 +187,7 @@ def setupUi(self):
self.defaultTextBox = QtGui.QLineEdit()
self.defaultTextBox.setText("0")
if self.param is not None:
self.defaultTextBox.setText(self.param.default)
self.defaultTextBox.setText(str(self.param.default))
self.horizontalLayout3.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayout3)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING \
@@ -206,16 +206,17 @@ def setupUi(self):
self.fileFolderCombo.addItem("Folder")
self.horizontalLayout2.addWidget(self.fileFolderCombo)
if self.param is not None:
self.fileFolderCombo.setCurrentIndex(1 if self.param.isFolder else 0)
self.fileFolderCombo.setCurrentIndex(1 if self.param.isFolder else 0)

self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed)
QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed)

self.verticalLayout.addWidget(self.buttonBox)

self.setLayout(self.verticalLayout)


@@ -55,7 +55,7 @@ def setValue(self, field):

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
"|" + str(self.parent) + "|" + str(self.datatype)
"|" + str(self.parent) + "|" + str(self.datatype) + "|" + str(self.optional)

def deserialize(self, s):
tokens = s.split("|")

0 comments on commit d927756

Please sign in to comment.
You can’t perform that action at this time.