]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89_page_vor.cxx
Make traffic take-off roll look a little better.
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page_vor.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 - daveluff AT ntlworld.com
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_vor.hxx"
29 #include <Navaids/navrecord.hxx>
30
31 using std::string;
32
33 KLN89VorPage::KLN89VorPage(KLN89* parent) 
34 : KLN89Page(parent) {
35         _nSubPages = 2;
36         _subPage = 0;
37         _name = "VOR";
38         _vor_id = "OSI";        // TODO - check a property for an initial value to allow user-override.
39         np = NULL;
40 }
41
42 KLN89VorPage::~KLN89VorPage() {
43 }
44
45 void KLN89VorPage::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(_vor_id.size() == 3) exact = true;
50         if(np == NULL) {
51                 np = _kln89->FindFirstVorById(_vor_id, multi, exact);
52         } else if(np->get_ident() != _vor_id) {
53                 np = _kln89->FindFirstVorById(_vor_id, multi, exact);
54         }
55         //if(np == NULL) cout << "NULL... ";
56         //if(b == false) cout << "false...\n";
57         /*
58         if(np && b) {
59                 cout << "VOR FOUND!\n";
60         } else {
61                 cout << ":-(\n";
62         }
63         */
64         if(np) {
65                 //cout << np->id << '\n';
66                 _vor_id = np->get_ident();
67                 if(_kln89->GetActiveWaypoint()) {
68                         if(_vor_id == _kln89->GetActiveWaypoint()->id) {
69                                 if(!(_kln89->_waypointAlert && _kln89->_blink)) {
70                                         // Active waypoint arrow
71                                         _kln89->DrawSpecialChar(4, 2, 0, 3);
72                                 }
73                         }
74                 }
75                 if(_kln89->_mode != KLN89_MODE_CRSR) {
76                         if(!_entInvert) {
77                                 if(!actPage) {
78                                         _kln89->DrawText(np->get_ident(), 2, 1, 3);
79                                 } else {
80                                         // If it's the ACT page, The ID is shifted slightly right to make space for the waypoint index.
81                                         _kln89->DrawText(np->get_ident(), 2, 4, 3);
82                                         char buf[3];
83                                         int n = snprintf(buf, 3, "%i", _kln89->GetActiveWaypointIndex() + 1);
84                                         _kln89->DrawText((string)buf, 2, 3 - n, 3);
85                                 }
86                         } else {
87                                 if(!_kln89->_blink) {
88                                         _kln89->DrawText(np->get_ident(), 2, 1, 3, false, 99);
89                                         _kln89->DrawEnt();
90                                 }
91                         }
92                 }
93                 if(_subPage == 0) {
94                         //// TODO - will almost certainly have to process freq below for FG
95                         _kln89->DrawFreq(np->get_freq(), 2, 9, 3);
96                         // TODO - trim VOR-DME from the name, convert to uppercase, abbreviate, etc
97                         _kln89->DrawText(np->name(), 2, 0, 2);
98                         //cout << np->lat << "... ";
99                         _kln89->DrawLatitude(np->get_lat(), 2, 3, 1);
100                         _kln89->DrawLongitude(np->get_lon(), 2, 3, 0);
101                 } else {
102                         _kln89->DrawText("Mag Var", 2, 0, 2);
103                         ////float mvf = np->magvar * SG_RADIANS_TO_DEGREES;
104                         //// TODO FIXME BELOW
105                         float mvf = 0.0;
106                         _kln89->DrawChar((mvf <= 0 ? 'E' : 'W'), 2, 9, 2);
107                         int mvi = (int)(fabs(mvf) + 0.5);
108                         string mvs = GPSitoa(mvi);
109                         _kln89->DrawText(mvs, 2, 13 - mvs.size(), 2);
110                         _kln89->DrawSpecialChar(0, 2, 13, 2);
111                         _kln89->DrawDirDistField(np->get_lat() * SG_DEGREES_TO_RADIANS, np->get_lon() * SG_DEGREES_TO_RADIANS, 2, 0, 0, 
112                                                  _to_flag, (_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 4 ? true : false));
113                 }
114         } else {
115                 if(_kln89->_mode != KLN89_MODE_CRSR) _kln89->DrawText(_vor_id, 2, 1, 3);
116                 if(_subPage == 0) {
117                         _kln89->DrawText("---.--", 2, 9, 3);
118                         _kln89->DrawText("--------------", 2, 0, 2);
119                         _kln89->DrawText("- -- --.--'", 2, 3, 1);
120                         _kln89->DrawText("---- --.--'", 2, 3, 0);
121                         _kln89->DrawSpecialChar(0, 2, 7, 1);
122                         _kln89->DrawSpecialChar(0, 2, 7, 0);
123                 }
124         }
125         
126         if(_kln89->_mode == KLN89_MODE_CRSR) {
127                 if(_uLinePos > 0 && _uLinePos < 4) {
128                         // TODO - blink as well
129                         _kln89->Underline(2, _uLinePos, 3, 1);
130                 }
131                 for(unsigned int i = 0; i < _vor_id.size(); ++i) {
132                         if(_uLinePos != (i + 1)) {
133                                 _kln89->DrawChar(_vor_id[i], 2, i + 1, 3);
134                         } else {
135                                 if(!_kln89->_blink) _kln89->DrawChar(_vor_id[i], 2, i + 1, 3);
136                         }
137                 }
138         }
139         
140         _id = _vor_id;
141                         
142         KLN89Page::Update(dt);
143 }
144
145 void KLN89VorPage::SetId(const string& s) {
146         _last_vor_id = _vor_id;
147         _save_vor_id = _vor_id;
148         _vor_id = s;
149         np = NULL;
150 }
151
152 void KLN89VorPage::CrsrPressed() {
153         if(_kln89->_mode == KLN89_MODE_DISP) return;
154         if(_kln89->_obsMode) {
155                 _uLinePos = 0;
156         } else {
157                 _uLinePos = 1;
158         }
159         if(_subPage == 0) {
160                 _maxULinePos = 17;
161         } else {
162                 _maxULinePos = 4;
163         }
164 }
165
166 void KLN89VorPage::ClrPressed() {
167         if(_subPage == 1 && _uLinePos == 4) {
168                 _to_flag = !_to_flag;
169         }
170 }
171
172 void KLN89VorPage::EntPressed() {
173         if(_entInvert) {
174                 _entInvert = false;
175                 _entInvert = false;
176                 if(_kln89->_dtoReview) {
177                         _kln89->DtoInitiate(_vor_id);
178                 } else {
179                         _last_vor_id = _vor_id;
180                         _vor_id = _save_vor_id;
181                 }
182         }
183 }
184
185 void KLN89VorPage::Knob2Left1() {
186         if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
187                 KLN89Page::Knob2Left1();
188         } else {
189                 if(_uLinePos < 4) {
190                         // Same logic for both pages - set the ID
191                         _vor_id = _vor_id.substr(0, _uLinePos);
192                         // ASSERT(_uLinePos > 0);
193                         if(_uLinePos == (_vor_id.size() + 1)) {
194                                 _vor_id += '9';
195                         } else {
196                                 _vor_id[_uLinePos - 1] = _kln89->DecChar(_vor_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
197                         }
198                 } else {
199                         if(_subPage == 0) {
200                                 // set by name
201                         } else {
202                                 // NO-OP - from/to field is switched by clr button, not inner knob.
203                         }
204                 }
205         }
206 }
207
208 void KLN89VorPage::Knob2Right1() {
209         if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
210                 KLN89Page::Knob2Right1();
211         } else {
212                 if(_uLinePos < 4) {
213                         // Same logic for both pages - set the ID
214                         _vor_id = _vor_id.substr(0, _uLinePos);
215                         // ASSERT(_uLinePos > 0);
216                         if(_uLinePos == (_vor_id.size() + 1)) {
217                                 _vor_id += 'A';
218                         } else {
219                                 _vor_id[_uLinePos - 1] = _kln89->IncChar(_vor_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
220                         }
221                 } else {
222                         if(_subPage == 0) {
223                                 // set by name
224                         } else {
225                                 // NO-OP - from/to field is switched by clr button, not inner knob.
226                         }
227                 }
228         }
229 }