1 // kln89_page.hxx - a class to manage the simulation of a KLN89
2 // GPS unit. Note that this is primarily the
3 // simulation of the user interface and display
4 // - the core GPS calculations such as position
5 // and waypoint sequencing are done (or should
6 // be done) by FG code.
8 // Written by David Luff, started 2005.
10 // Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of the
15 // License, or (at your option) any later version.
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include <Instrumentation/dclgps.hxx>
32 #include "kln89_page.hxx"
34 const int KLN89MapScales[2][21] = {{1, 2, 3, 5, 7, 10, 12, 15, 17, 20, 25, 30, 40, 60, 80, 100, 120, 160, 240, 320, 500},
35 {2, 4, 6, 9, 13, 18, 22, 28, 32, 37, 46, 55, 75, 110, 150, 185, 220, 300, 440, 600, 925}};
43 const char* KLN89TimeCodes[20] = { "UTC", "GST", "GDT", "ATS", "ATD", "EST", "EDT", "CST", "CDT", "MST",
44 "MDT", "PST", "PDT", "AKS", "AKD", "HAS", "HAD", "SST", "SDT", "LCL" };
47 // Used for storing airport town and county mapped by ID, since currently FG does not store this
48 typedef map<string, string> airport_id_str_map_type;
49 typedef airport_id_str_map_type::iterator airport_id_str_map_iterator;
51 class KLN89 : public DCLGPS {
53 friend class KLN89Page;
54 friend class KLN89AptPage;
55 friend class KLN89VorPage;
56 friend class KLN89NDBPage;
57 friend class KLN89IntPage;
58 friend class KLN89UsrPage;
59 friend class KLN89ActPage;
60 friend class KLN89NavPage;
61 friend class KLN89FplPage;
62 friend class KLN89CalPage;
63 friend class KLN89SetPage;
64 friend class KLN89OthPage;
65 friend class KLN89DirPage;
66 friend class KLN89NrstPage;
69 KLN89(RenderArea2D* instrument);
74 void update(double dt);
76 inline void SetTurnAnticipation(bool b) { _turnAnticipationEnabled = b; }
77 inline bool GetTurnAnticipation() { return(_turnAnticipationEnabled); }
79 inline void SetSuaAlertEnabled(bool b) { _suaAlertEnabled = b; }
80 inline bool GetSuaAlertEnabled() { return(_suaAlertEnabled); }
82 inline void SetAltAlertEnabled(bool b) { _altAlertEnabled = b; }
83 inline bool GetAltAlertEnabled() { return(_altAlertEnabled); }
85 inline bool GetMsgAlert() const { return(!_messageStack.empty()); }
100 void CreateDefaultFlightPlans();
103 //----------------------- Drawing functions which take CHARACTER units -------------------------
104 // Render string s in display field field at position x, y
105 // WHERE POSITION IS IN CHARACTER UNITS!
107 // invert: -1 => no inversion, 0 -> n => 1 char - s[invert] gets inverted, 99 => entire string gets inverted
108 void DrawText(const string& s, int field, int px, int py, bool bold = false, int invert = -1);
110 void DrawLatitude(double d, int field, int px, int py);
111 void DrawLongitude(double d, int field, int px, int py);
113 // Draw a frequency as xxx.xx
114 void DrawFreq(double d, int field, int px, int py);
116 // Draw a time in seconds as hh:mm
117 // NOTE: px is RIGHT JUSTIFIED!
118 void DrawTime(double time, int field, int px, int py);
120 // Draw an integer heading, where px specifies the position of the degrees sign at the RIGHT of the value.
121 void DrawHeading(int h, int field, int px, int py);
123 // Draw a distance spec'd as nm as an integer (TODO - may need 1 decimal place if < 100) where px specifies RHS of units.
124 // Some uses definately don't want decimal place though (as at present), so would have to be arg.
125 void DrawDist(double d, int field, int px, int py);
127 // Draw a speed specifed in knots. px is RHS of the units. Can draw up to 2 decimal places.
128 void DrawSpeed(double v, int field, int px, int py, int decimals = 0);
130 void Underline(int field, int px, int py, int len);
132 // Render a char at a given position as above (position in CHARACTER units)
133 void DrawChar(char c, int field, int px, int py, bool bold = false, bool invert = false);
134 void DrawSpecialChar(char c, int field, int cx, int cy, bool bold = false);
136 // Draws the dir/dist field at the bottom of the main field
137 void DrawDirDistField(double lat, double lon, int field, int px, int py, bool to_flag = true, bool cursel = false);
139 //--------------------------------- end char units -----------------------------------------------
141 //----------------------- Drawing functions which take PIXEL units ------------------------------
143 // Takes instrument *pixel* co-ordinates NOT character units
144 // Position is specified by the bottom of the *visible* portion, by default the left position unless align_right is true.
145 // The return value is the pixel width of the visible portion
146 int DrawSmallChar(char c, int x, int y, bool align_right = false);
148 void DrawFreeChar(char c, int x, int y, bool draw_background = false);
150 //----------------------------------- end pixel unit functions -----------------------------------
154 void DrawEnt(int field = 1, int px = 0, int py = 1);
156 void DrawMessageAlert();
158 void DrawKPH(int field, int cx, int cy);
160 void DrawDTO(int field, int cx, int cy);
162 // Draw the bar that indicates which page we're on (zero-based)
163 void DrawBar(int page);
167 void DrawLegTail(int py);
168 void DrawLongLegTail(int py);
169 void DrawHalfLegTail(int py);
171 void UpdateMapHeading();
173 // Draw the moving map
174 // Apt, VOR and SUA drawing can be suspended by setting draw_avs to false, without affecting the stored drawing preference state.
175 void DrawMap(bool draw_avs = true);
177 // Set whether the display should be draw pixelated (more primatives, but might be closer to real-life)
178 // or not (in which case it is assumed that pixels are square and can be merged into quads).
181 // Flashing output should be hidden when blink is true
186 // In Crsr mode, CRSR pressed events are passed to the active page, in disp mode they change which page is active
188 // And the facility to save a mode
191 // Increment/Decrement a character in the KLN89 A-Z,0-9 scheme.
192 // Set gap to true to get a space between A and 9 when wrapping, set wrap to false to disable wrap.
193 char IncChar(char c, bool gap = false, bool wrap = true);
194 char DecChar(char c, bool gap = false, bool wrap = true);
197 int _entJump; // The page to jump back to if ent is pressed. -1 indicates no jump
198 bool _entRestoreCrsr; // Indicates that pressing ENT at this point should restore cursor mode
206 // Moving-map display stuff
207 int _mapOrientation; // 0 => North (true) up, 1 => DTK up, 2 => TK up, 3 => heading up (only when connected to external heading source).
208 double _mapHeading; // Degrees. The actual map heading gets updated at a lower frequency than DrawMap() is called at, hence we need to store it.
209 double _mapHeadingUpdateTimer; // Timer to determine when to update the above.
210 bool _mapScaleAuto; // Indicates that map should autoscale when true.
211 int _mapScaleIndex; // Index into array of available map scales.
212 int _mapScaleUnits; // 0 => nm, 1 => km.
213 double _mapScale; // nm or km from aircraft position to top of map.
214 // Note that aircraft position differs depending on orientation, but 'scale' retains the same meaning,
215 // so the scale per pixel alters to suit the defined scale when the rendered aircraft position changes.
216 bool _drawSUA; // special user airspace
220 // Convert map to instrument coordinates
221 void MapToInstrument(int &x, int &y);
223 // The following map drawing functions all take MAP co-ordinates, NOT instrument co-ordinates!
225 // Draw the diamond style of user pos
226 void DrawUser1(int x, int y);
228 // Draw the airplane style of user pos
229 void DrawUser2(int x, int y);
231 // Draw an airport symbol on the moving map
232 void DrawApt(int x, int y);
234 // Draw a waypoint on the moving map
235 void DrawWaypoint(int x, int y);
237 // Draw a VOR on the moving map
238 void DrawVOR(int x, int y);
240 // Draw an airport or waypoint label on the moving map
241 // Specify position by the map pixel co-ordinate of the left or right, bottom, of the *visible* portion of the label.
242 // The black background quad will automatically overlap this by 1 pixel.
243 void DrawLabel(const string& s, int x1, int y1, bool right_align = false);
245 int GetLabelQuadrant(double h);
246 int GetLabelQuadrant(double h1, double h2);
248 // Draw a line on the moving map
249 void DrawLine(int x1, int y1, int x2, int y2);
251 // Draw normal sized text on the moving map
252 void DrawMapText(const string& s, int x, int y, bool draw_background = false);
254 void DrawMapUpArrow(int x, int y);
256 // Draw a Quad on the moving map
257 void DrawMapQuad(int x1, int y1, int x2, int y2, bool invert = false);
259 // Airport town and state mapped by ID, since currently FG does not store this
260 airport_id_str_map_type _airportTowns;
261 airport_id_str_map_type _airportStates;
263 // NOTE - It is a deliberate decision not to have a proper message page class,
264 // since button events get directed to the page that was active before the
265 // message was displayed, not the message page itself.
266 bool _dispMsg; // Set true while the message page is being displayed