]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89_page_fpl.cxx
James Turner : this patch
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page_fpl.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_fpl.hxx"
29
30 #include <algorithm>
31 #include <iostream>
32
33 using namespace std;
34
35 KLN89FplPage::KLN89FplPage(KLN89* parent)
36 : KLN89Page(parent) {
37         _nSubPages = 26;
38         _subPage = 0;
39         _name = "FPL";
40         _fpMode = 0;
41         _actFpMode = 0;
42         _wLinePos = 0;
43         _bEntWp = false;
44         _bEntExp = false;
45         _entWp = NULL;
46         _fplPos = 0;
47         _resetFplPos0 = true;
48         _delFP = false;
49         _delWp = false;
50         _delAppr = false;
51         _changeAppr = false;
52         _fp0SelWpId = "";
53 }
54
55 KLN89FplPage::~KLN89FplPage() {
56 }
57
58 void KLN89FplPage::Update(double dt) {
59         Calc();
60         
61         // NOTE - we need to draw the active leg arrow outside of this block to avoid the _delFP check.
62         // TODO - we really ought to merge the page 0 and other pages drawing code with a couple of lines of extra logic.
63         if(_subPage == 0 && !_delFP) {  // Note that in the _delFP case, the active flightplan gets a header, and hence the same geometry as the other fps, so we draw it there.
64                 // active FlightPlan
65                 // NOTE THAT FOR THE ACTIVE FLIGHT PLAN, TOP POSITION IS STILL 4 in the underline position scheme, to make 
66                 // copy and paste easier!!!!
67
68                 // ---------------------------------- Copy the active FlightPlan and insert approach header and fence if required ---------------
69                 // For synatical convienience
70                 //vector<GPSWaypoint*> waylist = _kln89->_flightPlans[_subPage]->waypoints;
71                 // Copy every waypoint for now.
72         // This is inefficient, but allows us to insert dummy waypoints to represent the header and fence 
73                 // in our *local copy* of the flightplan, if an approach is loaded.  There must be a better way to do this!!!!
74                 //cout << "AA" << endl;
75                 vector<GPSWaypoint> waylist;
76                 for(unsigned int i=0; i<_kln89->_flightPlans[_subPage]->waypoints.size(); ++i) {
77                         waylist.push_back(*_kln89->_flightPlans[_subPage]->waypoints[i]);
78                 }
79                 //cout << "BB" << endl;
80                 _hdrPos = -1;
81                 _fencePos = -1;
82                 if(_kln89->_approachLoaded) {
83                         GPSWaypoint wp;
84                         wp.id = "HHHH";
85                         wp.type = GPS_WP_VIRT;
86                         wp.appType = GPS_HDR;
87                         //cout << "CC" << endl;
88                         for(unsigned int i=0; i<waylist.size(); ++i) {
89                                 // Insert the hdr immediately before the IAF
90                                 if(waylist[i].appType == GPS_IAF) {
91                                         waylist.insert(waylist.begin()+i, wp);
92                                         // Need to insert empty string into the params to keep them in sync
93                                         _params.insert(_params.begin()+i-1, "");
94                                         _hdrPos = i;
95                                         break;
96                                 }
97                         }
98                         //cout << "DD" << endl;
99                         wp.id = "FFFF";
100                         wp.type = GPS_WP_VIRT;
101                         wp.appType = GPS_FENCE;
102                         for(unsigned int i=0; i<waylist.size(); ++i) {
103                                 // Insert the fence between the MAF and the MAP
104                                 if(waylist[i].appType == GPS_MAHP) {
105                                         waylist.insert(waylist.begin()+i, wp);
106                                         // Need to insert empty string into the params to keep them in sync
107                                         _params.insert(_params.begin()+i-1, "");
108                                         _fencePos = i;
109                                         break;
110                                 }
111                         }
112                 }
113                 /*
114                 // Now make up a vector of waypoint numbers, since they aren't aligned with list position anymore
115                 int num = 0;
116                 vector<int> numlist;
117                 numlist.clear();
118                 for(unsigned int i=0; i<waylist.size(); ++i) {
119                         if(waylist[i].appType != GPS_HDR && waylist[i].appType != GPS_FENCE) {
120                                 numlist.push_back(num);
121                                 num++;
122                         } else {
123                                 numlist.push_back(-1);
124                         }
125                 }
126                 */
127                 int hfcount = 0;
128                 for(unsigned int i=0; i<waylist.size(); ++i) {
129                         //cout << i + 1 - hfcount << ":  ID= " << waylist[i].id;
130                         if(waylist[i].appType == GPS_HDR) {
131                                 hfcount++;
132                                 //cout << " HDR!";
133                         }
134                         if(waylist[i].appType == GPS_FENCE) {
135                                 hfcount++;
136                                 //cout << " FENCE!";
137                         }
138                         //cout << '\n';
139                 }
140                 //----------------------------------------- end active FP copy ------------------------------------------------
141                 
142                 // Recalculate which waypoint is displayed at the top of the list if required (generally if this page has lost focus).
143                 int idx = _parent->GetActiveWaypointIndex();
144                 if(_resetFplPos0) {
145                         if(waylist.size() <= 1) {
146                                 _fplPos = 0;
147                         } else if(waylist.size() <= 4) {
148                                 _fplPos = 1;
149                         } else {
150                                 // Make the active waypoint the second WP displayed
151                                 _fplPos = idx;
152                                 if(_fplPos != 0) {
153                                         _fplPos--;
154                                 }
155                         }
156                         //cout << "HeaderPos = " << _hdrPos << ", fencePos = " << _fencePos << ", _fplPos = " << _fplPos << ", active waypoint index = " << _parent->GetActiveWaypointIndex() << '\n';
157                         if(_hdrPos >= 0 && idx >= _hdrPos) {
158                                 _fplPos++;
159                                 if(_fencePos >= 0 && (idx + 1) >= _fencePos) {
160                                         _fplPos++;
161                                 }
162                         }
163                         _resetFplPos0 = false;
164                 }
165                 
166                 // Increment the active waypoint position if required due hdr and fence here not above so it gets called every frame
167                 if(_hdrPos >= 0 && idx >= _hdrPos) {
168                         idx++;
169                         if(_fencePos >= 0 && idx >= _fencePos) {
170                                 idx++;
171                         }
172                 }
173                 
174                 // Draw the leg arrow etc
175                 int diff = idx - (int)_fplPos;
176                 int drawPos = -1;
177                 if(idx < 0) {
178                         // No active waypoint
179                 } else if(diff < 0) {
180                         // Off screen to the top
181                 } else if(diff > 2) {
182                         // TODO !
183                 } else {
184                         drawPos = diff;
185                 }
186                 // Only the head is blinked during waypoint alerting
187                 if(!(_kln89->_waypointAlert && _kln89->_blink)) {
188                         _kln89->DrawSpecialChar(4, 2, 0, 3-drawPos);
189                 }
190                 // If the active waypoint is immediately after an approach header then we need to do an extra-long tail leg
191                 if(_hdrPos >= 0 && idx == _hdrPos + 1) {
192                         if(drawPos > 0 && !_kln89->_dto) _kln89->DrawLongLegTail(3-drawPos);
193                 } else {
194                         if(drawPos > 0 && !_kln89->_dto) _kln89->DrawLegTail(3-drawPos);
195                 }
196                 
197                 //cout << "Top pos is " << _fplPos0 << ' ';
198                 
199                 if(_kln89->_mode == KLN89_MODE_CRSR) {
200                         if(_uLinePos == 3) {
201                                 _kln89->Underline(2, 13, 3, 3);
202                         } else if(_uLinePos >= 4) {
203                                 if(_bEntWp) {
204                                         if(_wLinePos == 0) {
205                                                 _kln89->Underline(2, 5, 3 - (_uLinePos - 4), 4);
206                                         } else if(_wLinePos == 4) {
207                                                 _kln89->Underline(2, 4, 3 - (_uLinePos - 4), 4);
208                                         } else {
209                                                 _kln89->Underline(2, 4, 3 - (_uLinePos - 4), _wLinePos);
210                                                 _kln89->Underline(2, 5 + _wLinePos, 3 - (_uLinePos - 4), 4 - _wLinePos);
211                                         }
212                                         if(!_kln89->_blink) {
213                                                 //_kln89->DrawText(_entWp->id, 2, 4, 2 - (_uLinePos - 4), false, _wLinePos);
214                                                 _kln89->DrawEnt();
215                                         }
216                                 } else {
217                                         _kln89->Underline(2, 4, 3 - (_uLinePos - 4), 5);
218                                 }
219                         }
220                 }
221                 // ----------------------------------
222                 //cout << "A1" << endl;
223                         
224                 // Sanity check the top position - remember that we can have an extra blank one at the bottom even if CRSR is off if crsr is switched on then off
225                 if((int)_fplPos > ((int)waylist.size()) - 3) _fplPos = (((int)waylist.size()) - 3 < 0 ? 0 : waylist.size() - 3);
226                 unsigned int last_pos;
227                 if(waylist.empty()) {
228                         last_pos = 0;
229                 } else {
230                         last_pos = ((int)_fplPos == ((int)waylist.size()) - 3 ? waylist.size() : waylist.size() - 1);
231                 }
232                 //cout << "Initialising last_pos, last_pos = " << last_pos << '\n';
233                 //cout << "B1" << endl;
234                 if(waylist.size() < 4) last_pos = waylist.size();
235                 
236                 // Don't draw the cyclic field header if the top waypoint is the approach header
237                 // Not sure if this also applies to the fence - don't think so but TODO - check!
238                 if(waylist[_fplPos].appType != GPS_HDR) {
239                         _kln89->DrawChar('>', 2, 12, 3);
240                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 3 && _kln89->_blink)) {
241                                 DrawFpMode(3);
242                         }
243                 }
244                 
245                 // ACTIVE
246                 for(unsigned int i=0; i<4; ++i) {
247                         //cout << "F1... " << i << endl;
248                         // Don't draw the waypoint number for the header or fence
249                         //cout << "_fplPos0 = " << _fplPos0 << ", waylist size is " << waylist.size() << '\n';
250                         //cout << "F1, i = " << i << ", way id = " << waylist[_fplPos0+i].id << '\n'; 
251                         if((waylist[_fplPos+i].appType == GPS_HDR || waylist[_fplPos+i].appType == GPS_FENCE) 
252                             && i != 3) {        // By definition, the header and fence lines can't be displayed on the last line hence the unconditional !i==3 is safe.
253                                 // no-op
254                                 //cout << "NOOP\n";
255                         } else {
256                                 int n = (i < 3 ? _fplPos + i + 1 : last_pos + 1);
257                                 if(_kln89->_approachLoaded) {
258                                         if(n > _hdrPos) --n;
259                                         if(n > _fencePos) --n;
260                                 }
261                                 string s = GPSitoa(n);
262                                 // Don't draw the colon for waypoints that are part of the published approach
263                                 if(waylist[_fplPos+i].appType == GPS_APP_NONE) {
264                                         s += ':';
265                                 }
266                                 if(!(_delWp && _uLinePos == i+4)) _kln89->DrawText(s, 2, 4 - (s[s.size()-1] == ':' ? s.size() : s.size()+1), 3 - i);
267                         }
268                         //cout << "F1 done!\n";
269                         bool drawID = true;
270                         if(_delWp && _uLinePos == i+4) {
271                                 if(!_kln89->_blink) {
272                                         _kln89->DrawText("Del", 2, 0, 3-i);
273                                         _kln89->DrawChar('?', 2, 10, 3-i);
274                                         _kln89->Underline(2, 0, 3-i, 11);
275                                         _kln89->DrawEnt();
276                                 }
277                         } else if(_kln89->_mode == KLN89_MODE_CRSR && _bEntWp && _uLinePos == i+4) {
278                                 if(!_kln89->_blink) {
279                                         if(_wLinePos >= _entWp->id.size()) {
280                                                 _kln89->DrawText(_entWp->id, 2, 4, 3-i);
281                                                 _kln89->DrawChar(' ', 2, 4+_wLinePos, 3-i, false, true);
282                                         } else {
283                                                 _kln89->DrawText(_entWp->id.substr(0, _wLinePos), 2, 4, 3-i);
284                                                 _kln89->DrawChar(_entWp->id[_wLinePos], 2, 4+_wLinePos, 3-i, false, true);
285                                                 _kln89->DrawText(_entWp->id.substr(_wLinePos+1, _entWp->id.size()-_wLinePos-1), 2, 5+_wLinePos, 3-i);
286                                         }
287                                 }
288                                 drawID = false;
289                         }
290                         //cout << "F2" << endl;
291                         if(drawID) {
292                                 //cout << "F2a" << endl;
293                                 if(i == 3 || _fplPos + i == waylist.size()) {
294                                         //cout << "F2a1" << endl;
295                                         //cout << "_uLinePos = " << _uLinePos << ", i = " << i << ", waylist.size() = " << waylist.size() << endl;
296                                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == (i + 4) && _kln89->_blink)) {
297                                                 //cout << "Drawing underline..." << endl;
298                                                 _kln89->DrawText(last_pos < waylist.size() ? waylist[last_pos].GetAprId() : "_____", 2, 4, 3-i);
299                                                 //cout << "2" << endl;
300                                         }
301                                         //cout << "3" << endl;
302                                         //cout << "last_pos = " << last_pos << endl;
303                                         if(last_pos > 0 && last_pos < waylist.size() && i > 0) {
304                                                 //cout << "4" << endl; 
305                                                 // Draw the param
306                                                 if(_actFpMode == 0) {
307                                                         string s = _params[last_pos - 1];
308                                                         _kln89->DrawText(s, 2, 16-s.size(), 3-i);
309                                                 } else if(_actFpMode == 3) {
310                                                         string s = _params[last_pos - 1];
311                                                         _kln89->DrawText(s, 2, 15-s.size(), 3-i);
312                                                         _kln89->DrawSpecialChar(0, 2, 15, 3-i);
313                                                 }
314                                                 //cout << "5" << endl;
315                                         }
316                                         //cout << "6" << endl;
317                                         break;
318                                 } else {
319                                         //cout << "F2a2" << endl;
320                                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == (i + 4) && _kln89->_blink)) {
321                                                 if(waylist[_fplPos+i].appType == GPS_HDR) {
322                                                         if(_delAppr) {
323                                                                 _kln89->DrawText("DELETE APPR?", 2, 1, 3-i);
324                                                         } else if(_changeAppr) {
325                                                                 _kln89->DrawText("CHANGE APPR?", 2, 1, 3-i);
326                                                         } else {
327                                                                 _kln89->DrawText(_kln89->_approachAbbrev, 2, 1, 3-i);
328                                                                 _kln89->DrawText(_kln89->_approachRwyStr, 2, 7, 3-i);
329                                                                 _kln89->DrawText(_kln89->_approachID, 2, 12, 3-i);
330                                                         }
331                                                 } else if(waylist[_fplPos+i].appType == GPS_FENCE) {
332                                                         _kln89->DrawText("*NO WPT SEQ", 2, 0, 3-i);
333                                                 } else {
334                                                         _kln89->DrawText(waylist[_fplPos+i].GetAprId(), 2, 4, 3-i);
335                                                 }
336                                         }
337                                 }
338                                 //cout << "F2b" << endl;
339                                 if(i > 0) {
340                                         // Draw the param
341                                         //cout << "i > 0 param draw...\n";
342                                         if(_actFpMode == 0) {
343                                                 string s = _params[_fplPos + i - 1];
344                                                 _kln89->DrawText(s, 2, 16-s.size(), 3-i);
345                                         } else if(_actFpMode == 3) {
346                                                 string s = _params[_fplPos + i - 1];
347                                                 _kln89->DrawText(s, 2, 15-s.size(), 3-i);
348                                                 _kln89->DrawSpecialChar(0, 2, 15, 3-i);
349                                         }
350                                 }
351                                 //cout << "F2c" << endl;
352                         }
353                         //cout << "F3" << endl;
354                 }
355                 //cout << "GGGGGG" << endl;
356         } else {  // Not active flightplan
357                 //cout << "Top pos is " << _fplPos << ' ';
358                 // For synatical convienience
359                 //int nWp = (_subPage == 0 && !_delFP ? 4 : 3); // number of waypoints to display
360                 vector<GPSWaypoint*> waylist = _kln89->_flightPlans[_subPage]->waypoints;
361                 if(waylist.empty()) {
362                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 1 && _kln89->_blink)) {
363                                 _kln89->DrawText(_delFP ? "Delete FPL?" : "Copy FPL 0?", 2, 0, 3);
364                         }
365                 } else {
366                         if(!(_kln89->_mode == KLN89_MODE_CRSR && (_uLinePos == 1 || _uLinePos == 2) && _kln89->_blink)) {
367                                 _kln89->DrawText(_delFP ? "Delete FPL?" : "Use?", 2, 0, 3);
368                         }
369                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 2 && _kln89->_blink)) {
370                                 if(!_delFP) _kln89->DrawText("Inverted?", 2, 5, 3);
371                         }
372                 }
373                 
374                 // ----------------------------------
375                 if(_kln89->_mode == KLN89_MODE_CRSR) {
376                         if(_uLinePos == 1) {
377                                 if(!_kln89->_blink) {
378                                         _kln89->Underline(2, 0, 3, (waylist.empty() || _delFP ? 11 : 4));       // This underline is blinked
379                                         _kln89->DrawEnt();
380                                 }
381                         } else if(_uLinePos == 2) {
382                                 // assert(!waylist.empty());
383                                 if(!_kln89->_blink) {
384                                         _kln89->Underline(2, 0, 3, 14); // This underline is blinked
385                                         _kln89->DrawEnt();
386                                 }
387                         } else if(_uLinePos == 3) {
388                                 _kln89->Underline(2, 13, 2, 3);
389                         } else if(_uLinePos >= 4) {
390                                 if(_bEntWp) {
391                                         if(_wLinePos == 0) {
392                                                 _kln89->Underline(2, 5, 2 - (_uLinePos - 4), 4);
393                                         } else if(_wLinePos == 4) {
394                                                 _kln89->Underline(2, 4, 2 - (_uLinePos - 4), 4);
395                                         } else {
396                                                 _kln89->Underline(2, 4, 2 - (_uLinePos - 4), _wLinePos);
397                                                 _kln89->Underline(2, 5 + _wLinePos, 2 - (_uLinePos - 4), 4 - _wLinePos);
398                                         }
399                                         if(!_kln89->_blink) {
400                                                 //_kln89->DrawText(_entWp->id, 2, 4, 2 - (_uLinePos - 4), false, _wLinePos);
401                                                 _kln89->DrawEnt();
402                                         }
403                                 } else {
404                                         if(!_delWp) _kln89->Underline(2, 4, 2 - (_uLinePos - 4), 5);
405                                 }
406                         }
407                 }
408                 // ----------------------------------
409                         
410                 _kln89->DrawChar('>', 2, 12, 2);
411                 if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == 3 && _kln89->_blink)) DrawFpMode(2);
412                 // Sanity check the top position - remember that we can have an extra blank one at the bottom even if CRSR is off if crsr is switched on then off
413                 if((int)_fplPos > ((int)waylist.size()) - 2) _fplPos = (((int)waylist.size()) - 2 < 0 ? 0 : waylist.size() - 2);
414                 unsigned int last_pos;
415                 if(waylist.empty()) {
416                         last_pos = 0;
417                 } else {
418                         last_pos = ((int)_fplPos == ((int)waylist.size()) - 2 ? waylist.size() : waylist.size() - 1);
419                 }
420                 if(waylist.size() < 3) last_pos = waylist.size();
421                 for(unsigned int i=0; i<3; ++i) {
422                         string s = GPSitoa(i < 2 ? _fplPos + i + 1 : last_pos + 1);
423                         s += ':';
424                         if(!(_delWp && _uLinePos == i+4)) _kln89->DrawText(s, 2, 4 - s.size(), 2 - i);
425                         bool drawID = true;
426                         if(_delWp && _uLinePos == i+4) {
427                                 if(!_kln89->_blink) {
428                                         _kln89->DrawText("Del", 2, 0, 2-i);
429                                         _kln89->DrawChar('?', 2, 10, 2-i);
430                                         _kln89->Underline(2, 0, 2-i, 11);
431                                         _kln89->DrawEnt();
432                                 }
433                         } else if(_kln89->_mode == KLN89_MODE_CRSR && _bEntWp && _uLinePos == i+4) {
434                                 if(!_kln89->_blink) {
435                                         if(_wLinePos >= _entWp->id.size()) {
436                                                 _kln89->DrawText(_entWp->id, 2, 4, 2-i);
437                                                 _kln89->DrawChar(' ', 2, 4+_wLinePos, 2-i, false, true);
438                                         } else {
439                                                 _kln89->DrawText(_entWp->id.substr(0, _wLinePos), 2, 4, 2-i);
440                                                 _kln89->DrawChar(_entWp->id[_wLinePos], 2, 4+_wLinePos, 2-i, false, true);
441                                                 _kln89->DrawText(_entWp->id.substr(_wLinePos+1, _entWp->id.size()-_wLinePos-1), 2, 5+_wLinePos, 2-i);
442                                         }
443                                 }
444                                 drawID = false;
445                         }
446                         if(drawID) {
447                                 if(i == 2 || _fplPos + i == waylist.size()) {
448                                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == (i + 4) && _kln89->_blink)) {
449                                                 _kln89->DrawText(last_pos < waylist.size() ? waylist[last_pos]->id : "_____", 2, 4, 2-i);
450                                         }
451                                         if(last_pos > 0 && last_pos < waylist.size() && i > 0) {
452                                                 // Draw the param
453                                                 if(_fpMode == 0) {
454                                                         string s = _params[last_pos - 1];
455                                                         _kln89->DrawText(s, 2, 16-s.size(), 2-i);
456                                                 }
457                                         }
458                                         break;
459                                 } else {
460                                         if(!(_kln89->_mode == KLN89_MODE_CRSR && _uLinePos == (i + 4) && _kln89->_blink)) {
461                                                 _kln89->DrawText(waylist[_fplPos+i]->id, 2, 4, 2-i);
462                                         }
463                                         if(i > 0) {
464                                                 // Draw the param
465                                                 if(_fpMode == 0) {
466                                                         string s = _params[_fplPos + i - 1];
467                                                         _kln89->DrawText(s, 2, 16-s.size(), 2-i);
468                                                 }
469                                         }
470                                 }
471                         }
472                 }
473         }
474         
475         KLN89Page::Update(dt);
476 }
477
478 void KLN89FplPage::DrawFpMode(int ypos) {
479         string s = "Dis";
480         if(0 == _subPage) {
481                 if(_actFpMode == 1) {
482                         s = "ETE";
483                 } else if(_actFpMode == 2) {
484                         s = "UTC";      // TODO - alter depending on chosen timezone
485                 } else if(_actFpMode == 3) {
486                         s = (_kln89->_obsMode ? "OBS" : "Dtk");
487                 }
488         } else {
489                 if(_fpMode == 1) {
490                         s = "Dtk";
491                 }
492         }
493         _kln89->DrawText(s, 2, 13, ypos);
494 }
495
496 // Bit of an ipsy-dipsy function this one - calc the required parameters for the displayed flightplan.
497 void KLN89FplPage::Calc() {
498         _params.clear();
499         GPSFlightPlan* fp = _kln89->_flightPlans[_subPage];
500         vector<GPSWaypoint*> wv = fp->waypoints;
501         if(0 == _subPage) {
502                 // Active FP - parameters are only displayed for the active waypoint onwards for the active plan,
503                 // and distance is cumulative from the user position.
504                 if(0 == _actFpMode) {
505                         // Dis
506                         double cum_tot = 0.0;
507                         if(wv.size() > 0) {
508                                 //cum_tot += _kln89->GetHorizontalSeparation(_kln89->_gpsLat, _kln89->_gpsLon, wv[0]->lat, wv[0]->lon) * SG_METER_TO_NM;
509                                 cum_tot += _kln89->GetGreatCircleDistance(_kln89->_gpsLat, _kln89->_gpsLon, wv[0]->lat, wv[0]->lon);
510                         }
511                         for(unsigned int i=1; i<wv.size(); ++i) {
512                                 //cum_tot += _kln89->GetHorizontalSeparation(wv[i-1]->lat, wv[i-1]->lon, wv[i]->lat, wv[i]->lon) * SG_METER_TO_NM;      // TODO - add units switch!
513                                 cum_tot += _kln89->GetGreatCircleDistance(wv[i-1]->lat, wv[i-1]->lon, wv[i]->lat, wv[i]->lon);  // TODO - add units switch!
514                                 int n = (int)(cum_tot + 0.5);
515                                 _params.push_back(GPSitoa(n));
516                         }
517                 } else if(1 == _actFpMode) {
518                 } else if(2 == _actFpMode) {
519                 } else {
520                         // Dtk
521                         for(int i=1; i<wv.size(); ++i) {
522                                 double dtk = _kln89->GetMagHeadingFromTo(wv[i-1]->lat, wv[i-1]->lon, wv[i]->lat, wv[i]->lon);
523                                 int n = (int)(dtk + 0.5);
524                                 _params.push_back(GPSitoa(n));
525                         }
526                         
527                 }
528         } else {
529                 // other FPs
530                 if(0 == _fpMode) {
531                         double cum_tot = 0.0;
532                         for(int i=1; i<wv.size(); ++i) {
533                                 //cum_tot += _kln89->GetHorizontalSeparation(wv[i-1]->lat, wv[i-1]->lon, wv[i]->lat, wv[i]->lon) * SG_METER_TO_NM;      // TODO - add units switch!
534                                 cum_tot += _kln89->GetGreatCircleDistance(wv[i-1]->lat, wv[i-1]->lon, wv[i]->lat, wv[i]->lon);  // TODO - add units switch!
535                                 int n = (int)(cum_tot + 0.5);
536                                 _params.push_back(GPSitoa(n));
537                         }
538                 } else {
539                 }
540         }
541 }
542
543 void KLN89FplPage::CrsrPressed() {
544         if(_delFP) {
545                 _delFP = false;
546                 _kln89->_mode = KLN89_MODE_DISP;
547                 return;
548         }
549
550         _wLinePos = 0;
551         if(_kln89->_mode == KLN89_MODE_DISP) {
552                 _fp0SelWpId.clear();
553                 if(_bEntWp) {
554                         for(unsigned int i = 0; i < _kln89->_flightPlans[_subPage]->waypoints.size(); ++i) {
555                                 if(_kln89->_flightPlans[_subPage]->waypoints[i] == _entWp) {
556                                         _kln89->_flightPlans[_subPage]->waypoints.erase(_kln89->_flightPlans[_subPage]->waypoints.begin() + i);
557                                 }
558                         }
559                         delete _entWp;
560                         _entWp = NULL;
561                         _bEntWp = false;
562                         _entWpStr.clear();
563                 }
564         } else {
565                 if(_kln89->_obsMode) {
566                         _uLinePos = 0;
567                 } else {
568                         if(_kln89->_flightPlans[_subPage]->IsEmpty()) {
569                                 _uLinePos = 4;
570                         } else {
571                                 _uLinePos = (_subPage == 0 ? 3 : 1);
572                         }
573                 }
574         }
575 }
576
577 void KLN89FplPage::ClrPressed() {
578         if(_delFP) {
579                 _kln89->_mode = KLN89_MODE_DISP;
580                 _delFP = false;
581         } else if(_delAppr) {
582                 _kln89->_mode = KLN89_MODE_DISP;
583                 _delAppr = false;
584         } else {
585                 if(KLN89_MODE_CRSR == _kln89->_mode) {
586                         // TODO - see if we need to delete a waypoint
587                         if(_uLinePos >= 4) {
588                                 if(_delWp) {
589                                         _kln89->_mode = KLN89_MODE_DISP;
590                                         _delWp = false;
591                                 } else {
592                                         // First check that we're not trying to delete an approach waypoint.  Note that we can delete the approach by deleting the header though.
593                                         // Check for approach waypoints or header/fences in flightplan 0
594                                         int n = _fplPos + _uLinePos - 4;
595                                         bool hdrPos = false;
596                                         bool fencePos = false;
597                                         //cout << "_fplPos = " << _fplPos << ", _uLinePos = " << _uLinePos << ", n = " << n << ", _hdrPos = " << _hdrPos << ", _fencePos = " << _fencePos << '\n';
598                                         if(n == _hdrPos) {
599                                                 //cout << "HEADER POS\n";
600                                                 hdrPos = true;
601                                         }
602                                         if(n == _fencePos) {
603                                                 //cout << "FENCE POS\n";
604                                                 fencePos = true;
605                                         }
606                                         if(_hdrPos >= 0 && n > _hdrPos) --n;
607                                         if(_fencePos >= 0 && n >= _fencePos) --n;       // This one needs to be >= since n is already decremented by 1 in the line above!
608                                         //cout << "New n = " << n << '\n';
609                                         if(hdrPos) {
610                                                 //cout << "HDRP\n";
611                                                 _delAppr = true;
612                                         } else if(fencePos) {
613                                                 //cout << "FENP\n";
614                                                 // no-op
615                                         } else if(n >= _kln89->_flightPlans[_subPage]->waypoints.size()) {
616                                                 // no-op - off the end of the list on the entry field
617                                         } else if(_kln89->_flightPlans[_subPage]->waypoints[n]->appType == GPS_APP_NONE) {
618                                                 //cout << "DELFP\n";
619                                                 _kln89->_mode = KLN89_MODE_CRSR;
620                                                 _delWp = true;
621                                         } else {
622                                                 ShowScratchpadMessage("Invald", " Del  ");
623                                         }
624                                 }
625                         } else if(_uLinePos == 3) {
626                                 if(_subPage == 0) {
627                                         _actFpMode++;
628                                         if(_actFpMode > 3) _actFpMode = 0;
629                                 } else {
630                                         _fpMode++;
631                                         if(_fpMode > 1) _fpMode = 0;
632                                 }
633                         }
634                 } else {
635                         _delFP = true;
636                         _uLinePos = 1;
637                         _kln89->_mode = KLN89_MODE_CRSR;
638                 }
639         }
640 }
641
642 void KLN89FplPage::CleanUp() {
643         // TODO - possibly need to clean up _delWp here as well, since it goes off if dto and then ent are pressed.
644         
645         _bEntWp = false;
646         for(unsigned int i = 0; i < _kln89->_flightPlans[_subPage]->waypoints.size(); ++i) {
647                 if(_kln89->_flightPlans[_subPage]->waypoints[i] == _entWp) {
648                         _kln89->_flightPlans[_subPage]->waypoints.erase(_kln89->_flightPlans[_subPage]->waypoints.begin() + i);
649                 }
650         }
651         delete _entWp;
652         _entWp = NULL;
653         _entWpStr.clear();
654         KLN89Page::CleanUp();
655 }
656
657 void KLN89FplPage::LooseFocus() {
658         _fplPos = 0;
659         _resetFplPos0 = true;
660         _wLinePos = 0;
661         _uLinePos = 0;
662         _fp0SelWpId.clear();
663         _scratchpadMsg = false;
664 }
665
666 void KLN89FplPage::EntPressed() {
667         if(_delFP) {
668                 _parent->ClearFlightPlan(_subPage);
669                 CrsrPressed();
670         } else if(_delWp) {
671                 int pos = _uLinePos - 4 + _fplPos;
672                 // Sanity check - the calculated wp position should never be off the end of the waypoint list.
673                 if(pos > _kln89->_flightPlans[_subPage]->waypoints.size() - 1) {
674                         cout << "ERROR - _uLinePos too big in KLN89FplPage::EntPressed!\n";
675                         return;
676                 }
677                 _kln89->_flightPlans[_subPage]->waypoints.erase(_kln89->_flightPlans[_subPage]->waypoints.begin() + pos);
678                 _delWp = false;
679                 // Do we need to re-calc _fplPos here?
680         } else if(_bEntExp) {
681                 _bEntWp = false;
682                 _bEntExp = false;
683                 _entWp = NULL;  // DON'T delete it! - it's been pushed onto the waypoint list at this point.
684                 _entWpStr.clear();
685                 _kln89->_cleanUpPage = -1;
686                 _wLinePos = 0;
687                 // TODO - in actual fact the previously underlined waypoint stays in the same position and underlined
688                 // in some or possibly all circumstances - need to check this out and match it, but not too important
689                 // for now.
690         } else if(_bEntWp) {
691                 if(_entWp != NULL) {
692                         // TODO - should be able to get rid of this switch I think and use the enum values.
693                         switch(_entWp->type) {
694                         case GPS_WP_APT:
695                                 _kln89->_activePage = _kln89->_pages[0];
696                                 _kln89->_curPage = 0;
697                                 ((KLN89Page*)_kln89->_pages[0])->SetEntInvert(true);
698                                 break;
699                         case GPS_WP_VOR:
700                                 _kln89->_activePage = _kln89->_pages[1];
701                                 _kln89->_curPage = 1;
702                                 ((KLN89Page*)_kln89->_pages[1])->SetEntInvert(true);
703                                 break;
704                         case GPS_WP_NDB:
705                                 _kln89->_activePage = _kln89->_pages[2];
706                                 _kln89->_curPage = 2;
707                                 ((KLN89Page*)_kln89->_pages[2])->SetEntInvert(true);
708                                 break;
709                         case GPS_WP_INT:
710                                 _kln89->_activePage = _kln89->_pages[3];
711                                 _kln89->_curPage = 3;
712                                 ((KLN89Page*)_kln89->_pages[3])->SetEntInvert(true);
713                                 break;
714                         case GPS_WP_USR:
715                                 _kln89->_activePage = _kln89->_pages[4];
716                                 _kln89->_curPage = 4;
717                                 ((KLN89Page*)_kln89->_pages[4])->SetEntInvert(true);
718                                 break;
719                         default:
720                                 cout << "Error - unknown waypoint type found in KLN89::FplPage::EntPressed()\n";
721                         }
722                         _kln89->_activePage->SetId(_entWp->id);
723                         _kln89->_entJump = 7;
724                         _kln89->_cleanUpPage = 7;
725                         _kln89->_entRestoreCrsr = true;
726                         _kln89->_mode = KLN89_MODE_DISP;
727                 }
728                 _bEntExp = true;
729         } else if(_uLinePos == 1) {
730                 if(_kln89->_flightPlans[_subPage]->IsEmpty()) {
731                         // Copy fpl 0
732                         for(unsigned int i=0; i<_kln89->_flightPlans[0]->waypoints.size(); ++i) {
733                                 GPSWaypoint* wp = new GPSWaypoint;
734                                 *wp = *(_kln89->_flightPlans[0]->waypoints[i]);
735                                 _kln89->_flightPlans[_subPage]->waypoints.push_back(wp);
736                         }
737                 } else {
738                         // Use
739                         _parent->ClearFlightPlan(0);
740                         for(unsigned int i=0; i<_kln89->_flightPlans[_subPage]->waypoints.size(); ++i) {
741                                 GPSWaypoint* wp = new GPSWaypoint;
742                                 *wp = *(_kln89->_flightPlans[_subPage]->waypoints[i]);
743                                 _kln89->_flightPlans[0]->waypoints.push_back(wp);
744                         }
745                         _kln89->OrientateToActiveFlightPlan();
746                         _subPage = 0;
747                 }
748                 _parent->CrsrPressed();
749         } else if(_uLinePos == 2) {
750                 if(_kln89->_flightPlans[_subPage]->IsEmpty()) {
751                         // ERROR !!!
752                 } else {
753                         // Use Invert
754                         _parent->ClearFlightPlan(0);
755                         for(unsigned int i=0; i<_kln89->_flightPlans[_subPage]->waypoints.size(); ++i) {
756                                 GPSWaypoint* wp = new GPSWaypoint;
757                                 *wp = *(_kln89->_flightPlans[_subPage]->waypoints[i]);
758                                 // FIXME - very inefficient - use a reverse iterator on the source array and push_back instead!!!!!!!!
759                                 _kln89->_flightPlans[0]->waypoints.insert(_kln89->_flightPlans[0]->waypoints.begin(), wp);
760                         }
761                         _kln89->OrientateToActiveFlightPlan();
762                 }
763                 _parent->CrsrPressed();
764                 _subPage = 0;
765         }
766 }
767
768 void KLN89FplPage::Knob1Left1() {
769         if(_delFP) {
770                 _delFP = false;
771                 return;
772         }
773         _delWp = false;
774         _changeAppr = false;
775
776         if(_kln89->_mode == KLN89_MODE_CRSR) {
777                 if(_bEntWp) {
778                         if(_wLinePos > 0) _wLinePos--;
779                 } else {
780                         // _uLinePos with empty/not-empty plan: 1 = Copy FPL 0? / Use?, 2 = unused if empty / Invert?, 3 = >Dis/Dtk field, 4+ = Waypoint 1+
781                         if(_uLinePos == 0) {
782                                 // No-op
783                         } else if(_uLinePos == 1 || _uLinePos == 2) {
784                                 _uLinePos--;
785                         } else if(_uLinePos == 3) {
786                                 _uLinePos = 4;
787                         } else if(_uLinePos == 4) {
788                                 if(_kln89->_flightPlans[_subPage]->IsEmpty()) {
789                                         _uLinePos = (_subPage == 0 ? 0 : 1);
790                                 } else if(_fplPos == 0) {
791                                         _uLinePos = (_subPage == 0 ? 0 : 2);
792                                 } else {
793                                         _fplPos--;
794                                 }
795                         } else if(_uLinePos == 5) {
796                                 _uLinePos = 3;
797                         } else {
798                                 _uLinePos--;
799                         }
800
801                         if(_subPage == 0 && _uLinePos > 3) {
802                                 int ix = _fplPos + (_uLinePos - 4);
803                                 if(_fencePos >= 0 && ix >= _fencePos) ix--;
804                                 if(_hdrPos >= 0 && ix >= _hdrPos) ix--;
805                                 if(ix >= _kln89->_activeFP->waypoints.size()) {
806                                         _fp0SelWpId.clear();
807                                 } else {
808                                         _fp0SelWpId = _kln89->_activeFP->waypoints[ix]->id;
809                                 }
810                         } else {
811                                 _fp0SelWpId.clear();
812                                 //cout << "Not page 0, or not in waypoints, clearing id!\n";
813                         }
814                 }
815         }
816 }
817
818 void KLN89FplPage::Knob1Right1() {
819         if(_delFP) {
820                 _delFP = false;
821                 return;
822         }
823         _delWp = false;
824         _changeAppr = false;
825         
826         if(_kln89->_mode == KLN89_MODE_CRSR) {
827                 if(_bEntWp) {
828                         if(_wLinePos < 4) _wLinePos++;
829                 } else {
830                         // _uLinePos with empty/not-empty plan: 
831                         // 1 = Copy FPL 0? / Use?, 2 = unused if empty / Invert?, 3 = >Dis/Dtk field, 4+ = Waypoint 1+
832                         if(_uLinePos == 0) {
833                                 _uLinePos = (_subPage == 0 ? 4 : 1);
834                         } else if(_uLinePos == 1) {
835                                 _uLinePos = (_kln89->_flightPlans[_subPage]->IsEmpty() ? 4 : 2);
836                         } else if(_uLinePos == 2) {
837                                 _uLinePos = 4;
838                         } else if(_uLinePos == 3) {
839                                 if(!_kln89->_flightPlans[_subPage]->IsEmpty()) _uLinePos = 5;
840                         } else if(_uLinePos == 4) {
841                                 _uLinePos = 3;
842                         } else if((_subPage == 0 && _uLinePos == 6) || (_subPage > 0 && _uLinePos == 5)) {
843                                 // Urrggh - complicated!
844                                 // 3 possibilities:
845                                 // 1: We're on the entry field at the end of the list, and can't move any more.
846                                 // 2: We're on the last or second-last field, and move to the last position
847                                 // 3: We're on a field before the second-last one, and don't move, but change the list-head position
848                                 // And 4: _subPage 0 can be complicated by the presence of header/fence lines in an approach.
849                                 int hfcount = 0;
850                                 if(_subPage == 0) {
851                                         if(_hdrPos >= 0) hfcount++;
852                                         if(_fencePos >= 0) hfcount++;
853                                 }
854                                 if(_kln89->_flightPlans[_subPage]->waypoints.size() == 1 || _fplPos == _kln89->_flightPlans[_subPage]->waypoints.size() + hfcount - 1) {
855                                         // 1: Don't move
856                                 } else if(_fplPos >= _kln89->_flightPlans[_subPage]->waypoints.size() + hfcount - (_subPage == 0 ? 4 : 3)) {
857                                         _uLinePos++;
858                                 } else {
859                                         _fplPos++;
860                                 }
861                         } else if(_uLinePos == 5) {
862                                 // Must be _subPage 0
863                                 _uLinePos++;
864                         } else {
865                                 // Must be the last line - either _uLinePos 6 or 7 depending on _subPage
866                                 int thresh = (_subPage == 0 ? 3 : 2);
867                                 if(_kln89->_flightPlans[_subPage]->waypoints.size() == thresh || _fplPos == _kln89->_flightPlans[_subPage]->waypoints.size() - thresh) {
868                                         // Don't move
869                                 } else {
870                                         _fplPos++;
871                                 }
872                         }
873                         
874                         if(_subPage == 0 && _uLinePos > 3) {
875                                 int ix = _fplPos + (_uLinePos - 4);
876                                 if(_fencePos >= 0 && ix >= _fencePos) ix--;
877                                 if(_hdrPos >= 0 && ix >= _hdrPos) ix--;
878                                 if(ix >= _kln89->_activeFP->waypoints.size()) {
879                                         _fp0SelWpId.clear();
880                                 } else {
881                                         _fp0SelWpId = _kln89->_activeFP->waypoints[ix]->id;
882                                 }
883                         } else {
884                                 _fp0SelWpId.clear();
885                                 //cout << "Not page 0, or not in waypoints, clearing id!\n";
886                         }
887                 }
888         }
889 }
890
891 void KLN89FplPage::Knob2Left1() {
892         if(_delFP) {
893                 _delFP = false;
894                 return;
895         }
896         _delWp = false;
897
898         if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
899                 if(_kln89->_mode != KLN89_MODE_CRSR) _resetFplPos0 = true;
900                 KLN89Page::Knob2Left1();
901         } else {
902                 if(_uLinePos > 3) {
903                         // Check for approach waypoints or header/fences in flightplan 0
904                         int n = _fplPos + _uLinePos - 4;
905                         bool hdrPos = false;
906                         bool fencePos = false;
907                         bool appWp = false;
908                         //cout << "_fplPos = " << _fplPos << ", _uLinePos = " << _uLinePos << ", n = " << n << ", _hdrPos = " << _hdrPos << ", _fencePos = " << _fencePos << '\n';
909                         if(n == _hdrPos) {
910                                 //cout << "HEADER POS\n";
911                                 hdrPos = true;
912                         }
913                         if(n == _fencePos) {
914                                 //cout << "FENCE POS\n";
915                                 fencePos = true;
916                         }
917                         if(_hdrPos >= 0 && n > _hdrPos) --n;
918                         if(_fencePos >= 0 && n >= _fencePos) --n;       // This one needs to be >= since n is already decremented by 1 in the line above!
919                         //cout << "New n = " << n << '\n';
920                         
921                         if(n < _kln89->_flightPlans[_subPage]->waypoints.size()) {
922                                 if(_kln89->_flightPlans[_subPage]->waypoints[n]->appType != GPS_APP_NONE) {
923                                         appWp = true;
924                                 }
925                         }
926                         
927                         if(hdrPos) {
928                                 // TODO - not sure what we actually do in this condition
929                                 _changeAppr = true;
930                         } else if(fencePos) {
931                                 // no-op?
932                         } else if(appWp) {
933                                 ShowScratchpadMessage("Invald", " Add  ");
934                         } else {
935                                 if((_wLinePos + 1) > _entWpStr.size()) {
936                                         _entWpStr += '9';
937                                 } else {
938                                         _entWpStr[_wLinePos] = _kln89->DecChar(_entWpStr[_wLinePos], (_wLinePos == 0 ? false : true));
939                                 }
940                                 _bEntWp = true;
941                                 _fp0SelWpId.clear();    // Waypoints don't become the DTO default whilst being entered.
942                                 
943         GPSWaypoint* wp = _kln89->FindFirstById(_entWpStr.substr(0, _wLinePos+1));
944                                 if(NULL == wp) {
945                                         // no-op
946                                 } else {
947                                         if(_entWp) {
948             *_entWp = *wp; // copy
949             delete wp;
950           } else {
951             _entWp = wp;
952             if(_fplPos + (_uLinePos - 4) >= _kln89->_flightPlans[_subPage]->waypoints.size()) {
953                                                         _kln89->_flightPlans[_subPage]->waypoints.push_back(_entWp);
954                                                 } else {
955                                                         _kln89->_flightPlans[_subPage]->waypoints.insert(_kln89->_flightPlans[_subPage]->waypoints.begin()+(_fplPos + (_uLinePos - 4)), _entWp);
956                                                 }
957           }
958                                 }
959                         }
960                 }
961         }
962 }
963
964 void KLN89FplPage::Knob2Right1() {
965         if(_delFP) {
966                 _delFP = false;
967                 return;
968         }
969         _delWp = false;
970
971         if(_kln89->_mode != KLN89_MODE_CRSR || _uLinePos == 0) {
972                 if(_kln89->_mode != KLN89_MODE_CRSR) _resetFplPos0 = true;
973                 KLN89Page::Knob2Right1();
974         } else {
975                 if(_uLinePos > 3) {
976                         // Check for approach waypoints or header/fences in flightplan 0
977                         int n = _fplPos + _uLinePos - 4;
978                         bool hdrPos = false;
979                         bool fencePos = false;
980                         bool appWp = false;
981                         //cout << "_fplPos = " << _fplPos << ", _uLinePos = " << _uLinePos << ", n = " << n << ", _hdrPos = " << _hdrPos << ", _fencePos = " << _fencePos << '\n';
982                         if(n == _hdrPos) {
983                                 //cout << "HEADER POS\n";
984                                 hdrPos = true;
985                         }
986                         if(n == _fencePos) {
987                                 //cout << "FENCE POS\n";
988                                 fencePos = true;
989                         }
990                         if(_hdrPos >= 0 && n > _hdrPos) --n;
991                         if(_fencePos >= 0 && n >= _fencePos) --n;       // This one needs to be >= since n is already decremented by 1 in the line above!
992                         //cout << "New n = " << n << '\n';
993                         
994                         if(n < _kln89->_flightPlans[_subPage]->waypoints.size()) {
995                                 if(_kln89->_flightPlans[_subPage]->waypoints[n]->appType != GPS_APP_NONE) {
996                                         appWp = true;
997                                 }
998                         }
999                         
1000                         if(hdrPos) {
1001                                 // TODO - not sure what we actually do in this condition
1002                                 _changeAppr = true;
1003                         } else if(fencePos) {
1004                                 // no-op?
1005                         } else if(appWp) {
1006                                 ShowScratchpadMessage("Invald", " Add  ");
1007                         } else {
1008                                 if((_wLinePos + 1) > _entWpStr.size()) {
1009                                         _entWpStr += '9';
1010                                 } else {
1011                                         _entWpStr[_wLinePos] = _kln89->DecChar(_entWpStr[_wLinePos], (_wLinePos == 0 ? false : true));
1012                                 }
1013                                 _bEntWp = true;
1014                                 _fp0SelWpId.clear();    // Waypoints don't become the DTO default whilst being entered.
1015                                 
1016         GPSWaypoint* wp = _kln89->FindFirstById(_entWpStr.substr(0, _wLinePos+1));
1017                                 if(NULL == wp) {
1018                                         // no-op
1019                                 } else {
1020                                         if(_entWp) {
1021             *_entWp = *wp; // copy
1022             delete wp;
1023           } else {
1024             _entWp = wp;
1025             if(_fplPos + (_uLinePos - 4) >= _kln89->_flightPlans[_subPage]->waypoints.size()) {
1026                                                         _kln89->_flightPlans[_subPage]->waypoints.push_back(_entWp);
1027                                                 } else {
1028                                                         _kln89->_flightPlans[_subPage]->waypoints.insert(_kln89->_flightPlans[_subPage]->waypoints.begin()+(_fplPos + (_uLinePos - 4)), _entWp);
1029                                                 }
1030           }
1031                                 }
1032                         }
1033                 }
1034         }
1035 }