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 #include "AirspaceFormatter.hpp"
26 #include "Engine/Airspace/AbstractAirspace.hpp"
27 #include "Engine/Airspace/AirspaceAltitude.hpp"
28 #include "Util/StaticString.hpp"
29 #include "Units/Units.hpp"
30 #include "Units/Descriptor.hpp"
33 AirspaceFormatter::FormatAltitudeShort(TCHAR
*buffer
,
34 const AirspaceAltitude
&altitude
)
36 switch (altitude
.reference
) {
37 case AltitudeReference::AGL
:
38 if (!positive(altitude
.altitude_above_terrain
))
39 _tcscpy(buffer
, _T("GND"));
41 _stprintf(buffer
, _T("%d %s AGL"),
42 iround(Units::ToUserAltitude(altitude
.altitude_above_terrain
)),
43 Units::GetAltitudeName());
46 case AltitudeReference::STD
:
47 _stprintf(buffer
, _T("FL%d"), (int)altitude
.flight_level
);
50 case AltitudeReference::MSL
:
51 _stprintf(buffer
, _T("%d %s"),
52 iround(Units::ToUserAltitude(altitude
.altitude
)),
53 Units::GetAltitudeName());
56 case AltitudeReference::NONE
:
63 AirspaceFormatter::FormatAltitude(TCHAR
*buffer
,
64 const AirspaceAltitude
&altitude
)
66 FormatAltitudeShort(buffer
, altitude
);
68 if ((altitude
.reference
== AltitudeReference::MSL
||
69 altitude
.reference
== AltitudeReference::AGL
) &&
70 Units::GetUserAltitudeUnit() == Unit::METER
)
71 /* additionally show airspace altitude in feet, because aviation
72 charts usually print altitudes in feet */
73 _stprintf(buffer
+ _tcslen(buffer
), _T(" (%d %s)"),
74 iround(Units::ToUserUnit(altitude
.altitude
, Unit::FEET
)),
75 Units::GetUnitName(Unit::FEET
));
77 if (altitude
.reference
!= AltitudeReference::MSL
&&
78 positive(altitude
.altitude
))
79 _stprintf(buffer
+ _tcslen(buffer
), _T(" %d %s"),
80 iround(Units::ToUserAltitude(altitude
.altitude
)),
81 Units::GetAltitudeName());