ListOfSimilarParticles.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. if (_RenameInfo != null)
  460. {
  461. dgV_SimilarParticles.Rows[0].Cells[2].Value = _RenameInfo[1];
  462. }
  463. dgV_SimilarParticles.Visible = true;
  464. }
  465. private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
  466. {
  467. if (posXray == null) return 0;
  468. if (posXray1 == null) return 0;
  469. if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
  470. {
  471. return 0;
  472. }
  473. var pXrayData = posXray.GetXrayData();
  474. var pXrayData1 = posXray1.GetXrayData();
  475. // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
  476. double dotProduct = 0;
  477. double d1 = 0;
  478. double d2 = 0;
  479. for (int i = 0; i < posXray.GetChannelsNum(); i++)
  480. {
  481. double r1 = pXrayData[i];
  482. double r2 = pXrayData1[i];
  483. r1 *= r2;
  484. dotProduct = dotProduct + r1;
  485. }
  486. d1 = posXray.GetXrayDataVectorNorm();
  487. d2 = posXray1.GetXrayDataVectorNorm();
  488. return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
  489. }
  490. private void ListOfSimilarParticles_Load(object sender, EventArgs e)
  491. {
  492. btn_Search_Click(null, null);
  493. }
  494. private void btn_OK_Click(object sender, EventArgs e)
  495. {
  496. if (_RenameInfo == null)
  497. {
  498. string CategoryName = "";
  499. //循环选中颗粒
  500. DataGridViewRow dgvr = dgV_SimilarParticles.Rows[0];
  501. CategoryName = dgvr.Cells[2].Value.ToString();
  502. string TypeId = "";
  503. string TypeName = "";
  504. string TypeColor = "";
  505. string GroupName = "";
  506. string GroupID = "";
  507. DataTable da = _particlesGridDevidePage.Particledata.GetParticleListForParticlSizeID("area", "");
  508. ModifyCategoryForm modifyCategoryForm = new ModifyCategoryForm(da, CategoryName);
  509. DialogResult result = modifyCategoryForm.ShowDialog();
  510. if (modifyCategoryForm.DoYouWantToModifyIt)
  511. {
  512. TypeId = modifyCategoryForm.OutTypeAndName[0];
  513. TypeName = modifyCategoryForm.OutTypeAndName[1];
  514. TypeColor = modifyCategoryForm.OutTypeAndName[2];
  515. GroupName = modifyCategoryForm.OutTypeAndName[3];
  516. GroupID = modifyCategoryForm.OutTypeAndName[4];
  517. _RenameInfo = new List<string>();
  518. _RenameInfo.Add(TypeId);
  519. _RenameInfo.Add(TypeName);
  520. _RenameInfo.Add(TypeColor);
  521. _RenameInfo.Add(GroupName);
  522. _RenameInfo.Add(GroupID);
  523. }
  524. else
  525. {
  526. return;
  527. }
  528. }
  529. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  530. foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
  531. {
  532. if (row.Cells["IsSelected"].Value != null && (bool)row.Cells["IsSelected"].Value)
  533. {
  534. row.Cells[1].Value = _RenameInfo[0];
  535. Bitmap ls_bp = (Bitmap)row.Cells[3].Value;
  536. List<string> list_str = (List<string>)ls_bp.Tag;
  537. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  538. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  539. List<int> ints = new List<int>();
  540. ints.Add(i_ls_fieldid);
  541. ints.Add(i_ls_particleid);
  542. var cmd = _particlesGridDevidePage.Particledata.GetUpdataAIncACmd(ints, _RenameInfo);
  543. cmdlist.Add(cmd);
  544. }
  545. }
  546. _particlesGridDevidePage.Particledata.ExecuteNonQueryBatch(cmdlist);
  547. this.DialogResult = DialogResult.OK;
  548. this.Close();
  549. }
  550. private void cBx_All_CheckedChanged(object sender, EventArgs e)
  551. {
  552. CheckBox selectAllCheckBox = (CheckBox)sender;
  553. foreach (DataGridViewRow row in dgV_SimilarParticles.Rows)
  554. {
  555. DataGridViewCheckBoxCell checkBox = row.Cells["IsSelected"] as DataGridViewCheckBoxCell;
  556. checkBox.Value = selectAllCheckBox.Checked;
  557. }
  558. dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
  559. }
  560. DataTable ObtainSourceOfSimilarParticles(int _classifyid)
  561. {
  562. if (_classifyid == -1)
  563. {
  564. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_InvalidParticle("");
  565. }
  566. else if (_classifyid == 9)
  567. {
  568. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_NotIdentifyParticle("");
  569. }
  570. else if (_classifyid != 4)
  571. {
  572. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_analyticalParticle("");
  573. }
  574. else if (_classifyid == 4)
  575. {
  576. return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_LowCountsParticle("");
  577. }
  578. return null;
  579. }
  580. private void btn_Cannnel_Click(object sender, EventArgs e)
  581. {
  582. this.DialogResult = DialogResult.Cancel;
  583. this.Close();
  584. }
  585. private void dgV_SimilarParticles_MouseUp(object sender, MouseEventArgs e)
  586. {
  587. var SelectRows = dgV_SimilarParticles.SelectedRows;
  588. if (SelectRows.Count != 0)
  589. {
  590. if (SelectRows.Count == 1)
  591. {
  592. DataGridViewRow dgvr = SelectRows[0];
  593. Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
  594. List<string> list_str = (List<string>)ls_bp.Tag;
  595. uint[] Search_xray = new uint[2000];
  596. uint[] Analysis_xray = new uint[2000];
  597. int i_xray_id = 0;
  598. List<Element> list_celementchemistryclr = new List<Element>();
  599. _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);
  600. List<OTSIncAReportGraph.Controls.ShowElementInfo> list_showelementinfo = new List<OTSIncAReportGraph.Controls.ShowElementInfo>();
  601. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  602. {
  603. OTSIncAReportGraph.Controls.ShowElementInfo ls_sei = new OTSIncAReportGraph.Controls.ShowElementInfo();
  604. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  605. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  606. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  607. double de_sx2 = 0;
  608. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  609. {
  610. de_sx2 = 0;
  611. }
  612. else
  613. {
  614. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  615. }
  616. ls_sei.dLF = de_sx2;
  617. list_showelementinfo.Add(ls_sei);
  618. }
  619. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  620. string str_IncAName = "";
  621. str_IncAName = Convert.ToString(dgvr.Cells[2].Value);
  622. 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));
  623. if (particle == null)
  624. {
  625. return;
  626. }
  627. 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));
  628. control_XRayTable1.Visible = true;
  629. control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
  630. //颗粒国标信息
  631. control_XRayTable1.GBInfoStr = "";
  632. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  633. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  634. string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
  635. DataRow[] drs = particles.Select(str);
  636. if (drs.Length > 0)
  637. {
  638. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
  639. Bitmap dpImage = new Bitmap(_particlesGridDevidePage.result.GetImageWidth(), _particlesGridDevidePage.result.GetImageHeight());
  640. using (Graphics graphics = Graphics.FromImage(dpImage))
  641. {
  642. graphics.Clear(Color.White); // 清除位图背景为白色
  643. }
  644. string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\";
  645. string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
  646. Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
  647. foreach (Segment seg in particle.SegmentList)
  648. {
  649. int f_length = seg.Length;
  650. for (int m = 0; m < f_length; m++)
  651. {
  652. int lsjs_x = seg.Start + m;
  653. int lsjs_y = seg.Height;
  654. var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y);
  655. dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
  656. }
  657. }
  658. Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(dpImage, rectangle);
  659. Bitmap bmap1 = _particlesGridDevidePage.Particledata.GetBitmapByParticle(m_originalImage, rectangle);
  660. control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
  661. Invalidate();
  662. }
  663. else
  664. {
  665. control_XRayTable1.Visible = false;
  666. }
  667. }
  668. }
  669. }
  670. private void movetoparticleToolStripMenuItem_Click(object sender, EventArgs e)
  671. {
  672. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  673. string i_ls_fieldid = "";
  674. string i_ls_particleid = "";
  675. int cou = dgV_SimilarParticles.SelectedRows.Count;
  676. if (cou > 0)
  677. {
  678. DataGridViewRow dgvr = dgV_SimilarParticles.SelectedRows[cou - 1];
  679. Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value;
  680. List<string> list_str = (List<string>)ls_bp.Tag;
  681. if (list_str != null)
  682. {
  683. i_ls_fieldid = list_str[0];
  684. i_ls_particleid = list_str[1];
  685. }
  686. }
  687. DataOperation.DataAccess.ParticleData particleData = new DataOperation.DataAccess.ParticleData(_particlesGridDevidePage.result.FilePath);
  688. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  689. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  690. if (m_mythread == null)
  691. {
  692. return;
  693. }
  694. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  695. {
  696. return;
  697. }
  698. if (m_mythread.ThreadState == ThreadState.Stopped)
  699. {
  700. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  701. }
  702. Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
  703. //改为线程调用,先判断线程状态
  704. m_mythread.Start(point);
  705. }
  706. #region 连接电镜相关
  707. /// <summary>
  708. /// 移动SEM到指定位置线程函数
  709. /// </summary>
  710. private void Thread_GO(object in_obj)
  711. {
  712. if (m_mythread_state == false)
  713. {
  714. m_mythread_state = true;
  715. Point sem_point = (Point)in_obj;
  716. //第一步,连接电镜
  717. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  718. Thread.Sleep(500);
  719. //第二步,移动到指定位置,先读取再设置
  720. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  721. {
  722. m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  723. }
  724. Thread.Sleep(1500);
  725. m_mythread_state = false;
  726. }
  727. }
  728. #endregion
  729. private void dgV_SimilarParticles_KeyUp(object sender, KeyEventArgs e)
  730. {
  731. if (e.KeyData == Keys.Down)
  732. {
  733. dgV_SimilarParticles_MouseUp(null, null);
  734. }
  735. if (e.KeyData == Keys.Up)
  736. {
  737. dgV_SimilarParticles_MouseUp(null, null);
  738. }
  739. if (e.KeyData == Keys.Space)
  740. {
  741. dgV_SimilarParticles_CellMouseDoubleClick(null,null);
  742. }
  743. }
  744. private void tB_SimilarRatio_KeyUp(object sender, KeyEventArgs e)
  745. {
  746. if (e.KeyData == Keys.Enter)
  747. {
  748. btn_Search_Click(null, null);
  749. }
  750. }
  751. private void dgV_SimilarParticles_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  752. {
  753. var SelectRows = dgV_SimilarParticles.SelectedRows;
  754. if (SelectRows.Count != 0)
  755. {
  756. if (SelectRows.Count == 1)
  757. {
  758. DataGridViewRow dgvr = SelectRows[0];
  759. if ((bool)dgvr.Cells[0].EditedFormattedValue == true)
  760. {
  761. dgvr.Cells[0].Value = false;
  762. }
  763. else
  764. {
  765. dgvr.Cells[0].Value = true;
  766. }
  767. dgV_SimilarParticles.Rows[0].Cells[0].Value = true;
  768. }
  769. }
  770. }
  771. public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, int classifyid)
  772. {
  773. InitializeComponent();
  774. _particlesGridDevidePage = particlesGridDevidePage;
  775. SelXrayclr.SetXrayData(SelXray);
  776. table = particlesGridDevidePage.table;
  777. _classifyid = classifyid;
  778. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  779. //设置窗体的双缓冲,以保证大数据时拖动不卡
  780. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  781. this.UpdateStyles();
  782. //利用反射设置DataGridView的双缓冲
  783. Type dgvType = this.dgV_SimilarParticles.GetType();
  784. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  785. pi.SetValue(this.dgV_SimilarParticles, true, null);
  786. this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null);
  787. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  788. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  789. this.control_XRayTable1.GBInfoStr = "";
  790. this.control_XRayTable1.GoodChineseName = "";
  791. this.control_XRayTable1.MaterialName = "";
  792. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  793. this.control_XRayTable1.Name = "control_XRayTable1";
  794. this.control_XRayTable1.ShowAnalysisXray = true;
  795. this.control_XRayTable1.ShowSearchXray = false;
  796. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  797. this.control_XRayTable1.STDName = "";
  798. this.control_XRayTable1.Visible = false;
  799. this.control_XRayTable1.label_close.Visible = true;
  800. panel1.Controls.Add(this.control_XRayTable1);
  801. }
  802. private void 从此颗粒之下取消选择ToolStripMenuItem_Click(object sender, EventArgs e)
  803. {
  804. var SelectRows = dgV_SimilarParticles.SelectedRows;
  805. if (SelectRows.Count != 0)
  806. {
  807. DataGridViewRow dgvr = SelectRows[0];
  808. for (int i = dgvr.Index + 1; i < dgV_SimilarParticles.Rows.Count; i++)
  809. {
  810. dgV_SimilarParticles.Rows[i].Cells[0].Value=false;
  811. }
  812. if(dgvr.Index + 1!= dgV_SimilarParticles.Rows.Count)
  813. {
  814. this.cBx_All.CheckedChanged -= new System.EventHandler(this.cBx_All_CheckedChanged);
  815. cBx_All.Checked=false;
  816. this.cBx_All.CheckedChanged += new System.EventHandler(this.cBx_All_CheckedChanged);
  817. }
  818. }
  819. }
  820. }
  821. }