Minor refactoring: Extract duplicated code.

This commit is contained in:
Kristian Bendiksen 2020-09-02 14:21:45 +02:00
parent 304e370747
commit c7a694f9b2
2 changed files with 39 additions and 33 deletions

View File

@ -283,17 +283,10 @@ QList<caf::PdmOptionItemInfo> RimFractureModel::calculateValueOptions( const caf
if ( fieldNeedingOptions == &m_overburdenFormation || fieldNeedingOptions == &m_underburdenFormation ) if ( fieldNeedingOptions == &m_overburdenFormation || fieldNeedingOptions == &m_underburdenFormation )
{ {
// Find an eclipse case RigEclipseCaseData* eclipseCaseData = getEclipseCaseData();
RimProject* proj = RimProject::current();
if ( proj->eclipseCases().empty() ) return options;
RimEclipseCase* eclipseCase = proj->eclipseCases()[0];
if ( !eclipseCase ) return options;
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
if ( !eclipseCaseData ) return options; if ( !eclipseCaseData ) return options;
std::vector<QString> formationNames = eclipseCase->eclipseCaseData()->formationNames(); std::vector<QString> formationNames = eclipseCaseData->formationNames();
for ( const QString& formationName : formationNames ) for ( const QString& formationName : formationNames )
{ {
options.push_back( caf::PdmOptionItemInfo( formationName, formationName ) ); options.push_back( caf::PdmOptionItemInfo( formationName, formationName ) );
@ -458,15 +451,7 @@ cvf::Vec3d RimFractureModel::calculateTSTDirection() const
{ {
cvf::Vec3d defaultDirection = cvf::Vec3d( 0.0, 0.0, -1.0 ); cvf::Vec3d defaultDirection = cvf::Vec3d( 0.0, 0.0, -1.0 );
// TODO: find a better way? RigEclipseCaseData* eclipseCaseData = getEclipseCaseData();
// Find an eclipse case
RimProject* proj = RimProject::current();
if ( proj->eclipseCases().empty() ) return defaultDirection;
RimEclipseCase* eclipseCase = proj->eclipseCases()[0];
if ( !eclipseCase ) return defaultDirection;
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
if ( !eclipseCaseData ) return defaultDirection; if ( !eclipseCaseData ) return defaultDirection;
RigMainGrid* mainGrid = eclipseCaseData->mainGrid(); RigMainGrid* mainGrid = eclipseCaseData->mainGrid();
@ -565,14 +550,7 @@ QString RimFractureModel::vecToString( const cvf::Vec3d& vec )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimFractureModel::findThicknessTargetPoints( cvf::Vec3d& topPosition, cvf::Vec3d& bottomPosition ) void RimFractureModel::findThicknessTargetPoints( cvf::Vec3d& topPosition, cvf::Vec3d& bottomPosition )
{ {
// TODO: duplicated and ugly! RigEclipseCaseData* eclipseCaseData = getEclipseCaseData();
RimProject* proj = RimProject::current();
if ( proj->eclipseCases().empty() ) return;
RimEclipseCase* eclipseCase = proj->eclipseCases()[0];
if ( !eclipseCase ) return;
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
if ( !eclipseCaseData ) return; if ( !eclipseCaseData ) return;
const cvf::Vec3d& position = anchorPosition(); const cvf::Vec3d& position = anchorPosition();
@ -581,7 +559,7 @@ void RimFractureModel::findThicknessTargetPoints( cvf::Vec3d& topPosition, cvf::
// Create a "fake" well path which from top to bottom of formation // Create a "fake" well path which from top to bottom of formation
// passing through the point and with the given direction // passing through the point and with the given direction
const cvf::BoundingBox& geometryBoundingBox = eclipseCase->mainGrid()->boundingBox(); const cvf::BoundingBox& geometryBoundingBox = eclipseCaseData->mainGrid()->boundingBox();
RiaLogging::info( QString( "All cells bounding box: %1 %2" ) RiaLogging::info( QString( "All cells bounding box: %1 %2" )
.arg( RimFractureModel::vecToString( geometryBoundingBox.min() ) ) .arg( RimFractureModel::vecToString( geometryBoundingBox.min() ) )
@ -942,3 +920,28 @@ double RimFractureModel::referenceTemperatureDepth() const
{ {
return m_referenceTemperatureDepth; return m_referenceTemperatureDepth;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCase* RimFractureModel::getEclipseCase()
{
// Find an eclipse case
RimProject* proj = RimProject::current();
if ( proj->eclipseCases().empty() ) return nullptr;
return proj->eclipseCases()[0];
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigEclipseCaseData* RimFractureModel::getEclipseCaseData()
{
// Find an eclipse case
RimEclipseCase* eclipseCase = getEclipseCase();
if ( !eclipseCase ) return nullptr;
return eclipseCase->eclipseCaseData();
}

View File

@ -36,6 +36,7 @@ class RimEclipseCase;
class RimWellPath; class RimWellPath;
class RimModeledWellPath; class RimModeledWellPath;
class RimElasticProperties; class RimElasticProperties;
class RigEclipseCaseData;
//================================================================================================== //==================================================================================================
/// ///
@ -127,12 +128,14 @@ protected:
bool* useOptionsOnly ) override; bool* useOptionsOnly ) override;
private: private:
void updatePositionFromMeasuredDepth(); void updatePositionFromMeasuredDepth();
void updateThicknessDirection(); void updateThicknessDirection();
cvf::Vec3d calculateTSTDirection() const; cvf::Vec3d calculateTSTDirection() const;
void findThicknessTargetPoints( cvf::Vec3d& topPosition, cvf::Vec3d& bottomPosition ); void findThicknessTargetPoints( cvf::Vec3d& topPosition, cvf::Vec3d& bottomPosition );
static QString vecToString( const cvf::Vec3d& vec ); static QString vecToString( const cvf::Vec3d& vec );
void updateThicknessDirectionWellPathName(); void updateThicknessDirectionWellPathName();
static RigEclipseCaseData* getEclipseCaseData();
static RimEclipseCase* getEclipseCase();
protected: protected:
caf::PdmField<double> m_MD; caf::PdmField<double> m_MD;