using Metis.ParameterSet;
using PaintDotNet.Base;
using PaintDotNet.Base.CommTool;
using PaintDotNet.Base.Enum;
using PaintDotNet.Base.Functionodel;
using PaintDotNet.CustomControl;
using PaintDotNet.Data.Action;
using PaintDotNet.Data.Param;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using static Metis.ParameterSet.ImageMenu;
namespace PaintDotNet.Processing
{
///
/// 预处理 - 常规操作
///
internal class NormalOperationDialog : Form
{
///
/// 步长 初始值1,依次增加
///
string stepLength = "00" + Startup.instance.step_length;
///
/// 公共按钮
///
private CommonControlButtons commonControlButtons;
///
/// 图像面板
///
private DocumentWorkspaceWindow documentWorkspace;
///
/// 主工作空间
///
private AppWorkspace appWorkspace;
///
/// 当前处理的程序
///
private ParamObject action;
///
/// 当前活动的图像
///
private OpenCvSharp.Mat imageMat;
///
/// 调用调色板的控件
///
private Panel panel2;
///
/// 调色板
///
private ColorsForm colorsFormGrid;
///
/// 一些方法用到了微米换算
///
private double ruleValue = 0.0;
///
/// 菜单id
///
private ActionType menuId;
///
/// stringarry参数高度
///
private int defaultHeight = 45;
//
/// 如果有参数保存,将参数带入
///
private Boolean initPamasValues = false;
///
/// 是否点击过应用按钮
/// 如果没有点过,直接点确定还需要走一遍方法,
/// 如果已经点过,直接拿当前图片
///
private bool applyButtonClick = false;
private PdnMenuItem MenuItem;
[Browsable(false)]
public AppWorkspace AppWorkspace
{
get
{
return this.appWorkspace;
}
set
{
this.appWorkspace = value;
}
}
///
/// dialog
///
///
/// 对应菜单的id
public NormalOperationDialog(AppWorkspace appWorkspace, ActionType menuId, string dialogText,PdnMenuItem menuItem)
{
this.menuId = menuId;
this.MenuItem = menuItem;
InitializeComponent();
InitializeLanguageText();
//
// 设置Dialog属性
//
this.AppWorkspace = appWorkspace;
this.StartPosition = FormStartPosition.CenterScreen;
this.Icon = PdnInfo.AppIcon;
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.groupBox1.Controls.Add(commonControlButtons);
this.imageMat = this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
Document document = Document.FromImageMat(imageMat.Clone());
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
this.documentWorkspace.GraphicsList = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList;
this.documentWorkspace.PhaseModels = this.appWorkspace.ActiveDocumentWorkspace.PhaseModelsForCopy;
//获取
//Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
ruleValue = this.AppWorkspace.ActiveDocumentWorkspace.GetRuler(MeasurementUnit.Micron);
resetNumber();
InitCommonButtonEvent();
SpecialAction(menuId, Color.Yellow.ToArgb());
}
/*///
/// 主要是为了改变自定义的进度条
///
///
///
private void decimalScopeControl_ValueChangedEvent(object sender, EventArgs e)
{
//特殊处理孔洞删除
if (menuId == ActionType.ActionHoleRemoval)
{
1111111
}
}*/
private void SpecialAction(ActionType menuId, int color)
{
//特殊处理孔洞删除
if (menuId == ActionType.ActionHoleRemoval)
{
//this.parametersSettingControl.applyButton.Visible = false;
/*List oneL = new List();
oneL.Add(0);
oneL.Add(double.MaxValue);
this.action.Lists[1].value = oneL;*/
List phases = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true && a.mat != null);
if (phases.Count > 0)
{
List phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true && a.mat != null);
for (int i = 0; i < phases.Count; i++)
{
PhaseModel model = new PhaseModel();
model.choise = phases[i].choise;
model.color = phases[i].color;
model.name = phases[i].name;
model.position = phases[i].position;
model.mat = new OpenCvSharp.Mat();
phases[i].mat.CopyTo(model.mat);
this.action.Lists[3].Value = color;
phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
this.documentWorkspace.Refresh();
}
}
}
}
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(menuId == ActionType.ActionHoleRemoval)
{
if (((RadioButton)sender).Checked)
{
GetMinMaxValue();
}
/*switch ((FilterParameters)(((RadioButton)sender).Tag))
{
case FilterParameters.Area:
if(((RadioButton)sender).Checked)
{
GetMinMaxValue();
}
break;
case FilterParameters.AreaRatio:
if (((RadioButton)sender).Checked)
{
GetMinMaxValue();
}
break;
case FilterParameters.AspectRatio:
if (((RadioButton)sender).Checked)
{
GetMinMaxValue();
}
break;
case FilterParameters.LongTrail:
if (((RadioButton)sender).Checked)
{
GetMinMaxValue();
}
break;
}*/
}
}
private void GetMinMaxValue()
{
DecimalScopeControl control = (DecimalScopeControl)(groupBoxParam.Controls.Find("ActionHoleRemoval", false)[0]);
control.Maximum2 = int.MaxValue;
this.applyButtonImpl(null, null);
if(((Action914)action).outmax>-1)
{
control.Maximum2 = (decimal)(((Action914)action).outmax);
}
}
private void CheckBox_CheckedChanged(object sender, EventArgs e)
{
}
///
/// 相颜色点击事件
///
///
///
private void panel2_Click(object sender, EventArgs e)
{
this.panel2 = ((Panel)sender);
this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(panel2.BackColor);
this.colorsFormGrid.ShowDialog();
}
///
/// Panel2的调色板颜色改变
///
///
///
private void gridColorChanged(object sender, EventArgs e)
{
Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
//更改背景色,触发事件
this.panel2.BackColor = color;
////改变配置文件里面的相颜色
//this.binaryExtractionModel.PhaseColor = color.ToArgb();
if (menuId == ActionType.ActionHoleRemoval)
this.SpecialAction(this.menuId, color.ToArgb());
//else OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
//关闭色板
this.colorsFormGrid.Close();
}
///
/// 初始化数据
///
public void InitData()
{
if (menuId == ActionType.ActionHoleRemoval)
{
GetMinMaxValue();
}
}
private void resetNumber()
{
switch (menuId)
{
//二值操作->腐蚀
case ActionType.ActionErosion:
action = new Data.Action.Action903();
break;
//二值操作->膨胀
case ActionType.ActionDilation:
action = new Data.Action.Action904();
break;
//二值操作->粗化
case ActionType.ActionThickening:
action = new Data.Action.Action905();
break;
//二值操作->细化
case ActionType.ActionThinning:
action = new Data.Action.Action906();
break;
//二值操作->开运算
case ActionType.ActionOpenExtraction:
action = new Data.Action.Action907();
break;
//二值操作->闭运算
case ActionType.ActionCloseExtraction:
action = new Data.Action.Action908();
break;
//二值操作->形态学分割
case ActionType.ActionMorphologySegment:
action = new Data.Action.Action909();
break;
//二值操作->分水岭分割
case ActionType.ActionWatershedSegment:
action = new Data.Action.Action910();
break;
//二值操作->去碎屑
case ActionType.ActionDebris:
action = new Data.Action.Action911();
break;
//二值操作->抽骨架
case ActionType.ActionSkeleton:
action = new Data.Action.Action912();
break;
//二值操作->孔洞删除
case ActionType.ActionHoleRemoval:
action = new Data.Action.Action914();
break;
default:
action = new Data.Action.Action903();
break;
}
for (int i = groupBoxParam.Controls.Count - 1; i > 0; i--)
{
if (!groupBoxParam.Controls[i].Name.Equals("button5"))
groupBoxParam.Controls.RemoveAt(i);
}
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);
GetParameters(Startup.instance.binaryActionModel);
}
else
{
//如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
if (AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId)
{
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.binaryActionModel);
}
int controlsTop = 0;
//初始化手动控件
for (int i = 0; i < action.Lists.Count; i++)
{
Args args = action.Lists[i];
if (args is IntegerNumber || args is DecimalNumber || args is OddNumber)
{
CustomControl.NumberParamControl numberParam = new CustomControl.NumberParamControl();
numberParam.Left = 78;
numberParam.Top = 35 + controlsTop;
//设置参数范围
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(args.value.ToString(), out fnum))
{
numberParam.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(53, 12);
label.TextAlign = ContentAlignment.MiddleRight;
label.Text = args.name + ":";
groupBoxParam.Controls.Add(label);
controlsTop += 45;
}
else if (args is ChoiseArray)
{
Label label = new Label();
label.Left = 19;
label.Top = 40 + controlsTop;
label.Size = new Size(53, 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 (j == 0)
{
radio.Checked = true;
}
radio.AutoSize = true;
radio.Location = new Point(88, 40 + controlsTop);
radio.Text = argsChoise.name + "";
radio.Tag = argsChoise.Key;
radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
radio.CheckedChanged += Radio_CheckedChanged;
radio.CheckedChanged += this.ParameterChangeEvent;
groupBoxParam.Controls.Add(radio);
controlsTop += 45;
}
}
else if (args is ColorNumber)
{
Label label = new Label();
label.Left = 5;
label.Top = 40 + controlsTop;
label.Size = new Size(65, 12);
label.TextAlign = ContentAlignment.MiddleRight;
label.Text = args.name + ":";
groupBoxParam.Controls.Add(label);
Panel panel = new Panel();
panel.BackColor = Color.FromArgb(int.Parse(args.Value.ToString()));
panel.Size = new Size(100, 35);
panel.Top = 25 + controlsTop;
panel.Left = 70;
if (menuId != ActionType.ActionHoleRemoval)
{
panel.BackColorChanged += ((ColorNumber)args).numberParam_ValueChanged;
panel.BackColorChanged += this.ParameterChangeEvent;
}
panel.Click += new EventHandler(panel2_Click);
groupBoxParam.Controls.Add(panel);
controlsTop += 45;
}
else if (args is StringArray)
{
Label label = new Label();
label.Left = 5;
label.Top = 40 + controlsTop;
label.Size = new Size(65, 12);
label.TextAlign = ContentAlignment.MiddleRight;
label.Text = args.name + ":";
groupBoxParam.Controls.Add(label);
Panel panel = new Panel();
panel.Size = new Size(200, defaultHeight);
panel.Top = 40 + controlsTop;
panel.Left = 70;
int position = 1;
int topMargin = 0;
//循环字典,铺多个radio
foreach (var item in (Dictionary)(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 * 110, topMargin);
radio.Text = item.Value.ToString();
radio.Tag = item.Key;
if (args.value != null && (int)(args.value) == (int)(object)item.Key)
{
radio.Checked = true;
}
else
{
radio.Checked = false;
}
radio.CheckedChanged += ((StringArray)args).numberParam_ValueChanged;
radio.CheckedChanged += Radio_CheckedChanged;
radio.CheckedChanged += this.ParameterChangeEvent;
panel.Controls.Add(radio);
if (position % 2 == 0) topMargin += 25;
position++;
}
groupBoxParam.Controls.Add(panel);
controlsTop += 45;
}
else if (args is DecimalScope)
{
DecimalScopeControl decimalScopeControl;
if (this.menuId == ActionType.ActionHoleRemoval)
{
decimalScopeControl = new DecimalScopeControl(PdnResources.GetString("Menu.numberrange.text") + ":", true, 100);
}
else
{
decimalScopeControl = new DecimalScopeControl(PdnResources.GetString("Menu.numberrange.text") + ":");
}
decimalScopeControl.Name = "ActionHoleRemoval";
decimalScopeControl.Size = new Size(350, 30);
decimalScopeControl.Top = 45 + controlsTop;
decimalScopeControl.Left = 5;
decimalScopeControl.numericUpDown1.Width = 50;
decimalScopeControl.numericUpDown2.Width = 50;
decimalScopeControl.DecimalPlaces = 2;
decimalScopeControl.ValueChanged += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
decimalScopeControl.ValueChanged += this.ParameterChangeEvent;
groupBoxParam.Controls.Add(decimalScopeControl);
controlsTop += 45;
//decimalScopeControl.minValue = ((List)(args.Value))[0];
//decimalScopeControl.maxValue = ((List)(args.Value))[1];
//decimalScopeControl.numericUpDown1.Value = (decimal)((List)(args.Value))[0];
//decimalScopeControl.numericUpDown2.Value = (decimal)((List)(args.Value))[1];
}
else if (args is BooleanObject)
{
Label label = new Label();
label.Left = 5;
label.Top = 40 + controlsTop;
label.Size = new Size(65, 12);
label.TextAlign = ContentAlignment.MiddleRight;
label.Text = args.name + ":";
groupBoxParam.Controls.Add(label);
CheckBox checkBox = new CheckBox();
checkBox.Text = args.name;
checkBox.Top = 35 + controlsTop;
checkBox.Left = 70;
checkBox.Checked = (bool)(((BooleanObject)args).value);
checkBox.CheckedChanged += new EventHandler(((BooleanObject)args).CheckBox_ValueChanged);
checkBox.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);
checkBox.CheckedChanged += this.ParameterChangeEvent;
groupBoxParam.Controls.Add(checkBox);
controlsTop += 45;
}
}
}
InitData();
}
private void ParameterChangeEvent(object sender, EventArgs e)
{
this.applyButtonClick = false;
}
private void BshTransferAdjustDialog_Load(object sender, EventArgs e)
{
//设置该参数false,以便方便的从子线程更新UI
//虽然这种方式省事,但是从严谨的角度考虑,在复杂多线程的情况下不能这样处理
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
//图像名称输入框
informationControl.fileNameTextBox1.Text = this.Text + "-" + stepLength;
parametersSettingControl.applyButtonClick += new EventHandler(applyButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
parametersSettingControl.sureButtonClick += new EventHandler(sureButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
}
///
/// 应用
///
///
///
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
{
//如果有选中的相
List phases = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true);
if (action.MenuId == ActionType.ActionWatershedSegment)
{
if (phases.Count > 0)
{
List phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
for (int i = 0; i < phases.Count; i++)
{
PhaseModel model = new PhaseModel();
model.choise = phases[i].choise;
model.color = phases[i].color;
model.name = phases[i].name;
model.position = phases[i].position;
model.mat = new OpenCvSharp.Mat();
phases[i].mat.CopyTo(model.mat);
phasesCopy[i].mat = action.PerformProcess(this.imageMat.Clone(), model, new Point()/*ruleValue*/);
this.documentWorkspace.Refresh();
}
}
else
{
OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
Document doc = Document.FromMat(mat);
this.documentWorkspace.Document = doc;
this.documentWorkspace.Refresh();
}
return;
}
if (phases.Count > 0)
{
List phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
for (int i = 0; i < phases.Count; i++)
{
if (phases[i].mat != null)
{
PhaseModel model = new PhaseModel();
model.choise = phases[i].choise;
model.color = phases[i].color;
model.name = phases[i].name;
model.position = phases[i].position;
model.mat = new OpenCvSharp.Mat();
phases[i].mat.CopyTo(model.mat);
phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
this.documentWorkspace.Refresh();
}
}
}
else
{
OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
Document doc = Document.FromMat(mat);
this.documentWorkspace.Document = doc;
this.documentWorkspace.Refresh();
}
this.applyButtonClick = true;
}
catch(Exception)
{
}
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
{
if(!this.applyButtonClick)
{
//特殊处理孔洞删除
if (menuId == ActionType.ActionHoleRemoval)
{
this.action.Lists[3].value = Color.Transparent.ToArgb();
}
//如果有选中的相
List phases = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true);
if (action.MenuId == ActionType.ActionWatershedSegment)
{
if (phases.Count > 0)
{
List phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
for (int i = 0; i < phases.Count; i++)
{
PhaseModel model = new PhaseModel();
model.choise = phases[i].choise;
model.color = phases[i].color;
model.name = phases[i].name;
model.position = phases[i].position;
model.mat = new OpenCvSharp.Mat();
phases[i].mat.CopyTo(model.mat);
phasesCopy[i].mat = action.PerformProcess(this.imageMat.Clone(), model, new Point()/*ruleValue*/);
this.documentWorkspace.Refresh();
}
}
else
{
OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
Document doc = Document.FromMat(mat);
this.documentWorkspace.Document = doc;
this.documentWorkspace.Refresh();
}
this.Invoke(new EventHandler(delegate
{
if (informationControl.radioButton1.Checked)
{
this.OpenFileImpl();
}
else
{
this.AppWorkspace.ActiveDocumentWorkspace.phaseModels = this.documentWorkspace.PhaseModels;
this.AppWorkspace.ActiveDocumentWorkspace.Refresh();
}
this.Close();
}));
return;
}
if (phases.Count > 0)
{
List phasesCopy = this.documentWorkspace.PhaseModels.FindAll(a => a.choise == true);
for (int i = 0; i < phases.Count; i++)
{
if (phases[i].mat != null)
{
PhaseModel model = new PhaseModel();
model.choise = phases[i].choise;
model.color = phases[i].color;
model.name = phases[i].name;
model.position = phases[i].position;
model.mat = new OpenCvSharp.Mat();
phases[i].mat.CopyTo(model.mat);
phasesCopy[i].mat = action.PerformProcess(model, ruleValue);
this.documentWorkspace.Refresh();
}
}
}
else
{
OpenCvSharp.Mat mat = action.PerformProcess(this.imageMat.Clone());
Document doc = Document.FromMat(mat);
this.documentWorkspace.Document = doc;
this.documentWorkspace.Refresh();
}
}
this.Invoke(new EventHandler(delegate
{
if (informationControl.radioButton1.Checked)
{
this.OpenFileImpl();
}
else
{
this.AppWorkspace.ActiveDocumentWorkspace.phaseModels = this.documentWorkspace.PhaseModels;
this.AppWorkspace.ActiveDocumentWorkspace.Refresh();
}
this.Close();
}));
}
catch (Exception)
{
}
finally
{
progressEvents.EndOperation(OperationResult.Finished);
}
};
procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
/*//生成新图-是
if (informationControl.radioButton1.Checked)
{
//特殊处理孔洞删除
if (menuId == ActionType.ActionHoleRemoval)
{
this.action.Lists[3].value = Color.Transparent.ToArgb();
}
if(!this.applyButtonClick)
{
this.applyButtonImpl(sender, e);
}
this.OpenFileImpl();
}
else
{
//特殊处理孔洞删除
if (menuId == ActionType.ActionHoleRemoval)
{
this.action.Lists[3].value = Color.Transparent.ToArgb();
}
if (!this.applyButtonClick)
{
this.applyButtonImpl(sender, e);
}
this.AppWorkspace.ActiveDocumentWorkspace.phaseModels = this.documentWorkspace.PhaseModels;
this.AppWorkspace.ActiveDocumentWorkspace.Refresh();
}
this.Close();*/
}
///
/// 生成新图
///
///
private void OpenFileImpl()
{
DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
Document document = Document.FromImageMat(this.documentWorkspace.CompositionSurface.CreatedAliasedMat().Clone());//return mat/*.Clone()*/;//待测试
dw.Document = document;
dw.PhaseModels = this.documentWorkspace.PhaseModelsForCopy;
dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
dw.rules = new Dictionary(this.AppWorkspace.ActiveDocumentWorkspace.rules);
//dw.PanelBottom.documentStrip.ShowPictures = false;
dw.fileText = informationControl.fileNameTextBox1.Text;
AppWorkspace.ActiveDocumentWorkspace = dw;
Startup.instance.step_length += 1;
}
///
/// 参数-重设
///
///
///
private void button5_Click(object sender, EventArgs e)
{
GetParameters(Startup.instance.binaryActionModel);
//初始化/重置参数
resetNumber();
}
#region 设计器
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
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");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
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(822, 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, 315);
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, 286);
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(442, 402);
this.groupBox1.TabIndex = 13;
this.groupBox1.TabStop = false;
//
// NormalOperationDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(846, 491);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBoxParam);
this.Controls.Add(this.informationControl);
this.Controls.Add(this.parametersSettingControl);
this.Name = "NormalOperationDialog";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NormalOperationDialog_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 GroupBox groupBox1;
#endregion
#region 关闭窗口时,保存参数
private void NormalOperationDialog_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();
}
//数字控制是否生成新图
if (informationControl.radioButton1.Checked)
newpic = 1 + "";
else
newpic = 0 + "";
List 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)
{
if (action.lists[i].Type == Dtryt.DecimalScope)
{
imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
imageMenu.ListParam[j].param_value = string.Join(",", ((List)(action.lists[i].Value)).ToArray());
imageMenu.ListParam[j].value = null;
}
else
{
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;
}
}
}
else //如果没保存过新增
{
ImageParam param = new ImageParam();
param.menuId = (int)action.MenuId;
param.param_key = action.lists[i].key;
if (action.lists[i].Type == Dtryt.DecimalScope)
{
param.param_type = (int)action.lists[i].Type;
param.param_value = string.Join(",", ((List)(action.lists[i].Value)).ToArray());
}
else
{
param.param_type = (int)action.lists[i].Type;
param.param_value = action.lists[i].value.ToString();
}
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.binaryActionModel = imageMenu;
//按路径和名称保存xml文件
string userInfoXml = XmlSerializeHelper.XmlSerialize(imageMenu);
//xml保存路径
string filePath = Application.StartupPath + "\\Config\\" + "Default\\BinaryActionSaving\\ParameterSaving.xml";
//保存xml
FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
}
///
/// 初始化时获取参数
///
/// 系统读取的参数配置
public void GetParameters(ImageMenu imageMenu)
{
List list = new List();
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))
{
if (list[j].param_type == (int)Base.Dtryt.Choise)
{
int valueC;
if (int.TryParse(list[j].param_value.ToString(), out valueC))
list[j].value = valueC;
else if (list[j].param_value.ToString() != "")
list[j].value = list[j].param_value.ToString();
else
list[j].value = 1;
}
if (list[j].param_type == (int)Base.Dtryt.Interger)
{
int valueC;
if (int.TryParse(list[j].param_value.ToString(), out valueC))
list[j].value = valueC;
else
list[j].value = 0;
}
else if (list[j].param_type == (int)Base.Dtryt.Array)
{
int valueC;
if ("Structures".Equals(list[j].param_key))
{
foreach (var item in (Dictionary)(action.Lists[i].initialValue))
{
if (list[j].param_value.ToString() == item.Key.ToString())
{
valueC = (int)(object)item.Key;
list[j].value = valueC;
break;
}
}
}
else if ("currentPhase".Equals(list[j].param_key))
{
foreach (var item in (Dictionary)(action.Lists[i].initialValue))
{
if (list[j].param_value.ToString() == item.Key.ToString())
{
valueC = (int)(object)item.Key;
list[j].value = valueC;
break;
}
}
}
else if ("UnitParameters".Equals(list[j].param_key))
{
foreach (var item in (Dictionary)(action.Lists[i].initialValue))
{
if (list[j].param_value.ToString() == item.Key.ToString())
{
valueC = (int)(object)item.Key;
list[j].value = valueC;
break;
}
}
}
else if ("FilterParameters".Equals(list[j].param_key))
{
foreach (var item in (Dictionary)(action.Lists[i].initialValue))
{
if (list[j].param_value.ToString() == item.Key.ToString())
{
valueC = (int)(object)item.Key;
list[j].value = valueC;
break;
}
}
}
else if ("FunctionParameters".Equals(list[j].param_key))
{
foreach (var item in (Dictionary)(action.Lists[i].initialValue))
{
if (list[j].param_value.ToString() == item.Key.ToString())
{
valueC = (int)(object)item.Key;
list[j].value = valueC;
break;
}
}
}
else
{
if (int.TryParse(list[j].param_value.ToString(), out valueC))
list[j].value = valueC;
else
list[j].value = 0;
}
}
else if (list[j].param_type == (int)Base.Dtryt.Boolean)
{
bool valueC;
if (Boolean.TryParse(list[j].param_value.ToString(), out valueC))
list[j].value = valueC;
else
list[j].value = list[j].param_value.ToString().Equals("0");
}
else if (list[j].param_type == (int)Base.Dtryt.DecimalScope)
{
string[] valuelst = list[j].param_value.Split(',');
List listV = new List();
foreach (string str in valuelst)
{
double outV;
if (double.TryParse(str, out outV))
listV.Add(outV);
else
listV.Add(0);
}
list[j].value = listV;
}
else if (list[j].param_type == (int)Base.Dtryt.Color)
{
int valueC;
if (int.TryParse(list[j].param_value.ToString(), out valueC))
list[j].value = valueC;
else
list[j].value = -65536;
}
action.Lists[i].Type = (Dtryt)list[j].param_type;
if (list[j].value != null)
{
action.Lists[i].value = list[j].value;
}
else
{
action.Lists[i].value = int.Parse(list[j].param_value);
}
break;
}
}
}
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;
}
}
}
}
}
#endregion
#region [脚本录制]
private void getScriptRecording()
{
List args = action.Lists;
appWorkspace.SetScriptStartRecording(MenuItem.MenuId, MenuItem.Text, args);
}
#endregion
}
}