-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCFPNRadarScreen.cpp
More file actions
277 lines (211 loc) · 9.23 KB
/
CFPNRadarScreen.cpp
File metadata and controls
277 lines (211 loc) · 9.23 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
#include "pch.h"
#include "CFPNRadarScreen.h"
#include "CFPNRadarTarget.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream>
#include <iomanip>
CFPNRadarScreen::CFPNRadarScreen() {
}
CFPNRadarScreen::~CFPNRadarScreen() = default; // this is weird!
void CFPNRadarScreen::OnAsrContentLoaded(bool loaded) {
// TODO: load settings
}
void CFPNRadarScreen::OnAsrContentToBeSaved() {
// TODO: save settings
}
void CFPNRadarScreen::OnRefresh(HDC hDC, int Phase) {
if (Phase != EuroScopePlugIn::REFRESH_PHASE_BEFORE_TAGS) return;
CDC dc;
dc.Attach(hDC);
CRect radarArea = GetRadarArea();
dc.FillRect(radarArea, &CBrush(BACKGROUND_COLOUR));
//CRect chatArea = GetChatArea();
radarArea.DeflateRect(70, 50); // margins
radarArea.right -= radarArea.right / 4;
// Split screen in 2 across the middle
CRect glideslopeArea = CRect(radarArea.left, radarArea.top, radarArea.right, radarArea.CenterPoint().y);
CRect trackArea = CRect(radarArea.left, radarArea.CenterPoint().y, radarArea.right, radarArea.bottom);
glideslopeArea.bottom -= 30;
trackArea.top += 30;
int range = ((CFPNPlugin*)GetPlugIn())->range;
drawVerticalScale(&dc, glideslopeArea, trackArea, range);
drawGlidepathAndHorizontalTicks(&dc, glideslopeArea, trackArea, range, 3.0f);
drawGSAxes(&dc, glideslopeArea);
drawTrackAxes(&dc, trackArea);
drawInfoText(&dc, glideslopeArea.left + 80, glideslopeArea.bottom - 10);
EuroScopePlugIn::CPosition runwayThreshold = ((CFPNPlugin*)GetPlugIn())->runwayThreshold;
//runwayThreshold.LoadFromStrings("W000.10.19.000", "N051.09.02.420");
EuroScopePlugIn::CPosition otherThreshold = ((CFPNPlugin*)GetPlugIn())->otherThreshold;
//otherThreshold.LoadFromStrings("W000.12.24.520", "N051.08.45.120");
std::vector<std::string> foundCallsigns = std::vector<std::string>();
for (EuroScopePlugIn::CRadarTarget target = GetPlugIn()->RadarTargetSelectFirst(); target.IsValid(); target = GetPlugIn()->RadarTargetSelectNext(target)) {
EuroScopePlugIn::CPosition pos = target.GetPosition().GetPosition();
if (pos.DistanceTo(runwayThreshold) > range * 1.5) continue;
int altitude = target.GetPosition().GetPressureAltitude();
float hdgToRunway = pos.DirectionTo(runwayThreshold);
float trackDeviationAngle = runwayThreshold.DirectionTo(otherThreshold) - hdgToRunway;
if (abs(trackDeviationAngle) > 8) continue;
std::string callsign = target.GetCallsign();
foundCallsigns.push_back(callsign);
bool found = false;
std::vector<CFPNRadarTarget> *prevTargets = ((CFPNPlugin*)GetPlugIn())->getPreviousTargets();
for (int i = 0; i < prevTargets->size(); i++) {
if ((prevTargets->at(i)).callsign == callsign) {
(prevTargets->at(i)).updatePosition(pos, altitude, range, runwayThreshold, otherThreshold);
(prevTargets->at(i)).draw(&dc);
found = true;
break;
}
}
if (!found) {
CFPNRadarTarget targetPlot = CFPNRadarTarget(callsign, pos, altitude, runwayThreshold, runwayThreshold.DirectionTo(otherThreshold), range, 3.0f, glideslopeArea, trackArea);
targetPlot.draw(&dc);
prevTargets->push_back(targetPlot);
}
}
/*EuroScopePlugIn::CPosition pos;
pos.LoadFromStrings("E000.01.00.319", "N051.10.17.164");
int altitude = 3000;
CFPNRadarTarget targetPlot = CFPNRadarTarget(pos, altitude, runwayThreshold, runwayThreshold.DirectionTo(otherThreshold), range, 3.0f, glideslopeArea, trackArea);
targetPlot.draw(&dc, (CFPNPlugin*)GetPlugIn());*/
dc.Detach();
}
void CFPNRadarScreen::drawGSAxes(CDC *pDC, CRect area) {
CPen axesPen(0, 2, AXES_COLOUR);
pDC->SelectObject(&axesPen);
// Y Axis
pDC->MoveTo(area.left, area.top);
pDC->LineTo(area.left, area.bottom);
// X Axis
int xAxisHeight = area.bottom + (area.top - area.bottom) / 9;
int xAxisLeft = area.left + X_AXIS_OFFSET;
pDC->MoveTo(xAxisLeft, xAxisHeight);
pDC->LineTo(area.right, xAxisHeight);
}
void CFPNRadarScreen::drawTrackAxes(CDC* pDC, CRect area) {
CPen axesPen(0, 2, AXES_COLOUR);
pDC->SelectObject(&axesPen);
// Y Axis
pDC->MoveTo(area.left, area.top);
pDC->LineTo(area.left, area.bottom);
// X Axis
int xAxisHeight = area.CenterPoint().y;
int xAxisLeft = area.left + X_AXIS_OFFSET;
pDC->MoveTo(xAxisLeft, xAxisHeight);
pDC->LineTo(area.right, xAxisHeight);
}
void CFPNRadarScreen::drawVerticalScale(CDC* pDC, CRect glideslopeArea, CRect trackArea, int range) {
CPen axesPen(0, 2, AXES_COLOUR);
pDC->SelectObject(&axesPen);
CFont font;
font.CreatePointFont(100, L"Courier New Bold", pDC);
pDC->SetTextColor(AXES_COLOUR);
pDC->SetTextAlign(TA_RIGHT);
auto* defFont = pDC->SelectObject(&font);
// Glideslope
pDC->MoveTo(glideslopeArea.left - 8, glideslopeArea.bottom);
pDC->LineTo(glideslopeArea.left + 8, glideslopeArea.bottom);
pDC->TextOutW(glideslopeArea.left - 13, glideslopeArea.bottom - 9, ("-" + std::to_string(range * 100)).c_str());
for (int i = 1; i <= 4; i++) {
int yPos = glideslopeArea.bottom + (glideslopeArea.top - glideslopeArea.bottom) * (2 * i + 1) / 9;
pDC->MoveTo(glideslopeArea.left - 8, yPos);
pDC->LineTo(glideslopeArea.left + 8, yPos);
pDC->TextOutW(glideslopeArea.left - 13, yPos - 7, std::to_string(i * 200 * range).c_str());
}
// Track
for (int i = 0; i <= 8; i++) {
if (i == 4) continue;
int yPos = trackArea.bottom + (trackArea.top - trackArea.bottom) * i / 8;
pDC->MoveTo(trackArea.left - 8, yPos);
pDC->LineTo(trackArea.left + 8, yPos);
pDC->TextOutW(trackArea.left - 13, yPos - 7, std::to_string((i - 4) * 400 * range).c_str());
}
pDC->SelectObject(defFont);
font.DeleteObject();
}
void CFPNRadarScreen::drawHorizontalScale(CDC* pDC, CRect glideslopeArea, CRect trackArea, int range) {
CPen axesPen(0, 2, AXES_COLOUR);
pDC->SelectObject(&axesPen);
CFont font;
font.CreatePointFont(100, L"Courier New Bold", pDC);
pDC->SetTextColor(AXES_COLOUR);
pDC->SetTextAlign(TA_RIGHT);
auto* defFont = pDC->SelectObject(&font);
pDC->SelectObject(defFont);
font.DeleteObject();
}
void CFPNRadarScreen::drawGlidepathAndHorizontalTicks(CDC* pDC, CRect glideslopeArea, CRect trackArea, int range, float angle) {
// Glideslope
CPen glideslopePen(0, 2, GLIDESLOPE_COLOUR);
pDC->SelectObject(&glideslopePen);
int xAxisHeight = glideslopeArea.bottom + (glideslopeArea.top - glideslopeArea.bottom) / 9;
int xAxisLeft = glideslopeArea.left + X_AXIS_OFFSET;
int topOfGS = xAxisHeight + (tan(angle * (M_PI / 180)) * 6076.0f * ((float)range / (range * 200)) * (double)((glideslopeArea.top - glideslopeArea.bottom) * 2 / 9));
pDC->MoveTo(xAxisLeft, xAxisHeight);
pDC->LineTo(glideslopeArea.right, topOfGS);
// Track paths @ 1.25 and 3 degrees
CPen trackDeviationPen(0, 1, TRACK_DEVIATION_COLOUR);
pDC->SelectObject(&trackDeviationPen);
int trackXAxisHeight = trackArea.CenterPoint().y;
int trackXAxisLeft = trackArea.left + X_AXIS_OFFSET;
for (int i = 0; i < 4; i++) {
float angle;
if (i == 0) angle = 3.0f;
else if (i == 1) angle = 1.25f;
else if (i == 2) angle = -1.25f;
else if (i == 3) angle = -3.0f;
int trackOffset = trackXAxisHeight + (tan(angle * (M_PI / 180)) * 6076.0f * ((float)range / (range * 400)) * (double)((trackArea.top - trackArea.bottom) / 8));
pDC->MoveTo(trackXAxisLeft, trackXAxisHeight);
pDC->LineTo(trackArea.right, trackOffset);
}
// Both axis ticks and text
CPen axesPen(0, 2, AXES_COLOUR);
pDC->SelectObject(&axesPen);
CFont font;
font.CreatePointFont(120, L"Courier New Bold", pDC);
pDC->SetTextColor(AXES_COLOUR);
pDC->SetTextAlign(TA_CENTER);
auto* defFont = pDC->SelectObject(&font);
for (int i = 0; i <= range * 2; i++) {
int xPos = xAxisLeft + (glideslopeArea.right - xAxisLeft) * i / (range * 2);
int displacement = i % 2 == 0 ? 8 : 4;
pDC->MoveTo(xPos, xAxisHeight - displacement); // GS
pDC->LineTo(xPos, xAxisHeight + displacement);
if (i % 2 == 0) pDC->TextOutW(xPos, xAxisHeight + 9, std::to_string(i / 2).c_str());
pDC->MoveTo(xPos, trackXAxisHeight - displacement); // track
pDC->LineTo(xPos, trackXAxisHeight + displacement);
if (i % 2 == 0) pDC->TextOutW(xPos, trackXAxisHeight + 9, std::to_string(i / 2).c_str());
}
// GS Ticks
pDC->SelectObject(&glideslopePen);
for (int i = 0; i <= range * 2; i++) {
int xPos = xAxisLeft + (glideslopeArea.right - xAxisLeft) * i / (range * 2);
int displacement = i % 2 == 0 ? 8 : 4;
int yPos = xAxisHeight + (tan(angle * (M_PI / 180)) * 6076.0f * (((float)i/2.0f) / (range * 200)) * (double)((glideslopeArea.top - glideslopeArea.bottom) * 2 / 9));
pDC->MoveTo(xPos, yPos - displacement); // GS
pDC->LineTo(xPos, yPos + displacement);
}
pDC->SelectObject(defFont);
font.DeleteObject();
}
void CFPNRadarScreen::drawInfoText(CDC* pDC, int x, int y) {
CFont font;
font.CreatePointFont(130, L"Courier New Bold", pDC);
pDC->SetTextColor(RGB(200, 255, 211));
pDC->SetTextAlign(TA_LEFT);
auto* defFont = pDC->SelectObject(&font);
std::string text = "GS: 3.0 RWY: ";
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << ((CFPNPlugin*)GetPlugIn())->runwayThreshold.DirectionTo(((CFPNPlugin*)GetPlugIn())->otherThreshold);
text += stream.str();
text += " DH: 200FT TIME : ";
SYSTEMTIME st;
GetSystemTime(&st);
text += (st.wHour < 10 ? "0" : "") + std::to_string(st.wHour) + ":"
+ (st.wMinute < 10 ? "0" : "") + std::to_string(st.wMinute) + ":"
+ (st.wSecond < 10 ? "0" : "") + std::to_string(st.wSecond);
pDC->TextOutW(x, y, text.c_str());
pDC->SelectObject(defFont);
font.DeleteObject();
}