X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FTankProperties.cxx;h=e07036f8f8d5b1caf645a1a8a384755594d18434;hb=85ae0697ee55c22523595c89ac643678809f3c88;hp=cb4f82c9821fb18de1343320d77c2ab273ad52b4;hpb=c7cccd8758e66c0d4ac71bd75709bae29f3322e4;p=flightgear.git diff --git a/src/FDM/TankProperties.cxx b/src/FDM/TankProperties.cxx index cb4f82c98..e07036f8f 100644 --- a/src/FDM/TankProperties.cxx +++ b/src/FDM/TankProperties.cxx @@ -26,6 +26,7 @@ #include "TankProperties.hxx" #include +#include #include
static const double LBS_PER_KG = 2.20462262; @@ -42,6 +43,10 @@ TankProperties::TankProperties(SGPropertyNode_ptr rootNode ) : _unusable_m3(0.0) { _tiedProperties.setRoot( rootNode ); +} + +void TankProperties::bind() +{ _tiedProperties.Tie("level-kg", this, &TankProperties::getContent_kg, &TankProperties::setContent_kg ); _tiedProperties.Tie("density-kgpm3", this, &TankProperties::getDensity_kgpm3, &TankProperties::setDensity_kgpm3 ); _tiedProperties.Tie("capacity-m3", this, &TankProperties::getCapacity_m3, &TankProperties::setCapacity_m3 ); @@ -67,6 +72,11 @@ TankProperties::~TankProperties() { } +void TankProperties::unbind() +{ + _tiedProperties.Untie(); +} + double TankProperties::getContent_kg() const { return _content_kg; @@ -74,7 +84,7 @@ double TankProperties::getContent_kg() const void TankProperties::setContent_kg( double value ) { - _content_kg = value; + _content_kg = SG_MAX2(value, 0.0); } double TankProperties::getDensity_kgpm3() const @@ -84,7 +94,7 @@ double TankProperties::getDensity_kgpm3() const void TankProperties::setDensity_kgpm3( double value ) { - _density_kgpm3 = value; + _density_kgpm3 = SG_MAX2(value, 0.0); } double TankProperties::getDensity_ppg() const @@ -94,7 +104,7 @@ double TankProperties::getDensity_ppg() const void TankProperties::setDensity_ppg( double value ) { - _density_kgpm3 = value * KG_PER_LBS / M3_PER_USGAL; + _density_kgpm3 = SG_MAX2(value * KG_PER_LBS / M3_PER_USGAL, 0.0); } double TankProperties::getContent_lbs() const @@ -104,7 +114,7 @@ double TankProperties::getContent_lbs() const void TankProperties::setContent_lbs( double value ) { - _content_kg = value * KG_PER_LBS; + _content_kg = SG_MAX2(value * KG_PER_LBS, 0.0); } double TankProperties::getContent_m3() const @@ -115,7 +125,7 @@ double TankProperties::getContent_m3() const void TankProperties::setContent_m3( double value ) { // ugly hack to allow setting of a volumetric content without having the density - _content_kg = value * (_density_kgpm3>0.0?_density_kgpm3:755.0); + _content_kg = SG_MAX2(value * (_density_kgpm3>0.0?_density_kgpm3:755.0), 0.0); } double TankProperties::getContent_gal_us() const @@ -145,7 +155,7 @@ double TankProperties::getCapacity_m3() const void TankProperties::setCapacity_m3( double value ) { - _capacity_m3 = value; + _capacity_m3 = SG_MAX2(value, 0.0); } double TankProperties::getCapacity_gal_us() const @@ -155,7 +165,7 @@ double TankProperties::getCapacity_gal_us() const void TankProperties::setCapacity_gal_us( double value ) { - _capacity_m3 = value * M3_PER_USGAL; + _capacity_m3 = SG_MAX2(value * M3_PER_USGAL, 0.0); } double TankProperties::getCapacity_gal_imp() const @@ -165,7 +175,7 @@ double TankProperties::getCapacity_gal_imp() const void TankProperties::setCapacity_gal_imp( double value ) { - _capacity_m3 = value * M3_PER_IMPGAL; + _capacity_m3 = SG_MAX2(value * M3_PER_IMPGAL, 0.0); } double TankProperties::getUnusable_m3() const @@ -175,7 +185,7 @@ double TankProperties::getUnusable_m3() const void TankProperties::setUnusable_m3( double value ) { - _unusable_m3 = value; + _unusable_m3 = SG_MAX2(value, 0.0); } double TankProperties::getUnusable_gal_us() const @@ -185,7 +195,7 @@ double TankProperties::getUnusable_gal_us() const void TankProperties::setUnusable_gal_us( double value ) { - _unusable_m3 = value * M3_PER_USGAL; + _unusable_m3 = SG_MAX2(value * M3_PER_USGAL, 0.0); } @@ -196,7 +206,7 @@ double TankProperties::getUnusable_gal_imp() const void TankProperties::setUnusable_gal_imp( double value ) { - _unusable_m3 = value * M3_PER_IMPGAL; + _unusable_m3 = SG_MAX2(value * M3_PER_IMPGAL, 0.0); } double TankProperties::getContent_norm() const @@ -226,12 +236,6 @@ TankPropertiesList::TankPropertiesList( SGPropertyNode_ptr rootNode ) } _tiedProperties.setRoot( rootNode ); - _tiedProperties.Tie("total-fuel-kg", this, &TankPropertiesList::getTotalContent_kg ); - _tiedProperties.Tie("total-fuel-lbs", this, &TankPropertiesList::getTotalContent_lbs ); - _tiedProperties.Tie("total-fuel-gal_us", this, &TankPropertiesList::getTotalContent_gal_us ); - _tiedProperties.Tie("total-fuel-gals", this, &TankPropertiesList::getTotalContent_gal_us ); - _tiedProperties.Tie("total-fuel-gal_imp", this, &TankPropertiesList::getTotalContent_gal_imp ); - _tiedProperties.Tie("total-fuel-norm", this, &TankPropertiesList::getTotalContent_norm ); } double TankPropertiesList::getTotalContent_lbs() const @@ -285,4 +289,23 @@ double TankPropertiesList::getTotalContent_norm() const return capacity > SGLimitsd::min() ? content / capacity : 0.0; } +void TankPropertiesList::bind() +{ + _tiedProperties.Tie("total-fuel-kg", this, &TankPropertiesList::getTotalContent_kg ); + _tiedProperties.Tie("total-fuel-lbs", this, &TankPropertiesList::getTotalContent_lbs ); + _tiedProperties.Tie("total-fuel-gal_us", this, &TankPropertiesList::getTotalContent_gal_us ); + _tiedProperties.Tie("total-fuel-gals", this, &TankPropertiesList::getTotalContent_gal_us ); + _tiedProperties.Tie("total-fuel-gal_imp", this, &TankPropertiesList::getTotalContent_gal_imp ); + _tiedProperties.Tie("total-fuel-norm", this, &TankPropertiesList::getTotalContent_norm ); + for( const_iterator it = begin(); it != end(); ++it ) { + (*it)->bind(); + } +} +void TankPropertiesList::unbind() +{ + for( const_iterator it = begin(); it != end(); ++it ) { + (*it)->unbind(); + } + _tiedProperties.Untie(); +}