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_dir.hxx"
29 #include <Main/fg_props.hxx>
33 KLN89DirPage::KLN89DirPage(KLN89* parent)
42 KLN89DirPage::~KLN89DirPage() {
45 void KLN89DirPage::Update(double dt) {
46 // TODO - this can apparently be "ACTIVATE:" under some circumstances
47 _kln89->DrawText("DIRECT TO:", 2, 2, 3);
49 if(_kln89->_mode == KLN89_MODE_CRSR) {
51 while(s.size() < 5) s += ' ';
52 if(_DToWpDispMode == 0) {
54 _kln89->DrawText(s, 2, 4, 1, false, 99);
55 _kln89->DrawEnt(1, 0, 1);
57 } else if(_DToWpDispMode == 1) {
59 _kln89->DrawText(s, 2, 4, 1, false, _uLinePos);
60 _kln89->DrawEnt(1, 0, 1);
62 _kln89->Underline(2, 4, 1, 5);
64 if(!_kln89->_blink) _kln89->DrawText("_____", 2, 4, 1);
65 _kln89->Underline(2, 4, 1, 5);
68 _kln89->DrawText("_____", 2, 4, 1);
71 KLN89Page::Update(dt);
74 // This can only be called from the KLN89 when DTO is pressed from outside of the DIR page.
75 // DO NOT USE IT to set _id internally from the DIR page, since it initialises various state
76 // based on the assumption that the DIR page is being first entered.
77 void KLN89DirPage::SetId(const string& s) {
81 if(!_kln89->_activeFP->IsEmpty()) {
82 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
87 _saveMasterMode = _kln89->_mode;
88 _uLinePos = 1; // Needed to stop Leg flashing
91 void KLN89DirPage::CrsrPressed() {
92 // Pressing CRSR clears the ID field (from sim).
96 void KLN89DirPage::ClrPressed() {
97 if(_kln89->_mode == KLN89_MODE_CRSR) {
98 if(_DToWpDispMode <= 1) {
102 // Restore the original master mode
103 _kln89->_mode = _saveMasterMode;
104 // Stop displaying dir page
105 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
112 void KLN89DirPage::EntPressed() {
113 // Trim any RH whitespace from _id
114 while(!_id.empty()) {
115 if(_id[_id.size()-1] == ' ') {
116 _id = _id.substr(0, _id.size()-1);
118 // Important to break, since usr waypoint names may contain space.
122 if(_DToWpDispMode == 2 || _id.empty()) {
125 if(_DToWpDispMode == 0) {
126 // It's a waypoint from the active flightplan - these get processed without data page review.
127 _kln89->DtoInitiate(_id);
129 // Display the appropriate data page for review (USR page if the ident is not currently valid)
130 _kln89->_dtoReview = true;
131 GPSWaypoint* wp = _kln89->FindFirstByExactId(_id);
133 // Set the current page to be the appropriate data page
134 _kln89->_curPage = wp->type;
137 // Set the current page to be the user page
138 _kln89->_curPage = 4;
140 // set the page ID and entInvert, and activate the current page.
141 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
142 _kln89->_activePage->SetId(_id);
143 _kln89->_activePage->SetEntInvert(true);
148 void KLN89DirPage::Knob2Left1() {
149 if(_kln89->_mode == KLN89_MODE_CRSR) {
150 if(fgGetBool("/instrumentation/kln89/scan-pull")) {
151 if(_DToWpDispMode == 2) {
152 if(!_kln89->_activeFP->IsEmpty()) {
153 // Switch to mode 0, set the position to the end of the active flightplan *and* run the mode 0 case.
155 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
158 if(_DToWpDispMode == 0) {
159 // If the knob is pulled out, then the unit cycles through the waypoints of the active flight plan
160 // (This is deduced from the Bendix-King sim, I haven't found it documented in the pilot guide).
161 // If the active flight plan is empty it clears the field (this is possible, e.g. if a data page was
162 // active when DTO was pressed).
163 if(!_kln89->_activeFP->IsEmpty()) {
164 if(_DToWpDispIndex == 0) {
165 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
169 _id = _kln89->_activeFP->waypoints[_DToWpDispIndex]->id;
174 // _DToWpDispMode == 1 is a NO-OP when the knob is out.
176 if(_DToWpDispMode == 0) {
177 // If the knob is not pulled out, then turning it transitions the DIR page to the waypoint selection mode
178 // and sets the waypoint to the first beginning with '9'
180 GPSWaypoint* wp = _kln89->FindFirstById(_id);
187 } else if(_DToWpDispMode == 1) {
188 while(_id.size() < (_uLinePos + 1)) {
191 char ch = _id[_uLinePos];
194 } else if(ch == '0') {
196 } else if(ch == 'A') {
197 // It seems that blanks are allowed within the name, but not for the first character
207 GPSWaypoint* wp = _kln89->FindFirstById(_id.substr(0, _uLinePos+1));
214 GPSWaypoint* wp = _kln89->FindFirstById(_id);
224 // If the cursor is not displayed, then we return to the page that was displayed prior to DTO being pressed,
225 // and pass the knob turn to that page, whether pulled out or not.
226 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
227 _kln89->_activePage->Knob2Left1();
231 void KLN89DirPage::Knob2Right1() {
232 if(_kln89->_mode == KLN89_MODE_CRSR) {
233 if(fgGetBool("/instrumentation/kln89/scan-pull")) {
234 if(_DToWpDispMode == 2) {
235 if(!_kln89->_activeFP->IsEmpty()) {
236 // Switch to mode 0, set the position to the end of the active flightplan *and* run the mode 0 case.
238 _DToWpDispIndex = (int)_kln89->_activeFP->waypoints.size() - 1;
241 if(_DToWpDispMode == 0) {
242 // If the knob is pulled out, then the unit cycles through the waypoints of the active flight plan
243 // (This is deduced from the Bendix-King sim, I haven't found it documented in the pilot guide).
244 // If the active flight plan is empty it clears the field (this is possible, e.g. if a data page was
245 // active when DTO was pressed).
246 if(!_kln89->_activeFP->IsEmpty()) {
247 if(_DToWpDispIndex == (int)_kln89->_activeFP->waypoints.size() - 1) {
252 _id = _kln89->_activeFP->waypoints[_DToWpDispIndex]->id;
257 // _DToWpDispMode == 1 is a NO-OP when the knob is out.
259 if(_DToWpDispMode == 0) {
260 // If the knob is not pulled out, then turning it transitions the DIR page to the waypoint selection mode
261 // and sets the waypoint to the first beginning with 'A'
263 GPSWaypoint* wp = _kln89->FindFirstById(_id);
270 } else if(_DToWpDispMode == 1) {
271 while(_id.size() < (_uLinePos + 1)) {
274 char ch = _id[_uLinePos];
277 } else if(ch == 'Z') {
279 } else if(ch == '9') {
280 // It seems that blanks are allowed within the name, but not for the first character
290 GPSWaypoint* wp = _kln89->FindFirstById(_id.substr(0, _uLinePos+1));
297 GPSWaypoint* wp = _kln89->FindFirstById(_id);
307 // If the cursor is not displayed, then we return to the page that was displayed prior to DTO being pressed,
308 // and pass the knob turn to that page, whether pulled out or not.
309 _kln89->_activePage = _kln89->_pages[_kln89->_curPage];
310 _kln89->_activePage->Knob2Right1();