///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2022 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RicShowGridCalculatorFeature.h" #include "RicGridCalculatorDialog.h" #include "RiaGuiApplication.h" #include "RimGridCalculationCollection.h" #include "RimGridCalculationVariable.h" #include "RimProject.h" #include "RimSummaryCalculationCollection.h" #include "RiuMainWindow.h" #include CAF_CMD_SOURCE_INIT( RicShowGridCalculatorFeature, "RicShowGridCalculatorFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicShowGridCalculatorFeature::addCalculationAndShowDialog( const RimEclipseResultAddress& address ) { RimProject* proj = RimProject::current(); RimGridCalculationCollection* calcColl = proj->gridCalculationCollection(); auto calculation = calcColl->addCalculation(); for ( auto& v : calculation->allVariables() ) { if ( auto gridVariable = dynamic_cast( v ) ) { gridVariable->setEclipseResultAddress( address ); } } RicGridCalculatorDialog* dialog = RicShowGridCalculatorFeature::gridCalculatorDialog( true ); dialog->setCalculationAndUpdateUi( calculation ); dialog->show(); dialog->raise(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RicGridCalculatorDialog* RicShowGridCalculatorFeature::gridCalculatorDialog( bool createIfNotPresent ) { RiuMainWindow* mainWindow = RiaGuiApplication::instance()->mainWindow(); if ( mainWindow ) { return mainWindow->gridCalculatorDialog( createIfNotPresent ); } return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicShowGridCalculatorFeature::hideGridCalculatorDialog() { auto dialog = RicShowGridCalculatorFeature::gridCalculatorDialog( false ); if ( dialog ) dialog->hide(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicShowGridCalculatorFeature::onActionTriggered( bool isChecked ) { RicGridCalculatorDialog* dialog = RicShowGridCalculatorFeature::gridCalculatorDialog( true ); RimProject* proj = RimProject::current(); RimGridCalculationCollection* calcColl = proj->gridCalculationCollection(); if ( calcColl->calculations().empty() ) { calcColl->addCalculation(); } dialog->setCalculationAndUpdateUi( calcColl->calculations()[0] ); dialog->show(); dialog->raise(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicShowGridCalculatorFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setText( "Grid Property Calculator" ); actionToSetup->setIcon( QIcon( ":/Calculator.svg" ) ); }