2004-01-31 19:47:45 +00:00
|
|
|
// route_mgr.hxx - manage a route (i.e. a collection of waypoints)
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started January 2004.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
|
2004-01-31 19:47:45 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-01-31 19:47:45 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _ROUTE_MGR_HXX
|
|
|
|
#define _ROUTE_MGR_HXX 1
|
|
|
|
|
|
|
|
#include <simgear/props/props.hxx>
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
|
2012-05-12 10:25:56 +01:00
|
|
|
#include <Navaids/FlightPlan.hxx>
|
2009-10-11 12:37:13 +01:00
|
|
|
|
2009-10-05 21:09:20 +00:00
|
|
|
// forward decls
|
|
|
|
class SGPath;
|
2009-10-11 12:37:13 +01:00
|
|
|
class PropertyWatcher;
|
2004-01-31 19:47:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Top level route manager class
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
class FGRouteMgr : public SGSubsystem,
|
|
|
|
public flightgear::FlightPlan::Delegate
|
2004-01-31 19:47:45 +00:00
|
|
|
{
|
2009-10-11 12:37:13 +01:00
|
|
|
public:
|
|
|
|
FGRouteMgr();
|
|
|
|
~FGRouteMgr();
|
|
|
|
|
|
|
|
void init ();
|
|
|
|
void postinit ();
|
|
|
|
void bind ();
|
|
|
|
void unbind ();
|
|
|
|
void update (double dt);
|
|
|
|
|
|
|
|
bool isRouteActive() const;
|
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
int currentIndex() const;
|
|
|
|
|
|
|
|
void setFlightPlan(flightgear::FlightPlan* plan);
|
|
|
|
flightgear::FlightPlan* flightPlan() const;
|
|
|
|
|
|
|
|
void clearRoute();
|
|
|
|
|
2009-10-11 12:37:13 +01:00
|
|
|
flightgear::Waypt* currentWaypt() const;
|
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
int numLegs() const;
|
2009-10-11 12:37:13 +01:00
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
// deprecated
|
2009-10-11 12:37:13 +01:00
|
|
|
int numWaypts() const
|
2012-04-24 22:55:30 +01:00
|
|
|
{ return numLegs(); }
|
|
|
|
|
|
|
|
// deprecated
|
2009-10-11 12:37:13 +01:00
|
|
|
flightgear::Waypt* wayptAtIndex(int index) const;
|
2012-04-24 22:55:30 +01:00
|
|
|
|
2011-07-03 17:56:01 +01:00
|
|
|
SGPropertyNode_ptr wayptNodeAtIndex(int index) const;
|
2012-04-24 22:55:30 +01:00
|
|
|
|
|
|
|
void removeLegAtIndex(int aIndex);
|
|
|
|
|
2009-10-11 12:37:13 +01:00
|
|
|
/**
|
|
|
|
* Activate a built route. This checks for various mandatory pieces of
|
|
|
|
* data, such as departure and destination airports, and creates waypoints
|
|
|
|
* for them on the route structure.
|
|
|
|
*
|
|
|
|
* returns true if the route was activated successfully, or false if the
|
|
|
|
* route could not be activated for some reason
|
|
|
|
*/
|
|
|
|
bool activate();
|
2012-09-26 22:43:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* deactivate the route if active
|
|
|
|
*/
|
|
|
|
void deactivate();
|
2004-01-31 19:47:45 +00:00
|
|
|
|
2009-10-11 12:37:13 +01:00
|
|
|
/**
|
|
|
|
* Step to the next waypoint on the active route
|
|
|
|
*/
|
|
|
|
void sequence();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current waypoint to the specified index.
|
|
|
|
*/
|
|
|
|
void jumpToIndex(int index);
|
|
|
|
|
2011-05-29 23:43:40 +01:00
|
|
|
bool saveRoute(const SGPath& p);
|
|
|
|
bool loadRoute(const SGPath& p);
|
2009-10-11 12:37:13 +01:00
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
flightgear::WayptRef waypointFromString(const std::string& target);
|
|
|
|
|
2009-10-11 12:37:13 +01:00
|
|
|
/**
|
|
|
|
* Helper command to setup current airport/runway if necessary
|
|
|
|
*/
|
|
|
|
void initAtPosition();
|
2012-04-24 22:55:30 +01:00
|
|
|
|
2004-01-31 19:47:45 +00:00
|
|
|
private:
|
2012-04-24 22:55:30 +01:00
|
|
|
flightgear::FlightPlan* _plan;
|
2009-10-11 12:37:13 +01:00
|
|
|
|
2009-10-05 21:09:20 +00:00
|
|
|
time_t _takeoffTime;
|
|
|
|
time_t _touchdownTime;
|
2012-04-24 22:55:30 +01:00
|
|
|
|
2004-01-31 19:47:45 +00:00
|
|
|
// automatic inputs
|
2009-10-05 21:09:20 +00:00
|
|
|
SGPropertyNode_ptr magvar;
|
|
|
|
|
2009-10-14 06:50:06 +00:00
|
|
|
// automatic outputs
|
2009-10-05 21:09:20 +00:00
|
|
|
SGPropertyNode_ptr departure; ///< departure airport information
|
|
|
|
SGPropertyNode_ptr destination; ///< destination airport information
|
|
|
|
SGPropertyNode_ptr alternate; ///< alternate airport information
|
|
|
|
SGPropertyNode_ptr cruise; ///< cruise information
|
|
|
|
|
|
|
|
SGPropertyNode_ptr totalDistance;
|
2012-04-09 14:06:44 +01:00
|
|
|
SGPropertyNode_ptr distanceToGo;
|
2009-10-05 21:09:20 +00:00
|
|
|
SGPropertyNode_ptr ete;
|
|
|
|
SGPropertyNode_ptr elapsedFlightTime;
|
|
|
|
|
|
|
|
SGPropertyNode_ptr active;
|
|
|
|
SGPropertyNode_ptr airborne;
|
|
|
|
|
|
|
|
SGPropertyNode_ptr wp0;
|
|
|
|
SGPropertyNode_ptr wp1;
|
|
|
|
SGPropertyNode_ptr wpn;
|
|
|
|
|
|
|
|
|
|
|
|
SGPropertyNode_ptr _pathNode;
|
2009-10-18 19:59:01 +00:00
|
|
|
SGPropertyNode_ptr _currentWpt;
|
|
|
|
|
2009-10-05 21:09:20 +00:00
|
|
|
|
2009-10-15 21:30:10 +00:00
|
|
|
/**
|
|
|
|
* Signal property to notify people that the route was edited
|
|
|
|
*/
|
|
|
|
SGPropertyNode_ptr _edited;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal property to notify when the last waypoint is reached
|
|
|
|
*/
|
|
|
|
SGPropertyNode_ptr _finished;
|
|
|
|
|
2012-05-07 23:48:56 +01:00
|
|
|
SGPropertyNode_ptr _flightplanChanged;
|
|
|
|
|
2009-10-05 21:09:20 +00:00
|
|
|
void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
|
|
|
|
|
2012-04-09 14:06:44 +01:00
|
|
|
/**
|
|
|
|
* retrieve the cached path distance along a leg
|
|
|
|
*/
|
|
|
|
double cachedLegPathDistanceM(int index) const;
|
|
|
|
double cachedWaypointPathTotalDistance(int index) const;
|
|
|
|
|
2009-10-05 21:09:20 +00:00
|
|
|
class InputListener : public SGPropertyChangeListener {
|
2006-05-08 14:35:29 +00:00
|
|
|
public:
|
2009-10-05 21:09:20 +00:00
|
|
|
InputListener(FGRouteMgr *m) : mgr(m) {}
|
2006-05-08 14:35:29 +00:00
|
|
|
virtual void valueChanged (SGPropertyNode * prop);
|
|
|
|
private:
|
|
|
|
FGRouteMgr *mgr;
|
|
|
|
};
|
|
|
|
|
|
|
|
SGPropertyNode_ptr input;
|
2009-10-05 21:09:20 +00:00
|
|
|
SGPropertyNode_ptr weightOnWheels;
|
2012-05-07 23:48:56 +01:00
|
|
|
SGPropertyNode_ptr groundSpeed;
|
|
|
|
|
2009-10-05 21:09:20 +00:00
|
|
|
InputListener *listener;
|
2011-05-29 23:43:40 +01:00
|
|
|
SGPropertyNode_ptr mirror;
|
2012-04-24 22:55:30 +01:00
|
|
|
|
2010-02-21 20:44:17 +00:00
|
|
|
/**
|
2009-10-11 12:37:13 +01:00
|
|
|
* Helper to keep various pieces of state in sync when the route is
|
2010-02-21 20:44:17 +00:00
|
|
|
* modified (waypoints added, inserted, removed). Notably, this fires the
|
|
|
|
* 'edited' signal.
|
|
|
|
*/
|
2012-04-24 22:55:30 +01:00
|
|
|
virtual void waypointsChanged();
|
2009-10-05 21:09:20 +00:00
|
|
|
|
2006-05-09 21:01:01 +00:00
|
|
|
void update_mirror();
|
2009-10-05 21:09:20 +00:00
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
virtual void currentWaypointChanged();
|
2009-10-15 21:30:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we've reached the final waypoint.
|
|
|
|
* Returns true if we have.
|
|
|
|
*/
|
|
|
|
bool checkFinished();
|
2009-11-07 00:16:52 +00:00
|
|
|
|
2009-10-11 12:37:13 +01:00
|
|
|
/**
|
|
|
|
* Predicate for helping the UI - test if at least one waypoint was
|
|
|
|
* entered by the user (as opposed to being generated by the route-manager)
|
|
|
|
*/
|
|
|
|
bool haveUserWaypoints() const;
|
|
|
|
|
2009-11-07 00:16:52 +00:00
|
|
|
// tied getters and setters
|
|
|
|
const char* getDepartureICAO() const;
|
|
|
|
const char* getDepartureName() const;
|
|
|
|
void setDepartureICAO(const char* aIdent);
|
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
const char* getDepartureRunway() const;
|
|
|
|
void setDepartureRunway(const char* aIdent);
|
|
|
|
|
|
|
|
const char* getSID() const;
|
|
|
|
void setSID(const char* aIdent);
|
|
|
|
|
2009-11-07 00:16:52 +00:00
|
|
|
const char* getDestinationICAO() const;
|
|
|
|
const char* getDestinationName() const;
|
|
|
|
void setDestinationICAO(const char* aIdent);
|
2004-01-31 19:47:45 +00:00
|
|
|
|
2012-04-24 22:55:30 +01:00
|
|
|
const char* getDestinationRunway() const;
|
|
|
|
void setDestinationRunway(const char* aIdent);
|
|
|
|
|
|
|
|
const char* getApproach() const;
|
|
|
|
void setApproach(const char* aIdent);
|
|
|
|
|
|
|
|
const char* getSTAR() const;
|
|
|
|
void setSTAR(const char* aIdent);
|
|
|
|
|
|
|
|
double getDepartureFieldElevation() const;
|
|
|
|
double getDestinationFieldElevation() const;
|
2004-01-31 19:47:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _ROUTE_MGR_HXX
|