#4087 Ensemble : When importing and ensemble, show by default an ensemble plot

This commit is contained in:
Magne Sjaastad 2019-02-18 13:09:50 +01:00
parent 3acd426ead
commit ba91122ba6
5 changed files with 172 additions and 112 deletions

View File

@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil 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>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@ -21,11 +21,12 @@
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "RicImportSummaryCasesFeature.h"
#include "RicCreateSummaryCaseCollectionFeature.h"
#include "RicImportSummaryCasesFeature.h"
#include "RifSummaryCaseRestartSelector.h"
#include "RimEnsembleCurveSet.h"
#include "RimGridSummaryCase.h"
#include "RimMainPlotCollection.h"
#include "RimOilField.h"
@ -33,24 +34,24 @@
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RiuPlotMainWindow.h"
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h"
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
#include <QAction>
#include <QFileDialog>
#include <QMessageBox>
#include <QInputDialog>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT(RicImportEnsembleFeature, "RicImportEnsembleFeature");
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
bool RicImportEnsembleFeature::isCommandEnabled()
{
@ -58,14 +59,15 @@ bool RicImportEnsembleFeature::isCommandEnabled()
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportEnsembleFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
QString pathCacheName = "ENSEMBLE_FILES";
QStringList fileNames = RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialog("Import Ensemble", pathCacheName);
RiaApplication* app = RiaApplication::instance();
QString pathCacheName = "ENSEMBLE_FILES";
QStringList fileNames =
RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialog("Import Ensemble", pathCacheName);
if (fileNames.isEmpty()) return;
QString ensembleName = askForEnsembleName();
@ -75,13 +77,11 @@ void RicImportEnsembleFeature::onActionTriggered(bool isChecked)
RicImportSummaryCasesFeature::createSummaryCasesFromFiles(fileNames, &cases, true);
RicImportSummaryCasesFeature::addSummaryCases(cases);
auto newGroup = RicCreateSummaryCaseCollectionFeature::groupSummaryCases(cases, ensembleName, true);
RimSummaryCaseCollection* ensemble = RicCreateSummaryCaseCollectionFeature::groupSummaryCases(cases, ensembleName, true);
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
if (mainPlotWindow && newGroup)
if (ensemble)
{
mainPlotWindow->selectAsCurrentItem(newGroup);
mainPlotWindow->updateSummaryPlotToolBar();
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate(ensemble);
}
std::vector<RimCase*> allCases;
@ -94,7 +94,7 @@ void RicImportEnsembleFeature::onActionTriggered(bool isChecked)
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportEnsembleFeature::setupActionLook(QAction* actionToSetup)
{
@ -103,13 +103,14 @@ void RicImportEnsembleFeature::setupActionLook(QAction* actionToSetup)
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QString RicImportEnsembleFeature::askForEnsembleName()
{
RimProject* project = RiaApplication::instance()->project();
std::vector<RimSummaryCaseCollection*> groups = project->summaryGroups();
int ensembleCount = std::count_if(groups.begin(), groups.end(), [](RimSummaryCaseCollection* group) { return group->isEnsemble(); });
RimProject* project = RiaApplication::instance()->project();
std::vector<RimSummaryCaseCollection*> groups = project->summaryGroups();
int ensembleCount =
std::count_if(groups.begin(), groups.end(), [](RimSummaryCaseCollection* group) { return group->isEnsemble(); });
ensembleCount += 1;
QInputDialog dialog;

View File

@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil 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>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@ -28,6 +28,7 @@
#include "RifSummaryCaseRestartSelector.h"
#include "RimEnsembleCurveSet.h"
#include "RimGridSummaryCase.h"
#include "RimMainPlotCollection.h"
#include "RimOilField.h"
@ -35,11 +36,13 @@
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RiuPlotMainWindow.h"
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h"
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
#include "cafProgressInfo.h"
@ -51,15 +54,14 @@
CAF_CMD_SOURCE_INIT(RicImportSummaryCasesFeature, "RicImportSummaryCasesFeature");
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QString RicImportSummaryCasesFeature::m_pathFilter = "*";
QString RicImportSummaryCasesFeature::m_pathFilter = "*";
QString RicImportSummaryCasesFeature::m_fileNameFilter = "*";
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
bool RicImportSummaryCasesFeature::isCommandEnabled()
{
@ -67,22 +69,27 @@ bool RicImportSummaryCasesFeature::isCommandEnabled()
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::onActionTriggered(bool isChecked)
{
RiaApplication* app = RiaApplication::instance();
QString pathCacheName = "INPUT_FILES";
QStringList fileNames = runRecursiveSummaryCaseFileSearchDialog("Import Summary Cases", pathCacheName);
RiaApplication* app = RiaApplication::instance();
QString pathCacheName = "INPUT_FILES";
QStringList fileNames = runRecursiveSummaryCaseFileSearchDialog("Import Summary Cases", pathCacheName);
std::vector<RimSummaryCase*> cases;
if (!fileNames.isEmpty()) createSummaryCasesFromFiles(fileNames, &cases);
addSummaryCases(cases);
if (!cases.empty())
{
createNewPlot(cases.front());
}
addCasesToGroupIfRelevant(cases);
for (const auto& rimCase : cases) RiaApplication::instance()->addToRecentFiles(rimCase->summaryHeaderFilename());
for (const auto& rimCase : cases)
RiaApplication::instance()->addToRecentFiles(rimCase->summaryHeaderFilename());
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
if (mainPlotWindow && !cases.empty())
@ -102,7 +109,7 @@ void RicImportSummaryCasesFeature::onActionTriggered(bool isChecked)
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::setupActionLook(QAction* actionToSetup)
{
@ -111,17 +118,22 @@ void RicImportSummaryCasesFeature::setupActionLook(QAction* actionToSetup)
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(const QStringList& fileNames, std::vector<RimSummaryCase*>* newCases)
bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(const QStringList& fileNames,
std::vector<RimSummaryCase*>* newCases)
{
RiaApplication* app = RiaApplication::instance();
std::vector<RimSummaryCase*> temp;
std::vector<RimSummaryCase*> temp;
std::vector<RimSummaryCase*>* cases = newCases ? newCases : &temp;
if (createSummaryCasesFromFiles(fileNames, cases))
{
addSummaryCases(*cases);
if (!cases->empty())
{
createNewPlot(cases->back());
}
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
if (mainPlotWindow && !cases->empty())
@ -145,20 +157,21 @@ bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(const QStri
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
bool RicImportSummaryCasesFeature::createSummaryCasesFromFiles(const QStringList& fileNames,
bool RicImportSummaryCasesFeature::createSummaryCasesFromFiles(const QStringList& fileNames,
std::vector<RimSummaryCase*>* newCases,
bool ensembleOrGroup)
bool ensembleOrGroup)
{
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
RimSummaryCaseMainCollection* sumCaseColl = proj->activeOilField() ? proj->activeOilField()->summaryCaseMainCollection() : nullptr;
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
RimSummaryCaseMainCollection* sumCaseColl =
proj->activeOilField() ? proj->activeOilField()->summaryCaseMainCollection() : nullptr;
if (newCases) newCases->clear();
if (!sumCaseColl) return false;
RifSummaryCaseRestartSelector fileSelector;
RifSummaryCaseRestartSelector fileSelector;
fileSelector.setEnsembleOrGroupMode(ensembleOrGroup);
fileSelector.determineFilesToImportFromSummaryFiles(fileNames);
@ -181,25 +194,21 @@ bool RicImportSummaryCasesFeature::createSummaryCasesFromFiles(const QStringList
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::addSummaryCases(const std::vector<RimSummaryCase*> cases)
{
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
RimSummaryCaseMainCollection* sumCaseColl = proj->activeOilField() ? proj->activeOilField()->summaryCaseMainCollection() : nullptr;
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
RimSummaryCaseMainCollection* sumCaseColl =
proj->activeOilField() ? proj->activeOilField()->summaryCaseMainCollection() : nullptr;
sumCaseColl->addCases(cases);
if (!cases.empty())
{
RicNewSummaryCurveFeature::createNewPlot(proj->mainPlotCollection->summaryPlotCollection(), cases.front());
}
sumCaseColl->updateAllRequiredEditors();
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::addCasesToGroupIfRelevant(const std::vector<RimSummaryCase*> cases)
{
@ -207,8 +216,8 @@ void RicImportSummaryCasesFeature::addCasesToGroupIfRelevant(const std::vector<R
if (selectedColl.size() == 1)
{
RimSummaryCaseCollection* coll = selectedColl.front();
RimSummaryCaseMainCollection* mainColl;
RimSummaryCaseCollection* coll = selectedColl.front();
RimSummaryCaseMainCollection* mainColl;
coll->firstAncestorOrThisOfType(mainColl);
if (mainColl)
@ -224,23 +233,30 @@ void RicImportSummaryCasesFeature::addCasesToGroupIfRelevant(const std::vector<R
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::createNewPlot(RimSummaryCase* summaryCase)
{
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
RicNewSummaryCurveFeature::createNewPlot(proj->mainPlotCollection->summaryPlotCollection(), summaryCase);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialog(const QString& dialogTitle,
const QString& pathCacheName)
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory(pathCacheName);
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory(pathCacheName);
RicFileHierarchyDialogResult result = RicFileHierarchyDialog::runRecursiveSearchDialog(nullptr,
dialogTitle,
defaultDir,
m_pathFilter,
m_fileNameFilter,
QStringList(".SMSPEC"));
RicFileHierarchyDialogResult result = RicFileHierarchyDialog::runRecursiveSearchDialog(
nullptr, dialogTitle, defaultDir, m_pathFilter, m_fileNameFilter, QStringList(".SMSPEC"));
// Remember filters
m_pathFilter = result.pathFilter;
m_pathFilter = result.pathFilter;
m_fileNameFilter = result.fileNameFilter;
if (!result.ok) return QStringList();

View File

@ -42,6 +42,7 @@ public:
static bool createSummaryCasesFromFiles(const QStringList& fileName, std::vector<RimSummaryCase*>* newCases, bool ensembleOrGroup = false);
static void addSummaryCases(const std::vector<RimSummaryCase*> cases);
static void addCasesToGroupIfRelevant(const std::vector<RimSummaryCase*> cases);
static void createNewPlot(RimSummaryCase* summaryCase);
static QStringList runRecursiveSummaryCaseFileSearchDialog(const QString& dialogTitle, const QString& pathCacheName);

View File

@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil 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>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@ -21,17 +21,17 @@
#include "RiaApplication.h"
#include "RiaColorTables.h"
#include "RiaSummaryTools.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimEnsembleCurveSetColorManager.h"
#include "RimMainPlotCollection.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RiaSummaryTools.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimEnsembleCurveSetColorManager.h"
#include "RiuPlotMainWindow.h"
@ -43,11 +43,60 @@
#include <QAction>
CAF_CMD_SOURCE_INIT(RicNewSummaryEnsembleCurveSetFeature, "RicNewSummaryEnsembleCurveSetFeature");
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RimEnsembleCurveSet* RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet(RimSummaryPlot* plot,
RimSummaryCaseCollection* ensemble)
{
CVF_ASSERT(plot && ensemble);
RimProject* project = RiaApplication::instance()->project();
CVF_ASSERT(project);
RimEnsembleCurveSet* curveSet = new RimEnsembleCurveSet();
// Use same counting as RicNewSummaryCurveFeature::onActionTriggered
auto colorIndex = plot->singleColorCurveCount();
curveSet->setColor(RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f(colorIndex));
curveSet->legendConfig()->setColorRange(
RimEnsembleCurveSetColorManager::cycledEnsembleColorRange(static_cast<int>(colorIndex)));
curveSet->setSummaryCaseCollection(ensemble);
curveSet->setSummaryAddress(RifEclipseSummaryAddress::fieldAddress("FOPT"));
plot->ensembleCurveSetCollection()->addCurveSet(curveSet);
return curveSet;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate(RimSummaryCaseCollection* ensemble)
{
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
RimSummaryPlotCollection* summaryPlotCollection = proj->mainPlotCollection->summaryPlotCollection();
RimSummaryPlot* plot = summaryPlotCollection->createSummaryPlotWithAutoTitle();
RimEnsembleCurveSet* curveSet = RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet(plot, ensemble);
plot->loadDataAndUpdate();
summaryPlotCollection->updateConnectedEditors();
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
if (mainPlotWindow)
{
mainPlotWindow->selectAsCurrentItem(curveSet);
mainPlotWindow->updateSummaryPlotToolBar();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewSummaryEnsembleCurveSetFeature::isCommandEnabled()
{
@ -55,7 +104,7 @@ bool RicNewSummaryEnsembleCurveSetFeature::isCommandEnabled()
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryEnsembleCurveSetFeature::onActionTriggered(bool isChecked)
{
@ -65,30 +114,14 @@ void RicNewSummaryEnsembleCurveSetFeature::onActionTriggered(bool isChecked)
RimSummaryPlot* plot = selectedSummaryPlot();
if (plot)
{
RimEnsembleCurveSet* curveSet = new RimEnsembleCurveSet();
auto ensemble = project->summaryGroups().back();
// Use same counting as RicNewSummaryCurveFeature::onActionTriggered
auto colorIndex = plot->singleColorCurveCount();
curveSet->setColor(RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f(colorIndex));
curveSet->legendConfig()->setColorRange(RimEnsembleCurveSetColorManager::cycledEnsembleColorRange(static_cast<int>(colorIndex)));
if (!project->summaryGroups().empty())
{
curveSet->setSummaryCaseCollection(project->summaryGroups().back());
}
plot->ensembleCurveSetCollection()->addCurveSet(curveSet);
plot->updateConnectedEditors();
RiaApplication::instance()->getOrCreateAndShowMainPlotWindow()->selectAsCurrentItem(curveSet);
RiuPlotMainWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
mainPlotWindow->updateSummaryPlotToolBar();
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate(ensemble);
}
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryEnsembleCurveSetFeature::setupActionLook(QAction* actionToSetup)
{
@ -97,13 +130,13 @@ void RicNewSummaryEnsembleCurveSetFeature::setupActionLook(QAction* actionToSetu
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicNewSummaryEnsembleCurveSetFeature::selectedSummaryPlot() const
{
RimSummaryPlot* sumPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>(caf::SelectionManager::instance()->selectedItem());
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>(caf::SelectionManager::instance()->selectedItem());
if (selObj)
{
sumPlot = RiaSummaryTools::parentSummaryPlot(selObj);

View File

@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil 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>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@ -23,18 +23,27 @@
#include <vector>
class RimSummaryPlot;
class RimEnsembleCurveSet;
class RimSummaryCaseCollection;
//==================================================================================================
///
///
//==================================================================================================
class RicNewSummaryEnsembleCurveSetFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static void createPlotForCurveSetAndUpdate(RimSummaryCaseCollection* ensemble);
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override;
private:
static RimEnsembleCurveSet* addDefaultCurveSet(RimSummaryPlot* plot, RimSummaryCaseCollection* ensemble);
private:
RimSummaryPlot* selectedSummaryPlot() const;