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"
|
|
|
|
|
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>
|
|
|
|
#include <QFileDialog>
|
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
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
writeWellPathGeometryToStream( *stream, wellPath, wellPath->name(), mdStepSize, 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,
|
|
|
|
const RimWellPath* wellPath,
|
|
|
|
const QString& exportName,
|
|
|
|
double mdStepSize,
|
|
|
|
bool writeProjectInfo )
|
2018-10-03 02:38:54 -05:00
|
|
|
{
|
2018-11-06 04:23:19 -06:00
|
|
|
auto wellPathGeom = wellPath->wellPathGeometry();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !wellPathGeom ) return;
|
2018-11-06 04:23:19 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
bool useMdRkb = false;
|
|
|
|
double rkb = 0.0;
|
2018-12-05 05:47:07 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const RimModeledWellPath* modeledWellPath = dynamic_cast<const RimModeledWellPath*>( wellPath );
|
|
|
|
if ( modeledWellPath )
|
2018-12-05 05:47:07 -06:00
|
|
|
{
|
|
|
|
useMdRkb = true;
|
2020-02-06 09:18:50 -06:00
|
|
|
if ( modeledWellPath->geometryDefinition()->airGap() != 0.0 )
|
|
|
|
{
|
|
|
|
rkb = modeledWellPath->geometryDefinition()->airGap();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-15 01:40:12 -05:00
|
|
|
rkb = modeledWellPath->geometryDefinition()->mdAtFirstTarget();
|
2020-02-06 09:18:50 -06:00
|
|
|
}
|
2018-12-05 05:47:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
writeWellPathGeometryToStream( stream, wellPathGeom, exportName, mdStepSize, useMdRkb, rkb, 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
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportSelectedWellPathsFeature::writeWellPathGeometryToStream( QTextStream& stream,
|
|
|
|
const RigWellPath* wellPathGeom,
|
|
|
|
const QString& exportName,
|
|
|
|
double mdStepSize,
|
|
|
|
bool useMdRkb,
|
|
|
|
double rkbOffset,
|
|
|
|
bool writeProjectInfo )
|
2018-12-05 05:47:07 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !wellPathGeom ) return;
|
2018-12-05 05:47:07 -06:00
|
|
|
|
2018-11-06 04:23:19 -06:00
|
|
|
double currMd = wellPathGeom->measureDepths().front() - mdStepSize;
|
2019-09-06 03:40:57 -05:00
|
|
|
double endMd = wellPathGeom->measureDepths().back();
|
2018-09-21 06:44:27 -05: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
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
formatter.comment( "Project: " + RiaApplication::instance()->project()->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-04-15 01:40:12 -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
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
while ( currMd < endMd )
|
2018-09-21 06:44:27 -05:00
|
|
|
{
|
|
|
|
currMd += mdStepSize;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currMd > endMd ) currMd = endMd;
|
2018-09-21 06:44:27 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
auto pt = wellPathGeom->interpolatedPointAlongWellPath( currMd );
|
2018-09-21 06:44:27 -05:00
|
|
|
double tvd = -pt.z();
|
|
|
|
|
|
|
|
// Write to file
|
2019-09-06 03:40:57 -05:00
|
|
|
formatter.add( pt.x() );
|
|
|
|
formatter.add( pt.y() );
|
|
|
|
formatter.add( tvd );
|
|
|
|
formatter.add( currMd + rkbOffset );
|
|
|
|
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;
|
|
|
|
}
|