Files
ResInsight/ApplicationCode/Commands/EclipseCommands/RicComputeStatisticsFeature.cpp
T

89 lines
3.3 KiB
C++
Raw Normal View History

2015-08-21 14:53:45 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
2015-08-21 14:53:45 +02:00
// 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.
//
2015-08-21 14:53:45 +02:00
// 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>
2015-08-21 14:53:45 +02:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicComputeStatisticsFeature.h"
#include "RimCaseCollection.h"
2015-08-21 14:53:45 +02:00
#include "RimEclipseCase.h"
#include "RimEclipseStatisticsCase.h"
#include "RimEclipseStatisticsCaseCollection.h"
#include "RimIdenticalGridCaseGroup.h"
#include "cafCmdFeatureManager.h"
#include "cafSelectionManager.h"
2015-08-21 14:53:45 +02:00
#include <QAction>
CAF_CMD_SOURCE_INIT( RicComputeStatisticsFeature, "RicComputeStatisticsFeature" );
2015-08-21 14:53:45 +02:00
//--------------------------------------------------------------------------------------------------
///
2015-08-21 14:53:45 +02:00
//--------------------------------------------------------------------------------------------------
bool RicComputeStatisticsFeature::isCommandEnabled()
{
std::vector<RimEclipseStatisticsCase*> selection = selectedCases();
if ( selection.size() > 0 )
2015-08-21 14:53:45 +02:00
{
RimEclipseStatisticsCase* statisticsCase = selection[0];
if ( statisticsCase )
2015-08-21 14:53:45 +02:00
{
2018-02-18 18:56:43 +01:00
RimIdenticalGridCaseGroup* gridCaseGroup = nullptr;
statisticsCase->firstAncestorOrThisOfType( gridCaseGroup );
2015-08-21 14:53:45 +02:00
2018-02-18 18:56:43 +01:00
RimCaseCollection* caseCollection = gridCaseGroup ? gridCaseGroup->caseCollection() : nullptr;
2015-08-21 14:53:45 +02:00
return caseCollection ? caseCollection->reservoirs.size() > 0 : false;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
2015-08-21 14:53:45 +02:00
//--------------------------------------------------------------------------------------------------
void RicComputeStatisticsFeature::onActionTriggered( bool isChecked )
2015-08-21 14:53:45 +02:00
{
std::vector<RimEclipseStatisticsCase*> selection = selectedCases();
if ( selection.size() > 0 )
2015-08-21 14:53:45 +02:00
{
RimEclipseStatisticsCase* statisticsCase = selection[0];
statisticsCase->computeStatisticsAndUpdateViews();
2015-08-21 14:53:45 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
2015-08-21 14:53:45 +02:00
//--------------------------------------------------------------------------------------------------
void RicComputeStatisticsFeature::setupActionLook( QAction* actionToSetup )
2015-08-21 14:53:45 +02:00
{
actionToSetup->setText( "Compute" );
2015-08-21 14:53:45 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2015-08-21 14:53:45 +02:00
//--------------------------------------------------------------------------------------------------
std::vector<RimEclipseStatisticsCase*> RicComputeStatisticsFeature::selectedCases()
{
std::vector<RimEclipseStatisticsCase*> selection;
caf::SelectionManager::instance()->objectsByType( &selection );
2015-08-21 14:53:45 +02:00
return selection;
}