2018-09-21 06:44:27 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016- Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-09-21 06:44:27 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2018-09-21 06:44:27 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-09-21 06:44:27 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicExportSelectedWellPathsFeature.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
|
|
|
#include "RicExportWellPathsUi.h"
|
|
|
|
|
2019-10-15 04:30:06 -05:00
|
|
|
#include "RifTextDataTableFormatter.h"
|
2018-11-01 04:04:50 -05:00
|
|
|
|
2018-09-21 06:44:27 -05:00
|
|
|
#include "RigWellPath.h"
|
2020-09-04 06:46:53 -05:00
|
|
|
#include "RigWellPathGeometryExporter.h"
|
2018-09-21 06:44:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimDialogData.h"
|
2018-11-06 04:23:19 -06:00
|
|
|
#include "RimModeledWellPath.h"
|
2018-09-21 06:44:27 -05:00
|
|
|
#include "RimProject.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimWellPath.h"
|
|
|
|
#include "RimWellPathGeometryDef.h"
|
2018-09-21 06:44:27 -05:00
|
|
|
|
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cafSelectionManagerTools.h"
|
2018-09-21 06:44:27 -05:00
|
|
|
|
|
|
|
#include <QAction>
|
2020-08-21 11:56:12 -05:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2018-10-03 02:38:54 -05:00
|
|
|
|
|
|
|
#include <cafUtils.h>
|
2018-09-21 06:44:27 -05:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicExportSelectedWellPathsFeature, "RicExportSelectedWellPathsFeature" );
|
2018-09-21 06:44:27 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::exportWellPath( const RimWellPath* wellPath,
|
|
|
|
double mdStepSize,
|
|
|
|
const QString& folder,
|
|
|
|
bool writeProjectInfo )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
auto fileName = wellPath->name() + ".dev";
|
2019-09-06 03:40:57 -05:00
|
|
|
auto filePtr = openFileForExport( folder, fileName );
|
|
|
|
auto stream = createOutputFileStream( *filePtr );
|
2018-10-03 02:38:54 -05:00
|
|
|
|
2020-09-04 06:46:53 -05:00
|
|
|
std::vector<double> xValues;
|
|
|
|
std::vector<double> yValues;
|
|
|
|
std::vector<double> tvdValues;
|
|
|
|
std::vector<double> mdValues;
|
|
|
|
|
|
|
|
bool useMdRkb = false;
|
|
|
|
RigWellPathGeometryExporter::exportWellPathGeometry( wellPath, mdStepSize, xValues, yValues, tvdValues, mdValues, useMdRkb );
|
|
|
|
|
|
|
|
writeWellPathGeometryToStream( *stream, wellPath->name(), xValues, yValues, tvdValues, mdValues, useMdRkb, writeProjectInfo );
|
2018-10-03 02:38:54 -05:00
|
|
|
filePtr->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-10-03 02:38:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::writeWellPathGeometryToStream( QTextStream& stream,
|
2020-09-04 06:46:53 -05:00
|
|
|
const RigWellPath* wellPathGeom,
|
2019-09-06 03:40:57 -05:00
|
|
|
const QString& exportName,
|
|
|
|
double mdStepSize,
|
2020-09-04 06:46:53 -05:00
|
|
|
bool useMdRkb,
|
|
|
|
double rkbOffset,
|
2019-09-06 03:40:57 -05:00
|
|
|
bool writeProjectInfo )
|
2018-10-03 02:38:54 -05:00
|
|
|
{
|
2020-09-04 06:46:53 -05:00
|
|
|
std::vector<double> xValues;
|
|
|
|
std::vector<double> yValues;
|
|
|
|
std::vector<double> tvdValues;
|
|
|
|
std::vector<double> mdValues;
|
2018-11-06 04:23:19 -06:00
|
|
|
|
2020-09-04 06:46:53 -05:00
|
|
|
RigWellPathGeometryExporter::exportWellPathGeometry( wellPathGeom, mdStepSize, rkbOffset, xValues, yValues, tvdValues, mdValues );
|
|
|
|
writeWellPathGeometryToStream( stream, exportName, xValues, yValues, tvdValues, mdValues, useMdRkb, writeProjectInfo );
|
2018-12-05 05:47:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-12-05 05:47:07 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-09-04 06:46:53 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::writeWellPathGeometryToStream( QTextStream& stream,
|
|
|
|
const QString& exportName,
|
|
|
|
const std::vector<double>& xValues,
|
|
|
|
const std::vector<double>& yValues,
|
|
|
|
const std::vector<double>& tvdValues,
|
|
|
|
const std::vector<double>& mdValues,
|
|
|
|
bool useMdRkb,
|
|
|
|
bool writeProjectInfo )
|
2018-12-05 05:47:07 -06:00
|
|
|
{
|
2019-10-15 04:30:06 -05:00
|
|
|
RifTextDataTableFormatter formatter( stream );
|
2019-10-15 07:18:57 -05:00
|
|
|
formatter.setHeaderPrefix( "# " );
|
2019-09-06 03:40:57 -05:00
|
|
|
formatter.setCommentPrefix( "# " );
|
|
|
|
formatter.setTableRowPrependText( " " );
|
2018-11-01 04:04:50 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( writeProjectInfo )
|
2018-11-01 04:04:50 -05:00
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
formatter.comment( "Project: " + RimProject::current()->fileName );
|
2018-11-01 04:04:50 -05:00
|
|
|
stream << endl;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
stream << "WELLNAME: '" << caf::Utils::makeValidFileBasename( exportName ) << "'" << endl;
|
2018-09-21 06:44:27 -05:00
|
|
|
|
2019-10-15 04:30:06 -05:00
|
|
|
auto numberFormat = RifTextDataTableDoubleFormatting( RIF_FLOAT, 2 );
|
2020-06-08 04:09:11 -05:00
|
|
|
formatter.header( {{"X", numberFormat, RIGHT},
|
|
|
|
{"Y", numberFormat, RIGHT},
|
|
|
|
{"TVDMSL", numberFormat, RIGHT},
|
|
|
|
{useMdRkb ? "MDRKB" : "MDMSL", numberFormat, RIGHT}} );
|
2018-11-01 04:04:50 -05:00
|
|
|
|
2020-09-04 06:46:53 -05:00
|
|
|
for ( size_t i = 0; i < xValues.size(); i++ )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
// Write to file
|
2020-09-04 06:46:53 -05:00
|
|
|
formatter.add( xValues[i] );
|
|
|
|
formatter.add( yValues[i] );
|
|
|
|
formatter.add( tvdValues[i] );
|
|
|
|
formatter.add( mdValues[i] );
|
2019-09-06 03:40:57 -05:00
|
|
|
formatter.rowCompleted( "" );
|
2018-09-21 06:44:27 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
formatter.tableCompleted( "", false );
|
2018-11-01 04:04:50 -05:00
|
|
|
|
2018-10-03 02:38:54 -05:00
|
|
|
stream << -999 << endl << endl;
|
2018-09-21 06:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QFilePtr RicExportSelectedWellPathsFeature::openFileForExport( const QString& folderName, const QString& fileName )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QDir exportFolder = QDir( folderName );
|
|
|
|
if ( !exportFolder.exists() )
|
2018-09-25 02:09:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
bool createdPath = exportFolder.mkpath( "." );
|
|
|
|
if ( createdPath ) RiaLogging::info( "Created export folder " + folderName );
|
2018-09-25 02:09:13 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString filePath = exportFolder.filePath( fileName );
|
|
|
|
QFilePtr exportFile( new QFile( filePath ) );
|
|
|
|
if ( !exportFile->open( QIODevice::WriteOnly | QIODevice::Text ) )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto errorMessage = QString( "Export Well Path: Could not open the file: %1" ).arg( filePath );
|
|
|
|
RiaLogging::error( errorMessage );
|
2018-09-21 06:44:27 -05:00
|
|
|
}
|
|
|
|
return exportFile;
|
|
|
|
}
|
|
|
|
|
2018-10-03 02:38:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-10-03 02:38:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QTextStreamPtr RicExportSelectedWellPathsFeature::createOutputFileStream( QFile& file )
|
2018-10-03 02:38:54 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto stream = QTextStreamPtr( new QTextStream( &file ) );
|
|
|
|
stream->setRealNumberNotation( QTextStream::FixedNotation );
|
|
|
|
stream->setRealNumberPrecision( 2 );
|
2018-10-03 02:38:54 -05:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::handleAction( const std::vector<RimWellPath*>& wellPaths )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !wellPaths.empty() )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
auto dialogData = openDialog();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( dialogData )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto folder = dialogData->exportFolder();
|
2018-09-21 06:44:27 -05:00
|
|
|
auto mdStepSize = dialogData->mdStepSize();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( folder.isEmpty() )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( auto wellPath : wellPaths )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
exportWellPath( wellPath, mdStepSize, folder );
|
2018-09-21 06:44:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicExportSelectedWellPathsFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
std::vector<RimWellPath*> wellPaths = caf::selectedObjectsByTypeStrict<RimWellPath*>();
|
|
|
|
|
|
|
|
return !wellPaths.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::onActionTriggered( bool isChecked )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
std::vector<RimWellPath*> wellPaths = caf::selectedObjectsByTypeStrict<RimWellPath*>();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
handleAction( wellPaths );
|
2018-09-21 06:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::setupActionLook( QAction* actionToSetup )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Export Selected Well Paths" );
|
|
|
|
actionToSetup->setIcon( QIcon( ":/WellLogCurve16x16.png" ) );
|
2018-09-21 06:44:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-21 06:44:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicExportWellPathsUi* RicExportSelectedWellPathsFeature::openDialog()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
RimProject* proj = app->project();
|
2018-09-21 06:44:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString startPath = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "WELL_PATH_EXPORT_DIR" );
|
|
|
|
if ( startPath.isEmpty() )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QFileInfo fi( proj->fileName() );
|
2018-09-21 06:44:27 -05:00
|
|
|
startPath = fi.absolutePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
RicExportWellPathsUi* featureUi = app->project()->dialogData()->wellPathsExportData();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( featureUi->exportFolder().isEmpty() )
|
2018-10-03 02:38:54 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
featureUi->setExportFolder( startPath );
|
2018-10-03 02:38:54 -05:00
|
|
|
}
|
2018-09-21 06:44:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmUiPropertyViewDialog propertyDialog( nullptr,
|
|
|
|
featureUi,
|
|
|
|
"Export Well Paths",
|
|
|
|
"",
|
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
|
|
|
|
propertyDialog.resize( QSize( 600, 60 ) );
|
2018-09-21 06:44:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( propertyDialog.exec() == QDialog::Accepted && !featureUi->exportFolder().isEmpty() )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
auto dialogData = app->project()->dialogData()->wellPathsExportData();
|
2019-09-06 03:40:57 -05:00
|
|
|
app->setLastUsedDialogDirectory( "WELL_PATH_EXPORT_DIR", dialogData->exportFolder() );
|
2018-09-21 06:44:27 -05:00
|
|
|
return dialogData;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|