-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpfd.cpp
More file actions
286 lines (220 loc) · 8.51 KB
/
Copy pathpfd.cpp
File metadata and controls
286 lines (220 loc) · 8.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
pfd.cpp - A Primary Flight Display OpenGL Avionics Widget
Copyright (C) 2003 Tom Dollmeyer (tom@dollmeyer.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
ToDo List
- add dive/climb arrows
- add standard rate turn indicators
- add hnav & vnav indicators
- add crab orientation
- add flight director bars
- add 3d terrain mapping
- convert to designer plugin
*/
#include <math.h>
#include "pfd.h"
#include <qstring.h>
#include <qfont.h>
#include <qgl.h>
#include <qlayout.h>
#include <qslider.h>
#include <qlabel.h>
#include <qpushbutton.h>
//Added by qt3to4:
#include <Q3GridLayout>
#if defined(Q_CC_MSVC)
#pragma warning(disable:4305) // init: truncation from const double to float
#endif
/*!
Create a GLPFD widget
*/
GLPFD::GLPFD( QWidget* parent, const char* name, const QGLWidget* shareWidget )
: QGLWidget( parent, name, shareWidget )
{
pitchTranslation = rollRotation = 0.0; // default object translation and rotation
IASTranslation = 0.0; // default IAS tape translation
IASValue = 0; // The default to show if no IAS calls come in
MSLTranslation = 0.0; // default MSL tape translation
MSLValue = 0; // The default to show if no MSL calls come in
VSIValue = 0; // The default vertical speed
// These should come from a cal file
Vs0 = 59;
Vs1 = 70;
Vx = 86;
Vy = 103;
Vfe = 122;
Va = 126;
Vno = 174;
Vne = 226;
IASMaxDisp = 200; // 400;
//MSLMinDisp = -10; //-fl 10 = -1000ft //-5000;
//MSLMaxDisp = 200; // fl 200 = 20000ft // 35000;
MSLMinDisp = -1000;
MSLMaxDisp = 20000;
displayTerrain = true;
displayTape = true;
}
/*!
Create a GLPFD widget
*/
GLPFD::GLPFD( const QGLFormat& format, QWidget* parent, const char* name,
const QGLWidget* shareWidget )
: QGLWidget( format, parent, name, shareWidget )
{
pitchTranslation = rollRotation = 0.0; // default object translation and rotation
IASTranslation = 0.0; // default object translation
IASValue = 0; // The default to show if on IAS calls come in
MSLTranslation = 0.0; // default MSL tape translation
MSLValue = 0; // The default to show if no MSL calls come in
VSIValue = 0; // The default vertical speed
// These should come from a cal file
Vs0 = 59;
Vs1 = 70;
Vx = 86;
Vy = 103;
Vfe = 122;
Va = 126;
Vno = 174;
Vne = 226;
IASMaxDisp = 400;
MSLMinDisp = -5000;
MSLMaxDisp = 35000;
displayTerrain = true;
displayTape = true;
}
/*!
Release allocated resources
*/
GLPFD::~GLPFD()
{
makeCurrent();
}
/*!
Set up the OpenGL rendering state, and define display list
*/
void GLPFD::initializeGL()
{
qglClearColor( QColor( eraseColor()) ); // Let OpenGL clear to background color
glEnable( GL_DEPTH_TEST );
}
/*!
Set up the OpenGL view port, matrix mode, etc.
*/
void GLPFD::resizeGL( int w, int h )
{
// Capture the window scaling for use by the rendering functions
pixW = w;
pixH = h;
pixW2 = w/2;
pixH2 = h/2;
// Set the window size specific scales, positions and sizes (nothing dynamic yet...)
pitchInView = 25.0; // degrees to display from horizon to top of viewport
IASInView = 25.0; // IAS units to display from center to top of viewport
MSLInView = 250.0; // IAS units to display from center to top of viewport
glViewport( 0, 0, (GLint)w, (GLint)h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(-pixW2, pixW2, -pixH2, pixH2, 0.0, 10.0);
}
void GLPFD::paintGL()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, 0.0 );
glScalef( 1.0, 1.0, 1.0 ); // drawing normal ie not mirrored
//glScalef( -1.0, 1.0, 1.0 ); // drawing mirrored but not the text ??
zfloat = -1.0; // Set the z position for ortho drawing
renderFixedASIMarkers(); // Draw the ASI fixed markings
renderFixedALTMarkers(); // Draw the ALT fixed markings
renderVSIValue(); // Draw the VSI digital display
renderHDGValue();
renderGForceValue();
//b2 start
renderFixedDIMarkers();
renderSlipBall();
if (!calibrated) {
renderCalibrate();
//return;
}
//b2 end
glTranslatef( 3.7 * pixH2, 0.0, 0.0); // Slide over to draw the VSI gauge
if (displayTape) renderFixedVSIMarkers();
// Slide ASI to current value
glTranslatef( - 3.7 * pixH2, -IASTranslation, 0.0);
if (displayTape) renderIASMarkers(); // Draw the ASI tape
// Slide ALT to current value
glTranslatef(0.0, IASTranslation-MSLTranslation, 0.0);
if (displayTape) renderMSLMarkers(); // Draw the ALT tape
zfloat = -2.0; // Put the horizon behind the tapes
glTranslatef( 0.0, MSLTranslation, 0.0); // Slide back,
renderFixedHorizonMarkers(); // draw the horizon fixed markings
glRotatef( rollRotation, 0.0, 0.0, 1.0 ); // then Roll,
renderRollMarkers(); // and draw the markers that roll but do not pitch
glTranslatef( 0.0, pitchTranslation, 0.0); // Pitch while rolled,
renderPitchMarkers(); // draw the pitch markers,
zfloat = -5.0; // Put the terrain behind everything else
if (displayTerrain) renderTerrain(); // draw the terrain
}
/*!
Launch a test dialog for the PFD
*/
void GLPFD::testPFD()
{
int r;
//TestPFD testpfd( this,0,TRUE,Qt::WStyle_Customize|Qt::WStyle_DialogBorder|Qt::Qt::WStyle_StaysOnTop);
TestPFD testpfd( this,0,TRUE); //,Qt::WStyle_Customize|Qt::WStyle_DialogBorder|Qt::WStyle_StaysOnTop);
testpfd.setCaption("PFD Input Overrides");
testpfd.resize( 333, 222 );
r = testpfd.exec();
}
TestPFD::TestPFD( QWidget* parent, const char* name,
bool modal, Qt::WFlags f )
: QDialog( parent, name, modal, f )
{
setCaption( "PFD -- Manual Control" );
// Define the Controls
QSlider* pitchSlider = new QSlider ( -360, 360, 60, 0, Qt::Horizontal, this, "pitchSlider" );
pitchSlider->setTickmarks( QSlider::TicksAbove );
QLabel* pitchSliderLabel = new QLabel( "Pitch", this, "pitchSliderLabel" );
connect( pitchSlider, SIGNAL(valueChanged(int)), parent, SLOT(setPitch(int)) );
QSlider* rollSlider = new QSlider ( -360, 360, 60, 0, Qt::Horizontal, this, "rollSlider" );
QLabel* rollSliderLabel = new QLabel( "Roll", this, "rollSliderLabel" );
connect( rollSlider, SIGNAL(valueChanged(int)), parent, SLOT(setRoll(int)) );
QSlider* IASSlider = new QSlider ( 0, 360, 6, 0, Qt::Horizontal, this, "IASSlider" );
QLabel* IASSliderLabel = new QLabel( "IAS", this, "IASSliderLabel" );
connect( IASSlider, SIGNAL(valueChanged(int)), parent, SLOT(setIAS(int)) );
QSlider* MSLSlider = new QSlider ( -3000, 12000, 60, 0, Qt::Horizontal, this, "MSLSlider" );
QLabel* MSLSliderLabel = new QLabel( "MSL", this, "MSLSliderLabel" );
connect( MSLSlider, SIGNAL(valueChanged(int)), parent, SLOT(setMSL(int)) );
QSlider* VSISlider = new QSlider ( -5000, 5000, 50, 0, Qt::Horizontal, this, "VSISlider" );
QLabel* VSISliderLabel = new QLabel( "VSI", this, "VSISliderLabel" );
connect( VSISlider, SIGNAL(valueChanged(int)), parent, SLOT(setVSI(int)) );
QPushButton* cancelPushButton = new QPushButton( "&Close Dialog", this );
connect( cancelPushButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
// Put manual PFD controls in the window
Q3GridLayout* PFDControlBox = new Q3GridLayout( this, 6, 2, 5, 5, "gridLayout");
PFDControlBox->addWidget( pitchSliderLabel, 0, 0 );
PFDControlBox->addWidget( pitchSlider, 0, 1 );
PFDControlBox->addWidget( rollSliderLabel, 1, 0 );
PFDControlBox->addWidget( rollSlider, 1, 1 );
PFDControlBox->addWidget( IASSliderLabel, 2, 0 );
PFDControlBox->addWidget( IASSlider, 2, 1 );
PFDControlBox->addWidget( MSLSliderLabel, 3, 0 );
PFDControlBox->addWidget( MSLSlider, 3, 1 );
PFDControlBox->addWidget( VSISliderLabel, 4, 0 );
PFDControlBox->addWidget( VSISlider, 4, 1 );
PFDControlBox->addWidget( cancelPushButton, 5, 1 );
}