using OpenCvSharp; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.Functionodel; using PaintDotNet.CustomControl; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using PaintDotNet.DbOpreate.DbBll; using PaintDotNet.DbOpreate.DbModel; using PaintDotNet.Annotation; using PaintDotNet.Annotation.Enum; using OpenCvSharp.Extensions; using System.Drawing.Drawing2D; using PaintDotNet; using PaintDotNet.Base.SettingModel; using Point = System.Drawing.Point; using PaintDotNet.Data.Param; using PaintDotNet.Base; using PaintDotNet.DedicatedAnalysis.DuctileIron.Common; using PaintDotNet.GeneralAnalysis; using Metis.ParameterSet; namespace PaintDotNet.DedicatedAnalysis.DuctileIron.GBT9441_2009.GraphiteNumber { internal class SpheroidizationNumberDialog : PdnBaseForm { #region /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeLanguageText() { this.bc = new PaintDotNet.CustomControl.BinaryControl(); // // bc // this.bc.BinaryBackColor = System.Drawing.Color.Red; this.bc.BinaryChecked = false; this.bc.BinaryStyle = 1; this.bc.Location = new System.Drawing.Point(151, 59); this.bc.Name = "bc"; this.bc.OriginChecked = false; this.bc.scope1End = 0D; this.bc.scope1Start = 0D; this.bc.scope2End = 0D; this.bc.scope2Start = 0D; this.bc.scope3End = 0D; this.bc.scope3Start = 0D; this.bc.Size = new System.Drawing.Size(360, 292); this.bc.TabIndex = 37; this.Controls.Add(this.bc); this.Controls.SetChildIndex(this.bc, 0); this.groupBox9.Text = PdnResources.GetString("Menu.Analysisresult.text"); this.button5.Text = PdnResources.GetString("Menu.Exportproject.text"); this.label8.Text = PdnResources.GetString("Menu.Decimal.text") + ":"; this.button9.Text = PdnResources.GetString("Menu.Exportresults.text"); 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.groupBox8.Text = PdnResources.GetString("Menu.Theesultshow.text"); this.groupBox6.Text = PdnResources.GetString("Menu.paramssettings.text"); this.checkBox6.Text = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Particleshecalculation.text"); this.groupBox5.Text = PdnResources.GetString("Menu.Particlescreening.text"); this.label3.Text = PdnResources.GetString("Menu.range.text") + ":"; this.checkBox3.Text = PdnResources.GetString("Menu.filter.text"); this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBox2.Text = PdnResources.GetString("Menu.Tools.ImageIndex.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.btnSetUp.Text = PdnResources.GetString("Menu.Setting.Text"); this.groupBox10.Text = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Resultsetting.text"); this.checkBox5.Text = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.further.text"); this.checkBox4.Text = PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Integer.text"); this.Text = "GBT9441-2009(" + PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text") + ")"; this.button3.Text = PdnResources.GetString("Menu.File.SaveAll.Text"); this.button4.Text = PdnResources.GetString("Menu.Applyall.text"); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.groupBox9 = new System.Windows.Forms.GroupBox(); this.dataGridView3 = new System.Windows.Forms.DataGridView(); this.button5 = new System.Windows.Forms.Button(); this.label10 = new System.Windows.Forms.Label(); 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.groupBox8 = new System.Windows.Forms.GroupBox(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.checkBox6 = new System.Windows.Forms.CheckBox(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.trackBar4 = new System.Windows.Forms.TrackBar(); this.trackBar2 = new System.Windows.Forms.TrackBar(); this.numericUpDown5 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); this.label3 = new System.Windows.Forms.Label(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.listView1 = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button2 = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.btnSetUp = new System.Windows.Forms.Button(); this.groupBox10 = new System.Windows.Forms.GroupBox(); this.checkBox5 = new System.Windows.Forms.CheckBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.groupBox9.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); this.groupBox8.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox6.SuspendLayout(); this.groupBox5.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); this.groupBox2.SuspendLayout(); this.groupBox1.SuspendLayout(); this.groupBox10.SuspendLayout(); this.SuspendLayout(); // // 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.dataGridView3); this.groupBox9.Controls.Add(this.button5); this.groupBox9.Controls.Add(this.label10); 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(13, 735); this.groupBox9.Name = "groupBox9"; this.groupBox9.Size = new System.Drawing.Size(1192, 204); this.groupBox9.TabIndex = 34; this.groupBox9.TabStop = false; // // dataGridView3 // this.dataGridView3.AllowUserToAddRows = false; this.dataGridView3.AllowUserToDeleteRows = false; this.dataGridView3.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.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(228, 122); 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(793, 76); this.dataGridView3.TabIndex = 12; // // button5 // this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button5.Location = new System.Drawing.Point(1049, 108); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(128, 26); this.button5.TabIndex = 10; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // label10 // this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.label10.AutoSize = true; this.label10.ForeColor = System.Drawing.SystemColors.ScrollBar; this.label10.Location = new System.Drawing.Point(1027, 9); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(11, 192); this.label10.TabIndex = 9; this.label10.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|"; // // 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(1101, 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(1063, 167); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(0, 12); this.label8.TabIndex = 6; // // 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(1049, 71); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(128, 26); this.button9.TabIndex = 5; 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(1049, 34); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(128, 26); this.button8.TabIndex = 4; 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.None; this.dataGridView2.Location = new System.Drawing.Point(228, 15); this.dataGridView2.MultiSelect = false; this.dataGridView2.Name = "dataGridView2"; this.dataGridView2.RowHeadersVisible = false; this.dataGridView2.RowTemplate.Height = 23; this.dataGridView2.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView2.Size = new System.Drawing.Size(793, 102); 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(145, 20); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(52, 26); this.button7.TabIndex = 1; 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(93, 26); this.button6.TabIndex = 0; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // 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(154, 525); this.groupBox8.Name = "groupBox8"; this.groupBox8.Size = new System.Drawing.Size(357, 205); this.groupBox8.TabIndex = 33; this.groupBox8.TabStop = false; // // 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.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.Size = new System.Drawing.Size(344, 178); this.dataGridView1.TabIndex = 0; // // groupBox6 // this.groupBox6.Controls.Add(this.checkBox6); this.groupBox6.Location = new System.Drawing.Point(153, 426); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(358, 43); this.groupBox6.TabIndex = 32; this.groupBox6.TabStop = false; // // checkBox6 // this.checkBox6.AutoSize = true; this.checkBox6.Location = new System.Drawing.Point(18, 17); this.checkBox6.Name = "checkBox6"; this.checkBox6.Size = new System.Drawing.Size(15, 14); this.checkBox6.TabIndex = 11; this.checkBox6.UseVisualStyleBackColor = true; this.checkBox6.CheckedChanged += new System.EventHandler(this.checkBox6_CheckedChanged); // // groupBox5 // this.groupBox5.Controls.Add(this.trackBar4); this.groupBox5.Controls.Add(this.trackBar2); this.groupBox5.Controls.Add(this.numericUpDown5); this.groupBox5.Controls.Add(this.numericUpDown4); this.groupBox5.Controls.Add(this.label3); this.groupBox5.Controls.Add(this.checkBox3); this.groupBox5.Location = new System.Drawing.Point(153, 352); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(358, 65); this.groupBox5.TabIndex = 31; this.groupBox5.TabStop = false; // // trackBar4 // this.trackBar4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.trackBar4.AutoSize = false; this.trackBar4.Location = new System.Drawing.Point(193, 32); this.trackBar4.Maximum = 0; this.trackBar4.Name = "trackBar4"; this.trackBar4.Size = new System.Drawing.Size(89, 25); this.trackBar4.TabIndex = 15; this.trackBar4.TickStyle = System.Windows.Forms.TickStyle.None; // // trackBar2 // this.trackBar2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.trackBar2.AutoSize = false; this.trackBar2.Location = new System.Drawing.Point(106, 32); this.trackBar2.Maximum = 0; this.trackBar2.Name = "trackBar2"; this.trackBar2.Size = new System.Drawing.Size(89, 25); this.trackBar2.TabIndex = 14; this.trackBar2.TickStyle = System.Windows.Forms.TickStyle.None; // // numericUpDown5 // this.numericUpDown5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.numericUpDown5.Location = new System.Drawing.Point(285, 33); this.numericUpDown5.Maximum = new decimal(new int[] { 0, 0, 0, 0}); this.numericUpDown5.Name = "numericUpDown5"; this.numericUpDown5.Size = new System.Drawing.Size(62, 21); this.numericUpDown5.TabIndex = 12; // // numericUpDown4 // this.numericUpDown4.Location = new System.Drawing.Point(46, 33); this.numericUpDown4.Maximum = new decimal(new int[] { 0, 0, 0, 0}); this.numericUpDown4.Name = "numericUpDown4"; this.numericUpDown4.Size = new System.Drawing.Size(60, 21); this.numericUpDown4.TabIndex = 10; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(9, 37); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(0, 12); this.label3.TabIndex = 9; // // checkBox3 // this.checkBox3.AutoSize = true; this.checkBox3.Location = new System.Drawing.Point(30, 16); this.checkBox3.Name = "checkBox3"; this.checkBox3.Size = new System.Drawing.Size(15, 14); this.checkBox3.TabIndex = 0; this.checkBox3.UseVisualStyleBackColor = true; this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); // // 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(517, 61); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(688, 668); this.groupBox3.TabIndex = 29; this.groupBox3.TabStop = false; // // 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(13, 61); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(135, 669); this.groupBox2.TabIndex = 28; this.groupBox2.TabStop = false; // // 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, 646); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged); this.listView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDown); // // 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; // // 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.button3); this.groupBox1.Controls.Add(this.button4); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.checkBox1); this.groupBox1.Controls.Add(this.btnSetUp); this.groupBox1.Location = new System.Drawing.Point(13, 4); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(1192, 50); this.groupBox1.TabIndex = 27; this.groupBox1.TabStop = false; // // 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.Location = new System.Drawing.Point(1011, 14); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(84, 30); this.button2.TabIndex = 2; 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(15, 14); this.checkBox1.TabIndex = 1; this.checkBox1.UseVisualStyleBackColor = true; // // btnSetUp // this.btnSetUp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.btnSetUp.Location = new System.Drawing.Point(15, 14); this.btnSetUp.Name = "btnSetUp"; this.btnSetUp.Size = new System.Drawing.Size(84, 30); this.btnSetUp.TabIndex = 0; this.btnSetUp.UseVisualStyleBackColor = true; this.btnSetUp.Click += new System.EventHandler(this.btnSetUp_Click); // // groupBox10 // this.groupBox10.Controls.Add(this.checkBox5); this.groupBox10.Controls.Add(this.checkBox4); this.groupBox10.Location = new System.Drawing.Point(153, 479); this.groupBox10.Name = "groupBox10"; this.groupBox10.Size = new System.Drawing.Size(358, 43); this.groupBox10.TabIndex = 36; this.groupBox10.TabStop = false; // // checkBox5 // this.checkBox5.AutoSize = true; this.checkBox5.Location = new System.Drawing.Point(91, 17); this.checkBox5.Name = "checkBox5"; this.checkBox5.Size = new System.Drawing.Size(15, 14); this.checkBox5.TabIndex = 12; this.checkBox5.UseVisualStyleBackColor = true; this.checkBox5.CheckedChanged += new System.EventHandler(this.checkBox5_CheckedChanged); // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Location = new System.Drawing.Point(18, 17); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(15, 14); this.checkBox4.TabIndex = 11; this.checkBox4.UseVisualStyleBackColor = true; this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged); // // 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(1101, 14); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(84, 30); this.button3.TabIndex = 17; this.button3.Text = "保存全部"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button4.Location = new System.Drawing.Point(921, 14); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(84, 30); this.button4.TabIndex = 16; this.button4.Text = "应用全部"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // SpheroidizationNumberDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1218, 943); this.Controls.Add(this.groupBox10); this.Controls.Add(this.groupBox9); this.Controls.Add(this.groupBox8); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "SpheroidizationNumberDialog"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.InclusionsStandardDialog_FormClosing); this.Load += new System.EventHandler(this.GrainSizeDialog_Load); this.Shown += new System.EventHandler(this.ShownChoiseItemAndInitData); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.Controls.SetChildIndex(this.groupBox8, 0); this.Controls.SetChildIndex(this.groupBox9, 0); this.Controls.SetChildIndex(this.groupBox10, 0); this.groupBox9.ResumeLayout(false); this.groupBox9.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); this.groupBox8.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); this.groupBox2.ResumeLayout(false); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox10.ResumeLayout(false); this.groupBox10.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox9; private System.Windows.Forms.Label label10; private System.Windows.Forms.Label label9; private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.Label label8; private System.Windows.Forms.Button button9; private System.Windows.Forms.Button button8; private System.Windows.Forms.DataGridView dataGridView2; private System.Windows.Forms.ListView listView2; private System.Windows.Forms.Button button7; private System.Windows.Forms.Button button6; private System.Windows.Forms.GroupBox groupBox8; private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.GroupBox groupBox6; private System.Windows.Forms.CheckBox checkBox6; private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.TrackBar trackBar4; private System.Windows.Forms.TrackBar trackBar2; private System.Windows.Forms.NumericUpDown numericUpDown5; private System.Windows.Forms.NumericUpDown numericUpDown4; private System.Windows.Forms.Label label3; private System.Windows.Forms.CheckBox checkBox3; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.ListView listView1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button button2; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.Button btnSetUp; private System.Windows.Forms.GroupBox groupBox10; private System.Windows.Forms.CheckBox checkBox5; private System.Windows.Forms.CheckBox checkBox4; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.Button button5; private System.Windows.Forms.DataGridView dataGridView3; private CustomControl.BinaryControl bc; #endregion public static SpheroidizationNumberDialog spheroidizationNumberDialog; /// /// 调色板 /// PaintDotNet.ColorsForm colorsForm1; PaintDotNet.ColorsForm colorsForm2; /// /// 主控件 /// private AppWorkspace appWorkspace; /// /// 图像面板 /// public DocumentWorkspaceWindow documentWorkspace; /// /// 公共按钮 /// private CommonControlButtons commonControlButtons; /// /// 选中图片的bitmap /// private Bitmap bitmap; /// /// 计算结果的表格集合 /// 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; /// /// 二值处理后的mat /// private Mat binarizationMat; /// /// 相的集合 /// private PhaseModel phaseModel; /// /// 单位标尺-微米 /// private double unitLength = 1; /// /// 单位标尺-毫米 /// private double unitLengthMm = 1; /// /// 放大倍数 /// private double multiple = 1; /// /// 坐标集合 /// private List pointList = new List(); /// /// 绘制点 /// private List leList = new List(); /// /// 面积率 /// private double areaRatio = 0; /// /// 面积率最大值 /// double maxAreaRatio = 0; /// /// 面积率最小值 /// double minAreaRatio = 100; /// /// 平均直径 /// double avgDiameter = 0; /// /// 等积圆直径 /// double equalDiameter; /// /// 等积圆最大直径 /// double maxEqualDiameter; /// /// 等积圆最小直径 /// double minEqualDiameter; /// /// 直径集合 /// List lstEqualDiameter; /// /// 大于最大半径个数 /// double largeMaxRadiusSum; /// /// 大于最大半径平均直径 /// double largeMaxRadiusAvg; /// /// 存储面积率颜色字典 /// public Dictionary colour = new Dictionary(); // /// 存储字号与颜色字典 /// public Dictionary colourFont = new Dictionary(); /// /// 碳化物尺寸最大值 /// private double maxSize = 0; /// /// 是否仅修改相的颜色 /// private bool changeColor = false; /// /// 样式 /// GrainSizeGuideAreaMethodModel grainSizeGuideAreaMethodModel; /// /// 是否选择了图片 /// private bool selectPicture = false; GrainCutOffPointStyleModel grainCutOffPointStyleModel; /// /// 颜色(1) /// private int pointColor2; /// /// 线宽(1) /// private int pointWidth2; /// /// 点样式 0:空心 1:实心(1) /// private int pointStyle2; /// /// 大小(1) /// private int pointDiameter2; /// /// 截点误差(1) /// private int pointError2; /// /// 形状 0:圆形 1:方形(1) /// private int pointshape2; /// /// 是否未对图片做其他操作 /// private bool isFirstSwitch = false; /// /// 中间数据 /// private List tempDataModel = new List(); private bool needChange = true; private int defaultIndex = -1; private bool isExportResults = false; private bool isExportReports = false; private bool isExportProjects = false; /// /// 是否脚本运行 /// private Boolean initScriptValues = false; /// /// 保存窗口参数 /// /// /// 各个图片对应数据 /// private Dictionary eachData = new Dictionary(); private const string ParamKey_Report = "report";//报告设置 private const string ParamKey_Screen = "screen";//筛选 private const string ParamKey_ScreenMin = "screenMin";//面积最小值 private const string ParamKey_ScreenMax = "screenMax";//面积最大值 private const string ParamKey_Diameter = "diameter";//直径小于20um不参与计算 private const string ParamKey_Integer = "integer";//整数 private const string ParamKey_Further = "further";//进一 private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数 private decimal areaMin = -1;//面积最小 private decimal areaMax = -1;//面积最大 #region 二值化相关 ///// ///// 初始系统参数配置值 ///// //private BinaryExtractionModel binaryExtractionModel; ///// ///// 处理程序 ///// //private ParamObject action = new Data.Action.Action901(); /// /// 调色板 /// private ColorsForm colorsFormGrid; ///// ///// 参数下拉的集合 ///// //private List files = new List(); //二值化集成1 BinaryClass binaryClass; private Button button3; private Button button4; private int menuId; private string menuName; #endregion public SpheroidizationNumberDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) { this.menuId = menuItem.MenuId; this.menuName = menuItem.Text; binaryClass = new BinaryClass(menuId); spheroidizationNumberDialog = this; this.appWorkspace = appWorkspace; NullKey(); InitializeComponent(); InitializeLanguageText(); InitPicList(); InitOtherTools(); InitCommonButtonEvent(); InitGridHeader(); SetAnalyzeModelFromXml("Template.Manager.item3.DuctileIronGBT9441Number"); } private void ShowImgEvent(object sender, EventArgs e) { listView1.Focus(); if (this.defaultIndex != -1) { //如果是脚本执行,将参数带入 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); } appWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数 } else {//读取上次关闭窗口时保存的参数 GetXmlParameter(); GetListParamModel(); } this.listView1.Items[defaultIndex].Focused = true; this.listView1.Items[defaultIndex].Selected = true; if (this.initScriptValues && this.appWorkspace.ScriptAutomatic) this.startScriptAutomaticAction(); } } /// 更新截点样式 /// public void UpdateCupOffPointStyle() { grainCutOffPointStyleModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainCutOffPointStyleModel.xml", FileMode.Open)); //// 0.5截点 //this.pointColor1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointColor; //this.pointWidth1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointWidth; //this.pointStyle1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointStyle; //this.pointDiameter1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointDiameter; //this.pointError1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointError; //this.pointshape1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointshape; // 1截点 this.pointColor2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointColor; this.pointWidth2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointWidth; this.pointStyle2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointStyle; this.pointDiameter2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointDiameter; this.pointError2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointError; this.pointshape2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointshape; //// 1.5/2截点 //this.pointColor3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointColor; //this.pointWidth3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointWidth; //this.pointStyle3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointStyle; //this.pointDiameter3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointDiameter; //this.pointError3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointError; //this.pointshape3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointshape; this.documentWorkspace.Refresh(); } /// /// 初始化面积率颜色、字号颜色 /// //private void InitColour() //{ // colour.Add("panel6", Color.Orange); // colour.Add("panel5", Color.Blue); // colour.Add("panel4", Color.Green); // colour.Add("panel3", Color.Pink); // colour.Add("panel2", Color.Violet); // colour.Add("panel1", Color.Yellow); // colourFont.Add("9", Color.Black); //} /// /// 初始化表头 /// private void InitGridHeader() { // //结果展示表 // this.dataGridView1.ColumnHeadersHeight = 50; DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn(); h1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h1.Width = 110; DataGridViewTextBoxColumn h3 = new DataGridViewTextBoxColumn(); h3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h3.Width = 110; DataGridViewTextBoxColumn h4 = new DataGridViewTextBoxColumn(); h4.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h4.Width = 110; DataGridViewTextBoxColumn h5 = new DataGridViewTextBoxColumn(); h5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h5.Width = 110; this.dataGridView1.Columns.Add(h1); this.dataGridView1.Columns.Add(h3); this.dataGridView1.Columns.Add(h4); this.dataGridView1.Columns.Add(h5); DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1); helper.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.view.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, PdnResources.GetString("Menu.Graphitecontent.text")+"(%)")); helper.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text"))); helper.Headers.Add(new DataGridViewHelper.TopHeader(3, 1, PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF")); this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView1.Columns[0].ReadOnly = true; this.dataGridView1.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//文字居中 this.dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView1.Columns[1].ReadOnly = true; this.dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView1.Columns[2].ReadOnly = true; this.dataGridView1.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView1.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView1.Columns[3].ReadOnly = true; this.dataGridView1.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView1.AllowUserToResizeRows = false; this.dataGridView1.AllowUserToResizeColumns = false; // //分析结果表 // this.dataGridView2.ColumnHeadersHeight = 30; DataGridViewTextBoxColumn h6 = new DataGridViewTextBoxColumn(); //h6.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h6.Width = 150; DataGridViewTextBoxColumn h7 = new DataGridViewTextBoxColumn(); //h7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h7.Width = 150; DataGridViewTextBoxColumn h9 = new DataGridViewTextBoxColumn(); //h9.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h9.Width = 150; DataGridViewTextBoxColumn h10 = new DataGridViewTextBoxColumn(); //h10.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h10.Width = 150; DataGridViewTextBoxColumn h11 = new DataGridViewTextBoxColumn(); //h11.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h11.Width = 150; this.dataGridView2.Columns.Add(h6); this.dataGridView2.Columns.Add(h7); this.dataGridView2.Columns.Add(h9); this.dataGridView2.Columns.Add(h10); this.dataGridView2.Columns.Add(h11); DataGridViewHelper helper2 = new DataGridViewHelper(this.dataGridView2); helper2.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.picture.Text"))); helper2.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, PdnResources.GetString("Menu.view.text"))); helper2.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, PdnResources.GetString("Menu.Graphitecontent.text")+"(%)")); helper2.Headers.Add(new DataGridViewHelper.TopHeader(3, 1, PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text"))); helper2.Headers.Add(new DataGridViewHelper.TopHeader(4, 1, PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF")); this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView2.Columns[0].ReadOnly = true; this.dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView2.Columns[1].ReadOnly = true; this.dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView2.Columns[2].ReadOnly = true; this.dataGridView2.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView2.Columns[3].ReadOnly = true; this.dataGridView2.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView2.Columns[4].ReadOnly = true; this.dataGridView2.AllowUserToResizeRows = false; this.dataGridView2.AllowUserToResizeColumns = false; this.dataGridView3.ColumnHeadersHeight = 30; DataGridViewTextBoxColumn h12 = new DataGridViewTextBoxColumn(); //h12.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h12.Width = 150; DataGridViewTextBoxColumn h13 = new DataGridViewTextBoxColumn(); //h13.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h13.Width = 150; DataGridViewTextBoxColumn h15 = new DataGridViewTextBoxColumn(); //h15.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h15.Width = 150; DataGridViewTextBoxColumn h16 = new DataGridViewTextBoxColumn(); //h16.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h16.Width = 150; DataGridViewTextBoxColumn h17 = new DataGridViewTextBoxColumn(); //h17.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; h17.Width = 150; this.dataGridView3.Columns.Add(h12); this.dataGridView3.Columns.Add(h13); this.dataGridView3.Columns.Add(h15); this.dataGridView3.Columns.Add(h16); this.dataGridView3.Columns.Add(h17); DataGridViewHelper helper3 = new DataGridViewHelper(this.dataGridView3); helper3.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.picture.Text"))); helper3.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, PdnResources.GetString("Menu.view.text"))); helper3.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, PdnResources.GetString("Menu.Graphitecontent.text")+"(%)")); helper3.Headers.Add(new DataGridViewHelper.TopHeader(3, 1, PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text"))); helper3.Headers.Add(new DataGridViewHelper.TopHeader(4, 1, PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF")); this.dataGridView3.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[0].ReadOnly = true; this.dataGridView3.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[1].ReadOnly = true; this.dataGridView3.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[2].ReadOnly = true; this.dataGridView3.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[3].ReadOnly = true; this.dataGridView3.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable; this.dataGridView3.Columns[4].ReadOnly = true; this.dataGridView3.AllowUserToResizeRows = false; this.dataGridView3.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); } /// /// 初始化画布按键功能 /// 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) { this.documentWorkspace.ZoomIn(); } private void zoomOutButton_Click(object sender, EventArgs e) { 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 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.documentWorkspace.panel.MouseDown += null; this.documentWorkspace.panel.Paint += Panel_Paint; this.documentWorkspace.panel.MouseMove += null; this.documentWorkspace.panel.MouseUp += null; //this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click); // //初始化操作按钮 // this.commonControlButtons = new CommonControlButtons(); this.commonControlButtons.Dock = DockStyle.Top; this.commonControlButtons.Height = 30; this.commonControlButtons.HideZoomToWindowAndActualSize(); this.commonControlButtons.Visible = false; this.groupBox3.Controls.Add(commonControlButtons); //二值化集成2 bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件 binaryClass.createDocumentItems(new string[] { PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"), PdnResources.GetString("Menu.Particlescreening.text") } , this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构 binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件 // //调色板 // //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.colorsForm1 = new ColorsForm(); this.colorsForm1.StartPosition = FormStartPosition.CenterScreen; this.colorsForm1.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); // //颜色panel给定初始值 // //this.panel1.BackColor = Color.Red; //// ////获取系统标尺-微米 //// //this.appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Micron, out unitLength); //// ////获取系统标尺-毫米 //// //this.appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLengthMm); // //获取系统标尺-放大倍数 // if (this.documentWorkspace.GetGainMultiple() != 0) { multiple = double.Parse(this.documentWorkspace.GetGainMultiple().ToString()); } } //二值化集成3 #region 二值化相关方法 private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e) { #region [开启脚本录制] if (appWorkspace.startScriptRecording) { getScriptRecording(); } #endregion this.saveDialogParamValues(); binaryClass.saveParams(); //xml保存路径 string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml"; GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open)); foreach (var analysisItem in this.eachData[GetImgKey()].ListParam) { bool foundItem = false; foreach (var item in analysisModelXml.ListParam) { if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId) { item.param_value = analysisItem.param_value; foundItem = true; break; } } if (!foundItem) analysisModelXml.ListParam.Add(analysisItem.cloneModel()); } //按路径和名称保存xml文件 string userInfoXml = XmlSerializeHelper.XmlSerialize(analysisModelXml); //保存xml FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create); } private void ShownChoiseItemAndInitData(object sender, EventArgs e) { binaryClass.RefreshHistogramControl1Values(); } /// /// 添加参数改变的监听 /// /// /// private void GrainSizeDialog_Load(object sender, EventArgs e) { this.binaryClass.loadParams(); if (this.initScriptValues && this.appWorkspace.ScriptAutomatic) this.startScriptAutomaticAction(); } private bool bcBinaryChecked() { return bc != null && bc.BinaryChecked; } private bool bcOriginChecked() { return bc != null && bc.OriginChecked; } /// /// Panel2的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { this.colorsForm1.Close(); changeColor = true; //ReLoadBinarization(); this.documentWorkspace.Refresh(); } /// /// 参数改变时,重新处理图像 /// /// /// private void bClassBinaryImplFinishAction(object sender, EventArgs e) { if (phaseModel != null) { sum++; this.documentWorkspace.PhaseModels[0].choise = false; if (bcBinaryChecked()) { if (bcOriginChecked()) { phaseModel.choise = false; } else { phaseModel.choise = true; } binarizationMat = this.documentWorkspace.PhaseModels[0].mat; //changeColor = false; ResetAreaAndContent(); ReloadDebrisSelection(); //appCommonDisplay.DisplayData(this.dataGridView1, true); } else { phaseModel.choise = false; appCommonDisplay.DisplayData(this.dataGridView1, false); } this.documentWorkspace.Refresh(); } else { //MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); } } AppCommon appCommonDisplay = new AppCommon(); /// /// 显示原图/原图+二值图 /// /// /// private void bcOriginCheckedChanged(object sender, EventArgs e) { if (phaseModel != null) { this.documentWorkspace.PhaseModels[0].choise = false; if (!bcBinaryChecked()) { phaseModel.choise = false; appCommonDisplay.DisplayData(this.dataGridView1, false); } else { if (bcOriginChecked()) { phaseModel.choise = false; appCommonDisplay.DisplayData(this.dataGridView1, false); } else { phaseModel.choise = true; appCommonDisplay.DisplayData(this.dataGridView1, true); } } this.documentWorkspace.Refresh(); } else { //MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); } } #endregion /// /// 初始化图片列表数据 /// 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 btnColour_Click(object sender, EventArgs e) { ColorSetting colorSetting = new ColorSetting(); colorSetting.ShowDialog(); } /// /// 显示参数设置按钮 /// /// /// private void btnDisplay_Click(object sender, EventArgs e) { DisplaySetting displaySetting = new DisplaySetting(); displaySetting.ShowDialog(); } /// /// 设置按钮 /// /// /// private void btnSetUp_Click(object sender, EventArgs e) { AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, "Template.Manager.item3.DuctileIronGBT9441Number"); if (metallographicMethodSetDialog.hasModule) { metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen; metallographicMethodSetDialog.ShowDialog(); } else { metallographicMethodSetDialog = null; } } /// /// 图像索引切换选中事件 /// /// /// double picArea = 0;//图片面积 int sum; private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected) { //获取标尺-微米 unitLength = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron); //获取标尺-毫米 unitLengthMm = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Millimeter); GetListParamModel(); sum = 0; this.selectPicture = true; this.dataGridView1.Rows.Clear(); if (this.documentWorkspace.PhaseModels.Count > 1) this.documentWorkspace.PhaseModels.Remove(this.documentWorkspace.PhaseModels[1]); this.commonControlButtons.Visible = true; this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList; this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); //总面积 picArea = AnalysisTools.GetPointsFromMat(BitmapConverter.ToMat(this.bitmap)); changeColor = false; phaseModel = new PhaseModel();//同上 phaseModel.choise = true; //二值化集成4 binaryClass.listView1_SelectedIndexChangedNoCheckedChanged(this.bitmap, this.imageList1.Images.Keys[this.listView1.FocusedItem.Index]); this.documentWorkspace.PhaseModels[0].choise = false; if (binaryClass.getModelMat(this.imageList1.Images.Keys[this.listView1.FocusedItem.Index]) != null) { this.binarizationMat = binaryClass.getModelMat(this.imageList1.Images.Keys[this.listView1.FocusedItem.Index]).Clone(); } else { if (this.documentWorkspace.PhaseModels[0].mat == null) { this.binarizationMat = new Mat(); } else { this.binarizationMat = this.documentWorkspace.PhaseModels[0].mat.Clone(); } } this.documentWorkspace.phaseModels.Add(phaseModel); if (sum == 0) { if (bcOriginChecked() || !bcBinaryChecked()) { phaseModel.choise = false; } ResetAreaAndContent(); ReloadDebrisSelection(); } else { if (bcOriginChecked() || !bcBinaryChecked()) { phaseModel.choise = false; } else { phaseModel.choise = true; } this.documentWorkspace.Refresh(); } sum = 0; } } Mat temp;//中间变量 List> ps;//需要过滤的轮廓的拓扑信息 List psCircular = null;//轮廓的拓扑信息 OpenCvSharp.Point[][] contours;//原始轮廓信息 double totalSum; //石墨总数 DataTable dtDataGridView1 = null; DataTable dtResult = null; AppCommon appCommon = new AppCommon(); /// /// 刷新颗粒筛选颜色面积率效果 /// private void ReloadDebrisSelection() { if (binarizationMat != null && bcBinaryChecked()) { this.dataGridView1.Rows.Clear(); dtDataGridView1 = new DataTable(); lstEqualDiameter = new List(); ps = new List>();//需要过滤的轮廓的拓扑信息 psCircular = new List();// HierarchyIndex[] hierachy; pointList.Clear(); leList.Clear(); temp = new Mat(); if (this.documentWorkspace.GraphicsList.IsExsitView()) { List points = new List();//各石墨轮廓集合 List> lstAttribute = new List>();//各个视场属性集合,索引0-横坐标,1-纵坐标,2-视场宽度,3-视场高度,4-视场面积 int sumFieldl = 0; //视场个数 Mat tempCopy = BinaryClass.BGRA2GRAY(binarizationMat); //调用处理视场方法 appCommon.MultiFieldView(appWorkspace, binarizationMat, listView1, documentWorkspace, out points, out lstAttribute, out sumFieldl); //累计各参数和,算平均 double sumTotalSum = 0; double sumSpheroidizationAreaRate = 0; double sumNoduleNumber = 0; double sumNoduleNumberF = 0; int h = 0; foreach (OpenCvSharp.Point[][] contours in points) { h++; totalSum = 0;//单视场石墨总数 double totalAreaSum = 0;//单视场石墨面积总数 for (int i = 0; i < contours.Length; i++) { for (int f = 0; f < contours[i].Length; f++) { contours[i][f].X = contours[i][f].X + lstAttribute[h - 1][0]; contours[i][f].Y = contours[i][f].Y + lstAttribute[h - 1][1]; } double area = appCommon.Area(tempCopy, contours[i][0]); if (area == 0) { area = contours[i].Length; } equalDiameter = Math.Sqrt(area / Math.PI) * 2 * unitLength;//等积圆直径 if (this.checkBox3.Checked) { if (this.checkBox6.Checked) { if (equalDiameter < 20) { ps.Add(contours[i].ToList()); continue; } if (area >= (this.trackBar2.Value / (unitLength * unitLength)) && area <= (this.trackBar4.Value / (unitLength * unitLength))) { ps.Add(contours[i].ToList()); } else { if (contours[i].Length < 5) { continue; } else { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } } else { if (area >= (this.trackBar2.Value / (unitLength * unitLength)) && area <= (this.trackBar4.Value / (unitLength * unitLength))) { ps.Add(contours[i].ToList()); } else { if (contours[i].Length < 5) { continue; } else { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } } } else { if (this.checkBox6.Checked) { if (equalDiameter < 20) { ps.Add(contours[i].ToList()); } } if (contours[i].Length < 5) continue; else { if (this.checkBox6.Checked) { if (equalDiameter >= 20) { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } else { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } } } //ScopeProcessing(psCircular); double noduleNumberF = totalSum / (lstAttribute[h - 1][4] * unitLengthMm * unitLengthMm);//石墨球数nF double spheroidizationAreaRate = 100 * totalAreaSum / lstAttribute[h - 1][4];//石墨含量 this.dataGridView1.Rows.Add($"{PdnResources.GetString("Menu.view.text")}{h}", spheroidizationAreaRate, totalSum, noduleNumberF); sumTotalSum += totalSum; sumNoduleNumberF += noduleNumberF; sumSpheroidizationAreaRate += spheroidizationAreaRate; } if (sumFieldl > 1) { this.dataGridView1.Rows.Add(PdnResources.GetString("Menu.Image.Average.Text"), sumSpheroidizationAreaRate / sumFieldl, sumTotalSum / sumFieldl, sumNoduleNumberF / sumFieldl); } } else { Mat tempCopy = BinaryClass.BGRA2GRAY(binarizationMat); Cv2.FindContours(BinaryClass.BGRA2GRAY(binarizationMat), out contours, out hierachy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone); totalSum = 0;//单视场石墨总数 double totalAreaSum = 0;//单视场面积总数 lstEqualDiameter = new List(); for (int i = 0; i < hierachy.Length; i++) { if (hierachy[i].Parent == -1) { double area = appCommon.Area(tempCopy, contours[i][0]); if (area == 0) { area = contours[i].Length; } equalDiameter = Math.Sqrt(area / Math.PI) * 2 * unitLength;//等积圆直径 if (this.checkBox3.Checked) { if (this.checkBox6.Checked) { if (equalDiameter < 20) { ps.Add(contours[i].ToList()); continue; } if (area >= (this.trackBar2.Value / (unitLength * unitLength)) && area <= (this.trackBar4.Value / (unitLength * unitLength))) { ps.Add(contours[i].ToList()); } else { if (contours[i].Length < 5) { continue; } else { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } } else { if (area >= (this.trackBar2.Value / (unitLength * unitLength)) && area <= (this.trackBar4.Value / (unitLength * unitLength))) { ps.Add(contours[i].ToList()); } else { if (contours[i].Length < 5) { continue; } else { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } } } else { if (this.checkBox6.Checked) { if (equalDiameter < 20) { ps.Add(contours[i].ToList()); } } if (contours[i].Length < 5) continue; else { if (this.checkBox6.Checked) { if (equalDiameter >= 20) { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } else { OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); totalAreaSum += area; totalSum++; psCircular.Add(contours[i]); if (equalDiameter > 0) { lstEqualDiameter.Add(equalDiameter); } pointList.Add(contours[i][0]); leList.Add(double.Parse(equalDiameter.ToString("F2"))); } } } } } if (pointList.Count > 0) { double noduleNumberF = totalSum / (picArea * unitLengthMm * unitLengthMm);//石墨球数nF double spheroidizationAreaRate = 100 * totalAreaSum / picArea;//石墨含量 //ScopeProcessing(psCircular); this.dataGridView1.Rows.Add(PdnResources.GetString("Menu.view.text")+"1", spheroidizationAreaRate, totalSum, noduleNumberF); } } binarizationMat.CopyTo(temp); //筛选颜色 Cv2.FillPoly(temp, ps, new Scalar(0, 0, 0, 0)); phaseModel.mat = temp; //RefreshDataGridView1(); this.documentWorkspace.Refresh(); //数据结果保存 dtDataGridView1 = appCommon.ResultDataSaving(dataGridView1); string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName(); string tag = this.imageList1.Images.Keys[this.listView1.FocusedItem.Index]; //dtResult = new DataTable(tag); //分析数据保存 dtResult = appCommon.AnalysisDataSaving(this.dataGridView1, imgName, tag); if (dtDataGridView1.Rows.Count > 0) { RefreshDataGridView1(); } //原图判断 if (bcOriginChecked()) { appCommonDisplay.DisplayData(this.dataGridView1, false); } } } /// /// 添加内容单元格 /// /// /// /// private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag) { DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell(); textboxcell.Value = text; textboxcell.Tag = tag; return textboxcell; } /// /// 刷新其他信息 /// private void ResetAreaAndContent() { if (binarizationMat != null && bcBinaryChecked()) { OpenCvSharp.Point[][] contours;//原始轮廓信息 HierarchyIndex[] hierachy; Mat tempCopy = BinaryClass.BGRA2GRAY(binarizationMat); //Mat temp = new Mat(); //binarizationMat.CopyTo(temp); Cv2.FindContours(BinaryClass.BGRA2GRAY(binarizationMat), out contours, out hierachy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone); if (hierachy.Length > 0) { double maxArea = 0;//面积最大值 double minArea = 9999999999;//面积最小值 double area = 0; for (int i = 0; i < hierachy.Length; i++) { if (hierachy[i].Parent == -1) { area = appCommon.Area(tempCopy, contours[i][0]); if (maxArea < area) maxArea = area; if (minArea > area) minArea = area; } //if (contours[i].Length < 5) // continue; //else //{ // OpenCvSharp.RotatedRect rect = OpenCvSharp.Cv2.FitEllipse(contours[i]); //} } //phaseModel.mat = temp; if (!changeColor) { maxArea = maxArea * unitLength * unitLength; minArea = minArea * unitLength * unitLength; int maxNum = (int)Math.Ceiling(maxArea);//获取面积最大值 int minNum = (int)Math.Floor(minArea);//获取面积最小值 //先解绑事件以防数据赋值异常 this.numericUpDown4.ValueChanged -= numericUpDown4_ValueChanged; this.numericUpDown5.ValueChanged -= numericUpDown5_ValueChanged; this.trackBar2.Scroll -= trackBar2_Scroll; this.trackBar4.Scroll -= trackBar4_Scroll; this.numericUpDown4.Maximum = maxNum; this.numericUpDown4.Minimum = minNum; this.trackBar2.Maximum = maxNum; this.trackBar2.Minimum = minNum; this.numericUpDown5.Maximum = maxNum; this.numericUpDown5.Minimum = minNum; this.trackBar4.Maximum = maxNum; this.trackBar4.Minimum = minNum; this.numericUpDown4.Value = minNum; this.trackBar2.Value = minNum; this.numericUpDown5.Value = maxNum; this.trackBar4.Value = maxNum; if (areaMin != -1 && areaMin >= this.numericUpDown4.Minimum && areaMin <= this.numericUpDown5.Maximum) { trackBar2.Value = (int)areaMin; this.numericUpDown4.Value = areaMin; } if (areaMax != -1 && areaMax >= this.numericUpDown4.Value && areaMax <= this.numericUpDown5.Maximum) { trackBar4.Value = (int)areaMax; this.numericUpDown5.Value = areaMax; } this.numericUpDown4.ValueChanged += new EventHandler(numericUpDown4_ValueChanged); this.numericUpDown5.ValueChanged += new EventHandler(numericUpDown5_ValueChanged); this.trackBar2.Scroll += new EventHandler(trackBar2_Scroll); this.trackBar4.Scroll += new EventHandler(trackBar4_Scroll); //RefreshDataGridView1(); } } else { this.trackBar2.Maximum = 0; this.trackBar2.Minimum = 0; this.trackBar4.Maximum = 0; this.trackBar4.Minimum = 0; this.numericUpDown4.Maximum = 0; this.numericUpDown4.Minimum = 0; this.numericUpDown5.Maximum = 0; this.numericUpDown5.Minimum = 0; } } } ///// ///// 轮廓颜色 ///// ///// ///// //private void panel2_Click(object sender, EventArgs e) //{ // this.colorsForm2.UserPrimaryColor = ColorBgra.FromColor(this.panel1.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(); // changeColor = true; // ReloadDebrisSelection(); // //ReLoadBinarization(); // //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; RefreshDataGridView1(); RefreshDataGridView2(); } /// /// 是否筛选 /// /// /// private void checkBox3_CheckedChanged(object sender, EventArgs e) { if (this.documentWorkspace == null || this.documentWorkspace.CompositionSurface == null) return; ResetAreaAndContent(); ReloadDebrisSelection(); //if (this.checkBox10.Checked && this.checkBox3.Checked) // ReloadDebrisSelection(); //if (this.checkBox10.Checked && !this.checkBox3.Checked) //{ // ReloadDebrisSelection(); //} } /// /// 颗粒筛选范围最小值 /// /// /// private void numericUpDown4_ValueChanged(object sender, EventArgs e) { if (this.numericUpDown4.Value > this.numericUpDown5.Value) this.numericUpDown4.Value = this.numericUpDown5.Value; this.trackBar2.Value = Convert.ToInt32(this.numericUpDown4.Value); areaMin = this.numericUpDown4.Value; areaMax = this.numericUpDown5.Value; //二值判断 if (this.checkBox3.Checked && bcBinaryChecked() && !this.checkBox4.Checked) { ReloadDebrisSelection(); } if (this.checkBox3.Checked && bcBinaryChecked() && this.checkBox4.Checked) { ReloadDebrisSelection(); } } /// /// 颗粒筛选范围最大值 /// /// /// private void numericUpDown5_ValueChanged(object sender, EventArgs e) { if (this.numericUpDown5.Value < this.numericUpDown4.Value) this.numericUpDown5.Value = this.numericUpDown4.Value; this.trackBar4.Value = Convert.ToInt32(this.numericUpDown5.Value); areaMin = this.numericUpDown4.Value; areaMax = this.numericUpDown5.Value; //二值判断 if (this.checkBox3.Checked && bcBinaryChecked() && !this.checkBox4.Checked) { ReloadDebrisSelection(); } if (this.checkBox3.Checked && bcBinaryChecked() && this.checkBox4.Checked) { ReloadDebrisSelection(); } } /// /// 颗粒筛选最小值滚动条 /// /// /// private void trackBar2_Scroll(object sender, EventArgs e) { this.numericUpDown4.Value = this.trackBar2.Value; } /// /// 颗粒筛选最大值滚动条 /// /// /// private void trackBar4_Scroll(object sender, EventArgs e) { this.numericUpDown5.Value = this.trackBar4.Value; } /// /// 添加画布绑定事件 /// public void AddPictureBoxEvent() { this.documentWorkspace.panel.Paint -= new PaintEventHandler(this.Panel_Paint); this.documentWorkspace.panel.Paint += new PaintEventHandler(this.Panel_Paint); } //List pointFs = new List(); ///// ///// 停止绘制 ///// //private bool stop; ///// ///// 是否绘制 ///// //private bool canDraw = true; ///// ///// 直径 ///// //private double length; ///// ///// 圆心 ///// //private PointF center; ///// ///// 选中圆轮廓点集合 ///// //private List outlineLst; //float x = 0; //float y = 0; ///// ///// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点 ///// //private int pointKb = 0; ///// ///// 辅助计算偏移量-移动线两端的点 ///// //private PointF lastPoint = new PointF(0, 0); ///// ///// 辅助计算偏移量-移动线中间的点 ///// //private PointF tempPoint = new PointF(0, 0); ///// ///// 测量点 ///// //public List rectangleFList = new List(); ///// ///// 存储所有线的点集合 ///// //private List pointLst = new List(); ///// ///// 判断图形是否可移动 ///// //private bool canMove = false; ///// ///// 移动圆的哪一个点 ///// //private int movePointIndex = -1; ///// ///// 存储当前线的点集合 ///// //private PointF[] nowLine; ///// ///// 起止点 ///// //private System.Drawing.PointF startPoint, endPoint; ///// ///// 鼠标按下 ///// ///// ///// //private void Panel_MouseDown(object sender, MouseEventArgs e) //{ // if (operationK >= 0 && e.Button == MouseButtons.Left) // { // PointF downPoint = documentWorkspace.GetScalePoint(e.Location); // // 换算后的点 // if (operationK == 0) // { // pointLst.Clear(); // nowLine = new PointF[4]; // startPoint = endPoint = downPoint; // nowLine = new PointF[4]; // nowLine[0] = startPoint; // nowLine[1] = endPoint; // pointLst.Add(nowLine); // } // else if (operationK == 1) // { // lastPoint.X = downPoint.X; // lastPoint.Y = downPoint.Y; // tempPoint.X = downPoint.X; // tempPoint.Y = downPoint.Y; // for (int i = rectangleFList.Count - 1; i >= 0; i--) // { // Region a = null; // GraphicsPath path = new GraphicsPath(); // if (length > 0) // { // path.AddEllipse(new Rectangle((int)(center.X - (float)length / 2), (int)(center.Y - (float)length / 2), (int)length, (int)length)); // a = new Region(path); // if (a.IsVisible(downPoint.X, downPoint.Y) || new RectangleF(pointLst[0][0].X - 4, pointLst[0][0].Y - 4, 8, 8).Contains(downPoint) || new RectangleF(pointLst[0][1].X - 4, pointLst[0][1].Y - 4, 8, 8).Contains(downPoint)) // { // selected = i; // canMove = true; // this.documentWorkspace.panel.Cursor = Cursors.SizeAll; // } // else // { // selected = -1; // canMove = false; // this.documentWorkspace.panel.Cursor = Cursors.Default; // } // } // //if (rectangleFList[i].Contains(downPoint)) // //{ // // selected = i; // // canMove = true; // // this.documentWorkspace.panel.Cursor = Cursors.SizeAll; // //} // //else // //{ // // selected = -1; // // canMove = false; // // this.documentWorkspace.panel.Cursor = Cursors.Default; // //} // } // if (selected > -1) // { // if (new RectangleF(pointLst[0][0].X - 4, pointLst[0][0].Y - 4, 8, 8).Contains(downPoint)) // movePointIndex = 0; // else if (new RectangleF(pointLst[0][1].X - 4, pointLst[0][1].Y - 4, 8, 8).Contains(downPoint)) // movePointIndex = 1; // else // movePointIndex = -1; // } // if (canMove) // return; // } // } //} ///// 鼠标移动 ///// ///// ///// //private void Panel_MouseMove(object sender, MouseEventArgs e) //{ // // 换算后的点 // PointF movePoint = documentWorkspace.GetScalePoint(e.Location); // RectangleF pointF = new RectangleF(movePoint.X, movePoint.Y, 2, 2); // if (canMove) // { // Region a = null; // GraphicsPath path = new GraphicsPath(); // if (length > 0) // { // path.AddEllipse(new Rectangle((int)(center.X - (float)length / 2), (int)(center.Y - (float)length / 2), (int)length, (int)length)); // a = new Region(path); // if (a.IsVisible(movePoint.X, movePoint.Y)) // { // this.documentWorkspace.panel.Cursor = Cursors.SizeAll; // } // else // { // this.documentWorkspace.panel.Cursor = Cursors.Default; // } // //for (int i = rectangleFList.Count - 1; i >= 0; i--) // //{ // // if (rectangleFList[i].Contains(movePoint)) // // { // // this.documentWorkspace.panel.Cursor = Cursors.SizeAll; // // } // // else // // { // // this.documentWorkspace.panel.Cursor = Cursors.Default; // // } // //} // if (new RectangleF(pointLst[0][0].X - 4, pointLst[0][0].Y - 4, 8, 8).Contains(movePoint)) // { // this.documentWorkspace.panel.Cursor = Cursors.Cross; // } // else if (new RectangleF(pointLst[0][1].X - 4, pointLst[0][1].Y - 4, 8, 8).Contains(movePoint)) // { // this.documentWorkspace.panel.Cursor = Cursors.Cross; // } // } // } // if (operationK >= 0 && e.Button == MouseButtons.Left) // { // if (operationK == 0) // { // this.endPoint = movePoint; // pointLst[0][1] = endPoint; // } // else if (operationK == 1 && selected > -1) // { // float dx = movePoint.X - lastPoint.X; // float dy = movePoint.Y - lastPoint.Y; // float dxTemp = movePoint.X - tempPoint.X; // float dyTemp = movePoint.Y - tempPoint.Y; // lastPoint.X = movePoint.X; // lastPoint.Y = movePoint.Y; // if (movePointIndex == -1) // { // RectangleF rectangleF = new RectangleF(); // rectangleF = rectangleFList[selected]; // if (rectangleF.Contains(movePoint)) // this.documentWorkspace.panel.Cursor = Cursors.SizeAll; // rectangleF.X += dx; // rectangleF.Y += dy; // rectangleFList[selected] = rectangleF; // for (int i = 0; i < pointLst[selected].Count(); i++) // { // if (pointLst[selected][i] == PointF.Empty) // continue; // pointLst[selected][i].X += dx; // pointLst[selected][i].Y += dy; // } // } // else if (movePointIndex == 0) // { // pointLst[0][0].X += dx; // pointLst[0][0].Y += dy; // rectangleFList[0] = CalcOtherRectangle(pointLst[0][0], pointLst[0][1]); // } // else if (movePointIndex == 1) // { // pointLst[0][1].X += dx; // pointLst[0][1].Y += dy; // } // } // } // if (this.checkBox10.Checked && psCircular != null) // { // ReloadDebrisSelection(); // //ScopeProcessing(psCircular); // //RefreshDataGridView1(); // } // documentWorkspace.Refresh(); //} ///// ///// 鼠标抬起 ///// ///// ///// //private void Panel_MouseUp(object sender, MouseEventArgs e) //{ // rectangleFList.Clear(); // this.stop = false; // this.canDraw = false; // if (pointLst.Count > 0) // { // RectangleF rectangleF = CalcOtherRectangle(pointLst[0][0], pointLst[0][1]); // rectangleFList.Add(rectangleF); // } //} ///// ///// 计算外接矩形 ///// //private RectangleF CalcOtherRectangle(PointF p1, PointF p2) //{ // RectangleF rectangleF = new RectangleF(); // if (p1.X > p2.X) // rectangleF.X = p2.X; // else // rectangleF.X = p1.X; // if (p1.Y > p2.Y) // rectangleF.Y = p2.Y; // else // rectangleF.Y = p1.Y; // rectangleF.Width = Math.Abs(p2.X - p1.X); // rectangleF.Height = Math.Abs(p2.Y - p1.Y); // return new RectangleF(rectangleF.X - 4, rectangleF.Y - 4, rectangleF.Width + 8, rectangleF.Height + 8); //} ///// ///// 添加圆按钮 ///// ///// ///// //private void button1_Click(object sender, EventArgs e) //{ // //pointLst.Clear(); // operationK = 0; // selected = -1; // this.canDraw = true; // this.stop = true; // this.documentWorkspace.Refresh(); //} ///// ///// 0:添加 1:选择 2:删除 ///// //private int operationK = -1; ///// ///// 被选择的线 ///// //private int selected = -1; ///// ///// 选择圆按钮 ///// ///// ///// //private void button3_Click(object sender, EventArgs e) //{ // operationK = 1; //} //double noduleNumber; //石墨球数 //double noduleNumberF;//平方毫米内石墨球数 //List psCircularWithin;//园内石墨集合,包含与圆相切的石墨 ///// ///// 获取圆内信息 ///// //private void ScopeProcessing(List psCircular) //{ // List psCircularWithin = new List(); // noduleNumber = 0; // noduleNumberF = 0; // Region a = null; // GraphicsPath path = new GraphicsPath(); // if (length > 0) // { // path.AddEllipse(new Rectangle((int)(center.X - (float)length / 2), (int)(center.Y - (float)length / 2), (int)length, (int)length)); // a = new Region(path); // for (int i = 0; i < psCircular.Count; i++) // { // for (int j = 0; j < psCircular[i].Length; j++) // { // if (a.IsVisible(psCircular[i][j].X, psCircular[i][j].Y)) // { // psCircularWithin.Add(psCircular[i]); // break; // } // } // } // for (int i = 0; i < psCircularWithin.Count; i++) // { // int sum = 0; // for (int j = 0; j < psCircularWithin[i].Length; j++) // { // if (!a.IsVisible(psCircularWithin[i][j].X, psCircularWithin[i][j].Y)) // { // noduleNumber += 0.5; // break; // } // else // { // sum++; // } // } // if (psCircularWithin[i].Length == sum) // { // noduleNumber += 1; // } // } // double r = length * unitLengthMm / 2; // double circularArea = r * r * Math.PI; // noduleNumberF = noduleNumber / circularArea; // } //} /// /// 进一 /// /// /// private void checkBox5_CheckedChanged(object sender, EventArgs e) { if (this.checkBox5.Checked) { this.checkBox4.Checked = false; } RefreshDataGridView1(); RefreshDataGridView2(); } /// /// 取整 /// /// /// private void checkBox4_CheckedChanged(object sender, EventArgs e) { if (this.checkBox4.Checked) { this.checkBox5.Checked = false; } RefreshDataGridView1(); RefreshDataGridView2(); } /// /// 绘制事件 /// /// /// private void Panel_Paint(object sender, PaintEventArgs e) { if (this.documentWorkspace.CompositionSurface != null) { Rectangle rc = this.documentWorkspace.panel.ClientRectangle; int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio); int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio); int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2; int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2; e.Graphics.TranslateTransform(x, y); e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio); Draw(e.Graphics); e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio); e.Graphics.TranslateTransform(-x, -y); } } /// /// 绘制 /// private void Draw(Graphics graphics) { // 抗锯齿 graphics.SmoothingMode = SmoothingMode.AntiAlias; // 以下为绘制样式 //Pen linePen = new Pen(Color.FromArgb(this.panel2.BackColor.ToArgb()), int.Parse(this.numericUpDown6.Value.ToString())); //Pen borderUp = new Pen(Color.Black);//填充点外圈上 //Pen borderLower = new Pen(Color.Black);//填充点外圈下 //Pen borderLeft = new Pen(Color.Black);//填充点外圈上 //Pen borderRight = new Pen(Color.Black);//填充点外圈下 //// 圆形 //if (operationK == 0 && pointLst.Count > 0) //{ // // 判断位置 // PointF pointF = new PointF(this.pointLst[0][0].X, pointLst[0][0].Y); // PointF pointF1 = new PointF(this.pointLst[0][1].X, this.pointLst[0][1].Y); // // 直径 // this.length = BasicCalculationHelper.GetDistance(pointF, pointF1, 10); // double x = (pointF.X + pointF1.X) / 2; // double y = (pointF.Y + pointF1.Y) / 2; // // 圆心 // this.center = new PointF((float)x, (float)y); // this.outlineLst = new List(); // if (pointF.X != pointF1.X || pointF.Y != pointF1.Y) // graphics.DrawEllipse(linePen, center.X - (float)length / 2, center.Y - (float)length / 2, (float)length, (float)length); //} //if (operationK == 1 && pointLst.Count > 0) //{ // // 判断位置 // PointF pointF = new PointF(this.pointLst[0][0].X, pointLst[0][0].Y); // PointF pointF1 = new PointF(this.pointLst[0][1].X, this.pointLst[0][1].Y); // // 直径 // this.length = BasicCalculationHelper.GetDistance(pointF, pointF1, 10); // double x = (pointF.X + pointF1.X) / 2; // double y = (pointF.Y + pointF1.Y) / 2; // // 圆心 // this.center = new PointF((float)x, (float)y); // graphics.DrawEllipse(linePen, center.X - (float)length / 2, center.Y - (float)length / 2, (float)length, (float)length); // if (selected > -1) // { // graphics.DrawRectangle(borderUp, new Rectangle((int)(pointLst[0][0].X - 4), (int)(pointLst[0][0].Y - 4), 8, 8)); // graphics.DrawRectangle(borderUp, new Rectangle((int)(pointLst[0][1].X - 4), (int)(pointLst[0][1].Y - 4), 8, 8)); // //graphics.DrawRectangle(borderUp, new Rectangle((int)(center.X) - 4, (int)(center.Y- length / 2) - 4, 8, 8)); // //graphics.DrawRectangle(borderLower, new Rectangle((int)(center.X) - 4, (int)(center.Y + length / 2) - 4, 8, 8)); // //graphics.DrawRectangle(borderLeft, new Rectangle((int)(center.X - length / 2) - 4, (int)(center.Y ) - 4, 8, 8)); // //graphics.DrawRectangle(borderLeft, new Rectangle((int)(center.X + length / 2) - 4, (int)(center.Y) - 4, 8, 8)); // } //} } /// /// 等积圆直径小于20um的颗粒不参与计算 /// /// /// private void checkBox6_CheckedChanged(object sender, EventArgs e) { ReloadDebrisSelection(); } DialogResult dr; /// /// 保存结果 /// /// /// private void button2_Click(object sender, EventArgs e) { if (picArea == 0) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); return; } else { if (!bcBinaryChecked()) { MessageBox.Show(PdnResources.GetString("Menu.PleaseBinarize.text")+"!"); return; } } 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 && dataGridView1.Rows[0].Visible) { if (this.listView2.Items.Count > 0) { foreach (ListViewItem item in this.listView2.Items) { if (!blSaveAll && item.Name.Equals(tag)) { dr = MessageBox.Show(PdnResources.GetString("Menu.Theanalysisreertoreplaceit.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); break; } } foreach (ListViewItem item in this.listView2.Items) { if (item.Name.Equals(tag)) { if (dr == DialogResult.OK || blSaveAll) { replace = true; } else { return; } break; } } } //有重名需要替换 if (replace) { for (int i = 0; i < this.resultTableList.Count; i++) { if (this.resultTableList[i].TableName.Equals(tag)) { rowIndex = i; this.resultTableList.Remove(this.resultTableList[i]); if (this.pointList.Count > 0) { resultTableList.Insert(rowIndex, dtResult); } } } } 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; if (this.pointList.Count > 0) { resultTableList.Insert(rowIndex, dtResult); } } 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); Draw(graphics); if (bitDic.ContainsKey(tag)) bitDic[tag] = tempBit; else bitDic.Add(tag, tempBit); //拼接中间数据 List> dataList = new List>(); List columnName = new List(); columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text")); if (this.checkBox6.Checked) { columnName.Add(PdnResources.GetString("Menu.umisoproductcirclediameter.text")); } else { columnName.Add(PdnResources.GetString("Menu.Diameterofequalareacircle.text")); } dataList.Add(columnName); if (this.lstEqualDiameter.Count > 0) { for (int i = 0; i < this.lstEqualDiameter.Count; i++) { List strList = new List(); strList.Add((i + 1).ToString()); strList.Add(this.lstEqualDiameter[i].ToString()); dataList.Add(strList); } } bool isExist = false;//是否已存在进行替换 int modelIndex = -1;//要替换的下标 for (int j = 0; j < tempDataModel.Count; j++) { if (tempDataModel[j].tagName.Equals(tag)) { isExist = true; modelIndex = j; break; } } if (isExist && modelIndex > -1) tempDataModel[modelIndex].dataList = dataList; else { ExportProjectModel newModel = new ExportProjectModel(); newModel.tagName = tag; newModel.picName = imgName; newModel.dataList = dataList; tempDataModel.Add(newModel); } } else { MessageBox.Show(PdnResources.GetString("Menu.Nodatatosave.text")); } } } /// /// 刷新数据展示表 /// private void RefreshDataGridView1() { this.dataGridView1.Rows.Clear(); if (dtDataGridView1 != null && dtDataGridView1.Rows.Count > 0) { dataGridView1.Rows.Add(dtDataGridView1.Rows.Count);//增加同等数量的行数 int i = 0; foreach (DataRow row in dtDataGridView1.Rows)//逐个读取单元格的内容; { DataGridViewRow r1 = dataGridView1.Rows[i]; r1.Cells[0].Value = row.RowState.ToString(); for (int j = 0; j < dtDataGridView1.Columns.Count; j++) { if (j == 0) { r1.Cells[j].Value = row[j].ToString(); } else { if (j == 1 || j == 2 || j == 3) { if (this.checkBox4.Checked) { r1.Cells[j].Value = Math.Floor(double.Parse(row[j].ToString())); } else if (this.checkBox5.Checked) { r1.Cells[j].Value = Math.Ceiling(double.Parse(row[j].ToString())); } else if (!this.checkBox4.Checked && !this.checkBox5.Checked) { r1.Cells[j].Value = Math.Round(double.Parse(string.IsNullOrEmpty(row[j].ToString()) ? "0" : row[j].ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } else { r1.Cells[j].Value = Math.Round(double.Parse(string.IsNullOrEmpty(row[j].ToString()) ? "0" : row[j].ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } } i++; } } } /// /// 刷新分析结果表 /// private void RefreshDataGridView2() { //需要计算平均值的集合 List lstTotalSum = new List(); List lstSpheroidizationAreaRate = new List(); List lstNoduleNumber = new List(); List lstsumNoduleNumberF = new List(); //综合平均值 double avglstTotalSum = 0; double avglstSpheroidizationAreaRate = 0; double avglstNoduleNumber = 0; double avglstsumNoduleNumberF = 0; this.dataGridView2.Rows.Clear(); if (resultTableList.Count > 0) { dataGridView2.Rows.Clear(); dataGridView3.Rows.Clear(); if (this.showAll) { //dataGridView2.Rows.Clear(); int i = 0; for (int k = 0; k < resultTableList.Count; k++) { dataGridView2.Rows.Add(resultTableList[k].Rows.Count);//增加同等数量的行数 foreach (DataRow row in resultTableList[k].Rows)//逐个读取单元格的内容; { DataGridViewRow r1 = dataGridView2.Rows[i]; r1.Cells[0].Value = row.RowState.ToString(); for (int j = 0; j < resultTableList[k].Columns.Count; j++) { if (j == 0 || j == 1) { r1.Cells[j].Value = row[j].ToString(); } else { if (j == 2 || j == 3 || j == 4) { if (this.checkBox4.Checked) { r1.Cells[j].Value = Math.Floor(double.Parse(row[j].ToString())); } else if (this.checkBox5.Checked) { r1.Cells[j].Value = Math.Ceiling(double.Parse(row[j].ToString())); } else if (!this.checkBox4.Checked && !this.checkBox5.Checked) { r1.Cells[j].Value = Math.Round(double.Parse(string.IsNullOrEmpty(row[j].ToString()) ? "0" : row[j].ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } else { r1.Cells[j].Value = Math.Round(double.Parse(string.IsNullOrEmpty(row[j].ToString()) ? "0" : row[j].ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } //r1.Cells[j].Value = row[j]; if (!row[1].Equals(PdnResources.GetString("Menu.Image.Average.Text"))) { //if (j == 2) //{ // lstTotalSum.Add(double.Parse(row[j].ToString())); //} if (j == 2) { lstSpheroidizationAreaRate.Add(double.Parse(row[j].ToString())); } if (j == 3) { lstNoduleNumber.Add(double.Parse(row[j].ToString())); } if (j == 4) { lstsumNoduleNumberF.Add(double.Parse(row[j].ToString())); } } } i++; } } } else { //dataGridView2.Rows.Clear(); if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0) { int h = 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)) { dataGridView2.Rows.Add(dt.Rows.Count);//增加同等数量的行数 foreach (DataRow row in dt.Rows)//逐个读取单元格的内容; { DataGridViewRow r1 = dataGridView2.Rows[h]; r1.Cells[0].Value = row.RowState.ToString(); for (int j = 0; j < dt.Columns.Count; j++) { if (j == 0 || j == 1) { r1.Cells[j].Value = row[j].ToString(); } else { if (j == 2 || j == 3 || j == 4) { if (this.checkBox4.Checked) { r1.Cells[j].Value = Math.Floor(double.Parse(row[j].ToString())); } else if (this.checkBox5.Checked) { r1.Cells[j].Value = Math.Ceiling(double.Parse(row[j].ToString())); } else if (!this.checkBox4.Checked && !this.checkBox5.Checked) { r1.Cells[j].Value = Math.Round(double.Parse(string.IsNullOrEmpty(row[j].ToString()) ? "0" : row[j].ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } else { r1.Cells[j].Value = Math.Round(double.Parse(string.IsNullOrEmpty(row[j].ToString()) ? "0" : row[j].ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } //r1.Cells[j].Value = row[j]; if (!row[1].Equals(PdnResources.GetString("Menu.Image.Average.Text"))) { //if (j == 2) //{ // lstTotalSum.Add(double.Parse(row[j].ToString())); //} if (j == 2) { lstSpheroidizationAreaRate.Add(double.Parse(row[j].ToString())); } if (j == 3) { lstNoduleNumber.Add(double.Parse(row[j].ToString())); } if (j == 4) { lstsumNoduleNumberF.Add(double.Parse(row[j].ToString())); } } } h++; } } } } } } if (dataGridView2.Rows.Count > 0) { if (lstTotalSum.Count > 0) { avglstTotalSum = (double)lstTotalSum.Average(); } if (lstSpheroidizationAreaRate.Count > 0) { if (this.checkBox4.Checked) { avglstSpheroidizationAreaRate = Math.Floor((double)lstSpheroidizationAreaRate.Average()); } else if (this.checkBox5.Checked) { avglstSpheroidizationAreaRate = Math.Ceiling((double)lstSpheroidizationAreaRate.Average()); } else if (!this.checkBox4.Checked && !this.checkBox5.Checked) { avglstSpheroidizationAreaRate = Math.Round(double.Parse(string.IsNullOrEmpty(((double)lstSpheroidizationAreaRate.Average()).ToString()) ? "0" : ((double)lstSpheroidizationAreaRate.Average()).ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } if (lstNoduleNumber.Count > 0) { avglstNoduleNumber = (double)lstNoduleNumber.Average(); if (this.checkBox4.Checked) { avglstNoduleNumber = Math.Floor((double)lstNoduleNumber.Average()); } else if (this.checkBox5.Checked) { avglstNoduleNumber = Math.Ceiling((double)lstNoduleNumber.Average()); } else if (!this.checkBox4.Checked && !this.checkBox5.Checked) { avglstNoduleNumber = Math.Round(double.Parse(string.IsNullOrEmpty(((double)lstNoduleNumber.Average()).ToString()) ? "0" : ((double)lstNoduleNumber.Average()).ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } if (lstsumNoduleNumberF.Count > 0) { if (this.checkBox4.Checked) { avglstsumNoduleNumberF = Math.Floor((double)lstsumNoduleNumberF.Average()); } else if (this.checkBox5.Checked) { avglstsumNoduleNumberF = Math.Ceiling((double)lstsumNoduleNumberF.Average()); } else if (!this.checkBox4.Checked && !this.checkBox5.Checked) { avglstsumNoduleNumberF = Math.Round(double.Parse(string.IsNullOrEmpty(((double)lstsumNoduleNumberF.Average()).ToString()) ? "0" : ((double)lstsumNoduleNumberF.Average()).ToString()), Convert.ToInt32(this.numericUpDown1.Value)); } } this.dataGridView3.Rows.Add(PdnResources.GetString("Menu.comprehensive.text"), PdnResources.GetString("Menu.Comprehensivaverage.text"), avglstSpheroidizationAreaRate, avglstNoduleNumber, avglstsumNoduleNumberF); } } else { dataGridView2.Rows.Clear(); dataGridView3.Rows.Clear(); } } /// /// 生成报告 /// /// /// private void button8_Click(object sender, EventArgs e) { if (dataGridView2.Rows.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text")+"!"); return; } if (this.checkBox1.Checked) this.btnSetUp.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>(); List contentHead = new List(); contentHead.Add(PdnResources.GetString("Menu.picture.Text")); contentHead.Add(PdnResources.GetString("Menu.view.text")); contentHead.Add(PdnResources.GetString("Menu.Graphitecontent.text")+"(%)"); contentHead.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")); contentHead.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF"); ; analysisContent.Add(contentHead); foreach (DataGridViewRow item in this.dataGridView2.Rows) { List content = new List(); content.Add(item.Cells[0].Value.ToString()); content.Add(item.Cells[1].Value.ToString()); content.Add(item.Cells[2].Value.ToString()); content.Add(item.Cells[3].Value.ToString()); content.Add(item.Cells[4].Value.ToString()); analysisContent.Add(content); } analysisContent.Add(new List() { "\r" }); foreach (DataGridViewRow item in this.dataGridView3.Rows) { List content = new List(); content.Add(item.Cells[0].Value.ToString()); content.Add(item.Cells[1].Value.ToString()); content.Add(item.Cells[2].Value.ToString()); content.Add(item.Cells[3].Value.ToString()); content.Add(item.Cells[4].Value.ToString()); analysisContent.Add(content); } //图片 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]); } } } } this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos); } else MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!"); } /// /// 导出项目 /// /// /// private void button5_Click(object sender, EventArgs e) { if (dataGridView2.Rows.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text")+"!"); return; } if (this.checkBox1.Checked) this.btnSetUp.PerformClick(); if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify)) { Instrument.ProjectEngineering.NodeItem nodeItem = this.appWorkspace.GetInsertProjectPath(2, "Menu.DedicatedAnalysis.BlackMetal.DuctileIron.Text", this.analyzeSettingModel.savePath); if (nodeItem == null) return; //获取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>(); List contentHead = new List(); contentHead.Add(PdnResources.GetString("Menu.picture.Text")); contentHead.Add(PdnResources.GetString("Menu.view.text")); contentHead.Add(PdnResources.GetString("Menu.Graphitecontent.text")+"(%)"); contentHead.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")); contentHead.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF"); ; analysisContent.Add(contentHead); foreach (DataGridViewRow item in this.dataGridView2.Rows) { List content = new List(); content.Add(item.Cells[0].Value.ToString()); content.Add(item.Cells[1].Value.ToString()); content.Add(item.Cells[2].Value.ToString()); content.Add(item.Cells[3].Value.ToString()); content.Add(item.Cells[4].Value.ToString()); analysisContent.Add(content); } analysisContent.Add(new List() { "\r" }); foreach (DataGridViewRow item in this.dataGridView3.Rows) { List content = new List(); content.Add(item.Cells[0].Value.ToString()); content.Add(item.Cells[1].Value.ToString()); content.Add(item.Cells[2].Value.ToString()); content.Add(item.Cells[3].Value.ToString()); content.Add(item.Cells[4].Value.ToString()); analysisContent.Add(content); } //图片 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]); } } } } this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, tempDataModel, bitList, tagInfos, nodeItem.path, nodeItem.code); //保存项目信息到数据库 this.appWorkspace.InsertIntoDB(this.analyzeSettingModel, nodeItem); } else MessageBox.Show(PdnResources.GetString("Menu.Pleasesettheanalysisreportfirst.text")+"!"); } /// /// 导出结果 /// /// /// 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.CreatePrompt = true; exe.Title = "Export Excel File"; exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); exe.FileName = PdnResources.GetString("Menu.DedicatedAnalysis.BlackMetal.DuctileIron.Text")+"(GBT9441" + PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+ ")" + PdnResources.GetString("Menu.Analysisresult.text") + DateTime.Now.ToString("yyyyMMddHHmmss"); DialogResult dr = exe.ShowDialog(); if (dr != DialogResult.OK) return; DataTable dtb = new DataTable(); dtb.Columns.Add(PdnResources.GetString("Menu.picture.Text")); dtb.Columns.Add(PdnResources.GetString("Menu.view.text")); dtb.Columns.Add(PdnResources.GetString("Menu.Graphitecontent.text")+"(%)"); dtb.Columns.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")); dtb.Columns.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF"); for (int i = 0; i < this.dataGridView2.Rows.Count; i++) { DataRow dataRow = dtb.NewRow(); dataRow[PdnResources.GetString("Menu.picture.Text")] = this.dataGridView2.Rows[i].Cells[0].Value; dataRow[PdnResources.GetString("Menu.view.text")] = this.dataGridView2.Rows[i].Cells[1].Value; dataRow[PdnResources.GetString("Menu.Graphitecontent.text")+"(%)"] = this.dataGridView2.Rows[i].Cells[2].Value; dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")] = this.dataGridView2.Rows[i].Cells[3].Value; dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF"] = this.dataGridView2.Rows[i].Cells[4].Value; dtb.Rows.Add(dataRow); } for (int i = 0; i < this.dataGridView3.Rows.Count; i++) { DataRow dataRow = dtb.NewRow(); dataRow[PdnResources.GetString("Menu.picture.Text")] = this.dataGridView3.Rows[i].Cells[0].Value; dataRow[PdnResources.GetString("Menu.view.text")] = this.dataGridView3.Rows[i].Cells[1].Value; dataRow[PdnResources.GetString("Menu.Graphitecontent.text") + "(%)"] = this.dataGridView3.Rows[i].Cells[2].Value; dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")] = this.dataGridView3.Rows[i].Cells[3].Value; dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text") + "nF"] = this.dataGridView3.Rows[i].Cells[4].Value; dtb.Rows.Add(dataRow); } //DataTable dtb1 = new DataTable(); //dtb1.Columns.Add(PdnResources.GetString("Menu.picture.Text")); //dtb1.Columns.Add(PdnResources.GetString("Menu.view.text")); //dtb1.Columns.Add(PdnResources.GetString("Menu.Graphitecontent.text")+"(%)"); //dtb1.Columns.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")); //dtb1.Columns.Add(PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF"); //for (int i = 0; i < this.dataGridView3.Rows.Count; i++) //{ // DataRow dataRow = dtb1.NewRow(); // dataRow[PdnResources.GetString("Menu.picture.Text")] = this.dataGridView3.Rows[i].Cells[0].Value; // dataRow[PdnResources.GetString("Menu.view.text")] = this.dataGridView3.Rows[i].Cells[1].Value; // dataRow[PdnResources.GetString("Menu.Graphitecontent.text")+"(%)"] = this.dataGridView3.Rows[i].Cells[2].Value; // dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")] = this.dataGridView3.Rows[i].Cells[3].Value; // dataRow[PdnResources.GetString("Menu.Dedicatedanalysis.blackmetal.Graphitecount.text")+"nF"] = this.dataGridView3.Rows[i].Cells[4].Value; // dtb1.Rows.Add(dataRow); //} List list = new List(); list.Add(dtb); //list.Add(dtb1); this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, false, false, true); } else MessageBox.Show(PdnResources.GetString("Menu.Noanalysineratereport.text")+"!"); } private void listView2_SelectedIndexChanged(object sender, EventArgs e) { if (this.showAll) return; RefreshDataGridView2(); } /// /// 全部显示 /// /// /// 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(); } } } #region 参数保存及提取 /// /// 保存参数的key,value和type /// /// /// /// private void saveParamValue(string param_key, string param_value, int param_type) { bool foundItem = false; if (!this.eachData.ContainsKey(GetImgKey())) { GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel(); analysisItem.menuId = this.menuId; analysisItem.param_key = param_key; analysisItem.param_type = param_type; analysisItem.param_value = param_value; analysisItem.setValue(); analysisItem.ListParam = new List(); analysisItem.ListParam.Add(analysisItem); this.eachData.Add(GetImgKey(), analysisItem); } foreach (var item in this.eachData[GetImgKey()].ListParam) { if (item.param_key.Equals(param_key) && item.menuId == this.menuId) { item.param_value = param_value; item.setValue(); foundItem = true; break; } } if (!foundItem) { GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel(); analysisItem.menuId = this.menuId; analysisItem.param_key = param_key; analysisItem.param_type = param_type; analysisItem.param_value = param_value; analysisItem.setValue(); this.eachData[GetImgKey()].ListParam.Add(analysisItem); } } /// /// 保存界面中的参数到model /// private void saveDialogParamValues() { saveParamValue(ParamKey_Report, checkBox1.Checked ? "0" : "1", (int)PaintDotNet.Base.Dtryt.Boolean);//报告设置 saveParamValue(ParamKey_Screen, checkBox3.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//筛选 saveParamValue(ParamKey_ScreenMin, numericUpDown4 != null ? numericUpDown4.Value.ToString() : "", (int)Base.Dtryt.Decimal);//面积最小值 saveParamValue(ParamKey_ScreenMax, numericUpDown5 != null ? numericUpDown5.Value.ToString() : "", (int)Base.Dtryt.Decimal);//面积最大值 saveParamValue(ParamKey_Diameter, checkBox6.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//直径小于20um saveParamValue(ParamKey_Integer, checkBox4.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//整数 saveParamValue(ParamKey_Further, checkBox5.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//进一 saveParamValue(ParamKey_DecimalPlace, numericUpDown1 != null ? numericUpDown1.Value.ToString() : "", (int)Base.Dtryt.Decimal);//保留小数位数 } /// /// 获取保存的参数 /// private void GetListParamModel() { if (this.eachData.ContainsKey(GetImgKey()) && this.eachData[GetImgKey()] != null) { for (int i = 0; i < this.eachData[GetImgKey()].ListParam.Count; i++) { switch (this.eachData[GetImgKey()].ListParam[i].param_key) { case ParamKey_Report: checkBox1.Checked = (Boolean)this.eachData[GetImgKey()].ListParam[i].value; break; case ParamKey_Screen: checkBox3.Checked = (Boolean)this.eachData[GetImgKey()].ListParam[i].value; break; case ParamKey_ScreenMin: areaMin = decimal.Parse(this.eachData[GetImgKey()].ListParam[i].param_value); break; case ParamKey_ScreenMax: areaMax = decimal.Parse(this.eachData[GetImgKey()].ListParam[i].param_value); break; case ParamKey_Diameter: checkBox6.Checked = (Boolean)this.eachData[GetImgKey()].ListParam[i].value; break; case ParamKey_Integer: checkBox4.Checked = (Boolean)this.eachData[GetImgKey()].ListParam[i].value; break; case ParamKey_Further: checkBox5.Checked = (Boolean)this.eachData[GetImgKey()].ListParam[i].value; break; case ParamKey_DecimalPlace: numericUpDown1.Value = decimal.Parse(this.eachData[GetImgKey()].ListParam[i].param_value); break; } } } } /// /// 获取XML保存的参数 /// private void GetXmlParameter() { string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml"; GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open)); for (int i = 0; i < listView1.Items.Count; i++) { if (this.eachData.ContainsKey(listView1.Items[i].Index.ToString())) { this.eachData[listView1.Items[i].Index.ToString()] = analysisModelXml.cloneListParamModel(this.menuId); } else { this.eachData.Add(listView1.Items[i].Index.ToString(), analysisModelXml.cloneListParamModel(this.menuId)); } } foreach (var item in this.eachData[GetImgKey()].ListParam) item.setValue(); } /// /// 保存参数,防止没有图片 /// private void NullKey() { GrainSizeAnalysisModel grainsizeanalysismodel = new GrainSizeAnalysisModel(); grainsizeanalysismodel.ListParam = new List(); this.eachData.Add("null", grainsizeanalysismodel); } private string GetImgKey() { string key = this.listView1.FocusedItem != null ? this.listView1.FocusedItem.Index.ToString() : "null"; return key; } #endregion private void button4_Click(object sender, EventArgs e) { if (this.listView1.FocusedItem == null) { return; } binaryClass.saveParams(); binaryClass.applyToAll(this.imageList1.Images.Keys, this.imageList1.Images.Keys[int.Parse(GetImgKey())]); saveDialogParamValues(); GrainSizeAnalysisModel data = new GrainSizeAnalysisModel(); if (eachData.ContainsKey(GetImgKey())) { data = eachData[GetImgKey()]; } for (int i = 0; i < listView1.Items.Count; i++) { eachData[i.ToString()] = data.cloneListParamModel(this.menuId); this.listView1.EnsureVisible(i); this.listView1.Items[i].Focused = true; this.listView1.Items[i].Selected = true; } } private bool blSaveAll = false; private void button3_Click(object sender, EventArgs e) { if (this.listView1.FocusedItem == null) { return; } if (eachData.Count - 1 != listView1.Items.Count) { MessageBox.Show("请先点击应用全部!"); return; } saveDialogParamValues(); int current = int.Parse(GetImgKey()); for (int i = 0; i < listView1.Items.Count; i++) { this.listView1.EnsureVisible(i); this.listView1.Items[i].Focused = true; this.listView1.Items[i].Selected = true; this.button2.PerformClick(); blSaveAll = true; } this.listView1.EnsureVisible(current); this.listView1.Items[current].Focused = true; this.listView1.Items[current].Selected = true; blSaveAll = false; } private void listView1_MouseDown(object sender, MouseEventArgs e) { if (this.listView1.FocusedItem != null) saveDialogParamValues(); } #region [脚本相关] private void getValue(string key, object value) { switch (key) { case "parameter1": checkBox3.Checked = Convert.ToBoolean(value); break; case "parameter2": int min = Convert.ToInt32(value); decimal minDec = Convert.ToDecimal(value); if (bcBinaryChecked()) { if (trackBar2.Minimum > min || trackBar2.Maximum < min) { trackBar2.Value = trackBar2.Minimum; } else { trackBar2.Value = min; } if (numericUpDown4.Minimum > min || numericUpDown4.Maximum < min) { numericUpDown4.Value = numericUpDown4.Minimum; } else { numericUpDown4.Value = minDec; } } break; case "parameter3": int max = Convert.ToInt32(value); decimal maxDec = Convert.ToDecimal(value); if (bcBinaryChecked()) { if (trackBar4.Minimum > max || trackBar4.Maximum < max) { trackBar4.Value = trackBar4.Maximum; } else { trackBar4.Value = max; } if (numericUpDown5.Minimum > max || numericUpDown5.Maximum < max) { numericUpDown5.Value = numericUpDown5.Maximum; } else { numericUpDown5.Value = maxDec; } } break; case "parameter4": checkBox6.Checked = Convert.ToBoolean(value); break; case "parameter5": checkBox4.Checked = Convert.ToBoolean(value); break; case "parameter6": if (Convert.ToBoolean(value)) { if (!checkBox4.Checked) { checkBox5.Checked = Convert.ToBoolean(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() { this.button4.PerformClick(); this.button3.PerformClick(); this.button6.Text = PdnResources.GetString("Menu.Cancelshowall.text"); this.showAll = true; RefreshDataGridView2(); if (isExportResults)//导出结果 this.button9.PerformClick(); if (isExportReports)//生成报告 this.button8.PerformClick(); if (isExportProjects)//导出项目 this.button5.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); } //找出二值相关参数 进行赋值 List isNullList = args.Where(m => m.value == null).ToList(); foreach (var item in isNullList) { item.value = binaryClass.setScriptRecording(item.key); } appWorkspace.SetScriptStartRecording(this.menuId, menuName, args); } private object setScriptRecording(string key) { object value = null; switch (key) { case "parameter1": value = checkBox3.Checked; break; case "parameter2": value = trackBar2.Value; break; case "parameter3": value = trackBar4.Value; break; case "parameter4": value = checkBox6.Checked; break; case "parameter5": value = checkBox4.Checked; break; case "parameter6": value = checkBox5.Checked; 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 } }