Skip to content

Commit 84b117b

Browse files
committed
Some code clean up
1 parent 58f89c3 commit 84b117b

6 files changed

+64
-62
lines changed

ESTrackFunctions/CFlightPlanFunctions.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CFlightPlanFunctions::~CFlightPlanFunctions()
1111
{
1212
}
1313

14-
std::string CFlightPlanFunctions::StripRouteString(std::string route, EuroScopePlugIn::CFlightPlan & flightplan)
14+
std::string CFlightPlanFunctions::StripRouteString(std::string route, const EuroScopePlugIn::CFlightPlan & flightplan)
1515
{
1616
StripInvalid(route, flightplan);
1717
StripWhitespace(route);
@@ -23,11 +23,11 @@ void CFlightPlanFunctions::StripWhitespace(std::string & str)
2323
str = std::regex_replace(str, std::regex{ "^\\s+|(\\s)\\s+" }, "$1");
2424
}
2525

26-
void CFlightPlanFunctions::StripInvalid(std::string & str, EuroScopePlugIn::CFlightPlan & flightplan)
26+
void CFlightPlanFunctions::StripInvalid(std::string & str, const EuroScopePlugIn::CFlightPlan & flightplan)
2727
{
28-
std::string departure{ flightplan.GetFlightPlanData().GetOrigin() };
28+
std::string origin{ flightplan.GetFlightPlanData().GetOrigin() };
2929
std::string destination{ flightplan.GetFlightPlanData().GetDestination() };
30-
std::regex rDeparture{ "(?:^|\\s)" + departure + "\\s"};
30+
std::regex rDeparture{ "(?:^|\\s)" + origin +"\\s" };
3131
std::regex rDestination{ "\\s" + destination + "(?:\\s|$)" };
3232
std::regex rSpeedLevel{ "(?:^|\\s)[NKM]\\d{3,4}[FAM]\\d{3,4}" };
3333
std::regex rSidStar{ "(?:^|\\s)SID | STAR(?:$|\\s)" };

ESTrackFunctions/CFlightPlanFunctions.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ class CFlightPlanFunctions
88
public:
99
CFlightPlanFunctions();
1010
virtual ~CFlightPlanFunctions();
11-
12-
std::string StripRouteString(std::string route, EuroScopePlugIn::CFlightPlan & flightplan);
11+
std::string StripRouteString(std::string route, const EuroScopePlugIn::CFlightPlan & flightplan);
1312

1413
private:
1514
void StripWhitespace(std::string & str);
16-
void StripInvalid(std::string & str, EuroScopePlugIn::CFlightPlan & flightplan);
15+
void StripInvalid(std::string & str, const EuroScopePlugIn::CFlightPlan & flightplan);
1716
};
1817

ESTrackFunctions/ESTrackFunctions.cpp

+51-48
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,10 @@ CESTrackFunctions::CESTrackFunctions()
1010
RegisterTagItemFunction("Clean FP", ITEM_FUNCTION_CLEAN_FP);
1111
}
1212

13-
1413
CESTrackFunctions::~CESTrackFunctions()
1514
{
1615
}
1716

