Compare commits

..
Author SHA1 Message Date
Dylan Jeannin 5ce5478bf4 Interpolated profiles: fix undo/redo misconnection of undo_stack between geometry and profile window, adding a new data in the profile model, common to both window 2026-09-11 18:48:45 +02:00
Dylan Jeannin 0dbea26a2e BoundaryConditions: fix index error in deletion for boundary cond. 2026-09-11 16:50:47 +02:00
Dylan Jeannin b0e0dc75f1 Fix pep8 2026-09-11 14:17:04 +02:00
Dylan Jeannin 318f6a4668 Geometry: undo/redo restores interpolated data in the model 2026-09-11 14:10:55 +02:00
Dylan Jeannin fdb5cd23e7 Translation: correct albedo display to water albedo, + update translation 2026-09-11 10:12:59 +02:00
Dylan Jeannin e064c1aee5 Interpolated profiles: modify an interpolated profile, or something relative to it in the model, will no longer considerate this profile as an interpolated one 2026-09-10 19:17:23 +02:00
Dylan Jeannin e0bc481ae2 Geometry: Orange color instead of red for interpolated profiles in the graph in geometry window 2026-09-10 15:18:59 +02:00
Dylan Jeannin 081e6e7322 Geometry:toggle interpolated profiles visibility in geometry table and plots 2026-09-10 13:56:46 +02:00
Dylan Jeannin a0d8b9ea43 Split reach : disabled endpoint and struture-linked profiles in reach split selector, instead of deleting them from the list 2026-09-09 13:54:01 +02:00
Dylan Jeannin d97620ad56 Replace missing reach warning with a reach selection dropdown list on opening geometry, frictions, sediment layers, and initial conditions 2026-09-09 10:31:22 +02:00
Dylan Jeannin 6d4dc3a22b Merge branch 'new_design_main_page' into dev_dylan 2026-09-08 17:31:54 +02:00
Dylan Jeannin 74d23386a7 Network: cleanest version of drag clic to move on the graph + network graph view only on the main tab (no more interaction on mouse hover) + graph on main tab 2026-09-08 17:31:01 +02:00
Dylan Jeannin 9f46bcd853 View main window: fix refresh network preview when selecting a reach 2026-09-08 15:42:04 +02:00
Dylan Jeannin bcc9dd1a0d View main window: keep zoom on the geographical graph after a change in the geometry 2026-09-08 14:02:53 +02:00
Dylan Jeannin fc40552d68 View main window: add a splitter to resize both network graph and geometry graph 2026-09-08 13:28:51 +02:00
Dylan Jeannin f41050fe5c Design main window: UI improvement for the graph tab, QBox, titles... 2026-09-07 17:37:52 +02:00
Dylan Jeannin 97f487c0af Design main window: Network graph is now connected with the edition window to refresh after every change 2026-09-07 17:06:24 +02:00
Dylan Jeannin 499e16975f Design main window: New tab with network of the study 2026-09-07 16:31:35 +02:00
Dylan Jeannin 75f3c07cd9 Solver: export the relative time for solver files, in the case of a study in date mode, which is the date mentionned in the data minus the study start date 2026-09-07 15:35:27 +02:00
Dylan Jeannin 0a0c00d877 Results with disabled profiles: fix a bug happening when we are looking at results, and we modify enable/disable some profiles at the same time. Now the plot uses the profiles stored with the results, and no more in the model 2026-09-07 13:48:17 +02:00
Dylan Jeannin 8d2c18b6af Timeseries: fix problem with copy/paste data in timeseries for the date mode 2026-09-07 12:10:45 +02:00
Dylan Jeannin 2d2f83436c Date/time: now save global timestamp in the model, instead of relative 2026-09-07 11:17:04 +02:00
Dylan Jeannin beece68498 SolverParameters: new combobox instead of index in the value field for critical shields, shields correction and solid capacity 2026-09-04 11:40:04 +02:00
Dylan Jeannin d8e9d786d9 LateralContributionsAdisTS: correctly highlight the profiles in the interval + refacto function name 2026-09-03 16:29:32 +02:00
Dylan Jeannin 7ef305e724 Pollutants: ref to pol_name in the title of the lateral_contribution_pollutant 2026-09-03 13:00:53 +02:00
45 changed files with 1065 additions and 353 deletions

No files matched your search

