]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/groundnetwork.hxx
Several Bugfixes:
[flightgear.git] / src / Airports / groundnetwork.hxx
index fb6089dfae2533bf0e41b0b8f57ff6442942e68b..cec19d38bfcc666659ca0db819185f03c03dd606 100644 (file)
 #ifndef _GROUNDNETWORK_HXX_
 #define _GROUNDNETWORK_HXX_
 
-#include <simgear/compiler.h>
+#include <osg/Geode>
+#include <osg/Geometry>
+#include <osg/MatrixTransform>
+#include <osg/Shape>
 
 
-#include STL_STRING
-#include <vector>
+#include <simgear/compiler.h>
+#include <simgear/route/waypoint.hxx>
 
-SG_USING_STD(string);
-SG_USING_STD(vector);
+#include <string>
+#include <vector>
 
+using std::string;
+using std::vector;
 
+#include "gnnode.hxx"
 #include "parking.hxx"
-//#include <AIModel/AIBase.hxx>
-
+#include <ATC/trafficcontrol.hxx>
 
 
 class FGTaxiSegment; // forward reference
 class FGAIFlightPlan; // forward reference
+class FGAirport;      // forward reference
 
-typedef vector<FGTaxiSegment>  FGTaxiSegmentVector;
-typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
-typedef vector<FGTaxiSegment>::iterator FGTaxiSegmentVectorIterator;
-typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
-
-/**************************************************************************************
- * class FGTaxiNode
- *************************************************************************************/
-class FGTaxiNode 
-{
-private:
-  double lat;
-  double lon;
-  int index;
-  FGTaxiSegmentPointerVector next; // a vector to all the segments leaving from this node
-  
-public:
-  FGTaxiNode();
-  FGTaxiNode(double, double, int);
-
-  void setIndex(int idx)                  { index = idx;};
-  void setLatitude (double val)           { lat = val;};
-  void setLongitude(double val)           { lon = val;};
-  void setLatitude (const string& val)           { lat = processPosition(val);  };
-  void setLongitude(const string& val)           { lon = processPosition(val);  };
-  void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
-  
-  double getLatitude() { return lat;};
-  double getLongitude(){ return lon;};
-
-  int getIndex() { return index; };
-  FGTaxiNode *getAddress() { return this;};
-  FGTaxiSegmentPointerVectorIterator getBeginRoute() { return next.begin(); };
-  FGTaxiSegmentPointerVectorIterator getEndRoute()   { return next.end();   }; 
-  bool operator<(const FGTaxiNode &other) const { return index < other.index; };
-};
+typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
+typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
 
