2016-08-24 01:30:12 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016- Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-08-24 01:30:12 -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
|
|
|
//
|
2016-08-24 01:30:12 -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>
|
2016-08-24 01:30:12 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicImportFormationNamesFeature.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2017-10-20 07:34:56 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "Rim3dView.h"
|
2017-10-20 09:10:45 -05:00
|
|
|
#include "RimCase.h"
|
|
|
|
#include "RimEclipseCase.h"
|
2017-10-20 07:34:56 -05:00
|
|
|
#include "RimFormationNames.h"
|
|
|
|
#include "RimFormationNamesCollection.h"
|
2017-10-20 09:10:45 -05:00
|
|
|
#include "RimGeoMechCase.h"
|
2016-08-24 01:30:12 -05:00
|
|
|
#include "RimOilField.h"
|
2017-10-20 07:34:56 -05:00
|
|
|
#include "RimProject.h"
|
2017-10-20 09:10:45 -05:00
|
|
|
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
#include "RigFemPartResultsCollection.h"
|
|
|
|
#include "RigGeoMechCaseData.h"
|
|
|
|
|
2018-02-27 09:37:06 -06:00
|
|
|
#include "Riu3DMainWindowTools.h"
|
2016-08-24 01:30:12 -05:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicImportFormationNamesFeature, "RicImportFormationNamesFeature" );
|
2016-08-24 01:30:12 -05:00
|
|
|
|
2019-09-26 08:43:13 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimFormationNames* RicImportFormationNamesFeature::importFormationFiles( const QStringList& fileNames )
|
|
|
|
{
|
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
RimFormationNamesCollection* fomNameColl = proj->activeOilField()->formationNamesCollection();
|
|
|
|
if ( !fomNameColl )
|
|
|
|
{
|
|
|
|
fomNameColl = new RimFormationNamesCollection;
|
|
|
|
proj->activeOilField()->formationNamesCollection = fomNameColl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each file, find existing Formation names item, or create new
|
|
|
|
RimFormationNames* formationNames = fomNameColl->importFiles( fileNames );
|
|
|
|
fomNameColl->updateConnectedEditors();
|
|
|
|
|
|
|
|
return formationNames;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:30:12 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-08-24 01:30:12 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicImportFormationNamesFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-08-24 01:30:12 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicImportFormationNamesFeature::onActionTriggered( bool isChecked )
|
2016-08-24 01:30:12 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
QString defaultDir = app->lastUsedDialogDirectory( "BINARY_GRID" );
|
2019-10-18 07:45:12 -05:00
|
|
|
|
|
|
|
QString filterText = QString(
|
|
|
|
"Formation Names description File (*.lyr);;FMU Layer Zone Table(%1);;All Files (*.*)" )
|
|
|
|
.arg( RimFormationNames::layerZoneTableFileName() );
|
|
|
|
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
|
2019-09-06 03:40:57 -05:00
|
|
|
"Import Formation Names",
|
|
|
|
defaultDir,
|
2019-10-18 07:45:12 -05:00
|
|
|
filterText );
|
2016-08-24 01:30:12 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( fileNames.isEmpty() ) return;
|
2016-08-24 01:30:12 -05:00
|
|
|
|
|
|
|
// Remember the path to next time
|
2019-09-06 03:40:57 -05:00
|
|
|
app->setLastUsedDialogDirectory( "BINARY_GRID", QFileInfo( fileNames.last() ).absolutePath() );
|
2016-08-24 01:30:12 -05:00
|
|
|
|
|
|
|
// Find or create the FomationNamesCollection
|
2019-09-26 08:43:13 -05:00
|
|
|
RimFormationNames* formationName = importFormationFiles( fileNames );
|
2017-10-20 09:10:45 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( fileNames.size() > 1 ) return;
|
2017-12-01 08:38:29 -06:00
|
|
|
|
2019-09-26 08:43:13 -05:00
|
|
|
if ( formationName )
|
2017-10-20 09:10:45 -05:00
|
|
|
{
|
2019-09-26 08:43:13 -05:00
|
|
|
RimProject* proj = RiaApplication::instance()->project();
|
|
|
|
|
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
proj->allCases( cases );
|
|
|
|
|
|
|
|
if ( !cases.empty() )
|
2017-10-20 09:10:45 -05:00
|
|
|
{
|
2019-09-26 08:43:13 -05:00
|
|
|
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
|
|
|
|
if ( activeView )
|
2018-05-15 04:31:06 -05:00
|
|
|
{
|
2019-09-26 08:43:13 -05:00
|
|
|
RimCase* ownerCase = activeView->ownerCase();
|
|
|
|
if ( ownerCase )
|
|
|
|
{
|
|
|
|
ownerCase->setFormationNames( formationName );
|
2020-01-06 07:33:54 -06:00
|
|
|
ownerCase->updateFormationNamesData();
|
2019-09-26 08:43:13 -05:00
|
|
|
ownerCase->updateConnectedEditors();
|
|
|
|
}
|
2018-05-15 04:31:06 -05:00
|
|
|
}
|
2017-10-20 09:10:45 -05:00
|
|
|
}
|
2017-10-20 07:34:56 -05:00
|
|
|
|
2019-09-26 08:43:13 -05:00
|
|
|
if ( formationName )
|
|
|
|
{
|
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( formationName );
|
|
|
|
}
|
2017-10-20 07:34:56 -05:00
|
|
|
}
|
2016-08-24 01:30:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-08-24 01:30:12 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicImportFormationNamesFeature::setupActionLook( QAction* actionToSetup )
|
2016-08-24 01:30:12 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setIcon( QIcon( ":/FormationCollection16x16.png" ) );
|
|
|
|
actionToSetup->setText( "Import Formation Names" );
|
2016-08-24 01:30:12 -05:00
|
|
|
}
|