]> git.mxchange.org Git - flightgear.git/blob - src/Airports/sidstar.cxx
httpd: provide more airport information in geojson
[flightgear.git] / src / Airports / sidstar.cxx
1 // sidstar.cxx - Code to manage departure / arrival procedures
2 // Written by Durk Talsma, started March 2009.
3 //
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19 // $Id$
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <iostream>
26 #include <stdlib.h>
27
28 #include <simgear/props/props.hxx>
29 #include <simgear/props/props_io.hxx>
30
31 #include <AIModel/AIFlightPlan.hxx>
32 #include <Airports/airport.hxx>
33
34 #include "sidstar.hxx"
35
36 using std::cerr;
37 using std::endl;
38 using std::string;
39
40 FGSidStar::FGSidStar(FGAirport *ap) {
41      id = ap->getId();
42      initialized = false;
43 }
44
45
46 FGSidStar::FGSidStar(const FGSidStar &other) {
47      cerr << "TODO" << endl;
48 }
49
50 void FGSidStar::load(SGPath filename) {
51   SGPropertyNode root;
52   string runway;
53   string name;
54   try {
55       readProperties(filename.str(), &root);
56   } catch (const sg_exception &) {
57       SG_LOG(SG_GENERAL, SG_ALERT,
58        "Error reading AI flight plan: " << filename.str());
59        // cout << path.str() << endl;
60      return;
61   }
62
63   SGPropertyNode * node = root.getNode("SIDS");
64   FGAIFlightPlan *fp;
65   for (int i = 0; i < node->nChildren(); i++) { 
66      fp = new FGAIFlightPlan;
67      SGPropertyNode * fpl_node = node->getChild(i);
68      name   =  fpl_node->getStringValue("name", "END");
69      runway =  fpl_node->getStringValue("runway", "27");
70      //cerr << "Runway = " << runway << endl;
71      fp->setName(name);
72      SGPropertyNode * wpts_node = fpl_node->getNode("wpts");
73      for (int j = 0; j < wpts_node->nChildren(); j++) { 
74           FGAIWaypoint* wpt = new FGAIWaypoint;
75           SGPropertyNode * wpt_node = wpts_node->getChild(j);
76           //cerr << "Reading waypoint " << j << wpt_node->getStringValue("name", "END") << endl;
77           wpt->setName        (wpt_node->getStringValue("name", "END"));
78           wpt->setLatitude    (wpt_node->getDoubleValue("lat", 0));
79           wpt->setLongitude   (wpt_node->getDoubleValue("lon", 0));
80           wpt->setAltitude    (wpt_node->getDoubleValue("alt", 0));
81           wpt->setSpeed       (wpt_node->getDoubleValue("ktas", 0));
82           wpt->setCrossat     (wpt_node->getDoubleValue("crossat", -10000));
83           wpt->setGear_down   (wpt_node->getBoolValue("gear-down", false));
84           wpt->setFlaps_down  (wpt_node->getBoolValue("flaps-down", false));
85           wpt->setOn_ground   (wpt_node->getBoolValue("on-ground", false));
86           wpt->setTime_sec    (wpt_node->getDoubleValue("time-sec", 0));
87           wpt->setTime        (wpt_node->getStringValue("time", ""));
88
89           if (wpt->contains("END")) 
90                 wpt->setFinished(true);
91           else 
92                 wpt->setFinished(false);
93
94           // 
95           fp->addWaypoint( wpt );
96      }
97      data[runway].push_back(fp);
98      //cerr << "Runway = " << runway << endl;
99    }
100
101
102   //wpt_iterator = waypoints.begin();
103   //cout << waypoints.size() << " waypoints read." << endl;
104 }
105
106
107 FGAIFlightPlan *FGSidStar::getBest(string activeRunway, double heading)
108 {
109     //cerr << "Getting best procedure for " << activeRunway << endl;
110     for (FlightPlanVecIterator i = data[activeRunway].begin(); i != data[activeRunway].end(); i++) {
111         //cerr << (*i)->getName() << endl;
112     }
113     int size = data[activeRunway].size();
114     //cerr << "size is " << size << endl;
115     if (size) {
116         return data[activeRunway][(rand() % size)];
117      } else {
118         return 0;
119     }
120 }