2019-08-09 02:54:55 -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 "RicSummaryPlotFeatureImpl.h"
|
|
|
|
|
|
|
|
#include "RimSummaryCurve.h"
|
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
#include "RimSummaryPlotCollection.h"
|
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimMainPlotCollection.h"
|
2019-08-13 04:48:57 -05:00
|
|
|
#include "RimSummaryCase.h"
|
2019-08-09 02:54:55 -05:00
|
|
|
|
|
|
|
#include "RiuPlotMainWindowTools.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaColorTables.h"
|
2019-08-09 06:15:32 -05:00
|
|
|
#include "RiaPreferences.h"
|
2019-08-13 04:48:57 -05:00
|
|
|
#include "RiaEclipseFileNameTools.h"
|
|
|
|
|
2019-08-09 06:15:32 -05:00
|
|
|
#include "RifSummaryReaderInterface.h"
|
2019-08-13 04:48:57 -05:00
|
|
|
|
|
|
|
#include "RicImportGeneralDataFeature.h"
|
|
|
|
|
|
|
|
#include <QStringList>
|
2019-08-09 02:54:55 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryCurve* RicSummaryPlotFeatureImpl::addDefaultCurveToPlot(RimSummaryPlot* plot, RimSummaryCase* summaryCase)
|
|
|
|
{
|
|
|
|
if (plot)
|
|
|
|
{
|
2019-08-09 06:15:32 -05:00
|
|
|
RifEclipseSummaryAddress defaultAddressToUse;
|
|
|
|
|
|
|
|
QString curvesTextFilter = RiaApplication::instance()->preferences()->defaultSummaryCurvesTextFilter;
|
|
|
|
QStringList curveFilters = curvesTextFilter.split(";", QString::SkipEmptyParts);
|
|
|
|
|
|
|
|
if ( curveFilters.size() )
|
|
|
|
{
|
|
|
|
const std::set<RifEclipseSummaryAddress>& addrs = summaryCase->summaryReader()->allResultAddresses();
|
|
|
|
|
|
|
|
for ( const auto & addr : addrs )
|
|
|
|
{
|
|
|
|
const QString& filter = curveFilters[0];
|
|
|
|
{
|
|
|
|
if ( addr.isUiTextMatchingFilterText(filter) )
|
|
|
|
{
|
|
|
|
defaultAddressToUse = addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 02:54:55 -05:00
|
|
|
RimSummaryCurve* newCurve = new RimSummaryCurve();
|
|
|
|
|
|
|
|
// Use same counting as RicNewSummaryEnsembleCurveSetFeature::onActionTriggered
|
|
|
|
cvf::Color3f curveColor = RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f(plot->singleColorCurveCount());
|
|
|
|
newCurve->setColor(curveColor);
|
|
|
|
|
|
|
|
plot->addCurveNoUpdate(newCurve);
|
|
|
|
|
|
|
|
if (summaryCase)
|
|
|
|
{
|
|
|
|
newCurve->setSummaryCaseY(summaryCase);
|
|
|
|
}
|
|
|
|
|
2019-08-09 06:15:32 -05:00
|
|
|
newCurve->setSummaryAddressYAndApplyInterpolation(defaultAddressToUse);
|
2019-08-09 02:54:55 -05:00
|
|
|
|
|
|
|
return newCurve;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-08-09 06:15:32 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimSummaryCurve*> RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot(RimSummaryPlot* plot, RimSummaryCase* summaryCase)
|
|
|
|
{
|
|
|
|
std::vector<RimSummaryCurve*> defaultCurves;
|
|
|
|
|
|
|
|
QString curvesTextFilter = RiaApplication::instance()->preferences()->defaultSummaryCurvesTextFilter;
|
|
|
|
QStringList curveFilters = curvesTextFilter.split(";", QString::SkipEmptyParts);
|
|
|
|
|
2019-08-13 07:16:51 -05:00
|
|
|
return addCurvesFromAddressFiltersToPlot(curveFilters, plot, summaryCase, false);
|
2019-08-09 06:15:32 -05:00
|
|
|
}
|
|
|
|
|
2019-08-09 02:54:55 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotFeatureImpl::ensureAtLeastOnePlot(RimSummaryPlotCollection* summaryPlotCollection, RimSummaryCase* summaryCase)
|
|
|
|
{
|
|
|
|
if (summaryPlotCollection && summaryCase)
|
|
|
|
{
|
|
|
|
if (summaryPlotCollection->summaryPlots.empty())
|
|
|
|
{
|
|
|
|
createDefaultSummaryPlot(summaryCase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicSummaryPlotFeatureImpl::createDefaultSummaryPlot( RimSummaryCase* summaryCase)
|
|
|
|
{
|
|
|
|
RimSummaryPlotCollection* summaryPlotCollection = RiaApplication::instance()->project()->mainPlotCollection->summaryPlotCollection();
|
|
|
|
|
2019-08-13 04:48:57 -05:00
|
|
|
if (summaryPlotCollection && summaryCase && !RiaApplication::instance()->preferences()->defaultSummaryCurvesTextFilter().isEmpty())
|
2019-08-09 02:54:55 -05:00
|
|
|
{
|
|
|
|
auto plot = summaryPlotCollection->createSummaryPlotWithAutoTitle();
|
|
|
|
|
2019-08-09 06:15:32 -05:00
|
|
|
std::vector<RimSummaryCurve*> curves = RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot(plot, summaryCase);
|
|
|
|
|
|
|
|
plot->applyDefaultCurveAppearances();
|
2019-08-09 02:54:55 -05:00
|
|
|
plot->loadDataAndUpdate();
|
|
|
|
|
|
|
|
summaryPlotCollection->updateConnectedEditors();
|
|
|
|
|
2019-08-09 06:15:32 -05:00
|
|
|
caf::PdmObject* itemToSelect = plot;
|
|
|
|
if (curves.size()) itemToSelect = curves[0];
|
|
|
|
|
|
|
|
RiuPlotMainWindowTools::setExpanded(itemToSelect);
|
|
|
|
RiuPlotMainWindowTools::selectAsCurrentItem(itemToSelect);
|
2019-08-09 02:54:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 04:48:57 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryPlot* RicSummaryPlotFeatureImpl::createSummaryPlotFromCommandLine(const QStringList & arguments)
|
|
|
|
{
|
|
|
|
RimSummaryPlot* plot = RicSummaryPlotFeatureImpl::createSummaryPlotFromArgumentLine(arguments);
|
|
|
|
return plot;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryPlot* RicSummaryPlotFeatureImpl::createSummaryPlotFromArgumentLine(const QStringList & arguments)
|
|
|
|
{
|
|
|
|
// Split arguments in options, vectors and filenames
|
|
|
|
|
|
|
|
QStringList options;
|
|
|
|
QStringList summaryAddressFilters;
|
|
|
|
QStringList summaryFiles;
|
|
|
|
|
|
|
|
|
|
|
|
for (int optionIdx = 0; optionIdx < arguments.size(); ++optionIdx)
|
|
|
|
{
|
|
|
|
if (arguments[optionIdx].startsWith("-"))
|
|
|
|
{
|
|
|
|
if (arguments[optionIdx] == "-help")
|
|
|
|
{
|
|
|
|
RiaApplication::instance()->showFormattedTextInMessageBoxOrConsole(
|
|
|
|
"The --summaryplot option has the following syntax:\n"
|
|
|
|
"\n"
|
|
|
|
"[<plotOptions>] <eclipsesummaryvectors> [<eclipsedatafiles>]\n"
|
|
|
|
"\n"
|
|
|
|
"It Creates a summary plot using all the <eclipsedatafiles>, and all the summary vectors defined in <eclipsesummaryvectors>.\n"
|
|
|
|
"The <eclipsesummaryvectors> has the syntax <vectorname>[:<item>[:<subitem>[:i,j,k]]] and can be repeated.\n"
|
|
|
|
"Wildcards can also be used, eg. \"WOPT:*\" to select the total oil production from all the wells.\n"
|
|
|
|
"The <eclipsedatafiles> can be written with or without extension. Only the corresponding SMSPEC file will be opened for each case.\n"
|
|
|
|
"\n"
|
|
|
|
"The summary plot options are: \n"
|
|
|
|
" -help\t Show this help text and ignore the rest of the options.\n"
|
2019-08-13 07:16:51 -05:00
|
|
|
" -nl Omit legend in plot.\n"
|
|
|
|
" -h Include history vectors. Will be read from the summary file if the vectors exist.\n"
|
|
|
|
" Only history vectors from the first summary case in the project will be included.\n"
|
2019-08-13 04:48:57 -05:00
|
|
|
);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
options.push_back(arguments[optionIdx]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RiaEclipseFileNameTools nameTool(arguments[optionIdx]);
|
|
|
|
QString smSpecFileName = nameTool.findRelatedSummarySpecFile();
|
|
|
|
if (smSpecFileName != "")
|
|
|
|
{
|
|
|
|
summaryFiles.push_back(smSpecFileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
summaryAddressFilters.push_back(arguments[optionIdx]) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-09 02:54:55 -05:00
|
|
|
|
2019-08-13 04:48:57 -05:00
|
|
|
if ( summaryAddressFilters.empty() )
|
|
|
|
{
|
|
|
|
RiaLogging::error("Needs at least one summary vector to create a plot.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( summaryFiles.size() )
|
|
|
|
{
|
|
|
|
RicImportGeneralDataFeature::OpenCaseResults results =
|
|
|
|
RicImportGeneralDataFeature::openEclipseFilesFromFileNames(summaryFiles, false);
|
|
|
|
}
|
2019-08-13 07:16:51 -05:00
|
|
|
bool hideLegend = options.contains("-nl");
|
|
|
|
bool addHistoryCurves = options.contains("-h");
|
2019-08-13 04:48:57 -05:00
|
|
|
|
|
|
|
std::vector<RimSummaryCase*> summaryCasesToUse = RiaApplication::instance()->project()->allSummaryCases();
|
|
|
|
|
|
|
|
if ( summaryCasesToUse.size() )
|
|
|
|
{
|
|
|
|
RimSummaryPlotCollection* sumPlotColl = RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
|
|
|
RimSummaryPlot* newPlot = sumPlotColl->createSummaryPlotWithAutoTitle();
|
|
|
|
|
|
|
|
for (RimSummaryCase* sumCase : summaryCasesToUse)
|
|
|
|
{
|
2019-08-13 07:16:51 -05:00
|
|
|
RicSummaryPlotFeatureImpl::addCurvesFromAddressFiltersToPlot(summaryAddressFilters, newPlot, sumCase, addHistoryCurves);
|
|
|
|
addHistoryCurves = false;
|
2019-08-13 04:48:57 -05:00
|
|
|
}
|
|
|
|
|
2019-08-13 07:16:51 -05:00
|
|
|
if (hideLegend)
|
2019-08-13 04:48:57 -05:00
|
|
|
{
|
|
|
|
newPlot->showLegend(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
newPlot->applyDefaultCurveAppearances();
|
|
|
|
newPlot->loadDataAndUpdate();
|
|
|
|
|
|
|
|
sumPlotColl->updateConnectedEditors();
|
|
|
|
|
|
|
|
RiuPlotMainWindowTools::setExpanded(newPlot);
|
|
|
|
RiuPlotMainWindowTools::selectAsCurrentItem(newPlot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RiaLogging::error("Needs at least one summary case to create a plot.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RimSummaryCurve*> RicSummaryPlotFeatureImpl::addCurvesFromAddressFiltersToPlot(const QStringList& curveFilters,
|
|
|
|
RimSummaryPlot* plot,
|
2019-08-13 07:16:51 -05:00
|
|
|
RimSummaryCase* summaryCase,
|
|
|
|
bool addHistoryCurves)
|
2019-08-13 04:48:57 -05:00
|
|
|
{
|
|
|
|
std::vector<RimSummaryCurve*> createdCurves;
|
|
|
|
|
|
|
|
const std::set<RifEclipseSummaryAddress>& addrs = summaryCase->summaryReader()->allResultAddresses();
|
|
|
|
std::vector<RifEclipseSummaryAddress> curveAddressesToUse;
|
2019-08-13 08:35:14 -05:00
|
|
|
int curveFilterCount = curveFilters.size();
|
|
|
|
|
|
|
|
std::vector<bool> usedFilters(curveFilterCount, false);
|
2019-08-13 04:48:57 -05:00
|
|
|
|
|
|
|
for (const auto & addr : addrs)
|
|
|
|
{
|
2019-08-13 08:35:14 -05:00
|
|
|
for (int cfIdx = 0 ; cfIdx < curveFilterCount ; ++cfIdx)
|
2019-08-13 04:48:57 -05:00
|
|
|
{
|
2019-08-13 08:35:14 -05:00
|
|
|
if ( addr.isUiTextMatchingFilterText( curveFilters[cfIdx]) )
|
2019-08-13 04:48:57 -05:00
|
|
|
{
|
|
|
|
curveAddressesToUse.push_back(addr);
|
2019-08-13 08:35:14 -05:00
|
|
|
usedFilters[cfIdx] = true;
|
2019-08-13 04:48:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 08:35:14 -05:00
|
|
|
for (int cfIdx = 0 ; cfIdx < curveFilterCount ; ++cfIdx)
|
|
|
|
{
|
|
|
|
if (!usedFilters[cfIdx])
|
|
|
|
{
|
|
|
|
RiaLogging::warning("Vector filter \"" + curveFilters[cfIdx] + "\" did not match anything in case: \"" + summaryCase->caseName() + "\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 07:16:51 -05:00
|
|
|
if (addHistoryCurves)
|
|
|
|
{
|
|
|
|
std::vector<RifEclipseSummaryAddress> historyAddressesToUse;
|
|
|
|
for (RifEclipseSummaryAddress historyAddr : curveAddressesToUse)
|
|
|
|
{
|
|
|
|
historyAddr.setQuantityName(historyAddr.quantityName() + "H");
|
|
|
|
if (addrs.count(historyAddr))
|
|
|
|
{
|
|
|
|
historyAddressesToUse.push_back(historyAddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curveAddressesToUse.insert( curveAddressesToUse.end(), historyAddressesToUse.begin(), historyAddressesToUse.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-13 04:48:57 -05:00
|
|
|
for (const auto & addr : curveAddressesToUse)
|
|
|
|
{
|
|
|
|
RimSummaryCurve* newCurve = new RimSummaryCurve();
|
|
|
|
plot->addCurveNoUpdate(newCurve);
|
|
|
|
if (summaryCase)
|
|
|
|
{
|
|
|
|
newCurve->setSummaryCaseY(summaryCase);
|
|
|
|
}
|
|
|
|
newCurve->setSummaryAddressYAndApplyInterpolation(addr);
|
|
|
|
createdCurves.push_back(newCurve);
|
|
|
|
}
|
|
|
|
|
|
|
|
return createdCurves;
|
|
|
|
}
|