frmReMeasure.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  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[] Analysis_xray = new uint[2000];
  534. //获取Xray数据
  535. for (int i = 0; i < 2000; i++)
  536. {
  537. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  538. }
  539. //get CElementChemistryClr list
  540. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  541. for (int i = 0; i < particle.ElementList.Count; i++)
  542. {
  543. ShowElementInfo ls_sei = new ShowElementInfo();
  544. ls_sei.ElementName = particle.ElementList[i].Name;
  545. ls_sei.Percentage = particle.ElementList[i].Percentage;
  546. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  547. double de_K_Peak = 0;
  548. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak == "-")
  549. {
  550. de_K_Peak = 0;
  551. }
  552. else
  553. {
  554. de_K_Peak = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  555. }
  556. ls_sei.dLF = de_K_Peak;
  557. list_showelementinfo.Add(ls_sei);
  558. }
  559. //获取数据后,需要对xraytable设置
  560. control_XRayTable1.Visible = false;
  561. control_XRayTable1.SetXRayShowLineValue(Analysis_xray, list_showelementinfo);
  562. //颗粒国标信息
  563. control_XRayTable1.GBInfoStr = "";
  564. control_XRayTable1.MaterialName = particle.TypeName;//名称
  565. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  566. control_XRayTable1.Visible = true;
  567. this.Refresh();
  568. }
  569. public string GetScanSpeedString(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS a_nScanSpeed)
  570. {
  571. string strScanSpeedId = "";
  572. if (a_nScanSpeed >= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.low && a_nScanSpeed <= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.high)
  573. {
  574. strScanSpeedId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_SCANSPEED + (int)a_nScanSpeed);
  575. }
  576. return strScanSpeedId;
  577. }
  578. public static string GetXRayScanModeIdString(otsdataconst.OTS_X_RAY_SCAN_MODE a_nXRayScanMode)
  579. {
  580. string strXRayScanModeId = "";
  581. if (a_nXRayScanMode >= otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode && a_nXRayScanMode <= otsdataconst.OTS_X_RAY_SCAN_MODE.FeatureMode)
  582. {
  583. strXRayScanModeId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_XRAYSCANMODE + (int)a_nXRayScanMode);
  584. }
  585. return strXRayScanModeId;
  586. }
  587. private void BTN_NO_Click(object sender, EventArgs e)
  588. {
  589. stopFlag = true;
  590. }
  591. private void BTN_YES_Click(object sender, EventArgs e)
  592. {
  593. //参数定义
  594. nBrukerDwellTime = DwellTimeLevel.Low;
  595. switch (IDC_COMBO_IMGSCANSPEED.SelectedIndex)
  596. {
  597. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.low:
  598. nBrukerDwellTime = DwellTimeLevel.Low;
  599. break;
  600. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
  601. nBrukerDwellTime = DwellTimeLevel.Medium;
  602. break;
  603. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.high:
  604. nBrukerDwellTime = DwellTimeLevel.High;
  605. break;
  606. default:
  607. nBrukerDwellTime = DwellTimeLevel.Low;
  608. break;
  609. }
  610. //nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
  611. tabControl_grid.SelectedIndex = 0;
  612. tabControl_grid.Enabled = false;
  613. groupBox_param.Enabled = false;
  614. partFunIndex = CB_partFun.SelectedIndex;
  615. xrayScanMode = IDC_COMBO_XRAYSCANMODE.SelectedIndex;
  616. bgw_process.RunWorkerAsync();
  617. }
  618. private void bgw_process_DoWork(object sender, DoWorkEventArgs e)
  619. {
  620. //第一步,连接电镜
  621. if (!m_OTSIncAReportGridsFun.Connection_ForParticlesGrid())
  622. {
  623. SetProgressMessage(table["str2"].ToString(), richTextBox_process);
  624. return;
  625. }
  626. Thread.Sleep(500);
  627. keyValuesMat = new Dictionary<int, Mat>();
  628. for (int i = 0; i < SelectedParticles.Count; i++)
  629. {
  630. if (!(bool)dgV_ParticlesDevidePage.Rows[i].Cells[0].Value)
  631. {
  632. MessageBox.Show(i.ToString());
  633. continue;
  634. }
  635. if (stopFlag)
  636. {
  637. MessageBox.Show(table["str3"].ToString());
  638. return;
  639. }
  640. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  641. {
  642. dgV_ParticlesDevidePage.Rows[i].DefaultCellStyle.BackColor = Color.Blue;
  643. SetProgressMessage(table["str4"].ToString() + (i + 1), richTextBox_process);
  644. double new_ScanFieldSize_width = (SelectedParticles[i].RectWidth + (double)NUD_Outspread.Value) * old_pixelsize;
  645. double new_ScanFieldSize_height = (SelectedParticles[i].RectHeight + (double)NUD_Outspread.Value) * old_pixelsize;
  646. double mag_width = Math.Round((ScanFieldSizeX100 / new_ScanFieldSize_width) * 100, 2);
  647. double mag_height = Math.Round((ScanFieldSizeY100 / new_ScanFieldSize_height) * 100, 2);
  648. double final_mag = mag_width > mag_height ? mag_height : mag_width;
  649. new_pixelsize = new_ScanFieldSize_width / width;
  650. SetProgressMessage(table["str5"].ToString() + final_mag, richTextBox_process);
  651. if (!m_OTSIncAReportGridsFun.SetMagnification(final_mag))
  652. {
  653. SetProgressMessage(table["str6"].ToString(), richTextBox_process);
  654. return;
  655. }
  656. Point point = Control_DrawDistrbutionImageAndBSE.CalculateParticleCenterPosition(ReportFun.resultFile, new Point(SelectedParticles[i].SEMPosX, SelectedParticles[i].SEMPosY), new Point(SelectedParticles[i].PosX, SelectedParticles[i].PosY));
  657. SetProgressMessage(table["str7"].ToString() + point.X + "," + point.Y, richTextBox_process);
  658. if (!m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(point.X, point.Y))
  659. {
  660. SetProgressMessage(table["str8"].ToString(), richTextBox_process);
  661. return;
  662. }
  663. SetProgressMessage(table["str9"].ToString(), richTextBox_process);
  664. byte[] ImageByte = new byte[width * height];
  665. if (!m_OTSIncAReportGridsFun.AcquireBSEImage(sampleName, width, height, nBrukerDwellTime, ref ImageByte))
  666. {
  667. SetProgressMessage(table["str10"].ToString(), richTextBox_process);
  668. return;
  669. }
  670. SetProgressMessage(table["str11"].ToString(), richTextBox_process);
  671. //Mat mat = new Mat(@"F:\汽车清洁度\20220325\2\Sample1\FIELD_FILES\Field" + i + ".bmp", ImreadModes.Grayscale);
  672. //Mat mat = new Mat(resultFile.FilePath + "\\" + savePathName + "\\" + SelectedParticles[i].FieldId + "_" + SelectedParticles[i].ParticleId + ".bmp", ImreadModes.Grayscale);
  673. Mat mat = new Mat(height, width, MatType.CV_8UC1, ImageByte);
  674. Particle particle_new = (Particle)ReportFun.CloneObject(SelectedParticles[i]);
  675. particle_new.XrayId = SelectedParticles[i].XrayId + 10000;
  676. if (!FindNewPartInfo(ref mat, particle_new))
  677. {
  678. SetProgressMessage(table["str12"].ToString(), richTextBox_process);
  679. return;
  680. }
  681. SetProgressMessage(table["str13"].ToString(), richTextBox_process);
  682. if (!m_OTSIncAReportGridsFun.AcquisitionSpectrum(ReportFun.resultFile.FilePath + "\\FIELD_FILES\\", xrayScanMode, new_pixelsize, ref particle_new, (uint)NUD_SCANTIME.Value))
  683. {
  684. SetProgressMessage(table["str14"].ToString(), richTextBox_process);
  685. return;
  686. }
  687. showXrayChart(particle_new);//显示Xray图
  688. SaveXray(particle_new.FieldId + "_" + particle_new.ParticleId + ".bmp");//保存图谱图
  689. keyValuesMat.Add(i, mat);
  690. bgw_process.ReportProgress(0, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat));
  691. SetProgressMessage(table["str16"].ToString() + (i + 1), richTextBox_process);
  692. dgV_ParticlesDevidePage.Rows[i].DefaultCellStyle.BackColor = Color.Green;
  693. SelectedParticles[i] = particle_new;
  694. }
  695. }
  696. ReadSuccessDb();
  697. BindDataGridView(dataGridView_success, successParticles);
  698. BindDataGridView(dgV_ParticlesDevidePage, SelectedParticles);
  699. Thread.Sleep(500);
  700. SetProgressMessage(table["str17"].ToString(), richTextBox_process);
  701. }
  702. private void bgw_process_ProgressChanged(object sender, ProgressChangedEventArgs e)
  703. {
  704. switch (e.ProgressPercentage)
  705. {
  706. case 0: pictureBox_part.Image = (Bitmap)e.UserState; break;
  707. default:
  708. break;
  709. }
  710. }
  711. private bool SaveImg(string imgName, Mat mat)
  712. {
  713. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName))
  714. {
  715. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName);
  716. }
  717. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image"))
  718. {
  719. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image");
  720. }
  721. Cv2.ImWrite(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\image\\" + imgName, mat);
  722. return true;
  723. }
  724. private bool SaveXray(string imgName)
  725. {
  726. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName))
  727. {
  728. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName);
  729. }
  730. if (!Directory.Exists(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\xray"))
  731. {
  732. Directory.CreateDirectory(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\xray");
  733. }
  734. using (Bitmap bmp = new Bitmap(control_XRayTable1.Width, control_XRayTable1.Height))
  735. {
  736. control_XRayTable1.DrawToBitmap(bmp, control_XRayTable1.ClientRectangle);
  737. bmp.Save(ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName + "\\xray\\" + imgName);
  738. }
  739. return true;
  740. }
  741. /// <summary>
  742. /// 颗粒处理核心方法
  743. /// </summary>
  744. /// <param name="mat"></param>
  745. /// <param name="particle_new"></param>
  746. /// <returns></returns>
  747. private bool FindNewPartInfo(ref Mat mat, Particle particle_new)
  748. {
  749. try
  750. {
  751. using (Mat mat_dst = new Mat())
  752. {
  753. Dictionary<int, double> keyValuePairs = new Dictionary<int, double>();
  754. switch (partFunIndex)
  755. {
  756. case 0: Cv2.Threshold(mat, mat_dst, 0, 255, ThresholdTypes.Triangle);break;
  757. case 1: Cv2.Threshold(mat, mat_dst, 0, 255, ThresholdTypes.Otsu);break;
  758. }
  759. Mat labelMat = new Mat();
  760. Mat stats = new Mat();//点的信息
  761. Mat centroids = new Mat();//质心的信息
  762. int nonenum = Cv2.ConnectedComponentsWithStats(mat_dst, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
  763. for (int h = 1; h < centroids.Height; h++)
  764. {
  765. int areaField = stats.At<int>(h, 4);
  766. keyValuePairs.Add(h, areaField);
  767. }
  768. int Key = 0;//新颗粒序列
  769. if (CB_HAND.Checked)//手动处理
  770. {
  771. Mat srcWhite = new Mat(mat_dst.Height, mat_dst.Width, MatType.CV_8UC1, new Scalar(0));//黑色底图
  772. mat.CopyTo(srcWhite, mat_dst);
  773. bgw_process.ReportProgress(0, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(srcWhite));
  774. SetProgressMessage(table["str18"].ToString(), richTextBox_process);
  775. GetKeyNo(labelMat, mat_dst.Width, mat_dst.Height, ref Key);
  776. }
  777. else//自动处理
  778. {
  779. keyValuePairs = keyValuePairs.OrderByDescending(a => a.Value).ToDictionary(a => a.Key, b => b.Value);
  780. Dictionary<int, double> dsList = new Dictionary<int, double>();
  781. for (int i = 0; i < keyValuePairs.Count; i++)
  782. {
  783. dsList.Add(keyValuePairs.ElementAt(i).Key, Math.Abs(keyValuePairs.ElementAt(i).Value * new_pixelsize * new_pixelsize - particle_new.Area));
  784. }
  785. dsList = dsList.OrderBy(a => a.Value).ToDictionary(a => a.Key, b => b.Value);
  786. Key = dsList.ElementAt(0).Key;
  787. }
  788. Cv2.CvtColor(mat_dst, mat_dst, ColorConversionCodes.RGB2BGR);
  789. OpenCvSharp.Point centroidsPoint = new OpenCvSharp.Point((int)centroids.At<double>(Key, 0), (int)centroids.At<double>(Key, 1));
  790. Rect rect = new Rect(stats.At<int>(Key, 0), stats.At<int>(Key, 1), stats.At<int>(Key, 2), stats.At<int>(Key, 3));
  791. Cv2.Circle(mat_dst, centroidsPoint, 5, Scalar.Green, -1);
  792. Cv2.Rectangle(mat_dst, rect, Scalar.Red);
  793. bgw_process.ReportProgress(0, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_dst));
  794. //保存局部高清图片
  795. mat = new Mat(mat, rect);
  796. if (mat.Width > mat.Height)
  797. {
  798. dsize = new OpenCvSharp.Size(100, 100 * mat.Height / mat.Width);
  799. }
  800. else
  801. {
  802. dsize = new OpenCvSharp.Size(100 * mat.Width / mat.Height, 100);
  803. }
  804. Cv2.Resize(mat, mat, dsize, 0, 0, InterpolationFlags.Cubic);
  805. //保存高清图
  806. SaveImg(particle_new.FieldId + "_" + particle_new.ParticleId + ".bmp", mat);
  807. //取各个轮廓内的像素
  808. List<Point> points = new List<Point>();
  809. for (int k = 0; k < labelMat.Height; k++)
  810. {
  811. for (int j = 0; j < labelMat.Width; j++)
  812. {
  813. int no = labelMat.Get<int>(k, j);
  814. if (Key == no)
  815. {
  816. points.Add(new Point(j, k));
  817. }
  818. }
  819. }
  820. //保存颗粒信息
  821. particle_new.PosX = centroidsPoint.X;
  822. particle_new.PosY = centroidsPoint.Y;
  823. particle_new.RectLeft = stats.At<int>(Key, 0);
  824. particle_new.RectTop = stats.At<int>(Key, 1);
  825. particle_new.RectWidth = stats.At<int>(Key, 2);
  826. particle_new.RectHeight = stats.At<int>(Key, 3);
  827. List<COTSSegmentClr> SegmentClrList1 = new List<COTSSegmentClr>();
  828. List<Segment> SegmentList1 = new List<Segment>();
  829. ReportFun.GetSegment(points, particle_new, SegmentClrList1, ref SegmentList1);
  830. particle_new.SegmentList = SegmentList1;
  831. particle_new.SegmentNum = SegmentList1.Count;
  832. }
  833. }
  834. catch (Exception ex)
  835. {
  836. SetProgressMessage(ex.ToString(), richTextBox_process);
  837. return false;
  838. }
  839. return true;
  840. }
  841. private void bgw_process_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  842. {
  843. stopFlag = false;
  844. tabControl_grid.Enabled = true;
  845. groupBox_param.Enabled = true;
  846. }
  847. private void pictureBox_part_MouseDown(object sender, MouseEventArgs e)
  848. {
  849. if (CB_HAND.Checked && pictureBox_part.Image != null)
  850. {
  851. int originalWidth = this.pictureBox_part.Image.Width;
  852. int originalHeight = this.pictureBox_part.Image.Height;
  853. PropertyInfo rectangleProperty = this.pictureBox_part.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  854. Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(this.pictureBox_part, null);
  855. int currentWidth = rectangle.Width;
  856. int currentHeight = rectangle.Height;
  857. double rate = (double)currentHeight / (double)originalHeight;
  858. int black_left_width = (currentWidth == this.pictureBox_part.Width) ? 0 : (this.pictureBox_part.Width - currentWidth) / 2;
  859. int black_top_height = (currentHeight == this.pictureBox_part.Height) ? 0 : (this.pictureBox_part.Height - currentHeight) / 2;
  860. int zoom_x = e.X - black_left_width;
  861. int zoom_y = e.Y - black_top_height;
  862. double original_x = (double)zoom_x / rate;
  863. double original_y = (double)zoom_y / rate;
  864. //StringBuilder sb = new StringBuilder();
  865. //sb.AppendFormat("原始尺寸{0}/{1}(宽/高)\r\n", originalWidth, originalHeight);
  866. //sb.AppendFormat("缩放状态图片尺寸{0}/{1}(宽/高)\r\n", currentWidth, currentHeight);
  867. //sb.AppendFormat("缩放比率{0}\r\n", rate);
  868. //sb.AppendFormat("左留白宽度{0}\r\n", black_left_width);
  869. //sb.AppendFormat("上留白高度{0}\r\n", black_top_height);
  870. //sb.AppendFormat("当前鼠标坐标{0}/{1}(X/Y)\r\n", e.X, e.Y);
  871. //sb.AppendFormat("缩放图中鼠标坐标{0}/{1}(X/Y)\r\n", zoom_x, zoom_y);
  872. //sb.AppendFormat("原始图中鼠标坐标{0}/{1}(X/Y)\r\n", original_x, original_y);
  873. handPoint = new Point((int)original_x, (int)original_y);
  874. }
  875. }
  876. /// <summary>
  877. ///获取手动处理序号
  878. /// </summary>
  879. /// <param name="labelMat"></param>
  880. /// <param name="width"></param>
  881. /// <param name="height"></param>
  882. /// <param name="key"></param>
  883. private void GetKeyNo(Mat labelMat, int width, int height, ref int key)
  884. {
  885. handPoint = new Point(-1, -1);
  886. Color color = groupBox_img.BackColor;
  887. while (key == 0 && stopFlag == false)
  888. {
  889. groupBox_img.BackColor = Color.Red;
  890. Thread.Sleep(1000);
  891. if (handPoint.X >= 0 && handPoint.X < width && handPoint.Y >= 0 && handPoint.Y < height)
  892. {
  893. key = labelMat.Get<int>((int)handPoint.Y, (int)handPoint.X);
  894. }
  895. }
  896. groupBox_img.BackColor = color;
  897. }
  898. private void dgV_ParticlesDevidePage_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  899. {
  900. if (e.ColumnIndex == 0)
  901. {
  902. foreach (DataGridViewRow dr in dgV_ParticlesDevidePage.Rows)
  903. {
  904. dr.Cells[0].Value = !isCheck;
  905. }
  906. isCheck = !isCheck;
  907. }
  908. }
  909. private void dgV_ParticlesDevidePage_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  910. {
  911. if (e.ColumnIndex == 0 && e.RowIndex != -1)
  912. {
  913. if ((bool)dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)
  914. {
  915. dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = false;
  916. }
  917. else
  918. {
  919. dgV_ParticlesDevidePage.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;
  920. }
  921. }
  922. if (e.RowIndex != -1)
  923. {
  924. 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";
  925. if (File.Exists(imagePath))
  926. {
  927. pictureBox_part.Image = new Bitmap(imagePath);
  928. }
  929. else
  930. {
  931. pictureBox_part.Image = null;
  932. }
  933. showXrayChart(SelectedParticles[e.RowIndex]);//显示Xray图
  934. }
  935. }
  936. private void dataGridView_success_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  937. {
  938. if (e.RowIndex != -1)
  939. {
  940. 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";
  941. if (File.Exists(imagePath))
  942. {
  943. pictureBox_part.Image = new Bitmap(imagePath);
  944. }
  945. else
  946. {
  947. pictureBox_part.Image = null;
  948. }
  949. showXrayChart(successParticles[e.RowIndex]);//显示Xray图
  950. }
  951. }
  952. private void BTN_EXPORT_Click(object sender, EventArgs e)
  953. {
  954. ExportDgvToExcel export = new ExportDgvToExcel();
  955. SetState(false);
  956. string imagePath = ReportFun.resultFile.FilePath + "\\" + m_ReportApp.savePathName;
  957. export.ExportExcel(imagePath, dataGridView_success, "宋体", 11);//默认文件名,DataGridView控件的名称,字体,字号
  958. SetState(true);
  959. MessageBox.Show(table["str37"].ToString(), table["str38"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  960. }
  961. private void SetState(bool isTrue)
  962. {
  963. dataGridView_success.Columns["FieldID"].Visible = isTrue;
  964. dataGridView_success.Columns["particleid"].Visible = isTrue;
  965. dataGridView_success.Columns["SEMPosX"].Visible = isTrue;
  966. dataGridView_success.Columns["SEMPosY"].Visible = isTrue;
  967. }
  968. }
  969. }