ListOfSimilarParticles.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. using OTSCLRINTERFACE;
  2. using OTSCommon;
  3. using OTSCommon.DBOperate.Model;
  4. using OTSIncAReportApp.OTSRstMgrFunction;
  5. using OTSIncAReportGraph.Class;
  6. using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
  7. using OTSPeriodicTable;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Data.SQLite;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Threading;
  17. using System.Windows.Forms;
  18. using Color = System.Drawing.Color;
  19. namespace OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage
  20. {
  21. public partial class ListOfSimilarParticles : Form
  22. {
  23. OTSIncAReportGrids.ParticlesGridDevidePage _particlesGridDevidePage;
  24. CPosXrayClr SelXrayclr = new CPosXrayClr();
  25. DataTable particlesAll;
  26. DataTable particles;
  27. Hashtable table;
  28. int _classifyid;
  29. List<string> _RenameInfo;
  30. private Thread m_mythread;
  31. //记录线程是否已经运行完成的状态
  32. private bool m_mythread_state = false;
  33. //底层操作类
  34. OTSReportGridsFun m_OTSIncAReportGridsFun = null;
  35. public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, int classifyid, List<string> RenameInfo)
  36. {
  37. InitializeComponent();
  38. _particlesGridDevidePage = particlesGridDevidePage;
  39. SelXrayclr.SetXrayData(SelXray);
  40. table = particlesGridDevidePage.table;
  41. _classifyid = classifyid;
  42. _RenameInfo = RenameInfo;
  43. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  44. //设置窗体的双缓冲,以保证大数据时拖动不卡
  45. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  46. this.UpdateStyles();
  47. //利用反射设置DataGridView的双缓冲
  48. Type dgvType = this.dgV_SimilarParticles.GetType();
  49. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  50. pi.SetValue(this.dgV_SimilarParticles, true, null);
  51. this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null);
  52. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  53. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  54. this.control_XRayTable1.GBInfoStr = "";
  55. this.control_XRayTable1.GoodChineseName = "";
  56. this.control_XRayTable1.MaterialName = "";
  57. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  58. this.control_XRayTable1.Name = "control_XRayTable1";
  59. this.control_XRayTable1.ShowAnalysisXray = true;
  60. this.control_XRayTable1.ShowSearchXray = false;
  61. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  62. this.control_XRayTable1.STDName = "";
  63. this.control_XRayTable1.Visible = false;
  64. this.control_XRayTable1.label_close.Visible = true;
  65. panel1.Controls.Add(this.control_XRayTable1);
  66. }
  67. private void btn_Search_Click(object sender, EventArgs e)
  68. {
  69. double val;
  70. if (!double.TryParse(tB_SimilarRatio.Text, out val))
  71. {
  72. MessageBox.Show("The value must range from 0 to 100!");
  73. return;
  74. }
  75. else
  76. {
  77. this.Cursor = Cursors.WaitCursor;
  78. particlesAll = ObtainSourceOfSimilarParticles(_classifyid);
  79. DataTable elementchemistry = _particlesGridDevidePage.Particledata.GetElementChemistry();
  80. for (int i = 0; i < particlesAll.Rows.Count; i++)
  81. {
  82. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  83. DataRow[] drs = elementchemistry.Select(str);
  84. string ConcatenatedString = "";
  85. for (int j = 0; j < drs.Length; j++)
  86. {
  87. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  88. }
  89. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  90. }
  91. particlesAll.Columns.Add("SimilarRatio", typeof(double));
  92. particles = particlesAll.Clone();
  93. DataTable mergeParticles = _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_mergeParticles("");
  94. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  95. {
  96. _particlesGridDevidePage.RemoveMergeParticles(ref particlesAll, mergeParticles);
  97. }
  98. foreach (DataRow row in particlesAll.Rows)
  99. {
  100. var tmpPart = _particlesGridDevidePage.Particledata.GetParticleXrayDataByFidAndPid(row["fieldid"].ToString(), row["xrayid"].ToString());
  101. if (tmpPart != null)
  102. {
  103. uint[] Search_xray = new uint[2000];
  104. for (int i = 0; i < 2000; i++)
  105. {
  106. Search_xray[i] = BitConverter.ToUInt32(tmpPart.XRayData, i * 4);
  107. }
  108. CPosXrayClr Xrayclr = new CPosXrayClr();
  109. Xrayclr.SetXrayData(Search_xray);
  110. row["SimilarRatio"] = GetCosValue(SelXrayclr, Xrayclr);
  111. if ((double)row["SimilarRatio"] >= val/100)
  112. {
  113. particles.ImportRow(row);
  114. }
  115. }
  116. }
  117. particles.DefaultView.Sort = "SimilarRatio DESC";
  118. particles = particles.DefaultView.ToTable();
  119. BindDataGridView();
  120. SetDataGridViewStyle();
  121. cBx_All.Checked = false;
  122. cBx_All.Checked = true;
  123. this.Cursor = Cursors.Default;
  124. }
  125. }
  126. private void SetDataGridViewStyle()
  127. {
  128. //用户不能调整标题的高度
  129. dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  130. //用户不能调整 行高
  131. dgV_SimilarParticles.AllowUserToResizeRows = false;
  132. //点击选择整行
  133. dgV_SimilarParticles.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  134. //居中显示
  135. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  136. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  137. dgV_SimilarParticles.DefaultCellStyle = dataGridViewCellStyle1;
  138. dgV_SimilarParticles.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  139. //再次重覆禁用拖动表头高度,居然有效果了
  140. dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  141. //设置grid可以复制
  142. dgV_SimilarParticles.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  143. //设置每列的宽度
  144. dgV_SimilarParticles.Columns[0].Width = 30;//第一列序号的宽度设置一下吧,要不太丑
  145. dgV_SimilarParticles.Columns[1].Width = 50;
  146. for (int i = 4; i < dgV_SimilarParticles.Columns.Count; i++)
  147. {
  148. dgV_SimilarParticles.Columns[i].Width = 65;
  149. }
  150. //设置序号列不排序
  151. dgV_SimilarParticles.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  152. dgV_SimilarParticles.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  153. //设置序号列不可以设置宽度
  154. dgV_SimilarParticles.Columns[0].Resizable = DataGridViewTriState.False;
  155. dgV_SimilarParticles.RowsDefaultCellStyle.BackColor = Color.Azure;
  156. if (dgV_SimilarParticles.Rows.Count > 0)
  157. {
  158. dgV_SimilarParticles.Rows[0].Frozen = true;
  159. }
  160. }
  161. private void BindDataGridView()
  162. {
  163. dgV_SimilarParticles.Visible = false;
  164. dgV_SimilarParticles.Rows.Clear();
  165. dgV_SimilarParticles.Columns.Clear();
  166. string str_DefaultComputedColName = "", str_ElementsColName = "";
  167. DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData");
  168. DataTable dt = ds.Tables["Member"];
  169. foreach (DataRow element in dt.Rows)
  170. {
  171. string RegName = element["RegName"].ToString();
  172. if (RegName == "DefaultComputedColName")
  173. {
  174. str_DefaultComputedColName = element["strValue"].ToString();
  175. }
  176. if (RegName == "ElementsColName")
  177. {
  178. str_ElementsColName = element["strValue"].ToString();
  179. }
  180. }
  181. string[] strs = str_DefaultComputedColName.Split(',');
  182. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  183. keyValues.Add("SimilarRatio", "相似度");
  184. keyValues.Add("TypeName", table["str6"].ToString());
  185. keyValues.Add("ParticleImage", table["str5"].ToString());
  186. keyValues.Add("FieldId", "FieldId");
  187. keyValues.Add("ParticleId", "ParticleId");
  188. keyValues.Add("SEMPosX", "SEMPosX");
  189. keyValues.Add("SEMPosY", "SEMPosY");
  190. for (int i = 0; i < strs.Count(); i++)
  191. {
  192. if (strs[i] == "ParticleCoordinate")
  193. {
  194. keyValues.Add("AbPosX", "PosX");
  195. keyValues.Add("AbPosY", "PosY");
  196. }
  197. if (strs[i] == "Area")
  198. {
  199. keyValues.Add("Area", table["str21"].ToString());
  200. }
  201. if (strs[i] == "EquivalentCircleDiameter")
  202. {
  203. keyValues.Add("Equivalent", table["str22"].ToString());
  204. }
  205. if (strs[i] == "MaxDiameter")
  206. {
  207. keyValues.Add("DMAX", table["str23"].ToString());
  208. }
  209. if (strs[i] == "MinDiameter")
  210. {
  211. keyValues.Add("DMIN", table["str24"].ToString());
  212. }
  213. if (strs[i] == "DiameterRatio")
  214. {
  215. keyValues.Add("DiameterRatio", table["str25"].ToString());
  216. }
  217. if (strs[i] == "FerretDiameter")
  218. {
  219. keyValues.Add("DFERET", table["str26"].ToString());
  220. }
  221. if (strs[i] == "PERP")
  222. {
  223. keyValues.Add("DPERP", table["str27"].ToString());
  224. }
  225. if (strs[i] == "PERI")
  226. {
  227. keyValues.Add("PERIMETER", table["str28"].ToString());
  228. }
  229. if (strs[i] == "INSCR")
  230. {
  231. keyValues.Add("DINSCR", table["str29"].ToString());
  232. }
  233. if (strs[i] == "MEAN")
  234. {
  235. keyValues.Add("DMEAN", table["str30"].ToString());
  236. }
  237. if (strs[i] == "ELONG")
  238. {
  239. keyValues.Add("DELONG", table["str31"].ToString());
  240. }
  241. if (strs[i] == "ASPECT_ELONG")
  242. {
  243. keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
  244. }
  245. if (strs[i] == "Orientation")
  246. {
  247. keyValues.Add("ORIENTATION", table["str33"].ToString());
  248. }
  249. if (strs[i] == "XRayDataCount")
  250. {
  251. keyValues.Add("XRayDataCount", "XRay计数");
  252. }
  253. }
  254. keyValues.Add("Element", "Element");
  255. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  256. for (int irow = 0; irow < keyValues.Count; irow++)
  257. {
  258. if (en.MoveNext())
  259. {
  260. if (en.Current.Key == "ParticleImage")
  261. {
  262. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  263. iconColumn.Name = en.Current.Key;
  264. iconColumn.HeaderText = en.Current.Value;
  265. dgV_SimilarParticles.Columns.Add(iconColumn);
  266. }
  267. else if (en.Current.Key == "Element")
  268. {
  269. }
  270. else
  271. {
  272. dgV_SimilarParticles.Columns.Add(en.Current.Key, en.Current.Value);
  273. 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")
  274. {
  275. int id = dgV_SimilarParticles.Columns.Count;
  276. dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType";
  277. }
  278. }
  279. }
  280. }
  281. if (particlesAll == null)
  282. {
  283. return;
  284. }
  285. string particleM = "";
  286. List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
  287. for (int i = 0; i < ElementTypeSort.Count; i++)
  288. {
  289. if (ElementTypeSort[0] == "")
  290. {
  291. ElementTypeSort.RemoveAt(0);
  292. break;
  293. }
  294. dgV_SimilarParticles.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
  295. int id = dgV_SimilarParticles.Columns.Count;
  296. dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType";
  297. }
  298. string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
  299. KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  300. for (int i = 0; i < particles.Rows.Count; i++)
  301. {
  302. Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  303. int add_rowindex = dgV_SimilarParticles.Rows.Add();
  304. for (int k = 0; k < keyValues.Count; k++)
  305. {
  306. if (enl.MoveNext())
  307. {
  308. if (enl.Current.Key == "ParticleImage")
  309. {
  310. if (particles.Columns.Contains("SubParticles"))
  311. {
  312. string subt = particles.Rows[i]["SubParticles"].ToString();
  313. if (subt != null && subt != "")
  314. {
  315. double ScanFieldSize = _particlesGridDevidePage.result.GetScanFieldSizeX();
  316. string filePatht = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
  317. string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
  318. Bitmap tempbit = _particlesGridDevidePage.Particledata.ReadImageFile(imagePatht);
  319. int pixw = tempbit.Width;
  320. double xs = pixw / ScanFieldSize;
  321. particleM = particleM + "," + subt;
  322. Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapForBig(subt, xs, _particlesGridDevidePage.result.FilePath, tempbit.Height, tempbit.Width);
  323. if (bmap != null)
  324. {
  325. string[] str = subt.Split(',');
  326. bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
  327. dgV_SimilarParticles.Rows[add_rowindex].Height = 150;
  328. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap;
  329. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  330. dgV_SimilarParticles.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate;
  331. }
  332. else
  333. {
  334. dgV_SimilarParticles.Rows[add_rowindex].Height = 150;
  335. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  336. }
  337. }
  338. }
  339. else
  340. {
  341. if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  342. {
  343. string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  344. FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), _particlesGridDevidePage.Particledata.ReadImageFile(imagePath));
  345. }
  346. 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"]) };
  347. Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
  348. bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString(), particles.Rows[i]["XrayId"].ToString() };
  349. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap;
  350. dgV_SimilarParticles.Rows[add_rowindex].Height = bmap.Height + 20;
  351. }
  352. }
  353. if (enl.Current.Key == "DiameterRatio")
  354. {
  355. double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  356. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  357. }
  358. if (en.Current.Key == "Element")
  359. {
  360. }
  361. if (enl.Current.Key == "ASPECT_ELONG")
  362. {
  363. double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  364. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  365. }
  366. if (particles.Columns.Contains(enl.Current.Key))
  367. {
  368. double num = 0;
  369. if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  370. {
  371. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  372. }
  373. else if (enl.Current.Key == "Element")
  374. {
  375. List<string> elementtemp = new List<string>(ElementTypeSort);
  376. string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  377. for (int j = 0; j < strcbo.Length; j++)
  378. {
  379. if (ElementTypeSort.Count == 0)
  380. {
  381. break;
  382. }
  383. string[] str = strcbo[j].Split('-');
  384. if (ElementTypeSort.Contains(str[0]))
  385. { dgV_SimilarParticles.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
  386. elementtemp.Remove(str[0].ToString());
  387. }
  388. foreach (var ele in elementtemp)
  389. {
  390. dgV_SimilarParticles.Rows[add_rowindex].Cells[ele].Value = "0";
  391. }
  392. }
  393. else
  394. {
  395. double val = 0;
  396. if (double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]), out val))
  397. {
  398. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = val;
  399. }
  400. else
  401. {
  402. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  403. }
  404. }
  405. }
  406. if (enl.Current.Key == "TypeName")
  407. {
  408. if (particles.Rows[i]["TypeId"].ToString() == "9")
  409. {
  410. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  411. }
  412. }
  413. if (enl.Current.Key == "Equivalent")
  414. {
  415. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  416. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  417. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  418. }
  419. if (enl.Current.Key == "AbPosX")
  420. {
  421. 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"])));
  422. dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosX"].Value = point.X;
  423. dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y;
  424. }
  425. }
  426. }
  427. }
  428. DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
  429. checkBoxColumn.HeaderText = "选择";
  430. checkBoxColumn.Name = "IsSelected";
  431. checkBoxColumn.TrueValue = true;
  432. checkBoxColumn.FalseValue = false;
  433. checkBoxColumn.Width = 30;
  434. checkBoxColumn.ReadOnly = false;
  435. dgV_SimilarParticles.Columns.Insert(0, checkBoxColumn);
  436. dgV_SimilarParticles.Rows[0].Cells[2].Value = _RenameInfo[1];
  437. dgV_SimilarParticles.Visible = true;
  438. }
  439. private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
  440. {
  441. if (posXray == null) return 0;
  442. if (posXray1 == null) return 0;
  443. if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
  444. {
  445. return 0;
  446. }
  447. var pXrayData = posXray.GetXrayData();
  448. var pXrayData1 = posXray1.GetXrayData();
  449. // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
  450. double dotProduct = 0;
  451. double d1 = 0;
  452. double d2 = 0;
  453. for (int i = 0; i < posXray.GetChannelsNum(); i++)
  454. {
  455. double r1 = pXrayData[i];
  456. double r2 = pXrayData1[i];
  457. r1 *= r2;
  458. dotProduct = dotProduct + r1;
  459. }
  460. d1 = posXray.GetXrayDataVectorNorm();
  461. d2 = posXray1.GetXrayDataVectorNorm();
  462. return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
  463. }
  464. private void ListOfSimilarParticles_Load(object sender, EventArgs e)
  465. {
  466. btn_Search_Click(null, null);
  467. }
  468. private void btn_OK_Click(object sender, EventArgs e)
  469. {
  470. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  471. foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
  472. {
  473. if (row.Cells["IsSelected"].Value != null && (bool)row.Cells["IsSelected"].Value)
  474. {
  475. row.Cells[1].Value = _RenameInfo[0];
  476. Bitmap ls_bp = (Bitmap)row.Cells[3].Value;
  477. List<string> list_str = (List<string>)ls_bp.Tag;
  478. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  479. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  480. List<int> ints = new List<int>();
  481. ints.Add(i_ls_fieldid);
  482. ints.Add(i_ls_particleid);
  483. var cmd = _particlesGridDevidePage.Particledata.GetUpdataAIncACmd(ints, _RenameInfo);
  484. cmdlist.Add(cmd);
  485. }
  486. }
  487. _particlesGridDevidePage.Particledata.ExecuteNonQueryBatch(cmdlist);
  488. this.DialogResult = DialogResult.OK;
  489. this.Close();
  490. }
  491. private void dgV_SimilarParticles_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  492. {
  493. var SelectRows = dgV_SimilarParticles.SelectedRows;
  494. if (SelectRows.Count != 0)
  495. {
  496. if (SelectRows.Count == 1)
  497. {
  498. DataGridViewRow dgvr = SelectRows[0];
  499. if ((bool)dgvr.Cells[0].EditedFormattedValue == true)
  500. {
  501. dgvr.Cells[0].Value = false;
  502. }
  503. else
  504. {
  505. dgvr.Cells[0].Value = true;
  506. }
  507. dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
  508. }
  509. }
  510. }
  511. private void cBx_All_CheckedChanged(object sender, EventArgs e)
  512. {
  513. CheckBox selectAllCheckBox = (CheckBox)sender;
  514. foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
  515. {
  516. DataGridViewCheckBoxCell checkBox = row.Cells["IsSelected"] as DataGridViewCheckBoxCell;
  517. checkBox.Value = selectAllCheckBox.Checked;
  518. }
  519. dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
  520. }
  521. DataTable ObtainSourceOfSimilarParticles(int _classifyid)
  522. {
  523. if (_classifyid == -1)
  524. {
  525. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_InvalidParticle("");
  526. }
  527. else if (_classifyid == 9)
  528. {
  529. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_NotIdentifyParticle("");
  530. }
  531. else if (_classifyid != 4)
  532. {
  533. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_analyticalParticle("");
  534. }
  535. return null;
  536. }
  537. private void btn_Cannnel_Click(object sender, EventArgs e)
  538. {
  539. this.DialogResult = DialogResult.Cancel;
  540. this.Close();
  541. }
  542. private void dgV_SimilarParticles_MouseUp(object sender, MouseEventArgs e)
  543. {
  544. var SelectRows = dgV_SimilarParticles.SelectedRows;
  545. if (SelectRows.Count != 0)
  546. {
  547. if (SelectRows.Count == 1)
  548. {
  549. DataGridViewRow dgvr = SelectRows[0];
  550. Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
  551. List<string> list_str = (List<string>)ls_bp.Tag;
  552. uint[] Search_xray = new uint[2000];
  553. uint[] Analysis_xray = new uint[2000];
  554. int i_xray_id = 0;
  555. List<Element> list_celementchemistryclr = new List<Element>();
  556. _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);
  557. List<OTSIncAReportGraph.Controls.ShowElementInfo> list_showelementinfo = new List<OTSIncAReportGraph.Controls.ShowElementInfo>();
  558. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  559. {
  560. OTSIncAReportGraph.Controls.ShowElementInfo ls_sei = new OTSIncAReportGraph.Controls.ShowElementInfo();
  561. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  562. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  563. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  564. double de_sx2 = 0;
  565. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  566. {
  567. de_sx2 = 0;
  568. }
  569. else
  570. {
  571. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  572. }
  573. ls_sei.dLF = de_sx2;
  574. list_showelementinfo.Add(ls_sei);
  575. }
  576. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  577. string str_IncAName = "";
  578. str_IncAName = Convert.ToString(dgvr.Cells[2].Value);
  579. Particle particle = _particlesGridDevidePage.result.List_OTSField.Find(x => x.FieldID == Convert.ToInt32(dgvr.Cells["fieldid"].Value)).ParticleList.Find(x => x.ParticleId == Convert.ToInt32(dgvr.Cells["particleId"].Value));
  580. if (particle == null)
  581. {
  582. return;
  583. }
  584. 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));
  585. control_XRayTable1.Visible = true;
  586. control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
  587. //颗粒国标信息
  588. control_XRayTable1.GBInfoStr = "";
  589. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  590. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  591. string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
  592. DataRow[] drs = particles.Select(str);
  593. if (drs.Length > 0)
  594. {
  595. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
  596. Bitmap dpImage = new Bitmap(_particlesGridDevidePage.result.GetImageWidth(), _particlesGridDevidePage.result.GetImageHeight());
  597. using (Graphics graphics = Graphics.FromImage(dpImage))
  598. {
  599. graphics.Clear(Color.White); // 清除位图背景为白色
  600. }
  601. string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
  602. string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
  603. Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
  604. foreach (Segment seg in particle.SegmentList)
  605. {
  606. int f_length = seg.Length;
  607. for (int m = 0; m < f_length; m++)
  608. {
  609. int lsjs_x = seg.Start + m;
  610. int lsjs_y = seg.Height;
  611. var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y);
  612. dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
  613. }
  614. }
  615. Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(dpImage, rectangle);
  616. Bitmap bmap1 = _particlesGridDevidePage.Particledata.GetBitmapByParticle(m_originalImage, rectangle);
  617. control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
  618. Invalidate();
  619. }
  620. else
  621. {
  622. control_XRayTable1.Visible = false;
  623. }
  624. }
  625. }
  626. }
  627. private void movetoparticleToolStripMenuItem_Click(object sender, EventArgs e)
  628. {
  629. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  630. string i_ls_fieldid = "";
  631. string i_ls_particleid = "";
  632. int cou = dgV_SimilarParticles.SelectedRows.Count;
  633. if (cou > 0)
  634. {
  635. DataGridViewRow dgvr = dgV_SimilarParticles.SelectedRows[cou - 1];
  636. Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
  637. List<string> list_str = (List<string>)ls_bp.Tag;
  638. if (list_str != null)
  639. {
  640. i_ls_fieldid = list_str[0];
  641. i_ls_particleid = list_str[1];
  642. }
  643. }
  644. DataOperation.DataAccess.ParticleData particleData = new DataOperation.DataAccess.ParticleData(_particlesGridDevidePage.result.FilePath);
  645. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  646. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  647. if (m_mythread == null)
  648. {
  649. return;
  650. }
  651. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  652. {
  653. return;
  654. }
  655. if (m_mythread.ThreadState == ThreadState.Stopped)
  656. {
  657. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  658. }
  659. Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
  660. //改为线程调用,先判断线程状态
  661. m_mythread.Start(point);
  662. }
  663. #region 连接电镜相关
  664. /// <summary>
  665. /// 移动SEM到指定位置线程函数
  666. /// </summary>
  667. private void Thread_GO(object in_obj)
  668. {
  669. if (m_mythread_state == false)
  670. {
  671. m_mythread_state = true;
  672. Point sem_point = (Point)in_obj;
  673. //第一步,连接电镜
  674. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  675. Thread.Sleep(500);
  676. //第二步,移动到指定位置,先读取再设置
  677. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  678. {
  679. m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  680. }
  681. Thread.Sleep(1500);
  682. m_mythread_state = false;
  683. }
  684. }
  685. #endregion
  686. private void dgV_SimilarParticles_KeyUp(object sender, KeyEventArgs e)
  687. {
  688. if (e.KeyData == Keys.Down)
  689. {
  690. dgV_SimilarParticles_MouseUp(null, null);
  691. }
  692. if (e.KeyData == Keys.Up)
  693. {
  694. dgV_SimilarParticles_MouseUp(null, null);
  695. }
  696. if (e.KeyData == Keys.Space)
  697. {
  698. dgV_SimilarParticles_CellMouseClick(null,null);
  699. }
  700. }
  701. private void tB_SimilarRatio_KeyUp(object sender, KeyEventArgs e)
  702. {
  703. if (e.KeyData == Keys.Enter)
  704. {
  705. btn_Search_Click(null, null);
  706. }
  707. }
  708. }
  709. }