BshTransferAdjustDialog.cs 66 KB

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