diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index 253fc135b2..2f0e6f408b 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -68,6 +68,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicCommandFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicReloadCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicReloadSummaryCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicReloadSummaryCasesFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicFlyToObjectFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicGridStatisticsDialog.h @@ -150,6 +151,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicReloadCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicReloadSummaryCaseFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicReplaceSummaryCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicFlyToObjectFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicGridStatisticsDialog.cpp diff --git a/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp b/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp index b6e2db167f..9f50c28440 100644 --- a/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp +++ b/ApplicationCode/Commands/RicImportGeneralDataFeature.cpp @@ -154,7 +154,7 @@ void RicImportGeneralDataFeature::setupActionLook( QAction* actionToSetup ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicImportGeneralDataFeature::openFileDialog( ImportFileType fileTypes ) +QStringList RicImportGeneralDataFeature::getEclipseFileNamesWithDialog( RiaDefines::ImportFileType fileTypes ) { QString eclipseGridFilePattern( "*.GRID" ); QString eclipseEGridFilePattern( "*.EGRID" ); @@ -195,7 +195,15 @@ void RicImportGeneralDataFeature::openFileDialog( ImportFileType fileTypes ) "Import Data File", defaultDir, fullPattern ); + return fileNames; +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportGeneralDataFeature::openFileDialog( ImportFileType fileTypes ) +{ + QStringList fileNames = getEclipseFileNamesWithDialog( fileTypes ); if ( fileNames.empty() ) return; if ( fileTypes == ANY_ECLIPSE_FILE ) diff --git a/ApplicationCode/Commands/RicImportGeneralDataFeature.h b/ApplicationCode/Commands/RicImportGeneralDataFeature.h index 9e14e8ffdf..b0b1f0947a 100644 --- a/ApplicationCode/Commands/RicImportGeneralDataFeature.h +++ b/ApplicationCode/Commands/RicImportGeneralDataFeature.h @@ -48,6 +48,7 @@ public: static OpenCaseResults openEclipseFilesFromFileNames( const QStringList& fileNames, bool doCreateDefaultPlot ); static QStringList fileNamesFromCaseNames( const QStringList& caseNames ); + static QStringList getEclipseFileNamesWithDialog( RiaDefines::ImportFileType fileTypes ); protected: // Overrides diff --git a/ApplicationCode/Commands/RicReplaceSummaryCaseFeature.cpp b/ApplicationCode/Commands/RicReplaceSummaryCaseFeature.cpp new file mode 100644 index 0000000000..507ee9964b --- /dev/null +++ b/ApplicationCode/Commands/RicReplaceSummaryCaseFeature.cpp @@ -0,0 +1,83 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- 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 "RicReplaceSummaryCaseFeature.h" + +#include "RiaLogging.h" +#include "RiaSummaryTools.h" + +#include "RicImportGeneralDataFeature.h" + +#include "RimFileSummaryCase.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" +#include "RimSummaryCaseMainCollection.h" +#include "RimSummaryPlot.h" +#include "RimSummaryPlotCollection.h" + +#include "cafPdmObject.h" +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicReplaceSummaryCaseFeature, "RicReplaceSummaryCaseFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicReplaceSummaryCaseFeature::isCommandEnabled() +{ + RimSummaryCase* rimSummaryCase = caf::SelectionManager::instance()->selectedItemOfType(); + return rimSummaryCase != nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicReplaceSummaryCaseFeature::onActionTriggered( bool isChecked ) +{ + RimFileSummaryCase* summaryCase = caf::SelectionManager::instance()->selectedItemOfType(); + if ( !summaryCase ) return; + + const QStringList fileNames = RicImportGeneralDataFeature::getEclipseFileNamesWithDialog( + RiaDefines::ECLIPSE_SUMMARY_FILE ); + if ( fileNames.isEmpty() ) return; + + QString oldSummaryHeaderFilename = summaryCase->summaryHeaderFilename(); + summaryCase->setSummaryHeaderFileName( fileNames[0] ); + summaryCase->resetAutoShortName(); + summaryCase->createSummaryReaderInterface(); + summaryCase->createRftReaderInterface(); + RiaLogging::info( QString( "Replaced summary data for %1" ).arg( oldSummaryHeaderFilename ) ); + + RimSummaryPlotCollection* summaryPlotColl = RiaSummaryTools::summaryPlotCollection(); + for ( RimSummaryPlot* summaryPlot : summaryPlotColl->summaryPlots ) + { + summaryPlot->loadDataAndUpdate(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicReplaceSummaryCaseFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "Replace" ); + // TODO: get an icon? + // actionToSetup->setIcon( QIcon( ":/Refresh-32.png" ) ); +} diff --git a/ApplicationCode/Commands/RicReplaceSummaryCaseFeature.h b/ApplicationCode/Commands/RicReplaceSummaryCaseFeature.h new file mode 100644 index 0000000000..767588a430 --- /dev/null +++ b/ApplicationCode/Commands/RicReplaceSummaryCaseFeature.h @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RicReplaceSummaryCaseFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index f9918973ba..f003a511bd 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -847,6 +847,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicImportObservedDataFeature"; menuBuilder << "RicImportObservedFmuDataFeature"; menuBuilder << "RicReloadSummaryCaseFeature"; + menuBuilder << "RicReplaceSummaryCaseFeature"; menuBuilder << "RicCreateSummaryCaseCollectionFeature"; menuBuilder << "Separator"; menuBuilder << "RicCutReferencesToClipboardFeature"; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.cpp index 5197abd42e..764617e10b 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.cpp @@ -34,6 +34,8 @@ CAF_PDM_ABSTRACT_SOURCE_INIT( RimSummaryCase, "SummaryCase" ); +const QString RimSummaryCase::DEFAULT_DISPLAY_NAME = "Display Name"; + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -41,7 +43,7 @@ RimSummaryCase::RimSummaryCase() { CAF_PDM_InitObject( "Summary Case", ":/SummaryCase16x16.png", "", "" ); - CAF_PDM_InitField( &m_shortName, "ShortName", QString( "Display Name" ), "Display Name", "", "", "" ); + CAF_PDM_InitField( &m_shortName, "ShortName", QString( "Display Name" ), DEFAULT_DISPLAY_NAME, "", "", "" ); CAF_PDM_InitField( &m_useAutoShortName, "AutoShortyName", false, "Use Auto Display Name", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_summaryHeaderFilename, "SummaryHeaderFilename", "Summary Header File", "", "", "" ); @@ -231,10 +233,19 @@ void RimSummaryCase::updateAutoShortName() m_shortName = oilField->uniqueShortNameForCase( this ); } - else if ( m_shortName() == QString( "Display Name" ) ) + else if ( m_shortName() == DEFAULT_DISPLAY_NAME ) { m_shortName = caseName(); } updateTreeItemName(); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryCase::resetAutoShortName() +{ + m_shortName = DEFAULT_DISPLAY_NAME; + updateAutoShortName(); +} diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.h index 5e9705c0b8..2214cee0ee 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCase.h @@ -50,6 +50,7 @@ public: RiaEclipseUnitTools::UnitSystemType unitsSystem(); void updateAutoShortName(); + void resetAutoShortName(); void updateOptionSensitivity(); virtual void createSummaryReaderInterface() = 0; @@ -87,6 +88,8 @@ protected: std::shared_ptr m_crlParameters; + static const QString DEFAULT_DISPLAY_NAME; + private: void initAfterRead() override; };