ListOfSimilarParticles.cs 40 KB

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