]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/groundnetwork.hxx
commradio: improvements for atis speech
[flightgear.git] / src / Airports / groundnetwork.hxx
index 10a78b275abc236cfd547bf229358a9333684243..76eaa899e4e71f0f498c46332607588c2dd32003 100644 (file)
 #define _GROUNDNETWORK_HXX_
 
 #include <simgear/compiler.h>
-#include <simgear/route/waypoint.hxx>
 
 #include <string>
-#include <vector>
-
-using std::string;
-using std::vector;
 
 #include "gnnode.hxx"
 #include "parking.hxx"
 #include <ATC/trafficcontrol.hxx>
 
-class FGTaxiSegment; // forward reference
-class FGAIFlightPlan; // forward reference
-class FGAirport;      // forward reference
-
-typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
-typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
-
-//typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
-//typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
+class Block
+{
+private:
+    int id;
+    time_t blocktime;
+    time_t touch;
+public:
+    Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
+    ~Block() {};
+    int getId() { return id; };
+    void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
+    const time_t getBlockTime() const { return blocktime; };
+    time_t getTimeStamp() { return touch; };
+    bool operator< (const Block &other) const { return blocktime < other.blocktime; };
+};
 
 /***************************************************************************************
  * class FGTaxiSegment
@@ -53,105 +54,52 @@ typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
 class FGTaxiSegment
 {
 private:
-  int startNode;
-  int endNode;
-  double length;
-  double course;
-  double headingDiff;
-  bool isActive;
-  bool isPushBackRoute;
-  FGTaxiNode *start;
-  FGTaxiNode *end;
-  int index;
-  FGTaxiSegment *oppositeDirection;
-
+    const PositionedID startNode;
+    const PositionedID endNode;
+    
+    bool isActive;
+    BlockList blockTimes;
+
+    int index;
+    FGTaxiSegment *oppositeDirection;
 
+    friend class FGGroundNetwork;
 public:
-  FGTaxiSegment() :
-      startNode(0),
-      endNode(0),
-      length(0),
-      course(0),
-      headingDiff(0),
-      isActive(0),
-      isPushBackRoute(0),
-      start(0),
-      end(0),
-      index(0),
-      oppositeDirection(0)
-  {
-  };
-
-  FGTaxiSegment         (const FGTaxiSegment &other) :
-      startNode         (other.startNode),
-      endNode           (other.endNode),
-      length            (other.length),
-      course            (other.course),
-      headingDiff       (other.headingDiff),
-      isActive          (other.isActive),
-      isPushBackRoute   (other.isPushBackRoute),
-      start             (other.start),
-      end               (other.end),
-      index             (other.index),
-      oppositeDirection (other.oppositeDirection)
-  {
-  };
-
-  FGTaxiSegment& operator=(const FGTaxiSegment &other)
-  {
-      startNode          = other.startNode;
-      endNode            = other.endNode;
-      length             = other.length;
-      course             = other.course;
-      headingDiff        = other.headingDiff;
-      isActive           = other.isActive;
-      isPushBackRoute    = other.isPushBackRoute;
-      start              = other.start;
-      end                = other.end;
-      index              = other.index;
-      oppositeDirection  = other.oppositeDirection;
-      return *this;
-  };
-
-  void setIndex        (int val) { index     = val; };
-  void setStartNodeRef (int val) { startNode = val; };
-  void setEndNodeRef   (int val) { endNode   = val; };
-
-  void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
-
-  void setStart(FGTaxiNodeVector *nodes);
-  void setEnd  (FGTaxiNodeVector *nodes);
-  void setPushBackType(bool val) { isPushBackRoute = val; };
-  void setTrackDistance();
-
-  FGTaxiNode * getEnd() { return end;};
-  FGTaxiNode * getStart() { return start; };
-  double getLength() { return length; };
-  int getIndex() { return index; };
+    FGTaxiSegment(PositionedID start, PositionedID end);
   
-  bool isPushBack() { return isPushBackRoute; };
-
-  int getPenalty(int nGates);
-
-  FGTaxiSegment *getAddress() { return this;};
-
-  bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
-  bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
-  FGTaxiSegment *opposite() { return oppositeDirection; };
-  void setCourseDiff(double crse);
-
-
+    void setIndex        (int val) {
+        index     = val;
+    };
   
-};
-
-
+    void setDimensions(double elevation);
+    void block(int id, time_t blockTime, time_t now);
+    void unblock(time_t now); 
+    bool hasBlock(time_t now);
 
+    FGTaxiNodeRef getEnd() const;
+    FGTaxiNodeRef getStart() const;
+  
+    double getLength() const;
+  
+    // compute the center of the arc
+    SGGeod getCenter() const;
+  
+    double getHeading() const;
+    
+    int getIndex() {
+      return index;
+    };
 
-typedef vector<int> intVec;
-typedef vector<int>::iterator intVecIterator;
+    int getPenalty(int nGates);
 
+    bool operator<(const FGTaxiSegment &other) const {
+        return index < other.index;
+    };
 
+    FGTaxiSegment *opposite() {
+        return oppositeDirection;
+    };
+};
 
 /***************************************************************************************
  * class FGTaxiRoute
@@ -159,121 +107,136 @@ typedef vector<int>::iterator intVecIterator;
 class FGTaxiRoute
 {
 private:
-  intVec nodes;
-  intVec routes;
-  double distance;
-  int depth;
-  intVecIterator currNode;
-  intVecIterator currRoute;
+    PositionedIDVec nodes;
+    double distance;
+    PositionedIDVec::iterator currNode;
 
 public:
-  FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
-  FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) { 
-    nodes = nds; 
-    routes = rts;
-    distance = dist; 
-    currNode = nodes.begin();
-    depth = dpth;
-  };
-
-  FGTaxiRoute& operator= (const FGTaxiRoute &other) {
-    nodes = other.nodes;
-    routes = other.routes;
-    distance = other.distance;
-    depth = other.depth;
-    currNode = nodes.begin();
-    currRoute = routes.begin();
-    return *this;
-  };
-
-  FGTaxiRoute(const FGTaxiRoute& copy) :
-    nodes(copy.nodes),
-    routes(copy.routes),
-    distance(copy.distance),
-    depth(copy.depth),
-    currNode(nodes.begin()),
-    currRoute(routes.begin())
-  {};
-
-  bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
-  bool empty () { return nodes.begin() == nodes.end(); };
-  bool next(int *nde); 
-  bool next(int *nde, int *rte);
-  void rewind(int legNr);
+    FGTaxiRoute() {
+        distance = 0;
+        currNode = nodes.begin();
+    };
+  
+    FGTaxiRoute(const PositionedIDVec& nds, double dist, int dpth) {
+        nodes = nds;
+        distance = dist;
+        currNode = nodes.begin();
+    };
+
+    FGTaxiRoute& operator= (const FGTaxiRoute &other) {
+        nodes = other.nodes;
+        distance = other.distance;
+        currNode = nodes.begin();
+        return *this;
+    };
+
+    FGTaxiRoute(const FGTaxiRoute& copy) :
+            nodes(copy.nodes),
+            distance(copy.distance),
+            currNode(nodes.begin())
+    {};
+
+    bool operator< (const FGTaxiRoute &other) const {
+        return distance < other.distance;
+    };
+    bool empty () {
+        return nodes.empty();
+    };
+    bool next(PositionedID *nde);
   
-  void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
-  int size() { return nodes.size(); };
-  int getDepth() { return depth; };
+    void first() {
+        currNode = nodes.begin();
+    };
+    int size() {
+        return nodes.size();
+    };
+    int nodesLeft() {
+        return nodes.end() - currNode;
+    };
 };
 
-typedef vector<FGTaxiRoute> TaxiRouteVector;
-typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
-
 /**************************************************************************************
  * class FGGroundNetWork
  *************************************************************************************/
 class FGGroundNetwork : public FGATCController
 {
 private:
-  bool hasNetwork;
-  //int maxDepth;
-  int count;
-  FGTaxiNodeVector    nodes;
-  FGTaxiNodeVector    pushBackNodes;
-  FGTaxiSegmentVector segments;
-  //intVec route;
-  //intVec nodesStack;
-  //intVec routesStack;
-  TaxiRouteVector routes;
-  TrafficVector activeTraffic;
-  TrafficVectorIterator currTraffic;
-
-  bool foundRoute;
-  double totalDistance, maxDistance;
-  FGTowerController *towerController;
-  FGAirport *parent;
-
-
-  //void printRoutingError(string);
-
-  void checkSpeedAdjustment(int id, double lat, double lon, 
-                           double heading, double speed, double alt);
-  void checkHoldPosition(int id, double lat, double lon, 
-                        double heading, double speed, double alt);
+    bool hasNetwork;
+    bool networkInitialized;
+    time_t nextSave;
+    //int maxDepth;
+    int count;
+    int version;
+  
+    FGTaxiSegmentVector segments;
 
-public:
-  FGGroundNetwork();
-  ~FGGroundNetwork();
+    TrafficVector activeTraffic;
+    TrafficVectorIterator currTraffic;
 
-  void addNode   (const FGTaxiNode& node);
-  void addNodes  (FGParkingVec *parkings);
-  void addSegment(const FGTaxiSegment& seg); 
+    double totalDistance, maxDistance;
+    FGTowerController *towerController;
+    FGAirport *parent;
 
-  void init();
-  bool exists() { return hasNetwork; };
-  void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
-  
-  int findNearestNode(double lat, double lon);
-  int findNearestNode(const SGGeod& aGeod);
-  
-  FGTaxiNode *findNode(unsigned idx);
-  FGTaxiSegment *findSegment(unsigned idx);
-  FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
-  //void trace(FGTaxiNode *, int, int, double dist);
 
-  int getNrOfNodes() { return nodes.size(); };
+    //void printRoutingError(string);
 
-  void setParent(FGAirport *par) { parent = par; };
+    void checkSpeedAdjustment(int id, double lat, double lon,
+                              double heading, double speed, double alt);
+    void checkHoldPosition(int id, double lat, double lon,
+                           double heading, double speed, double alt);
 
-  virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
-                               double lat, double lon, double hdg, double spd, double alt, 
-                               double radius, int leg, FGAIAircraft *aircraft);
-  virtual void signOff(int id);
-  virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
-  virtual bool hasInstruction(int id);
-  virtual FGATCInstruction getInstruction(int id);
 