@@ -531,7 +531,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
new_0 = self._types[0](data[0].replace(",", "."))
new_1 = self._types[1](data[1].replace(",", "."))
return (new_0, new_1)
return Data(new_0, new_1, types=self._types, status=self._status)
def add(self, index: int):
value = Data(
@@ -543,7 +543,10 @@ class BoundaryConditionAdisTS(SQLSubModel):
return value
def insert(self, index: int, value):
self._data.insert(index, value)
if value in self._data:
value.set_as_not_deleted()
else:
self._data.insert(index, value)
self.modified()
def delete_i(self, indexes):
@@ -419,7 +419,7 @@ class BoundaryConditionTemperature(SQLSubModel):
new_0 = self._types[0](data[0].replace(",", "."))
new_1 = self._types[1](data[1].replace(",", "."))
return (new_0, new_1)
return Data(new_0, new_1, types=self._types, status=self._status)
def add(self, index: int):
value = Data(
@@ -431,7 +431,10 @@ class BoundaryConditionTemperature(SQLSubModel):
return value
def insert(self, index: int, value):
self._data.insert(index, value)
if value in self._data:
value.set_as_not_deleted()
else:
self._data.insert(index, value)
self.modified()
def delete_i(self, indexes):
+3
View File
@@ -55,8 +55,11 @@ class Point(SQLSubModel):
@name.setter
def name(self, name):
changed = self._name != name
self._name = name
self.modified()
if changed and self._profile is not None:
self._profile.content_modified()
def is_named(self):
"""
+9
View File
@@ -329,8 +329,11 @@ class PointXYZ(Point):
@x.setter
def x(self, value):
changed = self._x != float(value)
self._x = float(value)
self.modified()
if changed and self._profile is not None:
self._profile.content_modified()
@property
def y(self):
@@ -338,8 +341,11 @@ class PointXYZ(Point):
@y.setter
def y(self, value):
changed = self._y != float(value)
self._y = float(value)
self.modified()
if changed and self._profile is not None:
self._profile.content_modified()
@property
def z(self):
@@ -347,8 +353,11 @@ class PointXYZ(Point):
@z.setter
def z(self, value):
changed = self._z != float(value)
self._z = float(value)
self.modified()
if changed and self._profile is not None:
self._profile.content_modified()
def shift(self, x, y, z):
self.x += x
+56 -12
View File
@@ -47,6 +47,8 @@ class Profile(object):
self._sl = None
self._points: List[Point] = []
self._modification_count = 0
self._old_interpolated = ""
self._profile_type = _type
@@ -160,8 +162,13 @@ class Profile(object):
@rk.setter
def rk(self, value: float):
self._rk = float(value)
self.modified()
value = float(value)
changed = value != self._rk
self._rk = value
if changed:
self.content_modified()
else:
self.modified()
@property
def name(self):
@@ -173,8 +180,13 @@ class Profile(object):
@name.setter
def name(self, value: str):
self._name = value.strip()
self.modified()
value = value.strip()
changed = value != self._name
self._name = value
if changed:
self.content_modified()
else:
self.modified()
@property
def sl(self):
@@ -217,6 +229,38 @@ class Profile(object):
return [point for point in self.points
if point.is_named()]
@property
def modification_count(self):
"""Content revision for this session; not stored in the database."""
return self._modification_count
def increase_modification_count(self):
"""Increase content revision for this session;
not stored in the database."""
self._modification_count += 1
def decrease_modification_count(self):
"""Decrease content revision for this session;
not stored in the database."""
self._modification_count -= 1
@property
def old_interpolated(self):
"""Old interpolated value for this session;
not stored in the database."""
return self._old_interpolated
@old_interpolated.setter
def old_interpolated(self, value):
self._old_interpolated = value
def content_modified(self):
"""An edited profile is no longer an interpolation result."""
# self._modification_count += 1
if hasattr(self, "_interpolated"):
self._interpolated = False
self.modified()
def insert_point(self, index: int, point: Point):
"""Insert point at index.
@@ -232,7 +276,7 @@ class Profile(object):
else:
self._points.insert(index, point)
self.modified()
self.content_modified()
def delete_i(self, indexes: list):
list(
@@ -245,7 +289,7 @@ class Profile(object):
)
)
self.modified()
self.content_modified()
def delete_points(self, points):
"""Delete some elements in profile list
@@ -262,7 +306,7 @@ class Profile(object):
points
)
)
self.modified()
self.content_modified()
# Move
@@ -272,7 +316,7 @@ class Profile(object):
p = self._points
p[index], p[next] = p[next], p[index]
self.modified()
self.content_modified()
def move_down_point(self, index: int):
if index >= 0:
@@ -280,7 +324,7 @@ class Profile(object):
p = self._points
p[index], p[prev] = p[prev], p[index]
self.modified()
self.content_modified()
# Sort
@@ -297,7 +341,7 @@ class Profile(object):
key=predicate,
reverse=is_reversed
)
self.modified()
self.content_modified()
@timer
def sort_with_indexes(self, indexes: list):
@@ -313,12 +357,12 @@ class Profile(object):
)
)
)
self.modified()
self.content_modified()
@timer
def reverse(self):
self._points.reverse()
self.modified()
self.content_modified()
# Sediment Layers
+5 -4
View File
@@ -559,7 +559,7 @@ class ProfileXYZ(Profile, SQLSubModel):
)
self._points.append(pt)
self.modified()
self.content_modified()
def get_point_i(self, index: int) -> PointXYZ:
"""Get point at index.
@@ -624,7 +624,7 @@ class ProfileXYZ(Profile, SQLSubModel):
)
self.points.append(point_xyz)
self.modified()
self.content_modified()
def insert(self, index: int):
"""Insert a new point at index.
@@ -643,7 +643,7 @@ class ProfileXYZ(Profile, SQLSubModel):
point = PointXYZ(x=x, y=y, z=z, profile=self, status=self._status)
self._points.insert(index, point)
self.modified()
self.content_modified()
return point
@@ -1172,8 +1172,9 @@ class ProfileXYZ(Profile, SQLSubModel):
interpolated=self.interpolated)
for i, k in enumerate(self.points):
p.insert_point(i, k.copy())
p.insert_point(i, k.cloned_for(p))
p._interpolated = self.interpolated
return p
def purge_aligned_points(self):
+6 -2
View File
@@ -594,7 +594,9 @@ class AdisTSwc(AdisTS):
f.write(f"*---------++++++++++\n")
for LC_data in LC.data:
tmp = timestamp_to_old_pamhyr_date_adists(int(LC_data[0]))
tmp = timestamp_to_old_pamhyr_date_adists(
int(self.export_time(study, LC_data[0]))
)
f.write(" ".join((f"{tmp}",
f"{LC_data[1]}\n")))
f.write(f"*\n")
@@ -626,7 +628,9 @@ class AdisTSwc(AdisTS):
f.write(f"*---------++++++++++\n")
for BC_data in BC.data:
tmp = timestamp_to_old_pamhyr_date_adists(int(BC_data[0]))
tmp = timestamp_to_old_pamhyr_date_adists(
int(self.export_time(study, BC_data[0]))
)
f.write(" ".join((f"{tmp}",
f"{BC_data[1]}\n")))
f.write(f"*\n")
+6 -2
View File
@@ -884,7 +884,9 @@ class AdisTTwc(AdisTT):
f.write("*temps |temperature (degC)\n")
f.write("*---------++++++++++\n")
for value in boundary_condition.data:
date = timestamp_to_old_pamhyr_date_adists(int(value[0]))
date = timestamp_to_old_pamhyr_date_adists(
int(self.export_time(study, value[0]))
)
f.write(f"{date} {value[1]}\n")
f.write("*\n")
return filename
@@ -907,7 +909,9 @@ class AdisTTwc(AdisTT):
f.write("*temps |value\n")
f.write("*---------++++++++++\n")
for value in weather_parameter.data:
date = timestamp_to_old_pamhyr_date_adists(int(value[0]))
date = timestamp_to_old_pamhyr_date_adists(
int(self.export_time(study, value[0]))
)
f.write(f"{date} {value[1]}\n")
f.write("*\n")
return filename
+11 -1
View File
@@ -19,8 +19,9 @@
import os
import logging
from datetime import datetime
from datetime import datetime, timezone
from tools import timer, parse_command_line, get_version, logger_exception
from tools import parse_datetime
try:
# Installation allow Unix-like signal
@@ -44,6 +45,15 @@ logger = logging.getLogger()
class CommandLineSolver(AbstractSolver):
_type = ""
@staticmethod
def export_time(study, value):
"""Return elapsed seconds before applying the solver file's units."""
if study.time_system != "date":
return value
# Match the UTC timestamps produced by date entry in the tables.
start = parse_datetime(study.date).replace(tzinfo=timezone.utc)
return float(value) - start.timestamp()
def __init__(self, name):
super(CommandLineSolver, self).__init__(name)
+19 -10
View File
@@ -303,7 +303,7 @@ class Mage(CommandLineSolver):
# Point line
wfile.write(f"{x} {y} {z} {n} {sediment}\n")
def _export_BC(self, t, bounds, repertory, qlog, name="0"):
def _export_BC(self, study, t, bounds, repertory, qlog, name="0"):
files = []
if len(bounds) == 0:
@@ -333,7 +333,7 @@ class Mage(CommandLineSolver):
v1 = d[1]
if t in ["HYD", "LIM"]:
v0 /= 60 # Convert first column to minute
v0 = self.export_time(study, v0) / 60 # Minutes
f.write(f"{v0:9} {v1:9} \n")
@@ -365,10 +365,17 @@ class Mage(CommandLineSolver):
elif bound.bctype == "SL":
QSO.append(bound)
files = files + self._export_BC("AVA", AVA, repertory, qlog, name=name)
files = files + self._export_BC("HYD", HYD, repertory, qlog, name=name)
files = files + self._export_BC("LIM", LIM, repertory, qlog, name=name)
files = files + self._export_QSO(QSO, repertory, qlog, name=name)
files = files + self._export_BC(
study, "AVA", AVA, repertory, qlog, name=name
)
files = files + self._export_BC(
study, "HYD", HYD, repertory, qlog, name=name
)
files = files + self._export_BC(
study, "LIM", LIM, repertory, qlog, name=name
)
files = files + self._export_QSO(study, QSO, repertory,
qlog, name=name)
return files
@@ -422,10 +429,11 @@ class Mage(CommandLineSolver):
if d.is_deleted():
continue
time = self.export_time(study, d[0])
if lateral.lctype in ["EV"]:
f.write(f"{d[0]:10.3f}{-d[1]:10.3f}\n")
f.write(f"{time:10.3f}{-d[1]:10.3f}\n")
else:
f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n")
f.write(f"{time:10.3f}{d[1]:10.3f}\n")
def _export_RUG(self, study, repertory, qlog, name="0"):
files = []
@@ -964,7 +972,7 @@ class Mage8(Mage):
return files
def _export_QSO(self, bounds, repertory, qlog, name="0"):
def _export_QSO(self, study, bounds, repertory, qlog, name="0"):
files = []
if len(bounds) == 0:
@@ -994,7 +1002,8 @@ class Mage8(Mage):
# Data
for d in bound.data:
f.write(f"{d[0]/60:10.3f}{d[1]:10.3f}\n")
time = self.export_time(study, d[0]) / 60
f.write(f"{time:10.3f}{d[1]:10.3f}\n")
return files
+4 -2
View File
@@ -550,7 +550,8 @@ class Rubar3(CommandLineSolver):
for bc in bcs:
f.write(f"{len(bc)}\n")
for d0, d1 in bc.data:
f.write(f"{d1} {d0}\n")
time = self.export_time(study, d0)
f.write(f"{d1} {time}\n")
def _export_condav(self, study, repertory, qlog, name="0"):
if qlog is not None:
@@ -577,7 +578,8 @@ class Rubar3(CommandLineSolver):
f.write(f"{d1} {d0}\n")
else:
for d0, d1 in bc.data:
f.write(f"{d0} {d1}\n")
time = self.export_time(study, d0)
f.write(f"{time} {d1}\n")
def read_profil(self, study, fname, results, qlog=None, name="0"):
logger.info(f"read: profil.{name}")
+10 -9
View File
@@ -24,7 +24,7 @@ from datetime import date, time, datetime, timedelta
from tools import (
trace, timer,
timestamp_to_old_pamhyr_date,
old_pamhyr_date_to_timestamp, format_datetime
old_pamhyr_date_to_timestamp, format_datetime, parse_datetime
)
from View.Tools.PamhyrTable import PamhyrTableModel
@@ -98,7 +98,7 @@ class TableModel(PamhyrTableModel):
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = format_datetime(
self._start_date + timedelta(seconds=float(v))
datetime(1970, 1, 1) + timedelta(seconds=float(v))
)
else:
value = f"{v}"
@@ -118,7 +118,7 @@ class TableModel(PamhyrTableModel):
try:
if (self._data.header[column] == "time"
and self._opt_data == "date"):
value = self.date_to_elapsed_seconds(value)
value = self.date_to_timestamp(value)
row = self.get_true_data_row(row)
@@ -238,17 +238,18 @@ class TableModel(PamhyrTableModel):
if len(data) == 0:
return
try:
rows = [self._data.new_from_data(header, d) for d in data]
except (ValueError, TypeError, IndexError) as error:
logger.warning(error)
return False
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
rows
)
)
+1 -1
View File
@@ -124,7 +124,7 @@ class DelCommand(QUndoCommand):
self._bcs.insert(self._tab, row, el)
def redo(self):
self._bcs.delete_i(self._tab, self._rows)
self._bcs.delete(self._tab, [el for _, el in self._bc])
class SortCommand(QUndoCommand):
@@ -88,7 +88,7 @@ class TableModel(PamhyrTableModel):
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = format_datetime(
self._start_date + timedelta(seconds=float(v))
datetime(1970, 1, 1) + timedelta(seconds=float(v))
)
else:
value = f"{v}"
@@ -108,7 +108,7 @@ class TableModel(PamhyrTableModel):
try:
if (self._data.header[column] == "time"
and self._opt_data == "date"):
value = self.date_to_elapsed_seconds(value)
value = self.date_to_timestamp(value)
row = self.get_true_data_row(row)
@@ -169,17 +169,18 @@ class TableModel(PamhyrTableModel):
if len(data) == 0:
return
try:
rows = [self._data.new_from_data(header, d) for d in data]
except (ValueError, TypeError, IndexError) as error:
logger.warning(error)
return False
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
rows
)
)
@@ -88,7 +88,7 @@ class TableModel(PamhyrTableModel):
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = format_datetime(
self._start_date + timedelta(seconds=float(v))
datetime(1970, 1, 1) + timedelta(seconds=float(v))
)
else:
value = f"{v}"
@@ -108,7 +108,7 @@ class TableModel(PamhyrTableModel):
try:
if (self._data.header[column] == "time"
and self._opt_data == "date"):
value = self.date_to_elapsed_seconds(value)
value = self.date_to_timestamp(value)
row = self.get_true_data_row(row)
@@ -169,17 +169,18 @@ class TableModel(PamhyrTableModel):
if len(data) == 0:
return
try:
rows = [self._data.new_from_data(header, d) for d in data]
except (ValueError, TypeError, IndexError) as error:
logger.warning(error)
return False
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
rows
)
)
+7 -4
View File
@@ -112,7 +112,7 @@ class PlotAC(PamhyrPlot):
profile_id = 0
profile = self.data.profile(profile_id)
if profile is None:
if profile is None or self._parent.tableView.isRowHidden(profile_id):
return
station = profile.get_station()
@@ -192,21 +192,24 @@ class PlotAC(PamhyrPlot):
self.plot_selected.set_data([], [])
self.next_plot_selected.set_data([], [])
if 0 <= previous_id < self.data.number_profiles:
if (0 <= previous_id < self.data.number_profiles
and not self._parent.tableView.isRowHidden(previous_id)):
self.previous_plot_selected.set_data(
self.data.profile(previous_id).get_station(),
self.data.profile(previous_id).z()
)
self.previous_plot_selected.set_visible(True)
if 0 <= profile_id < self.data.number_profiles:
if (0 <= profile_id < self.data.number_profiles
and not self._parent.tableView.isRowHidden(profile_id)):
self.plot_selected.set_data(
self.data.profile(profile_id).get_station(),
self.data.profile(profile_id).z()
)
self.plot_selected.set_visible(True)
if 0 <= next_id < self.data.number_profiles:
if (0 <= next_id < self.data.number_profiles
and not self._parent.tableView.isRowHidden(next_id)):
self.next_plot_selected.set_data(
self.data.profile(next_id).get_station(),
self.data.profile(next_id).z()
+15 -15
View File
@@ -110,9 +110,9 @@ class PlotRKZ(PamhyrPlot):
def _closest_rk(self, event):
s = event.artist.get_segments()
x = [i[0, 0] for i in s]
mx = event.mouseevent.xdata
points = enumerate(x)
points = [(i, segment[0, 0]) for i, segment in enumerate(s)
if len(segment)]
def dist_mouse(point):
x = point[1]
@@ -136,6 +136,7 @@ class PlotRKZ(PamhyrPlot):
if len(ind) == 0:
return
ind = [i for i in ind if not self._table.isRowHidden(i)]
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
@@ -150,18 +151,7 @@ class PlotRKZ(PamhyrPlot):
self._table.scrollTo(self._table.model().index(ind[-1], 0))
def _select_range_in_table(self, ind1, ind2):
if self._table is not None:
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection(self._table.model().index(ind1, 0),
self._table.model().index(ind2, 0))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
self._table.scrollTo(self._table.model().index(ind2, 0))
self._select_in_table(list(range(ind1, ind2 + 1)))
@timer
def redraw(self, data):
@@ -213,13 +203,23 @@ class PlotRKZ(PamhyrPlot):
picker=10,
)
if self._table is not None:
segments = self.line_rk_zmin_zmax.get_segments()
self.line_rk_zmin_zmax.set_segments([
segment[:0] if self._table.isRowHidden(row) else segment
for row, segment in enumerate(segments)
])
def color_highlight(self):
rows = sorted(list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
))
colors = [self.color_plot for row in range(len(self._data))]
colors = [
"darkorange" if profile.interpolated else self.color_plot
for profile in self._data.profiles
]
style = ["-" for row in range(len(self._data))]
if len(rows) > 0:
for row in rows:
+15 -18
View File
@@ -136,6 +136,7 @@ class PlotXY(PamhyrPlot):
index = QItemSelection()
if len(ind) == 0:
return
ind = [i for i in ind if not self._table.isRowHidden(i)]
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select(
@@ -149,18 +150,7 @@ class PlotXY(PamhyrPlot):
self._table.scrollTo(self._table.model().index(ind[-1], 0))
def _select_range_in_table(self, ind1, ind2):
if self._table is not None:
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection(self._table.model().index(ind1, 0),
self._table.model().index(ind2, 0))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
self._table.scrollTo(self._table.model().index(ind2, 0))
self._select_in_table(list(range(ind1, ind2 + 1)))
@timer
def redraw(self, data):
@@ -189,10 +179,14 @@ class PlotXY(PamhyrPlot):
def draw_xy(self):
self.line_xy = []
for xy in zip(self.data.get_x(), self.data.get_y()):
self.line_xy.append(np.column_stack(xy))
for row, profile in enumerate(self.data.profiles):
hidden = self._table is not None and self._table.isRowHidden(row)
self.line_xy.append(
np.empty((0, 2)) if hidden or len(profile) == 0
else np.column_stack((profile.x(), profile.y()))
)
self._colors, self._style = self.color_hightlight()
self._colors, self._style = self.color_highlight()
self.line_xy_collection = collections.LineCollection(
self.line_xy,
colors=self._colors,
@@ -201,13 +195,16 @@ class PlotXY(PamhyrPlot):
)
self.canvas.axes.add_collection(self.line_xy_collection)
def color_hightlight(self):
def color_highlight(self):
rows = sorted(list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
))
colors = [self.color_plot for row in range(len(self._data))]
colors = [
"darkorange" if profile.interpolated else self.color_plot
for profile in self._data.profiles
]
style = ["-" for row in range(len(self._data))]
if len(rows) > 0:
for row in rows:
@@ -320,7 +317,7 @@ class PlotXY(PamhyrPlot):
def update_current(self):
if self._current_data_update:
self._colors, self._style = self.color_hightlight()
self._colors, self._style = self.color_highlight()
self.line_xy_collection.set_colors(self._colors)
self.line_xy_collection.set_linestyle(self._style)
+106 -1
View File
@@ -37,6 +37,11 @@ class SetDataCommand(QUndoCommand):
self._index = index
self._old = old_value
self._new = self.type(new_value)
if self._profile.old_interpolated == "":
if self._profile.interpolated:
self._profile.old_interpolated = "interpolated"
else:
self._profile.old_interpolated = "not_interpolated"
class SetXCommand(SetDataCommand):
@@ -46,10 +51,19 @@ class SetXCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).x = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).x = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -60,10 +74,19 @@ class SetYCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).y = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).y = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -74,10 +97,19 @@ class SetZCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).z = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).z = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -89,9 +121,20 @@ class SetNameCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).name = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).name = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
class AddCommand(QUndoCommand):
@@ -104,6 +147,13 @@ class AddCommand(QUndoCommand):
def undo(self):
self._profile.delete_i([self._index])
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
@@ -111,7 +161,8 @@ class AddCommand(QUndoCommand):
self._point = self._profile.insert(self._index)
else:
self._profile.insert_point(self._index, self._point)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -125,10 +176,19 @@ class DelCommand(QUndoCommand):
def undo(self):
for point in self._points:
point.set_as_not_deleted()
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.delete_points(self._points)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -153,10 +213,19 @@ class SortCommand(QUndoCommand):
def undo(self):
self._profile.sort_with_indexes(self._indexes)
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.sort(self._column, self._reverse)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -173,6 +242,13 @@ class MoveCommand(QUndoCommand):
self._profile.move_up_point(self._i)
else:
self._profile.move_down_point(self._i)
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
@@ -180,6 +256,8 @@ class MoveCommand(QUndoCommand):
self._profile.move_up_point(self._i)
else:
self._profile.move_down_point(self._i)
self._profile.increase_modification_count()
self._profile.interpolated = False
self._profile.modified()
@@ -191,10 +269,19 @@ class ReverseCommand(QUndoCommand):
def undo(self):
self._profile.reverse()
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.reverse()
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -209,10 +296,19 @@ class PurgeCommand(QUndoCommand):
def undo(self):
for point in self._deleted:
point.set_as_not_deleted()
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._deleted = self._profile.purge(self._np_purge)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@@ -228,9 +324,18 @@ class PasteCommand(QUndoCommand):
def undo(self):
self._profile.delete_points(self._points)
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
for point in self._points:
self._profile.insert_point(self._row, point)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
+3
View File
@@ -45,6 +45,9 @@ class GeometryTranslate(MainTranslate):
self._dict["cross_sections"] = _translate("Geometry", "cross-sections")
self._dict["profile"] = _translate("Geometry", "cross-section")
self._dict["profiles"] = _translate("Geometry", "cross-sections")
self._dict["show_interpolated_profiles"] = _translate(
"Geometry", "Show interpolated profiles"
)
self._dict["cross_section_enabled_count"] = _translate(
"Geometry", "Cross-section enabled ({count} disabled)"
)
+33 -4
View File
@@ -41,6 +41,7 @@ class SetDataCommand(QUndoCommand):
self._index = index
self._old = old_value
self._new = self.type(new_value)
self._profile = self._reach.profile(self._index)
class SetNameCommand(SetDataCommand):
@@ -48,24 +49,52 @@ class SetNameCommand(SetDataCommand):
self.type = str
super(SetNameCommand, self).__init__(
reach, index, old_value, new_value)
if self._profile.old_interpolated == "":
if self._profile.interpolated:
self._profile.old_interpolated = "interpolated"
else:
self._profile.old_interpolated = "not_interpolated"
def undo(self):
self._reach.profile(self._index).name = self._old
self._profile.name = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
def redo(self):
self._reach.profile(self._index).name = self._new
# Name setter will automatically update the interpolated attribute
self._profile.name = self._new
self._profile.increase_modification_count()
class SetRKCommand(SetDataCommand):
def __init__(self, reach, index, old_value, new_value):
self.type = float
super(SetRKCommand, self).__init__(reach, index, old_value, new_value)
if self._profile.old_interpolated == "":
if self._profile.interpolated:
self._profile.old_interpolated = "interpolated"
else:
self._profile.old_interpolated = "not_interpolated"
def undo(self):
self._reach.profile(self._index).rk = self._old
self._profile.rk = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
def redo(self):
self._reach.profile(self._index).rk = self._new
# RK setter will automatically update the interpolated attribute
self._profile.rk = self._new
self._profile.increase_modification_count()
class SetEnabledCommand(QUndoCommand):
+35
View File
@@ -127,6 +127,9 @@ class GeometryWindow(PamhyrWindow):
table.setAlternatingRowColors(True)
def setup_checkbox(self):
self.find(QCheckBox, "checkBox_show_interpolated").setText(
self._trad["show_interpolated_profiles"]
)
self._checkbox = self.find(QCheckBox, "checkBox_enabled")
self._set_checkbox_state()
@@ -197,6 +200,18 @@ class GeometryWindow(PamhyrWindow):
self._status_label.setText(txt)
def setup_connections(self):
self.find(QCheckBox, "checkBox_show_interpolated").toggled.connect(
self.update_interpolated_profiles_visibility
)
self.find(QCheckBox, "checkBox_show_interpolated").toggled.connect(
self.update_redraw
)
self._table.modelReset.connect(
self.update_interpolated_profiles_visibility)
self._table.rowsInserted.connect(
self.update_interpolated_profiles_visibility)
self._table.rowsRemoved.connect(
self.update_interpolated_profiles_visibility)
if self._study.is_read_only():
actions = {
"action_export": self.export_to_file,
@@ -237,6 +252,24 @@ class GeometryWindow(PamhyrWindow):
def update(self):
self._update()
def update_interpolated_profiles_visibility(self):
show_interpolated = self.find(
QCheckBox, "checkBox_show_interpolated"
).isChecked()
selection = self.tableView.selectionModel()
for row in range(self._table.rowCount()):
hidden = not show_interpolated \
and self._reach.profile(row).interpolated
self.tableView.setRowHidden(row, hidden)
if hidden:
selection.select(
self._table.index(row, 0),
QItemSelectionModel.Deselect | QItemSelectionModel.Rows
)
if selection.currentIndex().row() == row:
selection.setCurrentIndex(QModelIndex(),
QItemSelectionModel.NoUpdate)
def update_redraw(self):
self._update(redraw=True)
@@ -248,6 +281,7 @@ class GeometryWindow(PamhyrWindow):
self.find(QAction, "action_meshing").setEnabled(enabled)
def _update(self, redraw=False, propagate=True):
self.update_interpolated_profiles_visibility()
self.update_meshing_action()
if redraw:
@@ -498,6 +532,7 @@ class GeometryWindow(PamhyrWindow):
data=self._reach,
trad=self._trad,
toolbar=self._toolbar_ac,
parent=self,
)
self._plot_ac.draw()
+9 -8
View File
@@ -77,7 +77,7 @@ class TableModel(PamhyrTableModel):
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = format_datetime(
self._start_date + timedelta(seconds=float(v))
datetime(1970, 1, 1) + timedelta(seconds=float(v))
)
else:
value = f"{v}"
@@ -97,7 +97,7 @@ class TableModel(PamhyrTableModel):
try:
if (self._data.header[column] == "time"
and self._opt_data == "date"):
value = self.date_to_elapsed_seconds(value)
value = self.date_to_timestamp(value)
self._undo.push(
SetDataCommand(
@@ -184,17 +184,18 @@ class TableModel(PamhyrTableModel):
if len(data) == 0:
return
try:
rows = [self._data.new_from_data(header, d) for d in data]
except (ValueError, TypeError, IndexError) as error:
logger.warning(error)
return False
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
rows
)
)
+3 -3
View File
@@ -127,7 +127,7 @@ class PlotXY(PamhyrPlot):
for xy in zip(self.data.get_x(), self.data.get_y()):
self.line_xy.append(np.column_stack(xy))
self._colors, self._style = self.color_hightlight()
self._colors, self._style = self.color_highlight()
self.line_xy_collection = collections.LineCollection(
self.line_xy,
colors=self._colors,
@@ -136,7 +136,7 @@ class PlotXY(PamhyrPlot):
)
self.canvas.axes.add_collection(self.line_xy_collection)
def color_hightlight(self):
def color_highlight(self):
rk_min, rk_max = (-1, -1)
if self._highlight_data is not None:
rk_min, rk_max = self._highlight_data
@@ -250,7 +250,7 @@ class PlotXY(PamhyrPlot):
def update_current(self):
if self._current_data_update:
self._colors, self._style = self.color_hightlight()
self._colors, self._style = self.color_highlight()
self.line_xy_collection.set_colors(self._colors)
self.line_xy_collection.set_linestyle(self._style)
@@ -91,7 +91,7 @@ class TableModel(PamhyrTableModel):
value = timestamp_to_old_pamhyr_date_adists(int(v))
else:
value = format_datetime(
self._start_date + timedelta(seconds=float(v))
datetime(1970, 1, 1) + timedelta(seconds=float(v))
)
else:
value = f"{v}"
@@ -111,7 +111,7 @@ class TableModel(PamhyrTableModel):
try:
if (self._data.header[column] == "time"
and self._opt_data == "date"):
value = self.date_to_elapsed_seconds(value)
value = self.date_to_timestamp(value)
row = self.get_true_data_row(row)
@@ -57,6 +57,15 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
name = trad[self._pamhyr_name]
if self._data is not None:
pollutant_name = next(
(
pollutant.name
for pollutant in study.river.Pollutants.Pollutants_List
if pollutant.id == self._data.pollutant
),
None
)
if self._data.reach is not None:
reach_name = next(filter(
lambda reach: reach.id == self._data.reach,
@@ -75,12 +84,10 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
else:
end_rk = trad['not_associated']
name += (
f" - {study.name} - " +
f"{reach_name} - " +
f"({begin_rk} - " +
f"{end_rk})"
)
name += f" - {study.name}"
if pollutant_name is not None:
name += f" - {pollutant_name}"
name += f" - {reach_name} - ({begin_rk} - {end_rk})"
super(EditLateralContributionAdisTSWindow, self).__init__(
title=name,
@@ -0,0 +1,36 @@
# PlotXY.py -- Pamhyr
# Copyright (C) 2023-2026 INRAE
#
# 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.
#
# This program 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 <https://www.gnu.org/licenses/>.
from View.Geometry.PlotXY import PlotXY as GeometryPlotXY
class PlotXY(GeometryPlotXY):
"""Geometry plot highlighting the lateral-contribution extent."""
def color_highlight(self):
rk_min, rk_max = (-1, -1)
if self.highlight is not None:
rk_min, rk_max = self.highlight
colors = [
self.color_plot_river_bottom for _ in range(len(self.data))
]
for index, rk in enumerate(self.data.get_rk_complete_profiles()):
if rk_min <= rk <= rk_max:
colors[index] = self.color_plot_current
styles = ["-" for _ in range(len(self.data))]
return colors, styles
@@ -45,7 +45,7 @@ from View.LateralContributionsAdisTS.Table import (
)
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.Geometry.PlotXY import PlotXY
from View.LateralContributionsAdisTS.PlotXY import PlotXY
from View.LateralContributionsAdisTS.translate \
import LCTranslate
from View.LateralContributionsAdisTS.Edit.Window \
+65 -31
View File
@@ -61,6 +61,7 @@ from View.WaitingDialog import WaitingDialog
from View.MainWindowTabInfo import WidgetInfo
from View.MainWindowTabChecker import WidgetChecker
from View.MainWindowTabGraph import WidgetGraph
from View.Configure.Window import ConfigureWindow
from View.Study.Window import NewStudyWindow
@@ -235,6 +236,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def setup_tab(self):
self.setup_tab_info()
self.setup_tab_graph()
self.setup_tab_checker()
def setup_tab_info(self):
@@ -261,6 +263,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self._trad["tab_checker_name"]
)
def setup_tab_graph(self):
tab_widget = self.findChild(QTabWidget, "tabWidget")
self._tab_widget_graph = WidgetGraph(
study=self._study, trad=self._trad, parent=self
)
tab_widget.insertTab(
0, self._tab_widget_graph,
self._trad["tab_graph_name"]
)
tab_widget.setCurrentWidget(self._tab_widget_graph)
def enable_actions(self, action: str, enable: bool):
"""Enable of disable an action componant
@@ -545,6 +560,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self._do_propagate_update_rec(window, keys)
self._tab_widget_checker.update(modules=keys)
self._tab_widget_graph.update()
def _do_propagate_update_info_tab(self, keys):
modules = Modules.modelling_list()
@@ -570,6 +586,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self._tab_widget_info.study = self._study
self._tab_widget_info.update()
if self._tab_widget_graph.study != self._study:
self._tab_widget_graph.study = self._study
self._tab_widget_graph.update()
if self._tab_widget_checker.study != self._study:
self._tab_widget_checker.study = self._study
self._tab_widget_checker.update(modules=Modules.STUDY)
@@ -898,13 +918,32 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
# MSG AND DIALOG #
##################
def msg_select_reach(self):
self.message_box(
window_title=self._trad["Warning"],
text=self._trad["mb_select_reach_title"],
informative_text=self._trad["mb_select_reach_msg"]
def ensure_current_reach(self):
"""Offer a reach selection when needed;
return False on cancellation."""
if self._study is None:
return False
river = self._study.river
if river.has_current_reach():
return True
edges = list(river.edges())
if not edges:
QMessageBox.information(
self, self._trad["Select reach"], self._trad["no_reach"]
)
return False
labels = [f"{edge.name or self._trad['reach']} (#{edge.id})"
for edge in edges]
selected, accepted = QInputDialog.getItem(
self, self._trad["Select reach"],
self._trad["reach"] + ":", labels, 0, False
)
self.open_network()
if not accepted:
return False
river.set_current_reach(edges[labels.index(selected)])
self._tab_widget_graph.update()
self._propagate_update(key=Modules.NETWORK)
return True
def dialog_reopen_study(self):
dlg = QMessageBox(self)
@@ -1287,6 +1326,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
return
self.network = NetworkWindow(study=self._study, parent=self)
self.network.networkChanged.connect(
self._tab_widget_graph.update, Qt.QueuedConnection
)
self.network.show()
def open_scenarios(self):
@@ -1336,7 +1378,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
Returns:
Nothing
"""
if (self._study is not None and self._study.river.has_current_reach()):
if self.ensure_current_reach():
reach = self._study.river.current_reach().reach
if self.sub_window_exists(
@@ -1356,9 +1398,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
geometry.show()
return geometry
else:
self.msg_select_reach()
return None
return None
def open_meshing(self):
"""Open the current reach geometry and its meshing dialog."""
@@ -1441,27 +1481,24 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
strick.show()
def open_frictions(self):
if self._study is not None:
if self._study.river.has_current_reach():
reach = self._study.river.current_reach()
if self.ensure_current_reach():
reach = self._study.river.current_reach()
if self.sub_window_exists(
FrictionsWindow,
data=[self._study, self.conf, reach]
):
return
if self.sub_window_exists(
FrictionsWindow,
data=[self._study, self.conf, reach]
):
return
frictions = FrictionsWindow(
study=self._study,
config=self.conf,
parent=self
)
frictions.show()
else:
self.msg_select_reach()
frictions = FrictionsWindow(
study=self._study,
config=self.conf,
parent=self
)
frictions.show()
def open_initial_conditions(self):
if self._study.river.has_current_reach():
if self.ensure_current_reach():
reach = self._study.river.current_reach()
if self.sub_window_exists(
@@ -1477,8 +1514,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
parent=self
)
initial.show()
else:
self.msg_select_reach()
def open_additional_files(self):
if self._study is not None:
@@ -1552,8 +1587,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
return
if not self._study.river.has_current_reach():
self.msg_select_reach()
if not self.ensure_current_reach():
return
reach = self._study.river.current_reach().reach
+139
View File
@@ -0,0 +1,139 @@
# MainWindowTabGraph.py -- Pamhyr
# Copyright (C) 2026 INRAE
#
# 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.
# -*- coding: utf-8 -*-
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
from View.PlotXY import PlotXY
from View.Network.GraphWidget import GraphWidget
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QWidget, QGroupBox, QLabel, QHBoxLayout, QVBoxLayout, QSplitter,
)
class WidgetGraph(QWidget):
"""Read-only network graph displayed in the main window."""
def __init__(self, study=None, trad=None, parent=None):
super(WidgetGraph, self).__init__(parent)
self._study = study
self._trad = trad
self._plot_river = None
layout = QHBoxLayout(self)
self._splitter = QSplitter(Qt.Horizontal, self)
self._splitter.setChildrenCollapsible(False)
layout.addWidget(self._splitter)
self._graph_widget = None
self._graph_group = QGroupBox(
self._trad["graph_network_title"], self
)
self._graph_layout = QVBoxLayout(self._graph_group)
self._graph_title = QLabel(self._graph_group)
self._graph_title.setTextFormat(Qt.PlainText)
self._graph_title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self._graph_title.setWordWrap(True)
self._graph_layout.addWidget(self._graph_title)
self._update_graph_title()
self._splitter.addWidget(self._graph_group)
self.canvas = MplCanvas(width=5, height=4, dpi=100)
self.canvas.setObjectName("canvas_graph")
self.toolbar = PamhyrPlotToolbar(
self.canvas, self,
items=["home", "zoom", "save", "iso", "back/forward", "move"]
)
self._plot_group = QGroupBox(
self._trad["graph_geographic_title"], self
)
self._plot_layout = QVBoxLayout(self._plot_group)
self._plot_layout.addWidget(self.toolbar)
self._plot_layout.addWidget(self.canvas, 1)
self._splitter.addWidget(self._plot_group)
self._splitter.setStretchFactor(0, 1)
self._splitter.setStretchFactor(1, 1)
self._splitter.setSizes([1000, 1000])
self.plot = PlotXY(
canvas=self.canvas,
data=None,
trad=self._trad,
toolbar=self.toolbar,
parent=self
)
@property
def study(self):
return self._study
@study.setter
def study(self, study):
self._study = study
self._update_graph_title()
def _update_graph_title(self):
self._graph_title.setText(
self._study.name if self._study is not None else ""
)
def update(self):
river = self._study.river if self._study is not None else None
view = None
if river is not None and river is self._plot_river:
axes = self.canvas.axes
if axes.has_data():
view = (axes.get_xlim(), axes.get_ylim(),
axes.get_aspect(), axes.get_adjustable())
self._update_graph_title()
if (self._graph_widget is not None
and (self._study is None
or self._graph_widget.graph is not self._study.river)):
self._graph_layout.removeWidget(self._graph_widget)
self._graph_widget.deleteLater()
self._graph_widget = None
if self._study is not None and self._graph_widget is None:
self._graph_widget = GraphWidget(
self._study.river,
parent=self,
only_display=True,
trad=self._trad,
)
self._graph_layout.addWidget(self._graph_widget, 1)
elif self._graph_widget is not None:
self._graph_widget.display_update()
data = None
geotiff = None
if self._study is not None:
data = self._study.river.enable_edges()
geotiff = self._study.river.geotiff
self.plot = PlotXY(
canvas=self.canvas,
data=data,
geotiff=geotiff,
trad=self._trad,
toolbar=self.toolbar,
parent=self
)
self.plot.update()
self._plot_river = river
if view is not None:
x_limits, y_limits, aspect, adjustable = view
self.canvas.axes.set_aspect(aspect, adjustable=adjustable)
self.canvas.axes.set_xlim(x_limits)
self.canvas.axes.set_ylim(y_limits)
self.canvas.draw_idle()
+47 -17
View File
@@ -448,6 +448,7 @@ class NewEdgeLine(QGraphicsItem):
class GraphWidget(QGraphicsView):
changeEdge = pyqtSignal(object)
changeNode = pyqtSignal(object)
currentEdgeChanged = pyqtSignal()
def __init__(self, graph, parent=None,
min_size=(400, 400), max_size=None,
@@ -476,6 +477,7 @@ class GraphWidget(QGraphicsView):
self.m_origin_x = 0.0
self.m_origin_y = 0.0
self.clicked = False
self._panning = False
self.setup_scene(min_size, max_size, size)
@@ -491,8 +493,8 @@ class GraphWidget(QGraphicsView):
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
self.scale(1, 1)
self.previousScale = 1
self.scale(0.7, 0.7)
self.previousScale = 0.7
self.centerOn(1000.0, 1000.0)
if min_size:
@@ -667,6 +669,13 @@ class GraphWidget(QGraphicsView):
Returns:
Nothing
"""
# Scene items are destroyed by clear(); do not retain hover/selection
# references to them when refreshing another view of the same graph.
self._selected_item = None
self._selected_new_edge_src_node = None
self._current_edge = None
self._current_moved_node = None
self.tmp_line = None
self.scene().clear()
self.create_items()
@@ -875,6 +884,9 @@ class GraphWidget(QGraphicsView):
if previous_edge:
previous_edge.update()
edge.update()
if previous_edge is not edge:
self.currentEdgeChanged.emit()
except Exception as e:
logger.warning(str(e))
@@ -937,6 +949,8 @@ class GraphWidget(QGraphicsView):
def mousePressEvent(self, event):
if self._only_display:
if event.button() == Qt.LeftButton:
self._start_pan(event)
return
if event.button() == Qt.RightButton \
@@ -959,6 +973,12 @@ class GraphWidget(QGraphicsView):
self._selected_new_edge_src_node = None
items = self.items(event.pos())
if event.button() == Qt.LeftButton and not any(
isinstance(item, (NodeItem, EdgeItem, NodeText))
for item in items
):
self._start_pan(event)
return
if items and type(items[0]) is EdgeItem:
edge = items[0]
if edge:
@@ -1007,7 +1027,10 @@ class GraphWidget(QGraphicsView):
def mouseReleaseEvent(self, event):
self.clicked = False
if self._only_display:
if self._panning or self._only_display:
self._panning = False
self.viewport().unsetCursor()
event.accept()
return
locked = self.graph._status.is_read_only()
@@ -1029,7 +1052,28 @@ class GraphWidget(QGraphicsView):
self.update()
super(GraphWidget, self).mouseReleaseEvent(event)
def _start_pan(self, event):
self.clicked = True
self._panning = True
self.m_origin_x = event.x()
self.m_origin_y = event.y()
self.viewport().setCursor(Qt.ClosedHandCursor)
event.accept()
def mouseMoveEvent(self, event):
if self._panning or self._only_display:
if self._panning and event.buttons() & Qt.LeftButton:
dx = event.x() - self.m_origin_x
dy = event.y() - self.m_origin_y
horizontal = self.horizontalScrollBar()
vertical = self.verticalScrollBar()
horizontal.setValue(horizontal.value() - dx)
vertical.setValue(vertical.value() - dy)
self.m_origin_x = event.x()
self.m_origin_y = event.y()
event.accept()
return
pos = self.mapToScene(event.pos())
locked = self.graph._status.is_read_only()
@@ -1061,20 +1105,6 @@ class GraphWidget(QGraphicsView):
# If state is "move"
if self._state == "move":
# Move on scene
if not self.selected_item():
if event.buttons() & Qt.LeftButton:
old_p = self.mapToScene(
int(self.m_origin_x), int(self.m_origin_y)
)
new_p = self.mapToScene(event.pos())
translation = new_p - old_p
self.translate(translation.x(), translation.y())
self.m_origin_x = event.x()
self.m_origin_y = event.y()
# Propagate event
self.update()
super(GraphWidget, self).mouseMoveEvent(event)
+26 -7
View File
@@ -64,7 +64,17 @@ class SelectProfileDialog(PamhyrDialog):
self._reach = reach
self._profile = None
self._profiles = self._reach.reach.enabled_profiles
self._profiles = list(self._reach.reach.profiles)
structure_profiles = [
structure.input_section
for structure in study.river.hydraulic_structures.lst
if structure.input_reach is reach and not structure.is_deleted()
]
self._selectable_indices = [
index for index, profile in enumerate(self._profiles)
if 0 < index < len(self._profiles) - 1
and profile not in structure_profiles
]
self.setup_combobox()
@@ -74,19 +84,28 @@ class SelectProfileDialog(PamhyrDialog):
list(
map(
lambda p: p.display_name(),
self._reach.reach.profiles[1:-1]
self._profiles
)
)
)
if len(self._profiles) == 0:
self.find(QDialogButtonBox, "buttonBox")\
.button(QDialogButtonBox.Ok)\
.setEnabled(False)
combobox = self.find(QComboBox, "comboBox")
for index in range(len(self._profiles)):
if index not in self._selectable_indices:
item = combobox.model().item(index)
item.setFlags(item.flags() &
~(Qt.ItemIsEnabled | Qt.ItemIsSelectable))
combobox.setCurrentIndex(
self._selectable_indices[0] if self._selectable_indices else -1
)
self.find(QDialogButtonBox, "buttonBox")\
.button(QDialogButtonBox.Ok)\
.setEnabled(bool(self._selectable_indices))
def accept(self):
index = self.find(QComboBox, "comboBox").currentIndex()
if not 0 <= index < len(self._profiles):
if index not in self._selectable_indices:
return
self._profile = self._profiles[index]
+4
View File
@@ -58,6 +58,8 @@ _translate = QCoreApplication.translate
class NetworkWindow(PamhyrWindow):
networkChanged = pyqtSignal()
_pamhyr_ui = "Network"
_pamhyr_name = "River network"
@@ -140,6 +142,8 @@ class NetworkWindow(PamhyrWindow):
self._graph_layout.addWidget(self._graph_widget)
def setup_connections(self):
self._undo_stack.indexChanged.connect(self.networkChanged)
self._graph_widget.currentEdgeChanged.connect(self.networkChanged)
self._nodes_model.dataChanged.connect(self.update)
self._reachs_model.dataChanged.connect(
self._graph_widget.display_update)
+7 -4
View File
@@ -76,11 +76,14 @@ class PlotRKC(PamhyrPlot):
@staticmethod
def reach_geometry(reach):
"""Return geometry values for profiles present in the results."""
# The study's enabled profiles can change after a calculation. Keep
# coordinates in the same order as the result profiles and columns.
profiles = reach.profiles
return (
reach.geometry.get_rk_enabled_profiles(),
reach.geometry.get_z_min_enabled_profiles(),
reach.geometry.get_z_max_enabled_profiles()
)
[profile.rk for profile in profiles],
[profile.geometry.z_min() for profile in profiles],
[profile.geometry.z_max() for profile in profiles],
)
@timer
def draw(self, highlight=None):
+51 -1
View File
@@ -45,6 +45,36 @@ logger = logging.getLogger()
_translate = QCoreApplication.translate
class ValueDelegate(QItemDelegate):
"""Use a combo box for solver parameters backed by an index."""
def createEditor(self, parent, option, index):
choices = index.model().value_choices(index)
if choices is None:
return QLineEdit(parent)
editor = QComboBox(parent)
for value, label in choices.items():
editor.addItem(label, value)
return editor
def setEditorData(self, editor, index):
if isinstance(editor, QComboBox):
current = index.model().raw_value(index)
editor.setCurrentIndex(editor.findData(current))
else:
editor.setText(str(index.model().raw_value(index)))
def setModelData(self, editor, model, index):
if isinstance(editor, QComboBox):
model.setData(index, editor.currentData())
else:
model.setData(index, editor.text())
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
class TableModel(PamhyrTableModel):
def _setup_lst(self):
self._tab = self._opt_data
@@ -68,6 +98,10 @@ class TableModel(PamhyrTableModel):
elif cname == "value":
value = self._lst.get(row)[cname]
choices = self.value_choices(index)
if choices is not None:
return choices.get(value, value)
if value in self._trad.get_dict("yes_no"):
value = self._trad.get_dict("yes_no")[value]
@@ -79,7 +113,14 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
choices = self.value_choices(index)
if choices is not None:
reverse_choices = {label: key for key, label in choices.items()}
value = reverse_choices.get(value, value)
if str(self.raw_value(index)) == str(value):
return False
elif self.is_same_data(index, value):
return False
row = index.row()
@@ -103,6 +144,15 @@ class TableModel(PamhyrTableModel):
self.dataChanged.emit(index, index)
return True
def value_choices(self, index):
if not index.isValid():
return None
name = self._lst.get(index.row())["name"]
return self._trad.get_dict("indexed_values").get(name)
def raw_value(self, index):
return self._lst.get(index.row())["value"]
def undo(self):
self._undo.undo()
self.layoutChanged.emit()
+2 -1
View File
@@ -41,7 +41,7 @@ from PyQt5.QtWidgets import (
)
from View.SolverParameters.UndoCommand import *
from View.SolverParameters.Table import TableModel
from View.SolverParameters.Table import TableModel, ValueDelegate
from View.SolverParameters.translate import ParamTranslate
from Solver.Solvers import solver_long_name, solver_type_list
@@ -103,6 +103,7 @@ class SolverParametersWindow(PamhyrWindow):
opt_data=st,
table_headers=self._trad.get_dict("table_headers"),
editable_headers=editable_headers,
delegates={"value": ValueDelegate(table)},
trad=self._trad,
undo=self._undo_stack[st],
)
+24
View File
@@ -50,6 +50,30 @@ class ParamTranslate(MainTranslate):
_translate("SolverParameters", "N"): "n",
}
self._sub_dict["indexed_values"] = {
"mage_shields_critique": {
"1": _translate("SolverParameters", "Constant (0.047)"),
"2": _translate("SolverParameters", "Soulsby (1997)"),
"3": _translate("SolverParameters", "Camenen (2012)"),
},
"mage_shields_correction": {
"0": _translate("SolverParameters", "No correction"),
"1": _translate("SolverParameters", "Effective Shields"),
},
"mage_capacite_solide": {
"1": _translate(
"SolverParameters", "Meyer-Peter & Muller (1948)"
),
"2": _translate(
"SolverParameters", "Camenen & Larson (2005)"
),
"3": _translate(
"SolverParameters", "Engelund & Hansen (1967)"
),
"4": _translate("SolverParameters", "Recking (2013)"),
},
}
self._sub_dict["names"] = {
"all_init_time":
_translate("SolverParameters",
+4 -3
View File
@@ -18,6 +18,7 @@
import logging
import traceback
from datetime import timezone
from tools import trace, timer, parse_datetime
@@ -62,8 +63,8 @@ class PamhyrTextDelegate(QStyledItemDelegate):
class PamhyrTableModel(QAbstractTableModel):
def date_to_elapsed_seconds(self, value):
"""Convert an entered date to seconds since the study start date."""
def date_to_timestamp(self, value):
"""Convert an accepted calendar date to its raw UTC timestamp."""
try:
entered_date = parse_datetime(value)
except ValueError as error:
@@ -81,7 +82,7 @@ class PamhyrTableModel(QAbstractTableModel):
)
raise error
return (entered_date - self._start_date).total_seconds()
return entered_date.replace(tzinfo=timezone.utc).timestamp()
def _setup_delegates(self):
if self._table_view is None:
+11 -6
View File
@@ -175,6 +175,15 @@ class MainTranslate(UnitTranslate):
self._dict["tab_checker_name"] = _translate(
"MainWindow", "Checks"
)
self._dict["tab_graph_name"] = _translate(
"MainWindow", "Graph"
)
self._dict["graph_network_title"] = _translate(
"MainWindow", "Hydrographic network"
)
self._dict["graph_geographic_title"] = _translate(
"MainWindow", "Geographic view"
)
self._dict["open_debug"] = _translate(
"MainWindow", "Open debug window"
@@ -200,13 +209,9 @@ class MainTranslate(UnitTranslate):
self._dict["Warning"] = _translate(
"MainWindow", "Warning"
)
self._dict["mb_select_reach_title"] = _translate(
"MainWindow", "Please select a reach"
)
self._dict["mb_select_reach_msg"] = _translate(
self._dict["no_reach"] = _translate(
"MainWindow",
"This edition window need a reach selected "
"into the river network to work on it"
"Create a reach in the network before opening this window."
)
self._dict["mb_last_open_title"] = _translate(
+9 -8
View File
@@ -78,7 +78,7 @@ class TableModel(PamhyrTableModel):
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = format_datetime(
self._start_date + timedelta(seconds=float(v))
datetime(1970, 1, 1) + timedelta(seconds=float(v))
)
else:
value = f"{v}"
@@ -98,7 +98,7 @@ class TableModel(PamhyrTableModel):
try:
if (self._data.header[column] == "time"
and self._opt_data == "date"):
value = self.date_to_elapsed_seconds(value)
value = self.date_to_timestamp(value)
self._undo.push(
SetDataCommand(
@@ -175,17 +175,18 @@ class TableModel(PamhyrTableModel):
if len(data) == 0:
return
try:
rows = [self._data.new_from_data(header, d) for d in data]
except (ValueError, TypeError, IndexError) as error:
logger.warning(error)
return False
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
rows
)
)
+1 -1
View File
@@ -40,7 +40,7 @@ class WPETranslate(WeatherParametersTranslate):
"Humidity"),
"radiation": _translate("WeatherParameters", "Radiation (W/m²)"),
"wind speed": _translate("WeatherParameters", "Wind Speed (m/s)"),
"albedo": _translate("WeatherParameters", "Albedo"),
"albedo": _translate("WeatherParameters", "Water albedo"),
"shading coefficient": _translate("WeatherParameters",
"Shading Coefficient"),
"cloud cover fraction": _translate("WeatherParameters",
+1 -1
View File
@@ -76,7 +76,7 @@ class WeatherParametersTranslate(MainTranslate):
"Groundwater Temperature (°C)"),
"surface_flow_rate": _translate("WeatherParameters",
"Groundwater Flow Rate (m³/s)"),
"albedo": _translate("WeatherParameters", "Albedo"),
"albedo": _translate("WeatherParameters", "Water albedo"),
"shading_coefficient": _translate("WeatherParameters",
"Shading Coefficient"),
"cloud_cover_fraction": _translate("WeatherParameters",
@@ -56,7 +56,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>TextLabel</string>
<string></string>
</property>
</widget>
</item>
+10
View File
@@ -25,6 +25,16 @@
</property>
<widget class="QWidget" name="horizontalLayoutWidget">
<layout class="QVBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBox_show_interpolated">
<property name="text">
<string notr="true">Show interpolated profiles</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="tableView"/>
</item>
+227 -147
View File
File diff suppressed because it is too large. Load diff