///////////////////////////////////////////////////////////////////////////////// // // 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 "Rim3dView.h" #include "RimGridView.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 ) { 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 ); // Ignore values for kinds which is known to not have values if ( !RimWellMeasurement::kindHasValue( measurement.kind ) ) { wellMeasurement->setValue( 0.0 ); } wellPathCollection->measurementCollection()->appendMeasurement( wellMeasurement ); lastWellMeasurement = wellMeasurement; } wellPathCollection->uiCapability()->updateConnectedEditors(); if ( app->project() ) { std::vector views; app->project()->allViews( views ); for ( auto& view : views ) { RimGridView* gridView = dynamic_cast( view ); if ( gridView ) { gridView->updateWellMeasurements(); } } 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; }