轮胎外观检测添加思谋语义分割模型检测工具
C3204
12 小时以前 98c0775fe3b61a37d90dd5756287f385a311adf0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using LB_VisionControls.Forms;
 
namespace LB_VisionProcesses.Forms
{
    public partial class GlobalVarControl : UserControl
    {
        NumericUpDown numericUpDown = new NumericUpDown();
        CheckBox checkBox = new CheckBox();
        TextBox textBox = new TextBox();
        ComboBox comboBox = new ComboBox();
 
        public bool isSelected
        {
            get { return ckbLabel.Checked; }
        }
 
        public string Key
        {
            get { return ckbLabel.Text; }
        }
 
        public object Value
        {
            get
            {
                string type = cmbType.Text;
                switch (type)
                {
                    case "int":
                        return Convert.ToInt32(numericUpDown.Value);
                    case "double":
                        return Convert.ToDouble(numericUpDown.Value);
                    case "bool":
                        return checkBox.Checked;
                    case "List<string>":
                        return textBox.Text.Split(',').ToList();
                    case "string":
                    default:
                        return textBox.Text;
                }
            }
        }
 
        public GlobalVarControl(string key, object value = null)
        {
            InitializeComponent();
            ckbLabel.Text = key;
 
            if (value == null)
            {
                cmbType.Text = "string";
                return;
            }
 
            Type type = value?.GetType();
            switch (type)
            {
                case Type t when t == typeof(int):
                    cmbType.Text = "int";
                    numericUpDown.Value = Convert.ToDecimal((int)value);
                    break;
                case Type t when t == typeof(double):
                    cmbType.Text = "double";
                    numericUpDown.Value = Convert.ToDecimal((double)value);
                    break;
                case Type t when t == typeof(bool):
                    cmbType.Text = "bool";
                    checkBox.Checked = Convert.ToBoolean(value);
                    break;
                case Type t when t == typeof(List<string>):
                    cmbType.Text = "string";
                    textBox.Text = string.Join(',', value as List<string>);
                    break;
                default:
                    cmbType.Text = "string";
                    textBox.Text = value.ToString();
                    break;
            }
        }
 
        private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            numericUpDown.Visible = false;
            checkBox.Visible = false;
            textBox.Visible = false;
            comboBox.Visible = false;
 
            string type = cmbType.Text;
            switch (type)
            {
                case "int":
                    numericUpDown.Increment = 1;
                    numericUpDown.Value = 0;
                    tableLayoutPanel1.Controls.Add(numericUpDown, 2, 0);
                    numericUpDown.Dock = DockStyle.Fill;
                    numericUpDown.Visible = true;
                    numericUpDown.Maximum = 999;
                    numericUpDown.Minimum = -999;
                    break;
                case "double":
                    numericUpDown.Increment = Convert.ToDecimal(0.1);
                    numericUpDown.Value = Convert.ToDecimal(0.0);
                    tableLayoutPanel1.Controls.Add(numericUpDown, 2, 0);
                    numericUpDown.Dock = DockStyle.Fill;
                    numericUpDown.Visible = true;
                    numericUpDown.Maximum = 999;
                    numericUpDown.Minimum = -999;
                    break;
                case "bool":
                    checkBox.Checked = false;
                    checkBox.Text = "";
                    tableLayoutPanel1.Controls.Add(checkBox, 2, 0);
                    checkBox.Dock = DockStyle.Fill;
                    checkBox.Visible = true;
                    break;
                case "List<string>":
                case "string":
                default:
                    textBox.Text = "";
                    tableLayoutPanel1.Controls.Add(textBox, 2, 0);
                    textBox.Dock = DockStyle.Fill;
                    textBox.Visible = true;
                    break;
            }
        }
 
        private System.Windows.Forms.ToolTip toolTip = new System.Windows.Forms.ToolTip();
        private void ShowToolTip(Control control, string message) => toolTip.SetToolTip(control, message);
 
        private void ckbLabel_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button.ToString() == "Right")
            {
                if (ckbLabel.Text.Contains("."))
                {
                    MessageBox.Show($"变量【{ckbLabel.Text}】不允许重命名!", "异常");
                    return;
                }
 
                RenameForm renameForm = new RenameForm(ckbLabel.Text);
                renameForm.ShowDialog();
                if (renameForm.bRename)
                {
                    string oriName = renameForm.strOriName;
                    string newName = renameForm.strNewName;
 
                    if (IProcess.dicGlobalVars.ContainsKey(newName))
                        MessageBox.Show($"变量【{newName}】已存在,请更换名称", "异常");
                    else
                    {
                        if (!IProcess.dicGlobalVars.TryRemove(oriName, out object obj)
                           || !IProcess.dicGlobalVars.TryAdd(newName, obj))
                        {
                            MessageBox.Show($"重命名为【{newName}】失败!", "异常");
                            return;
                        }
                        ckbLabel.Text = newName;
                    }
                }
            }
        }
    }
}