NormalOperationDialog.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  1. using Metis.ParameterSet;
  2. using PaintDotNet.Base;
  3. using PaintDotNet.Base.CommTool;
  4. using PaintDotNet.Base.Enum;
  5. using PaintDotNet.Base.Functionodel;
  6. using PaintDotNet.CustomControl;
  7. using PaintDotNet.Data.Action;
  8. using PaintDotNet.Data.Param;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. using static Metis.ParameterSet.ImageMenu;
  17. namespace PaintDotNet.Processing
  18. {
  19. /// <summary>
  20. /// 预处理 - 常规操作
  21. /// </summary>
  22. internal class NormalOperationDialog : Form
  23. {
  24. /// <summary>
  25. /// 步长 初始值1,依次增加
  26. /// </summary>
  27. string stepLength = "00" + Startup.instance.step_length;
  28. /// <summary>
  29. /// 公共按钮
  30. /// </summary>
  31. private CommonControlButtons commonControlButtons;
  32. /// <summary>
  33. /// 图像面板
  34. /// </summary>
  35. private DocumentWorkspaceWindow documentWorkspace;
  36. /// <summary>
  37. /// 主工作空间
  38. /// </summary>
  39. private AppWorkspace appWorkspace;
  40. /// <summary>
  41. /// 当前处理的程序
  42. /// </summary>
  43. private ParamObject action;
  44. /// <summary>
  45. /// 当前活动的图像
  46. /// </summary>
  47. private OpenCvSharp.Mat imageMat;
  48. /// <summary>
  49. /// 调用调色板的控件
  50. /// </summary>
  51. private Panel panel2;
  52. /// <summary>
  53. /// 调色板
  54. /// </summary>
  55. private ColorsForm colorsFormGrid;
  56. /// <summary>
  57. /// 一些方法用到了微米换算
  58. /// </summary>
  59. private double ruleValue = 0.0;
  60. /// <summary>
  61. /// 菜单id
  62. /// </summary>
  63. private ActionType menuId;
  64. /// <summary>
  65. /// stringarry参数高度
  66. /// </summary>
  67. private int defaultHeight = 45;
  68. // <summary>
  69. /// 如果有参数保存,将参数带入
  70. /// </summary>
  71. private Boolean initPamasValues = false;
  72. /// <summary>
  73. /// 是否点击过应用按钮
  74. /// 如果没有点过,直接点确定还需要走一遍方法,
  75. /// 如果已经点过,直接拿当前图片
  76. /// </summary>
  77. private bool applyButtonClick = false;
  78. private PdnMenuItem MenuItem;
  79. [Browsable(false)]
  80. public AppWorkspace AppWorkspace
  81. {
  82. get
  83. {
  84. return this.appWorkspace;
  85. }
  86. set
  87. {
  88. this.appWorkspace = value;
  89. }
  90. }
  91. /// <summary>
  92. /// dialog
  93. /// </summary>
  94. /// <param name="appWorkspace"></param>
  95. /// <param name="menuId">对应菜单的id</param>
  96. public NormalOperationDialog(AppWorkspace appWorkspace, ActionType menuId, string dialogText,PdnMenuItem menuItem)
  97. {
  98. this.menuId = menuId;
  99. this.MenuItem = menuItem;
  100. InitializeComponent();
  101. InitializeLanguageText();
  102. //
  103. // 设置Dialog属性
  104. //
  105. this.AppWorkspace = appWorkspace;
  106. this.StartPosition = FormStartPosition.CenterScreen;
  107. this.Icon = PdnInfo.AppIcon;
  108. this.Text = dialogText;
  109. //
  110. //初始化色板
  111. //
  112. this.colorsFormGrid = new ColorsForm();
  113. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  114. this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  115. //
  116. //初始化图像控件
  117. //
  118. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  119. this.documentWorkspace.Dock = DockStyle.Fill;
  120. this.documentWorkspace.HookMouseEvents();
  121. this.documentWorkspace.AuxiliaryLineEnabled = false;
  122. this.documentWorkspace.Visible = false;
  123. this.groupBox1.Controls.Add(documentWorkspace);
  124. //
  125. //初始化操作按钮
  126. //
  127. this.commonControlButtons = new CommonControlButtons();
  128. this.commonControlButtons.Dock = DockStyle.Top;
  129. this.commonControlButtons.Height = 30;
  130. this.groupBox1.Controls.Add(commonControlButtons);
  131. this.imageMat = this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
  132. Document document = Document.FromImageMat(imageMat.Clone());
  133. this.documentWorkspace.Document = document;
  134. this.documentWorkspace.Visible = true;
  135. this.documentWorkspace.GraphicsList = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList;
  136. this.documentWorkspace.PhaseModels = this.appWorkspace.ActiveDocumentWorkspace.PhaseModelsForCopy;
  137. //获取
  138. //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
  139. ruleValue = this.AppWorkspace.ActiveDocumentWorkspace.GetRuler(MeasurementUnit.Micron);
  140. resetNumber();
  141. InitCommonButtonEvent();
  142. SpecialAction(menuId, Color.Yellow.ToArgb());
  143. }
  144. /*/// <summary>
  145. /// 主要是为了改变自定义的进度条
  146. /// </summary>
  147. /// <param name="sender"></param>
  148. /// <param name="e"></param>
  149. private void decimalScopeControl_ValueChangedEvent(object sender, EventArgs e)
  150. {
  151. //特殊处理孔洞删除
  152. if (menuId == ActionType.ActionHoleRemoval)
  153. {
  154. 1111111
  155. }
  156. }*/
  157. private void SpecialAction(ActionType menuId, int color)
  158. {
  159. //特殊处理孔洞删除
  160. if (menuId == ActionType.ActionHoleRemoval)
  161. {
  162. //this.parametersSettingControl.applyButton.Visible = false;
  163. /*List<double> oneL = new List<double>();
  164. oneL.Add(0);
  165. oneL.Add(double.MaxValue);
  166. this.action.Lists[1].value = oneL;*/
  167. List<PhaseModel> phases = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true && a.mat != null);
  168. if (phases.Count > 0)
  169. {
  170. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true && a.mat != null);
  171. for (int i = 0; i < phases.Count; i++)
  172. {
  173. PhaseModel model = new PhaseModel();
  174. model.choise = phases[i].choise;
  175. model.color = phases[i].color;
  176. model.name = phases[i].name;
  177. model.position = phases[i].position;
  178. model.mat = new OpenCvSharp.Mat();
  179. phases[i].mat.CopyTo(model.mat);
  180. this.action.Lists[3].Value = color;
  181. phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
  182. this.documentWorkspace.Refresh();
  183. }
  184. }
  185. }
  186. }
  187. private void InitCommonButtonEvent()
  188. {
  189. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  190. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  191. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  192. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  193. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  194. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  195. }
  196. private void zoomInButton_Click(object sender, EventArgs e)
  197. {
  198. this.documentWorkspace.ZoomIn();
  199. }
  200. private void zoomOutButton_Click(object sender, EventArgs e)
  201. {
  202. this.documentWorkspace.ZoomOut();
  203. }
  204. private void zoomToWindowButton_Click(object sender, EventArgs e)
  205. {
  206. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  207. }
  208. private void actualSizeButton_Click(object sender, EventArgs e)
  209. {
  210. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  211. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  212. }
  213. private void pointerButton_Click(object sender, EventArgs e)
  214. {
  215. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  216. }
  217. private void mobileModeButton_Click(object sender, EventArgs e)
  218. {
  219. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  220. }
  221. /// <summary>
  222. /// 切换参数
  223. /// </summary>
  224. /// <param name="sender"></param>
  225. /// <param name="e"></param>
  226. private void Radio_CheckedChanged(object sender, EventArgs e)
  227. {
  228. //如果是孔洞删除,则判断范围的最大最小值
  229. if(menuId == ActionType.ActionHoleRemoval)
  230. {
  231. if (((RadioButton)sender).Checked)
  232. {
  233. GetMinMaxValue();
  234. }
  235. /*switch ((FilterParameters)(((RadioButton)sender).Tag))
  236. {
  237. case FilterParameters.Area:
  238. if(((RadioButton)sender).Checked)
  239. {
  240. GetMinMaxValue();
  241. }
  242. break;
  243. case FilterParameters.AreaRatio:
  244. if (((RadioButton)sender).Checked)
  245. {
  246. GetMinMaxValue();
  247. }
  248. break;
  249. case FilterParameters.AspectRatio:
  250. if (((RadioButton)sender).Checked)
  251. {
  252. GetMinMaxValue();
  253. }
  254. break;
  255. case FilterParameters.LongTrail:
  256. if (((RadioButton)sender).Checked)
  257. {
  258. GetMinMaxValue();
  259. }
  260. break;
  261. }*/
  262. }
  263. }
  264. private void GetMinMaxValue()
  265. {
  266. DecimalScopeControl control = (DecimalScopeControl)(groupBoxParam.Controls.Find("ActionHoleRemoval", false)[0]);
  267. control.Maximum2 = int.MaxValue;
  268. this.applyButtonImpl(null, null);
  269. if(((Action914)action).outmax>-1)
  270. {
  271. control.Maximum2 = (decimal)(((Action914)action).outmax);
  272. }
  273. }
  274. private void CheckBox_CheckedChanged(object sender, EventArgs e)
  275. {
  276. }
  277. /// <summary>
  278. /// 相颜色点击事件
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void panel2_Click(object sender, EventArgs e)
  283. {
  284. this.panel2 = ((Panel)sender);
  285. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(panel2.BackColor);
  286. this.colorsFormGrid.ShowDialog();
  287. }
  288. /// <summary>
  289. /// Panel2的调色板颜色改变
  290. /// </summary>
  291. /// <param name="sender"></param>
  292. /// <param name="e"></param>
  293. private void gridColorChanged(object sender, EventArgs e)
  294. {
  295. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  296. //更改背景色,触发事件
  297. this.panel2.BackColor = color;
  298. ////改变配置文件里面的相颜色
  299. //this.binaryExtractionModel.PhaseColor = color.ToArgb();
  300. if (menuId == ActionType.ActionHoleRemoval)
  301. this.SpecialAction(this.menuId, color.ToArgb());
  302. //else OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
  303. //关闭色板
  304. this.colorsFormGrid.Close();
  305. }
  306. /// <summary>
  307. /// 初始化数据
  308. /// </summary>
  309. public void InitData()
  310. {
  311. if (menuId == ActionType.ActionHoleRemoval)
  312. {
  313. GetMinMaxValue();
  314. }
  315. }
  316. private void resetNumber()
  317. {
  318. switch (menuId)
  319. {
  320. //二值操作->腐蚀
  321. case ActionType.ActionErosion:
  322. action = new Data.Action.Action903();
  323. break;
  324. //二值操作->膨胀
  325. case ActionType.ActionDilation:
  326. action = new Data.Action.Action904();
  327. break;
  328. //二值操作->粗化
  329. case ActionType.ActionThickening:
  330. action = new Data.Action.Action905();
  331. break;
  332. //二值操作->细化
  333. case ActionType.ActionThinning:
  334. action = new Data.Action.Action906();
  335. break;
  336. //二值操作->开运算
  337. case ActionType.ActionOpenExtraction:
  338. action = new Data.Action.Action907();
  339. break;
  340. //二值操作->闭运算
  341. case ActionType.ActionCloseExtraction:
  342. action = new Data.Action.Action908();
  343. break;
  344. //二值操作->形态学分割
  345. case ActionType.ActionMorphologySegment:
  346. action = new Data.Action.Action909();
  347. break;
  348. //二值操作->分水岭分割
  349. case ActionType.ActionWatershedSegment:
  350. action = new Data.Action.Action910();
  351. break;
  352. //二值操作->去碎屑
  353. case ActionType.ActionDebris:
  354. action = new Data.Action.Action911();
  355. break;
  356. //二值操作->抽骨架
  357. case ActionType.ActionSkeleton:
  358. action = new Data.Action.Action912();
  359. break;
  360. //二值操作->孔洞删除
  361. case ActionType.ActionHoleRemoval:
  362. action = new Data.Action.Action914();
  363. break;
  364. default:
  365. action = new Data.Action.Action903();
  366. break;
  367. }
  368. for (int i = groupBoxParam.Controls.Count - 1; i > 0; i--)
  369. {
  370. if (!groupBoxParam.Controls[i].Name.Equals("button5"))
  371. groupBoxParam.Controls.RemoveAt(i);
  372. }
  373. if (action.Lists == null || action.Lists.Count < 1)
  374. {
  375. Label label = new Label();
  376. label.Left = 7;
  377. label.Top = 31;
  378. label.Size = new Size(60, 12);
  379. label.TextAlign = ContentAlignment.TopLeft;
  380. label.Text = PdnResources.GetString("Menu.Noparams.text");
  381. groupBoxParam.Controls.Add(label);
  382. GetParameters(Startup.instance.binaryActionModel);
  383. }
  384. else
  385. {
  386. //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
  387. if (AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId)
  388. {
  389. foreach (Args arg in action.Lists)
  390. {
  391. Args param1 = AppWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key));
  392. if (param1.value != null)
  393. arg.Value = param1.value;
  394. }
  395. AppWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数
  396. }
  397. else
  398. {
  399. GetParameters(Startup.instance.binaryActionModel);
  400. }
  401. int controlsTop = 0;
  402. //初始化手动控件
  403. for (int i = 0; i < action.Lists.Count; i++)
  404. {
  405. Args args = action.Lists[i];
  406. if (args is IntegerNumber || args is DecimalNumber || args is OddNumber)
  407. {
  408. CustomControl.NumberParamControl numberParam = new CustomControl.NumberParamControl();
  409. numberParam.Left = 78;
  410. numberParam.Top = 35 + controlsTop;
  411. //设置参数范围
  412. numberParam.paramIndex = 100 + i;
  413. if (args is DecimalNumber)
  414. {
  415. numberParam.DecimalPlaces = ((DecimalNumber)args).DecimalPlaces;
  416. numberParam.Minimum = (double)((DecimalNumber)args).Min;
  417. numberParam.Maximum = (double)((DecimalNumber)args).Max;
  418. }
  419. else if (args is OddNumber)
  420. {
  421. numberParam.Increment = 2;
  422. numberParam.Minimum = ((OddNumber)args).Min;
  423. numberParam.Maximum = ((OddNumber)args).Max;
  424. numberParam.IsOddNumber = true;
  425. }
  426. else
  427. {
  428. numberParam.DecimalPlaces = 0;
  429. numberParam.Minimum = ((IntegerNumber)args).Min;
  430. numberParam.Maximum = ((IntegerNumber)args).Max;
  431. }
  432. double fnum = 0;
  433. if (double.TryParse(args.value.ToString(), out fnum))
  434. {
  435. numberParam.Value = fnum;
  436. }
  437. groupBoxParam.Controls.Add(numberParam);
  438. groupBoxParam.Controls.SetChildIndex(numberParam, 100 + i);
  439. if (args is DecimalNumber)
  440. {
  441. numberParam.ValueChanged += new EventHandler(((DecimalNumber)args).numberParam_ValueChanged);
  442. }
  443. else if (args is OddNumber)
  444. {
  445. numberParam.ValueChanged += new EventHandler(((OddNumber)args).numberParam_ValueChanged);
  446. }
  447. else
  448. {
  449. numberParam.ValueChanged += new EventHandler(((IntegerNumber)args).numberParam_ValueChanged);
  450. }
  451. numberParam.ValueChanged += this.ParameterChangeEvent;
  452. Label label = new Label();
  453. label.Left = 19;
  454. label.Top = 40 + controlsTop;
  455. label.Size = new Size(53, 12);
  456. label.TextAlign = ContentAlignment.MiddleRight;
  457. label.Text = args.name + ":";
  458. groupBoxParam.Controls.Add(label);
  459. controlsTop += 45;
  460. }
  461. else if (args is ChoiseArray)
  462. {
  463. Label label = new Label();
  464. label.Left = 19;
  465. label.Top = 40 + controlsTop;
  466. label.Size = new Size(53, 12);
  467. label.TextAlign = ContentAlignment.MiddleRight;
  468. label.Text = args.name + ":";
  469. groupBoxParam.Controls.Add(label);
  470. //初始化选项列表
  471. for (int j = 0; j < args.choiseList.Count; j++)
  472. {
  473. BooleanObject argsChoise = args.choiseList[j] as BooleanObject;
  474. RadioButton radio = new RadioButton();
  475. if (j == 0)
  476. {
  477. radio.Checked = true;
  478. }
  479. radio.AutoSize = true;
  480. radio.Location = new Point(88, 40 + controlsTop);
  481. radio.Text = argsChoise.name + "";
  482. radio.Tag = argsChoise.Key;
  483. radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
  484. radio.CheckedChanged += Radio_CheckedChanged;
  485. radio.CheckedChanged += this.ParameterChangeEvent;
  486. groupBoxParam.Controls.Add(radio);
  487. controlsTop += 45;
  488. }
  489. }
  490. else if (args is ColorNumber)
  491. {
  492. Label label = new Label();
  493. label.Left = 5;
  494. label.Top = 40 + controlsTop;
  495. label.Size = new Size(65, 12);
  496. label.TextAlign = ContentAlignment.MiddleRight;
  497. label.Text = args.name + ":";
  498. groupBoxParam.Controls.Add(label);
  499. Panel panel = new Panel();
  500. panel.BackColor = Color.FromArgb(int.Parse(args.Value.ToString()));
  501. panel.Size = new Size(100, 35);
  502. panel.Top = 25 + controlsTop;
  503. panel.Left = 70;
  504. if (menuId != ActionType.ActionHoleRemoval)
  505. {
  506. panel.BackColorChanged += ((ColorNumber)args).numberParam_ValueChanged;
  507. panel.BackColorChanged += this.ParameterChangeEvent;
  508. }
  509. panel.Click += new EventHandler(panel2_Click);
  510. groupBoxParam.Controls.Add(panel);
  511. controlsTop += 45;
  512. }
  513. else if (args is StringArray)
  514. {
  515. Label label = new Label();
  516. label.Left = 5;
  517. label.Top = 40 + controlsTop;
  518. label.Size = new Size(65, 12);
  519. label.TextAlign = ContentAlignment.MiddleRight;
  520. label.Text = args.name + ":";
  521. groupBoxParam.Controls.Add(label);
  522. Panel panel = new Panel();
  523. panel.Size = new Size(200, defaultHeight);
  524. panel.Top = 40 + controlsTop;
  525. panel.Left = 70;
  526. int position = 1;
  527. int topMargin = 0;
  528. //循环字典,铺多个radio
  529. foreach (var item in (Dictionary<Enum, object>)(args.initialValue))
  530. {
  531. int xvalue = 0;
  532. if (position % 1 == 0) xvalue = 0;
  533. if (position % 2 == 0) xvalue = 1;
  534. //if (position % 3 == 0) xvalue = 2;
  535. RadioButton radio = new RadioButton();
  536. if (position == 1)
  537. {
  538. radio.Checked = true;
  539. }
  540. radio.AutoSize = true;
  541. radio.Location = new Point(xvalue * 110, topMargin);
  542. radio.Text = item.Value.ToString();
  543. radio.Tag = item.Key;
  544. if (args.value != null && (int)(args.value) == (int)(object)item.Key)
  545. {
  546. radio.Checked = true;
  547. }
  548. else
  549. {
  550. radio.Checked = false;
  551. }
  552. radio.CheckedChanged += ((StringArray)args).numberParam_ValueChanged;
  553. radio.CheckedChanged += Radio_CheckedChanged;
  554. radio.CheckedChanged += this.ParameterChangeEvent;
  555. panel.Controls.Add(radio);
  556. if (position % 2 == 0) topMargin += 25;
  557. position++;
  558. }
  559. groupBoxParam.Controls.Add(panel);
  560. controlsTop += 45;
  561. }
  562. else if (args is DecimalScope)
  563. {
  564. DecimalScopeControl decimalScopeControl;
  565. if (this.menuId == ActionType.ActionHoleRemoval)
  566. {
  567. decimalScopeControl = new DecimalScopeControl(PdnResources.GetString("Menu.numberrange.text") + ":", true, 100);
  568. }
  569. else
  570. {
  571. decimalScopeControl = new DecimalScopeControl(PdnResources.GetString("Menu.numberrange.text") + ":");
  572. }
  573. decimalScopeControl.Name = "ActionHoleRemoval";
  574. decimalScopeControl.Size = new Size(350, 30);
  575. decimalScopeControl.Top = 45 + controlsTop;
  576. decimalScopeControl.Left = 5;
  577. decimalScopeControl.numericUpDown1.Width = 50;
  578. decimalScopeControl.numericUpDown2.Width = 50;
  579. decimalScopeControl.DecimalPlaces = 2;
  580. decimalScopeControl.ValueChanged += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
  581. decimalScopeControl.ValueChanged += this.ParameterChangeEvent;
  582. groupBoxParam.Controls.Add(decimalScopeControl);
  583. controlsTop += 45;
  584. //decimalScopeControl.minValue = ((List<double>)(args.Value))[0];
  585. //decimalScopeControl.maxValue = ((List<double>)(args.Value))[1];
  586. //decimalScopeControl.numericUpDown1.Value = (decimal)((List<double>)(args.Value))[0];
  587. //decimalScopeControl.numericUpDown2.Value = (decimal)((List<double>)(args.Value))[1];
  588. }
  589. else if (args is BooleanObject)
  590. {
  591. Label label = new Label();
  592. label.Left = 5;
  593. label.Top = 40 + controlsTop;
  594. label.Size = new Size(65, 12);
  595. label.TextAlign = ContentAlignment.MiddleRight;
  596. label.Text = args.name + ":";
  597. groupBoxParam.Controls.Add(label);
  598. CheckBox checkBox = new CheckBox();
  599. checkBox.Text = args.name;
  600. checkBox.Top = 35 + controlsTop;
  601. checkBox.Left = 70;
  602. checkBox.Checked = (bool)(((BooleanObject)args).value);
  603. checkBox.CheckedChanged += new EventHandler(((BooleanObject)args).CheckBox_ValueChanged);
  604. checkBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
  605. checkBox.CheckedChanged += this.ParameterChangeEvent;
  606. groupBoxParam.Controls.Add(checkBox);
  607. controlsTop += 45;
  608. }
  609. }
  610. }
  611. InitData();
  612. }
  613. private void ParameterChangeEvent(object sender, EventArgs e)
  614. {
  615. this.applyButtonClick = false;
  616. }
  617. private void BshTransferAdjustDialog_Load(object sender, EventArgs e)
  618. {
  619. //设置该参数false,以便方便的从子线程更新UI
  620. //虽然这种方式省事,但是从严谨的角度考虑,在复杂多线程的情况下不能这样处理
  621. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
  622. //图像名称输入框
  623. informationControl.fileNameTextBox1.Text = this.Text + "-" + stepLength;
  624. parametersSettingControl.applyButtonClick += new EventHandler(applyButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
  625. parametersSettingControl.sureButtonClick += new EventHandler(sureButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
  626. }
  627. /// <summary>
  628. /// 应用
  629. /// </summary>
  630. /// <param name="sender"></param>
  631. /// <param name="e"></param>
  632. private void applyButtonImpl(object sender, EventArgs e)
  633. {
  634. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  635. int itemCount = 100;
  636. ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
  637. System.Threading.ThreadStart copyThreadProc =
  638. delegate ()
  639. {
  640. try
  641. {
  642. //如果有选中的相
  643. List<PhaseModel> phases = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  644. if (action.MenuId == ActionType.ActionWatershedSegment)
  645. {
  646. if (phases.Count > 0)
  647. {
  648. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  649. for (int i = 0; i < phases.Count; i++)
  650. {
  651. PhaseModel model = new PhaseModel();
  652. model.choise = phases[i].choise;
  653. model.color = phases[i].color;
  654. model.name = phases[i].name;
  655. model.position = phases[i].position;
  656. model.mat = new OpenCvSharp.Mat();
  657. phases[i].mat.CopyTo(model.mat);
  658. phasesCopy[i].mat = action.PerformProcess(this.imageMat.Clone(), model, new Point()/*ruleValue*/);
  659. this.documentWorkspace.Refresh();
  660. }
  661. }
  662. else
  663. {
  664. OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
  665. Document doc = Document.FromMat(mat);
  666. this.documentWorkspace.Document = doc;
  667. this.documentWorkspace.Refresh();
  668. }
  669. return;
  670. }
  671. if (phases.Count > 0)
  672. {
  673. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  674. for (int i = 0; i < phases.Count; i++)
  675. {
  676. if (phases[i].mat != null)
  677. {
  678. PhaseModel model = new PhaseModel();
  679. model.choise = phases[i].choise;
  680. model.color = phases[i].color;
  681. model.name = phases[i].name;
  682. model.position = phases[i].position;
  683. model.mat = new OpenCvSharp.Mat();
  684. phases[i].mat.CopyTo(model.mat);
  685. phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
  686. this.documentWorkspace.Refresh();
  687. }
  688. }
  689. }
  690. else
  691. {
  692. OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
  693. Document doc = Document.FromMat(mat);
  694. this.documentWorkspace.Document = doc;
  695. this.documentWorkspace.Refresh();
  696. }
  697. this.applyButtonClick = true;
  698. }
  699. catch(Exception)
  700. {
  701. }
  702. finally
  703. {
  704. progressEvents.EndOperation(OperationResult.Finished);
  705. }
  706. };
  707. procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
  708. }
  709. /// <summary>
  710. /// 确定
  711. /// </summary>
  712. /// <param name="sender"></param>
  713. /// <param name="e"></param>
  714. internal void sureButtonImpl(object sender, EventArgs e)
  715. {
  716. ProgressThreadProcClass procClass = new ProgressThreadProcClass();
  717. int itemCount = 100;
  718. ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
  719. System.Threading.ThreadStart copyThreadProc =
  720. delegate ()
  721. {
  722. try
  723. {
  724. if(!this.applyButtonClick)
  725. {
  726. //特殊处理孔洞删除
  727. if (menuId == ActionType.ActionHoleRemoval)
  728. {
  729. this.action.Lists[3].value = Color.Transparent.ToArgb();
  730. }
  731. //如果有选中的相
  732. List<PhaseModel> phases = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  733. if (action.MenuId == ActionType.ActionWatershedSegment)
  734. {
  735. if (phases.Count > 0)
  736. {
  737. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  738. for (int i = 0; i < phases.Count; i++)
  739. {
  740. PhaseModel model = new PhaseModel();
  741. model.choise = phases[i].choise;
  742. model.color = phases[i].color;
  743. model.name = phases[i].name;
  744. model.position = phases[i].position;
  745. model.mat = new OpenCvSharp.Mat();
  746. phases[i].mat.CopyTo(model.mat);
  747. phasesCopy[i].mat = action.PerformProcess(this.imageMat.Clone(), model, new Point()/*ruleValue*/);
  748. this.documentWorkspace.Refresh();
  749. }
  750. }
  751. else
  752. {
  753. OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
  754. Document doc = Document.FromMat(mat);
  755. this.documentWorkspace.Document = doc;
  756. this.documentWorkspace.Refresh();
  757. }
  758. this.Invoke(new EventHandler(delegate
  759. {
  760. if (informationControl.radioButton1.Checked)
  761. {
  762. this.OpenFileImpl();
  763. }
  764. else
  765. {
  766. this.AppWorkspace.ActiveDocumentWorkspace.phaseModels = this.documentWorkspace.PhaseModels;
  767. this.AppWorkspace.ActiveDocumentWorkspace.Refresh();
  768. }
  769. this.Close();
  770. }));
  771. return;
  772. }
  773. if (phases.Count > 0)
  774. {
  775. List<PhaseModel> phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
  776. for (int i = 0; i < phases.Count; i++)
  777. {
  778. if (phases[i].mat != null)
  779. {
  780. PhaseModel model = new PhaseModel();
  781. model.choise = phases[i].choise;
  782. model.color = phases[i].color;
  783. model.name = phases[i].name;
  784. model.position = phases[i].position;
  785. model.mat = new OpenCvSharp.Mat();
  786. phases[i].mat.CopyTo(model.mat);
  787. phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
  788. this.documentWorkspace.Refresh();
  789. }
  790. }
  791. }
  792. else
  793. {
  794. OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
  795. Document doc = Document.FromMat(mat);
  796. this.documentWorkspace.Document = doc;
  797. this.documentWorkspace.Refresh();
  798. }
  799. }
  800. this.Invoke(new EventHandler(delegate
  801. {
  802. if (informationControl.radioButton1.Checked)
  803. {
  804. this.OpenFileImpl();
  805. }
  806. else
  807. {
  808. this.AppWorkspace.ActiveDocumentWorkspace.phaseModels = this.documentWorkspace.PhaseModels;
  809. this.AppWorkspace.ActiveDocumentWorkspace.Refresh();
  810. }
  811. this.Close();
  812. }));
  813. }
  814. catch (Exception)
  815. {
  816. }
  817. finally
  818. {
  819. progressEvents.EndOperation(OperationResult.Finished);
  820. }
  821. };
  822. procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
  823. /*//生成新图-是
  824. if (informationControl.radioButton1.Checked)
  825. {
  826. //特殊处理孔洞删除
  827. if (menuId == ActionType.ActionHoleRemoval)
  828. {
  829. this.action.Lists[3].value = Color.Transparent.ToArgb();
  830. }
  831. if(!this.applyButtonClick)
  832. {
  833. this.applyButtonImpl(sender, e);
  834. }
  835. this.OpenFileImpl();
  836. }
  837. else
  838. {
  839. //特殊处理孔洞删除
  840. if (menuId == ActionType.ActionHoleRemoval)
  841. {
  842. this.action.Lists[3].value = Color.Transparent.ToArgb();
  843. }
  844. if (!this.applyButtonClick)
  845. {
  846. this.applyButtonImpl(sender, e);
  847. }
  848. this.AppWorkspace.ActiveDocumentWorkspace.phaseModels = this.documentWorkspace.PhaseModels;
  849. this.AppWorkspace.ActiveDocumentWorkspace.Refresh();
  850. }
  851. this.Close();*/
  852. }
  853. /// <summary>
  854. /// 生成新图
  855. /// </summary>
  856. /// <param name="mat"></param>
  857. private void OpenFileImpl()
  858. {
  859. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  860. Document document = Document.FromImageMat(this.documentWorkspace.CompositionSurface.CreatedAliasedMat().Clone());//return mat/*.Clone()*/;//待测试
  861. dw.Document = document;
  862. dw.PhaseModels = this.documentWorkspace.PhaseModelsForCopy;
  863. dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  864. dw.rules = new Dictionary<MeasurementUnit, double>(this.AppWorkspace.ActiveDocumentWorkspace.rules);
  865. //dw.PanelBottom.documentStrip.ShowPictures = false;
  866. dw.fileText = informationControl.fileNameTextBox1.Text;
  867. AppWorkspace.ActiveDocumentWorkspace = dw;
  868. Startup.instance.step_length += 1;
  869. }
  870. /// <summary>
  871. /// 参数-重设
  872. /// </summary>
  873. /// <param name="sender"></param>
  874. /// <param name="e"></param>
  875. private void button5_Click(object sender, EventArgs e)
  876. {
  877. GetParameters(Startup.instance.binaryActionModel);
  878. //初始化/重置参数
  879. resetNumber();
  880. }
  881. #region 设计器
  882. /// <summary>
  883. /// Required designer variable.
  884. /// </summary>
  885. private System.ComponentModel.IContainer components = null;
  886. /// <summary>
  887. /// Clean up any resources being used.
  888. /// </summary>
  889. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  890. protected override void Dispose(bool disposing)
  891. {
  892. if (disposing && (components != null))
  893. {
  894. components.Dispose();
  895. }
  896. base.Dispose(disposing);
  897. }
  898. #region Windows Form Designer generated code
  899. private void InitializeLanguageText()
  900. {
  901. this.groupBoxParam.Text = PdnResources.GetString("Menu.params.text");
  902. this.button5.Text = PdnResources.GetString("Menu.rebuild.Text");
  903. this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
  904. this.Text = PdnResources.GetString("Menu.geprocessiconditioningsaturationbrigh.Text");
  905. }
  906. /// <summary>
  907. /// Required method for Designer support - do not modify
  908. /// the contents of this method with the code editor.
  909. /// </summary>
  910. private void InitializeComponent()
  911. {
  912. this.parametersSettingControl = new PaintDotNet.CustomControl.ParametersSettingAdjustControl();
  913. this.informationControl = new PaintDotNet.CustomControl.InformationAdjustControl();
  914. this.groupBoxParam = new System.Windows.Forms.GroupBox();
  915. this.button5 = new System.Windows.Forms.Button();
  916. this.groupBox1 = new System.Windows.Forms.GroupBox();
  917. this.groupBoxParam.SuspendLayout();
  918. this.SuspendLayout();
  919. //
  920. // parametersSettingControl
  921. //
  922. this.parametersSettingControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  923. | System.Windows.Forms.AnchorStyles.Right)));
  924. this.parametersSettingControl.Location = new System.Drawing.Point(12, 12);
  925. this.parametersSettingControl.Name = "parametersSettingControl";
  926. this.parametersSettingControl.Size = new System.Drawing.Size(822, 58);
  927. this.parametersSettingControl.TabIndex = 9;
  928. //
  929. // informationControl
  930. //
  931. this.informationControl.Location = new System.Drawing.Point(12, 76);
  932. this.informationControl.Name = "informationControl";
  933. this.informationControl.Size = new System.Drawing.Size(373, 82);
  934. this.informationControl.TabIndex = 11;
  935. //
  936. // groupBoxParam
  937. //
  938. this.groupBoxParam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  939. | System.Windows.Forms.AnchorStyles.Left)));
  940. this.groupBoxParam.Controls.Add(this.button5);
  941. this.groupBoxParam.Location = new System.Drawing.Point(12, 164);
  942. this.groupBoxParam.Name = "groupBoxParam";
  943. this.groupBoxParam.Size = new System.Drawing.Size(373, 315);
  944. this.groupBoxParam.TabIndex = 12;
  945. this.groupBoxParam.TabStop = false;
  946. //
  947. // button5
  948. //
  949. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  950. this.button5.Location = new System.Drawing.Point(292, 286);
  951. this.button5.Name = "button5";
  952. this.button5.Size = new System.Drawing.Size(75, 23);
  953. this.button5.TabIndex = 1;
  954. this.button5.UseVisualStyleBackColor = true;
  955. this.button5.Click += new System.EventHandler(this.button5_Click);
  956. //
  957. // groupBox1
  958. //
  959. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  960. | System.Windows.Forms.AnchorStyles.Left)
  961. | System.Windows.Forms.AnchorStyles.Right)));
  962. this.groupBox1.Location = new System.Drawing.Point(392, 77);
  963. this.groupBox1.Name = "groupBox1";
  964. this.groupBox1.Size = new System.Drawing.Size(442, 402);
  965. this.groupBox1.TabIndex = 13;
  966. this.groupBox1.TabStop = false;
  967. //
  968. // NormalOperationDialog
  969. //
  970. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  971. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  972. this.ClientSize = new System.Drawing.Size(846, 491);
  973. this.Controls.Add(this.groupBox1);
  974. this.Controls.Add(this.groupBoxParam);
  975. this.Controls.Add(this.informationControl);
  976. this.Controls.Add(this.parametersSettingControl);
  977. this.Name = "NormalOperationDialog";
  978. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NormalOperationDialog_FormClosing);
  979. this.Load += new System.EventHandler(this.BshTransferAdjustDialog_Load);
  980. this.groupBoxParam.ResumeLayout(false);
  981. this.ResumeLayout(false);
  982. }
  983. #endregion
  984. private CustomControl.ParametersSettingAdjustControl parametersSettingControl;
  985. private CustomControl.InformationAdjustControl informationControl;
  986. private System.Windows.Forms.GroupBox groupBoxParam;
  987. private System.Windows.Forms.Button button5;
  988. private GroupBox groupBox1;
  989. #endregion
  990. #region 关闭窗口时,保存参数
  991. private void NormalOperationDialog_FormClosing(object sender, FormClosingEventArgs e)
  992. {
  993. #region [开启脚本录制]
  994. if (appWorkspace.startScriptRecording)
  995. {
  996. getScriptRecording();
  997. }
  998. #endregion
  999. string newpic = 1 + "";
  1000. //获取参数实体
  1001. ImageMenu imageMenu;
  1002. if (Startup.instance.imageMenuModel != null)
  1003. {
  1004. imageMenu = Startup.instance.imageMenuModel;
  1005. }
  1006. else
  1007. {
  1008. imageMenu = new ImageMenu();
  1009. imageMenu.ListParam = new List<ImageParam>();
  1010. }
  1011. //数字控制是否生成新图
  1012. if (informationControl.radioButton1.Checked)
  1013. newpic = 1 + "";
  1014. else
  1015. newpic = 0 + "";
  1016. List<ImageParam> list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
  1017. if (list.Count == 0)
  1018. {
  1019. ImageParam param = new ImageParam();
  1020. param.menuId = (int)action.MenuId;
  1021. param.param_key = "param_newpic";
  1022. param.param_type = -1;
  1023. param.param_value = newpic;
  1024. imageMenu.ListParam.Add(param);
  1025. }
  1026. //判断页面是否有参数
  1027. if (action.lists.Count > 0)
  1028. {
  1029. for (int i = 0; i < action.lists.Count; i++)
  1030. {
  1031. if (list.Count > 0)//是否存过参数
  1032. {
  1033. for (int j = 0; j < imageMenu.ListParam.Count; j++)//给参数实体赋值
  1034. {
  1035. if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == action.lists[i].key)
  1036. {
  1037. if (action.lists[i].Type == Dtryt.DecimalScope)
  1038. {
  1039. imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
  1040. imageMenu.ListParam[j].param_value = string.Join(",", ((List<double>)(action.lists[i].Value)).ToArray());
  1041. imageMenu.ListParam[j].value = null;
  1042. }
  1043. else
  1044. {
  1045. imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
  1046. imageMenu.ListParam[j].param_value = action.lists[i].value.ToString();
  1047. }
  1048. //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
  1049. }
  1050. else if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
  1051. {
  1052. //imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
  1053. imageMenu.ListParam[j].param_value = newpic;
  1054. //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
  1055. }
  1056. }
  1057. }
  1058. else //如果没保存过新增
  1059. {
  1060. ImageParam param = new ImageParam();
  1061. param.menuId = (int)action.MenuId;
  1062. param.param_key = action.lists[i].key;
  1063. if (action.lists[i].Type == Dtryt.DecimalScope)
  1064. {
  1065. param.param_type = (int)action.lists[i].Type;
  1066. param.param_value = string.Join(",", ((List<double>)(action.lists[i].Value)).ToArray());
  1067. }
  1068. else
  1069. {
  1070. param.param_type = (int)action.lists[i].Type;
  1071. param.param_value = action.lists[i].value.ToString();
  1072. }
  1073. imageMenu.ListParam.Add(param);
  1074. }
  1075. }
  1076. }
  1077. else //没有参数,给是否生成新图赋值
  1078. {
  1079. if (list.Count > 0)
  1080. {
  1081. for (int j = 0; j < imageMenu.ListParam.Count; j++)
  1082. {
  1083. if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
  1084. {
  1085. imageMenu.ListParam[j].param_value = newpic;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. Startup.instance.binaryActionModel = imageMenu;
  1091. //按路径和名称保存xml文件
  1092. string userInfoXml = XmlSerializeHelper.XmlSerialize<ImageMenu>(imageMenu);
  1093. //xml保存路径
  1094. string filePath = Application.StartupPath + "\\Config\\" + "Default\\BinaryActionSaving\\ParameterSaving.xml";
  1095. //保存xml
  1096. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
  1097. }
  1098. /// <summary>
  1099. /// 初始化时获取参数
  1100. /// </summary>
  1101. /// <param name="imageMenu">系统读取的参数配置</param>
  1102. public void GetParameters(ImageMenu imageMenu)
  1103. {
  1104. List<ImageParam> list = new List<ImageParam>();
  1105. if (imageMenu.ListParam.Count > 0)
  1106. list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
  1107. if (list.Count > 0)
  1108. {
  1109. initPamasValues = true;
  1110. for (int i = 0; i < action.Lists.Count; i++)
  1111. {
  1112. for (int j = 0; j < list.Count; j++)
  1113. {
  1114. if (list[j].param_key.Equals(action.Lists[i].key))
  1115. {
  1116. if (list[j].param_type == (int)Base.Dtryt.Choise)
  1117. {
  1118. int valueC;
  1119. if (int.TryParse(list[j].param_value.ToString(), out valueC))
  1120. list[j].value = valueC;
  1121. else if (list[j].param_value.ToString() != "")
  1122. list[j].value = list[j].param_value.ToString();
  1123. else
  1124. list[j].value = 1;
  1125. }
  1126. if (list[j].param_type == (int)Base.Dtryt.Interger)
  1127. {
  1128. int valueC;
  1129. if (int.TryParse(list[j].param_value.ToString(), out valueC))
  1130. list[j].value = valueC;
  1131. else
  1132. list[j].value = 0;
  1133. }
  1134. else if (list[j].param_type == (int)Base.Dtryt.Array)
  1135. {
  1136. int valueC;
  1137. if ("Structures".Equals(list[j].param_key))
  1138. {
  1139. foreach (var item in (Dictionary<Enum, object>)(action.Lists[i].initialValue))
  1140. {
  1141. if (list[j].param_value.ToString() == item.Key.ToString())
  1142. {
  1143. valueC = (int)(object)item.Key;
  1144. list[j].value = valueC;
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. else if ("currentPhase".Equals(list[j].param_key))
  1150. {
  1151. foreach (var item in (Dictionary<Enum, object>)(action.Lists[i].initialValue))
  1152. {
  1153. if (list[j].param_value.ToString() == item.Key.ToString())
  1154. {
  1155. valueC = (int)(object)item.Key;
  1156. list[j].value = valueC;
  1157. break;
  1158. }
  1159. }
  1160. }
  1161. else if ("UnitParameters".Equals(list[j].param_key))
  1162. {
  1163. foreach (var item in (Dictionary<Enum, object>)(action.Lists[i].initialValue))
  1164. {
  1165. if (list[j].param_value.ToString() == item.Key.ToString())
  1166. {
  1167. valueC = (int)(object)item.Key;
  1168. list[j].value = valueC;
  1169. break;
  1170. }
  1171. }
  1172. }
  1173. else if ("FilterParameters".Equals(list[j].param_key))
  1174. {
  1175. foreach (var item in (Dictionary<Enum, object>)(action.Lists[i].initialValue))
  1176. {
  1177. if (list[j].param_value.ToString() == item.Key.ToString())
  1178. {
  1179. valueC = (int)(object)item.Key;
  1180. list[j].value = valueC;
  1181. break;
  1182. }
  1183. }
  1184. }
  1185. else if ("FunctionParameters".Equals(list[j].param_key))
  1186. {
  1187. foreach (var item in (Dictionary<Enum, object>)(action.Lists[i].initialValue))
  1188. {
  1189. if (list[j].param_value.ToString() == item.Key.ToString())
  1190. {
  1191. valueC = (int)(object)item.Key;
  1192. list[j].value = valueC;
  1193. break;
  1194. }
  1195. }
  1196. }
  1197. else
  1198. {
  1199. if (int.TryParse(list[j].param_value.ToString(), out valueC))
  1200. list[j].value = valueC;
  1201. else
  1202. list[j].value = 0;
  1203. }
  1204. }
  1205. else if (list[j].param_type == (int)Base.Dtryt.Boolean)
  1206. {
  1207. bool valueC;
  1208. if (Boolean.TryParse(list[j].param_value.ToString(), out valueC))
  1209. list[j].value = valueC;
  1210. else
  1211. list[j].value = list[j].param_value.ToString().Equals("0");
  1212. }
  1213. else if (list[j].param_type == (int)Base.Dtryt.DecimalScope)
  1214. {
  1215. string[] valuelst = list[j].param_value.Split(',');
  1216. List<double> listV = new List<double>();
  1217. foreach (string str in valuelst)
  1218. {
  1219. double outV;
  1220. if (double.TryParse(str, out outV))
  1221. listV.Add(outV);
  1222. else
  1223. listV.Add(0);
  1224. }
  1225. list[j].value = listV;
  1226. }
  1227. else if (list[j].param_type == (int)Base.Dtryt.Color)
  1228. {
  1229. int valueC;
  1230. if (int.TryParse(list[j].param_value.ToString(), out valueC))
  1231. list[j].value = valueC;
  1232. else
  1233. list[j].value = -65536;
  1234. }
  1235. action.Lists[i].Type = (Dtryt)list[j].param_type;
  1236. if (list[j].value != null)
  1237. {
  1238. action.Lists[i].value = list[j].value;
  1239. }
  1240. else
  1241. {
  1242. action.Lists[i].value = int.Parse(list[j].param_value);
  1243. }
  1244. break;
  1245. }
  1246. }
  1247. }
  1248. for (int j = 0; j < list.Count; j++)
  1249. {
  1250. if ("param_newpic".Equals(list[j].param_key))
  1251. {
  1252. if (list[j].param_value == "1")
  1253. {
  1254. informationControl.radioButton1.Checked = true;
  1255. informationControl.radioButton2.Checked = false;
  1256. }
  1257. else
  1258. {
  1259. informationControl.radioButton1.Checked = false;
  1260. informationControl.radioButton2.Checked = true;
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. #endregion
  1267. #region [脚本录制]
  1268. private void getScriptRecording()
  1269. {
  1270. List<Args> args = action.Lists;
  1271. appWorkspace.SetScriptStartRecording(MenuItem.MenuId, MenuItem.Text, args);
  1272. }
  1273. #endregion
  1274. }
  1275. }