using OpenCvSharp;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.SettingModel;
using PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.GBT32461
{
internal class MethodAreaDialog : GrainSizeStandardDialog
{
#region 组件
private GroupBox groupBox11;
private Button button4;
private Button button2;
private CheckBox checkBox11;
private CheckBox checkBox5_0;
private CheckBox checkBox4_0;
private CheckBox checkBox3_0;
private DataGridViewTextBoxColumn ColumnTotal1;
private DataGridViewTextBoxColumn ColumnTotal2;
private GroupBox groupBox7;
private Button button10;
private Button button3;
private Button button8;
private RadioButton radioButton5;
private RadioButton radioButton4;
private RadioButton radioButton3;
private DataGridViewTextBoxColumn ColumnTotal3;
#endregion 组件
#region 构造函数
public MethodAreaDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) : base(appWorkspace, menuItem, new Base.DedicatedAnalysis.GrainSize.Standard.GBT32461.MethodArea())
{
}
#endregion 构造函数
#region 初始化组件
private void InitializeLanguageText()
{
this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text");
this.button4.Text = PdnResources.GetString("Menu.Refresh.text");
this.button2.Text = PdnResources.GetString("Menu.Setting.Text");
this.checkBox11.Text = PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text");
this.checkBox5_0.Text = PdnResources.GetString("Menu.Displaygrainnumber.text");
this.checkBox4_0.Text = PdnResources.GetString("Menu.displaygrid.text");
this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text");
this.Text = "GBT32461(" + PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Averagegraimethod.text") + ")";
this.Load += new System.EventHandler(this.MethodAreaDialog_Load);
}
private DataGridViewTextBoxColumn Column1;
private DataGridViewTextBoxColumn Column2;
private DataGridViewTextBoxColumn Column3;
private DataGridViewTextBoxColumn Column4;
private DataGridViewTextBoxColumn Column5;
private void MethodAreaDialog_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_0.Checked = (bool)ShowGrainBoundry;
if (GetParamValue1(ParamKey_ShowGrainNumber, out ShowGrainBoundry))//显示晶粒编号
this.checkBox5_0.Checked = (bool)ShowGrainBoundry;
if (GetParamValue1(ParamKey_ShowGrainColor, out ShowGrainBoundry))//用不同颜色显示晶粒
this.checkBox11.Checked = (bool)ShowGrainBoundry;
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.Column1.Name = "Column1";
this.Column1.ReadOnly = true;
//
// Column2
//
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
//
// Column3
//
this.Column3.Name = "Column3";
this.Column3.ReadOnly = true;
//
// Column4
//
this.Column4.Name = "Column4";
this.Column4.ReadOnly = true;
//
// Column5
//
this.Column5.Name = "Column5";
this.Column5.ReadOnly = true;
this.Column5.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
this.Column4.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text");
this.Column3.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Gridsize.text") + "(μm)";
this.Column2.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text");
this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3,
this.Column4,
this.Column5});
this.ColumnTotal1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnTotal2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnTotal3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnTotal1,
this.ColumnTotal2,
this.ColumnTotal3});
//
// ColumnTotal1
//
this.ColumnTotal1.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Gridsize.text") + "(μm)";
this.ColumnTotal1.Name = "ColumnTotal1";
this.ColumnTotal1.ReadOnly = true;
//
// ColumnTotal2
//
this.ColumnTotal2.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text");
this.ColumnTotal2.Name = "ColumnTotal2";
this.ColumnTotal2.ReadOnly = true;
//
// ColumnTotal3
//
this.ColumnTotal3.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
this.ColumnTotal3.Name = "ColumnTotal3";
this.ColumnTotal3.ReadOnly = true;
DetailListStringIndex.Add(0);
DetailListStringIndex.Add(1);
DetailListStringIndex.Add(3);
DetailListStringIndex.Add(4/*5*/);//##############
DetailListNotDoubleIndex.Add(0);
DetailListNotDoubleIndex.Add(1);
DetailListNotDoubleIndex.Add(3);
DetailListNotDoubleIndex.Add(4);
IndexChangedFromIndex.Clear();
IndexChangedToIndex.Clear();
IndexChangedFromIndex.Add(2);
IndexChangedFromIndex.Add(3);
IndexChangedToIndex.Add(0, new int[] { 2/*1*/, 0 });//求和
IndexChangedToIndex.Add(1, new int[] { 2/*1*/, 1 });//求和
//IndexChangedToIndex.Add(2, new int[] { 2, 2 });//平均
IndexChangedToIndex.Add(2, new int[] { 3, -1/*0*/ });//级别
this.button3.FlatStyle = FlatStyle.Flat;
this.button3.FlatAppearance.BorderSize = 0;
this.button3.BackgroundImageLayout = ImageLayout.Zoom;
this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference;
this.button3.Click += new EventHandler(this.button3_click);
this.button10.FlatStyle = FlatStyle.Flat;
this.button10.FlatAppearance.BorderSize = 0;
this.button10.BackgroundImageLayout = ImageLayout.Zoom;
this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
this.button10.Click += new EventHandler(this.button10_click);
this.button8.FlatStyle = FlatStyle.Flat;
this.button8.FlatAppearance.BorderSize = 0;
this.button8.BackgroundImageLayout = ImageLayout.Zoom;
this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
this.button8.Click += new EventHandler(this.button8_click);
getSonData();
}
///
/// 获取参数
///
protected override void getSonData()
{
object ShowGrainBoundry;
if (GetParamValue1(ParamKey_TargetSelection, out ShowGrainBoundry))//目标选择
{
int value = Convert.ToInt32(ShowGrainBoundry);
switch (value)
{
case 1:
this.button8_click(null, null);
break;
case 2:
this.button3_click(null, null);
break;
case 3:
this.button10_click(null, null);
break;
}
}
}
private void button3_click(object sender, EventArgs e)
{
this.TargetSelection = 2;
this.radioButton4.Checked = true;
this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference;
this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
}
private void button10_click(object sender, EventArgs e)
{
this.TargetSelection = 3;
this.radioButton5.Checked = true;
this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle3.png").Reference;
this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference;
}
private void button8_click(object sender, EventArgs e)
{
this.TargetSelection = 1;
this.radioButton3.Checked = true;
this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle1.png").Reference;
this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference;
this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
}
///
/// 计算汇总列表的平均晶粒度级别
///
///
protected override string getGradeTotalCal(DataGridViewRow dgvr, int digits)
{
double aec = double.Parse(dgvr.Cells[0].Value.ToString());
double grainNumber = double.Parse(dgvr.Cells[1].Value.ToString());
aec = aec * 0.001 * 0.001;
decimal M = 1;// this.getGainMultiple();
double small_l = (grainNumber * (double)M * (double)M) / aec;
decimal A = Convert.ToDecimal(small_l * 1);
double[] lengths = {3.88, 7.75 , 11.0, 15.50, 21.9, 25.0, 31.0, 43.8, 62.0, 69.4,
87.7, 100, 124, 175, 204, 248, 278, 351, 400, 496, 625, 701, 816,
992, 1111 , 1403, 1600, 1980, 2500, 2810, 3970, 4440, 5610,
7940, 10000, 11220, 12350, 15870, 20410, 22450, 27780, 31710, 40000, 44900, 63500, 89800
, 111100, 127000, 160000};
// 差值
decimal differenceNew;
decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 2.22, (double)A - 160001)));
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"};
return valueG[first];
}
private void InitializeComponent()
{
this.groupBox11 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.checkBox11 = new System.Windows.Forms.CheckBox();
this.checkBox5_0 = new System.Windows.Forms.CheckBox();
this.checkBox4_0 = new System.Windows.Forms.CheckBox();
this.checkBox3_0 = new System.Windows.Forms.CheckBox();
this.groupBox7 = new System.Windows.Forms.GroupBox();
this.button10 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.groupBox_img.SuspendLayout();
this.groupBox_analysisResult1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox11.SuspendLayout();
this.groupBox7.SuspendLayout();
this.SuspendLayout();
//
// groupBox11
//
this.groupBox11.Controls.Add(this.button2);
this.groupBox11.Controls.Add(this.button4);
this.groupBox11.Controls.Add(this.checkBox11);
this.groupBox11.Controls.Add(this.checkBox5_0);
this.groupBox11.Controls.Add(this.checkBox4_0);
this.groupBox11.Controls.Add(this.checkBox3_0);
this.groupBox11.Location = new System.Drawing.Point(179, 373);
this.groupBox11.Name = "groupBox11";
this.groupBox11.Size = new System.Drawing.Size(356, 71);
this.groupBox11.TabIndex = 38;
this.groupBox11.TabStop = false;
//
// button2
//
this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button2.Location = new System.Drawing.Point(271, 41);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 22);
this.button2.TabIndex = 19;
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button4
//
this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button4.Location = new System.Drawing.Point(271, 17);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 22);
this.button4.TabIndex = 18;
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// checkBox11
//
this.checkBox11.AutoSize = true;
this.checkBox11.Checked = true;
this.checkBox11.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox11.Location = new System.Drawing.Point(139, 44);
this.checkBox11.Name = "checkBox11";
this.checkBox11.Size = new System.Drawing.Size(15, 14);
this.checkBox11.TabIndex = 3;
this.checkBox11.UseVisualStyleBackColor = true;
this.checkBox11.CheckedChanged += new System.EventHandler(this.checkBox11_CheckedChanged);
//
// 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(140, 22);
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_0
//
this.checkBox4_0.AutoSize = true;
this.checkBox4_0.Checked = true;
this.checkBox4_0.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox4_0.Location = new System.Drawing.Point(15, 44);
this.checkBox4_0.Name = "checkBox4_0";
this.checkBox4_0.Size = new System.Drawing.Size(15, 14);
this.checkBox4_0.TabIndex = 1;
this.checkBox4_0.UseVisualStyleBackColor = true;
this.checkBox4_0.CheckedChanged += new System.EventHandler(this.checkBox4_0_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, 22);
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);
//
// groupBox7
//
this.groupBox7.Controls.Add(this.button10);
this.groupBox7.Controls.Add(this.button3);
this.groupBox7.Controls.Add(this.button8);
this.groupBox7.Controls.Add(this.radioButton5);
this.groupBox7.Controls.Add(this.radioButton4);
this.groupBox7.Controls.Add(this.radioButton3);
this.groupBox7.Location = new System.Drawing.Point(179, 450);
this.groupBox7.Name = "groupBox7";
this.groupBox7.Size = new System.Drawing.Size(356, 77);
this.groupBox7.TabIndex = 41;
this.groupBox7.TabStop = false;
this.groupBox7.Text = "目标选择";
//
// button10
//
this.button10.Location = new System.Drawing.Point(60, 21);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(40, 40);
this.button10.TabIndex = 5;
this.button10.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Location = new System.Drawing.Point(14, 21);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(40, 40);
this.button3.TabIndex = 4;
this.button3.UseVisualStyleBackColor = true;
//
// button8
//
this.button8.Location = new System.Drawing.Point(106, 21);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(40, 40);
this.button8.TabIndex = 3;
this.button8.UseVisualStyleBackColor = true;
this.button8.Visible = false;
//
// radioButton5
//
this.radioButton5.AutoSize = true;
this.radioButton5.Location = new System.Drawing.Point(238, 55);
this.radioButton5.Name = "radioButton5";
this.radioButton5.Size = new System.Drawing.Size(14, 13);
this.radioButton5.TabIndex = 2;
this.radioButton5.UseVisualStyleBackColor = true;
this.radioButton5.Visible = false;
//
// radioButton4
//
this.radioButton4.AutoSize = true;
this.radioButton4.Checked = true;
this.radioButton4.Location = new System.Drawing.Point(297, 44);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(14, 13);
this.radioButton4.TabIndex = 1;
this.radioButton4.TabStop = true;
this.radioButton4.UseVisualStyleBackColor = true;
this.radioButton4.Visible = false;
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(279, 21);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(14, 13);
this.radioButton3.TabIndex = 0;
this.radioButton3.UseVisualStyleBackColor = true;
this.radioButton3.Visible = false;
//
// MethodAreaDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.ClientSize = new System.Drawing.Size(1127, 810);
this.Controls.Add(this.groupBox7);
this.Controls.Add(this.groupBox11);
this.Name = "MethodAreaDialog";
this.Controls.SetChildIndex(this.groupBox3, 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.groupBox6groupBox_analysisResult2, 0);
this.Controls.SetChildIndex(this.groupBox_report, 0);
this.Controls.SetChildIndex(this.groupBox11, 0);
this.Controls.SetChildIndex(this.groupBox7, 0);
this.groupBox_img.ResumeLayout(false);
this.groupBox_analysisResult1.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox11.ResumeLayout(false);
this.groupBox11.PerformLayout();
this.groupBox7.ResumeLayout(false);
this.groupBox7.PerformLayout();
this.ResumeLayout(false);
}
#endregion 初始化组件
#region 需继承方法
protected override Boolean ShowGrainBoundryChecked()
{
return !showOrimat() && checkBox3_0.Checked;
}
protected override void refreshWhileImgChanged()
{
if (this.grainColorsMatDict.ContainsKey(getCurrentWorkTag()))
this.documentWorkspace.PhaseModels[2].mat = this.grainColorsMatDict[getCurrentWorkTag()];
if (this.bitmap != null && this.documentWorkspace.PhaseModels[2].mat != null)
{
//try
//{
// GetNumberOfGrains();
//}
//catch (Exception)
//{
//}
}
else
{
this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示##效果考虑优化
GSSClass.standardModel.massLabelPoints.Clear();//1013###19098(切换图片的时候前一张图的信息不遗留显示)}
this.documentWorkspace.Refresh();
}
}
///
/// 是否用不同颜色显示晶粒
///
///
protected override Boolean ShowGrainColorChecked()
{
return checkBox11.Checked;
}
///
/// 保存结果
///
protected override void buildListBox_analysisResult(string imagesKey, int analysisPicture, bool saveAll = false)
{
if (this.matOrg == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
return;
}
if (this.comboBox1.SelectedItem != null && !PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem))
{
string imgName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();
string tag = imagesKey;
System.Data.DataTable dataTable = new System.Data.DataTable();
bool replace = false;
int add = 0;
foreach (ListViewItem item in this.listView2.Items)
{
if (item.Tag.Equals(tag))
{
add++;
if (saveAll)
{
replace = true;
break;
}
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();
foreach (DataGridViewColumn c in this.dataGridView2.Columns)
{
dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
}
dgvr.Cells[0].Value = imgName;
dgvr.Cells[1].Value = this.comboBox1.SelectedItem;
if (analysisPicture != this.selectPicture)//更新二值图片
binaryClass.updateAnalysisData(imagesKey, analysisPicture);
GrainSizeGuideModel cal_GuideModel = this.GSSClass.GuideClass.guideModel;
if (this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
cal_GuideModel = this.GSSClass.GuideClass.guideDict[imagesKey];
//else if (analysisPicture != this.selectPicture)//根据选择的辅助线 计算对应图片的数据
//{
// this.calcOtherImgs(imagesKey, analysisPicture);
//}
if (this.GSSClass.GuideClass.guideModel.oldSelectItem == null)
this.GSSClass.GuideClass.guideModel.oldSelectItem = this.comboBox1SelectedItem.ToString();
if (cal_GuideModel.oldSelectItem == null)//##
cal_GuideModel.oldSelectItem = this.GSSClass.GuideClass.guideModel.oldSelectItem;
GrainSizeStandardModel cal_StandardModel = this.GSSClass.standardModel;
if (imagesKey != null)
{
if (!this.GSSClass.standardDict.ContainsKey(imagesKey))
this.GSSClass.standardDict.Add(imagesKey, this.GSSClass.standardModel.cloneListParamModel());
cal_StandardModel = this.GSSClass.standardDict[imagesKey];
if (analysisPicture == this.selectPicture && imagesKey.Equals(getCurrentWorkTag()))
this.GSSClass.standardModel = this.GSSClass.standardDict[imagesKey];
}
// 是否矩形辅助线
int isRect;
double aec = GSSClass.GuideClass.guideArea(cal_GuideModel, cal_GuideModel.oldSelectItem, out isRect, 0/*this.gbtType*/);
dgvr.Cells[2].Value = aec;
aec = aec * 0.001 * 0.001;
double grainNumber = GetNumberOfGrains(/*#########*/cal_StandardModel, cal_GuideModel, imagesKey/*getCurrentWorkTag()*/, analysisPicture/*this.selectPicture*/);
if (grainNumber > (int)grainNumber)
{
grainNumber = grainNumber + 0.5;
}
dgvr.Cells[3].Value = grainNumber;
decimal M = 1;// this.getGainMultiple();
double small_l = (grainNumber * (double)M * (double)M) / aec;
decimal A = Convert.ToDecimal(small_l * 1);
double[] lengths = {3.88, 7.75 , 11.0, 15.50, 21.9, 25.0, 31.0, 43.8, 62.0, 69.4,
87.7, 100, 124, 175, 204, 248, 278, 351, 400, 496, 625, 701, 816,
992, 1111 , 1403, 1600, 1980, 2500, 2810, 3970, 4440, 5610,
7940, 10000, 11220, 12350, 15870, 20410, 22450, 27780, 31710, 40000, 44900, 63500, 89800
, 111100, 127000, 160000};
// 差值
decimal differenceNew;//##20716
decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 2.88, (double)A - 160001)));
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[4].Value = 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;
}
}
foreach (DataGridViewColumn c in this.dataGridView2.Columns)
{
dataTable.Columns.Add(c.HeaderText);
}
for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
{
DataRow dataRow = dataTable.NewRow();
for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
{
dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value;
}
dataTable.Rows.Add(dataRow);
}
this.dataTables.Add(dataTable);
this.RefreshDataGridView4();
//保存处理后的图片
double pantographRatio = this.appWorkspace.DocumentWorkspaces[analysisPicture/*this.selectPicture*/].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
List tempBit = new List();
Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[analysisPicture].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 (binaryClass.getModelMat(imagesKey) != null)
{
Mat targetMat = binaryClass.getModelMat(imagesKey);
graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
}
if (this.grainBoundaryMatDict.ContainsKey(imagesKey))
{
Mat targetMat = this.grainBoundaryMatDict[imagesKey];
graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
}
if (this.grainColorsMatDict.ContainsKey(imagesKey) && !bcOriginChecked() && ShowGrainColorChecked())
{
Mat targetMat = this.grainColorsMatDict[imagesKey];
graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
}
graphics.SmoothingMode = SmoothingMode.AntiAlias;
drawSubclass(graphics);
newBit.Tag = pantographRatio;
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("X"+ PdnResources.GetString("Menu.coordinates.Text"));
columnName.Add("Y"+ PdnResources.GetString("Menu.coordinates.Text"));
columnName.Add(PdnResources.GetString("Menu.Whethertheinternal.Text"));
dataList.Add(columnName);
if (cal_StandardModel.massLabelPoints.Count > 0)
{
int index = 0;
int outMaxIndex = cal_StandardModel.massLabelPoints.Count - 0 - cal_StandardModel.within;
foreach (var item in cal_StandardModel.massLabelPoints.Values)
{
List strList = new List();
strList.Add(("" + (++index)).ToString());
strList.Add(item[2].ToString());
strList.Add(item[3].ToString());
if (outMaxIndex < index)
strList.Add(PdnResources.GetString("Menu.Yes.text"));
else
strList.Add(PdnResources.GetString("Menu.no.text"));
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);
}
}
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text")+"!");
}
}
protected override void SubclassInitialize()
{
InitializeComponent();
InitializeLanguageText();
}
//是否绘制辅助线
protected override bool showGridChecked()
{
return checkBox4_0.Checked;
}
////是否绘制截点
//protected override bool drawGuidePoints()
//{
// return (matOrg != null && this.checkBox5_0.Checked);
//}
////是否显示截点
//protected override Boolean drawDisplaySections()//##1
//{
// return this.checkBox5_0.Checked;
//}
//是否绘制编号
protected override bool showGrainNumberChecked()
{
return this.checkBox5_0.Checked;
}
//辅助线类型
protected override string[] getTypeNames()
{
return new string[] {
PdnResources.GetString("Menu.circular.Text")};
}
//protected override string getTemplateName()
//{
// return "Template.Manager.item3.GrainSizeArea_GBT32461";
//}
protected override string getProjectEngineeringName()
{
return "Menu.DedicatedAnalysis.NonferrousMetal.AluminiumAlloy.Text";
}
//protected override string getModelName()
//{
// return "GrainGBT32461AreaMethodModel.xml";
//}
#endregion
///
/// 设置晶粒颜色
///
///
///
private void button2_Click(object sender, EventArgs e)
{
//if (this.matOrg == null)
//{
// MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
// return;
//}
ShowGrainColorSettingDialog();
}
///
/// 刷新晶粒编号
///
///
///
private void button4_Click(object sender, EventArgs e)
{
if (this.matOrg == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
return;
}
GetNumberOfGrains();
}
///
/// 是否显示晶界
///
///
///
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 checkBox4_0_CheckedChanged(object sender, EventArgs e)
{
this.documentWorkspace.Refresh();
}
private void checkBox11_CheckedChanged(object sender, EventArgs e)
{
if (!showOrimat() && checkBox11.Checked)
{
this.documentWorkspace.PhaseModels[2].choise = true;
}
else
{
this.documentWorkspace.PhaseModels[2].choise = false;
}
this.documentWorkspace.Refresh();
}
private void checkBox5_0_CheckedChanged(object sender, EventArgs e)
{
this.documentWorkspace.Refresh();
}
}
}