Compare commits

...

3 Commits

6 changed files with 60 additions and 21 deletions

View File

@ -498,7 +498,7 @@ class InitialConditions(SQLSubModel):
data_discharge[profile.rk] = 0.0
else:
for data in self._data:
data_discharge[data["rk"]] = data["discharge"]
data_discharge[data["rk"].rk] = data["discharge"]
incline = self._reach.reach.get_incline_median_mean()
logger.debug(f"incline = {incline}")
@ -562,7 +562,9 @@ class InitialConditions(SQLSubModel):
data_height[profile.rk] = 0.0
else:
for data in self._data:
data_height[data["rk"]] = data["height"]
data_height[data["rk"].rk] = data["height"]
print(data_height)
incline = self._reach.reach.get_incline_median_mean()
logger.debug(f"incline = {incline}")
@ -571,11 +573,13 @@ class InitialConditions(SQLSubModel):
width = profile.width_approximation()
frictions = self._reach.frictions.frictions
strickler = None
if frictions is not None:
if len(frictions) >= 1:
for f in frictions:
if f.contains_rk(profile.rk):
strickler = f.get_friction(profile.rk)[0]
if strickler is None:
strickler = 25.0
@ -587,8 +591,9 @@ class InitialConditions(SQLSubModel):
else:
height = (
discharge
/
((width * 0.8) * strickler * (abs(incline) ** (0.5)))
/ ((width * 0.8)
* strickler
* (abs(incline) ** (0.5)))
) ** (0.6)
elevation = max(
@ -624,7 +629,7 @@ class InitialConditions(SQLSubModel):
data_discharge[profile.rk] = 0.0
else:
for data in self._data:
data_discharge[data["rk"]] = data["discharge"]
data_discharge[data["rk"].rk] = data["discharge"]
self._data = []
for profile in profiles:
@ -637,7 +642,7 @@ class InitialConditions(SQLSubModel):
[upstream_rk, downstream_rk],
[elevation1, elevation2])
new = Data(reach=self._reach, status=self._status)
new["rk"] = profile.rk
new["rk"] = profile
new["discharge"] = d
new["elevation"] = elevation
self._data.append(new)

View File

@ -72,7 +72,9 @@ class TableModel(PamhyrTableModel):
if 0 <= column < 2:
v = self._data.get_i(row)[column]
if self._data.get_type_column(column) == float:
value = f"{v:.4f}"
if type(v) == str:
v = v.replace(',', '.')
value = f"{float(v):.4f}"
elif self._data.header[column] == "time":
if self._opt_data == "time":
value = timestamp_to_old_pamhyr_date(int(v))

View File

@ -94,7 +94,9 @@ class AddCommand(QUndoCommand):
self._bcs = bcs
self._tab = tab
self._index = index
self._old = self._bcs.get(self._tab, self._index)
self._old = None
if len(self._bcs.get_tab(self._tab)) > self._index:
self._bcs.get(self._tab, self._index)
self._new = None
def undo(self):

View File

@ -113,7 +113,7 @@ class SortCommand(QUndoCommand):
def redo(self):
self._ics.sort(
reverse=self._reverse,
key=lambda x: x["rk"]
key=lambda x: x["rk"].rk
)
if self._indexes is None:
self._indexes = list(

View File

@ -686,13 +686,13 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
options=options,
)
self._backup_timer.blockSignals(True)
self._save_mutex.lock()
logger.debug(f"Save study as : {repr(file_name)}")
if file_name == "":
return
self._backup_timer.blockSignals(True)
self._save_mutex.lock()
if file_name.rsplit(".", 1)[-1] == "pamhyr":
logger.debug(
"Pamhyr extention is present : " +
@ -706,9 +706,42 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
self._study.filename = file_name + ".pamhyr"
sql_request_count = self._study.sql_save_request_count()
if len(self._study.scenarios) != 1:
self.save_as_study_multi_scenario()
else:
self.save_as_study_single_scenario()
self.conf.set_last_study(self._study.filename)
self._save_mutex.unlock()
self._backup_timer.blockSignals(False)
def save_as_study_multi_scenario(self):
scenarios = self._study.scenarios.lst
progress = QProgressDialog(
"Saving...", None,
"Saving scenarios...", None,
0, len(scenarios),
parent=self
)
progress.setWindowModality(Qt.WindowModal)
progress.setValue(0)
for scenario in scenarios:
self._study.reload_from_scenario(scenario)
self.save_as_study_single_scenario(scenario.id)
progress.setValue(progress.value() + 1)
def save_as_study_single_scenario(self, sid=-1):
sql_request_count = self._study.sql_save_request_count()
msg = "Saving..."
if sid != -1:
msg = f"Saving scenario {sid}..."
progress = QProgressDialog(
msg, None,
0, sql_request_count,
parent=self
)
@ -727,11 +760,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
logger.info(status)
self.statusbar.showMessage(status, 3000)
self.conf.set_last_study(self._study.filename)
self._save_mutex.unlock()
self._backup_timer.blockSignals(False)
def _backup(self):
logger.debug("Backup signal...")
if not self.conf.backup_enable:

View File

@ -357,8 +357,10 @@ class GraphWidget(QGraphicsView):
if len(selectable_items) == 0:
if event.buttons() & Qt.LeftButton:
old_p = self.mapToScene(
float(self.m_origin_x),
float(self.m_origin_y)
QPoint(
int(self.m_origin_x),
int(self.m_origin_y)
)
)
new_p = self.mapToScene(event.pos())
translation = new_p - old_p