MethodCutOffDialog.cs 39 KB

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