]> git.mxchange.org Git - flightgear.git/commitdiff
Fixes and code clean-up:
authordurk <durk>
Sun, 15 Jul 2007 14:08:31 +0000 (14:08 +0000)
committerdurk <durk>
Sun, 15 Jul 2007 14:08:31 +0000 (14:08 +0000)
- Airports Directory
Thomas Foerster: Pulls out the FGTaxiNode implementation into gnnode.cxx.
Melchior / Durk: Copy Constructor and assignment operator for FGTaxiRoute

- AIModels Directory
Durk / Melchior / Czaba Halasz: Ensure that all derived classes use AIBase
member 'callsign'. Adapted, moved and deleted getter/setter functions where
necessary
Czaba Halasz: Fix AIBase model path vs. submodel path consistency.

- Traffic Directory and AIModels CreateFlightPlanCruise
DT: Temporary revert parts of the position estimation code.

15 files changed:
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlanCreateCruise.cxx
src/AIModel/AIMultiplayer.cxx
src/AIModel/AIMultiplayer.hxx
src/AIModel/submodel.cxx
src/Airports/Makefile.am
src/Airports/gnnode.cxx [new file with mode: 0644]
src/Airports/gnnode.hxx
src/Airports/groundnetwork.cxx
src/Airports/groundnetwork.hxx
src/Traffic/Schedule.cxx

index 411b236c69190173d3e3a4ad0424ad6ab4ca5c94..39c97f8622fd77598caf73e8cd970a7c65a36e99 100644 (file)
@@ -113,10 +113,6 @@ void FGAIAircraft::bind() {
     props->tie("controls/gear/gear-down",
                SGRawValueMethods<FGAIAircraft,bool>(*this,
                                                     &FGAIAircraft::_getGearDown));
-    props->tie("callsign",
-               SGRawValueMethods<FGAIAircraft,const char *>(*this,
-                                                    &FGAIAircraft::_getCallSign));
-    //props->setStringValue("callsign", callsign.c_str());
 }
 
 
@@ -124,7 +120,6 @@ void FGAIAircraft::unbind() {
     FGAIBase::unbind();
 
     props->untie("controls/gear/gear-down");
-    props->untie("callsign");
 }
 
 
@@ -325,10 +320,6 @@ bool FGAIAircraft::_getGearDown() const {
     return _performance->gearExtensible(this);
 }
 
