diff --git a/src/sextante/core/GeoAlgorithm.py b/src/sextante/core/GeoAlgorithm.py index 1b69e31b973..ab432d2a8c7 100644 --- a/src/sextante/core/GeoAlgorithm.py +++ b/src/sextante/core/GeoAlgorithm.py @@ -230,7 +230,8 @@ class GeoAlgorithm: return None def getAsCommand(self): - '''Returns the command that would run this same algorithm from the console''' + '''Returns the command that would run this same algorithm from the console. + Should return null if the algorithm can be run from the console.''' s="Sextante.runalg(\"" + self.commandLineName() + "\"," for param in self.parameters: s+=param.getValueAsCommandLineParameter() + "," diff --git a/src/sextante/grass/DefineGrassRegionAction.py b/src/sextante/grass/DefineGrassRegionAction.py new file mode 100644 index 00000000000..3ec2a897641 --- /dev/null +++ b/src/sextante/grass/DefineGrassRegionAction.py @@ -0,0 +1,39 @@ +import os +from PyQt4 import QtGui, QtCore +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from sextante.gui.ToolboxAction import ToolboxAction +from sextante.core.QGisLayers import QGisLayers +from sextante.gui.RectangleMapTool import RectangleMapTool +from sextante.core.SextanteConfig import SextanteConfig +from sextante.grass.GrassUtils import GrassUtils + +class DefineGrassRegionAction(ToolboxAction): + + def __init__(self): + self.name="Define GRASS region on canvas" + self.group="Tools" + canvas = QGisLayers.iface.mapCanvas() + self.prevMapTool = canvas.mapTool() + self.tool = RectangleMapTool(canvas) + QtCore.QObject.connect(self.tool, SIGNAL("rectangleCreated()"), self.fillCoords) + + def getIcon(self): + return QtGui.QIcon(os.path.dirname(__file__) + "/../images/grass.png") + + def execute(self): + QtGui.QMessageBox.information(None, "GRASS Region", "Click and drag onto map canvas to define GRASS region") + canvas = QGisLayers.iface.mapCanvas() + canvas.setMapTool(self.tool) + + def fillCoords(self): + r = self.tool.rectangle() + SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN, r.xMinimum()) + SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, r.yMinimum()) + SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, r.xMaximum()) + SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, r.yMaximum()) + s = str(r.xMinimum()) + "," + str(r.xMaximum()) + "," + str(r.yMinimum()) + "," + str(r.yMaximum()) + self.tool.reset() + canvas = QGisLayers.iface.mapCanvas() + canvas.setMapTool(self.prevMapTool) + QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s) diff --git a/src/sextante/grass/GrassAlgorithmProvider.py b/src/sextante/grass/GrassAlgorithmProvider.py index fba483ae771..ece019a3876 100644 --- a/src/sextante/grass/GrassAlgorithmProvider.py +++ b/src/sextante/grass/GrassAlgorithmProvider.py @@ -7,11 +7,13 @@ from sextante.core.SextanteLog import SextanteLog from sextante.grass.GrassUtils import GrassUtils from sextante.grass.GrassAlgorithm import GrassAlgorithm from sextante.core.SextanteUtils import SextanteUtils +from sextante.grass.DefineGrassRegionAction import DefineGrassRegionAction class GrassAlgorithmProvider(AlgorithmProvider): def __init__(self): AlgorithmProvider.__init__(self) + self.actions.append(DefineGrassRegionAction()) self.createAlgsList() #preloading algorithms to speed up def initializeSettings(self): diff --git a/src/sextante/gui/ParametersDialog.py b/src/sextante/gui/ParametersDialog.py index 546005f09b4..acc7f4b72c7 100644 --- a/src/sextante/gui/ParametersDialog.py +++ b/src/sextante/gui/ParametersDialog.py @@ -151,7 +151,9 @@ class Ui_ParametersDialog(object): QApplication.restoreOverrideCursor() else: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) - SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, self.alg.getAsCommand()) + command = self.alg.getAsCommand() + if command: + SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command) ret = AlgorithmExecutor.runalg(self.alg, self) QApplication.restoreOverrideCursor() if ret: diff --git a/src/sextante/modeler/ModelerAlgorithm.py b/src/sextante/modeler/ModelerAlgorithm.py index 130af4b6b8a..619a209e21e 100644 --- a/src/sextante/modeler/ModelerAlgorithm.py +++ b/src/sextante/modeler/ModelerAlgorithm.py @@ -153,8 +153,8 @@ class ModelerAlgorithm(GeoAlgorithm): return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(len(self.algs)) def serialize(self): - s="NAME:" + self.name + "\n" - s +="GROUP:" + self.group + "\n" + s="NAME:" + str(self.name) + "\n" + s +="GROUP:" + str(self.group) + "\n" i = 0 for param in self.parameters: @@ -326,6 +326,12 @@ class ModelerAlgorithm(GeoAlgorithm): return False + def getAsCommand(self): + if self.descriptionFile: + return GeoAlgorithm.getAsCommand(self) + else: + return None + def commandLineName(self): return "modeler:" + os.path.basename(self.descriptionFile)[:-5].lower() diff --git a/src/sextante/modeler/ModelerDialog.py b/src/sextante/modeler/ModelerDialog.py index 56b2d258cf3..57adfab7af8 100644 --- a/src/sextante/modeler/ModelerDialog.py +++ b/src/sextante/modeler/ModelerDialog.py @@ -12,6 +12,8 @@ from sextante.modeler.Providers import Providers from sextante.script.ScriptUtils import ScriptUtils from sextante.gui.HelpEditionDialog import HelpEditionDialog import pickle +from sextante.gui.ParametersDialog import ParametersDialog +from sextante.core.SextanteUtils import SextanteUtils class ModelerDialog(QtGui.QDialog): def __init__(self, alg=None): @@ -121,6 +123,9 @@ class ModelerDialog(QtGui.QDialog): self.editHelpButton = QtGui.QPushButton() self.editHelpButton.setText("Edit model help") self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole) + self.runButton = QtGui.QPushButton() + self.runButton.setText("Run") + self.buttonBox.addButton(self.runButton, QtGui.QDialogButtonBox.ActionRole) self.openButton = QtGui.QPushButton() self.openButton.setText("Open") self.buttonBox.addButton(self.openButton, QtGui.QDialogButtonBox.ActionRole) @@ -133,6 +138,7 @@ class ModelerDialog(QtGui.QDialog): QObject.connect(self.openButton, QtCore.SIGNAL("clicked()"), self.openModel) QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveModel) QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow) + QObject.connect(self.runButton, QtCore.SIGNAL("clicked()"), self.runModel) QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp) self.globalLayout = QtGui.QVBoxLayout() @@ -168,6 +174,23 @@ class ModelerDialog(QtGui.QDialog): fout.close() self.update = True + def runModel(self): + ##TODO: enable alg cloning without saving to file + if self.alg.descriptionFile is None: + self.alg.descriptionFile = SextanteUtils.getTempFilename("model") + text = self.alg.serialize() + fout = open(self.alg.descriptionFile, "w") + fout.write(text) + fout.close() + self.alg.provider = Providers.providers["Modeler"] + alg = copy.deepcopy(self.alg) + self.alg.descriptionFile = None + alg.descriptionFile = None + else: + alg = copy.deepcopy(self.alg) + dlg = ParametersDialog(alg) + dlg.exec_() + def saveModel(self): if str(self.textGroup.text()).strip() == "" or str(self.textName.text()).strip() == "": QMessageBox.warning(self, "Warning", "Please enter group and model names before saving")