1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489 |
- using Metis.ParameterSet;
- using PaintDotNet.Adjust;
- using PaintDotNet.Base;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.CustomControl;
- using PaintDotNet.Data.Action;
- using PaintDotNet.Data.Param;
- using PaintDotNet.DbOpreate.DbModel;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- using static Metis.ParameterSet.ImageMenu;
- namespace PaintDotNet.Processing
- {
- /// <summary>
- /// 图像处理窗口
- /// </summary>
- internal class BshTransferAdjustDialog : Form
- {
- /// <summary>
- /// 步长 初始值1,依次增加
- /// </summary>
- string stepLength = "00" + Startup.instance.step_length;
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 当前处理的程序
- /// </summary>
- private ParamObject action;
- /// <summary>
- /// 如果是脚本执行,将参数带入
- /// </summary>
- private Boolean initScriptValues = false;
- // <summary>
- /// 如果有参数保存,将参数带入
- /// </summary>
- private Boolean initPamasValues = false;
- /// <summary>
- /// 当前活动的图像
- /// </summary>
- private OpenCvSharp.Mat imageMat;
- /// <summary>
- /// 调用调色板的控件
- /// </summary>
- private Panel panel2;
- /// <summary>
- /// 调用原图取色 显示色板的控件
- /// </summary>
- private Panel panel3;
- /// <summary>
- /// 是否使用原图取色
- /// </summary>
- private bool item3Checked;
- /// <summary>
- /// 调色板
- /// </summary>
- private ColorsForm colorsFormGrid;
- /// <summary>
- /// 像素格式
- /// </summary>
- private PixelFormat pixelFormat;
- /// <summary>
- /// 图像面板
- /// </summary>
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- /// <summary>
- /// 是否点击过应用按钮
- /// 如果没有点过,直接点确定还需要走一遍方法,
- /// 如果已经点过,直接拿当前图片
- /// </summary>
- private bool applyButtonClick = false;
- private PdnMenuItem MenuItem;
- private double ruler = 0;
- private decimal gainMultiple = 0;
- private int width = 0;
- private int height = 0;
- /// <summary>
- /// 选中参数的索引
- /// </summary>
- private string index = "1";
- [Browsable(false)]
- public AppWorkspace AppWorkspace
- {
- get
- {
- return this.appWorkspace;
- }
- set
- {
- this.appWorkspace = value;
- }
- }
- ActionType menuIdOverall;
- /// <summary>
- /// dialog
- /// </summary>
- /// <param name="appWorkspace"></param>
- /// <param name="menuId">对应菜单的id</param>
- public BshTransferAdjustDialog(AppWorkspace appWorkspace, ActionType menuId, string dialogText,PdnMenuItem menuItem)
- {
- menuIdOverall = menuId;
- this.MenuItem = menuItem;
- InitializeComponent();
- InitializeLanguageText();
- //
- // 设置Dialog属性
- //
- this.AppWorkspace = appWorkspace;
- this.StartPosition = FormStartPosition.CenterScreen;
- this.Icon = PdnInfo.AppIcon;
- this.imageMat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
- this.pixelFormat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.PixelFormat;
- this.Text = dialogText;
- //
- //初始化色板
- //
- this.colorsFormGrid = new ColorsForm();
- this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- //
- //初始化图像控件
- //
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.AuxiliaryLineEnabled = false;
- this.documentWorkspace.Visible = false;
- this.groupBox1.Controls.Add(documentWorkspace);
- //
- //初始化操作按钮
- //
- this.commonControlButtons = new CommonControlButtons();
- this.commonControlButtons.Dock = DockStyle.Top;
- this.commonControlButtons.Height = 30;
- this.commonControlButtons.HideZoomToWindowAndActualSize();
- this.groupBox1.Controls.Add(commonControlButtons);
- switch (menuId)
- {
- //图像偏移
- case ActionType.ActionImageOffset:
- action = new Data.Action.Action507();
- ((Action507)action).one.Min = -imageMat.Height;
- ((Action507)action).one.Max = imageMat.Height;
- ((Action507)action).two.Min = -imageMat.Width;
- ((Action507)action).two.Max = imageMat.Width;
- break;
- //调节
- case ActionType.ActionRevertColor:
- action = new Data.Action.Action5010();
- break;
- case ActionType.ActionBgr2Gray:
- action = new Data.Action.Action5011();
- break;
- case ActionType.ActionWhiteBalance:
- action = new Data.Action.Action5012();
- //白平衡原图取点
- this.documentWorkspace.panel.MouseClick += PicturePreviewControl1_item3MouseDown;
- //picturePreviewControl1.item3MouseDown += PicturePreviewControl1_item3MouseDown;
- break;
- case ActionType.ActionColorBalance:
- action = new Data.Action.Action5013();
- break;
- case ActionType.ActionShadingCorrection:
- action = new Data.Action.Action5014();
- break;
- case ActionType.ActionHSB:
- action = new Data.Action.Action5015();
- break;
- case ActionType.ActionBCG:
- action = new Data.Action.Action5016();
- break;
- case ActionType.ActionImageRotate:
- action = new Data.Action.Action5017();
- break;
- case ActionType.ImageChangeResolution:
- action = new Data.Action.Action6001();
- break;
- //锐化
- case ActionType.ActionPortray:
- action = new Data.Action.Action5020();
- break;
- case ActionType.ActionEnhanceContour:
- action = new Data.Action.Action5021();
- break;
- case ActionType.ActionBlurMask:
- action = new Data.Action.Action5022();
- break;
- //平滑
- case ActionType.Sigma:
- action = new Data.Action.Action5030();
- break;
- case ActionType.GaussianFiltering:
- action = new Data.Action.Action5031();
- break;
- case ActionType.LowPassFiltering:
- action = new Data.Action.Action5032();
- break;
- case ActionType.MedianFiltering:
- action = new Data.Action.Action5033();
- break;
- case ActionType.GaussianBlur:
- action = new Data.Action.Action5034();
- break;
- case ActionType.BilateralFiltering:
- action = new Data.Action.Action5035();
- break;
- case ActionType.WaveletDenoising:
- action = new Data.Action.Action5036();
- break;
- //边缘检测
- case ActionType.Log:
- action = new Data.Action.Action5040();
- break;
- case ActionType.Canny:
- action = new Data.Action.Action5041();
- break;
- case ActionType.Sobel:
- action = new Data.Action.Action5042();
- break;
- case ActionType.Kirsch:
- action = new Data.Action.Action5043();
- break;
- case ActionType.Prewitt:
- action = new Data.Action.Action5044();
- break;
- case ActionType.Roberts:
- action = new Data.Action.Action5045();
- break;
- case ActionType.Laplace:
- action = new Data.Action.Action5046();
- break;
- //图像间操作
- case ActionType.ActionImageAddition:
- action = new Data.Action.Action5050();
- break;
- default:
- action = new Data.Action.Action5010();
- break;
- }
- if (action.Lists == null || action.Lists.Count < 1)
- {
- Label label = new Label();
- label.Left = 7;
- label.Top = 31;
- label.Size = new Size(60, 12);
- label.TextAlign = ContentAlignment.TopLeft;
- label.Text = PdnResources.GetString("Menu.Noparams.text");
- groupBoxParam.Controls.Add(label);
- this.button5.Visible = false;
- GetParameters(Startup.instance.imageMenuModel);
- }
- else
- {
- //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
- if (AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId)
- {
- this.initScriptValues = true;
- foreach (Args arg in action.Lists)
- {
- Args param1 = AppWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key));
- if (param1.value != null)
- arg.Value = param1.value;
- }
- AppWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数
- }
- else
- {
- GetParameters(Startup.instance.imageMenuModel);
- this.initScriptValues = false;
- }
- int controlsTop = 0;
- //初始化手动控件
- for (int i = 0; i < action.Lists.Count; i++)
- {
- Args args = action.Lists[i];
- index = args.value.ToString();
- if (args is IntegerNumber || args is DecimalNumber || args is OddNumber)
- {
- CustomControl.NumberParamControl numberParam = new CustomControl.NumberParamControl();
- numberParam.Left = 78;
- numberParam.Top = 35 + controlsTop;
- numberParam.Tag = args.key;
- //设置参数范围
- numberParam.paramIndex = 100 + i;
- if (args is DecimalNumber)
- {
- numberParam.DecimalPlaces = ((DecimalNumber)args).DecimalPlaces;
- numberParam.Minimum = (double)((DecimalNumber)args).Min;
- numberParam.Maximum = (double)((DecimalNumber)args).Max;
- }
- else if (args is OddNumber)
- {
- numberParam.Increment = 2;
- numberParam.Minimum = ((OddNumber)args).Min;
- numberParam.Maximum = ((OddNumber)args).Max;
- numberParam.IsOddNumber = true;
- }
- else
- {
- numberParam.DecimalPlaces = 0;
- numberParam.Minimum = ((IntegerNumber)args).Min;
- numberParam.Maximum = ((IntegerNumber)args).Max;
- }
- double fnum = 0;
- if (double.TryParse((initScriptValues || initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
- {
- numberParam.Value = fnum;
- //args.Value = fnum;
- }
- groupBoxParam.Controls.Add(numberParam);
- groupBoxParam.Controls.SetChildIndex(numberParam, 100 + i);
- if (args is DecimalNumber)
- {
- numberParam.ValueChanged += new EventHandler(((DecimalNumber)args).numberParam_ValueChanged);
- }
- else if (args is OddNumber)
- {
- numberParam.ValueChanged += new EventHandler(((OddNumber)args).numberParam_ValueChanged);
- }
- else
- {
- numberParam.ValueChanged += new EventHandler(((IntegerNumber)args).numberParam_ValueChanged);
- }
- numberParam.ValueChanged += this.ParameterChangeEvent;
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(65, 12);//55->65 调试值,提交备注:调试3-双边滤波-邻域直径。
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- groupBoxParam.Controls.Add(label);
- controlsTop += 45;
- }
- else if (args is BooleanObject)
- {
- Label label = new Label();
- label.Left = 10;
- label.Top = 40 + controlsTop;
- label.Size = new Size(75, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- //colorPanel.BackColorChanged += ((ColorNumber)arg).numberParam_ValueChanged;
- ////radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
- groupBoxParam.Controls.Add(label);
- CheckBox check = new CheckBox();
- check.Left = 88;
- check.Top = 40 + controlsTop;
- check.AutoSize = true;
- check.CheckedChanged += ((BooleanObject)args).Boolean_ValueChanged;
- check.CheckedChanged += this.CheckBoxChangeEvent;
- groupBoxParam.Controls.Add(check);
- controlsTop += 45;
- }
- else if (args is ChoiseArray)
- {
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(55, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- groupBoxParam.Controls.Add(label);
- //初始化选项列表
- for (int j = 0; j < args.choiseList.Count; j++)
- {
- BooleanObject argsChoise = args.choiseList[j] as BooleanObject;
- RadioButton radio = new RadioButton();
- if (argsChoise.key == args.value)
- {
- radio.Checked = true;
- }
- radio.AutoSize = true;
- radio.Location = new Point(88, 40 + controlsTop/*topMargin*/);
- radio.Text = argsChoise.name + "";
- radio.Tag = argsChoise.Key;
- radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
- radio.CheckedChanged += Radio_CheckedChanged;
- groupBoxParam.Controls.Add(radio);
- if (argsChoise.Lists.Count > 0)
- {
- ColorNumber phaseColor = argsChoise.Lists[0] as ColorNumber;
- if (phaseColor.Key.Equals("phaseColor"))
- {
- Panel panel = new Panel();
- panel.BackColor = Color.FromArgb(int.Parse(phaseColor.Value.ToString()));
- panel.Size = new Size(53, 20);
- panel.Top = 37 + controlsTop;
- panel.Left = 178;
- groupBoxParam.Controls.Add(panel);
- panel.Click += new System.EventHandler(this.panel2_Click);
- panel.BackColorChanged += ((ColorNumber)phaseColor).numberParam_ValueChanged;
- panel.BackColorChanged += this.ParameterChangeEvent;
- this.panel2 = panel;
- }
- else if (phaseColor.Key.Equals("imageColor"))
- {
- Panel panel = new Panel();
- panel.BackColor = Color.FromArgb(int.Parse(phaseColor.Value.ToString()));
- panel.Size = new Size(53, 20);
- panel.Top = 37 + controlsTop;
- panel.Left = 178;
- groupBoxParam.Controls.Add(panel);
- panel.BackColorChanged += ((ColorNumber)phaseColor).numberParam_ValueChanged;
- panel.BackColorChanged += this.ParameterChangeEvent;
- this.panel3 = panel;
- }
- }
- controlsTop += 45;
- }
- }
- else if (args is ColorNumber)
- {
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(65, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- //colorPanel.BackColorChanged += ((ColorNumber)arg).numberParam_ValueChanged;
- ////radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
- groupBoxParam.Controls.Add(label);
- Panel panel = new Panel();
- panel.BackColor = Color.FromArgb(int.Parse(args.Value.ToString()));
- panel.Size = new Size(53, 20);
- panel.Top = 35 + controlsTop;
- panel.Left = 85;
- groupBoxParam.Controls.Add(panel);
- panel.Click += new System.EventHandler(this.panel2_Click);
- panel.BackColorChanged += ((ColorNumber)args).numberParam_ValueChanged;
- panel.BackColorChanged += this.ParameterChangeEvent;
- this.panel2 = panel;
- controlsTop += 45;
- }
- else if (args is StringArray)
- {
- Label label = new Label();
- label.Left = 29;
- label.Top = 40 + controlsTop;
- label.Size = new Size(55, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- groupBoxParam.Controls.Add(label);
- Panel panel = new Panel();
- panel.AutoSize = true;
- panel.Top = 40 + controlsTop;
- panel.Left = 88;
- int position = 1;
- int topMargin = 0;
- //循环字典,铺多个radio
- foreach (var item in (Dictionary<Enum, object>)args.initialValue/*((initScriptValues || initPamasValues ? args.value : args.initialValue))*/)
- {
- int xvalue = 0;
- if (position % 1 == 0) xvalue = 0;
- if (position % 2 == 0) xvalue = 1;
- if (position % 3 == 0) xvalue = 2;
- RadioButton radio = new RadioButton();
- if (position == 1)
- {
- radio.Checked = true;
- }
- radio.AutoSize = true;
- radio.Location = new Point(xvalue * 90, topMargin);
- radio.Text = item.Value.ToString();
- radio.Tag = item.Key;
- radio.Checked = item.Key.ToString().Equals(args.value.ToString());
- radio.CheckedChanged += ((StringArray)args).numberParam_ValueChanged;
- radio.CheckedChanged += this.ParameterChangeEvent;
- panel.Controls.Add(radio);
- if (position % 3 == 0) topMargin += 25;
- position++;
- }
- groupBoxParam.Controls.Add(panel);
- controlsTop += 45;
- }
- }
- }
- InitData();
- InitCommonButtonEvent();
- }
- private void startScriptAutomaticAction()
- {
- applyButtonImpl(null, null);
- sureButtonImpl(null, null);
- }
- private void ParameterChangeEvent(object sender, EventArgs e)
- {
- this.applyButtonClick = false;
- if (action is Action6001)
- {
- int width = 0;
- bool isCheck = false;
- foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
- {
- if (control is CustomControl.NumberParamControl)
- {
- CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
- if (numberParam.Tag.Equals("width"))
- {
- width = (int)numberParam.Value;
- }
- }
- if (control is CheckBox)
- {
- CheckBox checkBox = (CheckBox)control;
- if (checkBox.Checked)
- {
- isCheck = true;
- }
- }
- }
- if (isCheck)
- {
- double matProportion = Convert.ToDouble(this.imageMat.Width) / Convert.ToDouble(this.imageMat.Height);
- foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
- {
- if (control is CustomControl.NumberParamControl)
- {
- CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
- if (numberParam.Tag.Equals("height"))
- {
- numberParam.Value = width / matProportion;
- }
- }
- }
- }
- }
- }
- private void CheckBoxChangeEvent(object sender, EventArgs e)
- {
- this.applyButtonClick = false;
- CheckBox checkBox = (CheckBox)sender;
- if (!checkBox.Checked)
- {
- return;
- }
- if (action is Action6001)
- {
- int width = 0;
- foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
- {
- if (control is CustomControl.NumberParamControl)
- {
- CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
- if (numberParam.Tag.Equals("width"))
- {
- width = (int)numberParam.Value;
- }
- }
- }
- double matProportion = Convert.ToDouble(this.imageMat.Width) / Convert.ToDouble(this.imageMat.Height);
- foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
- {
- if (control is CustomControl.NumberParamControl)
- {
- CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
-
- if (numberParam.Tag.Equals("height"))
- {
- numberParam.Value = width / matProportion;
- }
- }
- }
- }
- }
- private void InitCommonButtonEvent()
- {
- this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
- this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
- this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
- this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
- this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
- }
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomIn();
- }
- private void zoomOutButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomOut();
- }
- private void zoomToWindowButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- private void actualSizeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- private void pointerButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
- }
- private void mobileModeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
- }
- private void Radio_CheckedChanged(object sender, EventArgs e)
- {
- if (((RadioButton)sender).Tag.Equals("3"))//原图取色
- {
- this.item3Checked = ((RadioButton)sender).Checked;
- //picturePreviewControl1.selectColorMode(this.item3Checked);
- }
- OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- }
- /// <summary>
- /// 相颜色点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel2_Click(object sender, EventArgs e)
- {
- this.panel2 = ((Panel)sender);
- this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(panel2.BackColor);
- this.colorsFormGrid.ShowDialog();
- }
- /// <summary>
- /// Panel2的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridColorChanged(object sender, EventArgs e)
- {
- Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
- //更改背景色,触发事件
- this.panel2.BackColor = color;
- ////改变配置文件里面的相颜色
- //this.binaryExtractionModel.PhaseColor = color.ToArgb();
- OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
- //if (menuIdOverall == ActionType.ActionImageRotate)
- //{
- // OpenCvSharp.Mat src = action.PerformProcess(PaintDotNet.Camera.Tools.ToMat(this.bitmap));
- // //GeometryIntent.ImageRotate(src, mat, float.Parse(action.lists[0].value.ToString()), OpenCvSharp.InterpolationFlags.Linear);
- // mat = GeometryIntent.MatRotate(src, float.Parse(action.lists[0].value.ToString()), new OpenCvSharp.Scalar(panel2.BackColor.B, panel2.BackColor.G, panel2.BackColor.R, 255));
- //}
- //else
- //{
- // mat = action.PerformProcess(PaintDotNet.Camera.Tools.ToMat(this.bitmap));
- //}
- //OpenCvSharp.Mat mat = action.PerformProcess(PaintDotNet.Camera.Tools.ToMat(this.bitmap));
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- //关闭色板
- this.colorsFormGrid.Close();
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- public void InitData()
- {
- Document document = Document.FromImageMat(this.imageMat.Clone());
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Visible = true;
- this.documentWorkspace.Refresh();
- //给picturebox赋值
- //picturePreviewControl1.pictureBox1.Image = this.bitmap;
- //初始化/重置参数
- resetNumber();
- //this.initScriptValues = false;//阻止第二次进入仍然被赋值参数
- }
- private void resetNumber()
- {
- if (action is Action5012)//白平衡
- {
- //GetParameters(Startup.instance.imageMenuModel);
- this.item3Checked = false;
- //重新初始化选项列表
- Args args = action.Lists[0];
- for (int j = 0; j < args.choiseList.Count; j++)
- {
- BooleanObject argsChoise = args.choiseList[j] as BooleanObject;
- if (argsChoise.Lists.Count > 0)
- {
- ColorNumber phaseColor = argsChoise.Lists[0] as ColorNumber;
- if (phaseColor.Key.Equals("phaseColor"))//色板取色
- {
- this.panel2.BackColor = Color.FromArgb(int.Parse((initScriptValues || initPamasValues ? phaseColor.value : phaseColor.initialValue).ToString()));
- }
- else if (phaseColor.Key.Equals("imageColor"))//原图取色
- {
- this.panel3.BackColor = Color.FromArgb(int.Parse((initScriptValues || initPamasValues ? phaseColor.value : phaseColor.initialValue).ToString()));
- }
- }
- }
- }
- if (action is Action507 || action is Action5017)//图像偏移
- {
- //重新初始化选色面板
- for (int j = 0; j < action.Lists.Count; j++)
- {
- ColorNumber phaseColor = action.Lists[j] as ColorNumber;
- if (phaseColor is ColorNumber)
- {
- this.panel2.BackColor = Color.FromArgb(int.Parse((initScriptValues || initPamasValues ? phaseColor.value : phaseColor.initialValue).ToString()));
- break;
- }
- }
- }
- foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
- {
- if (control is CustomControl.NumberParamControl)
- {
- CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
- if (numberParam.paramIndex >= 100)
- {
- //List<Args> list1s = action.Lists[0];
- Args args = /*list1s*/action.Lists[numberParam.paramIndex - 100];
- double fnum = 0;
- if (double.TryParse((initScriptValues || initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
- {
- numberParam.Value = fnum;
- }
- //numberParam.Value = (int)args.initialValue;
- }
- }
- else if (control is RadioButton)
- {
- if (control.Tag.Equals(index))
- {
- ((RadioButton)control).Checked = true;
- }
- else
- {
- ((RadioButton)control).Checked = false;
- }
- }
- }
- }
- /// <summary>
- /// 原图取点的响应方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PicturePreviewControl1_item3MouseDown(object sender, MouseEventArgs e)
- {
- if (this.item3Checked)
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(new System.Drawing.Point(e.X, e.Y));
- int x = point.X;
- int y = point.Y;
- if (x >= 0 && y >= 0 && x < this.documentWorkspace.CompositionSurface.Width && y < this.documentWorkspace.CompositionSurface.Height)
- {
- OpenCvSharp.Mat srt = this.imageMat.Clone();
- OpenCvSharp.Vec3b bgr = srt.At<OpenCvSharp.Vec3b>(y, x);
- Color color = Color.FromArgb(bgr[2], bgr[1], bgr[0]);
- //更改背景色,触发事件
- this.panel3.BackColor = color;
- OpenCvSharp.Mat mat = action.PerformProcess(srt);
- //mat.Set(e.Location.Y, e.Location.X, new OpenCvSharp.Vec3b(0, 0, 255));//测试取点的位置
- //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- }
- }
- }
- private void BshTransferAdjustDialog_Load(object sender, EventArgs e)
- {
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
- //图像名称输入框
- informationControl.fileNameTextBox1.Text = this.Text + "-" + stepLength;
- //picturePreviewControl1.isShown = true;
- parametersSettingControl.applyButtonClick += new EventHandler(applyButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
- parametersSettingControl.sureButtonClick += new EventHandler(sureButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
- if (this.initScriptValues && this.appWorkspace.ScriptAutomatic)
- {
- this.startScriptAutomaticAction();
- }
- }
- //应用
- private void applyButtonImpl(object sender, EventArgs e)
- {
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- int itemCount = 100;
- ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- OpenCvSharp.Mat mat = new OpenCvSharp.Mat();
- if (menuIdOverall == ActionType.ImageChangeResolution)
- {
- double ruleData = 1;
- decimal gainMultiple = 0;
- if (this.documentWorkspace.xmlSaveModel == null)
- {
- this.appWorkspace.getMeasureInfo().TryGetValue(Startup.instance.ruleDB == null ? MeasurementUnit.Micron : (MeasurementUnit)(Startup.instance.ruleDB.ruler_units), out ruleData);
- gainMultiple = Startup.instance.ruleDB == null ? 1 : Startup.instance.ruleDB.gain_multiple;
- }
- else
- {
- ruleData = this.documentWorkspace.GetRuler((MeasurementUnit)this.documentWorkspace.xmlSaveModel.ruler_units);
- gainMultiple = this.documentWorkspace.xmlSaveModel.gain_multiple;
- }
- this.width = Convert.ToInt32(action.lists[0].value);
- this.height = Convert.ToInt32(action.lists[1].value);
- if (!action.lists[3].value.ToString().Equals("Pixel"))
- {
- int width = this.imageMat.Width;
- int height = this.imageMat.Height;
- int realWidth = Convert.ToInt32(Convert.ToDouble(this.width) * ruleData);
- int realHeight = Convert.ToInt32(Convert.ToDouble(this.height) * ruleData);
- double ruler = Convert.ToDouble(this.width) / realWidth;
- this.gainMultiple *= (width / realWidth);
- action.lists[0].value = realWidth;
- action.lists[1].value = realHeight;
- this.ruler = ruler;
- }
- else
- {
- if (this.documentWorkspace.xmlSaveModel == null)
- {
- this.appWorkspace.getMeasureInfo().TryGetValue((MeasurementUnit)Startup.instance.ruleDB.ruler_units, out ruleData);
- }
- else
- {
- ruleData = this.documentWorkspace.GetRuler((MeasurementUnit)Startup.instance.ruleDB.ruler_units);
- }
- int width = this.imageMat.Width;
- this.gainMultiple *= (width / this.width);
- double ruler = Convert.ToDouble((width * ruleData) / Convert.ToDouble(action.lists[0].value));
- this.ruler = ruler;
- }
- mat = action.PerformProcess(this.imageMat.Clone());
- }
- else
- {
- mat = action.PerformProcess(this.imageMat.Clone());
- }
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- this.applyButtonClick = true;
- }
- catch (Exception ex)
- {
- }
- finally
- {
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
- }
- //确定
- internal void sureButtonImpl(object sender, EventArgs e)
- {
- ProgressThreadProcClass procClass = new ProgressThreadProcClass();
- int itemCount = 100;
- ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- OpenCvSharp.Mat mat = new OpenCvSharp.Mat();
- if (menuIdOverall == ActionType.ImageChangeResolution)
- {
- if (!this.applyButtonClick)
- {
- if (this.pixelFormat == PixelFormat.Format8bppIndexed && mat.Type() != OpenCvSharp.MatType.CV_8UC1)
- {
- mat = mat.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2GRAY);
- }
- double ruleData = 1;
- if (this.documentWorkspace.xmlSaveModel == null)
- {
- this.appWorkspace.getMeasureInfo().TryGetValue(Startup.instance.ruleDB == null ? MeasurementUnit.Micron : (MeasurementUnit)(Startup.instance.ruleDB.ruler_units), out ruleData);
- gainMultiple = Startup.instance.ruleDB == null ? 1 : Startup.instance.ruleDB.gain_multiple;
- }
- else
- {
- ruleData = this.documentWorkspace.GetRuler((MeasurementUnit)this.documentWorkspace.xmlSaveModel.ruler_units);
- gainMultiple = this.documentWorkspace.xmlSaveModel.gain_multiple;
- }
- if (!action.lists[3].value.ToString().Equals("Pixel"))
- {
- int width = this.imageMat.Width;
- int height = this.imageMat.Height;
- int realWidth = Convert.ToInt32(Convert.ToDouble(this.width) * ruleData);
- int realHeight = Convert.ToInt32(Convert.ToDouble(this.height) * ruleData);
- this.gainMultiple *= (width / realWidth);
- double ruler = Convert.ToDouble(this.width) / realWidth;
- action.lists[0].value = realWidth;
- action.lists[1].value = realHeight;
- this.ruler = ruler;
- }
- else
- {
- int width = this.imageMat.Width;
- this.gainMultiple *= (width / this.width);
- double ruler = Convert.ToDouble((width * ruleData) / Convert.ToDouble(this.width));
- this.ruler = ruler;
- }
- }
- else {
- double ruleData = 1;
- if (this.documentWorkspace.xmlSaveModel == null)
- {
- this.appWorkspace.getMeasureInfo().TryGetValue(Startup.instance.ruleDB == null ? MeasurementUnit.Micron : (MeasurementUnit)(Startup.instance.ruleDB.ruler_units), out ruleData);
- gainMultiple = Startup.instance.ruleDB == null ? 1 : Startup.instance.ruleDB.gain_multiple;
- }
- else
- {
- ruleData = this.documentWorkspace.GetRuler((MeasurementUnit)this.documentWorkspace.xmlSaveModel.ruler_units);
- gainMultiple = this.documentWorkspace.xmlSaveModel.gain_multiple;
- }
- if (!action.lists[3].value.ToString().Equals("Pixel"))
- {
-
- int width = this.imageMat.Width;
- int height = this.imageMat.Height;
- int realWidth = Convert.ToInt32(Convert.ToDouble(this.width) * ruleData);
- int realHeight = Convert.ToInt32(Convert.ToDouble(this.height) * ruleData);
- double ruler = Convert.ToDouble(this.width) / realWidth;
- this.gainMultiple *= (width / realWidth);
- action.lists[0].value = realWidth;
- action.lists[1].value = realHeight;
- }
- else {
- int width = this.imageMat.Width;
- this.gainMultiple *= (width / this.width);
- double ruler = Convert.ToDouble((width * ruleData) / Convert.ToDouble(this.width));
- this.ruler = ruler;
- }
- }
- mat = action.PerformProcess(this.imageMat.Clone());
- }
- else
- {
- mat = action.PerformProcess(this.imageMat.Clone());
- if (!this.applyButtonClick)
- {
- if (this.pixelFormat == PixelFormat.Format8bppIndexed && mat.Type() != OpenCvSharp.MatType.CV_8UC1)
- {
- mat = mat.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2GRAY);
- }
- }
- else
- {
- mat = this.documentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- }
- }
- this.Invoke(new EventHandler(delegate
- {
- //生成新图-是
- if (informationControl.radioButton1.Checked)
- {
- this.OpenFileImpl(mat);
- }
- else
- {
- Document document = Document.FromImageMat(mat);
- AppWorkspace.ActiveDocumentWorkspace.Document = document;
- }
- this.Close();
- }));
- }
- catch (Exception ex)
- {
- }
- finally
- {
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
- }
- //生成新图
- private void OpenFileImpl(OpenCvSharp.Mat mat)
- {
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(mat);
- dw.Document = document;
- dw.fileText = informationControl.fileNameTextBox1.Text;
- if (this.ruler != 0)
- {
- dw.RuleAttribute("分辨率调整", ruler, MeasurementUnit.Micron, this.gainMultiple);
- }
- else
- {
- dw.xmlSaveModel = this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- dw.rules = this.appWorkspace.ActiveDocumentWorkspace.rules;
- }
- AppWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- //参数-重设
- private void button5_Click(object sender, EventArgs e)
- {
- GetParameters(Startup.instance.imageMenuModel);
- //初始化/重置参数
- resetNumber();
- Document document = Document.FromImageMat(this.imageMat.Clone());
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- //picturePreviewControl1.pictureBox1.Image = this.bitmap;
- }
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- private void InitializeLanguageText()
- {
- this.groupBoxParam.Text = PdnResources.GetString("Menu.params.text");
- this.button5.Text = PdnResources.GetString("Menu.rebuild.Text");
- this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
- this.Text = PdnResources.GetString("Menu.geprocessiconditioningsaturationbrigh.Text");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.parametersSettingControl = new PaintDotNet.CustomControl.ParametersSettingAdjustControl();
- this.informationControl = new PaintDotNet.CustomControl.InformationAdjustControl();
- this.groupBoxParam = new System.Windows.Forms.GroupBox();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.groupBoxParam.SuspendLayout();
- this.SuspendLayout();
- //
- // parametersSettingControl
- //
- this.parametersSettingControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.parametersSettingControl.Location = new System.Drawing.Point(12, 12);
- this.parametersSettingControl.Name = "parametersSettingControl";
- this.parametersSettingControl.Size = new System.Drawing.Size(918, 58);
- this.parametersSettingControl.TabIndex = 9;
- //
- // informationControl
- //
- this.informationControl.Location = new System.Drawing.Point(12, 76);
- this.informationControl.Name = "informationControl";
- this.informationControl.Size = new System.Drawing.Size(373, 82);
- this.informationControl.TabIndex = 11;
- //
- // groupBoxParam
- //
- this.groupBoxParam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.groupBoxParam.Controls.Add(this.button5);
- this.groupBoxParam.Location = new System.Drawing.Point(12, 164);
- this.groupBoxParam.Name = "groupBoxParam";
- this.groupBoxParam.Size = new System.Drawing.Size(373, 353);
- this.groupBoxParam.TabIndex = 12;
- this.groupBoxParam.TabStop = false;
- //
- // button5
- //
- this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button5.Location = new System.Drawing.Point(292, 324);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 1;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Location = new System.Drawing.Point(392, 77);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(538, 440);
- this.groupBox1.TabIndex = 13;
- this.groupBox1.TabStop = false;
- //
- // BshTransferAdjustDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(942, 529);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.groupBoxParam);
- this.Controls.Add(this.informationControl);
- this.Controls.Add(this.parametersSettingControl);
- this.Name = "BshTransferAdjustDialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.BshTransferAdjustDialog_FormClosing);
- this.Load += new System.EventHandler(this.BshTransferAdjustDialog_Load);
- this.groupBoxParam.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private CustomControl.ParametersSettingAdjustControl parametersSettingControl;
- private CustomControl.InformationAdjustControl informationControl;
- private System.Windows.Forms.GroupBox groupBoxParam;
- private System.Windows.Forms.Button button5;
- private System.Windows.Forms.GroupBox groupBox1;
- private void BshTransferAdjustDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- #region [开启脚本录制]
- if (appWorkspace.startScriptRecording)
- {
- getScriptRecording();
- }
- #endregion
- string newpic = 1 + "";
- //获取参数实体
- ImageMenu imageMenu;
- if (Startup.instance.imageMenuModel != null)
- {
- imageMenu = Startup.instance.imageMenuModel;
- }
- else
- {
- imageMenu = new ImageMenu();
- imageMenu.ListParam = new List<ImageParam>();
- }
- //数字控制是否生成新图
- if (informationControl.radioButton1.Checked)
- newpic = 1 + "";
- else
- newpic = 0 + "";
- List<ImageParam> list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
- if (list.Count == 0)
- {
- ImageParam param = new ImageParam();
- param.menuId = (int)action.MenuId;
- param.param_key = "param_newpic";
- param.param_type = -1;
- param.param_value = newpic;
- imageMenu.ListParam.Add(param);
- }
- //判断页面是否有参数
- if (action.lists.Count > 0)
- {
- for (int i = 0; i < action.lists.Count; i++)
- {
- if (list.Count > 0)//是否存过参数
- {
- for (int j = 0; j < imageMenu.ListParam.Count; j++)//给参数实体赋值
- {
- if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == action.lists[i].key)
- {
- imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
- imageMenu.ListParam[j].param_value = action.lists[i].value.ToString();
- //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
- }
- else if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
- {
- //imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
- imageMenu.ListParam[j].param_value = newpic;
- //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
- }
- }
- //判断是否是白平衡
- if (action.MenuId == ActionType.ActionWhiteBalance)
- {
- for (int j = 0; j < imageMenu.ListParam.Count; j++)//给参数实体赋值
- {
- if (int.Parse(action.Lists[0].value.ToString()) > 1)
- {
- if (imageMenu.ListParam[j].param_key == "phaseColor" || imageMenu.ListParam[j].param_key == "imageColor")
- {
- imageMenu.ListParam[j].menuId = (int)action.MenuId;
- imageMenu.ListParam[j].param_key = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].key;
- imageMenu.ListParam[j].param_value = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].value.ToString();
- }
- }
- }
- }
- }
- else //如果没保存过新增
- {
- ImageParam param = new ImageParam();
- param.menuId = (int)action.MenuId;
- param.param_key = action.lists[i].key;
- param.param_type = (int)action.lists[i].Type;
- param.param_value = action.lists[i].value.ToString();
- //判断是否是白平衡
- if (action.MenuId == ActionType.ActionWhiteBalance)
- {
- ImageParam param5012 = new ImageParam();
- try
- {
- param5012.menuId = (int)action.MenuId;
- param5012.param_key = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].key;
- param5012.param_value = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].value.ToString();
- }
- catch (Exception)
- {
- //ImageParam param5012 = new ImageParam();
- param5012.menuId = (int)action.MenuId;
- param5012.param_key = "objectSelect";
- param5012.param_value = "1";
- }
- imageMenu.ListParam.Add(param5012);
- }
- imageMenu.ListParam.Add(param);
- }
- }
- }
- else //没有参数,给是否生成新图赋值
- {
- if (list.Count > 0)
- {
- for (int j = 0; j < imageMenu.ListParam.Count; j++)
- {
- if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
- {
- imageMenu.ListParam[j].param_value = newpic;
- }
- }
- }
- }
- Startup.instance.imageMenuModel = imageMenu;
- //按路径和名称保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<ImageMenu>(imageMenu);
- //xml保存路径
- string filePath = Application.StartupPath + "\\Config\\" + "Default\\ParameterSaving\\ParameterSaving.xml";
- //保存xml
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
- }
- /// <summary>
- /// 初始化时获取参数
- /// </summary>
- /// <param name="imageMenu">系统读取的参数配置</param>
- public void GetParameters(ImageMenu imageMenu)
- {
- List<ImageParam> list = new List<ImageParam>();
- if (imageMenu.ListParam.Count > 0)
- list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
- if (list.Count > 0)
- {
- initPamasValues = true;
- for (int i = 0; i < action.Lists.Count; i++)
- {
- for (int j = 0; j < list.Count; j++)
- {
- if (list[j].param_key.Equals(action.Lists[i].key))
- {
- action.Lists[i].Type = (Dtryt)list[j].param_type;
- action.Lists[i].value = list[j].param_value;
- break;
- }
- }
- //判断是否是白平衡
- if (action.MenuId == ActionType.ActionWhiteBalance)
- {
- for (int j = 0; j < list.Count; j++)//给参数实体赋值
- {
- if (list[j].param_key == "phaseColor")
- {
- action.Lists[0].choiseList[1].Lists[0].key = "phaseColor";
- action.Lists[0].choiseList[1].Lists[0].value = list[j].param_value;
- }
- if (list[j].param_key == "imageColor")
- {
- action.Lists[0].choiseList[2].Lists[0].key = "imageColor";
- action.Lists[0].choiseList[2].Lists[0].value = list[j].param_value;
- }
- }
- }
- }
- for (int j = 0; j < list.Count; j++)
- {
- if ("param_newpic".Equals(list[j].param_key))
- {
- if (list[j].param_value == "1")
- {
- informationControl.radioButton1.Checked = true;
- informationControl.radioButton2.Checked = false;
- }
- else
- {
- informationControl.radioButton1.Checked = false;
- informationControl.radioButton2.Checked = true;
- }
- }
- }
- }
- }
- #region [脚本录制]
- private void getScriptRecording()
- {
- List<Args> args = action.Lists;
- if (action is Action5012) {
- args[0].Type = Dtryt.Choise;
- //if (Convert.ToInt32(args[0].value) == 2)
- //{
- // ColorNumber phase0Color = new ColorNumber();
- // phase0Color.key = "imageColor";
- // phase0Color.name = PdnResources.GetString("Menu.ImageProcessing.adjust.Theoriginalcolor.text");
- // phase0Color.Value = this.panel2.BackColor.ToArgb();
- // phase0Color.initialValue = this.panel2.BackColor.ToArgb();
- // args.Add(phase0Color);
-
- //} else if (Convert.ToInt32(args[0].value) == 3) {
- // ColorNumber phaseColor = new ColorNumber();
- // phaseColor.key = "phaseColor";
- // phaseColor.name = PdnResources.GetString("Menu.ImageProcessing.adjust.Colorpicking.text");
- // phaseColor.Value = this.panel3.BackColor.ToArgb();
- // phaseColor.initialValue = this.panel3.BackColor.ToArgb();
- // args.Add(phaseColor);
- //}
- }
- appWorkspace.SetScriptStartRecording(MenuItem.MenuId, MenuItem.Text, args);
- }
- #endregion
- }
- }
|