frmReMeasure.cs 49 KB

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