using Metis.ParameterSet;
using PaintDotNet.Base;
using PaintDotNet.Base.CommTool;
using PaintDotNet.CustomControl;
using PaintDotNet.Data.Param;
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
{
///
/// 图像间操作
///
internal class InterImageOpDialog : Form
{
#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
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.groupBoxParam = new System.Windows.Forms.GroupBox();
this.listView1 = new System.Windows.Forms.ListView();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.labelFileName1 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.button5 = new System.Windows.Forms.Button();
this.informationControl = new PaintDotNet.CustomControl.InformationAdjustControl();
this.parametersSettingControl = new PaintDotNet.CustomControl.ParametersSettingAdjustControl();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBoxParam.SuspendLayout();
this.SuspendLayout();
//
// 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.listView1);
this.groupBoxParam.Controls.Add(this.labelFileName1);
this.groupBoxParam.Controls.Add(this.label1);
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, 574);
this.groupBoxParam.TabIndex = 16;
this.groupBoxParam.TabStop = false;
//
// listView1
//
this.listView1.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.listView1.HideSelection = false;
this.listView1.LargeImageList = this.imageList1;
this.listView1.Location = new System.Drawing.Point(217, 152);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(113, 377);
this.listView1.TabIndex = 7;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.Visible = false;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick);
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// labelFileName1
//
this.labelFileName1.AutoSize = true;
this.labelFileName1.Location = new System.Drawing.Point(88, 40);
this.labelFileName1.Name = "labelFileName1";
this.labelFileName1.Size = new System.Drawing.Size(221, 12);
this.labelFileName1.TabIndex = 3;
this.labelFileName1.Text = "label2label2label2label2label2label2";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(11, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 12);
this.label1.TabIndex = 2;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// 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, 545);
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);
//
// 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 = 15;
//
// 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(776, 58);
this.parametersSettingControl.TabIndex = 13;
//
// 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(396, 661);
this.groupBox1.TabIndex = 17;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "预览";
//
// InterImageOpDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 750);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBoxParam);
this.Controls.Add(this.informationControl);
this.Controls.Add(this.parametersSettingControl);
this.Name = "InterImageOpDialog";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.InterImageOpDialog_FormClosing);
this.Load += new System.EventHandler(this.InterImageOpDialog_Load);
this.groupBoxParam.ResumeLayout(false);
this.groupBoxParam.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBoxParam;
private System.Windows.Forms.Button button5;
private CustomControl.InformationAdjustControl informationControl;
private CustomControl.ParametersSettingAdjustControl parametersSettingControl;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label labelFileName1;
private System.Windows.Forms.ListView listView1;
private ImageList imageList1;
private GroupBox groupBox1;
#endregion
///
/// 步长 初始值1,依次增加
///
string stepLength = "00" + Startup.instance.step_length;
private AppWorkspace appWorkspace;
///
/// 像素格式
///
private PixelFormat pixelFormat;
///
/// 处理程序
///
private ParamObject action;
///
/// 图像面板
///
private DocumentWorkspaceWindow documentWorkspace;
///
/// 公共按钮
///
private CommonControlButtons commonControlButtons;
//
/// 如果有参数保存,将参数带入
///
private Boolean initPamasValues = false;
//图片选择窗口
private InterImagePickerDialog imagePickerDialog;
private PdnMenuItem MenuItem;
[Browsable(false)]
public AppWorkspace AppWorkspace
{
get
{
return this.appWorkspace;
}
set
{
this.appWorkspace = value;
}
}
///
/// dialog
///
///
/// 对应菜单的id
public InterImageOpDialog(AppWorkspace appWorkspace, ActionType menuId, string dialogText, PdnMenuItem menuItem)
{
this.AppWorkspace = appWorkspace;
InitializeComponent();
this.MenuItem = menuItem;
this.pixelFormat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.PixelFormat;
this.Text = PdnResources.GetString("Menu.ImageProcessing.boundarydetection.Imageprodd.text");
this.button5.Text = PdnResources.GetString("Menu.rebuild.Text");
this.label1.Text = PdnResources.GetString("Menu.Inputimage1.text") + ":";
this.groupBoxParam.Text = PdnResources.GetString("Menu.params.text");
this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
//
// 设置Dialog属性
//
this.StartPosition = FormStartPosition.CenterScreen;
this.Icon = PdnInfo.AppIcon;
this.Text = dialogText;
//
//初始化图像控件
//
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.RealTimeStitching:
action = new Data.Action.Action411();
break;
case ActionType.ActionImageAddition:
action = new Data.Action.Action5050();
break;
case ActionType.ActionImageSubtraction:
action = new Data.Action.Action5051();
break;
case ActionType.ActionImageMultiplication:
action = new Data.Action.Action5052();
break;
case ActionType.ActionImageDivision:
action = new Data.Action.Action5053();
break;
case ActionType.ActionImageAverage:
action = new Data.Action.Action5054();
break;
case ActionType.ActionImageSquare:
action = new Data.Action.Action5055();
break;
case ActionType.ActionImageSquareBoot:
action = new Data.Action.Action5056();
break;
case ActionType.ActionImageLogarithm:
action = new Data.Action.Action5057();
break;
case ActionType.ActionImageIndex:
action = new Data.Action.Action5058();
break;
case ActionType.ActionImageMax:
action = new Data.Action.Action5059();
break;
case ActionType.ActionImageMin:
action = new Data.Action.Action5060();
break;
default:
action = new Data.Action.Action5010();
break;
}
if (action.Lists == null || action.Lists.Count < 1)
{
GetParameters(Startup.instance.imageMenuModel);
//暂无参数
}
else
{
GetParameters(Startup.instance.imageMenuModel);
int controlsTop = 45;
//初始化手动控件
for (int i = 0; i < action.Lists.Count; i++)
{
Args args = action.Lists[i];
if (args is InputMatObject)
{
CustomControl.InputMatControl inputMat = new CustomControl.InputMatControl();
inputMat.Left = 88;
inputMat.Top = 35 + controlsTop;
//设置参数范围
inputMat.paramIndex = 100 + i;
inputMat.selectButtonClick += new EventHandler(selectButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
groupBoxParam.Controls.Add(inputMat);
groupBoxParam.Controls.SetChildIndex(inputMat, 100 + i);
//inputMat.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged); //111
Label label = new Label();
label.Left = 11;
label.Top = 40 + controlsTop;
label.Size = new Size(71, 12);
label.TextAlign = ContentAlignment.MiddleRight;
label.Text = args.name + ":";
groupBoxParam.Controls.Add(label);
controlsTop += 45;
}
else if (args is DecimalNumber)
{
CustomControl.NumberParamControl numberParam = new CustomControl.NumberParamControl();
numberParam.Left = 88;
numberParam.Top = 35 + controlsTop;
//设置参数范围
numberParam.paramIndex = 100 + i;
numberParam.DecimalPlaces = ((DecimalNumber)args).DecimalPlaces;
numberParam.Minimum = (double)((DecimalNumber)args).Min;
numberParam.Maximum = (double)((DecimalNumber)args).Max;
double fnum = 0;
if (double.TryParse((initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
{
numberParam.Value = fnum;
}
//numberParam.Value = /*(int)*/args.initialValue;
groupBoxParam.Controls.Add(numberParam);
groupBoxParam.Controls.SetChildIndex(numberParam, 100 + i);
if (args is DecimalNumber)
{
numberParam.ValueChanged += new EventHandler(((DecimalNumber)args).numberParam_ValueChanged);
}
else
{
numberParam.ValueChanged += new EventHandler(((IntegerNumber)args).numberParam_ValueChanged);
}
Label label = new Label();
label.Left = 11;
label.Top = 40 + controlsTop;
label.Size = new Size(71, 12);
label.TextAlign = ContentAlignment.MiddleRight;
label.Text = args.name + ":";
groupBoxParam.Controls.Add(label);
controlsTop += 45;
}
}
}
InitData();
InitCommonButtonEvent();
}
///
/// 初始化数据
///
public void InitData()
{
///
/// 当前活动的图像
OpenCvSharp.Mat imageMat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
//给picturebox赋值
Document document = Document.FromImageMat(imageMat);//待测试
this.documentWorkspace.Document = document;
this.documentWorkspace.Visible = true;
this.documentWorkspace.Refresh();
//给输入图像1赋值
labelFileName1.Text = AppWorkspace.ActiveDocumentWorkspace.GetFriendlyName();
//初始化/重置参数
resetNumber();
//初始化图片列表
for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
{
this.imageList1.Images.Add("img" + i, AppWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap());
listView1.Items.Add("", i);
listView1.Items[i].ImageIndex = i;
listView1.Items[i].Name = "";
}
}
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 resetNumber()
{
foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
{
if (control is CustomControl.InputMatControl)
{
CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
inputMat.TextValue = AppWorkspace.ActiveDocumentWorkspace.GetFriendlyName();
if (inputMat.paramIndex >= 100)
{
Args args = action.Lists[inputMat.paramIndex - 100];
args.Value = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
}
}
else if (control is CustomControl.NumberParamControl && ((CustomControl.NumberParamControl)control).paramIndex >= 100)
{
CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
//List list1s = action.Lists[0];
Args args = /*list1s*/action.Lists[numberParam.paramIndex - 100];
double fnum = 0;
if (double.TryParse((initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
{
numberParam.Value = fnum;
}
//numberParam.Value = (int)args.initialValue;
}
}
}
private void InterImageOpDialog_Load(object sender, EventArgs e)
{
//图像名称输入框
informationControl.fileNameTextBox1.Text = this.Text + "-" + stepLength;
//picturePreviewControl1.isShown = true;
parametersSettingControl.applyButtonClick += new EventHandler(applyButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
parametersSettingControl.sureButtonClick += new EventHandler(sureButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
}
//应用
private void applyButtonImpl(object sender, EventArgs e)
{
OpenCvSharp.Mat mat = action.PerformProcess(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone());
Document document = Document.FromMat(mat);
this.documentWorkspace.Document = document;
this.documentWorkspace.Refresh();
//picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
if (action.MenuId == ActionType.RealTimeStitching)
{
Document doc = Document.FromMat(mat.Clone());
AppWorkspace.ActiveDocumentWorkspace.Document = doc;
AppWorkspace.ActiveDocumentWorkspace.Refresh();
}
}
//确定
internal void sureButtonImpl(object sender, EventArgs e)
{
OpenCvSharp.Mat mat = action.PerformProcess(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone());
if (this.pixelFormat == PixelFormat.Format8bppIndexed && mat.Type() != OpenCvSharp.MatType.CV_8UC1)
{
mat = mat.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2GRAY);
}
//生成新图-是
if (informationControl.radioButton1.Checked)
{
this.OpenFileImpl(mat);
}
else
{
AppWorkspace.ActiveDocumentWorkspace.Document = Document.FromMat(mat);
AppWorkspace.ActiveDocumentWorkspace.Refresh();
//AppWorkspace.ActiveDocumentWorkspace.CompositionSurface = Surface.CopyFromBitmap(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat));
}
this.Close();
}
//生成新图
private void OpenFileImpl(OpenCvSharp.Mat mat)
{
DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
Document document = Document.FromImageMat(mat);
dw.Document = document;
dw.fileText = informationControl.fileNameTextBox1.Text;
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)
{
//初始化/重置参数
resetNumber();
documentWorkspace.Document = AppWorkspace.ActiveDocumentWorkspace.Document;
documentWorkspace.Refresh();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
{
if (control is CustomControl.InputMatControl)
{
CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
inputMat.TextValue = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
if (inputMat.paramIndex >= 100)
{
Args args = action.Lists[inputMat.paramIndex - 100];
args.Value = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreatedAliasedMat().Clone();
((InputMatObject)args).FriendlyName = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
((InputMatObject)args).FilePath = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].FilePath;
}
}
}
listView1.Visible = false;
}
///
/// 选择图像按钮点击事件
///
///
///
private void selectButtonImpl(object sender, EventArgs e)
{
//listView1.Visible = true;
if (imagePickerDialog == null)
{
imagePickerDialog = new InterImagePickerDialog(AppWorkspace);
//imagePickerDialog.StartPosition = FormStartPosition.CenterScreen;
imagePickerDialog.StartPosition = FormStartPosition.Manual;
//Point pt = MousePosition;//获取鼠标的屏幕坐标// PointToScreen(((CustomControl.InputMatControl)sender).Location).Y + ((CustomControl.InputMatControl)sender).Height;//
imagePickerDialog.Left = ((CustomControl.InputMatControl)sender).Left + 12 + this.Left + groupBoxParam.Left;// pt.X;
imagePickerDialog.Top = ((CustomControl.InputMatControl)sender).Bottom + 36 + this.Top + groupBoxParam.Top;// pt.Y;
imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
imagePickerDialog.Show();
}
else
{
if (!imagePickerDialog.IsDisposed)
{
imagePickerDialog.WindowState = FormWindowState.Normal;
}
else
{
imagePickerDialog = new InterImagePickerDialog(AppWorkspace);
//imagePickerDialog.StartPosition = FormStartPosition.CenterScreen;
imagePickerDialog.StartPosition = FormStartPosition.Manual;
//Point pt = MousePosition;//获取鼠标的屏幕坐标
imagePickerDialog.Left = ((CustomControl.InputMatControl)sender).Left + 12 + this.Left + groupBoxParam.Left;// pt.X;
imagePickerDialog.Top = ((CustomControl.InputMatControl)sender).Bottom + 36 + this.Top + groupBoxParam.Top;// pt.Y;
imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
imagePickerDialog.Show();
}
}
}
private void inputMat_ValueChanged(object sender, EventArgs e) //111
{
//DocumentWorkspace workspace = AppWorkspace.DocumentWorkspaces[this.dataGridView1.CurrentRow.Index];
if (sender is DocumentWorkspace)
{
foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
{
if (control is CustomControl.InputMatControl)
{
CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
inputMat.TextValue = ((DocumentWorkspace)sender).GetFriendlyName();
if (inputMat.paramIndex >= 100)
{
Args args = action.Lists[inputMat.paramIndex - 100];
args.Value = ((DocumentWorkspace)sender).CompositionSurface.CreatedAliasedMat().Clone();
((InputMatObject)args).FriendlyName = ((DocumentWorkspace)sender).GetFriendlyName();
((InputMatObject)args).FilePath = ((DocumentWorkspace)sender).FilePath;
}
}
}
}
//Bitmap map = workspace.SurfaceBox.Surface.CreateAliasedBitmap();
//OpenCvSharp.Mat mat = PaintDotNet.Camera.Tools.ToMat(map);
////改变Args的值
//Args args = action.Lists[((OpenCvSharp.Mat)sender).paramIndex - 100];
////args.Value = ((CustomControl.InputMatControl)sender).Value;
}
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
{
if (control is CustomControl.InputMatControl)
{
CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
inputMat.TextValue = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
if (inputMat.paramIndex >= 100)
{
Args args = action.Lists[inputMat.paramIndex - 100];
args.Value = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreatedAliasedMat().Clone();
((InputMatObject)args).FriendlyName = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
((InputMatObject)args).FilePath = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].FilePath;
}
//inputMat.
}
}
listView1.Visible = false;
}
private void InterImageOpDialog_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);
}
//imageMenu.ListParam = new List();
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;
}
}
}
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();
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);
//xml保存路径
string filePath = Application.StartupPath + "\\Config\\" + "Default\\ParameterSaving\\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))
{
action.Lists[i].Type = (Dtryt)list[j].param_type;
action.Lists[i].value = 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;
}
}
}
}
}
#region [脚本录制]
private void getScriptRecording()
{
List args = action.Lists;
appWorkspace.SetScriptStartRecording(MenuItem.MenuId, MenuItem.Text, args);
}
#endregion
}
}