]> git.mxchange.org Git - flightgear.git/blob - src/Airports/gnnode.cxx
Several Bugfixes:
[flightgear.git] / src / Airports / gnnode.cxx
1 #include "gnnode.hxx"
2 #include "groundnetwork.hxx"
3
4 #include <iostream>
5 #include <algorithm>
6
7 #include <osg/Geode>
8 #include <Main/globals.hxx>
9 #include <Scenery/scenery.hxx>
10
11 using std::sort;
12
13 /*****************************************************************************
14  * Helper function for parsing position string
15  ****************************************************************************/
16 double processPosition(const string &pos)
17 {
18   string prefix;
19   string subs;
20   string degree;
21   string decimal;
22   int sign = 1;
23   double value;
24   subs = pos;
25   prefix= subs.substr(0,1);
26   if (prefix == string("S") || (prefix == string("W")))
27     sign = -1;
28   subs    = subs.substr(1, subs.length());
29   degree  = subs.substr(0, subs.find(" ",0));
30   decimal = subs.substr(subs.find(" ",0), subs.length());
31   
32               
33   //cerr << sign << " "<< degree << " " << decimal << endl;
34   value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
35   //cerr << value <<endl;
36   //exit(1);
37   return value;
38 }
39
40 //bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b) {
41 //  return a->hasSmallerHeadingDiff(*b);
42 //}
43
44 bool sortByLength(FGTaxiSegment *a, FGTaxiSegment *b) {
45   return a->getLength() > b->getLength();
46 }
47
48 /**************************************************************************
49  * FGTaxiNode
50  *************************************************************************/
51 void FGTaxiNode::setElevation(double val)
52 {
53     geod.setElevationM(val);
54 }
55
56 void FGTaxiNode::setLatitude (double val)
57 {
58   geod.setLatitudeDeg(val);
59 }
60
61 void FGTaxiNode::setLongitude(double val)
62 {
63   geod.setLongitudeDeg(val);
64 }
65
66 void FGTaxiNode::setLatitude (const string& val)
67 {
68   geod.setLatitudeDeg(processPosition(val));
69 }
70
71 void FGTaxiNode::setLongitude(const string& val)
72 {
73   geod.setLongitudeDeg(processPosition(val));
74 }
75   
76 double FGTaxiNode::getElevationFt(double refelev)
77 {
78     double elevF = geod.getElevationFt();
79     double elevationEnd = 0;
80     if ((elevF == 0) || (elevF == refelev)) {
81         SGGeod center2 = geod;
82         FGScenery * local_scenery = globals->get_scenery();
83         center2.setElevationM(SG_MAX_ELEVATION_M);
84         if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
85             geod.setElevationM(elevationEnd);
86         }
87     }
88     //cerr << "Returning elevation : " << geod.getElevationM() << ". Ref elev (feet) = " << refelev << endl;
89     return geod.getElevationFt();
90 }
91
92 double FGTaxiNode::getElevationM(double refelev)
93 {
94     double refelevFt = refelev * SG_METER_TO_FEET;
95     double retval = getElevationFt(refelevFt);
96     //cerr << "Returning elevation : " << geod.getElevationM() << ". Ref elev (meters) = " << refelev << endl;
97     return geod.getElevationM();
98 }