2019-09-19 04:39:32 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- Equinor ASA
|
|
|
|
//
|
|
|
|
// 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 "RicSummaryPlotTemplateTools.h"
|
|
|
|
|
2019-09-30 06:28:08 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
2019-09-19 04:39:32 -05:00
|
|
|
#include "RiaLogging.h"
|
2019-10-30 04:41:38 -05:00
|
|
|
#include "RiaPreferences.h"
|
2022-01-10 07:51:31 -06:00
|
|
|
#include "RiaSummaryAddressAnalyzer.h"
|
2019-09-19 04:39:32 -05:00
|
|
|
|
2022-04-06 10:39:07 -05:00
|
|
|
#include "PlotBuilderCommands/RicSummaryPlotBuilder.h"
|
2019-09-30 07:05:19 -05:00
|
|
|
#include "RicSelectPlotTemplateUi.h"
|
2019-09-30 06:28:08 -05:00
|
|
|
|
2019-09-29 05:42:38 -05:00
|
|
|
#include "RifSummaryReaderInterface.h"
|
2019-09-30 06:28:08 -05:00
|
|
|
|
|
|
|
#include "PlotTemplates/RimPlotTemplateFileItem.h"
|
|
|
|
#include "RimDialogData.h"
|
2019-10-04 11:46:30 -05:00
|
|
|
#include "RimEnsembleCurveSet.h"
|
|
|
|
#include "RimEnsembleCurveSetCollection.h"
|
2019-09-29 05:42:38 -05:00
|
|
|
#include "RimMainPlotCollection.h"
|
|
|
|
#include "RimProject.h"
|
2022-04-01 07:04:46 -05:00
|
|
|
#include "RimSummaryAddressCollection.h"
|
2019-09-29 05:42:38 -05:00
|
|
|
#include "RimSummaryCase.h"
|
2019-09-19 04:39:32 -05:00
|
|
|
#include "RimSummaryCurve.h"
|
2022-04-01 07:04:46 -05:00
|
|
|
#include "RimSummaryMultiPlot.h"
|
2019-09-19 04:39:32 -05:00
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
|
2019-09-30 06:28:08 -05:00
|
|
|
#include "RiuPlotMainWindow.h"
|
|
|
|
|
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
2019-10-04 11:46:30 -05:00
|
|
|
#include "cafSelectionManager.h"
|
2019-10-07 00:47:44 -05:00
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
#include <QFile>
|
2019-10-07 05:05:14 -05:00
|
|
|
#include <QRegularExpression>
|
2019-09-19 04:39:32 -05:00
|
|
|
|
2022-04-01 07:04:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryMultiPlot* RicSummaryPlotTemplateTools::createMultiPlotFromTemplateFile( const QString& fileName )
|
|
|
|
{
|
|
|
|
QFile importFile( fileName );
|
|
|
|
if ( !importFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
|
|
{
|
|
|
|
RiaLogging::error( QString( "Create Plot from Template : Could not open the file: %1" ).arg( fileName ) );
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream stream( &importFile );
|
|
|
|
|
|
|
|
QString objectAsText = stream.readAll();
|
|
|
|
|
|
|
|
caf::PdmObjectHandle* obj =
|
|
|
|
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText,
|
|
|
|
caf::PdmDefaultObjectFactory::instance(),
|
|
|
|
true );
|
|
|
|
|
|
|
|
return dynamic_cast<RimSummaryMultiPlot*>( obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryMultiPlot* summaryMultiPlot,
|
|
|
|
const std::vector<RimSummaryCase*>& selectedSummaryCases,
|
|
|
|
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles,
|
|
|
|
const std::vector<QString>& wellNames,
|
2022-04-07 14:06:40 -05:00
|
|
|
const std::vector<QString>& groupNames,
|
|
|
|
const std::vector<QString>& regions )
|
2022-04-01 07:04:46 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
// Assumes this plot is inserted into the project. This is required when assigning the ptrFields
|
|
|
|
RimProject* proj = nullptr;
|
|
|
|
summaryMultiPlot->firstAncestorOfType( proj );
|
|
|
|
CAF_ASSERT( proj );
|
|
|
|
|
|
|
|
auto plots = summaryMultiPlot->plots();
|
|
|
|
for ( auto p : plots )
|
|
|
|
{
|
|
|
|
auto summaryPlot = dynamic_cast<RimSummaryPlot*>( p );
|
|
|
|
if ( summaryPlot )
|
2022-04-07 14:06:40 -05:00
|
|
|
setValuesForPlaceholders( summaryPlot, selectedSummaryCases, selectedEnsembles, wellNames, groupNames, regions );
|
2022-04-01 07:04:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryPlot* summaryPlot,
|
|
|
|
const std::vector<RimSummaryCase*>& selectedSummaryCases,
|
|
|
|
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles,
|
|
|
|
const std::vector<QString>& wellNames,
|
2022-04-07 14:06:40 -05:00
|
|
|
const std::vector<QString>& groupNames,
|
|
|
|
const std::vector<QString>& regions )
|
2022-04-01 07:04:46 -05:00
|
|
|
{
|
|
|
|
// Assumes this plot is inserted into the project. This is required when assigning the ptrFields
|
|
|
|
RimProject* proj = nullptr;
|
|
|
|
summaryPlot->firstAncestorOfType( proj );
|
|
|
|
CAF_ASSERT( proj );
|
|
|
|
|
|
|
|
{
|
|
|
|
// Replace single summary curves data sources
|
|
|
|
|
|
|
|
auto summaryCurves = summaryPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS );
|
|
|
|
for ( const auto& curve : summaryCurves )
|
|
|
|
{
|
|
|
|
auto fieldHandle = curve->findField( RicSummaryPlotTemplateTools::summaryCaseFieldKeyword() );
|
|
|
|
if ( fieldHandle )
|
|
|
|
{
|
|
|
|
bool conversionOk = false;
|
|
|
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase();
|
|
|
|
|
|
|
|
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
|
|
|
int indexValue =
|
|
|
|
RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk );
|
|
|
|
|
|
|
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( selectedSummaryCases.size() ) )
|
|
|
|
{
|
|
|
|
auto summaryCaseY = selectedSummaryCases[static_cast<int>( indexValue )];
|
|
|
|
curve->setSummaryCaseY( summaryCaseY );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace placeholders with object names from selection
|
|
|
|
auto curveAdr = curve->summaryAddressY();
|
|
|
|
setPlaceholderWellName( &curveAdr, wellNames );
|
2022-04-07 14:06:40 -05:00
|
|
|
setPlaceholderGroupName( &curveAdr, groupNames );
|
2022-04-01 07:04:46 -05:00
|
|
|
setPlaceholderRegion( &curveAdr, regions );
|
|
|
|
curve->setSummaryAddressY( curveAdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( const auto& curveSet : summaryPlot->curveSets() )
|
|
|
|
{
|
|
|
|
const QString summaryGroupFieldKeyword = RicSummaryPlotTemplateTools::summaryGroupFieldKeyword();
|
|
|
|
|
|
|
|
auto fieldHandle = curveSet->findField( summaryGroupFieldKeyword );
|
|
|
|
if ( fieldHandle )
|
|
|
|
{
|
|
|
|
bool conversionOk = false;
|
|
|
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup();
|
|
|
|
|
|
|
|
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
|
|
|
int indexValue =
|
|
|
|
RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk );
|
|
|
|
|
|
|
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( selectedEnsembles.size() ) )
|
|
|
|
{
|
|
|
|
auto ensembleCase = selectedEnsembles[static_cast<int>( indexValue )];
|
|
|
|
curveSet->setSummaryCaseCollection( ensembleCase );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace placeholders with object names from selection
|
|
|
|
auto curveAdr = curveSet->summaryAddress();
|
|
|
|
setPlaceholderWellName( &curveAdr, wellNames );
|
2022-04-07 14:06:40 -05:00
|
|
|
setPlaceholderGroupName( &curveAdr, groupNames );
|
2022-04-01 07:04:46 -05:00
|
|
|
setPlaceholderRegion( &curveAdr, regions );
|
|
|
|
curveSet->setSummaryAddress( curveAdr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const QString& fileName )
|
|
|
|
{
|
|
|
|
QFile importFile( fileName );
|
|
|
|
if ( !importFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
|
|
{
|
|
|
|
RiaLogging::error( QString( "Create Plot from Template : Could not open the file: %1" ).arg( fileName ) );
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream stream( &importFile );
|
|
|
|
|
|
|
|
QString objectAsText = stream.readAll();
|
|
|
|
|
|
|
|
caf::PdmObjectHandle* obj =
|
2019-11-14 13:48:11 -06:00
|
|
|
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText,
|
|
|
|
caf::PdmDefaultObjectFactory::instance(),
|
|
|
|
true );
|
2019-09-19 04:39:32 -05:00
|
|
|
|
2021-11-08 02:55:58 -06:00
|
|
|
auto* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
|
2019-09-19 04:39:32 -05:00
|
|
|
if ( newSummaryPlot )
|
|
|
|
{
|
2021-11-08 02:55:58 -06:00
|
|
|
bool isTemplateBefore_2021_06 = !objectAsText.contains( "<PlotCurveAppearance>" );
|
|
|
|
if ( isTemplateBefore_2021_06 )
|
|
|
|
{
|
|
|
|
for ( auto c : newSummaryPlot->summaryAndEnsembleCurves() )
|
|
|
|
{
|
|
|
|
// Special handling of appearance settings because we do not have any support for file version of
|
|
|
|
// plot templates
|
|
|
|
// https://github.com/OPM/ResInsight/issues/8257
|
|
|
|
c->updateCurveAppearanceForFilesOlderThan_2021_06();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
return newSummaryPlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-09-29 05:42:38 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
|
2019-10-04 11:46:30 -05:00
|
|
|
RimSummaryPlot* summaryPlot,
|
|
|
|
const std::vector<RimSummaryCase*>& selectedSummaryCases,
|
|
|
|
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles )
|
2019-09-29 05:42:38 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
if ( !summaryPlot ) return;
|
|
|
|
|
|
|
|
if ( selectedSummaryCases.empty() && selectedEnsembles.empty() ) return;
|
|
|
|
|
2022-04-06 10:39:07 -05:00
|
|
|
RimSummaryMultiPlot* multiPlot = RicSummaryPlotBuilder::createAndAppendSingleSummaryMultiPlot( summaryPlot );
|
2019-10-08 00:27:45 -05:00
|
|
|
summaryPlot->resolveReferencesRecursively();
|
|
|
|
summaryPlot->initAfterReadRecursively();
|
|
|
|
|
2019-09-29 05:42:38 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
// Replace single summary curves data sources
|
|
|
|
|
|
|
|
auto summaryCurves = summaryPlot->summaryCurves();
|
2019-09-29 05:42:38 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
const QString summaryFieldKeyword = RicSummaryPlotTemplateTools::summaryCaseFieldKeyword();
|
2019-09-29 05:42:38 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
int maximumIndexValue = -1;
|
|
|
|
for ( const auto& curve : summaryCurves )
|
2019-09-29 05:42:38 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
auto fieldHandle = curve->findField( summaryFieldKeyword );
|
|
|
|
if ( fieldHandle )
|
|
|
|
{
|
|
|
|
bool conversionOk = false;
|
|
|
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase();
|
2019-10-04 11:46:30 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
2020-02-12 04:43:15 -06:00
|
|
|
int indexValue =
|
|
|
|
RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk );
|
2019-10-07 03:30:17 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
maximumIndexValue = std::max( maximumIndexValue, indexValue );
|
2019-10-07 05:05:14 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( selectedSummaryCases.size() ) )
|
|
|
|
{
|
|
|
|
auto summaryCaseY = selectedSummaryCases[static_cast<int>( indexValue )];
|
|
|
|
curve->setSummaryCaseY( summaryCaseY );
|
2019-10-04 11:46:30 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
auto currentAddressY = curve->summaryAddressY();
|
|
|
|
if ( summaryCaseY->summaryReader() && !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) )
|
2019-10-07 05:05:14 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses();
|
2019-09-29 05:42:38 -05:00
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
auto candidate =
|
|
|
|
RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY, allAddresses );
|
2019-10-08 00:27:45 -05:00
|
|
|
if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID )
|
2019-09-29 05:42:38 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
curve->setSummaryAddressY( candidate );
|
2019-09-29 05:42:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 04:57:30 -05:00
|
|
|
if ( selectedSummaryCases.size() > static_cast<size_t>( maximumIndexValue + 1 ) )
|
2019-10-04 11:46:30 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
// Use the curve style of the last curve in template, and duplicate this for remaining data sources
|
2019-10-07 03:30:17 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
if ( !summaryCurves.empty() )
|
2019-10-04 11:46:30 -05:00
|
|
|
{
|
2019-10-08 00:27:45 -05:00
|
|
|
auto lastSummaryCurve = summaryCurves.back();
|
|
|
|
|
|
|
|
for ( size_t i = maximumIndexValue; i < selectedSummaryCases.size(); i++ )
|
2019-10-04 11:46:30 -05:00
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
auto newCurve =
|
|
|
|
dynamic_cast<RimSummaryCurve*>( lastSummaryCurve->xmlCapability()->copyByXmlSerialization(
|
2019-10-08 00:27:45 -05:00
|
|
|
caf::PdmDefaultObjectFactory::instance() ) );
|
2019-10-04 11:46:30 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
auto summaryCaseY = selectedSummaryCases[i];
|
|
|
|
newCurve->setSummaryCaseY( summaryCaseY );
|
|
|
|
summaryPlot->addCurveAndUpdate( newCurve );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-04 11:46:30 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
{
|
|
|
|
// Replace ensemble data sources
|
|
|
|
|
|
|
|
auto summaryCurveSets = summaryPlot->ensembleCurveSetCollection()->curveSets();
|
|
|
|
|
|
|
|
const QString summaryGroupFieldKeyword = RicSummaryPlotTemplateTools::summaryGroupFieldKeyword();
|
|
|
|
|
|
|
|
int maximumIndexValue = -1;
|
|
|
|
|
|
|
|
for ( const auto& curveSet : summaryCurveSets )
|
|
|
|
{
|
|
|
|
auto fieldHandle = curveSet->findField( summaryGroupFieldKeyword );
|
|
|
|
if ( fieldHandle )
|
|
|
|
{
|
|
|
|
bool conversionOk = false;
|
|
|
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup();
|
|
|
|
|
|
|
|
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
2020-02-12 04:43:15 -06:00
|
|
|
int indexValue =
|
|
|
|
RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk );
|
2019-10-08 00:27:45 -05:00
|
|
|
|
|
|
|
maximumIndexValue = std::max( maximumIndexValue, indexValue );
|
|
|
|
|
2019-10-08 01:18:09 -05:00
|
|
|
if ( conversionOk && indexValue < static_cast<int>( selectedEnsembles.size() ) )
|
2019-10-08 00:27:45 -05:00
|
|
|
{
|
|
|
|
auto summaryCaseY = selectedEnsembles[indexValue];
|
|
|
|
curveSet->setSummaryCaseCollection( summaryCaseY );
|
2019-10-04 11:46:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 04:57:30 -05:00
|
|
|
if ( selectedEnsembles.size() > static_cast<size_t>( maximumIndexValue + 1 ) )
|
2019-10-08 00:27:45 -05:00
|
|
|
{
|
|
|
|
// Use the curve style of the last curve in template, and duplicate this for remaining data sources
|
|
|
|
|
|
|
|
if ( !summaryCurveSets.empty() )
|
|
|
|
{
|
|
|
|
auto lastSummaryCurveSet = summaryCurveSets.back();
|
|
|
|
|
|
|
|
for ( size_t i = maximumIndexValue; i < selectedEnsembles.size(); i++ )
|
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
auto newCurveSet =
|
|
|
|
dynamic_cast<RimEnsembleCurveSet*>( lastSummaryCurveSet->xmlCapability()->copyByXmlSerialization(
|
2019-10-08 00:27:45 -05:00
|
|
|
caf::PdmDefaultObjectFactory::instance() ) );
|
2019-09-29 05:42:38 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
auto ensembleDataSource = selectedEnsembles[i];
|
|
|
|
newCurveSet->setSummaryCaseCollection( ensembleDataSource );
|
2019-09-29 05:42:38 -05:00
|
|
|
|
2019-10-08 00:27:45 -05:00
|
|
|
summaryPlot->ensembleCurveSetCollection()->addCurveSet( newCurveSet );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-29 05:42:38 -05:00
|
|
|
}
|
2019-10-08 00:27:45 -05:00
|
|
|
|
2022-04-06 10:39:07 -05:00
|
|
|
multiPlot->updateConnectedEditors();
|
2019-10-08 00:27:45 -05:00
|
|
|
|
|
|
|
summaryPlot->loadDataAndUpdate();
|
2019-09-29 05:42:38 -05:00
|
|
|
}
|
|
|
|
|
2019-09-19 04:39:32 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:43:15 -06:00
|
|
|
QString RicSummaryPlotTemplateTools::htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot,
|
|
|
|
const std::set<RifEclipseSummaryAddress>& selectedSummaryAddresses,
|
|
|
|
const std::vector<caf::PdmObject*>& selectedSources )
|
2019-09-19 04:39:32 -05:00
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
2022-01-10 07:51:31 -06:00
|
|
|
RiaSummaryAddressAnalyzer selectionAnalyzer;
|
2019-09-19 04:39:32 -05:00
|
|
|
|
2019-10-04 02:09:22 -05:00
|
|
|
selectionAnalyzer.appendAddresses( selectedSummaryAddresses );
|
2019-09-19 04:39:32 -05:00
|
|
|
|
|
|
|
if ( templatePlot )
|
|
|
|
{
|
2022-01-10 07:51:31 -06:00
|
|
|
std::set<QString> templateSources;
|
|
|
|
RiaSummaryAddressAnalyzer templateAnalyzer;
|
2019-09-19 04:39:32 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
std::set<RifEclipseSummaryAddress> templateAddresses;
|
|
|
|
|
|
|
|
for ( const auto& curve : templatePlot->summaryCurves() )
|
|
|
|
{
|
|
|
|
auto adr = curve->summaryAddressY();
|
|
|
|
templateAddresses.insert( adr );
|
|
|
|
|
|
|
|
auto fieldHandle = curve->findField( "SummaryCase" );
|
|
|
|
if ( fieldHandle )
|
|
|
|
{
|
|
|
|
auto test = fieldHandle->xmlCapability()->referenceString();
|
|
|
|
templateSources.insert( test );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:09:22 -05:00
|
|
|
templateAnalyzer.appendAddresses( templateAddresses );
|
2019-09-19 04:39:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
text += "<b> Requirements </b><br>";
|
|
|
|
|
|
|
|
if ( !templateSources.empty() )
|
|
|
|
{
|
|
|
|
QString itemText = "Source Cases";
|
|
|
|
size_t requiredCount = templateSources.size();
|
|
|
|
size_t selectedCount = selectedSources.size();
|
|
|
|
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !templateAnalyzer.wellNames().empty() )
|
|
|
|
{
|
|
|
|
QString itemText = "Wells";
|
|
|
|
size_t requiredCount = templateAnalyzer.wellNames().size();
|
|
|
|
size_t selectedCount = selectionAnalyzer.wellNames().size();
|
|
|
|
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:06:40 -05:00
|
|
|
if ( !templateAnalyzer.groupNames().empty() )
|
2019-09-19 04:39:32 -05:00
|
|
|
{
|
2022-04-07 14:06:40 -05:00
|
|
|
QString itemText = "Groups";
|
|
|
|
size_t requiredCount = templateAnalyzer.groupNames().size();
|
|
|
|
size_t selectedCount = selectionAnalyzer.groupNames().size();
|
2019-09-19 04:39:32 -05:00
|
|
|
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !templateAnalyzer.regionNumbers().empty() )
|
|
|
|
{
|
|
|
|
QString itemText = "Regions";
|
|
|
|
size_t requiredCount = templateAnalyzer.regionNumbers().size();
|
|
|
|
size_t selectedCount = selectionAnalyzer.regionNumbers().size();
|
|
|
|
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:43:15 -06:00
|
|
|
QString RicSummaryPlotTemplateTools::htmlTextFromCount( const QString& itemText, size_t requiredItemCount, size_t selectionCount )
|
2019-09-19 04:39:32 -05:00
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
QString colorString = "green";
|
|
|
|
|
|
|
|
if ( selectionCount < requiredItemCount )
|
|
|
|
colorString = "red";
|
|
|
|
else if ( selectionCount > requiredItemCount )
|
|
|
|
colorString = "orange";
|
|
|
|
|
|
|
|
text += QString( "<b><font color='%1'>" ).arg( colorString );
|
|
|
|
text += QString( "%1 : %2 selected (%3 required)\n" ).arg( itemText ).arg( selectionCount ).arg( requiredItemCount );
|
|
|
|
text += "</font></b>";
|
|
|
|
|
|
|
|
text += "<br>";
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2019-09-29 05:42:38 -05:00
|
|
|
|
2019-09-30 06:28:08 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RicSummaryPlotTemplateTools::selectPlotTemplatePath()
|
|
|
|
{
|
2019-12-17 00:32:19 -06:00
|
|
|
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
|
|
|
|
RicSelectPlotTemplateUi ui;
|
2019-09-30 06:28:08 -05:00
|
|
|
|
2019-12-17 00:32:19 -06:00
|
|
|
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, &ui, "Select Plot Template", "" );
|
2019-10-30 04:42:16 -05:00
|
|
|
propertyDialog.resize( QSize( 400, 600 ) );
|
2019-09-30 06:28:08 -05:00
|
|
|
|
2019-12-17 00:32:19 -06:00
|
|
|
if ( propertyDialog.exec() == QDialog::Accepted && !ui.selectedPlotTemplates().empty() )
|
2019-09-30 06:28:08 -05:00
|
|
|
{
|
2019-12-17 00:32:19 -06:00
|
|
|
QString fileName = ui.selectedPlotTemplates().front()->absoluteFilePath();
|
2019-09-30 06:28:08 -05:00
|
|
|
|
2021-04-28 03:29:53 -05:00
|
|
|
RiaPreferences::current()->setDefaultPlotTemplatePath( fileName );
|
|
|
|
RiaPreferences::current()->writePreferencesToApplicationStore();
|
2019-10-30 04:41:38 -05:00
|
|
|
|
2019-09-30 06:28:08 -05:00
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
2022-04-01 07:04:46 -05:00
|
|
|
return {};
|
2019-09-30 06:28:08 -05:00
|
|
|
}
|
|
|
|
|
2019-10-04 11:46:30 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimSummaryCase*> RicSummaryPlotTemplateTools::selectedSummaryCases()
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryCase*> objects;
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects );
|
|
|
|
|
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimSummaryCaseCollection*> RicSummaryPlotTemplateTools::selectedSummaryCaseCollections()
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryCaseCollection*> objects;
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects );
|
|
|
|
|
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
2022-04-01 07:04:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimSummaryAddressCollection*> RicSummaryPlotTemplateTools::selectedSummaryAddressCollections()
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryAddressCollection*> objects;
|
|
|
|
caf::SelectionManager::instance()->objectsByType( &objects );
|
|
|
|
|
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
2019-10-07 03:30:17 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RicSummaryPlotTemplateTools::summaryCaseFieldKeyword()
|
|
|
|
{
|
|
|
|
return "SummaryCase";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-10-08 00:27:45 -05:00
|
|
|
QString RicSummaryPlotTemplateTools::summaryGroupFieldKeyword()
|
2019-10-07 03:30:17 -05:00
|
|
|
{
|
|
|
|
return "SummaryGroup";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCase()
|
|
|
|
{
|
2022-04-01 07:04:46 -05:00
|
|
|
return "__CASE_NAME__";
|
2019-10-07 03:30:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup()
|
|
|
|
{
|
2022-04-01 07:04:46 -05:00
|
|
|
return "__ENSEMBLE_NAME__";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RicSummaryPlotTemplateTools::placeholderTextForWell()
|
|
|
|
{
|
|
|
|
return "__WELL_NAME__";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-04-07 14:06:40 -05:00
|
|
|
QString RicSummaryPlotTemplateTools::placeholderTextForGroup()
|
2022-04-01 07:04:46 -05:00
|
|
|
{
|
|
|
|
return "__WELL_GROUP__";
|
2019-10-07 03:30:17 -05:00
|
|
|
}
|
|
|
|
|
2019-09-29 05:42:38 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RifEclipseSummaryAddress
|
|
|
|
RicSummaryPlotTemplateTools::firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress,
|
|
|
|
const std::set<RifEclipseSummaryAddress>& allAddresses )
|
|
|
|
{
|
|
|
|
for ( const auto& a : allAddresses )
|
|
|
|
{
|
|
|
|
if ( sourceAddress.quantityName() == a.quantityName() )
|
|
|
|
{
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 07:04:46 -05:00
|
|
|
return {};
|
2019-09-29 05:42:38 -05:00
|
|
|
}
|
2019-10-07 05:05:14 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
int RicSummaryPlotTemplateTools::findValueForKeyword( const QString& keyword, const QString& valueString, bool* ok )
|
|
|
|
{
|
|
|
|
// Example string : "CASE_NAME 1"
|
|
|
|
// Will match the string specified by keyword, and return the value captured by the regexp
|
|
|
|
|
|
|
|
QString regexpString = QString( "%1 (\\d++)" ).arg( keyword );
|
|
|
|
QRegularExpression rx( regexpString );
|
|
|
|
|
|
|
|
auto match = rx.match( valueString );
|
|
|
|
if ( match.hasMatch() )
|
|
|
|
{
|
|
|
|
QString integerAsText = match.captured( 1 );
|
|
|
|
|
|
|
|
if ( !integerAsText.isEmpty() )
|
|
|
|
{
|
|
|
|
int integerValue = integerAsText.toInt();
|
|
|
|
|
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
*ok = true;
|
|
|
|
}
|
|
|
|
return integerValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
*ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2022-04-01 07:04:46 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotTemplateTools::setPlaceholderWellName( RifEclipseSummaryAddress* summaryAddress,
|
|
|
|
const std::vector<QString>& wellNames )
|
|
|
|
{
|
|
|
|
if ( wellNames.empty() ) return;
|
|
|
|
|
|
|
|
auto sourceWellName = QString::fromStdString( summaryAddress->wellName() );
|
|
|
|
bool conversionOk = false;
|
|
|
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForWell();
|
|
|
|
|
|
|
|
int indexValue = RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, sourceWellName, &conversionOk );
|
|
|
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( wellNames.size() ) )
|
|
|
|
{
|
|
|
|
summaryAddress->setWellName( wellNames[indexValue].toStdString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-04-07 14:06:40 -05:00
|
|
|
void RicSummaryPlotTemplateTools::setPlaceholderGroupName( RifEclipseSummaryAddress* summaryAddress,
|
|
|
|
const std::vector<QString>& groupNames )
|
2022-04-01 07:04:46 -05:00
|
|
|
{
|
2022-04-07 14:06:40 -05:00
|
|
|
if ( groupNames.empty() ) return;
|
2022-04-01 07:04:46 -05:00
|
|
|
|
2022-04-07 14:06:40 -05:00
|
|
|
auto sourceGroupName = QString::fromStdString( summaryAddress->groupName() );
|
|
|
|
bool conversionOk = false;
|
|
|
|
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForGroup();
|
2022-04-01 07:04:46 -05:00
|
|
|
|
2022-04-07 14:06:40 -05:00
|
|
|
int indexValue = RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, sourceGroupName, &conversionOk );
|
|
|
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( groupNames.size() ) )
|
2022-04-01 07:04:46 -05:00
|
|
|
{
|
2022-04-07 14:06:40 -05:00
|
|
|
summaryAddress->setGroupName( groupNames[indexValue].toStdString() );
|
2022-04-01 07:04:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotTemplateTools::setPlaceholderRegion( RifEclipseSummaryAddress* summaryAddress,
|
|
|
|
const std::vector<QString>& regions )
|
|
|
|
{
|
|
|
|
CAF_ASSERT( summaryAddress );
|
|
|
|
if ( regions.empty() ) return;
|
|
|
|
|
|
|
|
int indexValue = summaryAddress->regionNumber();
|
|
|
|
if ( indexValue < -1 )
|
|
|
|
{
|
|
|
|
indexValue = -( indexValue - 2 );
|
|
|
|
|
|
|
|
bool conversionOk = false;
|
|
|
|
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( regions.size() ) )
|
|
|
|
{
|
|
|
|
summaryAddress->setRegion( regions[indexValue].toInt() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|