diff --git a/OpenNest/Forms/PostProcessorConfigForm.Designer.cs b/OpenNest/Forms/PostProcessorConfigForm.Designer.cs new file mode 100644 index 0000000..fb18312 --- /dev/null +++ b/OpenNest/Forms/PostProcessorConfigForm.Designer.cs @@ -0,0 +1,98 @@ +namespace OpenNest.Forms +{ + partial class PostProcessorConfigForm + { + private System.ComponentModel.IContainer components = null; + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + private void InitializeComponent() + { + this.propertyGrid = new System.Windows.Forms.PropertyGrid(); + this.bottomPanel = new OpenNest.Controls.BottomPanel(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.bottomPanel.SuspendLayout(); + this.SuspendLayout(); + // + // propertyGrid + // + this.propertyGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.propertyGrid.Location = new System.Drawing.Point(0, 0); + this.propertyGrid.Name = "propertyGrid"; + this.propertyGrid.Size = new System.Drawing.Size(484, 511); + this.propertyGrid.TabIndex = 0; + this.propertyGrid.ToolbarVisible = true; + this.propertyGrid.PropertySort = System.Windows.Forms.PropertySort.Categorized; + // + // bottomPanel + // + this.bottomPanel.Controls.Add(this.okButton); + this.bottomPanel.Controls.Add(this.cancelButton); + this.bottomPanel.Dock = System.Windows.Forms.DockStyle.Bottom; + this.bottomPanel.Location = new System.Drawing.Point(0, 511); + this.bottomPanel.Name = "bottomPanel"; + this.bottomPanel.Size = new System.Drawing.Size(484, 50); + this.bottomPanel.TabIndex = 1; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.okButton.Location = new System.Drawing.Point(286, 11); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(90, 28); + this.okButton.TabIndex = 0; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(382, 11); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(90, 28); + this.cancelButton.TabIndex = 1; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // PostProcessorConfigForm + // + this.AcceptButton = this.okButton; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(484, 561); + this.Controls.Add(this.propertyGrid); + this.Controls.Add(this.bottomPanel); + this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "PostProcessorConfigForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Post Processor Settings"; + this.bottomPanel.ResumeLayout(false); + this.ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.PropertyGrid propertyGrid; + private Controls.BottomPanel bottomPanel; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + } +} diff --git a/OpenNest/Forms/PostProcessorConfigForm.cs b/OpenNest/Forms/PostProcessorConfigForm.cs new file mode 100644 index 0000000..0582da4 --- /dev/null +++ b/OpenNest/Forms/PostProcessorConfigForm.cs @@ -0,0 +1,42 @@ +using System; +using System.Text.Json; +using System.Windows.Forms; + +namespace OpenNest.Forms +{ + public partial class PostProcessorConfigForm : Form + { + private readonly IConfigurablePostProcessor postProcessor; + private readonly string configBackup; + + public PostProcessorConfigForm(IConfigurablePostProcessor postProcessor) + { + InitializeComponent(); + + this.postProcessor = postProcessor; + this.Text = postProcessor.Name + " Settings"; + + // Deep-clone config as JSON backup for cancel/restore + configBackup = JsonSerializer.Serialize(postProcessor.Config, postProcessor.Config.GetType()); + + propertyGrid.SelectedObject = postProcessor.Config; + } + + private void okButton_Click(object sender, EventArgs e) + { + postProcessor.SaveConfig(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + // Restore config from backup + var original = JsonSerializer.Deserialize(configBackup, postProcessor.Config.GetType()); + var properties = postProcessor.Config.GetType().GetProperties(); + foreach (var prop in properties) + { + if (prop.CanWrite) + prop.SetValue(postProcessor.Config, prop.GetValue(original)); + } + } + } +}