forked from vranki/ExtPlane-Panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunits.cpp
More file actions
107 lines (91 loc) · 2.46 KB
/
units.cpp
File metadata and controls
107 lines (91 loc) · 2.46 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
#include "units.h"
Units::Units()
{
}
double Units::convertSpeed(VelocityUnit from, VelocityUnit to, double value) {
double ms = 0;
if(from == VELOCITY_KTS)
ms = value * 0.51;
if(from == VELOCITY_KMH)
ms = value * 0.278;
if(from == VELOCITY_MS)
ms = value;
if(from == VELOCITY_FPM)
ms = value * 0.00508;
if(to == VELOCITY_KMH)
return ms * 3.6;
if(to == VELOCITY_KTS)
return ms * 1.94;
if(to == VELOCITY_FPM)
return ms * 196.850393;
return ms;
}
double Units::convertDistance(DistanceUnit from, DistanceUnit to, double value) {
double m = 0;
if(from == DISTANCE_M)
m = value;
if(from == DISTANCE_FT)
m = value * 0.3048;
if(to == DISTANCE_FT)
return m*3.2808399;
return m;
}
double Units::convertPressure(PressureUnit from, PressureUnit to, double value) {
double pa = 0;
if(from == PRESSURE_PA)
pa = value;
if(from == PRESSURE_HPA)
pa = value*100.0;
if(from == PRESSURE_INCHES_HG)
pa = value * 3386.389;
if(to == PRESSURE_HPA)
return pa/100.0;
if(to == PRESSURE_INCHES_HG)
return pa/3386.389;
return pa;
}
QString Units::unitName(VelocityUnit unit) {
if(unit == VELOCITY_KTS)
return "kts";
if(unit == VELOCITY_KMH)
return "km/h";
if(unit == VELOCITY_MS)
return "m/s";
if(unit == VELOCITY_FPM)
return "ft/min";
return "?";
}
QString Units::unitName(DistanceUnit unit) {
if(unit == DISTANCE_M)
return "meters";
if(unit == DISTANCE_FT)
return "feet";
return "?";
}
QString Units::unitName(PressureUnit unit) {
if(unit == PRESSURE_PA)
return "Pa";
if(unit == PRESSURE_HPA)
return "hPa";
if(unit == PRESSURE_INCHES_HG)
return "inHg";
return "?";
}
VelocityUnit Units::velocityUnitForName(QString name) {
if(name=="kts") return VELOCITY_KTS;
if(name=="km/h") return VELOCITY_KMH;
if(name=="m/s") return VELOCITY_MS;
if(name=="ft/min") return VELOCITY_FPM;
return VELOCITY_UNKNOWN;
}
DistanceUnit Units::distanceUnitForName(QString name) {
if(name=="meters") return DISTANCE_M;
if(name=="feet") return DISTANCE_FT;
return DISTANCE_UNKNOWN;
}
PressureUnit Units::pressureUnitForName(QString name) {
if(name=="Pa") return PRESSURE_PA;
if(name=="hPa") return PRESSURE_HPA;
if(name=="inHg") return PRESSURE_INCHES_HG;
return PRESSURE_UNKNOWN;
}