using System; using OpenNest.CutOffs; using OpenNest.Desktop.Rendering; using OpenNest.Geometry; using OpenNest.Undo; namespace OpenNest.Desktop.Interaction; /// The mouse button behind a pointer event. public enum ToolButton { None, Left, Middle, Right, } /// Modifier keys held during a pointer event. [Flags] public enum ToolModifiers { None = 0, Shift = 1, Control = 2, Alt = 4, } /// /// A pointer event as a plate tool sees it: where it is in plate coordinates and on screen, the /// button pressed or released (for a move, the button held), and the modifier keys. /// public readonly record struct ToolPointer(Vector World, ScreenPoint Screen, ToolButton Button, ToolModifiers Modifiers); /// What a plate tool works on: the view that hosts it, in either desktop app. public interface IPlateToolHost { /// The plate shown, or null. Plate Plate { get; } PlateSelection Selection { get; } PlateHitTester HitTester { get; } /// The view's world/screen mapping, for tolerances given in pixels. ViewTransform View { get; } /// Requests a redraw. void Invalidate(); /// /// Opens one undoable edit of the plate (see ). A /// view without a nest history records nothing. /// ChangeScope BeginChange(string label, object coalesceKey = null); /// /// The settings cut-offs are rebuilt with after an edit moves or removes parts. /// CutOffSettings CutOffSettings { get; } /// /// True while the plate must not be edited, as the WinForms view's EditsLocked: the /// nest is locked (Auto Nest is running on it; later, an inspection panel shows it). Edits /// and drag-moves are refused; panning and zooming stay live. /// bool EditsLocked { get; } } /// /// One interactive plate-view tool, toolkit-neutral: the view forwards pointer events to the /// active tool and draws what it exposes. Exactly one tool is active at a time; see /// . /// public abstract class PlateTool { protected PlateTool(IPlateToolHost host) { Host = host ?? throw new ArgumentNullException(nameof(host)); } protected IPlateToolHost Host { get; } /// The name shown in the status bar. public abstract string Name { get; } /// Status bar guidance shown after the name, or null for the name alone. public virtual string Hint => null; /// Whether the tool is mid-task, so Escape cancels that task rather than ending the tool. public abstract bool IsBusy { get; } /// Whether Escape from Select may bring this tool back after it ends. public virtual bool ResumeOnEscape => true; /// Whether the tool stays active when the view shows another plate. public virtual bool SurvivesPlateChange => false; /// Raised when changes. public event EventHandler HintChanged; /// Called when the tool becomes active (again, when Escape resumes it). public virtual void Activate() { } /// Called when the tool stops being active, after . public virtual void Deactivate() { } /// Abandons the task in progress. public abstract void Cancel(); /// Called when a tool that survives plate changes sees another plate. public virtual void OnPlateChanged() { } /// Whether the tool used the event. public virtual bool PointerPressed(ToolPointer pointer) => false; /// Whether the tool used the event. public virtual bool PointerMoved(ToolPointer pointer) => false; /// Whether the tool used the event. public virtual bool PointerReleased(ToolPointer pointer) => false; /// /// The view lost the pointer mid-gesture (Alt+Tab during a drag, say), so no release will /// follow: the tool ends the gesture in progress. /// public virtual void PointerCaptureLost() { } protected void RaiseHintChanged() => HintChanged?.Invoke(this, EventArgs.Empty); }