-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGPFParametersPanel.py
275 lines (242 loc) · 12.2 KB
/
GPFParametersPanel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
"""
***************************************************************************
GPFParametersPanel.py
-------------------------------------
Copyright (C) 2014 TIGER-NET (www.tiger-net.org)
***************************************************************************
* This plugin is part of the Water Observation Information System (WOIS) *
* developed under the TIGER-NET project funded by the European Space *
* Agency as part of the long-term TIGER initiative aiming at promoting *
* the use of Earth Observation (EO) for improved Integrated Water *
* Resources Management (IWRM) in Africa. *
* *
* WOIS is a free software i.e. you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, either version 3 of the License, *
* or (at your option) any later version. *
* *
* WOIS is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
* for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************
"""
from processing.gui.ParametersPanel import ParametersPanel
from processing_gpf.GPFUtils import GPFUtils
from processing_gpf.GPFParameters import ParameterBands, ParameterPolarisations, ParameterPixelSize
from PyQt4 import QtGui, QtCore
# GPF parameters panel is the same as normal parameters panel except
# it can also handle ParameterBands, ParameterPolarisations and
# ParameterPixelSize with special UI
class GPFParametersPanel(ParametersPanel):
def getWidgetFromParameter(self, param):
if isinstance(param, ParameterPolarisations):
item = GPFPolarisationsSelectorPanel(param.default, self.parent, self.alg.programKey, param.bandSourceRaster, False)
elif isinstance(param, ParameterBands):
item = GPFBandsSelectorPanel(param.default, self.parent, self.alg.programKey, param.bandSourceRaster, False)
# Special treatment for S1 Toolbox Terrain-Correction to get pixel sizes from SAR image
elif isinstance(param, ParameterPixelSize):
item = S1TbxPixelSizeInputPanel(param.default, param.isInteger, self.parent, self.alg.programKey)
else:
item = ParametersPanel.getWidgetFromParameter(self, param)
return item
# Special functionality for S1 Toolbox terrain-correction
# S1 Toolbox pixel size input panel is the same as normal number
# input panel except that it has a button next to it
# to show selected products pixel size.
class S1TbxPixelSizeInputPanel(QtGui.QWidget):
def __init__(self, default, isInteger, parent, programKey):
QtGui.QWidget.__init__(self)
self.parent = parent
self.programKey = programKey
self.numberPanel = QtGui.QLineEdit()
self.numberPanel.setText(str(default))
self.metadataButton = QtGui.QPushButton()
self.metadataButton.setMaximumWidth(75)
self.metadataButton.setText("Pixel Size")
self.metadataButton.clicked.connect(self.showMetadataDialog)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.addWidget(self.numberPanel)
self.horizontalLayout.addWidget(self.metadataButton)
def showMetadataDialog(self):
sourceProduct = self.parent.getRasterParamPath("sourceProduct")
pixelSizes = GPFUtils.getS1TbxPixelSize(sourceProduct, self.programKey)
dlg = S1TbxPixelSizeInputDialog(pixelSizes, sourceProduct, self.parent)
dlg.show()
def getValue(self):
return self.numberPanel.text()
def text(self):
return self.getValue()
# Simple dialog displaying SAR image pixel sizes
class S1TbxPixelSizeInputDialog(QtGui.QDialog):
def __init__(self, pixelSizes, filename, parent):
self.pixelSizes = pixelSizes
self.filename = filename
QtGui.QDialog.__init__(self, parent)
self.setWindowModality(0)
self.setupUi()
def setupUi(self):
self.resize(500, 180)
self.setWindowTitle("Pixel Sizes: "+str(self.filename))
self.verticalLayout = QtGui.QVBoxLayout(self)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.table = QtGui.QTableWidget()
self.table.setColumnCount(1)
self.table.setColumnWidth(0,270)
self.table.verticalHeader().setVisible(False)
self.table.horizontalHeader().setVisible(False)
self.table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.setTableContent()
self.horizontalLayout.addWidget(self.table)
self.setLayout(self.horizontalLayout)
self.verticalLayout.addLayout(self.horizontalLayout)
def setTableContent(self):
self.table.setRowCount(len(self.pixelSizes))
i=0
for k,v in self.pixelSizes.items():
item = QtGui.QLineEdit()
item.setReadOnly(True)
text = str(k).strip() + ":\t\t" + str(v).strip()
item.setText(text)
self.table.setCellWidget(i,0, item)
i += 1
# GPF bands selector panel is the same as normal text panel
# except that it has a button next to it to show band names
class GPFBandsSelectorPanel(QtGui.QWidget):
def __init__(self, default, parent, programKey, bandSourceRaster, appendProductName):
QtGui.QWidget.__init__(self)
self.parent = parent
self.appendProductName = appendProductName
self.bandSourceRaster = bandSourceRaster
self.programKey = programKey
self.bandsPanel = QtGui.QLineEdit()
self.bandsPanel.setText(str(default))
self.bandsButton = QtGui.QPushButton()
self.bandsButton.setMaximumWidth(85)
self.bandsButton.setText("Bands")
self.bandsButton.clicked.connect(self.showBandsDialog)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.addWidget(self.bandsPanel)
self.horizontalLayout.addWidget(self.bandsButton)
def setBandsPanel(self, bands):
self.bandsPanel.setText(bands)
def showBandsDialog(self):
bands = GPFUtils.getBeamBandNames(self.getFilePath(), self.programKey, self.appendProductName)
dlg = GPFBandsListDialog(bands, self.getFilePath(), self)
dlg.show()
def getFilePath(self):
value = self.parent.getRasterParamPath(self.bandSourceRaster)
return value
def getValue(self):
return self.bandsPanel.text()
def text(self):
return self.getValue()
# Simple dialog displaying a list of bands
class GPFBandsListDialog(QtGui.QDialog):
def __init__(self, bands, filename, parent):
self.bands = bands
self.selectedBands = []
self.filename = filename
QtGui.QDialog.__init__(self, parent)
self.parent = parent
self.setWindowModality(0)
self.setupUi()
def setupUi(self):
self.resize(381, 320)
self.setWindowTitle("Band names: "+str(self.filename))
self.verticalLayout = QtGui.QVBoxLayout(self)
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Vertical)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Close)
self.selectAllButton = QtGui.QPushButton()
self.selectAllButton.setText("(de)Select all")
self.buttonBox.addButton(self.selectAllButton, QtGui.QDialogButtonBox.ActionRole)
self.copyButton = QtGui.QPushButton()
self.copyButton.setText("Copy band names")
self.buttonBox.addButton(self.copyButton, QtGui.QDialogButtonBox.ActionRole)
self.setButton = QtGui.QPushButton()
self.setButton.setText("Set band names")
self.buttonBox.addButton(self.setButton, QtGui.QDialogButtonBox.ActionRole)
self.table = QtGui.QTableWidget()
self.table.setColumnCount(1)
self.table.setColumnWidth(0,270)
self.table.verticalHeader().setVisible(False)
self.table.horizontalHeader().setVisible(False)
self.table.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.setTableContent()
self.horizontalLayout.addWidget(self.table)
self.horizontalLayout.addWidget(self.buttonBox)
self.setLayout(self.horizontalLayout)
self.verticalLayout.addLayout(self.horizontalLayout)
self.label = QtGui.QLabel("Selected bands:")
self.verticalLayout.addWidget(self.label)
self.bandList = QtGui.QLineEdit()
self.verticalLayout.addWidget(self.bandList)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.close)
QtCore.QObject.connect(self.selectAllButton, QtCore.SIGNAL("clicked()"), self.selectAll)
QtCore.QObject.connect(self.copyButton, QtCore.SIGNAL("clicked()"), self.copyBands)
QtCore.QObject.connect(self.setButton, QtCore.SIGNAL("clicked()"), self.setBands)
QtCore.QMetaObject.connectSlotsByName(self)
def setTableContent(self):
self.table.setRowCount(len(self.bands))
for i in range(len(self.bands)):
item = QtGui.QCheckBox()
item.setText(self.bands[i])
self.table.setCellWidget(i,0, item)
QtCore.QObject.connect(item, QtCore.SIGNAL("stateChanged(int)"), self.updateBandList)
def updateBandList(self):
selectedBands = ""
for i in range(len(self.bands)):
widget = self.table.cellWidget(i, 0)
if widget.isChecked():
selectedBands+=widget.text()
selectedBands+=","
if selectedBands:
if selectedBands[-1] == ",":
selectedBands = selectedBands[:-1]
self.bandList.setText(selectedBands)
def selectAll(self):
checked = False
for i in range(len(self.bands)):
widget = self.table.cellWidget(i, 0)
if not widget.isChecked():
checked = True
break
for i in range(len(self.bands)):
widget = self.table.cellWidget(i, 0)
widget.setChecked(checked)
def copyBands(self):
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(self.bandList.text())
def setBands(self):
self.parent.setBandsPanel(self.bandList.text())
QtGui.QDialog.close(self)
def close(self):
QtGui.QDialog.close(self)
class GPFPolarisationsSelectorPanel(GPFBandsSelectorPanel):
def __init__(self, default, parent, programKey, bandSourceRaster, appendProductName):
super(GPFPolarisationsSelectorPanel, self).__init__(default, parent, programKey, bandSourceRaster, appendProductName)
self.bandsButton.setText("Polarisations")
def showBandsDialog(self):
polarisations = GPFUtils.getPolarisations(self.getFilePath())
dlg = GPFPolarisationsListDialog(polarisations, self.getFilePath(), self)
dlg.show()
class GPFPolarisationsListDialog(GPFBandsListDialog):
def setupUi(self):
super(GPFPolarisationsListDialog, self).setupUi()
self.setWindowTitle("Polarisations: "+str(self.filename))
self.copyButton.setText("Copy polarisations")
self.setButton.setText("Set polarisations")
self.label.setText("Selected polarisations:")