-typedef vector<FGTaxiNode> FGTaxiNodeVector;
-typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
+//typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
+//typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
 
 /***************************************************************************************
  * class FGTaxiSegment
@@ -88,255 +60,311 @@ typedef vector<FGTaxiNode>::iterator FGTaxiNodeVectorIterator;
 class FGTaxiSegment
 {
 private:
-  int startNode;
-  int endNode;
-  double length;
-  FGTaxiNode *start;
-  FGTaxiNode *end;
-  int index;
-  FGTaxiSegment *oppositeDirection;
+    int startNode;
+    int endNode;
+    double length;
+    double heading;
+    SGGeod center;
+    bool isActive;
+    bool isPushBackRoute;
+    bool isBlocked;
+    FGTaxiNode *start;
+    FGTaxiNode *end;
+    int index;
+    FGTaxiSegment *oppositeDirection;
 
-public:
-  FGTaxiSegment();
-  //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
-
-  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 setTrackDistance();
+public:
+    FGTaxiSegment() :
+            startNode(0),
+            endNode(0),
+            length(0),
+            heading(0),
+            isActive(0),
+            isPushBackRoute(0),
+            isBlocked(0),
+            start(0),
+            end(0),
+            index(0),
+            oppositeDirection(0)
+    {
+    };
+
+    FGTaxiSegment         (const FGTaxiSegment &other) :
+            startNode         (other.startNode),
+            endNode           (other.endNode),
+            length            (other.length),
+            heading           (other.heading),
+            center            (other.center),
+            isActive          (other.isActive),
+            isPushBackRoute   (other.isPushBackRoute),
+            isBlocked         (other.isBlocked),
+            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;
+        heading            = other.heading;
+        center             = other.center;
+        isActive           = other.isActive;
+        isPushBackRoute    = other.isPushBackRoute;
+        isBlocked          = other.isBlocked;
+        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 setDimensions(double elevation);
+    void block() {
+        isBlocked = true;
+    }
+    void unblock() {
+        isBlocked = false;
+    };
+    bool hasBlock() {
+        return isBlocked;
+    };
+
+    FGTaxiNode * getEnd() {
+        return end;
+    };
+    FGTaxiNode * getStart() {
+        return start;
+    };
+    double getLength() {
+        return length;
+    };
+    int getIndex() {
+        return index;
+    };
+    double getLatitude()  {
+        return center.getLatitudeDeg();
+    };
+    double getLongitude() {
+        return center.getLongitudeDeg();
+    };
+    double getHeading()   {
+        return heading;
+    };
+    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);
 
-  FGTaxiNode * getEnd() { return end;};
-  FGTaxiNode * getStart() { return start; };
-  double getLength() { return length; };
-  int getIndex() { return index; };
 
- FGTaxiSegment *getAddress() { return this;};
 
-  bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
-  FGTaxiSegment *opposite() { return oppositeDirection; };
 
-  
 };
 
 
+
+
 typedef vector<int> intVec;
 typedef vector<int>::iterator intVecIterator;
 
+
+
 /***************************************************************************************
  * class FGTaxiRoute
  **************************************************************************************/
 class FGTaxiRoute
 {
 private:
-  intVec nodes;
-  intVec routes;
-  double distance;
-  intVecIterator currNode;
-  intVecIterator currRoute;
+    intVec nodes;
+    intVec routes;
+    double distance;
+//  int depth;
+    intVecIterator currNode;
+    intVecIterator currRoute;
 
 public:
-  FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
-  FGTaxiRoute(intVec nds, intVec rts, double dist) { 
-    nodes = nds; 
-    routes = rts;
-    distance = dist; 
-    currNode = nodes.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);
-  
-  void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
-  int size() { return nodes.size(); };
+    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();
+        currRoute = routes.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);
+
+    void first() {
+        currNode = nodes.begin();
+        currRoute = routes.begin();
+    };
+    int size() {
+        return nodes.size();
+    };
+    int nodesLeft() {
+        return nodes.end() - currNode;
+    };
+
+//  int getDepth() { return depth; };
 };
 
 typedef vector<FGTaxiRoute> TaxiRouteVector;
 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
 
 /**************************************************************************************
- * class FGATCInstruction
- * like class FGATC Controller, this class definition should go into its own file
- * and or directory... For now, just testing this stuff out though...
- *************************************************************************************/
-class FGATCInstruction
-{
-private:
-  bool holdPattern;
-  bool holdPosition;
-  bool changeSpeed;
-  bool changeHeading;
-  bool changeAltitude;
-
-  double speed;
-  double heading;
-  double alt;
-public:
-
-  FGATCInstruction();
-  bool hasInstruction   ();
-  bool getHoldPattern   () { return holdPattern;    };
-  bool getHoldPosition  () { return holdPosition;   };
-  bool getChangeSpeed   () { return changeSpeed;    };
-  bool getChangeHeading () { return changeHeading;  };
-  bool getChangeAltitude() { return changeAltitude; };
-
-  double getSpeed       () { return speed; };
-  double getHeading     () { return heading; };
-  double getAlt         () { return alt; };
-
-  void setHoldPattern   (bool val) { holdPattern    = val; };
-  void setHoldPosition  (bool val) { holdPosition   = val; };
-  void setChangeSpeed   (bool val) { changeSpeed    = val; };
-  void setChangeHeading (bool val) { changeHeading  = val; };
-  void setChangeAltitude(bool val) { changeAltitude = val; };
-
-  void setSpeed       (double val) { speed   = val; };
-  void setHeading     (double val) { heading = val; };
-  void setAlt         (double val) { alt     = val; };
-};
-
-class FGGroundNetwork;
-
-/**************************************************************************************
- * class FGTrafficRecord
+ * class FGGroundNetWork
  *************************************************************************************/
