-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsEditor.cs
219 lines (181 loc) · 6.71 KB
/
SettingsEditor.cs
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using AzimuthSuite.AzmCore;
using System;
using System.Net;
using System.Windows.Forms;
using UCNLDrivers;
using UCNLUI;
using UCNLUI.Dialogs;
namespace AzimuthSuite
{
public partial class SettingsEditor : Form
{
#region Properties
ushort addrMask
{
get
{
ushort result = 0;
for (int i = 0; i < 16; i++)
{
if (remotesList.GetItemCheckState(i) == CheckState.Checked)
{
result |= (ushort)(1 << i);
}
}
return result;
}
set
{
for (int i = 0; i < 16; i++)
{
if ((value & (ushort)(1 << i)) != 0)
remotesList.SetItemCheckState(i, CheckState.Checked);
}
}
}
bool isUseAUXGNSS
{
get => isUseAUXGNSSChb.Checked;
set => isUseAUXGNSSChb.Checked = value;
}
bool isUseMagneticCompassOnly
{
get => IsUseMagneticCompassOnlyChb.Checked;
set => IsUseMagneticCompassOnlyChb.Checked = value;
}
BaudRate AUXGNSSBaudrate
{
get => (BaudRate)Enum.Parse(typeof(BaudRate), auxGNSSBaudrateCbx.SelectedItem.ToString());
set => UIHelpers.TrySetCbxItem(auxGNSSBaudrateCbx, value.ToString());
}
double salinity_PSU
{
get => Convert.ToDouble(styEdit.Value);
set => UIHelpers.SetNumericEditValue(styEdit, value);
}
double maxRange_m
{
get => Convert.ToDouble(maxRangeEdit.Value);
set => UIHelpers.SetNumericEditValue(maxRangeEdit, value);
}
double xOffset_m
{
get => Convert.ToDouble(xOffsetEdit.Value);
set => UIHelpers.SetNumericEditValue(xOffsetEdit, value);
}
double yOffset_m
{
get => Convert.ToDouble(yOffsetEdit.Value);
set => UIHelpers.SetNumericEditValue(yOffsetEdit, value);
}
double angleAdjust_deg
{
get => Convert.ToDouble(antennaAdjustAngleEdit.Value);
set => UIHelpers.SetNumericEditValue(antennaAdjustAngleEdit, value);
}
BaudRate OutputPortBaudrate
{
get => (BaudRate)Enum.Parse(typeof(BaudRate), outputPortBaudrateCbx.SelectedItem.ToString());
set => UIHelpers.TrySetCbxItem(outputPortBaudrateCbx, value.ToString());
}
public SettingsContainer Value
{
get
{
SettingsContainer result = new SettingsContainer
{
AddressMask = addrMask,
UseAUXGNSSCompas = isUseAUXGNSS,
AUXGNSSCompasBaudrate = AUXGNSSBaudrate,
Salinity_PSU = salinity_PSU,
MaxDist_m = maxRange_m,
TransverseOffset_m = xOffset_m,
LongitudalOffset_m = yOffset_m,
HeadingAdjust_deg = angleAdjust_deg,
SerialOutputPortBaudrate = OutputPortBaudrate,
IsUseMagneticCompassOnly = isUseMagneticCompassOnly,
};
return result;
}
set
{
addrMask = value.AddressMask;
isUseAUXGNSS = value.UseAUXGNSSCompas;
AUXGNSSBaudrate = value.AUXGNSSCompasBaudrate;
salinity_PSU = value.Salinity_PSU;
maxRange_m = value.MaxDist_m;
xOffset_m = value.TransverseOffset_m;
yOffset_m = value.LongitudalOffset_m;
angleAdjust_deg = value.HeadingAdjust_deg;
OutputPortBaudrate = value.SerialOutputPortBaudrate;
isUseMagneticCompassOnly = value.IsUseMagneticCompassOnly;
}
}
#endregion
#region Constructor
public SettingsEditor()
{
InitializeComponent();
remotesList.Items.Clear();
var items = Enum.GetValues(typeof(REMOTE_ADDR_Enum));
foreach (REMOTE_ADDR_Enum rAddr in items)
{
if (rAddr != REMOTE_ADDR_Enum.REM_ADDR_INVALID)
remotesList.Items.Add(rAddr);
}
var bRates = Enum.GetNames(typeof(BaudRate));
auxGNSSBaudrateCbx.Items.Clear();
auxGNSSBaudrateCbx.Items.AddRange(bRates);
AUXGNSSBaudrate = BaudRate.baudRate9600;
outputPortBaudrateCbx.Items.Clear();
outputPortBaudrateCbx.Items.AddRange(bRates);
OutputPortBaudrate = BaudRate.baudRate9600;
}
#endregion
#region Methods
private void CheckValidity()
{
okBtn.Enabled = remotesList.CheckedItems.Count > 0;
}
#endregion
#region Handlers
private void remotesCheckAllBtn_Click(object sender, EventArgs e)
{
for (int i = 0; i < remotesList.Items.Count; i++)
remotesList.SetItemChecked(i, true);
}
private void remotesUncheckAllBtn_Click(object sender, EventArgs e)
{
for (int i = 0; i < remotesList.Items.Count; i++)
remotesList.SetItemChecked(i, false);
}
private void isUseAUXGNSSChb_CheckedChanged(object sender, EventArgs e)
{
auxGNSSGroup.Enabled = isUseAUXGNSS;
if (!isUseAUXGNSS)
IsUseMagneticCompassOnlyChb.Checked = false;
IsUseMagneticCompassOnlyChb.Enabled = isUseAUXGNSS;
}
private void setDaultsBtn_Click(object sender, EventArgs e)
{
Value = new SettingsContainer();
}
private void styDialogBtn_Click(object sender, EventArgs e)
{
using (SalinityDialog sDialog = new SalinityDialog())
{
sDialog.Text = LocalisedStrings.SettingsEditor_WaterSalinityDialogTitle;
if (sDialog.ShowDialog() == DialogResult.OK)
{
salinity_PSU = sDialog.Salinity;
}
}
}
private void remotesList_ItemCheck(object sender, ItemCheckEventArgs e)
{
okBtn.Enabled =
(!((remotesList.CheckedItems.Count == 1) && (e.NewValue == CheckState.Unchecked)));
}
#endregion
}
}