You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cigarette/WindowsFormsApp2/DialogSetup.cs

469 lines
19 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WindowsFormsApp2
{
public struct CamSetting
{
public int expo;
public int gain;
public int filt;
};
public struct PassWord
{
public string ori;
public string dst;
public string agin;
};
public struct ChangeShift
{
public int Ah;
public int Am;
public int Bh;
public int Bm;
public int Ch;
public int Cm;
public int shift_time;
public int shift_byhand;
public static implicit operator ChangeShift(int v)
{
throw new NotImplementedException();
}
}
public struct CameraGlue
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public int[] shoot;
};
public struct Setting
{
public bool ok;
public bool IsAutoOpenCam;
public bool IsAutoWork;
public int saveimage;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4, ArraySubType = UnmanagedType.Struct)]
public CamSetting[] camerasetting;
public bool IsNeedChangePsd;
public PassWord mapsd;
public PassWord oppsd;
public ChangeShift changeshift;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4, ArraySubType =UnmanagedType.Struct)]
public CameraGlue[] Cameraglue;
};
public partial class DialogSetup : Form
{
const int NumberOfSupportedCameras = 8;
public static Setting cam_setting = new Setting();
public void UpdateDialog()
{
textBox_old_pwd.Text = "";
textBox_new_pwd.Text = "";
textBox_confirm_pwd.Text = "";
textBox_op_old_pwd.Text = "";
textBox_op_new_pwd.Text = "";
textBox6.Text = "";
this.checkBox_auto_open.Checked = cam_setting.IsAutoOpenCam;
this.checkBox_auto_work.Checked = cam_setting.IsAutoWork;
switch(cam_setting.saveimage)
{
case 0: this.radioButton_none.Checked = true; this.radioButton_save_ng.Checked = false; this.radioButton_save_all.Checked = false; break;
case 1: this.radioButton_none.Checked = false; this.radioButton_save_ng.Checked = true; this.radioButton_save_all.Checked = false; break;
case 2: this.radioButton_none.Checked = false; this.radioButton_save_ng.Checked = false; this.radioButton_save_all.Checked = true; break;
}
if (cam_setting.camerasetting != null)
{
this.textBox_expo_1.Text = cam_setting.camerasetting[0].expo.ToString();
this.textBox_expo_2.Text = cam_setting.camerasetting[1].expo.ToString();
this.textBox_expo_3.Text = cam_setting.camerasetting[2].expo.ToString();
this.textBox_expo_4.Text = cam_setting.camerasetting[3].expo.ToString();
this.textBox_expo_5.Text = cam_setting.camerasetting[4].expo.ToString();
this.textBox_expo_6.Text = cam_setting.camerasetting[5].expo.ToString();
this.textBox_expo_7.Text = cam_setting.camerasetting[6].expo.ToString();
this.textBox_expo_8.Text = cam_setting.camerasetting[7].expo.ToString();
this.textBox_gain_1.Text = cam_setting.camerasetting[0].gain.ToString();
this.textBox_gain_2.Text = cam_setting.camerasetting[1].gain.ToString();
this.textBox_gain_3.Text = cam_setting.camerasetting[2].gain.ToString();
this.textBox_gain_4.Text = cam_setting.camerasetting[3].gain.ToString();
this.textBox_gain_5.Text = cam_setting.camerasetting[4].gain.ToString();
this.textBox_gain_6.Text = cam_setting.camerasetting[5].gain.ToString();
this.textBox_gain_7.Text = cam_setting.camerasetting[6].gain.ToString();
this.textBox_gain_8.Text = cam_setting.camerasetting[7].gain.ToString();
this.textBox_filter_1.Text = cam_setting.camerasetting[0].filt.ToString();
this.textBox_filter_2.Text = cam_setting.camerasetting[1].filt.ToString();
this.textBox_filter_3.Text = cam_setting.camerasetting[2].filt.ToString();
this.textBox_filter_4.Text = cam_setting.camerasetting[3].filt.ToString();
this.textBox_filter_5.Text = cam_setting.camerasetting[4].filt.ToString();
this.textBox_filter_6.Text = cam_setting.camerasetting[5].filt.ToString();
this.textBox_filter_7.Text = cam_setting.camerasetting[6].filt.ToString();
this.textBox_filter_8.Text = cam_setting.camerasetting[7].filt.ToString();
}
}
public DialogSetup()
{
InitializeComponent();
int index = 0;
cam_setting.ok = true;
cam_setting.IsAutoOpenCam = false;
cam_setting.IsAutoWork = false;
cam_setting.saveimage = 0;
cam_setting.camerasetting = new CamSetting[NumberOfSupportedCameras];
for (; index < NumberOfSupportedCameras; index++)
{
cam_setting.camerasetting[index].expo = 0;
cam_setting.camerasetting[index].gain = 0;
cam_setting.camerasetting[index].filt = 0;
}
index = 6 + NumberOfSupportedCameras * 3;
cam_setting.changeshift.shift_byhand = 0;
cam_setting.changeshift.shift_time = 0;
index = index + 2;
cam_setting.changeshift.Ah = 0;
cam_setting.changeshift.Am = 0;
cam_setting.changeshift.Bh = 0;
cam_setting.changeshift.Bm = 0;
cam_setting.changeshift.Ch = 0;
cam_setting.changeshift.Cm = 0;
index = index + 6;
cam_setting.Cameraglue = new CameraGlue[NumberOfSupportedCameras];
for (int i = 0; i < NumberOfSupportedCameras; i++)
{
cam_setting.Cameraglue[i].shoot = new int[3];
cam_setting.Cameraglue[i].shoot[0] = 0;
cam_setting.Cameraglue[i].shoot[1] = 0;
cam_setting.Cameraglue[i].shoot[2] = 0;
}
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void radioButton_save_all_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton_save_all.Checked)
{
this.radioButton_save_ng.Checked = false;
this.radioButton_save_all.Checked = true;
this.radioButton_none.Checked = false;
}
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button_config_Click(object sender, EventArgs e)
{
Camera_glue cameraGlue = new Camera_glue();
cameraGlue.StartPosition = FormStartPosition.CenterScreen;
cameraGlue.TopMost = true;
cameraGlue.ShowDialog();
}
private void button_change_Click(object sender, EventArgs e)
{
Change_shift changeShift = new Change_shift();
changeShift.StartPosition = FormStartPosition.CenterScreen;
changeShift.TopMost = true;
changeShift.ShowDialog();
}
private void button_statistic_Click(object sender, EventArgs e)
{
Output_statistic outputStatistic = new Output_statistic();
outputStatistic.StartPosition = FormStartPosition.CenterScreen;
outputStatistic.TopMost = true;
outputStatistic.ShowDialog();
}
private void checkBox_auto_open_CheckedChanged(object sender, EventArgs e)
{
cam_setting.IsAutoOpenCam = this.checkBox_auto_open.Checked;
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private void checkBox_auto_work_CheckedChanged(object sender, EventArgs e)
{
cam_setting.IsAutoWork = this.checkBox_auto_work.Checked;
}
private void radioButton_save_ng_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton_save_ng.Checked)
{
this.radioButton_save_ng.Checked = true;
this.radioButton_save_all.Checked = false;
this.radioButton_none.Checked = false;
}
}
private void radioButton_none_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton_none.Checked)
{
this.radioButton_save_ng.Checked = false;
this.radioButton_save_all.Checked = false;
this.radioButton_none.Checked = true;
}
}
private void textBox_expo_1_TextChanged(object sender, EventArgs e)
{
if(textBox_expo_1.Text != string.Empty)
cam_setting.camerasetting[0].expo = Convert.ToInt32(this.textBox_expo_1.Text.ToString());
}
private void textBox_expo_2_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_2.Text != string.Empty)
cam_setting.camerasetting[1].expo = Convert.ToInt32(this.textBox_expo_2.Text.ToString());
}
private void textBox_expo_3_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_3.Text != string.Empty)
cam_setting.camerasetting[2].expo = Convert.ToInt32(this.textBox_expo_3.Text.ToString());
}
private void textBox_expo_4_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_4.Text != string.Empty)
cam_setting.camerasetting[3].expo = Convert.ToInt32(this.textBox_expo_4.Text.ToString());
}
private void textBox_expo_5_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_5.Text != string.Empty)
cam_setting.camerasetting[4].expo = Convert.ToInt32(this.textBox_expo_5.Text.ToString());
}
private void textBox_expo_6_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_6.Text != string.Empty)
cam_setting.camerasetting[5].expo = Convert.ToInt32(this.textBox_expo_6.Text.ToString());
}
private void textBox_expo_7_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_7.Text != string.Empty)
cam_setting.camerasetting[6].expo = Convert.ToInt32(this.textBox_expo_7.Text.ToString());
}
private void textBox_expo_8_TextChanged(object sender, EventArgs e)
{
if (textBox_expo_8.Text != string.Empty)
cam_setting.camerasetting[7].expo = Convert.ToInt32(this.textBox_expo_8.Text.ToString());
}
private void textBox_gain_1_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_1.Text != string.Empty)
cam_setting.camerasetting[0].gain = Convert.ToInt32(this.textBox_gain_1.Text.ToString());
}
private void textBox_gain_2_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_2.Text != string.Empty)
cam_setting.camerasetting[1].gain = Convert.ToInt32(this.textBox_gain_2.Text.ToString());
}
private void textBox_gain_3_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_3.Text != string.Empty)
cam_setting.camerasetting[2].gain = Convert.ToInt32(this.textBox_gain_3.Text.ToString());
}
private void textBox_gain_4_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_4.Text != string.Empty)
cam_setting.camerasetting[3].gain = Convert.ToInt32(this.textBox_gain_4.Text.ToString());
}
private void textBox_gain_5_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_5.Text != string.Empty)
cam_setting.camerasetting[4].gain = Convert.ToInt32(this.textBox_gain_5.Text.ToString());
}
private void textBox_gain_6_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_6.Text != string.Empty)
cam_setting.camerasetting[5].gain = Convert.ToInt32(this.textBox_gain_6.Text.ToString());
}
private void textBox_gain_7_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_7.Text != string.Empty)
cam_setting.camerasetting[6].gain = Convert.ToInt32(this.textBox_gain_7.Text.ToString());
}
private void textBox_gain_8_TextChanged(object sender, EventArgs e)
{
if (textBox_gain_8.Text != string.Empty)
cam_setting.camerasetting[7].gain = Convert.ToInt32(this.textBox_gain_8.Text.ToString());
}
private void textBox_filter_1_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_1.Text != string.Empty)
cam_setting.camerasetting[0].filt = Convert.ToInt32(this.textBox_filter_1.Text.ToString());
}
private void textBox_filter_2_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_2.Text != string.Empty)
cam_setting.camerasetting[1].filt = Convert.ToInt32(this.textBox_filter_2.Text.ToString());
}
private void textBox_filter_3_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_3.Text != string.Empty)
cam_setting.camerasetting[2].filt = Convert.ToInt32(this.textBox_filter_3.Text.ToString());
}
private void textBox_filter_4_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_4.Text != string.Empty)
cam_setting.camerasetting[3].filt = Convert.ToInt32(this.textBox_filter_4.Text.ToString());
}
private void textBox_filter_5_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_5.Text != string.Empty)
cam_setting.camerasetting[4].filt = Convert.ToInt32(this.textBox_filter_5.Text.ToString());
}
private void textBox_filter_6_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_6.Text != string.Empty)
cam_setting.camerasetting[5].filt = Convert.ToInt32(this.textBox_filter_6.Text.ToString());
}
private void textBox_filter_7_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_7.Text != string.Empty)
cam_setting.camerasetting[6].filt = Convert.ToInt32(this.textBox_filter_7.Text.ToString());
}
private void textBox_filter_8_TextChanged(object sender, EventArgs e)
{
if (textBox_filter_8.Text != string.Empty)
cam_setting.camerasetting[7].filt = Convert.ToInt32(this.textBox_filter_8.Text.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
// 保存参数按钮
2 years ago
String msg = "UPDSETTING:";
msg += NumberOfSupportedCameras.ToString() + ":";
msg += cam_setting.IsAutoOpenCam.ToString() + ":";
msg += cam_setting.IsAutoWork.ToString() + ":";
msg += cam_setting.saveimage.ToString() + ":";
for (int index = 0; index < NumberOfSupportedCameras; index++)
{
msg += cam_setting.camerasetting[index].expo.ToString() + ":";
msg += cam_setting.camerasetting[index].gain.ToString() + ":";
msg += cam_setting.camerasetting[index].filt.ToString() + ":";
}
msg += cam_setting.changeshift.shift_byhand.ToString() + ":";
msg += cam_setting.changeshift.shift_time.ToString() + ":";
msg += cam_setting.changeshift.Ah.ToString() + ":";
msg += cam_setting.changeshift.Am.ToString() + ":";
msg += cam_setting.changeshift.Bh.ToString() + ":";
msg += cam_setting.changeshift.Bm.ToString() + ":";
msg += cam_setting.changeshift.Ch.ToString() + ":";
msg += cam_setting.changeshift.Cm.ToString() + ":";
for (int i = 0; i < NumberOfSupportedCameras; i++)
{
msg += cam_setting.Cameraglue[i].shoot[0].ToString() + ":";
msg += cam_setting.Cameraglue[i].shoot[1].ToString() + ":";
msg += cam_setting.Cameraglue[i].shoot[2].ToString() + ":";
}
UserControl1.SendMsg(msg);
}
private void button1_Click(object sender, EventArgs e)
{
String msg = "ADMINPWDCHANGE:";
cam_setting.mapsd.ori = this.textBox_old_pwd.Text.ToString();
cam_setting.mapsd.dst = this.textBox_new_pwd.Text.ToString();
cam_setting.mapsd.agin = this.textBox_confirm_pwd.Text.ToString();
msg = msg + cam_setting.mapsd.ori + ":" + cam_setting.mapsd.dst + ":" + cam_setting.mapsd.agin;
UserControl1.SendMsg(msg);
}
private void button2_Click(object sender, EventArgs e)
{
String msg = "OPERPWDCHANGE:";
cam_setting.oppsd.ori = this.textBox_op_old_pwd.Text.ToString();
cam_setting.oppsd.dst = this.textBox_op_new_pwd.Text.ToString();
cam_setting.oppsd.agin = this.textBox6.Text.ToString();
msg = msg + cam_setting.oppsd.ori + ":" + cam_setting.oppsd.dst + ":" + cam_setting.oppsd.agin;
UserControl1.SendMsg(msg);
}
private void button_image_Click(object sender, EventArgs e)
{
if(this.radioButton_none.Checked == true)
{
cam_setting.saveimage = 0;
}
else if(this.radioButton_save_ng.Checked == true)
{
cam_setting.saveimage = 1;
}
else if(this.radioButton_save_all.Checked == true)
{
cam_setting.saveimage = 2;
}
}
private void m_KeyPress(object sender, KeyPressEventArgs e)
{
if (
(e.KeyChar > 32 && e.KeyChar < 47)||
(e.KeyChar > 58 && e.KeyChar < 127)
)//具体数字含义请查询ascii表
{
MessageBox.Show("请输⼊数字!");//消息提⽰框
e.Handled = true;//将事件标记为已处理,否则⽆效字符会继续填充进去
}
}
private void button5_Click(object sender, EventArgs e)
{
UserControl1.SendMsg("RESTART");
MessageBox.Show("正在重启软件");///
this.Close();///
}
private void SetConf_Click(object sender, EventArgs e)
{
UserControl1.SendMsg("SETCONF");
}
private void GetConf_Click(object sender, EventArgs e)
{
UserControl1.SendMsg("GETCONF");
}
}
}