ResInsight/ApplicationLibCode/Commands/ExportCommands/RicExportFaultsFeature.cpp

116 lines
4.1 KiB
C++
Raw Normal View History

2016-11-25 08:57:17 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
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.
//
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.
//
// 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"
#include "RiaLogging.h"
#include "RiaResultNames.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"
2019-03-19 07:52:48 -05:00
#include "RifEclipseInputFileTools.h"
#include "RimEclipseCase.h"
#include "RimFaultInView.h"
#include "RiuFileDialogTools.h"
#include "cafSelectionManager.h"
#include "cafUtils.h"
2016-11-25 08:57:17 -06:00
#include <QAction>
CAF_CMD_SOURCE_INIT( RicExportFaultsFeature, "RicExportFaultsFeature" );
2016-11-25 08:57:17 -06:00
//--------------------------------------------------------------------------------------------------
///
2016-11-25 08:57:17 -06:00
//--------------------------------------------------------------------------------------------------
bool RicExportFaultsFeature::isCommandEnabled()
{
std::vector<RimFaultInView*> selectedFaults;
2016-11-25 08:57:17 -06:00
caf::SelectionManager::instance()->objectsByType( &selectedFaults );
2016-11-25 08:57:17 -06:00
return ( selectedFaults.size() > 0 );
2016-11-25 08:57:17 -06:00
}
//--------------------------------------------------------------------------------------------------
///
2016-11-25 08:57:17 -06:00
//--------------------------------------------------------------------------------------------------
void RicExportFaultsFeature::onActionTriggered( bool isChecked )
2016-11-25 08:57:17 -06:00
{
this->disableModelChangeContribution();
std::vector<RimFaultInView*> selectedFaults;
2016-11-25 08:57:17 -06:00
caf::SelectionManager::instance()->objectsByType( &selectedFaults );
2016-11-25 08:57:17 -06:00
if ( selectedFaults.size() == 0 ) return;
2016-11-25 08:57:17 -06:00
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallbackToProjectFolder( "FAULTS" );
2016-11-25 08:57:17 -06:00
QString selectedDir = RiuFileDialogTools::getExistingDirectory( nullptr, tr( "Select Directory" ), defaultDir );
2016-11-25 08:57:17 -06:00
if ( selectedDir.isNull() )
{
// Stop if folder selection was cancelled.
return;
}
for ( RimFaultInView* rimFault : selectedFaults )
2016-11-25 08:57:17 -06:00
{
RimEclipseCase* eclCase = nullptr;
rimFault->firstAncestorOrThisOfType( eclCase );
2016-11-25 08:57:17 -06:00
if ( eclCase )
{
QString caseName = eclCase->caseUserDescription();
2016-11-25 08:57:17 -06:00
QString faultName = rimFault->name();
if ( faultName == RiaResultNames::undefinedGridFaultName() ) faultName = "UNDEF";
if ( faultName == RiaResultNames::undefinedGridFaultWithInactiveName() ) faultName = "UNDEF_IA";
2016-11-25 08:57:17 -06:00
QString baseFilename = "Fault_" + faultName + "_" + caseName;
baseFilename = caf::Utils::makeValidFileBasename( baseFilename );
2016-11-25 08:57:17 -06:00
QString completeFilename = selectedDir + "/" + baseFilename + ".grdecl";
2016-11-25 08:57:17 -06:00
RifEclipseInputFileTools::saveFault( completeFilename,
eclCase->eclipseCaseData()->mainGrid(),
rimFault->faultGeometry()->faultFaces(),
faultName );
}
2016-11-25 08:57:17 -06:00
}
// Remember the path to next time
RiaApplication::instance()->setLastUsedDialogDirectory( "FAULTS", selectedDir );
2016-11-25 08:57:17 -06:00
}
//--------------------------------------------------------------------------------------------------
///
2016-11-25 08:57:17 -06:00
//--------------------------------------------------------------------------------------------------
void RicExportFaultsFeature::setupActionLook( QAction* actionToSetup )
2016-11-25 08:57:17 -06: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
}