feat: create LeadInToolWindow floating form

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-02 13:38:13 -04:00
parent ebab795f86
commit 93391c4b8f
3 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
using OpenNest.CNC.CuttingStrategy;
using OpenNest.Controls;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace OpenNest.Forms
{
public class LeadInToolWindow : Form
{
private readonly CuttingPanel cuttingPanel;
public CuttingPanel CuttingPanel => cuttingPanel;
public event EventHandler ParametersChanged
{
add => cuttingPanel.ParametersChanged += value;
remove => cuttingPanel.ParametersChanged -= value;
}
public event EventHandler AutoAssignClicked
{
add => cuttingPanel.AutoAssignClicked += value;
remove => cuttingPanel.AutoAssignClicked -= value;
}
public LeadInToolWindow()
{
Text = "Lead-In Properties";
FormBorderStyle = FormBorderStyle.SizableToolWindow;
ShowInTaskbar = false;
StartPosition = FormStartPosition.Manual;
MinimumSize = new Size(300, 400);
Size = new Size(400, 580);
cuttingPanel = new CuttingPanel
{
Dock = DockStyle.Fill,
ShowAutoAssign = true
};
Controls.Add(cuttingPanel);
RestorePosition();
}
public CuttingParameters BuildParameters() => cuttingPanel.BuildParameters();
public void LoadFromParameters(CuttingParameters p) => cuttingPanel.LoadFromParameters(p);
public ContourType? ActiveContourType
{
get => cuttingPanel.ActiveContourType;
set => cuttingPanel.ActiveContourType = value;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
Hide();
}
SavePosition();
base.OnFormClosing(e);
}
protected override void OnMove(EventArgs e)
{
base.OnMove(e);
if (WindowState == FormWindowState.Normal)
SavePosition();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (WindowState == FormWindowState.Normal)
SavePosition();
}
private void SavePosition()
{
if (WindowState != FormWindowState.Normal)
return;
Properties.Settings.Default.LeadInToolWindowLocation = Location;
Properties.Settings.Default.LeadInToolWindowSize = Size;
Properties.Settings.Default.Save();
}
private void RestorePosition()
{
var savedLocation = Properties.Settings.Default.LeadInToolWindowLocation;
var savedSize = Properties.Settings.Default.LeadInToolWindowSize;
if (savedSize.Width > 0 && savedSize.Height > 0)
Size = savedSize;
if (savedLocation.X != 0 || savedLocation.Y != 0)
{
var screen = Screen.FromPoint(savedLocation);
if (screen.WorkingArea.Contains(savedLocation))
Location = savedLocation;
else
CenterToParent();
}
}
}
}

View File

@@ -238,5 +238,29 @@ namespace OpenNest.Properties {
this["CuttingParametersJson"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0, 0")]
public global::System.Drawing.Point LeadInToolWindowLocation {
get {
return ((global::System.Drawing.Point)(this["LeadInToolWindowLocation"]));
}
set {
this["LeadInToolWindowLocation"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0, 0")]
public global::System.Drawing.Size LeadInToolWindowSize {
get {
return ((global::System.Drawing.Size)(this["LeadInToolWindowSize"]));
}
set {
this["LeadInToolWindowSize"] = value;
}
}
}
}

View File

@@ -56,5 +56,11 @@
<Setting Name="CuttingParametersJson" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="LeadInToolWindowLocation" Type="System.Drawing.Point" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting>
<Setting Name="LeadInToolWindowSize" Type="System.Drawing.Size" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting>
</Settings>
</SettingsFile>