From: Paul RASCLE Date: Tue, 4 Apr 2017 11:39:37 +0000 (+0200) Subject: fix boundary condition dialog X-Git-Tag: Salome_8_3_Hydro_2_0rc1~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=764e37987f26c769e00bdcba719f48e0a7b4e764;p=modules%2Fhydrosolver.git fix boundary condition dialog --- diff --git a/src/HYDROGUI/BndConditionsDialog.py b/src/HYDROGUI/BndConditionsDialog.py index 9cc7dfc..81884e8 100755 --- a/src/HYDROGUI/BndConditionsDialog.py +++ b/src/HYDROGUI/BndConditionsDialog.py @@ -46,27 +46,17 @@ def get_med_groups_on_edges(file_path): """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) @@ -156,6 +146,7 @@ class BoundaryConditionsDialog(QDialog): """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) @@ -175,12 +166,15 @@ class BoundaryConditionsDialog(QDialog): 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): @@ -260,6 +254,7 @@ class BoundaryConditionsDialog(QDialog): """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()) @@ -273,18 +268,24 @@ class BoundaryConditionsDialog(QDialog): 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): @@ -295,6 +296,7 @@ class BoundaryConditionsDialog(QDialog): """Set groups list""" def set_groups(self, groups): + #print "set_groups" self.boundaryConditionsTable.setRowCount(0) for group in groups: # Add row @@ -303,12 +305,13 @@ class BoundaryConditionsDialog(QDialog): # '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) @@ -337,24 +340,35 @@ class BoundaryConditionsDialog(QDialog): """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: @@ -384,12 +398,13 @@ class BoundaryConditionsDialog(QDialog): 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).")) diff --git a/src/HYDROTools/boundaryConditions.py b/src/HYDROTools/boundaryConditions.py index 041314d..c090777 100644 --- a/src/HYDROTools/boundaryConditions.py +++ b/src/HYDROTools/boundaryConditions.py @@ -14,7 +14,7 @@ class PresetReader(): return self._errors def __get_value(self, str): - value = None + value = '' if str.isdigit(): value = int(str) @@ -34,7 +34,7 @@ class PresetReader(): for line in f: cstr = " ".join(line.split()) values = cstr.strip().split(PRS_SEP) - + #print values if len(values) != 5: self._errors.append("Line #%s: wrong number of values in the preset." % line_number) elif values[0].strip() == "": @@ -49,9 +49,10 @@ class PresetReader(): litbor = self.__get_value(values[4]) presets[name] = (lihbor, liubor, livbor, litbor) + #print name, presets[name] + #print presets.keys() except IOError as err: self._errors.append(err.strerror) - return presets """Boundary condition object""" @@ -151,7 +152,6 @@ class BoundaryConditionReader(): self._errors.append("Number of conditions does not match (%s instead of %s)" % (cnd_count, nb_conditions)) except IOError as err: self._errors.append(err.strerror) - return conditions """Boundary conditions file writer""" diff --git a/tests/data/bnd_conditions_presets.txt b/tests/data/bnd_conditions_presets.txt index 25b07c6..238b8b5 100644 --- a/tests/data/bnd_conditions_presets.txt +++ b/tests/data/bnd_conditions_presets.txt @@ -1,3 +1,15 @@ 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