fixed label under 3d view

This commit is contained in:
ykcheungab
2026-09-15 21:50:37 +08:00
parent c2293d4d41
commit c538dbf074
7 changed files with 269 additions and 212 deletions
+70 -11
View File
@@ -282,11 +282,22 @@ class ThreeDPanel(QFrame):
controls.addStretch(1)
# -------------------------------------------------------------------- legend
# What is on screen, in three short pieces: the ramp the shader used, the numbers
# it used it for, and which source produced the field. Reading the picture needs
# the first two, so they stay; nothing here is a setting.
# The ramp and its effective numeric bounds remain visible in normal mode.
# Everything explanatory below them follows the diagnostics switch.
scale_row = QHBoxLayout()
scale_row.setContentsMargins(0, 0, 0, 0)
scale_row.setSpacing(6)
self.scale_lower_label = QLabel()
self.scale_lower_label.setObjectName("panelMeta")
self.scale_lower_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
scale_row.addWidget(self.scale_lower_label)
self.scale_bar = ColorScaleBar()
root.addWidget(self.scale_bar)
scale_row.addWidget(self.scale_bar, 1)
self.scale_upper_label = QLabel()
self.scale_upper_label.setObjectName("panelMeta")
self.scale_upper_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
scale_row.addWidget(self.scale_upper_label)
root.addLayout(scale_row)
legend_row = QHBoxLayout()
legend_row.setContentsMargins(0, 0, 0, 0)
@@ -345,16 +356,20 @@ class ThreeDPanel(QFrame):
def set_descriptor(self, descriptor: Optional[FieldDescriptor]) -> None:
"""The measurement currently on screen — or none, which hides the bar."""
if descriptor != self._descriptor:
self._effective_scale = None
self._descriptor = descriptor
self._render_field_note()
if descriptor is None or descriptor.quantity == "unavailable":
# No measurement: do not leave the previous range on display.
self.legend_label.setText(t("scene3d.legend_none"))
self.legend_label.setVisible(True)
self.legend_label.setVisible(self._show_diagnostics)
self.scale_combo.setEnabled(False)
self.lower_spin.setEnabled(False)
self.upper_spin.setEnabled(False)
self.scale_bar.setVisible(False)
self.scale_lower_label.setVisible(False)
self.scale_upper_label.setVisible(False)
return
self.scale_combo.setEnabled(True)
fixed = self.scale_combo.currentData() == "fixed"
@@ -364,6 +379,7 @@ class ThreeDPanel(QFrame):
"diverging" if descriptor.signed and not fixed else "sequential"
)
self.scale_bar.setVisible(True)
self._render_scale_bounds()
self._render_legend()
def set_capabilities(self, capabilities: Optional[SceneCapabilities]) -> None:
@@ -410,6 +426,7 @@ class ThreeDPanel(QFrame):
quality=quality,
)
)
self.legend_label.setVisible(self._show_diagnostics)
return
mode = t(
"scene3d.legend_auto"
@@ -429,6 +446,32 @@ class ThreeDPanel(QFrame):
quality=quality,
)
)
self.legend_label.setVisible(self._show_diagnostics)
def _render_scale_bounds(self) -> None:
"""Show only the numeric bounds needed to read the color ramp."""
descriptor = self._descriptor
visible = bool(
descriptor is not None and descriptor.quantity != "unavailable"
)
lower = ""
upper = ""
mode = str(self.scale_combo.currentData() or "fixed")
effective = self._effective_scale
if visible and mode == "fixed":
lower = f"{self.lower_spin.value():.3g}"
upper = f"{self.upper_spin.value():.3g}"
elif (
visible
and effective is not None
and effective.scale_mode == "automatic"
):
lower = f"{effective.scale_lower:.3g}"
upper = f"{effective.scale_upper:.3g}"
self.scale_lower_label.setText(lower)
self.scale_upper_label.setText(upper)
self.scale_lower_label.setVisible(visible)
self.scale_upper_label.setVisible(visible)
def _set_legend(self, text: str) -> None:
"""One legend line, with the whole text in the tooltip (it may be clipped)."""
@@ -438,7 +481,7 @@ class ThreeDPanel(QFrame):
def set_state(self, state: SceneState) -> None:
self._state = state
self.state_label.setText(t(f"scene3d.state_{state}"))
self.state_label.setVisible(state != "live")
self.state_label.setVisible(self._show_diagnostics and state != "live")
def set_source_kind(self, kind: str) -> None:
"""Say where the field comes from: ``live``, ``replay`` or ``recompute``.
@@ -459,6 +502,7 @@ class ThreeDPanel(QFrame):
self._source_kind = kind
self.source_label.setText(t(f"scene3d.source_{kind}"))
self.source_label.setToolTip(t(f"scene3d.source_{kind}_tip"))
self.source_label.setVisible(self._show_diagnostics)
def set_diagnostic(self, diagnostic: Optional[Diagnostic]) -> None:
"""One diagnostic line. The 2D views stay usable behind it.
@@ -484,13 +528,16 @@ class ThreeDPanel(QFrame):
def set_diagnostics_visible(self, visible: bool) -> None:
"""How much the pane explains itself (see the window's 诊断信息 switch).
Off: the pane states what the picture *is* — the colour ramp, the quantity and
its range, where the field came from, and any warning about the measurement —
and stops explaining the pipeline around it. On: the same picture plus those
explanations, which is what an engineer asking "why is that frame blank" wants.
Off: only the colour ramp and its numeric bounds remain, except that warnings
and errors about the measurement are still shown. On: quantity, source, state,
substitutions and pipeline explanations are restored.
"""
self._show_diagnostics = bool(visible)
self._render_field_note()
self.source_label.setVisible(self._show_diagnostics)
self.state_label.setVisible(
self._show_diagnostics and self._state != "live"
)
self.set_diagnostic(None)
def diagnostics_visible(self) -> bool:
@@ -506,7 +553,13 @@ class ThreeDPanel(QFrame):
"""
wanted = _FIELD_QUANTITY.get(self.field(), "")
shown = "" if self._descriptor is None else str(self._descriptor.quantity)
if not wanted or not shown or shown == wanted or shown == "unavailable":
if (
not self._show_diagnostics
or not wanted
or not shown
or shown == wanted
or shown == "unavailable"
):
self.field_note.setText("")
self.field_note.setVisible(False)
return
@@ -528,6 +581,7 @@ class ThreeDPanel(QFrame):
def set_render_stats(self, stats: RenderStats) -> None:
"""Display-side statistics only: never shown as recording health."""
self._effective_scale = stats
self._render_scale_bounds()
self._render_legend()
self.stats_label.setText(
t(
@@ -658,6 +712,7 @@ class ThreeDPanel(QFrame):
def _emit_settings(self) -> None:
if self._syncing:
return
self._render_scale_bounds()
self.settingsChanged.emit(self.settings())
def _legend_reset_note(self) -> None:
@@ -686,5 +741,9 @@ class ThreeDPanel(QFrame):
self.state_label.setText(t(f"scene3d.state_{self._state}"))
self.source_label.setText(t(f"scene3d.source_{self._source_kind}"))
self.source_label.setToolTip(t(f"scene3d.source_{self._source_kind}_tip"))
self.source_label.setVisible(self._show_diagnostics)
self.state_label.setVisible(
self._show_diagnostics and self._state != "live"
)
self.set_capabilities(self._capabilities)
self.set_descriptor(self._descriptor)