X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FTankProperties.cxx;h=05e83ce117f25a02b0e1ba908240da6342a8ea03;hb=38226af24ec01e8f0a20d7fd73ef838a69f6ef25;hp=8cfc768b3757c46db8c5347a099b75700d22d682;hpb=fcf1709df61ec93182dc51ca4afa58ea152749a0;p=flightgear.git diff --git a/src/FDM/TankProperties.cxx b/src/FDM/TankProperties.cxx index 8cfc768b3..05e83ce11 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; @@ -38,12 +39,18 @@ static const double M3_PER_IMPGAL = 1.0/IMPGAL_PER_M3; TankProperties::TankProperties(SGPropertyNode_ptr rootNode ) : _content_kg(0.0), _density_kgpm3(0.0), - _capacity_m3(0.0) + _capacity_m3(0.0), + _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 ); + _tiedProperties.Tie("unusable-m3", this, &TankProperties::getUnusable_m3, &TankProperties::setUnusable_m3 ); _tiedProperties.Tie("level-m3", this, &TankProperties::getContent_m3, &TankProperties::setContent_m3 ); _tiedProperties.Tie("level-norm", this, &TankProperties::getContent_norm, &TankProperties::setContent_norm ); @@ -51,14 +58,25 @@ TankProperties::TankProperties(SGPropertyNode_ptr rootNode ) : _tiedProperties.Tie("level-lbs", this, &TankProperties::getContent_lbs, &TankProperties::setContent_lbs ); _tiedProperties.Tie("level-gal_us", this, &TankProperties::getContent_gal_us, &TankProperties::setContent_gal_us ); _tiedProperties.Tie("level-gal_imp", this, &TankProperties::getContent_gal_imp, &TankProperties::setContent_gal_imp ); + _tiedProperties.Tie("capacity-gal_us", this, &TankProperties::getCapacity_gal_us, &TankProperties::setCapacity_gal_us ); + _tiedProperties.Tie("unusable-gal_us", this, &TankProperties::getUnusable_gal_us, &TankProperties::setUnusable_gal_us ); + _tiedProperties.Tie("capacity-gal_imp", this, &TankProperties::getCapacity_gal_imp, &TankProperties::setCapacity_gal_imp ); + _tiedProperties.Tie("unusable-gal_imp", this, &TankProperties::getUnusable_gal_imp, &TankProperties::setUnusable_gal_imp ); + + _tiedProperties.Tie("empty", this, &TankProperties::getEmpty ); } TankProperties::~TankProperties() { } +void TankProperties::unbind() +{ + _tiedProperties.Untie(); +} + double TankProperties::getContent_kg() const { return _content_kg; @@ -66,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 @@ -76,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 @@ -86,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 @@ -96,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 @@ -106,7 +124,8 @@ double TankProperties::getContent_m3() const void TankProperties::setContent_m3( double value ) { - _content_kg = value * _density_kgpm3; + // ugly hack to allow setting of a volumetric content without having the density + _content_kg = SG_MAX2(value * (_density_kgpm3>0.0?_density_kgpm3:755.0), 0.0); } double TankProperties::getContent_gal_us() const @@ -136,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 @@ -146,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 @@ -156,7 +175,38 @@ 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 +{ + return _unusable_m3; +} + +void TankProperties::setUnusable_m3( double value ) +{ + _unusable_m3 = SG_MAX2(value, 0.0); +} + +double TankProperties::getUnusable_gal_us() const +{ + return _unusable_m3 * USGAL_PER_M3; +} + +void TankProperties::setUnusable_gal_us( double value ) +{ + _unusable_m3 = SG_MAX2(value * M3_PER_USGAL, 0.0); +} + + +double TankProperties::getUnusable_gal_imp() const +{ + return _unusable_m3 * IMPGAL_PER_M3; +} + +void TankProperties::setUnusable_gal_imp( double value ) +{ + _unusable_m3 = SG_MAX2(value * M3_PER_IMPGAL, 0.0); } double TankProperties::getContent_norm() const @@ -169,12 +219,19 @@ void TankProperties::setContent_norm( double value ) setContent_m3(_capacity_m3 * value); } +bool TankProperties::getEmpty() const +{ + return getContent_m3() <= _unusable_m3; +} + TankPropertiesList::TankPropertiesList( SGPropertyNode_ptr rootNode ) { // we don't have a global rule how many tanks we support, so I assume eight. - // Because hard coded values suck, make it settable by a property - size_type n = rootNode->getIntValue( "numtanks", 8 ); - for( size_type i = 0; i < n; i++ ) { + // Because hard coded values suck, make it settable by a property. + // If tanks were configured, use that number + int n = rootNode->getChildren("tank").size(); + if( n == 0 ) n = rootNode->getIntValue( "numtanks", 8 ); + for( int i = 0; i < n; i++ ) { push_back( new TankProperties( rootNode->getChild( "tank", i, true ) ) ); } @@ -238,4 +295,17 @@ double TankPropertiesList::getTotalContent_norm() const return capacity > SGLimitsd::min() ? content / capacity : 0.0; } +void TankPropertiesList::bind() +{ + 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(); +}