-
Notifications
You must be signed in to change notification settings - Fork 0
/
WPManager.cs
248 lines (208 loc) · 6.93 KB
/
WPManager.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using System;
using UCNLDrivers;
using UCNLNav;
using UCNLPhysics;
namespace UCNLUI
{
public class WPManager
{
#region Properties
public bool IsAutoSalinity { get; set; }
public bool IsAutoSoundSpeed { get; set; }
public bool IsAutoGravity { get; set; }
double _soundSpeed = PHX.PHX_FWTR_SOUND_SPEED_MPS;
double _salinity = PHX.PHX_FWTR_SALINITY_PSU;
double salinity
{
get => _salinity;
set
{
if (Math.Abs(_salinity - value) > 0.1)
{
_salinity = value;
SalinityChanged.Rise(this, new EventArgs());
if (IsAutoSoundSpeed)
UpdateSoundSpeed();
}
}
}
double soundSpeed
{
get => _soundSpeed;
set
{
if (Math.Abs(_soundSpeed - value) > 0.1)
{
_soundSpeed = value;
SoundSpeedChanged.Rise(this, new EventArgs());
}
}
}
double temperature = 0;
double pressure = PHX.PHX_ATM_PRESSURE_MBAR;
double atmospheric_pressure = PHX.PHX_ATM_PRESSURE_MBAR;
public double Temperature
{
get => temperature;
set
{
temperature = value;
if (IsAutoSoundSpeed)
UpdateSoundSpeed();
}
}
public double Pressure
{
get => pressure;
set
{
pressure = value;
if (IsAutoSoundSpeed)
UpdateSoundSpeed();
}
}
public double AtmosphericPressure
{
get => atmospheric_pressure;
set
{
atmospheric_pressure = value;
if (IsAutoSoundSpeed)
{
/// TODO Recalc
}
}
}
public double SoundSpeed
{
get => _soundSpeed;
set
{
if ((value >= PHX.PHX_FWTR_SOUND_SPEED_MPS_MIN) &&
(value <= PHX.PHX_FWTR_SOUND_SPEED_MPS_MAX))
{
soundSpeed = value;
IsAutoSoundSpeed = false;
}
else
throw new ArgumentOutOfRangeException(
string.Format("Value must be in a range {0}..{1}",
PHX.PHX_FWTR_SOUND_SPEED_MPS_MIN,
PHX.PHX_FWTR_SOUND_SPEED_MPS_MAX));
}
}
public double Salinity
{
get => _salinity;
set
{
if ((value >= PHX.PHX_SALINITY_PSU_MIN) && (value <= PHX.PHX_SALINITY_PSU_MAX))
{
IsAutoSalinity = false;
salinity = value;
}
else
throw new ArgumentOutOfRangeException(
string.Format("Value must be in a range {0}..{1} PSU",
PHX.PHX_SALINITY_PSU_MIN,
PHX.PHX_SALINITY_PSU_MAX));
}
}
double _gravityAcceleration = PHX.PHX_GRAVITY_ACC_MPS2;
double gravityAcceleration
{
get => _gravityAcceleration;
set
{
if (Math.Abs(_gravityAcceleration - value) > 0.0001)
{
_gravityAcceleration = value;
GravityAccelerationChanged.Rise(this, new EventArgs());
}
}
}
public double GravityAcceleration
{
get => _gravityAcceleration;
set
{
if ((value >= PHX.PHX_GRAVITY_ACC_MPS2_MIN) && (value <= PHX.PHX_GRAVITY_ACC_MPS2_MAX))
{
gravityAcceleration = value;
IsAutoGravity = false;
}
else
throw new ArgumentOutOfRangeException();
}
}
double _latitude = 48;
public double Latitude_Deg
{
get => _latitude;
private set
{
if ((value >= -90) && (value <= 90))
{
_latitude = value;
if (IsAutoGravity)
gravityAcceleration = PHX.Gravity_constant_wgs84_calc(_latitude);
}
else
throw new ArgumentOutOfRangeException("Value must be in range from -90 to 90");
}
}
double _longitude = 44;
public double Longitude_Deg
{
get => _longitude;
private set
{
if ((value >= -180) && (value <= 180))
_longitude = value;
else
throw new ArgumentOutOfRangeException("Value must be in range from -180 to 180");
}
}
double salinityLatPoint = 48;
double salinityLonPoint = 44;
public double SalinityLatPoint { get => salinityLatPoint; }
public double SalinityLonPoint { get => salinityLonPoint; }
#endregion
#region Constructor
#endregion
#region Methods
private void UpdateSoundSpeed()
{
soundSpeed = PHX.Speed_of_sound_UNESCO_calc(temperature, pressure, salinity);
}
public void UpdateLocation(double lat_deg, double lon_deg)
{
Latitude_Deg = lat_deg;
Longitude_Deg = lon_deg;
_ = Algorithms.VincentyInverse(
Algorithms.Deg2Rad(lat_deg), Algorithms.Deg2Rad(lon_deg),
Algorithms.Deg2Rad(salinityLatPoint), Algorithms.Deg2Rad(salinityLonPoint),
Algorithms.WGS84Ellipsoid,
Algorithms.VNC_DEF_EPSILON,
Algorithms.VNC_DEF_IT_LIMIT,
out double range,
out _,
out _,
out _);
if (range > 1000)
{
if (IsAutoSalinity)
{
UCNLSalinity.WWSalinityProvider sProvider = new UCNLSalinity.WWSalinityProvider("WWSalinity.xml");
salinity = sProvider.GetNearestSalinity(_latitude, _longitude, out salinityLatPoint, out salinityLonPoint);
}
}
}
#endregion
#region Events
public EventHandler SoundSpeedChanged;
public EventHandler SalinityChanged;
public EventHandler GravityAccelerationChanged;
#endregion
}
}