Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

Group selection: marquee, Ctrl and Shift in the tree and on the pictures, a drag or the arrows move the group

Alexander Graefe9f68d576fd4
diff --git a/CLAUDE.md b/CLAUDE.md
index 7985b73..2fba504 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -129,7 +129,14 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
the layer it measures (2026-10-18), sources on both; graph boxes lie over every handle and dot, the selected
item is drawn last among its kind, except the handles themselves (Panel.ZIndex breaks the Tab cycle, 2026-10-18);
arrows nudge, selection syncs with the tree, a click on
- empty space deselects. Probe graph boxes follow their probe while attached, resize by a grip, keep their text
+ empty space deselects. **Group selection** (2026-10-19): one shared `SelectedItems` list on the window beside the
+ current `SelectedItem` (the properties pane shows the current one); in the tree Ctrl+click, Insert or Ctrl+Space
+ toggles a row, Shift+click or Shift+arrows selects the range from the anchor, Ctrl+A everything, the row's context
+ menu has both; on the pictures a drag on empty space is a marquee (Shift adds, Ctrl toggles), Ctrl+click on a handle
+ toggles, Shift+click adds; a drag of the handle of one of several selected items, or the arrows on it, moves them all
+ through `IMovable` with the delta limited so none leaves the canvas (the formation holds); Escape during a drag puts
+ things back; Remove, Duplicate and Enabled act on the whole selection when their target is in it; the lever, grips
+ and point handles belong to the current item alone. Probe graph boxes follow their probe while attached, resize by a grip, keep their text
size; an amplitude axis is symmetric about zero.
- **Colour schemes** are stop lists in `.wdscheme` XML, shipped ones embedded, user ones in
`%LOCALAPPDATA%\WaveDudeNext\ColorSchemes`, project ones in the `.wdproj`; an in-house picker edits stops;
@@ -174,10 +181,10 @@ numbers: no GPU JPEG, no OpenCL colouring at presentation, no `Vector256`, no Di
## Harnesses
-`library_check` (100+ checks: engines, store, renderer, schemes, probes, scratch, reduced preview, importer, export, parts).
+`library_check` (100+ checks: engines, store, renderer, schemes, probes, scratch, reduced preview, importer, export, parts, group move).
UI, all on `Common.ps1`, with their check counts: `PreviewCheck` 43, `RunCheck` 71, `LanguageCheck` 11,
`ProbeGraphCheck` 39, `ImportCheck` 10, `ExportCheck` 38, `PreviewQualityCheck` 35, `SceneImageCheck` 8,
-`ColorPickerCheck` 13, `KeyboardCheck` 13, `AboutCheck` 18. Test projects `tiny*.wdproj` sit beside them. A harness
+`ColorPickerCheck` 13, `KeyboardCheck` 13, `AboutCheck` 18, `SelectionCheck` 10. Test projects `tiny*.wdproj` sit beside them. A harness
sets the persisted settings it expects (split orientation, preview quality). Known flake: a second app start in one
script sometimes comes up active; only the foreground guard fails then.
diff --git a/WaveDudeNext.WPF/Commands/ProjectCommands.cs b/WaveDudeNext.WPF/Commands/ProjectCommands.cs
index 373a9ea..06cec4d 100644
--- a/WaveDudeNext.WPF/Commands/ProjectCommands.cs
+++ b/WaveDudeNext.WPF/Commands/ProjectCommands.cs
@@ -50,6 +50,12 @@ public static class ProjectCommands
/// <summary>Swaps a source or probe with its successor.</summary>
public static readonly RoutedUICommand MoveDown = new("Move down", nameof(MoveDown), typeof(ProjectCommands));
+ /// <summary>Selects every source, part and probe (Ctrl+A in the tree and on the preview; the tree's context menu).</summary>
+ public static readonly RoutedUICommand SelectAll = new("Select all", nameof(SelectAll), typeof(ProjectCommands));
+
+ /// <summary>Adds the item to the selection or takes it out again (Insert or Ctrl+Space on the tree row; the tree's context menu).</summary>
+ public static readonly RoutedUICommand ToggleSelected = new("Select or deselect", nameof(ToggleSelected), typeof(ProjectCommands));
+
/// <summary>Flips a source's or part's Enabled or a probe's Active (the tree's check boxes; Space on the selected row).</summary>
public static readonly RoutedUICommand ToggleEnabled = new("Enable or disable", nameof(ToggleEnabled), typeof(ProjectCommands));
diff --git a/WaveDudeNext.WPF/Controls/MarkerThumb.cs b/WaveDudeNext.WPF/Controls/MarkerThumb.cs
index afeb5c0..1dc185a 100644
--- a/WaveDudeNext.WPF/Controls/MarkerThumb.cs
+++ b/WaveDudeNext.WPF/Controls/MarkerThumb.cs
@@ -113,11 +113,11 @@ public sealed class MarkerThumb : Thumb
/// <summary>Model coordinate of the point (or the box's height, for a corner) when the current drag started (canvas pixels).</summary>
internal int DragStartY { get; set; }
- /// <summary>Mouse movement since the drag started, in canvas pixels (fractional, so slow drags add up).</summary>
- internal double DragDeltaX { get; set; }
+ /// <summary>Where the mouse was when the drag started, in continuous canvas coordinates; a drag is measured from here against the mouse's absolute position, never from the handle, which may be held back (a clamp, a group's limit) and would feed the miss back (2026-10-19).</summary>
+ internal double PressCanvasX { get; set; }
- /// <summary>Mouse movement since the drag started, in canvas pixels.</summary>
- internal double DragDeltaY { get; set; }
+ /// <summary>The vertical part of <see cref="PressCanvasX"/>.</summary>
+ internal double PressCanvasY { get; set; }
/// <summary>For a grip or point handle: where the mouse took hold, relative to the handle's canvas position (canvas pixels), so the handle keeps that grip while it follows the mouse.</summary>
internal double GrabOffsetX { get; set; }
diff --git a/WaveDudeNext.WPF/Controls/ProbeGraphOverlay.cs b/WaveDudeNext.WPF/Controls/ProbeGraphOverlay.cs
index 28a5d74..90f883e 100644
--- a/WaveDudeNext.WPF/Controls/ProbeGraphOverlay.cs
+++ b/WaveDudeNext.WPF/Controls/ProbeGraphOverlay.cs
@@ -442,8 +442,12 @@ public sealed class ProbeGraphOverlay : Panel
{
(thumb.DragStartX, thumb.DragStartY) = (probe.BoxX, probe.BoxY);
}
- thumb.DragDeltaX = 0;
- thumb.DragDeltaY = 0;
+ // the drag is measured from the mouse's absolute position (in canvas units; only the difference matters): the
+ // thumb's own deltas come from where the box is, and a box held at the canvas edge or snapped to a size would
+ // add the miss again on every move (2026-10-19, the same loop the scene overlay's handles had)
+ double pressScale = ScaleFor(RenderSize);
+ Point press = Mouse.GetPosition(this);
+ (thumb.PressCanvasX, thumb.PressCanvasY) = pressScale > 0 ? (press.X / pressScale, press.Y / pressScale) : (0.0, 0.0);
SelectedItem = probe;
thumb.Focus();
}
@@ -456,10 +460,9 @@ public sealed class ProbeGraphOverlay : Panel
{
return;
}
- thumb.DragDeltaX += e.HorizontalChange / scale;
- thumb.DragDeltaY += e.VerticalChange / scale;
- int x = thumb.DragStartX + (int)Math.Round(thumb.DragDeltaX);
- int y = thumb.DragStartY + (int)Math.Round(thumb.DragDeltaY);
+ Point mouse = Mouse.GetPosition(this);
+ int x = thumb.DragStartX + (int)Math.Round(mouse.X / scale - thumb.PressCanvasX);
+ int y = thumb.DragStartY + (int)Math.Round(mouse.Y / scale - thumb.PressCanvasY);
var probe = (Probe)thumb.Item;
if (thumb.Role == MarkerRole.ProbeBoxCorner)
{
diff --git a/WaveDudeNext.WPF/Controls/SceneOverlay.cs b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
index e90415b..2a5a6b4 100644
--- a/WaveDudeNext.WPF/Controls/SceneOverlay.cs
+++ b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
@@ -38,10 +38,14 @@ namespace WaveDudeNext.WPF.Controls;
/// outline in the accent colour with a size grip on a corner or vertex (drag sets the extents) and a handle on each
/// point of an outline's or fibre's list (2026-10-19, the user's request), plus the item names as labels. Dragging a handle, or moving it with the arrow keys while it has keyboard focus, writes the
/// new canvas coordinates to the model; grabbing or focusing a handle makes its item the
-/// <see cref="SelectedItem"/>. The overlay fills the same rectangle as the picture (an
-/// <see cref="Image"/> with <see cref="Stretch.Uniform"/>), so it maps canvas pixels to its own
-/// coordinates with the same uniform scale and centring. UI thread; listens to the model's change
-/// notifications.
+/// <see cref="SelectedItem"/>. Several items can be selected at once (<see cref="SelectedItems"/>, 2026-10-19, the
+/// user's request): a drag on empty picture space draws a marquee that selects the items whose handles it covers
+/// (Shift adds, Ctrl toggles), Ctrl+click on a handle toggles its item and Shift+click adds it, and a drag of the
+/// handle of one of several selected items, or the arrow keys on it, moves them all by the same delta, limited so
+/// that none leaves the canvas (<see cref="Movable.Limit"/>); Escape during a drag puts things back. The rotation
+/// lever, grips and point handles belong to the current item alone. The overlay fills the same rectangle as the
+/// picture (an <see cref="Image"/> with <see cref="Stretch.Uniform"/>), so it maps canvas pixels to its own
+/// coordinates with the same uniform scale and centring. UI thread; listens to the model's change notifications.
/// </summary>
public sealed class SceneOverlay : Panel
{
@@ -62,6 +66,10 @@ public sealed class SceneOverlay : Panel
nameof(SelectedItem), typeof(object), typeof(SceneOverlay),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (d, _) => ((SceneOverlay)d).UpdateSelection()));
+ /// <summary>Identifies the <see cref="SelectedItems"/> property.</summary>
+ public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
+ nameof(SelectedItems), typeof(ObservableCollection<object>), typeof(SceneOverlay), new PropertyMetadata(null, OnSelectedItemsChanged));
+
/// <summary>Identifies the <see cref="Layer"/> property.</summary>
public static readonly DependencyProperty LayerProperty = DependencyProperty.Register(
nameof(Layer), typeof(ProbeLayer?), typeof(SceneOverlay), new PropertyMetadata(null, (d, _) => ((SceneOverlay)d).Rebuild()));
@@ -120,10 +128,25 @@ public sealed class SceneOverlay : Panel
private readonly HashSet<INotifyCollectionChanged> _pointLists = [];
private bool _regenerating;
+ /// <summary>Where a press on empty picture space happened, in this element's coordinates; a move beyond the drag threshold opens the marquee.</summary>
+ private Point? _marqueeStart;
+ /// <summary>The marquee while it is drawn.</summary>
+ private Rect? _marquee;
+ /// <summary>The items a drag of one of their handles moves together; null for a single-item drag.</summary>
+ private List<IMovable>? _group;
+ /// <summary>How far the group has been moved in the current drag (canvas pixels), to take it back on Escape.</summary>
+ private (int Dx, int Dy) _groupApplied;
+ /// <summary>A press with Ctrl or Shift on a handle changes the selection and does not drag.</summary>
+ private bool _suppressDrag;
+ /// <summary>The angle a rotation handle's item had when its drag started, to restore on Escape.</summary>
+ private double _dragStartAngle;
+
public SceneOverlay()
{
- // no background: a click beside the handles falls through to the probe graph boxes under this layer
- // (and on to the picture), 2026-10-14
+ // a transparent background takes the press for the marquee; the press still bubbles on to the pane, which
+ // focuses itself and clears the selection unless Shift or Ctrl is held (2026-10-19; until then no background,
+ // so a click fell through to the graph boxes, which lie over this layer since 2026-10-18 anyway)
+ Background = Brushes.Transparent;
IsHitTestVisible = true;
Focusable = false;
}
@@ -149,13 +172,42 @@ public sealed class SceneOverlay : Panel
set => SetValue(CanvasHeightProperty, value);
}
- /// <summary>The source, part or probe selected in the project (highlighted); set when a handle is grabbed or focused.</summary>
+ /// <summary>The source, part or probe selected in the project (highlighted); set when a handle is grabbed or focused. The current item of <see cref="SelectedItems"/>.</summary>
public object? SelectedItem
{
get => GetValue(SelectedItemProperty);
set => SetValue(SelectedItemProperty, value);
}
+ /// <summary>The shared selection (the main window's): every item in it is highlighted and moves with a group drag; the overlay adds and removes items by marquee, Ctrl and Shift.</summary>
+ public ObservableCollection<object>? SelectedItems
+ {
+ get => (ObservableCollection<object>?)GetValue(SelectedItemsProperty);
+ set => SetValue(SelectedItemsProperty, value);
+ }
+
+ private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var overlay = (SceneOverlay)d;
+ if (e.OldValue is ObservableCollection<object> old)
+ {
+ old.CollectionChanged -= overlay.OnSelectionChanged;
+ }
+ if (e.NewValue is ObservableCollection<object> set)
+ {
+ set.CollectionChanged += overlay.OnSelectionChanged;
+ }
+ overlay.UpdateSelection();
+ }
+
+ private void OnSelectionChanged(object? sender, NotifyCollectionChangedEventArgs e) => UpdateSelection();
+
+ /// <summary>Whether <paramref name="item"/> is the current item or one of the selected ones.</summary>
+ private bool IsSelected(object item) => ReferenceEquals(item, SelectedItem) || (SelectedItems?.Contains(item) ?? false);
+
+ /// <summary>The handle roles that move an item as a whole (not a lever, grip or point): the ones a group drag starts from.</summary>
+ private static bool MovesWhole(MarkerRole role) => role is MarkerRole.Source or MarkerRole.Part or MarkerRole.ProbeA or MarkerRole.ProbeB;
+
/// <summary>
/// The picture's layer: only the probes measuring it get handles and lines here (2026-10-18, the user's rule: a probe
/// on both pictures confused, above all in a single-picture view). Sources drive both layers and show on both.
@@ -344,7 +396,16 @@ public sealed class SceneOverlay : Panel
AutomationProperties.SetAutomationId(thumb, automationId);
thumb.DragStarted += OnDragStarted;
thumb.DragDelta += OnDragDelta;
- thumb.GotKeyboardFocus += (_, _) => SelectedItem = item;
+ thumb.DragCompleted += OnDragCompleted;
+ // Tab to a handle selects its item; a press is left to the drag start, which reads Ctrl and Shift first (the
+ // thumb focuses itself before it raises the drag start)
+ thumb.GotKeyboardFocus += (_, _) =>
+ {
+ if (Mouse.LeftButton != MouseButtonState.Pressed)
+ {
+ SelectedItem = item;
+ }
+ };
UpdateOpacity(thumb);
Children.Add(thumb);
}
@@ -398,11 +459,11 @@ public sealed class SceneOverlay : Panel
object? selected = SelectedItem;
foreach (MarkerThumb thumb in Children)
{
- thumb.IsSelectedMarker = ReferenceEquals(thumb.Item, selected);
+ thumb.IsSelectedMarker = IsSelected(thumb.Item);
if (thumb.Role is MarkerRole.SourceAngle or MarkerRole.PartAngle or MarkerRole.PartGrip or MarkerRole.PartPoint)
{
- // the rotation handle, grip and point handles only while their source or part is selected (the user's rule, 2026-10-14); collapsed, they are out of the Tab cycle too
- thumb.Visibility = thumb.IsSelectedMarker ? Visibility.Visible : Visibility.Collapsed;
+ // the rotation handle, grip and point handles only while their source or part is the current item (the user's rule, 2026-10-14); collapsed, they are out of the Tab cycle too
+ thumb.Visibility = ReferenceEquals(thumb.Item, selected) ? Visibility.Visible : Visibility.Collapsed;
}
}
InvalidateVisual();
@@ -702,7 +763,7 @@ public sealed class SceneOverlay : Panel
{
continue;
}
- bool isSelected = ReferenceEquals(probe, selected);
+ bool isSelected = IsSelected(probe);
Point a = ToView(probe.AX, probe.AY);
Point b = ToView(probe.BX, probe.BY);
// a dark line under the dashed light one, so the line reads on any picture
@@ -715,10 +776,10 @@ public sealed class SceneOverlay : Panel
{
continue;
}
- bool isSelected = ReferenceEquals(source, selected);
+ bool isSelected = IsSelected(source);
Brush dots = isSelected ? AccentBrush : LineBrush;
var halo = new Pen(HaloBrush, 1.5);
- if (isSelected)
+ if (ReferenceEquals(source, selected))
{
// the row axis from the centre to the rotation handle, so the turn reads as a lever; with the handle, only while selected
Point axisEnd = AnglePoint(source, RenderSize);
@@ -730,20 +791,24 @@ public sealed class SceneOverlay : Panel
dc.DrawEllipse(dots, halo, ToView(element.X, element.Y), ElementDotRadius, ElementDotRadius);
}
}
- if (selected is OpticalPart selectedPart && project.Parts.Contains(selectedPart))
+ foreach (OpticalPart part in SelectedLast(project.Parts, selected))
{
+ if (!IsSelected(part))
+ {
+ continue;
+ }
// the part's outline as painted, in the accent colour, so the shape reads apart from the scene's glow
- (double X, double Y)[] outline = selectedPart.Outline();
+ (double X, double Y)[] outline = part.Outline();
if (outline.Length >= 2)
{
var geometry = new StreamGeometry();
using (StreamGeometryContext context = geometry.Open())
{
- (double x0, double y0) = selectedPart.ToCanvas(outline[0].X, outline[0].Y);
- context.BeginFigure(ToViewExact(x0, y0, RenderSize), false, selectedPart.OutlineClosed);
+ (double x0, double y0) = part.ToCanvas(outline[0].X, outline[0].Y);
+ context.BeginFigure(ToViewExact(x0, y0, RenderSize), false, part.OutlineClosed);
for (int i = 1; i < outline.Length; i++)
{
- (double x, double y) = selectedPart.ToCanvas(outline[i].X, outline[i].Y);
+ (double x, double y) = part.ToCanvas(outline[i].X, outline[i].Y);
context.LineTo(ToViewExact(x, y, RenderSize), true, true);
}
}
@@ -751,10 +816,21 @@ public sealed class SceneOverlay : Panel
dc.DrawGeometry(null, new Pen(HaloBrush, 3.0) { LineJoin = PenLineJoin.Round }, geometry);
dc.DrawGeometry(null, new Pen(AccentBrush, 1.0) { LineJoin = PenLineJoin.Round }, geometry);
}
- // the part's axis from the centre to its rotation handle, the lever, while it is selected
- Point axisEnd = AnglePoint(selectedPart, RenderSize);
- dc.DrawLine(new Pen(HaloBrush, 3.0), ToView(selectedPart.X, selectedPart.Y), axisEnd);
- dc.DrawLine(new Pen(AccentBrush, 1.0) { DashStyle = DashStyles.Dot }, ToView(selectedPart.X, selectedPart.Y), axisEnd);
+ if (ReferenceEquals(part, selected))
+ {
+ // the part's axis from the centre to its rotation handle, the lever, while it is the current item
+ Point axisEnd = AnglePoint(part, RenderSize);
+ dc.DrawLine(new Pen(HaloBrush, 3.0), ToView(part.X, part.Y), axisEnd);
+ dc.DrawLine(new Pen(AccentBrush, 1.0) { DashStyle = DashStyles.Dot }, ToView(part.X, part.Y), axisEnd);
+ }
+ }
+ if (_marquee is { } marquee)
+ {
+ // the marquee: a faint accent fill under a dashed accent edge
+ Brush fill = AccentBrush.Clone();
+ fill.Opacity = 0.15;
+ fill.Freeze();
+ dc.DrawRectangle(fill, new Pen(AccentBrush, 1.0) { DashStyle = DashStyles.Dash }, marquee);
}
dc.Pop();
foreach (MarkerThumb thumb in Children.OfType<MarkerThumb>().OrderBy(thumb => thumb.IsSelectedMarker))
@@ -778,29 +854,210 @@ public sealed class SceneOverlay : Panel
}
}
+ // ---------------------------------------------------------------- the marquee
+
+ /// <inheritdoc/>
+ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
+ {
+ base.OnMouseLeftButtonDown(e);
+ // a press on empty space (the handles are thumbs and handle their own press): maybe the start of a marquee;
+ // not handled, so the pane focuses itself and clears the selection as before
+ _marqueeStart = e.Handled ? null : e.GetPosition(this);
+ }
+
+ /// <inheritdoc/>
+ protected override void OnMouseMove(MouseEventArgs e)
+ {
+ base.OnMouseMove(e);
+ if (_marqueeStart is not { } start || e.LeftButton != MouseButtonState.Pressed)
+ {
+ return;
+ }
+ Point at = e.GetPosition(this);
+ if (_marquee == null)
+ {
+ if (Math.Abs(at.X - start.X) < SystemParameters.MinimumHorizontalDragDistance && Math.Abs(at.Y - start.Y) < SystemParameters.MinimumVerticalDragDistance)
+ {
+ return;
+ }
+ CaptureMouse();
+ }
+ _marquee = new Rect(start, at);
+ InvalidateVisual();
+ }
+
+ /// <inheritdoc/>
+ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
+ {
+ base.OnMouseLeftButtonUp(e);
+ if (_marquee is { } marquee)
+ {
+ EndMarquee();
+ ApplyMarquee(marquee);
+ e.Handled = true;
+ }
+ _marqueeStart = null;
+ }
+
+ /// <inheritdoc/>
+ protected override void OnLostMouseCapture(MouseEventArgs e)
+ {
+ base.OnLostMouseCapture(e);
+ if (_marquee != null)
+ {
+ EndMarquee();
+ }
+ _marqueeStart = null;
+ }
+
+ private void EndMarquee()
+ {
+ _marquee = null;
+ if (IsMouseCaptured)
+ {
+ ReleaseMouseCapture();
+ }
+ InvalidateVisual();
+ }
+
+ /// <summary>
+ /// Selects the items whose whole-item handles lie in <paramref name="marquee"/>: with Ctrl each is toggled, with
+ /// Shift they are added, else they become the selection (the pane cleared it on the press); the last one becomes
+ /// the current item.
+ /// </summary>
+ private void ApplyMarquee(Rect marquee)
+ {
+ if (SelectedItems is not { } set)
+ {
+ return;
+ }
+ var covered = new List<object>();
+ foreach (MarkerThumb thumb in Children)
+ {
+ if (!MovesWhole(thumb.Role) || covered.Contains(thumb.Item))
+ {
+ continue;
+ }
+ (int x, int y) = PointOf(thumb);
+ if (marquee.Contains(ToView(x, y)))
+ {
+ covered.Add(thumb.Item);
+ }
+ }
+ ModifierKeys modifiers = Keyboard.Modifiers;
+ if ((modifiers & ModifierKeys.Control) != 0)
+ {
+ foreach (object item in covered)
+ {
+ if (!set.Remove(item))
+ {
+ set.Add(item);
+ }
+ }
+ }
+ else
+ {
+ if ((modifiers & ModifierKeys.Shift) == 0)
+ {
+ set.Clear();
+ }
+ foreach (object item in covered)
+ {
+ if (!set.Contains(item))
+ {
+ set.Add(item);
+ }
+ }
+ }
+ SelectedItem = set.LastOrDefault();
+ }
+
// ---------------------------------------------------------------- dragging and keys
+ /// <summary>
+ /// A press on a handle: with Ctrl the item is toggled in the selection, with Shift added, and no drag follows; a
+ /// press on one of several selected items prepares a drag of them all; any other press makes the item the selection.
+ /// </summary>
private void OnDragStarted(object sender, DragStartedEventArgs e)
{
var thumb = (MarkerThumb)sender;
(thumb.DragStartX, thumb.DragStartY) = PointOf(thumb);
- thumb.DragDeltaX = 0;
- thumb.DragDeltaY = 0;
+ (thumb.PressCanvasX, thumb.PressCanvasY) = ToCanvasExact(Mouse.GetPosition(this));
+ _group = null;
+ _groupApplied = (0, 0);
+ _suppressDrag = false;
+ _dragStartAngle = AngleOf(thumb.Item);
if (thumb.Role is MarkerRole.PartGrip or MarkerRole.PartPoint && CanvasOf(thumb) is { } handle)
{
(double mouseX, double mouseY) = ToCanvasExact(Mouse.GetPosition(this));
thumb.GrabOffsetX = mouseX - handle.X;
thumb.GrabOffsetY = mouseY - handle.Y;
}
+ if (MovesWhole(thumb.Role) && SelectedItems is { } set)
+ {
+ ModifierKeys modifiers = Keyboard.Modifiers;
+ if ((modifiers & ModifierKeys.Control) != 0)
+ {
+ _suppressDrag = true;
+ if (set.Remove(thumb.Item))
+ {
+ SelectedItem = set.LastOrDefault();
+ return;
+ }
+ set.Add(thumb.Item);
+ }
+ else if ((modifiers & ModifierKeys.Shift) != 0)
+ {
+ _suppressDrag = true;
+ if (!set.Contains(thumb.Item))
+ {
+ set.Add(thumb.Item);
+ }
+ }
+ else if (set.Count > 1 && set.Contains(thumb.Item))
+ {
+ _group = [.. set.OfType<IMovable>()];
+ }
+ }
SelectedItem = thumb.Item;
thumb.Focus();
}
+ /// <summary>A drag that ends where it began on one of a group makes that item the selection (as a click would); a cancelled drag (Escape) puts the item or group back.</summary>
+ private void OnDragCompleted(object sender, DragCompletedEventArgs e)
+ {
+ var thumb = (MarkerThumb)sender;
+ if (e.Canceled)
+ {
+ if (_group != null)
+ {
+ Movable.MoveAll(_group, -_groupApplied.Dx, -_groupApplied.Dy);
+ }
+ else if (thumb.Role is MarkerRole.SourceAngle or MarkerRole.PartAngle)
+ {
+ SetAngle(thumb.Item, _dragStartAngle);
+ }
+ else if (!_suppressDrag)
+ {
+ SetPoint(thumb, thumb.DragStartX, thumb.DragStartY);
+ }
+ }
+ else if (_group != null && _groupApplied == (0, 0) && SelectedItems is { } set && Keyboard.Modifiers == ModifierKeys.None)
+ {
+ set.Clear();
+ set.Add(thumb.Item);
+ SelectedItem = thumb.Item;
+ }
+ _group = null;
+ _groupApplied = (0, 0);
+ _suppressDrag = false;
+ }
+
private void OnDragDelta(object sender, DragDeltaEventArgs e)
{
var thumb = (MarkerThumb)sender;
double scale = Scale;
- if (scale <= 0)
+ if (scale <= 0 || _suppressDrag)
{
return;
}
@@ -819,9 +1076,24 @@ public sealed class SceneOverlay : Panel
SetPoint(thumb, (int)Math.Round(mouseX - thumb.GrabOffsetX), (int)Math.Round(mouseY - thumb.GrabOffsetY));
return;
}
- thumb.DragDeltaX += e.HorizontalChange / scale;
- thumb.DragDeltaY += e.VerticalChange / scale;
- SetPoint(thumb, thumb.DragStartX + (int)Math.Round(thumb.DragDeltaX), thumb.DragStartY + (int)Math.Round(thumb.DragDeltaY));
+ // the move so far, from the mouse's absolute position: the thumb's own deltas are measured from where the handle
+ // is, and a handle held back by the canvas edge or a group's limit would add the miss again on every move
+ // (2026-10-19: a group with a tall probe, once stopped at the top, could then only jump between the extremes)
+ (double nowX, double nowY) = ToCanvasExact(Mouse.GetPosition(this));
+ int movedX = (int)Math.Round(nowX - thumb.PressCanvasX);
+ int movedY = (int)Math.Round(nowY - thumb.PressCanvasY);
+ if (_group != null)
+ {
+ // the group follows the mouse as far as the canvas lets its outermost member go; the limit is taken step by
+ // step on the anchors as they are, which is the same limit since the formation never changes
+ int wantedX = movedX - _groupApplied.Dx;
+ int wantedY = movedY - _groupApplied.Dy;
+ (int dx, int dy) = Movable.Limit(_group, wantedX, wantedY, CanvasWidth, CanvasHeight);
+ Movable.MoveAll(_group, dx, dy);
+ _groupApplied = (_groupApplied.Dx + dx, _groupApplied.Dy + dy);
+ return;
+ }
+ SetPoint(thumb, thumb.DragStartX + movedX, thumb.DragStartY + movedY);
}
private static Brush Freeze(Brush brush)
@@ -830,7 +1102,7 @@ public sealed class SceneOverlay : Panel
return brush;
}
- /// <summary>The arrow keys move the focused handle by one canvas pixel, ten with Shift; on a rotation handle they turn the array or part by a degree (Right and Up counter-clockwise), ten with Shift.</summary>
+ /// <summary>The arrow keys move the focused handle by one canvas pixel, ten with Shift (every selected item when the handle's item is one of several); on a rotation handle they turn the array or part by a degree (Right and Up counter-clockwise), ten with Shift. Escape cancels a drag in progress.</summary>
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
@@ -838,6 +1110,12 @@ public sealed class SceneOverlay : Panel
{
return;
}
+ if (e.Key == Key.Escape && thumb.IsDragging)
+ {
+ thumb.CancelDrag(); // raises the completed event as cancelled, which puts things back
+ e.Handled = true;
+ return;
+ }
int step = (Keyboard.Modifiers & ModifierKeys.Shift) != 0 ? KeyStepFast : KeyStep;
if (thumb.Role is MarkerRole.SourceAngle or MarkerRole.PartAngle)
{
@@ -861,6 +1139,14 @@ public sealed class SceneOverlay : Panel
{
return;
}
+ if (MovesWhole(thumb.Role) && SelectedItems is { Count: > 1 } set && set.Contains(thumb.Item))
+ {
+ List<IMovable> group = [.. set.OfType<IMovable>()];
+ (dx, dy) = Movable.Limit(group, dx, dy, CanvasWidth, CanvasHeight);
+ Movable.MoveAll(group, dx, dy);
+ e.Handled = true;
+ return;
+ }
(int x, int y) = PointOf(thumb);
SetPoint(thumb, x + dx, y + dy);
e.Handled = true;
diff --git a/WaveDudeNext.WPF/MainWindow.Live.cs b/WaveDudeNext.WPF/MainWindow.Live.cs
index 67817ef..25265ad 100644
--- a/WaveDudeNext.WPF/MainWindow.Live.cs
+++ b/WaveDudeNext.WPF/MainWindow.Live.cs
@@ -137,6 +137,7 @@ public partial class MainWindow
/// <summary>A new project: watch it instead of the old one; nothing is stale and no scratch frame applies.</summary>
private void OnProjectReplaced(Project? project)
{
+ SelectedItems.Clear();
_watcher?.Dispose();
_watcher = null;
_imageCache = null;
diff --git a/WaveDudeNext.WPF/MainWindow.Project.cs b/WaveDudeNext.WPF/MainWindow.Project.cs
index f4f2b38..a8728ee 100644
--- a/WaveDudeNext.WPF/MainWindow.Project.cs
+++ b/WaveDudeNext.WPF/MainWindow.Project.cs
@@ -37,6 +37,63 @@ public partial class MainWindow
{
private object? Target(object? parameter) => parameter ?? SelectedItem;
+ /// <summary>
+ /// What a command acts on: the whole selection when its target is one of several selected items (Explorer's rule,
+ /// 2026-10-19), else the target alone. A snapshot, since acting changes the selection.
+ /// </summary>
+ private object[] Group(object? parameter)
+ {
+ object? target = Target(parameter);
+ if (target == null)
+ {
+ return [];
+ }
+ return SelectedItems.Count > 1 && SelectedItems.Contains(target) ? [.. SelectedItems] : [target];
+ }
+
+ /// <summary>Every source, part and probe in tree order; the range selections and Select all draw on it.</summary>
+ private IEnumerable<object> Selectable() => Project.Sources.Cast<object>().Concat(Project.Parts).Concat(Project.Probes);
+
+ private void CanSelectAll(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = Selectable().Any();
+
+ /// <summary>Ctrl+A: every source, part and probe; the last one becomes the current item.</summary>
+ private void OnSelectAll(object sender, ExecutedRoutedEventArgs e)
+ {
+ object[] all = [.. Selectable()];
+ SelectedItems.Clear();
+ foreach (object item in all)
+ {
+ SelectedItems.Add(item);
+ }
+ SelectedItem = all.Length > 0 ? all[^1] : null;
+ }
+
+ private void CanToggleSelected(object sender, CanExecuteRoutedEventArgs e) =>
+ e.CanExecute = Target(e.Parameter) is Source or OpticalPart or Probe;
+
+ /// <summary>Insert or Ctrl+Space on a tree row: into the selection, or out of it (the current item then moves to the last one left).</summary>
+ private void OnToggleSelected(object sender, ExecutedRoutedEventArgs e)
+ {
+ object? item = Target(e.Parameter);
+ if (item is not (Source or OpticalPart or Probe))
+ {
+ return;
+ }
+ if (SelectedItems.Contains(item))
+ {
+ SelectedItems.Remove(item);
+ if (ReferenceEquals(SelectedItem, item))
+ {
+ SelectedItem = SelectedItems.LastOrDefault();
+ }
+ }
+ else
+ {
+ SelectedItems.Add(item);
+ SelectedItem = item;
+ }
+ }
+
/// <summary>The project list a tree node stands for: a folder's list, or the list containing an item.</summary>
private IList? ListOf(object? node) => node switch
{
@@ -113,70 +170,89 @@ public partial class MainWindow
private void CanToggleEnabled(object sender, CanExecuteRoutedEventArgs e) =>
e.CanExecute = Target(e.Parameter) is Source or OpticalPart or Probe;
- /// <summary>The tree's check boxes by keyboard: Space on a selected source, part or probe flips it (the author's point 11, 2026-10-13).</summary>
+ /// <summary>The tree's check boxes by keyboard: Space on a selected source, part or probe flips it (the author's point 11, 2026-10-13); each of a selected group flips on its own.</summary>
private void OnToggleEnabled(object sender, ExecutedRoutedEventArgs e)
{
- switch (Target(e.Parameter))
+ foreach (object item in Group(e.Parameter))
{
- case Source source:
- source.Enabled = !source.Enabled;
- break;
- case OpticalPart part:
- part.Enabled = !part.Enabled;
- break;
- case Probe probe:
- probe.Active = !probe.Active;
- break;
+ switch (item)
+ {
+ case Source source:
+ source.Enabled = !source.Enabled;
+ break;
+ case OpticalPart part:
+ part.Enabled = !part.Enabled;
+ break;
+ case Probe probe:
+ probe.Active = !probe.Active;
+ break;
+ }
}
}
+ /// <summary>A copy after each original; the copies become the selection, the last one the current item with the caret in its name.</summary>
private void OnDuplicate(object sender, ExecutedRoutedEventArgs e)
{
- switch (Target(e.Parameter))
+ var copies = new List<object>();
+ foreach (object item in Group(e.Parameter))
{
- case Source source:
- Added(Project.Duplicate(source));
- break;
- case OpticalPart part:
- Added(Project.Duplicate(part));
- break;
- case Probe probe:
- Added(Project.Duplicate(probe));
- break;
- case ColorScheme scheme:
- Added(Project.Duplicate(scheme));
- break;
+ object? copy = item switch
+ {
+ Source source => Project.Duplicate(source),
+ OpticalPart part => Project.Duplicate(part),
+ Probe probe => Project.Duplicate(probe),
+ ColorScheme scheme => Project.Duplicate(scheme),
+ _ => null,
+ };
+ if (copy != null)
+ {
+ copies.Add(copy);
+ }
}
+ if (copies.Count == 0)
+ {
+ return;
+ }
+ SelectedItems.Clear();
+ foreach (object copy in copies)
+ {
+ SelectedItems.Add(copy);
+ }
+ Added(copies[^1]);
}
+ /// <summary>Removes the target, or the whole selection it belongs to; the user is kept in place at the slot of the last one removed.</summary>
private void OnRemove(object sender, ExecutedRoutedEventArgs e)
{
- object? item = Target(e.Parameter);
- IList? list = ListOf(item);
- if (list == null)
+ object[] group = Group(e.Parameter);
+ if (group.Length == 0 || ListOf(group[^1]) is not { } list)
{
return;
}
- int index = list.IndexOf(item);
- switch (item)
+ int index = list.IndexOf(group[^1]);
+ foreach (object item in group)
{
- case Source source:
- Project.Remove(source);
- break;
- case OpticalPart part:
- Project.Remove(part);
- break;
- case Probe probe:
- Project.Remove(probe);
- break;
- case ColorScheme scheme:
- Project.Remove(scheme);
- break;
+ SelectedItems.Remove(item);
+ switch (item)
+ {
+ case Source source:
+ Project.Remove(source);
+ break;
+ case OpticalPart part:
+ Project.Remove(part);
+ break;
+ case Probe probe:
+ Project.Remove(probe);
+ break;
+ case ColorScheme scheme:
+ Project.Remove(scheme);
+ break;
+ }
}
// keep the user in place: the item that took the slot, else the folder
if (list.Count > 0)
{
- projectTree.Select(list[Math.Min(index, list.Count - 1)]!);
+ projectTree.Select(list[Math.Clamp(index, 0, list.Count - 1)]!);
}
else
{
diff --git a/WaveDudeNext.WPF/MainWindow.xaml b/WaveDudeNext.WPF/MainWindow.xaml
index ff4a5f4..d146d20 100644
--- a/WaveDudeNext.WPF/MainWindow.xaml
+++ b/WaveDudeNext.WPF/MainWindow.xaml
@@ -184,6 +184,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<CommandBinding Command="{x:Static commands:ProjectCommands.MoveUp}" CanExecute="CanMoveUp" Executed="OnMoveUp" />
<CommandBinding Command="{x:Static commands:ProjectCommands.MoveDown}" CanExecute="CanMoveDown" Executed="OnMoveDown" />
<CommandBinding Command="{x:Static commands:ProjectCommands.ToggleEnabled}" CanExecute="CanToggleEnabled" Executed="OnToggleEnabled" />
+ <CommandBinding Command="{x:Static commands:ProjectCommands.SelectAll}" CanExecute="CanSelectAll" Executed="OnSelectAll" />
+ <CommandBinding Command="{x:Static commands:ProjectCommands.ToggleSelected}" CanExecute="CanToggleSelected" Executed="OnToggleSelected" />
<CommandBinding Command="{x:Static commands:ProjectCommands.BrowseSceneImage}" Executed="OnBrowseSceneImage" />
<CommandBinding Command="{x:Static commands:HelpCommands.About}" Executed="OnHelpAbout" />
</Window.CommandBindings>
@@ -341,7 +343,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<docking:DockHost x:Name="dockHost">
<docking:DockHost.Items>
<docking:DockItem x:Name="projectDock" Id="project" Title="{StaticResource PaneProject}" DefaultSide="Left">
- <panes:ProjectTree x:Name="projectTree" Project="{Binding Project}" SelectedItemChanged="OnTreeSelectionChanged" />
+ <panes:ProjectTree x:Name="projectTree" Project="{Binding Project}" SelectedItems="{Binding SelectedItems}" SelectedItemChanged="OnTreeSelectionChanged" />
</docking:DockItem>
<docking:DockItem x:Name="propertiesDock" Id="properties" Title="{StaticResource PaneProperties}" DefaultSide="Right">
<panes:PropertiesPane x:Name="propertiesPane" SelectedObject="{Binding SelectedItem}" Project="{Binding Project}" />
@@ -352,7 +354,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
</docking:DockHost.Items>
<docking:DockHost.DocumentContent>
<Border BorderThickness="1" BorderBrush="{DynamicResource ToolWindowBorder}">
- <panes:PreviewPane x:Name="previewPane" Project="{Binding Project}" Run="{Binding Run}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
+ <panes:PreviewPane x:Name="previewPane" Project="{Binding Project}" Run="{Binding Run}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" SelectedItems="{Binding SelectedItems}"
IsStale="{Binding IsRunStale}" IsProbesStale="{Binding IsProbesStale}" ScratchFrame="{Binding ScratchFrame}"
IsComputing="{Binding IsComputingFrame}"
Position="{Binding PreviewPosition, Mode=TwoWay}" IsPlaying="{Binding IsPreviewPlaying, Mode=OneWayToSource}"
diff --git a/WaveDudeNext.WPF/MainWindow.xaml.cs b/WaveDudeNext.WPF/MainWindow.xaml.cs
index 7d7b770..07bf5d9 100644
--- a/WaveDudeNext.WPF/MainWindow.xaml.cs
+++ b/WaveDudeNext.WPF/MainWindow.xaml.cs
@@ -15,6 +15,7 @@
// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
// <https://www.gnu.org/licenses/>.
+using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
@@ -150,13 +151,21 @@ public partial class MainWindow : Window
set => SetValue(IsDirtyProperty, value);
}
- /// <summary>The model object selected in the project tree (or on the preview's pictures), or null.</summary>
+ /// <summary>The model object selected in the project tree (or on the preview's pictures), or null: the current item, always one of <see cref="SelectedItems"/>.</summary>
public object? SelectedItem
{
get => GetValue(SelectedItemProperty);
set => SetValue(SelectedItemProperty, value);
}
+ /// <summary>
+ /// The selected sources, parts and probes (2026-10-19, the user's request): one shared list the tree, the preview's
+ /// overlays and the commands all edit and watch. <see cref="SelectedItem"/> is the current one among them, the one
+ /// the properties pane shows; setting a current item that is not in the list makes the list that item alone, and
+ /// null empties it. The tree and the overlays add and remove the rest (Ctrl and Shift, the marquee).
+ /// </summary>
+ public ObservableCollection<object> SelectedItems { get; } = [];
+
/// <summary>
/// A selection made elsewhere (a marker or graph box on the preview) is mirrored in the tree, which then
/// raises its own change with the same item. The tree node does not take the focus: the handle keeps it,
@@ -167,10 +176,17 @@ public partial class MainWindow : Window
CommandManager.InvalidateRequerySuggested();
if (item == null)
{
+ SelectedItems.Clear();
// deselected on the preview (a click on empty space): the tree lets go too
projectTree.ClearSelection();
}
- else if (!ReferenceEquals(projectTree.SelectedItem, item))
+ else if (!SelectedItems.Contains(item))
+ {
+ // a plain selection: the item alone (the tree and the overlays put an item in first when they mean to extend)
+ SelectedItems.Clear();
+ SelectedItems.Add(item);
+ }
+ if (item != null && !ReferenceEquals(projectTree.SelectedItem, item))
{
projectTree.Select(item, focus: false);
}
diff --git a/WaveDudeNext.WPF/Panes/PreviewPane.xaml b/WaveDudeNext.WPF/Panes/PreviewPane.xaml
index a682b81..83e08d9 100644
--- a/WaveDudeNext.WPF/Panes/PreviewPane.xaml
+++ b/WaveDudeNext.WPF/Panes/PreviewPane.xaml
@@ -371,6 +371,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<KeyBinding Key="X" Command="{x:Static commands:PreviewCommands.ClearRange}" />
<KeyBinding Key="L" Command="{x:Static commands:PreviewCommands.ToggleLoop}" />
<KeyBinding Key="F" Command="{x:Static commands:PreviewCommands.ToggleLive}" />
+ <KeyBinding Key="A" Modifiers="Ctrl" Command="{x:Static commands:ProjectCommands.SelectAll}" />
</UserControl.InputBindings>
<DockPanel>
@@ -538,7 +539,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
CanvasWidth="{Binding CanvasWidth, RelativeSource={RelativeSource AncestorType={x:Type local:PreviewPane}}}"
CanvasHeight="{Binding CanvasHeight, RelativeSource={RelativeSource AncestorType={x:Type local:PreviewPane}}}"
Layer="{Binding Path=(local:PreviewPane.Layer), RelativeSource={RelativeSource TemplatedParent}}"
- SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType={x:Type local:PreviewPane}}, Mode=TwoWay}" />
+ SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType={x:Type local:PreviewPane}}, Mode=TwoWay}"
+ SelectedItems="{Binding SelectedItems, RelativeSource={RelativeSource AncestorType={x:Type local:PreviewPane}}}" />
<!-- the probes' graph boxes, over the handles: no handle or emitter dot is ever drawn on a graph (the user's
rule, 2026-10-18; until then the boxes lay under the handles, to keep a handle over a box grabbable, and
a handle under a box is reached by Tab or the tree instead); which probes depends on the cell's layer
diff --git a/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs b/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs
index 378a002..b6a0bfe 100644
--- a/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs
+++ b/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs
@@ -15,6 +15,7 @@
// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
// <https://www.gnu.org/licenses/>.
+using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
@@ -192,6 +193,10 @@ public partial class PreviewPane : UserControl
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(
nameof(SelectedItem), typeof(object), typeof(PreviewPane), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
+ /// <summary>Identifies the <see cref="SelectedItems"/> property.</summary>
+ public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
+ nameof(SelectedItems), typeof(ObservableCollection<object>), typeof(PreviewPane));
+
/// <summary>Identifies the <see cref="IsStale"/> property.</summary>
public static readonly DependencyProperty IsStaleProperty = DependencyProperty.Register(
nameof(IsStale), typeof(bool), typeof(PreviewPane), new PropertyMetadata(false, (d, _) => ((PreviewPane)d).UpdateSource()));
@@ -472,6 +477,13 @@ public partial class PreviewPane : UserControl
set => SetValue(SelectedItemProperty, value);
}
+ /// <summary>The shared selection of sources, parts and probes (the main window's), handed to the overlays, which highlight, extend and drag it.</summary>
+ public ObservableCollection<object>? SelectedItems
+ {
+ get => (ObservableCollection<object>?)GetValue(SelectedItemsProperty);
+ set => SetValue(SelectedItemsProperty, value);
+ }
+
/// <summary>Whether the project was edited since the run started, so the stored frames no longer show it; the available-frames shading goes grey.</summary>
public bool IsStale
{
@@ -1093,11 +1105,12 @@ public partial class PreviewPane : UserControl
/// <summary>
/// A click on the pictures gives the pane keyboard focus so that Space toggles playback, and a left click on
/// empty space (the handles and graph boxes are thumbs, which handle their own press) deselects the current
- /// item (the user's rule, 2026-10-15).
+ /// item (the user's rule, 2026-10-15), unless Shift or Ctrl is held: then a marquee that follows adds to the
+ /// selection (2026-10-19).
/// </summary>
private void OnPicturesMouseDown(object sender, MouseButtonEventArgs e)
{
- if (e.ChangedButton == MouseButton.Left)
+ if (e.ChangedButton == MouseButton.Left && (Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) == 0)
{
SelectedItem = null;
}
diff --git a/WaveDudeNext.WPF/Panes/ProjectTree.xaml b/WaveDudeNext.WPF/Panes/ProjectTree.xaml
index c6a9233..4cdbbec 100644
--- a/WaveDudeNext.WPF/Panes/ProjectTree.xaml
+++ b/WaveDudeNext.WPF/Panes/ProjectTree.xaml
@@ -130,10 +130,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
PreviewMouseLeftButtonDown="OnPreviewMouseLeftButtonDown" PreviewMouseMove="OnPreviewMouseMove"
DragOver="OnDragOver" DragLeave="OnDragLeave" Drop="OnDrop">
- <!-- keys act on the selection; only while the tree has focus -->
+ <!-- keys act on the selection; only while the tree has focus. Insert and Ctrl+Space put the row into the selection or
+ take it out, Ctrl+A selects every item (2026-10-19); Shift with the arrows extends a range through the TreeView's own
+ selection change (the code-behind) -->
<TreeView.InputBindings>
<KeyBinding Key="Delete" Command="{x:Static commands:ProjectCommands.Remove}" />
<KeyBinding Key="Space" Command="{x:Static commands:ProjectCommands.ToggleEnabled}" />
+ <KeyBinding Key="Insert" Command="{x:Static commands:ProjectCommands.ToggleSelected}" />
+ <KeyBinding Key="Space" Modifiers="Ctrl" Command="{x:Static commands:ProjectCommands.ToggleSelected}" />
+ <KeyBinding Key="A" Modifiers="Ctrl" Command="{x:Static commands:ProjectCommands.SelectAll}" />
<KeyBinding Key="D" Modifiers="Ctrl" Command="{x:Static commands:ProjectCommands.Duplicate}" />
<KeyBinding Key="Up" Modifiers="Alt" Command="{x:Static commands:ProjectCommands.MoveUp}" />
<KeyBinding Key="Down" Modifiers="Alt" Command="{x:Static commands:ProjectCommands.MoveDown}" />
@@ -169,6 +174,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
</MenuItem>
<MenuItem Header="{DynamicResource MenuProjectAddProbe}" Command="{x:Static commands:ProjectCommands.AddProbe}" />
<Separator />
+ <MenuItem Header="{DynamicResource MenuProjectToggleSelected}" Command="{x:Static commands:ProjectCommands.ToggleSelected}" InputGestureText="Ins" AutomationProperties.AutomationId="ContextToggleSelected" />
+ <MenuItem Header="{DynamicResource MenuProjectSelectAll}" Command="{x:Static commands:ProjectCommands.SelectAll}" InputGestureText="Ctrl+A" AutomationProperties.AutomationId="ContextSelectAll" />
+ <Separator />
<MenuItem Header="{DynamicResource MenuProjectToggleEnabled}" Command="{x:Static commands:ProjectCommands.ToggleEnabled}" InputGestureText="Space" />
<MenuItem Header="{DynamicResource MenuProjectDuplicate}" Command="{x:Static commands:ProjectCommands.Duplicate}" InputGestureText="Ctrl+D" />
<MenuItem Header="{DynamicResource MenuProjectRemove}" Command="{x:Static commands:ProjectCommands.Remove}" InputGestureText="Del" />
@@ -182,6 +190,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
</ContextMenu>
</Setter.Value>
</Setter>
+ <Style.Triggers>
+ <!-- a row in the selection beside the current one: the inactive-selection colours; the TreeView's own
+ selection (the current row) is drawn by the template's trigger and wins. The status tells a harness -->
+ <Trigger Property="local:ProjectTree.IsInSelection" Value="True">
+ <Setter Property="Background" Value="{DynamicResource TreeViewItemSelectedInactive}" />
+ <Setter Property="Foreground" Value="{DynamicResource TreeViewItemSelectedInactiveForeground}" />
+ <Setter Property="AutomationProperties.ItemStatus" Value="InSelection" />
+ </Trigger>
+ </Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
diff --git a/WaveDudeNext.WPF/Panes/ProjectTree.xaml.cs b/WaveDudeNext.WPF/Panes/ProjectTree.xaml.cs
index 1b66626..8cb6ea3 100644
--- a/WaveDudeNext.WPF/Panes/ProjectTree.xaml.cs
+++ b/WaveDudeNext.WPF/Panes/ProjectTree.xaml.cs
@@ -17,6 +17,8 @@
using WaveDudeNext.Rendering;
using System.Collections;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
@@ -33,7 +35,10 @@ namespace WaveDudeNext.WPF.Panes;
/// The project tree: the <see cref="Project"/> as root with its sections, sources, optical parts and probes
/// beneath. Nodes are the model objects themselves; the templates in the XAML decide how each
/// type is shown and which properties form its children. Sources, parts and probes can be reordered
-/// by dragging a row onto a sibling (line above or below) or onto their folder (append).
+/// by dragging a row onto a sibling (line above or below) or onto their folder (append). Several sources, parts and
+/// probes can be selected at once (2026-10-19, the user's request): Ctrl+click or Insert toggles a row, Shift+click or
+/// Shift with the arrows selects the range from the anchor (the last plain selection), Ctrl+A everything; the extra
+/// rows are marked through <see cref="IsInSelectionProperty"/>, the TreeView's own selection stays the current item.
/// </summary>
public partial class ProjectTree : UserControl
{
@@ -49,9 +54,19 @@ public partial class ProjectTree : UserControl
/// <summary>Identifies the <see cref="SelectedItem"/> property.</summary>
public static readonly DependencyProperty SelectedItemProperty = SelectedItemKey.DependencyProperty;
+ /// <summary>Identifies the <see cref="SelectedItems"/> property.</summary>
+ public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
+ nameof(SelectedItems), typeof(ObservableCollection<object>), typeof(ProjectTree), new PropertyMetadata(null, OnSelectedItemsChanged));
+
+ /// <summary>Attached to a row whose item is in <see cref="SelectedItems"/>; the row style highlights it.</summary>
+ public static readonly DependencyProperty IsInSelectionProperty = DependencyProperty.RegisterAttached(
+ "IsInSelection", typeof(bool), typeof(ProjectTree), new PropertyMetadata(false));
+
private object? _dragCandidate;
private Point _dragStart;
private InsertionAdorner? _adorner;
+ private object? _anchor;
+ private bool _mirroring;
public ProjectTree()
{
@@ -75,18 +90,79 @@ public partial class ProjectTree : UserControl
/// <summary>Raised when <see cref="SelectedItem"/> changes.</summary>
public event RoutedPropertyChangedEventHandler<object>? SelectedItemChanged;
- /// <summary>Selects the node of a model object once the tree has generated it; with <paramref name="focus"/> the node also takes keyboard focus.</summary>
+ /// <summary>The shared selection (the main window's); the tree adds and removes items on Ctrl, Shift, Insert and marks their rows.</summary>
+ public ObservableCollection<object>? SelectedItems
+ {
+ get => (ObservableCollection<object>?)GetValue(SelectedItemsProperty);
+ set => SetValue(SelectedItemsProperty, value);
+ }
+
+ /// <summary>Whether a row's item is in the selection beside the current one.</summary>
+ public static bool GetIsInSelection(DependencyObject element) => (bool)element.GetValue(IsInSelectionProperty);
+
+ /// <summary>Sets <see cref="IsInSelectionProperty"/>.</summary>
+ public static void SetIsInSelection(DependencyObject element, bool value) => element.SetValue(IsInSelectionProperty, value);
+
+ private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var owner = (ProjectTree)d;
+ if (e.OldValue is ObservableCollection<object> old)
+ {
+ old.CollectionChanged -= owner.OnSelectionChanged;
+ }
+ if (e.NewValue is ObservableCollection<object> set)
+ {
+ set.CollectionChanged += owner.OnSelectionChanged;
+ }
+ owner.UpdateRowStates();
+ }
+
+ private void OnSelectionChanged(object? sender, NotifyCollectionChangedEventArgs e) => UpdateRowStates();
+
+ /// <summary>Marks the rows of the selected items; a row not generated yet is marked when the selection next changes.</summary>
+ private void UpdateRowStates()
+ {
+ ObservableCollection<object>? set = SelectedItems;
+ MarkRows(tree, row => set != null && set.Contains(row.DataContext));
+ }
+
+ private static void MarkRows(ItemsControl parent, Func<TreeViewItem, bool> inSelection)
+ {
+ foreach (object node in parent.Items)
+ {
+ if (parent.ItemContainerGenerator.ContainerFromItem(node) is TreeViewItem row)
+ {
+ SetIsInSelection(row, inSelection(row));
+ MarkRows(row, inSelection);
+ }
+ }
+ }
+
/// <summary>Deselects the selected node, if any; the tree then raises its change with null (2026-10-15, a click on empty preview space).</summary>
public void ClearSelection()
{
if (tree.SelectedItem is { } item)
{
- tree.SetSelectedItem(item, expand: false, focus: false, select: false);
+ Mirror(() => tree.SetSelectedItem(item, expand: false, focus: false, select: false));
}
}
+ /// <summary>Selects the node of a model object once the tree has generated it; with <paramref name="focus"/> the node also takes keyboard focus. A selection mirrored from elsewhere leaves the shared selection as it is.</summary>
public void Select(object item, bool focus = true) =>
- Dispatcher.InvokeAsync(() => tree.SetSelectedItem(item, expand: true, focus), DispatcherPriority.Loaded);
+ Dispatcher.InvokeAsync(() => Mirror(() => tree.SetSelectedItem(item, expand: true, focus)), DispatcherPriority.Loaded);
+
+ private void Mirror(Action action)
+ {
+ _mirroring = true;
+ try
+ {
+ action();
+ }
+ finally
+ {
+ _mirroring = false;
+ }
+ }
/// <summary>Selects the root node; call after setting <see cref="Project"/>.</summary>
public void SelectRoot()
@@ -124,12 +200,92 @@ public partial class ProjectTree : UserControl
return null;
}
+ /// <summary>
+ /// The TreeView's selection changed: by the user (a click, the arrows) the shared selection becomes that item alone,
+ /// or with Shift held the range from the anchor to it; mirrored from elsewhere it is left alone. Then the window hears.
+ /// </summary>
private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
+ if (!_mirroring && SelectedItems is { } set && e.NewValue is Source or OpticalPart or Probe)
+ {
+ if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0 && _anchor != null && !ReferenceEquals(_anchor, e.NewValue))
+ {
+ SelectRange(_anchor, e.NewValue);
+ }
+ else
+ {
+ set.Clear();
+ set.Add(e.NewValue);
+ _anchor = e.NewValue;
+ }
+ }
SelectedItem = e.NewValue;
SelectedItemChanged?.Invoke(this, e);
}
+ /// <summary>Every source, part and probe in tree order.</summary>
+ private IEnumerable<object> Selectable() =>
+ Project == null ? [] : Project.Sources.Cast<object>().Concat(Project.Parts).Concat(Project.Probes);
+
+ /// <summary>Makes the selection the items from <paramref name="from"/> to <paramref name="to"/> in tree order, either way round.</summary>
+ private void SelectRange(object from, object to)
+ {
+ if (SelectedItems is not { } set)
+ {
+ return;
+ }
+ object[] all = [.. Selectable()];
+ int a = Array.IndexOf(all, from), b = Array.IndexOf(all, to);
+ if (a < 0 || b < 0)
+ {
+ return;
+ }
+ set.Clear();
+ for (int i = Math.Min(a, b); i <= Math.Max(a, b); i++)
+ {
+ set.Add(all[i]);
+ }
+ }
+
+ /// <summary>Ctrl+click toggles the row; Shift+click selects the range from the anchor. Both make the row current without the TreeView's own plain selection.</summary>
+ private bool TryModifiedClick(object item)
+ {
+ if (SelectedItems is not { } set || item is not (Source or OpticalPart or Probe))
+ {
+ return false;
+ }
+ if ((Keyboard.Modifiers & ModifierKeys.Control) != 0)
+ {
+ if (set.Contains(item))
+ {
+ set.Remove(item);
+ object? current = set.LastOrDefault();
+ if (current != null)
+ {
+ Mirror(() => tree.SetSelectedItem(current, expand: false, focus: true));
+ }
+ else
+ {
+ ClearSelection();
+ }
+ }
+ else
+ {
+ set.Add(item);
+ _anchor = item;
+ Mirror(() => tree.SetSelectedItem(item, expand: false, focus: true));
+ }
+ return true;
+ }
+ if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
+ {
+ SelectRange(_anchor ?? tree.SelectedItem ?? item, item);
+ Mirror(() => tree.SetSelectedItem(item, expand: false, focus: true));
+ return true;
+ }
+ return false;
+ }
+
// ----- drag-and-drop reordering -----
private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
@@ -142,6 +298,11 @@ public partial class ProjectTree : UserControl
}
if (FindAncestor<TreeViewItem>(origin) is { DataContext: Source or OpticalPart or Probe or ColorScheme } row)
{
+ if (TryModifiedClick(row.DataContext))
+ {
+ e.Handled = true; // the TreeView would make the row its plain selection
+ return;
+ }
_dragCandidate = row.DataContext;
_dragStart = e.GetPosition(tree);
}
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index 97c6cb1..549b962 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -123,6 +123,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuProjectRemove">_Entfernen</s:String>
<s:String x:Key="MenuProjectMoveUp">Nach _oben</s:String>
<s:String x:Key="MenuProjectMoveDown">Nach _unten</s:String>
+ <s:String x:Key="MenuProjectSelectAll">_Alles auswählen</s:String>
+ <s:String x:Key="MenuProjectToggleSelected">Zur Auswahl hinzufügen oder en_tfernen</s:String>
<s:String x:Key="ToolAddSource">+ Quelle</s:String>
<s:String x:Key="ToolAddProbe">+ Sonde</s:String>
<s:String x:Key="ToolAddPart">+ Bauteil</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index 9304ff9..26ff185 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -125,6 +125,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuProjectRemove">_Remove</s:String>
<s:String x:Key="MenuProjectMoveUp">Move _up</s:String>
<s:String x:Key="MenuProjectMoveDown">Move _down</s:String>
+ <s:String x:Key="MenuProjectSelectAll">Select _all</s:String>
+ <s:String x:Key="MenuProjectToggleSelected">Add to or remove from selec_tion</s:String>
<s:String x:Key="ToolAddSource">+ Source</s:String>
<s:String x:Key="ToolAddProbe">+ Probe</s:String>
<s:String x:Key="ToolAddPart">+ Part</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index eb82d15..f6562be 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -123,6 +123,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuProjectRemove">_Supprimer</s:String>
<s:String x:Key="MenuProjectMoveUp">_Monter</s:String>
<s:String x:Key="MenuProjectMoveDown">D_escendre</s:String>
+ <s:String x:Key="MenuProjectSelectAll">_Tout sélectionner</s:String>
+ <s:String x:Key="MenuProjectToggleSelected">Ajouter à la sélection ou en re_tirer</s:String>
<s:String x:Key="ToolAddSource">+ Source</s:String>
<s:String x:Key="ToolAddProbe">+ Sonde</s:String>
<s:String x:Key="ToolAddPart">+ Composant</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index a066c48..2ee2b84 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -123,6 +123,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuProjectRemove">_Verwijderen</s:String>
<s:String x:Key="MenuProjectMoveUp">Om_hoog</s:String>
<s:String x:Key="MenuProjectMoveDown">Om_laag</s:String>
+ <s:String x:Key="MenuProjectSelectAll">_Alles selecteren</s:String>
+ <s:String x:Key="MenuProjectToggleSelected">Aan selectie toevoegen of eruit verwij_deren</s:String>
<s:String x:Key="ToolAddSource">+ Bron</s:String>
<s:String x:Key="ToolAddProbe">+ Sonde</s:String>
<s:String x:Key="ToolAddPart">+ Onderdeel</s:String>
diff --git a/WaveDudeNext/Model/IMovable.cs b/WaveDudeNext/Model/IMovable.cs
new file mode 100644
index 0000000..ce42b06
--- /dev/null
+++ b/WaveDudeNext/Model/IMovable.cs
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next 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. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+namespace WaveDudeNext.Model;
+
+/// <summary>
+/// An item of the project that sits on the canvas and moves as a whole: a source, an optical part (its centre, the
+/// shape follows) or a probe (both ends; its graph box follows while attached to point A). The preview moves a
+/// selection of several through this, by a drag of one of their handles or the arrow keys (2026-10-19, the user's
+/// request). UI thread, like the rest of the model.
+/// </summary>
+public interface IMovable
+{
+ /// <summary>The canvas points the item is anchored at, in canvas pixels; a group move keeps every one of them on the canvas (<see cref="Movable.Limit"/>).</summary>
+ IEnumerable<(int X, int Y)> Anchors { get; }
+
+ /// <summary>Moves the item by <paramref name="dx"/>, <paramref name="dy"/> canvas pixels, without clamping.</summary>
+ void MoveBy(int dx, int dy);
+}
+
+/// <summary>Moving several <see cref="IMovable"/>s as a group. Pure functions over the model; UI thread.</summary>
+public static class Movable
+{
+ /// <summary>
+ /// The part of a wanted move (<paramref name="dx"/>, <paramref name="dy"/>) that keeps every anchor of
+ /// <paramref name="items"/> on a canvas of <paramref name="width"/> × <paramref name="height"/> pixels, so a group
+ /// pushed against the edge stops as a whole and keeps its formation instead of piling up there (the user's choice,
+ /// 2026-10-19). An anchor already outside the canvas can only move back in. Items without anchors do not limit the move.
+ /// </summary>
+ public static (int Dx, int Dy) Limit(IEnumerable<IMovable> items, int dx, int dy, int width, int height)
+ {
+ int minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
+ foreach (IMovable item in items)
+ {
+ foreach ((int x, int y) in item.Anchors)
+ {
+ minX = Math.Min(minX, x);
+ minY = Math.Min(minY, y);
+ maxX = Math.Max(maxX, x);
+ maxY = Math.Max(maxY, y);
+ }
+ }
+ if (minX == int.MaxValue)
+ {
+ return (dx, dy);
+ }
+ int right = Math.Max(0, width - 1);
+ int bottom = Math.Max(0, height - 1);
+ dx = Math.Clamp(dx, Math.Min(0, -minX), Math.Max(0, right - maxX));
+ dy = Math.Clamp(dy, Math.Min(0, -minY), Math.Max(0, bottom - maxY));
+ return (dx, dy);
+ }
+
+ /// <summary>Moves every item by the same delta; nothing happens for a zero delta.</summary>
+ public static void MoveAll(IEnumerable<IMovable> items, int dx, int dy)
+ {
+ if (dx == 0 && dy == 0)
+ {
+ return;
+ }
+ foreach (IMovable item in items)
+ {
+ item.MoveBy(dx, dy);
+ }
+ }
+}
diff --git a/WaveDudeNext/Model/OpticalPart.cs b/WaveDudeNext/Model/OpticalPart.cs
index 77def84..73b9406 100644
--- a/WaveDudeNext/Model/OpticalPart.cs
+++ b/WaveDudeNext/Model/OpticalPart.cs
@@ -52,7 +52,7 @@ public enum PartKind
/// Refractive indices run from 1.00 to 2.55 in steps of 0.01 (red = index × 100). One subclass per kind; the kind is
/// chosen when the part is added and never changes.
/// </summary>
-public abstract class OpticalPart : ObservableObject
+public abstract class OpticalPart : ObservableObject, IMovable
{
/// <summary>Smallest refractive index a part can have.</summary>
public const double MinIndex = 1.0;
@@ -162,6 +162,18 @@ public abstract class OpticalPart : ObservableObject
return (ox * cos - oy * sin, ox * sin + oy * cos);
}
+ /// <inheritdoc/>
+ [XmlIgnore]
+ [Browsable(false)]
+ public IEnumerable<(int X, int Y)> Anchors => [(X, Y)];
+
+ /// <inheritdoc/>
+ public void MoveBy(int dx, int dy)
+ {
+ X += dx;
+ Y += dy;
+ }
+
/// <summary>Clamps every value into its valid range; the angle is brought into (-180, 180].</summary>
public virtual void Normalize()
{
diff --git a/WaveDudeNext/Model/Probe.cs b/WaveDudeNext/Model/Probe.cs
index dae3445..05f3e43 100644
--- a/WaveDudeNext/Model/Probe.cs
+++ b/WaveDudeNext/Model/Probe.cs
@@ -80,7 +80,7 @@ public enum ProbeScaleMode
/// A measurement point or line on the canvas and the graph that shows its values. Positions are
/// canvas pixels with the origin at the top left.
/// </summary>
-public sealed class Probe : ObservableObject
+public sealed class Probe : ObservableObject, IMovable
{
/// <summary>Default <see cref="Window"/> in steps.</summary>
public const int DefaultWindow = 500;
@@ -423,6 +423,24 @@ public sealed class Probe : ObservableObject
public static ProbeMeasurement[] MeasurementsFor(ProbeLayer layer) =>
layer == ProbeLayer.Field ? [ProbeMeasurement.Amplitude] : [ProbeMeasurement.Value, ProbeMeasurement.IntegratedValue];
+
+ /// <inheritdoc/>
+ [XmlIgnore]
+ [Browsable(false)]
+ public IEnumerable<(int X, int Y)> Anchors => Kind == ProbeKind.Line ? [(AX, AY), (BX, BY)] : [(AX, AY)];
+
+ /// <summary>Moves point A, and point B of a line probe, by the delta; the graph box follows while it sits on point A.</summary>
+ public void MoveBy(int dx, int dy)
+ {
+ AX += dx;
+ AY += dy;
+ if (Kind == ProbeKind.Line)
+ {
+ BX += dx;
+ BY += dy;
+ }
+ }
+
/// <summary>
/// Forces a consistent state: the field only allows <see cref="ProbeMeasurement.Amplitude"/>,
/// the intensity output never does; an empty or inverted Y range becomes -1..1; the window,
diff --git a/WaveDudeNext/Model/Source.cs b/WaveDudeNext/Model/Source.cs
index 3049671..2095228 100644
--- a/WaveDudeNext/Model/Source.cs
+++ b/WaveDudeNext/Model/Source.cs
@@ -45,7 +45,7 @@ public enum PulseShape
/// remnant of the 8-bit image channel; above 255 the grid cannot sample the wave), amplitude in percent, phase in
/// degrees with decimals, widths in cycles of the source frequency, detach time in simulation steps.
/// </summary>
-public sealed class Source : ObservableObject
+public sealed class Source : ObservableObject, IMovable
{
/// <summary>Smallest frequency level: just above 0, a wave of any length.</summary>
public const double MinLevel = 0.01;
@@ -262,6 +262,18 @@ public sealed class Source : ObservableObject
/// </summary>
public Pcg32 CreateRandom(int projectSeed) => new((ulong)(uint)projectSeed, Pcg32.StableHash(Name));
+ /// <inheritdoc/>
+ [XmlIgnore]
+ [Browsable(false)]
+ public IEnumerable<(int X, int Y)> Anchors => [(X, Y)];
+
+ /// <inheritdoc/>
+ public void MoveBy(int dx, int dy)
+ {
+ X += dx;
+ Y += dy;
+ }
+
/// <summary>Clamps every value into its valid range.</summary>
public void Normalize()
{
diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.cs
index 6463833..5b48717 100644
--- a/_tools/library_check/Program.cs
+++ b/_tools/library_check/Program.cs
@@ -256,6 +256,7 @@ internal static class Program
CheckEmitterMapping();
CheckMirror(W, H);
CheckDecimalLevels(W, H);
+ CheckMovable();
CheckFrameStore(scene);
CheckPreviewQuality(scene, W, H);
CheckRenderer();
@@ -678,6 +679,39 @@ internal static class Program
}
}
+ private static void CheckMovable()
+ {
+ Console.WriteLine("--- movable items (group move)");
+ var project = new Project();
+ project.Scene.Width = 64;
+ project.Scene.Height = 48;
+ Source source = project.AddSource();
+ source.X = 10;
+ source.Y = 10;
+ OpticalPart part = project.AddPart(PartKind.Rectangle);
+ part.X = 50;
+ part.Y = 40;
+ Probe probe = project.AddProbe();
+ probe.Kind = ProbeKind.Line;
+ probe.AX = 5;
+ probe.AY = 5;
+ probe.BX = 20;
+ probe.BY = 30;
+ probe.BoxX = probe.AX;
+ probe.BoxY = probe.AY;
+ IMovable[] items = [source, part, probe];
+ Check(source.Anchors.SequenceEqual([(10, 10)]) && part.Anchors.SequenceEqual([(50, 40)]) && probe.Anchors.SequenceEqual([(5, 5), (20, 30)]), "anchors: a source's and a part's position, both ends of a line probe");
+ Check(Movable.Limit(items, -10, -10, 64, 48) == (-5, -5), "a move up and left stops when the first anchor reaches the edge");
+ Check(Movable.Limit(items, 100, 100, 64, 48) == (13, 7), "a move down and right stops when the last anchor reaches the edge");
+ Check(Movable.Limit(items, 3, -2, 64, 48) == (3, -2), "a move that fits passes unchanged");
+ Check(Movable.Limit([], 9, 9, 64, 48) == (9, 9), "no anchors, no limit");
+ Movable.MoveAll(items, 3, 2);
+ Check(source.X == 13 && source.Y == 12 && part.X == 53 && part.Y == 42 && probe.AX == 8 && probe.AY == 7 && probe.BX == 23 && probe.BY == 32, "every item moved by the same delta");
+ Check(probe.BoxX == 8 && probe.BoxY == 7 && probe.IsBoxAttached, "the attached graph box followed point A");
+ probe.Kind = ProbeKind.Point;
+ Check(probe.Anchors.SequenceEqual([(8, 7)]), "a point probe anchors at point A alone");
+ }
+
/// <summary>Max |u| over the canvas columns <paramref name="x0"/>..<paramref name="x1"/> of a padded field.</summary>
private static float MaxAbsColumns(float[] padded, int W, int H, int x0, int x1)
{
diff --git a/_tools/ui_check/SelectionCheck.ps1 b/_tools/ui_check/SelectionCheck.ps1
new file mode 100644
index 0000000..1309e2a
--- /dev/null
+++ b/_tools/ui_check/SelectionCheck.ps1
@@ -0,0 +1,113 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Copyright (C) 2026 Alexander Graef <[email protected]>
+#
+# This file is part of WaveDude Next, a 2D wave simulator.
+#
+# Based on the work of
+# Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+# <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+# 0x23 (Diffraction Limited), author of WaveSimulator2D
+# <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+#
+# WaveDude Next 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. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+# <https://www.gnu.org/licenses/>.
+
+# Drives the group selection (2026-10-19) on tiny.wdproj by keyboard alone: a second source is added, "Select all"
+# from a tree row's context menu (the Apps key) puts both into the selection (the rows carry the item status
+# "InSelection", the last one is the current item), Insert takes the current item out again, a Tab to a source
+# handle on the preview keeps the selection, the arrow keys move both sources by the same amount, and Delete on
+# the tree with both selected removes both. Ctrl, Shift and the mouse marquee cannot be posted and stay untested.
+# Usage:
+# powershell -ExecutionPolicy Bypass -File _tools\ui_check\SelectionCheck.ps1 [-Exe <path>] [-Trace]
+param(
+ [string]$Exe = (Join-Path $PSScriptRoot "..\..\WaveDudeNext.WPF\bin\Debug\net10.0-windows\WaveDudeNext.WPF.exe"),
+ [switch]$Trace
+)
+. (Join-Path $PSScriptRoot "Common.ps1")
+$VK_APPS = 0x5D; $VK_INSERT = 0x2D; $VK_DELETE = 0x2E
+function Has([string]$id) { try { (Find $id) -ne $null } catch { $false } }
+function Status([string]$id) { return (Find $id).Current.ItemStatus }
+function PopupFocusedId() {
+ $byProcess = New-Object System.Windows.Automation.PropertyCondition($A::ProcessIdProperty, $script:p.Id)
+ $focused = New-Object System.Windows.Automation.PropertyCondition($A::HasKeyboardFocusProperty, $true)
+ foreach ($top in $A::RootElement.FindAll([System.Windows.Automation.TreeScope]::Children, $byProcess)) {
+ $e = $top.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $focused)
+ if ($e -ne $null) { return $e.Current.AutomationId }
+ }
+ return "(none)"
+}
+# Tab until a tree row holds focus: the walk from the preview's handles back to the tree passes every transport
+# control and the messages pane, more than the shared helper's 80 stops, and the tree lands on the row it focused
+# last, whichever that is
+function FocusOnTree() {
+ for ($i = 0; $i -lt 250; $i++) {
+ if ((FocusedId) -like "Tree:*") { return }
+ Key $VK_TAB 30
+ }
+ throw "could not reach the tree with Tab; focus is at $(FocusedId)"
+}
+function Step([string]$what, [int]$vk, [int]$settle) {
+ Key $vk $settle
+ if ($Trace) { " {0,-8} focus {1} foreground {2}" -f $what, (FocusedId), (Foreground) }
+}
+# opens the focused row's context menu and picks the entry with the given id; whether it was reached lands in
+# $script:menuReached (a return value would carry the trace lines along)
+function PickFromRowMenu([string]$id) {
+ Step "Apps" $VK_APPS 300
+ for ($i = 0; $i -lt 12 -and (PopupFocusedId) -ne $id; $i++) { Step "Down" $VK_DOWN 120 }
+ $script:menuReached = (PopupFocusedId) -eq $id
+ Step "Enter" $VK_RETURN 300
+}
+
+Start-App $Exe (Join-Path $PSScriptRoot "tiny.wdproj")
+try {
+ # a second source, so there is a group to select
+ FocusOn "ToolAddSource"
+ Step "Space" $VK_SPACE 400
+ $null = WaitFor { Has "Tree:Source 2" } 3000 100
+ Check "Space on + Source adds Source 2" (Has "Tree:Source 2") (FocusedId)
+ Check "a plain selection: the new Source 2 is the selection, Source 1 is not in it" ((Status "Tree:Source 2") -eq "InSelection" -and (Status "Tree:Source 1") -ne "InSelection") ("{0} / {1}" -f (Status "Tree:Source 1"), (Status "Tree:Source 2"))
+
+ # Select all from a row's context menu (Tab into the tree lands on the current row, Source 2)
+ FocusOn "Tree:Source 2"
+ PickFromRowMenu "ContextSelectAll"
+ Check "the row's context menu reaches Select all" $script:menuReached (FocusedId)
+ Check "Select all puts both sources into the selection; the last one is the current item" ((Status "Tree:Source 1") -eq "InSelection" -and (Status "Tree:Source 2") -eq "InSelection" -and (TreeItemSelected "Source 2")) ("{0} / {1}, current 2: {2}" -f (Status "Tree:Source 1"), (Status "Tree:Source 2"), (TreeItemSelected "Source 2"))
+
+ # Insert takes the current item out; the current item moves to the one left
+ Step "Insert" $VK_INSERT 300
+ Check "Insert takes the current item (Source 2) out of the selection; Source 1 is current and the only one left" ((Status "Tree:Source 2") -ne "InSelection" -and (Status "Tree:Source 1") -eq "InSelection" -and (TreeItemSelected "Source 1")) ("{0} / {1}" -f (Status "Tree:Source 1"), (Status "Tree:Source 2"))
+
+ # both again, then Tab on to the preview: the handle of a selected item keeps the group
+ PickFromRowMenu "ContextSelectAll"
+ FocusOn "Source:Source 1"
+ Check "Tab to the handle of Source 1 keeps both selected" ((Status "Tree:Source 1") -eq "InSelection" -and (Status "Tree:Source 2") -eq "InSelection" -and (Focused "Source:Source 1")) ("{0} / {1}, focus {2}" -f (Status "Tree:Source 1"), (Status "Tree:Source 2"), (FocusedId))
+ $before1 = CentreOf "Source:Source 1"
+ $before2 = CentreOf "Source:Source 2"
+ for ($i = 0; $i -lt 3; $i++) { Step "Right" $VK_RIGHT 150 }
+ Start-Sleep -Milliseconds 300
+ $after1 = CentreOf "Source:Source 1"
+ $after2 = CentreOf "Source:Source 2"
+ $dx1 = $after1[0] - $before1[0]; $dx2 = $after2[0] - $before2[0]
+ Check "Right three times moves both source handles right by the same amount (3 canvas pixels)" ($dx1 -gt 4 -and [math]::Abs($dx1 - $dx2) -lt 2 -and [math]::Abs($after1[1] - $before1[1]) -lt 1) ("dx {0:0.0} / {1:0.0}" -f $dx1, $dx2)
+ for ($i = 0; $i -lt 3; $i++) { Step "Left" $VK_LEFT 150 }
+ Start-Sleep -Milliseconds 300
+ $back1 = CentreOf "Source:Source 1"
+ $back2 = CentreOf "Source:Source 2"
+ Check "Left three times brings both back" ([math]::Abs($back1[0] - $before1[0]) -lt 1 -and [math]::Abs($back2[0] - $before2[0]) -lt 1) ("{0:0.0} vs {1:0.0}, {2:0.0} vs {3:0.0}" -f $back1[0], $before1[0], $back2[0], $before2[0])
+
+ # Delete on the tree with both selected removes both: back into the tree (its row takes a plain selection), Select all, Delete
+ FocusOnTree
+ PickFromRowMenu "ContextSelectAll"
+ Step "Delete" $VK_DELETE 400
+ Check "Delete with both selected removes both sources" (-not (Has "Tree:Source 1") -and -not (Has "Tree:Source 2")) ("1: {0}, 2: {1}" -f (Has "Tree:Source 1"), (Has "Tree:Source 2"))
+ Check "the app never took the foreground" ((Foreground) -ne "APP") (Foreground)
+}
+finally {
+ Stop-App
+}
+Write-Output ("{0} failure(s)" -f $script:failures)
+exit $script:failures