using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using PaintDotNet.Annotation;
using PaintDotNet.Annotation.Enum;
using PaintDotNet.Base;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.Functionodel;
using PaintDotNet.Base.SettingModel;
using PaintDotNet.CustomControl;
using PaintDotNet.Data.Param;
using PaintDotNet.GeneralAnalysis.Artwork;
using PaintDotNet.Processing;
using static PaintDotNet.GeneralAnalysis.Artwork.ImageTools;
namespace PaintDotNet.GeneralAnalysis
{
internal class ArtworkSettingEditDialog : PdnBaseForm
{
#region
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeLanguageText()
{
this.Text = PdnResources.GetString("Menu.Setting.Text");
this.label5.Text = PdnResources.GetString("Menu.Thecoordinateofthecenterpoin.Text") + ":";
this.label4.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Xcoordinateofcenterpoint.text") + ":";
this.groupBox5.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Position.text") + "2";
this.label7.Text = PdnResources.GetString("Menu.color.text") + ":";
this.label8.Text = PdnResources.GetString("Menu.Thecoordinateofthecenterpoin.Text") + ":";
this.label9.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Xcoordinateofcenterpoint.text") + ":";
this.groupBox6.Text = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
this.chkScrapIsDel.Text = PdnResources.GetString("Menu.Clasticdelete.text") + ":";
this.label12.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
this.label10.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Extractionrange.text") + ":";
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.btnSave.Text = PdnResources.GetString("Menu.imagecapture.timelapse.SaveSettings.text");
this.btnFromDisk.Text = PdnResources.GetString("Menu.harddisk.text");
this.btnFromGallery.Text = PdnResources.GetString("Menu.Gallery.text");
this.label1.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Processdrawingname.text") + ":";
this.groupBox2.Text = PdnResources.GetString("Menu.Previewpicture.Text");
this.groupBox3.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Definetheshape.text");
this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Sidelength.text") + ":";
this.groupBox4.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Position.text") + "1";
this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnSave = new System.Windows.Forms.Button();
this.btnFromDisk = new System.Windows.Forms.Button();
this.btnFromGallery = new System.Windows.Forms.Button();
this.txtName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.pnlTools = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.nudLineWidth = new System.Windows.Forms.NumericUpDown();
this.nudSide = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.nudPoint1Y = new System.Windows.Forms.NumericUpDown();
this.nudPoint1X = new System.Windows.Forms.NumericUpDown();
this.panel1 = new System.Windows.Forms.Panel();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.nudPoint2Y = new System.Windows.Forms.NumericUpDown();
this.nudPoint2X = new System.Windows.Forms.NumericUpDown();
this.panel2 = new System.Windows.Forms.Panel();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.groupBox6 = new System.Windows.Forms.GroupBox();
this.panel3 = new System.Windows.Forms.Panel();
this.label13 = new System.Windows.Forms.Label();
this.nudScrapMax = new System.Windows.Forms.NumericUpDown();
this.nudScrapMin = new System.Windows.Forms.NumericUpDown();
this.chkScrapIsDel = new System.Windows.Forms.CheckBox();
this.label12 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.nudTowValueMax = new System.Windows.Forms.NumericUpDown();
this.nudTowValueMin = new System.Windows.Forms.NumericUpDown();
this.label10 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudLineWidth)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudSide)).BeginInit();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPoint1Y)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudPoint1X)).BeginInit();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPoint2Y)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudPoint2X)).BeginInit();
this.groupBox6.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudScrapMax)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudScrapMin)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudTowValueMax)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudTowValueMin)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.btnSave);
this.groupBox1.Controls.Add(this.btnFromDisk);
this.groupBox1.Controls.Add(this.btnFromGallery);
this.groupBox1.Controls.Add(this.txtName);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(1018, 90);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// btnSave
//
this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSave.Location = new System.Drawing.Point(900, 33);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(91, 31);
this.btnSave.TabIndex = 4;
this.btnSave.Text = "保存设置";
this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// btnFromDisk
//
this.btnFromDisk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnFromDisk.Location = new System.Drawing.Point(794, 33);
this.btnFromDisk.Name = "btnFromDisk";
this.btnFromDisk.Size = new System.Drawing.Size(75, 31);
this.btnFromDisk.TabIndex = 3;
this.btnFromDisk.Text = "硬盘";
this.btnFromDisk.UseVisualStyleBackColor = true;
this.btnFromDisk.Click += new System.EventHandler(this.btnFromDisk_Click);
//
// btnFromGallery
//
this.btnFromGallery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnFromGallery.Location = new System.Drawing.Point(688, 33);
this.btnFromGallery.Name = "btnFromGallery";
this.btnFromGallery.Size = new System.Drawing.Size(75, 31);
this.btnFromGallery.TabIndex = 2;
this.btnFromGallery.Text = "图库";
this.btnFromGallery.UseVisualStyleBackColor = true;
this.btnFromGallery.Click += new System.EventHandler(this.btnFromGallery_Click);
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(141, 37);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(218, 21);
this.txtName.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(38, 44);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(77, 12);
this.label1.TabIndex = 0;
this.label1.Text = "工艺图名称:";
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.pnlTools);
this.groupBox2.Controls.Add(this.panel4);
this.groupBox2.Location = new System.Drawing.Point(12, 119);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(1018, 502);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "图片预览";
//
// pnlTools
//
this.pnlTools.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.pnlTools.BackColor = System.Drawing.SystemColors.Control;
this.pnlTools.Location = new System.Drawing.Point(433, 460);
this.pnlTools.Name = "pnlTools";
this.pnlTools.Size = new System.Drawing.Size(169, 36);
this.pnlTools.TabIndex = 1;
//
// panel4
//
this.panel4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel4.Location = new System.Drawing.Point(17, 24);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(984, 430);
this.panel4.TabIndex = 0;
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.groupBox3.Controls.Add(this.nudLineWidth);
this.groupBox3.Controls.Add(this.nudSide);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.label2);
this.groupBox3.Location = new System.Drawing.Point(12, 636);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(191, 137);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "定义外形";
//
// nudLineWidth
//
this.nudLineWidth.Location = new System.Drawing.Point(76, 61);
this.nudLineWidth.Maximum = new decimal(new int[] {
20,
0,
0,
0});
this.nudLineWidth.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nudLineWidth.Name = "nudLineWidth";
this.nudLineWidth.Size = new System.Drawing.Size(74, 21);
this.nudLineWidth.TabIndex = 5;
this.nudLineWidth.Value = new decimal(new int[] {
1,
0,
0,
0});
this.nudLineWidth.ValueChanged += new System.EventHandler(this.nudLineWidth_ValueChanged);
this.nudLineWidth.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudLineWidth_KeyUp);
//
// nudSide
//
this.nudSide.Location = new System.Drawing.Point(76, 28);
this.nudSide.Minimum = new decimal(new int[] {
10,
0,
0,
0});
this.nudSide.Name = "nudSide";
this.nudSide.Size = new System.Drawing.Size(74, 21);
this.nudSide.TabIndex = 3;
this.nudSide.Value = new decimal(new int[] {
20,
0,
0,
0});
this.nudSide.ValueChanged += new System.EventHandler(this.nudSide_ValueChanged);
this.nudSide.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudSide_KeyUp);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(18, 66);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(41, 12);
this.label3.TabIndex = 4;
this.label3.Text = "线宽:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(18, 30);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 12);
this.label2.TabIndex = 3;
this.label2.Text = "边长:";
//
// groupBox4
//
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.groupBox4.Controls.Add(this.nudPoint1Y);
this.groupBox4.Controls.Add(this.nudPoint1X);
this.groupBox4.Controls.Add(this.panel1);
this.groupBox4.Controls.Add(this.label6);
this.groupBox4.Controls.Add(this.label5);
this.groupBox4.Controls.Add(this.label4);
this.groupBox4.Location = new System.Drawing.Point(220, 636);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(216, 137);
this.groupBox4.TabIndex = 3;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "定位1";
//
// nudPoint1Y
//
this.nudPoint1Y.Location = new System.Drawing.Point(123, 59);
this.nudPoint1Y.Maximum = new decimal(new int[] {
99999999,
0,
0,
0});
this.nudPoint1Y.Name = "nudPoint1Y";
this.nudPoint1Y.Size = new System.Drawing.Size(78, 21);
this.nudPoint1Y.TabIndex = 11;
this.nudPoint1Y.ValueChanged += new System.EventHandler(this.nudPoint1Y_ValueChanged);
this.nudPoint1Y.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudPoint1Y_KeyUp);
//
// nudPoint1X
//
this.nudPoint1X.Location = new System.Drawing.Point(123, 24);
this.nudPoint1X.Maximum = new decimal(new int[] {
999999999,
0,
0,
0});
this.nudPoint1X.Name = "nudPoint1X";
this.nudPoint1X.Size = new System.Drawing.Size(78, 21);
this.nudPoint1X.TabIndex = 10;
this.nudPoint1X.ValueChanged += new System.EventHandler(this.nudPoint1X_ValueChanged);
this.nudPoint1X.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudPoint1X_KeyUp);
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Location = new System.Drawing.Point(82, 95);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(105, 26);
this.panel1.TabIndex = 9;
this.panel1.BackColorChanged += new System.EventHandler(this.panel1_BackColorChanged);
this.panel1.Click += new System.EventHandler(this.panel1_Click);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(22, 99);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(41, 12);
this.label6.TabIndex = 8;
this.label6.Text = "颜色:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(22, 64);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(83, 12);
this.label5.TabIndex = 6;
this.label5.Text = "中心点Y坐标:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(22, 29);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(83, 12);
this.label4.TabIndex = 4;
this.label4.Text = "中心点X坐标:";
//
// groupBox5
//
this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.groupBox5.Controls.Add(this.nudPoint2Y);
this.groupBox5.Controls.Add(this.nudPoint2X);
this.groupBox5.Controls.Add(this.panel2);
this.groupBox5.Controls.Add(this.label7);
this.groupBox5.Controls.Add(this.label8);
this.groupBox5.Controls.Add(this.label9);
this.groupBox5.Location = new System.Drawing.Point(458, 636);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(216, 137);
this.groupBox5.TabIndex = 4;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "定位2";
//
// nudPoint2Y
//
this.nudPoint2Y.Location = new System.Drawing.Point(132, 57);
this.nudPoint2Y.Maximum = new decimal(new int[] {
99999999,
0,
0,
0});
this.nudPoint2Y.Name = "nudPoint2Y";
this.nudPoint2Y.Size = new System.Drawing.Size(78, 21);
this.nudPoint2Y.TabIndex = 17;
this.nudPoint2Y.ValueChanged += new System.EventHandler(this.nudPoint2Y_ValueChanged);
this.nudPoint2Y.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudPoint2Y_KeyUp);
//
// nudPoint2X
//
this.nudPoint2X.Location = new System.Drawing.Point(132, 23);
this.nudPoint2X.Maximum = new decimal(new int[] {
99999999,
0,
0,
0});
this.nudPoint2X.Name = "nudPoint2X";
this.nudPoint2X.Size = new System.Drawing.Size(78, 21);
this.nudPoint2X.TabIndex = 16;
this.nudPoint2X.ValueChanged += new System.EventHandler(this.nudPoint2X_ValueChanged);
this.nudPoint2X.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudPoint2X_KeyUp);
//
// panel2
//
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Location = new System.Drawing.Point(86, 93);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(105, 26);
this.panel2.TabIndex = 15;
this.panel2.BackColorChanged += new System.EventHandler(this.panel2_BackColorChanged);
this.panel2.Click += new System.EventHandler(this.panel2_Click);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(26, 99);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(41, 12);
this.label7.TabIndex = 14;
this.label7.Text = "颜色:";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(26, 62);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(83, 12);
this.label8.TabIndex = 12;
this.label8.Text = "中心点Y坐标:";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(26, 27);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(83, 12);
this.label9.TabIndex = 10;
this.label9.Text = "中心点X坐标:";
//
// groupBox6
//
this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox6.Controls.Add(this.panel3);
this.groupBox6.Controls.Add(this.label13);
this.groupBox6.Controls.Add(this.nudScrapMax);
this.groupBox6.Controls.Add(this.nudScrapMin);
this.groupBox6.Controls.Add(this.chkScrapIsDel);
this.groupBox6.Controls.Add(this.label12);
this.groupBox6.Controls.Add(this.label11);
this.groupBox6.Controls.Add(this.nudTowValueMax);
this.groupBox6.Controls.Add(this.nudTowValueMin);
this.groupBox6.Controls.Add(this.label10);
this.groupBox6.Location = new System.Drawing.Point(691, 636);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(339, 137);
this.groupBox6.TabIndex = 5;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "二值提取";
//
// panel3
//
this.panel3.BackColor = System.Drawing.Color.Red;
this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel3.Location = new System.Drawing.Point(136, 57);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(105, 26);
this.panel3.TabIndex = 16;
this.panel3.BackColorChanged += new System.EventHandler(this.panel3_BackColorChanged);
this.panel3.Click += new System.EventHandler(this.panel3_Click);
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(223, 101);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(11, 12);
this.label13.TabIndex = 13;
this.label13.Text = "~";
//
// nudScrapMax
//
this.nudScrapMax.Location = new System.Drawing.Point(252, 91);
this.nudScrapMax.Maximum = new decimal(new int[] {
9999,
0,
0,
0});
this.nudScrapMax.Name = "nudScrapMax";
this.nudScrapMax.Size = new System.Drawing.Size(74, 21);
this.nudScrapMax.TabIndex = 12;
this.nudScrapMax.ValueChanged += new System.EventHandler(this.nudScrapMax_ValueChanged);
this.nudScrapMax.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudScrapMax_KeyUp);
//
// nudScrapMin
//
this.nudScrapMin.Location = new System.Drawing.Point(136, 91);
this.nudScrapMin.Maximum = new decimal(new int[] {
9999,
0,
0,
0});
this.nudScrapMin.Name = "nudScrapMin";
this.nudScrapMin.Size = new System.Drawing.Size(74, 21);
this.nudScrapMin.TabIndex = 11;
this.nudScrapMin.ValueChanged += new System.EventHandler(this.nudScrapMin_ValueChanged);
this.nudScrapMin.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudScrapMin_KeyUp);
//
// chkScrapIsDel
//
this.chkScrapIsDel.AutoSize = true;
this.chkScrapIsDel.Location = new System.Drawing.Point(26, 98);
this.chkScrapIsDel.Name = "chkScrapIsDel";
this.chkScrapIsDel.Size = new System.Drawing.Size(72, 16);
this.chkScrapIsDel.TabIndex = 10;
this.chkScrapIsDel.Text = "碎屑删除";
this.chkScrapIsDel.UseVisualStyleBackColor = true;
this.chkScrapIsDel.CheckedChanged += new System.EventHandler(this.chkScrapIsDel_CheckedChanged);
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(23, 61);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(53, 12);
this.label12.TabIndex = 9;
this.label12.Text = "相颜色:";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(223, 34);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(11, 12);
this.label11.TabIndex = 8;
this.label11.Text = "~";
//
// nudTowValueMax
//
this.nudTowValueMax.Location = new System.Drawing.Point(252, 24);
this.nudTowValueMax.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.nudTowValueMax.Name = "nudTowValueMax";
this.nudTowValueMax.Size = new System.Drawing.Size(74, 21);
this.nudTowValueMax.TabIndex = 7;
this.nudTowValueMax.ValueChanged += new System.EventHandler(this.nudTowValue_ValueChanged);
this.nudTowValueMax.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudTowValueMax_KeyUp);
//
// nudTowValueMin
//
this.nudTowValueMin.Location = new System.Drawing.Point(136, 26);
this.nudTowValueMin.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.nudTowValueMin.Name = "nudTowValueMin";
this.nudTowValueMin.Size = new System.Drawing.Size(74, 21);
this.nudTowValueMin.TabIndex = 6;
this.nudTowValueMin.ValueChanged += new System.EventHandler(this.nudTowValue_ValueChanged);
this.nudTowValueMin.KeyUp += new System.Windows.Forms.KeyEventHandler(this.nudTowValueMin_KeyUp);
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(23, 30);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(65, 12);
this.label10.TabIndex = 0;
this.label10.Text = "提取范围:";
//
// ArtworkSettingEditDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1042, 785);
this.Controls.Add(this.groupBox6);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "ArtworkSettingEditDialog";
this.Text = "工艺图设定";
this.Resize += new System.EventHandler(this.ArtworkSettingEditDialog_Resize);
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.groupBox4, 0);
this.Controls.SetChildIndex(this.groupBox5, 0);
this.Controls.SetChildIndex(this.groupBox6, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudLineWidth)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudSide)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPoint1Y)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudPoint1X)).EndInit();
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudPoint2Y)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudPoint2X)).EndInit();
this.groupBox6.ResumeLayout(false);
this.groupBox6.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudScrapMax)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudScrapMin)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudTowValueMax)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudTowValueMin)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.Button btnFromDisk;
private System.Windows.Forms.Button btnFromGallery;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.NumericUpDown nudLineWidth;
private System.Windows.Forms.NumericUpDown nudSide;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.GroupBox groupBox6;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.NumericUpDown nudTowValueMax;
private System.Windows.Forms.NumericUpDown nudTowValueMin;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.NumericUpDown nudScrapMax;
private System.Windows.Forms.NumericUpDown nudScrapMin;
private System.Windows.Forms.CheckBox chkScrapIsDel;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.NumericUpDown nudPoint1Y;
private System.Windows.Forms.NumericUpDown nudPoint1X;
private System.Windows.Forms.NumericUpDown nudPoint2Y;
private System.Windows.Forms.NumericUpDown nudPoint2X;
private System.Windows.Forms.Panel pnlTools;
#endregion
private ArtworkModel m_artworkModel;
private List m_artworkLists = new List();
private ArtworkModel.Item m_artwork;
///
/// 网格调色板
///
PaintDotNet.ColorsForm colorsFormGrid;
///
/// 图片选择窗口
///
private InterImagePickerDialog imagePickerDialog;
private string m_filePath = Application.StartupPath + "\\Artwork\\";
private int m_index;
private AppWorkspace m_appWorkspace;
private DocumentWorkspaceWindow m_documentWorkspace;
private ArtworkControlButtons m_controlButtons;
private int m_width;
private int m_height;
private Bitmap m_bitmap;
private string m_picName;
private string m_originalPicName;
private string m_thumbnailName;
private object m_currentSender;
private Form m_parentForm;
///
/// 单位标尺
///
private double unitLength = 1;
///
/// 二值图像
///
private Mat m_mat;
///
/// 处理程序
///
private ParamObject action = new Data.Action.Action901();
///
/// 初始系统参数配置值
///
private BinaryExtractionModel binaryExtractionModel;
private int m_angle = 0;
public ArtworkSettingEditDialog(Form form, AppWorkspace workspace, int index)
{
m_parentForm = form;
m_appWorkspace = workspace;
m_index = index;
if (!Directory.Exists(m_filePath))
{
Directory.CreateDirectory(m_filePath);//不存在就创建目录
}
this.binaryExtractionModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\Default.xml", FileMode.Open));
InitializeComponent();
InitializeLanguageText();
InitializeData();
this.colorsFormGrid = new ColorsForm();
this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
InitializeTools();
}
private void InitializeData()
{
this.m_documentWorkspace = new DocumentWorkspaceWindow(m_appWorkspace);
this.m_documentWorkspace.AppWorkspaceTop = m_appWorkspace;
this.m_documentWorkspace.Visible = true;
this.m_documentWorkspace.Dock = DockStyle.Fill;
this.panel4.Controls.Add(this.m_documentWorkspace);
//
//初始化相
//
PhaseModel model = new PhaseModel();
model.choise = true;
model.mat = null;
model.color = panel3.BackColor.ToArgb();
model.position = this.m_documentWorkspace.PhaseModels.Count + 1;
model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
this.m_documentWorkspace.PhaseModels.Add(model);
this.m_documentWorkspace.GraphicsList = new GraphicsList(this.m_documentWorkspace);
this.m_documentWorkspace.GraphicsList.SelectChanged += GraphicsList_SelectChanged;
m_artworkModel = Startup.instance.artworkModel;
m_artworkLists = m_artworkModel.items;
if (m_index == -1)
{
m_artwork = new ArtworkModel.Item();
//m_bitmap = new Bitmap(100, 100);
m_picName = System.Guid.NewGuid().ToString("N") + ".Png";
m_thumbnailName = System.Guid.NewGuid().ToString("N") + ".Png";
m_originalPicName = System.Guid.NewGuid().ToString("N") + ".Png";
panel3.BackColor = Color.Blue;
}
else
{
m_artwork = m_artworkLists[m_index];
if (System.IO.File.Exists(m_filePath + m_artwork.originalPic))
{
Image bitmap1 = Image.FromFile(m_filePath + m_artwork.originalPic);
m_bitmap = new Bitmap(bitmap1);
bitmap1.Dispose();
}
else
{
m_bitmap = new Bitmap(100, 100);
}
this.m_documentWorkspace.Document = Document.FromImage(m_bitmap);
m_picName = m_artwork.pic;
m_thumbnailName = m_artwork.thumbnail;
m_originalPicName = m_artwork.originalPic;
txtName.Text = m_artwork.artworkName;
nudSide.Value = m_artwork.side;
nudLineWidth.Value = m_artwork.lineWidth;
nudPoint1X.Value = m_artwork.point1X;
nudPoint1Y.Value = m_artwork.point1Y;
panel1.BackColor = ColorTranslator.FromHtml(m_artwork.point1Color);
nudPoint2X.Value = m_artwork.point2X;
nudPoint2Y.Value = m_artwork.point2Y;
panel2.BackColor = ColorTranslator.FromHtml(m_artwork.point2Color);
nudTowValueMin.Value = m_artwork.twoValueGetMin;
nudTowValueMax.Value = m_artwork.twoValueGetMax;
panel3.BackColor = ColorTranslator.FromHtml(m_artwork.twoValueColor);
chkScrapIsDel.Checked = m_artwork.scrapIsDel;
nudScrapMin.Value = m_artwork.scrapMin;
nudScrapMax.Value = m_artwork.scrapMax;
}
//先修改参数
foreach (Args args in action.Lists)
{
switch (args.Key)
{
case "phaseColor":
args.Value = panel3.BackColor.ToArgb();
break;
case "debrisRemoval":
args.Value = chkScrapIsDel.Checked;
break;
case "scope1":
((List)args.Value)[0] = (int)nudTowValueMin.Value;
((List)args.Value)[1] = (int)nudTowValueMax.Value;
break;
case "scope4":
((List)args.Value)[0] = (double)nudScrapMin.Value;
((List)args.Value)[1] = (double)nudScrapMax.Value;
break;
}
}
this.binaryExtractionModel.DebrisRemoval = chkScrapIsDel.Checked;
this.binaryExtractionModel.DebrisAreaStart = (int)nudScrapMin.Value;
this.binaryExtractionModel.DebrisAreaEnd = (int)nudScrapMax.Value;
this.binaryExtractionModel.ColorOneStart = (int)nudTowValueMin.Value;
this.binaryExtractionModel.ColorOneEnd = (int)nudTowValueMax.Value;
this.binaryExtractionModel.PhaseColor = panel3.BackColor.ToArgb();
}
private void GraphicsList_SelectChanged(object sender, EventArgs e)
{
GraphicsList graphicsList = (GraphicsList)sender;
if (graphicsList.Count < 2)
{
return;
}
for (int i = 0; i < graphicsList.Count; i++)
{
RectangleF rectangle = graphicsList[i].GetBoundingBox();
if (((DrawObject)graphicsList[i]).ID == 0)
{
nudPoint1X.Value = (int)rectangle.X + nudSide.Value / 2;
nudPoint1Y.Value = (int)rectangle.Y + nudSide.Value / 2;
}
else
{
nudPoint2X.Value = (int)rectangle.X + nudSide.Value / 2;
nudPoint2Y.Value = (int)rectangle.Y + nudSide.Value / 2;
}
}
}
private void InitializeTools()
{
this.m_controlButtons = new ArtworkControlButtons();
this.m_controlButtons.Dock = DockStyle.Top;
this.m_controlButtons.Height = 30;
this.m_controlButtons.HideMovingDirection();
this.m_controlButtons.turnLeftButton.Visible = true;
this.m_controlButtons.turnRightButton.Visible = true;
this.pnlTools.Controls.Add(m_controlButtons);
this.m_controlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
this.m_controlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
this.m_controlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
this.m_controlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
this.m_controlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
this.m_controlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
this.m_controlButtons.turnLeftButton.Click += new EventHandler(turnLeftButton_Click);
this.m_controlButtons.turnRightButton.Click += new EventHandler(turnRightButton_Click);
//
//获取系统标尺-微米
//
this.m_appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength);
//this.m_appWorkspace.ActiveDocumentWorkspace.GetRuler(MeasurementUnit.Micron);
}
private void turnRightButton_Click(object sender, EventArgs e)
{
if (m_bitmap == null)
{
return;
}
m_angle += 1;
if(m_angle == 4)
{
m_angle = 0;
}
m_bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.m_documentWorkspace.Document = Document.FromImage(m_bitmap);
this.applyButtonImpl();
}
private void turnLeftButton_Click(object sender, EventArgs e)
{
if (m_bitmap == null)
{
return;
}
m_angle -= 1;
if (m_angle == -4)
{
m_angle = 0;
}
m_bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
this.m_documentWorkspace.Document = Document.FromImage(m_bitmap);
this.applyButtonImpl();
}
private void mobileModeButton_Click(object sender, EventArgs e)
{
this.m_documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
}
private void pointerButton_Click(object sender, EventArgs e)
{
this.m_documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
}
private void zoomToWindowButton_Click(object sender, EventArgs e)
{
if (this.m_documentWorkspace.CompositionSurface != null)
{
this.m_documentWorkspace.ZoomToWindow();
}
}
private void actualSizeButton_Click(object sender, EventArgs e)
{
if (this.m_documentWorkspace.CompositionSurface != null)
{
this.m_documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
this.m_documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
}
}
private void zoomOutButton_Click(object sender, EventArgs e)
{
if (this.m_documentWorkspace.CompositionSurface != null)
this.m_documentWorkspace.ZoomOut();
}
private void zoomInButton_Click(object sender, EventArgs e)
{
if (this.m_documentWorkspace.CompositionSurface != null)
this.m_documentWorkspace.ZoomIn();
}
private void MovePointReceived(int index, int x, int y)
{
if(index ==0)
{
this.Invoke(new Action(() =>
{
nudPoint1X.Value = x;
nudPoint1Y.Value = y;
}));
}
else
{
this.Invoke(new Action(() =>
{
nudPoint2X.Value = x;
nudPoint2Y.Value = y;
}));
}
}
private void SetBitmap(Bitmap bitmap)
{
m_bitmap = bitmap;
m_width = bitmap.Width;
m_height = bitmap.Height;
this.m_documentWorkspace.Document = Document.FromImage(m_bitmap);
this.applyButtonImpl();
// 新添加
if (m_index == -1)
{
int side = Convert.ToInt32(nudSide.Value / 2);
Random ran = new Random();
nudPoint1X.Value = ran.Next(side, m_width - side);
nudPoint1Y.Value = ran.Next(side, m_height - side);
nudPoint2X.Value = ran.Next(side, m_width - side);
nudPoint2Y.Value = ran.Next(side, m_height - side);
panel1.BackColor = Color.Green;
panel2.BackColor = Color.Red;
}
}
private void btnFromDisk_Click(object sender, EventArgs e)
{
Bitmap newBit1 = ChooseImageFromHardDisk();//暂时接收一下,如果为空则不替换原有的原图对象
if (newBit1 != null)
{
this.SetBitmap(newBit1);
}
}
///
/// 从硬盘选择图片
///
///
private Bitmap ChooseImageFromHardDisk()
{
OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
DialogResult result = openFileDialog.ShowDialog();
if (result == DialogResult.OK)
{
Image image = Image.FromFile(openFileDialog.FileName);
Bitmap newBit = new Bitmap(image);
return newBit;
}
else
{
return null;
}
}
private void btnFromGallery_Click(object sender, EventArgs e)
{
ImagePickerDialog(sender);
}
///
/// 弹出图库选择窗口
///
///
private void ImagePickerDialog(object sender)
{
if (imagePickerDialog == null)
{
imagePickerDialog = new InterImagePickerDialog(m_appWorkspace);
imagePickerDialog.StartPosition = FormStartPosition.Manual;
if (this.Right >= System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - 150)
{
imagePickerDialog.Left = Screen.PrimaryScreen.Bounds.Width - 500;
}
else
{
imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
}
imagePickerDialog.Top = ((Button)sender).Bottom + 50 ;
imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
imagePickerDialog.Show();
}
else
{
if (!imagePickerDialog.IsDisposed)
{
imagePickerDialog.WindowState = FormWindowState.Normal;
}
else
{
imagePickerDialog = new InterImagePickerDialog(m_appWorkspace);
imagePickerDialog.StartPosition = FormStartPosition.Manual;
if (this.Right >= System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - 150)
{
imagePickerDialog.Left = Screen.PrimaryScreen.Bounds.Width - 500;
}
else
{
imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
}
imagePickerDialog.Top = ((Button)sender).Bottom + 50;
imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
imagePickerDialog.Show();
}
}
}
///
/// 从图库选择待对照图片
///
///
///
private void inputMat_ValueChanged(object sender, EventArgs e)
{
if (sender is DocumentWorkspace)
{
Bitmap bitmap1 = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();
if (bitmap1 != null)
{
this.SetBitmap(bitmap1);
}
}
}
private void ShowColorsForm(object sender)
{
Panel panel = (Panel)sender;
this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(panel.BackColor);
this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
this.colorsFormGrid.ShowDialog();
}
///
/// 网格Panel的调色板颜色改变
///
///
///
private void gridColorChanged(object sender, EventArgs e)
{
Panel panel = (Panel)m_currentSender;
Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
panel.BackColor = color;
this.colorsFormGrid.Close();
}
///
/// 定位1颜色
///
///
///
private void panel1_Click(object sender, EventArgs e)
{
m_currentSender = sender;
ShowColorsForm(sender);
}
///
/// 定位2颜色
///
///
///
private void panel2_Click(object sender, EventArgs e)
{
m_currentSender = sender;
ShowColorsForm(sender);
}
///
/// 二值提取颜色
///
///
///
private void panel3_Click(object sender, EventArgs e)
{
m_currentSender = sender;
ShowColorsForm(sender);
}
private void DrawRectangle(int index, Color color, int lineWidth, int x, int y, int width, int height)
{
for(int i= 0; i< this.m_documentWorkspace.GraphicsList.Count; i++)
{
if(((DrawObject)this.m_documentWorkspace.GraphicsList[i]).ID == index)
{
this.m_documentWorkspace.GraphicsList.RemoveObj((DrawObject)this.m_documentWorkspace.GraphicsList[i]);
}
}
Rectangle rectangle1 = new Rectangle(x, y, width, height);
Pen pen = new Pen(color, lineWidth);
this.m_documentWorkspace.ActiveTool = DrawToolType.DrawArtworkRectangle;
this.m_documentWorkspace.CreateArtworkRectangle(index, pen, rectangle1);
}
private void DrawPoint1()
{
Color color = panel1.BackColor;
int lineWidth = Convert.ToInt32(nudLineWidth.Value);
int X = Convert.ToInt32(nudPoint1X.Value);
int Y = Convert.ToInt32(nudPoint1Y.Value);
int width = Convert.ToInt32(nudSide.Value);
int height = width;
int x = X - width / 2;
int y = Y - height / 2;
DrawRectangle(0, color, lineWidth, x, y, width, height);
}
private void DrawPoint2()
{
Color color = panel2.BackColor;
int lineWidth = Convert.ToInt32(nudLineWidth.Value);
int X = Convert.ToInt32(nudPoint2X.Value);
int Y = Convert.ToInt32(nudPoint2Y.Value);
int width = Convert.ToInt32(nudSide.Value);
int height = width;
int x = X - width / 2;
int y = Y - height / 2;
DrawRectangle(1, color, lineWidth, x, y, width, height);
}
private void panel1_BackColorChanged(object sender, EventArgs e)
{
DrawPoint1();
}
private void nudPoint1X_ValueChanged(object sender, EventArgs e)
{
if (m_width <= 0 || m_height <= 0)
{
return;
}
int X = Convert.ToInt32(nudPoint1X.Value);
int width = Convert.ToInt32(nudSide.Value);
if (X - width / 2 < 0)
{
nudPoint1X.Value = width / 2;
}
else if (X + width / 2 > m_width)
{
nudPoint1X.Value = (m_width - width / 2);
}
DrawPoint1();
}
private void nudPoint1Y_ValueChanged(object sender, EventArgs e)
{
if (m_width <= 0 || m_height <= 0)
{
return;
}
int Y = Convert.ToInt32(nudPoint1Y.Value);
int height = Convert.ToInt32(nudSide.Value);
if (Y - height / 2 < 0)
{
nudPoint1Y.Value = (height / 2);
}
else if (Y + height / 2 > m_height)
{
nudPoint1Y.Value = (m_height - height / 2);
}
DrawPoint1();
}
private void panel2_BackColorChanged(object sender, EventArgs e)
{
DrawPoint2();
}
private void nudLineWidth_ValueChanged(object sender, EventArgs e)
{
DrawPoint1();
DrawPoint2();
}
private void nudSide_ValueChanged(object sender, EventArgs e)
{
DrawPoint1();
DrawPoint2();
}
private void nudPoint2X_ValueChanged(object sender, EventArgs e)
{
if (m_width <= 0 || m_height <= 0)
{
return;
}
int X = Convert.ToInt32(nudPoint2X.Value);
int width = Convert.ToInt32(nudSide.Value);
if (X - width / 2 < 0)
{
nudPoint2X.Value = (width / 2);
}
else if (X + width / 2 > m_width)
{
nudPoint2X.Value = (m_width - width / 2);
}
DrawPoint2();
}
private void nudPoint2Y_ValueChanged(object sender, EventArgs e)
{
if (m_width <= 0 || m_height <= 0)
{
return;
}
int Y = Convert.ToInt32(nudPoint2Y.Value);
int height = Convert.ToInt32(nudSide.Value);
if (Y - height / 2 < 0)
{
nudPoint2Y.Value = (height / 2);
}
else if (Y + height / 2 > m_height)
{
nudPoint2Y.Value = (m_height - height / 2);
}
DrawPoint2();
}
private void btnSave_Click(object sender, EventArgs e)
{
string artworkName = txtName.Text.Trim();
if (string.IsNullOrEmpty(artworkName))
{
MessageBox.Show(PdnResources.GetString("Menu.Pleasefillisdrawing.text"));
return;
}
if (m_bitmap == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddaprocessdrawing.text"));
return;
}
if (System.IO.File.Exists(m_filePath + m_picName))
{
System.IO.File.Delete(m_filePath + m_picName);
}
if (System.IO.File.Exists(m_filePath + m_thumbnailName))
{
System.IO.File.Delete(m_filePath + m_thumbnailName);
}
if (System.IO.File.Exists(m_filePath + m_originalPicName))
{
System.IO.File.Delete(m_filePath + m_originalPicName);
}
m_bitmap.Save(m_filePath + m_originalPicName, System.Drawing.Imaging.ImageFormat.Png);
m_artwork.originalPic = m_originalPicName;
if (m_mat != null)
{
// 二值图像
Bitmap image1 = BitmapConverter.ToBitmap(m_mat);
Bitmap[] bitmaps = new Bitmap[2];
bitmaps[0] = m_bitmap;
bitmaps[1] = image1;
m_bitmap = ImageTools.Overlap(bitmaps, m_bitmap.Width, m_bitmap.Height, OverlapType.TOPLEFT);
image1.Dispose();
}
m_bitmap.Save(m_filePath + m_picName, System.Drawing.Imaging.ImageFormat.Png);
m_artwork.pic = m_picName;
Surface surface = Surface.CopyFromBitmap(m_bitmap);
surface.CreateThumbnail();
Bitmap image = surface.Thumbnail;
image.Save(m_filePath + m_thumbnailName, System.Drawing.Imaging.ImageFormat.Png);
m_artwork.thumbnail = m_thumbnailName;
m_artwork.artworkName = artworkName;
m_artwork.side = Convert.ToInt32(nudSide.Value);
m_artwork.lineWidth = Convert.ToInt32(nudLineWidth.Value);
m_artwork.point1X = Convert.ToInt32(nudPoint1X.Value);
m_artwork.point1Y = Convert.ToInt32(nudPoint1Y.Value);
m_artwork.point1Color = ColorTranslator.ToHtml(panel1.BackColor);
m_artwork.point2X = Convert.ToInt32(nudPoint2X.Value);
m_artwork.point2Y = Convert.ToInt32(nudPoint2Y.Value);
m_artwork.point2Color = ColorTranslator.ToHtml(panel2.BackColor);
m_artwork.twoValueGetMin = Convert.ToInt32(nudTowValueMin.Value);
m_artwork.twoValueGetMax = Convert.ToInt32(nudTowValueMax.Value);
m_artwork.twoValueColor = ColorTranslator.ToHtml(panel3.BackColor);
m_artwork.scrapIsDel = chkScrapIsDel.Checked;
m_artwork.scrapMin = Convert.ToInt32(nudScrapMin.Value);
m_artwork.scrapMax = Convert.ToInt32(nudScrapMax.Value);
if (m_index == -1)
{
m_artworkLists.Add(m_artwork);
}
string stageModelXml = XmlSerializeHelper.XmlSerialize(m_artworkModel);
string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ArtworkModel.xml";
if (FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create))
{
Startup.instance.artworkModel = m_artworkModel;
((ArtworkSettingDialog)m_parentForm).ArtworkListLoad();
//MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
m_bitmap.Dispose();
this.Close();
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Savefailed.text"));
}
}
private void applyButtonImpl()
{
if (m_bitmap == null)
{
return;
}
long start = Cv2.GetTickCount();
//判断是否存在视场,如果存在视场,则把视场提取出来,进行处理
if (this.m_documentWorkspace.GraphicsList.IsExsitView())
{
this.m_documentWorkspace.PhaseModels[0].mat = action.PerformProcess(
PaintDotNet.Camera.Tools.ToMat(this.m_documentWorkspace.GetFullSizeWithRegion()),
PaintDotNet.Camera.Tools.ToMat(this.m_bitmap));
this.m_documentWorkspace.PhaseModels[0].color = this.panel3.BackColor.ToArgb();
this.m_documentWorkspace.Refresh();
}
else
{
m_mat = action.PerformProcess(PaintDotNet.Camera.Tools.ToMat(this.m_bitmap));
this.m_documentWorkspace.PhaseModels[0].mat = m_mat;
this.m_documentWorkspace.PhaseModels[0].color = this.panel3.BackColor.ToArgb();
this.m_documentWorkspace.Refresh();
}
double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency();
System.Console.WriteLine("执行时间:" + time);
}
private void panel3_BackColorChanged(object sender, EventArgs e)
{
Color color = this.panel3.BackColor;
//先修改参数
foreach (Args args in action.Lists)
{
if (args.Key == "phaseColor")
{
args.Value = color.ToArgb();
break;
}
}
//改变配置文件里面的相颜色
this.binaryExtractionModel.PhaseColor = color.ToArgb();
this.applyButtonImpl();
}
private void nudTowValue_ValueChanged(object sender, EventArgs e)
{
//参数改变
foreach (Args args in action.Lists)
{
if (args.Key == "scope1")
{
((List)args.Value)[0] = (int)this.nudTowValueMin.Value;
((List)args.Value)[1] = (int)this.nudTowValueMax.Value;
break;
}
}
this.binaryExtractionModel.ColorOneStart = (int)(this.nudTowValueMin.Value);
this.binaryExtractionModel.ColorOneEnd = (int)(this.nudTowValueMax.Value);
this.applyButtonImpl();
}
///
/// 碎屑面积起始值
///
///
///
private void nudScrapMin_ValueChanged(object sender, EventArgs e)
{
nudScrapMax.Value = Math.Max(nudScrapMax.Value, nudScrapMin.Value);
//参数改变
foreach (Args args in action.Lists)
{
if (args.Key == "scope4")
{
((List)args.Value)[0] = (double)nudScrapMin.Value / unitLength / unitLength;
((List)args.Value)[1] = (double)nudScrapMax.Value / unitLength / unitLength;
break;
}
}
this.binaryExtractionModel.DebrisAreaStart = (int)((double)nudScrapMin.Value / unitLength / unitLength);
this.binaryExtractionModel.DebrisAreaEnd = (int)((double)nudScrapMax.Value / unitLength / unitLength);
this.applyButtonImpl();
}
///
/// 碎屑面积截止值
///
///
///
private void nudScrapMax_ValueChanged(object sender, EventArgs e)
{
nudScrapMin.Value = Math.Min(nudScrapMin.Value, nudScrapMax.Value);
//参数改变
foreach (Args args in action.Lists)
{
if (args.Key == "scope4")
{
((List)args.Value)[0] = (double)nudScrapMin.Value / unitLength / unitLength;
((List)args.Value)[1] = (double)nudScrapMax.Value / unitLength / unitLength;
break;
}
}
this.binaryExtractionModel.DebrisAreaStart = (int)((double)nudScrapMin.Value / unitLength / unitLength);
this.binaryExtractionModel.DebrisAreaEnd = (int)((double)nudScrapMax.Value / unitLength / unitLength);
this.applyButtonImpl();
}
private void chkScrapIsDel_CheckedChanged(object sender, EventArgs e)
{
//参数改变
foreach (Args args in action.Lists)
{
if (args.Key == "debrisRemoval")
{
args.Value = this.chkScrapIsDel.Checked;
break;
}
}
this.binaryExtractionModel.DebrisRemoval = this.chkScrapIsDel.Checked;
this.applyButtonImpl();
}
private void ArtworkSettingEditDialog_Resize(object sender, EventArgs e)
{
this.pnlTools.Left = panel4.Left + (panel4.Width - pnlTools.Width) / 2;
}
private void nudTowValueMin_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudTowValueMin.Value = Convert.ToInt32(this.nudTowValueMin.Text);
}
catch (Exception)
{
}
}
private void nudTowValueMax_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudTowValueMax.Value = Convert.ToInt32(this.nudTowValueMax.Text);
}
catch (Exception)
{
}
}
private void nudScrapMin_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudScrapMin.Value = Convert.ToInt32(this.nudScrapMin.Text);
}
catch (Exception)
{
}
}
private void nudScrapMax_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudScrapMax.Value = Convert.ToInt32(this.nudScrapMax.Text);
}
catch (Exception)
{
}
}
private void nudSide_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudSide.Value = Convert.ToInt32(this.nudSide.Text);
}
catch (Exception)
{
}
}
private void nudLineWidth_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudLineWidth.Value = Convert.ToInt32(this.nudLineWidth.Text);
}
catch (Exception)
{
}
}
private void nudPoint1X_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudPoint1X.Value = Convert.ToInt32(this.nudPoint1X.Text);
}
catch (Exception)
{
}
}
private void nudPoint1Y_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudPoint1Y.Value = Convert.ToInt32(this.nudPoint1Y.Text);
}
catch (Exception)
{
}
}
private void nudPoint2X_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudPoint2X.Value = Convert.ToInt32(this.nudPoint2X.Text);
}
catch (Exception)
{
}
}
private void nudPoint2Y_KeyUp(object sender, KeyEventArgs e)
{
try
{
nudPoint2Y.Value = Convert.ToInt32(this.nudPoint2Y.Text);
}
catch (Exception)
{
}
}
}
}