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