-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCSiTRadar.cpp
3680 lines (2904 loc) · 126 KB
/
CSiTRadar.cpp
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "pch.h"
#include "CSiTRadar.h"
using namespace Gdiplus;
// Initialize Static Members
unordered_map<string, ACData> CSiTRadar::mAcData;
unordered_map<string, int> CSiTRadar::tempTagData;
map<string, menuButton> TopMenu::menuButtons;
unordered_map<string, clock_t> CSiTRadar::hoAcceptedTime;
map<string, bool> CSiTRadar::destAirportList;
buttonStates CSiTRadar::menuState = {};
bool CSiTRadar::halfSecTick = FALSE;
CRadarScreen* CSiTRadar::m_pRadScr;
unordered_map<int, ACList> acLists;
unordered_map<string, bool> CSiTRadar::acADSB;
unordered_map<string, bool> CSiTRadar::acRVSM;
CSiTRadar::CSiTRadar()
{
m_pRadScr = this;
halfSec = clock();
halfSecTick = FALSE;
menuState.haloRad = 5;
menuState.ptlTool = FALSE;
menuLayer = 0;
#pragma region intializeLists
//initialize lists
ACList atisList, offScreenList;
atisList.listType = LIST_TIME_ATIS;
atisList.p = { 500,84 }; // Default Location
offScreenList.p = { 0,500 }; // Default Location
offScreenList.listType = LIST_OFF_SCREEN;
acLists[LIST_TIME_ATIS] = atisList;
acLists[LIST_OFF_SCREEN] = offScreenList;
#pragma endregion
// load settings file
try {
if (menuState.ctrlRemarkDefaults.size() < 7) {
for (int i = (int)menuState.ctrlRemarkDefaults.size(); i < 7; i++) {
menuState.ctrlRemarkDefaults.emplace_back("");
}
}
std::ifstream settings_file(".\\situWx\\settings.json");
if (settings_file.is_open()) {
json j = json::parse(settings_file);
wxRadar::wxLatCtr = j["wxlat"];
wxRadar::wxLongCtr = j["wxlong"];
acLists[LIST_TIME_ATIS].p.x = j["atisList"]["x"];
acLists[LIST_TIME_ATIS].p.y = j["atisList"]["y"];
acLists[LIST_OFF_SCREEN].p.x = j["offScreenList"]["x"];
acLists[LIST_OFF_SCREEN].p.y = j["offScreenList"]["y"];
menuState.numHistoryDots = j["menuState"]["numHistoryDots"];
menuState.bigACID = j["menuState"]["bigACID"];
menuState.wxAll = j["menuState"]["wxAll"];
menuState.filterBypassAll = j["menuState"]["filterBypassAll"];
menuState.extAltToggle = j["menuState"]["extAltToggle"];
if (!j["prefSFI"].is_null()) {
menuState.SFIPrefStringDefault = j["prefSFI"];
}
if (!j["ctrlRemarks"].is_null()) {
for (int i = 0; i < 7; i++) {
menuState.ctrlRemarkDefaults[i] = j["ctrlRemarks"][i];
}
}
}
// write defaults if no file
else {
std::ofstream settings_file(".\\situWx\\settings.json");
json j;
j["wxlat"] = wxRadar::wxLatCtr;
j["wxlong"] = wxRadar::wxLongCtr;
j["atisList"]["x"] = acLists[LIST_TIME_ATIS].p.x;
j["atisList"]["y"] = acLists[LIST_TIME_ATIS].p.y;
j["offScreenList"]["x"] = acLists[LIST_OFF_SCREEN].p.x;
j["offScreenList"]["y"] = acLists[LIST_OFF_SCREEN].p.y;
j["prefSFI"] = menuState.SFIPrefStringDefault;
j["ctrlRemarks"] = menuState.ctrlRemarkDefaults;
j["menuState"]["numHistoryDots"] = menuState.numHistoryDots;
j["menuState"]["bigACID"] = menuState.bigACID;
j["menuState"]["wxAll"] = menuState.wxAll;
j["menuState"]["filterBypassAll"] = menuState.filterBypassAll;
j["menuState"]["extAltToggle"] = menuState.extAltToggle;
settings_file << j;
}
}
catch (std::ifstream::failure e) {
};
try {
if ( (((clock() - menuState.lastWxRefresh) / CLOCKS_PER_SEC) > 600 && (menuState.wxAll || menuState.wxHigh)) ||
menuState.lastWxRefresh == 0) {
std::future<void> fa = std::async(std::launch::async, wxRadar::GetRainViewerJSON, this);
std::future<void> fb = std::async(std::launch::async, wxRadar::parseRadarPNG, this);
menuState.lastWxRefresh = clock();
}
// on intial load, only do once so that asr loading is not slowed (update will happen "on refresh" afterwards)
if (menuState.lastMetarRefresh == 0) {
std::thread tc(wxRadar::parseVatsimMetar, 0);
tc.detach();
//std::future<void> fc = std::async(std::launch::async, wxRadar::parseVatsimMetar, 0);
menuState.lastMetarRefresh = clock();
}
if (menuState.lastAtisRefresh == 0) {
std::thread td(wxRadar::parseVatsimATIS, 0);
td.detach();
//std::future<void> fd = std::async(std::launch::async, wxRadar::parseVatsimATIS, 0);
menuState.lastAtisRefresh = clock();
}
}
catch (...) {
GetPlugIn()->DisplayUserMessage("VATCAN Situ", "WX Parser", string("PNG Failed to Parse").c_str(), true, false, false, false, false);
}
CSiTRadar::mAcData.reserve(256);
time = clock();
oldTime = clock();
}
CSiTRadar::~CSiTRadar()
{
// Save settings file
try {
std::ifstream settings_file(".\\situWx\\settings.json");
if (settings_file.is_open()) {
std::ofstream settings_file(".\\situWx\\settings.json");
json j;
j["wxlat"] = wxRadar::wxLatCtr;
j["wxlong"] = wxRadar::wxLongCtr;
j["atisList"]["x"] = acLists[LIST_TIME_ATIS].p.x;
j["atisList"]["y"] = acLists[LIST_TIME_ATIS].p.y;
j["offScreenList"]["x"] = acLists[LIST_OFF_SCREEN].p.x;
j["offScreenList"]["y"] = acLists[LIST_OFF_SCREEN].p.y;
j["prefSFI"] = menuState.SFIPrefStringDefault;
j["ctrlRemarks"] = menuState.ctrlRemarkDefaults;
j["menuState"]["numHistoryDots"] = menuState.numHistoryDots;
j["menuState"]["bigACID"] = menuState.bigACID;
j["menuState"]["wxAll"] = menuState.wxAll;
j["menuState"]["filterBypassAll"] = menuState.filterBypassAll;
j["menuState"]["extAltToggle"] = menuState.extAltToggle;
settings_file << j;
}
}
catch (std::ifstream::failure e) {
};
m_pRadScr = nullptr;
}
void CSiTRadar::OnRefresh(HDC hdc, int phase)
{
std::future<void> fb, fc, fd;
if (m_pRadScr != this) {
m_pRadScr = this;
const char* sfi;
if ((sfi = GetDataFromAsr("prefSFI")) != NULL) {
menuState.SFIPrefStringASRSetting = sfi;
}
else {
menuState.SFIPrefStringASRSetting = menuState.SFIPrefStringDefault;
}
}
// if no windows are open, there can be no focused textfield
if (menuState.radarScrWindows.empty()) {
menuState.focusedItem.m_focus_on = false;
}
else {
// see if any focused items are set
menuState.focusedItem.m_focus_on = false;
for (auto& win : menuState.radarScrWindows) {
for (auto& tf : win.second.m_textfields_) {
if(tf.m_focused) {
menuState.focusedItem.m_focus_on = true;
menuState.focusedItem.m_focused_tf = &tf;
}
}
}
}
// get cursor position and screen info
POINT p;
if (GetCursorPos(&p)) {
if (ScreenToClient(GetActiveWindow(), &p)) {}
}
RECT radarea = GetRadarArea();
// Get threaded messages
for (auto &message : wxRadar::asyncMessages) {
GetPlugIn()->DisplayUserMessage("VATCAN Situ", "Warning", message.reponseMessage.c_str(), true, false, false, false, false);
}
wxRadar::asyncMessages.clear();
#pragma region timers
// time based functions
double time = ((double)clock() - (double)halfSec) / ((double)CLOCKS_PER_SEC);
if (time >= 0.5) {
halfSec = clock();
halfSecTick = !halfSecTick;
}
if (phase == REFRESH_PHASE_BEFORE_TAGS) {
if (((clock() - menuState.lastWxRefresh) / CLOCKS_PER_SEC) > 600 && (menuState.wxAll || menuState.wxHigh)) {
// autorefresh weather download every 10 minutes
fb = std::async(std::launch::async, wxRadar::parseRadarPNG, this);
menuState.lastWxRefresh = clock();
}
if (((clock() - menuState.lastMetarRefresh) / CLOCKS_PER_SEC) > 600) { // update METAR every 10 mins
std::thread tc(wxRadar::parseVatsimMetar, 0);
tc.detach();
// fc = std::async(std::launch::async, wxRadar::parseVatsimMetar, 0);
menuState.lastMetarRefresh = clock();
}
if (((clock() - menuState.lastAtisRefresh) / CLOCKS_PER_SEC) > 120) { // update ATIS letter every 2 mins
std::thread td(wxRadar::parseVatsimATIS, 0);
td.detach();
// fd = std::async(std::launch::async, wxRadar::parseVatsimATIS, 0);
menuState.lastAtisRefresh = clock();
}
if (((clock() - menuState.handoffModeStartTime) / CLOCKS_PER_SEC) > 10 && menuState.handoffMode) {
menuState.handoffMode = FALSE;
menuState.SFIMode = false;
CSiTRadar::menuState.jurisdictionIndex = 0;
SituPlugin::SendKeyboardPresses({ 0x01 });
}
// Garbage collect every 5 minutes
if (((clock() - menuState.lastAcListMaint) / CLOCKS_PER_SEC) > 300) {
menuState.recentCallsignsSeen.clear();
for (CRadarTarget radarTarget = GetPlugIn()->RadarTargetSelectFirst(); radarTarget.IsValid();
radarTarget = GetPlugIn()->RadarTargetSelectNext(radarTarget))
{
string callSign = radarTarget.GetCallsign();
// Get active radar targets for garbage cleaning
menuState.recentCallsignsSeen.emplace_back(callSign);
}
auto it = mAcData.cbegin();
while (it != mAcData.cend())
{
if (std::find(menuState.recentCallsignsSeen.begin(), menuState.recentCallsignsSeen.end(), it->first) == menuState.recentCallsignsSeen.end())
{
// supported in C++11
it = mAcData.erase(it);
}
else {
++it;
}
}
auto squawkCodeIt = menuState.squawkCodes.begin();
while (squawkCodeIt != menuState.squawkCodes.end())
{
if (std::find(menuState.recentCallsignsSeen.begin(), menuState.recentCallsignsSeen.end(), squawkCodeIt->fpcs) == menuState.recentCallsignsSeen.end())
{
squawkCodeIt = menuState.squawkCodes.erase(squawkCodeIt);
}
else {
++squawkCodeIt;
}
}
menuState.lastAcListMaint = clock();
GetPlugIn()->DisplayUserMessage("VATCAN Situ", "menuState.squawkCodes:", to_string(menuState.squawkCodes.size()).c_str(), true, false, false, false, false);
}
}
#pragma endregion
// set up the drawing renderer
CDC dc;
dc.Attach(hdc);
Graphics g(hdc);
double pixnm = PixelsPerNM();
// Check if ASR is an IFR file
if (GetDataFromAsr("DisplayTypeName") != NULL) {
string DisplayType = GetDataFromAsr("DisplayTypeName");
// VFR asrs should show the NARDS displays
if (strcmp(DisplayType.c_str(), "VFR") == 0) {
if (phase == REFRESH_PHASE_AFTER_TAGS) {
for (CRadarTarget radarTarget = GetPlugIn()->RadarTargetSelectFirst(); radarTarget.IsValid();
radarTarget = GetPlugIn()->RadarTargetSelectNext(radarTarget))
{
string callSign = radarTarget.GetCallsign();
CSiTRadar::mAcData[radarTarget.GetCallsign()].tagType = 1;
bool isCorrelated = radarTarget.GetCorrelatedFlightPlan().IsValid();
POINT p = ConvertCoordFromPositionToPixel(radarTarget.GetPosition().GetPosition());
// Altitude filters
if (!radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerIsMe() || strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), GetPlugIn()->ControllerMyself().GetPositionId()) == 0) {
if (altFilterOn && radarTarget.GetPosition().GetPressureAltitude() < altFilterLow * 100 && !menuState.filterBypassAll) {
continue;
}
if (altFilterOn && altFilterHigh > 0 && radarTarget.GetPosition().GetPressureAltitude() > altFilterHigh * 100 && !menuState.filterBypassAll) {
continue;
}
}
// draw PPS
bool isVFR = mAcData[callSign].hasVFRFP;
bool isRVSM = mAcData[callSign].isRVSM;
bool isADSB = mAcData[callSign].isADSB;
if ((!isCorrelated && !isADSB) || (radarTarget.GetPosition().GetRadarFlags() != 0 && isADSB && !isCorrelated)) {
mAcData[callSign].tagType = 3; // sets this if RT is uncorr
}
else if (isCorrelated && mAcData[callSign].tagType == 3) { mAcData[callSign].tagType = 0; } // only sets once to go from uncorr to corr
// then allows it to be opened closed etc
COLORREF ppsColor;
// logic for the color of the PPS
if (radarTarget.GetPosition().GetRadarFlags() == 0) { ppsColor = C_PPS_YELLOW; }
else if (radarTarget.GetPosition().GetRadarFlags() == 1 && !isCorrelated) { ppsColor = C_PPS_MAGENTA; }
else if (!strcmp(radarTarget.GetPosition().GetSquawk(), "7600") || !strcmp(radarTarget.GetPosition().GetSquawk(), "7700")) { ppsColor = C_PPS_RED; }
else if (isVFR && isCorrelated) { ppsColor = C_PPS_ORANGE; }
else { ppsColor = C_PPS_YELLOW; }
if (radarTarget.GetPosition().GetTransponderI() == TRUE && halfSecTick) { ppsColor = C_WHITE; }
RECT prect = CPPS::DrawPPS(&dc, isCorrelated, isVFR, isADSB, isRVSM, radarTarget.GetPosition().GetRadarFlags(), ppsColor, radarTarget.GetPosition().GetSquawk(), p);
AddScreenObject(AIRCRAFT_SYMBOL, callSign.c_str(), prect, FALSE, "");
// display CJS
if ((radarTarget.GetPosition().GetRadarFlags() >= 2 && isCorrelated) || CSiTRadar::mAcData[radarTarget.GetCallsign()].isADSB) {
string CJS = GetPlugIn()->FlightPlanSelect(callSign.c_str()).GetTrackingControllerId();
COLORREF cjsColor = C_PPS_YELLOW;
dc.SelectObject(CFontHelper::Euroscope14);
dc.SetTextColor(cjsColor);
RECT rectCJS;
rectCJS.left = p.x - 6;
rectCJS.right = p.x + 75;
rectCJS.top = p.y - 18;
rectCJS.bottom = p.y;
dc.DrawText(CJS.c_str(), &rectCJS, DT_LEFT);
}
if (radarTarget.GetPosition().GetRadarFlags() != 0) {
CACTag::DrawNARDSTag(&dc, this, &radarTarget, &radarTarget.GetCorrelatedFlightPlan(), &rtagOffset);
}
}
// NARDS Menu
}
}
// IFR asrs should display the CAATS QAB
if (strcmp(DisplayType.c_str(), "IFR") == 0) {
if (phase == REFRESH_PHASE_AFTER_TAGS) {
// Draw the mouse halo before menu, so it goes behind it
if (menuState.haloCursor == true) {
HaloTool::drawHalo(&dc, p, menuState.haloRad, pixnm);
SituPlugin::prevMouseDelta = 0; // sync refrehes
}
DrawACList(acLists[LIST_TIME_ATIS].p, &dc, mAcData, LIST_TIME_ATIS);
DrawACList(acLists[LIST_OFF_SCREEN].p, &dc, mAcData, LIST_OFF_SCREEN);
/*
CACList MessageList;
MessageList.m_listType = LIST_MESSAGES;
MessageList.m_dc = &dc;
MessageList.origin = { 800,85 };
MessageList.m_collapsed = false;
vector<string> msgList;
msgList.push_back("NO CORRELATION MULTI DISCRETE");
msgList.push_back("MULT DSCRT UNASSOC 2456");
MessageList.m_header = "Message List";
if (!msgList.empty()) { MessageList.m_header += " (" + to_string(msgList.size()) + ")"; }
MessageList.PopulatetList(msgList);
MessageList.DrawList();
*/
for (CRadarTarget radarTarget = GetPlugIn()->RadarTargetSelectFirst(); radarTarget.IsValid();
radarTarget = GetPlugIn()->RadarTargetSelectNext(radarTarget))
{
string callSign = radarTarget.GetCallsign();
if (menuState.filterBypassAll) {
mAcData[radarTarget.GetCallsign()].tagType = 1;
}
// Correlation check
if (radarTarget.GetPosition().GetRadarFlags() > 1) {
auto sqitr = find_if(menuState.squawkCodes.begin(), menuState.squawkCodes.end(), [&radarTarget](SSquawkCodeManagement& m)->bool {return !strcmp(m.squawk.c_str(), radarTarget.GetPosition().GetSquawk()); });
if (radarTarget.GetCorrelatedFlightPlan().IsValid()) {
if (sqitr == menuState.squawkCodes.end()) {
radarTarget.Uncorrelate();
}
}
else {
if (sqitr != menuState.squawkCodes.end()) {
int sqkc = atoi(radarTarget.GetPosition().GetSquawk());
if (sqkc == 1000 || sqkc == 1200 || sqkc == 1400 || sqkc == 2000) {}
else {
if (sqitr->numCorrelatedRT == 0) {
radarTarget.CorrelateWithFlightPlan(GetPlugIn()->FlightPlanSelect(sqitr->fpcs.c_str()));
sqitr->numCorrelatedRT++;
mAcData[callSign].multipleDiscrete = false;
}
else {
// Multiple discrete offender handling, squawk should be forced on and it should flash, and it should not correlate
radarTarget.Uncorrelate();
mAcData[callSign].multipleDiscrete = true;
//to-do add message to message list:
}
}
}
}
}
if (radarTarget.GetPosition().GetRadarFlags() < 2) {
if (radarTarget.GetPosition().GetRadarFlags() == 0 || !mAcData[radarTarget.GetCallsign()].manualCorr) {
radarTarget.Uncorrelate();
}
}
// altitude filtering
// Destination airport highlighting
auto itr = std::find(begin(CSiTRadar::menuState.destICAO), end(CSiTRadar::menuState.destICAO), radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetDestination());
bool isDest = false;
if (itr != end(CSiTRadar::menuState.destICAO)
&& strcmp(radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetDestination(), "") != 0) {
if (CSiTRadar::menuState.destArptOn[distance(CSiTRadar::menuState.destICAO, itr)]) {
isDest = true;
}
}
if (!radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerIsMe()) // Filter the aircraft if this statement is true, i.e. I'm not tracking
{
if (strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), GetPlugIn()->ControllerMyself().GetPositionId()) != 0 &&
strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), "") == 0) {
if (altFilterOn && radarTarget.GetPosition().GetPressureAltitude() < altFilterLow * 100
&& !menuState.filterBypassAll
) {
continue;
}
if (altFilterOn && altFilterHigh > 0 && radarTarget.GetPosition().GetPressureAltitude() > altFilterHigh * 100
&& !menuState.filterBypassAll
&& !isDest) {
if (radarTarget.GetPosition().GetRadarFlags() != 1) { // can't filter primary targets will make it just respect the high limit, to avoid ground clutter
continue;
}
}
}
}
POINT p = ConvertCoordFromPositionToPixel(radarTarget.GetPosition().GetPosition());
// Check if target is on the display area
if (p.y < GetRadarArea().top ||
p.y > GetRadarArea().bottom ||
p.x < GetRadarArea().left ||
p.x > GetRadarArea().right)
{
mAcData[radarTarget.GetCallsign()].isOnScreen = false;
}
else {
mAcData[radarTarget.GetCallsign()].isOnScreen = true;
}
// Draw pending direct to line if exists
if (mAcData[callSign].directToLineOn) {
HPEN targetPen;
targetPen = CreatePen(PS_DASHDOT, 1, C_WHITE);
dc.SelectObject(targetPen);
dc.MoveTo(p);
dc.LineTo(ConvertCoordFromPositionToPixel(mAcData[callSign].directToPendingPosition));
RECT dctFixNameRect;
dctFixNameRect.top = ConvertCoordFromPositionToPixel(mAcData[callSign].directToPendingPosition).y + 3;
dctFixNameRect.left = ConvertCoordFromPositionToPixel(mAcData[callSign].directToPendingPosition).x -15;
dc.DrawText(mAcData[callSign].directToPendingFixName.c_str(), &dctFixNameRect, DT_CENTER | DT_CALCRECT);
dc.DrawText(mAcData[callSign].directToPendingFixName.c_str(), &dctFixNameRect, DT_CENTER);
DeleteObject(targetPen);
}
// Get information about the Aircraft/Flightplan
bool isCorrelated = radarTarget.GetCorrelatedFlightPlan().IsValid();
bool isVFR = mAcData[callSign].hasVFRFP;
bool isRVSM = mAcData[callSign].isRVSM;
bool isADSB = mAcData[callSign].isADSB;
// Draw PTL
if (hasPTL.find(radarTarget.GetCallsign()) != hasPTL.end()) {
HaloTool::drawPTL(&dc, radarTarget, this, p, menuState.ptlLength);
}
else if (menuState.ptlAll && radarTarget.GetPosition().GetRadarFlags() != 0) {
if (radarTarget.GetPosition().GetRadarFlags() == 4 && !isADSB) {}
else {
HaloTool::drawPTL(&dc, radarTarget, this, p, menuState.ptlLength);
}
}
else if ((CSiTRadar::menuState.ebPTL && radarTarget.GetPosition().GetReportedHeading() > 0 && radarTarget.GetPosition().GetReportedHeading() < 181) ||
(CSiTRadar::menuState.wbPTL && radarTarget.GetPosition().GetReportedHeading() > 180 && radarTarget.GetPosition().GetReportedHeading() < 360)
) {
HaloTool::drawPTL(&dc, radarTarget, this, p, menuState.ptlLength);
}
// Draw TBS Marker
// TBS only at CYYZ
//Determine if the aircraft is on approach
if (radarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetClearedAltitude() == 1 ||
radarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().GetClearedAltitude() == 2)
{
if (!strcmp(radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetDestination(), "CYYZ"))
{
if (radarTarget.GetCorrelatedFlightPlan().GetDistanceToDestination() < 20 &&
radarTarget.GetCorrelatedFlightPlan().GetDistanceToDestination() > 1 &&
radarTarget.GetPosition().GetPressureAltitude() > 500) {
int i = radarTarget.GetTrackHeading() - menuState.tbsHdg + 10 ; // ES reports in true, 10 for mag var in CYYZ
if (i < 7 && i > -7)
{
double tbsDist = 0;
// Lead plane is L
if (radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftWtc() == 'L') {
tbsDist = 3; // min radar
if ((double)radarTarget.GetGS() / 3600 * 68 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 68;
}
}
// Lead plane is M
if (radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftWtc() == 'M') {
if (mAcData[callSign].follower == 0) {
tbsDist = 4;
if ((double)radarTarget.GetGS() / 3600 * 90 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 90;
}
}
else if (mAcData[callSign].follower >= 1) {
tbsDist = 3; // min radar
if ((double)radarTarget.GetGS() / 3600 * 68 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 68;
}
}
}
// Lead Plane is H
if (radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftWtc() == 'H') {
if (mAcData[callSign].follower == 0) {
tbsDist = 6;
if ((double)radarTarget.GetGS() / 3600 * 135 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 135;
}
}
else if (mAcData[callSign].follower == 1) {
tbsDist = 5;
if ((double)radarTarget.GetGS() / 3600 * 113 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 113;
}
}
else if (mAcData[callSign].follower == 2) {
tbsDist = 4;
if ((double)radarTarget.GetGS() / 3600 * 90 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 90;
}
}
else if (mAcData[callSign].follower == 3) {
tbsDist = 3;
if ((double)radarTarget.GetGS() / 3600 * 68 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 68;
}
}
}
// Lead Plane is J
if (radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftWtc() == 'J') {
if (mAcData[callSign].follower == 0) {
tbsDist = 8;
if ((double)radarTarget.GetGS() / 3600 * 180 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 180;
}
}
else if (mAcData[callSign].follower == 1) {
tbsDist = 7;
if ((double)radarTarget.GetGS() / 3600 * 158 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 158;
}
}
else if (mAcData[callSign].follower == 2) {
tbsDist = 6;
if ((double)radarTarget.GetGS() / 3600 * 135 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 135;
}
}
else if (mAcData[callSign].follower == 3) {
tbsDist = 4;
if ((double)radarTarget.GetGS() / 3600 * 90 < tbsDist) {
tbsDist = (double)radarTarget.GetGS() / 3600 * 90;
}
}
}
if (menuState.tbsMixed && tbsDist < 5) {
tbsDist = 5;
}
if (tbsDist != 0) {
POINT followerP = HaloTool::drawTBS(&dc, radarTarget, this, p, tbsDist, pixnm, (double)((double)menuState.tbsHdg - 10));
// draw letter to allow toggling of follower
dc.SelectObject(CFontHelper::Euroscope14);
dc.SetTextColor(C_PPS_TBS_PINK);
RECT rectTBS;
rectTBS.left = followerP.x + 5;
rectTBS.right = followerP.x + 15;
rectTBS.top = followerP.y - 5;
rectTBS.bottom = followerP.y + 10;
string tbsFollowerStr;
if (mAcData[callSign].follower == 0) { tbsFollowerStr = 'L'; }
if (mAcData[callSign].follower == 1) { tbsFollowerStr = 'M'; }
if (mAcData[callSign].follower == 2) { tbsFollowerStr = 'H'; }
if (mAcData[callSign].follower == 3) { tbsFollowerStr = 'J'; }
dc.DrawText(tbsFollowerStr.c_str(), &rectTBS, DT_LEFT);
AddScreenObject(TBS_FOLLOWER_TOGGLE, callSign.c_str(), rectTBS, false, "Toggle TBS Follower");
}
}
}
}
}
if ((!isCorrelated && !isADSB) || (radarTarget.GetPosition().GetRadarFlags() != 0 && isADSB && !isCorrelated)) {
mAcData[callSign].tagType = 3; // sets this if RT is uncorr
}
else if (isCorrelated && mAcData[callSign].tagType == 3) { mAcData[callSign].tagType = 0; } // only sets once to go from uncorr to corr
// then allows it to be opened closed etc
COLORREF ppsColor;
// logic for the color of the PPS
if (radarTarget.GetPosition().GetRadarFlags() == 0) { ppsColor = C_PPS_YELLOW; }
else if (radarTarget.GetPosition().GetRadarFlags() == 1 ) { ppsColor = C_PPS_MAGENTA; }
else if (!strcmp(radarTarget.GetPosition().GetSquawk(), "7600") || !strcmp(radarTarget.GetPosition().GetSquawk(), "7700")) { ppsColor = C_PPS_RED; }
else if (isVFR && isCorrelated) { ppsColor = C_PPS_ORANGE; }
else { ppsColor = C_PPS_YELLOW; }
if (radarTarget.GetPosition().GetTransponderI() == TRUE && halfSecTick) { ppsColor = C_WHITE; }
RECT prect = CPPS::DrawPPS(&dc, isCorrelated, isVFR, isADSB, isRVSM, radarTarget.GetPosition().GetRadarFlags(), ppsColor, radarTarget.GetPosition().GetSquawk(), p);
AddScreenObject(AIRCRAFT_SYMBOL, callSign.c_str(), prect, FALSE, "");
if (radarTarget.GetPosition().GetRadarFlags() != 0 && radarTarget.GetPosition().GetRadarFlags() !=4) {
CACTag::DrawRTACTag(&dc, this, &radarTarget, &radarTarget.GetCorrelatedFlightPlan(), &rtagOffset);
if (radarTarget.GetGS() > 10) {
CACTag::DrawHistoryDots(&dc, &radarTarget);
}
}
else if (radarTarget.GetPosition().GetRadarFlags() == 4 && isADSB) {
CACTag::DrawRTACTag(&dc, this, &radarTarget, &radarTarget.GetCorrelatedFlightPlan(), &rtagOffset);
if (radarTarget.GetGS() > 10) {
CACTag::DrawHistoryDots(&dc, &radarTarget);
}
}
// ADSB targets; if no primary or secondary radar, but the plane has ADSB equipment suffix (assumed space based ADS-B with no gaps)
/*
if (radarTarget.GetPosition().GetRadarFlags() == 0
&& isADSB) {
if (mAcData[callSign].tagType != 0 && mAcData[callSign].tagType != 1) { mAcData[callSign].tagType = 1; }
CACTag::DrawRTACTag(&dc, this, &radarTarget, &GetPlugIn()->FlightPlanSelect(callSign.c_str()), &rtagOffset);
CACTag::DrawRTConnector(&dc, this, &radarTarget, &GetPlugIn()->FlightPlanSelect(callSign.c_str()), C_PPS_YELLOW, &rtagOffset);
CACTag::DrawHistoryDots(&dc, &radarTarget);
}
*/
// Tag Level Logic
if (menuState.nearbyCJS.find(radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerId()) != menuState.nearbyCJS.end() &&
menuState.nearbyCJS.at(radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerId())) {
// Open tags for quick looked targets
CSiTRadar::mAcData[radarTarget.GetCallsign()].tagType = 1;
CSiTRadar::mAcData[radarTarget.GetCallsign()].isQuickLooked = true;
}
else if (menuState.nearbyCJS.find(radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerId()) != menuState.nearbyCJS.end() &&
!menuState.nearbyCJS.at(radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerId())
&& CSiTRadar::mAcData[radarTarget.GetCallsign()].isQuickLooked) {
CSiTRadar::mAcData[radarTarget.GetCallsign()].tagType = 0;
CSiTRadar::mAcData[radarTarget.GetCallsign()].isQuickLooked = false;
}
if (radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerIsMe()) {
CSiTRadar::mAcData[radarTarget.GetCallsign()].tagType = 1; // alpha tag if you have jurisdiction over the aircraft
CSiTRadar::mAcData[radarTarget.GetCallsign()].isJurisdictional = true;
// if you are handing off to someone
if (strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), "") != 0) {
mAcData[callSign].isHandoff = TRUE;
// Clear the entry used for pointout coordination
radarTarget.GetCorrelatedFlightPlan().GetControllerAssignedData().SetFlightStripAnnotation(0, "");
}
}
else {
CSiTRadar::mAcData[radarTarget.GetCallsign()].isJurisdictional = false;
}
// Once the handoff is complete,
if (mAcData[callSign].isHandoff == TRUE && strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), "") == 0) {
mAcData[callSign].isHandoff = FALSE;
// record the time of handoff acceptance unless the handoff is recalled by yourself
if (!radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerIsMe()) {
hoAcceptedTime[callSign] = clock();
// if jurisdiction changes, pointouts are cleared
GetPlugIn()->FlightPlanSelect(callSign.c_str()).GetControllerAssignedData().SetFlightStripAnnotation(1, "");
SendPointOut(mAcData[GetPlugIn()->FlightPlanSelectASEL().GetCallsign()].POTarget.c_str(), "", &GetPlugIn()->FlightPlanSelect(GetPlugIn()->FlightPlanSelectASEL().GetCallsign()));
mAcData[callSign].pointOutFromMe = false;
mAcData[callSign].pointOutToMe = false;
mAcData[callSign].POTarget = "";
mAcData[callSign].POString = "";
}
}
// Post handoff blinking and then close the tag
if (hoAcceptedTime.find(callSign) != hoAcceptedTime.end() && (clock() - hoAcceptedTime[callSign]) / CLOCKS_PER_SEC > 12) {
hoAcceptedTime.erase(callSign);
// if quick look is open, defer closing the tag until bypass All filter is off;
if (!menuState.filterBypassAll) {
mAcData[callSign].tagType = 0;
}
if (menuState.filterBypassAll) {
tempTagData[callSign] = 0;
}
}
// Once the handoff to me is completed,
if (mAcData[callSign].isHandoffToMe == TRUE && strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), "") == 0) {
mAcData[callSign].isHandoffToMe = FALSE;
}
// Open a bravo tag, during a handoff to you
if (strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), GetPlugIn()->ControllerMyself().GetPositionId()) == 0 &&
strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), "") != 0) {
CSiTRadar::mAcData[radarTarget.GetCallsign()].tagType = 1;
mAcData[callSign].isHandoffToMe = TRUE;
}
// Handoff warning system: if the plane is within 2 minutes of exiting your airspace, CJS will blink
COLORREF cjsColor = C_PPS_YELLOW;
if (radarTarget.GetCorrelatedFlightPlan().GetTrackingControllerIsMe()) {
if (radarTarget.GetCorrelatedFlightPlan().GetSectorExitMinutes() <= 2
&& radarTarget.GetCorrelatedFlightPlan().GetSectorExitMinutes() >= 0
&& halfSecTick == TRUE
&& strcmp(radarTarget.GetCorrelatedFlightPlan().GetHandoffTargetControllerId(), "") == 0) {
cjsColor = C_WHITE;
}
}
// show CJS for controller tracking aircraft // or if in handoff mode, show the target controller's CJS
if ((radarTarget.GetPosition().GetRadarFlags() >= 2 && isCorrelated)) { // || CSiTRadar::mAcData[radarTarget.GetCallsign()].isADSB) {
if (radarTarget.GetPosition().GetRadarFlags() == 4 && !isADSB) {}
else {
dc.SelectObject(CFontHelper::Euroscope14);
dc.SetTextColor(cjsColor);
RECT rectCJS;
rectCJS.left = p.x - 8;
rectCJS.right = p.x + 75;
rectCJS.top = p.y - 20;
rectCJS.bottom = p.y;
string CJS = GetPlugIn()->FlightPlanSelect(callSign.c_str()).GetTrackingControllerId();
if (menuState.handoffMode &&
strcmp(radarTarget.GetCallsign(), GetPlugIn()->FlightPlanSelectASEL().GetCallsign()) == 0) {
CJS = GetPlugIn()->ControllerSelect(GetPlugIn()->FlightPlanSelect(callSign.c_str()).GetCoordinatedNextController()).GetPositionId();
dc.SetTextColor(C_WHITE);
}
dc.DrawText(CJS.c_str(), &rectCJS, DT_LEFT);
dc.SetTextColor(cjsColor);
}
}
// plane halo looks at the <map> hashalo to see if callsign has a halo, if so, draws halo
if (hashalo.find(radarTarget.GetCallsign()) != hashalo.end()) {
HaloTool::drawHalo(&dc, p, menuState.haloRad, pixnm);
}
// Draw the Selected Aircraft Box
HPEN targetPen;
RECT selectBox{};
selectBox.left = p.x - 6;
selectBox.right = p.x + 7;
selectBox.top = p.y - 6;
selectBox.bottom = p.y + 7;
targetPen = CreatePen(PS_SOLID, 1, C_WHITE);
dc.SelectObject(targetPen);
dc.SelectStockObject(NULL_BRUSH);
dc.SelectObject(CFontHelper::Euroscope14);
dc.SetTextColor(C_WHITE);
if (CSiTRadar::menuState.handoffMode || CSiTRadar::menuState.SFIMode) {
if (strcmp(radarTarget.GetCallsign(), GetPlugIn()->FlightPlanSelectASEL().GetCallsign()) == 0) {
dc.Rectangle(&selectBox);
RECT rectHO;
rectHO.left = p.x - 16;
rectHO.right = p.x + 20;
rectHO.top = p.y + 8;
rectHO.bottom = p.y + 28;
if (menuState.handoffMode) {
dc.DrawText("H/O", &rectHO, DT_CENTER);
}
if (menuState.SFIMode) {
dc.DrawText("SFI", &rectHO, DT_CENTER);
}
}
}
else if (mAcData[callSign].pointOutToMe){
if (mAcData[callSign].pointOutPendingApproval) { // change to flashing for point out events;
dc.Rectangle(&selectBox);
RECT rectHighlight;
string POString, POString2;
POString = "P/Out " + mAcData[callSign].POTarget;
POString2 = mAcData[callSign].POString;
rectHighlight.left = p.x - 9;
rectHighlight.right = p.x + 20;
rectHighlight.top = p.y + 8;
rectHighlight.bottom = p.y + 28;
AddScreenObject(HIGHLIGHT_POINT_OUT_ACCEPT, callSign.c_str(), rectHighlight, false, "Accept Point Out");
dc.DrawText(POString.c_str(), &rectHighlight, DT_LEFT | DT_CALCRECT);
if (halfSecTick) {
dc.DrawText(POString.c_str(), &rectHighlight, DT_LEFT);
}
rectHighlight.top = rectHighlight.bottom - 3;
dc.DrawText(POString2.c_str(), &rectHighlight, DT_LEFT | DT_CALCRECT);
if (halfSecTick) {
dc.DrawText(POString2.c_str(), &rectHighlight, DT_LEFT);
}
AddScreenObject(HIGHLIGHT_POINT_OUT_ACCEPT, callSign.c_str(), rectHighlight, false, "Accept Point Out");
}
else {
dc.Rectangle(&selectBox);
RECT rectHighlight;
string POString, POString2;
POString = "P/Out " + mAcData[callSign].POTarget;
POString2 = mAcData[callSign].POString;
rectHighlight.left = p.x - 9;
rectHighlight.right = p.x + 20;
rectHighlight.top = p.y + 8;
rectHighlight.bottom = p.y + 28;
dc.DrawText(POString.c_str(), &rectHighlight, DT_LEFT | DT_CALCRECT);
dc.DrawText(POString.c_str(), &rectHighlight, DT_LEFT);
rectHighlight.top = rectHighlight.bottom - 3;
dc.DrawText(POString2.c_str(), &rectHighlight, DT_LEFT | DT_CALCRECT);
dc.DrawText(POString2.c_str(), &rectHighlight, DT_LEFT);
}
}
else if (mAcData[callSign].pointOutFromMe) {
dc.Rectangle(&selectBox);
if ( ((clock() - mAcData[callSign].POAcceptTime) / CLOCKS_PER_SEC) < 8 &&
((clock() - mAcData[callSign].POAcceptTime) / CLOCKS_PER_SEC) > 0 &&
halfSecTick) {
bool i = true;
} else {
RECT rectHighlight;
string POString, POString2;
POString = "P/Out " + mAcData[callSign].POTarget;
POString2 = mAcData[callSign].POString;
rectHighlight.left = p.x - 9;
rectHighlight.right = p.x + 20;