#5111 Add command to reload well measurements from file

This commit is contained in:
Kristian Bendiksen 2020-01-14 14:04:01 +01:00 committed by Magne Sjaastad
parent ed19f41586
commit fc43c42f10
8 changed files with 312 additions and 97 deletions

View File

@ -61,6 +61,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicDeleteItemFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeleteSubItemsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeleteSummaryCaseCollectionFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeleteWellMeasurementFilePathFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicReloadWellMeasurementsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicWellMeasurementImportTools.h
${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.h
@ -149,6 +151,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicDeleteItemFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeleteSubItemsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeleteSummaryCaseCollectionFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeleteWellMeasurementFilePathFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicReloadWellMeasurementsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicWellMeasurementImportTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.cpp

View File

@ -0,0 +1,65 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicReloadWellMeasurementsFeature.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimWellMeasurementFilePath.h"
#include "RicWellMeasurementImportTools.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicReloadWellMeasurementsFeature, "RicReloadWellMeasurementsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicReloadWellMeasurementsFeature::isCommandEnabled()
{
std::vector<RimWellMeasurementFilePath*> filePaths;
caf::SelectionManager::instance()->objectsByType( &filePaths );
return !filePaths.empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadWellMeasurementsFeature::onActionTriggered( bool isChecked )
{
std::vector<RimWellMeasurementFilePath*> filePaths;
caf::SelectionManager::instance()->objectsByType( &filePaths );
if ( filePaths.empty() ) return;
RicWellMeasurementImportTools::removeWellMeasurementsFromFiles( filePaths );
RicWellMeasurementImportTools::importWellMeasurementsFromFiles( filePaths );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadWellMeasurementsFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Reload" );
actionToSetup->setIcon( QIcon( ":/Refresh-32.png" ) );
}

View File

@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
class RicReloadWellMeasurementsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -0,0 +1,163 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicWellMeasurementImportTools.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "Rim3dView.h"
#include "RimGridView.h"
#include "RimProject.h"
#include "RimWellMeasurement.h"
#include "RimWellMeasurementCollection.h"
#include "RimWellMeasurementFilePath.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RifFileParseTools.h"
#include "RifWellMeasurementReader.h"
#include "Riu3DMainWindowTools.h"
#include "Riu3dSelectionManager.h"
#include "cafSelectionManager.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellMeasurementImportTools::importWellMeasurementsFromFiles( const std::vector<RimWellMeasurementFilePath*>& filePaths )
{
if ( filePaths.empty() ) return;
QStringList files;
for ( RimWellMeasurementFilePath* filePath : filePaths )
{
files.append( filePath->filePath() );
}
// This assumes that the filepaths have the same well path collection
RimWellPathCollection* wellPathCollection = nullptr;
filePaths[0]->firstAncestorOrThisOfType( wellPathCollection );
if ( wellPathCollection )
{
importWellMeasurementsFromFiles( files, wellPathCollection );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellMeasurementImportTools::importWellMeasurementsFromFiles( const QStringList& filePaths,
RimWellPathCollection* wellPathCollection )
{
std::vector<RifWellMeasurement> wellMeasurements;
try
{
RifWellMeasurementReader::readWellMeasurements( wellMeasurements, filePaths );
}
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 );
wellMeasurement->setFilePath( measurement.filePath );
// 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();
RiaApplication* app = RiaApplication::instance();
if ( app->project() )
{
std::vector<Rim3dView*> views;
app->project()->allViews( views );
for ( auto& view : views )
{
RimGridView* gridView = dynamic_cast<RimGridView*>( view );
if ( gridView )
{
gridView->updateWellMeasurements();
}
}
app->project()->scheduleCreateDisplayModelAndRedrawAllViews();
}
if ( lastWellMeasurement )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastWellMeasurement );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellMeasurementImportTools::removeWellMeasurementsFromFiles( const std::vector<RimWellMeasurementFilePath*>& filePaths )
{
for ( RimWellMeasurementFilePath* filePath : filePaths )
{
RimWellMeasurementCollection* wellMeasurementCollection = nullptr;
filePath->firstAncestorOrThisOfType( wellMeasurementCollection );
if ( wellMeasurementCollection )
{
wellMeasurementCollection->removeMeasurementsForFilePath( filePath );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathCollection* RicWellMeasurementImportTools::selectedWellPathCollection()
{
std::vector<RimWellPathCollection*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
if ( objects.size() == 1 )
{
return objects[0];
}
auto measurementColl = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellMeasurementCollection>();
if ( measurementColl )
{
return caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPathCollection>();
}
return nullptr;
}

View File

@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QStringList>
#include <vector>
class RimWellPathCollection;
class RimWellMeasurementFilePath;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RicWellMeasurementImportTools
{
public:
static void importWellMeasurementsFromFiles( const std::vector<RimWellMeasurementFilePath*>& filePaths );
static void removeWellMeasurementsFromFiles( const std::vector<RimWellMeasurementFilePath*>& filePaths );
static void importWellMeasurementsFromFiles( const QStringList& filePaths, RimWellPathCollection* wellPathCollection );
static RimWellPathCollection* selectedWellPathCollection();
private:
// Hidden to avoid instantiation
RicWellMeasurementImportTools();
};

View File

@ -19,25 +19,13 @@
#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 "RicWellMeasurementImportTools.h"
#include "Riu3DMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileDialog>
@ -48,7 +36,7 @@ CAF_CMD_SOURCE_INIT( RicImportWellMeasurementsFeature, "RicImportWellMeasurement
//--------------------------------------------------------------------------------------------------
bool RicImportWellMeasurementsFeature::isCommandEnabled()
{
return ( RicImportWellMeasurementsFeature::selectedWellPathCollection() != nullptr );
return ( RicWellMeasurementImportTools::selectedWellPathCollection() != nullptr );
}
//--------------------------------------------------------------------------------------------------
@ -56,7 +44,7 @@ bool RicImportWellMeasurementsFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicImportWellMeasurementsFeature::onActionTriggered( bool isChecked )
{
RimWellPathCollection* wellPathCollection = RicImportWellMeasurementsFeature::selectedWellPathCollection();
RimWellPathCollection* wellPathCollection = RicWellMeasurementImportTools::selectedWellPathCollection();
CVF_ASSERT( wellPathCollection );
// Open dialog box to select well path files
@ -72,61 +60,7 @@ void RicImportWellMeasurementsFeature::onActionTriggered( bool isChecked )
// Remember the path to next time
app->setLastUsedDialogDirectory( "WELLPATH_DIR", QFileInfo( wellPathFilePaths.last() ).absolutePath() );
std::vector<RifWellMeasurement> 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 );
wellMeasurement->setFilePath( measurement.filePath );
// 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<Rim3dView*> views;
app->project()->allViews( views );
for ( auto& view : views )
{
RimGridView* gridView = dynamic_cast<RimGridView*>( view );
if ( gridView )
{
gridView->updateWellMeasurements();
}
}
app->project()->scheduleCreateDisplayModelAndRedrawAllViews();
}
if ( lastWellMeasurement )
{
Riu3DMainWindowTools::selectAsCurrentItem( lastWellMeasurement );
}
RicWellMeasurementImportTools::importWellMeasurementsFromFiles( wellPathFilePaths, wellPathCollection );
}
//--------------------------------------------------------------------------------------------------
@ -136,25 +70,3 @@ void RicImportWellMeasurementsFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Import Measurements" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathCollection* RicImportWellMeasurementsFeature::selectedWellPathCollection()
{
std::vector<RimWellPathCollection*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
if ( objects.size() == 1 )
{
return objects[0];
}
auto measurementColl = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellMeasurementCollection>();
if ( measurementColl )
{
return caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPathCollection>();
}
return nullptr;
}

View File

@ -20,8 +20,6 @@
#include "cafCmdFeature.h"
class RimWellPathCollection;
//==================================================================================================
///
//==================================================================================================
@ -34,7 +32,4 @@ protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
static RimWellPathCollection* selectedWellPathCollection();
};

View File

@ -330,6 +330,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
}
else if ( dynamic_cast<RimWellMeasurementFilePath*>( firstUiItem ) )
{
menuBuilder << "RicReloadWellMeasurementsFeature";
menuBuilder << "RicDeleteWellMeasurementFilePathFeature";
menuBuilder << "RicImportWellMeasurementsFeature";
}