2015-09-15 08:23:25 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
# include "RimWellLogFileCurve.h"
2017-02-24 07:14:29 -06:00
# include "RigWellLogCurveData.h"
2017-10-12 10:05:52 -05:00
# include "RigWellPath.h"
2017-02-24 07:14:29 -06:00
2015-09-16 08:31:04 -05:00
# include "RimOilField.h"
2017-02-24 07:14:29 -06:00
# include "RimProject.h"
2015-09-16 09:06:06 -05:00
# include "RimWellLogFile.h"
2017-02-24 07:14:29 -06:00
# include "RimWellLogFileChannel.h"
2015-09-16 08:31:04 -05:00
# include "RimWellLogPlot.h"
2017-02-24 07:14:29 -06:00
# include "RimWellLogTrack.h"
# include "RimWellPath.h"
# include "RimWellPathCollection.h"
2015-09-16 08:31:04 -05:00
2015-11-06 01:32:58 -06:00
# include "RiuLineSegmentQwtPlotCurve.h"
2017-10-12 10:05:52 -05:00
# include "RiuWellLogTrack.h"
2015-09-16 08:31:04 -05:00
# include "RiaApplication.h"
2015-10-30 05:42:11 -05:00
# include "RiaPreferences.h"
2015-09-16 08:31:04 -05:00
# include "cafPdmUiTreeOrdering.h"
2015-10-30 05:42:11 -05:00
# include <QMessageBox>
2015-09-15 08:23:25 -05:00
CAF_PDM_SOURCE_INIT ( RimWellLogFileCurve , " WellLogFileCurve " ) ;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogFileCurve : : RimWellLogFileCurve ( )
{
CAF_PDM_InitObject ( " Well Log File Curve " , " " , " " , " " ) ;
2015-09-16 08:31:04 -05:00
CAF_PDM_InitFieldNoDefault ( & m_wellPath , " CurveWellPath " , " Well Path " , " " , " " , " " ) ;
2016-10-10 08:38:31 -05:00
m_wellPath . uiCapability ( ) - > setUiTreeChildrenHidden ( true ) ;
2015-09-16 08:31:04 -05:00
CAF_PDM_InitFieldNoDefault ( & m_wellLogChannnelName , " CurveWellLogChannel " , " Well Log Channel " , " " , " " , " " ) ;
2017-10-12 10:05:52 -05:00
m_wellPath = nullptr ;
2015-09-15 08:23:25 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogFileCurve : : ~ RimWellLogFileCurve ( )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-09-23 01:47:04 -05:00
void RimWellLogFileCurve : : onLoadDataAndUpdate ( bool updateParentPlot )
2015-09-15 08:23:25 -05:00
{
2016-05-23 10:13:03 -05:00
RimWellLogCurve : : updateCurvePresentation ( ) ;
2015-09-16 08:31:04 -05:00
2015-10-27 08:44:53 -05:00
if ( isCurveVisible ( ) )
2015-09-16 08:31:04 -05:00
{
2015-10-15 04:27:12 -05:00
m_curveData = new RigWellLogCurveData ;
2015-10-30 05:42:11 -05:00
RimWellLogPlot * wellLogPlot ;
2016-09-21 06:59:41 -05:00
firstAncestorOrThisOfType ( wellLogPlot ) ;
2015-10-30 05:42:11 -05:00
CVF_ASSERT ( wellLogPlot ) ;
2017-10-12 10:05:52 -05:00
if ( m_wellPath )
2015-09-16 08:31:04 -05:00
{
2017-10-06 06:24:45 -05:00
RimWellLogFile * logFileInfo = m_wellPath - > wellLogFile ( ) ;
2015-09-16 08:31:04 -05:00
if ( logFileInfo )
{
RigWellLogFile * wellLogFile = logFileInfo - > wellLogFile ( ) ;
2015-10-12 05:40:10 -05:00
if ( wellLogFile )
2015-09-18 02:05:15 -05:00
{
2015-10-12 05:40:10 -05:00
std : : vector < double > values = wellLogFile - > values ( m_wellLogChannnelName ) ;
2017-10-12 10:05:52 -05:00
std : : vector < double > measuredDepthValues = wellLogFile - > depthValues ( ) ;
if ( wellLogPlot & & wellLogPlot - > depthType ( ) = = RimWellLogPlot : : TRUE_VERTICAL_DEPTH )
{
RigWellPath * rigWellPath = m_wellPath - > wellPathGeometry ( ) ;
if ( rigWellPath )
{
std : : vector < double > trueVerticeldepthValues ;
for ( double measuredDepthValue : measuredDepthValues )
{
trueVerticeldepthValues . push_back ( - rigWellPath - > interpolatedPointAlongWellPath ( measuredDepthValue ) . z ( ) ) ;
}
if ( values . size ( ) = = trueVerticeldepthValues . size ( ) & & values . size ( ) = = measuredDepthValues . size ( ) )
{
m_curveData - > setValuesWithTVD ( values , measuredDepthValues , trueVerticeldepthValues , wellLogFile - > depthUnit ( ) , false ) ;
}
}
else
{
if ( RiaApplication : : instance ( ) - > preferences ( ) - > showLasCurveWithoutTvdWarning ( ) )
{
QString tmp = QString ( " Display of True Vertical Depth (TVD) for LAS curves is not possible without a well log path, and the LAS curve will be hidden in this mode. \n \n " ) ;
tmp + = " Control display of this warning from \" Preferences->Show LAS curve without TVD warning \" " ;
QMessageBox : : warning ( nullptr , " LAS curve without TVD " , tmp ) ;
}
}
}
else
2015-10-12 05:40:10 -05:00
{
2017-10-12 10:05:52 -05:00
if ( values . size ( ) = = measuredDepthValues . size ( ) )
{
m_curveData - > setValuesAndMD ( values , measuredDepthValues , wellLogFile - > depthUnit ( ) , false ) ;
}
2015-10-12 05:40:10 -05:00
}
2015-09-18 02:05:15 -05:00
}
2015-09-22 08:12:33 -05:00
2016-05-23 10:13:03 -05:00
if ( m_isUsingAutoName )
2015-09-22 08:45:58 -05:00
{
2016-05-23 10:13:03 -05:00
m_qwtPlotCurve - > setTitle ( createCurveAutoName ( ) ) ;
2015-09-22 08:45:58 -05:00
}
2015-09-16 08:31:04 -05:00
}
}
2015-10-15 04:27:12 -05:00
2017-10-12 10:05:52 -05:00
2017-06-13 08:41:52 -05:00
RiaDefines : : DepthUnitType displayUnit = RiaDefines : : UNIT_METER ;
2015-12-02 06:39:16 -06:00
if ( wellLogPlot )
{
displayUnit = wellLogPlot - > depthUnit ( ) ;
}
2017-10-12 10:05:52 -05:00
if ( wellLogPlot & & wellLogPlot - > depthType ( ) = = RimWellLogPlot : : TRUE_VERTICAL_DEPTH )
{
m_qwtPlotCurve - > setSamples ( m_curveData - > xPlotValues ( ) . data ( ) , m_curveData - > trueDepthPlotValues ( displayUnit ) . data ( ) , static_cast < int > ( m_curveData - > xPlotValues ( ) . size ( ) ) ) ;
}
else
{
m_qwtPlotCurve - > setSamples ( m_curveData - > xPlotValues ( ) . data ( ) , m_curveData - > measuredDepthPlotValues ( displayUnit ) . data ( ) , static_cast < int > ( m_curveData - > xPlotValues ( ) . size ( ) ) ) ;
}
2015-11-06 03:08:35 -06:00
m_qwtPlotCurve - > setLineSegmentStartStopIndices ( m_curveData - > polylineStartStopIndices ( ) ) ;
2015-09-22 04:17:24 -05:00
2016-09-13 02:59:34 -05:00
updateZoomInParentPlot ( ) ;
2015-09-22 04:17:24 -05:00
2016-05-23 10:13:03 -05:00
if ( m_parentQwtPlot ) m_parentQwtPlot - > replot ( ) ;
2015-09-16 08:31:04 -05:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogFileCurve : : setWellPath ( RimWellPath * wellPath )
{
m_wellPath = wellPath ;
2015-09-15 08:23:25 -05:00
}
2017-10-05 03:54:52 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPath * RimWellLogFileCurve : : wellPath ( ) const
{
return m_wellPath ;
}
2015-09-15 08:23:25 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-09-16 08:31:04 -05:00
void RimWellLogFileCurve : : setWellLogChannelName ( const QString & name )
2015-09-15 08:23:25 -05:00
{
2015-09-16 08:31:04 -05:00
m_wellLogChannnelName = name ;
2015-09-15 08:23:25 -05:00
}
2015-09-16 08:31:04 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogFileCurve : : fieldChangedByUi ( const caf : : PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
{
2015-11-04 09:19:38 -06:00
RimWellLogCurve : : fieldChangedByUi ( changedField , oldValue , newValue ) ;
2015-09-16 08:31:04 -05:00
if ( changedField = = & m_wellPath )
{
2017-09-23 01:47:04 -05:00
this - > loadDataAndUpdate ( true ) ;
2015-09-16 08:31:04 -05:00
}
else if ( changedField = = & m_wellLogChannnelName )
{
2017-09-23 01:47:04 -05:00
this - > loadDataAndUpdate ( true ) ;
2015-09-16 08:31:04 -05:00
}
2016-05-23 10:13:03 -05:00
if ( m_parentQwtPlot ) m_parentQwtPlot - > replot ( ) ;
2015-09-16 08:31:04 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogFileCurve : : defineUiOrdering ( QString uiConfigName , caf : : PdmUiOrdering & uiOrdering )
{
2017-03-17 09:51:32 -05:00
RimPlotCurve : : updateOptionSensitivity ( ) ;
2015-09-22 08:23:52 -05:00
caf : : PdmUiGroup * curveDataGroup = uiOrdering . addNewGroup ( " Curve Data " ) ;
curveDataGroup - > add ( & m_wellPath ) ;
curveDataGroup - > add ( & m_wellLogChannnelName ) ;
caf : : PdmUiGroup * appearanceGroup = uiOrdering . addNewGroup ( " Appearance " ) ;
2017-04-07 07:43:26 -05:00
RimPlotCurve : : appearanceUiOrdering ( * appearanceGroup ) ;
caf : : PdmUiGroup * nameGroup = uiOrdering . addNewGroup ( " Curve Name " ) ;
2017-05-01 13:13:13 -05:00
nameGroup - > add ( & m_showLegend ) ;
2017-04-07 07:43:26 -05:00
RimPlotCurve : : curveNameUiOrdering ( * nameGroup ) ;
2015-09-16 08:31:04 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogFileCurve : : defineUiTreeOrdering ( caf : : PdmUiTreeOrdering & uiTreeOrdering , QString uiConfigName /*= ""*/ )
{
2017-03-22 09:57:04 -05:00
uiTreeOrdering . skipRemainingChildren ( true ) ;
2015-09-16 08:31:04 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList < caf : : PdmOptionItemInfo > RimWellLogFileCurve : : calculateValueOptions ( const caf : : PdmFieldHandle * fieldNeedingOptions , bool * useOptionsOnly )
{
2017-01-05 00:57:37 -06:00
QList < caf : : PdmOptionItemInfo > options ;
2015-09-16 08:31:04 -05:00
2017-01-05 00:57:37 -06:00
options = RimWellLogCurve : : calculateValueOptions ( fieldNeedingOptions , useOptionsOnly ) ;
if ( options . size ( ) > 0 ) return options ;
2015-12-01 09:22:18 -06:00
2015-09-16 08:31:04 -05:00
if ( fieldNeedingOptions = = & m_wellPath )
{
RimProject * proj = RiaApplication : : instance ( ) - > project ( ) ;
if ( proj - > activeOilField ( ) - > wellPathCollection ( ) )
{
caf : : PdmChildArrayField < RimWellPath * > & wellPaths = proj - > activeOilField ( ) - > wellPathCollection ( ) - > wellPaths ;
for ( size_t i = 0 ; i < wellPaths . size ( ) ; i + + )
{
2017-01-05 00:53:14 -06:00
// Only include well paths coming from a well log file
2017-10-06 06:24:45 -05:00
if ( wellPaths [ i ] - > wellLogFile ( ) )
2015-09-25 11:04:10 -05:00
{
2017-01-05 00:57:37 -06:00
options . push_back ( caf : : PdmOptionItemInfo ( wellPaths [ i ] - > name ( ) , wellPaths [ i ] ) ) ;
2015-09-25 11:04:10 -05:00
}
2015-09-16 08:31:04 -05:00
}
2017-01-05 00:57:37 -06:00
if ( options . size ( ) > 0 )
2015-09-16 08:31:04 -05:00
{
2017-01-05 00:57:37 -06:00
options . push_front ( caf : : PdmOptionItemInfo ( " None " , nullptr ) ) ;
2015-09-16 08:31:04 -05:00
}
}
}
if ( fieldNeedingOptions = = & m_wellLogChannnelName )
{
if ( m_wellPath ( ) )
{
2017-10-06 06:24:45 -05:00
RimWellLogFile * wellLogFile = m_wellPath - > wellLogFile ( ) ;
2015-09-16 09:06:06 -05:00
if ( wellLogFile )
2015-09-16 08:31:04 -05:00
{
2017-10-06 06:34:45 -05:00
std : : vector < RimWellLogFileChannel * > fileLogs = wellLogFile - > wellLogChannels ( ) ;
2015-09-16 08:31:04 -05:00
2017-10-06 06:34:45 -05:00
for ( size_t i = 0 ; i < fileLogs . size ( ) ; i + + )
2015-09-16 08:31:04 -05:00
{
2017-10-06 06:34:45 -05:00
QString wellLogChannelName = fileLogs [ i ] - > name ( ) ;
2017-01-05 00:57:37 -06:00
options . push_back ( caf : : PdmOptionItemInfo ( wellLogChannelName , wellLogChannelName ) ) ;
2015-09-16 08:31:04 -05:00
}
}
}
2015-09-18 02:05:15 -05:00
2017-01-05 00:57:37 -06:00
if ( options . size ( ) = = 0 )
2015-09-18 02:05:15 -05:00
{
2017-01-05 00:57:37 -06:00
options . push_back ( caf : : PdmOptionItemInfo ( " None " , " None " ) ) ;
2015-09-18 02:05:15 -05:00
}
2015-09-16 08:31:04 -05:00
}
2017-01-05 00:57:37 -06:00
return options ;
2015-09-16 08:31:04 -05:00
}
2015-09-18 06:02:33 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-05-23 10:13:03 -05:00
QString RimWellLogFileCurve : : createCurveAutoName ( )
2015-09-18 06:02:33 -05:00
{
2015-09-22 08:12:33 -05:00
if ( m_wellPath )
2015-09-18 06:43:09 -05:00
{
QString txt ;
2015-10-16 04:15:04 -05:00
txt + = wellName ( ) ;
2015-09-18 06:43:09 -05:00
txt + = " : " ;
txt + = m_wellLogChannnelName ;
2017-10-06 06:24:45 -05:00
RimWellLogFile * logFileInfo = m_wellPath - > wellLogFile ( ) ;
2017-10-12 10:05:52 -05:00
RigWellLogFile * wellLogFile = logFileInfo ? logFileInfo - > wellLogFile ( ) : nullptr ;
2015-09-22 08:12:33 -05:00
if ( wellLogFile )
2015-09-21 03:10:25 -05:00
{
2015-12-02 07:21:22 -06:00
RimWellLogPlot * wellLogPlot ;
2016-09-21 06:59:41 -05:00
firstAncestorOrThisOfType ( wellLogPlot ) ;
2015-12-02 07:21:22 -06:00
CVF_ASSERT ( wellLogPlot ) ;
QString unitName = wellLogFile - > wellLogChannelUnitString ( m_wellLogChannnelName , wellLogPlot - > depthUnit ( ) ) ;
2015-09-22 08:12:33 -05:00
if ( ! unitName . isEmpty ( ) )
{
2015-09-22 08:45:58 -05:00
txt + = QString ( " [%1] " ) . arg ( unitName ) ;
2015-09-22 08:12:33 -05:00
}
2015-09-21 03:10:25 -05:00
}
2015-09-18 06:43:09 -05:00
return txt ;
}
2017-10-12 10:05:52 -05:00
2015-09-18 06:43:09 -05:00
return " Empty curve " ;
2015-09-18 06:02:33 -05:00
}
2015-10-15 07:37:57 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimWellLogFileCurve : : wellLogChannelName ( ) const
{
return m_wellLogChannnelName ;
}
2015-10-16 04:15:04 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimWellLogFileCurve : : wellName ( ) const
{
return m_wellPath - > name ( ) ;
}