123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828 |
- 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
- {
- /// <summary>
- /// 图像间操作
- /// </summary>
- internal class InterImageOpDialog : Form
- {
- #region 控件
- /// <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
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- 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
- /// <summary>
- /// 步长 初始值1,依次增加
- /// </summary>
- string stepLength = "00" + Startup.instance.step_length;
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 像素格式
- /// </summary>
- private PixelFormat pixelFormat;
- /// <summary>
- /// 处理程序
- /// </summary>
- private ParamObject action;
- /// <summary>
- /// 图像面板
- /// </summary>
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- // <summary>
- /// 如果有参数保存,将参数带入
- /// </summary>
- private Boolean initPamasValues = false;
- //图片选择窗口
- private InterImagePickerDialog imagePickerDialog;
- private PdnMenuItem MenuItem;
- [Browsable(false)]
- public AppWorkspace AppWorkspace
- {
- get
- {
- return this.appWorkspace;
- }
- set
- {
- this.appWorkspace = value;
- }
- }
- /// <summary>
- /// dialog
- /// </summary>
- /// <param name="appWorkspace"></param>
- /// <param name="menuId">对应菜单的id</param>
- 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();
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- public void InitData()
- {
- /// <summary>
- /// 当前活动的图像
- 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<Args> 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;
- }
- /// <summary>
- /// 选择图像按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<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);
- }
- //imageMenu.ListParam = new List<mic_script_step_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;
- }
- }
- }
- 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>(imageMenu);
- //xml保存路径
- string filePath = Application.StartupPath + "\\Config\\" + "Default\\ParameterSaving\\ParameterSaving.xml";
- //保存xml
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
- }
- 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;
- }
- }
- }
- 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;
- appWorkspace.SetScriptStartRecording(MenuItem.MenuId, MenuItem.Text, args);
- }
- #endregion
- }
- }
|