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 - daveluff AT ntlworld.com
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>
33 KLN89NDBPage::KLN89NDBPage(KLN89* parent)
42 KLN89NDBPage::~KLN89NDBPage() {
45 void KLN89NDBPage::Update(double dt) {
46 bool actPage = (_kln89->_activePage->GetName() == "ACT" ? true : false);
47 bool multi; // Not set by FindFirst...
49 if(_ndb_id.size() == 3) exact = true;
51 np = _kln89->FindFirstNDBById(_ndb_id, multi, exact);
52 } else if(np->get_ident() != _ndb_id) {
53 np = _kln89->FindFirstNDBById(_ndb_id, multi, exact);
55 //if(np == NULL) cout << "NULL... ";
56 //if(b == false) cout << "false...\n";
59 cout << "VOR FOUND!\n";
65 //cout << np->id << '\n';
66 _ndb_id = np->get_ident();
67 if(_kln89->GetActiveWaypoint()) {
68 if(_ndb_id == _kln89->GetActiveWaypoint()->id) {
69 if(!(_kln89->_waypointAlert && _kln89->_blink)) {
70 // Active waypoint arrow
71 _kln89->DrawSpecialChar(4, 2, 0, 3);
75 if(_kln89->_mode != KLN89_MODE_CRSR) {
78 _kln89->DrawText(np->get_ident(), 2, 1, 3);
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);
83 int n = snprintf(buf, 3, "%i", _kln89->GetActiveWaypointIndex() + 1);
84 _kln89->DrawText((string)buf, 2, 3 - n, 3);
88 _kln89->DrawText(np->get_ident(), 2, 1, 3, false, 99);
94 // TODO - trim VOR-DME from the name, convert to uppercase, abbreviate, etc
95 _kln89->DrawText(np->name(), 2, 0, 2);
96 _kln89->DrawLatitude(np->get_lat(), 2, 3, 1);
97 _kln89->DrawLongitude(np->get_lon(), 2, 3, 0);
99 _kln89->DrawDirDistField(np->get_lat() * SG_DEGREES_TO_RADIANS, np->get_lon() * SG_DEGREES_TO_RADIANS,
100 2, 0, 0, _to_flag, (_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 4 ? true : false));
103 if(_kln89->_mode != KLN89_MODE_CRSR) _kln89->DrawText(_ndb_id, 2, 1, 3);
105 _kln89->DrawText("----.-", 2, 9, 3);
106 _kln89->DrawText("--------------", 2, 0, 2);
107 _kln89->DrawText("- -- --.--'", 2, 3, 1);
108 _kln89->DrawText("---- --.--'", 2, 3, 0);
109 _kln89->DrawSpecialChar(0, 2, 7, 1);
110 _kln89->DrawSpecialChar(0, 2, 7, 0);
114 if(_kln89->_mode == KLN89_MODE_CRSR) {
115 if(_uLinePos > 0 && _uLinePos < 4) {
116 // TODO - blink as well
117 _kln89->Underline(2, _uLinePos, 3, 1);
119 for(unsigned int i = 0; i < _ndb_id.size(); ++i) {
120 if(_uLinePos != (i + 1)) {
121 _kln89->DrawChar(_ndb_id[i], 2, i + 1, 3);
123 if(!_kln89->_blink) _kln89->DrawChar(_ndb_id[i], 2, i + 1, 3);
130 KLN89Page::Update(dt);
133 void KLN89NDBPage::SetId(const string& s) {
134 _last_ndb_id = _ndb_id;
135 _save_ndb_id = _ndb_id;
140 void KLN89NDBPage::CrsrPressed() {
141 if(_kln89->_mode == KLN89_MODE_DISP) return;
142 if(_kln89->_obsMode) {
154 void KLN89NDBPage::ClrPressed() {
155 if(_subPage == 1 && _uLinePos == 4) {
156 _to_flag = !_to_flag;
160 void KLN89NDBPage::EntPressed() {
163 if(_kln89->_dtoReview) {
164 _kln89->DtoInitiate(_ndb_id);
166 _last_ndb_id = _ndb_id;
167 _ndb_id = _save_ndb_id;
172 void KLN89NDBPage::Knob2Left1() {
173 if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
174 KLN89Page::Knob2Left1();
177 // Same logic for both pages - set the ID
178 _ndb_id = _ndb_id.substr(0, _uLinePos);
179 // ASSERT(_uLinePos > 0);
180 if(_uLinePos == (_ndb_id.size() + 1)) {
183 _ndb_id[_uLinePos - 1] = _kln89->DecChar(_ndb_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
189 // NO-OP - from/to field is switched by clr button, not inner knob.
195 void KLN89NDBPage::Knob2Right1() {
196 if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
197 KLN89Page::Knob2Right1();
200 // Same logic for both pages - set the ID
201 _ndb_id = _ndb_id.substr(0, _uLinePos);
202 // ASSERT(_uLinePos > 0);
203 if(_uLinePos == (_ndb_id.size() + 1)) {
206 _ndb_id[_uLinePos - 1] = _kln89->IncChar(_ndb_id[_uLinePos - 1], (_uLinePos == 1 ? false : true));
212 // NO-OP - from/to field is switched by clr button, not inner knob.