Skip to content

Commit 6d8426d

Browse files
committed
Added flightplan and route entry parsing
1 parent d5115c1 commit 6d8426d

File tree

7 files changed

+182
-0
lines changed

7 files changed

+182
-0
lines changed

DelHel/CDelHel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "helpers.h"
1818
#include "airport.h"
1919
#include "validation.h"
20+
#include "flightplan.h"
2021

2122
using json = nlohmann::json;
2223
using namespace std::chrono_literals;

DelHel/DelHel.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,15 @@
204204
<ItemGroup>
205205
<ClCompile Include="CDelHel.cpp" />
206206
<ClCompile Include="DelHel.cpp" />
207+
<ClCompile Include="flightplan.cpp" />
207208
<ClCompile Include="helpers.cpp" />
208209
<ClCompile Include="pch.cpp">
209210
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
210211
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
211212
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
212213
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
213214
</ClCompile>
215+
<ClCompile Include="route_entry.cpp" />
214216
</ItemGroup>
215217
<ItemGroup>
216218
<CopyFileToFolders Include="..\airports.json">
@@ -224,9 +226,11 @@
224226
<ClInclude Include="CDelHel.h" />
225227
<ClInclude Include="constants.h" />
226228
<ClInclude Include="DelHel.h" />
229+
<ClInclude Include="flightplan.h" />
227230
<ClInclude Include="framework.h" />
228231
<ClInclude Include="pch.h" />
229232
<ClInclude Include="Resource.h" />
233+
<ClInclude Include="route_entry.h" />
230234
<ClInclude Include="sid.h" />
231235
<ClInclude Include="targetver.h" />
232236
<ClInclude Include="helpers.h" />

DelHel/DelHel.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<ClCompile Include="helpers.cpp">
2828
<Filter>Source Files</Filter>
2929
</ClCompile>
30+
<ClCompile Include="flightplan.cpp">
31+
<Filter>Source Files</Filter>
32+
</ClCompile>
33+
<ClCompile Include="route_entry.cpp">
34+
<Filter>Source Files</Filter>
35+
</ClCompile>
3036
</ItemGroup>
3137
<ItemGroup>
3238
<None Include="DelHel.def">
@@ -70,6 +76,12 @@
7076
<ClInclude Include="validation.h">
7177
<Filter>Header Files</Filter>
7278
</ClInclude>
79+
<ClInclude Include="flightplan.h">
80+
<Filter>Header Files</Filter>
81+
</ClInclude>
82+
<ClInclude Include="route_entry.h">
83+
<Filter>Header Files</Filter>
84+
</ClInclude>
7385
</ItemGroup>
7486
<ItemGroup>
7587
<ResourceCompile Include="DelHel.rc">

