NormalOperationDialog.cs 62 KB

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