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"
|
2021-01-21 05:58:46 -06:00
|
|
|
|
#include "RiaResultNames.h"
|
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
|
#include "RigFemPartResultsCollection.h"
|
|
|
|
|
#include "RigFormationNames.h"
|
|
|
|
|
#include "RigGeoMechCaseData.h"
|
2021-01-21 05:58:46 -06:00
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
|
#include "Rim3dView.h"
|
2017-10-20 09:10:45 -05:00
|
|
|
|
#include "RimCase.h"
|
2021-01-21 05:58:46 -06:00
|
|
|
|
#include "RimColorLegend.h"
|
|
|
|
|
#include "RimColorLegendCollection.h"
|
|
|
|
|
#include "RimColorLegendItem.h"
|
2017-10-20 09:10:45 -05:00
|
|
|
|
#include "RimEclipseCase.h"
|
2020-07-30 07:31:11 -05:00
|
|
|
|
#include "RimEclipseCellColors.h"
|
2022-08-24 02:39:15 -05:00
|
|
|
|
#include "RimEclipseContourMapView.h"
|
2020-07-30 07:31:11 -05:00
|
|
|
|
#include "RimEclipseView.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"
|
2020-07-30 07:31:11 -05:00
|
|
|
|
#include "RimGeoMechCellColors.h"
|
2022-08-24 02:39:15 -05:00
|
|
|
|
#include "RimGeoMechContourMapView.h"
|
2020-07-30 07:31:11 -05:00
|
|
|
|
#include "RimGeoMechView.h"
|
2016-08-24 01:30:12 -05:00
|
|
|
|
#include "RimOilField.h"
|
2017-10-20 07:34:56 -05:00
|
|
|
|
#include "RimProject.h"
|
2020-07-30 07:31:11 -05:00
|
|
|
|
#include "RimRegularLegendConfig.h"
|
|
|
|
|
|
2018-02-27 09:37:06 -06:00
|
|
|
|
#include "Riu3DMainWindowTools.h"
|
2020-08-21 11:56:44 -05:00
|
|
|
|
#include "RiuFileDialogTools.h"
|
2016-08-24 01:30:12 -05:00
|
|
|
|
|
|
|
|
|
#include <QAction>
|
2020-08-21 11:56:44 -05:00
|
|
|
|
#include <QFileInfo>
|
2016-08-24 01:30:12 -05:00
|
|
|
|
|
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 )
|
|
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
|
RimProject* proj = RimProject::current();
|
2019-09-26 08:43:13 -05:00
|
|
|
|
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
|
2020-07-30 07:31:11 -05:00
|
|
|
|
std::vector<RimFormationNames*> formationNames = fomNameColl->importFiles( fileNames );
|
2019-09-26 08:43:13 -05:00
|
|
|
|
fomNameColl->updateConnectedEditors();
|
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
for ( int i = 0; i < fileNames.size(); i++ )
|
|
|
|
|
{
|
2020-08-04 02:03:31 -05:00
|
|
|
|
auto colors = formationNames[i]->formationNamesData()->formationColors();
|
|
|
|
|
|
|
|
|
|
bool anyValidColor = false;
|
|
|
|
|
for ( const auto& color : colors )
|
|
|
|
|
{
|
|
|
|
|
if ( color.isValid() )
|
|
|
|
|
{
|
|
|
|
|
anyValidColor = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( anyValidColor )
|
|
|
|
|
{
|
2020-08-05 07:46:27 -05:00
|
|
|
|
QString baseName = QFileInfo( fileNames[i] ).baseName();
|
|
|
|
|
RicImportFormationNamesFeature::addCustomColorLegend( baseName, formationNames[i] );
|
2020-08-04 02:03:31 -05:00
|
|
|
|
}
|
2020-07-30 07:31:11 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 07:18:36 -05:00
|
|
|
|
if ( !formationNames.empty() ) return formationNames.back();
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
2019-09-26 08:43:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-24 01:30:12 -05:00
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-07-30 07:31:11 -05:00
|
|
|
|
/// If only one formation file is imported, the formation will automatically be set in the active
|
2020-08-24 01:32:35 -05:00
|
|
|
|
/// view<65>s case. Import of LYR files with colors create custom color legends according to color
|
2020-07-30 07:31:11 -05:00
|
|
|
|
/// definition on each file. However, color legend must be set by the user.
|
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
|
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
|
QString filterText = QString( "Formation Names description File (*.lyr);;FMU Layer Zone Table(%1);;All Files (*.*)" )
|
|
|
|
|
.arg( RimFormationNames::layerZoneTableFileName() );
|
|
|
|
|
|
|
|
|
|
QStringList fileNames =
|
|
|
|
|
RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(), "Import Formation Names", defaultDir, 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
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
// Find or create the FormationNamesCollection
|
|
|
|
|
RimFormationNames* formationNames = importFormationFiles( fileNames );
|
2017-10-20 09:10:45 -05:00
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
// If we have more than 1 formation file, do not modify selected formation for the case in active view.
|
2019-09-06 03:40:57 -05:00
|
|
|
|
if ( fileNames.size() > 1 ) return;
|
2017-12-01 08:38:29 -06:00
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
if ( formationNames )
|
2017-10-20 09:10:45 -05:00
|
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
|
RimProject* proj = RimProject::current();
|
2019-09-26 08:43:13 -05:00
|
|
|
|
|
2023-09-11 08:12:18 -05:00
|
|
|
|
std::vector<RimCase*> cases = proj->allGridCases();
|
2019-09-26 08:43:13 -05:00
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
// Legend name is base name of the one formation file, c.f. RicImportFormationNamesFeature::importFormationFiles()
|
|
|
|
|
QString legendName = QFileInfo( fileNames.last() ).baseName();
|
|
|
|
|
|
2019-09-26 08:43:13 -05:00
|
|
|
|
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 )
|
|
|
|
|
{
|
2020-07-30 07:31:11 -05:00
|
|
|
|
ownerCase->setFormationNames( formationNames );
|
2020-01-06 07:33:54 -06:00
|
|
|
|
ownerCase->updateFormationNamesData();
|
2020-07-30 07:31:11 -05:00
|
|
|
|
|
|
|
|
|
setFormationCellResultAndLegend( activeView, legendName );
|
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
|
|
|
|
|
2020-07-30 07:31:11 -05:00
|
|
|
|
if ( formationNames )
|
2019-09-26 08:43:13 -05:00
|
|
|
|
{
|
2020-07-30 07:31:11 -05:00
|
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( formationNames );
|
2019-09-26 08:43:13 -05:00
|
|
|
|
}
|
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" ) );
|
2020-07-30 07:31:11 -05:00
|
|
|
|
actionToSetup->setText( "Import Formations" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RicImportFormationNamesFeature::addCustomColorLegend( QString& name, RimFormationNames* rimFormationNames )
|
|
|
|
|
{
|
|
|
|
|
RigFormationNames* rigFormationNames = rimFormationNames->formationNamesData();
|
|
|
|
|
if ( !rigFormationNames ) return;
|
|
|
|
|
|
|
|
|
|
const std::vector<QString>& formationNames = rigFormationNames->formationNames();
|
|
|
|
|
const std::vector<cvf::Color3f>& formationColors = rigFormationNames->formationColors();
|
|
|
|
|
|
|
|
|
|
// return if no formation names or colors (latter e.g. in case of FMU input or LYR without colors)
|
|
|
|
|
if ( formationNames.empty() || formationColors.empty() ) return;
|
|
|
|
|
|
2022-08-24 02:39:15 -05:00
|
|
|
|
auto* colorLegend = new RimColorLegend;
|
2020-07-30 07:31:11 -05:00
|
|
|
|
colorLegend->setColorLegendName( name );
|
|
|
|
|
|
|
|
|
|
for ( size_t i = 0; i < formationColors.size(); i++ )
|
|
|
|
|
{
|
2022-08-24 02:39:15 -05:00
|
|
|
|
auto* colorLegendItem = new RimColorLegendItem;
|
2020-07-30 07:31:11 -05:00
|
|
|
|
|
|
|
|
|
colorLegendItem->setValues( formationNames[i], (int)i, formationColors[i] );
|
|
|
|
|
|
|
|
|
|
colorLegend->appendColorLegendItem( colorLegendItem );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RimProject* proj = RimProject::current();
|
|
|
|
|
|
|
|
|
|
RimColorLegendCollection* colorLegendCollection = proj->colorLegendCollection;
|
|
|
|
|
|
|
|
|
|
colorLegendCollection->appendCustomColorLegend( colorLegend );
|
|
|
|
|
colorLegendCollection->updateConnectedEditors();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RicImportFormationNamesFeature::setFormationCellResultAndLegend( Rim3dView* activeView, QString& legendName )
|
|
|
|
|
{
|
2022-08-24 02:39:15 -05:00
|
|
|
|
auto eclipseContourMapView = dynamic_cast<RimEclipseContourMapView*>( activeView );
|
|
|
|
|
if ( eclipseContourMapView ) return;
|
|
|
|
|
|
|
|
|
|
auto geoMechContourMapView = dynamic_cast<RimGeoMechContourMapView*>( activeView );
|
|
|
|
|
if ( geoMechContourMapView ) return;
|
2020-07-30 07:31:11 -05:00
|
|
|
|
|
2022-08-24 02:39:15 -05:00
|
|
|
|
RimRegularLegendConfig* legendConfig = nullptr;
|
|
|
|
|
auto* eclView = dynamic_cast<RimEclipseView*>( activeView );
|
2020-07-30 07:31:11 -05:00
|
|
|
|
if ( eclView )
|
|
|
|
|
{
|
|
|
|
|
eclView->cellResult()->setResultType( RiaDefines::ResultCatType::FORMATION_NAMES );
|
2021-01-21 05:58:46 -06:00
|
|
|
|
eclView->cellResult()->setResultVariable( RiaResultNames::activeFormationNamesResultName() );
|
2020-07-30 07:31:11 -05:00
|
|
|
|
|
|
|
|
|
legendConfig = eclView->cellResult()->legendConfig();
|
|
|
|
|
|
|
|
|
|
eclView->cellResult()->updateUiFieldsFromActiveResult();
|
|
|
|
|
eclView->cellResult()->loadDataAndUpdate();
|
|
|
|
|
eclView->updateAllRequiredEditors();
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 02:39:15 -05:00
|
|
|
|
auto* geoMechView = dynamic_cast<RimGeoMechView*>( activeView );
|
2020-07-30 07:31:11 -05:00
|
|
|
|
if ( geoMechView )
|
|
|
|
|
{
|
2020-08-04 04:20:54 -05:00
|
|
|
|
legendConfig = geoMechView->cellResult()->legendConfig();
|
2020-07-30 07:31:11 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 04:20:54 -05:00
|
|
|
|
if ( legendConfig )
|
|
|
|
|
{
|
|
|
|
|
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
|
2020-07-30 07:31:11 -05:00
|
|
|
|
|
2020-08-04 04:20:54 -05:00
|
|
|
|
RimColorLegend* legend = colorLegendCollection->findByName( legendName );
|
|
|
|
|
if ( legend )
|
|
|
|
|
{
|
|
|
|
|
legendConfig->setColorLegend( legend );
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-26 10:11:13 -05:00
|
|
|
|
if ( eclView ) eclView->updateDisplayModelForCurrentTimeStepAndRedraw();
|
2016-08-24 01:30:12 -05:00
|
|
|
|
}
|