From e04daa7596060ff80ed65dabf19402dddcc08cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 13 Aug 2019 11:48:57 +0200 Subject: [PATCH] #3950 Add the minimal --summaryplot commandline option. Using shell globbing for filenames, and only one additional option implemented. Avoid creating default plot when using --summaryplot --- .../Application/RiaApplication.cpp | 2 +- .../Application/RiaConsoleApplication.cpp | 2 +- .../Application/RiaGuiApplication.cpp | 8 +- .../Application/Tools/RiaArgumentParser.cpp | 7 + .../Commands/RicImportGeneralDataFeature.cpp | 12 +- .../Commands/RicImportGeneralDataFeature.h | 6 +- .../Commands/RicImportSummaryCasesFeature.cpp | 3 +- .../Commands/RicImportSummaryCasesFeature.h | 4 +- .../RicSummaryPlotFeatureImpl.cpp | 179 +++++++++++++++--- .../RicSummaryPlotFeatureImpl.h | 10 +- .../Summary/RimSummaryPlot.cpp | 8 + .../ProjectDataModel/Summary/RimSummaryPlot.h | 1 + 12 files changed, 199 insertions(+), 43 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index d8772cdcfd..f454d83071 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -289,7 +289,7 @@ bool RiaApplication::openFile(const QString& fileName) } else if (fileType & RiaDefines::ANY_ECLIPSE_FILE) { - loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames(QStringList{fileName}); + loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames(QStringList{fileName}, true); lastUsedDialogTag = RiaDefines::defaultDirectoryLabel(fileType); } diff --git a/ApplicationCode/Application/RiaConsoleApplication.cpp b/ApplicationCode/Application/RiaConsoleApplication.cpp index 8d3687a126..ddd8b733d2 100644 --- a/ApplicationCode/Application/RiaConsoleApplication.cpp +++ b/ApplicationCode/Application/RiaConsoleApplication.cpp @@ -259,7 +259,7 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments(cvf::Pr { QStringList fileNames = RicImportGeneralDataFeature::fileNamesFromCaseNames(cvfqt::Utils::toQStringList(o.values())); RicImportGeneralDataFeature::OpenCaseResults results = - RicImportGeneralDataFeature::openEclipseFilesFromFileNames(fileNames); + RicImportGeneralDataFeature::openEclipseFilesFromFileNames(fileNames, true); } if (cvf::Option o = progOpt->option("commandFile")) diff --git a/ApplicationCode/Application/RiaGuiApplication.cpp b/ApplicationCode/Application/RiaGuiApplication.cpp index 88eabb6d4c..21c9441b5b 100644 --- a/ApplicationCode/Application/RiaGuiApplication.cpp +++ b/ApplicationCode/Application/RiaGuiApplication.cpp @@ -133,6 +133,7 @@ #ifdef USE_UNIT_TESTS #include "gtest/gtest.h" #endif // USE_UNIT_TESTS +#include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h" namespace caf { @@ -657,6 +658,11 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments(cvf::Progra } } + if (cvf::Option o = progOpt->option("summaryplot")) + { + RicSummaryPlotFeatureImpl::createSummaryPlotFromArgumentLine( cvfqt::Utils::toQStringList(o.values())); + } + QString projectFileName; if (progOpt->hasOption("last")) @@ -777,7 +783,7 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments(cvf::Progra QStringList fileNames = RicImportGeneralDataFeature::fileNamesFromCaseNames(cvfqt::Utils::toQStringList(o.values())); RicImportGeneralDataFeature::OpenCaseResults results = - RicImportGeneralDataFeature::openEclipseFilesFromFileNames(fileNames); + RicImportGeneralDataFeature::openEclipseFilesFromFileNames(fileNames, true); if (results && !results.eclipseSummaryFiles.empty()) { getOrCreateAndShowMainPlotWindow(); diff --git a/ApplicationCode/Application/Tools/RiaArgumentParser.cpp b/ApplicationCode/Application/Tools/RiaArgumentParser.cpp index 5168ffcf71..f641eb8eb7 100644 --- a/ApplicationCode/Application/Tools/RiaArgumentParser.cpp +++ b/ApplicationCode/Application/Tools/RiaArgumentParser.cpp @@ -72,6 +72,13 @@ bool RiaArgumentParser::parseArguments(cvf::ProgramOptions* progOpt) progOpt->registerOption("server", "[]", "Launch as a GRPC server. Default port is 50051", cvf::ProgramOptions::SINGLE_VALUE); progOpt->registerOption("startdir", "", "Set startup directory.\n", cvf::ProgramOptions::SINGLE_VALUE); + progOpt->registerOption("summaryplot", + "[] []", + "Creates a summary plot using all the ," + "and all the summary vectors defined in ." + "Use --summaryplot -help to show a more detailed help text.\n", + cvf::ProgramOptions::OPTIONAL_MULTI_VALUE); + progOpt->registerOption("commandFile", "", "Execute the command file.", cvf::ProgramOptions::SINGLE_VALUE); progOpt->registerOption("commandFileReplaceCases", "[] ", diff --git a/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp b/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp index 2620eece67..c643c67c26 100644 --- a/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp +++ b/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp @@ -42,7 +42,8 @@ CAF_CMD_SOURCE_INIT(RicImportGeneralDataFeature, "RicImportGeneralDataFeature"); /// //-------------------------------------------------------------------------------------------------- RicImportGeneralDataFeature::OpenCaseResults - RicImportGeneralDataFeature::openEclipseFilesFromFileNames(const QStringList& fileNames) + RicImportGeneralDataFeature::openEclipseFilesFromFileNames(const QStringList& fileNames, + bool doCreateDefaultPlot) { CVF_ASSERT(!fileNames.empty()); @@ -89,7 +90,7 @@ RicImportGeneralDataFeature::OpenCaseResults } if (!eclipseSummaryFiles.empty()) { - if (!openSummaryCaseFromFileNames(eclipseSummaryFiles)) + if (!openSummaryCaseFromFileNames(eclipseSummaryFiles, doCreateDefaultPlot)) { return OpenCaseResults(); } @@ -200,7 +201,7 @@ void RicImportGeneralDataFeature::openFileDialog(ImportFileType fileTypes) RiaApplication::instance()->setLastUsedDialogDirectory(defaultDirectoryLabel(ANY_ECLIPSE_FILE), fileNames.front()); } - if (!openEclipseFilesFromFileNames(fileNames)) + if (!openEclipseFilesFromFileNames(fileNames, true)) { RiaLogging::error(QString("Failed to open file names: %1").arg(fileNames.join(", "))); } @@ -240,10 +241,11 @@ bool RicImportGeneralDataFeature::openInputEclipseCaseFromFileNames(const QStrin //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RicImportGeneralDataFeature::openSummaryCaseFromFileNames(const QStringList& fileNames) +bool RicImportGeneralDataFeature::openSummaryCaseFromFileNames(const QStringList& fileNames, + bool doCreateDefaultPlot) { std::vector newCases; - if (RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(fileNames, &newCases)) + if (RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(fileNames, doCreateDefaultPlot, &newCases)) { RicImportSummaryCasesFeature::addCasesToGroupIfRelevant(newCases); for (const RimSummaryCase* newCase : newCases) diff --git a/ApplicationCode/Commands/RicImportGeneralDataFeature.h b/ApplicationCode/Commands/RicImportGeneralDataFeature.h index 7a8b095f8b..fc2ad9da3b 100644 --- a/ApplicationCode/Commands/RicImportGeneralDataFeature.h +++ b/ApplicationCode/Commands/RicImportGeneralDataFeature.h @@ -46,7 +46,8 @@ public: } }; - static OpenCaseResults openEclipseFilesFromFileNames(const QStringList& fileNames); + static OpenCaseResults openEclipseFilesFromFileNames(const QStringList& fileNames, + bool doCreateDefaultPlot); static QStringList fileNamesFromCaseNames(const QStringList& caseNames); protected: @@ -60,6 +61,7 @@ protected: static bool openEclipseCaseFromFileNames(const QStringList& fileNames); static bool openInputEclipseCaseFromFileNames(const QStringList& fileNames); - static bool openSummaryCaseFromFileNames(const QStringList& fileNames); + static bool openSummaryCaseFromFileNames(const QStringList& fileNames, + bool doCreateDefaultPlot = true); }; diff --git a/ApplicationCode/Commands/RicImportSummaryCasesFeature.cpp b/ApplicationCode/Commands/RicImportSummaryCasesFeature.cpp index f0bf868874..7b11294139 100644 --- a/ApplicationCode/Commands/RicImportSummaryCasesFeature.cpp +++ b/ApplicationCode/Commands/RicImportSummaryCasesFeature.cpp @@ -122,6 +122,7 @@ void RicImportSummaryCasesFeature::setupActionLook(QAction* actionToSetup) /// //-------------------------------------------------------------------------------------------------- bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(const QStringList& fileNames, + bool doCreateDefaultPlot, std::vector* newCases) { RiaGuiApplication* app = RiaGuiApplication::instance(); @@ -131,7 +132,7 @@ bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(const QStri if (createSummaryCasesFromFiles(fileNames, cases)) { addSummaryCases(*cases); - if (!cases->empty()) + if (!cases->empty() && doCreateDefaultPlot) { RicSummaryPlotFeatureImpl::createDefaultSummaryPlot(cases->back()); } diff --git a/ApplicationCode/Commands/RicImportSummaryCasesFeature.h b/ApplicationCode/Commands/RicImportSummaryCasesFeature.h index 14afbad64a..8e226f9c5a 100644 --- a/ApplicationCode/Commands/RicImportSummaryCasesFeature.h +++ b/ApplicationCode/Commands/RicImportSummaryCasesFeature.h @@ -38,7 +38,9 @@ class RicImportSummaryCasesFeature : public caf::CmdFeature public: RicImportSummaryCasesFeature() { } - static bool createAndAddSummaryCasesFromFiles(const QStringList& fileName, std::vector* newCases = nullptr); + static bool createAndAddSummaryCasesFromFiles(const QStringList& fileName, + bool doCreateDefaultPlot, + std::vector* newCases = nullptr); static bool createSummaryCasesFromFiles(const QStringList& fileName, std::vector* newCases, bool ensembleOrGroup = false); static void addSummaryCases(const std::vector cases); static void addCasesToGroupIfRelevant(const std::vector cases); diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp index 11811f7424..716a28fef9 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp @@ -23,14 +23,20 @@ #include "RimSummaryPlotCollection.h" #include "RimProject.h" #include "RimMainPlotCollection.h" +#include "RimSummaryCase.h" #include "RiuPlotMainWindowTools.h" #include "RiaApplication.h" #include "RiaColorTables.h" #include "RiaPreferences.h" +#include "RiaEclipseFileNameTools.h" + #include "RifSummaryReaderInterface.h" -#include "RimSummaryCase.h" + +#include "RicImportGeneralDataFeature.h" + +#include //-------------------------------------------------------------------------------------------------- /// @@ -91,33 +97,7 @@ std::vector RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( QString curvesTextFilter = RiaApplication::instance()->preferences()->defaultSummaryCurvesTextFilter; QStringList curveFilters = curvesTextFilter.split(";", QString::SkipEmptyParts); - const std::set& addrs = summaryCase->summaryReader()->allResultAddresses(); - std::vector curveAddressesToUse; - - for (const auto & addr : addrs) - { - for (const QString& filter: curveFilters) - { - if ( addr.isUiTextMatchingFilterText(filter) ) - { - curveAddressesToUse.push_back(addr); - } - } - } - - for (const auto & addr : curveAddressesToUse) - { - RimSummaryCurve* newCurve = new RimSummaryCurve(); - plot->addCurveNoUpdate(newCurve); - if (summaryCase) - { - newCurve->setSummaryCaseY(summaryCase); - } - newCurve->setSummaryAddressYAndApplyInterpolation(addr); - defaultCurves.push_back(newCurve); - } - - return defaultCurves; + return addCurvesFromAddressFiltersToPlot(curveFilters, plot, summaryCase); } //-------------------------------------------------------------------------------------------------- @@ -141,7 +121,7 @@ void RicSummaryPlotFeatureImpl::createDefaultSummaryPlot( RimSummaryCase* summar { RimSummaryPlotCollection* summaryPlotCollection = RiaApplication::instance()->project()->mainPlotCollection->summaryPlotCollection(); - if (summaryPlotCollection && summaryCase) + if (summaryPlotCollection && summaryCase && !RiaApplication::instance()->preferences()->defaultSummaryCurvesTextFilter().isEmpty()) { auto plot = summaryPlotCollection->createSummaryPlotWithAutoTitle(); @@ -160,4 +140,145 @@ void RicSummaryPlotFeatureImpl::createDefaultSummaryPlot( RimSummaryCase* summar } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +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" + "[] []\n" + "\n" + "It Creates a summary plot using all the , and all the summary vectors defined in .\n" + "The has the syntax [:[:[: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 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" + " -nl Omit legend in plot." + ); + 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]) ; + } + } + } + + 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); + } + + std::vector summaryCasesToUse = RiaApplication::instance()->project()->allSummaryCases(); + + if ( summaryCasesToUse.size() ) + { + RimSummaryPlotCollection* sumPlotColl = RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); + RimSummaryPlot* newPlot = sumPlotColl->createSummaryPlotWithAutoTitle(); + + for (RimSummaryCase* sumCase : summaryCasesToUse) + { + RicSummaryPlotFeatureImpl::addCurvesFromAddressFiltersToPlot(summaryAddressFilters, newPlot, sumCase); + } + + if (options.contains("-nl")) + { + 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 RicSummaryPlotFeatureImpl::addCurvesFromAddressFiltersToPlot(const QStringList& curveFilters, + RimSummaryPlot* plot, + RimSummaryCase* summaryCase) +{ + std::vector createdCurves; + + const std::set& addrs = summaryCase->summaryReader()->allResultAddresses(); + std::vector curveAddressesToUse; + + for (const auto & addr : addrs) + { + for (const QString& filter: curveFilters) + { + if ( addr.isUiTextMatchingFilterText(filter) ) + { + curveAddressesToUse.push_back(addr); + } + } + } + + 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; +} diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.h b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.h index 3ddd497fd0..b5a078856b 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.h @@ -23,15 +23,21 @@ class RimSummaryCase; class RimSummaryPlotCollection; #include +class QStringList; + class RicSummaryPlotFeatureImpl { public: static RimSummaryCurve* addDefaultCurveToPlot(RimSummaryPlot* plot, RimSummaryCase* summaryCase); + static std::vector addCurvesFromAddressFiltersToPlot(const QStringList& curveFilters, + RimSummaryPlot* plot, + RimSummaryCase* summaryCase); static std::vector addDefaultCurvesToPlot(RimSummaryPlot* plot, RimSummaryCase* summaryCase); static void ensureAtLeastOnePlot(RimSummaryPlotCollection* summaryPlotCollection, RimSummaryCase* summaryCase); static void createDefaultSummaryPlot(RimSummaryCase* summaryCase); - - + + static RimSummaryPlot* createSummaryPlotFromCommandLine(const QStringList & arguments); + static RimSummaryPlot* createSummaryPlotFromArgumentLine(const QStringList & arguments); }; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 092e4a60ad..1569c7377e 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -1794,6 +1794,14 @@ caf::PdmObject* RimSummaryPlot::findRimPlotObjectFromQwtCurve(const QwtPlotCurve return nullptr; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::showLegend(bool enable) +{ + m_showLegend = enable; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index 7a51c40c60..ebb6a87529 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -148,6 +148,7 @@ public: void selectAxisInPropertyEditor(int axis) override; void setAutoZoomForAllAxes(bool enableAutoZoom) override; caf::PdmObject* findRimPlotObjectFromQwtCurve(const QwtPlotCurve* curve) const override; + void showLegend(bool enable); public: // RimViewWindow overrides