forked from pierr3/ModeS
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ModeSDisplay.cpp
52 lines (43 loc) · 1.72 KB
/
ModeSDisplay.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
#include "stdafx.h"
#include "ModeSDisplay.h"
CModeSDisplay::CModeSDisplay(const CModeSCodes& msc) :
ModeSCodes(msc)
{};
void CModeSDisplay::OnFunctionCall(int FunctionId, const char * sItemString, POINT Pt, RECT Area)
{
if (FunctionId == ItemCodes::TAG_FUNC_ASSIGNMODEAS) {
if (!GetPlugIn()->ControllerMyself().IsValid() || !GetPlugIn()->ControllerMyself().IsController())
return;
EuroScopePlugIn::CFlightPlan FlightPlan = GetPlugIn()->FlightPlanSelectASEL();
if (!FlightPlan.IsValid())
return;
if (!strcmp(FlightPlan.GetFlightPlanData().GetPlanType(), "V")) {
StartTagFunction(FlightPlan.GetCallsign(), nullptr, 0, "", nullptr, EuroScopePlugIn::TAG_ITEM_FUNCTION_SQUAWK_POPUP, Pt, Area);
return;
}
if (ModeSCodes.isAcModeS(FlightPlan) && ModeSCodes.isApModeS(FlightPlan.GetFlightPlanData().GetDestination()))
FlightPlan.GetControllerAssignedData().SetSquawk(::mode_s_code);
else {
if (PendingSquawks.find(FlightPlan.GetCallsign()) == PendingSquawks.end())
PendingSquawks.insert(std::make_pair(FlightPlan.GetCallsign(), std::async(LoadWebSquawk,
std::string(FlightPlan.GetFlightPlanData().GetOrigin()), std::string(GetPlugIn()->ControllerMyself().GetCallsign()))));
}
}
}
void CModeSDisplay::OnRefresh(HDC hDC, int Phase)
{
for (auto it = PendingSquawks.begin(), next_it = it; it != PendingSquawks.end(); it = next_it)
{
bool must_delete = false;
if (it->second.valid() && it->second.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
std::string squawk = it->second.get();
GetPlugIn()->FlightPlanSelect(it->first).GetControllerAssignedData().SetSquawk(squawk.c_str());
must_delete = true;
}
++next_it;
if (must_delete)
{
PendingSquawks.erase(it);
}
}
}