Geometry:toggle interpolated profiles visibility in geometry table and plots

dev_dylan
Dylan Jeannin 2026-09-10 13:56:46 +02:00
parent a0d8b9ea43
commit 081e6e7322
6 changed files with 69 additions and 32 deletions

View File

@ -112,7 +112,7 @@ class PlotAC(PamhyrPlot):
profile_id = 0 profile_id = 0
profile = self.data.profile(profile_id) profile = self.data.profile(profile_id)
if profile is None: if profile is None or self._parent.tableView.isRowHidden(profile_id):
return return
station = profile.get_station() station = profile.get_station()
@ -192,21 +192,24 @@ class PlotAC(PamhyrPlot):
self.plot_selected.set_data([], []) self.plot_selected.set_data([], [])
self.next_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.previous_plot_selected.set_data(
self.data.profile(previous_id).get_station(), self.data.profile(previous_id).get_station(),
self.data.profile(previous_id).z() self.data.profile(previous_id).z()
) )
self.previous_plot_selected.set_visible(True) 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.plot_selected.set_data(
self.data.profile(profile_id).get_station(), self.data.profile(profile_id).get_station(),
self.data.profile(profile_id).z() self.data.profile(profile_id).z()
) )
self.plot_selected.set_visible(True) 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.next_plot_selected.set_data(
self.data.profile(next_id).get_station(), self.data.profile(next_id).get_station(),
self.data.profile(next_id).z() self.data.profile(next_id).z()

View File

@ -110,9 +110,9 @@ class PlotRKZ(PamhyrPlot):
def _closest_rk(self, event): def _closest_rk(self, event):
s = event.artist.get_segments() s = event.artist.get_segments()
x = [i[0, 0] for i in s]
mx = event.mouseevent.xdata 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): def dist_mouse(point):
x = point[1] x = point[1]
@ -136,6 +136,7 @@ class PlotRKZ(PamhyrPlot):
if len(ind) == 0: if len(ind) == 0:
return return
ind = [i for i in ind if not self._table.isRowHidden(i)]
for i in ind: for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0))) 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)) self._table.scrollTo(self._table.model().index(ind[-1], 0))
def _select_range_in_table(self, ind1, ind2): def _select_range_in_table(self, ind1, ind2):
if self._table is not None: self._select_in_table(list(range(ind1, ind2 + 1)))
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))
@timer @timer
def redraw(self, data): def redraw(self, data):
@ -213,6 +203,13 @@ class PlotRKZ(PamhyrPlot):
picker=10, 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): def color_highlight(self):
rows = sorted(list( rows = sorted(list(
set( set(

View File

@ -136,6 +136,7 @@ class PlotXY(PamhyrPlot):
index = QItemSelection() index = QItemSelection()
if len(ind) == 0: if len(ind) == 0:
return return
ind = [i for i in ind if not self._table.isRowHidden(i)]
for i in ind: for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0))) index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select( selection.select(
@ -149,18 +150,7 @@ class PlotXY(PamhyrPlot):
self._table.scrollTo(self._table.model().index(ind[-1], 0)) self._table.scrollTo(self._table.model().index(ind[-1], 0))
def _select_range_in_table(self, ind1, ind2): def _select_range_in_table(self, ind1, ind2):
if self._table is not None: self._select_in_table(list(range(ind1, ind2 + 1)))
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))
@timer @timer
def redraw(self, data): def redraw(self, data):
@ -189,8 +179,12 @@ class PlotXY(PamhyrPlot):
def draw_xy(self): def draw_xy(self):
self.line_xy = [] self.line_xy = []
for xy in zip(self.data.get_x(), self.data.get_y()): for row, profile in enumerate(self.data.profiles):
self.line_xy.append(np.column_stack(xy)) 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._colors, self._style = self.color_highlight()
self.line_xy_collection = collections.LineCollection( self.line_xy_collection = collections.LineCollection(

View File

@ -45,6 +45,9 @@ class GeometryTranslate(MainTranslate):
self._dict["cross_sections"] = _translate("Geometry", "cross-sections") self._dict["cross_sections"] = _translate("Geometry", "cross-sections")
self._dict["profile"] = _translate("Geometry", "cross-section") self._dict["profile"] = _translate("Geometry", "cross-section")
self._dict["profiles"] = _translate("Geometry", "cross-sections") self._dict["profiles"] = _translate("Geometry", "cross-sections")
self._dict["show_interpolated_profiles"] = _translate(
"Geometry", "Show interpolated profiles"
)
self._dict["cross_section_enabled_count"] = _translate( self._dict["cross_section_enabled_count"] = _translate(
"Geometry", "Cross-section enabled ({count} disabled)" "Geometry", "Cross-section enabled ({count} disabled)"
) )

View File

@ -127,6 +127,9 @@ class GeometryWindow(PamhyrWindow):
table.setAlternatingRowColors(True) table.setAlternatingRowColors(True)
def setup_checkbox(self): def setup_checkbox(self):
self.find(QCheckBox, "checkBox_show_interpolated").setText(
self._trad["show_interpolated_profiles"]
)
self._checkbox = self.find(QCheckBox, "checkBox_enabled") self._checkbox = self.find(QCheckBox, "checkBox_enabled")
self._set_checkbox_state() self._set_checkbox_state()
@ -197,6 +200,15 @@ class GeometryWindow(PamhyrWindow):
self._status_label.setText(txt) self._status_label.setText(txt)
def setup_connections(self): 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(): if self._study.is_read_only():
actions = { actions = {
"action_export": self.export_to_file, "action_export": self.export_to_file,
@ -237,6 +249,22 @@ class GeometryWindow(PamhyrWindow):
def update(self): def update(self):
self._update() 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): def update_redraw(self):
self._update(redraw=True) self._update(redraw=True)
@ -248,6 +276,7 @@ class GeometryWindow(PamhyrWindow):
self.find(QAction, "action_meshing").setEnabled(enabled) self.find(QAction, "action_meshing").setEnabled(enabled)
def _update(self, redraw=False, propagate=True): def _update(self, redraw=False, propagate=True):
self.update_interpolated_profiles_visibility()
self.update_meshing_action() self.update_meshing_action()
if redraw: if redraw:
@ -498,6 +527,7 @@ class GeometryWindow(PamhyrWindow):
data=self._reach, data=self._reach,
trad=self._trad, trad=self._trad,
toolbar=self._toolbar_ac, toolbar=self._toolbar_ac,
parent=self,
) )
self._plot_ac.draw() self._plot_ac.draw()

View File

@ -25,6 +25,16 @@
</property> </property>
<widget class="QWidget" name="horizontalLayoutWidget"> <widget class="QWidget" name="horizontalLayoutWidget">
<layout class="QVBoxLayout" name="horizontalLayout"> <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> <item>
<widget class="QTableView" name="tableView"/> <widget class="QTableView" name="tableView"/>
</item> </item>