]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.hxx
Merge branch 'jmt/units-fix' into maint
[flightgear.git] / src / Autopilot / route_mgr.hxx
index 8952ed922436acc8223b163bca0f1f75ffa14709..b096572591533419f4a429cedde07d820c64240a 100644 (file)
 #ifndef _ROUTE_MGR_HXX
 #define _ROUTE_MGR_HXX 1
 
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <simgear/compiler.h>
-
-#include STL_STRING
-#include <vector>
-
-SG_USING_STD(string);
-SG_USING_STD(vector);
-
 #include <simgear/props/props.hxx>
-#include <simgear/route/route.hxx>
+#include <simgear/route/waypoint.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 
+// forward decls
+class SGRoute;
+class SGPath;
+
+class FGAirport;
+typedef SGSharedPtr<FGAirport> FGAirportRef;
 
 /**
  * Top level route manager class
@@ -54,48 +44,100 @@ class FGRouteMgr : public SGSubsystem
 {
 
 private:
-
-    SGRoute *route;
-
+    SGRoute* _route;
+    time_t _takeoffTime;
+    time_t _touchdownTime;
+    FGAirportRef _departure;
+    FGAirportRef _destination;
+    
     // automatic inputs
     SGPropertyNode_ptr lon;
     SGPropertyNode_ptr lat;
     SGPropertyNode_ptr alt;
-
-    // automatic outputs
-    SGPropertyNode_ptr true_hdg_deg;
-    SGPropertyNode_ptr target_altitude_ft;
-    SGPropertyNode_ptr altitude_lock;
-
-    SGPropertyNode_ptr wp0_id;
-    SGPropertyNode_ptr wp0_dist;
-    SGPropertyNode_ptr wp0_eta;
-
-    SGPropertyNode_ptr wp1_id;
-    SGPropertyNode_ptr wp1_dist;
-    SGPropertyNode_ptr wp1_eta;
-
-    SGPropertyNode_ptr wpn_id;
-    SGPropertyNode_ptr wpn_dist;
-    SGPropertyNode_ptr wpn_eta;
-
-
-    class Listener : public SGPropertyChangeListener {
+    SGPropertyNode_ptr magvar;
+    
+    // automatic outputs    
+    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;
+    SGPropertyNode_ptr ete;
+    SGPropertyNode_ptr elapsedFlightTime;
+    
+    SGPropertyNode_ptr active;
+    SGPropertyNode_ptr airborne;
+    
+    SGPropertyNode_ptr wp0;
+    SGPropertyNode_ptr wp1;
+    SGPropertyNode_ptr wpn;
+    
+    
+    SGPropertyNode_ptr _pathNode;
+    SGPropertyNode_ptr _currentWpt;
+    
+    
+    /** 
+     * 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;
+    
+    void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
+    
+    class InputListener : public SGPropertyChangeListener {
     public:
-        Listener(FGRouteMgr *m) : mgr(m) {}
+        InputListener(FGRouteMgr *m) : mgr(m) {}
         virtual void valueChanged (SGPropertyNode * prop);
     private:
         FGRouteMgr *mgr;
     };
 
     SGPropertyNode_ptr input;
-    Listener *listener;
+    SGPropertyNode_ptr weightOnWheels;
+    
+    InputListener *listener;
     SGPropertyNode_ptr mirror;
-    bool altitude_set;
 
-    int make_waypoint( SGWayPoint **wp, string& target );
+    /**
+     * Create a SGWayPoint from a string in the following format:
+     *  - simple identifier
+     *  - decimal-lon,decimal-lat
+     *  - airport-id/runway-id
+     *  - navaid/radial-deg/offset-nm
+     */
+    SGWayPoint* make_waypoint(const string& target);
+    
+    
     void update_mirror();
-
+    
+    void currentWaypointChanged();
+    
+    /**
+     * Parse a route/wp node (from a saved, property-lsit formatted route)
+     */
+    void parseRouteWaypoint(SGPropertyNode* aWP);
+    
+    /**
+     * Check if we've reached the final waypoint. 
+     * Returns true if we have.
+     */
+    bool checkFinished();
+    
+// tied getters and setters
+    const char* getDepartureICAO() const;
+    const char* getDepartureName() const;
+    void setDepartureICAO(const char* aIdent);
+    
+    const char* getDestinationICAO() const;
+    const char* getDestinationName() const;
+    void setDestinationICAO(const char* aIdent);
+    
 public:
 
     FGRouteMgr();
@@ -109,18 +151,45 @@ public:
 
     bool build ();
 
-    int new_waypoint( const string& tgt_alt, int n = -1 );
+    void new_waypoint( const string& tgt_alt, int n = -1 );
     void add_waypoint( const SGWayPoint& wp, int n = -1 );
     SGWayPoint pop_waypoint( int i = 0 );
 
-    SGWayPoint get_waypoint( int i ) const {
-        return route->get_waypoint(i);
-    }
-
-    int size() const {
-        return route->size();
-    }
-
+    SGWayPoint get_waypoint( int i ) const;
+    int size() const;
+        
+    bool isRouteActive() const;
+        
+    int currentWaypoint() const;
+       
+    /**
+     * Find a waypoint in the route, by position, and return its index, or
+     * -1 if no matching waypoint was found in the route.
+     */
+    int findWaypoint(const SGGeod& aPos) const;
+          
+    /**
+     * 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();
+
+    /**
+     * Step to the next waypoint on the active route
+     */
+    void sequence();
+    
+    /**
+     *
+     */
+    void jumpToIndex(int index);
+    
+    void saveRoute();
+    void loadRoute();
 };