2015-08-21 11:47:59 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-08-21 11:47:59 +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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-08-21 11:47:59 +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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-08-21 11:47:59 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RicNewStatisticsCaseFeature.h"
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RimCaseCollection.h"
|
2015-08-21 11:47:59 +02:00
|
|
|
#include "RimEclipseStatisticsCase.h"
|
|
|
|
|
#include "RimEclipseStatisticsCaseCollection.h"
|
|
|
|
|
#include "RimIdenticalGridCaseGroup.h"
|
|
|
|
|
#include "RimProject.h"
|
2026-02-13 08:28:34 +01:00
|
|
|
#include "RimReservoirGridEnsembleBase.h"
|
2015-08-21 11:47:59 +02:00
|
|
|
|
2018-02-27 15:53:33 +01:00
|
|
|
#include "Riu3DMainWindowTools.h"
|
2015-08-21 11:47:59 +02:00
|
|
|
|
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_CMD_SOURCE_INIT( RicNewStatisticsCaseFeature, "RicNewStatisticsCaseFeature" );
|
2015-08-21 11:47:59 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-08-21 11:47:59 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-06-26 14:28:46 +02:00
|
|
|
bool RicNewStatisticsCaseFeature::isCommandEnabled() const
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2018-02-18 18:56:43 +01:00
|
|
|
return selectedValidUIItem() != nullptr;
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-08-21 11:47:59 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicNewStatisticsCaseFeature::onActionTriggered( bool isChecked )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
|
|
|
|
caf::PdmUiItem* uiItem = selectedValidUIItem();
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( uiItem )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
RimEclipseStatisticsCase* newCase = addStatisticalCalculation( uiItem );
|
|
|
|
|
if ( newCase )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( newCase );
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-08-21 11:47:59 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicNewStatisticsCaseFeature::setupActionLook( QAction* actionToSetup )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setText( "New Statistics Case" );
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-08-21 11:47:59 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
caf::PdmUiItem* RicNewStatisticsCaseFeature::selectedValidUIItem()
|
|
|
|
|
{
|
2025-04-08 12:53:14 +02:00
|
|
|
const auto statisticsCaseCollections = caf::SelectionManager::instance()->objectsByType<RimEclipseStatisticsCaseCollection>();
|
2023-09-27 08:07:49 +02:00
|
|
|
if ( !statisticsCaseCollections.empty() )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
|
|
|
|
return statisticsCaseCollections[0];
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 12:53:14 +02:00
|
|
|
const auto caseCollections = caf::SelectionManager::instance()->objectsByType<RimCaseCollection>();
|
2023-09-27 08:07:49 +02:00
|
|
|
if ( !caseCollections.empty() )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( RimIdenticalGridCaseGroup::isStatisticsCaseCollection( caseCollections[0] ) )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
|
|
|
|
return caseCollections[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-18 18:56:43 +01:00
|
|
|
return nullptr;
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-08-21 11:47:59 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
RimEclipseStatisticsCase* RicNewStatisticsCaseFeature::addStatisticalCalculation( caf::PdmUiItem* uiItem )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2026-02-13 08:28:34 +01:00
|
|
|
RimCaseCollection* caseCollection = nullptr;
|
2015-08-21 11:47:59 +02:00
|
|
|
|
2026-02-13 08:28:34 +01:00
|
|
|
if ( auto* statCase = dynamic_cast<RimEclipseStatisticsCase*>( uiItem ) )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2026-02-13 08:28:34 +01:00
|
|
|
caseCollection = statCase->parentStatisticsCaseCollection();
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|
2026-02-13 08:28:34 +01:00
|
|
|
else if ( auto* caseColl = dynamic_cast<RimCaseCollection*>( uiItem ) )
|
2015-08-21 11:47:59 +02:00
|
|
|
{
|
2026-02-13 08:28:34 +01:00
|
|
|
caseCollection = caseColl;
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 08:28:34 +01:00
|
|
|
if ( !caseCollection ) return nullptr;
|
2015-08-21 11:47:59 +02:00
|
|
|
|
2026-02-13 08:28:34 +01:00
|
|
|
auto* ensembleBase = caseCollection->parentGridEnsembleBase();
|
|
|
|
|
if ( !ensembleBase ) return nullptr;
|
|
|
|
|
|
|
|
|
|
auto* createdObject = ensembleBase->createAndAppendStatisticsCase();
|
|
|
|
|
RimProject::current()->assignCaseIdToCase( createdObject );
|
|
|
|
|
|
|
|
|
|
caseCollection->parentField()->ownerObject()->uiCapability()->updateConnectedEditors();
|
|
|
|
|
|
|
|
|
|
return createdObject;
|
2015-08-21 11:47:59 +02:00
|
|
|
}
|