Skip to content

Commit f10f755

Browse files
author
volayaf
committedJul 30, 2012
changed region mechanism in grass. Now it is set in each execution, using an extent parameter. This is a more flexible mechanism, with more possibilities
ExtentPanel now can be set to the min covering extent of input values. This is the default value, when the text box is blank, except when it is not possible to do so. git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@318 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent b5d83c0 commit f10f755

10 files changed

+249
-90
lines changed
 

‎.settings/org.eclipse.core.resources.prefs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#Thu Jun 07 09:09:17 CEST 2012
1+
#Sat Jul 28 13:07:03 CEST 2012
22
eclipse.preferences.version=1
33
encoding//src/sextante/ftools/ftools_utils.py=utf-8
4+
encoding//src/sextante/gui/AlgorithmExecutionDialog.py=latin1
45
encoding//src/sextante/gui/ParametersDialog.py=latin1
56
encoding//src/sextante/gui/ui_ParametersDialog.py=utf-8
67
encoding//src/sextante/gui/ui_SextanteToolbox.py=utf-8

‎src/sextante/grass/GrassAlgorithm.py

Lines changed: 89 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
from sextante.core.LayerExporter import LayerExporter
2424
from sextante.core.WrongHelpFileException import WrongHelpFileException
2525
from sextante.outputs.OutputFile import OutputFile
26+
from sextante.parameters.ParameterExtent import ParameterExtent
27+
from sextante.parameters.ParameterNumber import ParameterNumber
2628

2729
class GrassAlgorithm(GeoAlgorithm):
2830

31+
GRASS_REGION_EXTENT_PARAMETER = "GRASS_REGION_PARAMETER"
32+
GRASS_REGION_CELLSIZE_PARAMETER = "GRASS_REGION_CELLSIZE_PARAMETER"
33+
2934
def __init__(self, descriptionfile):
3035
GeoAlgorithm.__init__(self)
3136
self.descriptionFile = descriptionfile
@@ -98,55 +103,67 @@ def defineCharacteristicsFromFile(self):
98103
raise e
99104
lines.close()
100105

101-
def calculateRegion(self):
102-
auto = SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION)
103-
if auto:
104-
try:
105-
self.cellsize = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_CELLSIZE)
106-
except Exception:
107-
self.cellsize = 0;
108-
first = True;
109-
for param in self.parameters:
110-
if param.value:
111-
if isinstance(param, (ParameterRaster, ParameterVector)):
112-
if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
113-
layer = param.value
114-
else:
115-
layer = QGisLayers.getObjectFromUri(param.value)
116-
self.addToRegion(layer, first)
117-
first = False
118-
elif isinstance(param, ParameterMultipleInput):
119-
layers = param.value.split(";")
120-
for layername in layers:
121-
layer = QGisLayers.getObjectFromUri(layername, first)
122-
self.addToRegion(layer, first)
123-
first = False
124-
if self.cellsize == 0:
125-
self.cellsize = 1
126-
else:
127-
self.xmin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMIN)
128-
self.xmax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMAX)
129-
self.ymin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMIN)
130-
self.ymax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMAX)
131-
self.cellsize = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_CELLSIZE)
132-
133-
134-
def addToRegion(self, layer, first):
135-
if first:
136-
self.xmin = layer.extent().xMinimum()
137-
self.xmax = layer.extent().xMaximum()
138-
self.ymin = layer.extent().yMinimum()
139-
self.ymax = layer.extent().yMaximum()
140-
if isinstance(layer, QgsRasterLayer):
141-
self.cellsize = (layer.extent().xMaximum() - layer.extent().xMinimum())/layer.width()
142-
else:
143-
self.xmin = min(self.xmin, layer.extent().xMinimum())
144-
self.xmax = max(self.xmax, layer.extent().xMaximum())
145-
self.ymin = min(self.ymin, layer.extent().yMinimum())
146-
self.ymax = max(self.ymax, layer.extent().yMaximum())
147-
if isinstance(layer, QgsRasterLayer):
148-
self.cellsize = max(self.cellsize, (layer.extent().xMaximum() - layer.extent().xMinimum())/layer.width())
106+
#=======================================================================
107+
# self.xmin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMIN)
108+
# self.xmax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMAX)
109+
# self.ymin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMIN)
110+
# self.ymax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMAX)
111+
# extentString = str(self.xmin) + "," + str(self.xmax) + str(self.xmin) + "," + str(self.xmax)
112+
# self.cellsize = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_CELLSIZE)
113+
#=======================================================================
114+
self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, "GRASS region extent"))
115+
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize", 0, None, 1))
149116

