using Metis.ParameterSet; using OpenCvSharp; using PaintDotNet.Base; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.Functionodel; using PaintDotNet.Base.SettingModel; using PaintDotNet.CustomControl; using PaintDotNet.Data.Param; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; using System.Windows.Forms; namespace PaintDotNet.Binarization { /// /// 二值提取 /// internal class BinaryExtractDialog : PdnBaseForm { #region 控件 private GroupBox groupBox1; private GroupBox groupBox2; private CheckBox checkBox1; private Button button2; private Button button1; private GroupBox groupBox3; private GroupBox groupBox4; private ListView listView1; private ImageList imageList1; private IContainer components; private GroupBox groupBox5; private GroupBox groupBox6; private GroupBox groupBox7; private Label label1; private ComboBox comboBox1; private Button button3; private Button button4; private Button button5; private CheckBox checkBox2; private CheckBox checkBox3; private CheckBox checkBox4; private NumericUpDown numericUpDown2; private NumericUpDown numericUpDown1; private RadioButton radioButton2; private RadioButton radioButton1; private Panel panel2; private Label label2; private Button button6; private Button button7; private CheckBox checkBox5; private CustomControl.DecimalScopeControl numberScopeControl3; private CustomControl.DecimalScopeControl numberScopeControl2; private CustomControl.DecimalScopeControl numberScopeControl1; private RadioButton radioButton5; private RadioButton radioButton4; private RadioButton radioButton3; private CustomControl.HistogramControl histogramControl1; private Button button8; private Button button9; private Button button10; #endregion /// /// 主控件 /// private AppWorkspace appWorkspace; /// /// 公共按钮 /// private CommonControlButtons commonControlButtons; /// /// 图像面板 /// private DocumentWorkspaceWindow documentWorkspace; /// /// 处理程序 /// private ParamObject action = new Data.Action.Action901(); /// /// 步长 初始值1,依次增加 /// private string stepLength = "00" + Startup.instance.step_length; /// /// 调色板 /// private ColorsForm colorsFormGrid; /// /// 选中图片的mat /// private Mat imageMat; /// /// 参数下拉的集合 /// private List files = new List(); /// /// 初始系统参数配置值 /// private BinaryExtractionModel binaryExtractionModel; /// /// 选中的左侧list的下标 /// private int index = 0; /// /// 单位标尺 /// private double unitLength = 1; /// /// 另存为弹出框显示 /// private CreateNameDialog dialog; private int menuId; private string menuName; /// /// 各个图片对应数据 /// private GrainSizeAnalysisModel analysisModel; private const string ParamKey_Paramlist = "paramlist";//参数列表 private const string ParamKey_NewPic = "newPic";//创建新图 public BinaryExtractDialog(AppWorkspace appWorkspace, string dialogText, PdnMenuItem menuItem) { this.menuId = menuItem.MenuId; this.menuName = menuItem.Text; string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryActionSaving\\ParameterSaving.xml"; GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open)); this.analysisModel = analysisModelXml.cloneListParamModel(this.menuId); foreach (var item in this.analysisModel.ListParam) item.setValue(); InitializeComponent(); InitializeLanguageText(); // // 设置Dialog属性 // this.appWorkspace = appWorkspace; this.Text = dialogText; this.Icon = PdnInfo.AppIcon; // // 初始化目标选择的背景图 // this.InitButtonBackgroundImage(); // //初始化色板 // this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; // //初始化图像控件 // 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); // //初始化相 // PhaseModel model = new PhaseModel(); model.choise = true; model.mat = null; model.color = panel2.BackColor.ToArgb(); model.position = this.documentWorkspace.PhaseModels.Count + 1; model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"); this.documentWorkspace.PhaseModels.Add(model); // // 设置listview事件 // this.listView1.SelectedIndexChanged += new EventHandler(this.ListViewSelectedIndexChanged); InitParameterList(); //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId); if (this.appWorkspace.ScriptRunning && this.appWorkspace.ScriptCurrentParam != null && this.appWorkspace.ScriptCurrentParam.MenuId == action.MenuId) { foreach (Args arg in action.Lists) { Args param1 = this.appWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key)); if (param1.value != null) arg.Value = param1.value; } foreach (Args args in action.Lists) { if (args.Key == "colorInterval") { this.binaryExtractionModel.ColorInterval = (Boolean)args.Value ? 2 : 1; } else if (args.Key == "scope1") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorOneStart = (int)twoL[0]; this.binaryExtractionModel.ColorOneEnd = (int)twoL[1]; } else if (args.Key == "scope2") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorTwoStart = (int)twoL[0]; this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1]; } else if (args.Key == "scope3") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorThreeStart = (int)twoL[0]; this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1]; } else if (args.Key == "deleteBoundaryObject") { this.binaryExtractionModel.DeleteBoundaryObject = (bool)args.Value; } else if (args.Key == "holeFilling") { this.binaryExtractionModel.HoleFilling = (bool)args.Value; } else if (args.Key == "debrisRemoval") { this.binaryExtractionModel.DebrisRemoval = (bool)args.Value; } else if (args.Key == "scope4") { this.binaryExtractionModel.DebrisAreaStart = (int)((List)args.Value)[0]; this.binaryExtractionModel.DebrisAreaEnd = (int)((List)args.Value)[1]; } else if (args.Key == "binaryStyle") { this.binaryExtractionModel.BinaryStyle = (int)args.Value; } else if (args.Key == "phaseColor") { this.binaryExtractionModel.PhaseColor = (int)args.Value; } else if (args.Key == "targetSelection") { this.binaryExtractionModel.TargetSelection = (int)args.Value - 1; } else if (args.Key == "createNewImg") { checkBox1.Checked = (int)args.Value == 0 ? true : false; } } this.appWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数 } InitPicList(); InitHistogramDragEvent(); InitCommonButtonEvent(); this.Shown += new EventHandler(this.ShownChoiseItemAndInitData); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing); } private void formClosing(object sender, EventArgs e) { #region [开启脚本录制] if (appWorkspace.startScriptRecording) { getScriptRecording(); } #endregion } private void ShownChoiseItemAndInitData(object sender, EventArgs e) { //滚动到指定的行位置 this.listView1.EnsureVisible(index); // 初始化数据 this.imageMat = this.appWorkspace.DocumentWorkspaces[index].CompositionSurface.CreatedAliasedMat(); Document document = Document.FromImageMat(imageMat.Clone()); this.documentWorkspace.Document = document; this.documentWorkspace.Visible = true; this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[index].GraphicsList; //this.applyButtonImpl(null, null); //显示直方图 this.histogramControl1.CreateHistogram(this.imageMat, true, 339, 130, 0); GetListParamModel(); InitParameterToControl(); } private void InitButtonBackgroundImage() { this.button8.FlatStyle = FlatStyle.Flat; this.button8.FlatAppearance.BorderSize = 0; this.button8.BackgroundImageLayout = ImageLayout.Zoom; this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference; this.button8.Click += new EventHandler(this.button8_click); this.button9.FlatStyle = FlatStyle.Flat; this.button9.FlatAppearance.BorderSize = 0; this.button9.BackgroundImageLayout = ImageLayout.Zoom; this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference; this.button9.Click += new EventHandler(this.button9_click); this.button10.FlatStyle = FlatStyle.Flat; this.button10.FlatAppearance.BorderSize = 0; this.button10.BackgroundImageLayout = ImageLayout.Zoom; this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference; this.button10.Click += new EventHandler(this.button10_click); } private void button8_click(object sender, EventArgs e) { this.binaryExtractionModel.TargetSelection = 1; this.radioButton3.Checked = true; this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle1.png").Reference; this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference; this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference; } private void button9_click(object sender, EventArgs e) { this.binaryExtractionModel.TargetSelection = 2; this.radioButton4.Checked = true; this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle2.png").Reference; this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference; this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray3.png").Reference; } private void button10_click(object sender, EventArgs e) { this.binaryExtractionModel.TargetSelection = 3; this.radioButton5.Checked = true; this.button10.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyle3.png").Reference; this.button8.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray1.png").Reference; this.button9.BackgroundImage = PdnResources.GetImageResource("Images.BinaryExtractChoiseStyleGray2.png").Reference; } 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) { if (this.imageMat != null) this.documentWorkspace.ZoomIn(); } private void zoomOutButton_Click(object sender, EventArgs e) { if (this.imageMat != null) 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 InitHistogramDragEvent() { this.histogramControl1.DragOneEventActionFinish += new EventHandler>(this.DragOneEvent); this.histogramControl1.DragTwoEventActionFinish += new EventHandler>(this.DragTwoEvent); this.histogramControl1.DragThreeEventActionFinish += new EventHandler>(this.DragThreeEvent); this.histogramControl1.DragFourEventActionFinish += new EventHandler>(this.DragFourEvent); this.histogramControl1.DragFiveEventActionFinish += new EventHandler>(this.DragFiveEvent); this.histogramControl1.DragSixEventActionFinish += new EventHandler>(this.DragSixEvent); } /// /// 颜色区间2 截止值变化 /// /// /// private void DragFourEvent(object sender, EventArgs e) { this.numberScopeControl2.maxValue = e.Data; this.SetArgsValue(); } /// /// 颜色区间2 起始值变化 /// /// /// private void DragThreeEvent(object sender, EventArgs e) { this.numberScopeControl2.minValue = e.Data; this.SetArgsValue(); } /// /// 颜色区间1 截止值变化 /// /// /// private void DragTwoEvent(object sender, EventArgs e) { if (this.binaryExtractionModel.ColorInterval == 1) { this.numberScopeControl1.maxValue = e.Data; } else if (this.binaryExtractionModel.ColorInterval == 2) { this.numberScopeControl3.maxValue = e.Data; } this.SetArgsValue(); } /// /// 颜色区间1 起始值变化 /// /// /// private void DragOneEvent(object sender, EventArgs e) { if (this.binaryExtractionModel.ColorInterval == 1) { this.numberScopeControl1.minValue = e.Data; } else if (this.binaryExtractionModel.ColorInterval == 2) { this.numberScopeControl3.minValue = e.Data; } this.SetArgsValue(); } private void DragFiveEvent(object sender, EventArgs e) { this.DeleteEventHandler(); if (this.binaryExtractionModel.ColorInterval == 1) { this.numberScopeControl1.minValue = e.Data[1]; this.numberScopeControl1.maxValue = e.Data[0]; } else if (this.binaryExtractionModel.ColorInterval == 2) { this.numberScopeControl3.minValue = e.Data[1]; this.numberScopeControl3.maxValue = e.Data[0]; } this.AddEventHandler(); this.SetArgsValue(); this.applyButtonImpl(null, null); } private void DragSixEvent(object sender, EventArgs e) { this.DeleteEventHandler(); /*if (this.binaryExtractionModel.ColorInterval == 1) {*/ this.numberScopeControl2.minValue = e.Data[1]; this.numberScopeControl2.maxValue = e.Data[0]; /*} else if (this.binaryExtractionModel.ColorInterval == 2) { this.numberScopeControl3.minValue = e.Data[1]; this.numberScopeControl3.maxValue = e.Data[0]; }*/ this.AddEventHandler(); this.SetArgsValue(); this.applyButtonImpl(null, null); } /// /// 初始化参数配置下拉 /// public void InitParameterList(int index = 0, bool reInit = true) { List fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\"); files.Clear(); foreach (string fileName in fileNames) { string name = fileName.Substring(0, fileName.LastIndexOf(".")); files.Add(name); } this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged; this.comboBox1.DataSource = null; this.comboBox1.DataSource = files; string nowModelName = Startup.instance.configModel.BinaryParameter.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf(".")); if (index != 0) { if (this.files.Count > index) { this.comboBox1.SelectedIndex = index; } else { this.comboBox1.SelectedIndex = 0; } } else { this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName)); } if (reInit) { this.binaryExtractionModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open)); } this.panel2.BackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor); this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { this.binaryExtractionModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open)); this.InitParameterToControl(); this.applyButtonImpl(null, null); } /// /// 把参数的值设置到控件上 /// public void InitParameterToControl() { if (this.binaryExtractionModel != null) { //阈值相关 //1个颜色区间还是2个 if (this.binaryExtractionModel.ColorInterval == 1) { this.numberScopeControl2.Visible = false; this.numberScopeControl3.Visible = false; this.button6.Text = PdnResources.GetString("Menu.inverse.text"); } else { this.numberScopeControl2.Visible = true; this.numberScopeControl3.Visible = true; this.button6.Text = PdnResources.GetString("Menu.Uncheck.text"); } //删除事件 this.DeleteEventHandler(); this.numberScopeControl1.maxValue = this.binaryExtractionModel.ColorOneEnd; this.numberScopeControl1.minValue = this.binaryExtractionModel.ColorOneStart; this.numberScopeControl2.maxValue = this.binaryExtractionModel.ColorTwoEnd; this.numberScopeControl2.minValue = this.binaryExtractionModel.ColorTwoStart; this.numberScopeControl3.maxValue = this.binaryExtractionModel.ColorThreeEnd; this.numberScopeControl3.minValue = this.binaryExtractionModel.ColorThreeStart; this.checkBox2.Checked = this.binaryExtractionModel.DeleteBoundaryObject; this.checkBox3.Checked = this.binaryExtractionModel.HoleFilling; this.checkBox4.Checked = this.binaryExtractionModel.DebrisRemoval; this.numericUpDown1.Value = this.binaryExtractionModel.DebrisAreaStart; this.numericUpDown2.Value = this.binaryExtractionModel.DebrisAreaEnd; if (this.binaryExtractionModel.BinaryStyle == 1) this.radioButton1.Checked = true; if (this.binaryExtractionModel.BinaryStyle == 2) this.radioButton2.Checked = true; this.panel2.BackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor); if (this.binaryExtractionModel.TargetSelection == 1) { this.button8_click(null, null); } if (this.binaryExtractionModel.TargetSelection == 2) { this.button9_click(null, null); } if (this.binaryExtractionModel.TargetSelection == 3) { this.button10_click(null, null); } this.SetArgsValue(); foreach (Args args in action.Lists) { if (args.Key == "targetSelection") { args.Value = this.binaryExtractionModel.TargetSelection; } else if (args.Key == "phaseColor") { args.Value = this.binaryExtractionModel.PhaseColor; } else if (args.Key == "binaryStyle") { args.Value = this.binaryExtractionModel.BinaryStyle; } } //添加事件 this.AddEventHandler(); //处理直方图 if (this.binaryExtractionModel.ColorInterval == 1) { this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue)); } else { this.histogramControl1.UpdateVerticalBarWithTwoScope( (int)(this.numberScopeControl3.minValue), (int)(this.numberScopeControl3.maxValue), (int)(this.numberScopeControl2.minValue), (int)(this.numberScopeControl2.maxValue) ); } } } /// /// 删除事件 /// private void DeleteEventHandler() { this.numberScopeControl1.ValueChanged -= this.numberScope1_ValueChanged; this.numberScopeControl1.numericUpDown1.KeyUp -= this.numberScope1_ValueChanged; this.numberScopeControl1.numericUpDown2.KeyUp -= this.numberScope1_ValueChanged; this.numberScopeControl3.numericUpDown2.KeyUp -= this.applyButtonImpl; this.numberScopeControl2.ValueChanged -= this.numberScope2_ValueChanged; this.numberScopeControl2.numericUpDown1.KeyUp -= this.numberScope2_ValueChanged; this.numberScopeControl2.numericUpDown2.KeyUp -= this.numberScope2_ValueChanged; this.numberScopeControl3.ValueChanged -= this.numberScope3_ValueChanged; this.numberScopeControl3.numericUpDown1.KeyUp -= this.numberScope3_ValueChanged; this.numberScopeControl3.numericUpDown2.KeyUp -= this.numberScope3_ValueChanged; //this.numberScopeControl1.ValueChanged -= this.applyButtonImpl; //this.numberScopeControl2.ValueChanged -= this.applyButtonImpl; //this.numberScopeControl3.ValueChanged -= this.applyButtonImpl; this.radioButton1.CheckedChanged -= this.radioButton1Or2_ValueChanged; this.radioButton2.CheckedChanged -= this.radioButton1Or2_ValueChanged; this.checkBox2.CheckedChanged -= this.applyButtonImpl; this.panel2.BackColorChanged -= this.applyButtonImpl; this.checkBox3.CheckedChanged -= this.applyButtonImpl; this.checkBox4.CheckedChanged -= this.applyButtonImpl; this.numericUpDown1.KeyUp -= this.Detritus_ValueChanged; this.numericUpDown1.ValueChanged -= new System.EventHandler(this.Detritus_ValueChanged); this.numericUpDown2.KeyUp -= this.Detritus_ValueChanged; this.numericUpDown2.ValueChanged -= new System.EventHandler(this.Detritus_ValueChanged); this.radioButton5.CheckedChanged -= this.radioButton5_CheckedChanged; this.radioButton4.CheckedChanged -= this.radioButton5_CheckedChanged; this.radioButton3.CheckedChanged -= this.radioButton5_CheckedChanged; } /// /// 添加事件 /// private void AddEventHandler() { this.numberScopeControl1.ValueChanged += this.numberScope1_ValueChanged; this.numberScopeControl1.numericUpDown1.KeyUp += this.numberScope1_ValueChanged; this.numberScopeControl1.numericUpDown2.KeyUp += this.numberScope1_ValueChanged; this.numberScopeControl3.numericUpDown2.KeyUp += this.applyButtonImpl; this.numberScopeControl2.ValueChanged += this.numberScope2_ValueChanged; this.numberScopeControl2.numericUpDown1.KeyUp += this.numberScope2_ValueChanged; this.numberScopeControl2.numericUpDown2.KeyUp += this.numberScope2_ValueChanged; this.numberScopeControl3.ValueChanged += this.numberScope3_ValueChanged; this.numberScopeControl3.numericUpDown1.KeyUp += this.numberScope3_ValueChanged; this.numberScopeControl3.numericUpDown2.KeyUp += this.numberScope3_ValueChanged; //this.numberScopeControl1.ValueChanged += this.applyButtonImpl; //this.numberScopeControl2.ValueChanged += this.applyButtonImpl; //this.numberScopeControl3.ValueChanged += this.applyButtonImpl; this.radioButton1.CheckedChanged += this.radioButton1Or2_ValueChanged; this.radioButton2.CheckedChanged += this.radioButton1Or2_ValueChanged; this.checkBox2.CheckedChanged += this.applyButtonImpl; this.panel2.BackColorChanged += this.applyButtonImpl; this.checkBox3.CheckedChanged += this.applyButtonImpl; this.checkBox4.CheckedChanged += this.applyButtonImpl; this.numericUpDown1.KeyUp += this.Detritus_ValueChanged; this.numericUpDown1.ValueChanged += new System.EventHandler(this.Detritus_ValueChanged); this.numericUpDown2.KeyUp += this.Detritus_ValueChanged; this.numericUpDown2.ValueChanged += new System.EventHandler(this.Detritus_ValueChanged); this.radioButton5.CheckedChanged += this.radioButton5_CheckedChanged; this.radioButton4.CheckedChanged += this.radioButton5_CheckedChanged; this.radioButton3.CheckedChanged += this.radioButton5_CheckedChanged; } /// /// 初始化图片列表数据 /// public void InitPicList() { //初始化图片列表 for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++) { this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.Thumbnail);//.CreateAliasedBitmap() this.listView1.Items.Add("", i); this.listView1.Items[i].ImageIndex = i; this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName(); if (this.appWorkspace.DocumentWorkspaces[i].Equals(this.appWorkspace.ActiveDocumentWorkspace)) { index = i; } } // // 初始化选中的数据 // this.listView1.Items[index].Selected = true; //选中行 } /// /// ListView图片选择改变事件 /// /// /// private void ListViewSelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0) { //获取标尺-微米 unitLength = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].GetRuler(MeasurementUnit.Micron); this.appWorkspace.ActiveDocumentWorkspace = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index]; this.imageMat = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].CompositionSurface.CreatedAliasedMat(); Document document = Document.FromImageMat(imageMat.Clone()); this.documentWorkspace.Document = document; this.documentWorkspace.Visible = true; this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].GraphicsList; if (this.checkBox4.Checked) { //参数改变 foreach (Args args in action.Lists) { if (args.Key == "scope4") { ((List)args.Value)[0] = (double)numericUpDown1.Value / unitLength / unitLength; ((List)args.Value)[1] = (double)numericUpDown2.Value / unitLength / unitLength; break; } } this.binaryExtractionModel.DebrisAreaStart = (int)((double)numericUpDown1.Value / unitLength / unitLength); this.binaryExtractionModel.DebrisAreaEnd = (int)((double)numericUpDown2.Value / unitLength / unitLength); } this.applyButtonImpl(sender, e); //显示直方图 this.histogramControl1.CreateHistogram(this.imageMat, true, 339, 130, 0); } } /// /// 添加参数改变的监听 /// /// /// private void BinaryExtractionDialog_Load(object sender, EventArgs e) { System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; foreach (Args args in action.Lists) { switch (args.Key) { case "phaseColor": args.Value = this.binaryExtractionModel.PhaseColor; break; default: break; } } this.applyButtonImpl(null, null); } #region 参数事件 #region 阈值相关 /// /// 反选/取消反选 /// /// /// private void button6_Click(object sender, EventArgs e) { this.DeleteEventHandler(); if (numberScopeControl2.Visible) { this.numberScopeControl1.minValue = this.numberScopeControl3.maxValue; this.numberScopeControl1.maxValue = this.numberScopeControl2.minValue; this.numberScopeControl2.Visible = false; this.numberScopeControl3.Visible = false; this.button6.Text = PdnResources.GetString("Menu.inverse.text"); this.binaryExtractionModel.ColorInterval = 1; this.histogramControl1.Flag = 1; //处理直方图 this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue)); } else { this.numberScopeControl3.minValue = 0; this.numberScopeControl3.maxValue = this.numberScopeControl1.minValue; this.numberScopeControl2.minValue = this.numberScopeControl1.maxValue; this.numberScopeControl2.maxValue = 255; this.numberScopeControl2.Visible = true; this.numberScopeControl3.Visible = true; this.button6.Text = PdnResources.GetString("Menu.Uncheck.text"); this.binaryExtractionModel.ColorInterval = 2; this.histogramControl1.Flag = 2; //处理直方图 this.histogramControl1.UpdateVerticalBarWithTwoScope( (int)(this.numberScopeControl3.minValue), (int)(this.numberScopeControl3.maxValue), (int)(this.numberScopeControl2.minValue), (int)(this.numberScopeControl2.maxValue) ); } this.AddEventHandler(); this.SetArgsValue(); this.applyButtonImpl(null, null); } /// /// 一个颜色区间时 /// 区间值变化的事件 /// /// /// private void numberScope1_ValueChanged(object sender, EventArgs e) { this.SetArgsValue(); this.binaryExtractionModel.ColorOneStart = (int)(this.numberScopeControl1.numericUpDown1.Value); this.binaryExtractionModel.ColorOneEnd = (int)(this.numberScopeControl1.numericUpDown2.Value); //处理直方图 this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue)); this.applyButtonImpl(null, null); } /// /// 二个颜色区间时 /// 区间1值变化的事件 /// /// /// private void numberScope2_ValueChanged(object sender, EventArgs e) { this.SetArgsValue(); this.binaryExtractionModel.ColorTwoStart = (int)(this.numberScopeControl2.minValue); this.binaryExtractionModel.ColorTwoEnd = (int)(this.numberScopeControl2.maxValue); //处理直方图 this.histogramControl1.UpdateVerticalBarWithTwoScope( (int)(this.numberScopeControl3.minValue), (int)(this.numberScopeControl3.maxValue), (int)(this.numberScopeControl2.minValue), (int)(this.numberScopeControl2.maxValue) ); this.applyButtonImpl(null, null); } /// /// 二个颜色区间时 /// 区间2值变化的事件 /// /// /// private void numberScope3_ValueChanged(object sender, EventArgs e) { this.SetArgsValue(); this.binaryExtractionModel.ColorThreeStart = (int)(this.numberScopeControl3.minValue); this.binaryExtractionModel.ColorThreeEnd = (int)(this.numberScopeControl3.maxValue); //处理直方图 this.histogramControl1.UpdateVerticalBarWithTwoScope( (int)(this.numberScopeControl3.minValue), (int)(this.numberScopeControl3.maxValue), (int)(this.numberScopeControl2.minValue), (int)(this.numberScopeControl2.maxValue) ); this.applyButtonImpl(null, null); } /// /// 自动阈值 /// /// /// private void button7_Click(object sender, EventArgs e) { this.DeleteEventHandler(); if (imageMat != null) { //先计算阈值 Mat mat = imageMat.Clone();// PaintDotNet.Camera.Tools.ToMat(bitmap); Mat gray = mat.CvtColor(ColorConversionCodes.BGR2GRAY); double otsu = Cv2.Threshold(gray, gray, 0, 255, ThresholdTypes.Triangle); if (otsu <= 10 || otsu >= 245) { otsu = Cv2.Threshold(mat.CvtColor(ColorConversionCodes.BGR2GRAY), gray, 0, 255, ThresholdTypes.Otsu);//.Triangle } { //隐藏控件 this.numberScopeControl1.minValue = this.numberScopeControl3.maxValue; this.numberScopeControl1.maxValue = this.numberScopeControl2.minValue; this.numberScopeControl2.Visible = false; this.numberScopeControl3.Visible = false; this.button6.Text = PdnResources.GetString("Menu.inverse.text"); this.binaryExtractionModel.ColorInterval = 1; this.histogramControl1.Flag = 1; //给控件赋值 this.numberScopeControl1.minValue = 0; this.numberScopeControl1.maxValue = otsu; this.binaryExtractionModel.ColorOneStart = Convert.ToInt32(this.numberScopeControl1.minValue); this.binaryExtractionModel.ColorOneEnd = Convert.ToInt32(otsu); this.SetArgsValue(); } //处理直方图 this.histogramControl1.UpdateVerticalBarWithOneScope(0, Convert.ToInt32(this.numberScopeControl1.maxValue)); mat.Dispose(); GC.Collect(); this.applyButtonImpl(sender, e); } else { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicturefirst.text")); } this.AddEventHandler(); } #endregion #region 处理细节 /// /// 删除边界对象 /// /// /// private void checkBox2_CheckedChanged(object sender, EventArgs e) { //参数改变 foreach (Args args in action.Lists) { if (args.Key == "deleteBoundaryObject") { args.Value = this.checkBox2.Checked; break; } } this.binaryExtractionModel.DeleteBoundaryObject = this.checkBox2.Checked; } /// /// 孔洞填充 /// /// /// private void checkBox3_CheckedChanged(object sender, EventArgs e) { //参数改变 foreach (Args args in action.Lists) { if (args.Key == "holeFilling") { args.Value = this.checkBox3.Checked; break; } } this.binaryExtractionModel.HoleFilling = this.checkBox3.Checked; } /// /// 碎屑删除 /// /// /// private void checkBox4_CheckedChanged(object sender, EventArgs e) { //参数改变 foreach (Args args in action.Lists) { if (args.Key == "debrisRemoval") { args.Value = this.checkBox4.Checked; break; } } this.binaryExtractionModel.DebrisRemoval = this.checkBox4.Checked; } /// /// 碎屑面积变化 /// /// /// private void Detritus_ValueChanged(object sender, EventArgs e) { if (this.checkBox4.Checked) { DeleteEventHandler(); if (((NumericUpDown)sender).Name.Equals("numericUpDown1")) numericUpDown2.Value = Math.Max(numericUpDown2.Value, numericUpDown1.Value); else if (((NumericUpDown)sender).Name.Equals("numericUpDown2")) numericUpDown1.Value = Math.Min(numericUpDown1.Value, numericUpDown2.Value); foreach (Args args in action.Lists) { if (args.Key == "scope4") { ((List)args.Value)[0] = (double)numericUpDown1.Value / unitLength / unitLength; ((List)args.Value)[1] = (double)numericUpDown2.Value / unitLength / unitLength; break; } } this.binaryExtractionModel.DebrisAreaStart = (int)((double)numericUpDown1.Value / unitLength / unitLength); this.binaryExtractionModel.DebrisAreaEnd = (int)((double)numericUpDown2.Value / unitLength / unitLength); this.applyButtonImpl(null, null); AddEventHandler(); } } #endregion #region 二值样式 /// /// 实心和边线 /// /// /// private void radioButton1Or2_ValueChanged(object sender, EventArgs e) { if (((RadioButton)sender).Checked) { //参数改变 foreach (Args args in action.Lists) { if (args.Key == "binaryStyle") { if (radioButton1.Checked) { args.Value = 1; } else { args.Value = 2; } break; } } this.binaryExtractionModel.BinaryStyle = radioButton1.Checked ? 1 : 2; this.applyButtonImpl(sender, e); } } /// /// 相颜色点击事件 /// /// /// private void panel2_Click(object sender, EventArgs e) { this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor); this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); this.colorsFormGrid.ShowDialog(); } /// /// Panel2的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { Color color = this.colorsFormGrid.UserPrimaryColor.ToColor(); //先修改参数 foreach (Args args in action.Lists) { if (args.Key == "phaseColor") { args.Value = color.ToArgb(); break; } } //更改背景色,触发事件 this.panel2.BackColor = color; //改变配置文件里面的相颜色 this.binaryExtractionModel.PhaseColor = color.ToArgb(); //关闭色板 this.colorsFormGrid.Close(); } #endregion #region 目标选择 /// /// 目标选择 /// /// /// private void radioButton5_CheckedChanged(object sender, EventArgs e) { //参数改变 foreach (Args args in action.Lists) { if (args.Key == "targetSelection") { if (radioButton3.Checked) { args.Value = 1; this.binaryExtractionModel.TargetSelection = 1; } else if (radioButton4.Checked) { args.Value = 2; this.binaryExtractionModel.TargetSelection = 2; } else { args.Value = 3; this.binaryExtractionModel.TargetSelection = 3; } break; } } if (((RadioButton)sender).Checked) { this.applyButtonImpl(null, null); } } #endregion #endregion /// /// 生成新图 /// /// private void OpenFileImpl() { if (imageMat != null) { DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace(); Document document = Document.FromImageMat(imageMat.Clone()); dw.Document = document; dw.fileText = this.Text + "-" + stepLength; dw.rules = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].rules; dw.xmlSaveModel = this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].xmlSaveModel; this.appWorkspace.ActiveDocumentWorkspace = dw; this.appWorkspace.ActiveDocumentWorkspace.PhaseModels = this.documentWorkspace.PhaseModelsForCopy; this.appWorkspace.ActiveDocumentWorkspace.Refresh(); Startup.instance.step_length += 1; stepLength = "00" + Startup.instance.step_length; } } /// /// 应用到全部 /// /// /// private void button2_Click(object sender, EventArgs e) { ProgressThreadProcClass procClass = new ProgressThreadProcClass(); int itemCount = 100; ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents(); System.Threading.ThreadStart copyThreadProc = delegate () { try { int num = this.appWorkspace.DocumentWorkspaces.Length; for (int i = 0; i < num; i++) { List list = new List(); PhaseModel model = new PhaseModel(); model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"); model.choise = true; if (this.appWorkspace.DocumentWorkspaces[i].GraphicsList.IsExsitView()) { model.mat = action.PerformProcess( PaintDotNet.Camera.Tools.ToMat(this.appWorkspace.DocumentWorkspaces[i].GetFullSizeWithRegion()), this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreatedAliasedMat().Clone(), true); model.color = this.panel2.BackColor.ToArgb(); } else { model.mat = action.PerformProcess(this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreatedAliasedMat().Clone(), true); model.color = this.panel2.BackColor.ToArgb(); } list.Add(model); this.Invoke(new EventHandler(delegate { if (checkBox1.Checked) { DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();//return mat/*.Clone()*/;//待测试 Document document = Document.FromImageMat(this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreatedAliasedMat().Clone()); dw.Document = document; dw.rules = this.appWorkspace.DocumentWorkspaces[i].rules; dw.xmlSaveModel = this.appWorkspace.DocumentWorkspaces[i].xmlSaveModel; dw.fileText = this.Text + "-" + stepLength; dw.PhaseModels = list; this.appWorkspace.ActiveDocumentWorkspace = dw; this.appWorkspace.ActiveDocumentWorkspace.Refresh(); Startup.instance.step_length += 1; stepLength = "00" + Startup.instance.step_length; } else { this.appWorkspace.DocumentWorkspaces[i].PhaseModels = list; this.appWorkspace.ActiveDocumentWorkspace.Refresh(); } })); } this.Invoke(new EventHandler(delegate { this.Close(); })); } catch (Exception) { } finally { progressEvents.EndOperation(OperationResult.Finished); } }; procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null); } /// /// 显示原图/原图+二值图 /// /// /// private void ShowOrHideOriginPic(object sender, EventArgs e) { if (!checkBox5.Checked) { this.documentWorkspace.PhaseModels[0].choise = true; } else { this.documentWorkspace.PhaseModels[0].choise = false; } this.documentWorkspace.Refresh(); } /// /// 参数改变时,重新处理图像 /// /// /// 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 { long start = Cv2.GetTickCount(); if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0) { //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理 if (this.documentWorkspace.GraphicsList.IsExsitView()) { this.documentWorkspace.PhaseModels.Clear(); PhaseModel model = new PhaseModel(); model.choise = true; model.mat = action.PerformProcess( PaintDotNet.Camera.Tools.ToMat(this.documentWorkspace.GetFullSizeWithRegion()), this.imageMat.Clone(), true); model.color = this.panel2.BackColor.ToArgb(); model.position = this.documentWorkspace.PhaseModels.Count + 1; model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"); this.documentWorkspace.PhaseModels.Add(model); } else { this.documentWorkspace.PhaseModels.Clear(); PhaseModel model = new PhaseModel(); model.choise = true; model.mat = action.PerformProcess(this.imageMat.Clone(), true); model.color = this.panel2.BackColor.ToArgb(); model.position = this.documentWorkspace.PhaseModels.Count + 1; model.name = PdnResources.GetString("Menu.BinaryAction.BinaryExtraction.Text"); this.documentWorkspace.PhaseModels.Add(model); } ShowOrHideOriginPic(null, null); } double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency(); System.Console.WriteLine(PdnResources.GetString("Menu.executiontime.Text") + ":" + time); } catch (Exception) { } finally { progressEvents.EndOperation(OperationResult.Finished); } }; procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, this.Text);//#21198 } /// /// 应用 /// /// /// private void applyButton_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0) { if (checkBox1.Checked) { this.OpenFileImpl(); } else { if (this.documentWorkspace.PhaseModels.Count > 0) { List models = new List(); foreach (PhaseModel temp in this.documentWorkspace.PhaseModels) { if (temp.mat == null) { return; } PhaseModel model = new PhaseModel(); model.choise = temp.choise; model.color = temp.color; model.mat = temp.mat.Clone(); model.name = temp.name; model.position = temp.position; models.Add(model); } this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].PhaseModels = models; this.appWorkspace.DocumentWorkspaces[this.listView1.SelectedItems[0].Index].Refresh(); } } } this.Close(); } /// /// 删除按钮 /// /// /// private void button3_Click(object sender, EventArgs e) { if ("Default".Equals(this.comboBox1.Text)) { MessageBox.Show(PdnResources.GetString("Menu.Defaultparamscannotbedeleted.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodeleteparams.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (dr == DialogResult.OK) { //删除xml文件 string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.Text + ".xml"; FileInfo fileInfo = new FileInfo(filePath); fileInfo.Delete(); //初始化xml文件列表 InitParameterList(this.comboBox1.SelectedIndex); this.binaryExtractionModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open)); InitParameterToControl(); } } /// /// 保存参数 /// /// /// private void button5_Click(object sender, EventArgs e) { foreach (Args args in action.Lists) { if (args.Key == "colorInterval") { this.binaryExtractionModel.ColorInterval = int.Parse(args.Value.ToString()); } else if (args.Key == "scope1") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorOneStart = (int)twoL[0]; this.binaryExtractionModel.ColorOneEnd = (int)twoL[1]; } else if (args.Key == "scope3") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorTwoStart = (int)twoL[0]; this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1]; } else if (args.Key == "scope2") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorThreeStart = (int)twoL[0]; this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1]; } else if (args.Key == "deleteBoundaryObject") { this.binaryExtractionModel.DeleteBoundaryObject = (bool)args.Value; } else if (args.Key == "holeFilling") { this.binaryExtractionModel.HoleFilling = (bool)args.Value; } else if (args.Key == "debrisRemoval") { this.binaryExtractionModel.DebrisRemoval = (bool)args.Value; } else if (args.Key == "scope4") { this.binaryExtractionModel.DebrisAreaStart = (int)((List)args.Value)[0]; this.binaryExtractionModel.DebrisAreaEnd = (int)((List)args.Value)[1]; } else if (args.Key == "binaryStyle") { this.binaryExtractionModel.BinaryStyle = (int)args.Value; } else if (args.Key == "phaseColor") { this.binaryExtractionModel.PhaseColor = (int)args.Value; } else if (args.Key == "targetSelection") { this.binaryExtractionModel.TargetSelection = (int)args.Value; } } string stageModelXml = XmlSerializeHelper.XmlSerialize(this.binaryExtractionModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + this.comboBox1.Text + ".xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); } /// /// 另存为 /// /// /// private void button4_Click(object sender, EventArgs e) { dialog = new CreateNameDialog(this); dialog.Text = PdnResources.GetString("Menu.File.SaveAs.Text"); dialog.StartPosition = FormStartPosition.CenterParent; dialog.ShowDialog(); } /// /// 另存为弹窗 确定保存 /// /// public override void GetCreateName(string name) { string currentcomboBox = this.comboBox1.Text; if (files.Contains(name)) { MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } BinaryExtractionModel newModel = this.binaryExtractionModel; foreach (Args args in action.Lists) { if (args.Key == "colorInterval") { this.binaryExtractionModel.ColorInterval = int.Parse(args.Value.ToString()); } else if (args.Key == "scope1") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorOneStart = (int)twoL[0]; this.binaryExtractionModel.ColorOneEnd = (int)twoL[1]; } else if (args.Key == "scope3") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorTwoStart = (int)twoL[0]; this.binaryExtractionModel.ColorTwoEnd = (int)twoL[1]; } else if (args.Key == "scope2") { List twoL = (List)args.Value; this.binaryExtractionModel.ColorThreeStart = (int)twoL[0]; this.binaryExtractionModel.ColorThreeEnd = (int)twoL[1]; } else if (args.Key == "deleteBoundaryObject") { this.binaryExtractionModel.DeleteBoundaryObject = (bool)args.Value; } else if (args.Key == "holeFilling") { this.binaryExtractionModel.HoleFilling = (bool)args.Value; } else if (args.Key == "debrisRemoval") { this.binaryExtractionModel.DebrisRemoval = (bool)args.Value; } else if (args.Key == "scope4") { this.binaryExtractionModel.DebrisAreaStart = (int)((List)args.Value)[0]; this.binaryExtractionModel.DebrisAreaEnd = (int)((List)args.Value)[1]; } else if (args.Key == "binaryStyle") { this.binaryExtractionModel.BinaryStyle = (int)args.Value; } else if (args.Key == "phaseColor") { this.binaryExtractionModel.PhaseColor = (int)args.Value; } else if (args.Key == "targetSelection") { this.binaryExtractionModel.TargetSelection = (int)args.Value; } } //另存为 string stageModelXml = XmlSerializeHelper.XmlSerialize(newModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\" + name + ".xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); InitParameterList(0, false); this.comboBox1.Text = currentcomboBox; dialog.Close(); } public void SetArgsValue() { foreach (Args args in action.Lists) { if (args.Key == "colorInterval") { args.Value = this.binaryExtractionModel.ColorInterval; } else if (args.Key == "scope1") { List twoL = new List(); twoL.Add(this.numberScopeControl1.minValue); twoL.Add(this.numberScopeControl1.maxValue); args.Value = twoL; } else if (args.Key == "scope2") { List twoL = new List(); twoL.Add(this.numberScopeControl3.minValue); twoL.Add(this.numberScopeControl3.maxValue); args.Value = twoL; } else if (args.Key == "scope3") { List twoL = new List(); twoL.Add(this.numberScopeControl2.minValue); twoL.Add(this.numberScopeControl2.maxValue); args.Value = twoL; } } } private void InitializeLanguageText() { this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text"); this.groupBox2.Text = PdnResources.GetString("Menu.operation.text"); this.button5.Text = PdnResources.GetString("Menu.File.Save.Text"); this.button4.Text = PdnResources.GetString("Menu.File.SaveAs.Text"); this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.label1.Text = PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.paramslist.text") + ":"; this.checkBox1.Text = PdnResources.GetString("Menu.Createnewgraph.text"); this.button2.Text = PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Applytoall.text"); this.button1.Text = PdnResources.GetString("Menu.application.text"); this.groupBox3.Text = PdnResources.GetString("Menu.Tools.Histogram.Text"); this.checkBox5.Text = PdnResources.GetString("Menu.Theoriginalcolor.text"); this.button7.Text = PdnResources.GetString("Menu.Automaticthreshold.text"); this.button6.Text = PdnResources.GetString("Menu.inverse.text"); this.groupBox4.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text"); this.groupBox5.Text = PdnResources.GetString("Menu.Processingdetails.text"); this.checkBox4.Text = PdnResources.GetString("Menu.Clasticdelete.text"); this.checkBox3.Text = PdnResources.GetString("Menu.BinaryAction.HoleFilling.Text"); this.checkBox2.Text = PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Deleteboundaryobject.text"); this.groupBox6.Text = PdnResources.GetString("Menu.Binarystyle.text"); this.label2.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":"; this.radioButton2.Text = PdnResources.GetString("Menu.Sideline.text"); this.radioButton1.Text = PdnResources.GetString("Menu.solid.text"); this.groupBox7.Text = PdnResources.GetString("Menu.Targetselection.text"); this.radioButton5.Text = PdnResources.GetString("Menu.style.text") + "3"; this.radioButton4.Text = PdnResources.GetString("Menu.style.text") + "2"; this.radioButton3.Text = PdnResources.GetString("Menu.style.text") + "1"; } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.button5 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.histogramControl1 = new PaintDotNet.CustomControl.HistogramControl(); this.numberScopeControl3 = new PaintDotNet.CustomControl.DecimalScopeControl(); this.numberScopeControl2 = new PaintDotNet.CustomControl.DecimalScopeControl(); this.numberScopeControl1 = new PaintDotNet.CustomControl.DecimalScopeControl(); this.checkBox5 = new System.Windows.Forms.CheckBox(); this.button7 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.listView1 = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.label2 = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.groupBox7 = new System.Windows.Forms.GroupBox(); this.button10 = new System.Windows.Forms.Button(); this.button9 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.radioButton5 = new System.Windows.Forms.RadioButton(); this.radioButton4 = new System.Windows.Forms.RadioButton(); this.radioButton3 = new System.Windows.Forms.RadioButton(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBox6.SuspendLayout(); this.groupBox7.SuspendLayout(); this.SuspendLayout(); // // 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(532, 70); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(398, 447); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; this.groupBox1.Text = "预览"; // // groupBox2 // this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.button5); this.groupBox2.Controls.Add(this.button4); this.groupBox2.Controls.Add(this.button3); this.groupBox2.Controls.Add(this.comboBox1); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.checkBox1); this.groupBox2.Controls.Add(this.button2); this.groupBox2.Controls.Add(this.button1); this.groupBox2.Location = new System.Drawing.Point(13, 12); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(917, 52); this.groupBox2.TabIndex = 6; this.groupBox2.TabStop = false; this.groupBox2.Text = "操作"; // // button5 // this.button5.Location = new System.Drawing.Point(354, 21); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(75, 23); this.button5.TabIndex = 10; this.button5.Text = "保存"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // button4 // this.button4.Location = new System.Drawing.Point(272, 21); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 23); this.button4.TabIndex = 9; this.button4.Text = "另存为"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button3 // this.button3.Location = new System.Drawing.Point(190, 21); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 8; this.button3.Text = "删除"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // comboBox1 // this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(82, 22); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(101, 20); this.comboBox1.TabIndex = 7; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(7, 26); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); this.label1.TabIndex = 6; this.label1.Text = "参数列表:"; // // checkBox1 // this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.Right; this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(680, 24); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(72, 16); this.checkBox1.TabIndex = 5; this.checkBox1.Text = "创建新图"; this.checkBox1.UseVisualStyleBackColor = true; // // button2 // this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right; this.button2.Location = new System.Drawing.Point(757, 20); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 4; this.button2.Text = "应用到全部一个"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.Anchor = System.Windows.Forms.AnchorStyles.Right; this.button1.Location = new System.Drawing.Point(838, 20); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 3; this.button1.Text = "应用"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.applyButton_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.histogramControl1); this.groupBox3.Controls.Add(this.numberScopeControl3); this.groupBox3.Controls.Add(this.numberScopeControl2); this.groupBox3.Controls.Add(this.numberScopeControl1); this.groupBox3.Controls.Add(this.checkBox5); this.groupBox3.Controls.Add(this.button7); this.groupBox3.Controls.Add(this.button6); this.groupBox3.Location = new System.Drawing.Point(159, 70); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(367, 221); this.groupBox3.TabIndex = 7; this.groupBox3.TabStop = false; this.groupBox3.Text = "直方图"; // // histogramControl1 // this.histogramControl1.Flag = 1; this.histogramControl1.Location = new System.Drawing.Point(8, 22); this.histogramControl1.Name = "histogramControl1"; this.histogramControl1.Size = new System.Drawing.Size(340, 130); this.histogramControl1.TabIndex = 16; // // numberScopeControl3 // this.numberScopeControl3.DecimalPlaces = 0; this.numberScopeControl3.Location = new System.Drawing.Point(8, 158); this.numberScopeControl3.Maximum = 255D; this.numberScopeControl3.maxValue = 0D; this.numberScopeControl3.Minimum = 0D; this.numberScopeControl3.minValue = 0D; this.numberScopeControl3.Name = "numberScopeControl3"; this.numberScopeControl3.Size = new System.Drawing.Size(150, 22); this.numberScopeControl3.TabIndex = 15; this.numberScopeControl3.Visible = false; // // numberScopeControl2 // this.numberScopeControl2.DecimalPlaces = 0; this.numberScopeControl2.Location = new System.Drawing.Point(186, 158); this.numberScopeControl2.Maximum = 255D; this.numberScopeControl2.maxValue = 0D; this.numberScopeControl2.Minimum = 0D; this.numberScopeControl2.minValue = 0D; this.numberScopeControl2.Name = "numberScopeControl2"; this.numberScopeControl2.Size = new System.Drawing.Size(150, 22); this.numberScopeControl2.TabIndex = 14; this.numberScopeControl2.Visible = false; // // numberScopeControl1 // this.numberScopeControl1.DecimalPlaces = 0; this.numberScopeControl1.Location = new System.Drawing.Point(8, 158); this.numberScopeControl1.Maximum = 255D; this.numberScopeControl1.maxValue = 0D; this.numberScopeControl1.Minimum = 0D; this.numberScopeControl1.minValue = 0D; this.numberScopeControl1.Name = "numberScopeControl1"; this.numberScopeControl1.Size = new System.Drawing.Size(150, 22); this.numberScopeControl1.TabIndex = 13; this.numberScopeControl1.Tag = "numberScopeControl1"; // // checkBox5 // this.checkBox5.Anchor = System.Windows.Forms.AnchorStyles.Right; this.checkBox5.AutoSize = true; this.checkBox5.Location = new System.Drawing.Point(311, 196); this.checkBox5.Name = "checkBox5"; this.checkBox5.Size = new System.Drawing.Size(48, 16); this.checkBox5.TabIndex = 11; this.checkBox5.Text = "原图"; this.checkBox5.UseVisualStyleBackColor = true; this.checkBox5.CheckedChanged += new System.EventHandler(this.ShowOrHideOriginPic); // // button7 // this.button7.Anchor = System.Windows.Forms.AnchorStyles.Right; this.button7.Location = new System.Drawing.Point(197, 192); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(75, 23); this.button7.TabIndex = 12; this.button7.Text = "自动阈值"; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // button6 // this.button6.Anchor = System.Windows.Forms.AnchorStyles.Right; this.button6.Location = new System.Drawing.Point(19, 192); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(75, 23); this.button6.TabIndex = 11; this.button6.Text = "反选"; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // groupBox4 // this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.groupBox4.Controls.Add(this.listView1); this.groupBox4.Location = new System.Drawing.Point(13, 71); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(140, 446); this.groupBox4.TabIndex = 8; this.groupBox4.TabStop = false; this.groupBox4.Text = "图像索引"; // // 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(7, 21); this.listView1.Name = "listView1"; this.listView1.Size = new System.Drawing.Size(127, 419); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; // // 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; // // groupBox5 // this.groupBox5.Controls.Add(this.numericUpDown2); this.groupBox5.Controls.Add(this.numericUpDown1); this.groupBox5.Controls.Add(this.checkBox4); this.groupBox5.Controls.Add(this.checkBox3); this.groupBox5.Controls.Add(this.checkBox2); this.groupBox5.Location = new System.Drawing.Point(160, 298); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(366, 64); this.groupBox5.TabIndex = 9; this.groupBox5.TabStop = false; this.groupBox5.Text = "处理细节"; // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(317, 26); this.numericUpDown2.Maximum = new decimal(new int[] { 2147483647, 0, 0, 0}); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(40, 21); this.numericUpDown2.TabIndex = 6; // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(272, 26); this.numericUpDown1.Maximum = new decimal(new int[] { 2147483647, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(40, 21); this.numericUpDown1.TabIndex = 5; // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Location = new System.Drawing.Point(197, 29); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(72, 16); this.checkBox4.TabIndex = 2; this.checkBox4.Text = "碎屑删除"; this.checkBox4.UseVisualStyleBackColor = true; this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged); // // checkBox3 // this.checkBox3.AutoSize = true; this.checkBox3.Location = new System.Drawing.Point(117, 29); this.checkBox3.Name = "checkBox3"; this.checkBox3.Size = new System.Drawing.Size(72, 16); this.checkBox3.TabIndex = 1; this.checkBox3.Text = "孔洞填充"; this.checkBox3.UseVisualStyleBackColor = true; this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged); // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(7, 29); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(96, 16); this.checkBox2.TabIndex = 0; this.checkBox2.Text = "删除边界对象"; this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // // groupBox6 // this.groupBox6.Controls.Add(this.label2); this.groupBox6.Controls.Add(this.panel2); this.groupBox6.Controls.Add(this.radioButton2); this.groupBox6.Controls.Add(this.radioButton1); this.groupBox6.Location = new System.Drawing.Point(159, 369); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(367, 64); this.groupBox6.TabIndex = 10; this.groupBox6.TabStop = false; this.groupBox6.Text = "二值样式"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(105, 34); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(41, 12); this.label2.TabIndex = 20; this.label2.Text = "相颜色"; // // panel2 // this.panel2.BackColor = System.Drawing.Color.Blue; this.panel2.Location = new System.Drawing.Point(160, 29); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(72, 21); this.panel2.TabIndex = 19; this.panel2.Click += new System.EventHandler(this.panel2_Click); // // radioButton2 // this.radioButton2.AutoSize = true; this.radioButton2.Location = new System.Drawing.Point(56, 32); this.radioButton2.Name = "radioButton2"; this.radioButton2.Size = new System.Drawing.Size(47, 16); this.radioButton2.TabIndex = 1; this.radioButton2.Text = "边线"; this.radioButton2.UseVisualStyleBackColor = true; // // radioButton1 // this.radioButton1.AutoSize = true; this.radioButton1.Checked = true; this.radioButton1.Location = new System.Drawing.Point(7, 32); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(47, 16); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = "实心"; this.radioButton1.UseVisualStyleBackColor = true; // // groupBox7 // this.groupBox7.Controls.Add(this.button10); this.groupBox7.Controls.Add(this.button9); this.groupBox7.Controls.Add(this.button8); this.groupBox7.Controls.Add(this.radioButton5); this.groupBox7.Controls.Add(this.radioButton4); this.groupBox7.Controls.Add(this.radioButton3); this.groupBox7.Location = new System.Drawing.Point(159, 440); this.groupBox7.Name = "groupBox7"; this.groupBox7.Size = new System.Drawing.Size(367, 77); this.groupBox7.TabIndex = 11; this.groupBox7.TabStop = false; this.groupBox7.Text = "目标选择"; // // button10 // this.button10.Location = new System.Drawing.Point(106, 21); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(40, 40); this.button10.TabIndex = 5; this.button10.UseVisualStyleBackColor = true; // // button9 // this.button9.Location = new System.Drawing.Point(60, 21); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(40, 40); this.button9.TabIndex = 4; this.button9.UseVisualStyleBackColor = true; // // button8 // this.button8.Location = new System.Drawing.Point(14, 21); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(40, 40); this.button8.TabIndex = 3; this.button8.UseVisualStyleBackColor = true; // // radioButton5 // this.radioButton5.AutoSize = true; this.radioButton5.Location = new System.Drawing.Point(238, 55); this.radioButton5.Name = "radioButton5"; this.radioButton5.Size = new System.Drawing.Size(14, 13); this.radioButton5.TabIndex = 2; this.radioButton5.UseVisualStyleBackColor = true; this.radioButton5.Visible = false; // // radioButton4 // this.radioButton4.AutoSize = true; this.radioButton4.Checked = true; this.radioButton4.Location = new System.Drawing.Point(297, 44); this.radioButton4.Name = "radioButton4"; this.radioButton4.Size = new System.Drawing.Size(14, 13); this.radioButton4.TabIndex = 1; this.radioButton4.TabStop = true; this.radioButton4.UseVisualStyleBackColor = true; this.radioButton4.Visible = false; // // radioButton3 // this.radioButton3.AutoSize = true; this.radioButton3.Location = new System.Drawing.Point(279, 21); this.radioButton3.Name = "radioButton3"; this.radioButton3.Size = new System.Drawing.Size(14, 13); this.radioButton3.TabIndex = 0; this.radioButton3.UseVisualStyleBackColor = true; this.radioButton3.Visible = false; // // BinaryExtractDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(942, 529); this.Controls.Add(this.groupBox7); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "BinaryExtractDialog"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "二值提取"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.BinaryExtractDialog_FormClosing); this.Load += new System.EventHandler(this.BinaryExtractionDialog_Load); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.groupBox4, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.Controls.SetChildIndex(this.groupBox7, 0); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); this.groupBox7.ResumeLayout(false); this.groupBox7.PerformLayout(); this.ResumeLayout(false); } #region 参数保存及提取 /// /// 保存参数的key,value和type /// /// /// /// private void saveParamValue(string param_key, string param_value, int param_type) { bool foundItem = false; foreach (var item in this.analysisModel.ListParam) { if (item.param_key.Equals(param_key) && item.menuId == this.menuId) { item.param_value = param_value; item.setValue(); foundItem = true; break; } } if (!foundItem) { GrainSizeAnalysisModel analysisItem = new GrainSizeAnalysisModel(); analysisItem.menuId = this.menuId; analysisItem.param_key = param_key; analysisItem.param_type = param_type; analysisItem.param_value = param_value; analysisItem.setValue(); this.analysisModel.ListParam.Add(analysisItem); } } /// /// 保存界面中的参数到model /// private void saveDialogParamValues() { saveParamValue(ParamKey_Paramlist, comboBox1.Text, (int)Base.Dtryt.ItemString);//参数列表 saveParamValue(ParamKey_NewPic, checkBox1.Checked ? "0" : "1", (int)Base.Dtryt.Boolean);//是否创建新图 } /// /// 获取保存的参数 /// private void GetListParamModel() { if (this.analysisModel != null) { for (int i = 0; i < this.analysisModel.ListParam.Count; i++) { switch (this.analysisModel.ListParam[i].param_key) { case ParamKey_Paramlist: comboBox1.Text = (string)this.analysisModel.ListParam[i].value; //comboBox1_SelectedIndexChanged(null, null); break; case ParamKey_NewPic: checkBox1.Checked = (Boolean)this.analysisModel.ListParam[i].value; break; } } } } private void BinaryExtractDialog_FormClosing(object sender, FormClosingEventArgs e) { this.saveDialogParamValues(); //xml保存路径 string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryActionSaving\\ParameterSaving.xml"; GrainSizeAnalysisModel analysisModelXml = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, System.IO.FileMode.Open)); foreach (var analysisItem in this.analysisModel.ListParam) { bool foundItem = false; foreach (var item in analysisModelXml.ListParam) { if (item.param_key.Equals(analysisItem.param_key) && item.menuId == analysisItem.menuId) { item.param_value = analysisItem.param_value; foundItem = true; break; } } if (!foundItem) analysisModelXml.ListParam.Add(analysisItem.cloneModel()); } //按路径和名称保存xml文件 string userInfoXml = XmlSerializeHelper.XmlSerialize(analysisModelXml); //保存xml FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create); } #endregion #region [脚本录制] private void getScriptRecording() { List args = action.Lists; foreach (var item in args) { item.value = setScriptRecording(item.key); } appWorkspace.SetScriptStartRecording(this.menuId, menuName, args); } private object setScriptRecording(string key) { object value = null; if (key == "colorInterval") { value = this.binaryExtractionModel.ColorInterval == 2 ? true : false; } else if (key == "scope1") { value = new List() { this.binaryExtractionModel.ColorOneStart, this.binaryExtractionModel.ColorOneEnd }; } else if (key == "scope2") { value = new List() { this.binaryExtractionModel.ColorTwoStart, this.binaryExtractionModel.ColorTwoEnd }; } else if (key == "scope3") { value = new List() { this.binaryExtractionModel.ColorThreeStart, this.binaryExtractionModel.ColorThreeEnd }; } else if (key == "deleteBoundaryObject") { value = this.binaryExtractionModel.DeleteBoundaryObject; } else if (key == "holeFilling") { value = this.binaryExtractionModel.HoleFilling; } else if (key == "debrisRemoval") { value = this.binaryExtractionModel.DebrisRemoval; } else if (key == "scope4") { value = new List() { this.binaryExtractionModel.DebrisAreaStart, this.binaryExtractionModel.DebrisAreaEnd }; } else if (key == "binaryStyle") { value = this.binaryExtractionModel.BinaryStyle; } else if (key == "phaseColor") { value = this.binaryExtractionModel.PhaseColor; } else if (key == "targetSelection") { value = this.binaryExtractionModel.TargetSelection + 1; } else if (key == "createNewImg") { value = checkBox1.Checked ? 0 : 1; } return value; } #endregion } }