Skip to content

Commit f80d7b1

Browse files
committed
Merge branch 'sid_allocation_update'
Fixes service-desk#48
2 parents 75aacdf + 4da4094 commit f80d7b1

13 files changed

+409
-279
lines changed

BeluxPlugin/BeluxGatePlanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void BeluxGatePlanner::parse_json(std::string const& data) {
3030
const std::string callsign = entry.key();
3131
const std::string gate = std::string(entry.value().as_string());
3232
BeluxGateEntry gate_entry(callsign, airport, gate);
33-
if (this->gate_list.find(callsign) != this->gate_list.end())
33+
if (this->gate_list.contains(callsign))
3434
{
3535
gate_entry.gate_has_changed = this->gate_list.at(callsign).gate != gate;
3636
}

BeluxPlugin/BeluxPlugin.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ BeluxPlugin::BeluxPlugin(void) : CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE, MY
5555
});
5656

5757
getActiveRunways();
58-
procedureAssigner->set_departure_runways(activeDepRunways);
58+
procedureAssigner->set_runways(&activeDepRunways, &activeArrRunways);
5959
if (procedureAssigner->setup_lara() < 1)
6060
{
6161
printMessage("SID", "Could not parse LARA");
@@ -252,10 +252,10 @@ void BeluxPlugin::ProcessFlightPlans()
252252
procedureAssigner->process_flight_plan(fp, force_new_procedure);
253253
}
254254

255-
if (activeAirports.find(dep_airport) == activeAirports.end() // IF Not found in belux airport list
255+
if (!activeAirports.contains(dep_airport)
256256
|| !fp.IsValid() || !fp.GetCorrelatedRadarTarget().IsValid()
257257
// OR flightplan has not been loaded/correleted correctly?
258-
|| processed->find(callsign) != processed->end() // OR was already processed
258+
|| processed->contains(callsign)
259259
|| (strcmp(fp.GetTrackingControllerId(), "") != 0 && !fp.GetTrackingControllerIsMe())
260260
// OR aircraft is tracked (with exception of aircraft tracked by current controller)
261261
|| fp.GetCorrelatedRadarTarget().GetGS() > 5 // OR moving: Ground speed > 5knots
@@ -392,7 +392,7 @@ void BeluxPlugin::OnTimer(int Counter)
392392
void BeluxPlugin::OnAirportRunwayActivityChanged(void)
393393
{
394394
getActiveRunways();
395-
procedureAssigner->set_departure_runways(activeDepRunways);
395+
procedureAssigner->set_runways(&activeDepRunways, &activeArrRunways);
396396
procedureAssigner->reprocess_all();
397397
}
398398

@@ -475,7 +475,7 @@ void BeluxPlugin::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget,
475475
break;
476476
{
477477
const string cs = FlightPlan.GetCallsign();
478-
if (gatePlanner.gate_list.find(cs) != gatePlanner.gate_list.end())
478+
if (gatePlanner.gate_list.contains(cs))
479479
{
480480
if (gatePlanner.gate_list[cs].color != NULL)
481481
{
@@ -597,7 +597,7 @@ void BeluxPlugin::getActiveRunways()
597597
rwy = SectorFileElementSelectNext(rwy, SECTOR_ELEMENT_RUNWAY))
598598
{
599599
const auto ad_name = boost::trim_copy(string(rwy.GetAirportName()));
600-
if (active_airports.find(ad_name) == active_airports.end())
600+
if (!active_airports.contains(ad_name))
601601
{
602602
continue; // Inactive AD
603603
}

BeluxPlugin/BeluxPlugin.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,34 @@ class BeluxPlugin :
5151
public:
5252
BeluxPlugin();
5353
virtual ~BeluxPlugin();
54-
virtual void BeluxPlugin::OnNewMetarReceived(const char* sStation, const char* sFullMetar);
55-
virtual void BeluxPlugin::OnFlightPlanFlightPlanDataUpdate(CFlightPlan FlightPlan);
56-
virtual void BeluxPlugin::OnFlightPlanDisconnect(CFlightPlan FlightPlan);
57-
virtual void BeluxPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, EuroScopePlugIn::CRadarTarget RadarTarget, int ItemCode, int TagData, char sItemString[16], int* pColorCode, COLORREF* pRGB, double* pFontSize);
58-
virtual void BeluxPlugin::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area);
59-
virtual bool BeluxPlugin::OnCompileCommand(const char* sCommandLine);
60-
virtual void BeluxPlugin::OnTimer(int Counter);
61-
virtual void BeluxPlugin::OnAirportRunwayActivityChanged(void);
54+
virtual void OnNewMetarReceived(const char* sStation, const char* sFullMetar);
55+
virtual void OnFlightPlanFlightPlanDataUpdate(CFlightPlan FlightPlan);
56+
virtual void OnFlightPlanDisconnect(CFlightPlan FlightPlan);
57+
virtual void OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, EuroScopePlugIn::CRadarTarget RadarTarget, int ItemCode, int TagData, char sItemString[16], int* pColorCode, COLORREF* pRGB, double* pFontSize);
58+
virtual void OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area);
59+
virtual bool OnCompileCommand(const char* sCommandLine);
60+
virtual void OnTimer(int Counter);
61+
virtual void OnAirportRunwayActivityChanged(void);
6262

6363

6464
protected:
65-
string BeluxPlugin::GetHttpsRequest(string host, string uri, string request, bool expect_long_json);
66-
string BeluxPlugin::GetGateInfo();
67-
string BeluxPlugin::GetAirportInfo(string airport);
68-
string BeluxPlugin::GetLatestPluginVersion();
69-
string BeluxPlugin::SwapGate(string callsign, string gate);
70-
void BeluxPlugin::ProcessMETAR(string airport, string metar);
65+
string GetHttpsRequest(string host, string uri, string request, bool expect_long_json);
66+
string GetGateInfo();
67+
string GetAirportInfo(string airport);
68+
string GetLatestPluginVersion();
69+
string SwapGate(string callsign, string gate);
70+
void ProcessMETAR(string airport, string metar);
7171
/**
7272
* \brief Sets all active runways in the plugin properties
7373
*/
74-
void BeluxPlugin::getActiveRunways();
75-
void BeluxPlugin::ProcessFlightPlans();
76-
void BeluxPlugin::FetchAndProcessGates();
77-
void BeluxPlugin::versionCheck();
78-
void BeluxPlugin::loadJSONconfig();
74+
void getActiveRunways();
75+
void ProcessFlightPlans();
76+
void FetchAndProcessGates();
77+
void versionCheck();
78+
void loadJSONconfig();
7979

80-
void BeluxPlugin::printDebugMessage(const string& function, const string& message);
81-
void BeluxPlugin::printMessage(const string& topic, const string& message);
80+
void printDebugMessage(const string& function, const string& message);
81+
void printMessage(const string& topic, const string& message);
8282
};
8383