117+
#===============================================================================
118+
# def calculateRegion(self):
119+
# auto = SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION)
120+
# if auto:
121+
# try:
122+
# self.cellsize = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_CELLSIZE)
123+
# except Exception:
124+
# self.cellsize = 0;
125+
# first = True;
126+
# for param in self.parameters:
127+
# if param.value:
128+
# if isinstance(param, (ParameterRaster, ParameterVector)):
129+
# if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
130+
# layer = param.value
131+
# else:
132+
# layer = QGisLayers.getObjectFromUri(param.value)
133+
# self.addToRegion(layer, first)
134+
# first = False
135+
# elif isinstance(param, ParameterMultipleInput):
136+
# layers = param.value.split(";")
137+
# for layername in layers:
138+
# layer = QGisLayers.getObjectFromUri(layername, first)
139+
# self.addToRegion(layer, first)
140+
# first = False
141+
# if self.cellsize == 0:
142+
# self.cellsize = 1
143+
# else:
144+
# self.xmin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMIN)
145+
# self.xmax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMAX)
146+
# self.ymin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMIN)
147+
# self.ymax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_YMAX)
148+
# self.cellsize = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_CELLSIZE)
149+
#
150+
#
151+
# def addToRegion(self, layer, first):
152+
# if first:
153+
# self.xmin = layer.extent().xMinimum()
154+
# self.xmax = layer.extent().xMaximum()
155+
# self.ymin = layer.extent().yMinimum()
156+
# self.ymax = layer.extent().yMaximum()
157+
# if isinstance(layer, QgsRasterLayer):
158+
# self.cellsize = (layer.extent().xMaximum() - layer.extent().xMinimum())/layer.width()
159+
# else:
160+
# self.xmin = min(self.xmin, layer.extent().xMinimum())
161+
# self.xmax = max(self.xmax, layer.extent().xMaximum())
162+
# self.ymin = min(self.ymin, layer.extent().yMinimum())
163+
# self.ymax = max(self.ymax, layer.extent().yMaximum())
164+
# if isinstance(layer, QgsRasterLayer):
165+
# self.cellsize = max(self.cellsize, (layer.extent().xMaximum() - layer.extent().xMinimum())/layer.width())
166+
#===============================================================================
150167

151168
def processAlgorithm(self, progress):
152169
if SextanteUtils.isWindows():
@@ -157,15 +174,17 @@ def processAlgorithm(self, progress):
157174
commands = []
158175
self.exportedLayers = {}
159176

160-
self.calculateRegion()
177+
#self.calculateRegion()
178+
region = str(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER))
179+
regionCoords = region.split(",")
161180
GrassUtils.createTempMapset();
162181

163182
command = "g.region"
164-
command += " n=" + str(self.ymax)
165-
command +=" s=" + str(self.ymin)
166-
command +=" e=" + str(self.xmax)
167-
command +=" w=" + str(self.xmin)
168-
command +=" res=" + str(self.cellsize);
183+
command += " n=" + str(regionCoords[3])
184+
command +=" s=" + str(regionCoords[2])
185+
command +=" e=" + str(regionCoords[1])
186+
command +=" w=" + str(regionCoords[0])
187+
command +=" res=" + str(self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER));
169188
commands.append(command)
170189

171190
#1: Export layer to grass mapset
@@ -200,6 +219,8 @@ def processAlgorithm(self, progress):
200219
for param in self.parameters:
201220
if param.value == None:
202221
continue
222+
if param.name == self.GRASS_REGION_CELLSIZE_PARAMETER or param.name == self.GRASS_REGION_EXTENT_PARAMETER:
223+
continue
203224
if isinstance(param, (ParameterRaster, ParameterVector)):
204225
value = param.value
205226
if value in self.exportedLayers.keys():
@@ -306,15 +327,17 @@ def getTempFilename(self):
306327
def commandLineName(self):
307328
return "grass:" + self.name[:self.name.find(" ")]
308329

