From eb5a0cf93658eed31fd3cbd75cc02bde7ae23df5 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 13 Mar 2023 14:47:44 +0100 Subject: [PATCH] Add reload and delete of pressure/depth data --- .../RicOpenInTextEditorFeature.cpp | 5 ++ .../Commands/CMakeLists_files.cmake | 2 + .../RicImportPressureDepthDataFeature.cpp | 19 +++-- .../RicReloadPressureDepthDataFeature.cpp | 75 +++++++++++++++++++ .../RicReloadPressureDepthDataFeature.h | 34 +++++++++ .../RimContextCommandBuilder.cpp | 8 +- .../RimObservedDataCollection.cpp | 9 +++ .../RimObservedDataCollection.h | 1 + .../ProjectDataModel/RimPressureDepthData.cpp | 12 ++- .../ProjectDataModel/RimPressureDepthData.h | 4 +- 10 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.cpp create mode 100644 ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.h diff --git a/ApplicationLibCode/Commands/ApplicationCommands/RicOpenInTextEditorFeature.cpp b/ApplicationLibCode/Commands/ApplicationCommands/RicOpenInTextEditorFeature.cpp index 103ea61123..89c9f8370c 100644 --- a/ApplicationLibCode/Commands/ApplicationCommands/RicOpenInTextEditorFeature.cpp +++ b/ApplicationLibCode/Commands/ApplicationCommands/RicOpenInTextEditorFeature.cpp @@ -80,6 +80,11 @@ void RicOpenInTextEditorFeature::onActionTriggered( bool isChecked ) { filePath = templateFileItem->absoluteFilePath(); } + + if ( auto pressureDepthData = dynamic_cast( uiItems.front() ) ) + { + filePath = pressureDepthData->filePath(); + } } if ( !filePath.isEmpty() ) diff --git a/ApplicationLibCode/Commands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/CMakeLists_files.cmake index cb8b727f2a..73ca084ac9 100644 --- a/ApplicationLibCode/Commands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/CMakeLists_files.cmake @@ -85,6 +85,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicDeleteUncheckedSubItemsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicRenameSummaryCaseFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicImportPressureDepthDataFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicReloadPressureDepthDataFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -173,6 +174,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicDeleteUncheckedSubItemsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicRenameSummaryCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicImportPressureDepthDataFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicReloadPressureDepthDataFeature.cpp ) if(RESINSIGHT_USE_QT_CHARTS) diff --git a/ApplicationLibCode/Commands/RicImportPressureDepthDataFeature.cpp b/ApplicationLibCode/Commands/RicImportPressureDepthDataFeature.cpp index 361a5e1bd5..ee2f0a74f4 100644 --- a/ApplicationLibCode/Commands/RicImportPressureDepthDataFeature.cpp +++ b/ApplicationLibCode/Commands/RicImportPressureDepthDataFeature.cpp @@ -50,20 +50,25 @@ CAF_CMD_SOURCE_INIT( RicImportPressureDepthDataFeature, "RicImportPressureDepthD //-------------------------------------------------------------------------------------------------- void RicImportPressureDepthDataFeature::selectPressureDepthDataPathInDialog() { - RiaApplication* app = RiaApplication::instance(); - QString defaultDir = app->lastUsedDialogDirectory( "SUMMARY_CASE_DIR" ); - QString filePath = RiuFileDialogTools::getOpenFileName( nullptr, "Import Pressure/Depth Data", defaultDir ); - + RiaApplication* app = RiaApplication::instance(); RimProject* proj = app->project(); RimObservedDataCollection* observedDataCollection = proj->activeOilField() ? proj->activeOilField()->observedDataCollection() : nullptr; if ( !observedDataCollection ) return; - const RimPressureDepthData* importedData = observedDataCollection->createAndAddPressureDepthDataFromPath( filePath ); + QString defaultDir = app->lastUsedDialogDirectory( "SUMMARY_CASE_DIR" ); + QString filterText = QString( "Text Files (*.txt);;All Files (*.*)" ); - if ( importedData != nullptr ) + RimPressureDepthData* firstImportedObject = nullptr; + QStringList filePaths = RiuFileDialogTools::getOpenFileNames( nullptr, "Import Pressure/Depth Data", defaultDir, filterText ); + for ( const QString& filePath : filePaths ) + { + RimPressureDepthData* importedData = observedDataCollection->createAndAddPressureDepthDataFromPath( filePath ); + if ( !firstImportedObject && importedData ) firstImportedObject = importedData; + } + if ( firstImportedObject != nullptr ) { RiuPlotMainWindowTools::showPlotMainWindow(); - RiuPlotMainWindowTools::selectAsCurrentItem( importedData ); + RiuPlotMainWindowTools::selectAsCurrentItem( firstImportedObject ); } } diff --git a/ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.cpp b/ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.cpp new file mode 100644 index 0000000000..b0c808e350 --- /dev/null +++ b/ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.cpp @@ -0,0 +1,75 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicReloadPressureDepthDataFeature.h" + +#include "RimPressureDepthData.h" +#include "RimViewWindow.h" + +#include "cafPdmObject.h" +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicReloadPressureDepthDataFeature, "RicReloadPressureDepthDataFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicReloadPressureDepthDataFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicReloadPressureDepthDataFeature::onActionTriggered( bool isChecked ) +{ + std::vector pressureDepthDataObjects; + caf::SelectionManager::instance()->objectsByType( &pressureDepthDataObjects ); + + for ( RimPressureDepthData* pressureDepthData : pressureDepthDataObjects ) + { + pressureDepthData->createRftReaderInterface(); + + std::vector referringObjects; + pressureDepthData->objectsWithReferringPtrFields( referringObjects ); + for ( auto refObj : referringObjects ) + { + if ( refObj ) + { + RimViewWindow* viewWindow = nullptr; + refObj->firstAncestorOrThisOfType( viewWindow ); + if ( viewWindow ) + { + viewWindow->loadDataAndUpdate(); + } + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicReloadPressureDepthDataFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "Reload" ); + actionToSetup->setIcon( QIcon( ":/Refresh.svg" ) ); +} diff --git a/ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.h b/ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.h new file mode 100644 index 0000000000..fb7ffca4bb --- /dev/null +++ b/ApplicationLibCode/Commands/RicReloadPressureDepthDataFeature.h @@ -0,0 +1,34 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RicReloadPressureDepthDataFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 1bc768fff3..2eb2974e52 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -105,6 +105,7 @@ #include "RimPlotDataFilterCollection.h" #include "RimPlotDataFilterItem.h" #include "RimPltPlotCollection.h" +#include "RimPressureDepthData.h" #include "RimPressureTable.h" #include "RimProject.h" #include "RimRftCase.h" @@ -133,6 +134,7 @@ #include "RimSummaryMultiPlot.h" #include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlot.h" +#include "RimSummaryTimeAxisProperties.h" #include "RimSurface.h" #include "RimSurfaceCollection.h" #include "RimValveTemplate.h" @@ -185,7 +187,6 @@ #include #include -#include "RimSummaryTimeAxisProperties.h" #include //-------------------------------------------------------------------------------------------------- @@ -1082,6 +1083,11 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder.addSeparator(); menuBuilder << "RicNewRftWellLogPlotFeature"; } + else if ( dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicOpenInTextEditorFeature"; + menuBuilder << "RicReloadPressureDepthDataFeature"; + } if ( dynamic_cast( firstUiItem ) ) { diff --git a/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.cpp index 530d794488..e6bb019a86 100644 --- a/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.cpp @@ -26,6 +26,7 @@ #include "RifKeywordVectorParser.h" #include "RimCsvUserData.h" +#include "RimMainPlotCollection.h" #include "RimObservedEclipseUserData.h" #include "RimObservedFmuRftData.h" #include "RimObservedSummaryData.h" @@ -112,6 +113,14 @@ std::vector RimObservedDataCollection::allPressureDepthDa return m_observedPressureDepthArray.children(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimObservedDataCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector& referringObjects ) +{ + RimMainPlotCollection::current()->loadDataAndUpdateAllPlots(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.h b/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.h index 259bf85f7c..499eb8d5d3 100644 --- a/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.h +++ b/ApplicationLibCode/ProjectDataModel/RimObservedDataCollection.h @@ -49,6 +49,7 @@ public: private: bool fileExists( const QString& fileName, QString* errorText = nullptr ); + void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector& referringObjects ) override; private: caf::PdmChildArrayField m_observedDataArray; diff --git a/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.cpp b/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.cpp index 05416202f3..6f50859955 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.cpp @@ -38,6 +38,16 @@ RimPressureDepthData::RimPressureDepthData() m_wells.xmlCapability()->disableIO(); m_wells.uiCapability()->setUiReadOnly( true ); m_wells.registerGetMethod( this, &RimPressureDepthData::wellNames ); + + setDeletable( true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimPressureDepthData::filePath() const +{ + return m_filePath().path(); } //-------------------------------------------------------------------------------------------------- @@ -53,7 +63,7 @@ void RimPressureDepthData::setFilePath( const QString& path ) //-------------------------------------------------------------------------------------------------- void RimPressureDepthData::createRftReaderInterface() { - m_fmuRftReader = new RifReaderPressureDepthData( m_filePath ); + m_fmuRftReader = new RifReaderPressureDepthData( m_filePath().path() ); m_fmuRftReader->load(); } diff --git a/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.h b/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.h index 34cd22c45a..8b8e27c60e 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.h +++ b/ApplicationLibCode/ProjectDataModel/RimPressureDepthData.h @@ -24,6 +24,7 @@ #include "RifReaderPressureDepthData.h" +#include "cafFilePath.h" #include "cafPdmField.h" #include "cafPdmObject.h" #include "cafPdmProxyValueField.h" @@ -35,6 +36,7 @@ class RimPressureDepthData : public RimNamedObject public: RimPressureDepthData(); + QString filePath() const; void setFilePath( const QString& path ); void createRftReaderInterface(); RifReaderRftInterface* rftReader(); @@ -45,6 +47,6 @@ public: private: cvf::ref m_fmuRftReader; - caf::PdmField m_filePath; + caf::PdmField m_filePath; caf::PdmProxyValueField> m_wells; };