4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_UNITS_HPP
25 #define XCSOAR_UNITS_HPP
27 #include "Units/Settings.hpp"
28 #include "Units/System.hpp"
29 #include "Math/fixed.hpp"
34 class AtmosphericPressure
;
39 * Namespace to manage unit conversions.
40 * internal system units are (metric SI).
44 extern UnitSetting current
;
46 void SetConfig(const UnitSetting
&new_config
);
49 * Returns the user-specified unit for a horizontal distance
50 * @return The user-specified unit for a horizontal distance
53 Unit
GetUserDistanceUnit();
56 * Returns the user-specified unit for an altitude
57 * @return The user-specified unit for an altitude
60 Unit
GetUserAltitudeUnit();
63 * Returns the user-specified unit for a temperature
64 * @return The user-specified unit for a temperature
67 Unit
GetUserTemperatureUnit();
70 * Returns the user-specified unit for a horizontal speed
71 * @return The user-specified unit for a horizontal speed
74 Unit
GetUserSpeedUnit();
77 * Returns the user-specified unit for a task speed
78 * @return The user-specified unit for a task speed
81 Unit
GetUserTaskSpeedUnit();
84 * Returns the user-specified unit for a vertical speed
85 * @return The user-specified unit for a vertical speed
88 Unit
GetUserVerticalSpeedUnit();
91 * Returns the user-specified unit for a wind speed
92 * @return The user-specified unit for a wind speed
95 Unit
GetUserWindSpeedUnit();
98 * Returns the user-specified unit for a pressure
99 * @return The user-specified unit for a pressure
102 Unit
GetUserPressureUnit();
105 Unit
GetUserUnitByGroup(UnitGroup group
);
108 const TCHAR
*GetSpeedName();
111 const TCHAR
*GetVerticalSpeedName();
114 const TCHAR
*GetWindSpeedName();
117 const TCHAR
*GetDistanceName();
120 const TCHAR
*GetAltitudeName();
123 const TCHAR
*GetTemperatureName();
126 const TCHAR
*GetTaskSpeedName();
129 const TCHAR
*GetPressureName();
132 ToUserAltitude(fixed value
)
134 return ToUserUnit(value
, current
.altitude_unit
);
138 ToSysAltitude(fixed value
)
140 return ToSysUnit(value
, current
.altitude_unit
);
144 ToUserTemperature(fixed value
)
146 return ToUserUnit(value
, current
.temperature_unit
);
150 ToSysTemperature(fixed value
)
152 return ToSysUnit(value
, current
.temperature_unit
);
156 ToUserDistance(fixed value
)
158 return ToUserUnit(value
, current
.distance_unit
);
162 ToSysDistance(fixed value
)
164 return ToSysUnit(value
, current
.distance_unit
);
168 ToUserSpeed(fixed value
)
170 return ToUserUnit(value
, current
.speed_unit
);
174 ToSysSpeed(fixed value
)
176 return ToSysUnit(value
, current
.speed_unit
);
180 ToUserVSpeed(fixed value
)
182 return ToUserUnit(value
, current
.vertical_speed_unit
);
186 ToSysVSpeed(fixed value
)
188 return ToSysUnit(value
, current
.vertical_speed_unit
);
192 ToUserTaskSpeed(fixed value
)
194 return ToUserUnit(value
, current
.task_speed_unit
);
198 ToSysTaskSpeed(fixed value
)
200 return ToSysUnit(value
, current
.task_speed_unit
);
204 ToUserWindSpeed(fixed value
)
206 return ToUserUnit(value
, current
.wind_speed_unit
);
210 ToSysWindSpeed(fixed value
)
212 return ToSysUnit(value
, current
.wind_speed_unit
);
216 ToUserPressure(fixed Value
)
218 return ToUserUnit(Value
, current
.pressure_unit
);
223 ToUserPressure(AtmosphericPressure value
);
226 ToSysPressure(fixed Value
)
228 return ToSysUnit(Value
, current
.pressure_unit
);
232 * Convert a pressure value from the user unit to an
233 * #AtmosphericPressure object.
237 FromUserPressure(fixed value
);