309-
def checkBeforeOpeningParametersDialog(self):
310-
for param in self.parameters:
311-
if isinstance(param, (ParameterRaster, ParameterVector)):
312-
return None
313-
if isinstance(param, ParameterMultipleInput):
314-
if not param.optional:
315-
return None
316-
317-
if SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION):
318-
return "This algorithm cannot be run with the 'auto-region' setting\nPlease set a GRASS region before running it"
319-
else:
320-
return None
330+
#===============================================================================
331+
# def checkBeforeOpeningParametersDialog(self):
332+
# for param in self.parameters:
333+
# if isinstance(param, (ParameterRaster, ParameterVector)):
334+
# return None
335+
# if isinstance(param, ParameterMultipleInput):
336+
# if not param.optional:
337+
# return None
338+
#
339+
# if SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION):
340+
# return "This algorithm cannot be run with the 'auto-region' setting\nPlease set a GRASS region before running it"
341+
# else:
342+
# return None
343+
#===============================================================================

‎src/sextante/grass/GrassAlgorithmProvider.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ class GrassAlgorithmProvider(AlgorithmProvider):
1414

1515
def __init__(self):
1616
AlgorithmProvider.__init__(self)
17-
self.actions.append(DefineGrassRegionAction())
18-
self.actions.append(DefineGrassRegionFromLayerAction())
17+
#=======================================================================
18+
# self.actions.append(DefineGrassRegionAction())
19+
# self.actions.append(DefineGrassRegionFromLayerAction())
20+
#=======================================================================
1921
self.createAlgsList() #preloading algorithms to speed up
2022

2123
def initializeSettings(self):
@@ -25,27 +27,31 @@ def initializeSettings(self):
2527
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_WIN_SHELL, "Msys folder", GrassUtils.grassWinShell()))
2628
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_LOG_COMMANDS, "Log execution commands", False))
2729
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_LOG_CONSOLE, "Log console output", False))
28-
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_AUTO_REGION, "Use min covering region", True))
30+
#SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_AUTO_REGION, "Use min covering region", True))
2931
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_LATLON, "Coordinates are lat/lon", False))
30-
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_XMIN, "GRASS Region min x", 0))
31-
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_YMIN, "GRASS Region min y", 0))
32-
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_XMAX, "GRASS Region max x", 1000))
33-
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_YMAX, "GRASS Region max y", 1000))
34-
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_CELLSIZE, "GRASS Region cellsize", 100))
32+
#=======================================================================
33+
# SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_XMIN, "GRASS Region min x", 0))
34+
# SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_YMIN, "GRASS Region min y", 0))
35+
# SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_XMAX, "GRASS Region max x", 1000))
36+
# SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_YMAX, "GRASS Region max y", 1000))
37+
# SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_CELLSIZE, "GRASS Region cellsize", 100))
38+
#=======================================================================
3539
SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_HELP_FOLDER, "GRASS help folder", GrassUtils.grassHelpPath()))
3640

3741
def unload(self):
3842
AlgorithmProvider.unload(self)
3943
if SextanteUtils.isWindows() or SextanteUtils.isMac():
4044
SextanteConfig.removeSetting(GrassUtils.GRASS_FOLDER)
4145
SextanteConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
42-
SextanteConfig.removeSetting(GrassUtils.GRASS_AUTO_REGION)
46+
#SextanteConfig.removeSetting(GrassUtils.GRASS_AUTO_REGION)
4347
SextanteConfig.removeSetting(GrassUtils.GRASS_LATLON)
44-
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMIN)
45-
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMIN)
46-
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMAX)
47-
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMAX)
48-
SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_CELLSIZE)
48+
#=======================================================================
49+
# SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMIN)
50+
# SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMIN)
51+
# SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMAX)
52+
# SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMAX)
53+
# SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_CELLSIZE)
54+
#=======================================================================
4955
SextanteConfig.removeSetting(GrassUtils.GRASS_HELP_FOLDER)
5056
SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
5157
SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)

‎src/sextante/grass/GrassUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class GrassUtils:
1111

1212
GRASS_LATLON = "GRASS_LATLON"
13-
GRASS_AUTO_REGION = "GRASS_AUTO_REGION"
13+
#GRASS_AUTO_REGION = "GRASS_AUTO_REGION"
1414
GRASS_REGION_XMIN = "GRASS_REGION_XMIN"
1515
GRASS_REGION_YMIN = "GRASS_REGION_YMIN"
1616
GRASS_REGION_XMAX = "GRASS_REGION_XMAX"

