TABM3Dialog.cs 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  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 TABM3Dialog : 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. /// 孔隙的mat
  46. /// </summary>
  47. Mat tempHoleMat;
  48. Bitmap tempHoleBitmap;
  49. /// <summary>
  50. /// 定义变量存储鼠标操作状态 1拖动上辅助线 2拖动下辅助线 /* 3拖动平行辅助线*/
  51. /// </summary>
  52. int mouseFlag = 0;
  53. ///// <summary>
  54. ///// 1显示辅助线 2移动辅助线 0隐藏辅助线
  55. ///// </summary>
  56. //int btnflag = 0;
  57. int contoursTop = 0;
  58. ///// <summary>
  59. ///// 辅助线
  60. ///// </summary>
  61. //Line top, bottom;
  62. /// <summary>
  63. /// 下面定义三个变量存储鼠标按下的坐标
  64. /// </summary>
  65. int xPos;
  66. int yPos;
  67. ///// <summary>
  68. ///// 定义变量存储鼠标操作状态 1拖动左辅助线 2拖动右辅助线 3拖动平行辅助线
  69. ///// </summary>
  70. //int mouseFlag = 0;
  71. ///// <summary>
  72. ///// 1显示辅助线 2移动辅助线 0隐藏辅助线
  73. ///// </summary>
  74. //int btnflag = 0;
  75. /// <summary>
  76. /// 左侧辅助线
  77. /// </summary>
  78. Line lineleft;
  79. /// <summary>
  80. /// 右侧辅助线
  81. /// </summary>
  82. Line lineright;
  83. /// <summary>
  84. /// 底部辅助线
  85. /// </summary>
  86. Line linebottom;
  87. /// <summary>
  88. /// 横向辅助线上孔隙的线段集合
  89. /// </summary>
  90. List<Line> honlines = new List<Line>();
  91. /// <summary>
  92. /// 横向辅助线
  93. /// </summary>
  94. List<Line> hlines = new List<Line>();
  95. /// <summary>
  96. /// 总长度
  97. /// </summary>
  98. double res_totalL;
  99. /// <summary>
  100. /// 平均孔隙截距
  101. /// </summary>
  102. double res_perL;
  103. /// <summary>
  104. /// 截点数量
  105. /// </summary>
  106. double res_count;
  107. /// <summary>
  108. /// 选择标尺的物理长度(微米/像素)
  109. /// </summary>
  110. double physical_length = 1;
  111. // <summary>
  112. /// 保存窗口参数
  113. /// </summary>
  114. private GrainSizeAnalysisModel analysisModel;
  115. private const string ParamKey_Report = "report";//报告设置
  116. private const string ParamKey_PoreColour = "poreColour";//孔隙颜色
  117. private const string ParamKey_PoreSpacing = "poreSpacing";//孔隙辅助线间距
  118. private const string ParamKey_GuideColour = "guideColour";//辅助线颜色
  119. private const string ParamKey_GuideWidth = "guideWidth";//辅助线线宽
  120. private const string ParamKey_GuideNumber = "guideNumber";//辅助线条数
  121. private const string ParamKey_GuideSpacing = "guideSpacing";//辅助线间距
  122. private const string ParamKey_PoreSetColour = "poreSetColour";//孔隙设置颜色
  123. private const string ParamKey_PoreSetWidth = "poreSetWidth";//孔隙设置线宽
  124. private const string ParamKey_DecimalPlace = "decimalPlace";//保留小数位数
  125. #endregion 属性
  126. #region 组件
  127. private Button button2;
  128. private GroupBox groupBox10;
  129. private Panel panel1;
  130. private Label label5;
  131. private GroupBox groupBox8;
  132. private Label label14;
  133. private Label label7;
  134. private Label label2;
  135. private Label label13;
  136. private Label label12;
  137. private GroupBox groupBox5;
  138. private Button button14;
  139. private Button button17;
  140. private Button button3;
  141. private Button button15;
  142. private Button button13;
  143. private Button button10;
  144. private Button button4;
  145. private Button button5;
  146. private GroupBox groupBox7;
  147. private Panel panel4;
  148. private TextBox textBox6;
  149. private TextBox textBox4;
  150. private TrackBar trackBar3;
  151. private TextBox textBox3;
  152. private Label label15;
  153. private Label label16;
  154. private Label label17;
  155. private Label label18;
  156. private GroupBox groupBox6;
  157. private Panel panel3;
  158. private TrackBar trackBar4;
  159. private TextBox textBox10;
  160. private Label label4;
  161. private Label label6;
  162. private TextBox textBox1;
  163. private Label label1;
  164. private Label label11;
  165. #endregion 组件
  166. #region 构造函数
  167. public TABM3Dialog(AppWorkspace appWorkspace, int menuId) : base(appWorkspace, menuId)
  168. {
  169. Dictionary<MeasurementUnit, double> measurementUnitDictionary = Startup.instance.rules;
  170. this.physical_length = measurementUnitDictionary[MeasurementUnit.Micron];
  171. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
  172. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  173. this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId);
  174. foreach (var item in this.analysisModel.ListParam)
  175. item.setValue();
  176. ////
  177. ////初始化色板
  178. ////
  179. //this.colorsFormGrid = new ColorsForm();
  180. //this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  181. //this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  182. GetListParamModel();
  183. InitGridHeader();
  184. }
  185. /// <summary>
  186. /// 初始化表头
  187. /// </summary>
  188. private void InitGridHeader()
  189. {
  190. DataGridViewTextBoxColumn Column2_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  191. DataGridViewTextBoxColumn Column3_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  192. DataGridViewTextBoxColumn Column4_total = new System.Windows.Forms.DataGridViewTextBoxColumn();
  193. Column2_total.Name = "Column2_total";
  194. Column2_total.ReadOnly = true;
  195. Column3_total.Name = "Column3_total";
  196. Column3_total.ReadOnly = true;
  197. Column4_total.Name = "Column4_total";
  198. Column4_total.ReadOnly = true;
  199. Column2_total.HeaderText = PdnResources.GetString("Menu.Totallengthofporeintercepts.text");
  200. Column3_total.HeaderText = PdnResources.GetString("Menu.Meanporeintercept.text");
  201. Column4_total.HeaderText = PdnResources.GetString("Menu.Numberofintercept.text");
  202. this.dataGridView_Total.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  203. Column2_total,
  204. Column3_total,
  205. Column4_total});
  206. this.dataGridView_Total.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  207. this.dataGridView_Total.Columns[0].ReadOnly = true;
  208. this.dataGridView_Total.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  209. this.dataGridView_Total.Columns[1].ReadOnly = true;
  210. this.dataGridView_Total.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  211. this.dataGridView_Total.Columns[2].ReadOnly = true;
  212. DataGridViewTextBoxColumn Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  213. DataGridViewTextBoxColumn Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  214. DataGridViewTextBoxColumn Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  215. DataGridViewTextBoxColumn Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  216. Column1.Name = "Column1";
  217. Column1.ReadOnly = true;
  218. Column2.Name = "Column2";
  219. Column2.ReadOnly = true;
  220. Column3.Name = "Column3";
  221. Column3.ReadOnly = true;
  222. Column4.Name = "Column4";
  223. Column4.ReadOnly = true;
  224. Column1.HeaderText = PdnResources.GetString("Menu.picture.Text");
  225. Column2.HeaderText = PdnResources.GetString("Menu.Totallengthofporeintercepts.text");
  226. Column3.HeaderText = PdnResources.GetString("Menu.Meanporeintercept.text");
  227. Column4.HeaderText = PdnResources.GetString("Menu.Numberofintercept.text");
  228. this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  229. Column1,
  230. Column2,
  231. Column3,
  232. Column4});
  233. Column1.Width = 195;
  234. Column2.Width = 165;
  235. Column3.Width = 165;
  236. Column4.Width = 165;
  237. this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  238. this.dataGridView2.Columns[0].ReadOnly = true;
  239. this.dataGridView2.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  240. this.dataGridView2.Columns[1].ReadOnly = true;
  241. this.dataGridView2.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
  242. this.dataGridView2.Columns[2].ReadOnly = true;
  243. this.dataGridView2.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
  244. this.dataGridView2.Columns[3].ReadOnly = true;
  245. }
  246. #endregion 构造函数
  247. #region 初始化组件和实现组件事件
  248. private void InitializeLanguageText()
  249. {
  250. //this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  251. //this.label19.Text = PdnResources.GetString("Menu.Distancefromtop.text") + ":";
  252. this.groupBox7.Text = PdnResources.GetString("Menu.Auxiliarylinesettings.text");
  253. this.label6.Text = PdnResources.GetString("Menu.color.text") + ":";
  254. this.label4.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  255. this.groupBox6.Text = PdnResources.GetString("Menu.holesetting.text");
  256. this.label5.Text = PdnResources.GetString("Menu.color.text") + ":";
  257. //this.label3.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  258. this.groupBox10.Text = "孔隙";// PdnResources.GetString("Menu.contour.text");
  259. this.button2.Text = PdnResources.GetString("Menu.reinformation.text");
  260. this.button5.Text = PdnResources.GetString("Menu.Image.Grayscale.Text");
  261. this.button4/*button3*/.Text = PdnResources.GetString("Menu.BinaryAction.ErosionExtraction.Text");
  262. this.button10.Text = PdnResources.GetString("Menu.BinaryAction.DilationExtraction.Text");
  263. this.button13.Text = PdnResources.GetString("Menu.Drawauxiliarylines.text");
  264. this.button3.Text = PdnResources.GetString("Menu.reinformation.text");
  265. this.button15.Text = "寻找孔隙";// PdnResources.GetString("Menu.searchcontour.text");
  266. this.button17.Text = PdnResources.GetString("Menu.auto-adjust.text");
  267. this.button14.Text = "修改孔隙";// PdnResources.GetString("Menu.easemodifytheoutline.Text");
  268. //this.button5.Text = PdnResources.GetString("Menu.reinformation.text");
  269. this.groupBox5.Text = PdnResources.GetString("Menu.Basicoperation.text");
  270. this.Text = "YYT 0988.14-2016(" + PdnResources.GetString("Menu.Meanporeintercept.text") + ")";
  271. this.label11.Text = PdnResources.GetString("Menu.Totallengthofporeintercepts.text") + ":";
  272. this.label12.Text = PdnResources.GetString("Menu.Meanporeintercept.text") + ":";
  273. this.label13.Text = PdnResources.GetString("Menu.Numberofintercept.text") + ":";
  274. //this.label11.Text = PdnResources.GetString("Menu.Averagethickness(μm).text") + ":";
  275. //this.label12.Text = PdnResources.GetString("Menu.standarddeviation.text") + ":";
  276. //this.label13.Text = PdnResources.GetString("Menu.confidencebound.text") + ":";
  277. this.groupBox8.Text = PdnResources.GetString("Menu.result.text");
  278. this.label18.Text = PdnResources.GetString("Menu.color.text") + ":";
  279. this.label17.Text = PdnResources.GetString("Menu.Numberof.text") + ":";
  280. this.label16.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  281. this.label15.Text = PdnResources.GetString("Menu.spacing.text") + ":";
  282. this.label1.Text = "辅助线间距";// PdnResources.GetString("Menu.spacing.text") + ":";
  283. }
  284. private void InitializeComponent()
  285. {
  286. this.button2 = new System.Windows.Forms.Button();
  287. this.groupBox10 = new System.Windows.Forms.GroupBox();
  288. this.textBox1 = new System.Windows.Forms.TextBox();
  289. this.label1 = new System.Windows.Forms.Label();
  290. this.panel1 = new System.Windows.Forms.Panel();
  291. this.label5 = new System.Windows.Forms.Label();
  292. this.groupBox8 = new System.Windows.Forms.GroupBox();
  293. this.label14 = new System.Windows.Forms.Label();
  294. this.label7 = new System.Windows.Forms.Label();
  295. this.label2 = new System.Windows.Forms.Label();
  296. this.label13 = new System.Windows.Forms.Label();
  297. this.label12 = new System.Windows.Forms.Label();
  298. this.label11 = new System.Windows.Forms.Label();
  299. this.groupBox5 = new System.Windows.Forms.GroupBox();
  300. this.button14 = new System.Windows.Forms.Button();
  301. this.button17 = new System.Windows.Forms.Button();
  302. this.button3 = new System.Windows.Forms.Button();
  303. this.button15 = new System.Windows.Forms.Button();
  304. this.button13 = new System.Windows.Forms.Button();
  305. this.button10 = new System.Windows.Forms.Button();
  306. this.button4 = new System.Windows.Forms.Button();
  307. this.button5 = new System.Windows.Forms.Button();
  308. this.groupBox7 = new System.Windows.Forms.GroupBox();
  309. this.panel4 = new System.Windows.Forms.Panel();
  310. this.textBox6 = new System.Windows.Forms.TextBox();
  311. this.textBox4 = new System.Windows.Forms.TextBox();
  312. this.trackBar3 = new System.Windows.Forms.TrackBar();
  313. this.textBox3 = new System.Windows.Forms.TextBox();
  314. this.label15 = new System.Windows.Forms.Label();
  315. this.label16 = new System.Windows.Forms.Label();
  316. this.label17 = new System.Windows.Forms.Label();
  317. this.label18 = new System.Windows.Forms.Label();
  318. this.groupBox6 = new System.Windows.Forms.GroupBox();
  319. this.panel3 = new System.Windows.Forms.Panel();
  320. this.trackBar4 = new System.Windows.Forms.TrackBar();
  321. this.textBox10 = new System.Windows.Forms.TextBox();
  322. this.label4 = new System.Windows.Forms.Label();
  323. this.label6 = new System.Windows.Forms.Label();
  324. this.groupBox_img.SuspendLayout();
  325. this.groupBox_report.SuspendLayout();
  326. this.groupBox_analysisResult1.SuspendLayout();
  327. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
  328. this.groupBox10.SuspendLayout();
  329. this.groupBox8.SuspendLayout();
  330. this.groupBox5.SuspendLayout();
  331. this.groupBox7.SuspendLayout();
  332. ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
  333. this.groupBox6.SuspendLayout();
  334. ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
  335. this.SuspendLayout();
  336. //
  337. // button2
  338. //
  339. this.button2.Location = new System.Drawing.Point(96, 39);
  340. this.button2.Name = "button2";
  341. this.button2.Size = new System.Drawing.Size(75, 23);
  342. this.button2.TabIndex = 6;
  343. this.button2.UseVisualStyleBackColor = true;
  344. //
  345. // groupBox10
  346. //
  347. this.groupBox10.Controls.Add(this.textBox1);
  348. this.groupBox10.Controls.Add(this.label1);
  349. this.groupBox10.Controls.Add(this.panel1);
  350. this.groupBox10.Controls.Add(this.label5);
  351. this.groupBox10.Location = new System.Drawing.Point(178, 383);
  352. this.groupBox10.Name = "groupBox10";
  353. this.groupBox10.Size = new System.Drawing.Size(354, 41);
  354. this.groupBox10.TabIndex = 42;
  355. this.groupBox10.TabStop = false;
  356. //
  357. // textBox1
  358. //
  359. this.textBox1.Location = new System.Drawing.Point(246, 15);
  360. this.textBox1.Name = "textBox1";
  361. this.textBox1.Size = new System.Drawing.Size(101, 21);
  362. this.textBox1.TabIndex = 25;
  363. this.textBox1.Text = "100";
  364. this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  365. this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyUp);
  366. //
  367. // label1
  368. //
  369. this.label1.AutoSize = true;
  370. this.label1.Location = new System.Drawing.Point(175, 20);
  371. this.label1.Name = "label1";
  372. this.label1.Size = new System.Drawing.Size(0, 12);
  373. this.label1.TabIndex = 24;
  374. //
  375. // panel1
  376. //
  377. this.panel1.BackColor = System.Drawing.Color.Orange;
  378. this.panel1.Location = new System.Drawing.Point(63, 15);
  379. this.panel1.Name = "panel1";
  380. this.panel1.Size = new System.Drawing.Size(105, 21);
  381. this.panel1.TabIndex = 21;
  382. this.panel1.Click += new System.EventHandler(this.panelC_Click);
  383. //
  384. // label5
  385. //
  386. this.label5.AutoSize = true;
  387. this.label5.Location = new System.Drawing.Point(15, 20);
  388. this.label5.Name = "label5";
  389. this.label5.Size = new System.Drawing.Size(0, 12);
  390. this.label5.TabIndex = 0;
  391. //
  392. // groupBox8
  393. //
  394. this.groupBox8.Controls.Add(this.label14);
  395. this.groupBox8.Controls.Add(this.label7);
  396. this.groupBox8.Controls.Add(this.label2);
  397. this.groupBox8.Controls.Add(this.label13);
  398. this.groupBox8.Controls.Add(this.label12);
  399. this.groupBox8.Controls.Add(this.label11);
  400. this.groupBox8.Location = new System.Drawing.Point(179, 563);
  401. this.groupBox8.Name = "groupBox8";
  402. this.groupBox8.Size = new System.Drawing.Size(353, 53);
  403. this.groupBox8.TabIndex = 43;
  404. this.groupBox8.TabStop = false;
  405. //
  406. // label14
  407. //
  408. this.label14.AutoSize = true;
  409. this.label14.Location = new System.Drawing.Point(243, 32);
  410. this.label14.Name = "label14";
  411. this.label14.Size = new System.Drawing.Size(0, 12);
  412. this.label14.TabIndex = 11;
  413. //
  414. // label7
  415. //
  416. this.label7.AutoSize = true;
  417. this.label7.Location = new System.Drawing.Point(110, 32);
  418. this.label7.Name = "label7";
  419. this.label7.Size = new System.Drawing.Size(0, 12);
  420. this.label7.TabIndex = 10;
  421. //
  422. // label2
  423. //
  424. this.label2.AutoSize = true;
  425. this.label2.Location = new System.Drawing.Point(123, 15);
  426. this.label2.Name = "label2";
  427. this.label2.Size = new System.Drawing.Size(0, 12);
  428. this.label2.TabIndex = 9;
  429. //
  430. // label13
  431. //
  432. this.label13.AutoSize = true;
  433. this.label13.Location = new System.Drawing.Point(172, 32);
  434. this.label13.Name = "label13";
  435. this.label13.Size = new System.Drawing.Size(0, 12);
  436. this.label13.TabIndex = 8;
  437. //
  438. // label12
  439. //
  440. this.label12.AutoSize = true;
  441. this.label12.Location = new System.Drawing.Point(15, 32);
  442. this.label12.Name = "label12";
  443. this.label12.Size = new System.Drawing.Size(0, 12);
  444. this.label12.TabIndex = 7;
  445. //
  446. // label11
  447. //
  448. this.label11.AutoSize = true;
  449. this.label11.Location = new System.Drawing.Point(16, 15);
  450. this.label11.Name = "label11";
  451. this.label11.Size = new System.Drawing.Size(0, 12);
  452. this.label11.TabIndex = 6;
  453. //
  454. // groupBox5
  455. //
  456. this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  457. | System.Windows.Forms.AnchorStyles.Right)));
  458. this.groupBox5.Controls.Add(this.button14);
  459. this.groupBox5.Controls.Add(this.button17);
  460. this.groupBox5.Controls.Add(this.button3);
  461. this.groupBox5.Controls.Add(this.button15);
  462. this.groupBox5.Controls.Add(this.button13);
  463. this.groupBox5.Controls.Add(this.button10);
  464. this.groupBox5.Controls.Add(this.button4);
  465. this.groupBox5.Controls.Add(this.button5);
  466. this.groupBox5.Location = new System.Drawing.Point(180, 317);
  467. this.groupBox5.Name = "groupBox5";
  468. this.groupBox5.Size = new System.Drawing.Size(353, 66);
  469. this.groupBox5.TabIndex = 44;
  470. this.groupBox5.TabStop = false;
  471. //
  472. // button14
  473. //
  474. this.button14.Location = new System.Drawing.Point(267, 40);
  475. this.button14.Name = "button14";
  476. this.button14.Size = new System.Drawing.Size(75, 23);
  477. this.button14.TabIndex = 8;
  478. this.button14.UseVisualStyleBackColor = true;
  479. this.button14.Click += new System.EventHandler(this.button14_Click);
  480. //
  481. // button17
  482. //
  483. this.button17.Location = new System.Drawing.Point(180, 40);
  484. this.button17.Name = "button17";
  485. this.button17.Size = new System.Drawing.Size(75, 23);
  486. this.button17.TabIndex = 7;
  487. this.button17.UseVisualStyleBackColor = true;
  488. this.button17.Click += new System.EventHandler(this.button17_Click);
  489. //
  490. // button3
  491. //
  492. this.button3.Location = new System.Drawing.Point(93, 40);
  493. this.button3.Name = "button3";
  494. this.button3.Size = new System.Drawing.Size(75, 23);
  495. this.button3.TabIndex = 6;
  496. this.button3.UseVisualStyleBackColor = true;
  497. this.button3.Click += new System.EventHandler(this.button3_Click);
  498. //
  499. // button15
  500. //
  501. this.button15.Location = new System.Drawing.Point(267, 15);
  502. this.button15.Name = "button15";
  503. this.button15.Size = new System.Drawing.Size(75, 23);
  504. this.button15.TabIndex = 5;
  505. this.button15.UseVisualStyleBackColor = true;
  506. this.button15.Click += new System.EventHandler(this.button15_Click);
  507. //
  508. // button13
  509. //
  510. this.button13.Location = new System.Drawing.Point(9, 40);
  511. this.button13.Name = "button13";
  512. this.button13.Size = new System.Drawing.Size(75, 23);
  513. this.button13.TabIndex = 3;
  514. this.button13.UseVisualStyleBackColor = true;
  515. this.button13.Click += new System.EventHandler(this.button13_Click);
  516. //
  517. // button10
  518. //
  519. this.button10.Location = new System.Drawing.Point(180, 15);
  520. this.button10.Name = "button10";
  521. this.button10.Size = new System.Drawing.Size(75, 23);
  522. this.button10.TabIndex = 2;
  523. this.button10.UseVisualStyleBackColor = true;
  524. this.button10.Click += new System.EventHandler(this.button10_Click);
  525. //
  526. // button4
  527. //
  528. this.button4.Location = new System.Drawing.Point(93, 15);
  529. this.button4.Name = "button4";
  530. this.button4.Size = new System.Drawing.Size(75, 23);
  531. this.button4.TabIndex = 1;
  532. this.button4.UseVisualStyleBackColor = true;
  533. this.button4.Click += new System.EventHandler(this.button4_Click);
  534. //
  535. // button5
  536. //
  537. this.button5.Location = new System.Drawing.Point(9, 15);
  538. this.button5.Name = "button5";
  539. this.button5.Size = new System.Drawing.Size(75, 23);
  540. this.button5.TabIndex = 0;
  541. this.button5.UseVisualStyleBackColor = true;
  542. this.button5.Click += new System.EventHandler(this.button5_Click);
  543. //
  544. // groupBox7
  545. //
  546. this.groupBox7.Controls.Add(this.panel4);
  547. this.groupBox7.Controls.Add(this.textBox6);
  548. this.groupBox7.Controls.Add(this.textBox4);
  549. this.groupBox7.Controls.Add(this.trackBar3);
  550. this.groupBox7.Controls.Add(this.textBox3);
  551. this.groupBox7.Controls.Add(this.label15);
  552. this.groupBox7.Controls.Add(this.label16);
  553. this.groupBox7.Controls.Add(this.label17);
  554. this.groupBox7.Controls.Add(this.label18);
  555. this.groupBox7.Location = new System.Drawing.Point(179, 430);
  556. this.groupBox7.Name = "groupBox7";
  557. this.groupBox7.Size = new System.Drawing.Size(354, 75);
  558. this.groupBox7.TabIndex = 45;
  559. this.groupBox7.TabStop = false;
  560. //
  561. // panel4
  562. //
  563. this.panel4.BackColor = System.Drawing.Color.Green;
  564. this.panel4.Location = new System.Drawing.Point(62, 17);
  565. this.panel4.Name = "panel4";
  566. this.panel4.Size = new System.Drawing.Size(105, 21);
  567. this.panel4.TabIndex = 23;
  568. this.panel4.Click += new System.EventHandler(this.panelC_Click);
  569. //
  570. // textBox6
  571. //
  572. this.textBox6.Location = new System.Drawing.Point(62, 41);
  573. this.textBox6.Name = "textBox6";
  574. this.textBox6.Size = new System.Drawing.Size(105, 21);
  575. this.textBox6.TabIndex = 10;
  576. this.textBox6.Text = "10";
  577. this.textBox6.TextChanged += new System.EventHandler(this.TextBox6_TextChanged);
  578. //
  579. // textBox4
  580. //
  581. this.textBox4.Location = new System.Drawing.Point(224, 41);
  582. this.textBox4.Name = "textBox4";
  583. this.textBox4.Size = new System.Drawing.Size(121, 21);
  584. this.textBox4.TabIndex = 8;
  585. this.textBox4.Text = "100";
  586. this.textBox4.TextChanged += new System.EventHandler(this.TextBox4_TextChanged);
  587. //
  588. // trackBar3
  589. //
  590. this.trackBar3.AutoSize = false;
  591. this.trackBar3.Cursor = System.Windows.Forms.Cursors.Hand;
  592. this.trackBar3.Location = new System.Drawing.Point(220, 18);
  593. this.trackBar3.Maximum = 50;
  594. this.trackBar3.Minimum = 1;
  595. this.trackBar3.Name = "trackBar3";
  596. this.trackBar3.Size = new System.Drawing.Size(84, 21);
  597. this.trackBar3.TabIndex = 7;
  598. this.trackBar3.TickStyle = System.Windows.Forms.TickStyle.None;
  599. this.trackBar3.Value = 3;
  600. this.trackBar3.Scroll += new System.EventHandler(this.trackBar3_Scroll);
  601. this.trackBar3.ValueChanged += new System.EventHandler(this.trackBar3_ValueChanged);
  602. //
  603. // textBox3
  604. //
  605. this.textBox3.Location = new System.Drawing.Point(310, 17);
  606. this.textBox3.Name = "textBox3";
  607. this.textBox3.Size = new System.Drawing.Size(35, 21);
  608. this.textBox3.TabIndex = 6;
  609. this.textBox3.Text = "3";
  610. this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  611. this.textBox3.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyUp);
  612. //
  613. // label15
  614. //
  615. this.label15.AutoSize = true;
  616. this.label15.Location = new System.Drawing.Point(173, 46);
  617. this.label15.Name = "label15";
  618. this.label15.Size = new System.Drawing.Size(0, 12);
  619. this.label15.TabIndex = 3;
  620. //
  621. // label16
  622. //
  623. this.label16.AutoSize = true;
  624. this.label16.Location = new System.Drawing.Point(173, 22);
  625. this.label16.Name = "label16";
  626. this.label16.Size = new System.Drawing.Size(0, 12);
  627. this.label16.TabIndex = 2;
  628. //
  629. // label17
  630. //
  631. this.label17.AutoSize = true;
  632. this.label17.Location = new System.Drawing.Point(15, 46);
  633. this.label17.Name = "label17";
  634. this.label17.Size = new System.Drawing.Size(0, 12);
  635. this.label17.TabIndex = 1;
  636. //
  637. // label18
  638. //
  639. this.label18.AutoSize = true;
  640. this.label18.Location = new System.Drawing.Point(15, 22);
  641. this.label18.Name = "label18";
  642. this.label18.Size = new System.Drawing.Size(0, 12);
  643. this.label18.TabIndex = 0;
  644. //
  645. // groupBox6
  646. //
  647. this.groupBox6.Controls.Add(this.panel3);
  648. this.groupBox6.Controls.Add(this.trackBar4);
  649. this.groupBox6.Controls.Add(this.textBox10);
  650. this.groupBox6.Controls.Add(this.label4);
  651. this.groupBox6.Controls.Add(this.label6);
  652. this.groupBox6.Location = new System.Drawing.Point(180, 511);
  653. this.groupBox6.Name = "groupBox6";
  654. this.groupBox6.Size = new System.Drawing.Size(354, 52);
  655. this.groupBox6.TabIndex = 46;
  656. this.groupBox6.TabStop = false;
  657. //
  658. // panel3
  659. //
  660. this.panel3.BackColor = System.Drawing.Color.Yellow;
  661. this.panel3.Location = new System.Drawing.Point(62, 18);
  662. this.panel3.Name = "panel3";
  663. this.panel3.Size = new System.Drawing.Size(105, 21);
  664. this.panel3.TabIndex = 22;
  665. this.panel3.Click += new System.EventHandler(this.panelC_Click);
  666. //
  667. // trackBar4
  668. //
  669. this.trackBar4.AutoSize = false;
  670. this.trackBar4.Cursor = System.Windows.Forms.Cursors.Hand;
  671. this.trackBar4.Location = new System.Drawing.Point(220, 20);
  672. this.trackBar4.Maximum = 50;
  673. this.trackBar4.Minimum = 1;
  674. this.trackBar4.Name = "trackBar4";
  675. this.trackBar4.Size = new System.Drawing.Size(84, 21);
  676. this.trackBar4.TabIndex = 7;
  677. this.trackBar4.TickStyle = System.Windows.Forms.TickStyle.None;
  678. this.trackBar4.Value = 3;
  679. this.trackBar4.Scroll += new System.EventHandler(this.trackBar4_Scroll);
  680. this.trackBar4.ValueChanged += new System.EventHandler(this.trackBar4_ValueChanged);
  681. //
  682. // textBox10
  683. //
  684. this.textBox10.Location = new System.Drawing.Point(310, 19);
  685. this.textBox10.Name = "textBox10";
  686. this.textBox10.Size = new System.Drawing.Size(35, 21);
  687. this.textBox10.TabIndex = 6;
  688. this.textBox10.Text = "3";
  689. this.textBox10.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWidth_KeyPress);
  690. this.textBox10.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox10_KeyUp);
  691. //
  692. // label4
  693. //
  694. this.label4.AutoSize = true;
  695. this.label4.Location = new System.Drawing.Point(173, 24);
  696. this.label4.Name = "label4";
  697. this.label4.Size = new System.Drawing.Size(0, 12);
  698. this.label4.TabIndex = 2;
  699. //
  700. // label6
  701. //
  702. this.label6.AutoSize = true;
  703. this.label6.Location = new System.Drawing.Point(15, 24);
  704. this.label6.Name = "label6";
  705. this.label6.Size = new System.Drawing.Size(0, 12);
  706. this.label6.TabIndex = 0;
  707. //
  708. // TABM3Dialog
  709. //
  710. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  711. this.ClientSize = new System.Drawing.Size(1127, 822);
  712. this.Controls.Add(this.groupBox6);
  713. this.Controls.Add(this.groupBox7);
  714. this.Controls.Add(this.groupBox5);
  715. this.Controls.Add(this.groupBox8);
  716. this.Controls.Add(this.groupBox10);
  717. this.Name = "TABM3Dialog";
  718. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TABM3Dialog_FormClosing);
  719. this.Controls.SetChildIndex(this.groupBox10, 0);
  720. this.Controls.SetChildIndex(this.groupBox8, 0);
  721. this.Controls.SetChildIndex(this.groupBox5, 0);
  722. this.Controls.SetChildIndex(this.groupBox_img, 0);
  723. this.Controls.SetChildIndex(this.groupBox_review, 0);
  724. this.Controls.SetChildIndex(this.groupBox_analysisResult1, 0);
  725. this.Controls.SetChildIndex(this.groupBox6groupBox_analysisResult2, 0);
  726. this.Controls.SetChildIndex(this.groupBox_report, 0);
  727. this.Controls.SetChildIndex(this.groupBox7, 0);
  728. this.Controls.SetChildIndex(this.groupBox6, 0);
  729. this.groupBox_img.ResumeLayout(false);
  730. this.groupBox_report.ResumeLayout(false);
  731. this.groupBox_report.PerformLayout();
  732. this.groupBox_analysisResult1.ResumeLayout(false);
  733. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
  734. this.groupBox10.ResumeLayout(false);
  735. this.groupBox10.PerformLayout();
  736. this.groupBox8.ResumeLayout(false);
  737. this.groupBox8.PerformLayout();
  738. this.groupBox5.ResumeLayout(false);
  739. this.groupBox7.ResumeLayout(false);
  740. this.groupBox7.PerformLayout();
  741. ((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
  742. this.groupBox6.ResumeLayout(false);
  743. this.groupBox6.PerformLayout();
  744. ((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit();
  745. this.ResumeLayout(false);
  746. }
  747. #endregion 初始化组件和实现组件事件
  748. #region 需继承的一部分方法
  749. protected override void drawSubclass(Graphics graphics)
  750. {
  751. if (tempHoleMat != null && tempHoleBitmap != null)
  752. {
  753. graphics.DrawImage(tempHoleBitmap, new PointF(0, 0));
  754. }
  755. Pen bluePen = new Pen(this.panel4.BackColor/*Color.FromArgb(255, 0, 208, 202)*/, this.trackBar3.Value/*5*/);
  756. //画左右下辅助线
  757. if (lineleft != null)
  758. graphics.DrawLine(bluePen, lineleft.startPoint, lineleft.endPoint);
  759. if (lineright != null)
  760. graphics.DrawLine(bluePen, lineright.startPoint, lineright.endPoint);
  761. //if (linebottom != null)
  762. // graphics.DrawLine(bluePen, linebottom.startPoint, linebottom.endPoint);
  763. if (hlines != null && hlines.Count() > 0)
  764. {
  765. foreach (Line l in hlines)
  766. {
  767. graphics.DrawLine(bluePen, l.startPoint, l.endPoint);
  768. }
  769. }
  770. //画笔
  771. Pen yellowPen = new Pen(this.panel3.BackColor/*Color.Yellow*/, this.trackBar4.Value/*5*/);
  772. if (honlines != null && honlines.Count() > 0)
  773. {
  774. foreach (Line l in honlines)
  775. {
  776. graphics.DrawLine(yellowPen, l.startPoint, l.endPoint);
  777. }
  778. }
  779. }
  780. //数据库的name(报告模板)
  781. protected override string getTemplateName()
  782. {
  783. return "Template.Manager.item3.TitaniumAlloyBio3Method";
  784. }
  785. //语言包的name(项目工程)
  786. protected override string getProjectEngineeringName()
  787. {
  788. return "Menu.DedicatedAnalysis.NonferrousMetal.TitaniumAlloyBiomaterial.Text";
  789. }
  790. protected override void SubclassInitialize()
  791. {
  792. InitializeComponent();
  793. InitializeLanguageText();
  794. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  795. this.panel3.Click += new System.EventHandler(this.panel1_Click);
  796. this.panel4.Click += new System.EventHandler(this.panel1_Click);
  797. //this.groupBox_img.Size = new System.Drawing.Size(158, 544/*514*/);
  798. //this.groupBox_review.Size = new System.Drawing.Size(575, 544/*514*/);
  799. //this.groupBox_analysisResult1.Location = new System.Drawing.Point(12, 622/*592*/);
  800. //this.groupBox6groupBox_analysisResult2.Location = new System.Drawing.Point(242, 622/*592*/);
  801. //this.groupBox_report.Location = new System.Drawing.Point(974, 622/*592*/);
  802. this.ClientSize = new System.Drawing.Size(1127, 852);///*822*/
  803. }
  804. //切换图片时控制前一张图的信息不遗留显示
  805. protected override void refreshWhileImgChanged()
  806. {
  807. this.physical_length = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  808. calculate1d = false;
  809. this.label2.Text = "";
  810. this.label7.Text = "";
  811. this.label14.Text = "";
  812. hlines.Clear();
  813. honlines.Clear();
  814. if (lineleft != null || linebottom != null || lineright != null)
  815. {
  816. btnflag = 0;
  817. lineleft = null;
  818. linebottom = null;
  819. lineright = null;
  820. }
  821. //contours = null;
  822. //vlines.Clear();
  823. //if (line != null)
  824. //{
  825. // btnflag = 0;
  826. // line = null;
  827. //}
  828. if (tempHoleMat != null)
  829. {
  830. tempHoleMat.Dispose();
  831. tempHoleMat = null;
  832. }
  833. //if (this.documentWorkspace.PhaseModels.Count() == 0 || this.documentWorkspace.PhaseModels[0].mat == null || !this.documentWorkspace.PhaseModels[0].choise)
  834. //{
  835. // binaryClass.performClickBinaryCheck(false);
  836. //}
  837. this.grayBitmap = false;
  838. }
  839. #endregion
  840. #region 基础操作
  841. /// <summary>
  842. /// 灰度化
  843. /// </summary>
  844. /// <param name="sender"></param>
  845. /// <param name="e"></param>
  846. private void button5_Click(object sender, EventArgs e)
  847. {
  848. if (this.bitmap == null)
  849. {
  850. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  851. return;
  852. }
  853. if (this.grayBitmap) {
  854. MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
  855. return;
  856. }
  857. this.grayBitmap = true;
  858. Mat lab1Img = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);
  859. if (lab1Img.Type() != MatType.CV_8UC1)
  860. {
  861. lab1Img = lab1Img.CvtColor(ColorConversionCodes.BGR2GRAY);
  862. Bitmap bitmap2 = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
  863. Document document = Document.FromImage(bitmap2);
  864. this.documentWorkspace.Document = document;
  865. }
  866. else
  867. MessageBox.Show(PdnResources.GetString("Menu.It'salreadygreyscale.text"));
  868. lab1Img.Dispose();
  869. lab1Img = null;
  870. }
  871. /// <summary>
  872. /// 腐蚀
  873. /// </summary>
  874. /// <param name="sender"></param>
  875. /// <param name="e"></param>
  876. private void button4_Click(object sender, EventArgs e)
  877. {
  878. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
  879. || this.documentWorkspace.PhaseModels[0].mat == null)
  880. {
  881. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  882. return;
  883. }
  884. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  885. Cv2.Erode(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
  886. this.documentWorkspace.PhaseModels[0].mat = lab1Img;
  887. this.documentWorkspace.Refresh();
  888. }
  889. /// <summary>
  890. /// 膨胀
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. /// <param name="e"></param>
  894. private void button10_Click(object sender, EventArgs e)
  895. {
  896. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise
  897. || this.documentWorkspace.PhaseModels[0].mat == null)
  898. {
  899. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  900. return;
  901. }
  902. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  903. Cv2.Dilate(lab1Img, lab1Img, new Mat(), null, 1, BorderTypes.Default);
  904. this.documentWorkspace.PhaseModels[0].mat = lab1Img;
  905. this.documentWorkspace.Refresh();
  906. }
  907. /// <summary>
  908. /// 寻找孔隙 (寻找轮廓)
  909. /// </summary>
  910. /// <param name="sender"></param>
  911. /// <param name="e"></param>
  912. private void button15_Click(object sender, EventArgs e)
  913. {
  914. findContour();
  915. }
  916. private void findContour(bool showMessageBox = true)
  917. {
  918. if (this.documentWorkspace.PhaseModels.Count < 1 || !this.documentWorkspace.PhaseModels[0].choise/* //###21476 */
  919. || this.documentWorkspace.PhaseModels[0].mat == null)
  920. {
  921. if (showMessageBox)
  922. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  923. return;
  924. }
  925. Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
  926. Color tempHoleColor = this.panel1.BackColor;
  927. Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
  928. Vec4b vec4B2 = new Vec4b(0, 0, 0, 0);
  929. if (tempHoleMat != null)
  930. {
  931. tempHoleMat.Dispose();
  932. tempHoleMat = null;
  933. }
  934. tempHoleMat = new Mat(analyzeMat.Size(), MatType.CV_8UC4);
  935. int Rows = analyzeMat.Rows;
  936. int Cols = analyzeMat.Cols;
  937. int[] point = new int[2];
  938. //多通道图像的格式化
  939. for (point[1] = 0; point[1] < Cols; point[1]++)
  940. {
  941. for (point[0] = 0; point[0] < Rows; point[0]++)
  942. {
  943. if (analyzeMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  944. tempHoleMat.Set(point, vec4B2);
  945. else
  946. tempHoleMat.Set(point, vec4B1);
  947. }
  948. }
  949. tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
  950. this.documentWorkspace.Refresh();
  951. }
  952. /// <summary>
  953. /// PanelC的调色板颜色改变
  954. /// </summary>
  955. /// <param name="sender"></param>
  956. /// <param name="e"></param>
  957. protected override void gridColorChanged(object sender, EventArgs e)
  958. {
  959. base.gridColorChanged(sender, e);
  960. if (this.panelC != this.panel1)
  961. return;
  962. Color tempHoleColor = this.panel1.BackColor;
  963. Vec4b vec4B1 = new Vec4b(tempHoleColor.B, tempHoleColor.G, tempHoleColor.R, 255);
  964. if (tempHoleMat == null)
  965. {
  966. return;
  967. }
  968. int Rows = tempHoleMat.Rows;
  969. int Cols = tempHoleMat.Cols;
  970. int[] point = new int[2];
  971. //多通道图像的格式化
  972. for (point[1] = 0; point[1] < Cols; point[1]++)
  973. {
  974. for (point[0] = 0; point[0] < Rows; point[0]++)
  975. {
  976. if (tempHoleMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
  977. tempHoleMat.Set(point, vec4B1);
  978. }
  979. }
  980. tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
  981. this.documentWorkspace.Refresh();
  982. //findContour(false);
  983. ////Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  984. //////更改背景色,触发事件
  985. ////this.panelC.BackColor = color;
  986. ////if (!findContour(false))
  987. //// this.documentWorkspace.Refresh();
  988. //////关闭色板
  989. ////this.colorsFormGrid.Close();
  990. }
  991. /// <summary>
  992. /// 自动调整
  993. /// </summary>
  994. /// <param name="sender"></param>
  995. /// <param name="e"></param>
  996. private void button17_Click(object sender, EventArgs e)
  997. {
  998. if (this.documentWorkspace.PhaseModels.Count < 1/* || !this.documentWorkspace.PhaseModels[0].choise*/
  999. || this.documentWorkspace.PhaseModels[0].mat == null)
  1000. {
  1001. binaryClass.performClickBinaryCheck(true);
  1002. }
  1003. this.button15.PerformClick();
  1004. }
  1005. /// <summary>
  1006. /// 绘制辅助线
  1007. /// </summary>
  1008. /// <param name="sender"></param>
  1009. /// <param name="e"></param>
  1010. private void button13_Click(object sender, EventArgs e)
  1011. {
  1012. if (tempHoleMat == null)
  1013. {
  1014. MessageBox.Show("请先进行寻找孔隙操作");
  1015. return;
  1016. }
  1017. //if (contours == null)
  1018. //{
  1019. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseclicktodrawtheoutlinefirst.text"));
  1020. // return;
  1021. //}
  1022. ////this.showPhaseMat();
  1023. Mat lab1Img = this.documentWorkspace.PhaseModels[0].mat;
  1024. if (lab1Img != null/* && drawg != null*/)// && line == null
  1025. {
  1026. //if (string.IsNullOrWhiteSpace(this.textBox4.Text) || textBox4.Text == "")
  1027. //{
  1028. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseentertheauxiliarylinespacingfirst.text"));
  1029. // return;
  1030. //}
  1031. string width = this.textBox4.Text.Trim();
  1032. double result;
  1033. if (!double.TryParse(width, out result))
  1034. {
  1035. MessageBox.Show(PdnResources.GetString("Menu.ormatforauxiliarylinespacin.Text"));
  1036. return;
  1037. }
  1038. string width2 = this.textBox6.Text.Trim();
  1039. int result2;
  1040. if (!int.TryParse(width2, out result2))
  1041. {
  1042. MessageBox.Show(PdnResources.GetString("Menu.Theinputforncorrect.text"));
  1043. return;
  1044. }
  1045. this.drawLines();
  1046. this.documentWorkspace.Refresh();
  1047. }
  1048. else
  1049. {
  1050. MessageBox.Show(PdnResources.GetString("Menu.Pleasebinarizefirst.text"));
  1051. }
  1052. }
  1053. /// <summary>
  1054. /// 绘制辅助线
  1055. /// </summary>
  1056. private void drawLines()
  1057. {
  1058. string line = this.textBox6.Text.Trim();
  1059. string width = this.textBox4.Text.Trim();
  1060. try
  1061. {
  1062. //画左右下辅助线
  1063. if (lineleft == null || lineright == null)
  1064. {
  1065. int margin = this.bitmap/*lab1Img*/.Width / 20;
  1066. int spaceLine = (int)((this.bitmap.Width - 2 * margin) * this.physical_length);
  1067. if (int.TryParse(this.textBox1.Text.ToString().Trim(), out spaceLine))
  1068. {
  1069. margin = (int)((this.bitmap.Width - spaceLine / this.physical_length) / 2);
  1070. }
  1071. lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
  1072. lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
  1073. }
  1074. if (linebottom == null)
  1075. {
  1076. linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
  1077. }
  1078. //画平行的多条辅助线
  1079. int n = int.Parse(line); //线的数量
  1080. int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
  1081. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1082. hlines.Clear();
  1083. {
  1084. for (int i = 0; i < n; i++)
  1085. {
  1086. Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y - per_w * i));
  1087. //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
  1088. hlines.Add(l);
  1089. }
  1090. }
  1091. honlines.Clear();
  1092. btnflag = 1;
  1093. //pictureBox1.Image = map;
  1094. }
  1095. catch (Exception ex)
  1096. {
  1097. MessageBox.Show(ex.Message);
  1098. }
  1099. }
  1100. /// <summary>
  1101. /// 重置
  1102. /// </summary>
  1103. /// <param name="sender"></param>
  1104. /// <param name="e"></param>
  1105. private void button3_Click(object sender, EventArgs e)
  1106. {
  1107. if (this.bitmap == null)
  1108. {
  1109. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text"));
  1110. return;
  1111. }
  1112. calculate1d = false;
  1113. this.label2.Text = "";
  1114. this.label7.Text = "";
  1115. this.label14.Text = "";
  1116. hlines.Clear();
  1117. honlines.Clear();
  1118. if (lineleft == null && linebottom == null && lineright == null)
  1119. { }
  1120. else
  1121. {
  1122. btnflag = 0;
  1123. lineleft = null;
  1124. linebottom = null;
  1125. lineright = null;
  1126. }
  1127. //contours = null;
  1128. //vlines.Clear();
  1129. //if (line == null)
  1130. //{
  1131. //}
  1132. //else
  1133. //{
  1134. // btnflag = 0;
  1135. // line = null;
  1136. //}
  1137. if (tempHoleMat != null)
  1138. {
  1139. tempHoleMat.Dispose();
  1140. tempHoleMat = null;
  1141. }
  1142. if (this.documentWorkspace.PhaseModels.Count() > 0)
  1143. {
  1144. this.documentWorkspace.PhaseModels[0].mat = null;
  1145. }
  1146. this.documentWorkspace.PhaseModels[0].choise = false;
  1147. binaryClass.performClickBinaryCheck(false);
  1148. //this.checkBox10.Checked = false;//PdnResources.GetString("Menu.Binarization.text");//####################
  1149. this.grayBitmap = false;
  1150. Document document = Document.FromImage(this.bitmap);
  1151. this.documentWorkspace.Document = document;
  1152. }
  1153. /// <summary>
  1154. /// 修改孔隙 (修改轮廓)
  1155. /// </summary>
  1156. /// <param name="sender"></param>
  1157. /// <param name="e"></param>
  1158. private void button14_Click(object sender, EventArgs e)
  1159. {
  1160. if (this.bitmap == null)
  1161. {
  1162. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  1163. return;
  1164. }
  1165. if (tempHoleMat == null)
  1166. {
  1167. MessageBox.Show("请先进行寻找孔隙操作");
  1168. return;
  1169. }
  1170. IntegrationClass.MetalsHoleAreaEditingDialog boundaryEditingDialog = new IntegrationClass.MetalsHoleAreaEditingDialog(this.appWorkspace, this.lstView_img.FocusedItem != null ? this.lstView_img.FocusedItem.Index : this.lstView_img.SelectedItems[0].Index, this.panel1.BackColor
  1171. , tempHoleMat);
  1172. if (boundaryEditingDialog.ShowDialog() == DialogResult.OK)
  1173. {
  1174. tempHoleMat = boundaryEditingDialog.PhaseMat.Clone();
  1175. tempHoleBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(tempHoleMat);
  1176. this.documentWorkspace.Refresh();
  1177. }
  1178. }
  1179. #endregion 基础操作
  1180. #region 控件监听事件
  1181. /// <summary>
  1182. /// 相颜色点击事件
  1183. /// </summary>
  1184. /// <param name="sender"></param>
  1185. /// <param name="e"></param>
  1186. private void panelC_Click(object sender, EventArgs e)
  1187. {
  1188. //this.panelC = (Panel)sender;
  1189. //this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(((Panel)sender).BackColor);
  1190. //this.colorsFormGrid.ShowDialog();
  1191. }
  1192. private void trackBar4_ValueChanged(object sender, EventArgs e)
  1193. {
  1194. this.documentWorkspace.Refresh();
  1195. }
  1196. private void trackBar4_Scroll(object sender, EventArgs e)
  1197. {
  1198. this.textBox10.Text = "" + this.trackBar4.Value;
  1199. }
  1200. private void trackBar3_ValueChanged(object sender, EventArgs e)
  1201. {
  1202. this.documentWorkspace.Refresh();
  1203. }
  1204. private void trackBar3_Scroll(object sender, EventArgs e)
  1205. {
  1206. this.textBox3.Text = "" + this.trackBar3.Value;
  1207. }
  1208. /// <summary>
  1209. /// 线宽输入框 对输入值做限制
  1210. /// </summary>
  1211. /// <param name="sender"></param>
  1212. private void varifyTextBoxValue(object sender)
  1213. {
  1214. if (string.IsNullOrEmpty(((TextBox)sender)/*this.textBox2*/.Text))
  1215. ((TextBox)sender)/*this.textBox2*/.Text = "1";
  1216. if (Convert.ToInt32(((TextBox)sender)/*this.textBox2*/.Text) > 50)
  1217. ((TextBox)sender)/*this.textBox2*/.Text = "50";
  1218. }
  1219. /// <summary>
  1220. /// 限制只可以输入0-9数字以及退格键
  1221. /// </summary>
  1222. /// <param name="sender"></param>
  1223. /// <param name="e"></param>
  1224. private void textBoxWidth_KeyPress(object sender, KeyPressEventArgs e)
  1225. {
  1226. if (e.KeyChar != '\b')//这是允许输入退格键 
  1227.             {
  1228. int len = ((TextBox)sender)/*this.textBox1*/.Text.Length;
  1229. if (len < 1 && e.KeyChar == '0')
  1230. {
  1231. e.Handled = true;
  1232. }
  1233. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  1234.                 {
  1235. e.Handled = true;
  1236. }
  1237. }
  1238. }
  1239. private void textBox10_KeyUp(object sender, KeyEventArgs e)
  1240. {
  1241. this.varifyTextBoxValue(sender);
  1242. this.trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
  1243. }
  1244. private void textBox3_KeyUp(object sender, KeyEventArgs e)
  1245. {
  1246. this.varifyTextBoxValue(sender);
  1247. this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1248. }
  1249. #endregion 控件监听事件
  1250. #region 矩形拖动
  1251. /// <summary>
  1252. /// 鼠标按下
  1253. /// </summary>
  1254. /// <param name="drawArea"></param>
  1255. /// <param name="e"></param>
  1256. protected override void OnMouseDown(object sender, MouseEventArgs e)
  1257. {
  1258. if (!CanUseMouseFunctions())
  1259. return;
  1260. try
  1261. {
  1262. //判断
  1263. //画左右下辅助线
  1264. if (linebottom == null || lineleft == null || lineright == null)
  1265. {
  1266. this.documentWorkspace.Cursor = Cursors.Default;
  1267. //在MouseDown处获知鼠标是否按下,并记录下此时的鼠标坐标值;
  1268. if (e.Button == MouseButtons.Left)
  1269. {
  1270. }
  1271. return;
  1272. //int margin = lab1Img.Width / 20;
  1273. //lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, lab1Img.Height));
  1274. //lineright = new Line(new System.Drawing.Point(lab1Img.Width - margin, 0), new System.Drawing.Point(lab1Img.Width - margin, lab1Img.Height));
  1275. }
  1276. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1277. float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
  1278. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
  1279. string line = this.textBox6.Text.Trim();
  1280. string width = this.textBox4.Text.Trim();
  1281. //画平行的多条辅助线
  1282. int n = int.Parse(line); //线的数量
  1283. int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
  1284. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1285. int bottomY1 = linebottom.startPoint.Y - per_w * (n - 1);
  1286. if (mouse_x < lineleft.startPoint.X + 10 && mouse_x > lineleft.startPoint.X - 10)
  1287. {
  1288. //拖动左辅助线
  1289. mouseFlag = 1;
  1290. }
  1291. else if (mouse_x < lineright.startPoint.X + 10 && mouse_x > lineright.startPoint.X - 10)
  1292. {
  1293. //拖动右辅助线
  1294. mouseFlag = 2;
  1295. }
  1296. else if (mouse_y < linebottom.startPoint.Y && mouse_y > bottomY1)
  1297. {
  1298. xPos = (int)mouse_x;// e.X;//当前x坐标
  1299. yPos = (int)mouse_y;// e.Y;//当前y坐标
  1300. //拖动平行辅助线
  1301. mouseFlag = 3;
  1302. }
  1303. else
  1304. {
  1305. this.documentWorkspace.Cursor = Cursors.Default;
  1306. }
  1307. }
  1308. catch (Exception ex)
  1309. {
  1310. MessageBox.Show(ex.Message);
  1311. }
  1312. }
  1313. /// <summary>
  1314. /// 移动
  1315. /// </summary>
  1316. /// <param name="sender"></param>
  1317. /// <param name="e"></param>
  1318. protected override void onMouseMove(object sender, MouseEventArgs e)
  1319. {
  1320. if (!CanUseMouseFunctions())
  1321. return;
  1322. //拖动左右辅助线
  1323. if (mouseFlag == 1 || mouseFlag == 2)
  1324. {
  1325. //Mat ImageROI = null;
  1326. try
  1327. {
  1328. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1329. float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
  1330. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
  1331. ////移动左辅助线
  1332. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1333. int margin = (int)mouse_x;
  1334. margin = Math.Min(this.bitmap/*lab1Img*/.Width - 10, margin);
  1335. margin = Math.Max(10, margin);
  1336. if (mouseFlag == 1)
  1337. {
  1338. if (lineright != null && margin > lineright.startPoint.X)
  1339. {
  1340. margin = lineright.startPoint.X - 1;
  1341. }
  1342. lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
  1343. }
  1344. else if (mouseFlag == 2)
  1345. {
  1346. if (lineleft != null && margin < lineleft.startPoint.X)
  1347. {
  1348. margin = lineleft.startPoint.X + 1;
  1349. }
  1350. lineright = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
  1351. }
  1352. if (mouseFlag == 1 || mouseFlag == 2)
  1353. {
  1354. //int margin = this.bitmap/*lab1Img*/.Width / 20;
  1355. int spaceLine = (int)((lineright.startPoint.X - lineleft.startPoint.X) * this.physical_length);
  1356. if (spaceLine > 0)
  1357. {
  1358. this.textBox1.Text = spaceLine + "";
  1359. }
  1360. //if (int.TryParse(this.textBox1.Text.ToString().Trim(), out spaceLine))
  1361. //{
  1362. // margin = (int)((this.bitmap.Width - spaceLine / this.physical_length) / 2);
  1363. //}
  1364. }
  1365. this.drawLines();
  1366. this.documentWorkspace.Refresh();
  1367. }
  1368. catch
  1369. {
  1370. }
  1371. finally
  1372. {
  1373. //ImageROI.Dispose();
  1374. //GC.Collect();
  1375. }
  1376. return;
  1377. }
  1378. //拖动平行辅助线
  1379. if (mouseFlag == 3)
  1380. {
  1381. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1382. float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
  1383. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
  1384. string line = this.textBox6.Text.Trim();
  1385. string width = this.textBox4.Text.Trim();
  1386. try
  1387. {
  1388. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1389. //画左右下辅助线
  1390. if (lineleft == null || lineright == null)
  1391. {
  1392. int margin = this.bitmap/*lab1Img*/.Width / 20;
  1393. lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
  1394. lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
  1395. }
  1396. if (linebottom == null)
  1397. {
  1398. linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
  1399. }
  1400. //bluePen = new Pen(Color.Blue, zoom);
  1401. //drawg.DrawLine(bluePen, lineleft.startPoint, lineleft.endPoint);
  1402. //drawg.DrawLine(bluePen, lineright.startPoint, lineright.endPoint);
  1403. //画平行的多条辅助线
  1404. int n = int.Parse(line); //线的数量
  1405. int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
  1406. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1407. hlines.Clear();
  1408. for (int i = 0; i < n; i++)
  1409. {
  1410. Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i));
  1411. //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
  1412. hlines.Add(l);
  1413. }
  1414. honlines.Clear();
  1415. btnflag = 1;
  1416. //pictureBox1.Image = map;
  1417. this.documentWorkspace.Refresh();
  1418. }
  1419. catch (Exception ex)
  1420. {
  1421. //MessageBox.Show(ex.Message);//解决不断弹出提示语的bug
  1422. }
  1423. return;
  1424. }
  1425. if (btnflag == 2)
  1426. {
  1427. //Mat ImageROI = null;
  1428. try
  1429. {
  1430. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1431. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
  1432. ////移动辅助线
  1433. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1434. }
  1435. catch (Exception b)
  1436. {
  1437. //MessageBox.Show(b.Message);//解决不断弹出提示语的bug
  1438. }
  1439. finally
  1440. {
  1441. //ImageROI.Dispose();
  1442. //GC.Collect();
  1443. }
  1444. return;
  1445. }
  1446. if (btnflag == 1)
  1447. {
  1448. try
  1449. {
  1450. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1451. float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
  1452. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
  1453. string line = this.textBox6.Text.Trim();
  1454. string width = this.textBox4.Text.Trim();
  1455. //画平行的多条辅助线
  1456. int n = int.Parse(line); //线的数量
  1457. int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
  1458. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1459. int bottomY1 = linebottom.startPoint.Y - per_w * (n - 1);
  1460. if ((mouse_x < lineleft.startPoint.X + 10 && mouse_x > lineleft.startPoint.X - 10) || (mouse_x < lineright.startPoint.X + 10 && mouse_x > lineright.startPoint.X - 10))
  1461. {
  1462. //移动辅助线
  1463. this.documentWorkspace.Cursor = Cursors.SizeWE;
  1464. }
  1465. else if (mouse_y < linebottom.startPoint.Y && mouse_y > bottomY1)
  1466. {
  1467. //移动辅助线
  1468. this.documentWorkspace.Cursor = Cursors.SizeAll;
  1469. }
  1470. else
  1471. {
  1472. this.documentWorkspace.Cursor = Cursors.Default;
  1473. }
  1474. }
  1475. catch (Exception ex)
  1476. {
  1477. //MessageBox.Show(ex.Message);//解决不断弹出提示语的bug
  1478. }
  1479. }
  1480. else
  1481. {
  1482. this.documentWorkspace.Cursor = Cursors.Default;
  1483. }
  1484. }
  1485. /// <summary>
  1486. /// 鼠标抬起
  1487. /// </summary>
  1488. /// <param name="sender"></param>
  1489. /// <param name="e"></param>
  1490. protected override void onMouseUp(object sender, MouseEventArgs e)
  1491. {
  1492. if (!CanUseMouseFunctions())
  1493. return;
  1494. //拖动平行辅助线
  1495. if (mouseFlag == 3)
  1496. {
  1497. System.Drawing.Point point = this.documentWorkspace.GetScalePoint(e.Location);
  1498. float mouse_x = point.X;// ((e.X - panel1.Location.X + 12) * zoom - imgX);
  1499. float mouse_y = point.Y;// ((e.Y - panel1.Location.Y + 12) * zoom - imgY);
  1500. string line = this.textBox6.Text.Trim();
  1501. string width = this.textBox4.Text.Trim();
  1502. try
  1503. {
  1504. //drawg.Clear(Color.FromArgb(0, 11, 11, 11));
  1505. //画左右下辅助线
  1506. if (lineleft == null || lineright == null)
  1507. {
  1508. int margin = this.bitmap/*lab1Img*/.Width / 20;
  1509. lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
  1510. lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
  1511. }
  1512. if (linebottom == null)
  1513. {
  1514. linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
  1515. }
  1516. //bluePen = new Pen(Color.Blue, zoom);
  1517. //drawg.DrawLine(bluePen, lineleft.startPoint, lineleft.endPoint);
  1518. //drawg.DrawLine(bluePen, lineright.startPoint, lineright.endPoint);
  1519. //画平行的多条辅助线
  1520. int n = int.Parse(line); //线的数量
  1521. int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
  1522. per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1523. hlines.Clear();
  1524. for (int i = 0; i < n; i++)
  1525. {
  1526. Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y + (int)(mouse_y - yPos) - per_w * i));
  1527. //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
  1528. hlines.Add(l);
  1529. }
  1530. honlines.Clear();
  1531. btnflag = 1;
  1532. //pictureBox1.Image = map;
  1533. linebottom.startPoint.Y = linebottom.startPoint.Y + (int)(mouse_y - yPos);
  1534. this.documentWorkspace.Refresh();
  1535. }
  1536. catch (Exception ex)
  1537. {
  1538. MessageBox.Show(ex.Message);
  1539. }
  1540. }
  1541. mouseFlag = 0;
  1542. }
  1543. #endregion
  1544. #region 分析结果的方法
  1545. /// <summary>
  1546. /// 点击保存结果按钮,用来返回需要新增的一行数据
  1547. /// </summary>
  1548. /// <param name="tag"></param>
  1549. /// <param name="imgName"></param>
  1550. /// <returns></returns>
  1551. protected override DataTable toInsertTableRow(string tag, string imgName)
  1552. {
  1553. DataTable dt = new DataTable(tag);
  1554. dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
  1555. dt.Columns.Add(PdnResources.GetString("Menu.Totallengthofporeintercepts.text"));
  1556. dt.Columns.Add(PdnResources.GetString("Menu.Meanporeintercept.text"));
  1557. dt.Columns.Add(PdnResources.GetString("Menu.Numberofintercept.text"));
  1558. //dt.Columns.Add(PdnResources.GetString("Menu.picture.Text"));
  1559. //dt.Columns.Add(PdnResources.GetString("Menu.Averagethickness(μm).text"));
  1560. //dt.Columns.Add(PdnResources.GetString("Menu.standarddeviation.text"));
  1561. //dt.Columns.Add(PdnResources.GetString("Menu.confidencebound.text"));
  1562. DataRow dataRow = dt.NewRow();
  1563. dataRow[PdnResources.GetString("Menu.picture.Text")] = imgName;
  1564. dataRow[PdnResources.GetString("Menu.Totallengthofporeintercepts.text")] = res_totalL;
  1565. dataRow[PdnResources.GetString("Menu.Meanporeintercept.text")] = res_perL;
  1566. dataRow[PdnResources.GetString("Menu.Numberofintercept.text")] = res_count;
  1567. dt.Rows.Add(dataRow);
  1568. return dt;
  1569. }
  1570. /// <summary>
  1571. /// 计算结果是否存在
  1572. /// </summary>
  1573. /// <returns>返回是否可以计算和保存结果</returns>
  1574. protected override bool resultCalculateExist()
  1575. {
  1576. return tempHoleMat != null;// vlines.Count > 0;
  1577. }
  1578. /// <summary>
  1579. /// 拼接中间数据
  1580. /// </summary>
  1581. /// <returns></returns>
  1582. protected override List<List<string>> buildTempDataList()
  1583. {
  1584. //return null;
  1585. List<List<string>> dataList = new List<List<string>>();
  1586. List<string> columnName = new List<string>();
  1587. //columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  1588. //columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.Xoordinate.Text"));
  1589. //columnName.Add(PdnResources.GetString("Menu.ToYcoordinate.Text"));
  1590. //columnName.Add(PdnResources.GetString("Menu.ToYcoonate.Text"));
  1591. //columnName.Add(PdnResources.GetString("Menu.Tools.AuxiliaryLine.Text") + PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text"));
  1592. //columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
  1593. columnName.Add(PdnResources.GetString("Menu.Imagement.Measurementlist.ordernumber.text"));
  1594. columnName.Add(PdnResources.GetString("Menu.eauxiliarylineYcoordinate.Text"));
  1595. columnName.Add(PdnResources.GetString("Menu.LeftXcoordinate.Text"));
  1596. columnName.Add(PdnResources.GetString("Menu.RightXcoordinate.Text"));
  1597. columnName.Add(PdnResources.GetString("Menu.Lengthofauxiliaryline.Text"));
  1598. columnName.Add(PdnResources.GetString("Menu.Physicallength.text"));//addAction:这里
  1599. dataList.Add(columnName);
  1600. int index = 0;
  1601. //if (honlines != null && honlines.Count() > 0)
  1602. //{
  1603. // foreach (Line l in honlines)
  1604. // {
  1605. // graphics.DrawLine(yellowPen, l.startPoint, l.endPoint);
  1606. // }
  1607. //}
  1608. //循环辅助线的集合
  1609. if (honlines != null && honlines.Count() > 0)
  1610. {
  1611. //循环每条线,找到和轮廓的交点
  1612. for (int i = 0; i < honlines.Count(); i++)
  1613. {
  1614. //Line l = honlines[i];
  1615. List<string> strList = new List<string>();
  1616. strList.Add((++index).ToString());
  1617. strList.Add(honlines[i].startPoint.Y.ToString());
  1618. strList.Add(honlines[i].startPoint.X.ToString());
  1619. strList.Add(honlines[i].endPoint.X.ToString());
  1620. strList.Add((honlines[i].endPoint.X - honlines[i].startPoint.X).ToString());
  1621. strList.Add(((honlines[i].endPoint.X - honlines[i].startPoint.X) * physical_length).ToString());
  1622. dataList.Add(strList);
  1623. }
  1624. }
  1625. //int index = 0;
  1626. //////厚度的数组
  1627. ////int[] thickness = new int[vlines.Count()];
  1628. ////循环辅助线的集合
  1629. //if (this.vlines.Count > 0)
  1630. //{
  1631. // //循环每条线,找到和轮廓的交点
  1632. // for (int i = 0; i < vlines.Count(); i++)
  1633. // {
  1634. // ////计算厚度,像素
  1635. // //thickness[i] = lineNum - vlines[i].startPoint.Y;
  1636. // List<string> strList = new List<string>();
  1637. // strList.Add((++index).ToString());
  1638. // strList.Add(vlines[i].startPoint.X.ToString());
  1639. // strList.Add(vlines[i].startPoint.Y.ToString());
  1640. // strList.Add(lineNum.ToString());
  1641. // strList.Add((lineNum - vlines[i].startPoint.Y).ToString());
  1642. // strList.Add(((lineNum - vlines[i].startPoint.Y) * physical_length).ToString());
  1643. // dataList.Add(strList);
  1644. // }
  1645. //}
  1646. return dataList;
  1647. }
  1648. /// <summary>
  1649. /// 计算结果
  1650. /// </summary>
  1651. /// <param name="sender"></param>
  1652. /// <param name="e"></param>
  1653. protected override void buttonCalculate_Click(object sender, EventArgs e)
  1654. {
  1655. //if (top == null || bottom == null)
  1656. //{
  1657. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectareafirst.text"));
  1658. // return;
  1659. //}
  1660. //int result = 0;
  1661. if (hlines.Count == 0)
  1662. {
  1663. MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
  1664. return;
  1665. }
  1666. if (!resultCalculateExist())
  1667. {
  1668. MessageBox.Show("请先进行寻找孔隙操作");//PdnResources.GetString("Menu.Pleaselookfortheoutlinefirst.text") ;//点击绘制轮廓
  1669. return;
  1670. //MessageBox.Show(PdnResources.GetString("Menu.Pleasedrawauxiliarylinesfirst.text"));
  1671. //return;
  1672. }
  1673. //calculation = true;
  1674. //循环计算有效的网格线平均孔隙密度
  1675. float totallength = 0;
  1676. //float perlength = 0;
  1677. int pointsum = 0;
  1678. //List<List<OpenCvSharp.Point>> ddd = new List<List<OpenCvSharp.Point>>();
  1679. honlines.Clear();
  1680. for (int i = 0; i < hlines.Count; i++)//hlines
  1681. {
  1682. //List<OpenCvSharp.Point> list = new List<OpenCvSharp.Point>();
  1683. int xMinPoint = Math.Min(lineleft.endPoint.X, lineright.endPoint.X);
  1684. int xMaxPoint = Math.Max(lineleft.endPoint.X, lineright.endPoint.X);
  1685. int yLinePoint = hlines[i].endPoint.Y;// - 1;
  1686. if (yLinePoint <= 0)
  1687. {
  1688. continue;
  1689. }
  1690. bool holeLineStart = true;//结束于视场的边缘或孔隙区域的中间,则这个区域不应包括在内
  1691. OpenCvSharp.Point startPoint = new OpenCvSharp.Point(-1, yLinePoint);
  1692. for (int j = xMinPoint; j <= xMaxPoint; j++)
  1693. {
  1694. if (tempHoleMat.At<Vec4b>(yLinePoint, j).Item3 > 0)//############
  1695. {
  1696. if (!holeLineStart)
  1697. {
  1698. startPoint.X = j;
  1699. //list.Add(new OpenCvSharp.Point(j, yLinePoint));//记录网格线的起始点
  1700. holeLineStart = true;
  1701. }
  1702. }
  1703. else if (holeLineStart)
  1704. {
  1705. holeLineStart = false;
  1706. if (startPoint.X > 0)
  1707. {
  1708. ++pointsum;
  1709. totallength += (j - startPoint.X);
  1710. honlines.Add(new Line(new System.Drawing.Point(startPoint.X, yLinePoint), new System.Drawing.Point(j, yLinePoint)));
  1711. //list.Add(new OpenCvSharp.Point(j, yLinePoint));//记录网格线的结束点
  1712. }
  1713. }
  1714. }
  1715. //if (!holeLineStart && list.Count > 0)//起始于视场的边缘或孔隙区域的中间,则这个区域不应包括在内
  1716. // list.RemoveAt(list.Count - 1);
  1717. //////for (int j = contours.Count() - 1; j >= 0; j--)//#
  1718. //////{
  1719. ////// List<OpenCvSharp.Point> dsd = contours[j].ToList<OpenCvSharp.Point>();
  1720. ////// List<OpenCvSharp.Point> lll = dsd.FindAll(a => a.Y == hlines[i].endPoint.Y - 1 && a.X > lineleft.endPoint.X && a.X < lineright.endPoint.X);
  1721. ////// if (lll != null && lll.Count > 0)
  1722. ////// {
  1723. ////// //过滤一下,如果点密集,只要一个
  1724. ////// int finetuning = 0;
  1725. ////// //过滤,如果一个轮廓返回了一个点或者奇数点,则抛弃
  1726. ////// List<OpenCvSharp.Point> temp = new List<OpenCvSharp.Point>();
  1727. ////// foreach (var Point in lll)
  1728. ////// {
  1729. ////// //过滤一下,如果点密集,只要一个
  1730. ////// if (finetuning == 0)
  1731. ////// {
  1732. ////// finetuning = Point.X;
  1733. ////// }
  1734. ////// else
  1735. ////// {
  1736. ////// if ((Point.X == finetuning + 1) || (Point.X == finetuning - 1))
  1737. ////// {
  1738. ////// finetuning = Point.X;
  1739. ////// continue;
  1740. ////// }
  1741. ////// finetuning = Point.X;
  1742. ////// }
  1743. ////// temp.Add(new OpenCvSharp.Point(Point.X, Point.Y));
  1744. ////// }
  1745. ////// list.AddRange(temp);
  1746. ////// }
  1747. //////}
  1748. ////list.Sort((a, b) => a.X.CompareTo(b.X));
  1749. //ddd.Add(list);
  1750. }
  1751. ////Cv2.ImShow("dst12344", dst1234);
  1752. //honlines.Clear();
  1753. ////绘制所有交点
  1754. //foreach (var point in ddd)
  1755. //{
  1756. // for (int k = 0; k < point.Count - 1; k += 2)
  1757. // {
  1758. // ////drawg.DrawEllipse(new Pen(Color.Yellow, drawsize), point[k].X, point[k].Y, drawsize, drawsize);
  1759. // OpenCvSharp.Point a = point[k];
  1760. // OpenCvSharp.Point b = point[k + 1];
  1761. // //int x = (a.X + b.X) / 2;
  1762. // ////lab1NoneContourImg
  1763. // //if (dst1234.At<byte>(a.Y, x) <= 0)
  1764. // //{
  1765. // // ++pointsum;
  1766. // // totallength += (b.X - a.X);
  1767. // //honlines.Add(new Line(new System.Drawing.Point(a.X, a.Y), new System.Drawing.Point(b.X, b.Y)));
  1768. // // //drawg.DrawLine(new Pen(Color.Yellow, drawsize), a.X, a.Y, b.X, b.Y);
  1769. // //}
  1770. // ////double innum = Cv2.PointPolygonTest(contours[j], new Point2f(x, a.Y), false);
  1771. // ////if (innum > 0)
  1772. // ////{
  1773. // //// drawg.DrawLine(new Pen(Color.Yellow, drawsize), a.X, a.Y, b.X, b.Y);
  1774. // //// break;
  1775. // ////}//########################################
  1776. // }
  1777. //}
  1778. //////Cv2.DrawContours(lab1Img, contours, -1, Scalar.Blue, Cv2.FILLED);
  1779. //////pictureBox1.BackgroundImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(lab1Img);
  1780. ////pictureBox1.Image = map;
  1781. this.documentWorkspace.Refresh();
  1782. res_totalL = totallength * physical_length;
  1783. res_perL = res_totalL / Math.Max(1, pointsum);
  1784. res_count = Math.Max(1, pointsum);
  1785. //计算结果
  1786. this.label2.Text = this.resShow(res_totalL.ToString());
  1787. this.label7.Text = this.resShow(res_perL.ToString());
  1788. this.label14.Text = res_count.ToString(); ;
  1789. calculate1d = true;
  1790. }
  1791. /// <summary>
  1792. /// 记录输入文字改变的状态
  1793. /// </summary>
  1794. int textBoxChanged = -1;
  1795. /// <summary>
  1796. /// 上辅助线居顶距离改变
  1797. /// </summary>
  1798. /// <param name="sender"></param>
  1799. /// <param name="e"></param>
  1800. private void TextBox4_TextChanged(object sender, EventArgs e)
  1801. {
  1802. if (this.bitmap == null)
  1803. {
  1804. return;
  1805. }
  1806. string width2 = this.textBox6.Text.Trim();
  1807. int result2;
  1808. if (!int.TryParse(width2, out result2))
  1809. {
  1810. //MessageBox.Show("线的数量输入格式不正确");
  1811. return;
  1812. }
  1813. string width = this.textBox4.Text.Trim();
  1814. double result;
  1815. if (!double.TryParse(width, out result))
  1816. {
  1817. return;
  1818. }
  1819. this.drawLines();
  1820. this.documentWorkspace.Refresh();
  1821. }
  1822. /// <summary>
  1823. /// 下辅助线居底距离改变
  1824. /// </summary>
  1825. /// <param name="sender"></param>
  1826. /// <param name="e"></param>
  1827. private void TextBox6_TextChanged(object sender, EventArgs e)
  1828. {
  1829. if (this.bitmap == null)
  1830. {
  1831. return;
  1832. }
  1833. string width = this.textBox4.Text.Trim();
  1834. double result;
  1835. if (!double.TryParse(width, out result))
  1836. {
  1837. //MessageBox.Show(PdnResources.GetString("Menu.Linespacinginputformatincorrect.text"));
  1838. return;
  1839. }
  1840. string width2 = this.textBox6.Text.Trim();
  1841. int result2;
  1842. if (!int.TryParse(width2, out result2))
  1843. {
  1844. //MessageBox.Show("线的数量输入格式不正确");
  1845. return;
  1846. }
  1847. this.drawLines();
  1848. this.documentWorkspace.Refresh();
  1849. }
  1850. /// <summary>
  1851. /// 小数点位数变化时刷新界面的数据
  1852. /// </summary>
  1853. protected override void RefreshDataGridView1()
  1854. {
  1855. if (calculate1d)
  1856. {
  1857. this.label2.Text = this.resShow(res_totalL.ToString());
  1858. this.label7.Text = this.resShow(res_perL.ToString());
  1859. this.label14.Text = this.resShow(res_count.ToString());
  1860. }
  1861. }
  1862. #endregion 分析结果的方法
  1863. private void textBox1_KeyUp(object sender, KeyEventArgs e)
  1864. {
  1865. //this.varifyTextBoxValue(sender);
  1866. //画左右下辅助线
  1867. if (lineleft != null || lineright != null)
  1868. {
  1869. int margin = this.bitmap/*lab1Img*/.Width / 20;
  1870. int spaceLine = (int)((this.bitmap.Width - 2 * margin) * this.physical_length);
  1871. if (int.TryParse(this.textBox1.Text.ToString().Trim(), out spaceLine))
  1872. {
  1873. margin = (int)((this.bitmap.Width - spaceLine / this.physical_length) / 2);
  1874. if (margin < 0)
  1875. {
  1876. margin = 1;
  1877. /*int */
  1878. spaceLine = (int)((this.bitmap.Width - 2) * this.physical_length);
  1879. if (spaceLine > 0)
  1880. {
  1881. this.textBox1.Text = spaceLine + "";
  1882. }
  1883. }
  1884. lineleft = new Line(new System.Drawing.Point(margin, 0), new System.Drawing.Point(margin, this.bitmap/*lab1Img*/.Height));
  1885. lineright = new Line(new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, 0), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width - margin, this.bitmap/*lab1Img*/.Height));
  1886. this.documentWorkspace.Refresh();
  1887. }
  1888. }
  1889. ////if (linebottom == null)
  1890. ////{
  1891. //// linebottom = new Line(new System.Drawing.Point(0, this.bitmap/*lab1Img*/.Height - 130), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, this.bitmap/*lab1Img*/.Height - 130));
  1892. ////}
  1893. //////画平行的多条辅助线
  1894. ////int n = int.Parse(line); //线的数量
  1895. ////int per_w = (int)(double.Parse(width) / this.physical_length); //线的间距(目前当成像素,将来需要从微米转成像素)
  1896. ////per_w = Math.Max(1, per_w);//避免报错“尝试除以零”
  1897. ////hlines.Clear();
  1898. ////{
  1899. //// for (int i = 0; i < n; i++)
  1900. //// {
  1901. //// Line l = new Line(new System.Drawing.Point(0, linebottom.startPoint.Y - per_w * i), new System.Drawing.Point(this.bitmap/*lab1Img*/.Width, linebottom.startPoint.Y - per_w * i));
  1902. //// //drawg.DrawLine(new Pen(Color.FromArgb(255, 0, 208, 202), zoom), l.startPoint, l.endPoint);
  1903. //// hlines.Add(l);
  1904. //// }
  1905. ////}
  1906. ////honlines.Clear();
  1907. ////btnflag = 1;
  1908. //this.documentWorkspace.Refresh();
  1909. ////this.trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1910. }
  1911. #region 参数保存及提取
  1912. /// <summary>
  1913. /// 保存参数的key,value和type
  1914. /// </summary>
  1915. /// <param name="param_key"></param>
  1916. /// <param name="param_value"></param>
  1917. /// <param name="param_type"></param>
  1918. private void saveParamValue(string param_key, string param_value, int param_type)
  1919. {
  1920. bool foundItem = false;
  1921. foreach (var item in this.analysisModel.ListParam)
  1922. {
  1923. if (item.param_key.Equals(param_key) && item.menuId == this.menuId)
  1924. {
  1925. item.param_value = param_value;
  1926. item.setValue();
  1927. foundItem = true;
  1928. break;
  1929. }
  1930. }
  1931. if (!foundItem)
  1932. {
  1933. GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel();
  1934. analysisItem.menuId = this.menuId;
  1935. analysisItem.param_key = param_key;
  1936. analysisItem.param_type = param_type;
  1937. analysisItem.param_value = param_value;
  1938. analysisItem.setValue();
  1939. this.analysisModel.ListParam.Add(analysisItem);
  1940. }
  1941. }
  1942. /// <summary>
  1943. /// 保存界面中的参数到model
  1944. /// </summary>
  1945. private void saveDialogParamValues()
  1946. {
  1947. saveParamValue(ParamKey_Report, checkBox_generateReport_opensetting.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//报告设置
  1948. saveParamValue(ParamKey_PoreColour, panel1.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//孔隙颜色
  1949. saveParamValue(ParamKey_PoreSpacing, textBox1.Text, (int)Base.Dtryt.ItemString);//孔隙辅助线间距
  1950. saveParamValue(ParamKey_GuideColour, panel4.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//辅助线颜色
  1951. saveParamValue(ParamKey_GuideWidth, textBox3.Text, (int)Base.Dtryt.ItemString);//辅助线线宽
  1952. saveParamValue(ParamKey_GuideNumber, textBox6.Text, (int)Base.Dtryt.ItemString);//辅助线条数
  1953. saveParamValue(ParamKey_GuideSpacing, textBox4.Text, (int)Base.Dtryt.ItemString);//辅助线间距
  1954. saveParamValue(ParamKey_PoreSetColour, panel3.BackColor.ToArgb().ToString(), (int)Base.Dtryt.Color);//孔隙设置颜色
  1955. saveParamValue(ParamKey_PoreSetWidth, textBox10.Text, (int)Base.Dtryt.ItemString);//孔隙设置线宽
  1956. saveParamValue(ParamKey_DecimalPlace, numericUpDown1_0 != null ? numericUpDown1_0.Value.ToString() : "", (int)Base.Dtryt.Decimal);//保留小数位数
  1957. }
  1958. /// <summary>
  1959. /// 获取保存的参数
  1960. /// </summary>
  1961. private void GetListParamModel()
  1962. {
  1963. if (this.analysisModel != null)
  1964. {
  1965. for (int i = 0; i < this.analysisModel.ListParam.Count; i++)
  1966. {
  1967. switch (this.analysisModel.ListParam[i].param_key)
  1968. {
  1969. case ParamKey_Report:
  1970. checkBox_generateReport_opensetting.Checked = (Boolean)this.analysisModel.ListParam[i].value;
  1971. break;
  1972. case ParamKey_PoreColour:
  1973. panel1.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1974. break;
  1975. case ParamKey_PoreSpacing:
  1976. textBox1.Text = this.analysisModel.ListParam[i].value.ToString();
  1977. break;
  1978. case ParamKey_GuideColour:
  1979. panel4.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1980. break;
  1981. case ParamKey_GuideWidth:
  1982. textBox3.Text = this.analysisModel.ListParam[i].value.ToString();
  1983. trackBar3.Value = Convert.ToInt32(this.textBox3.Text);
  1984. break;
  1985. case ParamKey_GuideNumber:
  1986. textBox6.Text = this.analysisModel.ListParam[i].value.ToString();
  1987. break;
  1988. case ParamKey_GuideSpacing:
  1989. textBox4.Text = this.analysisModel.ListParam[i].value.ToString();
  1990. break;
  1991. case ParamKey_PoreSetColour:
  1992. panel3.BackColor = Color.FromArgb((int)this.analysisModel.ListParam[i].value);
  1993. break;
  1994. case ParamKey_PoreSetWidth:
  1995. textBox10.Text = this.analysisModel.ListParam[i].value.ToString();
  1996. trackBar4.Value = Convert.ToInt32(this.textBox10.Text);
  1997. break;
  1998. case ParamKey_DecimalPlace:
  1999. numericUpDown1_0.Value = decimal.Parse(this.analysisModel.ListParam[i].param_value);
  2000. break;
  2001. }
  2002. }
  2003. }
  2004. }
  2005. /// <summary>
  2006. /// 关闭窗体时保存参数
  2007. /// </summary>
  2008. /// <param name="sender"></param>
  2009. /// <param name="e"></param>
  2010. private void TABM3Dialog_FormClosing(object sender, FormClosingEventArgs e)
  2011. {
  2012. this.saveDialogParamValues();
  2013. //xml保存路径
  2014. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml";
  2015. GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer<GrainSizeAnalysisModel>(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open));
  2016. foreach (var analysisItem in this.analysisModel.ListParam)
  2017. {
  2018. bool foundItem = false;
  2019. foreach (var item in analysisModelXml.ListParam)
  2020. {
  2021. if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId)
  2022. {
  2023. item.param_value = analysisItem.param_value;
  2024. foundItem = true;
  2025. break;
  2026. }
  2027. }
  2028. if (!foundItem)
  2029. analysisModelXml.ListParam.Add(analysisItem.cloneModel());
  2030. }
  2031. //按路径和名称保存xml文件
  2032. string userInfoXml = XmlSerializeHelper.XmlSerialize<GrainSizeAnalysisModel>(analysisModelXml);
  2033. //保存xml
  2034. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create);
  2035. }
  2036. #endregion
  2037. }
  2038. }