8484
inline static bool startsWith(const char* pre, const char* str)

BeluxPlugin/BeluxPlugin.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
100100
<AdditionalIncludeDirectories>C:\Program Files %28x86%29\EuroScope\PlugInEnvironment;C:\Users\Stef\Documents\Repositories\belux-euroscope-plugin\lib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
101101
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
102-
<LanguageStandard>stdcpp17</LanguageStandard>
102+
<LanguageStandard>stdcpp20</LanguageStandard>
103103
</ClCompile>
104104
<Link>
105105
<SubSystem>Windows</SubSystem>
@@ -158,7 +158,7 @@
158158
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
159159
<AdditionalIncludeDirectories>C:\Program Files %28x86%29\EuroScope\PlugInEnvironment;C:\Users\Stef\Documents\Repositories\belux-euroscope-plugin\lib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
160160
<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
161-
<LanguageStandard>stdcpp17</LanguageStandard>
161+
<LanguageStandard>stdcpp20</LanguageStandard>
162162
</ClCompile>
163163
<Link>
164164
<SubSystem>Windows</SubSystem>

BeluxPlugin/BeluxUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ string BeluxUtil::https_fetch_file(string url)
130130
tuple<double, double> BeluxUtil::calculate_mach(string callsign, int flightlevel, int gs, double hdg, double lat,
131131
double lon)
132132
{
133-
if (mach_timeout.find(callsign) == mach_timeout.end() || (get<1>(mach_timeout[callsign]) + 5) < std::time(0) &&
133+
if (!mach_timeout.contains(callsign) || (get<1>(mach_timeout[callsign]) + 5) < std::time(0) &&
134134
weatherdoc != NULL && !weatherdoc.HasParseError())
135135
{
136136
const int possibleFL_length = 17;

BeluxPlugin/BeluxUtil.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class BeluxUtil
4747

4848
static string https_fetch_file(string url);
4949

50-
map<string, tuple<double, double>> BeluxUtil::locations = {
50+
map<string, tuple<double, double>> locations = {
5151
{"DVR", {51.160,1.331}},
5252
{"KOK", {51.103,2.623}},
5353
{"FERDI" , {50.877,3.591}},

BeluxPlugin/ProcedureAssigner.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
#include <variant>
99

1010
bool ProcedureAssigner::should_process(const EuroScopePlugIn::CFlightPlan& flight_plan,
11-
bool ignore_already_assigned) const
11+
bool ignore_already_assigned) const
1212
{
1313
if (flight_plan.GetClearenceFlag())
1414
return false; // No reason to change it from under the ATCO
1515

1616
const auto adep = std::string(flight_plan.GetFlightPlanData().GetOrigin());
17-
if (std::find(std::begin(airports), std::end(airports), adep) ==
18-
std::end(airports))
17+
if (ranges::find(airports, adep) == std::end(airports))
1918
return false; // Not an airport we handle
2019

2120
if (!flight_plan.IsValid() || !flight_plan.GetCorrelatedRadarTarget().IsValid())
@@ -51,10 +50,10 @@ bool ProcedureAssigner::should_process(const EuroScopePlugIn::CFlightPlan& fligh
5150
}
5251

5352
std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::CFlightPlan& flight_plan,
54-
const std::string& sid_fix) const
53+
const std::string& sid_fix) const
5554
{
5655
const std::string origin = flight_plan.GetFlightPlanData().GetOrigin();
57-
if (departure_runways->find(origin) == departure_runways->end())
56+
if (!departure_runways->contains(origin))
5857
{
5958
return {};
6059
}
@@ -69,8 +68,8 @@ std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::
6968
if (origin == "EBLG")
7069
{
7170
// For EBLG, we never assign 22R/04L by default
72-
const bool has_04R = std::binary_search(origin_runways.begin(), origin_runways.end(), std::string("04R"));
73-
const bool has_22L = std::binary_search(origin_runways.begin(), origin_runways.end(), std::string("22L"));
71+
const bool has_04R = ranges::binary_search(origin_runways, std::string("04R"));
72+
const bool has_22L = ranges::binary_search(origin_runways, std::string("22L"));
7473

7574
if (has_04R)
7675
return "04R";
@@ -83,11 +82,11 @@ std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::
8382

8483
// Should only get here at EBBR
8584
const bool has_25R = std::binary_search(std::begin(origin_runways), std::end(origin_runways),
86-
std::string("25R"));
85+
std::string("25R"));
8786
const bool has_19 = std::binary_search(std::begin(origin_runways), std::end(origin_runways),
88-
std::string("19"));
87+
std::string("19"));
8988
const bool has_07R = std::binary_search(std::begin(origin_runways), std::end(origin_runways),
90-
std::string("07R"));
89+
std::string("07R"));
9190
const char wtc = flight_plan.GetFlightPlanData().GetAircraftWtc();
9291

9392
if (has_25R && has_19)
@@ -113,12 +112,13 @@ std::optional<std::string> ProcedureAssigner::get_runway(const EuroScopePlugIn::
113112
ProcedureAssigner::ProcedureAssigner(std::function<void(const std::string&)> printer)
114113
{
115114
departure_runways = new std::map<std::string, std::vector<std::string>>();
115+
arrival_runways = new std::map<std::string, std::vector<std::string>>();
116116
debug_printer = std::move(printer);
117117
}
118118

119119
// TODO: a lot of the data in this loop should really be cached between planes in one iteration...
120120
std::optional<SidEntry> ProcedureAssigner::process_flight_plan(const EuroScopePlugIn::CFlightPlan& flight_plan,
121-
bool force)
121+
bool force)
122122
{
123123
const std::string callsign = flight_plan.GetCallsign();
124124

@@ -210,9 +210,10 @@ size_t ProcedureAssigner::setup_lara(bool always) const
210210
lara_path += "\\TopSky\\TopSkyAreasManualAct.txt";
211211
std::ifstream ifs(lara_path);
212212
const std::string allocation_file((std::istreambuf_iterator<char>(ifs)),
213-
(std::istreambuf_iterator<char>()));
213+
(std::istreambuf_iterator<char>()));
214214
return lara_parser.parse_string(allocation_file);
215-
} catch (exception &e)
215+
}
216+
catch (exception& e)
216217
{
217218
const auto msg = "Could not parse LARA, areas may be inaccurate: " + std::string(e.what());
218219
debug_printer(msg);
@@ -231,14 +232,16 @@ void ProcedureAssigner::on_disconnect(const EuroScopePlugIn::CFlightPlan& flight
231232
cache.erase(found);
232233
}
233234

234-
void ProcedureAssigner::set_departure_runways(
235-
const std::map<std::string, std::vector<std::string>>& active_departure_runways)
235+
void ProcedureAssigner::set_runways(
236+
const std::map<std::string, std::vector<std::string>>* active_departure_runways, const std::map<std::string, std::
237+
vector<std::string>>*active_arrival_runways)
236238
{
237-
(*departure_runways) = active_departure_runways;
239+
departure_runways = active_departure_runways;
240+
arrival_runways = active_arrival_runways;
238241
airports.erase(airports.begin(), airports.end());
239242

240243

241-
for (const auto& [fst, snd] : active_departure_runways)
244+
for (const auto& [fst, snd] : *active_departure_runways)
242245
{
243246
airports.insert(fst);
244247
}
@@ -247,12 +250,12 @@ void ProcedureAssigner::set_departure_runways(
247250
}
248251

249252
std::optional<SidEntry> ProcedureAssigner::suggest(const EuroScopePlugIn::CFlightPlan& flight_plan,
250-
bool ignore_already_assigned)
253+
bool ignore_already_assigned)
251254
{
252255
const std::string callsign = flight_plan.GetCallsign();
253256

254257
// See if we have it cached
255-
if (cache.find(callsign) != cache.end())
258+
if (cache.contains(callsign))
256259
{
257260
return cache.at(callsign);
258261
}
@@ -264,7 +267,7 @@ std::optional<SidEntry> ProcedureAssigner::suggest(const EuroScopePlugIn::CFligh
264267

265268
typedef boost::split_iterator<std::string::const_iterator> SplitIter;
266269
for (SplitIter i = boost::make_split_iterator(route_text, boost::token_finder(boost::is_space()));
267-
i != SplitIter(); ++i)
270+
i != SplitIter(); ++i)
268271
{
269272
auto route_element = boost::copy_range<std::string>(*i);
270273
for (auto& fix : sid_fixes)
@@ -303,14 +306,16 @@ std::optional<SidEntry> ProcedureAssigner::suggest(const EuroScopePlugIn::CFligh
303306
// Get a tm struct for now in UTC
304307
tm now;
305308
gmtime_s(&now, &raw_time);
309+
const auto chrono_now = std::chrono::system_clock::now();
306310

307311
const auto areas = lara_parser.get_active(now);
308312

309-
auto entry = sid_allocation.find(flight_plan_data.GetOrigin(),
310-
sid_fix,
311-
flight_plan_data.GetDestination(),
312-
flight_plan_data.GetEngineNumber(),
313-
runway, now, areas);
313+
const std::string adep = flight_plan_data.GetOrigin();
314+
auto entry = sid_allocation.find(adep,
315+
sid_fix,
316+
flight_plan_data.GetDestination(),
317+
flight_plan_data.GetEngineNumber(),
318+
runway, chrono_now, areas, arrival_runways->at(adep));
314319
cache.insert_or_assign(callsign, entry);
315320
return entry;
316321
}

BeluxPlugin/ProcedureAssigner.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
#include "SidAllocation.h"
99
#include "LaraParser.h"
1010

11-
#define PREACTIVE_MINUTES 20
11+
constexpr int PREACTIVE_MINUTES = 20;
1212

1313
class ProcedureAssigner
1414
{
1515
private:
16-
std::map<std::string, std::vector<std::string>>* departure_runways;
16+
const std::map<std::string, std::vector<std::string>>* departure_runways;
17+
const std::map<std::string, std::vector<std::string>>* arrival_runways;
1718
std::set<std::string> airports;
1819
std::map<std::string, std::optional<SidEntry>> cache;
1920
std::function<void(const std::string&)> debug_printer;
@@ -59,7 +60,7 @@ class ProcedureAssigner
5960
* \param flight_plan The disconnected flight plan
6061
*/
6162
void on_disconnect(const EuroScopePlugIn::CFlightPlan& flight_plan);
62-
void set_departure_runways(const std::map<std::string, std::vector<std::string>>& active_departure_runways);
63+
void set_runways(const std::map<std::string, std::vector<std::string>>* active_departure_runways, const std::map<std::string, std::vector<std::string>>* active_arrival_runways);
6364
/**
6465
* \brief Suggests, but does not assign, a procedure for the provided flight plan, using caching.
6566
* \param flight_plan Flight plan to suggest a procedure for

0 commit comments

Comments
 (0)