-const char * FGAIAircraft::_getCallSign() const {
-    return callsign.c_str();
-}
-
 
 void FGAIAircraft::loadNextLeg() {
 
@@ -410,11 +401,6 @@ void FGAIAircraft::getGroundElev(double dt) {
 }
 
 
-void FGAIAircraft::setCallSign(const string& s) {
-    callsign = s;
-}
-
-
 void FGAIAircraft::doGroundAltitude() {
     if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
         altitude_ft = (tgt_altitude_ft + groundOffset);
index cf8e6babce1fd12164a83b32bf18df5011b3c3ed..2105a4a7310174ce783344d4f58153c80bdd6721 100644 (file)
@@ -61,8 +61,6 @@ public:
     void ClimbTo(double altitude);
     void TurnTo(double heading);
     
-    void setCallSign(const string& );
-
     void getGroundElev(double dt); //TODO these 3 really need to be public?
     void doGroundAltitude();
     void loadNextLeg  ();
@@ -137,9 +135,8 @@ private:
     bool holdPos;
 
     bool _getGearDown() const;
-    const char *_getCallSign() const;
+
     bool reachedWaypoint;
-    string callsign;             // The callsign of this tanker.
 
     PerformanceData* _performance; // the performance data for this aircraft
 };
index e375f606c917fb0f8defd9ff85b4d58406681806..28944390218b3edc59e51ae9b4447671bba3bdd5 100644 (file)
@@ -245,6 +245,10 @@ void FGAIBase::bind() {
         SGRawValueMethods<FGAIBase,double>(*this,
         &FGAIBase::_getCartPosZ,
         0));
+    props->tie("callsign",
+        SGRawValueMethods<FGAIBase,const char*>(*this,
+        &FGAIBase::_getCallsign,
+        0));
 
     props->tie("orientation/pitch-deg",   SGRawValuePointer<double>(&pitch));
     props->tie("orientation/roll-deg",    SGRawValuePointer<double>(&roll));
@@ -290,6 +294,7 @@ void FGAIBase::unbind() {
     props->untie("position/global-x");
     props->untie("position/global-y");
     props->untie("position/global-z");
+    props->untie("callsign");
 
     props->untie("orientation/pitch-deg");
     props->untie("orientation/roll-deg");
@@ -581,19 +586,23 @@ double FGAIBase::_getHeading() const {
     return hdg;
 }
 
-const char* FGAIBase::_getPath() {
+const char* FGAIBase::_getPath() const {
+    return model_path.c_str();
+}
+
+const char* FGAIBase::_getSMPath() const {
     return _path.c_str();
 }
 
-const char* FGAIBase::_getName() {
+const char* FGAIBase::_getName() const {
     return _name.c_str();
 }
 
-const char* FGAIBase::_getCallsign() {
+const char* FGAIBase::_getCallsign() const {
     return _callsign.c_str();
 }
 
-const char* FGAIBase::_getSubmodel() {
+const char* FGAIBase::_getSubmodel() const {
     return _submodel.c_str();
 }
 
@@ -621,7 +630,7 @@ void FGAIBase::CalculateMach() {
     // where:
     // a = speed of sound [ft/s]
     // g = specific heat ratio, which is usually equal to 1.4
-    // R = specific gas constant, which equals 1716 ft-lb/slug/°R
+    // R = specific gas constant, which equals 1716 ft-lb/slug/R
     a = sqrt ( 1.4 * 1716 * (T + 459.7));
 
     // calculate Mach number
index f802c9937f09f2ebcb74a9fac34e48c5c010cfae..d49336438bc664322725f08efd0d0f4a9d426d1c 100644 (file)
@@ -61,6 +61,7 @@ public:
     void setManager(FGAIManager* mgr, SGPropertyNode* p);
     void setPath( const char* model );
     void setSMPath( const string& p );
+    void setCallSign(const string& );
     void setSpeed( double speed_KTAS );
     void setAltitude( double altitude_ft );
     void setHeading( double heading );
@@ -225,11 +226,12 @@ public:
 
     SGPropertyNode* _getProps() const;
 
-    const char* _getPath();
-    const char* _getCallsign();
-    const char* _getTriggerNode();
-    const char* _getName();
-    const char* _getSubmodel();
+    const char* _getPath() const;
+    const char* _getSMPath() const;
+    const char* _getCallsign() const;
+    const char* _getTriggerNode() const;
+    const char* _getName() const;
+    const char* _getSubmodel() const;
 
 
     // These are used in the Mach number calculations
@@ -305,6 +307,11 @@ inline void FGAIBase::setLatitude ( double latitude ) {
     pos.setLatitudeDeg( latitude );
 }
 
+inline void FGAIBase::setCallSign(const string& s) {
+    _callsign = s;
+}
+
+
 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
 
 inline bool FGAIBase::getDie() { return delete_me; }
index 2d1887582eda1e42151cbd26e78b861d918d2445..362604be2aabac3514a8fa38dea4661da991d2ac 100644 (file)
@@ -192,8 +192,8 @@ FGAIFlightPlan::FGAIFlightPlan(const std::string& p,
        leg = 4;
       else if (timeDiff >= 2000)
        leg = 5;
-      
-      //cerr << "Set leg to : " << leg << endl;  
+
+      SG_LOG(SG_GENERAL, SG_INFO, "Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg);
       wpt_iterator = waypoints.begin();
       create(dep,arr, leg, alt, speed, lat, lon,
             firstLeg, radius, fltType, acType, airline);
index f9f39a5181c3d9e9fa2a27391c869653f0a58999..0af5ed1fa7385a7e68f4c31412500d97157ce6cb 100755 (executable)
@@ -75,9 +75,15 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
            }
        }
       //cerr << "1"<< endl;
-      SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2]));
-      double midlat = geoc.getLatitudeDeg();
-      double midlon = geoc.getLongitudeDeg();
+      //SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2]));
+
+      //double midlat = geoc.getLatitudeDeg();
+      //double midlon = geoc.getLongitudeDeg();
+
+      Point3D temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2]));
+      double midlat = temp.lat() * SG_RADIANS_TO_DEGREES;
+      double midlon = temp.lon() * SG_RADIANS_TO_DEGREES; 
+
 
       prevNode = tmpNode;
       tmpNode = globals->get_airwaynet()->findNearestNode(midlat, midlon);
index 717dc72afde736e4d5de6b665274f3e181a6ec78..b7b0f689cb8dc2e89118f1cc1257c676697beb79 100755 (executable)
@@ -48,7 +48,7 @@ bool FGAIMultiplayer::init(bool search_in_AI_path) {
     isTanker = false; // do this until this property is
                       // passed over the net
 
-    string str1 = mCallSign;
+    string str1 = _getCallsign();
     string str2 = "MOBIL";
 
     string::size_type loc1= str1.find( str2, 0 );
@@ -73,7 +73,7 @@ SGRawValueMethods<FGAIMultiplayer, type>(*this, &FGAIMultiplayer::get##name)
 SGRawValueMethods<FGAIMultiplayer, type>(*this, \
       &FGAIMultiplayer::get##name, &FGAIMultiplayer::set##name)
 
-    props->tie("callsign", AIMPROProp(const char *, CallSign));
+    //props->tie("callsign", AIMPROProp(const char *, CallSign));
 
     props->tie("controls/allow-extrapolation",
                AIMPRWProp(bool, AllowExtrapolation));
@@ -88,7 +88,7 @@ SGRawValueMethods<FGAIMultiplayer, type>(*this, \
 void FGAIMultiplayer::unbind() {
     FGAIBase::unbind();
 
-    props->untie("callsign");
+    //props->untie("callsign");
     props->untie("controls/allow-extrapolation");
     props->untie("controls/lag-adjust-system-speed");
     props->untie("refuel/contact");
index 596803a8d66c1c4157765f77fc80555c5a6fd971..6b30685aab218708b006ed9ec69e49cdf19d5ff4 100755 (executable)
@@ -40,11 +40,6 @@ public:
   void addMotionInfo(const FGExternalMotionData& motionInfo, long stamp);
   void setDoubleProperty(const std::string& prop, double val);
 
-  void setCallSign(const string& callSign)
-  { mCallSign = callSign; }
-  const char* getCallSign(void) const
-  { return mCallSign.c_str(); }
-
   long getLastTimestamp(void) const
   { return mLastTimestamp; }
 
@@ -77,8 +72,6 @@ private:
   typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
   PropertyMap mPropertyMap;
 
-  std::string mCallSign;
-
   double mTimeOffset;
   bool mTimeOffsetSet;
 
index c158c05f8f3fe875c79083457ee88a3f2831c5f8..7d065b8e10827259268d903d4a002b1cd2fa4fb8 100644 (file)
@@ -517,7 +517,7 @@ void FGSubmodelMgr::loadAI()
     sm_list_iterator end = sm_list.end();
 
     while (sm_list_itr != end) {
-        string path = (*sm_list_itr)->_getPath();
+        string path = (*sm_list_itr)->_getSMPath();
 
         if (path.empty()) {
             ++sm_list_itr;
index 7f067295adcaacf4dd9006892b316f41f6abd1fc..5cc6abe152199638f3510f7580d0b15679ec4429 100644 (file)
@@ -8,13 +8,13 @@ libAirports_a_SOURCES = \
        simple.cxx simple.hxx \
        runwayprefs.cxx runwayprefs.hxx \
        parking.cxx parking.hxx \
+       gnnode.cxx gnnode.hxx \
        groundnetwork.cxx groundnetwork.hxx \
        dynamics.cxx dynamics.hxx \
        trafficcontrol.cxx trafficcontrol.hxx \
        dynamicloader.cxx dynamicloader.hxx \
        runwayprefloader.cxx runwayprefloader.hxx \
-       xmlloader.cxx xmlloader.hxx \
-       gnnode.hxx 
+       xmlloader.cxx xmlloader.hxx 
 
 calc_loc_SOURCES = calc_loc.cxx
 calc_loc_LDADD = -lsgmath -lsgdebug -lsgmisc -lz $(base_LIBS)
diff --git a/src/Airports/gnnode.cxx b/src/Airports/gnnode.cxx
new file mode 100644 (file)
index 0000000..b3b34d9
--- /dev/null
@@ -0,0 +1,55 @@
+#include "gnnode.hxx"
+#include "groundnetwork.hxx"
+
+#include <algorithm>
+SG_USING_STD(sort);
+
+/*****************************************************************************
+ * Helper function for parsing position string
+ ****************************************************************************/
+double processPosition(const string &pos)
+{
+  string prefix;
+  string subs;
+  string degree;
+  string decimal;
+  int sign = 1;
+  double value;
+  subs = pos;
+  prefix= subs.substr(0,1);
+  if (prefix == string("S") || (prefix == string("W")))
+    sign = -1;
+  subs    = subs.substr(1, subs.length());
+  degree  = subs.substr(0, subs.find(" ",0));
+  decimal = subs.substr(subs.find(" ",0), subs.length());
+  
+             
+  //cerr << sign << " "<< degree << " " << decimal << endl;
+  value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
+  //cerr << value <<endl;
+  //exit(1);
+  return value;
+}
+
+bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b) {
+  return a->hasSmallerHeadingDiff(*b);
+}
+
+bool sortByLength(FGTaxiSegment *a, FGTaxiSegment *b) {
+  return a->getLength() > b->getLength();
+}
+
+/**************************************************************************
+ * FGTaxiNode
+ *************************************************************************/
+FGTaxiNode::FGTaxiNode()
+{
+}
+
+void FGTaxiNode::sortEndSegments(bool byLength)
+{
+  if (byLength)
+    sort(next.begin(), next.end(), sortByLength);
+  else
+    sort(next.begin(), next.end(), sortByHeadingDiff);
+}
index 703f1e46d221a6eb7096b0ddcce5d9bc952cb8c6..54dd662841952afb6736758293ed97d37cc95628 100644 (file)
@@ -27,6 +27,8 @@ class FGTaxiSegment;
 typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
 typedef FGTaxiSegmentVector::iterator FGTaxiSegmentVectorIterator;
 
+bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b);
+bool sortByLength     (FGTaxiSegment *a, FGTaxiSegment *b);
 double processPosition(const string& pos);
 
 class FGTaxiNode 
index 397671cbb167c99a8061dcf5b39fd939b7f607ea..9e26374aa52903c069eb10c426f2d0d0308f8f22 100644 (file)
 
 #include "groundnetwork.hxx"
 
-SG_USING_STD(sort);
-
-/*****************************************************************************
- * Helper function for parsing position string
- ****************************************************************************/
-double processPosition(const string &pos)
-{
-  string prefix;
-  string subs;
-  string degree;
-  string decimal;
-  int sign = 1;
-  double value;
-  subs = pos;
-  prefix= subs.substr(0,1);
-  if (prefix == string("S") || (prefix == string("W")))
-    sign = -1;
-  subs    = subs.substr(1, subs.length());
-  degree  = subs.substr(0, subs.find(" ",0));
-  decimal = subs.substr(subs.find(" ",0), subs.length());
-  
-             
-  //cerr << sign << " "<< degree << " " << decimal << endl;
-  value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
-  //cerr << value <<endl;
-  //exit(1);
-  return value;
-}
-
-/**************************************************************************
- * FGTaxiNode
- *************************************************************************/
-FGTaxiNode::FGTaxiNode()
-{
-}
-
-void FGTaxiNode::sortEndSegments(bool byLength)
-{
-  if (byLength)
-    sort(next.begin(), next.end(), sortByLength);
-  else
-    sort(next.begin(), next.end(), sortByHeadingDiff);
-}
-
-
-bool compare_nodes(FGTaxiNode *a, FGTaxiNode *b) {
-return (*a) < (*b);
-}
-
 /***************************************************************************
  * FGTaxiSegment
  **************************************************************************/
@@ -159,17 +110,7 @@ void FGTaxiSegment::setCourseDiff(double crse)
     headingDiff = fabs(headingDiff - 360);
 }
 
-bool compare_segments(FGTaxiSegment *a, FGTaxiSegment *b) {
-return (*a) < (*b);
-}
-
-bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b) {
-  return a->hasSmallerHeadingDiff(*b);
-}
 
-bool sortByLength(FGTaxiSegment *a, FGTaxiSegment *b) {
-  return a->getLength() > b->getLength();
-}
 /***************************************************************************
  * FGTaxiRoute
  **************************************************************************/
@@ -249,6 +190,13 @@ void FGTaxiRoute::rewind(int route)
 /***************************************************************************
  * FGGroundNetwork()
  **************************************************************************/
+bool compare_nodes(FGTaxiNode *a, FGTaxiNode *b) {
+return (*a) < (*b);
+}
+
+bool compare_segments(FGTaxiSegment *a, FGTaxiSegment *b) {
+return (*a) < (*b);
+}
 
 FGGroundNetwork::FGGroundNetwork()
 {
index b9370fa21d788beaab92d6ed6fcfb83cfbf6660e..3ed63e8c9b4b47118a34bf7e6be3b28051cdfb45 100644 (file)
@@ -126,6 +126,26 @@ public:
     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); 
@@ -140,10 +160,6 @@ public:
 typedef vector<FGTaxiRoute> TaxiRouteVector;
 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
 
-bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b);
-bool sortByLength     (FGTaxiSegment *a, FGTaxiSegment *b);
-
-
 /**************************************************************************************
  * class FGGroundNetWork
  *************************************************************************************/
index 35a1e44c92b81a10d424f07b10ee015498268d44..fcb27479aedb352a227322146091a37e2d59b263 100644 (file)
@@ -315,9 +315,14 @@ bool FGAISchedule::update(time_t now)
          
          if (now > (*i)->getDepartureTime())
            {
-              SGGeoc geoc = SGGeoc::fromCart(newPos);
-             lat = geoc.getLatitudeDeg();
-             lon = geoc.getLongitudeDeg(); 
+              //SGGeoc geoc = SGGeoc::fromCart(newPos);
+             //lat = geoc.getLatitudeDeg();
+             //lon = geoc.getLongitudeDeg(); 
+
+              Point3D temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2]));
+             lat = temp.lat() * SG_RADIANS_TO_DEGREES;
+             lon = temp.lon() * SG_RADIANS_TO_DEGREES; 
+
            }
          else
            {