mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#2886 Summary groups. Add convert group to ensemble command
This commit is contained in:
parent
bb033eb561
commit
368cca8b8d
@ -68,6 +68,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicFileHierarchyDialog.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSummaryCaseRestartDialog.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportEnsembleFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryGroupFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicConvertGroupToEnsembleFeature.h
|
||||
)
|
||||
|
||||
|
||||
@ -134,6 +135,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicFileHierarchyDialog.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSummaryCaseRestartDialog.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportEnsembleFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportSummaryGroupFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicConvertGroupToEnsembleFeature.cpp
|
||||
)
|
||||
|
||||
|
||||
|
@ -0,0 +1,91 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicConvertGroupToEnsembleFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RicImportEnsembleFeature.h"
|
||||
#include "RicCreateSummaryCaseCollectionFeature.h"
|
||||
|
||||
#include "RifSummaryCaseRestartSelector.h"
|
||||
|
||||
#include "RimGridSummaryCase.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
#include "RimSummaryCaseMainCollection.h"
|
||||
#include "RimSummaryPlotCollection.h"
|
||||
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuMainWindow.h"
|
||||
|
||||
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
||||
|
||||
#include "cafSelectionManagerTools.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicConvertGroupToEnsembleFeature, "RicConvertGroupToEnsembleFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicConvertGroupToEnsembleFeature::isCommandEnabled()
|
||||
{
|
||||
const auto& selGroups = caf::selectedObjectsByTypeStrict<RimSummaryCaseCollection*>();
|
||||
if (selGroups.empty()) return false;
|
||||
|
||||
for (const auto& group : selGroups)
|
||||
{
|
||||
if (!group->isEnsemble()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicConvertGroupToEnsembleFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
const auto& selGroups = caf::selectedObjectsByTypeStrict<RimSummaryCaseCollection*>();
|
||||
|
||||
for (const auto& group : selGroups)
|
||||
{
|
||||
if (group->isEnsemble()) continue;
|
||||
|
||||
RicImportEnsembleFeature::validateEnsembleCases(group->allSummaryCases());
|
||||
group->setAsEnsemble(true);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicConvertGroupToEnsembleFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/SummaryEnsemble16x16.png"));
|
||||
actionToSetup->setText("Convert to Ensemble");
|
||||
}
|
45
ApplicationCode/Commands/RicConvertGroupToEnsembleFeature.h
Normal file
45
ApplicationCode/Commands/RicConvertGroupToEnsembleFeature.h
Normal file
@ -0,0 +1,45 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
class RimSummaryCase;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicConvertGroupToEnsembleFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
virtual void onActionTriggered( bool isChecked ) override;
|
||||
virtual void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
|
||||
|
@ -48,6 +48,61 @@
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicImportEnsembleFeature, "RicImportEnsembleFeature");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicImportEnsembleFeature::validateEnsembleCases(std::vector<RimSummaryCase*> cases)
|
||||
{
|
||||
// Validate ensemble parameters
|
||||
try
|
||||
{
|
||||
QString errors;
|
||||
std::hash<std::string> paramsHasher;
|
||||
size_t paramsHash = 0;
|
||||
|
||||
for (RimSummaryCase* rimCase : cases)
|
||||
{
|
||||
if (rimCase->caseRealizationParameters() == nullptr || rimCase->caseRealizationParameters()->parameters().empty())
|
||||
{
|
||||
errors.append(QString("The case %1 has no ensemble parameters\n").arg(QFileInfo(rimCase->summaryHeaderFilename()).fileName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QString paramNames;
|
||||
for (std::pair<QString, RigCaseRealizationParameters::Value> paramPair : rimCase->caseRealizationParameters()->parameters())
|
||||
{
|
||||
paramNames.append(paramPair.first);
|
||||
}
|
||||
|
||||
size_t currHash = paramsHasher(paramNames.toStdString());
|
||||
if (paramsHash == 0)
|
||||
{
|
||||
paramsHash = currHash;
|
||||
}
|
||||
else if (paramsHash != currHash)
|
||||
{
|
||||
throw QString("Ensemble parameters differ between cases");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!errors.isEmpty())
|
||||
{
|
||||
throw errors;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (QString errorMessage)
|
||||
{
|
||||
QMessageBox mbox;
|
||||
mbox.setIcon(QMessageBox::Icon::Warning);
|
||||
mbox.setInformativeText(errorMessage);
|
||||
mbox.exec();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -103,60 +158,6 @@ void RicImportEnsembleFeature::setupActionLook(QAction* actionToSetup)
|
||||
actionToSetup->setText("Import Ensemble");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicImportEnsembleFeature::validateEnsembleCases(std::vector<RimSummaryCase*> cases)
|
||||
{
|
||||
// Validate ensemble parameters
|
||||
try
|
||||
{
|
||||
QString errors;
|
||||
std::hash<std::string> paramsHasher;
|
||||
size_t paramsHash = 0;
|
||||
|
||||
for (RimSummaryCase* rimCase : cases)
|
||||
{
|
||||
if (rimCase->caseRealizationParameters() == nullptr || rimCase->caseRealizationParameters()->parameters().empty())
|
||||
{
|
||||
errors.append(QString("The case %1 has no ensemble parameters\n").arg(QFileInfo(rimCase->summaryHeaderFilename()).fileName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QString paramNames;
|
||||
for (std::pair<QString, RigCaseRealizationParameters::Value> paramPair : rimCase->caseRealizationParameters()->parameters())
|
||||
{
|
||||
paramNames.append(paramPair.first);
|
||||
}
|
||||
|
||||
size_t currHash = paramsHasher(paramNames.toStdString());
|
||||
if (paramsHash == 0)
|
||||
{
|
||||
paramsHash = currHash;
|
||||
}
|
||||
else if (paramsHash != currHash)
|
||||
{
|
||||
throw QString("Ensemble parameters differ between cases");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!errors.isEmpty())
|
||||
{
|
||||
throw errors;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (QString errorMessage)
|
||||
{
|
||||
QMessageBox mbox;
|
||||
mbox.setIcon(QMessageBox::Icon::Warning);
|
||||
mbox.setInformativeText(errorMessage);
|
||||
mbox.exec();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -35,13 +35,15 @@ class RicImportEnsembleFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
static bool validateEnsembleCases(std::vector<RimSummaryCase*> cases);
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
virtual void onActionTriggered( bool isChecked ) override;
|
||||
virtual void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
bool validateEnsembleCases(std::vector<RimSummaryCase*> cases);
|
||||
QString askForEnsembleName();
|
||||
};
|
||||
|
||||
|
@ -495,6 +495,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
||||
menuBuilder << "RicNewSummaryPlotFeature";
|
||||
menuBuilder << "RicNewSummaryCrossPlotFeature";
|
||||
menuBuilder.addSeparator();
|
||||
menuBuilder << "RicConvertGroupToEnsembleFeature";
|
||||
menuBuilder.addSeparator();
|
||||
}
|
||||
else if (dynamic_cast<RimSummaryCase*>(uiItem))
|
||||
{
|
||||
@ -673,6 +675,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
||||
menuBuilder << "RicNewSummaryCrossPlotFeature";
|
||||
menuBuilder << "RicSummaryCurveSwitchAxisFeature";
|
||||
menuBuilder.addSeparator();
|
||||
menuBuilder << "RicConvertGroupToEnsembleFeature";
|
||||
menuBuilder.addSeparator();
|
||||
|
||||
if (!menuBuilder.isCmdFeatureAdded("RicNewFishbonesSubsFeature"))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user