]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/KLN89/kln89_page.cxx
James Turner : this patch
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page.cxx
1 // kln89_page.cxx - base class for 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 #include "kln89_page.hxx"
25 #include <Main/fg_props.hxx>
26
27 KLN89Page::KLN89Page(KLN89* parent) 
28 : GPSPage(parent) {
29         _kln89 = (KLN89*)parent;
30         _entInvert = false;
31         _to_flag = true;
32 }
33
34 KLN89Page::~KLN89Page() {
35 }
36
37 void KLN89Page::Update(double dt) {
38         bool crsr = (_kln89->_mode == KLN89_MODE_CRSR ? true : false);
39         bool nav1 = (_name == "NAV" && _subPage == 0);
40         bool nav4 = (_name == "NAV" && _subPage == 3);
41         // The extra level of check for the ACT page is necessary since
42         // ACT is implemented by using the other waypoint pages as
43         // appropriate.
44         bool act = (_kln89->_activePage->GetName() == "ACT");
45         _kln89->DrawDivider();
46         if(crsr) {
47                 if(!nav4) _kln89->DrawText("*CRSR*", 1, 0, 0);
48                 if(_uLinePos == 0) _kln89->Underline(1, 3, 1, 3);
49         } else {
50                 if(!nav4) {
51                         if(act) {
52                                 _kln89->DrawText("ACT", 1, 0, 0);
53                         } else {
54                                 _kln89->DrawText(_name, 1, 0, 0);
55                         }
56                         if(_name == "DIR") {
57                                 // Don't draw a subpage number
58                         } else if(_name == "USR" || _name == "FPL") {
59                                 // Zero-based
60                                 _kln89->DrawText(GPSitoa(_subPage), 1, 4, 0);
61                         } else {
62                                 // One-based
63                                 _kln89->DrawText(GPSitoa(_subPage+1), 1, 4, 0);
64                         }
65                 }
66         }
67         if(crsr && _uLinePos == 0 && _kln89->_blink) {
68                 // Don't draw
69         } else {
70                 if(_kln89->_obsMode) {
71                         _kln89->DrawText(GPSitoa(_kln89->_obsHeading), 1, 3, 1);
72                 } else {
73                         _kln89->DrawText("Leg", 1, 3, 1);
74                 }
75         }
76         _kln89->DrawText((_kln89->GetDistVelUnitsSI() ? "km" : "nm"), 1, 4, 3);
77         GPSWaypoint* awp = _parent->GetActiveWaypoint();
78         if(_kln89->_navFlagged) {
79                 _kln89->DrawText("--.-", 1, 0 ,3);
80                 // Only nav1 still gets speed drawn if nav is flagged - not ACT
81                 if(!nav1) _kln89->DrawText("------", 1, 0, 2);
82         } else {
83                 char buf[8];
84                 float f = _parent->GetDistToActiveWaypoint() * (_kln89->GetDistVelUnitsSI() ? 0.001 : SG_METER_TO_NM);
85                 snprintf(buf, 5, (f >= 100.0 ? "%4.0f" : "%4.1f"), f);
86                 string s = buf;
87                 _kln89->DrawText(s, 1, 4 - s.size(), 3, true);
88                 // Draw active waypoint ID, except for
89                 // nav1, act, and any waypoint pages matching 
90                 // active waypoint that need speed drawn instead.
91                 if(act || nav1 || (awp && awp->id == _id)) {
92                         _kln89->DrawSpeed(_kln89->_groundSpeed_kts, 1, 5, 2);
93                 } else {
94                         if(!(_kln89->_waypointAlert && _kln89->_blink)) _kln89->DrawText(awp->id, 1, 0, 2);
95                 }
96         }
97         /*
98         if(_noNrst) {
99                 _kln89->DrawText("  No  ", 1, 0, 1, false, 99);
100                 _kln89->DrawText(" Nrst ", 1, 0, 0, false, 99);
101         }
102         */
103         if(_scratchpadMsg) {
104                 _kln89->DrawText(_scratchpadLine1, 1, 0, 1, false, 99);
105                 _kln89->DrawText(_scratchpadLine2, 1, 0, 0, false, 99);
106                 _scratchpadTimer += dt;
107                 if(_scratchpadTimer > 4.0) {
108                         _scratchpadMsg = false;
109                         _scratchpadTimer = 0.0;
110                 }
111         }
112 }
113
114 void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
115         _scratchpadLine1 = line1;
116         _scratchpadLine2 = line2;
117         _scratchpadTimer = 0.0;
118         _scratchpadMsg = true;
119 }       
120
121 void KLN89Page::Knob1Left1() {
122         if(_kln89->_mode == KLN89_MODE_CRSR) {
123                 if(_uLinePos > 0) _uLinePos--;
124         }
125 }
126
127 void KLN89Page::Knob1Right1() {
128         if(_kln89->_mode == KLN89_MODE_CRSR) {
129                 if(_uLinePos < _maxULinePos) _uLinePos++;
130         }
131 }
132
133 void KLN89Page::Knob2Left1() {
134         if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
135                 GPSPage::Knob2Left1(); 
136         } else {
137                 if(_uLinePos == 0 && _kln89->_obsMode) {
138                         _kln89->_obsHeading--;
139                         if(_kln89->_obsHeading < 0) {
140                                 _kln89->_obsHeading += 360;
141                         }
142                         _kln89->SetOBSFromWaypoint();
143                 }
144         }
145 }
146
147 void KLN89Page::Knob2Right1() {
148         if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
149                 GPSPage::Knob2Right1(); 
150         } else {
151                 if(_uLinePos == 0 && _kln89->_obsMode) {
152                         _kln89->_obsHeading++;
153                         if(_kln89->_obsHeading > 359) {
154                                 _kln89->_obsHeading -= 360;
155                         }
156                         _kln89->SetOBSFromWaypoint();
157                 }
158         }
159 }
160
161 void KLN89Page::CrsrPressed() {
162         // Stick some sensible defaults in
163         if(_kln89->_obsMode) {
164                 _uLinePos = 0;
165         } else {
166                 _uLinePos = 1;
167         }
168         _maxULinePos = 1;
169 }
170
171 void KLN89Page::EntPressed() {}
172 void KLN89Page::ClrPressed() {}
173 void KLN89Page::DtoPressed() {}
174 void KLN89Page::NrstPressed() {}
175 void KLN89Page::AltPressed() {}
176
177 void KLN89Page::OBSPressed() {
178         if(_kln89->_obsMode) {
179                 // If ORS2 and not slaved to gps
180                 _uLinePos = 0;
181         } else {
182                 // Don't leave the cursor on in the leg position.
183                 if(_uLinePos == 0) {
184                         _kln89->_mode = KLN89_MODE_DISP;
185                 }
186         }
187 }
188
189 void KLN89Page::MsgPressed() {}
190
191 void KLN89Page::CleanUp() {
192         _kln89->_cleanUpPage = -1;
193 }
194
195 void KLN89Page::LooseFocus() {
196         _entInvert = false;
197 }
198
199 void KLN89Page::SetId(const string& s) {
200         _id = s;
201 }
202
203 const string& KLN89Page::GetId() {
204         return(_id);
205 }