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