MethodAreaDialog.cs 41 KB

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