| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991 |
- using OTSCLRINTERFACE;
- using OTSCommon;
- using OTSCommon.DBOperate;
- using OTSCommon.DBOperate.Model;
- using OTSIncAReportApp.OTSRstMgrFunction;
- using OTSIncAReportGraph.Class;
- using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
- using OTSPeriodicTable;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Threading;
- using System.Windows.Forms;
- using static OTSDataType.otsdataconst;
- using Color = System.Drawing.Color;
- namespace OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage
- {
- public partial class ListOfSimilarParticles : Form
- {
- OTSIncAReportGrids.ParticlesGridDevidePage _particlesGridDevidePage;
- CPosXrayClr SelXrayclr = new CPosXrayClr();
- DataTable particlesAll;
- DataTable particles;
- Hashtable table;
- List<string> _RenameInfo;
- private Thread m_mythread;
- //记录线程是否已经运行完成的状态
- private bool m_mythread_state = false;
- //底层操作类
- SEMAndEDSOperate m_OTSIncAReportGridsFun = null;
- frmReportApp m_ReportApp;
- public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, List<string> RenameInfo,frmReportApp ReportApp)
- {
- InitializeComponent();
- _particlesGridDevidePage = particlesGridDevidePage;
- SelXrayclr.SetXrayData(SelXray);
- table = particlesGridDevidePage.table;
- _RenameInfo = RenameInfo;
- m_ReportApp = ReportApp;
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- //设置窗体的双缓冲,以保证大数据时拖动不卡
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
- this.UpdateStyles();
- //利用反射设置DataGridView的双缓冲
- Type dgvType = this.dgV_SimilarParticles.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.dgV_SimilarParticles, true, null);
- this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null);
- this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
- this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.control_XRayTable1.GBInfoStr = "";
- this.control_XRayTable1.GoodChineseName = "";
- this.control_XRayTable1.MaterialName = "";
- this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
- this.control_XRayTable1.Name = "control_XRayTable1";
- this.control_XRayTable1.ShowAnalysisXray = true;
- this.control_XRayTable1.ShowSearchXray = false;
- this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
- this.control_XRayTable1.STDName = "";
- this.control_XRayTable1.Visible = false;
- this.control_XRayTable1.label_close.Visible = true;
- panel1.Controls.Add(this.control_XRayTable1);
- }
- private void btn_Search_Click(object sender, EventArgs e)
- {
- double val;
- if (!double.TryParse(tB_SimilarRatio.Text, out val))
- {
- MessageBox.Show("The value must range from 0 to 100!");
- return;
- }
- else
- {
- this.Cursor = Cursors.WaitCursor;
- particlesAll = ObtainSourceOfSimilarParticles();
- DataTable elementchemistry = _particlesGridDevidePage.Particledata.GetElementChemistry();
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
- DataRow[] drs = elementchemistry.Select(str);
- string ConcatenatedString = "";
- for (int j = 0; j < drs.Length; j++)
- {
- ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
- }
- particlesAll.Rows[i]["Element"] = ConcatenatedString;
- }
- particlesAll.Columns.Add("SimilarRatio", typeof(double));
- DataTable XRayData = _particlesGridDevidePage.Particledata.GetXRayData();
- particlesAll.Columns.Add("XRayDataCount");
- particles = particlesAll.Clone();
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- if (int.Parse(particlesAll.Rows[i]["particleId"].ToString()) > -1)
- {
- string subt = particlesAll.Rows[i]["SubParticles"].ToString();
- uint[] Analysis_xray = new uint[2000];
- particlesAll.Rows[i]["XRayDataCount"] = 0;
- if (subt == "")
- {
- string str = " XrayIndex= " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
- DataRow[] drs = XRayData.Select(str);
- uint xraycount = 0;
- if (drs != null)
- {
- if (drs.Length > 0)
- {
- for (int j = 0; j < 2000; j++)
- {
- Analysis_xray[j] = BitConverter.ToUInt32((byte[])drs[0][2], j * 4);
- }
- for (int j = 0; j < 2000; j++)
- {
- xraycount += Analysis_xray[j];
- }
- particlesAll.Rows[i]["XRayDataCount"] = xraycount;
- }
- }
- }
- else
- {
- DataRow dgvr = particlesAll.Rows[i];
- uint[] Search_xray = new uint[2000];
- _particlesGridDevidePage.Particledata.GetXrayByParticleTagIDAndFieldID_ForMergeParticle(Convert.ToInt32(dgvr["particleId"]), Convert.ToInt32(dgvr["fieldid"]), out Search_xray, out Analysis_xray);
- uint xraycount = 0;
- for (int j = 0; j < 2000; j++)
- {
- xraycount += Analysis_xray[j];
- }
- particlesAll.Rows[i]["XRayDataCount"] = xraycount;
- }
- CPosXrayClr Xrayclr = new CPosXrayClr();
- Xrayclr.SetXrayData(Analysis_xray);
- particlesAll.Rows[i]["SimilarRatio"] = GetCosValue(SelXrayclr, Xrayclr);
- if ((double)particlesAll.Rows[i]["SimilarRatio"] >= val / 100)
- {
- particles.ImportRow(particlesAll.Rows[i]);
- }
- }
- }
-
- particles.DefaultView.Sort = "SimilarRatio DESC";
- particles = particles.DefaultView.ToTable();
- BindDataGridView();
- SetDataGridViewStyle();
- cBx_All.Checked = false;
- cBx_All.Checked = true;
- label3.Text = "共搜索到" + (dgV_SimilarParticles.Rows.Count-1).ToString() + "个相似颗粒";
- this.Cursor = Cursors.Default;
- }
- }
- private void SetDataGridViewStyle()
- {
- //用户不能调整标题的高度
- dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //用户不能调整 行高
- dgV_SimilarParticles.AllowUserToResizeRows = false;
- //点击选择整行
- dgV_SimilarParticles.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- //居中显示
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dgV_SimilarParticles.DefaultCellStyle = dataGridViewCellStyle1;
- dgV_SimilarParticles.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- //再次重覆禁用拖动表头高度,居然有效果了
- dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //设置grid可以复制
- dgV_SimilarParticles.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
- //设置每列的宽度
- dgV_SimilarParticles.Columns[0].Width = 30;//第一列序号的宽度设置一下吧,要不太丑
- dgV_SimilarParticles.Columns[1].Width = 100;
- for (int i = 4; i < dgV_SimilarParticles.Columns.Count; i++)
- {
- dgV_SimilarParticles.Columns[i].Width = 65;
- }
- //设置序号列不排序
- dgV_SimilarParticles.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- dgV_SimilarParticles.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
- //设置序号列不可以设置宽度
- dgV_SimilarParticles.Columns[0].Resizable = DataGridViewTriState.False;
- dgV_SimilarParticles.RowsDefaultCellStyle.BackColor = Color.Azure;
- if (dgV_SimilarParticles.Rows.Count > 0)
- {
- dgV_SimilarParticles.Rows[0].Frozen = true;
- }
- }
- private void BindDataGridView()
- {
- dgV_SimilarParticles.Visible = false;
- dgV_SimilarParticles.Rows.Clear();
- dgV_SimilarParticles.Columns.Clear();
- string str_DefaultComputedColName = "", str_ElementsColName = "";
- DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData");
- DataTable dt = ds.Tables["Member"];
- foreach (DataRow element in dt.Rows)
- {
- string RegName = element["RegName"].ToString();
- if (RegName == "DefaultComputedColName")
- {
- str_DefaultComputedColName = element["strValue"].ToString();
- }
- if (RegName == "ElementsColName")
- {
- str_ElementsColName = element["strValue"].ToString();
- }
- }
- string[] strs = str_DefaultComputedColName.Split(',');
- Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
- keyValues.Add("SimilarRatio", "相似度");
- keyValues.Add("TypeName", table["str6"].ToString());
- keyValues.Add("ParticleImage", table["str5"].ToString());
- keyValues.Add("FieldId", "FieldId");
- keyValues.Add("ParticleId", "ParticleId");
- keyValues.Add("SEMPosX", "SEMPosX");
- keyValues.Add("SEMPosY", "SEMPosY");
- for (int i = 0; i < strs.Count(); i++)
- {
- if (strs[i] == "ParticleCoordinate")
- {
- keyValues.Add("AbPosX", "PosX");
- keyValues.Add("AbPosY", "PosY");
- }
- if (strs[i] == "Area")
- {
- keyValues.Add("Area", table["str21"].ToString());
- }
- if (strs[i] == "EquivalentCircleDiameter")
- {
- keyValues.Add("Equivalent", table["str22"].ToString());
- }
- if (strs[i] == "MaxDiameter")
- {
- keyValues.Add("DMAX", table["str23"].ToString());
- }
- if (strs[i] == "MinDiameter")
- {
- keyValues.Add("DMIN", table["str24"].ToString());
- }
- if (strs[i] == "DiameterRatio")
- {
- keyValues.Add("DiameterRatio", table["str25"].ToString());
- }
- if (strs[i] == "FerretDiameter")
- {
- keyValues.Add("DFERET", table["str26"].ToString());
- }
- if (strs[i] == "PERP")
- {
- keyValues.Add("DPERP", table["str27"].ToString());
- }
- if (strs[i] == "PERI")
- {
- keyValues.Add("PERIMETER", table["str28"].ToString());
- }
- if (strs[i] == "INSCR")
- {
- keyValues.Add("DINSCR", table["str29"].ToString());
- }
- if (strs[i] == "MEAN")
- {
- keyValues.Add("DMEAN", table["str30"].ToString());
- }
- if (strs[i] == "ELONG")
- {
- keyValues.Add("DELONG", table["str31"].ToString());
- }
- if (strs[i] == "ASPECT_ELONG")
- {
- keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
- }
- if (strs[i] == "Orientation")
- {
- keyValues.Add("ORIENTATION", table["str33"].ToString());
- }
- if (strs[i] == "XRayDataCount")
- {
- keyValues.Add("XRayDataCount", "XRay计数");
- }
- }
- keyValues.Add("Element", "Element");
- Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
- for (int irow = 0; irow < keyValues.Count; irow++)
- {
- if (en.MoveNext())
- {
- if (en.Current.Key == "ParticleImage")
- {
- DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
- iconColumn.Name = en.Current.Key;
- iconColumn.HeaderText = en.Current.Value;
- dgV_SimilarParticles.Columns.Add(iconColumn);
- }
- else if (en.Current.Key == "Element")
- {
- }
- else
- {
- dgV_SimilarParticles.Columns.Add(en.Current.Key, en.Current.Value);
- if (en.Current.Key == "Area" || en.Current.Key == "EquivalentCircleDiameter" || en.Current.Key == "MaxDiameter" || en.Current.Key == "MinDiameter" || en.Current.Key == "DiameterRatio" || en.Current.Key == "FerretDiameter" || en.Current.Key == "PERP" || en.Current.Key == "PERI" || en.Current.Key == "INSCR" || en.Current.Key == "MEAN" || en.Current.Key == "ELONG" || en.Current.Key == "ASPECT_ELONG" || en.Current.Key == "Orientation")
- {
- int id = dgV_SimilarParticles.Columns.Count;
- dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType";
- }
- }
- }
- }
- if (particlesAll == null)
- {
- return;
- }
- string particleM = "";
- List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
- for (int i = 0; i < ElementTypeSort.Count; i++)
- {
- if (ElementTypeSort[0] == "")
- {
- ElementTypeSort.RemoveAt(0);
- break;
- }
- dgV_SimilarParticles.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
- int id = dgV_SimilarParticles.Columns.Count;
- dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType";
- }
- string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
- KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
- for (int i = 0; i < particles.Rows.Count; i++)
- {
- Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
- Dictionary<string, Bitmap> fieldpics = new Dictionary<string, Bitmap>();
- int add_rowindex = dgV_SimilarParticles.Rows.Add();
- for (int k = 0; k < keyValues.Count; k++)
- {
- if (enl.MoveNext())
- {
- if (enl.Current.Key == "ParticleImage")
- {
- string subt = particles.Rows[i]["SubParticles"].ToString();
- dgV_SimilarParticles.Rows[add_rowindex].Height = 150;
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
- Bitmap bmap = null;
- if (subt != null && subt != "" && subt != "IsSubParticle")
- {
- double xs = _particlesGridDevidePage.result.GetPixelSize();
- int width = _particlesGridDevidePage.result.GetImageWidth();
- int height = _particlesGridDevidePage.result.GetImageHeight();
- string vs = "," + subt.Replace(':', '-') + ",";
- DataTable dataTable = _particlesGridDevidePage.Particledata.GetParticleAllForBig(vs);//组成拼接颗粒的子颗粒
- bmap = _particlesGridDevidePage.fldImgAccess.GetBitmapForMergedParticle(subt, xs, _particlesGridDevidePage.result.FilePath, height, width, dataTable);
- if (bmap != null)
- {
- string[] str = subt.Split(',');
- bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1] };
- }
- }
- else if (subt != "IsSubParticle")
- {
- if (!fieldpics.Keys.Contains(particles.Rows[i]["fieldid"].ToString()))
- {
- string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
- fieldpics.Add(particles.Rows[i]["fieldid"].ToString(), _particlesGridDevidePage.fldImgAccess.ReadImageFile(imagePath));
- }
- Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particles.Rows[i]["RectLeft"]), Y = Convert.ToInt32(particles.Rows[i]["RectTop"]), Width = Convert.ToInt32(particles.Rows[i]["RectWidth"]), Height = Convert.ToInt32(particles.Rows[i]["RectHeight"]) };
- bmap = _particlesGridDevidePage.fldImgAccess.GetBitmapByParticle(fieldpics[particles.Rows[i]["fieldid"].ToString()], rectangle);
- bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString() };
- dgV_SimilarParticles.Rows[add_rowindex].Height = bmap.Height + 20;
- }
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap;
- }
- if (enl.Current.Key == "DiameterRatio")
- {
- double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
- }
- if (en.Current.Key == "Element")
- {
- }
- if (enl.Current.Key == "ASPECT_ELONG")
- {
- double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
- }
- if (particles.Columns.Contains(enl.Current.Key))
- {
- double num = 0;
- if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
- {
- if (enl.Current.Key == "SimilarRatio")
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 5);
- }
- else
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);}
- }
- else if (enl.Current.Key == "Element")
- {
- List<string> elementtemp = new List<string>(ElementTypeSort);
- string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
- for (int j = 0; j < strcbo.Length; j++)
- {
- if (ElementTypeSort.Count == 0)
- {
- break;
- }
- string[] str = strcbo[j].Split('-');
- if (ElementTypeSort.Contains(str[0]))
- { dgV_SimilarParticles.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
- elementtemp.Remove(str[0].ToString());
- }
- foreach (var ele in elementtemp)
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[ele].Value = "0";
- }
- }
- else
- {
- double val = 0;
- if (double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]), out val))
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = val;
- }
- else
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
- }
- }
- }
- if (enl.Current.Key == "TypeName")
- {
- if (particles.Rows[i]["TypeId"].ToString() == "9")
- {
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = "Not Identified";
- }
- }
- if (enl.Current.Key == "Equivalent")
- {
- double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
- double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
- dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
- }
- if (enl.Current.Key == "AbPosX")
- {
- Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(Convert.ToInt32(particles.Rows[i]["SEMPosX"]), Convert.ToInt32(particles.Rows[i]["SEMPosY"])), new Point(Convert.ToInt32(particles.Rows[i]["PosX"]), Convert.ToInt32(particles.Rows[i]["PosY"])));
- dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosX"].Value = point.X;
- dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y;
- }
- }
- }
- }
- DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
- checkBoxColumn.HeaderText = "选择";
- checkBoxColumn.Name = "IsSelected";
- checkBoxColumn.TrueValue = true;
- checkBoxColumn.FalseValue = false;
- checkBoxColumn.Width = 30;
- checkBoxColumn.ReadOnly = false;
- dgV_SimilarParticles.Columns.Insert(0, checkBoxColumn);
- if (_RenameInfo != null)
- {
- dgV_SimilarParticles.Rows[0].Cells[2].Value = _RenameInfo[1];
- }
- dgV_SimilarParticles.Visible = true;
- }
- private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
- {
- if (posXray == null) return 0;
- if (posXray1 == null) return 0;
- if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
- {
- return 0;
- }
- var pXrayData = posXray.GetXrayData();
- var pXrayData1 = posXray1.GetXrayData();
- // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
- double dotProduct = 0;
- double d1 = 0;
- double d2 = 0;
- for (int i = 0; i < posXray.GetChannelsNum(); i++)
- {
- double r1 = pXrayData[i];
- double r2 = pXrayData1[i];
- r1 *= r2;
- dotProduct = dotProduct + r1;
- }
- d1 = posXray.GetXrayDataVectorNorm();
- d2 = posXray1.GetXrayDataVectorNorm();
- return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
- }
- private void ListOfSimilarParticles_Load(object sender, EventArgs e)
- {
- btn_Search_Click(null, null);
- }
- private void btn_OK_Click(object sender, EventArgs e)
- {
- if (_RenameInfo == null)
- {
- string CategoryName = "";
- //循环选中颗粒
- DataGridViewRow dgvr = dgV_SimilarParticles.Rows[0];
- CategoryName = dgvr.Cells[2].Value.ToString();
- string TypeId = "";
- string TypeName = "";
- string TypeColor = "";
- string GroupName = "";
- string GroupID = "";
- string GroupColor = "";
- string[] resulta = _particlesGridDevidePage.result.GetSTDName().Split('.');
- DataTable data = ReadClassification(_particlesGridDevidePage.result.FilePath, resulta[0]);
- ModifyCategoryForm modifyCategoryForm = new ModifyCategoryForm(data, CategoryName);
- DialogResult result = modifyCategoryForm.ShowDialog();
- if (modifyCategoryForm.DoYouWantToModifyIt)
- {
- TypeId = modifyCategoryForm.OutTypeAndName[0];
- TypeName = modifyCategoryForm.OutTypeAndName[1];
- TypeColor = modifyCategoryForm.OutTypeAndName[2];
- GroupName = modifyCategoryForm.OutTypeAndName[3];
- GroupID = modifyCategoryForm.OutTypeAndName[4];
- GroupColor = modifyCategoryForm.OutTypeAndName[5];
- _RenameInfo = new List<string>();
- _RenameInfo.Add(TypeId);
- _RenameInfo.Add(TypeName);
- _RenameInfo.Add(TypeColor);
- _RenameInfo.Add(GroupName);
- _RenameInfo.Add(GroupID);
- _RenameInfo.Add(GroupColor);
- }
- else
- {
- return;
- }
- }
- List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
- foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
- {
- if (row.Cells["IsSelected"].Value != null && (bool)row.Cells["IsSelected"].Value)
- {
- row.Cells[1].Value = _RenameInfo[0];
- Bitmap ls_bp = (Bitmap)row.Cells[3].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- int i_ls_fieldid = Convert.ToInt32(list_str[0]);
- int i_ls_particleid = Convert.ToInt32(list_str[1]);
- List<int> ints = new List<int>();
- ints.Add(i_ls_fieldid);
- ints.Add(i_ls_particleid);
- var cmd = _particlesGridDevidePage.Particledata.GetUpdataAIncACmd(ints, _RenameInfo);
- cmdlist.Add(cmd);
- }
- }
- _particlesGridDevidePage.Particledata.ExecuteNonQueryBatch(cmdlist);
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- /// <summary>
- /// 读取标准库的ClassifySTD表
- /// </summary>
- /// <param name="a_address"></param>
- /// <returns></returns>
- private DataTable ReadClassification(string a_address, string STDName)
- {
- DataTable dt_STDGroups = new DataTable();
- DataTable dt_ClassifySTD = new DataTable();
- DataTable dt_IncAData = new DataTable();
- var systype = m_ReportApp.m_RptConfigFile.Systype;
- if (systype == OTS_SysType_ID.IncA)
- {
- dt_ClassifySTD.Columns.Add("STDId");
- dt_ClassifySTD.Columns.Add("StrName");
- dt_ClassifySTD.Columns.Add("Color");
- dt_ClassifySTD.Columns.Add("KeyElementList");
- dt_ClassifySTD.Columns.Add("SubElementList");
- dt_ClassifySTD.Columns.Add("UsingImgPropertyList");
- dt_ClassifySTD.Columns.Add("UsingOtherPropertyList");
- dt_ClassifySTD.Columns.Add("Expression");
- dt_ClassifySTD.Columns.Add("Hardness");
- dt_ClassifySTD.Columns.Add("Density");
- dt_ClassifySTD.Columns.Add("Electrical_conductivity");
- dt_ClassifySTD.Columns.Add("BSE");
- dt_ClassifySTD.Columns.Add("Formula");
- dt_ClassifySTD.Columns.Add("Element");
- dt_ClassifySTD.Columns.Add("IfElementAnalysis");
- dt_ClassifySTD.Columns.Add("ListNum");
- dt_ClassifySTD.Columns.Add("GroupId");
- dt_ClassifySTD.Columns.Add("GroupName");
- dt_ClassifySTD.Columns.Add("GroupColor");
- DataTable da = _particlesGridDevidePage.Particledata.GetParticleListForParticlSizeID("area", "");
- for (int i = 0; i < da.Rows.Count; i++)
- {
- if (Convert.ToInt64(da.Rows[i]["TypeId"]) > 9)
- {
- DataRow newRow = dt_ClassifySTD.NewRow();
- newRow["STDId"] = da.Rows[i]["TypeId"];
- newRow["StrName"] = da.Rows[i]["TypeName"];
- newRow["Color"] = da.Rows[i]["TypeColor"];
- newRow["GroupId"] = da.Rows[i]["GroupId"];
- newRow["GroupName"] = da.Rows[i]["GroupName"];
- newRow["GroupColor"] = da.Rows[i]["GroupColor"];
- dt_ClassifySTD.Rows.Add(newRow);
- }
- }
- }
- else
- {
- SqLiteHelper sh_STDGroups = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'");
- dt_STDGroups = sh_STDGroups.ExecuteQuery("select * from STDGroups");
- SqLiteHelper sh_ClassifySTD = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'");
- dt_ClassifySTD = sh_ClassifySTD.ExecuteQuery("select * from ClassifySTD");
- dt_ClassifySTD.Columns.Add("GroupName");
- dt_ClassifySTD.Columns.Add("GroupColor");
- for (int i = 0; i < dt_ClassifySTD.Rows.Count; i++)
- {
- for (int a = 0; a < dt_STDGroups.Rows.Count; a++)
- {
- if (dt_ClassifySTD.Rows[i]["GroupId"].ToString() == dt_STDGroups.Rows[a]["id"].ToString())
- {
- dt_ClassifySTD.Rows[i]["GroupName"] = dt_STDGroups.Rows[a]["name"].ToString();
- dt_ClassifySTD.Rows[i]["GroupColor"] = dt_STDGroups.Rows[a]["color"].ToString();
- continue;
- }
- }
- }
- SqLiteHelper sh_Inclusion = new SqLiteHelper("data source='" + a_address + "\\FIELD_FILES\\Inclusion.db" + "'");
- dt_IncAData = sh_Inclusion.ExecuteQuery("select * from IncAData");
- for (int i = 0; i < dt_IncAData.Rows.Count; i++)
- {
- if (Convert.ToInt64(dt_IncAData.Rows[i]["TypeId"]) > 50000)
- {
- DataRow newRow = dt_ClassifySTD.NewRow();
- newRow["STDId"] = dt_IncAData.Rows[i]["TypeId"];
- newRow["StrName"] = dt_IncAData.Rows[i]["TypeName"];
- newRow["Color"] = dt_IncAData.Rows[i]["TypeColor"];
- newRow["GroupId"] = dt_IncAData.Rows[i]["GroupId"];
- newRow["GroupName"] = dt_IncAData.Rows[i]["GroupName"];
- newRow["GroupColor"] = dt_IncAData.Rows[i]["GroupColor"];
- dt_ClassifySTD.Rows.Add(newRow);
- }
- }
- }
-
- return dt_ClassifySTD;
- }
- private void cBx_All_CheckedChanged(object sender, EventArgs e)
- {
- CheckBox selectAllCheckBox = (CheckBox)sender;
- foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
- {
- DataGridViewCheckBoxCell checkBox = row.Cells["IsSelected"] as DataGridViewCheckBoxCell;
- checkBox.Value = selectAllCheckBox.Checked;
- }
- dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
- }
- DataTable ObtainSourceOfSimilarParticles()
- {
- return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_allParticles("");
- }
- private void btn_Cannnel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- }
- private void dgV_SimilarParticles_MouseUp(object sender, MouseEventArgs e)
- {
- var SelectRows = dgV_SimilarParticles.SelectedRows;
- if (SelectRows.Count != 0)
- {
- if (SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
- uint[] Search_xray = new uint[2000];
- uint[] Analysis_xray = new uint[2000];
- int i_xray_id = 0;
- List<Element> list_celementchemistryclr = new List<Element>();
- Particle particle = new Particle();
- string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
- DataRow[] drs = particles.Select(str);
- DataRow row = drs[0];
- string subt = row["SubParticles"].ToString();
- if (subt != "" && subt != null)
- {
- particle = _particlesGridDevidePage.Particledata.GetXrayByParticleTagIDAndFieldID_ForMergeParticle(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray);
- list_celementchemistryclr = particle.ElementList;
- }
- else
- {
- particle = _particlesGridDevidePage.ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
- }
- List<OTSIncAReportGraph.Controls.ShowElementInfo> list_showelementinfo = _particlesGridDevidePage.Particledata.GetShowElementInfos_ForMergeParticle(list_celementchemistryclr);
- string str_IncAName = "";
- str_IncAName = Convert.ToString(dgvr.Cells[2].Value);
- if (particle == null)
- {
- return;
- }
- control_XRayTable1.SetParticleInfo("Area:" + Math.Round(particle.Area, 2) + " " + "DMAX:" + Math.Round(particle.DMAX, 2) + " " + "DELONG:" + Math.Round(particle.DELONG, 2) + " " + "DFERET:" + Math.Round(particle.DFERET, 2) + " " + "DINSCR:" + Math.Round(particle.DINSCR, 2) + "\n" + "DMEAN:" + Math.Round(particle.DMEAN, 2) + " " + "DMIN:" + Math.Round(particle.DMIN, 2) + " " + "DPERP:" + Math.Round(particle.DPERP, 2) + " " + "ORIENTATION:" + Math.Round(particle.ORIENTATION, 2) + " " + "PERIMETER:" + Math.Round(particle.PERIMETER, 2));
- control_XRayTable1.Visible = true;
- control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
- control_XRayTable1.GBInfoStr = "";
- control_XRayTable1.MaterialName = str_IncAName;
- control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- if (subt == "" || subt == null)
- {
- Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
- Bitmap dpImage = _particlesGridDevidePage.ReportFun.GetBlackAndWhiteImage(particle);
- string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
- string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
- Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
- Bitmap bmap = _particlesGridDevidePage.fldImgAccess.GetBitmapByParticle(dpImage, rectangle);
- Bitmap bmap1 = _particlesGridDevidePage.fldImgAccess.GetBitmapByParticle(m_originalImage, rectangle);
- control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
- Invalidate();
- }
- else
- {
- double xs = _particlesGridDevidePage.result.GetPixelSize();
- int width = _particlesGridDevidePage.result.GetImageWidth();
- int height = _particlesGridDevidePage.result.GetImageHeight();
- int fldid = Convert.ToInt32(dgvr.Cells["fieldid"].Value);
- int partid = Convert.ToInt32(dgvr.Cells["particleId"].Value);
- var listseg = _particlesGridDevidePage.Particledata.GetSegmentData(fldid, partid);
- string vs = "," + subt.Replace(':', '-') + ",";
- DataTable dataTable = _particlesGridDevidePage.Particledata.GetParticleAllForBig(vs);//组成拼接颗粒的子颗粒
- Bitmap bp = _particlesGridDevidePage.fldImgAccess.GetBitmapForBigBlackAndWhiteImage(subt, xs, _particlesGridDevidePage.result.FilePath, height, width,dataTable,listseg);
- control_XRayTable1.SetBitmapOfPictureBox(ls_bp, bp);
- Invalidate();
- }
- }
- }
- }
- private void movetoparticleToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
- string i_ls_fieldid = "";
- string i_ls_particleid = "";
- int cou = dgV_SimilarParticles.SelectedRows.Count;
- if (cou > 0)
- {
- DataGridViewRow dgvr = dgV_SimilarParticles.SelectedRows[cou - 1];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- if (list_str != null)
- {
- i_ls_fieldid = list_str[0];
- i_ls_particleid = list_str[1];
- }
- }
- DataOperation.DataAccess.ParticleData particleData = new DataOperation.DataAccess.ParticleData(_particlesGridDevidePage.result.FilePath);
- Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
- //取得Field的Position,然后执行线程移动SEM到当前Field的位置
- if (m_mythread == null)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Stopped)
- {
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- }
- Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
- //改为线程调用,先判断线程状态
- m_mythread.Start(point);
- }
- #region 连接电镜相关
- /// <summary>
- /// 移动SEM到指定位置线程函数
- /// </summary>
- private void Thread_GO(object in_obj)
- {
- if (m_mythread_state == false)
- {
- m_mythread_state = true;
- Point sem_point = (Point)in_obj;
- //第一步,连接电镜
- m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
- Thread.Sleep(500);
- //第二步,移动到指定位置,先读取再设置
- if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
- {
- m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
- }
- Thread.Sleep(1500);
- m_mythread_state = false;
- }
- }
- #endregion
- private void dgV_SimilarParticles_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Down)
- {
- dgV_SimilarParticles_MouseUp(null, null);
- }
- if (e.KeyData == Keys.Up)
- {
- dgV_SimilarParticles_MouseUp(null, null);
- }
- if (e.KeyData == Keys.Space)
- {
- dgV_SimilarParticles_CellMouseDoubleClick(null,null);
- }
- }
- private void tB_SimilarRatio_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Enter)
- {
- btn_Search_Click(null, null);
- }
- }
- private void dgV_SimilarParticles_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- var SelectRows = dgV_SimilarParticles.SelectedRows;
- if (SelectRows.Count != 0)
- {
- if (SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- if ((bool)dgvr.Cells[0].EditedFormattedValue == true)
- {
- dgvr.Cells[0].Value = false;
- }
- else
- {
- dgvr.Cells[0].Value = true;
- }
- dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
- }
- }
- }
- public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, frmReportApp ReportApp)
- {
- InitializeComponent();
- _particlesGridDevidePage = particlesGridDevidePage;
- SelXrayclr.SetXrayData(SelXray);
- table = particlesGridDevidePage.table;
- m_ReportApp = ReportApp;
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- //设置窗体的双缓冲,以保证大数据时拖动不卡
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
- this.UpdateStyles();
- //利用反射设置DataGridView的双缓冲
- Type dgvType = this.dgV_SimilarParticles.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.dgV_SimilarParticles, true, null);
- this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null);
- this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
- this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.control_XRayTable1.GBInfoStr = "";
- this.control_XRayTable1.GoodChineseName = "";
- this.control_XRayTable1.MaterialName = "";
- this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
- this.control_XRayTable1.Name = "control_XRayTable1";
- this.control_XRayTable1.ShowAnalysisXray = true;
- this.control_XRayTable1.ShowSearchXray = false;
- this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
- this.control_XRayTable1.STDName = "";
- this.control_XRayTable1.Visible = false;
- this.control_XRayTable1.label_close.Visible = true;
- panel1.Controls.Add(this.control_XRayTable1);
- }
- private void 从此颗粒之下取消选择ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var SelectRows = dgV_SimilarParticles.SelectedRows;
- if (SelectRows.Count != 0)
- {
- DataGridViewRow dgvr = SelectRows[0];
- for (int i = dgvr.Index + 1; i < dgV_SimilarParticles.Rows.Count; i++)
- {
- dgV_SimilarParticles.Rows[i].Cells[0].Value=false;
- }
- if(dgvr.Index + 1!= dgV_SimilarParticles.Rows.Count)
- {
- this.cBx_All.CheckedChanged -= new System.EventHandler(this.cBx_All_CheckedChanged);
- cBx_All.Checked=false;
- this.cBx_All.CheckedChanged += new System.EventHandler(this.cBx_All_CheckedChanged);
- }
- }
- }
- }
- }
|