MethodCutOffDialog.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. using OpenCvSharp;
  2. using PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Windows.Forms;
  9. namespace PaintDotNet.DedicatedAnalysis.GrainSize.GBT32461
  10. {
  11. internal class MethodCutOffDialog : GrainSizeStandardDialog
  12. {
  13. /// <summary>
  14. /// 测定结果暂存
  15. /// </summary>
  16. private List<DataTable> dataTable1s = new List<DataTable>();
  17. /// <summary>
  18. /// 储存点击保存结果后的所有原图与分析图
  19. /// </summary>
  20. private Dictionary<string, List<Bitmap>> bitCeDingDic = new Dictionary<string, List<Bitmap>>();
  21. #region 组件
  22. private RadioButton radioButton_DarkGray;
  23. private GroupBox groupBox10;
  24. private Button button10;
  25. private Button button7_0;
  26. private GroupBox groupBox11;
  27. private CheckBox checkBox5_0;
  28. private CheckBox checkBox4;
  29. private CheckBox checkBox3_0;
  30. private Button button1;
  31. private Button button4;
  32. private DataGridView dataGridView1;
  33. private GroupBox groupBox5;
  34. private DataGridViewTextBoxColumn Column11;
  35. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
  36. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
  37. private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
  38. private Button button8;
  39. private Button button6_0;
  40. #endregion 组件
  41. /// <summary>
  42. /// 声明构造函数
  43. /// </summary>
  44. /// <param name="appWorkspace"></param>
  45. /// <param name="dialogText"></param>
  46. public MethodCutOffDialog(AppWorkspace appWorkspace) : base(appWorkspace, false, true)
  47. {
  48. }
  49. #region 初始化组件
  50. private void InitializeLanguageText()
  51. {
  52. this.radioButton_DarkGray.Text = PdnResources.GetString("Menu.Darkgray.text");
  53. this.groupBox10.Text = PdnResources.GetString("Menu.sectionoperation.text");
  54. this.button8.Text = PdnResources.GetString("Menu.1.5/2section.text");
  55. this.button6_0.Text = PdnResources.GetString("Menu.0.5section.text");
  56. this.button10.Text = PdnResources.GetString("Menu.Setting.Text");
  57. this.button7_0.Text = PdnResources.GetString("Menu.1section.text");
  58. this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text");
  59. this.checkBox5_0.Text = PdnResources.GetString("Menu.displaysections.text");
  60. this.checkBox4.Text = PdnResources.GetString("Menu.displaygrid.text");
  61. this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text");
  62. this.button1.Text = PdnResources.GetString("Menu.Savemeasurementresults.text");
  63. this.button4.Text = PdnResources.GetString("Menu.Deletemeasurementresult.text");
  64. this.Column11.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text");
  65. this.dataGridViewTextBoxColumn1.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Lengthofdetectionline.text");
  66. this.dataGridViewTextBoxColumn2.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Nnlines.text");
  67. this.dataGridViewTextBoxColumn4.HeaderText = PdnResources.GetString("Menu.Thenumberofsections.text");
  68. this.groupBox5.Text = PdnResources.GetString("Menu.measurementresults.text");
  69. this.Text = "GBT32461(" + PdnResources.GetString("Menu.Interceptmethod.text") + ")";
  70. }
  71. private void InitializeComponent()
  72. {
  73. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  74. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  75. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
  76. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
  77. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
  78. this.radioButton_DarkGray = new System.Windows.Forms.RadioButton();
  79. this.groupBox10 = new System.Windows.Forms.GroupBox();
  80. this.button8 = new System.Windows.Forms.Button();
  81. this.button6_0 = new System.Windows.Forms.Button();
  82. this.button10 = new System.Windows.Forms.Button();
  83. this.button7_0 = new System.Windows.Forms.Button();
  84. this.groupBox11 = new System.Windows.Forms.GroupBox();
  85. this.checkBox5_0 = new System.Windows.Forms.CheckBox();
  86. this.checkBox4 = new System.Windows.Forms.CheckBox();
  87. this.checkBox3_0 = new System.Windows.Forms.CheckBox();
  88. this.button1 = new System.Windows.Forms.Button();
  89. this.button4 = new System.Windows.Forms.Button();
  90. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  91. this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  92. this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  93. this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  94. this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  95. this.groupBox5 = new System.Windows.Forms.GroupBox();
  96. this.groupBox_analysisResult1.SuspendLayout();
  97. this.groupBox10.SuspendLayout();
  98. this.groupBox11.SuspendLayout();
  99. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  100. this.groupBox5.SuspendLayout();
  101. this.SuspendLayout();
  102. //
  103. // groupBox_img
  104. //
  105. this.groupBox_img.Size = new System.Drawing.Size(158, 428);
  106. //
  107. // groupBox_review
  108. //
  109. this.groupBox_review.Size = new System.Drawing.Size(575, 428);
  110. //
  111. // groupBox_report
  112. //
  113. this.groupBox_report.Location = new System.Drawing.Point(974, 506);
  114. //
  115. // groupBox6groupBox_analysisResult2
  116. //
  117. this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 506);
  118. //
  119. // groupBox_analysisResult1
  120. //
  121. this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 506);
  122. //
  123. // radioButton_DarkGray
  124. //
  125. this.radioButton_DarkGray.AutoSize = true;
  126. this.radioButton_DarkGray.Location = new System.Drawing.Point(178, 20);
  127. this.radioButton_DarkGray.Name = "radioButton_DarkGray";
  128. this.radioButton_DarkGray.Size = new System.Drawing.Size(59, 16);
  129. this.radioButton_DarkGray.TabIndex = 38;
  130. this.radioButton_DarkGray.TabStop = true;
  131. this.radioButton_DarkGray.UseVisualStyleBackColor = true;
  132. //
  133. // groupBox10
  134. //
  135. this.groupBox10.Controls.Add(this.button8);
  136. this.groupBox10.Controls.Add(this.button6_0);
  137. this.groupBox10.Controls.Add(this.button10);
  138. this.groupBox10.Controls.Add(this.button7_0);
  139. this.groupBox10.Location = new System.Drawing.Point(179, 555);
  140. this.groupBox10.Name = "groupBox10";
  141. this.groupBox10.Size = new System.Drawing.Size(208, 89);
  142. this.groupBox10.TabIndex = 38;
  143. this.groupBox10.TabStop = false;
  144. //
  145. // button8
  146. //
  147. this.button8.BackColor = System.Drawing.SystemColors.Control;
  148. this.button8.Location = new System.Drawing.Point(107, 50);
  149. this.button8.Name = "button8";
  150. this.button8.Size = new System.Drawing.Size(95, 26);
  151. this.button8.TabIndex = 13;
  152. this.button8.UseVisualStyleBackColor = false;
  153. this.button8.Click += new System.EventHandler(this.button8_Click);
  154. //
  155. // button6_0
  156. //
  157. this.button6_0.BackColor = System.Drawing.SystemColors.Control;
  158. this.button6_0.Location = new System.Drawing.Point(6, 51);
  159. this.button6_0.Name = "button6_0";
  160. this.button6_0.Size = new System.Drawing.Size(95, 26);
  161. this.button6_0.TabIndex = 12;
  162. this.button6_0.UseVisualStyleBackColor = false;
  163. this.button6_0.Click += new System.EventHandler(this.button6_0_Click);
  164. //
  165. // button10
  166. //
  167. this.button10.BackColor = System.Drawing.SystemColors.Control;
  168. this.button10.Location = new System.Drawing.Point(107, 20);
  169. this.button10.Name = "button10";
  170. this.button10.Size = new System.Drawing.Size(95, 26);
  171. this.button10.TabIndex = 11;
  172. this.button10.UseVisualStyleBackColor = false;
  173. this.button10.Click += new System.EventHandler(this.button10_Click);
  174. //
  175. // button7_0
  176. //
  177. this.button7_0.BackColor = System.Drawing.SystemColors.Control;
  178. this.button7_0.Location = new System.Drawing.Point(6, 20);
  179. this.button7_0.Name = "button7_0";
  180. this.button7_0.Size = new System.Drawing.Size(95, 26);
  181. this.button7_0.TabIndex = 8;
  182. this.button7_0.UseVisualStyleBackColor = false;
  183. this.button7_0.Click += new System.EventHandler(this.button7_0_Click);
  184. //
  185. // groupBox11
  186. //
  187. this.groupBox11.Controls.Add(this.checkBox5_0);
  188. this.groupBox11.Controls.Add(this.checkBox4);
  189. this.groupBox11.Controls.Add(this.checkBox3_0);
  190. this.groupBox11.Location = new System.Drawing.Point(393, 555);
  191. this.groupBox11.Name = "groupBox11";
  192. this.groupBox11.Size = new System.Drawing.Size(142, 89);
  193. this.groupBox11.TabIndex = 39;
  194. this.groupBox11.TabStop = false;
  195. //
  196. // checkBox5_0
  197. //
  198. this.checkBox5_0.AutoSize = true;
  199. this.checkBox5_0.Checked = true;
  200. this.checkBox5_0.CheckState = System.Windows.Forms.CheckState.Checked;
  201. this.checkBox5_0.Location = new System.Drawing.Point(15, 59);
  202. this.checkBox5_0.Name = "checkBox5_0";
  203. this.checkBox5_0.Size = new System.Drawing.Size(15, 14);
  204. this.checkBox5_0.TabIndex = 2;
  205. this.checkBox5_0.UseVisualStyleBackColor = true;
  206. this.checkBox5_0.CheckedChanged += new System.EventHandler(this.checkBox5_0_CheckedChanged);
  207. //
  208. // checkBox4
  209. //
  210. this.checkBox4.AutoSize = true;
  211. this.checkBox4.Checked = true;
  212. this.checkBox4.CheckState = System.Windows.Forms.CheckState.Checked;
  213. this.checkBox4.Location = new System.Drawing.Point(15, 37);
  214. this.checkBox4.Name = "checkBox4";
  215. this.checkBox4.Size = new System.Drawing.Size(15, 14);
  216. this.checkBox4.TabIndex = 1;
  217. this.checkBox4.UseVisualStyleBackColor = true;
  218. this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged);
  219. //
  220. // checkBox3_0
  221. //
  222. this.checkBox3_0.AutoSize = true;
  223. this.checkBox3_0.Checked = true;
  224. this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked;
  225. this.checkBox3_0.Location = new System.Drawing.Point(15, 15);
  226. this.checkBox3_0.Name = "checkBox3_0";
  227. this.checkBox3_0.Size = new System.Drawing.Size(15, 14);
  228. this.checkBox3_0.TabIndex = 0;
  229. this.checkBox3_0.UseVisualStyleBackColor = true;
  230. this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged);
  231. //
  232. // button1
  233. //
  234. this.button1.BackColor = System.Drawing.SystemColors.Control;
  235. this.button1.Location = new System.Drawing.Point(139, 11);
  236. this.button1.Name = "button1";
  237. this.button1.Size = new System.Drawing.Size(101, 23);
  238. this.button1.TabIndex = 5;
  239. this.button1.UseVisualStyleBackColor = false;
  240. this.button1.Click += new System.EventHandler(this.button1_Click);
  241. //
  242. // button4
  243. //
  244. this.button4.BackColor = System.Drawing.SystemColors.Control;
  245. this.button4.Location = new System.Drawing.Point(246, 11);
  246. this.button4.Name = "button4";
  247. this.button4.Size = new System.Drawing.Size(101, 23);
  248. this.button4.TabIndex = 4;
  249. this.button4.UseVisualStyleBackColor = false;
  250. this.button4.Click += new System.EventHandler(this.button4_Click);
  251. //
  252. // dataGridView1
  253. //
  254. this.dataGridView1.AllowUserToAddRows = false;
  255. this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
  256. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  257. dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
  258. dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  259. dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
  260. dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  261. dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  262. dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  263. this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
  264. this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  265. this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  266. this.Column11,
  267. this.dataGridViewTextBoxColumn1,
  268. this.dataGridViewTextBoxColumn2,
  269. this.dataGridViewTextBoxColumn4});
  270. this.dataGridView1.Location = new System.Drawing.Point(6, 36);
  271. this.dataGridView1.MultiSelect = false;
  272. this.dataGridView1.Name = "dataGridView1";
  273. this.dataGridView1.ReadOnly = true;
  274. this.dataGridView1.RowHeadersVisible = false;
  275. this.dataGridView1.RowTemplate.Height = 23;
  276. this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
  277. this.dataGridView1.Size = new System.Drawing.Size(341, 103);
  278. this.dataGridView1.TabIndex = 29;
  279. //
  280. // Column11
  281. //
  282. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  283. this.Column11.DefaultCellStyle = dataGridViewCellStyle2;
  284. this.Column11.Name = "Column11";
  285. this.Column11.ReadOnly = true;
  286. this.Column11.Width = 66;
  287. //
  288. // dataGridViewTextBoxColumn1
  289. //
  290. dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  291. this.dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle3;
  292. this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
  293. this.dataGridViewTextBoxColumn1.ReadOnly = true;
  294. //
  295. // dataGridViewTextBoxColumn2
  296. //
  297. dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  298. this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle4;
  299. this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
  300. this.dataGridViewTextBoxColumn2.ReadOnly = true;
  301. //
  302. // dataGridViewTextBoxColumn4
  303. //
  304. dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  305. this.dataGridViewTextBoxColumn4.DefaultCellStyle = dataGridViewCellStyle5;
  306. this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
  307. this.dataGridViewTextBoxColumn4.ReadOnly = true;
  308. this.dataGridViewTextBoxColumn4.Width = 72;
  309. //
  310. // groupBox5
  311. //
  312. this.groupBox5.Controls.Add(this.dataGridView1);
  313. this.groupBox5.Controls.Add(this.button4);
  314. this.groupBox5.Controls.Add(this.button1);
  315. this.groupBox5.Location = new System.Drawing.Point(179, 652);
  316. this.groupBox5.Name = "groupBox5";
  317. this.groupBox5.Size = new System.Drawing.Size(355, 145);
  318. this.groupBox5.TabIndex = 40;
  319. this.groupBox5.TabStop = false;
  320. //
  321. // MethodCutOffDialog
  322. //
  323. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  324. this.ClientSize = new System.Drawing.Size(1127, 1005);
  325. this.Controls.Add(this.groupBox5);
  326. this.Controls.Add(this.groupBox10);
  327. this.Controls.Add(this.groupBox11);
  328. this.Name = "MethodCutOffDialog";
  329. this.Load += new System.EventHandler(this.MethodCutOffDialog_Load);
  330. this.Controls.SetChildIndex(this.groupBox11, 0);
  331. this.Controls.SetChildIndex(this.groupBox10, 0);
  332. this.Controls.SetChildIndex(this.groupBox5, 0);
  333. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  334. this.Controls.SetChildIndex(this.groupBox_img, 0);
  335. this.Controls.SetChildIndex(this.groupBox_review, 0);
  336. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  337. this.Controls.SetChildIndex(this.groupBox_report, 0);
  338. this.groupBox_analysisResult1.ResumeLayout(false);
  339. this.groupBox10.ResumeLayout(false);
  340. this.groupBox11.ResumeLayout(false);
  341. this.groupBox11.PerformLayout();
  342. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  343. this.groupBox5.ResumeLayout(false);
  344. this.ResumeLayout(false);
  345. }
  346. #endregion 初始化组件
  347. #region 需继承方法
  348. protected override void refreshWhileImgChanged()
  349. {
  350. if (this.dataGridView1.Rows.Count > 0)
  351. {
  352. foreach (DataGridViewRow gridViewRow in this.dataGridView1.Rows)
  353. {
  354. foreach (var dataTable in this.dataTable1s)
  355. {
  356. if (dataTable.TableName.Equals(gridViewRow.Tag))
  357. {
  358. this.dataTable1s.Remove(dataTable);
  359. break;
  360. }
  361. }
  362. if (bitCeDingDic.ContainsKey((string)gridViewRow.Tag))
  363. bitCeDingDic.Remove((string)gridViewRow.Tag);
  364. }
  365. this.dataGridView1.Rows.Clear();
  366. }
  367. }
  368. /// <summary>
  369. /// 保存结果
  370. /// </summary>
  371. protected override void buildListBox_analysisResult()
  372. {
  373. if (this.matOrg == null)
  374. {
  375. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  376. return;
  377. }
  378. if (this.dataGridView1.Rows.Count == 0)
  379. {
  380. MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text"));
  381. return;
  382. }
  383. string imgName = getCurrentWorkspace().GetFriendlyName();
  384. string tag = getCurrentWorkTag();
  385. DataTable dataTable = new DataTable();
  386. bool replace = false;
  387. int add = 0;
  388. foreach (ListViewItem item in this.listView2.Items)
  389. {
  390. if (item.Tag.Equals(tag))
  391. {
  392. add++;
  393. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  394. if (dr == DialogResult.OK)
  395. {
  396. replace = true;
  397. }
  398. break;
  399. }
  400. }
  401. if (replace || this.listView2.Items.Count == 0 || add == 0)
  402. {
  403. if (!replace)
  404. {
  405. ListViewItem listViewItem = new ListViewItem();
  406. listViewItem.SubItems[0].Text = imgName;
  407. listViewItem.Tag = "" + tag;
  408. if (this.listView2.Items.Count == 0)
  409. this.listView2.Items.Add(listViewItem);
  410. else
  411. this.listView2.Items.Insert(0, listViewItem);
  412. }
  413. this.dataGridView2.Rows.Clear();
  414. DataGridViewRow dgvr = new DataGridViewRow();
  415. dgvr.Tag = tag;
  416. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  417. {
  418. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  419. }
  420. dgvr.Cells[0].Value = imgName;
  421. DataGridViewRow firRow = this.dataGridView1.Rows[0];
  422. object value1 = firRow.Cells[0].Value;//网格
  423. object value2 = firRow.Cells[1].Value;//网格长度
  424. object value3 = firRow.Cells[2].Value;//网格条数
  425. double value2Total = 0;
  426. foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  427. {
  428. value2Total += (double.Parse(Row.Cells[1].Value.ToString()) * double.Parse(Row.Cells[2].Value.ToString()));//网格总长度
  429. }
  430. double value4Total = 0;
  431. foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  432. {
  433. value4Total += double.Parse(Row.Cells[3].Value.ToString());//交点个数
  434. }
  435. if (value4Total == 0)
  436. {
  437. MessageBox.Show(PdnResources.GetString("Menu.Nomeasurementresult.text"));
  438. return;
  439. }
  440. //double value4Per = value4Total / this.dataGridView1.Rows.Count;
  441. dgvr.Cells[1].Value = value1;
  442. dgvr.Cells[2].Value = value2Total;
  443. dgvr.Cells[3].Value = value4Total;
  444. //dgvr.Cells[4].Value = value4Per;//级别
  445. decimal M = 1;// this.getGainMultiple();
  446. double small_l = value2Total / (value4Total * (double)M);
  447. //毫米转微米
  448. decimal A = Convert.ToDecimal(small_l * 1000);
  449. //dgvr.Cells[4].Value = small_l;// Math.Round(A, Convert.ToInt32(this.numericUpDown1_0.Value));
  450. double[] lengths = {453, 320 , 269, 226, 190, 177, 160, 135, 113, 106,
  451. 95.0, 89.0, 80.0, 67.3, 62.0, 56.6, 53.2, 47.6, 44.3, 40.0, 35.4, 33.6, 31.0,
  452. 28.3, 26.6 , 23.8, 22.2, 20.0, 17.7, 16.8, 14.1, 13.3, 11.9,
  453. 10.0, 8.86, 8.41, 7.98, 7.07, 6.20, 5.95, 5.32, 5.00, 4.43, 4.20, 3.54, 2.97
  454. , 2.66, 2.50, 2.22};
  455. //double[] areas = {2.06, 1.46 , 1.03, 0.730, 0.516, 0.365, 0.258, 0.182, 0.129, 0.0912,
  456. // 0.0645, 0.0456, 0.0323, 0.0228, 0.0161, 0.0114, 0.00807, 0.00570, 0.00403, 0.00285, 0.00202, 0.00143, 0.00101};
  457. // 差值
  458. decimal differenceNew = 0;
  459. decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 1.22, (double)A - 454)));
  460. double selectArea = 0;
  461. int first = -1;
  462. foreach (double item in lengths)
  463. {
  464. selectArea = item;
  465. differenceNew = Math.Abs(A - Convert.ToDecimal(item));
  466. if (differenceNew < differenceOld)
  467. {
  468. differenceOld = Math.Abs(A - Convert.ToDecimal(item));
  469. first++;
  470. }
  471. else
  472. break;
  473. }
  474. string[] valueG = {"00A", "0" , "0.5", "1.0", "1.5", "1.5"/**/, "2.0", "2.5", "3.0", "3.0",
  475. "3.5", "3.5", "4.0", "4.5", "4.5", "5.0", "5.0", "5.5", "5.5", "6.0", "6.0", "6.5", "6.5",
  476. "7.0", "7.0" , "7.5", "7.5", "8.0", "8.0", "8.5", "9.0", "9.0", "9.5",
  477. "10.0", "10.0", "10.5", "10.5", "11.0", "11.0", "11.5", "11.5", "12.0", "12.0", "12.5", "13.0", "13.5"
  478. , "13.5", "14.0", "14.0"};
  479. if (first >= valueG.Length)
  480. {
  481. first = valueG.Length - 1;
  482. }
  483. else if (first < 0)
  484. {
  485. first = 0;
  486. }
  487. dgvr.Cells[4].Value = valueG[first];
  488. this.dataGridView2.Rows.Add(dgvr);
  489. dataTable.TableName = tag;
  490. foreach (System.Data.DataTable dataTable1 in dataTables)
  491. {
  492. if (dataTable1.TableName.Equals(dataTable.TableName))
  493. {
  494. dataTables.Remove(dataTable1);
  495. break;
  496. }
  497. }
  498. for (int i = 0; i < this.dataGridView2.Columns.Count; i++)
  499. {
  500. dataTable.Columns.Add("" + i);
  501. }
  502. DataRow dataRow = dataTable.NewRow();
  503. dataRow["0"] = imgName;
  504. dataRow["1"] = dgvr.Cells[1].Value;// "网格1";
  505. dataRow["2"] = dgvr.Cells[2].Value;
  506. dataRow["3"] = dgvr.Cells[3].Value;
  507. dataRow["4"] = dgvr.Cells[4].Value;
  508. //dataRow["5"] = dgvr.Cells[5].Value;
  509. //dataRow["6"] = dgvr.Cells[6].Value;
  510. dataTable.Rows.Add(dataRow);
  511. this.dataTables.Add(dataTable);
  512. if (this.allShow)
  513. AllShow();
  514. this.RefreshDataGridView4();
  515. //保存处理后的图片
  516. List<Bitmap> tempBit = new List<Bitmap>();
  517. //Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  518. //tempBit.Add(originalBit);
  519. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  520. //Graphics graphics = Graphics.FromImage(newBit);
  521. //Draw(graphics);
  522. //tempBit.Add(newBit);
  523. foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitCeDingDic)
  524. {
  525. tempBit.Add(kv.Value[0]);
  526. tempBit.Add(kv.Value[1]);
  527. }
  528. if (bitDic.ContainsKey(tag))
  529. bitDic[tag] = tempBit;
  530. else
  531. bitDic.Add(tag, tempBit);
  532. //中间数据-拼接中间数据
  533. List<List<string>> dataList = new List<List<string>>();
  534. List<string> columnName = new List<string>();
  535. columnName.Add(PdnResources.GetString("Menu.Tools.GridLine.Text"));
  536. columnName.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Lengthofdetectionline.text"));
  537. columnName.Add(PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Nnlines.text"));
  538. columnName.Add(PdnResources.GetString("Menu.Thenumberofsections.text"));
  539. dataList.Add(columnName);
  540. foreach (DataGridViewRow Row in this.dataGridView1.Rows)
  541. {
  542. List<string> strList = new List<string>();
  543. strList.Add(Row.Cells[0].Value.ToString());
  544. strList.Add(Row.Cells[1].Value.ToString());
  545. strList.Add(Row.Cells[2].Value.ToString());
  546. strList.Add(Row.Cells[3].Value.ToString());
  547. dataList.Add(strList);
  548. }
  549. bool isExist = false;//是否已存在进行替换
  550. int modelIndex = -1;//要替换的下标
  551. for (int j = 0; j < tempDataModel.Count; j++)
  552. {
  553. if (tempDataModel[j].tagName.Equals(tag))
  554. {
  555. isExist = true;
  556. modelIndex = j;
  557. break;
  558. }
  559. }
  560. if (isExist && modelIndex > -1)
  561. tempDataModel[modelIndex].dataList = dataList;
  562. else
  563. {
  564. Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel();
  565. newModel.tagName = tag;
  566. newModel.picName = imgName;
  567. newModel.dataList = dataList;
  568. tempDataModel.Add(newModel);
  569. }
  570. }
  571. }
  572. //是否绘制辅助线
  573. protected override bool drawGuideLines()
  574. {
  575. return checkBox4.Checked;
  576. }
  577. //是否绘制截点
  578. protected override bool drawGuidePoints()
  579. {
  580. return (matOrg != null && this.checkBox5_0.Checked);
  581. }
  582. //辅助线类型
  583. protected override string[] getTypeNames()
  584. {
  585. return new string[] {
  586. PdnResources.GetString("Menu.Verticalauxiliaryline.text"),
  587. PdnResources.GetString("Menu.Horizontalauxiliaryline.text")};
  588. }
  589. protected override string getModelName()
  590. {
  591. return "GrainGBT32461CutOffMethodModel.xml";
  592. }
  593. protected override string getTemplateName()
  594. {
  595. return "Template.Manager.item3.GrainSizeCutOff_GBT32461";
  596. }
  597. protected override string getProjectEngineeringName()
  598. {
  599. return "Menu.DedicatedAnalysis.NonferrousMetal.AluminiumAlloy.Text";
  600. }
  601. protected override void SubclassInitialize()
  602. {
  603. InitializeComponent();
  604. InitializeLanguageText();
  605. }
  606. #endregion
  607. private void MethodCutOffDialog_Load(object sender, EventArgs e)
  608. {
  609. this.groupBox_img.Size = new System.Drawing.Size(158, 722);
  610. this.groupBox_review.Size = new System.Drawing.Size(575, 722);
  611. this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 800);
  612. this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 800);
  613. this.groupBox_report.Location = new System.Drawing.Point(974, 800);
  614. }
  615. /// <summary>
  616. /// 是否显示网格
  617. /// </summary>
  618. /// <param name="sender"></param>
  619. /// <param name="e"></param>
  620. private void checkBox4_CheckedChanged(object sender, EventArgs e)
  621. {
  622. this.documentWorkspace.Refresh();
  623. }
  624. /// <summary>
  625. /// 是否显示截点
  626. /// </summary>
  627. /// <param name="sender"></param>
  628. /// <param name="e"></param>
  629. private void checkBox5_0_CheckedChanged(object sender, EventArgs e)
  630. {
  631. if (!this.checkBox4.Checked)
  632. MessageBox.Show(PdnResources.GetString("Menu.Nogrid.text")+"!");
  633. this.documentWorkspace.Refresh();
  634. }
  635. /// <summary>
  636. /// 是否显示晶界
  637. /// </summary>
  638. /// <param name="sender"></param>
  639. /// <param name="e"></param>
  640. private void checkBox3_0_CheckedChanged(object sender, EventArgs e)
  641. {
  642. if (!showOrimat() && getGrainBoundryChecked() && checkBox3_0.Checked)
  643. {
  644. this.documentWorkspace.PhaseModels[1].choise = true;
  645. }
  646. else
  647. {
  648. this.documentWorkspace.PhaseModels[1].choise = false;
  649. }
  650. this.documentWorkspace.Refresh();
  651. }
  652. /// <summary>
  653. /// 设置截点样式
  654. /// </summary>
  655. /// <param name="sender"></param>
  656. /// <param name="e"></param>
  657. private void button10_Click(object sender, EventArgs e)
  658. {//###
  659. GrainSizeStandard.IntegrationClass.GrainSurveyPointStyleSettingDialog grainSurveyPointStyleSettingDialog = new GrainSizeStandard.IntegrationClass.GrainSurveyPointStyleSettingDialog();//###
  660. grainSurveyPointStyleSettingDialog.StartPosition = FormStartPosition.CenterScreen;
  661. grainSurveyPointStyleSettingDialog.ShowDialog(this);
  662. }
  663. /// <summary>
  664. /// 鼠标按下
  665. /// </summary>
  666. /// <param name="drawArea"></param>
  667. /// <param name="e"></param>
  668. protected override void OnMouseDown(object sender, MouseEventArgs e)
  669. {
  670. if (this.documentWorkspace.CompositionSurface == null)
  671. return;
  672. // 换算后的点
  673. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  674. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  675. && point1.X >= 0
  676. && point1.Y >= 0
  677. && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  678. {
  679. RectangleF rectangleF;
  680. // 复合辅助线
  681. int add = guideClass.getAddOfRStyle(point1, this.comboBox1.SelectedItem, out rectangleF);
  682. if (add == 0 && styleClass.PointKb > 0)
  683. rectangleF = guideClass.RectangleFLine;
  684. //手动添加截点
  685. styleClass.OnMouseDownFirst(point1, rectangleF, this.linePointList, sender, e);
  686. }
  687. if (styleClass.PointKb == 0)
  688. {
  689. //辅助线缩放
  690. guideClass.OnMouseDown(point1, sender, e);
  691. //辅助线移动
  692. base.OnMouseDown(sender, e);//##
  693. }
  694. //手动删除截点或取消添加截点
  695. styleClass.OnMouseDownNext(point1, sender, e);
  696. }
  697. private int dataTable1sTagInc = 0;
  698. /// <summary>
  699. /// 保存测定结果
  700. /// </summary>
  701. /// <param name="sender"></param>
  702. /// <param name="e"></param>
  703. private void button1_Click(object sender, EventArgs e)
  704. {
  705. if (this.matOrg == null)
  706. {
  707. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  708. return;
  709. }
  710. DataTable dataTable = new DataTable();
  711. //this.dataGridView111114.Rows.Clear();
  712. DataGridViewRow dgvr = new DataGridViewRow();
  713. dataTable1sTagInc++;
  714. dgvr.Tag = dataTable1sTagInc + "";
  715. foreach (DataGridViewColumn c in this.dataGridView1.Columns)
  716. {
  717. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  718. }
  719. dgvr.Cells[0].Value = this.comboBox1.SelectedItem;
  720. dgvr.Cells[1].Value = guideClass.LineLength;
  721. dgvr.Cells[2].Value = guideClass.LineDec;
  722. double countPoints = styleClass.getCountPoints();
  723. dgvr.Cells[3].Value = countPoints;
  724. this.dataGridView1.Rows.Add(dgvr);
  725. dataTable.TableName = (string)dgvr.Tag;
  726. for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
  727. {
  728. dataTable.Columns.Add("" + i);
  729. }
  730. DataRow dataRow = dataTable.NewRow();
  731. dataRow["0"] = dgvr.Cells[0].Value;
  732. dataRow["1"] = dgvr.Cells[1].Value;
  733. dataRow["2"] = dgvr.Cells[2].Value;
  734. dataRow["3"] = countPoints;// Convert.ToDecimal(this.p1RectangleFs.Count) + Convert.ToDecimal(this.p2RectangleFs.Count) / 2;
  735. dataTable.Rows.Add(dataRow);
  736. this.dataTable1s.Add(dataTable);
  737. //保存处理后的图片
  738. List<Bitmap> tempBit = new List<Bitmap>();
  739. Bitmap originalBit = this.bitmap;// this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  740. tempBit.Add(originalBit);
  741. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  742. Graphics graphics = Graphics.FromImage(newBit);
  743. if (this.documentWorkspace.PhaseModels[0].choise && this.documentWorkspace.PhaseModels[0].mat != null)
  744. {
  745. Mat targetMat = this.documentWorkspace.PhaseModels[0].mat;
  746. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  747. }
  748. if (this.documentWorkspace.PhaseModels[1].choise && this.documentWorkspace.PhaseModels[1].mat != null)
  749. {
  750. Mat targetMat = this.documentWorkspace.PhaseModels[1].mat;
  751. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  752. }
  753. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  754. drawSubclass/*Draw*/(graphics);
  755. tempBit.Add(newBit);
  756. if (bitCeDingDic.ContainsKey((string)dgvr.Tag))
  757. bitCeDingDic[(string)dgvr.Tag] = tempBit;
  758. else
  759. bitCeDingDic.Add((string)dgvr.Tag, tempBit);
  760. }
  761. /// <summary>
  762. /// 删除测定结果
  763. /// </summary>
  764. /// <param name="sender"></param>
  765. /// <param name="e"></param>
  766. private void button4_Click(object sender, EventArgs e)
  767. {
  768. if (this.dataGridView1.Rows.Count > 0)
  769. {
  770. if (this.dataGridView1.SelectedRows.Count > 0)
  771. {
  772. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  773. if (dr == DialogResult.OK)
  774. {
  775. DataGridViewRow gridViewRow = this.dataGridView1.SelectedRows[0];
  776. int selectIndex = gridViewRow.Index;
  777. foreach (var dataTable in this.dataTable1s)
  778. {
  779. if (dataTable.TableName.Equals(gridViewRow.Tag))
  780. {
  781. this.dataTable1s.Remove(dataTable);
  782. break;
  783. }
  784. }
  785. if (bitCeDingDic.ContainsKey((string)gridViewRow.Tag))
  786. bitCeDingDic.Remove((string)gridViewRow.Tag);
  787. this.dataGridView1.Rows.RemoveAt(selectIndex);
  788. //RefreshDataGridView1();
  789. }
  790. }
  791. else
  792. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthedatatobedeleted.text")+"!");
  793. }
  794. else
  795. MessageBox.Show(PdnResources.GetString("Menu.nodata.text")+"!");
  796. }
  797. private void AllShow()
  798. {
  799. this.dataGridView2.Rows.Clear();
  800. for (int i = 0; i < this.dataTables.Count; i++)
  801. {
  802. DataGridViewRow dgvr = new DataGridViewRow();
  803. dgvr.Tag = this.dataTables[i].TableName;
  804. foreach (DataGridViewColumn Column in this.dataGridView2.Columns)
  805. {
  806. dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
  807. }
  808. for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
  809. {
  810. //if (c > 2 && c < 4)
  811. // dgvr.Cells[c].Value = Math.Round((double)Convert.ToDecimal(this.dataTables[i].Rows[0][c]), Convert.ToInt32(this.numericUpDown1_0.Value)).ToString();
  812. //else
  813. dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
  814. }
  815. this.dataGridView2.Rows.Add(dgvr);
  816. }
  817. }
  818. /// <summary>
  819. /// 0.5截点添加
  820. /// </summary>
  821. /// <param name="sender"></param>
  822. /// <param name="e"></param>
  823. private void button6_0_Click(object sender, EventArgs e)
  824. {
  825. if (this.matOrg != null)
  826. styleClass.PointKb = 1;
  827. else
  828. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  829. }
  830. /// <summary>
  831. /// 1截点添加
  832. /// </summary>
  833. /// <param name="sender"></param>
  834. /// <param name="e"></param>
  835. private void button7_0_Click(object sender, EventArgs e)
  836. {
  837. if (this.matOrg != null)
  838. styleClass.PointKb = 2;
  839. else
  840. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  841. }
  842. /// <summary>
  843. /// 1.5截点添加
  844. /// </summary>
  845. /// <param name="sender"></param>
  846. /// <param name="e"></param>
  847. private void button8_Click(object sender, EventArgs e)
  848. {
  849. if (this.matOrg != null)
  850. styleClass.PointKb = 3;
  851. else
  852. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  853. }
  854. }
  855. }