-
Notifications
You must be signed in to change notification settings - Fork 3
/
ClassParameterDialog.py
362 lines (328 loc) · 15.3 KB
/
ClassParameterDialog.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Mascaret
Description : Mascaret parameters
Date : septembre 2017
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; 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. *
* *
***************************************************************************/
"""
import os
from qgis.PyQt.QtCore import *
from qgis.PyQt.uic import *
from qgis.core import *
from qgis.gui import *
if int(qVersion()[0]) < 5: # qt4
from qgis.PyQt.QtGui import *
else: # qt5
from qgis.PyQt.QtWidgets import *
class ClassParameterDialog(QDialog):
def __init__(self, mgis, kernel):
QDialog.__init__(self)
self.mgis = mgis
self.mdb = self.mgis.mdb
self.kernel = kernel
self.ui = loadUi(
os.path.join(self.mgis.masplugPath, 'ui/ui_parameter.ui'), self)
self.combo = {}
self.libel_var = []
self.variables = []
self.exclusion = {}
self.par = {}
self.init_ui()
self.ui.actionEvenement.triggered.connect(self.ch_event)
self.ui.actionRadioButton_law.triggered.connect(self.ch_event)
self.ui.buttonBox_valid.accepted.connect(self.accept_dialog)
self.ui.buttonBox_valid.rejected.connect(self.reject)
fct = self.selb(self.ui.box_velocity)
self.ui.actionbox_velocity.triggered.connect(fct)
fct = self.selb(self.ui.box_stress)
self.ui.actionbox_stress.triggered.connect(fct)
fct = self.selb(self.ui.box_hydro)
self.ui.actionbox_hydro.triggered.connect(fct)
fct = self.selb(self.ui.box_time)
self.ui.actionbox_time.triggered.connect(fct)
fct = self.selb(self.ui.box_coef)
self.ui.actionbox_coef.triggered.connect(fct)
fct = self.selb(self.ui.box_WaterLevel)
self.ui.actionbox_WaterLevel.triggered.connect(fct)
def init_ui(self):
"""initialisation GUI"""
self.combo = {'code': {1: 'Steady',
2: 'Unsteady',
3: 'Transcritical'},
'compositionLits': {0: 'Aucun',
1: 'Debord',
2: 'fond/berge'},
'option': {1: 'Sections de calcul',
2: 'couche Points de sortie'},
'postProcesseur': {1: 'Rubens',
2: 'Opthyca'},
'critereArret': {1: 'Temps maximum',
2: 'Nombre de pas de temps max',
3: 'Cote maximale de controle'},
}
self.libel_var = ["Bottom elevation",
"Left bank water level",
"Right bank water level",
"Minor friction coefficient",
"Major friction coefficient",
"Water level",
"Flow rate in minor river bed",
"Flow rate in major river bed",
"Wetted area of minor river bed",
"Wetted area of major river bed",
"Froude number",
"Coefficient beta of Debord's formula",
"Surface width of minor river bed",
"Surface width of major river bed",
"Surface width of storage area",
"Wetted perimeter of minor river bed",
"Wetted perimeter of major river bed",
"Hydaulic radius of minor river bed",
"Hydaulic radius of major river bed",
"Velocity of minor river bed",
"Velocity of major river bed",
"Bottom shear stress",
"Water depth",
"Average water depth",
"Flow rate in left major river bed",
"Flow rate in right major river bed",
"Wetted area of storage area",
"Cumulative volume of the active river bed",
"Cumulative volume of the storage area",
"Hydraulic head",
"Maximal water level",
"Date of maximal water level",
"Velocity for the maximal water level",
"Minimal water level",
"Date of minimal water level",
"Minimum minor river bed velocity",
"Maximum minor river bed velocity",
"Maximum surface width",
"Arrival time of the floodwave",
"Maximum flow rate",
"Date of maximum flow rate",
"Maximum energy",
"Total wetted area",
"Basin water level",
"Basin area",
"Basin volume",
"Link flow rate",
"Link velocity"
]
self.variables = ['ZREF',
'RGC',
'RDC',
'KMIN',
'KMAJ',
'Z',
'QMIN',
'QMAJ',
'S1',
'S2',
'FR',
'BETA',
'B1',
'B2',
'BS',
'P1',
'P2',
'RH1',
'RH2',
'VMIN',
'VMAJ',
'TAUF',
'Y',
'HMOY',
'Q2G',
'Q2D',
'SS',
'VOL',
'VOLS',
'CHAR',
'ZMAX',
'TZMA',
'VZMX',
'ZMIN',
'TZMI',
'VINF',
'VSUP',
'BMAX',
'TOND',
'QMAX',
'TQMA',
'EMAX',
'ATOT',
'ZCAS',
'SURCAS',
'VOLCAS',
'QECH',
'VECH'
]
# Q
self.exclusion = {'steady': ['presenceCasiers',
'elevCoteArrivFront',
'calcOndeSubmersion',
'froudeLimCondLim',
'traitImplicitFrot',
'implicitNoyauTrans',
'optimisNoyauTrans',
'perteChargeAutoElargissement',
'termesNonHydrostatiques',
'attenuationConvection',
'pasTempsVar',
'nbCourant',
'repriseCalcul',
'LigEauInit',
'modeEntree',
'fichLigEau',
'formatFichLig',
'initialisationAuto'],
'unsteady': ['elevCoteArrivFront',
'calcOndeSubmersion',
'froudeLimCondLim',
'traitImplicitFrot',
'implicitNoyauTrans',
'optimisNoyauTrans',
'perteChargeAutoElargissement',
'termesNonHydrostatiques',
'pasTempsVar',
'nbCourant',
'repriseCalcul'],
'transcritical': ['presenceCasiers',
'attenuationConvection',
'compositionLits',
'repriseCalcul']
}
self.create_dico_para()
self.init_gui()
def create_dico_para(self):
self.par = {}
# requete pour recuperer les parametres dans la base
sql = "SELECT parametre, {0}, libelle, gui, gui_type FROM {1}.{2};"
rows = self.mdb.run_query(
sql.format(self.kernel, self.mdb.SCHEMA, "parametres"), fetch=True)
for param, valeur, libelle, gui, gui_type in rows:
if gui_type == 'parameters':
if param == 'variablesStockees':
# valeurs = list(map(eval, valeur.title().split()))
valeurs = []
for var1 in valeur.title().split():
valeurs.append(eval(var1))
for var, val, lib in zip(self.variables, valeurs,
self.libel_var):
self.par[var] = {"val": val, "libelle": lib,
"gui": True, "gui_type": 'parameters'}
# self.par[var] = {"val": val, "libelle": lib}
else:
self.par[param] = {}
try:
self.par[param]["val"] = eval(valeur.title())
except:
self.par[param]["val"] = valeur
self.par[param]["libelle"] = libelle
self.par[param]["gui"] = self.str2bool(gui)
self.par[param]["gui_type"] = gui_type
def init_gui(self):
# pass
for param, info in self.par.items():
# self.mgis.add_info("param {} info {}".format(param, info))
if info['gui'] and info['gui_type'] == 'parameters':
obj = getattr(self.ui, param)
if isinstance(obj, QCheckBox):
obj.setChecked(info['val'])
elif isinstance(obj, QDoubleSpinBox) or isinstance(obj,
QSpinBox):
obj.setValue(info['val'])
elif obj == self.ui.evenement:
self.ui.evenement.setChecked(info['val'])
self.ch_event()
elif isinstance(obj, QComboBox):
if param == 'option':
val = info['val'] - 1
elif param == "compositionLits":
val = info['val']
elif param == "critereArret":
val = info['val'] - 1
elif param == 'postProcesseur':
val = info['val'] - 1
obj.setCurrentIndex(val)
else:
if self.mgis.DEBUG:
self.mgis.add_info(
"param {} obj {} val {}".format(param, obj,
info['val']))
if param in self.exclusion[self.kernel]:
obj.hide()
if isinstance(obj, QSpinBox) or isinstance(obj,
QDoubleSpinBox) \
or isinstance(obj, QComboBox):
getattr(self.ui, 'label_' + param).hide()
def ch_event(self):
"""event change between law and evenment"""
event = self.ui.evenement.isChecked()
self.par['evenement']["val"] = event
@staticmethod
def str2bool(s):
"""string to bool"""
if "True" in s or "TRUE" in s:
return True
else:
return False
def selb(self, obj):
"""function selectbox"""
return lambda: self.selectbox(obj)
def selectbox(self, box):
""" function allow to select or not for checkBox"""
for checkbox in box.findChildren(QCheckBox):
checkbox.setChecked(box.isChecked())
# checkbox.setEnabled(True)
def accept_dialog(self):
"""Modification of the parameters in sql table"""
var = []
for param, info in self.par.items():
if info['gui']:
obj = getattr(self.ui, param)
if param in self.variables:
var.append((param, obj))
continue
else:
if isinstance(obj, QCheckBox) or isinstance(obj,
QRadioButton):
val = obj.isChecked()
elif isinstance(obj, QComboBox):
val = obj.currentIndex()
if param == 'option' or param == "critereArret" or param == 'postProcesseur':
val = val + 1
elif param == "compositionLits":
val = val
else:
val = obj.value()
sql = """ UPDATE {0}.parametres
SET {1}='{2}'
WHERE parametre='{3}'
"""
self.mdb.run_query(
sql.format(self.mdb.SCHEMA, self.kernel, val, param))
#
liste = []
for var2 in self.variables:
for param, obj in var:
if var2 == param:
liste.append(str(obj.isChecked()).lower())
sql = """ UPDATE {0}.parametres
SET {1}='{2}'
WHERE parametre='variablesStockees'
"""
self.mdb.run_query(
sql.format(self.mdb.SCHEMA, self.kernel, " ".join(liste)))
self.close()