From: James Turner Date: Fri, 1 Jul 2016 09:54:29 +0000 (-0500) Subject: Further SGPath encoding fixes. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9db7d3ceed20474ad39b2252fd9c13c15f7c8d35;p=flightgear.git Further SGPath encoding fixes. --- diff --git a/src/Input/fgjs.cxx b/src/Input/fgjs.cxx index 8f7b8b6ae..bd84a17b0 100644 --- a/src/Input/fgjs.cxx +++ b/src/Input/fgjs.cxx @@ -301,7 +301,7 @@ static string fgScanForOption( const string& option ) { config.append( ".fgfsrc" ); config.concat( "." ); config.concat( hostname ); - arg = fgScanForOption( option, config.str() ); + arg = fgScanForOption( option, config ); } } #endif @@ -346,10 +346,10 @@ string getFGRoot ( int argc, char **argv ) { root = "../data"; #elif defined( _WIN32 ) root = "..\\data"; -#elif defined(__APPLE__) +#elif defined(__APPLE__) /* - The following code looks for the base package inside the application - bundle, in the standard Contents/Resources location. + The following code looks for the base package inside the application + bundle, in the standard Contents/Resources location. */ CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); diff --git a/src/Instrumentation/testgps.cxx b/src/Instrumentation/testgps.cxx index a35012f4b..6259d6991 100644 --- a/src/Instrumentation/testgps.cxx +++ b/src/Instrumentation/testgps.cxx @@ -2,6 +2,7 @@ #include #include +#include #include #include
@@ -32,23 +33,23 @@ void testSetPosition(const SGGeod& aPos) void printScratch(SGPropertyNode* scratch) { if (!scratch->getBoolValue("valid", false)) { - SG_LOG(SG_GENERAL, SG_ALERT, "Scratch is invalid."); + SG_LOG(SG_GENERAL, SG_ALERT, "Scratch is invalid."); return; } SG_LOG(SG_GENERAL, SG_ALERT, "Scratch:" << scratch->getStringValue("ident") << "/" << scratch->getStringValue("name")); - + SG_LOG(SG_GENERAL, SG_ALERT, "\t" << scratch->getDoubleValue("longitude-deg") << " " << scratch->getDoubleValue("latitude-deg") << " @ " << scratch->getDoubleValue("altitude-ft")); - + SG_LOG(SG_GENERAL, SG_ALERT, "\t" << scratch->getDoubleValue("true-bearing-deg") << " (" << scratch->getDoubleValue("mag-bearing-deg") << " magnetic) " << scratch->getDoubleValue("distance-nm")); - + if (scratch->hasChild("result-index")) { SG_LOG(SG_GENERAL, SG_ALERT, "\tresult-index:" << scratch->getIntValue("result-index")); - } - + } + if (scratch->hasChild("route-index")) { SG_LOG(SG_GENERAL, SG_ALERT, "\troute-index:" << scratch->getIntValue("route-index")); } @@ -81,133 +82,133 @@ int main(int argc, char* argv[]) try{ globals = new FGGlobals; - + fgInitFGRoot(argc, argv); if (!fgInitConfig(argc, argv) ) { SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed" ); exit(-1); } - - + + fgInitNav(); fgSetDouble("/environment/magnetic-variation-deg", 0.0); - + Airway::load(); - + SG_LOG(SG_GENERAL, SG_ALERT, "hello world!"); - + const FGAirport* egph = fgFindAirportID("EGPH"); SG_LOG(SG_GENERAL, SG_ALERT, "egph: cart location:" << egph->cart()); - + FGAirport::AirportFilter af; FGPositioned::List l = FGPositioned::findClosestN(egph->geod(), 20, 2000.0, &af); for (unsigned int i=0; iident() << "/" << l[i]->name()); } - + //l = FGPositioned::findWithinRange(egph->geod(), 500.0, &af); //for (unsigned int i=0; iident() << "/" << l[i]->name()); //} - + FGRouteMgr* rm = new FGRouteMgr; globals->add_subsystem( "route-manager", rm ); - + // FGEnvironmentMgr* envMgr = new FGEnvironmentMgr; // globals->add_subsystem("environment", envMgr); // envMgr->init(); - + fgSetBool("/sim/realism/simple-gps", true); - + // _realismSimpleGps - + SGPropertyNode* nd = fgGetNode("/instrumentation/gps", true); GPS* gps = new GPS(nd); globals->add_subsystem("gps", gps); const FGAirport* egph = fgFindAirportID("EGPH"); testSetPosition(egph->geod()); - + // startup the route manager rm->init(); - + nd->setBoolValue("serviceable", true); fgSetBool("/systems/electrical/outputs/gps", true); - + gps->init(); SGPropertyNode* scratch = nd->getChild("scratch", 0, true); SGPropertyNode* wp = nd->getChild("wp", 0, true); SGPropertyNode* wp1 = wp->getChild("wp", 1, true); - + // update a few times gps->update(0.05); gps->update(0.05); gps->update(0.05); - + scratch->setStringValue("query", "TL"); scratch->setStringValue("type", "Vor"); scratch->setBoolValue("exact", false); nd->setStringValue("command", "search"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + // alphanumeric sort, partial matching nd->setDoubleValue("config/min-runway-length-ft", 5000.0); scratch->setBoolValue("exact", false); scratch->setBoolValue("order-by-distance", false); scratch->setStringValue("query", "KS"); scratch->setStringValue("type", "apt"); - + nd->setStringValue("command", "search"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + // alphanumeric sort, explicit matching scratch->setBoolValue("exact", true); scratch->setBoolValue("order-by-distance", true); scratch->setStringValue("type", "vor"); scratch->setStringValue("query", "DCS"); - + nd->setStringValue("command", "search"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + // search on totally missing scratch->setBoolValue("exact", true); scratch->setBoolValue("order-by-distance", true); scratch->setStringValue("query", "FOFOFOFOF"); nd->setStringValue("command", "search"); printScratch(scratch); - + // nearest scratch->setStringValue("type", "apt"); scratch->setIntValue("max-results", 10); nd->setStringValue("command", "nearest"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + // direct to nd->setStringValue("command", "direct"); SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t" - << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg") + << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg") << " " << wp1->getDoubleValue("latitude-deg")); // OBS mode @@ -215,32 +216,32 @@ try{ scratch->setBoolValue("order-by-distance", true); nd->setStringValue("command", "search"); printScratch(scratch); - + nd->setStringValue("command", "obs"); SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t" - << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg") + << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg") << " " << wp1->getDoubleValue("latitude-deg")); - + // load route waypoints createDummyRoute(rm); scratch->setIntValue("route-index", 5); nd->setStringValue("command", "load-route-wpt"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + nd->setStringValue("command", "next"); printScratch(scratch); - + scratch->setIntValue("route-index", 2); nd->setStringValue("command", "load-route-wpt"); nd->setStringValue("command", "direct"); SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t" - << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg") + << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg") << " " << wp1->getDoubleValue("latitude-deg")); - + // route editing SGGeod pos = egph->geod(); scratch->setStringValue("ident", "FOOBAR"); @@ -248,19 +249,19 @@ try{ scratch->setDoubleValue("latitude-deg", pos.getLatitudeDeg()); nd->setStringValue("command", "define-user-wpt"); printScratch(scratch); - + // airways FGPositioned::TypeFilter vorFilt(FGPositioned::VOR); FGPositionedRef tla = FGPositioned::findClosestWithIdent("TLA", pos, &vorFilt); - FGPositionedRef big = FGPositioned::findClosestWithIdent("BIG", pos, &vorFilt); + FGPositionedRef big = FGPositioned::findClosestWithIdent("BIG", pos, &vorFilt); FGPositionedRef pol = FGPositioned::findClosestWithIdent("POL", pos, &vorFilt); - + const FGAirport* eddm = fgFindAirportID("EDDM"); - FGPositionedRef mun = FGPositioned::findClosestWithIdent("MUN", + FGPositionedRef mun = FGPositioned::findClosestWithIdent("MUN", eddm->geod(), &vorFilt); - + const FGAirport* ksfo = fgFindAirportID("KSFO"); - FGPositionedRef sfo = FGPositioned::findClosestWithIdent("SFO", + FGPositionedRef sfo = FGPositioned::findClosestWithIdent("SFO", ksfo->geod(), &vorFilt); @@ -269,14 +270,14 @@ try{ WayptRef awy3 = new NavaidWaypoint(pol, NULL); WayptRef awy4 = new NavaidWaypoint(mun, NULL); WayptRef awy5 = new NavaidWaypoint(sfo, NULL); - + WayptRef awy6 = new NavaidWaypoint( (FGPositioned*) fgFindAirportID("KJFK"), NULL); - + SGPath p("/Users/jmt/Desktop/airways.kml"); - std::fstream f; - f.open(p.str().c_str(), fstream::out | fstream::trunc); - + sg_ofstream f; + f.open(p, fstream::out | fstream::trunc); + // pre-amble f << "\n" "\n" @@ -285,67 +286,67 @@ try{ WayptVec route; Airway::highLevel()->route(awy1, awy3, route); Route::dumpRouteToLineString("egph-egcc", route, f); - + Airway::lowLevel()->route(awy1, awy2, route); Route::dumpRouteToLineString("egph-big", route, f); - + Airway::lowLevel()->route(awy2, awy4, route); Route::dumpRouteToLineString("big-mun", route, f); - + Airway::highLevel()->route(awy4, awy5, route); Route::dumpRouteToLineString("mun-sfo", route, f); - + Airway::lowLevel()->route(awy5, awy6, route); Route::dumpRouteToLineString("sfo-jfk", route, f); - + // post-amble - f << "\n" + f << "\n" "" << endl; f.close(); - + // procedures SGPath op("/Users/jmt/Desktop/procedures.kml"); - f.open(op.str().c_str(), fstream::out | fstream::trunc); - + f.open(op, fstream::out | fstream::trunc); + FGAirport* eham = (FGAirport*) fgFindAirportID("EHAM"); FGPositioned::TypeFilter fixFilt(FGPositioned::FIX); - + WayptVec approach; - FGPositionedRef redfa = FGPositioned::findClosestWithIdent("REDFA", + FGPositionedRef redfa = FGPositioned::findClosestWithIdent("REDFA", eham->geod(), &fixFilt); - bool ok = eham->buildApproach(new NavaidWaypoint(redfa, NULL), + bool ok = eham->buildApproach(new NavaidWaypoint(redfa, NULL), eham->getRunwayByIdent("18R"), approach); if (!ok ) { SG_LOG(SG_GENERAL, SG_INFO, "failed to build approach"); } - - - FGAirport* egll = (FGAirport*) fgFindAirportID("EGLL"); + + + FGAirport* egll = (FGAirport*) fgFindAirportID("EGLL"); WayptVec approach2; - ok = egll->buildApproach(new NavaidWaypoint(big, NULL), + ok = egll->buildApproach(new NavaidWaypoint(big, NULL), egll->getRunwayByIdent("27R"), approach2); if (!ok ) { SG_LOG(SG_GENERAL, SG_INFO, "failed to build approach"); } - + // pre-amble f << "\n" "\n" "\n"; - + Route::dumpRouteToLineString("REDFA 18R", approach, f); Route::dumpRouteToLineString("EGLL 27R", approach2, f); - + // post-amble - f << "\n" + f << "\n" "" << endl; - f.close(); - - + f.close(); + + return EXIT_SUCCESS; - + } catch (sg_exception& ex) { SG_LOG(SG_GENERAL, SG_ALERT, "exception:" << ex.getFormattedMessage()); } diff --git a/src/Navaids/awynet.cxx b/src/Navaids/awynet.cxx index e1476615a..a3760e217 100644 --- a/src/Navaids/awynet.cxx +++ b/src/Navaids/awynet.cxx @@ -205,7 +205,7 @@ void FGAirwayNetwork::load(const SGPath& path) int airwayIndex = 0; FGNode *n; - sg_gzifstream in( path.str() ); + sg_gzifstream in( path ); if ( !in.is_open() ) { SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() ); exit(-1); @@ -319,7 +319,7 @@ int FGAirwayNetwork::findNearestNode(const SGGeod& aPos) double minDist = HUGE_VAL; int index = -1; SGVec3d cart = SGVec3d::fromGeod(aPos); - + //cerr << "Lat " << lat << " lon " << lon << endl; for (FGNodeVectorIterator itr = nodes.begin(); @@ -465,4 +465,3 @@ void FGAirwayNetwork::trace(FGNode *currNode, int end, int depth, double distanc totalDistance -= distance; return; } - diff --git a/src/Network/ATC-Inputs.cxx b/src/Network/ATC-Inputs.cxx index 0e34f1a52..9e67e8b64 100644 --- a/src/Network/ATC-Inputs.cxx +++ b/src/Network/ATC-Inputs.cxx @@ -117,18 +117,13 @@ static void ATCReadSwitches( int fd, unsigned char *switch_bytes ) { void FGATCInput::init_config() { #if defined( unix ) || defined( __CYGWIN__ ) - if ( config.str()[0] != '/' ) { + if ( !config.isAbsolute() ) { // not an absolute path, prepend the standard location - SGPath tmp; - char *envp = ::getenv( "HOME" ); - if ( envp != NULL ) { - tmp = envp; - tmp.append( ".atcflightsim" ); - tmp.append( config.str() ); - config = tmp; - } + SGPath tmp = SGPath::home(); + tmp.append( ".atcflightsim" ); + tmp.append( config.utf8Str() ); } - readProperties( config.str(), globals->get_props() ); + readProperties( config, globals->get_props() ); #endif } @@ -239,7 +234,7 @@ static double scale( int center, int deadband, int min, int max, int value ) { result = (value - (center - deadband)) / range; } else if ( value >= (center + deadband) ) { range = max - (center + deadband); - result = (value - (center + deadband)) / range; + result = (value - (center + deadband)) / range; } else { result = 0.0; } @@ -279,7 +274,7 @@ static double clamp( double min, double max, double value ) { // cout << result << endl; - return result; + return result; } @@ -669,7 +664,7 @@ static void update_switch_matrix( switches = switches >> 1; } } -} +} bool FGATCInput::do_switches() { // Read the raw data @@ -873,7 +868,7 @@ bool FGATCInput::do_switches() { ///////////////////////////////////////////////////////////////////// -// Read radio switches +// Read radio switches ///////////////////////////////////////////////////////////////////// bool FGATCInput::do_radio_switches() { @@ -976,7 +971,7 @@ bool FGATCInput::process() { do_analog_in(); do_switches(); do_radio_switches(); - + return true; } diff --git a/src/Network/ATC-Main.cxx b/src/Network/ATC-Main.cxx index 97e582590..26adde7d3 100644 --- a/src/Network/ATC-Main.cxx +++ b/src/Network/ATC-Main.cxx @@ -94,20 +94,17 @@ static int fgATCMainRelease( int fd ) { void FGATCMain::init_config() { #if defined( unix ) || defined( __CYGWIN__ ) // Next check home directory for .fgfsrc.hostname file - char *envp = ::getenv( "HOME" ); - if ( envp != NULL ) { - SGPath atcsim_config( envp ); - atcsim_config.append( ".fgfs-atc610x.xml" ); - try { - SG_LOG(SG_NETWORK, SG_ALERT, - "Warning: loading deprecated config file: " << - atcsim_config.str() ); - readProperties( atcsim_config.str(), globals->get_props() ); - } catch (const sg_exception &e) { - // fail silently, this is an old style config file I want to continue - // to support if it exists. - } - } + SGPath atcsim_config = SGPath::home(); + atcsim_config.append( ".fgfs-atc610x.xml" ); + try { + SG_LOG(SG_NETWORK, SG_ALERT, + "Warning: loading deprecated config file: " << atcsim_config); + readProperties( atcsim_config, globals->get_props() ); + } catch (const sg_exception &e) { + // fail silently, this is an old style config file I want to continue + // to support if it exists. + } + #endif } @@ -115,7 +112,7 @@ void FGATCMain::init_config() { // Open and initialize ATC hardware bool FGATCMain::open() { if ( is_enabled() ) { - SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " + SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " << "is already in use, ignoring" ); return false; } diff --git a/src/Network/ATC-Outputs.cxx b/src/Network/ATC-Outputs.cxx index 9fa1046a1..2971ab1fc 100644 --- a/src/Network/ATC-Outputs.cxx +++ b/src/Network/ATC-Outputs.cxx @@ -229,18 +229,14 @@ void ATCSetLamp( int fd, int channel, bool value ) { void FGATCOutput::init_config() { #if defined( unix ) || defined( __CYGWIN__ ) - if ( config.str()[0] != '/' ) { - // not an absolute path, prepend the standard location - SGPath tmp; - char *envp = ::getenv( "HOME" ); - if ( envp != NULL ) { - tmp = envp; - tmp.append( ".atcflightsim" ); - tmp.append( config.str() ); - config = tmp; - } + if (!config.isAbsolute()) { + SGPath tmp = SGPath::home(); + tmp.append( ".atcflightsim" ); + tmp.append( config.utf8Str() ); + config = tmp; } - readProperties( config.str(), globals->get_props() ); + + readProperties( config, globals->get_props() ); #endif } @@ -547,7 +543,7 @@ bool FGATCOutput::do_lamps() { ///////////////////////////////////////////////////////////////////// -// Update the radio display +// Update the radio display ///////////////////////////////////////////////////////////////////// @@ -574,7 +570,7 @@ static bool navcom2_has_power() { static bool dme_has_power() { static SGPropertyNode *dme_bus_power = fgGetNode( "/systems/electrical/outputs/dme", true ); - + return (dme_bus_power->getDoubleValue() > 1.0); } @@ -680,7 +676,7 @@ bool FGATCOutput::do_radio_display() { } radio_display_data[0] = digits[1] << 4 | digits[2]; radio_display_data[1] = 0xf0 | digits[0]; - + // DME knots float knots = dme_kt->getFloatValue(); if ( knots > 999 ) { @@ -956,7 +952,7 @@ bool FGATCOutput::do_radio_display() { radio_display_data[34] = 0xff; radio_display_data[35] = 0xff; } - + // Transponder code and flight level if ( xpdr_has_power() && xpdr_serviceable->getBoolValue() ) { if ( xpdr_func_knob->getIntValue() == 2 ) { @@ -1062,7 +1058,7 @@ bool FGATCOutput::process() { #ifdef ATCFLIGHTSIM_HAVE_COMPASS do_steppers(); #endif - + return true; } diff --git a/utils/fgai/fgai.cxx b/utils/fgai/fgai.cxx index 4948693d4..998374949 100644 --- a/utils/fgai/fgai.cxx +++ b/utils/fgai/fgai.cxx @@ -390,14 +390,14 @@ public: { } virtual ~Physics() { } - + virtual void update(AIObject& object, const SGTimeStamp& dt) { SGVec3d down = getHorizontalLocalOrientation().backTransform(SGVec3d(0, 0, 1)); SGVec3d distToAimingPoint = getAimingPoint() - getPosition(); if (norm(distToAimingPoint - down*dot(down, distToAimingPoint)) <= 10*dt.toSecs()*norm(getLinearVelocity())) rotateAimingPoint(); - + SGVec3d aimingVector = normalize(getAimingPoint() - getPosition()); SGVec3d bodyAimingVector = getLocation().getOrientation().transform(aimingVector); @@ -424,12 +424,12 @@ public: { return _waypoints.front(); } void rotateAimingPoint() { _waypoints.splice(_waypoints.end(), _waypoints, _waypoints.begin()); } - + std::list _waypoints; double _targetVelocity; double _gearOffset; }; - + AIOgelInTrafficCircuit() { } virtual ~AIOgelInTrafficCircuit() @@ -594,7 +594,7 @@ main(int argc, char* argv[]) SGPath path(fg_root); path.append("HLA"); path.append("fg-local-fom.xml"); - manager->setFederationObjectModel(path.str()); + manager->setFederationObjectModel(path.local8BitStr()); } /// EDDS