mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1840 Summary case: Delete a summary collection with or without its contents
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- 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 "RicDeleteSummaryCaseCollectionFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
#include "RimSummaryCaseMainCollection.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
#include "RimSummaryPlotCollection.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicDeleteSummaryCaseCollectionFeature, "RicDeleteSummaryCaseCollectionFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicDeleteSummaryCaseCollectionFeature::deleteSummaryCaseCollection(RimSummaryCaseCollection* caseCollection)
|
||||
{
|
||||
RimSummaryPlotCollection* summaryPlotColl = RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
||||
|
||||
for (RimSummaryCase* summaryCase : caseCollection->allSummaryCases())
|
||||
{
|
||||
for (RimSummaryPlot* summaryPlot : summaryPlotColl->summaryPlots)
|
||||
{
|
||||
summaryPlot->removeCurvesAssosiatedWithCase(summaryCase);
|
||||
}
|
||||
}
|
||||
|
||||
summaryPlotColl->updateConnectedEditors();
|
||||
|
||||
/*RimSummaryCaseMainCollection* summaryCaseMainCollection = nullptr;
|
||||
caseCollection->firstAncestorOrThisOfTypeAsserted(summaryCaseMainCollection);
|
||||
summaryCaseMainCollection->removeCaseCollection(caseCollection);
|
||||
delete caseCollection;*/
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicDeleteSummaryCaseCollectionFeature::isCommandEnabled()
|
||||
{
|
||||
std::vector<RimSummaryCaseCollection*> selection;
|
||||
caf::SelectionManager::instance()->objectsByType(&selection);
|
||||
|
||||
return (selection.size() > 0);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicDeleteSummaryCaseCollectionFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
std::vector<RimSummaryCaseCollection*> selection;
|
||||
caf::SelectionManager::instance()->objectsByType(&selection);
|
||||
|
||||
bool userConfirmedClosingOfGroup = askUserWhereToPutTheSummaryCases(selection);
|
||||
|
||||
if (userConfirmedClosingOfGroup)
|
||||
{
|
||||
RimSummaryCaseMainCollection* summaryCaseMainCollection = nullptr;
|
||||
selection[0]->firstAncestorOrThisOfTypeAsserted(summaryCaseMainCollection);
|
||||
|
||||
for (RimSummaryCaseCollection* caseCollection : selection)
|
||||
{
|
||||
summaryCaseMainCollection->removeCaseCollection(caseCollection);
|
||||
delete caseCollection;
|
||||
}
|
||||
|
||||
summaryCaseMainCollection->updateConnectedEditors();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicDeleteSummaryCaseCollectionFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Delete Summary Case Group");
|
||||
actionToSetup->setIcon(QIcon(":/Erase.png"));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicDeleteSummaryCaseCollectionFeature::askUserWhereToPutTheSummaryCases(std::vector<RimSummaryCaseCollection*> selectedSummaryCases)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Question);
|
||||
|
||||
QString questionText;
|
||||
questionText = QString("Do you also want to close the summary cases in the group?");
|
||||
|
||||
msgBox.setText(questionText);
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
|
||||
int ret = msgBox.exec();
|
||||
|
||||
if (ret == QMessageBox::Yes)
|
||||
{
|
||||
for (RimSummaryCaseCollection* summaryCaseCollection : selectedSummaryCases)
|
||||
{
|
||||
RicDeleteSummaryCaseCollectionFeature::deleteSummaryCaseCollection(summaryCaseCollection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (ret == QMessageBox::No)
|
||||
{
|
||||
for (RimSummaryCaseCollection* summaryCaseCollection : selectedSummaryCases)
|
||||
{
|
||||
RicDeleteSummaryCaseCollectionFeature::moveSummaryCasesFromSummaryCollectionToMainSummaryCollection(summaryCaseCollection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicDeleteSummaryCaseCollectionFeature::moveSummaryCasesFromSummaryCollectionToMainSummaryCollection(RimSummaryCaseCollection* summaryCaseCollection)
|
||||
{
|
||||
std::vector<RimSummaryCase*> summaryCases = summaryCaseCollection->allSummaryCases();
|
||||
if (summaryCases.size() < 0) return;
|
||||
|
||||
RimSummaryCaseMainCollection* summaryCaseMainCollection = nullptr;
|
||||
summaryCaseCollection->firstAncestorOrThisOfType(summaryCaseMainCollection);
|
||||
|
||||
for (RimSummaryCase* summaryCase : summaryCases)
|
||||
{
|
||||
summaryCaseCollection->removeCase(summaryCase);
|
||||
summaryCaseMainCollection->addCase(summaryCase);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user