18-
bool CESTrackFunctions::OnCompileCommand(const char* sCommandLine)
19-
{
20-
if (!strcmp(sCommandLine, ".fpt"))
21-
{
22-
CleanFlightPlan(FlightPlanSelectASEL());
23-
return true;
24-
}
25-
if (!strcmp(sCommandLine, ".autodrop"))
26-
{
27-
autoDrop = (autoDrop == 1 ? 0 : 1);
28-
SaveDataToSettings("AutoDrop", "Drop Track for landing AC", (autoDrop == 1 ? "1" : "0"));
29-
return true;
30-
}
31-
return false;
32-
}
33-
34-
void CESTrackFunctions::OnTimer(int Counter)
35-
{
36-
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
37-
return;
38-
if (GetConnectionType() != EuroScopePlugIn::CONNECTION_TYPE_DIRECT)
39-
return;
40-
if (autoDrop)
41-
{
42-
for (auto flightplan = FlightPlanSelectFirst();
43-
flightplan.IsValid();
44-
flightplan = FlightPlanSelectNext(flightplan))
45-
{
46-
if (flightplan.GetSimulated()) continue;
47-
if (CheckDrop(flightplan))
48-
flightplan.EndTracking();
49-
}
50-
}
51-
}
52-
53-
void CESTrackFunctions::PostDebugMessage(std::string message)
54-
{
55-
DisplayUserMessage("Debug", "Debug", message.c_str(), true, true, true, false, false);
56-
}
57-
5817
bool CESTrackFunctions::CheckDrop(const EuroScopePlugIn::CFlightPlan & flightplan) const
5918
{
6019
if (!flightplan.GetTrackingControllerIsMe())
@@ -72,25 +31,69 @@ bool CESTrackFunctions::CheckDrop(const EuroScopePlugIn::CFlightPlan & flightpla
7231
return false;
7332
}
7433

75-
void CESTrackFunctions::CleanFlightPlan(EuroScopePlugIn::CFlightPlan & flightplan)
34+
void CESTrackFunctions::CleanFlightPlan()
7635
{
77-
if (!flightplan.IsValid()) return;
78-
std::string route{ FlightPlanFunctions.StripRouteString(flightplan.GetFlightPlanData().GetRoute(), flightplan) };
36+
auto flightplan{ FlightPlanSelectASEL() };
37+
if (!flightplan.IsValid())
38+
return;
39+
auto route{ FlightPlanFunctions.StripRouteString(flightplan.GetFlightPlanData().GetRoute(), flightplan) };
7940
flightplan.GetFlightPlanData().SetRoute(route.c_str());
8041
flightplan.GetFlightPlanData().AmendFlightPlan();
8142
}
8243

44+
void CESTrackFunctions::DisplayMessage(const std::string message, const std::string handler)
45+
{
46+
DisplayUserMessage(MY_PLUGIN_NAME, handler.c_str(), message.c_str(), true, true, true, false, false);
47+
}
48+
8349
void CESTrackFunctions::LoadSettings()
8450
{
85-
auto ad = GetDataFromSettings("AutoDrop");
86-
if (ad != NULL)
51+
auto ad{ GetDataFromSettings(SETTING_AUTODROP) };
52+
if (ad != nullptr)
8753
autoDrop = (strcmp(ad, "1") ? 1 : 0);
8854
}
8955

56+
bool CESTrackFunctions::OnCompileCommand(const char* sCommandLine)
57+
{
58+
if (!strcmp(sCommandLine, ".fpt"))
59+
{
60+
CleanFlightPlan();
61+
return true;
62+
}
63+
if (!strcmp(sCommandLine, ".autodrop"))
64+
{
65+
autoDrop = (autoDrop == 1 ? 0 : 1);
66+
SaveDataToSettings(SETTING_AUTODROP, "Drop Track for landing AC", (autoDrop == 1 ? "1" : "0"));
67+
if (autoDrop == 1)
68+
DisplayMessage("AutoDrop ON", "Info");
69+
else
70+
DisplayMessage("AutoDrop OFF", "Info");
71+
return true;
72+
}
73+
return false;
74+
}
75+
9076
void CESTrackFunctions::OnFunctionCall(int FunctionId, const char * sItemString, POINT Pt, RECT Area)
9177
{
92-
PostDebugMessage(sItemString);
9378
if (FunctionId == ITEM_FUNCTION_CLEAN_FP)
94-
CleanFlightPlan(FlightPlanSelectASEL());
79+
CleanFlightPlan();
9580
}
9681

82+
void CESTrackFunctions::OnTimer(int Counter)
83+
{
84+
if (!ControllerMyself().IsValid() || !ControllerMyself().IsController())
85+
return;
86+
if (GetConnectionType() != EuroScopePlugIn::CONNECTION_TYPE_DIRECT)
87+
return;
88+
if (autoDrop)
89+
{
90+
for (auto flightplan = FlightPlanSelectFirst();
91+
flightplan.IsValid();
92+
flightplan = FlightPlanSelectNext(flightplan))
93+
{
94+
if (flightplan.GetSimulated()) continue;
95+
if (CheckDrop(flightplan))
96+
flightplan.EndTracking();
97+
}
98+
}
99+
}

ESTrackFunctions/ESTrackFunctions.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ constexpr auto DROP_DISTANCE{ 10 };
1414
constexpr auto DROP_LEVEL{ 2500 };
1515

1616
constexpr auto ITEM_FUNCTION_CLEAN_FP{ 1 };
17+
constexpr auto SETTING_AUTODROP{ "AutoDrop" };
1718

1819
class CESTrackFunctions :
1920
public EuroScopePlugIn::CPlugIn
2021
{
2122
public:
2223
CESTrackFunctions();
2324
virtual ~CESTrackFunctions();
24-
bool OnCompileCommand(const char* sCommandLine);
25-
void OnTimer(int Counter);
26-
27-
void PostDebugMessage(std::string message);
2825

2926
private:
3027
int dropLevel{ DROP_LEVEL };
@@ -33,9 +30,11 @@ class CESTrackFunctions :
3330
CFlightPlanFunctions FlightPlanFunctions;
3431

3532
bool CheckDrop(const EuroScopePlugIn::CFlightPlan& flightplan) const;
36-
void CleanFlightPlan(EuroScopePlugIn::CFlightPlan& flightplan);
33+
void CleanFlightPlan();
34+
void DisplayMessage(const std::string message, const std::string handler = "Debug");
3735
void LoadSettings();
38-
36+
bool OnCompileCommand(const char* sCommandLine);
3937
void OnFunctionCall(int FunctionId, const char * sItemString, POINT Pt, RECT Area);
38+
void OnTimer(int Counter);
4039
};
4140

ESTrackFunctions/ESTrackFunctions.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<IntrinsicFunctions>true</IntrinsicFunctions>
9797
<SDLCheck>true</SDLCheck>
9898
<AdditionalIncludeDirectories>C:\Users\Olli\Documents\GitHub\ESTrackFunctions\ESTrackFunctions\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
99+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
99100
</ClCompile>
100101
<Link>
101102
<EnableCOMDATFolding>true</EnableCOMDATFolding>

ESTrackFunctions/PluginMain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ESTrackFunctions.h"
22

3-
CESTrackFunctions * pMyPlugIn = nullptr;
3+
CESTrackFunctions * pMyPlugIn{ nullptr };
44

55
void __declspec (dllexport) EuroScopePlugInInit(EuroScopePlugIn::CPlugIn ** pPlugInInstance)
66
{

0 commit comments

Comments
 (0)