123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- using PaintDotNet.Base;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.Data.Param;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Reflection;
- using System.Windows.Forms;
- namespace PaintDotNet.Instrument
- {
- /// <summary>
- /// 脚本管理
- /// </summary>
- internal class ScriptManageDialog : FloatingToolForm// PdnBaseForm
- {
- #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.button1 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.listBox1 = new System.Windows.Forms.ListBox();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(94, 12);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(50, 23);
- this.button1.TabIndex = 1;
- this.button1.Text = "新建";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(151, 12);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(50, 23);
- this.button2.TabIndex = 2;
- this.button2.Text = "修改";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(208, 12);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(50, 23);
- this.button3.TabIndex = 3;
- this.button3.Text = "删除";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(265, 12);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(50, 23);
- this.button4.TabIndex = 4;
- this.button4.Text = "刷新";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(12, 12);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 5;
- this.button5.Text = "执行";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // listBox1
- //
- this.listBox1.FormattingEnabled = true;
- this.listBox1.ItemHeight = 12;
- this.listBox1.Location = new System.Drawing.Point(12, 42);
- this.listBox1.Name = "listBox1";
- this.listBox1.Size = new System.Drawing.Size(303, 400);
- this.listBox1.TabIndex = 6;
- //
- // ScriptManageDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(323, 450);
- this.Controls.Add(this.listBox1);
- this.Controls.Add(this.button5);
- this.Controls.Add(this.button4);
- this.Controls.Add(this.button3);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.button1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.Name = "ScriptManageDialog";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "脚本管理";
- this.TopMost = false;
- this.Activated += new System.EventHandler(this.ScriptManageDialog_Activated_1);
- this.Controls.SetChildIndex(this.button1, 0);
- this.Controls.SetChildIndex(this.button2, 0);
- this.Controls.SetChildIndex(this.button3, 0);
- this.Controls.SetChildIndex(this.button4, 0);
- this.Controls.SetChildIndex(this.button5, 0);
- this.Controls.SetChildIndex(this.listBox1, 0);
- this.ResumeLayout(false);
- }
- #endregion
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.Button button4;
- private System.Windows.Forms.Button button5;
- private System.Windows.Forms.ListBox listBox1;
- #endregion
- private AppWorkspace appWorkspace;
- private ToolStripItemCollection collection;
- private ScriptEditDialog scriptEditDialog;
- //private ScriptStepDialog scriptStepDialog;
- private List<mic_script> list;
- /// <summary>
- /// 获取当前选中的脚本步骤
- /// </summary>
- List<mic_script_step> steps = new List<mic_script_step>();
- /// <summary>
- /// 获取当前选中的脚本步骤参数
- /// </summary>
- private List<mic_script_step_param> paramss = new List<mic_script_step_param>();
- /// <summary>
- /// 获取当前执行的脚本id和脚本参数
- /// </summary>
- private ParamObject currentParam = null;
- /// <summary>
- /// 当前正在执行哪个脚本
- /// </summary>
- private int currentRunningIndex = 0;
- /// <summary>
- /// 当前执行到哪个脚本
- /// </summary>
- private int currentIndex = 0;
- /// <summary>
- /// 手动退出脚本执行
- /// </summary>
- private bool alertShutDownAction = false;
- public ScriptManageDialog(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
- this.ShowInTaskbar = false;
- InitializeComponent();
- this.button1.Text = PdnResources.GetString("Menu.New.text");
- this.button2.Text = PdnResources.GetString("Menu.modify.Text");
- this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
- this.button4.Text = PdnResources.GetString("Menu.Refresh.text");
- this.button5.Text = PdnResources.GetString("Menu.tool.Scriptmanagement.execute.text");
- this.Text = PdnResources.GetString("Menu.Tools.Script.Text");
- this.Text = PdnResources.GetString("Menu.Tools.Script.Text");
- }
- /// <summary>
- /// 新建
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- this.appWorkspace.ScriptRecordingModel = null;
- this.appWorkspace.editScriptRecording = false;
- if (scriptEditDialog == null)
- {
- CreateScriptEditDialog();
- }
- else
- {
- if (scriptEditDialog.IsDisposed)
- {
- CreateScriptEditDialog();
- }
- else
- {
- scriptEditDialog.WindowState = FormWindowState.Normal;
- }
- }
- }
- private void CreateScriptEditDialog()
- {
- scriptEditDialog = new ScriptEditDialog(appWorkspace, false, null);
- scriptEditDialog.StartPosition = FormStartPosition.CenterScreen;
- scriptEditDialog.ShowDialog();
- }
- /// <summary>
- /// 设置当前执行到脚本功能的名称
- /// </summary>
- /// <param name="text"></param>
- private void setScriptText(string stepName)
- {
- if (stepName.StartsWith("-"))
- stepName = stepName.TrimStart(new char[] { '-' });
- appWorkspace.Widgets.RunningDialog.setScriptText(stepName, (this.currentRunningIndex == steps.Count - 1));
- //if (scriptStepDialog == null || scriptStepDialog.IsDisposed)
- // return;
- //scriptStepDialog.setScriptText(stepName, (currentRunningIndex == steps.Count - 1));
- }
- /// <summary>
- /// 初始化脚本列表
- /// </summary>
- private void InitScriptList()
- {
- this.listBox1.Items.Clear();
- list = mic_script_BLL.FindAll();
- foreach (var item in list)
- {
- this.listBox1.Items.Add(item.name);
- }
- }
- private void ScriptManageDialog_Activated_1(object sender, EventArgs e)
- {
- InitScriptList();
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- this.appWorkspace.ScriptRecordingModel = null;
- this.appWorkspace.editScriptRecording = false;
- if (this.listBox1.SelectedItem != null)
- {
- scriptEditDialog = new ScriptEditDialog(appWorkspace, true, list[this.listBox1.SelectedIndex]);
- scriptEditDialog.StartPosition = FormStartPosition.CenterScreen;
- scriptEditDialog.ShowDialog();
- }
- }
- /// <summary>
- /// 刷新
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- InitScriptList();
- }
- /// <summary>
- /// 删除脚本
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (this.listBox1.SelectedItem != null)
- {
- var toremoveItem = this.listBox1.SelectedItem;
- int selectedItem = this.listBox1.SelectedIndex;
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousureyouwanteletethescript.Text")+"?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);//0930###19008
- if (dr != DialogResult.OK)
- return;
- mic_script_BLL.Del(this.list[selectedItem].id);
- this.listBox1.Items.Remove(toremoveItem);
- }
- InitScriptList();
- }
- /// <summary>
- /// 当前正在执行哪个脚本
- /// </summary>
- public ParamObject ScriptCurrentParam
- {
- set
- {
- currentParam = value;
- }
- get
- {
- return currentParam;
- }
- }
- /// <summary>
- /// 退出脚本执行
- /// </summary>
- public void ShutDownScriptRunning()
- {
- this.alertShutDownAction = true;
- this.currentIndex = steps.Count;
- appWorkspace.ActiveDocumentWorkspace.ActiveTool= Annotation.Enum.DrawToolType.Pointer;
- appWorkspace.ScriptStopping = false;
- ResumeScriptRunning();
- }
- /// <summary>
- /// 用于标注测量后继续执行
- /// </summary>
- public void ResumeScriptRunning()
- {
- if (!appWorkspace.ScriptRunning)
- return;
- if (appWorkspace.ScriptStopping)
- return;
- //循环脚本步骤
- for (int index = this.currentIndex; index < steps.Count; index++)
- {
- mic_script_step step = steps[index];
- if (!appWorkspace.ScriptRunning)
- break;
- this.currentRunningIndex = index;
- //递归的方式
- this.RecursiveData(this.collection, step, "");
- if (appWorkspace.ScriptStopping)
- {
- this.currentIndex = index + 1;
- break;
- }
- }
- if (!appWorkspace.ScriptStopping)
- appWorkspace.ScriptRunning = false;
- refreshScriptRunningStatus();
- }
- /// <summary>
- /// 执行脚本
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (this.listBox1.SelectedItem != null)
- {
- //appWorkspace.Widgets.RunningDialog.Show();
- appWorkspace.Widgets.RunningDialog.Visible = true;
- ////appWorkspace.Widgets.RunningDialog.setScriptText(parentName + "-" + /*list[this.listBox1.SelectedIndex]*/((PdnMenuItem)collection[i]).Text);
- //scriptStepDialog = new ScriptStepDialog(appWorkspace, true, list[this.listBox1.SelectedIndex]);
- //scriptStepDialog.StartPosition = FormStartPosition.CenterParent/*.CenterScreen*/;
- //scriptStepDialog.Show();
- }
- if (this.listBox1.SelectedItem!=null)
- {
- this.currentIndex = 0;
- steps = mic_script_step_BLL.FindAllByScripId(list[this.listBox1.SelectedIndex].id);
- paramss = mic_script_step_param_BLL.FindAllByScriptId(list[this.listBox1.SelectedIndex].id);
- //this.WindowState = FormWindowState.Minimized;
- this.Enabled = false;
- appWorkspace.ScriptRunning = false;
- appWorkspace.ScriptStopping = false;
- appWorkspace.ScriptRunning = true;
- //appWorkspace.toolsPanel.RefreshTools();
- //appWorkspace.ToolBar.ResetCustomizeTools();
- //循环脚本步骤
- for (int index = this.currentIndex; index < steps.Count; index++)
- {
- mic_script_step step = steps[index];
- if (!appWorkspace.ScriptRunning)
- break;
- this.currentRunningIndex = index;
- //递归的方式
- this.RecursiveData(this.collection, step, "");
- if (appWorkspace.ScriptStopping)
- {
- this.currentIndex = index + 1;
- break;
- }
- //下面是根据name查找的方式,效率应该更高,不过需要改改数据结构
- /**
- ToolStripItem[] items = this.collection.Find(step.step_name, true);
- if (items != null && items.Length>0)
- {
- foreach(ToolStripItem item in items)
- {
- if (!item.Name.Equals("OpenRecent"))
- {
- if (item.GetType() != typeof(ToolStripSeparator))
- {
- if (step.menu_id == ((PdnMenuItem)item).MenuId)
- {
- ((PdnMenuItem)item).PerformClick();
- }
- }
- }
- }
- }
- **/
- }
- if (!appWorkspace.ScriptStopping)
- appWorkspace.ScriptRunning = false;
- refreshScriptRunningStatus();
- }
- }
- /// <summary>
- /// 脚本执行完成给出提示并刷新显示状态
- /// </summary>
- private void refreshScriptRunningStatus()
- {
- if (!appWorkspace.ScriptRunning && !appWorkspace.ScriptStopping)
- {
- if (this.alertShutDownAction)
- this.alertShutDownAction = false;
- else
- MessageBox.Show(PdnResources.GetString("Menu.criptexecutioncomplet.Text"));
- appWorkspace.Widgets.RunningDialog.Visible = false;
- //if (scriptStepDialog != null/* && !scriptStepDialog.IsDisposed*/)
- // scriptStepDialog.Close();
- //this.WindowState = FormWindowState.Normal;
- this.Enabled = true;
- //appWorkspace.toolsPanel.RefreshTools();
- //appWorkspace.ToolBar.ResetCustomizeTools();
- }
- }
- /// <summary>
- /// 递归查找菜单,暂时不用,改成直接用name查找
- /// </summary>
- /// <param name="collection"></param>
- /// <param name="step"></param>
- private void RecursiveData(ToolStripItemCollection collection, mic_script_step step, string parentName)
- {
- for (int i = 0; i < collection.Count; i++)
- {
- if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
- {
- if (collection[i] is PdnMenuItem)
- {
- if (step.menu_id == ((PdnMenuItem)collection[i]).MenuId)
- {
- if (step.automatic == 1 && !((PdnMenuItem)collection[i]).NeedOpenDialog)
- {
- //在这里反射出对应功能的参数类
- string className = InvariantData.path_Action + ".Action" + step.menu_id;
- ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- if (param != null && !(new List<string>() { "" }.Contains(param.OpenImage)) && param.Lists != null)
- {
- if (appWorkspace.ActiveDocumentWorkspace == null)
- {
- MessageBox.Show(((PdnMenuItem)collection[i]).Text + ":请打开图片");
- appWorkspace.ScriptRunning = false;
- break;
- }
- setScriptText(parentName + "-" + ((PdnMenuItem)collection[i]).Text);
- if (((PdnMenuItem)collection[i]).CanUseInSenseShield)
- {
- //if (((PdnMenuItem)collection[i]).NeedOpenDialog)
- //{
- // setScriptText(parentName + "-" + ((PdnMenuItem)collection[i]).Text);
- // ((PdnMenuItem)collection[i]).PerformClick();
- // if (this.currentRunningIndex < steps.Count - 1 && !((PdnMenuItem)collection[i]).AutoNextScript
- // && ((PdnMenuItem)collection[i]).NeedWaitKey && this.appWorkspace.GetScriptRunning())
- // this.appWorkspace.SetScriptStopping(true);
- //}
- //else
- //{
- DocumentWorkspace[] scriptWorkspaces = appWorkspace.ScriptWorkspaces;
- if (scriptWorkspaces == null)
- autoStep(param, step.id, parentName + "-" + ((PdnMenuItem)collection[i]).Text, null);
- else//循环处理多张打开的图片
- {
- foreach (DocumentWorkspace item in scriptWorkspaces)
- {
- autoStep(param, step.id, parentName + "-" + ((PdnMenuItem)collection[i]).Text, item);
- item.OpenInScriptRunning = false;
- }
- }
- }
- }
- else
- {
- this.currentParam = null;
- setScriptText(parentName + "-" + ((PdnMenuItem)collection[i]).Text);
- ((PdnMenuItem)collection[i]).PerformClick();
- if (this.currentRunningIndex < steps.Count - 1 && !((PdnMenuItem)collection[i]).AutoNextScript
- && ((PdnMenuItem)collection[i]).NeedWaitKey && this.appWorkspace.GetScriptRunning()
- /* 、、待调试已确认NeedOpenDialog是否多余 && !((PdnMenuItem)collection[i]).NeedOpenDialog*/)
- this.appWorkspace.SetScriptStopping(true);
- //else if (((PdnMenuItem)collection[i]).NeedOpenDialog)
- //{//...待调试已确认NeedOpenDialog是否多余
- // this.appWorkspace.SetScriptStopping(true);
- //}
- }
- }
- else
- {
- //在这里反射出对应功能的参数类
- string className = InvariantData.path_Action + ".Action" + step.menu_id;
- this.currentParam = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- if (this.currentParam != null && this.currentParam.Lists != null)
- {
- List<Args> list = new List<Args>();
- foreach (Args arg in this.currentParam.Lists)
- {
- mic_script_step_param param1 = paramss.Find(m => m.param_key.Equals(arg.Key) && m.step_id == step.id);
- if (param1 != null)
- {
- arg.Value = param1.value != null ? param1.value : param1.param_value;
- if (arg.choiseList != null && arg.choiseList.Count > 0)
- {
- try
- {
- int index = Convert.ToInt32(arg.value);
- var thisArg = arg.choiseList[index];
- foreach (var item in thisArg.lists)
- {
- mic_script_step_param thisParam = paramss.Find(m => m.param_key.Equals(item.Key) && m.step_id == step.id);
- if (thisParam != null)
- {
- item.value = thisParam.value != null ? thisParam.value : thisParam.param_value;
- list.Add(item);
- }
- }
- }
- catch (Exception)
- {
- continue;
- }
- }
- }
- }
- this.currentParam.lists.AddRange(list);
- }
- setScriptText(parentName + "-" + ((PdnMenuItem)collection[i]).Text);
- this.appWorkspace.ScriptAutomatic = (step.automatic == 1);
- ((PdnMenuItem)collection[i]).PerformClick();
- if (this.currentRunningIndex < steps.Count - 1 && !((PdnMenuItem)collection[i]).AutoNextScript
- && ((PdnMenuItem)collection[i]).NeedWaitKey && this.appWorkspace.GetScriptRunning())
- this.appWorkspace.SetScriptStopping(true);
- }
- }
- if (appWorkspace.ScriptStopping)
- {
- //waitKey();
- }
- else
- RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, step, parentName + "-" + ((PdnMenuItem)collection[i]).Text);
- }
- }
- }
- }
-
- /// <summary>
- /// 脚本自动执行的方法
- /// </summary>
- /// <param name="param"></param>
- /// <param name="stepId"></param>
- /// <param name="stepName"></param>
- private void autoStep(ParamObject param, int stepId, string stepName, DocumentWorkspace oneWorkSpace)
- {
- if (stepName.StartsWith("-"))
- stepName = stepName.TrimStart(new char[] { '-' });
- bool createNewImage = true;
- foreach (Args arg in param.Lists)
- {
- mic_script_step_param param1 = paramss.Find(m => m.param_key.Equals(arg.Key) && m.step_id == stepId);
- if (param1 != null)
- arg.Value = param1.value != null ? param1.value : param1.param_value;
- switch (arg.Key)
- {
- case "createNewImg":
- createNewImage = (int)arg.Value == 0 ? true : false;
- break;
- }
- }
- OpenCvSharp.Mat imageMat;
- if (oneWorkSpace == null)
- imageMat = appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
- else
- imageMat = oneWorkSpace.CompositionSurface.CreatedAliasedMat();
- if (param.OpenImage.Equals("current"))
- {
- OpenCvSharp.Mat mat = param.PerformProcess(imageMat.Clone());
- DocumentWorkspace dw;
- if (!createNewImage)
- {
- dw = appWorkspace.ActiveDocumentWorkspace;
- }
- else
- {
- dw = appWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(mat);
- dw.Document = document;
- dw.fileText = stepName + "-" + Startup.instance.step_length;
- dw.OpenInScriptRunning = (oneWorkSpace != null);
- dw.rules = appWorkspace.ActiveDocumentWorkspace.rules;
- dw.xmlSaveModel = appWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- this.appWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- }
- else if (param.OpenImage.Equals("addPhase"))
- {
- OpenCvSharp.Mat mat = param.PerformProcess(imageMat.Clone());
- List<PhaseModel> list = new List<PhaseModel>();
- PhaseModel model = new PhaseModel();
- model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text");
- model.choise = true;
- model.mat = mat;
- foreach (Args args in param.lists)
- {
- if (args.Key.Equals("phaseColor"))
- {
- model.color = (int)args.Value;
- break;
- }
- }
- list.Add(model);
- DocumentWorkspace dw;
- if (!createNewImage)
- {
- dw = appWorkspace.ActiveDocumentWorkspace;
- }
- else {
- dw = appWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(imageMat.Clone());
- dw.Document = document;
- dw.fileText = stepName + "-" + Startup.instance.step_length;
- dw.OpenInScriptRunning = (oneWorkSpace != null);
- dw.rules = appWorkspace.ActiveDocumentWorkspace.rules;
- dw.xmlSaveModel = appWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- this.appWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- dw.PhaseModels = list;
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- else if (param.OpenImage.Equals("currentPhase"))
- {
- //如果有选中的相
- List<PhaseModel> phases;
- if (oneWorkSpace == null)
- phases = appWorkspace.ActiveDocumentWorkspace.PhaseModels.FindAll(a => a.choise == true && a.mat != null);
- else
- phases = oneWorkSpace.PhaseModels.FindAll(a => a.choise == true && a.mat != null);
- if (phases.Count > 0)
- {
- //一些方法用到了微米换算
- double ruleValue = 0.0;
- Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);//获取
- List<PhaseModel> phasesCopy;
- if (oneWorkSpace == null)
- phasesCopy = appWorkspace.ActiveDocumentWorkspace.PhaseModelsForCopy;
- else
- phasesCopy = oneWorkSpace.PhaseModelsForCopy;
- for (int i = 0; i < phases.Count; i++)
- {
- if (phases[i].mat == null)
- continue;
- 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 = param.PerformProcess(model, ruleValue);
- }
- DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(imageMat.Clone());
- dw.Document = document;
- dw.fileText = stepName + "-" + Startup.instance.step_length;
- dw.xmlSaveModel = appWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- dw.PhaseModels = phasesCopy/*list*/;
- dw.OpenInScriptRunning = (oneWorkSpace != null);
- this.appWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- else
- {
- OpenCvSharp.Mat mat = param.PerformProcess(imageMat.Clone());
- if (mat != null)//###########
- {
- DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImageMat(mat);
- dw.Document = document;
- dw.fileText = stepName + "-" + Startup.instance.step_length;
- dw.OpenInScriptRunning = (oneWorkSpace != null);
- appWorkspace.ActiveDocumentWorkspace = dw;
- Startup.instance.step_length += 1;
- }
- }
- }
- }
- }
- }
|