using OpenCvSharp; using PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace PaintDotNet.DedicatedAnalysis.GrainSize.YST347 { internal class MethodCutOffDialog : GrainSizeStandardDialog { /// /// 测定结果暂存 /// private List dataTable1s = new List(); /// /// 储存点击保存结果后的所有原图与分析图 /// private Dictionary> bitCeDingDic = new Dictionary>(); #region 组件 private GroupBox groupBox10; private Button button10; private Button button7_0; private GroupBox groupBox11; private CheckBox checkBox5_0; private CheckBox checkBox4; private CheckBox checkBox3_0; private Button button1; private Button button4; private DataGridView dataGridView1; private GroupBox groupBox5; private DataGridViewTextBoxColumn Column11; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; private Button button8; private Button button6_0; private RadioButton radioButton_Black; #endregion 组件 /// /// 构造函数 /// /// /// public MethodCutOffDialog(AppWorkspace appWorkspace) : base(appWorkspace, false, true) { } #region 初始化组件 private void InitializeLanguageText() { this.groupBox10.Text = PdnResources.GetString("Menu.sectionoperation.text"); this.button8.Text = PdnResources.GetString("Menu.1.5/2section.text"); this.button6_0.Text = PdnResources.GetString("Menu.0.5sectionstyle.text"); this.button10.Text = PdnResources.GetString("Menu.Setting.Text"); this.button7_0.Text = PdnResources.GetString("Menu.1section.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.button1.Text = PdnResources.GetString("Menu.Savemeasurementresults.text"); this.button4.Text = PdnResources.GetString("Menu.Deletemeasurementresult.text"); this.Column11.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text"); this.dataGridViewTextBoxColumn1.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Lengthofdetectionline.text"); this.dataGridViewTextBoxColumn2.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Nnlines.text"); this.dataGridViewTextBoxColumn4.HeaderText = PdnResources.GetString("Menu.Thenumberofsections.text"); this.groupBox5.Text = PdnResources.GetString("Menu.measurementresults.text"); this.Text = "YST347(" + PdnResources.GetString("Menu.Interceptmethod.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(); this.groupBox10 = new System.Windows.Forms.GroupBox(); this.button8 = new System.Windows.Forms.Button(); this.button6_0 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); this.button7_0 = new System.Windows.Forms.Button(); this.groupBox11 = new System.Windows.Forms.GroupBox(); this.checkBox5_0 = new System.Windows.Forms.CheckBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.checkBox3_0 = new System.Windows.Forms.CheckBox(); this.button1 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.groupBox_analysisResult1.SuspendLayout(); this.groupBox10.SuspendLayout(); this.groupBox11.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.groupBox5.SuspendLayout(); this.SuspendLayout(); // // groupBox_img // this.groupBox_img.Size = new System.Drawing.Size(158, 428); // // groupBox_review // this.groupBox_review.Size = new System.Drawing.Size(575, 428); // // groupBox_report // this.groupBox_report.Location = new System.Drawing.Point(974, 506); // // groupBox6groupBox_analysisResult2 // this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 506); // // groupBox_analysisResult1 // this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 506); // // groupBox10 // this.groupBox10.Controls.Add(this.button8); this.groupBox10.Controls.Add(this.button6_0); this.groupBox10.Controls.Add(this.button10); this.groupBox10.Controls.Add(this.button7_0); this.groupBox10.Location = new System.Drawing.Point(179, 555); this.groupBox10.Name = "groupBox10"; this.groupBox10.Size = new System.Drawing.Size(208, 89); this.groupBox10.TabIndex = 38; this.groupBox10.TabStop = false; // // button8 // this.button8.BackColor = System.Drawing.SystemColors.Control; this.button8.Location = new System.Drawing.Point(109, 52); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(95, 26); this.button8.TabIndex = 13; this.button8.UseVisualStyleBackColor = false; this.button8.Click += new System.EventHandler(this.button8_Click); // // button6_0 // this.button6_0.BackColor = System.Drawing.SystemColors.Control; this.button6_0.Location = new System.Drawing.Point(8, 53); this.button6_0.Name = "button6_0"; this.button6_0.Size = new System.Drawing.Size(95, 26); this.button6_0.TabIndex = 12; this.button6_0.UseVisualStyleBackColor = false; this.button6_0.Click += new System.EventHandler(this.button6_0_Click); // // button10 // this.button10.BackColor = System.Drawing.SystemColors.Control; this.button10.Location = new System.Drawing.Point(107, 20); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(95, 26); this.button10.TabIndex = 11; 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(6, 20); this.button7_0.Name = "button7_0"; this.button7_0.Size = new System.Drawing.Size(95, 26); this.button7_0.TabIndex = 8; this.button7_0.UseVisualStyleBackColor = false; this.button7_0.Click += new System.EventHandler(this.button7_0_Click); // // groupBox11 // this.groupBox11.Controls.Add(this.checkBox5_0); this.groupBox11.Controls.Add(this.checkBox4); this.groupBox11.Controls.Add(this.checkBox3_0); this.groupBox11.Location = new System.Drawing.Point(393, 555); this.groupBox11.Name = "groupBox11"; this.groupBox11.Size = new System.Drawing.Size(142, 89); this.groupBox11.TabIndex = 39; this.groupBox11.TabStop = false; // // checkBox5_0 // this.checkBox5_0.AutoSize = true; this.checkBox5_0.Checked = true; this.checkBox5_0.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox5_0.Location = new System.Drawing.Point(15, 59); this.checkBox5_0.Name = "checkBox5_0"; this.checkBox5_0.Size = new System.Drawing.Size(15, 14); this.checkBox5_0.TabIndex = 2; this.checkBox5_0.UseVisualStyleBackColor = true; this.checkBox5_0.CheckedChanged += new System.EventHandler(this.checkBox5_0_CheckedChanged); // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Checked = true; this.checkBox4.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox4.Location = new System.Drawing.Point(15, 37); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(15, 14); this.checkBox4.TabIndex = 1; this.checkBox4.UseVisualStyleBackColor = true; this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged); // // 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, 15); 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); // // button1 // this.button1.BackColor = System.Drawing.SystemColors.Control; this.button1.Location = new System.Drawing.Point(139, 11); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(101, 23); this.button1.TabIndex = 5; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // button4 // this.button4.BackColor = System.Drawing.SystemColors.Control; this.button4.Location = new System.Drawing.Point(246, 11); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(101, 23); this.button4.TabIndex = 4; this.button4.UseVisualStyleBackColor = false; this.button4.Click += new System.EventHandler(this.button4_Click); // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Column11, this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2, this.dataGridViewTextBoxColumn4}); this.dataGridView1.Location = new System.Drawing.Point(6, 36); this.dataGridView1.MultiSelect = false; this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.Size = new System.Drawing.Size(341, 103); this.dataGridView1.TabIndex = 29; // // Column11 // dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.Column11.DefaultCellStyle = dataGridViewCellStyle2; this.Column11.Name = "Column11"; this.Column11.ReadOnly = true; this.Column11.Width = 66; // // dataGridViewTextBoxColumn1 // dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle3; this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; this.dataGridViewTextBoxColumn1.ReadOnly = true; // // dataGridViewTextBoxColumn2 // dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle4; this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; this.dataGridViewTextBoxColumn2.ReadOnly = true; // // dataGridViewTextBoxColumn4 // dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.dataGridViewTextBoxColumn4.DefaultCellStyle = dataGridViewCellStyle5; this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; this.dataGridViewTextBoxColumn4.ReadOnly = true; this.dataGridViewTextBoxColumn4.Width = 72; // // groupBox5 // this.groupBox5.Controls.Add(this.dataGridView1); this.groupBox5.Controls.Add(this.button4); this.groupBox5.Controls.Add(this.button1); this.groupBox5.Location = new System.Drawing.Point(179, 652); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(355, 145); this.groupBox5.TabIndex = 40; this.groupBox5.TabStop = false; // // MethodCutOffDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(1127, 1005); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox10); this.Controls.Add(this.groupBox11); this.Name = "MethodCutOffDialog"; this.Load += new System.EventHandler(this.MethodCutOffDialog_Load); this.Controls.SetChildIndex(this.groupBox11, 0); this.Controls.SetChildIndex(this.groupBox10, 0); this.Controls.SetChildIndex(this.groupBox5, 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.groupBox_analysisResult1.ResumeLayout(false); this.groupBox10.ResumeLayout(false); this.groupBox11.ResumeLayout(false); this.groupBox11.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.groupBox5.ResumeLayout(false); this.ResumeLayout(false); } #endregion 初始化组件 #region 需继承方法 protected override void refreshWhileImgChanged() { if (this.dataGridView1.Rows.Count > 0) { foreach (DataGridViewRow gridViewRow in this.dataGridView1.Rows) { foreach (var dataTable in this.dataTable1s) { if (dataTable.TableName.Equals(gridViewRow.Tag)) { this.dataTable1s.Remove(dataTable); break; } } if (bitCeDingDic.ContainsKey((string)gridViewRow.Tag)) bitCeDingDic.Remove((string)gridViewRow.Tag); } this.dataGridView1.Rows.Clear(); } } /// /// 保存结果 /// protected override void buildListBox_analysisResult() { if (this.matOrg == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); return; } if (this.dataGridView1.Rows.Count == 0) { MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text")); 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) { MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text")); return; } //double value4Per = value4Total / this.dataGridView1.Rows.Count; dgvr.Cells[1].Value = value1; dgvr.Cells[2].Value = value2Total; dgvr.Cells[3].Value = value4Total; //dgvr.Cells[4].Value = value4Per;//级别 decimal M = 1;// this.getGainMultiple(); dgvr.Cells[4].Value = 6.6439 * Math.Log10((value4Total * (double)M) / value2Total) - 3.2877; 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; dataTable.Rows.Add(dataRow); this.dataTables.Add(dataTable); if (this.allShow) AllShow(); this.RefreshDataGridView4(); //保存处理后的图片 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 bool drawGuideLines() { return checkBox4.Checked; } //是否绘制截点 protected override bool drawGuidePoints() { return (matOrg != null && this.checkBox5_0.Checked); } //辅助线类型 protected override string[] getTypeNames() { return new string[] { PdnResources.GetString("Menu.Verticalauxiliaryline.text"), PdnResources.GetString("Menu.Horizontalauxiliaryline.text")}; } protected override string getTemplateName() { return "Template.Manager.item3.GrainSizeCutOff_YST347"; } protected override string getProjectEngineeringName() { return "Menu.DedicatedAnalysis.NonferrousMetal.CopperAlloy.Text"; } protected override string getModelName() { return "GrainGBT32461CutOffMethodModel.xml"; } protected override void SubclassInitialize() { InitializeComponent(); InitializeLanguageText(); } #endregion private void MethodCutOffDialog_Load(object sender, EventArgs e) { 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 (!showOrimat() && getGrainBoundryChecked() && checkBox3_0.Checked) { this.documentWorkspace.PhaseModels[1].choise = true; } else { this.documentWorkspace.PhaseModels[1].choise = false; } this.documentWorkspace.Refresh(); } /// /// 设置截点样式 /// /// /// private void button10_Click(object sender, EventArgs e) {//### GrainSizeStandard.IntegrationClass.GrainSurveyPointStyleSettingDialog grainSurveyPointStyleSettingDialog = new GrainSizeStandard.IntegrationClass.GrainSurveyPointStyleSettingDialog();//### grainSurveyPointStyleSettingDialog.StartPosition = FormStartPosition.CenterScreen; grainSurveyPointStyleSettingDialog.ShowDialog(this); } /// /// 鼠标按下 /// /// /// 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 = guideClass.getAddOfRStyle(point1, this.comboBox1.SelectedItem, out rectangleF); if (add == 0 && styleClass.PointKb > 0) rectangleF = guideClass.RectangleFLine; //手动添加截点 styleClass.OnMouseDownFirst(point1, rectangleF, this.linePointList, sender, e); } if (styleClass.PointKb == 0) { //辅助线缩放 guideClass.OnMouseDown(point1, sender, e); //辅助线移动 base.OnMouseDown(sender, e);//## } //手动删除截点或取消添加截点 styleClass.OnMouseDownNext(point1, sender, e); } private int dataTable1sTagInc = 0; /// /// 保存测定结果 /// /// /// private void button1_Click(object sender, EventArgs e) { if (this.matOrg == null) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); return; } DataTable dataTable = new DataTable(); //this.dataGridView111114.Rows.Clear(); DataGridViewRow dgvr = new DataGridViewRow(); dataTable1sTagInc++; dgvr.Tag = dataTable1sTagInc + ""; foreach (DataGridViewColumn c in this.dataGridView1.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[0].Value = this.comboBox1.SelectedItem; dgvr.Cells[1].Value = guideClass.LineLength; dgvr.Cells[2].Value = guideClass.LineDec; double countPoints = styleClass.getCountPoints(); dgvr.Cells[3].Value = countPoints;// (float)this.p1RectangleFs.Count + (float)this.p2RectangleFs.Count / 2; this.dataGridView1.Rows.Add(dgvr); dataTable.TableName = (string)dgvr.Tag; for (int i = 0; i < this.dataGridView1.Columns.Count; i++) { dataTable.Columns.Add("" + i); } DataRow dataRow = dataTable.NewRow(); dataRow["0"] = dgvr.Cells[0].Value; dataRow["1"] = dgvr.Cells[1].Value; dataRow["2"] = dgvr.Cells[2].Value; dataRow["3"] = countPoints;// Convert.ToDecimal(this.p1RectangleFs.Count) + Convert.ToDecimal(this.p2RectangleFs.Count) / 2; dataTable.Rows.Add(dataRow); this.dataTable1s.Add(dataTable); //保存处理后的图片 List tempBit = new List(); Bitmap originalBit = this.bitmap;// 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); if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null) { Mat targetMat = this.documentWorkspace.PhaseModels[0].mat; 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); } graphics.SmoothingMode = SmoothingMode.AntiAlias; drawSubclass/*Draw*/(graphics); tempBit.Add(newBit); if (bitCeDingDic.ContainsKey((string)dgvr.Tag)) bitCeDingDic[(string)dgvr.Tag] = tempBit; else bitCeDingDic.Add((string)dgvr.Tag, tempBit); } /// /// 删除测定结果 /// /// /// private void button4_Click(object sender, EventArgs e) { if (this.dataGridView1.Rows.Count > 0) { if (this.dataGridView1.SelectedRows.Count > 0) { DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { DataGridViewRow gridViewRow = this.dataGridView1.SelectedRows[0]; int selectIndex = gridViewRow.Index; foreach (var dataTable in this.dataTable1s) { if (dataTable.TableName.Equals(gridViewRow.Tag)) { this.dataTable1s.Remove(dataTable); break; } } if (bitCeDingDic.ContainsKey((string)gridViewRow.Tag)) bitCeDingDic.Remove((string)gridViewRow.Tag); this.dataGridView1.Rows.RemoveAt(selectIndex); //RefreshDataGridView1(); } } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!"); } } else { MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!"); } } 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.matOrg != null) { //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!"); styleClass.PointKb = 1; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); } } /// /// 1截点添加 /// /// /// private void button7_0_Click(object sender, EventArgs e) { if (this.matOrg != null) { //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!"); styleClass.PointKb = 2; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); } } private void button8_Click(object sender, EventArgs e) { if (this.matOrg != null) { //MessageBox.Show(PdnResources.GetString("Menu.ftbuttontoaddainterceptadd.Text")+"!"); styleClass.PointKb = 3; } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!"); } } } }