"""Get preset name corresponding to the given values of LIHBOR, LIUBOR, LIVBOR and LITBOR"""
def get_preset_name(presets, lihbor, liubor, livbor, litbor):
- name = ''
-
- for preset_name in presets:
- values = presets[preset_name]
-
- p_lihbor = values[0]
- p_liubor = values[1]
- p_livbor = values[2]
- p_litbor = values[3]
-
- if not p_lihbor or p_lihbor == lihbor:
- if not p_liubor or p_liubor == liubor:
- if not p_livbor or p_livbor == livbor:
- if not p_litbor or p_litbor == litbor:
- name = preset_name
-
+ name = 'Custom'
+ res = (lihbor, liubor, livbor, litbor)
+ for key, val in presets.iteritems():
+ if val == res:
+ name = key
+ break
return name
"""Convert string to integer, return None if conversion is not possible"""
def get_int(str):
- value = None
+ value = ''
if str.isdigit():
value = int(str)
"""Process cell data changes"""
def on_cell_changed(self, row, column):
+ #print "on_cell_changed"
lihbor = liubor = livbor = litbor = None
item = self.boundaryConditionsTable.item(row, 1)
litbor = get_int(str(item.text()))
preset_name = get_preset_name(self.presets, lihbor, liubor, livbor, litbor)
+ #print "on_cell_changed ", preset_name, lihbor, liubor, livbor, litbor
combo = self.boundaryConditionsTable.cellWidget(row, 0)
if isinstance(combo, QComboBox):
ind = combo.findText(preset_name)
if ind >= 0:
+ combo.currentIndexChanged.disconnect(self.on_preset_changed)
combo.setCurrentIndex(ind)
+ combo.currentIndexChanged.connect(self.on_preset_changed)
"""Save the user data to boundary conditions file"""
def on_apply(self):
"""Called on preset selection in the first column of the table"""
def on_preset_changed(self):
+ #print"on_preset_changed"
combo = self.sender()
preset = str(combo.currentText())
liubor = values[1]
livbor = values[2]
litbor = values[3]
+ #print "on_preset_changed ", preset, lihbor, liubor, livbor, litbor
- if lihbor:
- self.boundaryConditionsTable.item(row_nb, 1).setText(str(lihbor))
+ #if lihbor is not None:
+ self.boundaryConditionsTable.item(row_nb, 1).setText(str(lihbor))
- if liubor:
- self.boundaryConditionsTable.item(row_nb, 2).setText(str(liubor))
+ #if liubor is not None:
+ self.boundaryConditionsTable.item(row_nb, 2).setText(str(liubor))
- if livbor:
- self.boundaryConditionsTable.item(row_nb, 3).setText(str(livbor))
+ #if livbor is not None:
+ self.boundaryConditionsTable.item(row_nb, 3).setText(str(livbor))
- if litbor:
- self.boundaryConditionsTable.item(row_nb, 4).setText(str(litbor))
+ #if litbor is not None:
+ self.boundaryConditionsTable.item(row_nb, 4).setText(str(litbor))
+
+ if isinstance(combo, QComboBox):
+ ind = combo.findText(preset)
+ if ind >= 0:
+ combo.setCurrentIndex(ind)
"""Define result file path"""
def on_result_file_browse(self):
"""Set groups list"""
def set_groups(self, groups):
+ #print "set_groups"
self.boundaryConditionsTable.setRowCount(0)
for group in groups:
# Add row
# 'Preset' column
combo = QComboBox(self)
- combo.addItem('')
+ #combo.addItem('')
if len(self.presets) > 0:
- combo.addItems(self.presets.keys())
+ items = self.presets.keys()
+ items.sort()
+ combo.addItems(items)
combo.setProperty(ROW_PROPERTY_NAME, row_nb)
-
combo.currentIndexChanged.connect(self.on_preset_changed)
self.boundaryConditionsTable.setCellWidget(row_nb, 0, combo)
"""Update conditions data in the table from the conditions input file"""
def update_table(self):
+ #print "update_table"
is_updated = False
nb_rows = self.boundaryConditionsTable.rowCount()
for row_nb in xrange(0, nb_rows):
group_name = str(self.boundaryConditionsTable.item(row_nb, 5).text())
if self.input_conditions.has_key(group_name):
+
values = self.input_conditions[group_name]
+ #print values
lihbor = str(values[0])
liubor = str(values[1])
livbor = str(values[2])
litbor = str(values[3])
+ #print lihbor, liubor, livbor, litbor
self.boundaryConditionsTable.item(row_nb, 1).setText(lihbor)
self.boundaryConditionsTable.item(row_nb, 2).setText(liubor)
self.boundaryConditionsTable.item(row_nb, 3).setText(livbor)
self.boundaryConditionsTable.item(row_nb, 4).setText(litbor)
+# combo = self.boundaryConditionsTable.cellWidget(row_nb, 0)
+# if isinstance(combo, QComboBox):
+# preset_name = get_preset_name(self.presets, lihbor, liubor, livbor, litbor)
+# ind = combo.findText(preset_name)
+# if ind >= 0:
+# combo.setCurrentIndex(ind)
+
is_updated = True
if not is_updated and nb_rows > 0 and len(self.input_conditions) > 0:
liubor = str(self.boundaryConditionsTable.item(row_nb, 2).text())
livbor = str(self.boundaryConditionsTable.item(row_nb, 3).text())
litbor = str(self.boundaryConditionsTable.item(row_nb, 4).text())
-
+ #print "valid: ", lihbor, liubor, livbor, litbor
if lihbor and liubor and livbor and litbor:
has_empty_cells = False # Full lines are OK
+ #print "valid: full line"
if (not lihbor) and (not liubor) and (not livbor) and (not litbor):
has_empty_cells = False # Empty lines are OK
- break
+ #print "valid: empty line"
if has_empty_cells:
QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Table has empty cell(s)."))
Closed boundaries/walls,2,2,2,2
-Imposed flow rate,4,5,5,5
-Imposed water level,5,4,4,4
+Prescribed H / prescribed T,5,4,4,5
+Prescribed H / free T,5,4,4,4
+Prescribed Q / prescribed T,4,5,5,5
+Prescribed Q / free T,4,5,5,4
+Prescribed Q and H / prescribed T,5,5,5,5
+Prescribed Q and H / free T,5,5,5,4
+Prescribed UV / prescribed T,4,6,6,5
+Prescribed UV / free T,4,6,6,4
+Prescribed UV and H / prescribed T,6,6,6,5
+Prescribed UV and H / free T,6,6,6,4
+Incident waves / prescribed T,1,1,1,5
+Incident waves / free T,1,1,1,4
+Custom,0,0,0,0
+None,'','','',''
\ No newline at end of file