feat: implement color and line type exclusion filters on CadConverterForm

Add per-entity IsVisible flag and wire up the Colors and Line Types
checkedlistboxes to filter entities by exclusion — checking an item
hides matching entities from the preview and from drawing export.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 13:14:09 -04:00
parent bc392b37dc
commit e078ef4b77
5 changed files with 327 additions and 208 deletions
+16
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using OpenNest.Math; using OpenNest.Math;
namespace OpenNest.Geometry namespace OpenNest.Geometry
@@ -13,6 +14,21 @@ namespace OpenNest.Geometry
boundingBox = new Box(); boundingBox = new Box();
} }
/// <summary>
/// Entity color (resolved from DXF ByLayer/ByBlock to actual color).
/// </summary>
public Color Color { get; set; }
/// <summary>
/// Entity linetype name (e.g. "Continuous", "Center", "Dashed").
/// </summary>
public string LineTypeName { get; set; }
/// <summary>
/// Whether this entity is visible (used for color/linetype filtering).
/// </summary>
public bool IsVisible { get; set; } = true;
/// <summary> /// <summary>
/// Smallest box that contains the entity. /// Smallest box that contains the entity.
/// </summary> /// </summary>
+1 -1
View File
@@ -103,7 +103,7 @@ namespace OpenNest.Controls
private void DrawEntity(Graphics g, Entity e, Pen pen) private void DrawEntity(Graphics g, Entity e, Pen pen)
{ {
if (!e.Layer.IsVisible) if (!e.Layer.IsVisible || !e.IsVisible)
return; return;
switch (e.Type) switch (e.Type)
+184 -179
View File
@@ -29,247 +29,252 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); splitContainer1 = new System.Windows.Forms.SplitContainer();
this.dataGridView1 = new System.Windows.Forms.DataGridView(); dataGridView1 = new System.Windows.Forms.DataGridView();
this.splitContainer2 = new System.Windows.Forms.SplitContainer(); splitContainer2 = new System.Windows.Forms.SplitContainer();
this.tabControl1 = new System.Windows.Forms.TabControl(); tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage(); tabPage1 = new System.Windows.Forms.TabPage();
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox(); checkedListBox1 = new System.Windows.Forms.CheckedListBox();
this.tabPage2 = new System.Windows.Forms.TabPage(); tabPage2 = new System.Windows.Forms.TabPage();
this.checkedListBox2 = new System.Windows.Forms.CheckedListBox(); checkedListBox2 = new System.Windows.Forms.CheckedListBox();
this.tabPage3 = new System.Windows.Forms.TabPage(); tabPage3 = new System.Windows.Forms.TabPage();
this.checkedListBox3 = new System.Windows.Forms.CheckedListBox(); checkedListBox3 = new System.Windows.Forms.CheckedListBox();
this.entityView1 = new OpenNest.Controls.EntityView(); entityView1 = new OpenNest.Controls.EntityView();
this.bottomPanel1 = new OpenNest.Controls.BottomPanel(); bottomPanel1 = new OpenNest.Controls.BottomPanel();
this.cancelButton = new System.Windows.Forms.Button(); cancelButton = new System.Windows.Forms.Button();
this.acceptButton = new System.Windows.Forms.Button(); acceptButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)splitContainer2).BeginInit();
this.splitContainer2.Panel1.SuspendLayout(); splitContainer2.Panel1.SuspendLayout();
this.splitContainer2.Panel2.SuspendLayout(); splitContainer2.Panel2.SuspendLayout();
this.splitContainer2.SuspendLayout(); splitContainer2.SuspendLayout();
this.tabControl1.SuspendLayout(); tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout(); tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout(); tabPage2.SuspendLayout();
this.tabPage3.SuspendLayout(); tabPage3.SuspendLayout();
this.bottomPanel1.SuspendLayout(); bottomPanel1.SuspendLayout();
this.SuspendLayout(); SuspendLayout();
// //
// splitContainer1 // splitContainer1
// //
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0); splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1"; splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
// //
// splitContainer1.Panel1 // splitContainer1.Panel1
// //
this.splitContainer1.Panel1.Controls.Add(this.dataGridView1); splitContainer1.Panel1.Controls.Add(dataGridView1);
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); splitContainer1.Panel2.Controls.Add(splitContainer2);
this.splitContainer1.Size = new System.Drawing.Size(928, 479); splitContainer1.Size = new System.Drawing.Size(928, 643);
this.splitContainer1.SplitterDistance = 225; splitContainer1.SplitterDistance = 302;
this.splitContainer1.TabIndex = 0; splitContainer1.TabIndex = 0;
// //
// dataGridView1 // dataGridView1
// //
this.dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToResizeRows = false; dataGridView1.AllowUserToResizeRows = false;
this.dataGridView1.BackgroundColor = System.Drawing.Color.White; dataGridView1.BackgroundColor = System.Drawing.Color.White;
this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None; dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); dataGridViewCellStyle1.SelectionBackColor = System.Drawing.Color.FromArgb(255, 255, 192);
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Black; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Black;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle1; dataGridView1.DefaultCellStyle = dataGridViewCellStyle1;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.GridColor = System.Drawing.Color.Gainsboro; dataGridView1.GridColor = System.Drawing.Color.Gainsboro;
this.dataGridView1.Location = new System.Drawing.Point(0, 0); dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.MultiSelect = false; dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1"; dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersVisible = false; dataGridView1.RowHeadersVisible = false;
this.dataGridView1.RowTemplate.Height = 26; dataGridView1.RowTemplate.Height = 26;
this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView1.Size = new System.Drawing.Size(928, 225); dataGridView1.Size = new System.Drawing.Size(928, 302);
this.dataGridView1.TabIndex = 0; dataGridView1.TabIndex = 0;
this.dataGridView1.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(this.dataGridView1_DataBindingComplete); dataGridView1.DataBindingComplete += dataGridView1_DataBindingComplete;
this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged); dataGridView1.SelectionChanged += dataGridView1_SelectionChanged;
// //
// splitContainer2 // splitContainer2
// //
this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer2.Location = new System.Drawing.Point(0, 0); splitContainer2.Location = new System.Drawing.Point(0, 0);
this.splitContainer2.Name = "splitContainer2"; splitContainer2.Name = "splitContainer2";
// //
// splitContainer2.Panel1 // splitContainer2.Panel1
// //
this.splitContainer2.Panel1.Controls.Add(this.tabControl1); splitContainer2.Panel1.Controls.Add(tabControl1);
// //
// splitContainer2.Panel2 // splitContainer2.Panel2
// //
this.splitContainer2.Panel2.Controls.Add(this.entityView1); splitContainer2.Panel2.Controls.Add(entityView1);
this.splitContainer2.Size = new System.Drawing.Size(928, 250); splitContainer2.Size = new System.Drawing.Size(928, 337);
this.splitContainer2.SplitterDistance = 309; splitContainer2.SplitterDistance = 309;
this.splitContainer2.TabIndex = 0; splitContainer2.TabIndex = 0;
// //
// tabControl1 // tabControl1
// //
this.tabControl1.Controls.Add(this.tabPage1); tabControl1.Controls.Add(tabPage1);
this.tabControl1.Controls.Add(this.tabPage2); tabControl1.Controls.Add(tabPage2);
this.tabControl1.Controls.Add(this.tabPage3); tabControl1.Controls.Add(tabPage3);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0); tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1"; tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0; tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(309, 250); tabControl1.Size = new System.Drawing.Size(309, 337);
this.tabControl1.TabIndex = 0; tabControl1.TabIndex = 0;
// //
// tabPage1 // tabPage1
// //
this.tabPage1.Controls.Add(this.checkedListBox1); tabPage1.Controls.Add(checkedListBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 25); tabPage1.Location = new System.Drawing.Point(4, 25);
this.tabPage1.Name = "tabPage1"; tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3); tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(301, 221); tabPage1.Size = new System.Drawing.Size(301, 308);
this.tabPage1.TabIndex = 0; tabPage1.TabIndex = 0;
this.tabPage1.Text = "Layers"; tabPage1.Text = "Layers";
this.tabPage1.UseVisualStyleBackColor = true; tabPage1.UseVisualStyleBackColor = true;
// //
// checkedListBox1 // checkedListBox1
// //
this.checkedListBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; checkedListBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.checkedListBox1.CheckOnClick = true; checkedListBox1.CheckOnClick = true;
this.checkedListBox1.Dock = System.Windows.Forms.DockStyle.Fill; checkedListBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkedListBox1.FormattingEnabled = true; checkedListBox1.FormattingEnabled = true;
this.checkedListBox1.Location = new System.Drawing.Point(3, 3); checkedListBox1.Location = new System.Drawing.Point(3, 3);
this.checkedListBox1.Name = "checkedListBox1"; checkedListBox1.Name = "checkedListBox1";
this.checkedListBox1.Size = new System.Drawing.Size(295, 215); checkedListBox1.Size = new System.Drawing.Size(295, 302);
this.checkedListBox1.TabIndex = 0; checkedListBox1.TabIndex = 0;
this.checkedListBox1.SelectedIndexChanged += new System.EventHandler(this.checkedListBox1_SelectedIndexChanged); checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
// //
// tabPage2 // tabPage2
// //
this.tabPage2.Controls.Add(this.checkedListBox2); tabPage2.Controls.Add(checkedListBox2);
this.tabPage2.Location = new System.Drawing.Point(4, 22); tabPage2.Location = new System.Drawing.Point(4, 24);
this.tabPage2.Name = "tabPage2"; tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3); tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(301, 294); tabPage2.Size = new System.Drawing.Size(301, 309);
this.tabPage2.TabIndex = 1; tabPage2.TabIndex = 1;
this.tabPage2.Text = "Colors"; tabPage2.Text = "Colors";
this.tabPage2.UseVisualStyleBackColor = true; tabPage2.UseVisualStyleBackColor = true;
// //
// checkedListBox2 // checkedListBox2
// //
this.checkedListBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; checkedListBox2.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.checkedListBox2.Dock = System.Windows.Forms.DockStyle.Fill; checkedListBox2.CheckOnClick = true;
this.checkedListBox2.FormattingEnabled = true; checkedListBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkedListBox2.Location = new System.Drawing.Point(3, 3); checkedListBox2.FormattingEnabled = true;
this.checkedListBox2.Name = "checkedListBox2"; checkedListBox2.Location = new System.Drawing.Point(3, 3);
this.checkedListBox2.Size = new System.Drawing.Size(295, 288); checkedListBox2.Name = "checkedListBox2";
this.checkedListBox2.TabIndex = 1; checkedListBox2.Size = new System.Drawing.Size(295, 303);
checkedListBox2.TabIndex = 1;
checkedListBox2.DrawItem += checkedListBox2_DrawItem;
checkedListBox2.SelectedIndexChanged += checkedListBox2_SelectedIndexChanged;
// //
// tabPage3 // tabPage3
// //
this.tabPage3.Controls.Add(this.checkedListBox3); tabPage3.Controls.Add(checkedListBox3);
this.tabPage3.Location = new System.Drawing.Point(4, 22); tabPage3.Location = new System.Drawing.Point(4, 24);
this.tabPage3.Name = "tabPage3"; tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3); tabPage3.Padding = new System.Windows.Forms.Padding(3);
this.tabPage3.Size = new System.Drawing.Size(301, 294); tabPage3.Size = new System.Drawing.Size(301, 309);
this.tabPage3.TabIndex = 2; tabPage3.TabIndex = 2;
this.tabPage3.Text = "Line Types"; tabPage3.Text = "Line Types";
this.tabPage3.UseVisualStyleBackColor = true; tabPage3.UseVisualStyleBackColor = true;
// //
// checkedListBox3 // checkedListBox3
// //
this.checkedListBox3.BorderStyle = System.Windows.Forms.BorderStyle.None; checkedListBox3.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.checkedListBox3.Dock = System.Windows.Forms.DockStyle.Fill; checkedListBox3.CheckOnClick = true;
this.checkedListBox3.FormattingEnabled = true; checkedListBox3.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkedListBox3.Location = new System.Drawing.Point(3, 3); checkedListBox3.FormattingEnabled = true;
this.checkedListBox3.Name = "checkedListBox3"; checkedListBox3.Location = new System.Drawing.Point(3, 3);
this.checkedListBox3.Size = new System.Drawing.Size(295, 288); checkedListBox3.Name = "checkedListBox3";
this.checkedListBox3.TabIndex = 2; checkedListBox3.Size = new System.Drawing.Size(295, 303);
checkedListBox3.TabIndex = 2;
checkedListBox3.SelectedIndexChanged += checkedListBox3_SelectedIndexChanged;
// //
// entityView1 // entityView1
// //
this.entityView1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(40)))), ((int)(((byte)(48))))); entityView1.BackColor = System.Drawing.Color.FromArgb(33, 40, 48);
this.entityView1.Cursor = System.Windows.Forms.Cursors.Cross; entityView1.Cursor = System.Windows.Forms.Cursors.Cross;
this.entityView1.Dock = System.Windows.Forms.DockStyle.Fill; entityView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.entityView1.Location = new System.Drawing.Point(0, 0); entityView1.Location = new System.Drawing.Point(0, 0);
this.entityView1.Name = "entityView1"; entityView1.Name = "entityView1";
this.entityView1.Size = new System.Drawing.Size(615, 250); entityView1.Size = new System.Drawing.Size(615, 337);
this.entityView1.TabIndex = 0; entityView1.TabIndex = 0;
this.entityView1.Text = "entityView1"; entityView1.Text = "entityView1";
// //
// bottomPanel1 // bottomPanel1
// //
this.bottomPanel1.Controls.Add(this.cancelButton); bottomPanel1.Controls.Add(cancelButton);
this.bottomPanel1.Controls.Add(this.acceptButton); bottomPanel1.Controls.Add(acceptButton);
this.bottomPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; bottomPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.bottomPanel1.Location = new System.Drawing.Point(0, 479); bottomPanel1.Location = new System.Drawing.Point(0, 643);
this.bottomPanel1.Name = "bottomPanel1"; bottomPanel1.Name = "bottomPanel1";
this.bottomPanel1.Size = new System.Drawing.Size(928, 50); bottomPanel1.Size = new System.Drawing.Size(928, 50);
this.bottomPanel1.TabIndex = 1; bottomPanel1.TabIndex = 1;
// //
// cancelButton // cancelButton
// //
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(826, 10); cancelButton.Location = new System.Drawing.Point(826, 10);
this.cancelButton.Name = "cancelButton"; cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(90, 28); cancelButton.Size = new System.Drawing.Size(90, 28);
this.cancelButton.TabIndex = 1; cancelButton.TabIndex = 1;
this.cancelButton.Text = "Cancel"; cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true; cancelButton.UseVisualStyleBackColor = true;
// //
// acceptButton // acceptButton
// //
this.acceptButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); acceptButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
this.acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK; acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.acceptButton.Location = new System.Drawing.Point(730, 10); acceptButton.Location = new System.Drawing.Point(730, 10);
this.acceptButton.Name = "acceptButton"; acceptButton.Name = "acceptButton";
this.acceptButton.Size = new System.Drawing.Size(90, 28); acceptButton.Size = new System.Drawing.Size(90, 28);
this.acceptButton.TabIndex = 0; acceptButton.TabIndex = 0;
this.acceptButton.Text = "Accept"; acceptButton.Text = "Accept";
this.acceptButton.UseVisualStyleBackColor = true; acceptButton.UseVisualStyleBackColor = true;
// //
// CadConverterForm // CadConverterForm
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(928, 529); ClientSize = new System.Drawing.Size(928, 693);
this.Controls.Add(this.splitContainer1); Controls.Add(splitContainer1);
this.Controls.Add(this.bottomPanel1); Controls.Add(bottomPanel1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
this.MinimizeBox = false; MinimizeBox = false;
this.Name = "CadConverterForm"; Name = "CadConverterForm";
this.ShowIcon = false; ShowIcon = false;
this.ShowInTaskbar = false; ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "CAD Converter"; Text = "CAD Converter";
this.splitContainer1.Panel1.ResumeLayout(false); splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false); splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
this.splitContainer1.ResumeLayout(false); splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
this.splitContainer2.Panel1.ResumeLayout(false); splitContainer2.Panel1.ResumeLayout(false);
this.splitContainer2.Panel2.ResumeLayout(false); splitContainer2.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); ((System.ComponentModel.ISupportInitialize)splitContainer2).EndInit();
this.splitContainer2.ResumeLayout(false); splitContainer2.ResumeLayout(false);
this.tabControl1.ResumeLayout(false); tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false); tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false); tabPage2.ResumeLayout(false);
this.tabPage3.ResumeLayout(false); tabPage3.ResumeLayout(false);
this.bottomPanel1.ResumeLayout(false); bottomPanel1.ResumeLayout(false);
this.ResumeLayout(false); ResumeLayout(false);
} }
+99 -1
View File
@@ -46,6 +46,9 @@ namespace OpenNest.Forms
entityView1.Entities.AddRange(item.Entities); entityView1.Entities.AddRange(item.Entities);
entityView1.ZoomToFit(); entityView1.ZoomToFit();
item.Entities.ForEach(e => e.IsVisible = true);
// Layers
checkedListBox1.Items.Clear(); checkedListBox1.Items.Clear();
var layers = item.Entities var layers = item.Entities
@@ -56,6 +59,27 @@ namespace OpenNest.Forms
foreach (var layer in layers) foreach (var layer in layers)
checkedListBox1.Items.Add(layer, true); checkedListBox1.Items.Add(layer, true);
// Colors
checkedListBox2.Items.Clear();
var colors = item.Entities
.Select(e => e.Color.ToArgb())
.Distinct()
.Select(argb => new ColorItem(Color.FromArgb(argb)));
foreach (var color in colors)
checkedListBox2.Items.Add(color, false);
// Line Types
checkedListBox3.Items.Clear();
var lineTypes = item.Entities
.Select(e => e.LineTypeName ?? "Continuous")
.Distinct();
foreach (var lineType in lineTypes)
checkedListBox3.Items.Add(lineType, false);
} }
private static Color GetNextColor() private static Color GetNextColor()
@@ -77,7 +101,7 @@ namespace OpenNest.Forms
foreach (var item in Items) foreach (var item in Items)
{ {
var entities = item.Entities.Where(e => e.Layer.IsVisible).ToList(); var entities = item.Entities.Where(e => e.Layer.IsVisible && e.IsVisible).ToList();
if (entities.Count == 0) if (entities.Count == 0)
continue; continue;
@@ -216,6 +240,64 @@ namespace OpenNest.Forms
entityView1.Invalidate(); entityView1.Invalidate();
} }
private void checkedListBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
UpdateEntityVisibility();
}
private void checkedListBox3_SelectedIndexChanged(object sender, System.EventArgs e)
{
UpdateEntityVisibility();
}
private void UpdateEntityVisibility()
{
var item = CurrentItem;
if (item == null) return;
var checkedColors = new HashSet<int>();
for (var i = 0; i < checkedListBox2.Items.Count; i++)
{
if (checkedListBox2.GetItemChecked(i))
checkedColors.Add(((ColorItem)checkedListBox2.Items[i]).Argb);
}
var checkedLineTypes = new HashSet<string>();
for (var i = 0; i < checkedListBox3.Items.Count; i++)
{
if (checkedListBox3.GetItemChecked(i))
checkedLineTypes.Add(checkedListBox3.Items[i].ToString());
}
item.Entities.ForEach(entity =>
{
entity.IsVisible = !checkedColors.Contains(entity.Color.ToArgb())
&& !checkedLineTypes.Contains(entity.LineTypeName ?? "Continuous");
});
entityView1.Invalidate();
}
private void checkedListBox2_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0) return;
e.DrawBackground();
var colorItem = (ColorItem)checkedListBox2.Items[e.Index];
var swatchRect = new Rectangle(e.Bounds.Left + 20, e.Bounds.Top + 2, 16, e.Bounds.Height - 4);
using (var brush = new SolidBrush(colorItem.Color))
e.Graphics.FillRectangle(brush, swatchRect);
e.Graphics.DrawRectangle(Pens.Gray, swatchRect);
var textRect = new Rectangle(swatchRect.Right + 4, e.Bounds.Top, e.Bounds.Width - swatchRect.Right - 4, e.Bounds.Height);
TextRenderer.DrawText(e.Graphics, colorItem.ToString(), e.Font, textRect, e.ForeColor, TextFormatFlags.VerticalCenter);
e.DrawFocusRectangle();
}
} }
class CadConverterItem class CadConverterItem
@@ -233,6 +315,22 @@ namespace OpenNest.Forms
public List<Entity> Entities { get; set; } public List<Entity> Entities { get; set; }
} }
class ColorItem
{
public int Argb { get; }
public Color Color { get; }
public ColorItem(Color color)
{
Color = color;
Argb = color.ToArgb();
}
public override string ToString() => $"RGB({Color.R}, {Color.G}, {Color.B})";
public override bool Equals(object obj) => obj is ColorItem other && Argb == other.Argb;
public override int GetHashCode() => Argb;
}
public class RandomColorGenerator public class RandomColorGenerator
{ {
private readonly Random random; private readonly Random random;
+27 -27
View File
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
The primary goals of this format is to allow a simple XML format The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes various data types are done through the TypeConverter classes
associated with the data types. associated with the data types.
Example: Example:
... ado.net/XML headers & schema ... ... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader> <resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment> <comment>This is a comment</comment>
</data> </data>
There are any number of "resheader" rows that contain simple There are any number of "resheader" rows that contain simple
name/value pairs. name/value pairs.
Each data row contains a name, and value. The row also contains a Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture. text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the Classes that don't support this are serialized and stored with the
mimetype set. mimetype set.
The mimetype is used for serialized objects, and tells the The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly: extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below. read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64 mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->