]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89_page_int.cxx
- fix unzoomed tapes (TODO: restore tick length)
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page_int.cxx
1 // kln89_page_*.[ch]xx - this file is one of the "pages" that
2 //                       are used in the KLN89 GPS unit simulation. 
3 //
4 // Written by David Luff, started 2005.
5 //
6 // Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "kln89_page_int.hxx"
29
30 KLN89IntPage::KLN89IntPage(KLN89* parent) 
31 : KLN89Page(parent) {
32         _nSubPages = 2;
33         _subPage = 0;
34         _name = "INT";
35         _int_id = "PORTE";
36         _last_int_id = "";
37         _fp = NULL;
38         _nearestVor = NULL;
39         _refNav = NULL;
40 }
41
42 KLN89IntPage::~KLN89IntPage() {
43 }
44
45 void KLN89IntPage::Update(double dt) {
46         bool actPage = (_kln89->_activePage->GetName() == "ACT" ? true : false);
47         bool multi;  // Not set by FindFirst...
48         bool exact = false;
49         if(_int_id.size() == 5) exact = true;
50         if(_fp == NULL) {
51                 _fp = _kln89->FindFirstIntById(_int_id, multi, exact);
52         } else if(_fp->get_ident() != _int_id) {
53                 _fp = _kln89->FindFirstIntById(_int_id, multi, exact);
54         }
55         
56         if(_fp) {
57                 _int_id = _fp->get_ident();
58                 if(_kln89->GetActiveWaypoint()) {
59                         if(_int_id == _kln89->GetActiveWaypoint()->id) {
60                                 if(!(_kln89->_waypointAlert && _kln89->_blink)) {
61                                         // Active waypoint arrow
62                                         _kln89->DrawSpecialChar(4, 2, 0, 3);
63                                 }
64                         }
65                 }
66                 if(_int_id != _last_int_id) {
67                         _nearestVor = _kln89->FindClosestVor(_fp->get_lat() * SG_DEGREES_TO_RADIANS, _fp->get_lon() * SG_DEGREES_TO_RADIANS);
68                         if(_nearestVor) {
69                                 _nvRadial = _kln89->GetMagHeadingFromTo(_nearestVor->get_lat() * SG_DEGREES_TO_RADIANS, _nearestVor->get_lon() * SG_DEGREES_TO_RADIANS,
70                                                                     _fp->get_lat() * SG_DEGREES_TO_RADIANS, _fp->get_lon() * SG_DEGREES_TO_RADIANS);
71                                 _nvDist = _kln89->GetGreatCircleDistance(_nearestVor->get_lat() * SG_DEGREES_TO_RADIANS, _nearestVor->get_lon() * SG_DEGREES_TO_RADIANS,
72                                                                      _fp->get_lat() * SG_DEGREES_TO_RADIANS, _fp->get_lon() * SG_DEGREES_TO_RADIANS);
73                                 _refNav = _nearestVor;  // TODO - check that this *always* holds - eg. when changing INT id after explicitly setting ref nav 
74                                                                         // but with no loss of focus.
75                         } else {
76                                 _refNav = NULL;
77                         }
78                         _last_int_id = _int_id;
79                 }
80                 if(_kln89->_mode != KLN89_MODE_CRSR) {
81                         if(!_entInvert) {
82                                 if(!actPage) {
83                                         _kln89->DrawText(_fp->get_ident(), 2, 1, 3);
84                                 } else {
85                                         // If it's the ACT page, The ID is shifted slightly right to make space for the waypoint index.
86                                         _kln89->DrawText(_fp->get_ident(), 2, 4, 3);
87                                         char buf[3];
88                                         int n = snprintf(buf, 3, "%i", _kln89->GetActiveWaypointIndex() + 1);
89                                         _kln89->DrawText((string)buf, 2, 3 - n, 3);
90                                         // We also draw an I to differentiate INT from USR when it's the ACT page
91                                         _kln89->DrawText("I", 2, 11, 3);
92                                 }
93                         } else {
94                                 if(!_kln89->_blink) {
95                                         _kln89->DrawText(_fp->get_ident(), 2, 1, 3, false, 99);
96                                         _kln89->DrawEnt();
97                                 }
98                         }
99                 }
100                 if(_subPage == 0) {
101                         _kln89->DrawLatitude(_fp->get_lat(), 2, 3, 2);
102                         _kln89->DrawLongitude(_fp->get_lon(), 2, 3, 1);
103                         _kln89->DrawDirDistField(_fp->get_lat() * SG_DEGREES_TO_RADIANS, _fp->get_lon() * SG_DEGREES_TO_RADIANS, 2, 0, 0, 
104                                                  _to_flag, (_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 6 ? true : false));
105                 } else {
106                         _kln89->DrawText("Ref:", 2, 1, 2);
107                         _kln89->DrawText("Rad:", 2, 1, 1);
108                         _kln89->DrawText("Dis:", 2, 1, 0);
109                         if(_refNav) {
110                                 _kln89->DrawText(_refNav->get_ident(), 2, 9, 2);        // TODO - flash and allow to change if under cursor
111                                 //_kln89->DrawHeading(_nvRadial, 2, 11, 1);
112                                 //_kln89->DrawDist(_nvDist, 2, 11, 0);
113                                 // Currently our draw heading and draw dist functions don't do as many decimal points as we want here,
114                                 // so draw it ourselves!
115                                 // Heading
116                                 char buf[10];
117                                 snprintf(buf, 6, "%.1f", _nvRadial);
118                                 string s = buf;
119                                 _kln89->DrawText(s, 2, 13 - s.size(), 1);
120                                 _kln89->DrawSpecialChar(0, 2, 13, 1);   // Degrees symbol
121                                 // Dist
122                                 double d = _nvDist;
123                                 d *= (_kln89->_distUnits == GPS_DIST_UNITS_NM ? 1.0 : SG_NM_TO_METER * 0.001);
124                                 snprintf(buf, 9, "%.1f", d);
125                                 s = buf;
126                                 s += (_kln89->_distUnits == GPS_DIST_UNITS_NM ? "nm" : "Km");
127                                 _kln89->DrawText(s, 2, 14 - s.size(), 0);
128                         }
129                 }
130         } else {
131                 // TODO - when we leave the page with invalid id and return it should
132                 // revert to showing the last valid id.  Same for vor/ndb/probably apt etc.
133                 if(_kln89->_mode != KLN89_MODE_CRSR) _kln89->DrawText(_int_id, 2, 1, 3);
134                 if(_subPage == 0) {
135                         _kln89->DrawText("- -- --.--'", 2, 3, 2);
136                         _kln89->DrawText("---- --.--'", 2, 3, 1);
137                         _kln89->DrawSpecialChar(0, 2, 7, 2);
138                         _kln89->DrawSpecialChar(0, 2, 7, 1);
139                         _kln89->DrawText(">---    ----", 2, 0, 0);
140                         _kln89->DrawSpecialChar(0, 2, 4, 0);
141                         _kln89->DrawText(_to_flag ? "To" : "Fr", 2, 5, 0);
142                         _kln89->DrawText(_kln89->_distUnits == GPS_DIST_UNITS_NM ? "nm" : "km", 2, 12, 0);
143                 }
144         }
145         
146         if(_kln89->_mode == KLN89_MODE_CRSR) {
147                 if(_uLinePos > 0 && _uLinePos < 6) {
148                         // TODO - blink as well
149                         _kln89->Underline(2, _uLinePos, 3, 1);
150                 }
151                 for(unsigned int i = 0; i < _int_id.size(); ++i) {
152                         if(_uLinePos != (i + 1)) {
153                                 _kln89->DrawChar(_int_id[i], 2, i + 1, 3);
154                         } else {
155                                 if(!_kln89->_blink) _kln89->DrawChar(_int_id[i], 2, i + 1, 3);
156                         }
157                 }
158         }
159         
160         // TODO - fix this duplication - use _id instead of _apt_id, _vor_id, _ndb_id, _int_id etc!
161         _id = _int_id;
162         
163         KLN89Page::Update(dt);
164 }
165
166 void KLN89IntPage::SetId(const string& s) {
167         _last_int_id = _int_id;
168         _save_int_id = _int_id;
169         _int_id = s;
170         _fp = NULL;
171 }
172
173 void KLN89IntPage::CrsrPressed() {
174         if(_kln89->_mode == KLN89_MODE_DISP) return;
175         if(_kln89->_obsMode) {
176                 _uLinePos = 0;
177         } else {
178                 _uLinePos = 1;
179         }
180         if(_subPage == 0) {
181                 _maxULinePos = 6;
182         } else {
183                 _maxULinePos = 6;
184         }
185 }
186
187 void KLN89IntPage::ClrPressed() {
188         if(_subPage == 0 && _uLinePos == 6) {
189                 _to_flag = !_to_flag;
190         }
191 }
192
193 void KLN89IntPage::EntPressed() {
194         if(_entInvert) {
195                 _entInvert = false;
196                 _last_int_id = _int_id;
197                 _int_id = _save_int_id;
198         }
199 }
200
201 void KLN89IntPage::Knob2Left1() {
202         if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
203                 KLN89Page::Knob2Left1();
204         } else {
205                 if(_uLinePos < 6) {
206                         // Same logic for both pages - set the ID
207                         _int_id = _int_id.substr(0, _uLinePos);
208                         // ASSERT(_uLinePos > 0);
209                         if(_uLinePos == (_int_id.size() + 1)) {
210                                 _int_id += '9';
211                         } else {
212                                 _int_id[_uLinePos - 1] = _kln89->DecChar(_int_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
213                         }
214                 } else {
215                         if(_subPage == 0) {
216                                 // NO-OP - from/to field is switched by clr button, not inner knob.
217                         } else {
218                                 // TODO - LNR type field.
219                         }
220                 }
221         }
222 }
223
224 void KLN89IntPage::Knob2Right1() {
225         if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
226                 KLN89Page::Knob2Right1();
227         } else {
228                 if(_uLinePos < 6) {
229                         // Same logic for both pages - set the ID
230                         _int_id = _int_id.substr(0, _uLinePos);
231                         // ASSERT(_uLinePos > 0);
232                         if(_uLinePos == (_int_id.size() + 1)) {
233                                 _int_id += 'A';
234                         } else {
235                                 _int_id[_uLinePos - 1] = _kln89->IncChar(_int_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
236                         }
237                 } else {
238                         if(_subPage == 0) {
239                                 // NO-OP - from/to field is switched by clr button, not inner knob.
240                         } else {
241                                 // TODO - LNR type field.
242                         }
243                 }
244         }
245 }
246