-class FGTrafficRecord
+class FGGroundNetwork : public FGATCController
 {
 private:
-  int id, waitsForId;
-  int currentPos;
-  intVec intentions;
-  FGATCInstruction instruction;
-  double latitude, longitude, heading, speed, altitude, radius;
-  
-  
-public:
-  FGTrafficRecord() {};
-  
-  void setId(int val)  { id = val; };
-  void setRadius(double rad) { radius = rad;};
-  void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
-  int getId() { return id;};
-  FGATCInstruction getInstruction() { return instruction;};
-  bool hasInstruction() { return instruction.hasInstruction(); };
-  void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
-  bool checkPositionAndIntentions(FGTrafficRecord &other);
-  int  crosses                   (FGGroundNetwork *, FGTrafficRecord &other); 
-  bool isOpposing                (FGGroundNetwork *, FGTrafficRecord &other, int node);
-
-  bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
-  
-  double getLatitude () { return latitude ; };
-  double getLongitude() { return longitude; };
-  double getHeading  () { return heading  ; };
-  double getSpeed    () { return speed    ; };
-  double getAltitude () { return altitude ; };
-  double getRadius   () { return radius   ; };
-
-  int getWaitsForId  () { return waitsForId; };
-
-  void setSpeedAdjustment(double spd) { instruction.setChangeSpeed(true); 
-                                        instruction.setSpeed(spd); };
-  void setHeadingAdjustment(double heading) { instruction.setChangeHeading(true);
-                                              instruction.setHeading(heading); };
-  void clearSpeedAdjustment  () { instruction.setChangeSpeed  (false); };
-  void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
-
-  bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
-  bool hasHoldPosition() { return instruction.getHoldPosition(); };
-  void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
-
-  void setWaitsForId(int id) { waitsForId = id; };
+    bool hasNetwork;
+    bool networkInitialized;
+    time_t nextSave;
+    //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;
 
-typedef vector<FGTrafficRecord> TrafficVector;
-typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
 
+    //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);
 
 
-/**************************************************************************************
- * class FGATCController
- * NOTE: this class serves as an abstraction layer for all sorts of ATC controller,
- * Ground and air, so eventually it should move to its own file / directory. 
- *************************************************************************************/
-class FGATCController
-{
-private:
-  double dt_count;
-public:
-  FGATCController() { dt_count = 0;};
-  virtual ~FGATCController() {};
-  virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
-                               double lat, double lon,
-                               double hdg, double spd, double alt, double radius) = 0;
-  virtual void             signOff(int id) = 0;
-  virtual void             update(int id, double lat, double lon, 
-                                 double heading, double speed, double alt, double dt) = 0;
-  virtual bool             hasInstruction(int id) = 0;
-  virtual FGATCInstruction getInstruction(int id) = 0;
-
-  double getDt() { return dt_count; };
-  void   setDt(double dt) { dt_count = dt;};
-};
 
-
-
-/**************************************************************************************
- * class FGGroundNetWork
- *************************************************************************************/
-class FGGroundNetwork : public FGATCController
-{
-private:
-  bool hasNetwork;
-  FGTaxiNodeVector    nodes;
-  FGTaxiSegmentVector segments;
-  //intVec route;
-  intVec nodesStack;
-  intVec routesStack;
-  TaxiRouteVector routes;
-  TrafficVector activeTraffic;
-  TrafficVectorIterator currTraffic;
-  
-  bool foundRoute;
-  double totalDistance, maxDistance;
-
-  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);
-  
 public:
-  FGGroundNetwork();
-
-  void addNode   (const FGTaxiNode& node);
-  void addNodes  (FGParkingVec *parkings);
-  void addSegment(const FGTaxiSegment& seg); 
-
-  void init();
-  bool exists() { return hasNetwork; };
-  int findNearestNode(double lat, double lon);
-  FGTaxiNode *findNode(int idx);
-  FGTaxiSegment *findSegment(int idx);
-  FGTaxiRoute findShortestRoute(int start, int end);
-  void trace(FGTaxiNode *, int, int, double dist);
-
-  virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
-                               double lat, double lon, double hdg, double spd, double alt, double radius);
-  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);
+    FGGroundNetwork();
+    ~FGGroundNetwork();
+
+    void addNode   (const FGTaxiNode& node);
+    void addNodes  (FGParkingVec *parkings);
+    void addSegment(const FGTaxiSegment& seg);
+
+    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 setParent(FGAirport *par) {
+        parent = par;
+    };
+
+    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 string getName();
+    virtual void update(double dt);
+
+    void saveElevationCache();
 };