-  bool checkForCircularWaits(int id);
+    void parseCache();
+  
+    void loadSegments();
+public:
+    FGGroundNetwork();
+    ~FGGroundNetwork();
+    
+    void setVersion (int v) { version = v;};
+    int getVersion() { return version; };
+
+    void init(FGAirport* pr);
+    bool exists() {
+        return hasNetwork;
+    };
+    void setTowerController(FGTowerController *twrCtrlr) {
+        towerController = twrCtrlr;
+    };
+
+    int findNearestNode(const SGGeod& aGeod) const;
+    int findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
+
+    FGTaxiNodeRef findNode(PositionedID idx) const;
+    FGTaxiSegment *findSegment(unsigned idx) const;
+  
+    /**
+     * Find the taxiway segment joining two (ground-net) nodes. Returns
+     * NULL if no such segment exists.
+     * It is permitted to pass 0 for the 'to' ID, indicating that any
+     * segment originating at 'from' is acceptable.
+     */
+    FGTaxiSegment* findSegment(PositionedID from, PositionedID to) const;
+  
+    FGTaxiRoute findShortestRoute(PositionedID start, PositionedID end, bool fullSearch=true);
+
+    virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
+                                  double lat, double lon, double hdg, double spd, double alt,
+                                  double radius, int leg, FGAIAircraft *aircraft);
+    virtual void signOff(int id);
+    virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
+    virtual bool hasInstruction(int id);
+    virtual FGATCInstruction getInstruction(int id);
+
+    bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
+                                AtcMsgDir msgDir);
+    bool checkForCircularWaits(int id);
+    virtual void render(bool);
+    virtual std::string getName();
+    virtual void update(double dt);
+
+    void saveElevationCache();
+    void addVersion(int v) {version = v; };
 };