feat: rebuild CadConverterForm with sidebar+preview layout
Replace the old DataGridView+TabControl layout with a sidebar containing FileListControl and FilterPanel on the left, and EntityView with a detail bar on the right. Adds drag-and-drop support, thread-safe parallel file import, bend detection integration, and split-to-DXF workflow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+128
-241
@@ -1,298 +1,185 @@
|
|||||||
namespace OpenNest.Forms
|
namespace OpenNest.Forms
|
||||||
{
|
{
|
||||||
partial class CadConverterForm
|
partial class CadConverterForm
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
mainSplitter = new System.Windows.Forms.SplitContainer();
|
||||||
splitContainer1 = new System.Windows.Forms.SplitContainer();
|
sidebarSplitter = new System.Windows.Forms.SplitContainer();
|
||||||
dataGridView1 = new System.Windows.Forms.DataGridView();
|
fileList = new OpenNest.Controls.FileListControl();
|
||||||
splitContainer2 = new System.Windows.Forms.SplitContainer();
|
filterPanel = new OpenNest.Controls.FilterPanel();
|
||||||
tabControl1 = new System.Windows.Forms.TabControl();
|
rightPanel = new System.Windows.Forms.Panel();
|
||||||
tabPage1 = new System.Windows.Forms.TabPage();
|
|
||||||
checkedListBox1 = new System.Windows.Forms.CheckedListBox();
|
|
||||||
tabPage2 = new System.Windows.Forms.TabPage();
|
|
||||||
checkedListBox2 = new System.Windows.Forms.CheckedListBox();
|
|
||||||
tabPage3 = new System.Windows.Forms.TabPage();
|
|
||||||
checkedListBox3 = new System.Windows.Forms.CheckedListBox();
|
|
||||||
entityView1 = new OpenNest.Controls.EntityView();
|
entityView1 = new OpenNest.Controls.EntityView();
|
||||||
|
detailBar = new System.Windows.Forms.Panel();
|
||||||
|
lblDimensions = new System.Windows.Forms.Label();
|
||||||
|
lblEntityCount = new System.Windows.Forms.Label();
|
||||||
|
numQuantity = new System.Windows.Forms.NumericUpDown();
|
||||||
|
txtCustomer = new System.Windows.Forms.TextBox();
|
||||||
|
btnSplit = new System.Windows.Forms.Button();
|
||||||
|
cboBendDetector = new System.Windows.Forms.ComboBox();
|
||||||
|
lblQty = new System.Windows.Forms.Label();
|
||||||
|
lblCust = new System.Windows.Forms.Label();
|
||||||
|
lblDetect = new System.Windows.Forms.Label();
|
||||||
bottomPanel1 = new OpenNest.Controls.BottomPanel();
|
bottomPanel1 = new OpenNest.Controls.BottomPanel();
|
||||||
cancelButton = new System.Windows.Forms.Button();
|
cancelButton = new System.Windows.Forms.Button();
|
||||||
acceptButton = new System.Windows.Forms.Button();
|
acceptButton = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
|
||||||
splitContainer1.Panel1.SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)mainSplitter).BeginInit();
|
||||||
splitContainer1.Panel2.SuspendLayout();
|
mainSplitter.Panel1.SuspendLayout();
|
||||||
splitContainer1.SuspendLayout();
|
mainSplitter.Panel2.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
mainSplitter.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)splitContainer2).BeginInit();
|
((System.ComponentModel.ISupportInitialize)sidebarSplitter).BeginInit();
|
||||||
splitContainer2.Panel1.SuspendLayout();
|
sidebarSplitter.Panel1.SuspendLayout();
|
||||||
splitContainer2.Panel2.SuspendLayout();
|
sidebarSplitter.Panel2.SuspendLayout();
|
||||||
splitContainer2.SuspendLayout();
|
sidebarSplitter.SuspendLayout();
|
||||||
tabControl1.SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)numQuantity).BeginInit();
|
||||||
tabPage1.SuspendLayout();
|
|
||||||
tabPage2.SuspendLayout();
|
|
||||||
tabPage3.SuspendLayout();
|
|
||||||
bottomPanel1.SuspendLayout();
|
bottomPanel1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
|
||||||
// splitContainer1
|
// mainSplitter (sidebar | preview)
|
||||||
//
|
mainSplitter.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
|
mainSplitter.SplitterDistance = 260;
|
||||||
splitContainer1.Location = new System.Drawing.Point(0, 0);
|
mainSplitter.SplitterWidth = 3;
|
||||||
splitContainer1.Name = "splitContainer1";
|
mainSplitter.Panel1.Controls.Add(sidebarSplitter);
|
||||||
splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
|
mainSplitter.Panel2.Controls.Add(rightPanel);
|
||||||
//
|
|
||||||
// splitContainer1.Panel1
|
// sidebarSplitter (file list | filter panel)
|
||||||
//
|
sidebarSplitter.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
splitContainer1.Panel1.Controls.Add(dataGridView1);
|
sidebarSplitter.Orientation = System.Windows.Forms.Orientation.Horizontal;
|
||||||
//
|
sidebarSplitter.SplitterDistance = 280;
|
||||||
// splitContainer1.Panel2
|
sidebarSplitter.SplitterWidth = 3;
|
||||||
//
|
sidebarSplitter.Panel1.Controls.Add(fileList);
|
||||||
splitContainer1.Panel2.Controls.Add(splitContainer2);
|
sidebarSplitter.Panel2.Controls.Add(filterPanel);
|
||||||
splitContainer1.Size = new System.Drawing.Size(928, 643);
|
|
||||||
splitContainer1.SplitterDistance = 302;
|
// fileList
|
||||||
splitContainer1.TabIndex = 0;
|
fileList.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
//
|
fileList.AllowDrop = true;
|
||||||
// dataGridView1
|
|
||||||
//
|
// filterPanel
|
||||||
dataGridView1.AllowUserToAddRows = false;
|
filterPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
dataGridView1.AllowUserToResizeRows = false;
|
|
||||||
dataGridView1.BackgroundColor = System.Drawing.Color.White;
|
// rightPanel
|
||||||
dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
rightPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
rightPanel.Controls.Add(entityView1);
|
||||||
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
rightPanel.Controls.Add(detailBar);
|
||||||
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, 0);
|
|
||||||
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
|
|
||||||
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.Color.FromArgb(255, 255, 192);
|
|
||||||
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Black;
|
|
||||||
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
|
||||||
dataGridView1.DefaultCellStyle = dataGridViewCellStyle1;
|
|
||||||
dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
dataGridView1.GridColor = System.Drawing.Color.Gainsboro;
|
|
||||||
dataGridView1.Location = new System.Drawing.Point(0, 0);
|
|
||||||
dataGridView1.MultiSelect = false;
|
|
||||||
dataGridView1.Name = "dataGridView1";
|
|
||||||
dataGridView1.RowHeadersVisible = false;
|
|
||||||
dataGridView1.RowTemplate.Height = 26;
|
|
||||||
dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
dataGridView1.Size = new System.Drawing.Size(928, 302);
|
|
||||||
dataGridView1.TabIndex = 0;
|
|
||||||
dataGridView1.DataBindingComplete += dataGridView1_DataBindingComplete;
|
|
||||||
dataGridView1.SelectionChanged += dataGridView1_SelectionChanged;
|
|
||||||
//
|
|
||||||
// splitContainer2
|
|
||||||
//
|
|
||||||
splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
splitContainer2.Location = new System.Drawing.Point(0, 0);
|
|
||||||
splitContainer2.Name = "splitContainer2";
|
|
||||||
//
|
|
||||||
// splitContainer2.Panel1
|
|
||||||
//
|
|
||||||
splitContainer2.Panel1.Controls.Add(tabControl1);
|
|
||||||
//
|
|
||||||
// splitContainer2.Panel2
|
|
||||||
//
|
|
||||||
splitContainer2.Panel2.Controls.Add(entityView1);
|
|
||||||
splitContainer2.Size = new System.Drawing.Size(928, 337);
|
|
||||||
splitContainer2.SplitterDistance = 309;
|
|
||||||
splitContainer2.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// tabControl1
|
|
||||||
//
|
|
||||||
tabControl1.Controls.Add(tabPage1);
|
|
||||||
tabControl1.Controls.Add(tabPage2);
|
|
||||||
tabControl1.Controls.Add(tabPage3);
|
|
||||||
tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
tabControl1.Location = new System.Drawing.Point(0, 0);
|
|
||||||
tabControl1.Name = "tabControl1";
|
|
||||||
tabControl1.SelectedIndex = 0;
|
|
||||||
tabControl1.Size = new System.Drawing.Size(309, 337);
|
|
||||||
tabControl1.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// tabPage1
|
|
||||||
//
|
|
||||||
tabPage1.Controls.Add(checkedListBox1);
|
|
||||||
tabPage1.Location = new System.Drawing.Point(4, 25);
|
|
||||||
tabPage1.Name = "tabPage1";
|
|
||||||
tabPage1.Padding = new System.Windows.Forms.Padding(3);
|
|
||||||
tabPage1.Size = new System.Drawing.Size(301, 308);
|
|
||||||
tabPage1.TabIndex = 0;
|
|
||||||
tabPage1.Text = "Layers";
|
|
||||||
tabPage1.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// checkedListBox1
|
|
||||||
//
|
|
||||||
checkedListBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
||||||
checkedListBox1.CheckOnClick = true;
|
|
||||||
checkedListBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
checkedListBox1.FormattingEnabled = true;
|
|
||||||
checkedListBox1.Location = new System.Drawing.Point(3, 3);
|
|
||||||
checkedListBox1.Name = "checkedListBox1";
|
|
||||||
checkedListBox1.Size = new System.Drawing.Size(295, 302);
|
|
||||||
checkedListBox1.TabIndex = 0;
|
|
||||||
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
|
|
||||||
//
|
|
||||||
// tabPage2
|
|
||||||
//
|
|
||||||
tabPage2.Controls.Add(checkedListBox2);
|
|
||||||
tabPage2.Location = new System.Drawing.Point(4, 24);
|
|
||||||
tabPage2.Name = "tabPage2";
|
|
||||||
tabPage2.Padding = new System.Windows.Forms.Padding(3);
|
|
||||||
tabPage2.Size = new System.Drawing.Size(301, 309);
|
|
||||||
tabPage2.TabIndex = 1;
|
|
||||||
tabPage2.Text = "Colors";
|
|
||||||
tabPage2.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// checkedListBox2
|
|
||||||
//
|
|
||||||
checkedListBox2.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
||||||
checkedListBox2.CheckOnClick = true;
|
|
||||||
checkedListBox2.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
checkedListBox2.FormattingEnabled = true;
|
|
||||||
checkedListBox2.Location = new System.Drawing.Point(3, 3);
|
|
||||||
checkedListBox2.Name = "checkedListBox2";
|
|
||||||
checkedListBox2.Size = new System.Drawing.Size(295, 303);
|
|
||||||
checkedListBox2.TabIndex = 1;
|
|
||||||
checkedListBox2.DrawItem += checkedListBox2_DrawItem;
|
|
||||||
checkedListBox2.SelectedIndexChanged += checkedListBox2_SelectedIndexChanged;
|
|
||||||
//
|
|
||||||
// tabPage3
|
|
||||||
//
|
|
||||||
tabPage3.Controls.Add(checkedListBox3);
|
|
||||||
tabPage3.Location = new System.Drawing.Point(4, 24);
|
|
||||||
tabPage3.Name = "tabPage3";
|
|
||||||
tabPage3.Padding = new System.Windows.Forms.Padding(3);
|
|
||||||
tabPage3.Size = new System.Drawing.Size(301, 309);
|
|
||||||
tabPage3.TabIndex = 2;
|
|
||||||
tabPage3.Text = "Line Types";
|
|
||||||
tabPage3.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// checkedListBox3
|
|
||||||
//
|
|
||||||
checkedListBox3.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
||||||
checkedListBox3.CheckOnClick = true;
|
|
||||||
checkedListBox3.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
checkedListBox3.FormattingEnabled = true;
|
|
||||||
checkedListBox3.Location = new System.Drawing.Point(3, 3);
|
|
||||||
checkedListBox3.Name = "checkedListBox3";
|
|
||||||
checkedListBox3.Size = new System.Drawing.Size(295, 303);
|
|
||||||
checkedListBox3.TabIndex = 2;
|
|
||||||
checkedListBox3.SelectedIndexChanged += checkedListBox3_SelectedIndexChanged;
|
|
||||||
//
|
|
||||||
// entityView1
|
// entityView1
|
||||||
//
|
|
||||||
entityView1.BackColor = System.Drawing.Color.FromArgb(33, 40, 48);
|
entityView1.BackColor = System.Drawing.Color.FromArgb(33, 40, 48);
|
||||||
entityView1.Cursor = System.Windows.Forms.Cursors.Cross;
|
entityView1.Cursor = System.Windows.Forms.Cursors.Cross;
|
||||||
entityView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
entityView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
entityView1.Location = new System.Drawing.Point(0, 0);
|
|
||||||
entityView1.Name = "entityView1";
|
// detailBar
|
||||||
entityView1.Size = new System.Drawing.Size(615, 337);
|
detailBar.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
entityView1.TabIndex = 0;
|
detailBar.Height = 36;
|
||||||
entityView1.Text = "entityView1";
|
detailBar.BackColor = System.Drawing.Color.FromArgb(245, 245, 245);
|
||||||
//
|
detailBar.Padding = new System.Windows.Forms.Padding(6, 4, 6, 4);
|
||||||
|
|
||||||
|
lblQty = new System.Windows.Forms.Label { Text = "Qty:", AutoSize = true, Location = new System.Drawing.Point(6, 9), Font = new System.Drawing.Font("Segoe UI", 9f) };
|
||||||
|
numQuantity.Location = new System.Drawing.Point(35, 5);
|
||||||
|
numQuantity.Size = new System.Drawing.Size(50, 24);
|
||||||
|
numQuantity.Minimum = 1;
|
||||||
|
numQuantity.Maximum = 9999;
|
||||||
|
numQuantity.Value = 1;
|
||||||
|
numQuantity.Font = new System.Drawing.Font("Segoe UI", 9f);
|
||||||
|
|
||||||
|
lblCust = new System.Windows.Forms.Label { Text = "Customer:", AutoSize = true, Location = new System.Drawing.Point(95, 9), Font = new System.Drawing.Font("Segoe UI", 9f) };
|
||||||
|
txtCustomer.Location = new System.Drawing.Point(165, 5);
|
||||||
|
txtCustomer.Size = new System.Drawing.Size(120, 24);
|
||||||
|
txtCustomer.Font = new System.Drawing.Font("Segoe UI", 9f);
|
||||||
|
txtCustomer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
|
||||||
|
lblDimensions = new System.Windows.Forms.Label { AutoSize = true, Location = new System.Drawing.Point(300, 9), Font = new System.Drawing.Font("Segoe UI", 9f), ForeColor = System.Drawing.Color.Gray };
|
||||||
|
lblEntityCount = new System.Windows.Forms.Label { AutoSize = true, Location = new System.Drawing.Point(420, 9), Font = new System.Drawing.Font("Segoe UI", 9f), ForeColor = System.Drawing.Color.Gray };
|
||||||
|
|
||||||
|
btnSplit = new System.Windows.Forms.Button { Text = "Split...", Location = new System.Drawing.Point(520, 4), Size = new System.Drawing.Size(60, 28), FlatStyle = System.Windows.Forms.FlatStyle.Flat, Font = new System.Drawing.Font("Segoe UI", 9f) };
|
||||||
|
|
||||||
|
lblDetect = new System.Windows.Forms.Label { Text = "Bends:", AutoSize = true, Location = new System.Drawing.Point(590, 9), Font = new System.Drawing.Font("Segoe UI", 9f) };
|
||||||
|
cboBendDetector.Location = new System.Drawing.Point(638, 5);
|
||||||
|
cboBendDetector.Size = new System.Drawing.Size(100, 24);
|
||||||
|
cboBendDetector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
cboBendDetector.Font = new System.Drawing.Font("Segoe UI", 9f);
|
||||||
|
|
||||||
|
detailBar.Controls.AddRange(new System.Windows.Forms.Control[] {
|
||||||
|
lblQty, numQuantity, lblCust, txtCustomer,
|
||||||
|
lblDimensions, lblEntityCount, btnSplit,
|
||||||
|
lblDetect, cboBendDetector
|
||||||
|
});
|
||||||
|
|
||||||
// bottomPanel1
|
// bottomPanel1
|
||||||
//
|
bottomPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||||
|
bottomPanel1.Height = 50;
|
||||||
bottomPanel1.Controls.Add(cancelButton);
|
bottomPanel1.Controls.Add(cancelButton);
|
||||||
bottomPanel1.Controls.Add(acceptButton);
|
bottomPanel1.Controls.Add(acceptButton);
|
||||||
bottomPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
|
||||||
bottomPanel1.Location = new System.Drawing.Point(0, 643);
|
|
||||||
bottomPanel1.Name = "bottomPanel1";
|
|
||||||
bottomPanel1.Size = new System.Drawing.Size(928, 50);
|
|
||||||
bottomPanel1.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// cancelButton
|
|
||||||
//
|
|
||||||
cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||||
cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||||
cancelButton.Location = new System.Drawing.Point(826, 10);
|
cancelButton.Location = new System.Drawing.Point(826, 10);
|
||||||
cancelButton.Name = "cancelButton";
|
|
||||||
cancelButton.Size = new System.Drawing.Size(90, 28);
|
cancelButton.Size = new System.Drawing.Size(90, 28);
|
||||||
cancelButton.TabIndex = 1;
|
|
||||||
cancelButton.Text = "Cancel";
|
cancelButton.Text = "Cancel";
|
||||||
cancelButton.UseVisualStyleBackColor = true;
|
cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
//
|
cancelButton.Font = new System.Drawing.Font("Segoe UI", 9f);
|
||||||
// acceptButton
|
|
||||||
//
|
|
||||||
acceptButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
acceptButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
|
||||||
acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK;
|
acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||||
acceptButton.Location = new System.Drawing.Point(730, 10);
|
acceptButton.Location = new System.Drawing.Point(730, 10);
|
||||||
acceptButton.Name = "acceptButton";
|
|
||||||
acceptButton.Size = new System.Drawing.Size(90, 28);
|
acceptButton.Size = new System.Drawing.Size(90, 28);
|
||||||
acceptButton.TabIndex = 0;
|
|
||||||
acceptButton.Text = "Accept";
|
acceptButton.Text = "Accept";
|
||||||
acceptButton.UseVisualStyleBackColor = true;
|
acceptButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
//
|
acceptButton.Font = new System.Drawing.Font("Segoe UI", 9f);
|
||||||
|
|
||||||
// CadConverterForm
|
// CadConverterForm
|
||||||
//
|
|
||||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||||
ClientSize = new System.Drawing.Size(928, 693);
|
ClientSize = new System.Drawing.Size(1024, 720);
|
||||||
Controls.Add(splitContainer1);
|
Controls.Add(mainSplitter);
|
||||||
Controls.Add(bottomPanel1);
|
Controls.Add(bottomPanel1);
|
||||||
Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
|
Font = new System.Drawing.Font("Segoe UI", 9f);
|
||||||
MinimizeBox = false;
|
MinimizeBox = false;
|
||||||
Name = "CadConverterForm";
|
|
||||||
ShowIcon = false;
|
ShowIcon = false;
|
||||||
ShowInTaskbar = false;
|
ShowInTaskbar = false;
|
||||||
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||||
Text = "CAD Converter";
|
Text = "CAD Converter";
|
||||||
splitContainer1.Panel1.ResumeLayout(false);
|
AllowDrop = true;
|
||||||
splitContainer1.Panel2.ResumeLayout(false);
|
|
||||||
((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
|
((System.ComponentModel.ISupportInitialize)mainSplitter).EndInit();
|
||||||
splitContainer1.ResumeLayout(false);
|
mainSplitter.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
((System.ComponentModel.ISupportInitialize)sidebarSplitter).EndInit();
|
||||||
splitContainer2.Panel1.ResumeLayout(false);
|
sidebarSplitter.ResumeLayout(false);
|
||||||
splitContainer2.Panel2.ResumeLayout(false);
|
((System.ComponentModel.ISupportInitialize)numQuantity).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)splitContainer2).EndInit();
|
|
||||||
splitContainer2.ResumeLayout(false);
|
|
||||||
tabControl1.ResumeLayout(false);
|
|
||||||
tabPage1.ResumeLayout(false);
|
|
||||||
tabPage2.ResumeLayout(false);
|
|
||||||
tabPage3.ResumeLayout(false);
|
|
||||||
bottomPanel1.ResumeLayout(false);
|
bottomPanel1.ResumeLayout(false);
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.SplitContainer mainSplitter;
|
||||||
|
private System.Windows.Forms.SplitContainer sidebarSplitter;
|
||||||
|
private Controls.FileListControl fileList;
|
||||||
|
private Controls.FilterPanel filterPanel;
|
||||||
|
private System.Windows.Forms.Panel rightPanel;
|
||||||
|
private Controls.EntityView entityView1;
|
||||||
|
private System.Windows.Forms.Panel detailBar;
|
||||||
|
private System.Windows.Forms.Label lblDimensions;
|
||||||
|
private System.Windows.Forms.Label lblEntityCount;
|
||||||
|
private System.Windows.Forms.NumericUpDown numQuantity;
|
||||||
|
private System.Windows.Forms.TextBox txtCustomer;
|
||||||
|
private System.Windows.Forms.Button btnSplit;
|
||||||
|
private System.Windows.Forms.ComboBox cboBendDetector;
|
||||||
|
private System.Windows.Forms.Label lblQty;
|
||||||
|
private System.Windows.Forms.Label lblCust;
|
||||||
|
private System.Windows.Forms.Label lblDetect;
|
||||||
|
private Controls.BottomPanel bottomPanel1;
|
||||||
private System.Windows.Forms.Button acceptButton;
|
private System.Windows.Forms.Button acceptButton;
|
||||||
private System.Windows.Forms.Button cancelButton;
|
private System.Windows.Forms.Button cancelButton;
|
||||||
private Controls.BottomPanel bottomPanel1;
|
|
||||||
private System.Windows.Forms.SplitContainer splitContainer1;
|
|
||||||
private System.Windows.Forms.DataGridView dataGridView1;
|
|
||||||
private System.Windows.Forms.SplitContainer splitContainer2;
|
|
||||||
private System.Windows.Forms.TabControl tabControl1;
|
|
||||||
private System.Windows.Forms.TabPage tabPage1;
|
|
||||||
private System.Windows.Forms.TabPage tabPage2;
|
|
||||||
private Controls.EntityView entityView1;
|
|
||||||
private System.Windows.Forms.CheckedListBox checkedListBox1;
|
|
||||||
private System.Windows.Forms.TabPage tabPage3;
|
|
||||||
private System.Windows.Forms.CheckedListBox checkedListBox2;
|
|
||||||
private System.Windows.Forms.CheckedListBox checkedListBox3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+295
-280
@@ -1,10 +1,13 @@
|
|||||||
using OpenNest.CNC;
|
using OpenNest.Bending;
|
||||||
|
using OpenNest.CNC;
|
||||||
|
using OpenNest.Controls;
|
||||||
using OpenNest.Converters;
|
using OpenNest.Converters;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
using OpenNest.IO;
|
using OpenNest.IO;
|
||||||
|
using OpenNest.IO.Bending;
|
||||||
using OpenNest.Properties;
|
using OpenNest.Properties;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -16,206 +19,203 @@ namespace OpenNest.Forms
|
|||||||
{
|
{
|
||||||
public partial class CadConverterForm : Form
|
public partial class CadConverterForm : Form
|
||||||
{
|
{
|
||||||
|
private static int colorIndex;
|
||||||
|
|
||||||
public CadConverterForm()
|
public CadConverterForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Items = new BindingList<CadConverterItem>();
|
fileList.SelectedIndexChanged += OnFileSelected;
|
||||||
dataGridView1.DataSource = Items;
|
filterPanel.FilterChanged += OnFilterChanged;
|
||||||
dataGridView1.DataError += dataGridView1_DataError;
|
filterPanel.BendLineSelected += OnBendLineSelected;
|
||||||
|
filterPanel.BendLineRemoved += OnBendLineRemoved;
|
||||||
|
btnSplit.Click += OnSplitClicked;
|
||||||
|
numQuantity.ValueChanged += OnQuantityChanged;
|
||||||
|
txtCustomer.TextChanged += OnCustomerChanged;
|
||||||
|
cboBendDetector.SelectedIndexChanged += OnBendDetectorChanged;
|
||||||
|
|
||||||
var splitColumn = new DataGridViewButtonColumn
|
// Populate bend detector dropdown
|
||||||
{
|
cboBendDetector.Items.Add("Auto");
|
||||||
Name = "Split",
|
foreach (var detector in BendDetectorRegistry.Detectors)
|
||||||
HeaderText = "",
|
cboBendDetector.Items.Add(detector.Name);
|
||||||
Text = "Split",
|
cboBendDetector.SelectedIndex = 0;
|
||||||
UseColumnTextForButtonValue = true,
|
|
||||||
Width = 50
|
// Drag & drop
|
||||||
};
|
AllowDrop = true;
|
||||||
dataGridView1.Columns.Add(splitColumn);
|
DragEnter += OnDragEnter;
|
||||||
dataGridView1.CellContentClick += OnCellContentClick;
|
DragDrop += OnDragDrop;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BindingList<CadConverterItem> Items { get; set; }
|
private FileListItem CurrentItem => fileList.SelectedItem;
|
||||||
|
|
||||||
private void SetRotation(Shape shape, RotationType rotation)
|
#region File Import
|
||||||
|
|
||||||
|
public void AddFile(string file) => AddFile(file, 0, null);
|
||||||
|
|
||||||
|
private void AddFile(string file, int detectorIndex, string detectorName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
var dir = shape.ToPolygon(3).RotationDirection();
|
|
||||||
|
|
||||||
if (dir != rotation)
|
|
||||||
shape.Reverse();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadItem(CadConverterItem item)
|
|
||||||
{
|
|
||||||
entityView1.Entities.Clear();
|
|
||||||
entityView1.Entities.AddRange(item.Entities);
|
|
||||||
entityView1.ZoomToFit();
|
|
||||||
|
|
||||||
item.Entities.ForEach(e => e.IsVisible = true);
|
|
||||||
|
|
||||||
// Layers
|
|
||||||
checkedListBox1.Items.Clear();
|
|
||||||
|
|
||||||
var layers = item.Entities
|
|
||||||
.Where(e => e.Layer != null)
|
|
||||||
.Select(e => e.Layer.Name)
|
|
||||||
.ToList()
|
|
||||||
.Distinct();
|
|
||||||
|
|
||||||
foreach (var layer in layers)
|
|
||||||
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 int colorIndex;
|
|
||||||
|
|
||||||
private static Color GetNextColor()
|
|
||||||
{
|
|
||||||
var color = ColorScheme.PartColors[colorIndex % ColorScheme.PartColors.Length];
|
|
||||||
colorIndex++;
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Drawing> GetDrawings()
|
|
||||||
{
|
|
||||||
var drawings = new List<Drawing>();
|
|
||||||
|
|
||||||
foreach (var item in Items)
|
|
||||||
{
|
|
||||||
if (item.SplitDrawings != null && item.SplitDrawings.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var splitDrawing in item.SplitDrawings)
|
|
||||||
splitDrawing.Color = GetNextColor();
|
|
||||||
drawings.AddRange(item.SplitDrawings);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var entities = item.Entities.Where(e => e.Layer.IsVisible && e.IsVisible).ToList();
|
|
||||||
|
|
||||||
if (entities.Count == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var drawing = new Drawing(item.Name);
|
|
||||||
drawing.Color = GetNextColor();
|
|
||||||
drawing.Customer = item.Customer;
|
|
||||||
drawing.Source.Path = item.Path;
|
|
||||||
drawing.Quantity.Required = item.Quantity;
|
|
||||||
|
|
||||||
var shape = new ShapeProfile(entities);
|
|
||||||
|
|
||||||
SetRotation(shape.Perimeter, RotationType.CW);
|
|
||||||
|
|
||||||
foreach (var cutout in shape.Cutouts)
|
|
||||||
SetRotation(cutout, RotationType.CCW);
|
|
||||||
|
|
||||||
entities = new List<Entity>();
|
|
||||||
entities.AddRange(shape.Perimeter.Entities);
|
|
||||||
|
|
||||||
shape.Cutouts.ForEach(cutout => entities.AddRange(cutout.Entities));
|
|
||||||
|
|
||||||
var pgm = ConvertGeometry.ToProgram(entities);
|
|
||||||
var firstCode = pgm[0];
|
|
||||||
|
|
||||||
if (firstCode.Type == CodeType.RapidMove)
|
|
||||||
{
|
|
||||||
var rapid = (RapidMove)firstCode;
|
|
||||||
|
|
||||||
drawing.Source.Offset = rapid.EndPoint;
|
|
||||||
|
|
||||||
pgm.Offset(-rapid.EndPoint);
|
|
||||||
pgm.Codes.RemoveAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
drawing.Program = pgm;
|
|
||||||
drawings.Add(drawing);
|
|
||||||
|
|
||||||
Thread.Sleep(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
return drawings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CadConverterItem CurrentItem
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return dataGridView1.SelectedRows.Count != 0
|
|
||||||
? Items[dataGridView1.SelectedRows[0].Index]
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddFile(string file)
|
|
||||||
{
|
{
|
||||||
var importer = new DxfImporter();
|
var importer = new DxfImporter();
|
||||||
importer.SplinePrecision = Settings.Default.ImportSplinePrecision;
|
importer.SplinePrecision = Settings.Default.ImportSplinePrecision;
|
||||||
|
var result = importer.Import(file);
|
||||||
|
|
||||||
var entities = new List<Entity>();
|
if (result.Entities.Count == 0)
|
||||||
|
|
||||||
if (!importer.GetGeometry(file, out entities))
|
|
||||||
{
|
|
||||||
MessageBox.Show("Failed to import file \"" + file + "\"");
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Compute bounds
|
||||||
|
var bounds = result.Entities.GetBoundingBox();
|
||||||
|
|
||||||
|
// Detect bends (detectorIndex/Name captured on UI thread)
|
||||||
|
var bends = new List<Bend>();
|
||||||
|
if (result.Document != null)
|
||||||
|
{
|
||||||
|
bends = detectorIndex == 0
|
||||||
|
? BendDetectorRegistry.AutoDetect(result.Document)
|
||||||
|
: BendDetectorRegistry.GetByName(detectorName)
|
||||||
|
?.DetectBends(result.Document)
|
||||||
|
?? new List<Bend>();
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (Items)
|
var item = new FileListItem
|
||||||
{
|
|
||||||
Items.Add(new CadConverterItem
|
|
||||||
{
|
{
|
||||||
Name = Path.GetFileNameWithoutExtension(file),
|
Name = Path.GetFileNameWithoutExtension(file),
|
||||||
Entities = entities,
|
Entities = result.Entities,
|
||||||
Path = file,
|
Path = file,
|
||||||
Quantity = 1,
|
Quantity = 1,
|
||||||
Customer = string.Empty
|
Customer = string.Empty,
|
||||||
});
|
Bends = bends,
|
||||||
|
Bounds = bounds,
|
||||||
|
EntityCount = result.Entities.Count
|
||||||
|
};
|
||||||
|
|
||||||
|
if (InvokeRequired)
|
||||||
|
BeginInvoke((Action)(() => fileList.AddItem(item)));
|
||||||
|
else
|
||||||
|
fileList.AddItem(item);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Error importing \"{file}\": {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddFiles(IEnumerable<string> files)
|
public void AddFiles(IEnumerable<string> files)
|
||||||
{
|
{
|
||||||
Parallel.ForEach(files, AddFile);
|
var fileArray = files.ToArray();
|
||||||
|
// Capture UI state on main thread before entering parallel loop
|
||||||
|
var detectorIndex = cboBendDetector.SelectedIndex;
|
||||||
|
var detectorName = cboBendDetector.SelectedItem?.ToString();
|
||||||
|
|
||||||
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
|
{
|
||||||
|
Parallel.ForEach(fileArray, file => AddFile(file, detectorIndex, detectorName));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
|
#endregion
|
||||||
|
|
||||||
|
#region Event Handlers
|
||||||
|
|
||||||
|
private void OnFileSelected(object sender, int index)
|
||||||
{
|
{
|
||||||
MessageBox.Show(e.Exception.Message);
|
var item = CurrentItem;
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
ClearDetailBar();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCellContentClick(object sender, DataGridViewCellEventArgs e)
|
LoadItem(item);
|
||||||
{
|
}
|
||||||
if (e.RowIndex < 0) return;
|
|
||||||
if (dataGridView1.Columns[e.ColumnIndex].Name != "Split") return;
|
private void LoadItem(FileListItem item)
|
||||||
|
{
|
||||||
|
entityView1.ClearPenCache();
|
||||||
|
entityView1.Entities.Clear();
|
||||||
|
entityView1.Entities.AddRange(item.Entities);
|
||||||
|
|
||||||
|
item.Entities.ForEach(e => e.IsVisible = true);
|
||||||
|
if (item.Entities.Any(e => e.Layer != null))
|
||||||
|
item.Entities.ForEach(e => e.Layer.IsVisible = true);
|
||||||
|
|
||||||
|
filterPanel.LoadItem(item.Entities, item.Bends);
|
||||||
|
|
||||||
|
numQuantity.Value = item.Quantity;
|
||||||
|
txtCustomer.Text = item.Customer ?? "";
|
||||||
|
|
||||||
|
var bounds = item.Bounds;
|
||||||
|
lblDimensions.Text = bounds != null
|
||||||
|
? $"{bounds.Width:0.#} x {bounds.Length:0.#}"
|
||||||
|
: "";
|
||||||
|
lblEntityCount.Text = $"{item.EntityCount} entities";
|
||||||
|
|
||||||
|
entityView1.ZoomToFit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearDetailBar()
|
||||||
|
{
|
||||||
|
numQuantity.Value = 1;
|
||||||
|
txtCustomer.Text = "";
|
||||||
|
lblDimensions.Text = "";
|
||||||
|
lblEntityCount.Text = "";
|
||||||
|
entityView1.Entities.Clear();
|
||||||
|
entityView1.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFilterChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var item = CurrentItem;
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
|
filterPanel.ApplyFilters(item.Entities);
|
||||||
|
entityView1.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBendLineSelected(object sender, int index)
|
||||||
|
{
|
||||||
|
// TODO: Highlight bend line in EntityView
|
||||||
|
entityView1.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBendLineRemoved(object sender, int index)
|
||||||
|
{
|
||||||
|
var item = CurrentItem;
|
||||||
|
if (item == null || index < 0 || index >= item.Bends.Count) return;
|
||||||
|
|
||||||
|
item.Bends.RemoveAt(index);
|
||||||
|
filterPanel.LoadItem(item.Entities, item.Bends);
|
||||||
|
entityView1.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnQuantityChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var item = CurrentItem;
|
||||||
|
if (item != null)
|
||||||
|
item.Quantity = (int)numQuantity.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCustomerChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var item = CurrentItem;
|
||||||
|
if (item != null)
|
||||||
|
item.Customer = txtCustomer.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBendDetectorChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Re-run bend detection on current item if it has a document
|
||||||
|
// For now, bend detection only runs at import time
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSplitClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var item = CurrentItem;
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
var item = Items[e.RowIndex];
|
|
||||||
var entities = item.Entities.Where(en => en.Layer.IsVisible && en.IsVisible).ToList();
|
var entities = item.Entities.Where(en => en.Layer.IsVisible && en.IsVisible).ToList();
|
||||||
if (entities.Count == 0) return;
|
if (entities.Count == 0) return;
|
||||||
|
|
||||||
// Build a temporary drawing from the item's entities (same logic as GetDrawings)
|
|
||||||
var shape = new ShapeProfile(entities);
|
var shape = new ShapeProfile(entities);
|
||||||
SetRotation(shape.Perimeter, RotationType.CW);
|
SetRotation(shape.Perimeter, RotationType.CW);
|
||||||
foreach (var cutout in shape.Cutouts)
|
foreach (var cutout in shape.Cutouts)
|
||||||
@@ -236,153 +236,168 @@ namespace OpenNest.Forms
|
|||||||
var drawing = new Drawing(item.Name, pgm);
|
var drawing = new Drawing(item.Name, pgm);
|
||||||
|
|
||||||
using var form = new SplitDrawingForm(drawing);
|
using var form = new SplitDrawingForm(drawing);
|
||||||
if (form.ShowDialog(this) == DialogResult.OK && form.ResultDrawings?.Count > 1)
|
if (form.ShowDialog(this) != DialogResult.OK || form.ResultDrawings?.Count <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Write split DXF files and re-import
|
||||||
|
var sourceDir = Path.GetDirectoryName(item.Path);
|
||||||
|
var baseName = Path.GetFileNameWithoutExtension(item.Path);
|
||||||
|
var writableDir = Directory.Exists(sourceDir) && IsDirectoryWritable(sourceDir)
|
||||||
|
? sourceDir
|
||||||
|
: Path.GetTempPath();
|
||||||
|
|
||||||
|
var index = fileList.SelectedIndex;
|
||||||
|
var newItems = new List<string>();
|
||||||
|
|
||||||
|
for (var i = 0; i < form.ResultDrawings.Count; i++)
|
||||||
{
|
{
|
||||||
item.SplitDrawings = form.ResultDrawings;
|
var splitName = $"{baseName}_split{i + 1}.dxf";
|
||||||
dataGridView1.InvalidateRow(e.RowIndex);
|
var splitPath = GetUniquePath(Path.Combine(writableDir, splitName));
|
||||||
}
|
|
||||||
|
// TODO: Use SplitDxfWriter when implemented
|
||||||
|
// For now, export via DxfExporter
|
||||||
|
var exporter = new DxfExporter();
|
||||||
|
using var stream = new FileStream(splitPath, FileMode.Create);
|
||||||
|
exporter.ExportProgram(form.ResultDrawings[i].Program, stream);
|
||||||
|
|
||||||
|
newItems.Add(splitPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
|
// Remove original and add split files
|
||||||
{
|
fileList.RemoveAt(index);
|
||||||
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
|
foreach (var path in newItems)
|
||||||
|
AddFile(path);
|
||||||
|
|
||||||
|
if (writableDir != sourceDir)
|
||||||
|
MessageBox.Show($"Split files written to: {writableDir}", "Split Output",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dataGridView1_SelectionChanged(object sender, System.EventArgs e)
|
private void OnDragEnter(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
var currentItem = CurrentItem;
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||||
|
e.Effect = DragDropEffects.Copy;
|
||||||
if (currentItem != null)
|
|
||||||
LoadItem(currentItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Colors
|
private void OnDragDrop(object sender, DragEventArgs e)
|
||||||
|
|
||||||
private static Color[] Colors = new Color[]
|
|
||||||
{
|
{
|
||||||
Color.FromArgb(160, 255, 255),
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||||
Color.FromArgb(160, 255, 160),
|
{
|
||||||
Color.FromArgb(160, 160, 255),
|
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||||
Color.FromArgb(255, 255, 160),
|
var dxfFiles = files.Where(f =>
|
||||||
Color.FromArgb(255, 160, 255),
|
f.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||||
Color.FromArgb(255, 160, 160),
|
if (dxfFiles.Length > 0)
|
||||||
|
AddFiles(dxfFiles);
|
||||||
Color.FromArgb(200, 255, 255),
|
}
|
||||||
Color.FromArgb(200, 255, 200),
|
}
|
||||||
Color.FromArgb(200, 200, 255),
|
|
||||||
Color.FromArgb(255, 255, 200),
|
|
||||||
Color.FromArgb(255, 200, 255),
|
|
||||||
Color.FromArgb(255, 200, 200),
|
|
||||||
};
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
|
#region Output
|
||||||
{
|
|
||||||
var index = checkedListBox1.SelectedIndex;
|
|
||||||
var layerName = checkedListBox1.Items[index].ToString();
|
|
||||||
var isVisible = checkedListBox1.CheckedItems.Contains(layerName);
|
|
||||||
|
|
||||||
CurrentItem.Entities.ForEach(entity =>
|
public List<Drawing> GetDrawings()
|
||||||
{
|
{
|
||||||
if (entity.Layer.Name == layerName)
|
var drawings = new List<Drawing>();
|
||||||
entity.Layer.IsVisible = isVisible;
|
|
||||||
});
|
|
||||||
|
|
||||||
entityView1.Invalidate();
|
foreach (var item in fileList.Items)
|
||||||
|
{
|
||||||
|
var entities = item.Entities.Where(e => e.Layer.IsVisible && e.IsVisible).ToList();
|
||||||
|
|
||||||
|
if (entities.Count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var drawing = new Drawing(item.Name);
|
||||||
|
drawing.Color = GetNextColor();
|
||||||
|
drawing.Customer = item.Customer;
|
||||||
|
drawing.Source.Path = item.Path;
|
||||||
|
drawing.Quantity.Required = item.Quantity;
|
||||||
|
|
||||||
|
// Copy bends
|
||||||
|
if (item.Bends != null)
|
||||||
|
drawing.Bends.AddRange(item.Bends);
|
||||||
|
|
||||||
|
var shape = new ShapeProfile(entities);
|
||||||
|
|
||||||
|
SetRotation(shape.Perimeter, RotationType.CW);
|
||||||
|
|
||||||
|
foreach (var cutout in shape.Cutouts)
|
||||||
|
SetRotation(cutout, RotationType.CCW);
|
||||||
|
|
||||||
|
entities = new List<Entity>();
|
||||||
|
entities.AddRange(shape.Perimeter.Entities);
|
||||||
|
shape.Cutouts.ForEach(cutout => entities.AddRange(cutout.Entities));
|
||||||
|
|
||||||
|
var pgm = ConvertGeometry.ToProgram(entities);
|
||||||
|
var firstCode = pgm[0];
|
||||||
|
|
||||||
|
if (firstCode.Type == CodeType.RapidMove)
|
||||||
|
{
|
||||||
|
var rapid = (RapidMove)firstCode;
|
||||||
|
drawing.Source.Offset = rapid.EndPoint;
|
||||||
|
pgm.Offset(-rapid.EndPoint);
|
||||||
|
pgm.Codes.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkedListBox2_SelectedIndexChanged(object sender, System.EventArgs e)
|
drawing.Program = pgm;
|
||||||
|
drawings.Add(drawing);
|
||||||
|
|
||||||
|
Thread.Sleep(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
return drawings;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
private static void SetRotation(Shape shape, RotationType rotation)
|
||||||
{
|
{
|
||||||
UpdateEntityVisibility();
|
try
|
||||||
}
|
|
||||||
|
|
||||||
private void checkedListBox3_SelectedIndexChanged(object sender, System.EventArgs e)
|
|
||||||
{
|
{
|
||||||
UpdateEntityVisibility();
|
var dir = shape.ToPolygon(3).RotationDirection();
|
||||||
|
if (dir != rotation) shape.Reverse();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateEntityVisibility()
|
private static Color GetNextColor()
|
||||||
{
|
{
|
||||||
var item = CurrentItem;
|
var color = ColorScheme.PartColors[colorIndex % ColorScheme.PartColors.Length];
|
||||||
if (item == null) return;
|
colorIndex++;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
var checkedColors = new HashSet<int>();
|
private static bool IsDirectoryWritable(string path)
|
||||||
for (var i = 0; i < checkedListBox2.Items.Count; i++)
|
|
||||||
{
|
{
|
||||||
if (checkedListBox2.GetItemChecked(i))
|
try
|
||||||
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))
|
var testFile = Path.Combine(path, $".writetest_{Guid.NewGuid()}");
|
||||||
checkedLineTypes.Add(checkedListBox3.Items[i].ToString());
|
File.WriteAllText(testFile, "");
|
||||||
|
File.Delete(testFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Entities.ForEach(entity =>
|
private static string GetUniquePath(string path)
|
||||||
{
|
{
|
||||||
entity.IsVisible = !checkedColors.Contains(entity.Color.ToArgb())
|
if (!File.Exists(path)) return path;
|
||||||
&& !checkedLineTypes.Contains(entity.LineTypeName ?? "Continuous");
|
|
||||||
});
|
|
||||||
|
|
||||||
entityView1.Invalidate();
|
var dir = Path.GetDirectoryName(path);
|
||||||
}
|
var name = Path.GetFileNameWithoutExtension(path);
|
||||||
|
var ext = Path.GetExtension(path);
|
||||||
|
var counter = 2;
|
||||||
|
|
||||||
private void checkedListBox2_DrawItem(object sender, DrawItemEventArgs e)
|
while (File.Exists(path))
|
||||||
{
|
{
|
||||||
if (e.Index < 0) return;
|
path = Path.Combine(dir, $"{name}_{counter}{ext}");
|
||||||
|
counter++;
|
||||||
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
|
return path;
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public string Customer { get; set; }
|
|
||||||
|
|
||||||
public int Quantity { get; set; }
|
|
||||||
|
|
||||||
[ReadOnly(true)]
|
|
||||||
public string Path { get; set; }
|
|
||||||
|
|
||||||
[Browsable(false)]
|
|
||||||
public List<Entity> Entities { get; set; }
|
|
||||||
|
|
||||||
[Browsable(false)]
|
|
||||||
public List<Drawing> SplitDrawings { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ColorItem
|
#endregion
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user