_last_longitude_deg(0),
_last_latitude_deg(0),
_last_altitude_m(0),
- _last_speed_kts(0)
-{
- int i;
- for ( i = 0; i < node->nChildren(); ++i ) {
- SGPropertyNode *child = node->getChild(i);
- string cname = child->getName();
- string cval = child->getStringValue();
- if ( cname == "name" ) {
- name = cval;
- } else if ( cname == "number" ) {
- num = child->getIntValue();
- } else {
- SG_LOG( SG_INSTR, SG_WARN, "Error in gps config logic" );
- if ( name.length() ) {
- SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
- }
- }
- }
-}
-
-GPS::GPS ()
- : _last_valid(false),
- _last_longitude_deg(0),
- _last_latitude_deg(0),
- _last_altitude_m(0),
- _last_speed_kts(0)
+ _last_speed_kts(0),
+ _wp0_latitude_deg(0),
+ _wp0_longitude_deg(0),
+ _wp0_altitude_m(0),
+ _wp1_latitude_deg(0),
+ _wp1_longitude_deg(0),
+ _wp1_altitude_m(0),
+ _alt_dist_ratio(0),
+ _distance_m(0),
+ _course_deg(0),
+ _name(node->getStringValue("name", "gps")),
+ _num(node->getIntValue("number", 0))
{
}
route->clear();
string branch;
- branch = "/instrumentation/" + name;
+ branch = "/instrumentation/" + _name;
- SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+ SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
_longitude_node = fgGetNode("/position/longitude-deg", true);
_latitude_node = fgGetNode("/position/latitude-deg", true);
_wp0_longitude_node = wp0_node->getChild("longitude-deg", 0, true);
_wp0_latitude_node = wp0_node->getChild("latitude-deg", 0, true);
- _wp0_altitude_node = wp0_node->getChild("altitude-deg", 0, true);
+ _wp0_altitude_node = wp0_node->getChild("altitude-ft", 0, true);
_wp0_ID_node = wp0_node->getChild("ID", 0, true);
_wp0_name_node = wp0_node->getChild("name", 0, true);
_wp0_course_node = wp0_node->getChild("desired-course-deg", 0, true);
_wp1_longitude_node = wp1_node->getChild("longitude-deg", 0, true);
_wp1_latitude_node = wp1_node->getChild("latitude-deg", 0, true);
- _wp1_altitude_node = wp1_node->getChild("altitude-deg", 0, true);
+ _wp1_altitude_node = wp1_node->getChild("altitude-ft", 0, true);
_wp1_ID_node = wp1_node->getChild("ID", 0, true);
_wp1_name_node = wp1_node->getChild("name", 0, true);
_wp1_course_node = wp1_node->getChild("desired-course-deg", 0, true);
_true_track_node =
node->getChild("indicated-track-true-deg", 0, true);
_magnetic_track_node =
- node->getChild("indicated-track_magnetic-deg", 0, true);
+ node->getChild("indicated-track-magnetic-deg", 0, true);
_speed_node =
node->getChild("indicated-ground-speed-kt", 0, true);
_odometer_node =
// If the get-nearest-airport-node is true.
// Get the nearest airport, and set it as waypoint 1.
if (_get_nearest_airport_node->getBoolValue()) {
- FGAirport a;
- //cout << "Airport found" << endl;
- a = globals->get_airports()->search(longitude_deg, latitude_deg, false);
- _wp1_ID_node->setStringValue(a.id.c_str());
- wp1_longitude_deg = a.longitude;
- wp1_latitude_deg = a.latitude;
- _wp1_name_node->setStringValue(a.name.c_str());
- _get_nearest_airport_node->setBoolValue(false);
- _last_wp1_ID = wp1_ID = a.id.c_str();
+ const FGAirport* a = globals->get_airports()->search(longitude_deg, latitude_deg, false);
+ if(a) {
+ _wp1_ID_node->setStringValue(a->getId().c_str());
+ wp1_longitude_deg = a->getLongitude();
+ wp1_latitude_deg = a->getLatitude();
+ _wp1_name_node->setStringValue(a->getName().c_str());
+ _get_nearest_airport_node->setBoolValue(false);
+ _last_wp1_ID = wp1_ID = a->getId().c_str();
+ }
}
// If the waypoint 0 ID has changed, try to find the new ID
string waypont_type =
_wp0_waypoint_type_node->getStringValue();
if (waypont_type == "airport") {
- FGAirport a;
- a = globals->get_airports()->search( wp0_ID );
- if ( a.id == wp0_ID ) {
- //cout << "Airport found" << endl;
- wp0_longitude_deg = a.longitude;
- wp0_latitude_deg = a.latitude;
- _wp0_name_node->setStringValue(a.name.c_str());
+ const FGAirport* a = globals->get_airports()->search( wp0_ID );
+ if ( a ) {
+ wp0_longitude_deg = a->getLongitude();
+ wp0_latitude_deg = a->getLatitude();
+ _wp0_name_node->setStringValue(a->getName().c_str());
}
}
else if (waypont_type == "nav") {
string waypont_type =
_wp1_waypoint_type_node->getStringValue();
if (waypont_type == "airport") {
- FGAirport a;
- a = globals->get_airports()->search( wp1_ID );
- if ( a.id == wp1_ID ) {
- //cout << "Airport found" << endl;
- wp1_longitude_deg = a.longitude;
- wp1_latitude_deg = a.latitude;
- _wp1_name_node->setStringValue(a.name.c_str());
+ const FGAirport* a = globals->get_airports()->search( wp1_ID );
+ if ( a ) {
+ wp1_longitude_deg = a->getLongitude();
+ wp1_latitude_deg = a->getLatitude();
+ _wp1_name_node->setStringValue(a->getName().c_str());
}
}
else if (waypont_type == "nav") {
popWp->setBoolValue(false);
route->delete_first();
+ _route->removeChild("Waypoint", 0, false);
}
} else {