viewport: select a section plane, highlight it, delete the selected one

Previously Del always removed the most recently added section plane. Now a
plane can be picked and deleted individually:

- ViewportCore tracks a selected plane index, kept valid as planes are
  added (the new one becomes selected), removed, or cleared.
- Clicking a gizmo with the section tool active selects that plane.
- The section gizmo geometry is baked white and coloured via its per-plane
  tint, so the selected plane draws in a bright amber highlight while the
  rest stay red (unchanged look).
- Del/Backspace removes the selected plane, falling back to the most recent
  one when nothing is selected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-07-09 12:48:38 +10:00
parent 12002ace86
commit 6e86072d5a
5 changed files with 58 additions and 18 deletions
+10 -4
View File
@@ -1554,6 +1554,7 @@ void ViewportWindow::mousePressEvent(QMouseEvent* event) {
const Eigen::Vector2i lp = toV2i(event->position().toPoint());
const int hit = core_.hitTestSectionGizmo(lp.x(), lp.y());
if (hit >= 0 && core_.beginSectionDrag(hit, lp.x(), lp.y())) {
core_.setSelectedSectionPlane(hit); // clicking a gizmo selects it
nav_drag_kind_ = NavDrag::Inactive;
Log::info().noquote().nospace()
<< "[wgpu section] drag start: plane=" << hit;
@@ -1918,9 +1919,10 @@ void ViewportWindow::keyPressEvent(QKeyEvent* event) {
// Section tool. K toggles the tool; Shift+K clears all planes. When
// the tool is active, click adds a plane at the surface (handled in
// mouseReleaseEvent), Esc deactivates, Del/Backspace removes the
// most recently added plane. Mirrors GL ViewportWindow + Bonsai's
// bind_shortcut(K / Shift+K) bindings.
// mouseReleaseEvent) or selects the gizmo under the cursor, Esc
// deactivates, Del/Backspace removes the selected plane (or the most
// recent one when nothing is selected). Mirrors GL ViewportWindow +
// Bonsai's bind_shortcut(K / Shift+K) bindings.
if (key == Qt::Key_K && !event->isAutoRepeat()) {
if (mods == Qt::ShiftModifier) {
clearSectionPlanes();
@@ -1936,7 +1938,11 @@ void ViewportWindow::keyPressEvent(QKeyEvent* event) {
}
if ((key == Qt::Key_Delete || key == Qt::Key_Backspace)
&& !section_planes_.empty()) {
removeSectionPlane(int(section_planes_.size()) - 1);
// Delete the selected plane; fall back to the most recent one when
// nothing is selected.
const int selected = core_.selectedSectionPlane();
removeSectionPlane(selected >= 0 ? selected
: int(section_planes_.size()) - 1);
return;
}
}