frmReMeasure.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. using OTSDataType;
  2. using OTSCommon.Model;
  3. using OTSMeasureApp;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
  14. using System.Threading;
  15. using static OTSDataType.otsdataconst;
  16. using OpenCvSharp;
  17. using Point = System.Drawing.Point;
  18. using OTSIncAReportGraph.Controls;
  19. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  20. using OTSCLRINTERFACE;
  21. using System.IO;
  22. using System.Reflection;
  23. using OTSModelSharp.ResourceManage;
  24. using System.Collections;
  25. using OTSIncAReportApp.SysMgrTools;
  26. using OTSIncAReportApp.DataOperation.DataAccess;
  27. using OTSModelSharp.DTLBase;
  28. using OTSRptPeriodicTable;
  29. using ExportToExcel;
  30. namespace OTSIncAReportApp
  31. {
  32. public partial class frmReMeasure : Form
  33. {
  34. frmReportApp m_ReportApp;
  35. OTSImageDisHelp ReportFun;
  36. OTSReportGridsFun m_OTSIncAReportGridsFun;
  37. List<Particle> SelectedParticles;
  38. List<Particle> successParticles;
  39. Dictionary<int, Mat> keyValuesMat;
  40. bool isCheck = true;
  41. bool stopFlag = false;//停止标识
  42. Point handPoint;
  43. int partFunIndex = 0;
  44. int xrayScanMode = 0;
  45. int nBrukerDwellTime = 0;
  46. double ScanFieldSizeX = 0;
  47. double ScanFieldSizeX100 = 0;
  48. double ScanFieldSizeY100 = 0;
  49. double oldMag = 0;
  50. double old_pixelsize = 0;
  51. double new_pixelsize = 0;
  52. string sampleName = "";
  53. int width = 0;
  54. int height = 0;
  55. OpenCvSharp.Size dsize;
  56. DataTable dt_new;
  57. //国际化
  58. Language lan;
  59. Hashtable table;
  60. private delegate void DelSetPro(string txt, RichTextBox richTextBox);//设置进度条进度的委托方法
  61. /// <summary>
  62. /// 设置进度。
  63. /// </summary>
  64. /// <param name="pro"></param>
  65. /// <param name="proBar"></param>
  66. private void SetProgressMessage(string txt, RichTextBox richTextBox)
  67. {
  68. //如果当前调用方不是创建控件的一方,则需要使用this.Invoke()
  69. //在这里,ProgressBar控件是由主线程创建的,所以子线程要对该控件进行操作
  70. //必须执行this.InvokeRequired进行判断。
  71. if (this.InvokeRequired)
  72. {
  73. DelSetPro setPro = new DelSetPro(SetProgressMessage);
  74. this.Invoke(setPro, new object[] { txt, richTextBox });
  75. }
  76. else
  77. {
  78. WriteRictBox(txt);
  79. }
  80. }
  81. #region 将文本追加到RictBox的尾部上
  82. /// <summary>
  83. /// 将文本追加到RictBox的尾部上
  84. /// </summary>
  85. public void WriteRictBox(string in_str)
  86. {
  87. //追加到rictbox尾部
  88. richTextBox_process.AppendText("[" + DateTime.Now.Hour.ToString() + ":"
  89. + DateTime.Now.Minute.ToString() + ":"
  90. + DateTime.Now.Second.ToString() + "]"
  91. + in_str + Environment.NewLine);
  92. richTextBox_process.ScrollToCaret();
  93. }
  94. #endregion
  95. public frmReMeasure(OTSImageDisHelp ReportFun, frmReportApp m_ReportApp)
  96. {
  97. InitializeComponent();
  98. lan = new Language(this);
  99. table = lan.GetNameTable(this.Name);
  100. this.m_ReportApp = m_ReportApp;
  101. //初始化底层操作类
  102. this.m_OTSIncAReportGridsFun = new OTSReportGridsFun(m_ReportApp);
  103. this.SelectedParticles = m_ReportApp.GetSelectedParticles();
  104. this.ReportFun = ReportFun;
  105. //load the userdefine control dynamically
  106. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_DrawDistrbutionImageAndBSE));
  107. this.control_XRayTable1 = new Control_XRayTable();
  108. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  109. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Fill;
  110. this.control_XRayTable1.GBInfoStr = "";
  111. this.control_XRayTable1.GoodChineseName = "";
  112. this.control_XRayTable1.MaterialName = "";
  113. this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAReportGraph.Controls.ShowElementInfo>)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
  114. this.control_XRayTable1.Name = "control_XRayTable1";
  115. this.control_XRayTable1.ShowAnalysisXray = true;
  116. this.control_XRayTable1.ShowSearchXray = false;
  117. this.control_XRayTable1.Size = new System.Drawing.Size(groupBox2.Width, groupBox2.Height);
  118. this.control_XRayTable1.STDName = "";
  119. this.control_XRayTable1.TabIndex = 16;
  120. this.groupBox2.Controls.Add(this.control_XRayTable1);
  121. ReadSuccessDb();
  122. //显示已测颗粒
  123. if (successParticles.Count != 0)
  124. {
  125. BindDataGridView(dataGridView_success, successParticles);
  126. }
  127. //显示待测颗粒
  128. if (SelectedParticles.Count != 0)
  129. {
  130. BindDataGridView(dgV_ParticlesDevidePage, SelectedParticles);
  131. }
  132. //默认选中
  133. foreach (DataGridViewRow dr in dgV_ParticlesDevidePage.Rows)
  134. {
  135. dr.Cells[0].Value = isCheck;
  136. }
  137. }
  138. /// <summary>
  139. /// 判断是否是二次测量颗粒
  140. /// </summary>
  141. private void UpdateDB()
  142. {
  143. if (dgV_ParticlesDevidePage.Rows.Count == SelectedParticles.Count)
  144. {
  145. for (int i = 0; i < SelectedParticles.Count; i++)
  146. {
  147. if (dt_new.Select("FieldId = " + SelectedParticles[i].FieldId + " and ParticleId = " + SelectedParticles[i].ParticleId + "").Count() != 0)
  148. {
  149. dgV_ParticlesDevidePage.Rows[i].Cells["ReMeasure"].Value = "是";
  150. }
  151. else
  152. {
  153. dgV_ParticlesDevidePage.Rows[i].Cells["ReMeasure"].Value = "否";
  154. }
  155. }
  156. }
  157. for (int i = 0; i < dataGridView_success.Rows.Count; i++)
  158. {
  159. dataGridView_success.Rows[i].Cells["ReMeasure"].Value = "是";
  160. }
  161. }
  162. /// <summary>
  163. /// 显示已测颗粒
  164. /// </summary>
  165. private void ReadSuccessDb()
  166. {
  167. SQLiteHelper sQLiteHelper = new SQLiteHelper(ReportFun.resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db");
  168. if (!sQLiteHelper.IsExist("IncADataReMeasure"))
  169. {
  170. sQLiteHelper.ExecuteNonQuery("CREATE TABLE IncADataReMeasure AS SELECT * FROM IncAData where 1=0;");
  171. }
  172. dt_new = sQLiteHelper.ExecuteDataTable("SELECT * FROM IncADataReMeasure");
  173. successParticles = new List<Particle>();
  174. for (int i = 0; i < dt_new.Rows.Count; i++)
  175. {
  176. DataTable dt_xray = sQLiteHelper.ExecuteDataTable("SELECT XrayData FROM XRayData WHERE FieldId = " + dt_new.Rows[i]["FieldId"].ToString() + " AND XrayIndex = " + dt_new.Rows[i]["XrayId"].ToString() + "");
  177. DataTable dt_Element = sQLiteHelper.ExecuteDataTable("SELECT * FROM ElementChemistry WHERE FieldId = " + dt_new.Rows[i]["FieldId"].ToString() + " AND XRayId = " + dt_new.Rows[i]["XrayId"].ToString() + "");
  178. Particle particle = new Particle();
  179. particle.FieldId = int.Parse(dt_new.Rows[i]["FieldId"].ToString());
  180. particle.ParticleId = int.Parse(dt_new.Rows[i]["ParticleId"].ToString());
  181. particle.AveGray = int.Parse(dt_new.Rows[i]["AveGray"].ToString());
  182. particle.RectLeft = int.Parse(dt_new.Rows[i]["RectLeft"].ToString());
  183. particle.RectTop = int.Parse(dt_new.Rows[i]["RectTop"].ToString());
  184. particle.RectWidth = int.Parse(dt_new.Rows[i]["RectWidth"].ToString());
  185. particle.RectHeight = int.Parse(dt_new.Rows[i]["RectHeight"].ToString());
  186. particle.Area = double.Parse(dt_new.Rows[i]["Area"].ToString());
  187. particle.PosX = int.Parse(dt_new.Rows[i]["PosX"].ToString());
  188. particle.PosY = int.Parse(dt_new.Rows[i]["PosY"].ToString());
  189. particle.TypeId = int.Parse(dt_new.Rows[i]["TypeId"].ToString());
  190. particle.SegmentNum = int.Parse(dt_new.Rows[i]["SegmentNum"].ToString());
  191. particle.SEMPosX = int.Parse(dt_new.Rows[i]["SEMPosX"].ToString());
  192. particle.SEMPosY = int.Parse(dt_new.Rows[i]["SEMPosY"].ToString());
  193. particle.XrayId = int.Parse(dt_new.Rows[i]["XrayId"].ToString());
  194. particle.DMAX = double.Parse(dt_new.Rows[i]["DMAX"].ToString());
  195. particle.DMIN = double.Parse(dt_new.Rows[i]["DMIN"].ToString());
  196. particle.DPERP = double.Parse(dt_new.Rows[i]["DPERP"].ToString());
  197. particle.PERIMETER = double.Parse(dt_new.Rows[i]["PERIMETER"].ToString());
  198. particle.ORIENTATION = double.Parse(dt_new.Rows[i]["ORIENTATION"].ToString());
  199. particle.DINSCR = double.Parse(dt_new.Rows[i]["DINSCR"].ToString());
  200. particle.DMEAN = double.Parse(dt_new.Rows[i]["DMEAN"].ToString());
  201. particle.DELONG = double.Parse(dt_new.Rows[i]["DELONG"].ToString());
  202. particle.DFERET = double.Parse(dt_new.Rows[i]["DFERET"].ToString());
  203. particle.TypeName = dt_new.Rows[i]["TypeName"].ToString();
  204. particle.TypeColor = dt_new.Rows[i]["TypeColor"].ToString();
  205. particle.XRayData = (Byte[])dt_xray.Rows[0][0];
  206. particle.ElementList = new List<Element>();
  207. particle.ElementNum = dt_Element.Rows.Count;
  208. for (int j = 0; j < dt_Element.Rows.Count; j++)
  209. {
  210. Element element = new Element();
  211. element.FieldId = particle.FieldId;
  212. element.XrayId = particle.XrayId;
  213. element.Name = dt_Element.Rows[j]["Name"].ToString();
  214. element.Percentage = double.Parse(dt_Element.Rows[j]["Percentage"].ToString());
  215. element.ElementNum = particle.ElementNum;
  216. particle.ElementList.Add(element);
  217. }
  218. successParticles.Add(particle);
  219. }
  220. }
  221. private void BindDataGridView(DataGridView dgv, List<Particle> particlesList)
  222. {
  223. dgv.Rows.Clear();
  224. dgv.Columns.Clear();
  225. //先建立个 CheckBox 栏
  226. DataGridViewCheckBoxColumn cbCol = new DataGridViewCheckBoxColumn();
  227. cbCol.Name = "dgv_check";
  228. cbCol.Width = 50; //设定宽度
  229. cbCol.HeaderText = "全选";
  230. cbCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; //置中
  231. dgv.Columns.Insert(0, cbCol);
  232. string startFun = ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)ReportFun.resultFile.ResultInfo["Sample"])["Members"])["MsrParams"])["SysType"].ToString();
  233. //从报告xml文件中加载,显示计算列,显示元素信息
  234. string str_DefaultComputedColName = "";
  235. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXmlData(Application.StartupPath + m_ReportApp.m_OTSReportMgrParamFile, "XMLData");
  236. DataTable dt = ds.Tables["Member"];
  237. foreach (DataRow element in dt.Rows)
  238. {
  239. string RegName = element["RegName"].ToString();
  240. if (RegName == "DefaultComputedColName")
  241. {
  242. str_DefaultComputedColName = element["strValue"].ToString();
  243. }
  244. }
  245. //获取需要显示的计算列
  246. string[] strs = str_DefaultComputedColName.Split(',');
  247. //列名
  248. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  249. keyValues.Add("rowid", table["str1"].ToString());
  250. keyValues.Add("ReMeasure", table["str19"].ToString());
  251. keyValues.Add("TypeName", table["str20"].ToString());
  252. keyValues.Add("FieldID", "FieldID");
  253. keyValues.Add("particleid", "particleid");
  254. keyValues.Add("SEMPosX", "SEMPosX");
  255. keyValues.Add("SEMPosY", "SEMPosY");
  256. for (int i = 0; i < strs.Count(); i++)
  257. {
  258. if (strs[i] == "Area")
  259. {
  260. keyValues.Add("Area", table["str21"].ToString());
  261. }
  262. if (strs[i] == "EquivalentCircleDiameter")
  263. {
  264. keyValues.Add("Equivalent", table["str22"].ToString());
  265. }
  266. if (strs[i] == "MaxDiameter")
  267. {
  268. keyValues.Add("DMAX", table["str23"].ToString());
  269. }
  270. if (strs[i] == "MinDiameter")
  271. {
  272. keyValues.Add("DMIN", table["str24"].ToString());
  273. }
  274. if (strs[i] == "DiameterRatio")
  275. {
  276. keyValues.Add("DiameterRatio", table["str25"].ToString());
  277. }
  278. if (strs[i] == "FerretDiameter")
  279. {
  280. keyValues.Add("DFERET", table["str26"].ToString());
  281. }
  282. if (strs[i] == "PERP")
  283. {
  284. keyValues.Add("DPERP", table["str27"].ToString());
  285. }
  286. if (strs[i] == "PERI")
  287. {
  288. keyValues.Add("PERIMETER", table["str28"].ToString());
  289. }
  290. if (strs[i] == "INSCR")
  291. {
  292. keyValues.Add("DINSCR", table["str29"].ToString());
  293. }
  294. if (strs[i] == "MEAN")
  295. {
  296. keyValues.Add("DMEAN", table["str30"].ToString());
  297. }
  298. if (strs[i] == "ELONG")
  299. {
  300. keyValues.Add("DELONG", table["str31"].ToString());
  301. }
  302. if (strs[i] == "ASPECT_ELONG")
  303. {
  304. keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
  305. }
  306. if (strs[i] == "Orientation")
  307. {
  308. keyValues.Add("ORIENTATION", table["str33"].ToString());
  309. }
  310. if (startFun == "1:CleannessA")
  311. {
  312. if (strs[i] == "Hardness")
  313. {
  314. keyValues.Add("Hardness", table["str36"].ToString());
  315. }
  316. if (strs[i] == "Density")
  317. {
  318. keyValues.Add("Density", table["str35"].ToString());
  319. }
  320. if (strs[i] == "Electrical_conductivity")
  321. {
  322. keyValues.Add("Electrical_conductivity", table["str34"].ToString());
  323. }
  324. }
  325. }
  326. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  327. for (int irow = 0; irow < keyValues.Count; irow++)
  328. {
  329. if (en.MoveNext())
  330. {
  331. dgv.Columns.Add(en.Current.Key, en.Current.Value);
  332. }
  333. }
  334. DataTable particles = UpdateTable(particlesList);
  335. for (int i = 0; i < particles.Rows.Count; i++)
  336. {
  337. Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  338. int add_rowindex = dgv.Rows.Add();
  339. for (int k = 1; k < keyValues.Count; k++)
  340. {
  341. if (enl.MoveNext())
  342. {
  343. if (enl.Current.Key == "rowid")
  344. {
  345. dgv.Rows[add_rowindex].Cells[k].Value = (i + 1);
  346. }
  347. if (enl.Current.Key == "DiameterRatio")
  348. {
  349. double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  350. dgv.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  351. }
  352. if (enl.Current.Key == "ASPECT_ELONG")
  353. {
  354. double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  355. dgv.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  356. }
  357. if (particles.Columns.Contains(enl.Current.Key))
  358. {
  359. double num = 0;
  360. if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  361. {
  362. dgv.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  363. }
  364. else
  365. {
  366. dgv.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  367. }
  368. }
  369. if (enl.Current.Key == "TypeName")
  370. {
  371. if (particles.Rows[i]["TypeId"].ToString() == "9")
  372. {
  373. dgv.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  374. }
  375. }
  376. if (enl.Current.Key == "Equivalent")
  377. {
  378. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  379. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  380. dgv.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  381. }
  382. }
  383. }
  384. }
  385. if (dgv.Name == "dataGridView_success")
  386. {
  387. dgv.Columns["dgv_check"].Visible = false;
  388. dgv.Columns["ReMeasure"].Visible = false;
  389. }
  390. UpdateDB();
  391. }
  392. private DataTable UpdateTable(List<Particle> particles)
  393. {
  394. List<Particle> selectParticles = particles;
  395. DataTable dtUelect = new DataTable();
  396. dtUelect.Columns.Add("fieldid");
  397. dtUelect.Columns.Add("particleid");
  398. dtUelect.Columns.Add("AveGray");
  399. dtUelect.Columns.Add("RectLeft");
  400. dtUelect.Columns.Add("RectTop");
  401. dtUelect.Columns.Add("RectWidth");
  402. dtUelect.Columns.Add("RectHeight");
  403. dtUelect.Columns.Add("Area");
  404. dtUelect.Columns.Add("PosX");
  405. dtUelect.Columns.Add("PosY");
  406. dtUelect.Columns.Add("TypeId");
  407. dtUelect.Columns.Add("SegmentNum");
  408. dtUelect.Columns.Add("SEMPosX");
  409. dtUelect.Columns.Add("SEMPosY");
  410. dtUelect.Columns.Add("XrayId");
  411. dtUelect.Columns.Add("DMAX");
  412. dtUelect.Columns.Add("DMIN");
  413. dtUelect.Columns.Add("DPERP");
  414. dtUelect.Columns.Add("PERIMETER");
  415. dtUelect.Columns.Add("ORIENTATION");
  416. dtUelect.Columns.Add("DINSCR");
  417. dtUelect.Columns.Add("DMEAN");
  418. dtUelect.Columns.Add("DELONG");
  419. dtUelect.Columns.Add("DFERET");
  420. dtUelect.Columns.Add("TypeName");
  421. dtUelect.Columns.Add("TypeColor");
  422. dtUelect.Columns.Add("SubParticles");
  423. dtUelect.Columns.Add("Element");
  424. dtUelect.Columns.Add("Hardness");
  425. dtUelect.Columns.Add("Density");
  426. dtUelect.Columns.Add("Electrical_conductivity");
  427. for (int i = 0; i < selectParticles.Count; i++)
  428. {
  429. dtUelect.Rows.Add(selectParticles[i].FieldId, selectParticles[i].ParticleId, selectParticles[i].AveGray, selectParticles[i].RectLeft, selectParticles[i].RectTop, selectParticles[i].RectWidth, selectParticles[i].RectHeight, selectParticles[i].Area, selectParticles[i].PosX, selectParticles[i].PosX, selectParticles[i].TypeId, /*selectParticles[i].ElementNum,*/ selectParticles[i].SegmentNum, selectParticles[i].SEMPosX, selectParticles[i].SEMPosY, selectParticles[i].ParticleId, selectParticles[i].DMAX, selectParticles[i].DMIN, selectParticles[i].DPERP, selectParticles[i].PERIMETER, selectParticles[i].ORIENTATION, selectParticles[i].DINSCR, selectParticles[i].DMEAN, selectParticles[i].DELONG, selectParticles[i].DFERET, selectParticles[i].TypeName, selectParticles[i].TypeColor, "", "", "", "", "");
  430. }
  431. string str_libraryName = ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)ReportFun.resultFile.ResultInfo["Sample"])["Members"])["MsrParams"])["STDName"].ToString();
  432. DataTable userLibraryData = new DataTable();
  433. UserLibraryData userLibrary = new UserLibraryData(str_libraryName);
  434. if (userLibrary != null)
  435. {
  436. userLibraryData = userLibrary.GetSubAttributeFromDatabase();
  437. }
  438. else
  439. {
  440. userLibraryData = null;
  441. }
  442. if (userLibraryData != null)
  443. {
  444. for (int i = 0; i < dtUelect.Rows.Count; i++)
  445. {
  446. DataRow[] dr = userLibraryData.Select("STDId=" + dtUelect.Rows[i]["TypeId"].ToString());
  447. if (dr.Length > 0)
  448. {
  449. dtUelect.Rows[i]["Hardness"] = System.Text.RegularExpressions.Regex.Replace(dr[0]["Hardness"].ToString(), @"[^\d.\d]", "");
  450. dtUelect.Rows[i]["Density"] = System.Text.RegularExpressions.Regex.Replace(dr[0]["Density"].ToString(), @"[^\d.\d]", "");
  451. dtUelect.Rows[i]["Electrical_conductivity"] = System.Text.RegularExpressions.Regex.Replace(dr[0]["Electrical_conductivity"].ToString(), @"[^\d.\d]", "");
  452. }
  453. else
  454. {
  455. dtUelect.Rows[i]["Hardness"] = "";
  456. dtUelect.Rows[i]["Density"] = "";
  457. dtUelect.Rows[i]["Electrical_conductivity"] = "";
  458. }
  459. }
  460. }
  461. else
  462. {
  463. for (int i = 0; i < dtUelect.Rows.Count; i++)
  464. {
  465. dtUelect.Rows[i]["Hardness"] = "";
  466. dtUelect.Rows[i]["Density"] = "";
  467. dtUelect.Rows[i]["Electrical_conductivity"] = "";
  468. }
  469. }
  470. ParticleData Particledata = new ParticleData(ReportFun.resultFile.FilePath);
  471. DataTable elementchemistry = Particledata.GetElementChemistry();
  472. for (int i = 0; i < dtUelect.Rows.Count; i++)
  473. {
  474. string str = "XRayId = " + dtUelect.Rows[i]["particleId"].ToString() + " and fieldid = " + dtUelect.Rows[i]["fieldid"].ToString();
  475. DataRow[] drs = elementchemistry.Select(str);
  476. string ConcatenatedString = "";
  477. for (int j = 0; j < drs.Length; j++)
  478. {
  479. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  480. }
  481. dtUelect.Rows[i]["Element"] = ConcatenatedString;
  482. }
  483. return dtUelect;
  484. }
  485. private void frmReMeasure_Load(object sender, EventArgs e)
  486. {
  487. //图像扫描精度
  488. IDC_COMBO_IMGSCANSPEED.Items.Clear();
  489. foreach (otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS enum_one in Enum.GetValues(typeof(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS)))
  490. {
  491. ComboBoxItem cbi = new ComboBoxItem();
  492. cbi.Text = GetScanSpeedString(enum_one);
  493. cbi.Value = (int)enum_one;
  494. IDC_COMBO_IMGSCANSPEED.Items.Add(cbi);
  495. }
  496. IDC_COMBO_IMGSCANSPEED.SelectedIndex = (int)otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.low;
  497. //X-Ray扫描方式
  498. IDC_COMBO_XRAYSCANMODE.Items.Clear();
  499. foreach (otsdataconst.OTS_X_RAY_SCAN_MODE enum_one in Enum.GetValues(typeof(otsdataconst.OTS_X_RAY_SCAN_MODE)))
  500. {
  501. ComboBoxItem cbi = new ComboBoxItem();
  502. cbi.Text = GetXRayScanModeIdString(enum_one);
  503. cbi.Value = (int)enum_one;
  504. IDC_COMBO_XRAYSCANMODE.Items.Add(cbi);
  505. }
  506. IDC_COMBO_XRAYSCANMODE.SelectedIndex = (int)otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode;
  507. //旧放大倍数
  508. Dictionary<string, object> sample = (Dictionary<string, object>)ReportFun.resultFile.ResultInfo["Sample"];
  509. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)(sample)["Members"]);
  510. Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
  511. Dictionary<string, object> SEMDataMsr = (Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["SEMDataMsr"]);
  512. ScanFieldSizeX = double.Parse(SEMDataMsr["ScanFieldSize"].ToString());
  513. ScanFieldSizeX100 = double.Parse(SEMDataMsr["ScanFieldSize100"].ToString());
  514. oldMag = Math.Round((ScanFieldSizeX100 / ScanFieldSizeX) * 100, 2);
  515. //LB_OLDMAGVALUE.Text = oldMag.ToString();
  516. //颗粒信息
  517. sampleName = sample["SampleName"].ToString();
  518. string ImageResolution = imageScanParam["ImageResolution"].ToString();
  519. width = int.Parse(ImageResolution.Split('_')[1]);
  520. height = int.Parse(ImageResolution.Split('_')[2]);
  521. old_pixelsize = ScanFieldSizeX / width;
  522. ScanFieldSizeY100 = height * old_pixelsize;
  523. //颗粒方法
  524. CB_partFun.SelectedIndex = 0;
  525. control_XRayTable1.Visible = false;
  526. }
  527. private void showXrayChart(Particle particle)
  528. {
  529. if (particle.XRayData == null)
  530. {
  531. //control_XRayTable1.Visible = false;
  532. return;
  533. }
  534. //显示xray相关信息
  535. uint[] Search_xray = new uint[2000];
  536. uint[] Analysis_xray = new uint[2000];
  537. //获取Xray数据
  538. for (int i = 0; i < 2000; i++)
  539. {
  540. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  541. }
  542. Search_xray = Analysis_xray;
  543. //get CElementChemistryClr list
  544. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  545. for (int i = 0; i < particle.ElementList.Count; i++)
  546. {
  547. ShowElementInfo ls_sei = new ShowElementInfo();
  548. ls_sei.ElementName = particle.ElementList[i].Name;
  549. ls_sei.Percentage = particle.ElementList[i].Percentage;
  550. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1);
  551. double de_sx2 = 0;
  552. if (CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "" || CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "-")
  553. {
  554. de_sx2 = 0;
  555. }
  556. else
  557. {
  558. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2);
  559. }
  560. ls_sei.dLF = de_sx2;
  561. list_showelementinfo.Add(ls_sei);
  562. }
  563. //获取数据后,需要对xraytable设置
  564. control_XRayTable1.Visible = false;
  565. control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
  566. //颗粒国标信息
  567. control_XRayTable1.GBInfoStr = "";
  568. control_XRayTable1.MaterialName = particle.TypeName;//名称
  569. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  570. control_XRayTable1.Visible = true;
  571. this.Refresh();
  572. }
  573. public string GetScanSpeedString(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS a_nScanSpeed)
  574. {
  575. string strScanSpeedId = "";
  576. if (a_nScanSpeed >= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.low && a_nScanSpeed <= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.high)
  577. {
  578. strScanSpeedId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_SCANSPEED + (int)a_nScanSpeed);
  579. }
  580. return strScanSpeedId;
  581. }
  582. public static string GetXRayScanModeIdString(otsdataconst.OTS_X_RAY_SCAN_MODE a_nXRayScanMode)
  583. {
  584. string strXRayScanModeId = "";
  585. if (a_nXRayScanMode >= otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode && a_nXRayScanMode <= otsdataconst.OTS_X_RAY_SCAN_MODE.FeatureMode)
  586. {
  587. strXRayScanModeId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_XRAYSCANMODE + (int)a_nXRayScanMode);
  588. }
  589. return strXRayScanModeId;
  590. }
  591. private void BTN_NO_Click(object sender, EventArgs e)
  592. {
  593. stopFlag = true;
  594. }
  595. private void BTN_YES_Click(object sender, EventArgs e)
  596. {
  597. //参数定义
  598. int nBrukerDwellTimeId = 3;
  599. switch (IDC_COMBO_IMGSCANSPEED.SelectedIndex)
  600. {
  601. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.low:
  602. nBrukerDwellTimeId = 3;
  603. break;
  604. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
  605. nBrukerDwellTimeId = 4;
  606. break;
  607. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.high:
  608. nBrukerDwellTimeId = 5;
  609. break;
  610. default:
  611. nBrukerDwellTimeId = 3;
  612. break;
  613. }
  614. nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
  615. tabControl_grid.SelectedIndex = 0;
  616. tabControl_grid.Enabled = false;
  617. groupBox_param.Enabled = false;
  618. partFunIndex = CB_partFun.SelectedIndex;
  619. xrayScanMode = IDC_COMBO_XRAYSCANMODE.SelectedIndex;
  620. bgw_process.RunWorkerAsync();
  621. }
  622. private void bgw_process_DoWork(object sender, DoWorkEventArgs e)
  623. {
  624. //第一步,连接电镜
  625. if (!m_OTSIncAReportGridsFun.Connection_ForParticlesGrid())
  626. {
  627. SetProgressMessage(table["str2"].ToString(), richTextBox_process);
  628. return;
  629. }
  630. Thread.Sleep(500);
  631. keyValuesMat = new Dictionary<int, Mat>();
  632. for (int i = 0; i < SelectedParticles.Count; i++)
  633. {
  634. if (!(bool)dgV_ParticlesDevidePage.Rows[i].Cells[0].Value)
  635. {
  636. MessageBox.Show(i.ToString());
  637. continue;
  638. }
  639. if (stopFlag)
  640. {
  641. MessageBox.Show(table["str3"].ToString());
  642. return;
  643. }
  644. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  645. {
  646. dgV_ParticlesDevidePage.Rows[i].DefaultCellStyle.BackColor = Color.Blue;
  647. SetProgressMessage(table["str4"].ToString() + (i + 1), richTextBox_process);
  648. double new_ScanFieldSize_width = (SelectedParticles[i].RectWidth + (double)NUD_Outspread.Value) * old_pixelsize;
  649. double new_ScanFieldSize_height = (SelectedParticles[i].RectHeight + (double)NUD_Outspread.Value) * old_pixelsize;
  650. double mag_width = Math.Round((ScanFieldSizeX100 / new_ScanFieldSize_width) * 100, 2);
  651. double mag_height = Math.Round((ScanFieldSizeY100 / new_ScanFieldSize_height) * 100, 2);
  652. double final_mag = mag_width > mag_height ? mag_height : mag_width;
  653. new_pixelsize = new_ScanFieldSize_width / width;
  654. SetProgressMessage(table["str5"].ToString() + final_mag, richTextBox_process);
  655. if (!m_OTSIncAReportGridsFun.SetMagnification(final_mag))
  656. {
  657. SetProgressMessage(table["str6"].ToString(), richTextBox_process);
  658. return;
  659. }
  660. Point point = Control_DrawDistrbutionImageAndBSE.CalculateParticleCenterPosition(ReportFun.resultFile, new Point(SelectedParticles[i].SEMPosX, SelectedParticles[i].SEMPosY), new Point(SelectedParticles[i].PosX, SelectedParticles[i].PosY));
  661. SetProgressMessage(table["str7"].ToString() + point.X + "," + point.Y, richTextBox_process);
  662. if (!m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(point.X, point.Y))
  663. {
  664. SetProgressMessage(table["str8"].ToString(), richTextBox_process);
  665. return;
  666. }
  667. SetProgressMessage(table["str9"].ToString(), richTextBox_process);
  668. byte[] ImageByte = new byte[width * height];
  669. if (!m_OTSIncAReportGridsFun.AcquireBSEImage(sampleName, width, height, nBrukerDwellTime, ref ImageByte))
  670. {
  671. SetProgressMessage(table["str10"].ToString(), richTextBox_process);
  672. return;
  673. }
  674. SetProgressMessage(table["str11"].ToString(), richTextBox_process);
  675. //Mat mat = new Mat(@"F:\汽车清洁度\20220325\2\Sample1\FIELD_FILES\Field" + i + ".bmp", ImreadModes.Grayscale);
  676. //Mat mat = new Mat(resultFile.FilePath + "\\" + savePathName + "\\" + SelectedParticles[i].FieldId + "_" + SelectedParticles[i].ParticleId + ".bmp", ImreadModes.Grayscale);
  677. Mat mat = new Mat(height, width, MatType.CV_8UC1, ImageByte);
  678. Particle particle_new = (Particle)ReportFun.CloneObject(SelectedParticles[i]);
  679. particle_new.XrayId = SelectedParticles[i].XrayId + 10000;
  680. if (!FindNewPartInfo(ref mat, particle_new))
  681. {
  682. SetProgressMessage(table["str12"].ToString(), richTextBox_process);
  683. return;
  684. }
  685. SetProgressMessage(table["str13"].ToString(), richTextBox_process);
  686. if (!m_OTSIncAReportGridsFun.AcquisitionSpectrum(ReportFun.resultFile.FilePath + "\\FIELD_FILES\\", xrayScanMode, new_pixelsize, ref particle_new, (uint)NUD_SCANTIME.Value))
  687. {
  688. SetProgressMessage(table["str14"].ToString(), richTextBox_process);
  689. return;
  690. }
  691. showXrayChart(particle_new);//显示Xray图
  692. SaveXray(particle_new.FieldId + "_" + particle_new.ParticleId + ".bmp");//保存图谱图
  693. keyValuesMat.Add(i, mat);
  694. bgw_process.ReportProgress(0, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat));
  695. SetProgressMessage(table["str16"].ToString() + (i + 1), richTextBox_process);
  696. dgV_ParticlesDevidePage.Rows[i].DefaultCellStyle.BackColor = Color.Green;
  697. SelectedParticles[i] = particle_new;
  698. }
  699. }
  700. ReadSuccessDb();
  701. BindDataGridView(dataGridView_success, successParticles);
  702. BindDataGridView(dgV_ParticlesDevidePage, SelectedParticles);
  703. Thread.Sleep(500);
  704. SetProgressMessage(table["str17"].ToString(), richTextBox_process);
  705. }
  706. private void bgw_process_ProgressChanged(object sender, ProgressChangedEventArgs e)
  707. {
  708. switch (e.ProgressPercentage)
  709. {
  710. case 0: pictureBox_part.Image = (Bitmap)e.UserState; break;
  711. default:
  712. break;
  713. }
  714. }
  715. private bool SaveImg(string imgName, Mat mat)
  716. {
  717. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName))
  718. {
  719. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName);
  720. }
  721. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image"))
  722. {
  723. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image");
  724. }
  725. Cv2.ImWrite(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image\\" + imgName, mat);
  726. return true;
  727. }
  728. private bool SaveXray(string imgName)
  729. {
  730. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName))
  731. {
  732. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName);
  733. }
  734. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\xray"))
  735. {
  736. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\xray");
  737. }
  738. using (Bitmap bmp = new Bitmap(control_XRayTable1.Width, control_XRayTable1.Height))
  739. {
  740. control_XRayTable1.DrawToBitmap(bmp, control_XRayTable1.ClientRectangle);
  741. bmp.Save(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\xray\\" + imgName);
  742. }
  743. return true;
  744. }
  745. /// <summary>
  746. /// 颗粒处理核心方法
  747. /// </summary>
  748. /// <param name="mat"></param>
  749. /// <param name="particle_new"></param>
  750. /// <returns></returns>
  751. private bool FindNewPartInfo(ref Mat mat, Particle particle_new)
  752. {
  753. try
  754. {
  755. using (Mat mat_dst = new Mat())
  756. {
  757. Dictionary<int, double> keyValuePairs = new Dictionary<int, double>();
  758. switch (partFunIndex)
  759. {
  760. case 0: Cv2.Threshold(mat, mat_dst, 0, 255, ThresholdTypes.Triangle);break;
  761. case 1: Cv2.Threshold(mat, mat_dst, 0, 255, ThresholdTypes.Otsu);break;
  762. }
  763. Mat labelMat = new Mat();
  764. Mat stats = new Mat();//点的信息
  765. Mat centroids = new Mat();//质心的信息
  766. int nonenum = Cv2.ConnectedComponentsWithStats(mat_dst, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
  767. for (int h = 1; h < centroids.Height; h++)
  768. {
  769. int areaField = stats.At<int>(h, 4);
  770. keyValuePairs.Add(h, areaField);
  771. }
  772. int Key = 0;//新颗粒序列
  773. if (CB_HAND.Checked)//手动处理
  774. {
  775. Mat srcWhite = new Mat(mat_dst.Height, mat_dst.Width, MatType.CV_8UC1, new Scalar(0));//黑色底图
  776. mat.CopyTo(srcWhite, mat_dst);
  777. bgw_process.ReportProgress(0, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(srcWhite));
  778. SetProgressMessage(table["str18"].ToString(), richTextBox_process);
  779. GetKeyNo(labelMat, mat_dst.Width, mat_dst.Height, ref Key);
  780. }
  781. else//自动处理
  782. {
  783. keyValuePairs = keyValuePairs.OrderByDescending(a => a.Value).ToDictionary(a => a.Key, b => b.Value);
  784. Dictionary<int, double> dsList = new Dictionary<int, double>();
  785. for (int i = 0; i < keyValuePairs.Count; i++)
  786. {
  787. dsList.Add(keyValuePairs.ElementAt(i).Key, Math.Abs(keyValuePairs.ElementAt(i).Value * new_pixelsize * new_pixelsize - particle_new.Area));
  788. }
  789. dsList = dsList.OrderBy(a => a.Value).ToDictionary(a => a.Key, b => b.Value);
  790. Key = dsList.ElementAt(0).Key;
  791. }
  792. Cv2.CvtColor(mat_dst, mat_dst, ColorConversionCodes.RGB2BGR);
  793. OpenCvSharp.Point centroidsPoint = new OpenCvSharp.Point((int)centroids.At<double>(Key, 0), (int)centroids.At<double>(Key, 1));
  794. Rect rect = new Rect(stats.At<int>(Key, 0), stats.At<int>(Key, 1), stats.At<int>(Key, 2), stats.At<int>(Key, 3));
  795. Cv2.Circle(mat_dst, centroidsPoint, 5, Scalar.Green, -1);
  796. Cv2.Rectangle(mat_dst, rect, Scalar.Red);
  797. bgw_process.ReportProgress(0, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_dst));
  798. //保存局部高清图片
  799. mat = new Mat(mat, rect);
  800. if (mat.Width > mat.Height)
  801. {
  802. dsize = new OpenCvSharp.Size(100, 100 * mat.Height / mat.Width);
  803. }
  804. else
  805. {
  806. dsize = new OpenCvSharp.Size(100 * mat.Width / mat.Height, 100);
  807. }
  808. Cv2.Resize(mat, mat, dsize, 0, 0, InterpolationFlags.Cubic);
  809. //保存高清图
  810. SaveImg(particle_new.FieldId + "_" + particle_new.ParticleId + ".bmp", mat);
  811. //取各个轮廓内的像素
  812. List<Point> points = new List<Point>();
  813. for (int k = 0; k < labelMat.Height; k++)
  814. {
  815. for (int j = 0; j < labelMat.Width; j++)
  816. {
  817. int no = labelMat.Get<int>(k, j);
  818. if (Key == no)
  819. {
  820. points.Add(new Point(j, k));
  821. }
  822. }
  823. }
  824. //保存颗粒信息
  825. particle_new.PosX = centroidsPoint.X;
  826. particle_new.PosY = centroidsPoint.Y;
  827. particle_new.RectLeft = stats.At<int>(Key, 0);
  828. particle_new.RectTop = stats.At<int>(Key, 1);
  829. particle_new.RectWidth = stats.At<int>(Key, 2);
  830. particle_new.RectHeight = stats.At<int>(Key, 3);
  831. List<COTSSegmentClr> SegmentClrList1 = new List<COTSSegmentClr>();
  832. List<Segment> SegmentList1 = new List<Segment>();
  833. ReportFun.GetSegment(points, particle_new, SegmentClrList1, ref SegmentList1);
  834. particle_new.SegmentList = SegmentList1;
  835. particle_new.SegmentNum = SegmentList1.Count;
  836. }
  837. }
  838. catch (Exception ex)
  839. {
  840. SetProgressMessage(ex.ToString(), richTextBox_process);
  841. return false;
  842. }
  843. return true;
  844. }
  845. private void bgw_process_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  846. {
  847. stopFlag = false;
  848. tabControl_grid.Enabled = true;
  849. groupBox_param.Enabled = true;
  850. }
  851. private void pictureBox_part_MouseDown(object sender, MouseEventArgs e)
  852. {
  853. if (CB_HAND.Checked && pictureBox_part.Image != null)
  854. {
  855. int originalWidth = this.pictureBox_part.Image.Width;
  856. int originalHeight = this.pictureBox_part.Image.Height;
  857. PropertyInfo rectangleProperty = this.pictureBox_part.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  858. Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(this.pictureBox_part, null);
  859. int currentWidth = rectangle.Width;
  860. int currentHeight = rectangle.Height;
  861. double rate = (double)currentHeight / (double)originalHeight;
  862. int black_left_width = (currentWidth == this.pictureBox_part.Width) ? 0 : (this.pictureBox_part.Width - currentWidth) / 2;
  863. int black_top_height = (currentHeight == this.pictureBox_part.Height) ? 0 : (this.pictureBox_part.Height - currentHeight) / 2;
  864. int zoom_x = e.X - black_left_width;
  865. int zoom_y = e.Y - black_top_height;
  866. double original_x = (double)zoom_x / rate;
  867. double original_y = (double)zoom_y / rate;
  868. //StringBuilder sb = new StringBuilder();
  869. //sb.AppendFormat("原始尺寸{0}/{1}(宽/高)\r\n", originalWidth, originalHeight);
  870. //sb.AppendFormat("缩放状态图片尺寸{0}/{1}(宽/高)\r\n", currentWidth, currentHeight);
  871. //sb.AppendFormat("缩放比率{0}\r\n", rate);
  872. //sb.AppendFormat("左留白宽度{0}\r\n", black_left_width);
  873. //sb.AppendFormat("上留白高度{0}\r\n", black_top_height);
  874. //sb.AppendFormat("当前鼠标坐标{0}/{1}(X/Y)\r\n", e.X, e.Y);
  875. //sb.AppendFormat("缩放图中鼠标坐标{0}/{1}(X/Y)\r\n", zoom_x, zoom_y);
  876. //sb.AppendFormat("原始图中鼠标坐标{0}/{1}(X/Y)\r\n", original_x, original_y);
  877. handPoint = new Point((int)original_x, (int)original_y);
  878. }
  879. }
  880. /// <summary>
  881. ///获取手动处理序号
  882. /// </summary>
  883. /// <param name="labelMat"></param>
  884. /// <param name="width"></param>
  885. /// <param name="height"></param>
  886. /// <param name="key"></param>
  887. private void GetKeyNo(Mat labelMat, int width, int height, ref int key)
  888. {
  889. handPoint = new Point(-1, -1);
  890. Color color = groupBox_img.BackColor;
  891. while (key == 0 && stopFlag == false)
  892. {
  893. groupBox_img.BackColor = Color.Red;
  894. Thread.Sleep(1000);
  895. if (handPoint.X >= 0 && handPoint.X < width && handPoint.Y >= 0 && handPoint.Y < height)
  896. {
  897. key = labelMat.Get<int>((int)handPoint.Y, (int)handPoint.X);
  898. }
  899. }
  900. groupBox_img.BackColor = color;
  901. }
  902. private void dgV_ParticlesDevidePage_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  903. {
  904. if (e.ColumnIndex == 0)
  905. {
  906. foreach (DataGridViewRow dr in dgV_ParticlesDevidePage.Rows)
  907. {
  908. dr.Cells[0].Value = !isCheck;
  909. }
  910. isCheck = !isCheck;
  911. }
  912. }
  913. private void dgV_ParticlesDevidePage_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  914. {
  915. if (e.ColumnIndex == 0 && e.RowIndex != -1)
  916. {
  917. if ((bool)dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
  918. {
  919. dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = false;
  920. }
  921. else
  922. {
  923. dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;
  924. }
  925. }
  926. if (e.RowIndex != -1)
  927. {
  928. string imagePath = ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image\\" + dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells["FieldID"].Value + "_" + dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells["particleid"].Value + ".bmp";
  929. if (File.Exists(imagePath))
  930. {
  931. pictureBox_part.Image = new Bitmap(imagePath);
  932. }
  933. else
  934. {
  935. pictureBox_part.Image = null;
  936. }
  937. showXrayChart(SelectedParticles[e.RowIndex]);//显示Xray图
  938. }
  939. }
  940. private void dataGridView_success_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  941. {
  942. if (e.RowIndex != -1)
  943. {
  944. string imagePath = ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image\\" + dataGridView_success.Rows[e.RowIndex].Cells["FieldID"].Value + "_" + dataGridView_success.Rows[e.RowIndex].Cells["particleid"].Value + ".bmp";
  945. if (File.Exists(imagePath))
  946. {
  947. pictureBox_part.Image = new Bitmap(imagePath);
  948. }
  949. else
  950. {
  951. pictureBox_part.Image = null;
  952. }
  953. showXrayChart(successParticles[e.RowIndex]);//显示Xray图
  954. }
  955. }
  956. private void BTN_EXPORT_Click(object sender, EventArgs e)
  957. {
  958. ExportDgvToExcel export = new ExportDgvToExcel();
  959. SetState(false);
  960. string imagePath = ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName;
  961. export.ExportExcel(imagePath, dataGridView_success, "宋体", 11);//默认文件名,DataGridView控件的名称,字体,字号
  962. SetState(true);
  963. MessageBox.Show(table["str37"].ToString(), table["str38"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  964. }
  965. private void SetState(bool isTrue)
  966. {
  967. dataGridView_success.Columns["FieldID"].Visible = isTrue;
  968. dataGridView_success.Columns["particleid"].Visible = isTrue;
  969. dataGridView_success.Columns["SEMPosX"].Visible = isTrue;
  970. dataGridView_success.Columns["SEMPosY"].Visible = isTrue;
  971. }
  972. }
  973. }