GalvanometerControl.cs
5.3 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
namespace UserFromControl
{
public partial class GalvanometerControl : UserControl
{
public GalvanometerControl()
{
InitializeComponent();
}
public string GroupName
{
get { return group.Text; }
set
{
group.Text = value;
}
}
private void btnShowPoint_Click(object sender, EventArgs e)
{
ShowCurrPoint();
}
public void ShowCurrPoint()
{
this.Cursor = Cursors.WaitCursor;
int x = FormUtil.GetIntValue(txtAreaX);
int y = FormUtil.GetIntValue(txtAreaY);
int px = FormUtil.GetIntValue(txtX);
int py = FormUtil.GetIntValue(txtY);
int pointType = cmbType.SelectedIndex + 1;
int pointLenth = FormUtil.GetIntValue(txtSize);
int pointLight = FormUtil.GetIntValue(txtLight);
//如果亮度和大小超过范围,直接用默认值
if (pointLenth < 0 || pointLenth > 255)
{
pointLenth = 1;
txtSize.Text = pointLenth.ToString();
}
if (pointLight < 0 || pointLight > 255)
{
pointLight = 10;
txtLight.Text = pointLight.ToString();
}
GalvanometerPoint p = new GalvanometerPoint(px, py, x, y, pointType, pointLenth, pointLight);
GalvanometerManager.ShowPoint(TSAVBean.Gal_Port, TSAVBean.Gal_Addr, p);
this.Cursor = Cursors.Default;
}
private void btnUp_Click(object sender, EventArgs e)
{
int x = FormUtil.GetIntValue(txtX);
int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.XAxis_Change));
txtX.Text = (x - stepValue).ToString();
ShowCurrPoint();
}
private void btnLeft_Click(object sender, EventArgs e)
{
int y = FormUtil.GetIntValue(txtY);
int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.YAxis_Change));
txtY.Text = (y + stepValue).ToString();
ShowCurrPoint();
}
private void btnRight_Click(object sender, EventArgs e)
{
int y = FormUtil.GetIntValue(txtY);
int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.YAxis_Change));
txtY.Text = (y - stepValue).ToString();
ShowCurrPoint();
}
private void btnDown_Click(object sender, EventArgs e)
{
int x = FormUtil.GetIntValue(txtX);
int stepValue = (int)(GetStepValue() * ConfigAppSettings.GetDoubleValue(Setting_Init.XAxis_Change));
txtX.Text = (x + stepValue).ToString();
ShowCurrPoint();
}
private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
{
int size = FormUtil.GetIntValue(txtSize);
if (cmbType.SelectedIndex.Equals(0) && size > 10)
{
txtSize.Text = "1";
}
else
{
if (size < 15)
txtSize.Text = "15";
}
}
public double XValue
{
set
{
txtX.Text = ((int)value).ToString();
}
get
{
return FormUtil.GetIntValue(txtX);
}
}
public double YValue
{
set
{
txtY.Text = ((int)value).ToString();
}
get
{
return FormUtil.GetIntValue(txtY);
}
}
public int PointType
{
set
{
cmbType.SelectedIndex = ((int)value)-1;
}
get
{
return cmbType.SelectedIndex+1;
}
}
public int PointSize
{
set
{
txtSize.Text = ((int)value).ToString();
}
get
{
return FormUtil.GetIntValue(txtSize);
}
}
public void UpdateStatus()
{
txtX.Text = GalvanometerManager.GetLastPoint().X.ToString();
txtY.Text = GalvanometerManager.GetLastPoint().Y.ToString();
}
private List<double> vallue = new List<double>() { 0.5, 1, 2, 5, 10, 20, 50 };
private double GetStepValue()
{
int index = cmbStep.SelectedIndex;
TSAVBean.LastStepIndex = index;
if (vallue.Count > index)
{
return vallue[index];
}
return 10;
}
private void GalvanometerControl_Load(object sender, EventArgs e)
{
cmbStep.SelectedIndex =TSAVBean.LastStepIndex;
if (cmbType.SelectedIndex < 0)
{
cmbType.SelectedIndex = 0;
}
}
}
}