‎src/sextante/grass/description/r.carve.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ParameterNumber|width|Stream width (in meters). Default is raster cell width|Non
77
ParameterNumber|depth|Additional stream depth (in meters)|None|None|1
88
ParameterBoolean|-n|No flat areas allowed in flow direction|False
99
OutputRaster|output|Name for output raster map
10-
OutputVector|points|ame for output vector map for adjusted stream points
10+
OutputVector|points|Name for output vector map for adjusted stream points

‎src/sextante/gui/AlgorithmExecutionDialog.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,19 @@ def setParamValues(self):
105105
for param in params:
106106
if param.hidden:
107107
continue
108+
if isinstance(param, ParameterExtent):
109+
continue
108110
if not self.setParamValue(param, self.paramTable.valueItems[param.name]):
109111
return False
110112

113+
for param in params:
114+
if isinstance(param, ParameterExtent):
115+
value = self.paramTable.valueItems[param.name].getValue()
116+
if value is not None:
117+
param.value = value
118+
else:
119+
return False
120+
111121
for output in outputs:
112122
if output.hidden:
113123
continue

‎src/sextante/gui/ExtentSelectionPanel.py

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1+
from qgis.core import *
12
from PyQt4 import QtGui, QtCore
23
from PyQt4.QtCore import *
34
from PyQt4.QtGui import *
45
from sextante.gui.RectangleMapTool import RectangleMapTool
56
from sextante.core.QGisLayers import QGisLayers
7+
from sextante.parameters.ParameterRaster import ParameterRaster
8+
from sextante.parameters.ParameterVector import ParameterVector
9+
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
610

711

812
class ExtentSelectionPanel(QtGui.QWidget):
913

10-
def __init__(self, dialog, default):
14+
def __init__(self, dialog, alg, default):
1115
super(ExtentSelectionPanel, self).__init__(None)
1216
self.dialog = dialog
17+
self.params = alg.parameters
1318
self.horizontalLayout = QtGui.QHBoxLayout(self)
1419
self.horizontalLayout.setSpacing(2)
1520
self.horizontalLayout.setMargin(0)
1621
self.text = QtGui.QLineEdit()
17-
self.text.setText(default)
22+
#self.text.setText(default)
1823
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
24+
if self.canUseAutoExtent():
25+
if hasattr(self.text, 'setPlaceholderText'):
26+
self.text.setPlaceholderText("[Leave blank to use min covering extent]")
1927
self.horizontalLayout.addWidget(self.text)
2028
self.pushButton = QtGui.QPushButton()
2129
self.pushButton.setText("...")
@@ -27,6 +35,15 @@ def __init__(self, dialog, default):
2735
self.tool = RectangleMapTool(canvas)
2836
self.connect(self.tool, SIGNAL("rectangleCreated()"), self.fillCoords)
2937

38+
def canUseAutoExtent(self):
39+
for param in self.params:
40+
if isinstance(param, (ParameterRaster, ParameterVector)):
41+
return True
42+
if isinstance(param, ParameterMultipleInput):
43+
return True
44+
45+
return False
46+
3047
def buttonPushed(self):
3148
popupmenu = QMenu()
3249
useLayerExtentAction = QtGui.QAction("Use layer/canvas extent", self.pushButton)
@@ -35,8 +52,55 @@ def buttonPushed(self):
3552
selectOnCanvasAction = QtGui.QAction("Select extent on canvas", self.pushButton)
3653
selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
3754
popupmenu.addAction(selectOnCanvasAction)
55+
if self.canUseAutoExtent():
56+
useMincoveringExtentAction = QtGui.QAction("Use min convering extent from input layers", self.pushButton)
57+
useMincoveringExtentAction.triggered.connect(self.useMinCoveringExtent)
58+
popupmenu.addAction(useMincoveringExtentAction)
59+
3860
popupmenu.exec_(QtGui.QCursor.pos())
3961

