Debian Codegraph @

src/Autopilot/route_mgr.hxx

raw symbols SCIP
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
13 #include <Navaids/FlightPlan.hxx>
14
15 // forward decls
16 class SGPath;
17 class PropertyWatcher;
18 class RoutePath;
19
20 /**
21 * Top level route manager class
22 *
23 */
24
25 class FGRouteMgr : public SGSubsystem,
26 public flightgear::FlightPlan::Delegate
27 {
28 public:
29 FGRouteMgr();
30 ~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
46 void setFlightPlan(const flightgear::FlightPlanRef& plan);
47 flightgear::FlightPlanRef flightPlan() const;
48
49 void clearRoute();
50
51 flightgear::Waypt* currentWaypt() const;
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
66 /**
67 * Activate a built route. This checks for various mandatory pieces of
68 * data, such as departure and destination airports, and creates waypoints
69 * for them on the route structure.
70 *
71 * returns true if the route was activated successfully, or false if the
72 * route could not be activated for some reason
73 */
74 bool activate();
75
76 /**
77 * deactivate the route if active
78 */
79 void deactivate();
80
81 /**
82 * Set the current waypoint to the specified index.
83 */
84 void jumpToIndex(int index);
85
86 bool saveRoute(const SGPath& p);
87 bool loadRoute(const SGPath& p);
88
89 /**
90 @brief Buiild a waypoint from a string description. Passed to the FlightPlan code to do
91 the actual parsing, see that method for details of syntax.
92
93 Insert position is used to indicate which existing route waypoint(s) to use, to select between
94 ambiguous names.
95 */
96 flightgear::WayptRef waypointFromString(const std::string& target, int insertPosition);
97
98 private:
99 bool commandDefineUserWaypoint(const SGPropertyNode * arg, SGPropertyNode * root);
100 bool commandDeleteUserWaypoint(const SGPropertyNode * arg, SGPropertyNode * root);
101
102 flightgear::FlightPlanRef _plan;
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; ///< departure airport information
112 SGPropertyNode_ptr destination; ///< destination airport information
113 SGPropertyNode_ptr alternate; ///< alternate airport information
114 SGPropertyNode_ptr cruise; ///< cruise information
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
133 /**
134 * Signal property to notify people that the route was edited
135 */
136 SGPropertyNode_ptr _edited;
137
138 /**
139 * Signal property to notify when the last waypoint is reached
140 */
141 SGPropertyNode_ptr _finished;
142
143 SGPropertyNode_ptr _flightplanChanged;
144
145 void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
146
147 /**
148 * retrieve the cached path distance along a leg
149 */
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
170 /**
171 * Helper to keep various pieces of state in sync when the route is
172 * modified (waypoints added, inserted, removed). Notably, this fires the
173 * 'edited' signal.
174 */
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 std::string getSIDWithTransition() const;
194
195 std::string getDestinationICAO() const;
196 std::string getDestinationName() const;
197 void setDestinationICAO(const std::string& aIdent);
198
199 std::string getDestinationRunway() const;
200 void setDestinationRunway(const std::string& aIdent);
201
202 std::string getApproach() const;
203 void setApproach(const std::string& aIdent);
204 std::string getApproachWithTransition() const;
205
206 std::string getSTAR() const;
207 void setSTAR(const std::string& aIdent);
208 std::string getSTARWithTransition() const;
209
210 double getDepartureFieldElevation() const;
211 double getDestinationFieldElevation() const;
212
213 int getCruiseAltitudeFt() const;
214 void setCruiseAltitudeFt(int ft);
215
216 int getCruiseFlightLevel() const;
217 void setCruiseFlightLevel(int fl);
218
219 int getCruiseSpeedKnots() const;
220 void setCruiseSpeedKnots(int kts);
221
222 double getCruiseSpeedMach() const;
223 void setCruiseSpeedMach(double m);
224
225 std::string getAlternate() const;
226 std::string getAlternateName() const;
227 void setAlternate(const std::string &icao);
228 };
229