TABM1Dialog.cs 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. using Metis.ParameterSet;
  2. using OpenCvSharp;
  3. using PaintDotNet.Base.CommTool;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Windows.Forms;
  10. namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals.YYT098814_2016
  11. {
  12. internal class TABM1Dialog : NonFMetalsStandardDialog
  13. {
  14. #region 属性
  15. ///// <summary>
  16. ///// 调色板
  17. ///// </summary>
  18. //private ColorsForm colorsFormGrid;
  19. //private Panel panelC;
  20. /// <summary>
  21. /// 是否调用了灰度化的算法
  22. /// </summary>
  23. private bool grayBitmap = false;
  24. /// <summary>
  25. /// 记录鼠标最后所在的点的y坐标
  26. /// </summary>
  27. int lineNum = 0;
  28. /// <summary>
  29. /// 竖直的辅助线
  30. /// </summary>
  31. List<Line> vlines = new List<Line>();
  32. /// <summary>
  33. /// 基体平行线
  34. /// </summary>
  35. Line line;
  36. /// <summary>
  37. /// 1显示基体界面 2移动基体界面 0隐藏基体界面
  38. /// </summary>
  39. int btnflag = 0;
  40. /// <summary>
  41. /// 轮廓的线
  42. /// </summary>
  43. System.Drawing.Point[][] tempLine;
  44. /// <summary>
  45. /// 平均涂层厚度
  46. /// </summary>
  47. double res_perL;
  48. /// <summary>
  49. /// 标准偏差
  50. /// </summary>
  51. double res_s1;
  52. /// <summary>
  53. /// 置信区间
  54. /// </summary>
  55. double res_c1;
  56. /// <summary>
  57. /// 选择标尺的物理长度(微米/像素)
  58. /// </summary>
  59. double physical_length = 1;
  60. // <summary>
  61. /// 保存窗口参数
  62. /// </summary>
  63. private GrainSizeAnalysisModel analysisModel;
  64. private const string ParamKey_Report = "report";//报告设置
  65. private const string ParamKey_OutlineColour = "outlineColour";//轮廓颜色
  66. private const string ParamKey_OutlineWidth = "outlineWidth";//轮廓线宽
  67. private const string ParamKey_BaseColour = "baseColour";//基线颜色
  68. private const string ParamKey_BaseWidth = "baseWidth";//基线线宽
  69. private const string ParamKey_GuideColour = "guideColour";//辅助线颜色
  70. private const string ParamKey_GuideWidth = "guideWidth";//辅助线线宽
  71. private const string ParamKey_GuideNumber = "guideNumber";//辅助线条数
  72. private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数
  73. #endregion 属性
  74. #region 组件
  75. private GroupBox groupBox_Basicoperation;
  76. private Button button14;
  77. private Button button17;
  78. private Button button2;
  79. private Button button15;
  80. private Button button13;
  81. private Button button10;
  82. private Button button3;
  83. private Button button4;
  84. private GroupBox groupBox10;
  85. private Panel panel1;
  86. private TrackBar trackBar5;
  87. private TextBox textBox9;
  88. private Label label3;
  89. private Label label5;
  90. private GroupBox groupBox6;
  91. private Panel panel3;
  92. private TrackBar trackBar4;
  93. private TextBox textBox10;
  94. private Label label4;
  95. private Label label6;
  96. private GroupBox groupBox7;
  97. private Panel panel4;
  98. private TextBox textBox6;
  99. private TextBox textBox4;
  100. private TrackBar trackBar3;
  101. private TextBox textBox3;
  102. private Label label15;
  103. private Label label16;
  104. private Label label17;
  105. private Label label18;
  106. private GroupBox groupBox8;
  107. private Label label14;
  108. private Label label7;
  109. private Label label2;
  110. private Label label13;
  111. private Label label12;
  112. private Label label11;
  113. private Button button5;
  114. #endregion 组件
  115. #region 构造函数
  116. public TABM1Dialog(AppWorkspace appWorkspace, int menuId) : base(appWorkspace, menuId)
  117. {
  118. Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
  119. this.physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
  120. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
  121. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  122. this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
  123. foreach (var item in this.analysisModel.ListParam)
  124. item.setValue();
  125. GetListParamModel();
  126. ////
  127. ////初始化色板
  128. ////
  129. //this.colorsFormGrid = new ColorsForm();
  130. //this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  131. //this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  132. InitGridHeader();
  133. }
  134. /// <summary>
  135. /// 初始化表头
  136. /// </summary>
  137. private void InitGridHeader()
  138. {
  139. DataGridViewTextBoxColumn Column2_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  140. DataGridViewTextBoxColumn Column3_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  141. DataGridViewTextBoxColumn Column4_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  142. Column2_total.Name = "Column2_total";
  143. Column2_total.ReadOnly = true;
  144. Column3_total.Name = "Column3_total";
  145. Column3_total.ReadOnly = true;
  146. Column4_total.Name = "Column4_total";
  147. Column4_total.ReadOnly = true;
  148. Column2_total.HeaderText = PdnResources.GetString("Menu.Averagethickness(μm).text");;
  149. Column3_total.HeaderText = PdnResources.GetString("Menu.standarddeviation.text");
  150. Column4_total.HeaderText = PdnResources.GetString("Menu.confidencebound.text");
  151. this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  152. Column2_total,
  153. Column3_total,
  154. Column4_total});
  155. this.dataGridView_Total.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  156. this.dataGridView_Total.Columns[0].ReadOnly = true;
  157. this.dataGridView_Total.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  158. this.dataGridView_Total.Columns[1].ReadOnly = true;
  159. this.dataGridView_Total.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  160. this.dataGridView_Total.Columns[2].ReadOnly = true;
  161. DataGridViewTextBoxColumn Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  162. DataGridViewTextBoxColumn Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  163. DataGridViewTextBoxColumn Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  164. DataGridViewTextBoxColumn Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  165. Column1.Name = "Column1";
  166. Column1.ReadOnly = true;
  167. Column2.Name = "Column2";
  168. Column2.ReadOnly = true;
  169. Column3.Name = "Column3";
  170. Column3.ReadOnly = true;
  171. Column4.Name = "Column4";
  172. Column4.ReadOnly = true;
  173. Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  174. Column2.HeaderText = PdnResources.GetString("Menu.Averagethickness(μm).text");
  175. Column3.HeaderText = PdnResources.GetString("Menu.standarddeviation.text");
  176. Column4.HeaderText = PdnResources.GetString("Menu.confidencebound.text");
  177. this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  178. Column1,
  179. Column2,
  180. Column3,
  181. Column4});
  182. Column1.Width = 195;
  183. Column2.Width = 165;
  184. Column3.Width = 165;
  185. Column4.Width = 165;
  186. this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  187. this.dataGridView2.Columns[0].ReadOnly = true;
  188. this.dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  189. this.dataGridView2.Columns[1].ReadOnly = true;
  190. this.dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  191. this.dataGridView2.Columns[2].ReadOnly = true;
  192. this.dataGridView2.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
  193. this.dataGridView2.Columns[3].ReadOnly = true;
  194. }
  195. #endregion 构造函数
  196. #region 初始化组件和实现组件事件
  197. private void InitializeLanguageText()
  198. {
  199. this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  200. this.label15.Text = PdnResources.GetString("Menu.spacing.text") + ":";
  201. this.groupBox7.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
  202. this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
  203. this.label4.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  204. this.groupBox6.Text = PdnResources.GetString("Menu.Baselinesettings.text");
  205. this.label5.Text = PdnResources.GetString("Menu.color.text") + ":";
  206. this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  207. this.groupBox10.Text = PdnResources.GetString("Menu.contour.text");
  208. this.button2.Text = PdnResources.GetString("Menu.reinformation.text");
  209. this.button4.Text = PdnResources.GetString("Menu.Image.Grayscale.Text");
  210. this.button3.Text = PdnResources.GetString("Menu.BinaryAction.ErosionExtraction.Text");
  211. this.button10.Text = PdnResources.GetString("Menu.BinaryAction.DilationExtraction.Text");
  212. this.button13.Text = PdnResources.GetString("Menu.Drawauxiliarylines.text");
  213. this.button15.Text = PdnResources.GetString("Menu.searchcontour.text");
  214. this.button17.Text = PdnResources.GetString("Menu.auto-adjust.text");
  215. this.button14.Text = PdnResources.GetString("Menu.easemodifytheoutline.Text");
  216. this.button5.Text = PdnResources.GetString("Menu.reinformation.text");
  217. this.groupBox_Basicoperation.Text = PdnResources.GetString("Menu.Basicoperation.text");
  218. this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.veragecoatingthickness.Text") + ")";
  219. this.label11.Text = PdnResources.GetString("Menu.Averagethickness(μm).text") + ":";
  220. this.label12.Text = PdnResources.GetString("Menu.standarddeviation.text") + ":";
  221. this.label13.Text = PdnResources.GetString("Menu.confidencebound.text") + ":";
  222. this.groupBox8.Text = PdnResources.GetString("Menu.result.text");
  223. this.label18.Text = PdnResources.GetString("Menu.color.text") + ":";
  224. this.label17.Text = PdnResources.GetString("Menu.Numberof.text") + ":";
  225. }
  226. private void InitializeComponent()
  227. {
  228. this.groupBox_Basicoperation = new System.Windows.Forms.GroupBox();
  229. this.button5 = new System.Windows.Forms.Button();
  230. this.button14 = new System.Windows.Forms.Button();
  231. this.button17 = new System.Windows.Forms.Button();
  232. this.button15 = new System.Windows.Forms.Button();
  233. this.button13 = new System.Windows.Forms.Button();
  234. this.button10 = new System.Windows.Forms.Button();
  235. this.button3 = new System.Windows.Forms.Button();
  236. this.button4 = new System.Windows.Forms.Button();
  237. this.button2 = new System.Windows.Forms.Button();
  238. this.groupBox10 = new System.Windows.Forms.GroupBox();
  239. this.panel1 = new System.Windows.Forms.Panel();
  240. this.trackBar5 = new System.Windows.Forms.TrackBar();
  241. this.textBox9 = new System.Windows.Forms.TextBox();
  242. this.label3 = new System.Windows.Forms.Label();
  243. this.label5 = new System.Windows.Forms.Label();
  244. this.groupBox6 = new System.Windows.Forms.GroupBox();
  245. this.panel3 = new System.Windows.Forms.Panel();
  246. this.trackBar4 = new System.Windows.Forms.TrackBar();
  247. this.textBox10 = new System.Windows.Forms.TextBox();
  248. this.label4 = new System.Windows.Forms.Label();
  249. this.label6 = new System.Windows.Forms.Label();
  250. this.groupBox7 = new System.Windows.Forms.GroupBox();
  251. this.panel4 = new System.Windows.Forms.Panel();
  252. this.textBox6 = new System.Windows.Forms.TextBox();
  253. this.textBox4 = new System.Windows.Forms.TextBox();
  254. this.trackBar3 = new System.Windows.Forms.TrackBar();
  255. this.textBox3 = new System.Windows.Forms.TextBox();
  256. this.label15 = new System.Windows.Forms.Label();
  257. this.label16 = new System.Windows.Forms.Label();
  258. this.label17 = new System.Windows.Forms.Label();
  259. this.label18 = new System.Windows.Forms.Label();
  260. this.groupBox8 = new System.Windows.Forms.GroupBox();
  261. this.label14 = new System.Windows.Forms.Label();
  262. this.label7 = new System.Windows.Forms.Label();
  263. this.label2 = new System.Windows.Forms.Label();
  264. this.label13 = new System.Windows.Forms.Label();
  265. this.label12 = new System.Windows.Forms.Label();
  266. this.label11 = new System.Windows.Forms.Label();
  267. this.groupBox_img.SuspendLayout();
  268. this.groupBox_report.SuspendLayout();
  269. this.groupBox_analysisResult1.SuspendLayout();
  270. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
  271. this.groupBox_Basicoperation.SuspendLayout();
  272. this.groupBox10.SuspendLayout();
  273. ((System.ComponentModel.ISupportInitialize)(this.trackBar5)).BeginInit();
  274. this.groupBox6.SuspendLayout();
  275. ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
  276. this.groupBox7.SuspendLayout();
  277. ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
  278. this.groupBox8.SuspendLayout();
  279. this.SuspendLayout();
  280. //
  281. // groupBox_Basicoperation
  282. //
  283. this.groupBox_Basicoperation.Controls.Add(this.button5);
  284. this.groupBox_Basicoperation.Controls.Add(this.button14);
  285. this.groupBox_Basicoperation.Controls.Add(this.button17);
  286. this.groupBox_Basicoperation.Controls.Add(this.button15);
  287. this.groupBox_Basicoperation.Controls.Add(this.button13);
  288. this.groupBox_Basicoperation.Controls.Add(this.button10);
  289. this.groupBox_Basicoperation.Controls.Add(this.button3);
  290. this.groupBox_Basicoperation.Controls.Add(this.button4);
  291. this.groupBox_Basicoperation.Location = new System.Drawing.Point(180, 317);
  292. this.groupBox_Basicoperation.Name = "groupBox_Basicoperation";
  293. this.groupBox_Basicoperation.Size = new System.Drawing.Size(353, 66);
  294. this.groupBox_Basicoperation.TabIndex = 39;
  295. this.groupBox_Basicoperation.TabStop = false;
  296. //
  297. // button5
  298. //
  299. this.button5.Location = new System.Drawing.Point(12, 39);
  300. this.button5.Name = "button5";
  301. this.button5.Size = new System.Drawing.Size(75, 23);
  302. this.button5.TabIndex = 9;
  303. this.button5.UseVisualStyleBackColor = true;
  304. this.button5.Click += new System.EventHandler(this.button5_Click);
  305. //
  306. // button14
  307. //
  308. this.button14.Location = new System.Drawing.Point(270, 39);
  309. this.button14.Name = "button14";
  310. this.button14.Size = new System.Drawing.Size(75, 23);
  311. this.button14.TabIndex = 8;
  312. this.button14.UseVisualStyleBackColor = true;
  313. this.button14.Click += new System.EventHandler(this.button14_Click);
  314. //
  315. // button17
  316. //
  317. this.button17.Location = new System.Drawing.Point(183, 39);
  318. this.button17.Name = "button17";
  319. this.button17.Size = new System.Drawing.Size(75, 23);
  320. this.button17.TabIndex = 7;
  321. this.button17.UseVisualStyleBackColor = true;
  322. this.button17.Click += new System.EventHandler(this.button17_Click);
  323. //
  324. // button15
  325. //
  326. this.button15.Location = new System.Drawing.Point(270, 16);
  327. this.button15.Name = "button15";
  328. this.button15.Size = new System.Drawing.Size(75, 23);
  329. this.button15.TabIndex = 5;
  330. this.button15.UseVisualStyleBackColor = true;
  331. this.button15.Click += new System.EventHandler(this.button15_Click);
  332. //
  333. // button13
  334. //
  335. this.button13.Location = new System.Drawing.Point(96, 39);
  336. this.button13.Name = "button13";
  337. this.button13.Size = new System.Drawing.Size(75, 23);
  338. this.button13.TabIndex = 3;
  339. this.button13.UseVisualStyleBackColor = true;
  340. this.button13.Click += new System.EventHandler(this.button13_Click);
  341. //
  342. // button10
  343. //
  344. this.button10.Location = new System.Drawing.Point(183, 16);
  345. this.button10.Name = "button10";
  346. this.button10.Size = new System.Drawing.Size(75, 23);
  347. this.button10.TabIndex = 2;
  348. this.button10.UseVisualStyleBackColor = true;
  349. this.button10.Click += new System.EventHandler(this.button10_Click);
  350. //
  351. // button3
  352. //
  353. this.button3.Location = new System.Drawing.Point(96, 16);
  354. this.button3.Name = "button3";
  355. this.button3.Size = new System.Drawing.Size(75, 23);
  356. this.button3.TabIndex = 1;
  357. this.button3.UseVisualStyleBackColor = true;
  358. this.button3.Click += new System.EventHandler(this.button3_Click);
  359. //
  360. // button4
  361. //
  362. this.button4.Location = new System.Drawing.Point(12, 16);
  363. this.button4.Name = "button4";
  364. this.button4.Size = new System.Drawing.Size(75, 23);
  365. this.button4.TabIndex = 0;
  366. this.button4.UseVisualStyleBackColor = true;
  367. this.button4.Click += new System.EventHandler(this.button4_Click);
  368. //
  369. // button2
  370. //
  371. this.button2.Location = new System.Drawing.Point(96, 39);
  372. this.button2.Name = "button2";
  373. this.button2.Size = new System.Drawing.Size(75, 23);
  374. this.button2.TabIndex = 6;
  375. this.button2.UseVisualStyleBackColor = true;
  376. //
  377. // groupBox10
  378. //
  379. this.groupBox10.Controls.Add(this.panel1);
  380. this.groupBox10.Controls.Add(this.trackBar5);
  381. this.groupBox10.Controls.Add(this.textBox9);
  382. this.groupBox10.Controls.Add(this.label3);
  383. this.groupBox10.Controls.Add(this.label5);
  384. this.groupBox10.Location = new System.Drawing.Point(178, 383);
  385. this.groupBox10.Name = "groupBox10";
  386. this.groupBox10.Size = new System.Drawing.Size(354, 41);
  387. this.groupBox10.TabIndex = 42;
  388. this.groupBox10.TabStop = false;
  389. //
  390. // panel1
  391. //
  392. this.panel1.BackColor = System.Drawing.Color.Red;
  393. this.panel1.Location = new System.Drawing.Point(63, 15);
  394. this.panel1.Name = "panel1";
  395. this.panel1.Size = new System.Drawing.Size(105, 21);
  396. this.panel1.TabIndex = 21;
  397. this.panel1.Click += new System.EventHandler(this.panelC_Click);
  398. //
  399. // trackBar5
  400. //
  401. this.trackBar5.AutoSize = false;
  402. this.trackBar5.Cursor = System.Windows.Forms.Cursors.Hand;
  403. this.trackBar5.Location = new System.Drawing.Point(214, 16);
  404. this.trackBar5.Maximum = 50;
  405. this.trackBar5.Minimum = 1;
  406. this.trackBar5.Name = "trackBar5";
  407. this.trackBar5.Size = new System.Drawing.Size(84, 21);
  408. this.trackBar5.TabIndex = 7;
  409. this.trackBar5.TickStyle = System.Windows.Forms.TickStyle.None;
  410. this.trackBar5.Value = 3;
  411. this.trackBar5.Scroll += new System.EventHandler(this.trackBar5_Scroll);
  412. this.trackBar5.ValueChanged += new System.EventHandler(this.trackBar5_ValueChanged);
  413. //
  414. // textBox9
  415. //
  416. this.textBox9.Location = new System.Drawing.Point(304, 15);
  417. this.textBox9.Name = "textBox9";
  418. this.textBox9.Size = new System.Drawing.Size(35, 21);
  419. this.textBox9.TabIndex = 6;
  420. this.textBox9.Text = "3";
  421. this.textBox9.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  422. this.textBox9.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox9_KeyUp);
  423. //
  424. // label3
  425. //
  426. this.label3.AutoSize = true;
  427. this.label3.Location = new System.Drawing.Point(173, 20);
  428. this.label3.Name = "label3";
  429. this.label3.Size = new System.Drawing.Size(0, 12);
  430. this.label3.TabIndex = 2;
  431. //
  432. // label5
  433. //
  434. this.label5.AutoSize = true;
  435. this.label5.Location = new System.Drawing.Point(15, 20);
  436. this.label5.Name = "label5";
  437. this.label5.Size = new System.Drawing.Size(0, 12);
  438. this.label5.TabIndex = 0;
  439. //
  440. // groupBox6
  441. //
  442. this.groupBox6.Controls.Add(this.panel3);
  443. this.groupBox6.Controls.Add(this.trackBar4);
  444. this.groupBox6.Controls.Add(this.textBox10);
  445. this.groupBox6.Controls.Add(this.label4);
  446. this.groupBox6.Controls.Add(this.label6);
  447. this.groupBox6.Location = new System.Drawing.Point(178, 426);
  448. this.groupBox6.Name = "groupBox6";
  449. this.groupBox6.Size = new System.Drawing.Size(354, 41);
  450. this.groupBox6.TabIndex = 41;
  451. this.groupBox6.TabStop = false;
  452. //
  453. // panel3
  454. //
  455. this.panel3.BackColor = System.Drawing.Color.Yellow;
  456. this.panel3.Location = new System.Drawing.Point(62, 14);
  457. this.panel3.Name = "panel3";
  458. this.panel3.Size = new System.Drawing.Size(105, 21);
  459. this.panel3.TabIndex = 22;
  460. this.panel3.Click += new System.EventHandler(this.panelC_Click);
  461. //
  462. // trackBar4
  463. //
  464. this.trackBar4.AutoSize = false;
  465. this.trackBar4.Cursor = System.Windows.Forms.Cursors.Hand;
  466. this.trackBar4.Location = new System.Drawing.Point(214, 16);
  467. this.trackBar4.Maximum = 50;
  468. this.trackBar4.Minimum = 1;
  469. this.trackBar4.Name = "trackBar4";
  470. this.trackBar4.Size = new System.Drawing.Size(84, 21);
  471. this.trackBar4.TabIndex = 7;
  472. this.trackBar4.TickStyle = System.Windows.Forms.TickStyle.None;
  473. this.trackBar4.Value = 3;
  474. this.trackBar4.Scroll += new System.EventHandler(this.trackBar4_Scroll);
  475. this.trackBar4.ValueChanged += new System.EventHandler(this.trackBar5_ValueChanged);
  476. //
  477. // textBox10
  478. //
  479. this.textBox10.Location = new System.Drawing.Point(304, 15);
  480. this.textBox10.Name = "textBox10";
  481. this.textBox10.Size = new System.Drawing.Size(35, 21);
  482. this.textBox10.TabIndex = 6;
  483. this.textBox10.Text = "3";
  484. this.textBox10.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  485. this.textBox10.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox10_KeyUp);
  486. //
  487. // label4
  488. //
  489. this.label4.AutoSize = true;
  490. this.label4.Location = new System.Drawing.Point(173, 20);
  491. this.label4.Name = "label4";
  492. this.label4.Size = new System.Drawing.Size(0, 12);
  493. this.label4.TabIndex = 2;
  494. //
  495. // label6
  496. //
  497. this.label6.AutoSize = true;
  498. this.label6.Location = new System.Drawing.Point(15, 20);
  499. this.label6.Name = "label6";
  500. this.label6.Size = new System.Drawing.Size(0, 12);
  501. this.label6.TabIndex = 0;
  502. //
  503. // groupBox7
  504. //
  505. this.groupBox7.Controls.Add(this.panel4);
  506. this.groupBox7.Controls.Add(this.textBox6);
  507. this.groupBox7.Controls.Add(this.textBox4);
  508. this.groupBox7.Controls.Add(this.trackBar3);
  509. this.groupBox7.Controls.Add(this.textBox3);
  510. this.groupBox7.Controls.Add(this.label15);
  511. this.groupBox7.Controls.Add(this.label16);
  512. this.groupBox7.Controls.Add(this.label17);
  513. this.groupBox7.Controls.Add(this.label18);
  514. this.groupBox7.Location = new System.Drawing.Point(178, 469);
  515. this.groupBox7.Name = "groupBox7";
  516. this.groupBox7.Size = new System.Drawing.Size(354, 64);
  517. this.groupBox7.TabIndex = 40;
  518. this.groupBox7.TabStop = false;
  519. //
  520. // panel4
  521. //
  522. this.panel4.BackColor = System.Drawing.Color.Green;
  523. this.panel4.Location = new System.Drawing.Point(62, 15);
  524. this.panel4.Name = "panel4";
  525. this.panel4.Size = new System.Drawing.Size(105, 21);
  526. this.panel4.TabIndex = 23;
  527. this.panel4.Click += new System.EventHandler(this.panelC_Click);
  528. //
  529. // textBox6
  530. //
  531. this.textBox6.Location = new System.Drawing.Point(62, 39);
  532. this.textBox6.Name = "textBox6";
  533. this.textBox6.Size = new System.Drawing.Size(105, 21);
  534. this.textBox6.TabIndex = 10;
  535. this.textBox6.Text = "10";
  536. this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
  537. this.textBox6.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox6_KeyUp);
  538. //
  539. // textBox4
  540. //
  541. this.textBox4.Location = new System.Drawing.Point(218, 39);
  542. this.textBox4.Name = "textBox4";
  543. this.textBox4.Size = new System.Drawing.Size(121, 21);
  544. this.textBox4.TabIndex = 8;
  545. this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
  546. this.textBox4.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox4_KeyUp);
  547. //
  548. // trackBar3
  549. //
  550. this.trackBar3.AutoSize = false;
  551. this.trackBar3.Cursor = System.Windows.Forms.Cursors.Hand;
  552. this.trackBar3.Location = new System.Drawing.Point(214, 16);
  553. this.trackBar3.Maximum = 50;
  554. this.trackBar3.Minimum = 1;
  555. this.trackBar3.Name = "trackBar3";
  556. this.trackBar3.Size = new System.Drawing.Size(84, 21);
  557. this.trackBar3.TabIndex = 7;
  558. this.trackBar3.TickStyle = System.Windows.Forms.TickStyle.None;
  559. this.trackBar3.Value = 3;
  560. this.trackBar3.Scroll += new System.EventHandler(this.trackBar3_Scroll);
  561. this.trackBar3.ValueChanged += new System.EventHandler(this.trackBar5_ValueChanged);
  562. //
  563. // textBox3
  564. //
  565. this.textBox3.Location = new System.Drawing.Point(304, 15);
  566. this.textBox3.Name = "textBox3";
  567. this.textBox3.Size = new System.Drawing.Size(35, 21);
  568. this.textBox3.TabIndex = 6;
  569. this.textBox3.Text = "3";
  570. this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  571. this.textBox3.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyUp);
  572. //
  573. // label15
  574. //
  575. this.label15.AutoSize = true;
  576. this.label15.Location = new System.Drawing.Point(173, 44);
  577. this.label15.Name = "label15";
  578. this.label15.Size = new System.Drawing.Size(0, 12);
  579. this.label15.TabIndex = 3;
  580. //
  581. // label16
  582. //
  583. this.label16.AutoSize = true;
  584. this.label16.Location = new System.Drawing.Point(173, 20);
  585. this.label16.Name = "label16";
  586. this.label16.Size = new System.Drawing.Size(0, 12);
  587. this.label16.TabIndex = 2;
  588. //
  589. // label17
  590. //
  591. this.label17.AutoSize = true;
  592. this.label17.Location = new System.Drawing.Point(15, 44);
  593. this.label17.Name = "label17";
  594. this.label17.Size = new System.Drawing.Size(0, 12);
  595. this.label17.TabIndex = 1;
  596. //
  597. // label18
  598. //
  599. this.label18.AutoSize = true;
  600. this.label18.Location = new System.Drawing.Point(15, 20);
  601. this.label18.Name = "label18";
  602. this.label18.Size = new System.Drawing.Size(0, 12);
  603. this.label18.TabIndex = 0;
  604. //
  605. // groupBox8
  606. //
  607. this.groupBox8.Controls.Add(this.label14);
  608. this.groupBox8.Controls.Add(this.label7);
  609. this.groupBox8.Controls.Add(this.label2);
  610. this.groupBox8.Controls.Add(this.label13);
  611. this.groupBox8.Controls.Add(this.label12);
  612. this.groupBox8.Controls.Add(this.label11);
  613. this.groupBox8.Location = new System.Drawing.Point(179, 533);
  614. this.groupBox8.Name = "groupBox8";
  615. this.groupBox8.Size = new System.Drawing.Size(353, 53);
  616. this.groupBox8.TabIndex = 43;
  617. this.groupBox8.TabStop = false;
  618. //
  619. // label14
  620. //
  621. this.label14.AutoSize = true;
  622. this.label14.Location = new System.Drawing.Point(243, 32);
  623. this.label14.Name = "label14";
  624. this.label14.Size = new System.Drawing.Size(0, 12);
  625. this.label14.TabIndex = 11;
  626. //
  627. // label7
  628. //
  629. this.label7.AutoSize = true;
  630. this.label7.Location = new System.Drawing.Point(86, 32);
  631. this.label7.Name = "label7";
  632. this.label7.Size = new System.Drawing.Size(0, 12);
  633. this.label7.TabIndex = 10;
  634. //
  635. // label2
  636. //
  637. this.label2.AutoSize = true;
  638. this.label2.Location = new System.Drawing.Point(135, 15);
  639. this.label2.Name = "label2";
  640. this.label2.Size = new System.Drawing.Size(0, 12);
  641. this.label2.TabIndex = 9;
  642. //
  643. // label13
  644. //
  645. this.label13.AutoSize = true;
  646. this.label13.Location = new System.Drawing.Point(172, 32);
  647. this.label13.Name = "label13";
  648. this.label13.Size = new System.Drawing.Size(0, 12);
  649. this.label13.TabIndex = 8;
  650. //
  651. // label12
  652. //
  653. this.label12.AutoSize = true;
  654. this.label12.Location = new System.Drawing.Point(15, 32);
  655. this.label12.Name = "label12";
  656. this.label12.Size = new System.Drawing.Size(0, 12);
  657. this.label12.TabIndex = 7;
  658. //
  659. // label11
  660. //
  661. this.label11.AutoSize = true;
  662. this.label11.Location = new System.Drawing.Point(16, 15);
  663. this.label11.Name = "label11";
  664. this.label11.Size = new System.Drawing.Size(0, 12);
  665. this.label11.TabIndex = 6;
  666. //
  667. // TABM1Dialog
  668. //
  669. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  670. this.ClientSize = new System.Drawing.Size(1127, 810);
  671. this.Controls.Add(this.groupBox8);
  672. this.Controls.Add(this.groupBox10);
  673. this.Controls.Add(this.groupBox6);
  674. this.Controls.Add(this.groupBox7);
  675. this.Controls.Add(this.groupBox_Basicoperation);
  676. this.Name = "TABM1Dialog";
  677. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TABM1Dialog_FormClosing);
  678. this.Controls.SetChildIndex(this.groupBox_img, 0);
  679. this.Controls.SetChildIndex(this.groupBox_review, 0);
  680. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  681. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  682. this.Controls.SetChildIndex(this.groupBox_report, 0);
  683. this.Controls.SetChildIndex(this.groupBox_Basicoperation, 0);
  684. this.Controls.SetChildIndex(this.groupBox7, 0);
  685. this.Controls.SetChildIndex(this.groupBox6, 0);
  686. this.Controls.SetChildIndex(this.groupBox10, 0);
  687. this.Controls.SetChildIndex(this.groupBox8, 0);
  688. this.groupBox_img.ResumeLayout(false);
  689. this.groupBox_report.ResumeLayout(false);
  690. this.groupBox_report.PerformLayout();
  691. this.groupBox_analysisResult1.ResumeLayout(false);
  692. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
  693. this.groupBox_Basicoperation.ResumeLayout(false);
  694. this.groupBox10.ResumeLayout(false);
  695. this.groupBox10.PerformLayout();
  696. ((System.ComponentModel.ISupportInitialize)(this.trackBar5)).EndInit();
  697. this.groupBox6.ResumeLayout(false);
  698. this.groupBox6.PerformLayout();
  699. ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit();
  700. this.groupBox7.ResumeLayout(false);
  701. this.groupBox7.PerformLayout();
  702. ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
  703. this.groupBox8.ResumeLayout(false);
  704. this.groupBox8.PerformLayout();
  705. this.ResumeLayout(false);
  706. }
  707. #endregion 初始化组件和实现组件事件
  708. #region 需继承的一部分方法
  709. protected override void drawSubclass(Graphics graphics)
  710. {
  711. if (vlines.Count() > 0)
  712. {
  713. Pen bluePen = new Pen(this.panel4.BackColor, this.trackBar3.Value);
  714. int index = 0;
  715. Font myFont = new Font("宋体", 12);
  716. Brush bush = new SolidBrush(this.panel4.BackColor);//填充的颜色
  717. foreach (Line temp in vlines)
  718. {
  719. graphics.DrawLine(bluePen, temp.startPoint, temp.endPoint);
  720. graphics.DrawString("" + (++index), myFont, bush, temp.endPoint.X - 1 + this.trackBar3.Value / 2, temp.endPoint.Y - 16 - this.trackBar4.Value / 2);
  721. }
  722. }
  723. if (tempLine != null && tempLine.Length > 0/* && !bcOriginChecked()*/)//###19575 【用户反馈】点击显示原图后,二值化和绘制轮廓功能都取消了,需要显示原图功能为在原图和处理好的图片之间可以进行相互的切换
  724. {
  725. Pen lineColor = new Pen(this.panel1.BackColor, this.trackBar5.Value);
  726. for (int index = 0; index < tempLine.Length; index++)
  727. {
  728. System.Drawing.Point[] tempLine1 = tempLine[index];
  729. graphics.DrawLines(lineColor, tempLine1);
  730. }
  731. }
  732. //###19400 【客户反馈】专用分析-钛合金,平均涂层厚度,基线的涂层显示在最上边
  733. //画笔
  734. Pen yellowPen = new Pen(this.panel3.BackColor, this.trackBar4.Value);
  735. if (line == null)
  736. {
  737. btnflag = 0;
  738. //System.Drawing.Point point1 = new System.Drawing.Point(0, lab1Img.Height - 130);
  739. //System.Drawing.Point point2 = new System.Drawing.Point(lab1Img.Width, lab1Img.Height - 130);
  740. //line = new Line(point1, point2);
  741. //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  742. }
  743. else
  744. {
  745. if (btnflag == 0)
  746. btnflag = 1;
  747. graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  748. }
  749. }
  750. //数据库的name(报告模板)
  751. protected override string getTemplateName()
  752. {
  753. return "Template.Manager.item3.TitaniumAlloyBio1Method";
  754. }
  755. //语言包的name(项目工程)
  756. protected override string getProjectEngineeringName()
  757. {
  758. return "Menu.DedicatedAnalysis.NonferrousMetal.TitaniumAlloyBiomaterial.Text";
  759. }
  760. protected override void SubclassInitialize()
  761. {
  762. InitializeComponent();
  763. InitializeLanguageText();
  764. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  765. this.panel3.Click += new System.EventHandler(this.panel1_Click);
  766. this.panel4.Click += new System.EventHandler(this.panel1_Click);
  767. }
  768. //切换图片时控制前一张图的信息不遗留显示
  769. protected override void refreshWhileImgChanged()
  770. {
  771. this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  772. calculate1d = false;
  773. this.label2.Text = "";
  774. this.label7.Text = "";
  775. this.label14.Text = "";
  776. vlines.Clear();
  777. if (line != null)
  778. {
  779. btnflag = 0;
  780. line = null;
  781. }
  782. tempLine = new System.Drawing.Point[][] { };
  783. //if (this.documentWorkspace.PhaseModels.Count() == 0 || this.documentWorkspace.PhaseModels[0].mat == null || !this.documentWorkspace.PhaseModels[0].choise)
  784. //{
  785. // binaryClass.performClickBinaryCheck(false);
  786. //}
  787. this.grayBitmap = false;
  788. if (this.bitmap == null)
  789. {
  790. return;
  791. }
  792. if (textBoxChanged == 1)
  793. {
  794. textBoxChanged = -1;
  795. return;
  796. }
  797. if (string.IsNullOrWhiteSpace(this.textBox6.Text) || textBox6.Text == "")
  798. {
  799. return;
  800. }
  801. int w;
  802. try
  803. {
  804. w = int.Parse(this.textBox6.Text);
  805. textBoxChanged = 2;
  806. }
  807. catch (Exception b)
  808. {
  809. MessageBox.Show(b.Message);
  810. return;
  811. }
  812. int per_w = (int)((this.bitmap/*lab1Img*/.Width / Math.Max(1, (w + 1))) * physical_length);
  813. textBox4.Text = per_w.ToString();
  814. }
  815. #endregion
  816. #region 基础操作
  817. /// <summary>
  818. /// 灰度化
  819. /// </summary>
  820. /// <param name="sender"></param>
  821. /// <param name="e"></param>
  822. private void button4_Click(object sender, EventArgs e)
  823. {
  824. if (this.bitmap == null)
  825. {
  826. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  827. return;
  828. }
  829. if (this.grayBitmap) {
  830. MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
  831. return;
  832. }
  833. this.grayBitmap = true;
  834. Mat lab1Img = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);
  835. if (lab1Img.Type() != MatType.CV_8UC1)
  836. {
  837. lab1Img = lab1Img.CvtColor(ColorConversionCodes.BGR2GRAY);
  838. Bitmap bitmap2 = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
  839. Document document = Document.FromImage(bitmap2);
  840. this.documentWorkspace.Document = document;
  841. }
  842. else
  843. MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
  844. lab1Img.Dispose();
  845. lab1Img = null;
  846. }
  847. /// <summary>
  848. /// 腐蚀
  849. /// </summary>
  850. /// <param name="sender"></param>
  851. /// <param name="e"></param>
  852. private void button3_Click(object sender, EventArgs e)
  853. {
  854. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
  855. || this.documentWorkspace.PhaseModels[0].mat == null)
  856. {
  857. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  858. return;
  859. }
  860. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  861. Cv2.Erode(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
  862. this.documentWorkspace.PhaseModels[0].mat = lab1Img;
  863. this.documentWorkspace.Refresh();
  864. }
  865. /// <summary>
  866. /// 膨胀
  867. /// </summary>
  868. /// <param name="sender"></param>
  869. /// <param name="e"></param>
  870. private void button10_Click(object sender, EventArgs e)
  871. {
  872. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
  873. || this.documentWorkspace.PhaseModels[0].mat == null)
  874. {
  875. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  876. return;
  877. }
  878. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  879. Cv2.Dilate(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
  880. this.documentWorkspace.PhaseModels[0].mat = lab1Img;
  881. this.documentWorkspace.Refresh();
  882. }
  883. /// <summary>
  884. /// 寻找轮廓
  885. /// </summary>
  886. /// <param name="sender"></param>
  887. /// <param name="e"></param>
  888. private void button15_Click(object sender, EventArgs e)
  889. {
  890. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise/* //###21424 */
  891. || this.documentWorkspace.PhaseModels[0].mat == null)
  892. {
  893. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  894. return;
  895. }
  896. Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
  897. bool findTempLineSuccess;
  898. int Rows = analyzeMat.Rows;
  899. int Cols = analyzeMat.Cols;
  900. int[] point = new int[2];
  901. List<System.Drawing.Point> tempPointList = new List<System.Drawing.Point>();
  902. //多通道图像的格式化
  903. for (point[1] = 0; point[1] < Cols; point[1]++)
  904. {
  905. findTempLineSuccess = false;
  906. for (point[0] = 1; point[0] < Rows; point[0]++)
  907. {
  908. if (analyzeMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  909. {
  910. tempPointList.Add(new System.Drawing.Point(point[1], point[0]));
  911. findTempLineSuccess = true;//找到了最上边的交点
  912. break;
  913. }
  914. }
  915. if (!findTempLineSuccess)//如果没有找到最上边的交点,设置交点为图像的最高点
  916. {
  917. point[0] = 0;
  918. tempPointList.Add(new System.Drawing.Point(point[1], point[0]));
  919. }
  920. }
  921. tempLine = new System.Drawing.Point[][] { tempPointList.ToArray() };
  922. this.documentWorkspace.Refresh();
  923. }
  924. /// <summary>
  925. /// 自动调整
  926. /// </summary>
  927. /// <param name="sender"></param>
  928. /// <param name="e"></param>
  929. private void button17_Click(object sender, EventArgs e)
  930. {
  931. if (this.documentWorkspace.PhaseModels.Count < 1/* || !this.documentWorkspace.PhaseModels[0].choise*/
  932. || this.documentWorkspace.PhaseModels[0].mat == null)
  933. {
  934. binaryClass.performClickBinaryCheck(true);
  935. }
  936. this.button15.PerformClick();
  937. }
  938. /// <summary>
  939. /// 绘制辅助线
  940. /// </summary>
  941. /// <param name="sender"></param>
  942. /// <param name="e"></param>
  943. private void button13_Click(object sender, EventArgs e)
  944. {
  945. if (!(tempLine != null && tempLine.Length > 0))
  946. {
  947. MessageBox.Show(PdnResources.GetString("Menu.Pleaseclicktodrawtheoutlinefirst.text"));
  948. return;
  949. }
  950. //this.showPhaseMat();
  951. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  952. if (lab1Img != null)// && line == null
  953. {
  954. if (string.IsNullOrWhiteSpace(this.textBox4.Text) || textBox4.Text == "")
  955. {
  956. MessageBox.Show(PdnResources.GetString("Menu.Pleaseentertheauxiliarylinespacingfirst.text"));
  957. return;
  958. }
  959. //if (string.IsNullOrWhiteSpace(this.textBox2.Text) || textBox2.Text == "")
  960. //{
  961. // return;
  962. //}
  963. int per_w;
  964. try
  965. {
  966. per_w = (int)(float.Parse(this.textBox4.Text) / physical_length);
  967. }
  968. catch (Exception b)
  969. {
  970. MessageBox.Show(b.Message);
  971. return;
  972. }
  973. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  974. if (line == null)
  975. {
  976. btnflag = 1;
  977. System.Drawing.Point point1 = new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130);
  978. System.Drawing.Point point2 = new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130);
  979. line = new Line(point1, point2);
  980. //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  981. }
  982. //画均匀垂直于基体平行线的线
  983. int y = lineNum = line.endPoint.Y;
  984. //trackBar1.Value = lineNum;
  985. int w = (lab1Img.Width / per_w) - 1;
  986. w = Math.Max(1, w);
  987. //textBox4.Text = w.ToString();//##条数XXXXXXXXXXX//0914###18438
  988. vlines.Clear();
  989. for (int i = 0; i < w; i++)
  990. {
  991. int temp_y = -1;
  992. //找轮廓内所有跟线的x相交的点,取y最大(//###################最小)的值进行计算
  993. for (int n = 0; n < tempLine.Length; n++)
  994. {
  995. System.Drawing.Point[] pointsL = tempLine[n];
  996. for (int m = 0; m < pointsL.Length; m++)
  997. {
  998. if (pointsL[m].X == per_w * (i + 1))
  999. {
  1000. if (temp_y == -1)
  1001. {
  1002. temp_y = pointsL[m].Y;
  1003. }
  1004. else
  1005. {
  1006. if (pointsL[m].Y < temp_y)
  1007. {
  1008. temp_y = pointsL[m].Y;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. }
  1014. System.Drawing.Point tpoint1 = new System.Drawing.Point(per_w * (i + 1), temp_y);
  1015. System.Drawing.Point tpoint2 = new System.Drawing.Point(per_w * (i + 1), y);
  1016. Line temp = new Line(tpoint1, tpoint2);
  1017. vlines.Add(temp);
  1018. }
  1019. int w11 = vlines.Count();// (this.bitmap/*lab1Img*/.Width / per_w) - 1;
  1020. w11 = Math.Max(1, w11);
  1021. textBox6.Text = w11.ToString();//0914###18438//#########################这个是遗留的深层问题,后续优化。
  1022. this.documentWorkspace.Refresh();
  1023. //calculated = false;
  1024. //pictureBox1.Image = this.bitmap;// map;//#####
  1025. }
  1026. else
  1027. {
  1028. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  1029. }
  1030. }
  1031. /// <summary>
  1032. /// 重置
  1033. /// </summary>
  1034. /// <param name="sender"></param>
  1035. /// <param name="e"></param>
  1036. private void button5_Click(object sender, EventArgs e)
  1037. {
  1038. if (this.bitmap == null)
  1039. {
  1040. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  1041. return;
  1042. }
  1043. calculate1d = false;
  1044. this.label2.Text = "";
  1045. this.label7.Text = "";
  1046. this.label14.Text = "";
  1047. vlines.Clear();
  1048. if (line == null)
  1049. {
  1050. }
  1051. else
  1052. {
  1053. btnflag = 0;
  1054. line = null;
  1055. }
  1056. tempLine = new System.Drawing.Point[][] { };
  1057. if (this.documentWorkspace.PhaseModels.Count() > 0)
  1058. {
  1059. this.documentWorkspace.PhaseModels[0].mat = null;
  1060. }
  1061. this.documentWorkspace.PhaseModels[0].choise = false;
  1062. binaryClass.performClickBinaryCheck(false);
  1063. //this.checkBox10.Checked = false;//PdnResources.GetString("Menu.Binarization.text");//####################
  1064. this.grayBitmap = false;
  1065. Document document = Document.FromImage(this.bitmap);
  1066. this.documentWorkspace.Document = document;
  1067. }
  1068. /// <summary>
  1069. /// 修改轮廓
  1070. /// </summary>
  1071. /// <param name="sender"></param>
  1072. /// <param name="e"></param>
  1073. private void button14_Click(object sender, EventArgs e)
  1074. {
  1075. if (!(tempLine != null && tempLine.Length > 0))
  1076. {
  1077. MessageBox.Show(PdnResources.GetString("Menu.Pleaseclicktodrawtheoutlinefirst.text"));
  1078. //MessageBox.Show("请先进行寻找轮廓操作"/*PdnResources.GetString("Menu.Pleaseperformuctionfirst.text")*/);
  1079. return;
  1080. }
  1081. IntegrationClass.MetalsBoundaryEditingDialog boundaryEditingDialog = new IntegrationClass.MetalsBoundaryEditingDialog(this.appWorkspace, this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index, this.panel1.BackColor
  1082. , tempLine.ToList());
  1083. if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
  1084. {
  1085. tempLine = boundaryEditingDialog.AnalyzePoints.ToArray();
  1086. this.documentWorkspace.Refresh();
  1087. }
  1088. }
  1089. #endregion 基础操作
  1090. #region 控件监听事件
  1091. /// <summary>
  1092. /// 相颜色点击事件
  1093. /// </summary>
  1094. /// <param name="sender"></param>
  1095. /// <param name="e"></param>
  1096. private void panelC_Click(object sender, EventArgs e)
  1097. {
  1098. //this.panelC = (Panel)sender;
  1099. //this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
  1100. //this.colorsFormGrid.ShowDialog();
  1101. }
  1102. ///// <summary>
  1103. ///// PanelC的调色板颜色改变
  1104. ///// </summary>
  1105. ///// <param name="sender"></param>
  1106. ///// <param name="e"></param>
  1107. //private void gridColorChanged(object sender, EventArgs e)
  1108. //{
  1109. // Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  1110. // //更改背景色,触发事件
  1111. // this.panelC.BackColor = color;
  1112. // this.documentWorkspace.Refresh();
  1113. // //关闭色板
  1114. // this.colorsFormGrid.Close();
  1115. //}
  1116. /// <summary>
  1117. /// 线宽条控件改变事件
  1118. /// </summary>
  1119. /// <param name="sender"></param>
  1120. /// <param name="e"></param>
  1121. private void trackBar5_ValueChanged(object sender, EventArgs e)
  1122. {
  1123. this.documentWorkspace.Refresh();
  1124. }
  1125. private void trackBar5_Scroll(object sender, EventArgs e)
  1126. {
  1127. this.textBox9.Text = "" + this.trackBar5.Value;
  1128. }
  1129. private void trackBar4_Scroll(object sender, EventArgs e)
  1130. {
  1131. this.textBox10.Text = "" + this.trackBar4.Value;
  1132. }
  1133. private void trackBar3_Scroll(object sender, EventArgs e)
  1134. {
  1135. this.textBox3.Text = "" + this.trackBar3.Value;
  1136. }
  1137. /// <summary>
  1138. /// 线宽输入框 对输入值做限制
  1139. /// </summary>
  1140. /// <param name="sender"></param>
  1141. private void varifyTextBoxValue(object sender)
  1142. {
  1143. if (string.IsNullOrEmpty(((TextBox)sender)/*this.textBox2*/.Text))
  1144. ((TextBox)sender)/*this.textBox2*/.Text = "1";
  1145. if (Convert.ToInt32(((TextBox)sender)/*this.textBox2*/.Text) > 50)
  1146. ((TextBox)sender)/*this.textBox2*/.Text = "50";
  1147. }
  1148. /// <summary>
  1149. /// 限制只可以输入0-9数字以及退格键
  1150. /// </summary>
  1151. /// <param name="sender"></param>
  1152. /// <param name="e"></param>
  1153. private void textBoxWidth_KeyPress(object sender, KeyPressEventArgs e)
  1154. {
  1155. if (e.KeyChar != '\b')//这是允许输入退格键 
  1156.             {
  1157. int len = ((TextBox)sender)/*this.textBox1*/.Text.Length;
  1158. if (len < 1 && e.KeyChar == '0')
  1159. {
  1160. e.Handled = true;
  1161. }
  1162. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  1163.                 {
  1164. e.Handled = true;
  1165. }
  1166. }
  1167. }
  1168. private void textBox9_KeyUp(object sender, KeyEventArgs e)
  1169. {
  1170. this.varifyTextBoxValue(sender);
  1171. this.trackBar5.Value = Convert.ToInt32(this.textBox9.Text);
  1172. }
  1173. private void textBox10_KeyUp(object sender, KeyEventArgs e)
  1174. {
  1175. this.varifyTextBoxValue(sender);
  1176. this.trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
  1177. }
  1178. private void textBox3_KeyUp(object sender, KeyEventArgs e)
  1179. {
  1180. this.varifyTextBoxValue(sender);
  1181. this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1182. }
  1183. /// <summary>
  1184. /// 记录输入文字改变的状态
  1185. /// </summary>
  1186. int textBoxChanged = -1;
  1187. /// <summary>
  1188. /// 辅助线间距改变
  1189. /// </summary>
  1190. /// <param name="sender"></param>
  1191. /// <param name="e"></param>
  1192. private void textBox4_TextChanged(object sender, EventArgs e)
  1193. {
  1194. }
  1195. /// <summary>
  1196. /// 辅助线数量改变
  1197. /// </summary>
  1198. /// <param name="sender"></param>
  1199. /// <param name="e"></param>
  1200. private void textBox6_TextChanged(object sender, EventArgs e)
  1201. {
  1202. }
  1203. #endregion 控件监听事件
  1204. #region 矩形拖动
  1205. /// <summary>
  1206. /// 鼠标按下
  1207. /// </summary>
  1208. /// <param name="drawArea"></param>
  1209. /// <param name="e"></param>
  1210. protected override void OnMouseDown(object sender, MouseEventArgs e)
  1211. {
  1212. if (!CanUseMouseFunctions())
  1213. return;
  1214. if (btnflag == 1)
  1215. {
  1216. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1217. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
  1218. if (mouse_y < line.startPoint.Y + 10 && mouse_y > line.startPoint.Y - 10)
  1219. {
  1220. //移动基体
  1221. btnflag = 2;//已经按下
  1222. this.documentWorkspace/*pictureBox1*/.Cursor = Cursors.SizeNS;
  1223. }
  1224. }
  1225. }
  1226. /// <summary>
  1227. /// 移动
  1228. /// </summary>
  1229. /// <param name="sender"></param>
  1230. /// <param name="e"></param>
  1231. protected override void onMouseMove(object sender, MouseEventArgs e)
  1232. {
  1233. if (!CanUseMouseFunctions())
  1234. return;
  1235. if (btnflag == 2)
  1236. {
  1237. //Mat ImageROI = null;
  1238. try
  1239. {
  1240. if (line == null)
  1241. {
  1242. btnflag = 1;
  1243. System.Drawing.Point point1 = new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130);
  1244. System.Drawing.Point point2 = new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130);
  1245. line = new Line(point1, point2);
  1246. //graphics.DrawLine(yellowPen, line.startPoint, line.endPoint);
  1247. }
  1248. //float mouse_y = ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
  1249. //mouse_y = Math.Min(lab1Img.Height - 10, mouse_y);
  1250. //mouse_y = Math.Max(10, mouse_y);
  1251. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1252. //移动基体
  1253. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1254. line.startPoint.Y = (int)point.Y;// mouse_y;
  1255. line.endPoint.Y = (int)point.Y;// mouse_y;
  1256. //drawg.DrawLine(yellowPen, line.startPoint, line.endPoint);
  1257. //pictureBox1.Image = map;
  1258. this.documentWorkspace.Refresh();
  1259. }
  1260. catch
  1261. {
  1262. }
  1263. finally
  1264. {
  1265. //ImageROI.Dispose();
  1266. //GC.Collect();
  1267. }
  1268. return;
  1269. }
  1270. if (btnflag == 1)
  1271. {
  1272. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1273. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12/*12*/) * zoom - imgY);
  1274. if (mouse_y < line.startPoint.Y + 10 && mouse_y > line.startPoint.Y - 10)
  1275. {
  1276. this.documentWorkspace.Cursor = Cursors.SizeNS;
  1277. //pictureBox1.Cursor = Cursors.SizeNS;
  1278. }
  1279. else
  1280. {
  1281. this.documentWorkspace.Cursor = Cursors.Default;
  1282. ////图片平移,在MouseMove处添加拖动函数操作
  1283. //if (isSelected && IsMouseInPanel()) //确定已经激发MouseDown事件,和鼠标在picturebox的范围内
  1284. //{
  1285. // this.pictureBox1.Left = this.pictureBox1.Left + (Cursor.Position.X - mouseDownPoint.X);
  1286. // this.pictureBox1.Top = this.pictureBox1.Top + (Cursor.Position.Y - mouseDownPoint.Y);
  1287. // mouseDownPoint.X = Cursor.Position.X;
  1288. // mouseDownPoint.Y = Cursor.Position.Y;
  1289. //}
  1290. //else
  1291. //{
  1292. // pictureBox1.Cursor = Cursors.Default;
  1293. //}
  1294. }
  1295. }
  1296. }
  1297. /// <summary>
  1298. /// 鼠标抬起
  1299. /// </summary>
  1300. /// <param name="sender"></param>
  1301. /// <param name="e"></param>
  1302. protected override void onMouseUp(object sender, MouseEventArgs e)
  1303. {
  1304. if (!CanUseMouseFunctions())
  1305. return;
  1306. if (btnflag == 2)
  1307. {
  1308. btnflag = 1;
  1309. }
  1310. }
  1311. #endregion
  1312. #region 分析结果的方法
  1313. /// <summary>
  1314. /// 点击保存结果按钮,用来返回需要新增的一行数据
  1315. /// </summary>
  1316. /// <param name="tag"></param>
  1317. /// <param name="imgName"></param>
  1318. /// <returns></returns>
  1319. protected override DataTable toInsertTableRow(string tag, string imgName)
  1320. {
  1321. DataTable dt = new DataTable(tag);
  1322. dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
  1323. dt.Columns.Add(PdnResources.GetString("Menu.Averagethickness(μm).text"));
  1324. dt.Columns.Add(PdnResources.GetString("Menu.standarddeviation.text"));
  1325. dt.Columns.Add(PdnResources.GetString("Menu.confidencebound.text"));
  1326. DataRow dataRow = dt.NewRow();
  1327. dataRow[PdnResources.GetString("Menu.picture.Text")] = imgName;
  1328. dataRow[PdnResources.GetString("Menu.Averagethickness(μm).text")] = res_perL;
  1329. dataRow[PdnResources.GetString("Menu.standarddeviation.text")] = res_s1;
  1330. dataRow[PdnResources.GetString("Menu.confidencebound.text")] = res_c1;
  1331. dt.Rows.Add(dataRow);
  1332. return dt;
  1333. }
  1334. /// <summary>
  1335. /// 计算结果是否存在
  1336. /// </summary>
  1337. /// <returns>返回是否可以计算和保存结果</returns>
  1338. protected override bool resultCalculateExist()
  1339. {
  1340. return vlines.Count > 0;
  1341. }
  1342. /// <summary>
  1343. /// 拼接中间数据
  1344. /// </summary>
  1345. /// <returns></returns>
  1346. protected override List<List<string>> buildTempDataList()
  1347. {
  1348. List<List<string>> dataList = new List<List<string>>();
  1349. List<string> columnName = new List<string>();
  1350. columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  1351. columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.Xoordinate.Text"));
  1352. columnName.Add(PdnResources.GetString("Menu.ToYcoordinate.Text"));
  1353. columnName.Add(PdnResources.GetString("Menu.ToYcoonate.Text"));
  1354. columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text"));
  1355. columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
  1356. dataList.Add(columnName);
  1357. int index = 0;
  1358. ////厚度的数组
  1359. //int[] thickness = new int[vlines.Count()];
  1360. //循环辅助线的集合
  1361. if (this.vlines.Count > 0)
  1362. {
  1363. //循环每条线,找到和轮廓的交点
  1364. for (int i = 0; i < vlines.Count(); i++)
  1365. {
  1366. ////计算厚度,像素
  1367. //thickness[i] = lineNum - vlines[i].startPoint.Y;
  1368. List<string> strList = new List<string>();
  1369. strList.Add((++index).ToString());
  1370. strList.Add(vlines[i].startPoint.X.ToString());
  1371. strList.Add(vlines[i].startPoint.Y.ToString());
  1372. strList.Add(lineNum.ToString());
  1373. strList.Add((lineNum - vlines[i].startPoint.Y).ToString());
  1374. strList.Add(((lineNum - vlines[i].startPoint.Y) * physical_length).ToString());
  1375. dataList.Add(strList);
  1376. }
  1377. }
  1378. return dataList;
  1379. }
  1380. /// <summary>
  1381. /// 计算结果
  1382. /// </summary>
  1383. /// <param name="sender"></param>
  1384. /// <param name="e"></param>
  1385. protected override void buttonCalculate_Click(object sender, EventArgs e)
  1386. {
  1387. if (!resultCalculateExist())
  1388. {
  1389. MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
  1390. return;
  1391. }
  1392. //厚度的数组
  1393. int[] thickness = new int[vlines.Count()];
  1394. //循环每条线,找到和轮廓的交点
  1395. for (int i = 0; i < vlines.Count(); i++)
  1396. {
  1397. //计算厚度,像素
  1398. thickness[i] = lineNum - vlines[i].startPoint.Y;
  1399. }
  1400. //平均涂层厚度
  1401. res_perL = thickness.Sum() * physical_length / Math.Max(1, thickness.Length);//考虑使用 thickness.Average
  1402. //计算偏差
  1403. double sqrtSum = 0;
  1404. for (int i = 0; i < vlines.Count(); i++)
  1405. {
  1406. sqrtSum += Math.Pow(thickness[i] * physical_length - res_perL, 2.0);
  1407. }
  1408. //标准偏差
  1409. res_s1 = Math.Sqrt(sqrtSum / Math.Max(1, vlines.Count() - 1));
  1410. //置信区间
  1411. res_c1 = 2 * res_s1 / Math.Sqrt(Math.Max(1, vlines.Count()));
  1412. this.label2.Text = this.resShow(res_perL.ToString());
  1413. this.label7.Text = this.resShow(res_s1.ToString());
  1414. this.label14.Text = this.resShow(res_c1.ToString());
  1415. calculate1d = true;
  1416. }
  1417. /// <summary>
  1418. /// 小数点位数变化时刷新界面的数据
  1419. /// </summary>
  1420. protected override void RefreshDataGridView1()
  1421. {
  1422. if (calculate1d)
  1423. {
  1424. this.label2.Text = this.resShow(res_perL.ToString());
  1425. this.label7.Text = this.resShow(res_s1.ToString());
  1426. this.label14.Text = this.resShow(res_c1.ToString());
  1427. }
  1428. }
  1429. #endregion 分析结果的方法
  1430. #region 参数保存及提取
  1431. /// <summary>
  1432. /// 保存参数的key,value和type
  1433. /// </summary>
  1434. /// <param name="param_key"></param>
  1435. /// <param name="param_value"></param>
  1436. /// <param name="param_type"></param>
  1437. private void saveParamValue(string param_key, string param_value, int param_type)
  1438. {
  1439. bool foundItem = false;
  1440. foreach (var item in this.analysisModel.ListParam)
  1441. {
  1442. if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
  1443. {
  1444. item.param_value = param_value;
  1445. item.setValue();
  1446. foundItem = true;
  1447. break;
  1448. }
  1449. }
  1450. if (!foundItem)
  1451. {
  1452. GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
  1453. analysisItem.menuId = this.menuId;
  1454. analysisItem.param_key = param_key;
  1455. analysisItem.param_type = param_type;
  1456. analysisItem.param_value = param_value;
  1457. analysisItem.setValue();
  1458. this.analysisModel.ListParam.Add(analysisItem);
  1459. }
  1460. }
  1461. /// <summary>
  1462. /// 保存界面中的参数到model
  1463. /// </summary>
  1464. private void saveDialogParamValues()
  1465. {
  1466. saveParamValue(ParamKey_Report, checkBox_generateReport_opensetting.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//报告设置
  1467. saveParamValue(ParamKey_OutlineColour, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//轮廓颜色
  1468. saveParamValue(ParamKey_OutlineWidth, textBox9.Text, (int)Base.Dtryt.ItemString);//轮廓线宽
  1469. saveParamValue(ParamKey_BaseColour, panel3.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//基线颜色
  1470. saveParamValue(ParamKey_BaseWidth, textBox10.Text, (int)Base.Dtryt.ItemString);//基线线宽
  1471. saveParamValue(ParamKey_GuideColour, panel4.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//辅助线颜色
  1472. saveParamValue(ParamKey_GuideWidth, textBox3.Text, (int)Base.Dtryt.ItemString);//辅助线线宽
  1473. saveParamValue(ParamKey_GuideNumber, textBox6.Text, (int)Base.Dtryt.ItemString);//辅助线条数
  1474. saveParamValue(ParamKey_DecimalPlace, numericUpDown1_0 != null ? numericUpDown1_0.Value.ToString() : "", (int)Base.Dtryt.Decimal);//保留小数位数
  1475. }
  1476. /// <summary>
  1477. /// 获取保存的参数
  1478. /// </summary>
  1479. private void GetListParamModel()
  1480. {
  1481. if (this.analysisModel != null)
  1482. {
  1483. for (int i = 0; i < this.analysisModel.ListParam.Count; i++)
  1484. {
  1485. switch (this.analysisModel.ListParam[i].param_key)
  1486. {
  1487. case ParamKey_Report:
  1488. checkBox_generateReport_opensetting.Checked = (Boolean)this.analysisModel.ListParam[i].value;
  1489. break;
  1490. case ParamKey_OutlineColour:
  1491. panel1.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1492. break;
  1493. case ParamKey_OutlineWidth:
  1494. textBox9.Text = this.analysisModel.ListParam[i].value.ToString();
  1495. trackBar5.Value = Convert.ToInt32(this.textBox9.Text);
  1496. break;
  1497. case ParamKey_BaseColour:
  1498. panel3.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1499. break;
  1500. case ParamKey_BaseWidth:
  1501. textBox10.Text = this.analysisModel.ListParam[i].value.ToString();
  1502. trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
  1503. break;
  1504. case ParamKey_GuideColour:
  1505. panel4.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1506. break;
  1507. case ParamKey_GuideWidth:
  1508. textBox3.Text = this.analysisModel.ListParam[i].value.ToString();
  1509. trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1510. break;
  1511. case ParamKey_GuideNumber:
  1512. textBox6.Text = this.analysisModel.ListParam[i].value.ToString();
  1513. break;
  1514. case ParamKey_DecimalPlace:
  1515. numericUpDown1_0.Value = decimal.Parse(this.analysisModel.ListParam[i].param_value);
  1516. break;
  1517. }
  1518. }
  1519. }
  1520. }
  1521. /// <summary>
  1522. /// 关闭窗体时保存参数
  1523. /// </summary>
  1524. /// <param name="sender"></param>
  1525. /// <param name="e"></param>
  1526. private void TABM1Dialog_FormClosing(object sender, FormClosingEventArgs e)
  1527. {
  1528. this.saveDialogParamValues();
  1529. //xml保存路径
  1530. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
  1531. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  1532. foreach (var analysisItem in this.analysisModel.ListParam)
  1533. {
  1534. bool foundItem = false;
  1535. foreach (var item in analysisModelXml.ListParam)
  1536. {
  1537. if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId)
  1538. {
  1539. item.param_value = analysisItem.param_value;
  1540. foundItem = true;
  1541. break;
  1542. }
  1543. }
  1544. if (!foundItem)
  1545. analysisModelXml.ListParam.Add(analysisItem.cloneModel());
  1546. }
  1547. //按路径和名称保存xml文件
  1548. string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
  1549. //保存xml
  1550. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
  1551. }
  1552. #endregion
  1553. private void textBox6_KeyUp(object sender, KeyEventArgs e)
  1554. {
  1555. if (this.bitmap == null)
  1556. {
  1557. return;
  1558. }
  1559. if (textBoxChanged == 1)
  1560. {
  1561. textBoxChanged = -1;
  1562. return;
  1563. }
  1564. if (string.IsNullOrWhiteSpace(this.textBox6.Text) || textBox6.Text == "")
  1565. {
  1566. return;
  1567. }
  1568. int w;
  1569. try
  1570. {
  1571. w = int.Parse(this.textBox6.Text);
  1572. textBoxChanged = 2;
  1573. }
  1574. catch (Exception b)
  1575. {
  1576. MessageBox.Show(b.Message);
  1577. return;
  1578. }
  1579. double per_w = (this.bitmap/*lab1Img*/.Width / Math.Max(1, (w + 1))) * physical_length;
  1580. textBox4.Text = per_w.ToString();
  1581. }
  1582. private void textBox4_KeyUp(object sender, KeyEventArgs e)
  1583. {
  1584. if (this.bitmap == null)
  1585. {
  1586. return;
  1587. }
  1588. if (textBoxChanged == 2 && textBox6.Focused)
  1589. {
  1590. textBoxChanged = -1;
  1591. return;
  1592. }
  1593. if (string.IsNullOrWhiteSpace(this.textBox4.Text) || textBox4.Text == "")
  1594. {
  1595. return;
  1596. }
  1597. try
  1598. {
  1599. int per_w;
  1600. try
  1601. {
  1602. per_w = (int)(float.Parse(this.textBox4.Text) / physical_length);
  1603. textBoxChanged = 1;
  1604. }
  1605. catch (Exception b)
  1606. {
  1607. MessageBox.Show(b.Message);
  1608. return;
  1609. }
  1610. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1611. int w = (this.bitmap/*lab1Img*/.Width / per_w) - 1;
  1612. w = Math.Max(1, w);
  1613. textBox6.Text = w.ToString();
  1614. }
  1615. catch (Exception b)
  1616. {
  1617. MessageBox.Show(b.Message);
  1618. }
  1619. }
  1620. }
  1621. }