MethodAreaDialog.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. using OpenCvSharp;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.Base.SettingModel;
  4. using PaintDotNet.DedicatedAnalysis.GrainSizeStandard.IntegrationClass;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Drawing.Drawing2D;
  11. using System.Windows.Forms;
  12. namespace PaintDotNet.DedicatedAnalysis.GrainSizeStandard.GBT32461
  13. {
  14. internal class MethodAreaDialog : GrainSizeStandardDialog
  15. {
  16. #region 组件
  17. private GroupBox groupBox11;
  18. private Button button4;
  19. private Button button2;
  20. private CheckBox checkBox11;
  21. private CheckBox checkBox5_0;
  22. private CheckBox checkBox4_0;
  23. private CheckBox checkBox3_0;
  24. private DataGridViewTextBoxColumn ColumnTotal1;
  25. private DataGridViewTextBoxColumn ColumnTotal2;
  26. private GroupBox groupBox7;
  27. private Button button10;
  28. private Button button3;
  29. private Button button8;
  30. private RadioButton radioButton5;
  31. private RadioButton radioButton4;
  32. private RadioButton radioButton3;
  33. private DataGridViewTextBoxColumn ColumnTotal3;
  34. #endregion 组件
  35. #region 构造函数
  36. public MethodAreaDialog(AppWorkspace appWorkspace, PdnMenuItem menuItem) : base(appWorkspace, menuItem, new Base.DedicatedAnalysis.GrainSize.Standard.GBT32461.MethodArea())
  37. {
  38. }
  39. #endregion 构造函数
  40. #region 初始化组件
  41. private void InitializeLanguageText()
  42. {
  43. this.groupBox11.Text = PdnResources.GetString("Menu.Displayparamssettings.text");
  44. this.button4.Text = PdnResources.GetString("Menu.Refresh.text");
  45. this.button2.Text = PdnResources.GetString("Menu.Setting.Text");
  46. this.checkBox11.Text = PdnResources.GetString("Menu.Thegrainsareshownindifferentcolors.text");
  47. this.checkBox5_0.Text = PdnResources.GetString("Menu.Displaygrainnumber.text");
  48. this.checkBox4_0.Text = PdnResources.GetString("Menu.displaygrid.text");
  49. this.checkBox3_0.Text = PdnResources.GetString("Menu.displaygrainboundaries.text");
  50. this.Text = "GBT32461(" + PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Averagegraimethod.text") + ")";
  51. this.Load += new System.EventHandler(this.MethodAreaDialog_Load);
  52. }
  53. private DataGridViewTextBoxColumn Column1;
  54. private DataGridViewTextBoxColumn Column2;
  55. private DataGridViewTextBoxColumn Column3;
  56. private DataGridViewTextBoxColumn Column4;
  57. private DataGridViewTextBoxColumn Column5;
  58. private void MethodAreaDialog_Load(object sender, EventArgs e)
  59. {
  60. //this.button_ApplyToAll.Visible = false;
  61. //this.button_SaveAll.Visible = false;
  62. //this.btn_Grainboundarytoreproduce.Location = new System.Drawing.Point(912, 20);
  63. //this.btn_saveresult.Location = new System.Drawing.Point(993, 20);
  64. object ShowGrainBoundry;
  65. if (GetParamValue1(ParamKey_displaygrainboundaries, out ShowGrainBoundry))//显示晶界
  66. this.checkBox3_0.Checked = (bool)ShowGrainBoundry;
  67. if (GetParamValue1(ParamKey_displaygrid, out ShowGrainBoundry))//显示网格
  68. this.checkBox4_0.Checked = (bool)ShowGrainBoundry;
  69. if (GetParamValue1(ParamKey_ShowGrainNumber, out ShowGrainBoundry))//显示晶粒编号
  70. this.checkBox5_0.Checked = (bool)ShowGrainBoundry;
  71. if (GetParamValue1(ParamKey_ShowGrainColor, out ShowGrainBoundry))//用不同颜色显示晶粒
  72. this.checkBox11.Checked = (bool)ShowGrainBoundry;
  73. this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  74. this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  75. this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  76. this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  77. this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  78. this.Column1.Name = "Column1";
  79. this.Column1.ReadOnly = true;
  80. //
  81. // Column2
  82. //
  83. this.Column2.Name = "Column2";
  84. this.Column2.ReadOnly = true;
  85. //
  86. // Column3
  87. //
  88. this.Column3.Name = "Column3";
  89. this.Column3.ReadOnly = true;
  90. //
  91. // Column4
  92. //
  93. this.Column4.Name = "Column4";
  94. this.Column4.ReadOnly = true;
  95. //
  96. // Column5
  97. //
  98. this.Column5.Name = "Column5";
  99. this.Column5.ReadOnly = true;
  100. this.Column5.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
  101. this.Column4.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text");
  102. this.Column3.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Gridsize.text") + "(μm)";
  103. this.Column2.HeaderText = PdnResources.GetString("Menu.Tools.GridLine.Text");
  104. this.Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  105. this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  106. this.Column1,
  107. this.Column2,
  108. this.Column3,
  109. this.Column4,
  110. this.Column5});
  111. this.ColumnTotal1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  112. this.ColumnTotal2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  113. this.ColumnTotal3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  114. this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  115. this.ColumnTotal1,
  116. this.ColumnTotal2,
  117. this.ColumnTotal3});
  118. //
  119. // ColumnTotal1
  120. //
  121. this.ColumnTotal1.HeaderText = PdnResources.GetString("Menu.Dedicatedanalysis.Nmetals.Gridsize.text") + "(μm)";
  122. this.ColumnTotal1.Name = "ColumnTotal1";
  123. this.ColumnTotal1.ReadOnly = true;
  124. //
  125. // ColumnTotal2
  126. //
  127. this.ColumnTotal2.HeaderText = PdnResources.GetString("Menu.Numberofgrains.text");
  128. this.ColumnTotal2.Name = "ColumnTotal2";
  129. this.ColumnTotal2.ReadOnly = true;
  130. //
  131. // ColumnTotal3
  132. //
  133. this.ColumnTotal3.HeaderText = PdnResources.GetString("Menu.Averagegrainsizegrade.text");
  134. this.ColumnTotal3.Name = "ColumnTotal3";
  135. this.ColumnTotal3.ReadOnly = true;
  136. DetailListStringIndex.Add(0);
  137. DetailListStringIndex.Add(1);
  138. DetailListStringIndex.Add(3);
  139. DetailListStringIndex.Add(4/*5*/);//##############
  140. DetailListNotDoubleIndex.Add(0);
  141. DetailListNotDoubleIndex.Add(1);
  142. DetailListNotDoubleIndex.Add(3);
  143. DetailListNotDoubleIndex.Add(4);
  144. IndexChangedFromIndex.Clear();
  145. IndexChangedToIndex.Clear();
  146. IndexChangedFromIndex.Add(2);
  147. IndexChangedFromIndex.Add(3);
  148. IndexChangedToIndex.Add(0, new int[] { 2/*1*/, 0 });//求和
  149. IndexChangedToIndex.Add(1, new int[] { 2/*1*/, 1 });//求和
  150. //IndexChangedToIndex.Add(2, new int[] { 2, 2 });//平均
  151. IndexChangedToIndex.Add(2, new int[] { 3, -1/*0*/ });//级别
  152. this.button3.FlatStyle = FlatStyle.Flat;
  153. this.button3.FlatAppearance.BorderSize = 0;
  154. this.button3.BackgroundImageLayout = ImageLayout.Zoom;
  155. this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference;
  156. this.button3.Click += new EventHandler(this.button3_click);
  157. this.button10.FlatStyle = FlatStyle.Flat;
  158. this.button10.FlatAppearance.BorderSize = 0;
  159. this.button10.BackgroundImageLayout = ImageLayout.Zoom;
  160. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
  161. this.button10.Click += new EventHandler(this.button10_click);
  162. this.button8.FlatStyle = FlatStyle.Flat;
  163. this.button8.FlatAppearance.BorderSize = 0;
  164. this.button8.BackgroundImageLayout = ImageLayout.Zoom;
  165. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
  166. this.button8.Click += new EventHandler(this.button8_click);
  167. getSonData();
  168. }
  169. /// <summary>
  170. /// 获取参数
  171. /// </summary>
  172. protected override void getSonData()
  173. {
  174. object ShowGrainBoundry;
  175. if (GetParamValue1(ParamKey_TargetSelection, out ShowGrainBoundry))//目标选择
  176. {
  177. int value = Convert.ToInt32(ShowGrainBoundry);
  178. switch (value)
  179. {
  180. case 1:
  181. this.button8_click(null, null);
  182. break;
  183. case 2:
  184. this.button3_click(null, null);
  185. break;
  186. case 3:
  187. this.button10_click(null, null);
  188. break;
  189. }
  190. }
  191. }
  192. private void button3_click(object sender, EventArgs e)
  193. {
  194. this.TargetSelection = 2;
  195. this.radioButton4.Checked = true;
  196. this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference;
  197. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
  198. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
  199. }
  200. private void button10_click(object sender, EventArgs e)
  201. {
  202. this.TargetSelection = 3;
  203. this.radioButton5.Checked = true;
  204. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle3.png").Reference;
  205. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference;
  206. this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference;
  207. }
  208. private void button8_click(object sender, EventArgs e)
  209. {
  210. this.TargetSelection = 1;
  211. this.radioButton3.Checked = true;
  212. this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle1.png").Reference;
  213. this.button3.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference;
  214. this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference;
  215. }
  216. /// <summary>
  217. /// 计算汇总列表的平均晶粒度级别
  218. /// </summary>
  219. /// <returns></returns>
  220. protected override string getGradeTotalCal(DataGridViewRow dgvr, int digits)
  221. {
  222. double aec = double.Parse(dgvr.Cells[0].Value.ToString());
  223. double grainNumber = double.Parse(dgvr.Cells[1].Value.ToString());
  224. aec = aec * 0.001 * 0.001;
  225. decimal M = 1;// this.getGainMultiple();
  226. double small_l = (grainNumber * (double)M * (double)M) / aec;
  227. decimal A = Convert.ToDecimal(small_l * 1);
  228. double[] lengths = {3.88, 7.75 , 11.0, 15.50, 21.9, 25.0, 31.0, 43.8, 62.0, 69.4,
  229. 87.7, 100, 124, 175, 204, 248, 278, 351, 400, 496, 625, 701, 816,
  230. 992, 1111 , 1403, 1600, 1980, 2500, 2810, 3970, 4440, 5610,
  231. 7940, 10000, 11220, 12350, 15870, 20410, 22450, 27780, 31710, 40000, 44900, 63500, 89800
  232. , 111100, 127000, 160000};
  233. // 差值
  234. decimal differenceNew;
  235. decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 2.22, (double)A - 160001)));
  236. int first = 0;
  237. if ((double)A > lengths[lengths.Length - 1])
  238. first = lengths.Length - 1;
  239. else
  240. for (int firstI = 0; firstI < lengths.Length; firstI++)
  241. {
  242. double item = lengths[firstI];
  243. differenceNew = Math.Abs(A - Convert.ToDecimal(item));
  244. if (differenceNew < differenceOld)
  245. {
  246. differenceOld = Math.Abs(A - Convert.ToDecimal(item));
  247. first = firstI;
  248. }
  249. }
  250. string[] valueG = {"00A", "0" , "0.5", "1.0", "1.5", "1.5", "2.0", "2.5", "3.0", "3.0",
  251. "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",
  252. "7.0", "7.0" , "7.5", "7.5", "8.0", "8.0", "8.5", "9.0", "9.0", "9.5",
  253. "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"
  254. , "13.5", "14.0", "14.0"};
  255. return valueG[first];
  256. }
  257. private void InitializeComponent()
  258. {
  259. this.groupBox11 = new System.Windows.Forms.GroupBox();
  260. this.button2 = new System.Windows.Forms.Button();
  261. this.button4 = new System.Windows.Forms.Button();
  262. this.checkBox11 = new System.Windows.Forms.CheckBox();
  263. this.checkBox5_0 = new System.Windows.Forms.CheckBox();
  264. this.checkBox4_0 = new System.Windows.Forms.CheckBox();
  265. this.checkBox3_0 = new System.Windows.Forms.CheckBox();
  266. this.groupBox7 = new System.Windows.Forms.GroupBox();
  267. this.button10 = new System.Windows.Forms.Button();
  268. this.button3 = new System.Windows.Forms.Button();
  269. this.button8 = new System.Windows.Forms.Button();
  270. this.radioButton5 = new System.Windows.Forms.RadioButton();
  271. this.radioButton4 = new System.Windows.Forms.RadioButton();
  272. this.radioButton3 = new System.Windows.Forms.RadioButton();
  273. this.groupBox_img.SuspendLayout();
  274. this.groupBox_analysisResult1.SuspendLayout();
  275. this.groupBox3.SuspendLayout();
  276. this.groupBox11.SuspendLayout();
  277. this.groupBox7.SuspendLayout();
  278. this.SuspendLayout();
  279. //
  280. // groupBox11
  281. //
  282. this.groupBox11.Controls.Add(this.button2);
  283. this.groupBox11.Controls.Add(this.button4);
  284. this.groupBox11.Controls.Add(this.checkBox11);
  285. this.groupBox11.Controls.Add(this.checkBox5_0);
  286. this.groupBox11.Controls.Add(this.checkBox4_0);
  287. this.groupBox11.Controls.Add(this.checkBox3_0);
  288. this.groupBox11.Location = new System.Drawing.Point(179, 373);
  289. this.groupBox11.Name = "groupBox11";
  290. this.groupBox11.Size = new System.Drawing.Size(356, 71);
  291. this.groupBox11.TabIndex = 38;
  292. this.groupBox11.TabStop = false;
  293. //
  294. // button2
  295. //
  296. this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right;
  297. this.button2.Location = new System.Drawing.Point(271, 41);
  298. this.button2.Name = "button2";
  299. this.button2.Size = new System.Drawing.Size(75, 22);
  300. this.button2.TabIndex = 19;
  301. this.button2.UseVisualStyleBackColor = true;
  302. this.button2.Click += new System.EventHandler(this.button2_Click);
  303. //
  304. // button4
  305. //
  306. this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
  307. this.button4.Location = new System.Drawing.Point(271, 17);
  308. this.button4.Name = "button4";
  309. this.button4.Size = new System.Drawing.Size(75, 22);
  310. this.button4.TabIndex = 18;
  311. this.button4.UseVisualStyleBackColor = true;
  312. this.button4.Click += new System.EventHandler(this.button4_Click);
  313. //
  314. // checkBox11
  315. //
  316. this.checkBox11.AutoSize = true;
  317. this.checkBox11.Checked = true;
  318. this.checkBox11.CheckState = System.Windows.Forms.CheckState.Checked;
  319. this.checkBox11.Location = new System.Drawing.Point(139, 44);
  320. this.checkBox11.Name = "checkBox11";
  321. this.checkBox11.Size = new System.Drawing.Size(15, 14);
  322. this.checkBox11.TabIndex = 3;
  323. this.checkBox11.UseVisualStyleBackColor = true;
  324. this.checkBox11.CheckedChanged += new System.EventHandler(this.checkBox11_CheckedChanged);
  325. //
  326. // checkBox5_0
  327. //
  328. this.checkBox5_0.AutoSize = true;
  329. this.checkBox5_0.Checked = true;
  330. this.checkBox5_0.CheckState = System.Windows.Forms.CheckState.Checked;
  331. this.checkBox5_0.Location = new System.Drawing.Point(140, 22);
  332. this.checkBox5_0.Name = "checkBox5_0";
  333. this.checkBox5_0.Size = new System.Drawing.Size(15, 14);
  334. this.checkBox5_0.TabIndex = 2;
  335. this.checkBox5_0.UseVisualStyleBackColor = true;
  336. this.checkBox5_0.CheckedChanged += new System.EventHandler(this.checkBox5_0_CheckedChanged);
  337. //
  338. // checkBox4_0
  339. //
  340. this.checkBox4_0.AutoSize = true;
  341. this.checkBox4_0.Checked = true;
  342. this.checkBox4_0.CheckState = System.Windows.Forms.CheckState.Checked;
  343. this.checkBox4_0.Location = new System.Drawing.Point(15, 44);
  344. this.checkBox4_0.Name = "checkBox4_0";
  345. this.checkBox4_0.Size = new System.Drawing.Size(15, 14);
  346. this.checkBox4_0.TabIndex = 1;
  347. this.checkBox4_0.UseVisualStyleBackColor = true;
  348. this.checkBox4_0.CheckedChanged += new System.EventHandler(this.checkBox4_0_CheckedChanged);
  349. //
  350. // checkBox3_0
  351. //
  352. this.checkBox3_0.AutoSize = true;
  353. this.checkBox3_0.Checked = true;
  354. this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked;
  355. this.checkBox3_0.Location = new System.Drawing.Point(15, 22);
  356. this.checkBox3_0.Name = "checkBox3_0";
  357. this.checkBox3_0.Size = new System.Drawing.Size(15, 14);
  358. this.checkBox3_0.TabIndex = 0;
  359. this.checkBox3_0.UseVisualStyleBackColor = true;
  360. this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged);
  361. //
  362. // groupBox7
  363. //
  364. this.groupBox7.Controls.Add(this.button10);
  365. this.groupBox7.Controls.Add(this.button3);
  366. this.groupBox7.Controls.Add(this.button8);
  367. this.groupBox7.Controls.Add(this.radioButton5);
  368. this.groupBox7.Controls.Add(this.radioButton4);
  369. this.groupBox7.Controls.Add(this.radioButton3);
  370. this.groupBox7.Location = new System.Drawing.Point(179, 450);
  371. this.groupBox7.Name = "groupBox7";
  372. this.groupBox7.Size = new System.Drawing.Size(356, 77);
  373. this.groupBox7.TabIndex = 41;
  374. this.groupBox7.TabStop = false;
  375. this.groupBox7.Text = "目标选择";
  376. //
  377. // button10
  378. //
  379. this.button10.Location = new System.Drawing.Point(60, 21);
  380. this.button10.Name = "button10";
  381. this.button10.Size = new System.Drawing.Size(40, 40);
  382. this.button10.TabIndex = 5;
  383. this.button10.UseVisualStyleBackColor = true;
  384. //
  385. // button3
  386. //
  387. this.button3.Location = new System.Drawing.Point(14, 21);
  388. this.button3.Name = "button3";
  389. this.button3.Size = new System.Drawing.Size(40, 40);
  390. this.button3.TabIndex = 4;
  391. this.button3.UseVisualStyleBackColor = true;
  392. //
  393. // button8
  394. //
  395. this.button8.Location = new System.Drawing.Point(106, 21);
  396. this.button8.Name = "button8";
  397. this.button8.Size = new System.Drawing.Size(40, 40);
  398. this.button8.TabIndex = 3;
  399. this.button8.UseVisualStyleBackColor = true;
  400. this.button8.Visible = false;
  401. //
  402. // radioButton5
  403. //
  404. this.radioButton5.AutoSize = true;
  405. this.radioButton5.Location = new System.Drawing.Point(238, 55);
  406. this.radioButton5.Name = "radioButton5";
  407. this.radioButton5.Size = new System.Drawing.Size(14, 13);
  408. this.radioButton5.TabIndex = 2;
  409. this.radioButton5.UseVisualStyleBackColor = true;
  410. this.radioButton5.Visible = false;
  411. //
  412. // radioButton4
  413. //
  414. this.radioButton4.AutoSize = true;
  415. this.radioButton4.Checked = true;
  416. this.radioButton4.Location = new System.Drawing.Point(297, 44);
  417. this.radioButton4.Name = "radioButton4";
  418. this.radioButton4.Size = new System.Drawing.Size(14, 13);
  419. this.radioButton4.TabIndex = 1;
  420. this.radioButton4.TabStop = true;
  421. this.radioButton4.UseVisualStyleBackColor = true;
  422. this.radioButton4.Visible = false;
  423. //
  424. // radioButton3
  425. //
  426. this.radioButton3.AutoSize = true;
  427. this.radioButton3.Location = new System.Drawing.Point(279, 21);
  428. this.radioButton3.Name = "radioButton3";
  429. this.radioButton3.Size = new System.Drawing.Size(14, 13);
  430. this.radioButton3.TabIndex = 0;
  431. this.radioButton3.UseVisualStyleBackColor = true;
  432. this.radioButton3.Visible = false;
  433. //
  434. // MethodAreaDialog
  435. //
  436. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  437. this.ClientSize = new System.Drawing.Size(1127, 810);
  438. this.Controls.Add(this.groupBox7);
  439. this.Controls.Add(this.groupBox11);
  440. this.Name = "MethodAreaDialog";
  441. this.Controls.SetChildIndex(this.groupBox3, 0);
  442. this.Controls.SetChildIndex(this.groupBox_img, 0);
  443. this.Controls.SetChildIndex(this.groupBox_review, 0);
  444. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  445. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  446. this.Controls.SetChildIndex(this.groupBox_report, 0);
  447. this.Controls.SetChildIndex(this.groupBox11, 0);
  448. this.Controls.SetChildIndex(this.groupBox7, 0);
  449. this.groupBox_img.ResumeLayout(false);
  450. this.groupBox_analysisResult1.ResumeLayout(false);
  451. this.groupBox3.ResumeLayout(false);
  452. this.groupBox11.ResumeLayout(false);
  453. this.groupBox11.PerformLayout();
  454. this.groupBox7.ResumeLayout(false);
  455. this.groupBox7.PerformLayout();
  456. this.ResumeLayout(false);
  457. }
  458. #endregion 初始化组件
  459. #region 需继承方法
  460. protected override Boolean ShowGrainBoundryChecked()
  461. {
  462. return !showOrimat() && checkBox3_0.Checked;
  463. }
  464. protected override void refreshWhileImgChanged()
  465. {
  466. if (this.grainColorsMatDict.ContainsKey(getCurrentWorkTag()))
  467. this.documentWorkspace.PhaseModels[2].mat = this.grainColorsMatDict[getCurrentWorkTag()];
  468. if (this.bitmap != null && this.documentWorkspace.PhaseModels[2].mat != null)
  469. {
  470. //try
  471. //{
  472. // GetNumberOfGrains();
  473. //}
  474. //catch (Exception)
  475. //{
  476. //}
  477. }
  478. else
  479. {
  480. this.documentWorkspace.PhaseModels[2].mat = null;//清空前一张图的信息不遗留显示##效果考虑优化
  481. GSSClass.standardModel.massLabelPoints.Clear();//1013###19098(切换图片的时候前一张图的信息不遗留显示)}
  482. this.documentWorkspace.Refresh();
  483. }
  484. }
  485. /// <summary>
  486. /// 是否用不同颜色显示晶粒
  487. /// </summary>
  488. /// <returns></returns>
  489. protected override Boolean ShowGrainColorChecked()
  490. {
  491. return checkBox11.Checked;
  492. }
  493. /// <summary>
  494. /// 保存结果
  495. /// </summary>
  496. protected override void buildListBox_analysisResult(string imagesKey, int analysisPicture, bool saveAll = false)
  497. {
  498. if (this.matOrg == null)
  499. {
  500. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text")+"!");
  501. return;
  502. }
  503. if (this.comboBox1.SelectedItem != null && !PdnResources.GetString("Menu.Pleaseselecttheauxiliarylineused.text").Equals(this.comboBox1.SelectedItem))
  504. {
  505. string imgName = this.appWorkspace.DocumentWorkspaces[analysisPicture].GetFriendlyName();
  506. string tag = imagesKey;
  507. System.Data.DataTable dataTable = new System.Data.DataTable();
  508. bool replace = false;
  509. int add = 0;
  510. foreach (ListViewItem item in this.listView2.Items)
  511. {
  512. if (item.Tag.Equals(tag))
  513. {
  514. add++;
  515. if (saveAll)
  516. {
  517. replace = true;
  518. break;
  519. }
  520. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Theresuethertoreplace.text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  521. if (dr == DialogResult.OK)
  522. {
  523. replace = true;
  524. }
  525. break;
  526. }
  527. }
  528. if (replace || this.listView2.Items.Count == 0 || add == 0)
  529. {
  530. if (!replace)
  531. {
  532. ListViewItem listViewItem = new ListViewItem();
  533. listViewItem.SubItems[0].Text = imgName;
  534. listViewItem.Tag = "" + tag;
  535. if (this.listView2.Items.Count == 0)
  536. this.listView2.Items.Add(listViewItem);
  537. else
  538. this.listView2.Items.Insert(0, listViewItem);
  539. }
  540. this.dataGridView2.Rows.Clear();
  541. DataGridViewRow dgvr = new DataGridViewRow();
  542. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  543. {
  544. dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
  545. }
  546. dgvr.Cells[0].Value = imgName;
  547. dgvr.Cells[1].Value = this.comboBox1.SelectedItem;
  548. if (analysisPicture != this.selectPicture)//更新二值图片
  549. binaryClass.updateAnalysisData(imagesKey, analysisPicture);
  550. GrainSizeGuideModel cal_GuideModel = this.GSSClass.GuideClass.guideModel;
  551. if (this.GSSClass.GuideClass.guideDict.ContainsKey(imagesKey))
  552. cal_GuideModel = this.GSSClass.GuideClass.guideDict[imagesKey];
  553. //else if (analysisPicture != this.selectPicture)//根据选择的辅助线 计算对应图片的数据
  554. //{
  555. // this.calcOtherImgs(imagesKey, analysisPicture);
  556. //}
  557. if (this.GSSClass.GuideClass.guideModel.oldSelectItem == null)
  558. this.GSSClass.GuideClass.guideModel.oldSelectItem = this.comboBox1SelectedItem.ToString();
  559. if (cal_GuideModel.oldSelectItem == null)//##
  560. cal_GuideModel.oldSelectItem = this.GSSClass.GuideClass.guideModel.oldSelectItem;
  561. GrainSizeStandardModel cal_StandardModel = this.GSSClass.standardModel;
  562. if (imagesKey != null)
  563. {
  564. if (!this.GSSClass.standardDict.ContainsKey(imagesKey))
  565. this.GSSClass.standardDict.Add(imagesKey, this.GSSClass.standardModel.cloneListParamModel());
  566. cal_StandardModel = this.GSSClass.standardDict[imagesKey];
  567. if (analysisPicture == this.selectPicture && imagesKey.Equals(getCurrentWorkTag()))
  568. this.GSSClass.standardModel = this.GSSClass.standardDict[imagesKey];
  569. }
  570. // 是否矩形辅助线
  571. int isRect;
  572. double aec = GSSClass.GuideClass.guideArea(cal_GuideModel, cal_GuideModel.oldSelectItem, out isRect, 0/*this.gbtType*/);
  573. dgvr.Cells[2].Value = aec;
  574. aec = aec * 0.001 * 0.001;
  575. double grainNumber = GetNumberOfGrains(/*#########*/cal_StandardModel, cal_GuideModel, imagesKey/*getCurrentWorkTag()*/, analysisPicture/*this.selectPicture*/);
  576. if (grainNumber > (int)grainNumber)
  577. {
  578. grainNumber = grainNumber + 0.5;
  579. }
  580. dgvr.Cells[3].Value = grainNumber;
  581. decimal M = 1;// this.getGainMultiple();
  582. double small_l = (grainNumber * (double)M * (double)M) / aec;
  583. decimal A = Convert.ToDecimal(small_l * 1);
  584. double[] lengths = {3.88, 7.75 , 11.0, 15.50, 21.9, 25.0, 31.0, 43.8, 62.0, 69.4,
  585. 87.7, 100, 124, 175, 204, 248, 278, 351, 400, 496, 625, 701, 816,
  586. 992, 1111 , 1403, 1600, 1980, 2500, 2810, 3970, 4440, 5610,
  587. 7940, 10000, 11220, 12350, 15870, 20410, 22450, 27780, 31710, 40000, 44900, 63500, 89800
  588. , 111100, 127000, 160000};
  589. // 差值
  590. decimal differenceNew;//##20716
  591. decimal differenceOld = Math.Abs(Convert.ToDecimal(Math.Max((double)A - 2.88, (double)A - 160001)));
  592. int first = 0;
  593. if ((double)A > lengths[lengths.Length - 1])
  594. first = lengths.Length - 1;
  595. else
  596. for (int firstI = 0; firstI < lengths.Length; firstI++)
  597. {
  598. double item = lengths[firstI];
  599. differenceNew = Math.Abs(A - Convert.ToDecimal(item));
  600. if (differenceNew < differenceOld)
  601. {
  602. differenceOld = Math.Abs(A - Convert.ToDecimal(item));
  603. first = firstI;
  604. }
  605. }
  606. string[] valueG = {"00A", "0" , "0.5", "1.0", "1.5", "1.5"/**/, "2.0", "2.5", "3.0", "3.0",
  607. "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",
  608. "7.0", "7.0" , "7.5", "7.5", "8.0", "8.0", "8.5", "9.0", "9.0", "9.5",
  609. "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"
  610. , "13.5", "14.0", "14.0"};
  611. dgvr.Cells[4].Value = valueG[first];
  612. this.dataGridView2.Rows.Add(dgvr);
  613. dataTable.TableName = tag;
  614. foreach (System.Data.DataTable dataTable1 in dataTables)
  615. {
  616. if (dataTable1.TableName.Equals(dataTable.TableName))
  617. {
  618. dataTables.Remove(dataTable1);
  619. break;
  620. }
  621. }
  622. foreach (DataGridViewColumn c in this.dataGridView2.Columns)
  623. {
  624. dataTable.Columns.Add(c.HeaderText);
  625. }
  626. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  627. {
  628. DataRow dataRow = dataTable.NewRow();
  629. for (int c = 0; c < this.dataGridView2.Rows[r].Cells.Count; c++)
  630. {
  631. dataRow[this.dataGridView2.Columns[c].HeaderText] = this.dataGridView2.Rows[r].Cells[c].Value;
  632. }
  633. dataTable.Rows.Add(dataRow);
  634. }
  635. this.dataTables.Add(dataTable);
  636. this.RefreshDataGridView4();
  637. //保存处理后的图片
  638. double pantographRatio = this.appWorkspace.DocumentWorkspaces[analysisPicture/*this.selectPicture*/].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  639. List<Bitmap> tempBit = new List<Bitmap>();
  640. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[analysisPicture].CompositionSurface.CreateAliasedBitmap();
  641. originalBit.Tag = pantographRatio;
  642. tempBit.Add(originalBit);
  643. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  644. Graphics graphics = Graphics.FromImage(newBit);
  645. if (binaryClass.getModelMat(imagesKey) != null)
  646. {
  647. Mat targetMat = binaryClass.getModelMat(imagesKey);
  648. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  649. }
  650. if (this.grainBoundaryMatDict.ContainsKey(imagesKey))
  651. {
  652. Mat targetMat = this.grainBoundaryMatDict[imagesKey];
  653. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  654. }
  655. if (this.grainColorsMatDict.ContainsKey(imagesKey) && !bcOriginChecked() && ShowGrainColorChecked())
  656. {
  657. Mat targetMat = this.grainColorsMatDict[imagesKey];
  658. graphics.DrawImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(targetMat), 0, 0, targetMat.Width, targetMat.Height);
  659. }
  660. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  661. drawSubclass(graphics);
  662. newBit.Tag = pantographRatio;
  663. tempBit.Add(newBit);
  664. if (bitDic.ContainsKey(tag))
  665. bitDic[tag] = tempBit;
  666. else
  667. bitDic.Add(tag, tempBit);
  668. //拼接中间数据
  669. List<List<string>> dataList = new List<List<string>>();
  670. List<string> columnName = new List<string>();
  671. columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  672. columnName.Add("X"+ PdnResources.GetString("Menu.coordinates.Text"));
  673. columnName.Add("Y"+ PdnResources.GetString("Menu.coordinates.Text"));
  674. columnName.Add(PdnResources.GetString("Menu.Whethertheinternal.Text"));
  675. dataList.Add(columnName);
  676. if (cal_StandardModel.massLabelPoints.Count > 0)
  677. {
  678. int index = 0;
  679. int outMaxIndex = cal_StandardModel.massLabelPoints.Count - 0 - cal_StandardModel.within;
  680. foreach (var item in cal_StandardModel.massLabelPoints.Values)
  681. {
  682. List<string> strList = new List<string>();
  683. strList.Add(("" + (++index)).ToString());
  684. strList.Add(item[2].ToString());
  685. strList.Add(item[3].ToString());
  686. if (outMaxIndex < index)
  687. strList.Add(PdnResources.GetString("Menu.Yes.text"));
  688. else
  689. strList.Add(PdnResources.GetString("Menu.no.text"));
  690. dataList.Add(strList);
  691. }
  692. }
  693. bool isExist = false;//是否已存在进行替换
  694. int modelIndex = -1;//要替换的下标
  695. for (int j = 0; j < tempDataModel.Count; j++)
  696. {
  697. if (tempDataModel[j].tagName.Equals(tag))
  698. {
  699. isExist = true;
  700. modelIndex = j;
  701. break;
  702. }
  703. }
  704. if (isExist && modelIndex > -1)
  705. tempDataModel[modelIndex].dataList = dataList;
  706. else
  707. {
  708. Base.Functionodel.ExportProjectModel newModel = new Base.Functionodel.ExportProjectModel();
  709. newModel.tagName = tag;
  710. newModel.picName = imgName;
  711. newModel.dataList = dataList;
  712. tempDataModel.Add(newModel);
  713. }
  714. }
  715. }
  716. else
  717. {
  718. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectauxiliaryline.text")+"!");
  719. }
  720. }
  721. protected override void SubclassInitialize()
  722. {
  723. InitializeComponent();
  724. InitializeLanguageText();
  725. }
  726. //是否绘制辅助线
  727. protected override bool showGridChecked()
  728. {
  729. return checkBox4_0.Checked;
  730. }
  731. ////是否绘制截点
  732. //protected override bool drawGuidePoints()
  733. //{
  734. // return (matOrg != null && this.checkBox5_0.Checked);
  735. //}
  736. ////是否显示截点
  737. //protected override Boolean drawDisplaySections()//##1
  738. //{
  739. // return this.checkBox5_0.Checked;
  740. //}
  741. //是否绘制编号
  742. protected override bool showGrainNumberChecked()
  743. {
  744. return this.checkBox5_0.Checked;
  745. }
  746. //辅助线类型
  747. protected override string[] getTypeNames()
  748. {
  749. return new string[] {
  750. PdnResources.GetString("Menu.circular.Text")};
  751. }
  752. //protected override string getTemplateName()
  753. //{
  754. // return "Template.Manager.item3.GrainSizeArea_GBT32461";
  755. //}
  756. protected override string getProjectEngineeringName()
  757. {
  758. return "Menu.DedicatedAnalysis.NonferrousMetal.AluminiumAlloy.Text";
  759. }
  760. //protected override string getModelName()
  761. //{
  762. // return "GrainGBT32461AreaMethodModel.xml";
  763. //}
  764. #endregion
  765. /// <summary>
  766. /// 设置晶粒颜色
  767. /// </summary>
  768. /// <param name="sender"></param>
  769. /// <param name="e"></param>
  770. private void button2_Click(object sender, EventArgs e)
  771. {
  772. //if (this.matOrg == null)
  773. //{
  774. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  775. // return;
  776. //}
  777. ShowGrainColorSettingDialog();
  778. }
  779. /// <summary>
  780. /// 刷新晶粒编号
  781. /// </summary>
  782. /// <param name="sender"></param>
  783. /// <param name="e"></param>
  784. private void button4_Click(object sender, EventArgs e)
  785. {
  786. if (this.matOrg == null)
  787. {
  788. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  789. return;
  790. }
  791. GetNumberOfGrains();
  792. }
  793. /// <summary>
  794. /// 是否显示晶界
  795. /// </summary>
  796. /// <param name="sender"></param>
  797. /// <param name="e"></param>
  798. private void checkBox3_0_CheckedChanged(object sender, EventArgs e)
  799. {
  800. if (!showOrimat() && getGrainBoundryChecked() && checkBox3_0.Checked)
  801. {
  802. this.documentWorkspace.PhaseModels[1].choise = true;
  803. }
  804. else
  805. {
  806. this.documentWorkspace.PhaseModels[1].choise = false;
  807. }
  808. this.documentWorkspace.Refresh();
  809. }
  810. private void checkBox4_0_CheckedChanged(object sender, EventArgs e)
  811. {
  812. this.documentWorkspace.Refresh();
  813. }
  814. private void checkBox11_CheckedChanged(object sender, EventArgs e)
  815. {
  816. if (!showOrimat() && checkBox11.Checked)
  817. {
  818. this.documentWorkspace.PhaseModels[2].choise = true;
  819. }
  820. else
  821. {
  822. this.documentWorkspace.PhaseModels[2].choise = false;
  823. }
  824. this.documentWorkspace.Refresh();
  825. }
  826. private void checkBox5_0_CheckedChanged(object sender, EventArgs e)
  827. {
  828. this.documentWorkspace.Refresh();
  829. }
  830. }
  831. }