1 // kln89_page_*.[ch]xx - this file is one of the "pages" that
2 // are used in the KLN89 GPS unit simulation.
4 // Written by David Luff, started 2005.
6 // Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
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.
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.
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.
28 #include "kln89_page_ndb.hxx"
29 #include <Navaids/navrecord.hxx>
31 KLN89NDBPage::KLN89NDBPage(KLN89* parent)
40 KLN89NDBPage::~KLN89NDBPage() {
43 void KLN89NDBPage::Update(double dt) {
44 bool actPage = (_kln89->_activePage->GetName() == "ACT" ? true : false);
45 bool multi; // Not set by FindFirst...
47 if(_ndb_id.size() == 3) exact = true;
49 np = _kln89->FindFirstNDBById(_ndb_id, multi, exact);
50 } else if(np->get_ident() != _ndb_id) {
51 np = _kln89->FindFirstNDBById(_ndb_id, multi, exact);
53 //if(np == NULL) cout << "NULL... ";
54 //if(b == false) cout << "false...\n";
57 cout << "VOR FOUND!\n";
63 //cout << np->id << '\n';
64 _ndb_id = np->get_ident();
65 if(_kln89->GetActiveWaypoint()) {
66 if(_ndb_id == _kln89->GetActiveWaypoint()->id) {
67 if(!(_kln89->_waypointAlert && _kln89->_blink)) {
68 // Active waypoint arrow
69 _kln89->DrawSpecialChar(4, 2, 0, 3);
73 if(_kln89->_mode != KLN89_MODE_CRSR) {
76 _kln89->DrawText(np->get_ident(), 2, 1, 3);
78 // If it's the ACT page, The ID is shifted slightly right to make space for the waypoint index.
79 _kln89->DrawText(np->get_ident(), 2, 4, 3);
81 int n = snprintf(buf, 3, "%i", _kln89->GetActiveWaypointIndex() + 1);
82 _kln89->DrawText((string)buf, 2, 3 - n, 3);
86 _kln89->DrawText(np->get_ident(), 2, 1, 3, false, 99);
92 // TODO - trim VOR-DME from the name, convert to uppercase, abbreviate, etc
93 _kln89->DrawText(np->name(), 2, 0, 2);
94 _kln89->DrawLatitude(np->get_lat(), 2, 3, 1);
95 _kln89->DrawLongitude(np->get_lon(), 2, 3, 0);
97 _kln89->DrawDirDistField(np->get_lat() * SG_DEGREES_TO_RADIANS, np->get_lon() * SG_DEGREES_TO_RADIANS,
98 2, 0, 0, _to_flag, (_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 4 ? true : false));
101 if(_kln89->_mode != KLN89_MODE_CRSR) _kln89->DrawText(_ndb_id, 2, 1, 3);
103 _kln89->DrawText("----.-", 2, 9, 3);
104 _kln89->DrawText("--------------", 2, 0, 2);
105 _kln89->DrawText("- -- --.--'", 2, 3, 1);
106 _kln89->DrawText("---- --.--'", 2, 3, 0);
107 _kln89->DrawSpecialChar(0, 2, 7, 1);
108 _kln89->DrawSpecialChar(0, 2, 7, 0);
112 if(_kln89->_mode == KLN89_MODE_CRSR) {
113 if(_uLinePos > 0 && _uLinePos < 4) {
114 // TODO - blink as well
115 _kln89->Underline(2, _uLinePos, 3, 1);
117 for(unsigned int i = 0; i < _ndb_id.size(); ++i) {
118 if(_uLinePos != (i + 1)) {
119 _kln89->DrawChar(_ndb_id[i], 2, i + 1, 3);
121 if(!_kln89->_blink) _kln89->DrawChar(_ndb_id[i], 2, i + 1, 3);
128 KLN89Page::Update(dt);
131 void KLN89NDBPage::SetId(const string& s) {
132 _last_ndb_id = _ndb_id;
133 _save_ndb_id = _ndb_id;
138 void KLN89NDBPage::CrsrPressed() {
139 if(_kln89->_mode == KLN89_MODE_DISP) return;
140 if(_kln89->_obsMode) {
152 void KLN89NDBPage::ClrPressed() {
153 if(_subPage == 1 && _uLinePos == 4) {
154 _to_flag = !_to_flag;
158 void KLN89NDBPage::EntPressed() {
161 if(_kln89->_dtoReview) {
162 _kln89->DtoInitiate(_ndb_id);
164 _last_ndb_id = _ndb_id;
165 _ndb_id = _save_ndb_id;
170 void KLN89NDBPage::Knob2Left1() {
171 if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
172 KLN89Page::Knob2Left1();
175 // Same logic for both pages - set the ID
176 _ndb_id = _ndb_id.substr(0, _uLinePos);
177 // ASSERT(_uLinePos > 0);
178 if(_uLinePos == (_ndb_id.size() + 1)) {
181 _ndb_id[_uLinePos - 1] = _kln89->DecChar(_ndb_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
187 // NO-OP - from/to field is switched by clr button, not inner knob.
193 void KLN89NDBPage::Knob2Right1() {
194 if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
195 KLN89Page::Knob2Right1();
198 // Same logic for both pages - set the ID
199 _ndb_id = _ndb_id.substr(0, _uLinePos);
200 // ASSERT(_uLinePos > 0);
201 if(_uLinePos == (_ndb_id.size() + 1)) {
204 _ndb_id[_uLinePos - 1] = _kln89->IncChar(_ndb_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
210 // NO-OP - from/to field is switched by clr button, not inner knob.