X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FEnvironment%2Fmetarproperties.cxx;h=1ebdd33b0da805cc6f8ad59ea6513560b7fca24b;hb=9745a6fce3de367cf29c37829b312090e84c2487;hp=6d8c1c51a70625c8410910d7632dfd6f5e1e703c;hpb=7d95b7e09d584d7d4c62cd69e9ce8c872b2ad4d7;p=flightgear.git diff --git a/src/Environment/metarproperties.cxx b/src/Environment/metarproperties.cxx index 6d8c1c51a..1ebdd33b0 100644 --- a/src/Environment/metarproperties.cxx +++ b/src/Environment/metarproperties.cxx @@ -24,6 +24,8 @@ # include #endif +#include // for strlen + #include "metarproperties.hxx" #include "fgmetar.hxx" #include "environment.hxx" @@ -83,15 +85,13 @@ inline void MagneticVariation::recalc( double lon, double lat, double alt ) // calculation of magnetic variation is expensive. Cache the position // and perform this calculation only if it has changed if( _lon != lon || _lat != lat || _alt != alt ) { - SG_LOG(SG_ALL, SG_DEBUG, "Recalculating magvar for lon=" << lon << ", lat=" << lat << ", alt=" << alt ); + SG_LOG(SG_ENVIRONMENT, SG_DEBUG, "Recalculating magvar for lon=" << lon << ", lat=" << lat << ", alt=" << alt ); _lon = lon; _lat = lat; _alt = alt; - lon *= SGD_DEGREES_TO_RADIANS; - lat *= SGD_DEGREES_TO_RADIANS; - alt *= SG_FEET_TO_METER; - _time.update( lon, lat, 0, 0 ); + SGGeod location(SGGeod::fromDegFt(lon, lat, alt)); + _time.update( location, 0, 0 ); update( lon, lat, alt, _time.getJD() ); } } @@ -134,10 +134,14 @@ MetarProperties::MetarProperties( SGPropertyNode_ptr rootNode ) : _hail(0.0), _snow(0.0), _snow_cover(false), + _day(0), + _hour(0), + _minute(0), + _cavok(false), _magneticVariation(new MagneticVariation()) { // Hack to avoid static initialization order problems on OSX - if( coverage_string.size() == 0 ) { + if( coverage_string.empty() ) { coverage_string.push_back(SGCloudLayer::SG_CLOUD_CLEAR_STRING); coverage_string.push_back(SGCloudLayer::SG_CLOUD_FEW_STRING); coverage_string.push_back(SGCloudLayer::SG_CLOUD_SCATTERED_STRING); @@ -174,7 +178,11 @@ MetarProperties::MetarProperties( SGPropertyNode_ptr rootNode ) : _tiedProperties.Tie("hail-norm", &_hail ); _tiedProperties.Tie("snow-norm", &_snow); _tiedProperties.Tie("snow-cover", &_snow_cover ); + _tiedProperties.Tie("day", &_day ); + _tiedProperties.Tie("hour", &_hour ); + _tiedProperties.Tie("minute", &_minute ); _tiedProperties.Tie("decoded", this, &MetarProperties::get_decoded ); + _tiedProperties.Tie("cavok", &_cavok ); } MetarProperties::~MetarProperties() @@ -182,26 +190,50 @@ MetarProperties::~MetarProperties() delete _magneticVariation; } +void MetarProperties::invalidate() +{ + if( _metarValidNode->getBoolValue() ) + _metarValidNode->setBoolValue(false); +} static const double thickness_value[] = { 0, 65, 600, 750, 1000 }; -void MetarProperties::set_metar( const char * metar ) +const char* MetarProperties::get_metar() const +{ + if (!_metar) return ""; + return _metar->getData(); +} + +void MetarProperties::set_metar( const char * metarString ) { - _metar = metar; - SGSharedPtr m; + if ((metarString == NULL) || (strlen(metarString) == 0)) { + setMetar(m); + return; + } + try { - m = new FGMetar( _metar ); + m = new FGMetar( metarString ); } catch( sg_io_exception ) { - SG_LOG( SG_GENERAL, SG_WARN, "Can't parse metar: " << _metar ); + SG_LOG( SG_ENVIRONMENT, SG_WARN, "Can't parse metar: " << metarString ); _metarValidNode->setBoolValue(false); return; } - + + setMetar(m); +} + +void MetarProperties::setMetar( SGSharedPtr m ) +{ + _metar = m; _decoded.clear(); + if (!m) { + return; + } + const vector weather = m->getWeather(); - for( vector::const_iterator it = weather.begin(); it != weather.end(); it++ ) { + for( vector::const_iterator it = weather.begin(); it != weather.end(); ++it ) { if( false == _decoded.empty() ) _decoded.append(", "); _decoded.append(*it); } @@ -301,9 +333,6 @@ void MetarProperties::set_metar( const char * metar ) } } - vector cv = m->getClouds(); - vector::const_iterator cloud, cloud_end = cv.end(); - { static const char * LAYER = "layer"; SGPropertyNode_ptr cloudsNode = _rootNode->getNode("clouds", true ); @@ -374,6 +403,7 @@ void MetarProperties::set_metar( const char * metar ) -9999.0 : metarClouds[i].getAltitude_ft() + _station_elevation; + layerNode->setDoubleValue( "alpha", 1.0 ); layerNode->setStringValue( "coverage", coverage_string[coverage] ); layerNode->setDoubleValue( "coverage-type", SGCloudLayer::getCoverageType(coverage_string[coverage]) ); layerNode->setDoubleValue( "elevation-ft", elevation ); @@ -387,6 +417,10 @@ void MetarProperties::set_metar( const char * metar ) _hail = m->getHail(); _snow = m->getSnow(); _snow_cover = m->getSnowCover(); + _day = m->getDay(); + _hour = m->getHour(); + _minute = m->getMinute(); + _cavok = m->getCAVOK(); _metarValidNode->setBoolValue(true); }