DelHel/flightplan.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "pch.h"
2+
3+
#include "flightplan.h"
4+
5+
flightplan::flightplan(std::string callsign, const EuroScopePlugIn::CFlightPlanExtractedRoute& route, std::string rawRoute) : callsign(callsign), direction(0.0), distance(0.0)
6+
{
7+
this->ParseRoute(route, rawRoute);
8+
}
9+
10+
11+
flightplan::flightplan(const char* callsign, const EuroScopePlugIn::CFlightPlanExtractedRoute& route, const char* rawRoute) : flightplan(std::string(callsign), route, std::string(rawRoute))
12+
{
13+
}
14+
15+
void flightplan::ParseRoute(const EuroScopePlugIn::CFlightPlanExtractedRoute& route, std::string rawRoute)
16+
{
17+
this->route.clear();
18+
this->direction = 0.0;
19+
this->distance = 0.0;
20+
21+
EuroScopePlugIn::CPosition lastPos;
22+
EuroScopePlugIn::CPosition rePos;
23+
std::string airway;
24+
std::vector<route_entry> wps;
25+
int numPoints = route.GetPointsNumber();
26+
27+
for (int i = 0; i < numPoints; i++)
28+
{
29+
std::string name = route.GetPointName(i);
30+
31+
EuroScopePlugIn::CPosition pos = route.GetPointPosition(i);
32+
33+
double dir = 0.0;
34+
double dist = 0.0;
35+
if (i > 0) {
36+
dir = pos.DirectionTo(lastPos);
37+
dist = pos.DistanceTo(lastPos);
38+
}
39+
40+
lastPos = pos;
41+
42+
std::string aw = route.GetPointAirwayName(i);
43+
if (aw.size() > 0) {
44+
if (airway.size() == 0) {
45+
airway = aw;
46+
rePos = route.GetPointPosition(i);
47+
}
48+
else if (airway != aw) {
49+
double reDir = 0.0;
50+
double reDist = 0.0;
51+
if (i > 0) {
52+
EuroScopePlugIn::CPosition p = route.GetPointPosition(i - 1);
53+
54+
reDir = rePos.DirectionTo(p);
55+
reDist = rePos.DistanceTo(p);
56+
}
57+
58+
route_entry re(airway, reDir, reDist);
59+
re.airway = true;
60+
re.waypoints = wps;
61+
62+
this->route.push_back(re);
63+
64+
airway = aw;
65+
rePos = route.GetPointPosition(i);
66+
wps.clear();
67+
}
68+
69+
wps.push_back(route_entry(name, dir, dist));
70+
}
71+
else {
72+
if (airway.size() > 0) {
73+
double reDir = 0.0;
74+
double reDist = 0.0;
75+
if (i > 0) {
76+
EuroScopePlugIn::CPosition p = route.GetPointPosition(i - 1);
77+
78+
reDir = rePos.DirectionTo(p);
79+
reDist = rePos.DistanceTo(p);
80+
}
81+
82+
route_entry re(airway, reDir, reDist);
83+
re.airway = true;
84+
re.waypoints = wps;
85+
86+
this->route.push_back(re);
87+
88+
airway.clear();
89+
wps.clear();
90+
}
91+
92+
this->route.push_back(route_entry(name, dir, dist));
93+
}
94+
}
95+
96+
if (numPoints >= 2) {
97+
this->direction = route.GetPointPosition(0).DirectionTo(route.GetPointPosition(numPoints - 1));
98+
this->distance = route.GetPointPosition(0).DistanceTo(route.GetPointPosition(numPoints - 1));
99+
}
100+
}

DelHel/flightplan.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
#include <regex>
6+
7+
#include "EuroScope/EuroScopePlugIn.h"
8+
9+
#include "route_entry.h"
10+
11+
class flightplan
12+
{
13+
public:
14+
std::string callsign;
15+
std::vector<route_entry> route;
16+
double direction;
17+
double distance;
18+
19+
flightplan(std::string callsign, const EuroScopePlugIn::CFlightPlanExtractedRoute& route, std::string rawRoute);
20+
flightplan(const char* callsign, const EuroScopePlugIn::CFlightPlanExtractedRoute& route, const char* rawRoute);
21+
22+
void ParseRoute(const EuroScopePlugIn::CFlightPlanExtractedRoute& route, std::string rawRoute);
23+
};
24+

DelHel/route_entry.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "pch.h"
2+
3+
#include "route_entry.h"
4+
5+
route_entry::route_entry() : name(""), airway(false), direction(0.0), distance(0.0), rfl(0), speed(0)
6+
{
7+
}
8+
9+
route_entry::route_entry(std::string name) : name(name), airway(false), direction(0.0), distance(0.0), rfl(0), speed(0)
10+
{
11+
}
12+
13+
route_entry::route_entry(std::string name, double direction, double distance) : name(name), airway(false), direction(direction), distance(distance), rfl(0), speed(0)
14+
{
15+
}
16+
17+
route_entry::route_entry(std::string name, int rfl, int speed) : name(name), airway(false), direction(0.0), distance(0.0), rfl(rfl), speed(speed)
18+
{
19+
}

DelHel/route_entry.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
6+
class route_entry
7+
{
8+
public:
9+
std::string name;
10+
std::vector<route_entry> waypoints;
11+
bool airway;
12+
double direction;
13+
double distance;
14+
int rfl;
15+
int speed;
16+
17+
route_entry();
18+
route_entry(std::string name);
19+
route_entry(std::string name, double direction, double distance);
20+
route_entry(std::string name, int rfl, int speed);
21+
};
22+

0 commit comments

Comments
 (0)