From d266e44f1f29bbf1a3431cb8c82e814a522074db Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Mon, 11 Nov 2019 23:09:22 +0100 Subject: [PATCH] #5001 Add RicImportWellMeasurementsFeature. --- .../WellPathCommands/CMakeLists_files.cmake | 2 + .../RicImportWellMeasurementsFeature.cpp | 142 ++++++++++++++++++ .../RicImportWellMeasurementsFeature.h | 40 +++++ .../RimContextCommandBuilder.cpp | 1 + 4 files changed, 185 insertions(+) create mode 100644 ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.cpp create mode 100644 ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.h diff --git a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake index d1f45fe324..2ed251eb7d 100644 --- a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake @@ -17,6 +17,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicWellPathFormationsImportFileFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicPolylineTargetsPickEventHandler.h ${CMAKE_CURRENT_LIST_DIR}/RicNewPolylineTargetFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDeletePolylineTargetFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicImportWellMeasurementsFeature.h ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/Ric3dObjectEditorHandle.h ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulator.h ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellTarget3dEditor.h @@ -44,6 +45,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicWellPathFormationsImportFileFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicPolylineTargetsPickEventHandler.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewPolylineTargetFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDeletePolylineTargetFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicImportWellMeasurementsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/Ric3dObjectEditorHandle.cpp ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPointTangentManipulator.cpp ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicWellTarget3dEditor.cpp diff --git a/ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.cpp b/ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.cpp new file mode 100644 index 0000000000..9f7c5e6ec5 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.cpp @@ -0,0 +1,142 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicImportWellMeasurementsFeature.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RimPerforationCollection.h" +#include "RimPerforationInterval.h" +#include "RimProject.h" +#include "RimWellMeasurement.h" +#include "RimWellMeasurementCollection.h" +#include "RimWellPath.h" +#include "RimWellPathCollection.h" + +#include "RifFileParseTools.h" +#include "RifWellMeasurementReader.h" + +#include "Riu3DMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include +#include + +CAF_CMD_SOURCE_INIT( RicImportWellMeasurementsFeature, "RicImportWellMeasurementsFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportWellMeasurementsFeature::isCommandEnabled() +{ + return ( RicImportWellMeasurementsFeature::selectedWellPathCollection() != nullptr ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportWellMeasurementsFeature::onActionTriggered( bool isChecked ) +{ + RimWellPathCollection* wellPathCollection = RicImportWellMeasurementsFeature::selectedWellPathCollection(); + CVF_ASSERT( wellPathCollection ); + + // Open dialog box to select well path files + RiaApplication* app = RiaApplication::instance(); + QString defaultDir = app->lastUsedDialogDirectory( "WELLPATH_DIR" ); + QStringList wellPathFilePaths = QFileDialog::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(), + "Import Well Measurements", + defaultDir, + "Well Measurements (*.csv);;All Files (*.*)" ); + + if ( wellPathFilePaths.size() < 1 ) return; + + // Remember the path to next time + app->setLastUsedDialogDirectory( "WELLPATH_DIR", QFileInfo( wellPathFilePaths.last() ).absolutePath() ); + + std::vector wellMeasurements; + try + { + RifWellMeasurementReader::readWellMeasurements( wellMeasurements, wellPathFilePaths ); + } + catch ( FileParseException& exception ) + { + RiaLogging::warning( QString( "Well measurement import failed: '%1'." ).arg( exception.message ) ); + return; + } + + RimWellMeasurement* lastWellMeasurement = nullptr; + for ( auto& measurement : wellMeasurements ) + { + RimWellPath* wellPath = wellPathCollection->tryFindMatchingWellPath( measurement.wellName ); + if ( wellPath == nullptr ) + { + RiaLogging::warning( QString( "Import Well Measurements : Imported file contains unknown well path '%1'." ) + .arg( measurement.wellName ) ); + } + else + { + RimWellMeasurement* wellMeasurement = new RimWellMeasurement; + wellMeasurement->setWellName( measurement.wellName ); + wellMeasurement->setMD( measurement.MD ); + wellMeasurement->setValue( measurement.value ); + wellMeasurement->setDate( measurement.date ); + wellMeasurement->setQuality( measurement.quality ); + wellMeasurement->setKind( measurement.kind ); + wellMeasurement->setRemark( measurement.remark ); + wellPath->measurementCollection()->appendMeasurement( wellMeasurement ); + lastWellMeasurement = wellMeasurement; + } + } + wellPathCollection->uiCapability()->updateConnectedEditors(); + + if ( app->project() ) + { + app->project()->scheduleCreateDisplayModelAndRedrawAllViews(); + } + + if ( lastWellMeasurement ) + { + Riu3DMainWindowTools::selectAsCurrentItem( lastWellMeasurement ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportWellMeasurementsFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "Import Measurements" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellPathCollection* RicImportWellMeasurementsFeature::selectedWellPathCollection() +{ + std::vector objects; + caf::SelectionManager::instance()->objectsByType( &objects ); + + if ( objects.size() == 1 ) + { + return objects[0]; + } + + return nullptr; +} diff --git a/ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.h b/ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.h new file mode 100644 index 0000000000..d4776c1ac4 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/RicImportWellMeasurementsFeature.h @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 RimWellPathCollection; + +//================================================================================================== +/// +//================================================================================================== +class RicImportWellMeasurementsFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + +private: + static RimWellPathCollection* selectedWellPathCollection(); +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 7dc7192cb3..5dccc998db 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -310,6 +310,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder.addSeparator(); menuBuilder << "RicWellPathImportPerforationIntervalsFeature"; menuBuilder << "RicWellPathImportCompletionsFileFeature"; + menuBuilder << "RicImportWellMeasurementsFeature"; menuBuilder.subMenuEnd(); menuBuilder.addSeparator(); menuBuilder.subMenuStart( "Export Well Paths", QIcon( ":/Save.png" ) );