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