]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89.hxx
KLN89: Add initial implemenation of ALT pages.
[flightgear.git] / src / Instrumentation / KLN89 / kln89.hxx
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. 
7 //
8 // Written by David Luff, started 2005.
9 //
10 // Copyright (C) 2005 - David C Luff - daveluff AT ntlworld.com
11 //
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.
16 //
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.
21 //
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.
25 //
26 // $Id$
27
28 #ifndef _KLN89_HXX
29 #define _KLN89_HXX
30
31 #include <Instrumentation/dclgps.hxx>
32 #include "kln89_page.hxx"
33
34 class KLN89Page;
35
36 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},
37                                        {2, 4, 6, 9, 13, 18, 22, 28, 32, 37, 46, 55, 75, 110, 150, 185, 220, 300, 440, 600, 925}};
38
39 enum KLN89Mode {
40         KLN89_MODE_DISP,
41         KLN89_MODE_CRSR
42 };
43
44 /*
45 const char* KLN89TimeCodes[20] = { "UTC", "GST", "GDT", "ATS", "ATD", "EST", "EDT", "CST", "CDT", "MST", 
46                                    "MDT", "PST", "PDT", "AKS", "AKD", "HAS", "HAD", "SST", "SDT", "LCL" };
47 */
48
49 // Used for storing airport town and county mapped by ID, since currently FG does not store this
50 typedef map<string, string> airport_id_str_map_type;
51 typedef airport_id_str_map_type::iterator airport_id_str_map_iterator;
52
53 typedef vector<KLN89Page*> kln89_page_list_type;
54 typedef kln89_page_list_type::iterator kln89_page_list_itr;
55
56 class KLN89 : public DCLGPS {
57         
58         friend class KLN89Page;
59         friend class KLN89AptPage;
60         friend class KLN89VorPage;
61         friend class KLN89NDBPage;
62         friend class KLN89IntPage;
63         friend class KLN89UsrPage;
64         friend class KLN89ActPage;
65         friend class KLN89NavPage;
66         friend class KLN89FplPage;
67         friend class KLN89CalPage;
68         friend class KLN89SetPage;
69         friend class KLN89OthPage;
70         friend class KLN89AltPage;
71         friend class KLN89DirPage;
72         friend class KLN89NrstPage;
73         
74 public:
75         KLN89(RenderArea2D* instrument);
76         ~KLN89();
77         
78         void bind();
79         void unbind();
80         void init();
81         void update(double dt);
82         
83         inline void SetTurnAnticipation(bool b) { _turnAnticipationEnabled = b; }
84         inline bool GetTurnAnticipation() { return(_turnAnticipationEnabled); }
85
86         inline void SetSuaAlertEnabled(bool b) { _suaAlertEnabled = b; }
87         inline bool GetSuaAlertEnabled() { return(_suaAlertEnabled); }
88         
89         inline void SetAltAlertEnabled(bool b) { _altAlertEnabled = b; }
90         inline bool GetAltAlertEnabled() { return(_altAlertEnabled); }
91
92         void SetMinDisplayBrightness(int n);    // Set minDisplayBrightness (between 1 and 9)
93         void DecrementMinDisplayBrightness();   // Decrease by 1
94         void IncrementMinDisplayBrightness();   // Increase by 1
95         inline int GetMinDisplayBrightness() { return(_minDisplayBrightness); }
96         
97         inline bool GetMsgAlert() const { return(!_messageStack.empty()); }
98         
99         void Knob1Right1();
100         void Knob1Left1();
101         void Knob2Right1();
102         void Knob2Left1();
103         void CrsrPressed();
104         void EntPressed();
105         void ClrPressed();
106         void DtoPressed();
107         void NrstPressed();
108         void AltPressed();
109         void OBSPressed();
110         void MsgPressed();
111         
112         void CreateDefaultFlightPlans();
113
114 private:
115         void ToggleOBSMode();
116         
117         // Initiate Direct To operation to the supplied ID.
118         void DtoInitiate(const string& id);
119
120         //----------------------- Drawing functions which take CHARACTER units -------------------------
121         // Render string s in display field field at position x, y
122         // WHERE POSITION IS IN CHARACTER UNITS!
123         // zero y at bottom?
124         // invert: -1 => no inversion, 0 -> n => 1 char - s[invert] gets inverted, 99 => entire string gets inverted 
125         void DrawText(const string& s, int field, int px, int py, bool bold = false, int invert = -1);
126         
127         void DrawLatitude(double d, int field, int px, int py);
128         void DrawLongitude(double d, int field, int px, int py);
129
130         // Draw a frequency as xxx.xx
131         void DrawFreq(double d, int field, int px, int py);
132         
133         // Draw a time in seconds as hh:mm
134         // NOTE: px is RIGHT JUSTIFIED!
135         void DrawTime(double time, int field, int px, int py);
136
137         // Draw an integer heading, where px specifies the position of the degrees sign at the RIGHT of the value.
138         void DrawHeading(int h, int field, int px, int py);
139         
140         // Draw a distance spec'd as nm as an integer (TODO - may need 1 decimal place if < 100) where px specifies RHS of units.
141         // Some uses definately don't want decimal place though (as at present), so would have to be arg.
142         void DrawDist(double d, int field, int px, int py);
143         
144         // Draw a speed specifed in knots.  px is RHS of the units.  Can draw up to 2 decimal places.
145         void DrawSpeed(double v, int field, int px, int py, int decimals = 0);
146         
147         void Underline(int field, int px, int py, int len);
148         
149         // Render a char at a given position as above (position in CHARACTER units)
150         void DrawChar(char c, int field, int px, int py, bool bold = false, bool invert = false);
151         void DrawSpecialChar(char c, int field, int cx, int cy, bool bold = false);
152         
153         // Draws the dir/dist field at the bottom of the main field
154         void DrawDirDistField(double lat, double lon, int field, int px, int py, bool to_flag = true, bool cursel = false);
155         //
156         //--------------------------------- end char units -----------------------------------------------
157         
158         //----------------------- Drawing functions which take PIXEL units ------------------------------
159         //
160         // Takes instrument *pixel* co-ordinates NOT character units
161         // Position is specified by the bottom of the *visible* portion, by default the left position unless align_right is true.
162         // The return value is the pixel width of the visible portion
163         int DrawSmallChar(char c, int x, int y, bool align_right = false);
164         
165         void DrawFreeChar(char c, int x, int y, bool draw_background = false);
166         //
167         //----------------------------------- end pixel unit functions -----------------------------------
168         
169         void DrawDivider();
170         
171         void DrawEnt(int field = 1, int px = 0, int py = 1);
172         
173         void DrawMessageAlert();
174         
175         void DrawKPH(int field, int cx, int cy);
176         
177         void DrawDTO(int field, int cx, int cy);
178         
179         // Draw the bar that indicates which page we're on (zero-based)
180         void DrawBar(int page);
181         
182         void DrawCDI();
183         
184         void DrawLegTail(int py);
185         void DrawLongLegTail(int py);
186         void DrawHalfLegTail(int py);
187         
188         void UpdateMapHeading();
189         
190         // Draw the moving map
191         // Apt, VOR and SUA drawing can be suspended by setting draw_avs to false, without affecting the stored drawing preference state.
192         void DrawMap(bool draw_avs = true);
193         
194         // Set whether the display should be draw pixelated (more primatives, but might be closer to real-life)
195         // or not (in which case it is assumed that pixels are square and can be merged into quads).
196         bool _pixelated;
197         
198         // Flashing output should be hidden when blink is true 
199         bool _blink;
200         
201         double _cum_dt;
202         
203         // In Crsr mode, CRSR pressed events are passed to the active page, in disp mode they change which page is active
204         KLN89Mode _mode;
205         // And the facility to save a mode
206         KLN89Mode _lastMode;
207         
208         // Increment/Decrement a character in the KLN89 A-Z,0-9 scheme.  
209         // Set gap to true to get a space between A and 9 when wrapping, set wrap to false to disable wrap.
210         char IncChar(char c, bool gap = false, bool wrap = true);
211         char DecChar(char c, bool gap = false, bool wrap = true);
212
213         // ==================== Page organisation stuff =============
214         // The list of cyclical pages that the user can cycle through
215         kln89_page_list_type _pages;
216         
217         // The currently active page
218         KLN89Page* _activePage;
219         // And a facility to save the immediately preceeding active page
220         KLN89Page* _lastActivePage;
221         
222         // Ugly hack.  Housekeeping to allow us to temporarily display one page, while remembering which
223         // other page to "jump" back to.  Used when the waypoint pages are used to review waypoint entry
224         // from the flightplan page.
225         int _entJump;   // The page to jump back to if ENT is pressed.  -1 indicates no jump.
226         int _clrJump;   // The page to jump back to if CLR is pressed.  -1 indicates no jump.
227         bool _jumpRestoreCrsr;  // Indicates that jump back at this point should restore cursor mode.
228         
229         // Misc pages that aren't in the cyclic list.
230         // ALT
231         KLN89Page* _alt_page;
232         // Direct To
233         KLN89Page* _dir_page;
234         // Nearest
235         KLN89Page* _nrst_page;
236         // ====================== end of page stuff ===================
237         
238         // Moving-map display stuff
239         int _mapOrientation;    // 0 => North (true) up, 1 => DTK up, 2 => TK up, 3 => heading up (only when connected to external heading source).
240         double _mapHeading;             // Degrees.  The actual map heading gets updated at a lower frequency than DrawMap() is called at, hence we need to store it.
241         double _mapHeadingUpdateTimer;  // Timer to determine when to update the above.
242         bool _mapScaleAuto;             // Indicates that map should autoscale when true.
243         int _mapScaleIndex;             // Index into array of available map scales.
244         int _mapScaleUnits;             // 0 => nm, 1 => km.
245         double _mapScale;       // nm or km from aircraft position to top of map.
246                                                 // Note that aircraft position differs depending on orientation, but 'scale' retains the same meaning,
247                                                 // so the scale per pixel alters to suit the defined scale when the rendered aircraft position changes.
248         bool _drawSUA;  // special user airspace
249         bool _drawVOR;
250         bool _drawApt;
251         
252         // Convert map to instrument coordinates
253         void MapToInstrument(int &x, int &y);
254         
255         // The following map drawing functions all take MAP co-ordinates, NOT instrument co-ordinates!
256         
257         // Draw the diamond style of user pos
258         void DrawUser1(int x, int y);
259
260         // Draw the airplane style of user pos
261         void DrawUser2(int x, int y);
262         
263         // Draw an airport symbol on the moving map
264         void DrawApt(int x, int y);
265         
266         // Draw a waypoint on the moving map
267         void DrawWaypoint(int x, int y);
268         
269         // Draw a VOR on the moving map
270         void DrawVOR(int x, int y);
271         
272         // Draw an airport or waypoint label on the moving map
273         // Specify position by the map pixel co-ordinate of the left or right, bottom, of the *visible* portion of the label.
274         // The black background quad will automatically overlap this by 1 pixel.
275         void DrawLabel(const string& s, int x1, int y1, bool right_align = false);
276         
277         int GetLabelQuadrant(double h);
278         int GetLabelQuadrant(double h1, double h2);
279         
280         // Draw a line on the moving map
281         void DrawLine(int x1, int y1, int x2, int y2);
282         
283         // Draw normal sized text on the moving map
284         void DrawMapText(const string& s, int x, int y, bool draw_background = false);
285         
286         void DrawMapUpArrow(int x, int y);
287         
288         // Draw a Quad on the moving map
289         void DrawMapQuad(int x1, int y1, int x2, int y2, bool invert = false);
290         
291         // Airport town and state mapped by ID, since currently FG does not store this
292         airport_id_str_map_type _airportTowns;
293         airport_id_str_map_type _airportStates;
294         
295         // NOTE - It is a deliberate decision not to have a proper message page class,
296         // since button events get directed to the page that was active before the
297         // message was displayed, not the message page itself.
298         bool _dispMsg;  // Set true while the message page is being displayed
299         
300         // Sometimes the datapages can be used to review a waypoint whilst the user makes a decision,
301         // and we need to remember why.
302         bool _dtoReview;        // Set true when we a reviewing a waypoint for DTO operation.
303         
304         // Configuration settings that the user can set via. the KLN89 SET pages.
305         bool _suaAlertEnabled;          // Alert user to potential SUA entry
306         bool _altAlertEnabled;          // Alert user to min safe alt violation
307         int _minDisplayBrightness;      // Minimum display brightness in low light.
308         char _defaultFirstChar;         // Default first waypoint character.
309         
310         // The user-settable barometric pressure.
311         // This can be set in the range 22.00 -> 32.99", or 745 -> 1117mB/hPa.
312         // For user input, we maintain a single integer value that is either between 2200 and 3299 (")
313         // or between 745 and 1117 (mB/hPa).  It gets converted from one to the other only when the
314         // units are changed.
315         // For internal VNAV calculations (which we don't currently do) this will be converted to a floating
316         // point value before use.
317         int _userBaroSetting;
318 };
319
320 #endif  // _KLN89_HXX