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_dir.hxx"
29 #include <Main/fg_props.hxx>
31 KLN89DirPage::KLN89DirPage(KLN89* parent)
40 KLN89DirPage::~KLN89DirPage() {
43 void KLN89DirPage::Update(double dt) {
44 // TODO - this can apparently be "ACTIVATE:" under some circumstances
45 _kln89->DrawText("DIRECT TO:", 2, 2, 3);
47 if(_kln89->_mode == KLN89_MODE_CRSR) {
49 while(s.size() < 5) s += ' ';
50 if(_DToWpDispMode == 0) {
52 _kln89->DrawText(s, 2, 4, 1, false, 99);
53 _kln89->DrawEnt(1, 0, 1);
55 } else if(_DToWpDispMode == 1) {
57 _kln89->DrawText(s, 2, 4, 1, false, _uLinePos);
58 _kln89->DrawEnt(1, 0, 1);
60 _kln89->Underline(2, 4, 1, 5);
62 if(!_kln89->_blink) _kln89->DrawText("_____", 2, 4, 1);
63 _kln89->Underline(2, 4, 1, 5);
66 _kln89->DrawText("_____", 2, 4, 1);
69 KLN89Page::Update(dt);
72 // This can only be called from the KLN89 when DTO is pressed from outside of the DIR page.
73 // DO NOT USE IT to set _id internally from the DIR page, since it initialises various state
74 // based on the assumption that the DIR page is being first entered.
75 void KLN89DirPage::SetId(const string& s) {
79 if(!_kln89->_activeFP->IsEmpty()) {
80 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
85 _saveMasterMode = _kln89->_mode;
86 _uLinePos = 1; // Needed to stop Leg flashing
89 void KLN89DirPage::CrsrPressed() {
90 // Pressing CRSR clears the ID field (from sim).
94 void KLN89DirPage::ClrPressed() {
95 if(_kln89->_mode == KLN89_MODE_CRSR) {
96 if(_DToWpDispMode <= 1) {
100 // Restore the original master mode
101 _kln89->_mode = _saveMasterMode;
102 // Stop displaying dir page
103 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
110 void KLN89DirPage::EntPressed() {
111 // Trim any RH whitespace from _id
112 while(!_id.empty()) {
113 if(_id[_id.size()-1] == ' ') {
114 _id = _id.substr(0, _id.size()-1);
116 // Important to break, since usr waypoint names may contain space.
120 if(_DToWpDispMode == 2 || _id.empty()) {
123 if(_DToWpDispMode == 0) {
124 // It's a waypoint from the active flightplan - these get processed without data page review.
125 _kln89->DtoInitiate(_id);
127 // Display the appropriate data page for review (USR page if the ident is not currently valid)
128 _kln89->_dtoReview = true;
129 GPSWaypoint* wp = _kln89->FindFirstByExactId(_id);
131 // Set the current page to be the appropriate data page
132 _kln89->_curPage = wp->type;
135 // Set the current page to be the user page
136 _kln89->_curPage = 4;
138 // set the page ID and entInvert, and activate the current page.
139 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
140 _kln89->_activePage->SetId(_id);
141 _kln89->_activePage->SetEntInvert(true);
146 void KLN89DirPage::Knob2Left1() {
147 if(_kln89->_mode == KLN89_MODE_CRSR) {
148 if(fgGetBool("/instrumentation/kln89/scan-pull")) {
149 if(_DToWpDispMode == 2) {
150 if(!_kln89->_activeFP->IsEmpty()) {
151 // Switch to mode 0, set the position to the end of the active flightplan *and* run the mode 0 case.
153 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
156 if(_DToWpDispMode == 0) {
157 // If the knob is pulled out, then the unit cycles through the waypoints of the active flight plan
158 // (This is deduced from the Bendix-King sim, I haven't found it documented in the pilot guide).
159 // If the active flight plan is empty it clears the field (this is possible, e.g. if a data page was
160 // active when DTO was pressed).
161 if(!_kln89->_activeFP->IsEmpty()) {
162 if(_DToWpDispIndex == 0) {
163 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
167 _id = _kln89->_activeFP->waypoints[_DToWpDispIndex]->id;
172 // _DToWpDispMode == 1 is a NO-OP when the knob is out.
174 if(_DToWpDispMode == 0) {
175 // If the knob is not pulled out, then turning it transitions the DIR page to the waypoint selection mode
176 // and sets the waypoint to the first beginning with '9'
178 GPSWaypoint* wp = _kln89->FindFirstById(_id);
185 } else if(_DToWpDispMode == 1) {
186 while(_id.size() < (_uLinePos + 1)) {
189 char ch = _id[_uLinePos];
192 } else if(ch == '0') {
194 } else if(ch == 'A') {
195 // It seems that blanks are allowed within the name, but not for the first character
205 GPSWaypoint* wp = _kln89->FindFirstById(_id.substr(0, _uLinePos+1));
212 GPSWaypoint* wp = _kln89->FindFirstById(_id);
222 // If the cursor is not displayed, then we return to the page that was displayed prior to DTO being pressed,
223 // and pass the knob turn to that page, whether pulled out or not.
224 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
225 _kln89->_activePage->Knob2Left1();
229 void KLN89DirPage::Knob2Right1() {
230 if(_kln89->_mode == KLN89_MODE_CRSR) {
231 if(fgGetBool("/instrumentation/kln89/scan-pull")) {
232 if(_DToWpDispMode == 2) {
233 if(!_kln89->_activeFP->IsEmpty()) {
234 // Switch to mode 0, set the position to the end of the active flightplan *and* run the mode 0 case.
236 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
239 if(_DToWpDispMode == 0) {
240 // If the knob is pulled out, then the unit cycles through the waypoints of the active flight plan
241 // (This is deduced from the Bendix-King sim, I haven't found it documented in the pilot guide).
242 // If the active flight plan is empty it clears the field (this is possible, e.g. if a data page was
243 // active when DTO was pressed).
244 if(!_kln89->_activeFP->IsEmpty()) {
245 if(_DToWpDispIndex == (int)_kln89->_activeFP->waypoints.size() - 1) {
250 _id = _kln89->_activeFP->waypoints[_DToWpDispIndex]->id;
255 // _DToWpDispMode == 1 is a NO-OP when the knob is out.
257 if(_DToWpDispMode == 0) {
258 // If the knob is not pulled out, then turning it transitions the DIR page to the waypoint selection mode
259 // and sets the waypoint to the first beginning with 'A'
261 GPSWaypoint* wp = _kln89->FindFirstById(_id);
268 } else if(_DToWpDispMode == 1) {
269 while(_id.size() < (_uLinePos + 1)) {
272 char ch = _id[_uLinePos];
275 } else if(ch == 'Z') {
277 } else if(ch == '9') {
278 // It seems that blanks are allowed within the name, but not for the first character
288 GPSWaypoint* wp = _kln89->FindFirstById(_id.substr(0, _uLinePos+1));
295 GPSWaypoint* wp = _kln89->FindFirstById(_id);
305 // If the cursor is not displayed, then we return to the page that was displayed prior to DTO being pressed,
306 // and pass the knob turn to that page, whether pulled out or not.
307 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
308 _kln89->_activePage->Knob2Right1();