ListOfSimilarParticles.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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 = 50;
  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. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  401. }
  402. else if (enl.Current.Key == "Element")
  403. {
  404. List<string> elementtemp = new List<string>(ElementTypeSort);
  405. string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  406. for (int j = 0; j < strcbo.Length; j++)
  407. {
  408. if (ElementTypeSort.Count == 0)
  409. {
  410. break;
  411. }
  412. string[] str = strcbo[j].Split('-');
  413. if (ElementTypeSort.Contains(str[0]))
  414. { dgV_SimilarParticles.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
  415. elementtemp.Remove(str[0].ToString());
  416. }
  417. foreach (var ele in elementtemp)
  418. {
  419. dgV_SimilarParticles.Rows[add_rowindex].Cells[ele].Value = "0";
  420. }
  421. }
  422. else
  423. {
  424. double val = 0;
  425. if (double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]), out val))
  426. {
  427. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = val;
  428. }
  429. else
  430. {
  431. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  432. }
  433. }
  434. }
  435. if (enl.Current.Key == "TypeName")
  436. {
  437. if (particles.Rows[i]["TypeId"].ToString() == "9")
  438. {
  439. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  440. }
  441. }
  442. if (enl.Current.Key == "Equivalent")
  443. {
  444. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  445. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  446. dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  447. }
  448. if (enl.Current.Key == "AbPosX")
  449. {
  450. 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"])));
  451. dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosX"].Value = point.X;
  452. dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y;
  453. }
  454. }
  455. }
  456. }
  457. DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
  458. checkBoxColumn.HeaderText = "选择";
  459. checkBoxColumn.Name = "IsSelected";
  460. checkBoxColumn.TrueValue = true;
  461. checkBoxColumn.FalseValue = false;
  462. checkBoxColumn.Width = 30;
  463. checkBoxColumn.ReadOnly = false;
  464. dgV_SimilarParticles.Columns.Insert(0, checkBoxColumn);
  465. dgV_SimilarParticles.Rows[0].Cells[2].Value = _RenameInfo[1];
  466. dgV_SimilarParticles.Visible = true;
  467. }
  468. private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
  469. {
  470. if (posXray == null) return 0;
  471. if (posXray1 == null) return 0;
  472. if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
  473. {
  474. return 0;
  475. }
  476. var pXrayData = posXray.GetXrayData();
  477. var pXrayData1 = posXray1.GetXrayData();
  478. // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
  479. double dotProduct = 0;
  480. double d1 = 0;
  481. double d2 = 0;
  482. for (int i = 0; i < posXray.GetChannelsNum(); i++)
  483. {
  484. double r1 = pXrayData[i];
  485. double r2 = pXrayData1[i];
  486. r1 *= r2;
  487. dotProduct = dotProduct + r1;
  488. }
  489. d1 = posXray.GetXrayDataVectorNorm();
  490. d2 = posXray1.GetXrayDataVectorNorm();
  491. return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
  492. }
  493. private void ListOfSimilarParticles_Load(object sender, EventArgs e)
  494. {
  495. btn_Search_Click(null, null);
  496. }
  497. private void btn_OK_Click(object sender, EventArgs e)
  498. {
  499. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  500. foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
  501. {
  502. if (row.Cells["IsSelected"].Value != null && (bool)row.Cells["IsSelected"].Value)
  503. {
  504. row.Cells[1].Value = _RenameInfo[0];
  505. Bitmap ls_bp = (Bitmap)row.Cells[3].Value;
  506. List<string> list_str = (List<string>)ls_bp.Tag;
  507. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  508. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  509. List<int> ints = new List<int>();
  510. ints.Add(i_ls_fieldid);
  511. ints.Add(i_ls_particleid);
  512. var cmd = _particlesGridDevidePage.Particledata.GetUpdataAIncACmd(ints, _RenameInfo);
  513. cmdlist.Add(cmd);
  514. }
  515. }
  516. _particlesGridDevidePage.Particledata.ExecuteNonQueryBatch(cmdlist);
  517. this.DialogResult = DialogResult.OK;
  518. this.Close();
  519. }
  520. private void cBx_All_CheckedChanged(object sender, EventArgs e)
  521. {
  522. CheckBox selectAllCheckBox = (CheckBox)sender;
  523. foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
  524. {
  525. DataGridViewCheckBoxCell checkBox = row.Cells["IsSelected"] as DataGridViewCheckBoxCell;
  526. checkBox.Value = selectAllCheckBox.Checked;
  527. }
  528. dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
  529. }
  530. DataTable ObtainSourceOfSimilarParticles(int _classifyid)
  531. {
  532. if (_classifyid == -1)
  533. {
  534. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_InvalidParticle("");
  535. }
  536. else if (_classifyid == 9)
  537. {
  538. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_NotIdentifyParticle("");
  539. }
  540. else if (_classifyid != 4)
  541. {
  542. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_analyticalParticle("");
  543. }
  544. return null;
  545. }
  546. private void btn_Cannnel_Click(object sender, EventArgs e)
  547. {
  548. this.DialogResult = DialogResult.Cancel;
  549. this.Close();
  550. }
  551. private void dgV_SimilarParticles_MouseUp(object sender, MouseEventArgs e)
  552. {
  553. var SelectRows = dgV_SimilarParticles.SelectedRows;
  554. if (SelectRows.Count != 0)
  555. {
  556. if (SelectRows.Count == 1)
  557. {
  558. DataGridViewRow dgvr = SelectRows[0];
  559. Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
  560. List<string> list_str = (List<string>)ls_bp.Tag;
  561. uint[] Search_xray = new uint[2000];
  562. uint[] Analysis_xray = new uint[2000];
  563. int i_xray_id = 0;
  564. List<Element> list_celementchemistryclr = new List<Element>();
  565. _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);
  566. List<OTSIncAReportGraph.Controls.ShowElementInfo> list_showelementinfo = new List<OTSIncAReportGraph.Controls.ShowElementInfo>();
  567. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  568. {
  569. OTSIncAReportGraph.Controls.ShowElementInfo ls_sei = new OTSIncAReportGraph.Controls.ShowElementInfo();
  570. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  571. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  572. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  573. double de_sx2 = 0;
  574. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  575. {
  576. de_sx2 = 0;
  577. }
  578. else
  579. {
  580. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  581. }
  582. ls_sei.dLF = de_sx2;
  583. list_showelementinfo.Add(ls_sei);
  584. }
  585. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  586. string str_IncAName = "";
  587. str_IncAName = Convert.ToString(dgvr.Cells[2].Value);
  588. 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));
  589. if (particle == null)
  590. {
  591. return;
  592. }
  593. 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));
  594. control_XRayTable1.Visible = true;
  595. control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
  596. //颗粒国标信息
  597. control_XRayTable1.GBInfoStr = "";
  598. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  599. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  600. string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
  601. DataRow[] drs = particles.Select(str);
  602. if (drs.Length > 0)
  603. {
  604. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
  605. Bitmap dpImage = new Bitmap(_particlesGridDevidePage.result.GetImageWidth(), _particlesGridDevidePage.result.GetImageHeight());
  606. using (Graphics graphics = Graphics.FromImage(dpImage))
  607. {
  608. graphics.Clear(Color.White); // 清除位图背景为白色
  609. }
  610. string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
  611. string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
  612. Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
  613. foreach (Segment seg in particle.SegmentList)
  614. {
  615. int f_length = seg.Length;
  616. for (int m = 0; m < f_length; m++)
  617. {
  618. int lsjs_x = seg.Start + m;
  619. int lsjs_y = seg.Height;
  620. var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y);
  621. dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
  622. }
  623. }
  624. Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(dpImage, rectangle);
  625. Bitmap bmap1 = _particlesGridDevidePage.Particledata.GetBitmapByParticle(m_originalImage, rectangle);
  626. control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
  627. Invalidate();
  628. }
  629. else
  630. {
  631. control_XRayTable1.Visible = false;
  632. }
  633. }
  634. }
  635. }
  636. private void movetoparticleToolStripMenuItem_Click(object sender, EventArgs e)
  637. {
  638. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  639. string i_ls_fieldid = "";
  640. string i_ls_particleid = "";
  641. int cou = dgV_SimilarParticles.SelectedRows.Count;
  642. if (cou > 0)
  643. {
  644. DataGridViewRow dgvr = dgV_SimilarParticles.SelectedRows[cou - 1];
  645. Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
  646. List<string> list_str = (List<string>)ls_bp.Tag;
  647. if (list_str != null)
  648. {
  649. i_ls_fieldid = list_str[0];
  650. i_ls_particleid = list_str[1];
  651. }
  652. }
  653. DataOperation.DataAccess.ParticleData particleData = new DataOperation.DataAccess.ParticleData(_particlesGridDevidePage.result.FilePath);
  654. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  655. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  656. if (m_mythread == null)
  657. {
  658. return;
  659. }
  660. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  661. {
  662. return;
  663. }
  664. if (m_mythread.ThreadState == ThreadState.Stopped)
  665. {
  666. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  667. }
  668. Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
  669. //改为线程调用,先判断线程状态
  670. m_mythread.Start(point);
  671. }
  672. #region 连接电镜相关
  673. /// <summary>
  674. /// 移动SEM到指定位置线程函数
  675. /// </summary>
  676. private void Thread_GO(object in_obj)
  677. {
  678. if (m_mythread_state == false)
  679. {
  680. m_mythread_state = true;
  681. Point sem_point = (Point)in_obj;
  682. //第一步,连接电镜
  683. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  684. Thread.Sleep(500);
  685. //第二步,移动到指定位置,先读取再设置
  686. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  687. {
  688. m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  689. }
  690. Thread.Sleep(1500);
  691. m_mythread_state = false;
  692. }
  693. }
  694. #endregion
  695. private void dgV_SimilarParticles_KeyUp(object sender, KeyEventArgs e)
  696. {
  697. if (e.KeyData == Keys.Down)
  698. {
  699. dgV_SimilarParticles_MouseUp(null, null);
  700. }
  701. if (e.KeyData == Keys.Up)
  702. {
  703. dgV_SimilarParticles_MouseUp(null, null);
  704. }
  705. if (e.KeyData == Keys.Space)
  706. {
  707. dgV_SimilarParticles_CellMouseDoubleClick(null,null);
  708. }
  709. }
  710. private void tB_SimilarRatio_KeyUp(object sender, KeyEventArgs e)
  711. {
  712. if (e.KeyData == Keys.Enter)
  713. {
  714. btn_Search_Click(null, null);
  715. }
  716. }
  717. private void dgV_SimilarParticles_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  718. {
  719. var SelectRows = dgV_SimilarParticles.SelectedRows;
  720. if (SelectRows.Count != 0)
  721. {
  722. if (SelectRows.Count == 1)
  723. {
  724. DataGridViewRow dgvr = SelectRows[0];
  725. if ((bool)dgvr.Cells[0].EditedFormattedValue == true)
  726. {
  727. dgvr.Cells[0].Value = false;
  728. }
  729. else
  730. {
  731. dgvr.Cells[0].Value = true;
  732. }
  733. dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
  734. }
  735. }
  736. }
  737. private void dgV_SimilarParticles_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  738. {
  739. }
  740. }
  741. }