ListOfSimilarParticles.cs 39 KB

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