FlightGear next
route_mgr.hxx
Go to the documentation of this file.
1// route_mgr.hxx - manage a route (i.e. a collection of waypoints)
2/*
3 * SPDX-FileCopyrightText: (C) 2004 Curtis L. Olson http://www.flightgear.org/~curt
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7
8#pragma once
9
10#include <simgear/props/props.hxx>
11#include <simgear/structure/subsystem_mgr.hxx>
12
14
15// forward decls
16class SGPath;
17class PropertyWatcher;
18class RoutePath;
19
24
25class FGRouteMgr : public SGSubsystem,
27{
28public:
29 FGRouteMgr();
31
32 // Subsystem API.
33 void bind() override;
34 void init() override;
35 void postinit() override;
36 void unbind() override;
37 void update(double dt) override;
38
39 // Subsystem identification.
40 static const char* staticSubsystemClassId() { return "route-manager"; }
41
42 bool isRouteActive() const;
43
44 int currentIndex() const;
45
48
49 void clearRoute();
50
52
53 int numLegs() const;
54
55 // deprecated
56 int numWaypts() const
57 { return numLegs(); }
58
59 // deprecated
60 flightgear::Waypt* wayptAtIndex(int index) const;
61
62 SGPropertyNode_ptr wayptNodeAtIndex(int index) const;
63
64 void removeLegAtIndex(int aIndex);
65
74 bool activate();
75
79 void deactivate();
80
84 void jumpToIndex(int index);
85
86 bool saveRoute(const SGPath& p);
87 bool loadRoute(const SGPath& p);
88
96 flightgear::WayptRef waypointFromString(const std::string& target, int insertPosition);
97
98private:
99 bool commandDefineUserWaypoint(const SGPropertyNode * arg, SGPropertyNode * root);
100 bool commandDeleteUserWaypoint(const SGPropertyNode * arg, SGPropertyNode * root);
101
103
104 time_t _takeoffTime;
105 time_t _touchdownTime;
106
107 // automatic inputs
108 SGPropertyNode_ptr magvar;
109
110 // automatic outputs
111 SGPropertyNode_ptr departure;
112 SGPropertyNode_ptr destination;
113 SGPropertyNode_ptr alternate;
114 SGPropertyNode_ptr cruise;
115
116 SGPropertyNode_ptr totalDistance;
117 SGPropertyNode_ptr distanceToGo;
118 SGPropertyNode_ptr ete;
119 SGPropertyNode_ptr elapsedFlightTime;
120
121 SGPropertyNode_ptr active;
122 SGPropertyNode_ptr airborne;
123
124 SGPropertyNode_ptr wp0;
125 SGPropertyNode_ptr wp1;
126 SGPropertyNode_ptr wpn;
127
128
129 SGPropertyNode_ptr _pathNode;
130 SGPropertyNode_ptr _currentWpt;
131 SGPropertyNode_ptr _isRoute;
132
136 SGPropertyNode_ptr _edited;
137
141 SGPropertyNode_ptr _finished;
142
143 SGPropertyNode_ptr _flightplanChanged;
144
145 void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
146
150 double cachedLegPathDistanceM(int index) const;
151 double cachedWaypointPathTotalDistance(int index) const;
152
153 class InputListener : public SGPropertyChangeListener {
154 public:
155 InputListener(FGRouteMgr *m) : mgr(m) {}
156 virtual void valueChanged (SGPropertyNode * prop);
157 private:
158 FGRouteMgr *mgr;
159 };
160
161 SGPropertyNode_ptr input;
162 SGPropertyNode_ptr weightOnWheels;
163 SGPropertyNode_ptr groundSpeed;
164
165 InputListener *listener;
166 SGPropertyNode_ptr mirror;
167
168 std::unique_ptr<RoutePath> _routePath;
169
175 void waypointsChanged() override;
176 void arrivalChanged() override;
177 void departureChanged() override;
178
179 void update_mirror();
180
181 void currentWaypointChanged() override;
182
183 // tied getters and setters
184 std::string getDepartureICAO() const;
185 std::string getDepartureName() const;
186 void setDepartureICAO(const std::string& aIdent);
187
188 std::string getDepartureRunway() const;
189 void setDepartureRunway(const std::string& aIdent);
190
191 std::string getSID() const;
192 void setSID(const std::string& aIdent);
193
194 std::string getDestinationICAO() const;
195 std::string getDestinationName() const;
196 void setDestinationICAO(const std::string& aIdent);
197
198 std::string getDestinationRunway() const;
199 void setDestinationRunway(const std::string& aIdent);
200
201 std::string getApproach() const;
202 void setApproach(const std::string& aIdent);
203
204 std::string getSTAR() const;
205 void setSTAR(const std::string& aIdent);
206
207 double getDepartureFieldElevation() const;
208 double getDestinationFieldElevation() const;
209
210 int getCruiseAltitudeFt() const;
211 void setCruiseAltitudeFt(int ft);
212
213 int getCruiseFlightLevel() const;
214 void setCruiseFlightLevel(int fl);
215
216 int getCruiseSpeedKnots() const;
217 void setCruiseSpeedKnots(int kts);
218
219 double getCruiseSpeedMach() const;
220 void setCruiseSpeedMach(double m);
221
222 std::string getAlternate() const;
223 std::string getAlternateName() const;
224 void setAlternate(const std::string &icao);
225};
226
#define p(x)
Top level route manager class.
Definition route_mgr.hxx:27
int numWaypts() const
Definition route_mgr.hxx:56
void deactivate()
deactivate the route if active
static const char * staticSubsystemClassId()
Definition route_mgr.hxx:40
flightgear::WayptRef waypointFromString(const std::string &target, int insertPosition)
Buiild a waypoint from a string description.
flightgear::Waypt * currentWaypt() const
bool isRouteActive() const
void clearRoute()
void setFlightPlan(const flightgear::FlightPlanRef &plan)
void bind() override
flightgear::Waypt * wayptAtIndex(int index) const
bool activate()
Activate a built route.
void update(double dt) override
void postinit() override
bool saveRoute(const SGPath &p)
void init() override
void removeLegAtIndex(int aIndex)
int numLegs() const
SGPropertyNode_ptr wayptNodeAtIndex(int index) const
void unbind() override
int currentIndex() const
bool loadRoute(const SGPath &p)
void jumpToIndex(int index)
Set the current waypoint to the specified index.
flightgear::FlightPlanRef flightPlan() const
Abstract base class for waypoints (and things that are treated similarly by navigation systems).
Definition route.hxx:105
SGSharedPtr< FlightPlan > FlightPlanRef
SGSharedPtr< Waypt > WayptRef