mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-05 21:53:27 -06:00
1da509166a
Add default implementation of isEnabled() and add const
117 lines
4.4 KiB
C++
117 lines
4.4 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2023- Equinor 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 "RicNewSummaryTableFeature.h"
|
|
|
|
#include "RiaSummaryTools.h"
|
|
|
|
#include "RimMainPlotCollection.h"
|
|
#include "RimSummaryAddress.h"
|
|
#include "RimSummaryTable.h"
|
|
#include "RimSummaryTableCollection.h"
|
|
|
|
#include "RiuPlotMainWindowTools.h"
|
|
|
|
#include "cafSelectionManagerTools.h"
|
|
|
|
#include "cvfAssert.h"
|
|
|
|
#include <QAction>
|
|
|
|
CAF_CMD_SOURCE_INIT( RicNewSummaryTableFeature, "RicNewSummaryTableFeature" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RicNewSummaryTableFeature::isCommandEnabled() const
|
|
{
|
|
RimSummaryTableCollection* tableColl = nullptr;
|
|
|
|
// Summary table collection selection
|
|
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
|
|
if ( selObj )
|
|
{
|
|
tableColl = RiaSummaryTools::parentSummaryTableCollection( selObj );
|
|
}
|
|
if ( tableColl ) return true;
|
|
|
|
// Summary Address selection - only for enabled categories
|
|
RimSummaryAddress* selectedSummaryAddress = nullptr;
|
|
if ( selObj )
|
|
{
|
|
selectedSummaryAddress = selObj->firstAncestorOrThisOfType<RimSummaryAddress>();
|
|
}
|
|
if ( selectedSummaryAddress && m_enabledCategories.contains( selectedSummaryAddress->address().category() ) ) return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicNewSummaryTableFeature::onActionTriggered( bool isChecked )
|
|
{
|
|
RimSummaryTableCollection* summaryTableColl = RimMainPlotCollection::current()->summaryTableCollection();
|
|
if ( !summaryTableColl ) return;
|
|
|
|
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
|
|
RimSummaryAddress* selectedSummaryAddress = nullptr;
|
|
if ( selObj )
|
|
{
|
|
selectedSummaryAddress = selObj->firstAncestorOrThisOfType<RimSummaryAddress>();
|
|
}
|
|
|
|
RimSummaryTable* summaryTable = nullptr;
|
|
if ( selectedSummaryAddress )
|
|
{
|
|
const auto adrObj = selectedSummaryAddress->address();
|
|
if ( !m_enabledCategories.contains( adrObj.category() ) ) return;
|
|
|
|
RimSummaryCase* summaryCase = RiaSummaryTools::summaryCaseById( selectedSummaryAddress->caseId() );
|
|
if ( !summaryCase ) return;
|
|
|
|
summaryTable = summaryTableColl->createSummaryTableFromCategoryAndVectorName( summaryCase,
|
|
adrObj.category(),
|
|
QString::fromStdString( adrObj.vectorName() ) );
|
|
}
|
|
else
|
|
{
|
|
summaryTable = summaryTableColl->createDefaultSummaryTable();
|
|
}
|
|
|
|
// Add summary table to collection
|
|
if ( summaryTable )
|
|
{
|
|
summaryTableColl->addTable( summaryTable );
|
|
summaryTableColl->updateConnectedEditors();
|
|
summaryTable->loadDataAndUpdate();
|
|
|
|
RiuPlotMainWindowTools::showPlotMainWindow();
|
|
RiuPlotMainWindowTools::onObjectAppended( summaryTable );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicNewSummaryTableFeature::setupActionLook( QAction* actionToSetup )
|
|
{
|
|
actionToSetup->setText( "New Summary Table" );
|
|
actionToSetup->setIcon( QIcon( ":/CorrelationMatrixPlot16x16.png" ) );
|
|
}
|