using OpenCvSharp; using PaintDotNet.Base.SettingModel; using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using GroupBox = System.Windows.Forms.GroupBox; using CheckBox = System.Windows.Forms.CheckBox; using Button = System.Windows.Forms.Button; using System.Data; using PaintDotNet.Base.CommTool; using System.Drawing.Drawing2D; using PaintDotNet.Annotation.Enum; namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.ManualMethod { internal class MethodCutOffDialog : GrainSizeStandardDialog { /// /// 调色板 /// private ColorsForm colorsFormGrid; private Panel panelC; /// /// 鼠标状态(0:添加 1:删除 2:选择) /// private int mouseStatus = -1; /// /// 测量线类型(0:全方位 1:水平 2:垂直) /// private int lineStyle = 0; /// /// 线条矩形 /// private Dictionary rectangleFsLines = new Dictionary(); private int selectLineIndex = -1; private PointF movePointStart; bool canMove = false; int movePointIndex = -1; bool canAdd = false; private int defaultIndex = -1; private bool canChange = false; /// /// 标尺 /// private double unitLength; /// /// 数据展示 /// private DataTable dataTable; /// /// 存在视场标记 /// private bool existViewFlag = false; /// /// 线条绘制点矩形集合 /// private Dictionary rectangleFs = new Dictionary(); /// /// 线条绘制点矩形 /// private RectangleF[] rectangleFsArr = new RectangleF[2]; /// /// 线条矩形 /// private PointF[] pointFsLine = new PointF[4]; /// /// 测定结果暂存 /// private List dataTable1s = new List(); /// /// 储存点击保存结果后的所有原图与分析图 /// private Dictionary> bitCeDingDic = new Dictionary>(); protected static string ParamKey_MainFontSize = "MainFontSize";//字号 protected static string ParamKey_MainFontColor = "MainFontColor"; // 字体颜色 protected static string ParamKey_MainLineWidth = "MainLineWidth"; protected static string ParamKey_MainLineColor = "MainLineColor"; #region 组件 private GroupBox groupBox11; private CheckBox checkBox3_0; private DataGridViewTextBoxColumn ColumnTotal1; private DataGridViewTextBoxColumn ColumnTotal2; private DataGridViewTextBoxColumn ColumnTotal3; private DataGridViewTextBoxColumn ColumnTotal4; private DataGridViewTextBoxColumn ColumnTotal5; private DataGridViewTextBoxColumn ColumnTotal6; private DataGridViewTextBoxColumn Column1; private DataGridViewTextBoxColumn Column2; private DataGridViewTextBoxColumn Column3; private DataGridViewTextBoxColumn Column4; private DataGridViewTextBoxColumn Column5; private DataGridViewTextBoxColumn Graisize; private DataGridViewTextBoxColumn Grainnumber; private DataGridViewTextBoxColumn Grainintercept; private DataGridViewTextBoxColumn Graingrade; private GroupBox groupBox1; private Button button10; private Button button7_0; private GroupBox groupBox2; private Label label4; private Label label3; private Label label5; private DataGridViewTextBoxColumn Column11; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5; private Label label8; private Label label7; private Label label6; private Label label1; private Panel panel2; private Panel panel1; private NumericUpDown numericUpDown3; private NumericUpDown numericUpDown4; private Button button2; private DataGridView dataGridView1; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn9; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn10; private Label labelNum; private Label labelMin; private Label labelMax; private DataGridViewTextBoxColumn Column6; #endregion 组件 #region 构造函数 public MethodCutOffDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) : base(appWorkspace, menuItem, null, 0) { // //初始化色板 // this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); getSonData(); } #endregion 构造函数 #region 初始化组件 private void InitializeComponentText() { //this.groupBox10.Text = PdnResources.GetString("Menu.sectionoperation.text"); } private void InitializeComponent() { System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); this.groupBox11 = new System.Windows.Forms.GroupBox(); this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); this.panel2 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel(); this.label8 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.checkBox3_0 = new System.Windows.Forms.CheckBox(); this.Graisize = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Grainnumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Grainintercept = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Graingrade = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button2 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); this.button7_0 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.labelNum = new System.Windows.Forms.Label(); this.labelMin = new System.Windows.Forms.Label(); this.labelMax = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn10 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox_img.SuspendLayout(); this.groupBox_analysisResult1.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox11.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // groupBox11 // this.groupBox11.Controls.Add(this.numericUpDown4); this.groupBox11.Controls.Add(this.numericUpDown3); this.groupBox11.Controls.Add(this.panel2); this.groupBox11.Controls.Add(this.panel1); this.groupBox11.Controls.Add(this.label8); this.groupBox11.Controls.Add(this.label7); this.groupBox11.Controls.Add(this.label6); this.groupBox11.Controls.Add(this.label1); this.groupBox11.Controls.Add(this.checkBox3_0); this.groupBox11.Location = new System.Drawing.Point(178, 364); this.groupBox11.Name = "groupBox11"; this.groupBox11.Size = new System.Drawing.Size(356, 83); this.groupBox11.TabIndex = 39; this.groupBox11.TabStop = false; // // numericUpDown4 // this.numericUpDown4.Location = new System.Drawing.Point(60, 37); this.numericUpDown4.Maximum = new decimal(new int[] { 9999, 0, 0, 0}); this.numericUpDown4.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown4.Name = "numericUpDown4"; this.numericUpDown4.Size = new System.Drawing.Size(55, 21); this.numericUpDown4.TabIndex = 30; this.numericUpDown4.Value = new decimal(new int[] { 20, 0, 0, 0}); // // numericUpDown3 // this.numericUpDown3.Location = new System.Drawing.Point(60, 59); this.numericUpDown3.Maximum = new decimal(new int[] { 9999, 0, 0, 0}); this.numericUpDown3.Minimum = new decimal(new int[] { 1, 0, 0, 0}); this.numericUpDown3.Name = "numericUpDown3"; this.numericUpDown3.Size = new System.Drawing.Size(55, 21); this.numericUpDown3.TabIndex = 29; this.numericUpDown3.Value = new decimal(new int[] { 1, 0, 0, 0}); // // panel2 // this.panel2.BackColor = System.Drawing.Color.Blue; this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel2.Location = new System.Drawing.Point(218, 60); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(49, 17); this.panel2.TabIndex = 28; this.panel2.Click += new System.EventHandler(this.panelC_Click); // // panel1 // this.panel1.BackColor = System.Drawing.Color.Yellow; this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel1.Location = new System.Drawing.Point(218, 39); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(49, 17); this.panel1.TabIndex = 27; this.panel1.Click += new System.EventHandler(this.panelC_Click); // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(147, 63); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(65, 12); this.label8.TabIndex = 8; this.label8.Text = "截距颜色:"; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(147, 42); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(65, 12); this.label7.TabIndex = 7; this.label7.Text = "字体颜色:"; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(13, 63); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(41, 12); this.label6.TabIndex = 6; this.label6.Text = "线宽:"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(13, 42); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(41, 12); this.label1.TabIndex = 5; this.label1.Text = "字号:"; // // checkBox3_0 // this.checkBox3_0.AutoSize = true; this.checkBox3_0.Checked = true; this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox3_0.Location = new System.Drawing.Point(15, 19); this.checkBox3_0.Name = "checkBox3_0"; this.checkBox3_0.Size = new System.Drawing.Size(15, 14); this.checkBox3_0.TabIndex = 0; this.checkBox3_0.UseVisualStyleBackColor = true; this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged); // // Graisize // this.Graisize.Name = "Graisize"; this.Graisize.ReadOnly = true; // // Grainnumber // this.Grainnumber.Name = "Grainnumber"; this.Grainnumber.ReadOnly = true; // // Grainintercept // this.Grainintercept.Name = "Grainintercept"; this.Grainintercept.ReadOnly = true; // // Graingrade // this.Graingrade.Name = "Graingrade"; this.Graingrade.ReadOnly = true; // // groupBox1 // this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button10); this.groupBox1.Controls.Add(this.button7_0); this.groupBox1.Location = new System.Drawing.Point(179, 315); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(356, 43); this.groupBox1.TabIndex = 40; this.groupBox1.TabStop = false; // // button2 // this.button2.BackColor = System.Drawing.SystemColors.Control; this.button2.Location = new System.Drawing.Point(215, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(95, 26); this.button2.TabIndex = 14; this.button2.UseVisualStyleBackColor = false; this.button2.Click += new System.EventHandler(this.button2_Click); // // button10 // this.button10.BackColor = System.Drawing.SystemColors.Control; this.button10.Location = new System.Drawing.Point(114, 12); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(95, 26); this.button10.TabIndex = 13; this.button10.UseVisualStyleBackColor = false; this.button10.Click += new System.EventHandler(this.button10_Click); // // button7_0 // this.button7_0.BackColor = System.Drawing.SystemColors.Control; this.button7_0.Location = new System.Drawing.Point(13, 12); this.button7_0.Name = "button7_0"; this.button7_0.Size = new System.Drawing.Size(95, 26); this.button7_0.TabIndex = 12; this.button7_0.UseVisualStyleBackColor = false; this.button7_0.Click += new System.EventHandler(this.button7_0_Click); this.button7_0.LostFocus += new System.EventHandler(this.button7_0_LostFocus); // // groupBox2 // this.groupBox2.Controls.Add(this.labelNum); this.groupBox2.Controls.Add(this.labelMin); this.groupBox2.Controls.Add(this.labelMax); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Location = new System.Drawing.Point(179, 446); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(356, 39); this.groupBox2.TabIndex = 41; this.groupBox2.TabStop = false; // // labelNum // this.labelNum.AutoSize = true; this.labelNum.Location = new System.Drawing.Point(309, 17); this.labelNum.Name = "labelNum"; this.labelNum.Size = new System.Drawing.Size(0, 12); this.labelNum.TabIndex = 7; // // labelMin // this.labelMin.AutoSize = true; this.labelMin.Location = new System.Drawing.Point(176, 17); this.labelMin.Name = "labelMin"; this.labelMin.Size = new System.Drawing.Size(0, 12); this.labelMin.TabIndex = 6; // // labelMax // this.labelMax.AutoSize = true; this.labelMax.Location = new System.Drawing.Point(57, 17); this.labelMax.Name = "labelMax"; this.labelMax.Size = new System.Drawing.Size(0, 12); this.labelMax.TabIndex = 5; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(13, 17); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 12); this.label5.TabIndex = 4; this.label5.Text = "最大:"; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(129, 17); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(41, 12); this.label4.TabIndex = 3; this.label4.Text = "最小:"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(262, 17); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(41, 12); this.label3.TabIndex = 2; this.label3.Text = "数量:"; // // Column11 // this.Column11.Name = "Column11"; // // dataGridViewTextBoxColumn1 // this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; // // dataGridViewTextBoxColumn2 // dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle1; this.dataGridViewTextBoxColumn2.HeaderText = "1"; this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; this.dataGridViewTextBoxColumn2.ReadOnly = true; this.dataGridViewTextBoxColumn2.Width = 50; // // dataGridViewTextBoxColumn3 // dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn3.DefaultCellStyle = dataGridViewCellStyle2; this.dataGridViewTextBoxColumn3.HeaderText = ".5"; this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; this.dataGridViewTextBoxColumn3.ReadOnly = true; this.dataGridViewTextBoxColumn3.Width = 50; // // dataGridViewTextBoxColumn4 // dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn4.DefaultCellStyle = dataGridViewCellStyle3; this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; this.dataGridViewTextBoxColumn4.ReadOnly = true; this.dataGridViewTextBoxColumn4.Width = 55; // // dataGridViewTextBoxColumn5 // dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn5.DefaultCellStyle = dataGridViewCellStyle4; this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5"; this.dataGridViewTextBoxColumn5.ReadOnly = true; this.dataGridViewTextBoxColumn5.Width = 69; // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle5; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewTextBoxColumn9, this.dataGridViewTextBoxColumn10}); this.dataGridView1.Location = new System.Drawing.Point(178, 487); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.Size = new System.Drawing.Size(356, 101); this.dataGridView1.TabIndex = 42; this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged); // // dataGridViewTextBoxColumn9 // dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn9.DefaultCellStyle = dataGridViewCellStyle6; this.dataGridViewTextBoxColumn9.Name = "dataGridViewTextBoxColumn9"; this.dataGridViewTextBoxColumn9.ReadOnly = true; this.dataGridViewTextBoxColumn9.Width = 111; // // dataGridViewTextBoxColumn10 // dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; this.dataGridViewTextBoxColumn10.DefaultCellStyle = dataGridViewCellStyle7; this.dataGridViewTextBoxColumn10.Name = "dataGridViewTextBoxColumn10"; this.dataGridViewTextBoxColumn10.ReadOnly = true; this.dataGridViewTextBoxColumn10.Width = 242; // // MethodCutOffDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(1127, 810); this.Controls.Add(this.dataGridView1); this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox11); this.KeyPreview = true; this.Name = "MethodCutOffDialog"; this.Load += new System.EventHandler(this.MethodCutOffDialog_Load); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MethodCutOffDialog_KeyDown); this.Controls.SetChildIndex(this.groupBox11, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0); this.Controls.SetChildIndex(this.groupBox_img, 0); this.Controls.SetChildIndex(this.groupBox_review, 0); this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0); this.Controls.SetChildIndex(this.groupBox_report, 0); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.dataGridView1, 0); this.groupBox_img.ResumeLayout(false); this.groupBox_analysisResult1.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox11.ResumeLayout(false); this.groupBox11.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); } #endregion 初始化组件 #region 需继承方法 /// /// 保存参数 /// protected override void saveSonData() { saveParamValue(ParamKey_displaygrainboundaries, checkBox3_0.Checked ? "0" : "1", (int)Base.Dtryt.Boolean); saveParamValue(ParamKey_MainFontSize, numericUpDown4.Value.ToString(), (int)Base.Dtryt.Interger); saveParamValue(ParamKey_MainFontColor, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Interger); saveParamValue(ParamKey_MainLineWidth, numericUpDown3.Value.ToString(), (int)Base.Dtryt.Interger); saveParamValue(ParamKey_MainLineColor, panel2.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Interger); } /// /// 获取参数 /// protected override void getSonData() { object ShowGrainBoundry; if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry)) checkBox3_0.Checked = Convert.ToInt32(ShowGrainBoundry) == 0 ? true : false; if (GetParamValue1(ParamKey_MainFontSize, out ShowGrainBoundry)) numericUpDown4.Value = Convert.ToInt32(ShowGrainBoundry); if (GetParamValue1(ParamKey_MainFontColor, out ShowGrainBoundry)) panel1.BackColor = Color.FromArgb(Convert.ToInt32(ShowGrainBoundry)); if (GetParamValue1(ParamKey_MainLineWidth, out ShowGrainBoundry)) numericUpDown3.Value = Convert.ToInt32(ShowGrainBoundry); if (GetParamValue1(ParamKey_MainLineColor, out ShowGrainBoundry)) panel2.BackColor = Color.FromArgb(Convert.ToInt32(ShowGrainBoundry)); } /// /// 保存结果 /// protected override void buildListBox_analysisResult(string imagesKey, int analysisPicture, bool saveAll = false) { //if (this.listView1.SelectedItems.Count == 0) //{ // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!"); // return; //} //if (this.dataGridView1.Rows.Count == 0) //{ // MessageBox.Show(PdnResources.GetString("Menu.Noresultdata.text") + "!"); // return; //} //string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName(); //string tag = this.imageList1.Images.Keys[this.listView1.SelectedItems[0].Index]; //DataTable dataTable = new DataTable(); //bool replace = false; //int add = 0; //foreach (ListViewItem item in this.listView2.Items) //{ // if (item.Tag.Equals(tag)) // { // add++; // DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); // if (dr == DialogResult.OK) // { // replace = true; // this.listView2.Items.Remove(item); // } // break; // } //} //if (replace || this.listView2.Items.Count == 0 || add == 0) //{ // ListViewItem listViewItem = new ListViewItem(); // listViewItem.SubItems[0].Text = imgName; // listViewItem.Tag = "" + tag; // if (this.listView2.Items.Count == 0) // this.listView2.Items.Add(listViewItem); // else // this.listView2.Items.Insert(0, listViewItem); // this.dataGridView4.Rows.Clear(); // for (int i = 0; i < this.dataTable.Rows.Count; i++) // { // DataGridViewRow dgvr = new DataGridViewRow(); // dgvr.Tag = tag; // foreach (DataGridViewColumn c in this.dataGridView4.Columns) // { // dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); // } // dgvr.Cells[0].Value = imgName; // dgvr.Cells[1].Value = this.dataTable.Rows[i][0]; // dgvr.Cells[2].Value = Math.Round(Convert.ToDouble(this.dataTable.Rows[i][1]), Convert.ToInt32(this.numericUpDown1.Value)); // this.dataGridView4.Rows.Add(dgvr); // } // dataTable.TableName = tag; // foreach (System.Data.DataTable dataTable1 in dataTables) // { // if (dataTable1.TableName.Equals(dataTable.TableName)) // { // dataTables.Remove(dataTable1); // break; // } // } // foreach (DataGridViewColumn c in this.dataGridView4.Columns) // { // dataTable.Columns.Add(c.HeaderText); // } // for (int i = 0; i < this.dataTable.Rows.Count; i++) // { // DataRow dataRow = dataTable.NewRow(); // dataRow[0] = imgName; // dataRow[1] = this.dataTable.Rows[i][0]; // dataRow[2] = this.dataTable.Rows[i][1]; // dataTable.Rows.Add(dataRow); // } // this.dataTables.Add(dataTable); // if (this.allShow) // AllShow(); // this.listView2.Items[0].Selected = true; // if (this.documentWorkspace.PhaseModels[0].mat != null) // { // //保存处理后的图片 // List tempBit = new List(); // Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); // tempBit.Add(originalBit); // Bitmap processedBit = BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].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)); // Draw(graphics); // tempBit.Add(newBit); // 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")); // columnName.Add(PdnResources.GetString("Menu.Linelength.text") + "(μm)"); // columnName.Add(PdnResources.GetString("Menu.Startingcoordinates.text")); // columnName.Add(PdnResources.GetString("Menu.Endpointcoordinates.Text")); // dataList.Add(columnName); // int no = 0; // foreach (var item in rectangleFs) // { // double length = BasicCalculationHelper.GetDistance(new Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 10) * unitLength; // no++; // List strList = new List(); // strList.Add("" + no); // strList.Add("" + length); // strList.Add("(" + (Convert.ToInt32(item.Key[0].X) + 6).ToString() + "," + (Convert.ToInt32(item.Key[0].Y) + 6).ToString() + ")"); // strList.Add("(" + (Convert.ToInt32(item.Key[1].X) + 6).ToString() + "," + (Convert.ToInt32(item.Key[1].Y) + 6).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); // } //} if (this.imageMat == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!"); return; } if (this.dataGridView1.Rows.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text")); return; } //if (this.comboBox1.SelectedItem == null || PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem)) //{ // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text") + "!"); // return; //} double value4Total = this.dataGridView1.Rows.Count - 1;// 0; //foreach (DataGridViewRow Row in this.dataGridView1.Rows) //{ // value4Total += double.Parse(Row.Cells[3].Value.ToString());//交点个数 //} if (value4Total < 1) { MessageBox.Show("请添加截距后保存结果"); return; } string imgName = getCurrentWorkspace().GetFriendlyName(); string tag = getCurrentWorkTag(); DataTable dataTable = new DataTable(); bool replace = false; int add = 0; foreach (ListViewItem item in this.listView2.Items) { if (item.Tag.Equals(tag)) { add++; DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { replace = true; } break; } } if (replace || this.listView2.Items.Count == 0 || add == 0) { if (!replace) { ListViewItem listViewItem = new ListViewItem(); listViewItem.SubItems[0].Text = imgName; listViewItem.Tag = "" + tag; if (this.listView2.Items.Count == 0) this.listView2.Items.Add(listViewItem); else this.listView2.Items.Insert(0, listViewItem); } this.dataGridView2.Rows.Clear(); DataGridViewRow dgvr = new DataGridViewRow(); dgvr.Tag = tag; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[0].Value = imgName; //DataGridViewRow firRow = this.dataGridView1.Rows[0]; //object value1 = firRow.Cells[0].Value;//网格 //object value2 = firRow.Cells[1].Value;//网格长度 //object value3 = firRow.Cells[2].Value;//网格条数 //double value2Total = 0; //foreach (DataGridViewRow Row in this.dataGridView1.Rows) //{ // value2Total += (double.Parse(Row.Cells[1].Value.ToString()) * double.Parse(Row.Cells[2].Value.ToString()));//网格总长度 //} ////double value4Total = 0; ////foreach (DataGridViewRow Row in this.dataGridView1.Rows) ////{ //// value4Total += double.Parse(Row.Cells[3].Value.ToString());//交点个数 ////} ////if (value4Total == 0)//###20791 ////{ //// MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text")); //// return; ////} //////double value4Per = value4Total / this.dataGridView1.Rows.Count; dgvr.Cells[1].Value = this.labelNum.Text;// value1; dgvr.Cells[2].Value = this.labelMax.Text;// value2Total; dgvr.Cells[3].Value = this.labelMin.Text;// value4Total; //dgvr.Cells[4].Value = value4Per;//级别 decimal M = 1;// this.getGainMultiple(); DataGridViewRow lastRow = this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1]; double small_l = double.Parse(lastRow.Cells[1].Value.ToString());// value2Total / (value4Total * (double)M); dgvr.Cells[4].Value = small_l; ////毫米转微米 //decimal A = Convert.ToDecimal(small_l * 1); ////dgvr.Cells[4].Value = small_l;// Math.Round(A, Convert.ToInt32(this.numericUpDown1_0.Value)); //double[] lengths = {453, 320 , 269, 226, 190, 177, 160, 135, 113, 106, // 95.0, 89.0, 80.0, 67.3, 62.0, 56.6, 53.2, 47.6, 44.3, 40.0, 35.4, 33.6, 31.0, // 28.3, 26.6 , 23.8, 22.2, 20.0, 17.7, 16.8, 14.1, 13.3, 11.9, // 10.0, 8.86, 8.41, 7.98, 7.07, 6.20, 5.95, 5.32, 5.00, 4.43, 4.20, 3.54, 2.97 //, 2.66, 2.50, 2.22}; //// 差值 //decimal differenceNew; //decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 1.22, (double)A - 454))); //int first = 0; //if ((double)A < lengths[lengths.Length - 1]) // first = lengths.Length - 1; //else // for (int firstI = 0; firstI < lengths.Length; firstI++) // { // double item = lengths[firstI]; // differenceNew = Math.Abs(A - Convert.ToDecimal(item)); // if (differenceNew < differenceOld) // { // differenceOld = Math.Abs(A - Convert.ToDecimal(item)); // first = firstI; // } // } //string[] valueG = {"00A", "0" , "0.5", "1.0", "1.5", "1.5"/**/, "2.0", "2.5", "3.0", "3.0", // "3.5", "3.5", "4.0", "4.5", "4.5", "5.0", "5.0", "5.5", "5.5", "6.0", "6.0", "6.5", "6.5", // "7.0", "7.0" , "7.5", "7.5", "8.0", "8.0", "8.5", "9.0", "9.0", "9.5", // "10.0", "10.0", "10.5", "10.5", "11.0", "11.0", "11.5", "11.5", "12.0", "12.0", "12.5", "13.0", "13.5" //, "13.5", "14.0", "14.0"}; dgvr.Cells[5].Value = -6.643856 * Math.Log10(small_l * 0.001) - 3.288;// valueG[first]; this.dataGridView2.Rows.Add(dgvr); dataTable.TableName = tag; foreach (System.Data.DataTable dataTable1 in dataTables) { if (dataTable1.TableName.Equals(dataTable.TableName)) { dataTables.Remove(dataTable1); break; } } for (int i = 0; i < this.dataGridView2.Columns.Count; i++) { dataTable.Columns.Add("" + i); } DataRow dataRow = dataTable.NewRow(); dataRow["0"] = imgName; dataRow["1"] = dgvr.Cells[1].Value;// "网格1"; dataRow["2"] = dgvr.Cells[2].Value; dataRow["3"] = dgvr.Cells[3].Value; dataRow["4"] = dgvr.Cells[4].Value; dataRow["5"] = dgvr.Cells[5].Value; //dataRow["6"] = dgvr.Cells[6].Value; dataTable.Rows.Add(dataRow); this.dataTables.Add(dataTable); if (this.allShow) AllShow(); this.RefreshDataGridView4(); //保存处理后的图片 double pantographRatio = this.appWorkspace.DocumentWorkspaces[this.selectPicture].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数 List tempBit = new List(); Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.imageMat);// this.bitmap;// this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); originalBit.Tag = pantographRatio; tempBit.Add(originalBit); Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); Graphics graphics = Graphics.FromImage(newBit); //if (true) //{ }//0914###18810 if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null) { Mat targetMat = this.PhaseModel0Mat; graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height); } if (this.documentWorkspace.PhaseModels[1].choise && this.documentWorkspace.PhaseModels[1].mat != null) { Mat targetMat = this.documentWorkspace.PhaseModels[1].mat; graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height); } if (this.documentWorkspace.PhaseModels[2].choise && this.documentWorkspace.PhaseModels[2].mat != null) { Mat targetMat = this.documentWorkspace.PhaseModels[2].mat; graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height); } graphics.SmoothingMode = SmoothingMode.AntiAlias; drawSubclass/*Draw*/(graphics); newBit.Tag = pantographRatio; tempBit.Add(newBit); if (bitDic.ContainsKey(tag)) bitDic[tag] = tempBit; else bitDic.Add(tag, tempBit); ////保存处理后的图片 //List tempBit = new List(); ////Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap(); ////tempBit.Add(originalBit); ////Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat); ////Graphics graphics = Graphics.FromImage(newBit); ////Draw(graphics); ////tempBit.Add(newBit); //foreach (KeyValuePair> kv in this.bitCeDingDic) //{ // tempBit.Add(kv.Value[0]); // tempBit.Add(kv.Value[1]); //} //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.Tools.GridLine.Text")*/); columnName.Add("截距长度"/*PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Lengthofdetectionline.text")*/); //columnName.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Nnlines.text")); //columnName.Add(PdnResources.GetString("Menu.Thenumberofsections.text")); dataList.Add(columnName); foreach (DataGridViewRow Row in this.dataGridView1.Rows) { List strList = new List(); strList.Add(Row.Cells[0].Value.ToString()); strList.Add(Row.Cells[1].Value.ToString()); //strList.Add(Row.Cells[2].Value.ToString()); //strList.Add(Row.Cells[3].Value.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 { Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel(); newModel.tagName = tag; newModel.picName = imgName; newModel.dataList = dataList; tempDataModel.Add(newModel); } } } /// /// 是否显示晶界 /// /// protected override Boolean ShowGrainBoundryChecked() { return checkBox3_0.Checked; } //是否绘制辅助线 protected override bool showGridChecked() { return false;// checkBox4.Checked; } //是否绘制截点 protected override bool drawGuidePoints() { return false;// (matOrg != null && this.checkBox5_0.Checked); } //是否显示截点 protected override Boolean drawDisplaySections()//##1 { return false;// this.checkBox5_0.Checked; } //辅助线类型 protected override string[] getTypeNames() { return new string[] { PdnResources.GetString("Menu.Verticalauxiliaryline.text"), PdnResources.GetString("Menu.Horizontalauxiliaryline.text"), PdnResources.GetString("Menu.Singlecircleauxiliaryline.text"), PdnResources.GetString("Menu.Three-circleauxiliaryline.text"), PdnResources.GetString("Menu.Compositeauxiliaryline.text")}; } protected override string getTemplateName() { return "Template.Manager.item3.GrainSizeCutOffManualMethod";// "Template.Manager.item3.GrainSizeCutOff6394Method"; } protected override string getProjectEngineeringName() { return "Menu.DedicatedAnalysis.BlackMetal.GrainSize.Text"; } protected override string getModelName() { return "GrainSizeGuideStyleModel.xml"; } protected override void SubclassInitialize() { InitializeComponent(); InitializeComponentText(); DetailListNotDoubleIndex.Add(0); //DetailListNotDoubleIndex.Add(1); IndexChangedFromIndex.Clear(); IndexChangedToIndex.Clear(); IndexChangedFromIndex.Add(1); IndexChangedFromIndex.Add(2); IndexChangedFromIndex.Add(3); IndexChangedFromIndex.Add(4); IndexChangedFromIndex.Add(5); IndexChangedToIndex.Add(0, new int[] { 2, 0 });//平均 IndexChangedToIndex.Add(1, new int[] { 2/*1*/, 1 });//求和 IndexChangedToIndex.Add(2, new int[] { 2, 2 });//平均 IndexChangedToIndex.Add(3, new int[] { 2/*3*/, 3 });//级别 IndexChangedToIndex.Add(4, new int[] { 2, 4 });//平均 for (int i = 0; i < this.dataGridView1.Columns.Count; i++) { this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } //for (int i = 0; i < this.dataGridView2.Columns.Count; i++) //{ // this.dataGridView2.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; //} //for (int i = 0; i < this.dataGridView4.Columns.Count; i++) //{ // this.dataGridView4.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; //} } #endregion private void MethodCutOffDialog_Load(object sender, EventArgs e) { this.button_ApplyToAll.Visible = false; this.button_SaveAll.Visible = false; this.btn_Grainboundarytoreproduce.Location = new System.Drawing.Point(912, 20); this.btn_saveresult.Location = new System.Drawing.Point(993, 20); object ShowGrainBoundry; if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry))//显示晶界 this.checkBox3_0.Checked = (bool)ShowGrainBoundry; //if (GetParamValue1(ParamKey_displaygrid, out ShowGrainBoundry))//显示网格 // this.checkBox4.Checked = (bool)ShowGrainBoundry; //if (GetParamValue1(ParamKey_displaysections, out ShowGrainBoundry))//显示截点 // this.checkBox5_0.Checked = (bool)ShowGrainBoundry; this.groupBox3.Visible = false; this.ColumnTotal1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnTotal2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnTotal3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnTotal4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnTotal5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnTotal6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ColumnTotal2, this.ColumnTotal3, this.ColumnTotal4, this.ColumnTotal5, this.ColumnTotal6}); // // ColumnTotal1 // this.ColumnTotal1.Name = "ColumnTotal1"; this.ColumnTotal1.ReadOnly = true; // // ColumnTotal2 // this.ColumnTotal2.Name = "ColumnTotal2"; this.ColumnTotal2.ReadOnly = true; // // ColumnTotal3 // this.ColumnTotal3.Name = "ColumnTotal3"; this.ColumnTotal3.ReadOnly = true; // // ColumnTotal4 // this.ColumnTotal4.Name = "ColumnTotal4"; this.ColumnTotal4.ReadOnly = true; // // ColumnTotal5 // this.ColumnTotal5.Name = "ColumnTotal5"; this.ColumnTotal5.ReadOnly = true; // // ColumnTotal6 // this.ColumnTotal6.Name = "ColumnTotal6"; this.ColumnTotal6.ReadOnly = true; this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4, this.Column5, this.Column6}); // // Column1 // this.Column1.Name = "Column1"; this.Column1.ReadOnly = true; // // Column2 // this.Column2.Name = "Column2"; this.Column2.ReadOnly = true; // // Column3 // this.Column3.Name = "Graisize"; this.Column3.ReadOnly = true; // // Column4 // this.Column4.Name = "Grainnumber"; this.Column4.ReadOnly = true; // // Column5 // this.Column5.Name = "Grainintercept"; this.Column5.ReadOnly = true; // // Column6 // this.Column6.Name = "Graingrade"; this.Column6.ReadOnly = true; this.dataGridViewTextBoxColumn9.HeaderText = "编号";// PdnResources.GetString("Menu.packet.text"); this.dataGridViewTextBoxColumn10.HeaderText = "截距长度";// PdnResources.GetString("Menu.Depthofnitridinglayer.text"); //this.button8.Text = PdnResources.GetString("Menu.1.5/2section.text"); //this.button6_0.Text = PdnResources.GetString("Menu.0.5sectionstyle.text"); this.button2.Text = "选择截距"; this.button10.Text = "删除截距"; this.button7_0.Text = "添加截距"; this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text"); //this.checkBox5_0.Text = PdnResources.GetString("Menu.displaysections.text"); //this.checkBox4.Text = PdnResources.GetString("Menu.displaygrid.text"); this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text"); this.ColumnTotal1.HeaderText = PdnResources.GetString("Menu.Intersectinggrainnumber.Text"); this.ColumnTotal2.HeaderText = "截距数量";//PdnResources.GetString("Menu.Numberofgrainsingrid.Text"); this.ColumnTotal3.HeaderText = "最大截距";// PdnResources.GetString("Menu.Totalmeshlength.Text") + "(μm)"; this.ColumnTotal4.HeaderText = "最小截距";// PdnResources.GetString("Menu.umberofpoints.Text"); this.ColumnTotal5.HeaderText = PdnResources.GetString("Menu.averageintercept.text") + "(μm)"; this.ColumnTotal6.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text"); this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text"); this.Column2.HeaderText = "截距数量";// PdnResources.GetString("Menu.Tools.GridLine.Text"); this.Column3.HeaderText = "最大截距";// PdnResources.GetString("Menu.Gridlength.text") + "(μm)"; this.Column4.HeaderText = "最小截距";// PdnResources.GetString("Menu.Thenumberofsections.text"); this.Column5.HeaderText = PdnResources.GetString("Menu.averageintercept.text") + "(μm)";// "平均截距";// this.Column6.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");// "";// this.Text = "手动测量";// "GBT6394_2017(" + PdnResources.GetString("Menu.sectionmethod.text") + ")"; //this.groupBox_img.Size = new System.Drawing.Size(158, 722); //this.groupBox_review.Size = new System.Drawing.Size(575, 722); //this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 800); //this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 800); //this.groupBox_report.Location = new System.Drawing.Point(974, 800); } ///// ///// 是否显示网格 ///// ///// ///// //private void checkBox4_CheckedChanged(object sender, EventArgs e) //{ // this.documentWorkspace.Refresh(); //} ///// ///// 是否显示截点 ///// ///// ///// //private void checkBox5_0_CheckedChanged(object sender, EventArgs e) //{ // if (!this.checkBox4.Checked) // MessageBox.Show(PdnResources.GetString("Menu.Nogrid.text")+"!"); // this.documentWorkspace.Refresh(); //} /// /// 是否显示晶界 /// /// /// private void checkBox3_0_CheckedChanged(object sender, EventArgs e) { if (this.documentWorkspace.PhaseModels.Count > 0) { if (!bcOriginChecked() && getGrainBoundryChecked() && checkBox3_0.Checked) { this.documentWorkspace.PhaseModels[1].choise = true; } else { this.documentWorkspace.PhaseModels[1].choise = false; } } this.documentWorkspace.Refresh(); } protected override void refreshWhileImgChanged() { object ShowGrainBoundry; if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry))//显示晶界 this.checkBox3_0.Checked = (bool)ShowGrainBoundry; //base.refreshWhileImgChanged(); if (getCurrentWorkspace() != null/* && this.listView1.FocusedItem.Selected*/) this.unitLength = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron); rectangleFs.Clear(); ////二值化集成4 //binaryClass.listView1_SelectedIndexChanged(this.bitmap); rectangleFsArr = new RectangleF[] { }; rectangleFs.Clear(); pointFsLine = new PointF[] { }; this.dataGridView1.Rows.Clear(); selectLineIndex = -1; rectangleFsLines.Clear(); } protected override void onMouseUp(object sender, MouseEventArgs e) { //base.onMouseUp(sender, e); canAdd = false; canMove = false; movePointIndex = -1; RefrashData(); if (mouseStatus == 2) SelectDataRow(); } /// /// 相颜色点击事件 /// /// /// private void panelC_Click(object sender, EventArgs e) { this.panelC = (Panel)sender; this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor); this.colorsFormGrid.ShowDialog(); } /// /// PanelC的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { Color color = this.colorsFormGrid.UserPrimaryColor.ToColor(); //更改背景色,触发事件 this.panelC.BackColor = color; this.documentWorkspace.Refresh(); //关闭色板 this.colorsFormGrid.Close(); } private void SelectDataRow() { if (this.dataGridView1.Rows.Count > selectLineIndex && selectLineIndex >= 0) this.dataGridView1.Rows[selectLineIndex].Selected = true; if (dataGridView1.SelectedRows.Count > 0) selectLineIndex = dataGridView1.SelectedRows[0].Index; } /// /// 刷新数据展示 /// private void RefrashData() { canChange = true; if (this.rectangleFs.Count == 0) return; this.dataGridView1.Rows.Clear(); int count = 0; double lengthMax = 0; double lengthMin = 0; if (rectangleFs.Count > 0) { foreach (var item in rectangleFs) { lengthMin = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new System.Drawing.Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 15) * unitLength; break; } } foreach (var item in rectangleFs) { count++; DataGridViewRow dgvr = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView1.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } double length = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new System.Drawing.Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 15) * unitLength; dgvr.Cells[0].Value = ""/*"L"*/ + count; if (length < lengthMin) lengthMin = length; if (length > lengthMax) lengthMax = length; dgvr.Cells[1].Value = this.DecnumString(length.ToString());// Math.Round(length, Convert.ToInt32(this.numericUpDown1.Value)); this.dataGridView1.Rows.Add(dgvr); } labelMax.Text = this.DecnumString(lengthMax.ToString()); labelMin.Text = this.DecnumString(lengthMin.ToString()); labelNum.Text = rectangleFs.Count.ToString(); dataTable = new DataTable(); foreach (DataGridViewColumn Column in this.dataGridView1.Columns) { dataTable.Columns.Add(Column.HeaderText); } count = 0; foreach (var item in rectangleFs) { count++; DataRow dataRow = dataTable.NewRow(); double length = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(item.Key[0].X) + 6, Convert.ToInt32(item.Key[0].Y) + 6), new System.Drawing.Point(Convert.ToInt32(item.Key[1].X) + 6, Convert.ToInt32(item.Key[1].Y) + 6), 15) * unitLength; dataRow[0] = ""/*"L"*/ + count; dataRow[1] = length; this.dataTable.Rows.Add(dataRow); } double allLength = 0; for (int i = 0; i < dataTable.Rows.Count; i++) { allLength += Convert.ToDouble(dataTable.Rows[i][1]); } DataGridViewRow dgvr1 = new DataGridViewRow(); foreach (DataGridViewColumn Column in this.dataGridView1.Columns) { dgvr1.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } dgvr1.Cells[0].Value = PdnResources.GetString("Menu.Image.Average.Text"); dgvr1.Cells[1].Value = this.DecnumString(allLength / this.dataTable.Rows.Count + "");// Math.Round(allLength / this.dataTable.Rows.Count, Convert.ToInt32(this.numericUpDown1.Value)); this.dataGridView1.Rows.Add(dgvr1); canChange = false; if (this.dataGridView1.DisplayedRowCount(false) == this.dataGridView1.RowCount)//##################### { //没有 this.dataGridViewTextBoxColumn10.Width = 242; } else { //有 this.dataGridViewTextBoxColumn10.Width = 227; } } PointF point1; protected override void onMouseMove(object sender, MouseEventArgs e) { base.onMouseMove(sender, e); // 换算后的点 this.point1 = documentWorkspace.GetScalePoint(e.Location); // 全方位线 if (lineStyle == 0) { if (mouseStatus == 0 && canAdd) { rectangleFsArr[1] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12); PointF startPoint = new PointF(rectangleFsArr[0].X + 6, rectangleFsArr[0].Y + 6); PointF endPoint = new PointF(rectangleFsArr[1].X + 6, rectangleFsArr[1].Y + 6); //计算需要旋转的角度 double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y)); double sAngle1 = 270 + angle; double eAngle1 = 90 + angle; System.Drawing.Point point3 = new System.Drawing.Point(); System.Drawing.Point point4 = new System.Drawing.Point(); System.Drawing.Point point5 = new System.Drawing.Point(); System.Drawing.Point point6 = new System.Drawing.Point(); if (sAngle1 is double.NaN && eAngle1 is double.NaN) { } else { point3 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), sAngle1); point4 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), eAngle1); point5 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), sAngle1); point6 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), eAngle1); } pointFsLine[0] = point3; pointFsLine[1] = point4; pointFsLine[2] = point6; pointFsLine[3] = point5; } } // 水平线 else if (lineStyle == 1) { if (mouseStatus == 0 && canAdd) { rectangleFsArr[1] = new RectangleF(point1.X - 6, rectangleFsArr[0].Y, 12, 12); pointFsLine[0] = new PointF(rectangleFsArr[0].X + 6, rectangleFsArr[0].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9); pointFsLine[1] = new PointF(rectangleFsArr[0].X + 6, rectangleFsArr[0].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3); pointFsLine[3] = new PointF(rectangleFsArr[1].X + 6, rectangleFsArr[1].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9); pointFsLine[2] = new PointF(rectangleFsArr[1].X + 6, rectangleFsArr[1].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3); } } // 垂直线 else if (lineStyle == 2) { if (mouseStatus == 0 && canAdd) { rectangleFsArr[1] = new RectangleF(rectangleFsArr[0].X, point1.Y - 6, 12, 12); pointFsLine[0] = new PointF(rectangleFsArr[0].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, rectangleFsArr[0].Y + 6); pointFsLine[1] = new PointF(rectangleFsArr[0].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, rectangleFsArr[0].Y + 6); pointFsLine[3] = new PointF(rectangleFsArr[1].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, rectangleFsArr[1].Y + 6); pointFsLine[2] = new PointF(rectangleFsArr[1].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, rectangleFsArr[1].Y + 6); } } if (this.mouseStatus == 2 && canMove) { if (this.selectLineIndex != -1) { int indexRectangleFs = -1; foreach (var item in rectangleFs) { indexRectangleFs++; if (selectLineIndex == indexRectangleFs) { // 全方位线 if (item.Value == 0) { // 线条起始点移动 if (movePointIndex == 0) { item.Key[0] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12); } else if (movePointIndex == 1) { item.Key[1] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12); } else if (movePointIndex == 2) { item.Key[0].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y); item.Key[1].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y); movePointStart = point1; } PointF startPoint = new PointF(item.Key[0].X + 6, item.Key[0].Y + 6); PointF endPoint = new PointF(item.Key[1].X + 6, item.Key[1].Y + 6); //计算需要旋转的角度 double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y)); double sAngle1 = 270 + angle; double eAngle1 = 90 + angle; System.Drawing.Point point3 = new System.Drawing.Point(); System.Drawing.Point point4 = new System.Drawing.Point(); System.Drawing.Point point5 = new System.Drawing.Point(); System.Drawing.Point point6 = new System.Drawing.Point(); if (sAngle1 is double.NaN && eAngle1 is double.NaN) { } else { point3 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), sAngle1); point4 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), eAngle1); point5 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), sAngle1); point6 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown3.Value / 2 + 3)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), eAngle1); } int indexRectangleFsLines = -1; foreach (var item1 in rectangleFsLines) { indexRectangleFsLines++; if (indexRectangleFsLines == indexRectangleFs) { item1.Key[0] = point3; item1.Key[1] = point4; item1.Key[2] = point6; item1.Key[3] = point5; //item1.Key[0] = new PointF(point3.X + 6, point3.Y + 9); //item1.Key[1] = new PointF(point4.X + 6, point3.Y - 9); //item1.Key[2] = new PointF(point6.X + 6, point6.Y + 9); //item1.Key[3] = new PointF(point5.X + 6, point3.Y - 9); } } } // 水平线 else if (item.Value == 1) { // 线条起始点移动 if (movePointIndex == 0) { item.Key[0] = new RectangleF(point1.X - 6, item.Key[1].Y, 12, 12); } else if (movePointIndex == 1) { item.Key[1] = new RectangleF(point1.X - 6, item.Key[0].Y, 12, 12); } else if (movePointIndex == 2) { item.Key[0].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y); item.Key[1].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y); movePointStart = point1; } int selectIndex = -1; foreach (var item1 in rectangleFsLines) { selectIndex++; if (selectIndex == selectLineIndex) { item1.Key[0] = new PointF(item.Key[0].X + 6, item.Key[0].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9); item1.Key[1] = new PointF(item.Key[0].X + 6, item.Key[0].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3); item1.Key[3] = new PointF(item.Key[1].X + 6, item.Key[1].Y/* + (float)(this.numericUpDown3.Value / 2)*/ + 9); item1.Key[2] = new PointF(item.Key[1].X + 6, item.Key[1].Y/* - (float)(this.numericUpDown3.Value / 2)*/ + 3); } } } // 垂直线 else if (item.Value == 2) { // 线条起始点移动 if (movePointIndex == 0) { item.Key[0] = new RectangleF(item.Key[1].X, point1.Y - 6, 12, 12); } else if (movePointIndex == 1) { item.Key[1] = new RectangleF(item.Key[0].X, point1.Y - 6, 12, 12); } else if (movePointIndex == 2) { item.Key[0].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y); item.Key[1].Offset(point1.X - movePointStart.X, point1.Y - movePointStart.Y); movePointStart = point1; } int selectIndex = -1; foreach (var item1 in rectangleFsLines) { selectIndex++; if (selectIndex == selectLineIndex) { item1.Key[0] = new PointF(item.Key[0].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, item.Key[0].Y + 6); item1.Key[1] = new PointF(item.Key[0].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, item.Key[0].Y + 6); item1.Key[3] = new PointF(item.Key[1].X/* + (float)(this.numericUpDown3.Value / 2)*/ + 9, item.Key[1].Y + 6); item1.Key[2] = new PointF(item.Key[1].X/* - (float)(this.numericUpDown3.Value / 2)*/ + 3, item.Key[1].Y + 6); } } } } } } } this.documentWorkspace.Refresh(); } protected override void drawSubclass(Graphics graphics, string imagesKey = null, int analysisPicture = -1) { //base.drawSubclass(graphics); Pen linePen = new Pen(this.panel2.BackColor, Convert.ToInt32(this.numericUpDown3.Value)); Pen linePen1 = new Pen(this.panel1.BackColor, Convert.ToInt32(this.numericUpDown3.Value)); //linePen.CustomStartCap = lineCap; //linePen.CustomEndCap = lineCap; int drawIndex = -1; foreach (var item in rectangleFs) { drawIndex++; if (selectLineIndex != -1 && drawIndex == this.selectLineIndex) { linePen.DashStyle = DashStyle.DashDot; } else linePen.DashStyle = DashStyle.Solid; graphics.DrawLine(linePen, new PointF(item.Key[0].X + 6, item.Key[0].Y + 6), new PointF(item.Key[1].X + 6, item.Key[1].Y + 6)); PointF startPoint = new PointF(item.Key[0].X + 6, item.Key[0].Y + 6); PointF endPoint = new PointF(item.Key[1].X + 6, item.Key[1].Y + 6); double length = BasicCalculationHelper.GetDistance(new System.Drawing.Point(Convert.ToInt32(startPoint.X) + 6, Convert.ToInt32(startPoint.Y) + 6), new System.Drawing.Point(Convert.ToInt32(endPoint.X) + 6, Convert.ToInt32(endPoint.Y) + 6), getNumericUpDown1Value()) * unitLength; //计算需要旋转的角度 double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y)); if (item.Value == 0) { // // 绘制两侧竖线 // double sAngle1 = 270 + angle; double eAngle1 = 90 + angle; System.Drawing.Point point3 = new System.Drawing.Point(); System.Drawing.Point point4 = new System.Drawing.Point(); System.Drawing.Point point5 = new System.Drawing.Point(); System.Drawing.Point point6 = new System.Drawing.Point(); if (sAngle1 is double.NaN && eAngle1 is double.NaN) { } else { point3 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), sAngle1); point4 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(startPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(startPoint.Y)), new System.Drawing.Point(Convert.ToInt32(startPoint.X), Convert.ToInt32(startPoint.Y)), eAngle1); point5 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), sAngle1); point6 = BasicCalculationHelper.GetAnglePoint(new System.Drawing.Point((Convert.ToInt32(endPoint.X)/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/), Convert.ToInt32(endPoint.Y)), new System.Drawing.Point(Convert.ToInt32(endPoint.X), Convert.ToInt32(endPoint.Y)), eAngle1); } graphics.DrawLine(linePen1, point3, point4); graphics.DrawLine(linePen1, point5, point6); SizeF sizeF = graphics.MeasureString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value))); PointF cen1 = new PointF((point3.X + point5.X) / 2, (point3.Y + point5.Y) / 2); PointF cen2 = new PointF((point4.X + point6.X) / 2, (point4.Y + point6.Y) / 2); PointF drawP1 = new PointF(cen1.X - sizeF.Width / 2, cen1.Y - sizeF.Height / 2); PointF drawP2 = new PointF(cen2.X - sizeF.Width / 2, cen2.Y - sizeF.Height / 2); PointF drawP3; if (angle < 90) drawP3 = drawP1; else drawP3 = drawP2; Matrix mtxSave = graphics.Transform; Matrix matrix = graphics.Transform; // 画布旋转 if (angle < 90) { matrix.RotateAt((float)angle, new PointF(cen1.X, cen1.Y)); graphics.Transform = matrix; } else { angle = BasicCalculationHelper.Angle(endPoint, startPoint, new PointF(endPoint.X, startPoint.Y)); matrix.RotateAt((float)angle, new PointF(cen2.X, cen2.Y)); graphics.Transform = matrix; } graphics.DrawString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)), new SolidBrush(this.panel1.BackColor/*Color.Black*/), drawP3); //还原为原始旋转矩阵 graphics.Transform = mtxSave; matrix.Dispose(); } else if (item.Value == 1) { graphics.DrawLine(linePen1, new PointF(startPoint.X, startPoint.Y/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/) , new PointF(startPoint.X, startPoint.Y/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/)); graphics.DrawLine(linePen1, new PointF(endPoint.X, endPoint.Y/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/) , new PointF(endPoint.X, endPoint.Y/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/)); SizeF sizeF = graphics.MeasureString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value))); PointF cen1 = new PointF((startPoint.X + endPoint.X) / 2, startPoint.Y/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/); graphics.DrawString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)), new SolidBrush(Color.Black), new PointF(cen1.X - sizeF.Width / 2, cen1.Y - sizeF.Height / 2)); } else if (item.Value == 2) { graphics.DrawLine(linePen1, new PointF(startPoint.X/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/, startPoint.Y) , new PointF(startPoint.X/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/, startPoint.Y)); graphics.DrawLine(linePen1, new PointF(endPoint.X/* - Convert.ToInt32(this.numericUpDown2.Value / 2)*/, endPoint.Y) , new PointF(endPoint.X/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/, endPoint.Y)); SizeF sizeF = graphics.MeasureString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value))); PointF cen1 = new PointF(startPoint.X/* + Convert.ToInt32(this.numericUpDown2.Value / 2)*/, (startPoint.Y + endPoint.Y) / 2); Matrix mtxSave = graphics.Transform; Matrix matrix = graphics.Transform; matrix.RotateAt((float)90, new PointF(cen1.X, cen1.Y)); graphics.Transform = matrix; graphics.DrawString(Math.Round(length, getNumericUpDown1Value()) + "μm", new Font("宋体", Convert.ToInt32(this.numericUpDown4.Value)), new SolidBrush(Color.Black), new PointF(cen1.X - sizeF.Width / 2, cen1.Y - sizeF.Height / 2)); //还原为原始旋转矩阵 graphics.Transform = mtxSave; matrix.Dispose(); } if (selectLineIndex != -1 && drawIndex == this.selectLineIndex) { graphics.FillRectangle(new SolidBrush(Color.Black), item.Key[0]); graphics.FillRectangle(new SolidBrush(Color.Black), item.Key[1]); } } System.Drawing.Drawing2D.GraphicsPath myGraphicsPath; Region myRegion; int selectIndex = -1; foreach (var item in rectangleFsLines) { selectIndex++; myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); myRegion = new Region(); myGraphicsPath.Reset(); myGraphicsPath.AddPolygon(new PointF[] { item.Key[0], item.Key[1], item.Key[2], item.Key[3] }); myRegion.MakeEmpty(); myRegion.Union(myGraphicsPath); //graphics.FillRegion(new SolidBrush(Color.Black), myRegion); } linePen.Dispose(); linePen1.Dispose(); } /// /// 鼠标按下 /// /// /// protected override void OnMouseDown(object sender, MouseEventArgs e) { if (this.documentWorkspace.CompositionSurface == null) return; //// 换算后的点 //PointF point1 = documentWorkspace.GetScalePoint(e.Location); //if (point1.X <= this.documentWorkspace.CompositionSurface.Width // && point1.X >= 0 // && point1.Y >= 0 // && point1.Y <= this.documentWorkspace.CompositionSurface.Height) //{ // RectangleF rectangleF; // // 复合辅助线 // int add = GSSClass.GuideClass.getAddOfRStyle(point1, this.comboBox1.SelectedItem, out rectangleF); // if (add == 0 && GSSClass.styleClass.PointKb > 0) // rectangleF = GSSClass.GuideClass.RectangleFLine; // //手动添加截点 // if (this.documentWorkspace.ActiveTool == Annotation.Enum.DrawToolType.InclusionNoEffect && GSSClass.styleClass.OnMouseDownNext(point1, sender, e)) // GSSClass.styleClass.OnMouseDownFirst(point1, rectangleF, GSSClass.linePointList, e); //} //if (GSSClass.styleClass.PointKb == 0) //{ // //辅助线缩放 // GSSClass.GuideClass.OnMouseDown(point1, sender, e); // //辅助线移动 // base.OnMouseDown(sender, e);//## //} if (e.Button == MouseButtons.Left) { // 换算后的点 PointF point1 = documentWorkspace.GetScalePoint(e.Location); selectLineIndex = -1; if (mouseStatus == 0) { canAdd = true; rectangleFsArr = new RectangleF[2]; pointFsLine = new PointF[4]; rectangleFsArr[0] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12); rectangleFsArr[1] = new RectangleF(point1.X - 6, point1.Y - 6, 12, 12); Dictionary rectangleFs1 = new Dictionary(); foreach (var item in rectangleFs) { rectangleFs1.Add(item.Key, item.Value); } rectangleFs = new Dictionary(); rectangleFs = rectangleFs1; if (lineStyle == 0) rectangleFs.Add(rectangleFsArr, 0); else if (lineStyle == 1) rectangleFs.Add(rectangleFsArr, 1); else if (lineStyle == 2) rectangleFs.Add(rectangleFsArr, 2); if (lineStyle == 0) rectangleFsLines.Add(pointFsLine, 0); else if (lineStyle == 1) rectangleFsLines.Add(pointFsLine, 1); else if (lineStyle == 2) rectangleFsLines.Add(pointFsLine, 2); } if (mouseStatus == 2) { System.Drawing.Drawing2D.GraphicsPath myGraphicsPath; Region myRegion; int selectIndex = -1; foreach (var item in rectangleFsLines) { selectIndex++; myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); myRegion = new Region(); myGraphicsPath.Reset(); myGraphicsPath.AddPolygon(new PointF[] { item.Key[0], item.Key[1], item.Key[2], item.Key[3] }); myRegion.MakeEmpty(); myRegion.Union(myGraphicsPath); //返回判断点是否在多边形里 //RectangleF rectangleF = myRegion.GetBounds(rag) double L = BasicCalculationHelper.GetDisFromPointToLine(item.Key[0], item.Key[2], point1); bool myPoint = L < 10 /*myRegion.IsVisible(point1)*/; if (myPoint) { selectLineIndex = selectIndex; break; } } if (selectLineIndex == -1) { selectIndex = -1; foreach (var item in rectangleFs) { selectIndex++; if (item.Key[0].Contains(point1)) { selectLineIndex = selectIndex; break; } else if (item.Key[1].Contains(point1)) { selectLineIndex = selectIndex; break; } } } //else // { // if(this.dataGridView1.Rows.Count > selectLineIndex) // this.dataGridView1.Rows[selectLineIndex].Selected = true; //} } if (mouseStatus == 2) { int indexRectangleFs = -1; foreach (var item in rectangleFs) { indexRectangleFs++; System.Drawing.Drawing2D.GraphicsPath myGraphicsPath; Region myRegion; int indexRectangleFsLines = -1; bool myPoint = false; foreach (var item1 in rectangleFsLines) { indexRectangleFsLines++; if (indexRectangleFs == indexRectangleFsLines) { myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); myRegion = new Region(); myGraphicsPath.Reset(); myGraphicsPath.AddPolygon(new PointF[] { item1.Key[0], item1.Key[1], item1.Key[2], item1.Key[3] }); myRegion.MakeEmpty(); myRegion.Union(myGraphicsPath); //返回判断点是否在多边形里 //myPoint = myRegion.IsVisible(point1); double L = BasicCalculationHelper.GetDisFromPointToLine(item1.Key[0], item1.Key[2], point1); myPoint = L < 10 /*myRegion.IsVisible(point1)*/; if (myPoint) { break; } } } if (item.Key[0].Contains(point1)) { movePointStart = point1; movePointIndex = 0; canMove = true; } else if (item.Key[1].Contains(point1)) { movePointStart = point1; movePointIndex = 1; canMove = true; } else if (myPoint) { movePointStart = point1; movePointIndex = 2; canMove = true; } } } } } private void AllShow() { this.dataGridView2.Rows.Clear(); for (int i = 0; i < this.dataTables.Count; i++) { DataGridViewRow dgvr = new DataGridViewRow(); dgvr.Tag = this.dataTables[i].TableName; foreach (DataGridViewColumn Column in this.dataGridView2.Columns) { dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell); } for (int c = 0; c < this.dataTables[i].Columns.Count; c++) { //if (c > 2 && c < 4) // dgvr.Cells[c].Value = Math.Round((double)Convert.ToDecimal(this.dataTables[i].Rows[0][c]), Convert.ToInt32(this.numericUpDown1_0.Value)).ToString(); //else dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString(); } this.dataGridView2.Rows.Add(dgvr); } } private void button6_0_Click(object sender, EventArgs e) { if (this.imageMat != null) { //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!"); GSSClass.styleClass.PointKb = 1; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!"); } } private void button7_0_LostFocus(object sender, EventArgs e) { this.mouseStatus = -1; } /// /// 添加测量线 /// /// /// private void button7_0_Click(object sender, EventArgs e) { if (this.imageMat != null) { this.mouseStatus = 0; this.selectLineIndex = -1; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!"); } } private void button8_Click(object sender, EventArgs e) { if (this.imageMat != null) { //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!"); GSSClass.styleClass.PointKb = 3; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text") + "!"); } } /// /// 选择截距 /// /// /// private void button2_Click(object sender, EventArgs e) { this.mouseStatus = 2; this.selectLineIndex = -1; } /// /// 删除截距 /// /// /// private void button10_Click(object sender, EventArgs e) { this.mouseStatus = 1; if (this.mouseStatus == 1) { if (selectLineIndex == -1) { MessageBox.Show("请先选择要删除的测量线!"); return; } int deleteIndex = -1; foreach (var item in rectangleFs) { deleteIndex++; if (deleteIndex == selectLineIndex) { rectangleFs.Remove(item.Key); break; } } deleteIndex = -1; foreach (var item in rectangleFsLines) { deleteIndex++; if (deleteIndex == selectLineIndex) { rectangleFsLines.Remove(item.Key); break; } } selectLineIndex = 0; if (selectLineIndex < -1) selectLineIndex = -1; if (rectangleFs.Count == 0) this.dataGridView1.Rows.Clear(); if (mouseStatus == 2) SelectDataRow(); RefrashData(); this.documentWorkspace.Refresh(); } } private void dataGridView1_SelectionChanged(object sender, EventArgs e) { //canChange = true; if (!canChange) { SelectDataRow(); this.documentWorkspace.Refresh(); } } /// /// 获取参数 /// protected override object saveRecordingData(string key) { object value = null; switch (key) { case "MainFontSize": value = numericUpDown4.Value; break; case "MainFontColor": value = panel1.BackColor.ToArgb(); break; case "MainLineWidth": value = numericUpDown3.Value; break; case "MainLineColor": value = panel2.BackColor.ToArgb(); break; } return value; } private void MethodCutOffDialog_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { button10_Click(null, null); e.Handled = true; } } } }