62+
def useMinCoveringExtent(self):
63+
self.text.setText("");
64+
65+
def getMinCoveringExtent(self):
66+
first = True
67+
found = False
68+
for param in self.params:
69+
if param.value:
70+
if isinstance(param, (ParameterRaster, ParameterVector)):
71+
found = True
72+
if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
73+
layer = param.value
74+
else:
75+
layer = QGisLayers.getObjectFromUri(param.value)
76+
self.addToRegion(layer, first)
77+
first = False
78+
elif isinstance(param, ParameterMultipleInput):
79+
found = True
80+
layers = param.value.split(";")
81+
for layername in layers:
82+
layer = QGisLayers.getObjectFromUri(layername, first)
83+
self.addToRegion(layer, first)
84+
first = False
85+
if found:
86+
return str(self.xmin) + "," + str(self.xmax) + "," + str(self.ymin) + "," + str(self.ymax)
87+
else:
88+
return None
89+
90+
91+
92+
def addToRegion(self, layer, first):
93+
if first:
94+
self.xmin = layer.extent().xMinimum()
95+
self.xmax = layer.extent().xMaximum()
96+
self.ymin = layer.extent().yMinimum()
97+
self.ymax = layer.extent().yMaximum()
98+
else:
99+
self.xmin = min(self.xmin, layer.extent().xMinimum())
100+
self.xmax = max(self.xmax, layer.extent().xMaximum())
101+
self.ymin = min(self.ymin, layer.extent().yMinimum())
102+
self.ymax = max(self.ymax, layer.extent().yMaximum())
103+
40104
def useLayerExtent(self):
41105
extentsDict = {}
42106
extentsDict["[Canvas]"] = QGisLayers.iface.mapCanvas().extent()
@@ -71,4 +135,7 @@ def setValueFromRect(self,r):
71135

72136

73137
def getValue(self):
74-
return str(self.text.text())
138+
if str(self.text.text()).strip() != "":
139+
return str(self.text.text())
140+
else:
141+
return self.getMinCoveringExtent()

‎src/sextante/gui/ParametersPanel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ def initGUI(self):
137137
self.verticalLayout.addStretch(1000)
138138
self.setLayout(self.verticalLayout)
139139

140+
#=======================================================================
141+
# for param in self.alg.parameters:
142+
# if isinstance(param, ParameterExtent):
143+
# self.widgets[param.name].useMinCovering()
144+
#=======================================================================
145+
140146
def showAdvancedParametersClicked(self):
141147
self.showAdvanced = not self.showAdvanced
142148
if self.showAdvanced:
@@ -247,7 +253,7 @@ def getWidgetFromParameter(self, param):
247253
elif isinstance(param, ParameterNumber):
248254
item = NumberInputPanel(param.default, param.isInteger)
249255
elif isinstance(param, ParameterExtent):
250-
item = ExtentSelectionPanel(self.parent, param.default)
256+
item = ExtentSelectionPanel(self.parent, self.alg, param.default)
251257
elif isinstance(param, ParameterCrs):
252258
item = CrsSelectionPanel(param.default)
253259
else:

‎src/sextante/modeler/ModelerParameterDefinitionDialog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sextante.parameters.ParameterNumber import ParameterNumber
1010
from sextante.parameters.ParameterString import ParameterString
1111
from sextante.parameters.ParameterTableField import ParameterTableField
12+
from sextante.parameters.ParameterExtent import ParameterExtent
1213

1314

1415
class ModelerParameterDefinitionDialog(QtGui.QDialog):
@@ -20,11 +21,12 @@ class ModelerParameterDefinitionDialog(QtGui.QDialog):
2021
PARAMETER_STRING="String"
2122
PARAMETER_BOOLEAN="Boolean"
2223
PARAMETER_TABLE_FIELD="Table field"
24+
PARAMETER_EXTENT="Extent"
2325
#TO ADD
2426
PARAMETER_MULTIPLE="Multiple input"
2527
PARAMETER_FIXED_TABLE="Fixed table"
2628

