frmReMeasure.cs 49 KB

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