#5659 Well Disks: Use decimal number format for small numbers

This commit is contained in:
Kristian Bendiksen 2020-03-24 15:11:04 +01:00 committed by Magne Sjaastad
parent 08f560a058
commit 3c2d456996
2 changed files with 17 additions and 17 deletions

View File

@ -193,8 +193,6 @@ void RivWellDiskPartMgr::buildWellDiskParts( size_t frameIndex, const caf::Displ
std::vector<std::pair<cvf::String, cvf::Vec3f>> labelsWithPosition; std::vector<std::pair<cvf::String, cvf::Vec3f>> labelsWithPosition;
int numberPrecision = 2;
double accumulatedPropertyValue = 0.0; double accumulatedPropertyValue = 0.0;
const double valueThresholdForLabel = 1e-6; const double valueThresholdForLabel = 1e-6;
@ -216,7 +214,7 @@ void RivWellDiskPartMgr::buildWellDiskParts( size_t frameIndex, const caf::Displ
if ( diskData.singlePropertyValue() > valueThresholdForLabel ) if ( diskData.singlePropertyValue() > valueThresholdForLabel )
{ {
const double singleProperty = diskData.singlePropertyValueSigned(); const double singleProperty = diskData.singlePropertyValueSigned();
labelText += QString( "\n%2" ).arg( singleProperty, 0, 'g', numberPrecision ); labelText += QString( "\n%2" ).arg( RivWellDiskPartMgr::formatNumber( singleProperty ) );
} }
} }
} }
@ -239,11 +237,8 @@ void RivWellDiskPartMgr::buildWellDiskParts( size_t frameIndex, const caf::Displ
if ( oilFraction > valueThresholdForLabel ) if ( oilFraction > valueThresholdForLabel )
{ {
auto p = createTextAndLocation( oilFraction / 2.0, auto p = createTextAndLocation( oilFraction / 2.0, diskPosition, ijScaleFactor, diskData.oilSigned() );
diskPosition,
ijScaleFactor,
diskData.oilSigned(),
numberPrecision );
labelsWithPosition.push_back( p ); labelsWithPosition.push_back( p );
aggregatedFraction += oilFraction; aggregatedFraction += oilFraction;
} }
@ -253,8 +248,7 @@ void RivWellDiskPartMgr::buildWellDiskParts( size_t frameIndex, const caf::Displ
auto p = createTextAndLocation( aggregatedFraction + gasFraction / 2.0, auto p = createTextAndLocation( aggregatedFraction + gasFraction / 2.0,
diskPosition, diskPosition,
ijScaleFactor, ijScaleFactor,
diskData.gasSigned(), diskData.gasSigned() );
numberPrecision );
labelsWithPosition.push_back( p ); labelsWithPosition.push_back( p );
aggregatedFraction += gasFraction; aggregatedFraction += gasFraction;
} }
@ -264,8 +258,7 @@ void RivWellDiskPartMgr::buildWellDiskParts( size_t frameIndex, const caf::Displ
auto p = createTextAndLocation( aggregatedFraction + waterFraction / 2.0, auto p = createTextAndLocation( aggregatedFraction + waterFraction / 2.0,
diskPosition, diskPosition,
ijScaleFactor, ijScaleFactor,
diskData.waterSigned(), diskData.waterSigned() );
numberPrecision );
labelsWithPosition.push_back( p ); labelsWithPosition.push_back( p );
aggregatedFraction += waterFraction; aggregatedFraction += waterFraction;
@ -409,14 +402,21 @@ void RivWellDiskPartMgr::buildWellDiskParts( size_t frameIndex, const caf::Displ
} }
} }
QString RivWellDiskPartMgr::formatNumber( double num )
{
if ( std::abs( num ) < 1e4 )
return QString::number( num, 'f', 1 );
else
return QString::number( num, 'g', 2 );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::pair<cvf::String, cvf::Vec3f> RivWellDiskPartMgr::createTextAndLocation( const double aggregatedFraction, std::pair<cvf::String, cvf::Vec3f> RivWellDiskPartMgr::createTextAndLocation( const double aggregatedFraction,
cvf::Vec3d diskPosition, cvf::Vec3d diskPosition,
double ijScaleFactor, double ijScaleFactor,
const double fraction, const double fraction )
int precision )
{ {
double sinA = cvf::Math::sin( aggregatedFraction * 2.0 * cvf::PI_F ); double sinA = cvf::Math::sin( aggregatedFraction * 2.0 * cvf::PI_F );
double cosA = cvf::Math::cos( aggregatedFraction * 2.0 * cvf::PI_F ); double cosA = cvf::Math::cos( aggregatedFraction * 2.0 * cvf::PI_F );
@ -430,7 +430,7 @@ std::pair<cvf::String, cvf::Vec3f> RivWellDiskPartMgr::createTextAndLocation( co
v.x() = v.x() + static_cast<float>( -sinA * radius ); v.x() = v.x() + static_cast<float>( -sinA * radius );
v.y() = v.y() + static_cast<float>( cosA * radius ); v.y() = v.y() + static_cast<float>( cosA * radius );
auto s = QString::number( fraction, 'g', precision ); auto s = RivWellDiskPartMgr::formatNumber( fraction );
cvf::String text = cvf::String( s.toStdString() ); cvf::String text = cvf::String( s.toStdString() );
auto p = std::make_pair( text, v ); auto p = std::make_pair( text, v );

View File

@ -59,14 +59,14 @@ private:
std::pair<cvf::String, cvf::Vec3f> createTextAndLocation( const double aggregatedFraction, std::pair<cvf::String, cvf::Vec3f> createTextAndLocation( const double aggregatedFraction,
cvf::Vec3d diskPosition, cvf::Vec3d diskPosition,
double ijScaleFactor, double ijScaleFactor,
const double fraction, const double fraction );
int precision );
void clearAllGeometry(); void clearAllGeometry();
Rim3dView* viewWithSettings(); Rim3dView* viewWithSettings();
RimSimWellInViewCollection* simWellInViewCollection(); RimSimWellInViewCollection* simWellInViewCollection();
static cvf::Color4f getWellInjectionColor( RigWellResultFrame::WellProductionType productionType ); static cvf::Color4f getWellInjectionColor( RigWellResultFrame::WellProductionType productionType );
static QString formatNumber( double num );
private: private:
caf::PdmPointer<RimSimWellInView> m_rimWell; caf::PdmPointer<RimSimWellInView> m_rimWell;