From 081e6e732232cfb6bb386a682260df806e7c93ac Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Thu, 10 Sep 2026 13:56:46 +0200 Subject: [PATCH] Geometry:toggle interpolated profiles visibility in geometry table and plots --- src/View/Geometry/PlotAC.py | 11 +++++++---- src/View/Geometry/PlotRKZ.py | 25 +++++++++++-------------- src/View/Geometry/PlotXY.py | 22 ++++++++-------------- src/View/Geometry/Translate.py | 3 +++ src/View/Geometry/Window.py | 30 ++++++++++++++++++++++++++++++ src/View/ui/GeometryReach.ui | 10 ++++++++++ 6 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/View/Geometry/PlotAC.py b/src/View/Geometry/PlotAC.py index b86ecb0a..9feba1d3 100644 --- a/src/View/Geometry/PlotAC.py +++ b/src/View/Geometry/PlotAC.py @@ -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() diff --git a/src/View/Geometry/PlotRKZ.py b/src/View/Geometry/PlotRKZ.py index 3de5ebac..a3bf8d1a 100644 --- a/src/View/Geometry/PlotRKZ.py +++ b/src/View/Geometry/PlotRKZ.py @@ -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,6 +203,13 @@ 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( diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py index 39e8feb8..dba2b394 100644 --- a/src/View/Geometry/PlotXY.py +++ b/src/View/Geometry/PlotXY.py @@ -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,8 +179,12 @@ 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_highlight() self.line_xy_collection = collections.LineCollection( diff --git a/src/View/Geometry/Translate.py b/src/View/Geometry/Translate.py index 282c500b..8124c929 100644 --- a/src/View/Geometry/Translate.py +++ b/src/View/Geometry/Translate.py @@ -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)" ) diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py index 5399243e..e6a706ac 100644 --- a/src/View/Geometry/Window.py +++ b/src/View/Geometry/Window.py @@ -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,15 @@ 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 +249,22 @@ 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 +276,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 +527,7 @@ class GeometryWindow(PamhyrWindow): data=self._reach, trad=self._trad, toolbar=self._toolbar_ac, + parent=self, ) self._plot_ac.draw() diff --git a/src/View/ui/GeometryReach.ui b/src/View/ui/GeometryReach.ui index c87ed1db..81aa2e83 100644 --- a/src/View/ui/GeometryReach.ui +++ b/src/View/ui/GeometryReach.ui @@ -25,6 +25,16 @@ + + + + Show interpolated profiles + + + true + + +