feat(ui): populate material combobox from post processors
Replaces the material textbox on EditNestInfoForm with a combobox whose items are aggregated from every loaded post processor that implements the new IMaterialProvidingPostProcessor interface. CincinnatiPostProcessor exposes its configured MaterialLibraries entries. Free-text entry still works so custom materials remain usable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenNest
|
||||
{
|
||||
public interface IMaterialProvidingPostProcessor
|
||||
{
|
||||
IEnumerable<string> GetMaterialNames();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using OpenNest.CNC;
|
||||
|
||||
namespace OpenNest.Posts.Cincinnati
|
||||
{
|
||||
public sealed class CincinnatiPostProcessor : IConfigurablePostProcessor
|
||||
public sealed class CincinnatiPostProcessor : IConfigurablePostProcessor, IMaterialProvidingPostProcessor
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
@@ -25,6 +25,16 @@ namespace OpenNest.Posts.Cincinnati
|
||||
|
||||
object IConfigurablePostProcessor.Config => Config;
|
||||
|
||||
public IEnumerable<string> GetMaterialNames()
|
||||
{
|
||||
if (Config?.MaterialLibraries == null)
|
||||
return System.Array.Empty<string>();
|
||||
|
||||
return Config.MaterialLibraries
|
||||
.Select(e => e.Material)
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s));
|
||||
}
|
||||
|
||||
public CincinnatiPostProcessor()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
|
||||
+4
-3
@@ -63,7 +63,7 @@
|
||||
this.textBox2 = new System.Windows.Forms.TextBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.labelMaterial = new System.Windows.Forms.Label();
|
||||
this.materialBox = new System.Windows.Forms.TextBox();
|
||||
this.materialBox = new System.Windows.Forms.ComboBox();
|
||||
this.tabPage2 = new System.Windows.Forms.TabPage();
|
||||
this.tabPage3 = new System.Windows.Forms.TabPage();
|
||||
this.notesBox = new System.Windows.Forms.TextBox();
|
||||
@@ -516,9 +516,10 @@
|
||||
// materialBox
|
||||
//
|
||||
this.materialBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.materialBox.FormattingEnabled = true;
|
||||
this.materialBox.Location = new System.Drawing.Point(135, 159);
|
||||
this.materialBox.Name = "materialBox";
|
||||
this.materialBox.Size = new System.Drawing.Size(224, 22);
|
||||
this.materialBox.Size = new System.Drawing.Size(224, 24);
|
||||
this.materialBox.TabIndex = 11;
|
||||
//
|
||||
// label3
|
||||
@@ -729,6 +730,6 @@
|
||||
private System.Windows.Forms.RadioButton radioButton2;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label labelMaterial;
|
||||
private System.Windows.Forms.TextBox materialBox;
|
||||
private System.Windows.Forms.ComboBox materialBox;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ namespace OpenNest.Forms
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
foreach (var name in PostProcessorMaterials.Names)
|
||||
materialBox.Items.Add(name);
|
||||
|
||||
timer = new Timer
|
||||
{
|
||||
SynchronizingObject = this,
|
||||
|
||||
@@ -351,6 +351,9 @@ namespace OpenNest.Forms
|
||||
postProcessorMenuItem.Tag = postProcessor;
|
||||
postProcessorMenuItem.Click += PostProcessor_Click;
|
||||
mnuNestPost.DropDownItems.Add(postProcessorMenuItem);
|
||||
|
||||
if (postProcessor is IMaterialProvidingPostProcessor materialProvider)
|
||||
PostProcessorMaterials.AddFrom(materialProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1157,6 +1160,9 @@ namespace OpenNest.Forms
|
||||
if (postProcessor == null)
|
||||
return;
|
||||
|
||||
if (postProcessor is IPostProcessorNestAware nestAware)
|
||||
nestAware.PrepareForNest(activeForm.Nest);
|
||||
|
||||
if (postProcessor is IConfigurablePostProcessor configurable)
|
||||
{
|
||||
using var configForm = new PostProcessorConfigForm(configurable);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenNest
|
||||
{
|
||||
public static class PostProcessorMaterials
|
||||
{
|
||||
private static readonly List<string> materials = new();
|
||||
|
||||
public static IReadOnlyList<string> Names => materials;
|
||||
|
||||
public static void AddFrom(IMaterialProvidingPostProcessor provider)
|
||||
{
|
||||
if (provider == null)
|
||||
return;
|
||||
|
||||
foreach (var name in provider.GetMaterialNames())
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(name)
|
||||
&& !materials.Contains(name, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
materials.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
materials.Sort(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user