using Metis.GeneralAnalysis; using Metis.ParameterSet; using OpenCvSharp; using OpenCvSharp.Extensions; using PaintDotNet.Annotation; using PaintDotNet.Annotation.Enum; using PaintDotNet.Base; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.Enum; using PaintDotNet.Base.Functionodel; using PaintDotNet.Base.SettingModel; using PaintDotNet.CustomControl; using PaintDotNet.Data.Param; using PaintDotNet.DbOpreate.DbBll; using PaintDotNet.DbOpreate.DbModel; using PaintDotNet.Instrument; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; using static PaintDotNet.Base.Functionodel.DebrisSelectionModel; namespace PaintDotNet.GeneralAnalysis { /// /// 颗粒统计 /// internal class DebrisSelectionDialog : PdnBaseForm { #region 基础控件 private Button button1; private CheckBox checkBox1; private Button button2; private GroupBox groupBox2; private ListView listView1; private GroupBox groupBox3; private GroupBox groupBox4; private GroupBox groupBox6; private GroupBox groupBox8; private DataGridView dataGridView1; private GroupBox groupBox9; private Button button6; private Button button7; private ListView listView2; private DataGridView dataGridView2; private Button button9; private Button button8; private NumericUpDown numericUpDown1; private Label label8; private Label label9; private ImageList imageList1; private IContainer components; private GroupBox groupBox1; private Label label1; private Button button3; private Panel panel1; private ComboBox comboBox1; private CheckBox checkBox3; private CheckBox checkBox2; private CheckBox checkBox4; private Label label2; private NumericUpDown numericUpDown2; private Label label3; private Button button4; private ComboBox comboBox3; private Label label4; private DataGridView dataGridView3; private Label label5; private Label label6; private NumericUpDown numericUpDown3; private Button button5; private Label label7; private Panel panel3; private Button btn_SetUp; private ComboBox comboBox2; private Panel panel2; private void InitializeLanguageText() { this.button8.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text"); this.button7.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.button6.Text = PdnResources.GetString("Menu.Showall.text"); this.Text = PdnResources.GetString("Menu.GeneralAnalysis.ParticleStatistics.Text"); this.checkBox2.Text = PdnResources.GetString("Menu.Generalanalysis.Particlestatistics.Displaynumber.text"); this.groupBox8.Text = PdnResources.GetString("Menu.Statisticalresultspreview.text"); this.groupBox9.Text = PdnResources.GetString("Menu.Analysisresult.text"); this.button3.Text = PdnResources.GetString("Menu.Exportproject.text"); this.label8.Text = PdnResources.GetString("Menu.Decimal.text") + ":"; this.button9.Text = PdnResources.GetString("Menu.Exportresults.text"); this.label4.Text = PdnResources.GetString("Menu.Generalanalysis.Particlestatistics.Statisticalselection.text") + ":"; this.label1.Text = PdnResources.GetString("Menu.color.text") + ":"; this.label7.Text = PdnResources.GetString("Menu.color.text") + ":"; this.groupBox6.Text = PdnResources.GetString("Menu.displaysetting.text"); this.label6.Text = PdnResources.GetString("Menu.Chooseacolor.Text") + ":"; this.label5.Text = PdnResources.GetString("Menu.Fontsize.text") + ":"; this.label3.Text = PdnResources.GetString("Menu.Generalanalysis.Particlestatistics.Articledata.text"); this.checkBox4.Text = PdnResources.GetString("Menu.Generalanalysis.Particlestatistics.Beforeshowing.text"); this.label2.Text = PdnResources.GetString("Menu.Font.text") + ":"; this.checkBox3.Text = PdnResources.GetString("Menu.Generalanalysis.Particlestatistics.Displayparams.text"); this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.button2.Text = PdnResources.GetString("Menu.Saveresult.text"); this.checkBox1.Text = PdnResources.GetString("Menu.Opensettingsatingreport.text"); this.button1.Text = PdnResources.GetString("Menu.Setting.Text"); this.groupBox2.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text"); this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBox4.Text = PdnResources.GetString("Menu.Generalanalysis.Particlestatistics.Selectstatistics.text"); this.button5.Text = PdnResources.GetString("Menu.Started.text"); this.button4.Text = PdnResources.GetString("Menu.Setting.Text"); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.btn_SetUp = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.listView1 = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.button5 = new System.Windows.Forms.Button(); this.dataGridView3 = new System.Windows.Forms.DataGridView(); this.button4 = new System.Windows.Forms.Button(); this.comboBox3 = new System.Windows.Forms.ComboBox(); this.label4 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.label7 = new System.Windows.Forms.Label(); this.panel3 = new System.Windows.Forms.Panel(); this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); this.panel2 = new System.Windows.Forms.Panel(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.label2 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.groupBox8 = new System.Windows.Forms.GroupBox(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.groupBox9 = new System.Windows.Forms.GroupBox(); this.button3 = new System.Windows.Forms.Button(); this.label9 = new System.Windows.Forms.Label(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.label8 = new System.Windows.Forms.Label(); this.button9 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.dataGridView2 = new System.Windows.Forms.DataGridView(); this.listView2 = new System.Windows.Forms.ListView(); this.button7 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).BeginInit(); this.groupBox6.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); this.groupBox8.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox9.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).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.btn_SetUp); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.checkBox1); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(14, 3); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(1081, 50); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // btn_SetUp // this.btn_SetUp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.btn_SetUp.Location = new System.Drawing.Point(895, 14); this.btn_SetUp.Name = "btn_SetUp"; this.btn_SetUp.Size = new System.Drawing.Size(84, 30); this.btn_SetUp.TabIndex = 3; this.btn_SetUp.Text = "卡规设置"; this.btn_SetUp.UseVisualStyleBackColor = true; this.btn_SetUp.Click += new System.EventHandler(this.btn_SetUp_Click); // // button2 // this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.button2.Enabled = false; this.button2.Location = new System.Drawing.Point(985, 14); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(84, 30); this.button2.TabIndex = 2; this.button2.Text = "保存结果"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // checkBox1 // this.checkBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(141, 21); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(132, 16); this.checkBox1.TabIndex = 1; this.checkBox1.Text = "生成报告时打开设置"; this.checkBox1.UseVisualStyleBackColor = true; // // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.button1.Location = new System.Drawing.Point(15, 14); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(84, 30); this.button1.TabIndex = 0; this.button1.Text = "设置"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox2 // this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.groupBox2.Controls.Add(this.listView1); this.groupBox2.Location = new System.Drawing.Point(14, 60); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(135, 497); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "图像索引"; // // listView1 // this.listView1.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.listView1.HideSelection = false; this.listView1.LargeImageList = this.imageList1; this.listView1.Location = new System.Drawing.Point(5, 17); this.listView1.MultiSelect = false; this.listView1.Name = "listView1"; this.listView1.Size = new System.Drawing.Size(124, 474); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); this.listView1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseUp); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize = new System.Drawing.Size(64, 64); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // groupBox3 // this.groupBox3.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.groupBox3.Location = new System.Drawing.Point(515, 60); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(580, 496); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "预览"; // // groupBox4 // this.groupBox4.Controls.Add(this.button5); this.groupBox4.Controls.Add(this.dataGridView3); this.groupBox4.Controls.Add(this.button4); this.groupBox4.Controls.Add(this.comboBox3); this.groupBox4.Controls.Add(this.label4); this.groupBox4.Location = new System.Drawing.Point(156, 60); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(353, 179); this.groupBox4.TabIndex = 4; this.groupBox4.TabStop = false; this.groupBox4.Text = "选择统计数据"; // // button5 // this.button5.Enabled = false; this.button5.Location = new System.Drawing.Point(291, 15); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(55, 23); this.button5.TabIndex = 4; this.button5.Tag = "1"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // dataGridView3 // this.dataGridView3.AllowUserToAddRows = false; this.dataGridView3.AllowUserToDeleteRows = false; this.dataGridView3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView3.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView3.BackgroundColor = System.Drawing.Color.White; this.dataGridView3.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; this.dataGridView3.Location = new System.Drawing.Point(6, 42); this.dataGridView3.MultiSelect = false; this.dataGridView3.Name = "dataGridView3"; this.dataGridView3.RowHeadersVisible = false; this.dataGridView3.RowTemplate.Height = 23; this.dataGridView3.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView3.Size = new System.Drawing.Size(340, 131); this.dataGridView3.TabIndex = 3; this.dataGridView3.CurrentCellDirtyStateChanged += new System.EventHandler(this.dataGridView3_CurrentCellDirtyStateChanged); // // button4 // this.button4.Enabled = false; this.button4.Location = new System.Drawing.Point(230, 15); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(55, 23); this.button4.TabIndex = 2; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // comboBox3 // this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox3.FormattingEnabled = true; this.comboBox3.Location = new System.Drawing.Point(79, 16); this.comboBox3.Name = "comboBox3"; this.comboBox3.Size = new System.Drawing.Size(141, 20); this.comboBox3.TabIndex = 1; this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged); // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(18, 20); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(0, 12); this.label4.TabIndex = 0; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(240, 20); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 7; // // panel1 // this.panel1.BackColor = System.Drawing.SystemColors.ButtonHighlight; this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel1.Location = new System.Drawing.Point(293, 16); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(44, 18); this.panel1.TabIndex = 5; this.panel1.BackColorChanged += new System.EventHandler(this.panel1_BackColorChanged); this.panel1.Click += new System.EventHandler(this.panel1_Click); // // groupBox6 // this.groupBox6.Controls.Add(this.comboBox2); this.groupBox6.Controls.Add(this.label7); this.groupBox6.Controls.Add(this.panel3); this.groupBox6.Controls.Add(this.numericUpDown3); this.groupBox6.Controls.Add(this.panel2); this.groupBox6.Controls.Add(this.label6); this.groupBox6.Controls.Add(this.label5); this.groupBox6.Controls.Add(this.label3); this.groupBox6.Controls.Add(this.numericUpDown2); this.groupBox6.Controls.Add(this.checkBox4); this.groupBox6.Controls.Add(this.label2); this.groupBox6.Controls.Add(this.comboBox1); this.groupBox6.Controls.Add(this.checkBox3); this.groupBox6.Controls.Add(this.checkBox2); this.groupBox6.Controls.Add(this.label1); this.groupBox6.Controls.Add(this.panel1); this.groupBox6.Location = new System.Drawing.Point(154, 241); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(354, 132); this.groupBox6.TabIndex = 6; this.groupBox6.TabStop = false; this.groupBox6.Text = "显示设置"; // // comboBox2 // this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox2.FormattingEnabled = true; this.comboBox2.Location = new System.Drawing.Point(94, 76); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(79, 20); this.comboBox2.TabIndex = 23; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(240, 49); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(0, 12); this.label7.TabIndex = 22; // // panel3 // this.panel3.BackColor = System.Drawing.SystemColors.ButtonHighlight; this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel3.Location = new System.Drawing.Point(293, 45); this.panel3.Name = "panel3"; this.panel3.Size = new System.Drawing.Size(44, 18); this.panel3.TabIndex = 21; this.panel3.BackColorChanged += new System.EventHandler(this.panel3_BackColorChanged); this.panel3.Click += new System.EventHandler(this.panel3_Click); // // numericUpDown3 // this.numericUpDown3.Location = new System.Drawing.Point(293, 77); this.numericUpDown3.Maximum = new decimal(new int[] { 49000, 0, 0, 0}); this.numericUpDown3.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown3.Name = "numericUpDown3"; this.numericUpDown3.Size = new System.Drawing.Size(44, 21); this.numericUpDown3.TabIndex = 20; this.numericUpDown3.Value = new decimal(new int[] { 15, 0, 0, 0}); this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged); // // panel2 // this.panel2.BackColor = System.Drawing.SystemColors.ButtonHighlight; this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel2.Location = new System.Drawing.Point(293, 108); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(44, 18); this.panel2.TabIndex = 19; this.panel2.BackColorChanged += new System.EventHandler(this.panel2_BackColorChanged); this.panel2.Click += new System.EventHandler(this.panel2_Click); // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(234, 111); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(0, 12); this.label6.TabIndex = 18; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(240, 81); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(0, 12); this.label5.TabIndex = 16; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(162, 111); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(0, 12); this.label3.TabIndex = 15; // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(94, 105); this.numericUpDown2.Maximum = new decimal(new int[] { 99999, 0, 0, 0}); this.numericUpDown2.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(55, 21); this.numericUpDown2.TabIndex = 14; this.numericUpDown2.Value = new decimal(new int[] { 10, 0, 0, 0}); this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged); // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Location = new System.Drawing.Point(20, 110); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(15, 14); this.checkBox4.TabIndex = 13; this.checkBox4.UseVisualStyleBackColor = true; this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(37, 81); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(0, 12); this.label2.TabIndex = 11; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(94, 47); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(106, 20); this.comboBox1.TabIndex = 10; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // checkBox3 // this.checkBox3.AutoSize = true; this.checkBox3.Location = new System.Drawing.Point(20, 49); this.checkBox3.Name = "checkBox3"; this.checkBox3.Size = new System.Drawing.Size(15, 14); this.checkBox3.TabIndex = 9; this.checkBox3.UseVisualStyleBackColor = true; this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(20, 20); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(15, 14); this.checkBox2.TabIndex = 8; this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // // groupBox8 // this.groupBox8.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.groupBox8.Controls.Add(this.dataGridView1); this.groupBox8.Location = new System.Drawing.Point(155, 377); this.groupBox8.Name = "groupBox8"; this.groupBox8.Size = new System.Drawing.Size(353, 179); this.groupBox8.TabIndex = 8; this.groupBox8.TabStop = false; this.groupBox8.Text = "统计结果预览"; // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AllowUserToDeleteRows = false; this.dataGridView1.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.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView1.BackgroundColor = System.Drawing.Color.White; this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; this.dataGridView1.Location = new System.Drawing.Point(7, 21); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.Size = new System.Drawing.Size(340, 152); this.dataGridView1.TabIndex = 0; this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick); // // groupBox9 // this.groupBox9.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox9.Controls.Add(this.button3); this.groupBox9.Controls.Add(this.label9); this.groupBox9.Controls.Add(this.numericUpDown1); this.groupBox9.Controls.Add(this.label8); this.groupBox9.Controls.Add(this.button9); this.groupBox9.Controls.Add(this.button8); this.groupBox9.Controls.Add(this.dataGridView2); this.groupBox9.Controls.Add(this.listView2); this.groupBox9.Controls.Add(this.button7); this.groupBox9.Controls.Add(this.button6); this.groupBox9.Location = new System.Drawing.Point(14, 562); this.groupBox9.Name = "groupBox9"; this.groupBox9.Size = new System.Drawing.Size(1081, 204); this.groupBox9.TabIndex = 9; this.groupBox9.TabStop = false; this.groupBox9.Text = "分析结果"; // // button3 // this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button3.Location = new System.Drawing.Point(941, 102); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(128, 26); this.button3.TabIndex = 10; this.button3.Text = "导出项目"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // label9 // this.label9.AutoSize = true; this.label9.ForeColor = System.Drawing.SystemColors.ScrollBar; this.label9.Location = new System.Drawing.Point(210, 9); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(11, 192); this.label9.TabIndex = 8; this.label9.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|"; // // numericUpDown1 // this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.numericUpDown1.Location = new System.Drawing.Point(993, 162); this.numericUpDown1.Maximum = new decimal(new int[] { 10, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(70, 21); this.numericUpDown1.TabIndex = 7; this.numericUpDown1.Value = new decimal(new int[] { 2, 0, 0, 0}); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // label8 // this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(957, 167); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(41, 12); this.label8.TabIndex = 6; this.label8.Text = "小数:"; // // button9 // this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button9.Location = new System.Drawing.Point(941, 68); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(128, 26); this.button9.TabIndex = 5; this.button9.Text = "导出结果"; this.button9.UseVisualStyleBackColor = true; this.button9.Click += new System.EventHandler(this.button9_Click); // // button8 // this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button8.Location = new System.Drawing.Point(941, 34); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(128, 26); this.button8.TabIndex = 4; this.button8.Text = "生成报告"; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // dataGridView2 // this.dataGridView2.AllowUserToAddRows = false; this.dataGridView2.AllowUserToDeleteRows = false; this.dataGridView2.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.dataGridView2.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGridView2.BackgroundColor = System.Drawing.Color.White; this.dataGridView2.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; this.dataGridView2.Location = new System.Drawing.Point(228, 20); this.dataGridView2.MultiSelect = false; this.dataGridView2.Name = "dataGridView2"; this.dataGridView2.ReadOnly = true; this.dataGridView2.RowHeadersVisible = false; this.dataGridView2.RowTemplate.Height = 23; this.dataGridView2.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView2.Size = new System.Drawing.Size(693, 176); this.dataGridView2.TabIndex = 3; // // listView2 // this.listView2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.listView2.HideSelection = false; this.listView2.Location = new System.Drawing.Point(16, 56); this.listView2.Name = "listView2"; this.listView2.Size = new System.Drawing.Size(181, 140); this.listView2.TabIndex = 2; this.listView2.UseCompatibleStateImageBehavior = false; this.listView2.SelectedIndexChanged += new System.EventHandler(this.listView2_SelectedIndexChanged); // // button7 // this.button7.Location = new System.Drawing.Point(112, 20); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(85, 26); this.button7.TabIndex = 1; this.button7.Text = "删除"; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // button6 // this.button6.Location = new System.Drawing.Point(16, 20); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(85, 26); this.button6.TabIndex = 0; this.button6.Text = "全部显示"; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // DebrisSelectionDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(1107, 771); this.Controls.Add(this.groupBox9); this.Controls.Add(this.groupBox8); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "DebrisSelectionDialog"; this.Text = "颗粒统计"; 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.groupBox6, 0); this.Controls.SetChildIndex(this.groupBox8, 0); this.Controls.SetChildIndex(this.groupBox9, 0); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).EndInit(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.groupBox8.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.groupBox9.ResumeLayout(false); this.groupBox9.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); this.ResumeLayout(false); } #endregion private ConfigModel config = Startup.instance.configModel; /// /// 调色板 /// PaintDotNet.ColorsForm colorsForm1; /// /// 调色板 /// PaintDotNet.ColorsForm colorsForm2; /// /// 调色板 /// PaintDotNet.ColorsForm colorsForm3; /// /// 主控件 /// private AppWorkspace appWorkspace; /// /// 图像面板 /// private DocumentWorkspaceWindow documentWorkspace; /// /// 公共按钮 /// private CommonControlButtons commonControlButtons; /// /// 选中图片的mat /// private Mat imageMat; /// /// 计算结果的表格集合 /// private List resultTableList = new List(); /// /// 保存用于生成报告的图片 /// private List bitList; /// /// 储存点击保存结果后的所有原图与分析图 /// private Dictionary> bitDic = new Dictionary>(); /// /// 是否显示全部 /// private bool showAll = false; /// /// 当前图片是否有视场 /// private bool isHadView = false; /// /// 原图mat-包括视场 /// private Mat mat; /// /// 原图的灰度图 /// private Mat matGray; /// /// 二值处理后的mat,但是是多通道的 /// private Mat binarizationMat; /// /// 原始图片的分割 /// private Mat[] mats; /// /// mask /// private Mat hole; /// /// 二值图的灰度图,单通道 /// private Mat binarizationMatGray; /// /// 相的集合 /// private PhaseModel phaseModel; /// /// 单位标尺 /// private double ruleValue = 1; /// /// 颗粒统计的条件 /// public DebrisSelectionModel debrisSelectionModel; /// /// 颗粒统计的条件的xml /// public readonly string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\" + "DebrisSelectionModel.xml"; /// /// 轮廓数组 /// public OpenCvSharp.Point[][] contours; /// /// 轮廓关系 /// public HierarchyIndex[] hierarchy; /// /// 轮廓对应的类,以及数据等 /// public List list = new List(); /// /// 筛选后的结果集合 /// public List set; /// /// 筛选的下拉 /// public Dictionary listDictionary = new Dictionary(); /// /// gridView1选中的行 /// public int gridView1SelectIndex = 0; /// /// 主控件选中图片索引 /// private int defaultIndex = -1; private GeneralAnalysisModel generalAnalysisModel = new GeneralAnalysisModel(); private bool firstShow = true; private Dictionary everyImgData = new Dictionary(); private string selectedImg = string.Empty; private bool isExportResults = false; private bool isExportReports = false; private bool isExportProjects = false; private int menuId; private string menuName; /// /// 是否脚本运行 /// private Boolean initScriptValues = false; public DebrisSelectionDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) { this.appWorkspace = appWorkspace; this.menuId = menuItem.MenuId; this.menuName = menuItem.Text; InitializeComponent(); InitializeLanguageText(); InitGridHeader(); InitPicList(); InitOtherTools(); InitCommonButtonEvent(); RefreshDebrisComboBox(); SetAnalyzeModelFromXml("Template.Manager.item2.ParticleStatistics"); } /// /// 初始化其他控件 /// private void InitOtherTools() { // //初始化图像控件 // this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace); this.documentWorkspace.Dock = DockStyle.Fill; this.documentWorkspace.HookMouseEvents(); this.documentWorkspace.AuxiliaryLineEnabled = false; this.documentWorkspace.Visible = false; this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.NullTool; this.groupBox3.Controls.Add(documentWorkspace); // //初始化操作按钮 // this.commonControlButtons = new CommonControlButtons(); this.commonControlButtons.Dock = DockStyle.Top; this.commonControlButtons.Height = 30; this.commonControlButtons.HideZoomToWindowAndActualSize(); this.groupBox3.Controls.Add(commonControlButtons); // //调色板 // this.colorsForm1 = new ColorsForm(); this.colorsForm1.StartPosition = FormStartPosition.CenterScreen; this.colorsForm1.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); // //调色板 // this.colorsForm2 = new ColorsForm(); this.colorsForm2.StartPosition = FormStartPosition.CenterScreen; this.colorsForm2.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); // //调色板 // this.colorsForm3 = new ColorsForm(); this.colorsForm3.StartPosition = FormStartPosition.CenterScreen; this.colorsForm3.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); // //颜色panel给定初始值 // this.panel1.BackColor = Color.Black; // //颜色pane2给定初始值 // this.panel2.BackColor = Color.Red; // //颜色pane3给定初始值 // this.panel3.BackColor = Color.Green; // //绑定字体下拉 // ArrayList fontsItems = new ArrayList(); System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection(); foreach (FontFamily fontFamily in fonts.Families) { fontsItems.Add(fontFamily.Name); } this.comboBox2.DataSource = fontsItems; this.comboBox2.Text = PdnResources.GetString("Menu.Songtypeface.Text"); //// ////获取系统标尺-微米 //// //this.appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength); // //获取xml存储数据 // //this.debrisSelectionModel = new DebrisSelectionModel(); ReloadDebrisSelectionFromXml(); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.saveLastData); } /// /// 初始化图片列表数据 /// public void InitPicList() { //初始化图片列表 for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++) { this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail); this.listView1.Items.Add("", i); this.listView1.Items[i].ImageIndex = i; this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace)) { defaultIndex = i; } } this.Shown += ShowImgEvent; } private void ShowImgEvent(object sender, EventArgs e) { listView1.Focus(); if (this.defaultIndex != -1) { this.listView1.Items[defaultIndex].Focused = true; this.listView1.Items[defaultIndex].Selected = true; //如果是脚本执行,将参数带入 if (appWorkspace.ScriptRunning && appWorkspace.ScriptCurrentParam != null) { this.initScriptValues = true;//ScriptAutomatic //Boolean initScriptValues = true; ////在这里反射出对应功能的参数类 string className = InvariantData.path_Action + ".Action" + menuId; ParamObject param = (ParamObject)System.Reflection.Assembly.Load(InvariantData.assembly_Data).CreateInstance(className); foreach (Args arg in param.Lists) { Args param1 = appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key)); if (param1.value != null) { arg.Value = param1.value; getValue(arg.key, arg.Value); if (arg.choiseList != null && arg.choiseList.Count > 0) { try { int index = Convert.ToInt32(arg.value); var thisArg = arg.choiseList[index]; foreach (var item in thisArg.lists) { Args thisParam = appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(item.Key)); if (thisParam != null) { item.Value = thisParam.value; getValue(item.key, item.Value); } } } catch (Exception) { continue; } } } } appWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数 } else {//读取上次关闭窗口时保存的参数 getLastData(); } this.firstShow = false; if (this.initScriptValues && this.appWorkspace.ScriptAutomatic) this.startScriptAutomaticAction(); } } /// /// 获取上次操作参数 /// private void getLastData() { string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml"; if (!System.IO.File.Exists(filePath)) { generalAnalysisModel = new GeneralAnalysisModel(); generalAnalysisModel.PolyphaseMutiAreaContentModels = new GeneralAnalysisModel.PolyphaseMutiAreaContentModel(); generalAnalysisModel.PolyphaseCounterAnalysisModels = new GeneralAnalysisModel.PolyphaseCounterAnalysisModel(); generalAnalysisModel.TwoPhaseScaleModels = new GeneralAnalysisModel.TwoPhaseScaleModel(); generalAnalysisModel.PolyphaseContentModels = new GeneralAnalysisModel.PolyphaseContentModel(); generalAnalysisModel.PolyphaseDistanceModels = new GeneralAnalysisModel.PolyphaseDistanceModel(); generalAnalysisModel.DebrisSelectionModels = new GeneralAnalysisModel.DebrisSelectionModel(); generalAnalysisModel.CountNumberAnalysisModels = new GeneralAnalysisModel.CountNumberAnalysisModel(); generalAnalysisModel.PolyphaseMutiAreaContentModels.hasUsed = false; generalAnalysisModel.PolyphaseCounterAnalysisModels.hasUsed = false; generalAnalysisModel.TwoPhaseScaleModels.hasUsed = false; generalAnalysisModel.PolyphaseContentModels.hasUsed = false; generalAnalysisModel.PolyphaseDistanceModels.hasUsed = false; generalAnalysisModel.DebrisSelectionModels.hasUsed = false; generalAnalysisModel.CountNumberAnalysisModels.hasUsed = false; string porosityInfoXml = XmlSerializeHelper.XmlSerialize(generalAnalysisModel); Directory.CreateDirectory(Application.StartupPath + "\\Config\\Default\\ParameterSaving\\"); FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.CreateNew); } else { generalAnalysisModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); if (generalAnalysisModel.DebrisSelectionModels == null) { generalAnalysisModel.DebrisSelectionModels = new GeneralAnalysisModel.DebrisSelectionModel(); } if (generalAnalysisModel.DebrisSelectionModels.hasUsed) { if (generalAnalysisModel.DebrisSelectionModels.parameter1 != -1 && generalAnalysisModel.DebrisSelectionModels.parameter1 <= comboBox1.Items.Count - 1) { comboBox3.SelectedIndex = generalAnalysisModel.DebrisSelectionModels.parameter1; } //foreach (var item in generalAnalysisModel.DebrisSelectionModels.parameter2) //{ // dataGridView3.Rows.Add(item.name, item.analyzingConditions, item.conditionsNum, item.associationCondition); //} checkBox2.Checked = generalAnalysisModel.DebrisSelectionModels.parameter3; panel1.BackColor = Color.FromArgb(generalAnalysisModel.DebrisSelectionModels.parameter4); checkBox3.Checked = generalAnalysisModel.DebrisSelectionModels.parameter5; if (generalAnalysisModel.DebrisSelectionModels.parameter6 != -1 && generalAnalysisModel.DebrisSelectionModels.parameter6 <= comboBox1.Items.Count - 1) { comboBox1.SelectedIndex = generalAnalysisModel.DebrisSelectionModels.parameter6; } panel3.BackColor = Color.FromArgb(generalAnalysisModel.DebrisSelectionModels.parameter7); if (generalAnalysisModel.DebrisSelectionModels.parameter8 != -1) { comboBox2.SelectedIndex = generalAnalysisModel.DebrisSelectionModels.parameter8; } numericUpDown3.Value = generalAnalysisModel.DebrisSelectionModels.parameter9; checkBox4.Checked = generalAnalysisModel.DebrisSelectionModels.parameter10; numericUpDown2.Value = generalAnalysisModel.DebrisSelectionModels.parameter11; panel2.BackColor = Color.FromArgb(generalAnalysisModel.DebrisSelectionModels.parameter12); numericUpDown1.Value = generalAnalysisModel.DebrisSelectionModels.parameter13; checkBox1.Checked = generalAnalysisModel.DebrisSelectionModels.parameter14; for (int i = 0; i < listView1.Items.Count; i++) { if (everyImgData.ContainsKey(listView1.Items[i].Name)) { everyImgData[listView1.Items[i].Name] = generalAnalysisModel.DebrisSelectionModels; } else { everyImgData.Add(listView1.Items[i].Name, generalAnalysisModel.DebrisSelectionModels); } } } } } /// /// 保存上次操作参数 /// private void saveLastData(object sender, EventArgs e) { #region [开启脚本录制] if (appWorkspace.startScriptRecording) { getScriptRecording(); } #endregion if (generalAnalysisModel.DebrisSelectionModels == null) { generalAnalysisModel.DebrisSelectionModels = new GeneralAnalysisModel.DebrisSelectionModel(); } generalAnalysisModel.DebrisSelectionModels.hasUsed = true; //generalAnalysisModel.DebrisSelectionModels.parameter2.Clear(); //for (int i = 0;i < dataGridView3.Rows.Count;i++) //{ // var dataList = new GeneralAnalysisModel.DebrisSelectionModel.DataList(); // dataList.name = dataGridView3.Rows[i].Cells[0].Value.ToString(); // dataList.analyzingConditions = dataGridView3.Rows[i].Cells[1].Value.ToString(); // dataList.conditionsNum = dataGridView3.Rows[i].Cells[2].Value.ToString(); // dataList.associationCondition = dataGridView3.Rows[i].Cells[3].Value.ToString(); // generalAnalysisModel.DebrisSelectionModels.parameter2.Add(dataList); //} generalAnalysisModel.DebrisSelectionModels.parameter3 = checkBox2.Checked; generalAnalysisModel.DebrisSelectionModels.parameter4 = panel1.BackColor.ToArgb(); generalAnalysisModel.DebrisSelectionModels.parameter5 = checkBox3.Checked; generalAnalysisModel.DebrisSelectionModels.parameter1 = comboBox3.SelectedIndex; generalAnalysisModel.DebrisSelectionModels.parameter6 = comboBox1.SelectedIndex; generalAnalysisModel.DebrisSelectionModels.parameter8 = comboBox2.SelectedIndex; generalAnalysisModel.DebrisSelectionModels.parameter7 = panel3.BackColor.ToArgb(); generalAnalysisModel.DebrisSelectionModels.parameter9 = (int)numericUpDown3.Value; generalAnalysisModel.DebrisSelectionModels.parameter10 = checkBox4.Checked; generalAnalysisModel.DebrisSelectionModels.parameter11 = (int)numericUpDown2.Value; generalAnalysisModel.DebrisSelectionModels.parameter12 = panel2.BackColor.ToArgb(); generalAnalysisModel.DebrisSelectionModels.parameter13 = (int)numericUpDown1.Value; generalAnalysisModel.DebrisSelectionModels.parameter14 = checkBox1.Checked; string filePath = Application.StartupPath + "\\Config\\Default\\ParameterSaving\\ParameterGeneralAnalysis.xml"; string porosityInfoXml = XmlSerializeHelper.XmlSerialize(generalAnalysisModel); FileOperationHelper.WriteStringToFile(porosityInfoXml, filePath, FileMode.Create); } /// /// 初始化表头 /// private void InitGridHeader() { // //选择统计数据表 // this.dataGridView3.ColumnHeadersHeight = 35; DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn(); h1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h1.Width = 84; DataGridViewTextBoxColumn h2 = new DataGridViewTextBoxColumn(); h2.Width = 84; DataGridViewTextBoxColumn h3 = new DataGridViewTextBoxColumn(); h3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h3.Width = 84; DataGridViewTextBoxColumn h4 = new DataGridViewTextBoxColumn(); h4.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h4.Width = 84; this.dataGridView3.Columns.Add(h1); this.dataGridView3.Columns.Add(h2); this.dataGridView3.Columns.Add(h3); this.dataGridView3.Columns.Add(h4); DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView3); helper.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.projectname.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, PdnResources.GetString("Menu.judgementconditions.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, PdnResources.GetString("Menu.Conditionvalue.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(3, 1, PdnResources.GetString("Menu.associatedcondition.text"))); this.dataGridView3.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[0].ReadOnly = true; this.dataGridView3.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//文字居中 this.dataGridView3.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[1].ReadOnly = true; this.dataGridView3.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView3.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView3.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[3].ReadOnly = true; this.dataGridView3.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView3.AllowUserToResizeRows = false; this.dataGridView3.AllowUserToResizeColumns = false; // //统计结果预览表 // this.dataGridView1.ColumnHeadersHeight = 30; this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.AllowUserToResizeColumns = false; // //分析结果表 // this.dataGridView2.ColumnHeadersHeight = 30; this.dataGridView2.AllowUserToResizeRows = false; this.dataGridView2.AllowUserToResizeColumns = false; // //左下表 // this.listView2.View = View.Details; ColumnHeader header0 = new ColumnHeader(); header0.Text = PdnResources.GetString("Menu.Imagelist.Text"); header0.Width = 175; this.listView2.Columns.Add(header0); } /// /// 重新加载xml中已经配置好的条件 /// public void ReloadDebrisSelectionFromXml() { if (System.IO.File.Exists(filePath)) { this.debrisSelectionModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); this.listView1_SelectedIndexChanged(null, null); } } /// /// 刷新统计选择的下拉框 /// public void RefreshDebrisComboBox() { this.comboBox3.DataSource = null; if (this.debrisSelectionModel != null && this.debrisSelectionModel.debrisSelectionList.Count > 0) { int selectedIndex = -1; if (this.comboBox3.SelectedIndex > -1)//获取上次选中的下标 selectedIndex = this.comboBox3.SelectedIndex; string[] dataSourceArr = new string[this.debrisSelectionModel.debrisSelectionList.Count]; for (int i = 0; i < this.debrisSelectionModel.debrisSelectionList.Count; i++) { dataSourceArr[i] = this.debrisSelectionModel.debrisSelectionList[i].itemName; } this.comboBox3.DataSource = dataSourceArr; if (selectedIndex != -1) this.comboBox3.SelectedIndex = selectedIndex; else this.comboBox3.SelectedIndex = 0; this.RefreshDebirsDataGrid(); this.listView1_SelectedIndexChanged(null, null); } } /// /// 刷新统计数据表 /// private void RefreshDebirsDataGrid() { this.dataGridView3.Rows.Clear(); this.dataGridView1.Rows.Clear(); this.dataGridView1.Columns.Clear(); if (this.comboBox3.SelectedIndex > -1 && this.debrisSelectionModel != null && this.debrisSelectionModel.debrisSelectionList.Count > 0) { DebrisSelectionModel.DebrisSelection model = this.debrisSelectionModel.debrisSelectionList.Find(a => a.itemName.Equals(this.comboBox3.SelectedValue.ToString())); if (model != null && model.conditionList.Count > 0) { DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1); RefreshResultViewDataGrid(null, 1, 0, helper, PdnResources.GetString("Menu.Particlenumber.Text")); listDictionary.Clear(); for (int i = 0; i < model.conditionList.Count; i++) { DebrisSelectionParameters parameter = (DebrisSelectionParameters)Enum.Parse(typeof(DebrisSelectionParameters), model.conditionList[i].conditionName); object paraName = new object(); InvariantData.debrisSelectionparameters.TryGetValue(parameter, out paraName); if (!listDictionary.ContainsKey(parameter)) { listDictionary.Add(parameter, paraName.ToString()); } else { continue; } DataGridViewRow row = new DataGridViewRow(); row.Height = 25; row.Cells.Add(CreateTextBoxCell(paraName.ToString(), model.conditionList[i].conditionName)); row.Cells.Add(CreateTextBoxCell(InvariantData.judgeCondition[model.conditionList[i].judgeCondition], model.conditionList[i].judgeCondition)); row.Cells.Add(CreateTextBoxCell(model.conditionList[i].conditionNum.ToString(), "")); row.Cells.Add(CreateTextBoxCell(InvariantData.joinCondition[model.conditionList[i].joinCondition], model.conditionList[i].joinCondition)); this.dataGridView3.Rows.Add(row); RefreshResultViewDataGrid(model.conditionList[i], model.conditionList.Count, i + 1, helper, paraName.ToString()); } RefreshParameterList(); this.dataGridView3.ClearSelection(); this.dataGridView1.ClearSelection(); } } //this.AutoSizeColumn(this.dataGridView1, 20); } /// /// 刷新结果预览表 /// /// /// /// /// /// private void RefreshResultViewDataGrid(DebrisSelectionModel.Condition model, int count, int nowNum, DataGridViewHelper helper, string itemName) { if (count > 0) { int columnWidth = 0; switch (count) { case 1: columnWidth = 336; break; case 2: columnWidth = 168; break; case 3: columnWidth = 112; break; default: columnWidth = 84; break; } DataGridViewTextBoxColumn tbColumn = new DataGridViewTextBoxColumn(); //if (nowNum != 0) tbColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; tbColumn.SortMode = DataGridViewColumnSortMode.Automatic; if (nowNum == 0) { tbColumn.Width = 70; } else { tbColumn.Width = columnWidth; } tbColumn.ValueType = typeof(double); this.dataGridView1.Columns.Add(tbColumn); helper.Headers.Add(new DataGridViewHelper.TopHeader(nowNum, 1, itemName)); } } /// /// 刷新显示参数列表 /// /// private void RefreshParameterList() { BindingSource bs = new BindingSource(); bs.DataSource = listDictionary; this.comboBox1.DataSource = null; this.comboBox1.DataSource = bs; this.comboBox1.DisplayMember = "value"; this.comboBox1.ValueMember = "key"; } /// /// 初始化画布按键功能 /// private void InitCommonButtonEvent() { this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click); this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click); this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click); this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click); this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click); this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click); } private void zoomInButton_Click(object sender, EventArgs e) { if (this.imageMat != null) this.documentWorkspace.ZoomIn(); } private void zoomOutButton_Click(object sender, EventArgs e) { if (this.imageMat != null) this.documentWorkspace.ZoomOut(); } private void zoomToWindowButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; } private void actualSizeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor; this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne; } private void pointerButton_Click(object sender, EventArgs e) { // this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer; } private void mobileModeButton_Click(object sender, EventArgs e) { this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode; } /// /// 调色板回调函数 /// /// /// private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce) { } /// /// 添加内容单元格 /// /// /// /// private DataGridViewTextBoxCell CreateTextBoxCell(object text, object tag) { DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell(); textboxcell.Value = text; textboxcell.Tag = tag; return textboxcell; } /// /// 设置按钮 /// /// /// private void button1_Click(object sender, EventArgs e) { AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, "Template.Manager.item2.ParticleStatistics"); if (metallographicMethodSetDialog.hasModule) { metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen; metallographicMethodSetDialog.ShowDialog(); } else { metallographicMethodSetDialog = null; } } /// /// 保存结果按钮 /// /// /// private void button2_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName(); string tag = this.imageList1.Images.Keys[this.listView1.SelectedItems[0].Index]; bool replace = false; int rowIndex = 0; if (this.dataGridView1.Rows.Count > 0) { if (this.listView2.Items.Count > 0) { foreach (ListViewItem item in this.listView2.Items) { if (item.Name.Equals(tag)) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theanalysisreertoreplaceit.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { replace = true; } else { return; } break; } } } //有重名需要替换 if (replace) { for (int ik = 0; ik < this.resultTableList.Count; ik++) { if (this.resultTableList[ik].TableName.Equals(tag)) { rowIndex = ik; this.resultTableList.Remove(this.resultTableList[ik]); DataTable dt = new DataTable(tag); DebrisSelectionModel.DebrisSelection model = this.debrisSelectionModel.debrisSelectionList.Find(a => a.itemName.Equals(this.comboBox3.SelectedValue.ToString())); if (model != null && model.conditionList.Count > 0) { dt.Columns.Add(new DataColumn(PdnResources.GetString("Menu.Generalanalysis.Twportion.imagename.text"), typeof(string))); dt.Columns.Add(new DataColumn(PdnResources.GetString("Menu.Particlenumber.Text"), typeof(string))); //DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1); listDictionary.Clear(); for (int i = 0; i < model.conditionList.Count; i++) { DebrisSelectionParameters parameter = (DebrisSelectionParameters)Enum.Parse(typeof(DebrisSelectionParameters), model.conditionList[i].conditionName); object paraName = new object(); InvariantData.debrisSelectionparameters.TryGetValue(parameter, out paraName); if (!listDictionary.ContainsKey(parameter)) { listDictionary.Add(parameter, paraName.ToString()); } else { continue; } dt.Columns.Add(new DataColumn(paraName.ToString(), typeof(string))); } } for (int f = 0; f < this.dataGridView1.Rows.Count; f++) { if (this.dataGridView1.Rows[f].Visible) { DataRow dataRow = dt.NewRow(); dataRow[PdnResources.GetString("Menu.Generalanalysis.Twportion.imagename.text")] = imgName; for (int j = 1; j < dt.Columns.Count; j++) { dataRow[dt.Columns[j].ColumnName] = ((DataGridViewTextBoxCell)this.dataGridView1.Rows[f].Cells[j - 1]).Tag.ToString(); } dt.Rows.Add(dataRow); } } resultTableList.Insert(rowIndex, dt); } } } //新增 else { ListViewItem listViewItem = new ListViewItem(); listViewItem.Name = tag; listViewItem.SubItems[0].Text = imgName; this.listView2.Items.Add(listViewItem); this.listView2.SelectedItems.Clear(); this.listView2.Items[this.listView2.Items.Count - 1].Selected = true; DataTable dt = new DataTable(tag); DebrisSelectionModel.DebrisSelection model = this.debrisSelectionModel.debrisSelectionList.Find(a => a.itemName.Equals(this.comboBox3.SelectedValue.ToString())); if (model != null && model.conditionList.Count > 0) { dt.Columns.Add(new DataColumn(PdnResources.GetString("Menu.Generalanalysis.Twportion.imagename.text"), typeof(string))); dt.Columns.Add(new DataColumn(PdnResources.GetString("Menu.Particlenumber.Text"), typeof(string))); //DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1); listDictionary.Clear(); for (int i = 0; i < model.conditionList.Count; i++) { DebrisSelectionParameters parameter = (DebrisSelectionParameters)Enum.Parse(typeof(DebrisSelectionParameters), model.conditionList[i].conditionName); object paraName = new object(); InvariantData.debrisSelectionparameters.TryGetValue(parameter, out paraName); if (!listDictionary.ContainsKey(parameter)) { listDictionary.Add(parameter, paraName.ToString()); } else { continue; } dt.Columns.Add(new DataColumn(paraName.ToString(), typeof(string))); } } for (int f = 0; f < this.dataGridView1.Rows.Count; f++) { if (this.dataGridView1.Rows[f].Visible) { DataRow dataRow = dt.NewRow(); dataRow[PdnResources.GetString("Menu.Generalanalysis.Twportion.imagename.text")] = imgName; for (int j = 1; j < dt.Columns.Count; j++) { dataRow[dt.Columns[j].ColumnName] = ((DataGridViewTextBoxCell)this.dataGridView1.Rows[f].Cells[j - 1]).Tag.ToString(); } dt.Rows.Add(dataRow); } } resultTableList.Add(dt); } RefreshDataGridView2(); //保存处理后的图片 double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数 List tempBit = new List(); Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); originalBit.Tag = pantographRatio; tempBit.Add(originalBit); Bitmap processedBit = BitmapConverter.ToBitmap(phaseModel.mat); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); graphics.DrawImage(processedBit, new PointF(0, 0)); newBit.Tag = pantographRatio; tempBit.Add(newBit); if (bitDic.ContainsKey(tag)) bitDic[tag] = tempBit; else bitDic.Add(tag, tempBit); } else { MessageBox.Show(PdnResources.GetString("Menu.Noinformationtosave.text")); } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapictaurefirst.Text")); } } /// /// 刷新分析结果表 /// private void RefreshDataGridView2() { this.dataGridView2.Columns.Clear(); this.dataGridView2.Rows.Clear(); if (this.showAll) { if (this.resultTableList.Count > 0) { int k = 0; int kk = 0; foreach (DataTable dt in resultTableList) { if (kk == 0) { for (int ii = 0; ii < dt.Columns.Count; ii++) { DataGridViewTextBoxColumn tbColumn = new DataGridViewTextBoxColumn(); tbColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; //tbColumn.Width = 250; tbColumn.HeaderText = dt.Columns[ii].ColumnName; tbColumn.ValueType = typeof(double); this.dataGridView2.Columns.Add(tbColumn); } } this.dataGridView2.Rows.Add(dt.Rows.Count);//增加同等数量的行数 foreach (DataRow row in dt.Rows)//逐个读取单元格的内容; { DataGridViewRow r1 = dataGridView2.Rows[k]; //r1.Cells[0].Value = row.RowState.ToString(); for (int j = 0; j < dt.Columns.Count; j++) { if (j > 0) { r1.Cells[j].Value = Math.Round(double.Parse(row[j].ToString()), (int)this.numericUpDown1.Value); } else { r1.Cells[j].Value = row[j].ToString(); } } k++; } kk++; } } } else { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { int k = 0; for (int i = 0; i < this.listView2.SelectedItems.Count; i++) { string tableName = this.listView2.SelectedItems[i].Name; foreach (DataTable dt in resultTableList) { if (dt.TableName.Equals(tableName)) { if (i == 0) { for (int ii = 0; ii < dt.Columns.Count; ii++) { DataGridViewTextBoxColumn tbColumn = new DataGridViewTextBoxColumn(); tbColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; //tbColumn.Width = 250; tbColumn.HeaderText = dt.Columns[ii].ColumnName; tbColumn.ValueType = typeof(double); this.dataGridView2.Columns.Add(tbColumn); } } this.dataGridView2.Rows.Add(dt.Rows.Count);//增加同等数量的行数 foreach (DataRow row in dt.Rows)//逐个读取单元格的内容; { DataGridViewRow r1 = dataGridView2.Rows[k]; //r1.Cells[0].Value = row.RowState.ToString(); for (int j = 0; j < dt.Columns.Count; j++) { if (j > 0) { r1.Cells[j].Value = Math.Round(double.Parse(row[j].ToString()), (int)this.numericUpDown1.Value); } else { r1.Cells[j].Value = row[j].ToString(); } } k++; } } } } } } this.AutoSizeColumn(this.dataGridView2, 20); } /// /// 全部显示按钮 /// /// /// private void button6_Click(object sender, EventArgs e) { if (this.button6.Text == PdnResources.GetString("Menu.Showall.text")) { this.button6.Text = PdnResources.GetString("Menu.Cancelshowall.text"); this.showAll = true; RefreshDataGridView2(); } else if (this.button6.Text == PdnResources.GetString("Menu.Cancelshowall.text")) { this.button6.Text = PdnResources.GetString("Menu.Showall.text"); this.showAll = false; RefreshDataGridView2(); } } /// /// 删除按钮 /// /// /// private void button7_Click(object sender, EventArgs e) { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Determineallanalysisrlete.text") + "?", PdnResources.GetString("Menu.alert.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { for (int i = 0; i < this.listView2.SelectedItems.Count; i++) { string tableName = this.listView2.SelectedItems[i].Name; foreach (DataTable dt in resultTableList) { if (dt.TableName.Equals(tableName)) { resultTableList.Remove(dt); break; } } if (bitDic.ContainsKey(tableName)) bitDic.Remove(tableName); } foreach (ListViewItem item in this.listView2.Items) { if (item.Selected) this.listView2.Items.Remove(item); } RefreshDataGridView2(); } } } private bool ExistInSelectItems(string tablename) { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { for (int i = 0; i < this.listView2.SelectedItems.Count; i++) { if (this.listView2.SelectedItems[i].Name.Equals(tablename)) { return true; } } } return false; } /// /// 生成报告按钮 /// /// /// private void button8_Click(object sender, EventArgs e) { if (this.checkBox1.Checked) this.button1.PerformClick(); if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { //获取word书签与excel单元格的关系,以字典方式存储 List mic_module_infos = mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify); Dictionary tagInfos = new Dictionary(); if (mic_module_infos != null && mic_module_infos.Count > 0) { foreach (mic_module_infos info in mic_module_infos) { tagInfos.Add(info.tag_name, info.cell_position); } } //分析结果 List> analysisContent = new List>(); if (this.listView2.Items != null && this.listView2.Items.Count > 0) { int k = 0; int kk = 0; foreach (DataTable dt in resultTableList) { if (kk == 0) { List contentHead = new List(); for (int ii = 0; ii < dt.Columns.Count; ii++) { contentHead.Add(dt.Columns[ii].ColumnName); } analysisContent.Add(contentHead); kk++; } //如果不是显示全部 if (!this.showAll) { if (!ExistInSelectItems(dt.TableName)) continue; } foreach (DataRow row in dt.Rows)//逐个读取单元格的内容; { List content = new List(); for (int j = 0; j < dt.Columns.Count; j++) { if (j > 0) { content.Add(Math.Round(double.Parse(row[j].ToString()), (int)this.numericUpDown1.Value).ToString()); } else { content.Add(row[j].ToString()); } } analysisContent.Add(content); k++; } } } //图片 bitList = new List(); if (this.showAll) { foreach (KeyValuePair> kv in this.bitDic) { bitList.Add(kv.Value[0]); bitList.Add(kv.Value[1]); } } else { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { foreach (ListViewItem item in this.listView2.SelectedItems) { if (bitDic.ContainsKey(item.Name)) { bitList.Add(bitDic[item.Name][0]); bitList.Add(bitDic[item.Name][1]); } } } } if (config.calipersSetModel != null && config.calipersSetModel.isExport == 1) CreateCalipersDataTable(); pNames = new Dictionary(); string dictPath = Application.StartupPath + "\\temp"; if (!System.IO.Directory.Exists(dictPath)) System.IO.Directory.CreateDirectory(dictPath); DeleteFolder(dictPath); string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName(); this.SaveAllImage(bitList, dictPath, 1, 1, imgName); this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos, dictPath, pNames); } else MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text") + "!"); } Dictionary pNames; /// /// 保存图片到本地 /// /// private void SaveAllImage(List bitList, string newPath, int originNum, int codeNum, string pName) { if (bitList != null && bitList.Count > 0) { for (int i = 0; i < bitList.Count; i++) { string bitPath = ""; //分别为原图和处理后的图命名 if (i % 2 == 0) { bitPath = newPath + "/" + "origin" + originNum + ".jpg"; pNames.Add("origin" + originNum, pName); } else { bitPath = newPath + "/" + codeNum + ".jpg"; pNames.Add(codeNum.ToString(), pName); } bitList[i].Save(bitPath); } } } public void DeleteFolder(string path) { foreach (string d in Directory.GetFileSystemEntries(path)) { if (System.IO.File.Exists(d)) { FileInfo fi = new FileInfo(d); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) fi.Attributes = FileAttributes.Normal; System.IO.File.Delete(d);//直接删除其中的文件 } else { DirectoryInfo d1 = new DirectoryInfo(d); if (d1.GetFiles().Length != 0) { DeleteFolder(d1.FullName); } Directory.Delete(d); } } } /// /// 导出结果按钮 /// /// /// private void button9_Click(object sender, EventArgs e) { if (this.dataGridView2.Rows.Count > 0) { SaveFileDialog exe = new SaveFileDialog(); exe.Filter = "Execl files (*.xlsx)|*.xlsx"; exe.FilterIndex = 0; exe.RestoreDirectory = true; exe.Title = "Export Excel File"; exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); exe.FileName = PdnResources.GetString("Menu.GeneralAnalysis.ParticleStatistics.Text") + PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddHHmmss"); DialogResult dr = exe.ShowDialog(); if (dr == DialogResult.OK) { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { List list = new List(); if (!this.showAll) { foreach (DataTable dtb in resultTableList) { if (!ExistInSelectItems(dtb.TableName)) { continue; } for (int j = 0; j < dtb.Rows.Count; j++) { for (int k = 1; k < dtb.Columns.Count; k++) { dtb.Rows[j][k] = Math.Round(double.Parse(dtb.Rows[j][k].ToString()), (int)this.numericUpDown1.Value); } } list.Add(dtb); } } else { list = resultTableList; } this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true); } else { MessageBox.Show(PdnResources.GetString("Menu.Selecttheresultstoexport.Text")); return; } } } else { MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text") + "!"); } } /// /// 图像索引切换选中事件 /// /// /// private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected) { ruleValue = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron); this.gridView1SelectIndex = 0; if (!string.IsNullOrEmpty(this.selectedImg)) { #region [保存参数] var model = new GeneralAnalysisModel.DebrisSelectionModel(); model.parameter3 = checkBox2.Checked; model.parameter4 = panel1.BackColor.ToArgb(); model.parameter5 = checkBox3.Checked; model.parameter1 = comboBox3.SelectedIndex; model.parameter6 = comboBox1.SelectedIndex; model.parameter8 = comboBox2.SelectedIndex; model.parameter7 = panel3.BackColor.ToArgb(); model.parameter9 = (int)numericUpDown3.Value; model.parameter10 = checkBox4.Checked; model.parameter11 = (int)numericUpDown2.Value; model.parameter12 = panel2.BackColor.ToArgb(); model.parameter13 = (int)numericUpDown1.Value; model.parameter14 = checkBox1.Checked; if (everyImgData.ContainsKey(this.selectedImg)) { everyImgData[this.selectedImg] = model; } else { everyImgData.Add(this.selectedImg, model); } #endregion } this.imageMat = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreatedAliasedMat(); Document document = Document.FromImageMat(imageMat.Clone()); this.documentWorkspace.Document = document; this.documentWorkspace.phaseModels.Clear(); this.phaseModel = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].AnalysisPhaseModel; this.documentWorkspace.phaseModels.Add(phaseModel); //获得视场并绘制 List drawObject = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.GetDrawClassList(DrawClass.View); if (drawObject != null && drawObject.Count > 0) { isHadView = true; foreach (DrawObject dObject in drawObject) { dObject.Selected = false; this.documentWorkspace.GraphicsList.Add(dObject); } } else { isHadView = false; this.documentWorkspace.GraphicsList.DeleteAllView(); } this.documentWorkspace.Visible = true; this.commonControlButtons.Visible = true; //获得图像对应的mat if (isHadView) this.mat = PaintDotNet.Camera.Tools.ToMat(this.documentWorkspace.GetFullSizeWithRegion());//获取视场对应的mat //}//待测试 else this.mat = this.imageMat.Clone(); if (this.set != null) this.set.Clear(); if (phaseModel != null && phaseModel.mat != null) { if (int.Parse(this.button5.Tag.ToString()) == 1) { this.button4.Enabled = true; } this.button5.Enabled = true; this.binarizationMat = phaseModel.mat; this.FindContourAndCalc(); this.FilterParticlesByCondition(); this.DrawConditionMat(); this.CreateDataGridViewData(); if (this.checkBox4.Checked) { for (int i = this.dataGridView1.Rows.Count - 1; i > (this.numericUpDown2.Value - 1); i--) { this.dataGridView1.Rows[i].Visible = false; } } } else { this.binarizationMat = null; this.dataGridView1.Rows.Clear(); this.button4.Enabled = false; this.button5.Enabled = false; if (this.firstShow) { return; } MessageBox.Show(PdnResources.GetString("Menu.Theselectotbeperformed.text")); } #region [设置参数] this.selectedImg = this.listView1.FocusedItem.Name; if (everyImgData.ContainsKey(this.selectedImg)) { var thisModel = everyImgData[this.selectedImg]; if (thisModel.parameter1 != -1 && thisModel.parameter6 <= comboBox1.Items.Count - 1) { comboBox3.SelectedIndex = thisModel.parameter1; } checkBox2.Checked = thisModel.parameter3; panel1.BackColor = Color.FromArgb(thisModel.parameter4); checkBox3.Checked = thisModel.parameter5; if (thisModel.parameter6 != -1 && thisModel.parameter6 <= comboBox1.Items.Count - 1) { comboBox1.SelectedIndex = thisModel.parameter6; } panel3.BackColor = Color.FromArgb(thisModel.parameter7); if (thisModel.parameter8 != -1) { comboBox2.SelectedIndex = thisModel.parameter8; } numericUpDown3.Value = thisModel.parameter9; checkBox4.Checked = thisModel.parameter10; numericUpDown2.Value = thisModel.parameter11; panel2.BackColor = Color.FromArgb(thisModel.parameter12); numericUpDown1.Value = thisModel.parameter13; checkBox1.Checked = thisModel.parameter14; } #endregion } } /// /// 寻找轮廓并计算 /// private void FindContourAndCalc() { if (this.binarizationMat != null) { this.list.Clear(); Cv2.FindContours(BinaryClass.BGRA2GRAY(this.binarizationMat), out contours, out hierarchy, OpenCvSharp.RetrievalModes.CComp, ContourApproximationModes.ApproxNone); if (contours != null && contours.Length > 0) { //double ruleValue = 0; //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue); this.matGray = this.mat.CvtColor(ColorConversionCodes.BGR2GRAY); this.binarizationMatGray = BinaryClass.BGRA2GRAY(this.binarizationMat)/*//### .CvtColor(ColorConversionCodes.BGR2GRAY)*/; this.mats = this.mat.Split(); this.hole = new Mat(mat.Size(), MatType.CV_8U, Scalar.All(-1)); int k = 1; int i = 0; foreach (OpenCvSharp.Point[] p in contours) { if (hierarchy[i].Parent == -1) { ContoursAndRelatedInfo info = new ContoursAndRelatedInfo(); info.contours = p; info.wholeContours = BasicCalculationHelper.GetWholeContoursTree(contours, hierarchy, i); info.index = k; info.rule = ruleValue; info.hierarchyIndex = hierarchy[i]; info.mat = this.mat; info.mats = this.mats; info.hole = this.hole; info.matGray = this.matGray; info.binarizationMatGray = this.binarizationMatGray; this.list.Add(info); k++; } i++; } } } } /// /// 根据条件筛选颗粒 /// private void FilterParticlesByCondition() { if (this.list != null && this.list.Count > 0) { if (this.debrisSelectionModel != null && this.debrisSelectionModel.debrisSelectionList != null && this.debrisSelectionModel.debrisSelectionList.Count > 0 && this.comboBox3.SelectedIndex >= 0) { DebrisSelectionModel.DebrisSelection debrisSelection = this.debrisSelectionModel.debrisSelectionList[this.comboBox3.SelectedIndex]; if (debrisSelection.conditionList != null && debrisSelection.conditionList.Count > 0) { //用于筛选的集合,如果是and则用set,如果是or则用全部的集合 List temps = this.list; //进行排序 for (int i = 0; i < temps.Count(); i++) { temps[i].index = i + 1; } //用于存储过滤后的集合 set = new List(); for (int flag = 0; flag < debrisSelection.conditionList.Count; flag++) { Condition condition = debrisSelection.conditionList[flag]; //声明linq的条件 Predicate match = null; List temp; switch ((DebrisSelectionParameters)Enum.Parse(typeof(DebrisSelectionParameters), condition.conditionName)) { case DebrisSelectionParameters.area: switch (condition.judgeCondition) { case 0: match = a => a.Area > condition.conditionNum; break; case 1: match = a => a.Area < condition.conditionNum; break; case 2: match = a => a.Area >= condition.conditionNum; break; case 3: match = a => a.Area <= condition.conditionNum; break; } break; case DebrisSelectionParameters.areaRatio: switch (condition.judgeCondition) { case 0: match = a => a.AreaRatio > condition.conditionNum; break; case 1: match = a => a.AreaRatio < condition.conditionNum; break; case 2: match = a => a.AreaRatio >= condition.conditionNum; break; case 3: match = a => a.AreaRatio <= condition.conditionNum; break; } break; case DebrisSelectionParameters.perimeter: switch (condition.judgeCondition) { case 0: match = a => a.Perimeter > condition.conditionNum; break; case 1: match = a => a.Perimeter < condition.conditionNum; break; case 2: match = a => a.Perimeter >= condition.conditionNum; break; case 3: match = a => a.Perimeter <= condition.conditionNum; break; } break; case DebrisSelectionParameters.longAxis: switch (condition.judgeCondition) { case 0: match = a => a.LongAxis > condition.conditionNum; break; case 1: match = a => a.LongAxis < condition.conditionNum; break; case 2: match = a => a.LongAxis >= condition.conditionNum; break; case 3: match = a => a.LongAxis <= condition.conditionNum; break; } break; case DebrisSelectionParameters.shortAxis: switch (condition.judgeCondition) { case 0: match = a => a.ShortAxis > condition.conditionNum; break; case 1: match = a => a.ShortAxis < condition.conditionNum; break; case 2: match = a => a.ShortAxis >= condition.conditionNum; break; case 3: match = a => a.ShortAxis <= condition.conditionNum; break; } break; case DebrisSelectionParameters.centerX: switch (condition.judgeCondition) { case 0: match = a => a.CenterX > condition.conditionNum; break; case 1: match = a => a.CenterX < condition.conditionNum; break; case 2: match = a => a.CenterX >= condition.conditionNum; break; case 3: match = a => a.CenterX <= condition.conditionNum; break; } break; case DebrisSelectionParameters.centerY: switch (condition.judgeCondition) { case 0: match = a => a.CenterY > condition.conditionNum; break; case 1: match = a => a.CenterY < condition.conditionNum; break; case 2: match = a => a.CenterY >= condition.conditionNum; break; case 3: match = a => a.CenterY <= condition.conditionNum; break; } break; case DebrisSelectionParameters.inclinationAngle: switch (condition.judgeCondition) { case 0: match = a => a.InclinationAngle > condition.conditionNum; break; case 1: match = a => a.InclinationAngle < condition.conditionNum; break; case 2: match = a => a.InclinationAngle >= condition.conditionNum; break; case 3: match = a => a.InclinationAngle <= condition.conditionNum; break; } break; case DebrisSelectionParameters.objectAppearance: switch (condition.judgeCondition) { case 0: match = a => a.ObjectAppearance > condition.conditionNum; break; case 1: match = a => a.ObjectAppearance < condition.conditionNum; break; case 2: match = a => a.ObjectAppearance >= condition.conditionNum; break; case 3: match = a => a.ObjectAppearance <= condition.conditionNum; break; } break; case DebrisSelectionParameters.height: switch (condition.judgeCondition) { case 0: match = a => a.Height > condition.conditionNum; break; case 1: match = a => a.Height < condition.conditionNum; break; case 2: match = a => a.Height >= condition.conditionNum; break; case 3: match = a => a.Height <= condition.conditionNum; break; } break; case DebrisSelectionParameters.width: switch (condition.judgeCondition) { case 0: match = a => a.Width > condition.conditionNum; break; case 1: match = a => a.Width < condition.conditionNum; break; case 2: match = a => a.Width >= condition.conditionNum; break; case 3: match = a => a.Width <= condition.conditionNum; break; } break; case DebrisSelectionParameters.aspectRatio: switch (condition.judgeCondition) { case 0: match = a => a.AspectRatio > condition.conditionNum; break; case 1: match = a => a.AspectRatio < condition.conditionNum; break; case 2: match = a => a.AspectRatio >= condition.conditionNum; break; case 3: match = a => a.AspectRatio <= condition.conditionNum; break; } break; case DebrisSelectionParameters.redDensity: switch (condition.judgeCondition) { case 0: match = a => a.RedDensity > condition.conditionNum; break; case 1: match = a => a.RedDensity < condition.conditionNum; break; case 2: match = a => a.RedDensity >= condition.conditionNum; break; case 3: match = a => a.RedDensity <= condition.conditionNum; break; } break; case DebrisSelectionParameters.greenDensity: switch (condition.judgeCondition) { case 0: match = a => a.GreenDensity > condition.conditionNum; break; case 1: match = a => a.GreenDensity < condition.conditionNum; break; case 2: match = a => a.GreenDensity >= condition.conditionNum; break; case 3: match = a => a.GreenDensity <= condition.conditionNum; break; } break; case DebrisSelectionParameters.blueDensity: switch (condition.judgeCondition) { case 0: match = a => a.BlueDensity > condition.conditionNum; break; case 1: match = a => a.BlueDensity < condition.conditionNum; break; case 2: match = a => a.BlueDensity >= condition.conditionNum; break; case 3: match = a => a.BlueDensity <= condition.conditionNum; break; } break; /*case DebrisSelectionParameters.maxDensity: switch (condition.judgeCondition) { case 0: match = a => a.MaxDensity > condition.conditionNum; break; case 1: match = a => a.MaxDensity < condition.conditionNum; break; case 2: match = a => a.MaxDensity >= condition.conditionNum; break; case 3: match = a => a.MaxDensity <= condition.conditionNum; break; } break; case DebrisSelectionParameters.minDensity: switch (condition.judgeCondition) { case 0: match = a => a.MinDensity > condition.conditionNum; break; case 1: match = a => a.MinDensity < condition.conditionNum; break; case 2: match = a => a.MinDensity >= condition.conditionNum; break; case 3: match = a => a.MinDensity <= condition.conditionNum; break; } break; case DebrisSelectionParameters.avgDensity: switch (condition.judgeCondition) { case 0: match = a => a.AvgDensity > condition.conditionNum; break; case 1: match = a => a.AvgDensity < condition.conditionNum; break; case 2: match = a => a.AvgDensity >= condition.conditionNum; break; case 3: match = a => a.AvgDensity <= condition.conditionNum; break; } break; case DebrisSelectionParameters.sumDensity: switch (condition.judgeCondition) { case 0: match = a => a.SumDensity > condition.conditionNum; break; case 1: match = a => a.SumDensity < condition.conditionNum; break; case 2: match = a => a.SumDensity >= condition.conditionNum; break; case 3: match = a => a.SumDensity <= condition.conditionNum; break; } break;*/ case DebrisSelectionParameters.majorAxis: switch (condition.judgeCondition) { case 0: match = a => a.MajorAxis > condition.conditionNum; break; case 1: match = a => a.MajorAxis < condition.conditionNum; break; case 2: match = a => a.MajorAxis >= condition.conditionNum; break; case 3: match = a => a.MajorAxis <= condition.conditionNum; break; } break; case DebrisSelectionParameters.minorAxis: switch (condition.judgeCondition) { case 0: match = a => a.MinorAxis > condition.conditionNum; break; case 1: match = a => a.MinorAxis < condition.conditionNum; break; case 2: match = a => a.MinorAxis >= condition.conditionNum; break; case 3: match = a => a.MinorAxis <= condition.conditionNum; break; } break; case DebrisSelectionParameters.circumcircleDiameter: switch (condition.judgeCondition) { case 0: match = a => a.CircumcircleDiameter > condition.conditionNum; break; case 1: match = a => a.CircumcircleDiameter < condition.conditionNum; break; case 2: match = a => a.CircumcircleDiameter >= condition.conditionNum; break; case 3: match = a => a.CircumcircleDiameter <= condition.conditionNum; break; } break; case DebrisSelectionParameters.nodularity: switch (condition.judgeCondition) { case 0: match = a => a.Nodularity > condition.conditionNum; break; case 1: match = a => a.Nodularity < condition.conditionNum; break; case 2: match = a => a.Nodularity >= condition.conditionNum; break; case 3: match = a => a.Nodularity <= condition.conditionNum; break; } break; case DebrisSelectionParameters.equalCircleDiameter: switch (condition.judgeCondition) { case 0: match = a => a.EqualCircleDiameter > condition.conditionNum; break; case 1: match = a => a.EqualCircleDiameter < condition.conditionNum; break; case 2: match = a => a.EqualCircleDiameter >= condition.conditionNum; break; case 3: match = a => a.EqualCircleDiameter <= condition.conditionNum; break; } break; case DebrisSelectionParameters.maxCaliperDiameter: switch (condition.judgeCondition) { case 0: match = a => a.MaxCaliperDiameter > condition.conditionNum; break; case 1: match = a => a.MaxCaliperDiameter < condition.conditionNum; break; case 2: match = a => a.MaxCaliperDiameter >= condition.conditionNum; break; case 3: match = a => a.MaxCaliperDiameter <= condition.conditionNum; break; } break; case DebrisSelectionParameters.minCaliperDiameter: switch (condition.judgeCondition) { case 0: match = a => a.MinCaliperDiameter > condition.conditionNum; break; case 1: match = a => a.MinCaliperDiameter < condition.conditionNum; break; case 2: match = a => a.MinCaliperDiameter >= condition.conditionNum; break; case 3: match = a => a.MinCaliperDiameter <= condition.conditionNum; break; } break; case DebrisSelectionParameters.avgCaliperDiameter: switch (condition.judgeCondition) { case 0: match = a => a.AvgCaliperDiameter > condition.conditionNum; break; case 1: match = a => a.AvgCaliperDiameter < condition.conditionNum; break; case 2: match = a => a.AvgCaliperDiameter >= condition.conditionNum; break; case 3: match = a => a.AvgCaliperDiameter <= condition.conditionNum; break; } break; case DebrisSelectionParameters.maxGray: switch (condition.judgeCondition) { case 0: match = a => a.MaxGray > condition.conditionNum; break; case 1: match = a => a.MaxGray < condition.conditionNum; break; case 2: match = a => a.MaxGray >= condition.conditionNum; break; case 3: match = a => a.MaxGray <= condition.conditionNum; break; } break; case DebrisSelectionParameters.minGray: switch (condition.judgeCondition) { case 0: match = a => a.MinGray > condition.conditionNum; break; case 1: match = a => a.MinGray < condition.conditionNum; break; case 2: match = a => a.MinGray >= condition.conditionNum; break; case 3: match = a => a.MinGray <= condition.conditionNum; break; } break; case DebrisSelectionParameters.avgGray: switch (condition.judgeCondition) { case 0: match = a => a.AvgGray > condition.conditionNum; break; case 1: match = a => a.AvgGray < condition.conditionNum; break; case 2: match = a => a.AvgGray >= condition.conditionNum; break; case 3: match = a => a.AvgGray <= condition.conditionNum; break; } break; case DebrisSelectionParameters.fiberLength: switch (condition.judgeCondition) { case 0: match = a => a.FiberLength > condition.conditionNum; break; case 1: match = a => a.FiberLength < condition.conditionNum; break; case 2: match = a => a.FiberLength >= condition.conditionNum; break; case 3: match = a => a.FiberLength <= condition.conditionNum; break; } break; case DebrisSelectionParameters.fillArea: switch (condition.judgeCondition) { case 0: match = a => a.FillArea > condition.conditionNum; break; case 1: match = a => a.FillArea < condition.conditionNum; break; case 2: match = a => a.FillArea >= condition.conditionNum; break; case 3: match = a => a.FillArea <= condition.conditionNum; break; } break; case DebrisSelectionParameters.waistDepth: switch (condition.judgeCondition) { case 0: match = a => a.WaistDepth > condition.conditionNum; break; case 1: match = a => a.WaistDepth < condition.conditionNum; break; case 2: match = a => a.WaistDepth >= condition.conditionNum; break; case 3: match = a => a.WaistDepth <= condition.conditionNum; break; } break; case DebrisSelectionParameters.waistDepthShort: switch (condition.judgeCondition) { case 0: match = a => a.WaistDepthShort > condition.conditionNum; break; case 1: match = a => a.WaistDepthShort < condition.conditionNum; break; case 2: match = a => a.WaistDepthShort >= condition.conditionNum; break; case 3: match = a => a.WaistDepthShort <= condition.conditionNum; break; } break; } //获取临时的筛选集合 temp = temps.FindAll(match).ToList(); if (flag - 1 >= 0) { //如果上一个循环是And if (debrisSelection.conditionList[flag - 1].joinCondition == 0) { set = temp; } else { set.AddRange(temp); } } else { set.AddRange(temp); } //去重复 set = set.Where((x, i) => set.FindIndex(n => n.index == x.index) == i).ToList(); if (flag < debrisSelection.conditionList.Count()) { //指定下一次循环从什么数据集中过滤 if (condition.joinCondition == 0) temps = set; else temps = this.list; } } //对index重新赋值 for (int i = 0; i < set.Count(); i++) { set[i].index = i + 1; } } } } } /// /// 根据筛选的条件进行绘制 /// private void DrawConditionMat() { if (this.set != null && this.set.Count > 0 && this.binarizationMat != null) { Mat mat1 = this.binarizationMat.Clone(); List> points = new List>(); foreach (ContoursAndRelatedInfo c in set) { points.Add(c.contours.ToList()); } if (points.Count > 0) { Mat temp = mat1.CvtColor(ColorConversionCodes.BGRA2BGR); for (int k = 0; k < points.Count; k++) { Rect rect; if (k == this.gridView1SelectIndex) { Cv2.FloodFill(temp, points[k][0], new Scalar(255 - this.panel2.BackColor.B, 255 - this.panel2.BackColor.G, 255 - this.panel2.BackColor.R, 255), out rect, null, null, FloodFillFlags.Link8); } else { Cv2.FloodFill(temp, points[k][0], new Scalar(this.panel2.BackColor.B, this.panel2.BackColor.G, this.panel2.BackColor.R, 255), out rect, null, null, FloodFillFlags.Link8); } } Cv2.Merge(temp.Split().Union(new Mat[] { mat1.Split()[3] }).ToArray(), mat1); //Cv2.FillPoly(mat1, points, new Scalar(this.panel2.BackColor.B, this.panel2.BackColor.G, this.panel2.BackColor.R, 255)) ; //如果显示编号,则绘制编号 //如果显示参数,则绘制参数 if (this.checkBox2.Checked || this.checkBox3.Checked) { using (Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat1)) { Graphics graphics = Graphics.FromImage(bitmap); Font font = new Font(this.comboBox2.SelectedItem.ToString(), (int)this.numericUpDown3.Value); Color color1 = this.panel1.BackColor; Color color3 = this.panel3.BackColor; foreach (ContoursAndRelatedInfo c in set) { if (this.checkBox2.Checked) { graphics.DrawString(c.index.ToString(), font, new SolidBrush(color1), new System.Drawing.Point(c.contours[0].X, c.contours[0].Y)); //Cv2.PutText(mat1, c.index.ToString(), new OpenCvSharp.Point(c.contours[0].X, c.contours[0].Y), HersheyFonts.HersheyComplex, 1, new Scalar(this.panel2.BackColor.B, this.panel2.BackColor.G, this.panel2.BackColor.R, 255), 3); } if (this.checkBox3.Checked && this.comboBox1.SelectedValue != null) { switch ((DebrisSelectionParameters)((int)(this.comboBox1.SelectedValue))) { case DebrisSelectionParameters.area: graphics.DrawString(Math.Round(c.Area, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.areaRatio: graphics.DrawString(Math.Round(c.AreaRatio, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.perimeter: graphics.DrawString(Math.Round(c.Perimeter, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.longAxis: graphics.DrawString(Math.Round(c.LongAxis, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.shortAxis: graphics.DrawString(Math.Round(c.ShortAxis, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.centerX: graphics.DrawString(Math.Round(c.CenterX * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.centerY: graphics.DrawString(Math.Round(c.CenterY * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.inclinationAngle: graphics.DrawString(Math.Round(c.InclinationAngle, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.objectAppearance: graphics.DrawString(Math.Round(c.ObjectAppearance, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.height: graphics.DrawString(Math.Round(c.Height * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.width: graphics.DrawString(Math.Round(c.Width * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.aspectRatio: graphics.DrawString(Math.Round(c.AspectRatio, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.redDensity: graphics.DrawString(Math.Round(c.RedDensity, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.greenDensity: graphics.DrawString(Math.Round(c.GreenDensity, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.blueDensity: graphics.DrawString(Math.Round(c.BlueDensity, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; /*case DebrisSelectionParameters.maxDensity: break; case DebrisSelectionParameters.minDensity: break; case DebrisSelectionParameters.avgDensity: break; case DebrisSelectionParameters.sumDensity: break;*/ case DebrisSelectionParameters.majorAxis: graphics.DrawString(Math.Round(c.MajorAxis, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.minorAxis: graphics.DrawString(Math.Round(c.MinorAxis, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.circumcircleDiameter: graphics.DrawString(Math.Round(c.CircumcircleDiameter, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.nodularity: graphics.DrawString(Math.Round(c.Nodularity, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.equalCircleDiameter: graphics.DrawString(Math.Round(c.EqualCircleDiameter, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.maxCaliperDiameter: graphics.DrawString(Math.Round(c.MaxCaliperDiameter * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.minCaliperDiameter: graphics.DrawString(Math.Round(c.MinCaliperDiameter * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.avgCaliperDiameter: graphics.DrawString(Math.Round(c.AvgCaliperDiameter * 1d, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.maxGray: graphics.DrawString(Math.Round(c.MaxGray, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.minGray: graphics.DrawString(Math.Round(c.MinGray, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.avgGray: graphics.DrawString(Math.Round(c.AvgGray, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.fiberLength: graphics.DrawString(Math.Round(c.FiberLength, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.fillArea: graphics.DrawString(Math.Round(c.FillArea, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.waistDepth: //graphics.DrawLine(new Pen(Color.Blue), new System.Drawing.Point(c.points_max[0].X, c.points_max[0].Y), new System.Drawing.Point(c.points_max[1].X, c.points_max[1].Y)); //graphics.DrawLine(new Pen(Color.Blue), new System.Drawing.Point(c.points_min[0].X, c.points_min[0].Y), new System.Drawing.Point(c.points_min[1].X, c.points_min[1].Y)); graphics.DrawString(Math.Round(c.WaistDepth, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; case DebrisSelectionParameters.waistDepthShort: graphics.DrawString(Math.Round(c.WaistDepthShort, (int)this.numericUpDown1.Value).ToString(), font, new SolidBrush(color3), new System.Drawing.Point(c.CenterX, c.CenterY)); break; } } } mat1 = PaintDotNet.Camera.Tools.ToMat(bitmap); } } } this.phaseModel.mat = mat1; this.documentWorkspace.Refresh(); } else { if (this.binarizationMat != null) { this.phaseModel.mat = this.binarizationMat; this.documentWorkspace.Refresh(); } } } private void CreateCalipersDataTable() { if (this.set == null || this.set.Count == 0) { MessageBox.Show("数据为空!"); return; } string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName(); List setCalipers = new List(this.set); var type = config.calipersSetModel.sort;//获取排序选项 int sortMode = config.calipersSetModel.sortMode;//获取排序方式 int exportRecord = config.calipersSetModel.exportRecord;//导出记录 //var keyss = InvariantData.debrisSelectionparameters.Where(q => q.Value.ToString() == type).Select(q => q.Key); var firstKey = InvariantData.debrisSelectionparameters.FirstOrDefault(q => q.Value.ToString() == type).Key; switch (firstKey) { case DebrisSelectionParameters.area: if (sortMode == 1) setCalipers.Sort((x, y) => -x.area.CompareTo(y.area)); else setCalipers.Sort((x, y) => x.area.CompareTo(y.area)); break; case DebrisSelectionParameters.areaRatio: if (sortMode == 1) setCalipers.Sort((x, y) => -x.areaRatio.CompareTo(y.areaRatio)); else setCalipers.Sort((x, y) => x.areaRatio.CompareTo(y.areaRatio)); break; case DebrisSelectionParameters.perimeter: if (sortMode == 1) setCalipers.Sort((x, y) => -x.perimeter.CompareTo(y.perimeter)); else setCalipers.Sort((x, y) => x.perimeter.CompareTo(y.perimeter)); break; case DebrisSelectionParameters.longAxis: if (sortMode == 1) setCalipers.Sort((x, y) => -x.longAxis.CompareTo(y.longAxis)); else setCalipers.Sort((x, y) => x.longAxis.CompareTo(y.longAxis)); break; case DebrisSelectionParameters.shortAxis: if (sortMode == 1) setCalipers.Sort((x, y) => -x.shortAxis.CompareTo(y.shortAxis)); else setCalipers.Sort((x, y) => x.shortAxis.CompareTo(y.shortAxis)); break; case DebrisSelectionParameters.centerX: if (sortMode == 1) setCalipers.Sort((x, y) => -x.centerX.CompareTo(y.centerX)); else setCalipers.Sort((x, y) => x.centerX.CompareTo(y.centerX)); break; case DebrisSelectionParameters.centerY: if (sortMode == 1) setCalipers.Sort((x, y) => -x.centerY.CompareTo(y.centerY)); else setCalipers.Sort((x, y) => x.centerY.CompareTo(y.centerY)); break; case DebrisSelectionParameters.inclinationAngle: if (sortMode == 1) setCalipers.Sort((x, y) => -x.inclinationAngle.CompareTo(y.inclinationAngle)); else setCalipers.Sort((x, y) => x.inclinationAngle.CompareTo(y.inclinationAngle)); break; case DebrisSelectionParameters.objectAppearance: if (sortMode == 1) setCalipers.Sort((x, y) => -x.inclinationAngle.CompareTo(y.inclinationAngle)); else setCalipers.Sort((x, y) => x.inclinationAngle.CompareTo(y.inclinationAngle)); break; case DebrisSelectionParameters.height: if (sortMode == 1) setCalipers.Sort((x, y) => -x.height.CompareTo(y.height)); else setCalipers.Sort((x, y) => x.height.CompareTo(y.height)); break; case DebrisSelectionParameters.width: if (sortMode == 1) setCalipers.Sort((x, y) => -x.width.CompareTo(y.width)); else setCalipers.Sort((x, y) => x.width.CompareTo(y.width)); break; case DebrisSelectionParameters.aspectRatio: if (sortMode == 1) setCalipers.Sort((x, y) => -x.aspectRatio.CompareTo(y.aspectRatio)); else setCalipers.Sort((x, y) => x.aspectRatio.CompareTo(y.aspectRatio)); break; case DebrisSelectionParameters.redDensity: if (sortMode == 1) setCalipers.Sort((x, y) => -x.redDensity.CompareTo(y.redDensity)); else setCalipers.Sort((x, y) => x.redDensity.CompareTo(y.redDensity)); break; case DebrisSelectionParameters.greenDensity: if (sortMode == 1) setCalipers.Sort((x, y) => -x.greenDensity.CompareTo(y.greenDensity)); else setCalipers.Sort((x, y) => x.greenDensity.CompareTo(y.greenDensity)); break; case DebrisSelectionParameters.blueDensity: if (sortMode == 1) setCalipers.Sort((x, y) => -x.blueDensity.CompareTo(y.blueDensity)); else setCalipers.Sort((x, y) => x.blueDensity.CompareTo(y.blueDensity)); break; /*case DebrisSelectionParameters.maxDensity: break; case DebrisSelectionParameters.minDensity: break; case DebrisSelectionParameters.avgDensity: break; case DebrisSelectionParameters.sumDensity: break;*/ case DebrisSelectionParameters.majorAxis: if (sortMode == 1) setCalipers.Sort((x, y) => -x.majorAxis.CompareTo(y.majorAxis)); else setCalipers.Sort((x, y) => x.majorAxis.CompareTo(y.majorAxis)); break; case DebrisSelectionParameters.minorAxis: if (sortMode == 1) setCalipers.Sort((x, y) => -x.minorAxis.CompareTo(y.minorAxis)); else setCalipers.Sort((x, y) => x.minorAxis.CompareTo(y.minorAxis)); break; case DebrisSelectionParameters.circumcircleDiameter: if (sortMode == 1) setCalipers.Sort((x, y) => -x.circumcircleDiameter.CompareTo(y.circumcircleDiameter)); else setCalipers.Sort((x, y) => x.circumcircleDiameter.CompareTo(y.circumcircleDiameter)); break; case DebrisSelectionParameters.nodularity: if (sortMode == 1) setCalipers.Sort((x, y) => -x.nodularity.CompareTo(y.nodularity)); else setCalipers.Sort((x, y) => x.nodularity.CompareTo(y.nodularity)); break; case DebrisSelectionParameters.equalCircleDiameter: if (sortMode == 1) setCalipers.Sort((x, y) => -x.equalCircleDiameter.CompareTo(y.equalCircleDiameter)); else setCalipers.Sort((x, y) => x.equalCircleDiameter.CompareTo(y.equalCircleDiameter)); break; case DebrisSelectionParameters.maxCaliperDiameter: if (sortMode == 1) setCalipers.Sort((x, y) => -x.maxCaliperDiameter.CompareTo(y.maxCaliperDiameter)); else setCalipers.Sort((x, y) => x.maxCaliperDiameter.CompareTo(y.maxCaliperDiameter)); break; case DebrisSelectionParameters.minCaliperDiameter: if (sortMode == 1) setCalipers.Sort((x, y) => -x.minCaliperDiameter.CompareTo(y.minCaliperDiameter)); else setCalipers.Sort((x, y) => x.minCaliperDiameter.CompareTo(y.minCaliperDiameter)); break; case DebrisSelectionParameters.avgCaliperDiameter: if (sortMode == 1) setCalipers.Sort((x, y) => -x.avgCaliperDiameter.CompareTo(y.avgCaliperDiameter)); else setCalipers.Sort((x, y) => x.avgCaliperDiameter.CompareTo(y.avgCaliperDiameter)); break; case DebrisSelectionParameters.maxGray: if (sortMode == 1) setCalipers.Sort((x, y) => -x.maxGray.CompareTo(y.maxGray)); else setCalipers.Sort((x, y) => x.maxGray.CompareTo(y.maxGray)); break; case DebrisSelectionParameters.minGray: if (sortMode == 1) setCalipers.Sort((x, y) => -x.minGray.CompareTo(y.minGray)); else setCalipers.Sort((x, y) => x.minGray.CompareTo(y.minGray)); break; case DebrisSelectionParameters.avgGray: if (sortMode == 1) setCalipers.Sort((x, y) => -x.avgGray.CompareTo(y.avgGray)); else setCalipers.Sort((x, y) => x.avgGray.CompareTo(y.avgGray)); break; case DebrisSelectionParameters.fiberLength: if (sortMode == 1) setCalipers.Sort((x, y) => -x.fiberLength.CompareTo(y.fiberLength)); else setCalipers.Sort((x, y) => x.fiberLength.CompareTo(y.fiberLength)); break; case DebrisSelectionParameters.fillArea: if (sortMode == 1) setCalipers.Sort((x, y) => -x.fillArea.CompareTo(y.fillArea)); else setCalipers.Sort((x, y) => x.fillArea.CompareTo(y.fillArea)); break; case DebrisSelectionParameters.waistDepth: if (sortMode == 1) setCalipers.Sort((x, y) => -x.waistDepth.CompareTo(y.waistDepth)); else setCalipers.Sort((x, y) => x.waistDepth.CompareTo(y.waistDepth)); break; case DebrisSelectionParameters.waistDepthShort: if (sortMode == 1) setCalipers.Sort((x, y) => -x.waistDepthShort.CompareTo(y.waistDepthShort)); else setCalipers.Sort((x, y) => x.waistDepthShort.CompareTo(y.waistDepthShort)); break; } var vs = InvariantData.debrisSelectionparameters.Values; string[] lst = vs.Select(a => a.ToString()).ToArray(); DataTable calipersTable = new DataTable(); DataColumn dc = new DataColumn("图片名称"); calipersTable.Columns.Add(dc); dc = new DataColumn("颗粒编号"); calipersTable.Columns.Add(dc); dc = new DataColumn("最大卡规直径"); calipersTable.Columns.Add(dc); dc = new DataColumn("最小卡规直径"); calipersTable.Columns.Add(dc); dc = new DataColumn("平均卡规直径"); calipersTable.Columns.Add(dc); dc = new DataColumn("最大/最小卡规直径"); calipersTable.Columns.Add(dc); dc = new DataColumn("最小/最大卡规直径"); calipersTable.Columns.Add(dc); for (int i = 1; i < 33; i++) { dc = new DataColumn("卡规" + i); calipersTable.Columns.Add(dc); } int length = exportRecord == 0 ? setCalipers.Count : (exportRecord > setCalipers.Count ? setCalipers.Count : exportRecord); for (int count = 0; count < length; count++) { DataRow dr = calipersTable.NewRow(); int index = 0; for (int i = 0; i < calipersTable.Columns.Count; i++) { if (i == 0) dr[i] = imgName; if (i == 1) dr[i] = setCalipers[count].index; if (i == 2) dr[i] = setCalipers[count].MaxCaliperDiameter; if (i == 3) dr[i] = setCalipers[count].MinCaliperDiameter; if (i == 4) dr[i] = setCalipers[count].AvgCaliperDiameter; if (i == 5) dr[i] = setCalipers[count].MinCaliperDiameter == 0 ? 0 : setCalipers[count].MaxCaliperDiameter / setCalipers[count].MinCaliperDiameter; if (i == 6) dr[i] = setCalipers[count].MaxCaliperDiameter == 0 ? 0 : setCalipers[count].MinCaliperDiameter / setCalipers[count].MaxCaliperDiameter; if (i > 6) { for (int j = index; j < 32; j++) { dr[i] = setCalipers[count].Vs.Count > j ? setCalipers[count].Vs[j] * ruleValue : 0; index = j + 1; break; } } } calipersTable.Rows.Add(dr); //calipersTable.Rows.Add(imgName, count + 1, setCalipers[count].Area, setCalipers[count].AreaRatio, setCalipers[count].Perimeter, setCalipers[count].LongAxis, setCalipers[count].ShortAxis, setCalipers[count].CenterX, setCalipers[count].CenterY, setCalipers[count].InclinationAngle, setCalipers[count].ObjectAppearance, setCalipers[count].Height, setCalipers[count].Width, setCalipers[count].AspectRatio, setCalipers[count].RedDensity, setCalipers[count].GreenDensity, setCalipers[count].BlueDensity, setCalipers[count].MajorAxis, setCalipers[count].MinorAxis, setCalipers[count].CircumcircleDiameter, setCalipers[count].Nodularity, setCalipers[count].EqualCircleDiameter, setCalipers[count].MaxCaliperDiameter, setCalipers[count].MinCaliperDiameter, setCalipers[count].AvgCaliperDiameter, setCalipers[count].MaxGray, setCalipers[count].MinGray, setCalipers[count].AvgGray, setCalipers[count].FiberLength, setCalipers[count].FillArea, setCalipers[count].WaistDepth, setCalipers[count].WaistDepthShort); } OfficeFileHandleHelper.calipersTable = calipersTable; //OfficeFileHandleHelper.ExportCalipersSet(calipersTable, ""); } /// /// 将筛选的结果添加到datagridview中 /// private void CreateDataGridViewData() { if (this.set != null && this.set.Count > 0) { this.set.Sort((l, r) => l.index.CompareTo(r.index)); this.dataGridView1.Rows.Clear(); foreach (ContoursAndRelatedInfo c in set) { DataGridViewRow row = new DataGridViewRow(); row.Height = 25; row.Cells.Add(CreateTextBoxCell(c.index, c.index)); foreach (var item in listDictionary) { switch (item.Key) { case DebrisSelectionParameters.area: row.Cells.Add(CreateTextBoxCell(Math.Round(c.Area, (int)this.numericUpDown1.Value), c.Area)); break; case DebrisSelectionParameters.areaRatio: row.Cells.Add(CreateTextBoxCell(Math.Round(c.AreaRatio, (int)this.numericUpDown1.Value), c.AreaRatio)); break; case DebrisSelectionParameters.perimeter: row.Cells.Add(CreateTextBoxCell(Math.Round(c.Perimeter, (int)this.numericUpDown1.Value), c.Perimeter)); break; case DebrisSelectionParameters.longAxis: row.Cells.Add(CreateTextBoxCell(Math.Round(c.LongAxis, (int)this.numericUpDown1.Value), c.LongAxis)); break; case DebrisSelectionParameters.shortAxis: row.Cells.Add(CreateTextBoxCell(Math.Round(c.ShortAxis, (int)this.numericUpDown1.Value), c.ShortAxis)); break; case DebrisSelectionParameters.centerX: row.Cells.Add(CreateTextBoxCell(Math.Round(c.CenterX * 1d, (int)this.numericUpDown1.Value), c.CenterX)); break; case DebrisSelectionParameters.centerY: row.Cells.Add(CreateTextBoxCell(Math.Round(c.CenterY * 1d, (int)this.numericUpDown1.Value), c.CenterY)); break; case DebrisSelectionParameters.inclinationAngle: row.Cells.Add(CreateTextBoxCell(Math.Round(c.InclinationAngle, (int)this.numericUpDown1.Value), c.InclinationAngle)); break; case DebrisSelectionParameters.objectAppearance: row.Cells.Add(CreateTextBoxCell(Math.Round(c.ObjectAppearance, (int)this.numericUpDown1.Value), c.ObjectAppearance)); break; case DebrisSelectionParameters.height: row.Cells.Add(CreateTextBoxCell(Math.Round(c.Height * 1d, (int)this.numericUpDown1.Value), c.Height)); break; case DebrisSelectionParameters.width: row.Cells.Add(CreateTextBoxCell(Math.Round(c.Width * 1d, (int)this.numericUpDown1.Value), c.Width)); break; case DebrisSelectionParameters.aspectRatio: row.Cells.Add(CreateTextBoxCell(Math.Round(c.AspectRatio, (int)this.numericUpDown1.Value), c.AspectRatio)); break; case DebrisSelectionParameters.redDensity: row.Cells.Add(CreateTextBoxCell(Math.Round(c.RedDensity, (int)this.numericUpDown1.Value), c.RedDensity)); break; case DebrisSelectionParameters.greenDensity: row.Cells.Add(CreateTextBoxCell(Math.Round(c.GreenDensity, (int)this.numericUpDown1.Value), c.GreenDensity)); break; case DebrisSelectionParameters.blueDensity: row.Cells.Add(CreateTextBoxCell(Math.Round(c.BlueDensity, (int)this.numericUpDown1.Value), c.BlueDensity)); break; /*case DebrisSelectionParameters.maxDensity: break; case DebrisSelectionParameters.minDensity: break; case DebrisSelectionParameters.avgDensity: break; case DebrisSelectionParameters.sumDensity: break;*/ case DebrisSelectionParameters.majorAxis: row.Cells.Add(CreateTextBoxCell(Math.Round(c.MajorAxis, (int)this.numericUpDown1.Value), c.MajorAxis)); break; case DebrisSelectionParameters.minorAxis: row.Cells.Add(CreateTextBoxCell(Math.Round(c.MinorAxis, (int)this.numericUpDown1.Value), c.MinorAxis)); break; case DebrisSelectionParameters.circumcircleDiameter: row.Cells.Add(CreateTextBoxCell(Math.Round(c.CircumcircleDiameter, (int)this.numericUpDown1.Value), c.CircumcircleDiameter)); break; case DebrisSelectionParameters.nodularity: row.Cells.Add(CreateTextBoxCell(Math.Round(c.Nodularity, (int)this.numericUpDown1.Value), c.Nodularity)); break; case DebrisSelectionParameters.equalCircleDiameter: row.Cells.Add(CreateTextBoxCell(Math.Round(c.EqualCircleDiameter, (int)this.numericUpDown1.Value), c.EqualCircleDiameter)); break; case DebrisSelectionParameters.maxCaliperDiameter: row.Cells.Add(CreateTextBoxCell(Math.Round(c.MaxCaliperDiameter * 1d, (int)this.numericUpDown1.Value), c.MaxCaliperDiameter)); break; case DebrisSelectionParameters.minCaliperDiameter: row.Cells.Add(CreateTextBoxCell(Math.Round(c.MinCaliperDiameter * 1d, (int)this.numericUpDown1.Value), c.MinCaliperDiameter)); break; case DebrisSelectionParameters.avgCaliperDiameter: row.Cells.Add(CreateTextBoxCell(Math.Round(c.AvgCaliperDiameter * 1d, (int)this.numericUpDown1.Value), c.AvgCaliperDiameter)); break; case DebrisSelectionParameters.maxGray: row.Cells.Add(CreateTextBoxCell(Math.Round(c.MaxGray, (int)this.numericUpDown1.Value), c.MaxGray)); break; case DebrisSelectionParameters.minGray: row.Cells.Add(CreateTextBoxCell(Math.Round(c.MinGray, (int)this.numericUpDown1.Value), c.MinGray)); break; case DebrisSelectionParameters.avgGray: row.Cells.Add(CreateTextBoxCell(Math.Round(c.AvgGray, (int)this.numericUpDown1.Value), c.AvgGray)); break; case DebrisSelectionParameters.fiberLength: row.Cells.Add(CreateTextBoxCell(Math.Round(c.FiberLength, (int)this.numericUpDown1.Value), c.FiberLength)); break; case DebrisSelectionParameters.fillArea: row.Cells.Add(CreateTextBoxCell(Math.Round(c.FillArea, (int)this.numericUpDown1.Value), c.FillArea)); break; case DebrisSelectionParameters.waistDepth: row.Cells.Add(CreateTextBoxCell(Math.Round(c.WaistDepth, (int)this.numericUpDown1.Value), c.WaistDepth)); break; case DebrisSelectionParameters.waistDepthShort: row.Cells.Add(CreateTextBoxCell(Math.Round(c.WaistDepthShort, (int)this.numericUpDown1.Value), c.WaistDepthShort)); break; } } if (this.dataGridView1.Columns.Count > 0) { this.dataGridView1.Rows.Add(row); } } } else { this.dataGridView1.Rows.Clear(); } } /// /// 分析结果列表选择切换 /// /// /// private void listView2_SelectedIndexChanged(object sender, EventArgs e) { if (this.showAll) return; RefreshDataGridView2(); } /// /// 刷新数据展示表 /// private void RefreshDataGridView1() { this.dataGridView1.Rows.Clear(); } /// /// 二值化颜色panel被点击 /// /// /// private void panel1_Click(object sender, EventArgs e) { this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor); this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.colorsForm1Changed)); this.colorsForm1.ShowDialog(); } private void colorsForm1Changed(object sender, EventArgs e) { this.panel1.BackColor = this.colorsForm1.UserPrimaryColor.ToColor(); this.colorsForm1.Close(); this.documentWorkspace.Refresh(); } /// /// 小数数字框值改变 /// /// /// private void numericUpDown1_ValueChanged(object sender, EventArgs e) { if (this.numericUpDown1.Value > this.numericUpDown1.Maximum) this.numericUpDown1.Value = this.numericUpDown1.Maximum; if (this.numericUpDown1.Value < this.numericUpDown1.Minimum) this.numericUpDown1.Value = this.numericUpDown1.Minimum; this.RefreshDataGridView1(); this.listView1_SelectedIndexChanged(null, null); this.RefreshDataGridView2(); this.DrawConditionMat(); } /// /// 导出项目到项目工程 /// /// /// private void button3_Click(object sender, EventArgs e) { try { if (this.analyzeSettingModel == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text") + "!"); return; } //获取项目工程内的文件夹路径 ProjectEngineering.NodeItem item = this.appWorkspace.GetInsertProjectPath(2, "Menu.GeneralAnalysis.ParticleStatistics.Text", this.analyzeSettingModel.savePath); if (item != null) { //向文件夹内保存图片和报告 if (!string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { //获取word书签与excel单元格的关系,以字典方式存储 List mic_module_infos = mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify); Dictionary tagInfos = new Dictionary(); if (mic_module_infos != null && mic_module_infos.Count > 0) { foreach (mic_module_infos info in mic_module_infos) { tagInfos.Add(info.tag_name, info.cell_position); } } //分析结果 List> analysisContent = new List>(); if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { int k = 0; int kk = 0; foreach (DataTable dt in resultTableList) { if (kk == 0) { List contentHead = new List(); for (int ii = 0; ii < dt.Columns.Count; ii++) { contentHead.Add(dt.Columns[ii].ColumnName); } analysisContent.Add(contentHead); kk++; } //如果不是显示全部 if (!this.showAll) { if (!ExistInSelectItems(dt.TableName)) continue; } foreach (DataRow row in dt.Rows)//逐个读取单元格的内容; { List content = new List(); for (int j = 0; j < dt.Columns.Count; j++) { if (j > 0) { content.Add(Math.Round(double.Parse(row[j].ToString()), (int)this.numericUpDown1.Value).ToString()); } else { content.Add(row[j].ToString()); } } analysisContent.Add(content); k++; } } } //图片 bitList = new List(); if (this.showAll) { foreach (KeyValuePair> kv in this.bitDic) { bitList.Add(kv.Value[0]); bitList.Add(kv.Value[1]); } } else { if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { foreach (ListViewItem rowItem in this.listView2.SelectedItems) { if (bitDic.ContainsKey(rowItem.Name)) { bitList.Add(bitDic[rowItem.Name][0]); bitList.Add(bitDic[rowItem.Name][1]); } } } } this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, null, bitList, tagInfos, item.path, item.code); } else { MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text") + "!"); return; } //保存项目信息到数据库 this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, item); } } catch (Exception) { } } /// /// 设置统计数据按钮 /// /// /// private void button4_Click(object sender, EventArgs e) { using (DebrisSelectionValidConditionDialog debrisSelectionValidConditionDialog = new DebrisSelectionValidConditionDialog(this)) { debrisSelectionValidConditionDialog.StartPosition = FormStartPosition.CenterScreen; debrisSelectionValidConditionDialog.ShowDialog(); } } /// /// 统计选择下拉框切换 /// /// /// private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { this.RefreshDebirsDataGrid(); this.listView1_SelectedIndexChanged(null, null); } private void panel2_Click(object sender, EventArgs e) { this.colorsForm2.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor); this.colorsForm2.setSaveBtn_Click(new System.EventHandler(this.colorsForm2Changed)); this.colorsForm2.ShowDialog(); } private void colorsForm2Changed(object sender, EventArgs e) { this.panel2.BackColor = this.colorsForm2.UserPrimaryColor.ToColor(); this.colorsForm2.Close(); this.documentWorkspace.Refresh(); } private void panel3_Click(object sender, EventArgs e) { this.colorsForm3.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor); this.colorsForm3.setSaveBtn_Click(new System.EventHandler(this.colorsForm3Changed)); this.colorsForm3.ShowDialog(); } private void colorsForm3Changed(object sender, EventArgs e) { this.panel3.BackColor = this.colorsForm3.UserPrimaryColor.ToColor(); this.colorsForm3.Close(); this.documentWorkspace.Refresh(); } /// /// 修改参数 /// /// /// private void dataGridView3_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (this.dataGridView3.IsCurrentCellDirty) { this.dataGridView3.CommitEdit(DataGridViewDataErrorContexts.Commit); //循环处理this.debrisSelectionModel for (int i = 0; i < this.dataGridView3.Rows.Count; i++) { double v; if (((DataGridViewTextBoxCell)this.dataGridView3.Rows[i].Cells[2]).Value != null && double.TryParse(((DataGridViewTextBoxCell)this.dataGridView3.Rows[i].Cells[2]).Value.ToString(), out v)) { this.debrisSelectionModel.debrisSelectionList[this.comboBox3.SelectedIndex].conditionList[i].conditionNum = v;// double.Parse(((DataGridViewTextBoxCell)this.dataGridView3.Rows[i].Cells[2]).Value.ToString()); } else { ((DataGridViewTextBoxCell)this.dataGridView3.Rows[i].Cells[2]).Value = this.debrisSelectionModel.debrisSelectionList[this.comboBox3.SelectedIndex].conditionList[i].conditionNum; } } //重新进行过滤 this.FilterParticlesByCondition(); //绘制图片 this.DrawConditionMat(); //处理数据 this.CreateDataGridViewData(); } } /// /// 显示编号事件 /// /// /// private void checkBox2_CheckedChanged(object sender, EventArgs e) { DrawConditionMat(); } /// /// 显示参数事件 /// /// /// private void checkBox3_CheckedChanged(object sender, EventArgs e) { DrawConditionMat(); } /// /// 显示前10事件的checkbox事件 /// /// /// private void checkBox4_CheckedChanged(object sender, EventArgs e) { if (this.checkBox4.Checked) { for (int i = this.dataGridView1.Rows.Count - 1; i > (this.numericUpDown2.Value - 1); i--) { this.dataGridView1.Rows[i].Visible = false; //this.dataGridView1.Rows.RemoveAt(i); } } else { this.listView1_SelectedIndexChanged(null, null); } } /// /// 显示前10的数字改变事件 /// /// /// private void numericUpDown2_ValueChanged(object sender, EventArgs e) { if (this.checkBox4.Checked) { for (int i = this.dataGridView1.Rows.Count - 1; i > 0; i--) { if (i > this.numericUpDown2.Value - 1) { this.dataGridView1.Rows[i].Visible = false; } else { this.dataGridView1.Rows[i].Visible = true; } //this.dataGridView1.Rows.RemoveAt(i); } } } /// /// 字体改变事件 /// /// /// private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { if (this.binarizationMat != null) DrawConditionMat(); } /// /// 字号改变事件 /// /// /// private void numericUpDown3_ValueChanged(object sender, EventArgs e) { if (this.binarizationMat != null) DrawConditionMat(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (this.binarizationMat != null) DrawConditionMat(); } private void panel1_BackColorChanged(object sender, EventArgs e) { if (this.binarizationMat != null) DrawConditionMat(); } private void panel2_BackColorChanged(object sender, EventArgs e) { if (this.binarizationMat != null) DrawConditionMat(); } private void panel3_BackColorChanged(object sender, EventArgs e) { if (this.binarizationMat != null) DrawConditionMat(); } private void button5_Click(object sender, EventArgs e) { if (int.Parse(this.button5.Tag.ToString()) == 1) { //判断是否存在数据 if (this.listView2.Items.Count > 0) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Restartingwillclearthecurrentdata.Text") + "!", PdnResources.GetString("Menu.Edit.Delete.Text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { this.listView2.Items.Clear(); this.dataGridView2.Columns.Clear(); this.dataGridView2.Rows.Clear(); this.resultTableList.Clear(); this.button2.Enabled = true; this.button5.Tag = 2; this.button5.Text = PdnResources.GetString("Menu.stop.text"); this.comboBox3.Enabled = false; this.button4.Enabled = false; } } else { this.button2.Enabled = true; this.button5.Tag = 2; this.button5.Text = PdnResources.GetString("Menu.stop.text"); this.comboBox3.Enabled = false; this.button4.Enabled = false; } } else if (int.Parse(this.button5.Tag.ToString()) == 2) { this.button2.Enabled = false; this.button5.Tag = 1; this.button5.Text = PdnResources.GetString("Menu.Started.text"); this.comboBox3.Enabled = true; this.button4.Enabled = true; } } private void listView1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (listView1.SelectedItems.Count == 0)//点击空白区 { if (this.listView1.FocusedItem != null) { ListViewItem item = this.listView1.GetItemAt(e.X, e.Y); if (item == null) { this.listView1.FocusedItem.Selected = true; } } } } } /// /// 准备用来处理单个颗粒的选中事件 /// /// /// private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { //当点击表头部的列时,e.RowIndex==-1 if (e.RowIndex > -1) { /*ContoursAndRelatedInfo contoursAndRelatedInfo = this.set[e.RowIndex]; Mat temp = new Mat(); Mat[] arr1 = this.binarizationMat.Split(); ;// this.phaseModel.mat.Split(); Mat[] arr2 = new Mat[3]; arr2[0] = arr1[0]; arr2[1] = arr1[1]; arr2[2] = arr1[2]; Cv2.Merge(arr2, temp); 111111111111 Rect rect; Cv2.FloodFill(temp, this.set[gridView1SelectIndex].contours[0], new Scalar(this.panel2.BackColor.B, this.panel2.BackColor.G, this.panel2.BackColor.R), out rect, null, null, FloodFillFlags.Link8); Cv2.FloodFill(temp, contoursAndRelatedInfo.contours[0], new Scalar(255 - this.panel2.BackColor.B, 255 - this.panel2.BackColor.G, 255 - this.panel2.BackColor.R), out rect, null, null, FloodFillFlags.Link8); Mat[] arr3 = temp.Split(); Mat[] arr4 = new Mat[4]; arr4[0] = arr3[0]; arr4[1] = arr3[1]; arr4[2] = arr3[2]; arr4[3] = arr1[3]; Cv2.Merge(arr4, temp); this.phaseModel.mat = temp; this.documentWorkspace.Refresh();*/ this.gridView1SelectIndex = e.RowIndex; this.DrawConditionMat(); } } #region [脚本相关] private void getValue(string key, Object value) { switch (key) { case "parameter1": checkBox2.Checked = Convert.ToBoolean(value); break; case "parameter2": panel1.BackColor = Color.FromArgb(Convert.ToInt32(value)); break; case "parameter3": checkBox3.Checked = Convert.ToBoolean(value); break; case "parameter4": comboBox1.SelectedIndex = Convert.ToInt32(value); break; case "parameter5": panel3.BackColor = Color.FromArgb(Convert.ToInt32(value)); break; case "parameter6": comboBox2.SelectedIndex = Convert.ToInt32(value); break; case "parameter7": numericUpDown3.Value = Convert.ToDecimal(value); break; case "parameter8": numericUpDown2.Value = Convert.ToDecimal(value); break; case "parameter9": panel2.BackColor = Color.FromArgb(Convert.ToInt32(value)); break; case "parameter10": checkBox4.Checked = Convert.ToBoolean(value); break; case "parameter11": comboBox3.SelectedIndex = Convert.ToInt32(value); break; case "OpenWhileExportReport": checkBox1.Checked = Convert.ToBoolean(value); break; case "CalculatorDecimalDigits": numericUpDown1.Value = Convert.ToDecimal(value); break; case "ExportResults": isExportResults = Convert.ToBoolean(value); break; case "ExportReports": isExportReports = Convert.ToBoolean(value); break; case "ExportProjects": isExportProjects = Convert.ToBoolean(value); break; } } /// /// 执行脚本自动化的步骤 /// private void startScriptAutomaticAction() { if (isExportResults)//导出结果 this.button9.PerformClick(); if (isExportReports)//生成报告 this.button8.PerformClick(); if (isExportProjects)//导出项目 this.button3.PerformClick(); this.appWorkspace.ScriptAutomatic = false; this.Close(); } #endregion #region [脚本录制] private void getScriptRecording() { string className = InvariantData.path_Action + ".Action" + menuId; ParamObject param = (ParamObject)System.Reflection.Assembly.Load(InvariantData.assembly_Data).CreateInstance(className); List args = param.Lists; foreach (var item in args) { item.value = setScriptRecording(item.key); } appWorkspace.SetScriptStartRecording(this.menuId, menuName, args); } private object setScriptRecording(string key) { object value = null; switch (key) { case "parameter1": value = checkBox2.Checked; break; case "parameter2": value = panel1.BackColor.ToArgb(); break; case "parameter3": value = checkBox3.Checked; break; case "parameter4": value = comboBox1.SelectedIndex; break; case "parameter5": value = panel3.BackColor.ToArgb(); break; case "parameter6": value = comboBox2.SelectedIndex; break; case "parameter7": value = numericUpDown3.Value; break; case "parameter8": value = numericUpDown2.Value; break; case "parameter9": value = panel2.BackColor.ToArgb(); break; case "parameter10": value = checkBox4.Checked; break; case "parameter11": value = comboBox3.SelectedIndex; break; case "OpenWhileExportReport": value = checkBox1.Checked; break; case "CalculatorDecimalDigits": value = numericUpDown1.Value; break; case "ExportResults": value = isExportResults; break; case "ExportReports": value = isExportReports; break; case "ExportProjects": value = isExportProjects; break; } return value; } #endregion private void btn_SetUp_Click(object sender, EventArgs e) { DebrisCalipersSetDialog debrisCalipersSetDialog = new DebrisCalipersSetDialog(); debrisCalipersSetDialog.ShowDialog(); } } }