using PaintDotNet.Annotation.Enum; using PaintDotNet.Annotation.relationModel; using PaintDotNet.Base.SettingModel; using PaintDotNet.Base.CommTool; using PaintDotNet.ImageCollect; using PaintDotNet.Setting.LabelComponent; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Windows.Forms; using PaintDotNet.ImageCollect; using PaintDotNet.Camera; namespace PaintDotNet.Setting { /// /// 设置->相机设置 /// internal class CameraSettingDialog : FloatingToolForm { /// /// 标注一二级关系 /// private static List list = new List(); /// /// 当前选中的参数 /// private CameraParamType cameraParamType; /// /// 相机参数 /// public CameraParamModel m_cameraParamModel = Startup.instance.cameraParamModel; /// /// 主配置文件的model /// private ConfigModel configModel = Startup.instance.configModel; /// /// 操作样式下拉数据 /// private List files = new List(); /// /// 另存为弹出框显示 /// private CreateNameDialog dialog; /// /// 另存为文件名 /// private string newName; // private Bitmap bitmap; // private OpenCvSharp.Mat mat; // private OpenCvSharp.Mat oldMat; //各页面组件 /*private LabelTextControl textControl; private LabelMarkDateControl dateMarkControl; private LabelMarkTimeControl timeMarkControl;*/ private AdjustContainer adjustCameraControl; private FrameCameraControl frameCameraControl; private CommonCameraControl commonCameraControl; //private int width, height; /// /// 相机 /// //private MIChrome5Pro m5pro; /// /// 一个矩阵数组,用来接收直方图,记得全部初始化 /// OpenCvSharp.Mat[] oldHists = new OpenCvSharp.Mat[] { new OpenCvSharp.Mat(), new OpenCvSharp.Mat(), new OpenCvSharp.Mat() }; /// /// BGR线条颜色 /// private OpenCvSharp.Scalar[] color = new OpenCvSharp.Scalar[] { new OpenCvSharp.Scalar(255, 0, 0, 255), new OpenCvSharp.Scalar(0, 255, 0, 255), new OpenCvSharp.Scalar(0, 0, 255, 255) }; #region 控件 private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Panel controlPanel; private System.Windows.Forms.ListBox listBox1; private Button button3; private Button button2; private Label label1; private Button btnClose; private Label label2; private PictureBox pictureBox1; private Label lblParamName; private Label label4; private Timer timer1; private System.ComponentModel.IContainer components; private Button btnRest; #endregion public CameraSettingDialog() { if (list == null || list.Count == 0) { CameraRelationModel crm1 = new CameraRelationModel(1, PdnResources.GetString("Menu.Image.Adjust.Text"), CameraParamType.Adjust); list.Add(crm1); CameraRelationModel crm2 = new CameraRelationModel(2, PdnResources.GetString("Menu.ImageCollection.CameraFrame.Text"), CameraParamType.Frame); list.Add(crm2); CameraRelationModel crm3 = new CameraRelationModel(3, PdnResources.GetString("Menu.ImageCollection.CameraConventional.Text"), CameraParamType.Common); list.Add(crm3); } adjustCameraControl = new AdjustContainer(); adjustCameraControl.Initialize(m_cameraParamModel, true); adjustCameraControl.Location = new Point(10, 15); frameCameraControl = new FrameCameraControl(m_cameraParamModel, true); frameCameraControl.Location = new Point(10, 15); commonCameraControl = new CommonCameraControl(); commonCameraControl.Initialize(m_cameraParamModel, true); commonCameraControl.Location = new Point(10, 15); InitializeComponent(); InitializeLanguageText(); InitializeData(); timer1.Tick += (s, e) => { controlPanel.Enabled = CameraManager.IsLive; if (CameraManager.IsLive) adjustCameraControl.UpdateDisplay(); }; this.Load += (s, e) => { timer1.Enabled = true; }; this.FormClosing += (s, e) => { frameCameraControl.Dispose(); adjustCameraControl.Dispose(); timer1.Enabled = false; }; } private void InitializeLanguageText() { this.label1.Text = PdnResources.GetString("Menu.Systemusecamera.text") + ":"; this.button3.Text = PdnResources.GetString("Menu.File.SaveAs.Text"); this.button2.Text = PdnResources.GetString("Menu.File.Save.Text"); this.groupBox3.Text = PdnResources.GetString("Menu.Type.text"); this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text"); this.btnRest.Text = PdnResources.GetString("Menu.reinformation.text"); this.Text = PdnResources.GetString("Menu.ImageCollection.CameraSetting.Text"); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.lblParamName = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.btnClose = new System.Windows.Forms.Button(); this.btnRest = new System.Windows.Forms.Button(); this.listBox1 = new System.Windows.Forms.ListBox(); this.controlPanel = new System.Windows.Forms.Panel(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.groupBox1.SuspendLayout(); this.groupBox3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.lblParamName); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.button3); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Location = new System.Drawing.Point(134, 13); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(556, 78); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; // // lblParamName // this.lblParamName.AutoSize = true; this.lblParamName.Location = new System.Drawing.Point(109, 47); this.lblParamName.Name = "lblParamName"; this.lblParamName.Size = new System.Drawing.Size(53, 12); this.lblParamName.TabIndex = 8; this.lblParamName.Text = " "; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(14, 47); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(89, 12); this.label4.TabIndex = 7; this.label4.Text = "相机参数名称:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(109, 25); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(53, 12); this.label2.TabIndex = 6; this.label2.Text = " "; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(14, 25); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(89, 12); this.label1.TabIndex = 5; this.label1.Text = "系统使用相机:"; // // button3 // this.button3.Location = new System.Drawing.Point(457, 20); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 2; this.button3.Text = "另存为"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button2 // this.button2.Location = new System.Drawing.Point(376, 19); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 1; this.button2.Text = "保存"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.pictureBox1); this.groupBox3.Controls.Add(this.btnClose); this.groupBox3.Controls.Add(this.btnRest); this.groupBox3.Controls.Add(this.listBox1); this.groupBox3.Location = new System.Drawing.Point(13, 13); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(115, 471); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; // // pictureBox1 // this.pictureBox1.Location = new System.Drawing.Point(6, 301); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(100, 50); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 4; this.pictureBox1.TabStop = false; // // btnClose // this.btnClose.Location = new System.Drawing.Point(16, 431); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(75, 23); this.btnClose.TabIndex = 3; this.btnClose.Text = "关闭"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // btnRest // this.btnRest.Location = new System.Drawing.Point(16, 393); this.btnRest.Name = "btnRest"; this.btnRest.Size = new System.Drawing.Size(75, 23); this.btnRest.TabIndex = 2; this.btnRest.Text = "重置"; this.btnRest.UseVisualStyleBackColor = true; this.btnRest.Click += new System.EventHandler(this.btnRest_Click); // // listBox1 // this.listBox1.FormattingEnabled = true; this.listBox1.ItemHeight = 12; this.listBox1.Location = new System.Drawing.Point(6, 20); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(103, 208); this.listBox1.TabIndex = 0; this.listBox1.SelectedValueChanged += new System.EventHandler(this.listBox1_SelectedValueChanged); // // controlPanel // this.controlPanel.AutoScroll = true; this.controlPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.controlPanel.Location = new System.Drawing.Point(134, 98); this.controlPanel.Name = "controlPanel"; this.controlPanel.Size = new System.Drawing.Size(556, 386); this.controlPanel.TabIndex = 5; // // CameraSettingDialog // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.ClientSize = new System.Drawing.Size(702, 496); this.Controls.Add(this.controlPanel); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "CameraSettingDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "相机设置"; this.Activated += new System.EventHandler(this.CameraSettingDialog_Activated); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.Controls.SetChildIndex(this.controlPanel, 0); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox3.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } /// /// 初始化数据 /// public void InitializeData() { //绑定左侧listbox数据 this.listBox1.Items.Clear(); foreach (CameraRelationModel model in list) { this.listBox1.Items.Add(model.name); } this.listBox1.SelectedIndex = 0; try { // 获取系统使用的相机名称 ICamera camera = CameraManager.CurrentCamera; // 获取系统使用的相机SN string sn; camera.ReadRegisterData(out sn); //label2.Text = camera.GetName(); if (!string.IsNullOrEmpty(sn)) { label2.Text = sn; } m_cameraParamModel = Startup.instance.cameraParamModel; lblParamName.Text = CameraConfigs.GetInstance().CurrentConfigFileName; } catch (Exception ex) { MessageBox.Show(ex.Message); } } /// /// 当前操作样式 下拉选切换 /// /// /// private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { InitializeData(); } /// /// 左侧listbox选择事件 /// /// /// private void listBox1_SelectedValueChanged(object sender, EventArgs e) { //首先更新右侧分类部分 UpdateRightCatalog(); //更新右侧设置界面 UpdateRightSettingUI(); } /// /// 更新右侧分类 /// private void UpdateRightCatalog() { this.controlPanel.Controls.Clear(); CameraRelationModel model = list[this.listBox1.SelectedIndex]; this.cameraParamType = model.cameraParamType; } /// /// 更新右侧设置 /// private void UpdateRightSettingUI() { this.controlPanel.Controls.Clear(); switch (this.cameraParamType) { case CameraParamType.Adjust: //调节 adjustCameraControl.Location = new Point(0, 0); this.controlPanel.Controls.Add(adjustCameraControl); break; case CameraParamType.Frame: //边框 frameCameraControl.Location = new Point(0, 0); this.controlPanel.Controls.Add(frameCameraControl); break; case CameraParamType.Common: //常规 commonCameraControl.Location = new Point(0, 0); this.controlPanel.Controls.Add(commonCameraControl); break; } } /// /// 另存为 出弹窗 /// /// /// private void button3_Click(object sender, EventArgs e) { dialog = new CreateNameDialog(this); dialog.Text = PdnResources.GetString("Menu.Savecamerasettings.text"); dialog.StartPosition = FormStartPosition.CenterParent; dialog.ShowDialog(); } /// /// 另存为弹窗 确定保存 /// /// public override void GetCreateName(string name) { // string currentcomboBox = this.comboBox1.Text; this.newName = name; if (CameraConfigs.GetInstance().FileExist(this.newName)) { MessageBox.Show(PdnResources.GetString("Menu.Namecannotbepeated.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } CameraConfigs.GetInstance().Save(this.m_cameraParamModel, this.newName); dialog.Close(); MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text")); } /// /// 保存 /// /// /// private void button2_Click(object sender, EventArgs e) { CameraConfigs.GetInstance().Save(); MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text")); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); this.Dispose(); } private void btnRest_Click(object sender, EventArgs e) { CameraConfigs cameraConfig = CameraConfigs.GetInstance(); Startup.instance.cameraParamModel = cameraConfig.GetDefaultCameraParamModel(); m_cameraParamModel = Startup.instance.cameraParamModel; if (adjustCameraControl != null) { adjustCameraControl.Initialize(Startup.instance.cameraParamModel); } if (frameCameraControl != null) { frameCameraControl.ResetCameraParamModel(Startup.instance.cameraParamModel); } if (commonCameraControl != null) { commonCameraControl.Initialize(Startup.instance.cameraParamModel); } } private void CameraSettingDialog_Activated(object sender, EventArgs e) { m_cameraParamModel = Startup.instance.cameraParamModel; lblParamName.Text = CameraConfigs.GetInstance().CurrentConfigFileName; adjustCameraControl.Initialize(m_cameraParamModel, true); frameCameraControl.ResetCameraParamModel(m_cameraParamModel); commonCameraControl.ResetCameraParamModel(m_cameraParamModel); } private void timer1_Tick(object sender, EventArgs e) { controlPanel.Enabled = Camera.CameraManager.IsLive; } } }