2018-04-18 06:56:01 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-04-19 07:00:00 -05:00
|
|
|
#include "RicImportEnsembleFeature.h"
|
2018-04-18 06:56:01 -05:00
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaPreferences.h"
|
|
|
|
|
|
|
|
#include "RicImportSummaryCasesFeature.h"
|
|
|
|
#include "RicCreateSummaryCaseCollectionFeature.h"
|
|
|
|
|
|
|
|
#include "RifSummaryCaseRestartSelector.h"
|
|
|
|
|
|
|
|
#include "RimGridSummaryCase.h"
|
|
|
|
#include "RimMainPlotCollection.h"
|
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimProject.h"
|
|
|
|
#include "RimSummaryCase.h"
|
2018-05-08 08:22:38 -05:00
|
|
|
#include "RimSummaryCaseCollection.h"
|
2018-04-18 06:56:01 -05:00
|
|
|
#include "RimSummaryCaseMainCollection.h"
|
|
|
|
#include "RimSummaryPlotCollection.h"
|
|
|
|
|
2018-04-26 23:28:08 -05:00
|
|
|
#include "RiuPlotMainWindow.h"
|
2018-04-18 06:56:01 -05:00
|
|
|
#include "RiuMainWindow.h"
|
|
|
|
|
|
|
|
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
|
|
|
2018-04-19 07:00:00 -05:00
|
|
|
CAF_CMD_SOURCE_INIT(RicImportEnsembleFeature, "RicImportEnsembleFeature");
|
2018-04-18 06:56:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-19 07:00:00 -05:00
|
|
|
bool RicImportEnsembleFeature::validateEnsembleCases(std::vector<RimSummaryCase*> cases)
|
2018-04-18 06:56:01 -05:00
|
|
|
{
|
2018-04-19 07:00:00 -05:00
|
|
|
// Validate ensemble parameters
|
2018-04-18 06:56:01 -05:00
|
|
|
try
|
|
|
|
{
|
2018-04-26 02:47:43 -05:00
|
|
|
QString errors;
|
2018-04-18 06:56:01 -05:00
|
|
|
std::hash<std::string> paramsHasher;
|
|
|
|
size_t paramsHash = 0;
|
|
|
|
|
|
|
|
for (RimSummaryCase* rimCase : cases)
|
|
|
|
{
|
2018-05-03 02:53:25 -05:00
|
|
|
if (rimCase->caseRealizationParameters() == nullptr || rimCase->caseRealizationParameters()->parameters().empty())
|
2018-04-18 06:56:01 -05:00
|
|
|
{
|
2018-04-26 02:47:43 -05:00
|
|
|
errors.append(QString("The case %1 has no ensemble parameters\n").arg(QFileInfo(rimCase->summaryHeaderFilename()).fileName()));
|
2018-04-18 06:56:01 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString paramNames;
|
2018-05-03 02:53:25 -05:00
|
|
|
for (std::pair<QString, RigCaseRealizationParameters::Value> paramPair : rimCase->caseRealizationParameters()->parameters())
|
2018-04-18 06:56:01 -05:00
|
|
|
{
|
|
|
|
paramNames.append(paramPair.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t currHash = paramsHasher(paramNames.toStdString());
|
|
|
|
if (paramsHash == 0)
|
|
|
|
{
|
|
|
|
paramsHash = currHash;
|
|
|
|
}
|
|
|
|
else if (paramsHash != currHash)
|
|
|
|
{
|
2018-04-19 07:00:00 -05:00
|
|
|
throw QString("Ensemble parameters differ between cases");
|
2018-04-18 06:56:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-26 02:47:43 -05:00
|
|
|
|
2018-07-02 07:53:13 -05:00
|
|
|
|
2018-04-26 02:47:43 -05:00
|
|
|
if (!errors.isEmpty())
|
|
|
|
{
|
2018-07-03 08:19:54 -05:00
|
|
|
errors.append("\n");
|
|
|
|
errors.append("No parameters file (parameters.txt or runspecification.xml) was found in \n");
|
|
|
|
errors.append("the searched folders. ResInsight searches the home folder of the summary \n");
|
|
|
|
errors.append("case file and the three folder levels above that.\n");
|
|
|
|
|
2018-04-26 02:47:43 -05:00
|
|
|
throw errors;
|
|
|
|
}
|
2018-04-18 06:56:01 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (QString errorMessage)
|
|
|
|
{
|
|
|
|
QMessageBox mbox;
|
|
|
|
mbox.setIcon(QMessageBox::Icon::Warning);
|
|
|
|
mbox.setInformativeText(errorMessage);
|
|
|
|
mbox.exec();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 01:32:44 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicImportEnsembleFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicImportEnsembleFeature::onActionTriggered(bool isChecked)
|
|
|
|
{
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
QStringList fileNames = RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialog("Import Ensemble");
|
|
|
|
|
|
|
|
if (fileNames.isEmpty()) return;
|
|
|
|
|
|
|
|
QString ensembleName = askForEnsembleName();
|
|
|
|
if (ensembleName.isEmpty()) return;
|
|
|
|
|
|
|
|
std::vector<RimSummaryCase*> cases;
|
2018-06-06 02:49:46 -05:00
|
|
|
RicImportSummaryCasesFeature::createSummaryCasesFromFiles(fileNames, &cases, true);
|
2018-05-11 01:32:44 -05:00
|
|
|
|
|
|
|
validateEnsembleCases(cases);
|
|
|
|
|
|
|
|
RicImportSummaryCasesFeature::addSummaryCases(cases);
|
2018-06-25 08:14:47 -05:00
|
|
|
auto newGroup = RicCreateSummaryCaseCollectionFeature::groupSummaryCases(cases, ensembleName, true);
|
2018-05-11 01:32:44 -05:00
|
|
|
|
|
|
|
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
|
2018-06-25 08:14:47 -05:00
|
|
|
if (mainPlotWindow && newGroup)
|
2018-05-11 01:32:44 -05:00
|
|
|
{
|
2018-06-25 08:14:47 -05:00
|
|
|
mainPlotWindow->selectAsCurrentItem(newGroup);
|
2018-05-11 01:32:44 -05:00
|
|
|
mainPlotWindow->updateSummaryPlotToolBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RimCase*> allCases;
|
|
|
|
app->project()->allCases(allCases);
|
|
|
|
|
|
|
|
if (allCases.size() == 0)
|
|
|
|
{
|
|
|
|
RiuMainWindow::instance()->close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicImportEnsembleFeature::setupActionLook(QAction* actionToSetup)
|
|
|
|
{
|
|
|
|
actionToSetup->setIcon(QIcon(":/SummaryEnsemble16x16.png"));
|
|
|
|
actionToSetup->setText("Import Ensemble");
|
|
|
|
}
|
|
|
|
|
2018-04-18 06:56:01 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-19 07:00:00 -05:00
|
|
|
QString RicImportEnsembleFeature::askForEnsembleName()
|
2018-04-18 06:56:01 -05:00
|
|
|
{
|
|
|
|
RimProject* project = RiaApplication::instance()->project();
|
2018-05-08 08:22:38 -05:00
|
|
|
std::vector<RimSummaryCaseCollection*> groups = project->summaryGroups();
|
|
|
|
int ensembleCount = std::count_if(groups.begin(), groups.end(), [](RimSummaryCaseCollection* group) { return group->isEnsemble(); });
|
|
|
|
ensembleCount += 1;
|
2018-04-18 06:56:01 -05:00
|
|
|
|
|
|
|
QInputDialog dialog;
|
|
|
|
dialog.setInputMode(QInputDialog::TextInput);
|
2018-04-19 02:18:09 -05:00
|
|
|
dialog.setWindowTitle("Ensemble Name");
|
|
|
|
dialog.setLabelText("Ensemble Name");
|
2018-05-08 08:22:38 -05:00
|
|
|
dialog.setTextValue(QString("Ensemble %1").arg(ensembleCount));
|
2018-04-18 06:56:01 -05:00
|
|
|
dialog.resize(300, 50);
|
|
|
|
dialog.exec();
|
|
|
|
return dialog.result() == QDialog::Accepted ? dialog.textValue() : QString("");
|
|
|
|
}
|