2017-05-08 03:48:11 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
2017-05-16 05:49:36 -05:00
// Copyright (C) 2017 Statoil ASA
2017-05-08 03:48:11 -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.
//
// 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 "RicExportFishbonesLateralsFeature.h"
# include "RiaApplication.h"
# include "RiaLogging.h"
2017-05-19 08:44:32 -05:00
# include "RimFishbonesCollection.h"
2017-05-08 03:48:11 -05:00
# include "RimFishbonesMultipleSubs.h"
# include "RimWellPath.h"
# include "cafSelectionManager.h"
# include "cafUtils.h"
# include "cvfAssert.h"
# include <QAction>
# include <QFileDialog>
# include <QMessageBox>
CAF_CMD_SOURCE_INIT ( RicExportFishbonesLateralsFeature , " RicExportFishbonesLateralsFeature " ) ;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportFishbonesLateralsFeature : : onActionTriggered ( bool isChecked )
{
2017-05-20 07:31:25 -05:00
RimFishbonesCollection * fishbonesCollection = selectedFishbonesCollection ( ) ;
CVF_ASSERT ( fishbonesCollection ) ;
RimWellPath * wellPath = nullptr ;
fishbonesCollection - > firstAncestorOrThisOfType ( wellPath ) ;
2017-05-08 03:48:11 -05:00
CVF_ASSERT ( wellPath ) ;
RiaApplication * app = RiaApplication : : instance ( ) ;
QString projectFolder = app - > currentProjectPath ( ) ;
QString defaultDir = app - > lastUsedDialogDirectoryWithFallback ( " WELL_PATH_EXPORT_DIR " , projectFolder ) ;
QString defaultFileName = defaultDir + " / " + caf : : Utils : : makeValidFileBasename ( ( wellPath - > name ( ) ) ) + " .dev " ;
QString completeFilename = QFileDialog : : getSaveFileName ( nullptr , " Select File for Well Path Data Export " , defaultFileName , " Well Path Text File(*.dev);;All files(*.*) " ) ;
if ( completeFilename . isEmpty ( ) ) return ;
QFile exportFile ( completeFilename ) ;
RiaLogging : : info ( " Starting export of Fishbones well path laterals to : " + completeFilename ) ;
if ( ! exportFile . open ( QIODevice : : WriteOnly ) )
{
RiaLogging : : error ( " Could not open the file : \n " + completeFilename ) ;
return ;
}
// See RifWellPathAsciiFileReader::readAllWellData for reading of dev files
2017-05-08 08:07:18 -05:00
//
// http://resinsight.org/docs/wellpaths/
2017-05-08 03:48:11 -05:00
// Export format
//
2017-05-08 08:07:18 -05:00
// wellname : <well name>__<sub lateral name>_<sub index>_<lateral index>
//
2017-05-08 03:48:11 -05:00
// for each coordinate along lateral, export
// x y TVD MD
// separate laterals using -999 on a single line
QTextStream stream ( & exportFile ) ;
2017-05-20 07:31:25 -05:00
for ( RimFishbonesMultipleSubs * fishbone : fishbonesCollection - > fishbonesSubs ( ) )
2017-05-08 03:48:11 -05:00
{
if ( ! fishbone - > isChecked ( ) ) continue ;
2017-06-02 03:16:16 -05:00
for ( auto & sub : fishbone - > installedLateralIndices ( ) )
2017-05-08 03:48:11 -05:00
{
2017-06-02 03:16:16 -05:00
for ( size_t lateralIndex : sub . lateralIndices )
2017-05-08 03:48:11 -05:00
{
2017-06-02 03:16:16 -05:00
std : : vector < std : : pair < cvf : : Vec3d , double > > coordsAndMD = fishbone - > coordsAndMDForLateral ( sub . subIndex , lateralIndex ) ;
2017-05-08 03:48:11 -05:00
// Pad with "0" to get a total of two characters defining the sub index text
2017-06-08 03:14:03 -05:00
QString subIndexText = QString ( " %1 " ) . arg ( sub . subIndex , 2 , 10 , QChar ( ' 0 ' ) ) ;
2017-05-08 03:48:11 -05:00
2017-05-19 02:51:19 -05:00
QString lateralNameCandidate = QString ( " %1_%2_%3_%4 " ) . arg ( wellPath - > name ( ) ) . arg ( " fishbone " ) . arg ( subIndexText ) . arg ( lateralIndex ) ;
2017-05-08 08:07:18 -05:00
QString lateralName = caf : : Utils : : makeValidFileBasename ( lateralNameCandidate ) ;
stream < < " WELLNAME: " < < lateralName < < endl ;
2017-05-08 03:48:11 -05:00
for ( auto coordMD : coordsAndMD )
{
2017-05-19 02:13:22 -05:00
int numberOfDecimals = 2 ;
2017-05-08 03:48:11 -05:00
// Export X and Y unchanged, invert sign of Z to get TVD, export MD unchanged
2017-06-02 03:16:16 -05:00
stream < < formatNumber ( coordMD . first . x ( ) , numberOfDecimals ) ;
stream < < " " < < formatNumber ( coordMD . first . y ( ) , numberOfDecimals ) ;
2017-05-19 02:13:22 -05:00
stream < < " " < < formatNumber ( - coordMD . first . z ( ) , numberOfDecimals ) ;
2017-06-02 03:16:16 -05:00
stream < < " " < < formatNumber ( coordMD . second , numberOfDecimals ) < < endl ;
2017-05-08 03:48:11 -05:00
}
stream < < - 999 < < endl < < endl ;
2017-06-02 03:16:16 -05:00
2017-05-08 03:48:11 -05:00
}
}
}
RiaLogging : : info ( " Completed export of Fishbones well path laterals to : " + completeFilename ) ;
}
2017-05-19 02:13:22 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicExportFishbonesLateralsFeature : : formatNumber ( double val , int numberOfDecimals )
{
return QString ( " %1 " ) . arg ( val , 0 , ' f ' , numberOfDecimals ) ;
}
2017-05-08 03:48:11 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-05-20 07:31:25 -05:00
RimFishbonesCollection * RicExportFishbonesLateralsFeature : : selectedFishbonesCollection ( )
2017-05-08 03:48:11 -05:00
{
2017-05-20 07:31:25 -05:00
RimFishbonesCollection * objToFind = nullptr ;
2017-05-08 03:48:11 -05:00
caf : : PdmUiItem * pdmUiItem = caf : : SelectionManager : : instance ( ) - > selectedItem ( ) ;
caf : : PdmObjectHandle * objHandle = dynamic_cast < caf : : PdmObjectHandle * > ( pdmUiItem ) ;
if ( objHandle )
{
2017-05-20 07:31:25 -05:00
objHandle - > firstAncestorOrThisOfType ( objToFind ) ;
2017-05-08 03:48:11 -05:00
}
2017-05-20 07:31:25 -05:00
return objToFind ;
2017-05-08 03:48:11 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportFishbonesLateralsFeature : : setupActionLook ( QAction * actionToSetup )
{
//actionToSetup->setIcon(QIcon(":/FractureSymbol16x16.png"));
2017-05-08 08:11:31 -05:00
actionToSetup - > setText ( " Export Laterals " ) ;
2017-05-08 03:48:11 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicExportFishbonesLateralsFeature : : isCommandEnabled ( )
{
2017-05-20 07:31:25 -05:00
if ( selectedFishbonesCollection ( ) )
2017-05-08 03:48:11 -05:00
{
return true ;
}
return false ;
}