2016-11-25 08:57:17 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-11-25 08:57:17 -06: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
|
|
|
//
|
2016-11-25 08:57:17 -06: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>
|
2016-11-25 08:57:17 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicExportFaultsFeature.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2018-02-02 02:37:34 -06:00
|
|
|
#include "RiaLogging.h"
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2017-01-10 02:51:39 -06:00
|
|
|
#include "RigEclipseCaseData.h"
|
2016-11-25 08:57:17 -06:00
|
|
|
#include "RigFault.h"
|
|
|
|
#include "RigMainGrid.h"
|
2017-01-09 12:51:15 -06:00
|
|
|
|
2019-03-19 07:52:48 -05:00
|
|
|
#include "RifEclipseInputFileTools.h"
|
|
|
|
|
2017-01-09 12:51:15 -06:00
|
|
|
#include "RimEclipseCase.h"
|
2017-10-13 08:01:52 -05:00
|
|
|
#include "RimFaultInView.h"
|
2017-01-09 12:51:15 -06:00
|
|
|
|
2020-08-21 11:56:44 -05:00
|
|
|
#include "RiuFileDialogTools.h"
|
|
|
|
|
2017-01-09 12:51:15 -06:00
|
|
|
#include "cafSelectionManager.h"
|
2017-01-04 03:45:04 -06:00
|
|
|
#include "cafUtils.h"
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2017-01-09 12:51:15 -06:00
|
|
|
#include <QAction>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicExportFaultsFeature, "RicExportFaultsFeature" );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-25 08:57:17 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicExportFaultsFeature::isCommandEnabled()
|
|
|
|
{
|
2017-10-13 08:01:52 -05:00
|
|
|
std::vector<RimFaultInView*> selectedFaults;
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedFaults );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( selectedFaults.size() > 0 );
|
2016-11-25 08:57:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-25 08:57:17 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportFaultsFeature::onActionTriggered( bool isChecked )
|
2016-11-25 08:57:17 -06:00
|
|
|
{
|
2017-04-20 03:38:58 -05:00
|
|
|
this->disableModelChangeContribution();
|
|
|
|
|
2017-10-13 08:01:52 -05:00
|
|
|
std::vector<RimFaultInView*> selectedFaults;
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::SelectionManager::instance()->objectsByType( &selectedFaults );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( selectedFaults.size() == 0 ) return;
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallbackToProjectFolder( "FAULTS" );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2020-08-21 11:56:44 -05:00
|
|
|
QString selectedDir = RiuFileDialogTools::getExistingDirectory( nullptr, tr( "Select Directory" ), defaultDir );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( selectedDir.isNull() )
|
|
|
|
{
|
2017-04-04 10:15:28 -05:00
|
|
|
// Stop if folder selection was cancelled.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( RimFaultInView* rimFault : selectedFaults )
|
2016-11-25 08:57:17 -06:00
|
|
|
{
|
|
|
|
RimEclipseCase* eclCase = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
rimFault->firstAncestorOrThisOfType( eclCase );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( eclCase )
|
2018-08-02 12:22:03 -05:00
|
|
|
{
|
|
|
|
QString caseName = eclCase->caseUserDescription();
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2018-08-02 12:22:03 -05:00
|
|
|
QString faultName = rimFault->name();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( faultName == RiaDefines::undefinedGridFaultName() ) faultName = "UNDEF";
|
|
|
|
if ( faultName == RiaDefines::undefinedGridFaultWithInactiveName() ) faultName = "UNDEF_IA";
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2018-08-02 12:22:03 -05:00
|
|
|
QString baseFilename = "Fault_" + faultName + "_" + caseName;
|
2019-09-06 03:40:57 -05:00
|
|
|
baseFilename = caf::Utils::makeValidFileBasename( baseFilename );
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2018-08-02 12:22:03 -05:00
|
|
|
QString completeFilename = selectedDir + "/" + baseFilename + ".grdecl";
|
2016-11-25 08:57:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RifEclipseInputFileTools::saveFault( completeFilename,
|
|
|
|
eclCase->eclipseCaseData()->mainGrid(),
|
|
|
|
rimFault->faultGeometry()->faultFaces(),
|
|
|
|
faultName );
|
2018-08-02 12:22:03 -05:00
|
|
|
}
|
2016-11-25 08:57:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember the path to next time
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaApplication::instance()->setLastUsedDialogDirectory( "FAULTS", selectedDir );
|
2016-11-25 08:57:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-25 08:57:17 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicExportFaultsFeature::setupActionLook( QAction* actionToSetup )
|
2016-11-25 08:57:17 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "Export Faults ..." );
|
2020-10-01 10:25:19 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/Save.svg" ) );
|
2016-11-25 08:57:17 -06:00
|
|
|
}
|