27-
paramTypes = [PARAMETER_BOOLEAN,PARAMETER_NUMBER, PARAMETER_RASTER,
29+
paramTypes = [PARAMETER_BOOLEAN,PARAMETER_NUMBER, PARAMETER_RASTER, PARAMETER_EXTENT,
2830
PARAMETER_STRING, PARAMETER_VECTOR, PARAMETER_TABLE, PARAMETER_TABLE_FIELD]
2931

3032
def __init__(self, alg, paramType = None, param = None):
@@ -66,7 +68,7 @@ def setupUi(self):
6668
self.yesNoCombo.addItem("No")
6769
self.horizontalLayout2.addWidget(self.yesNoCombo)
6870
self.verticalLayout.addLayout(self.horizontalLayout2)
69-
if self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD \
71+
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD \
7072
or isinstance(self.param, ParameterTableField):
7173
self.horizontalLayout2.addWidget(QtGui.QLabel("Parent layer"))
7274
self.parentCombo = QtGui.QComboBox()

‎src/sextante/modeler/ModelerParametersDialog.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from sextante.parameters.ParameterFile import ParameterFile
2424
from sextante.outputs.OutputFile import OutputFile
2525
from sextante.core.WrongHelpFileException import WrongHelpFileException
26+
from sextante.parameters.ParameterExtent import ParameterExtent
2627

2728
class ModelerParametersDialog(QtGui.QDialog):
2829

@@ -159,6 +160,13 @@ def getTables(self):
159160

160161
return tables
161162

163+
def getExtents(self):
164+
extents = []
165+
params = self.model.parameters
166+
for param in params:
167+
if isinstance(param, ParameterExtent):
168+
extents.append(AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, param.name, "", param.description))
169+
162170
def getNumbers(self):
163171
numbers = []
164172
params = self.model.parameters
@@ -295,6 +303,13 @@ def getWidgetFromParameter(self, param):
295303
for n in numbers:
296304
item.addItem(n.name(), n)
297305
item.setEditText(str(param.default))
306+
elif isinstance(param, ParameterExtent):
307+
item = QtGui.QComboBox()
308+
item.setEditable(True)
309+
extents = self.getExtents()
310+
for ex in extents:
311+
item.addItem(ex.name(), ex)
312+
item.setEditText(str(param.default))
298313
elif isinstance(param, ParameterFile):
299314
item = QtGui.QComboBox()
300315
item.setEditable(True)
@@ -513,6 +528,27 @@ def setParamNumberValue(self, param, widget):
513528
self.params[param.name] = value
514529
return True
515530

531+
def setParamExtentValue(self, param, widget):
532+
idx = widget.findText(widget.currentText())
533+
if idx < 0:
534+
name = self.getSafeNameForHarcodedParameter(param)
535+
value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
536+
self.params[param.name] = value
537+
s = str(widget.currentText())
538+
try:
539+
tokens = s.split(",")
540+
if len(tokens) != 4:
541+
return False
542+
for token in tokens:
543+
float(token)
544+
except:
545+
return False
546+
self.values[name] = s
547+
else:
548+
value = widget.itemData(widget.currentIndex()).toPyObject()
549+
self.params[param.name] = value
550+
return True
551+
516552
def setParamValue(self, param, widget):
517553
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
518554
return self.setParamValueLayerOrTable(param, widget)
@@ -522,6 +558,8 @@ def setParamValue(self, param, widget):
522558
return self.setParamStringValue(param, widget)
523559
elif isinstance(param, ParameterNumber):
524560
return self.setParamNumberValue(param, widget)
561+
elif isinstance(param, ParameterExtent):
562+
return self.setParamExtentValue(param, widget)
525563
elif isinstance(param, ParameterFile):
526564
return self.setParamFileValue(param, widget)
527565
elif isinstance(param, ParameterSelection):
@@ -542,7 +580,7 @@ def setParamValue(self, param, widget):
542580
self.params[param.name] = value
543581
self.values[name] = ParameterFixedTable.tableToString(widget.table)
544582
return True
545-
if isinstance(param, ParameterTableField):
583+
elif isinstance(param, ParameterTableField):
546584
return self.setParamTableFieldValue(param, widget)
547585
elif isinstance(param, ParameterMultipleInput):
548586
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
@@ -559,6 +597,12 @@ def setParamValue(self, param, widget):
559597
self.params[param.name] = value
560598
self.values[name] = ";".join(values)
561599
return True
600+
else:
601+
name = self.getSafeNameForHarcodedParameter(param)
602+
value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
603+
self.params[param.name] = value
604+
self.values[name] = str(widget.getText())
605+
return True
562606

563607
def getSafeNameForHarcodedParameter(self, param):
564608
if self.algIndex is None:

0 commit comments

Comments
 (0)
Please sign in to comment.