WIP: Color legend: import of lyr file with colors should generate custom color legend #5961

Work in progress:
- lacks support of views other than Eclipse views
- signature of RicImportFormationNamesFeature::importFormationFiles()
- reconsideration of variable names
This commit is contained in:
Stein Inge Dale 2020-07-30 14:31:11 +02:00 committed by Magne Sjaastad
parent edc4b39acb
commit 0424202461
4 changed files with 121 additions and 27 deletions

View File

@ -19,22 +19,29 @@
#include "RicImportFormationNamesFeature.h"
#include "RiaApplication.h"
#include "RigEclipseCaseData.h"
#include "RigFemPartResultsCollection.h"
#include "RigFormationNames.h"
#include "RigGeoMechCaseData.h"
#include "Rim3dView.h"
#include "RimCase.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RimFormationNames.h"
#include "RimFormationNamesCollection.h"
#include "RimGeoMechCase.h"
#include "RimGeoMechCellColors.h"
#include "RimGeoMechView.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RigEclipseCaseData.h"
#include "RigFemPartResultsCollection.h"
#include "RigGeoMechCaseData.h"
#include "Riu3DMainWindowTools.h"
#include "RimColorLegend.h"
#include "RimColorLegendCollection.h"
#include "RimColorLegendItem.h"
#include "RimRegularLegendConfig.h"
#include <QAction>
#include <QFileDialog>
@ -54,10 +61,15 @@ RimFormationNames* RicImportFormationNamesFeature::importFormationFiles( const Q
}
// For each file, find existing Formation names item, or create new
RimFormationNames* formationNames = fomNameColl->importFiles( fileNames );
std::vector<RimFormationNames*> formationNames = fomNameColl->importFiles( fileNames );
fomNameColl->updateConnectedEditors();
return formationNames;
for ( int i = 0; i < fileNames.size(); i++ )
{
RicImportFormationNamesFeature::addCustomColorLegend( QFileInfo( fileNames[i] ).baseName(), formationNames[i] );
}
return formationNames.back();
}
//--------------------------------------------------------------------------------------------------
@ -69,7 +81,9 @@ bool RicImportFormationNamesFeature::isCommandEnabled()
}
//--------------------------------------------------------------------------------------------------
///
/// If only one formation file is imported, the formation will automatically be set in the active
/// views case. Import of LYR files with colors create custom color legends according to color
/// definition on each file. However, color legend must be set by the user.
//--------------------------------------------------------------------------------------------------
void RicImportFormationNamesFeature::onActionTriggered( bool isChecked )
{
@ -90,18 +104,22 @@ void RicImportFormationNamesFeature::onActionTriggered( bool isChecked )
// Remember the path to next time
app->setLastUsedDialogDirectory( "BINARY_GRID", QFileInfo( fileNames.last() ).absolutePath() );
// Find or create the FomationNamesCollection
RimFormationNames* formationName = importFormationFiles( fileNames );
// Find or create the FormationNamesCollection
RimFormationNames* formationNames = importFormationFiles( fileNames );
// If we have more than 1 formation file, do not modify selected formation for the case in active view.
if ( fileNames.size() > 1 ) return;
if ( formationName )
if ( formationNames )
{
RimProject* proj = RimProject::current();
std::vector<RimCase*> cases;
proj->allCases( cases );
// Legend name is base name of the one formation file, c.f. RicImportFormationNamesFeature::importFormationFiles()
QString legendName = QFileInfo( fileNames.last() ).baseName();
if ( !cases.empty() )
{
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
@ -110,16 +128,18 @@ void RicImportFormationNamesFeature::onActionTriggered( bool isChecked )
RimCase* ownerCase = activeView->ownerCase();
if ( ownerCase )
{
ownerCase->setFormationNames( formationName );
ownerCase->setFormationNames( formationNames );
ownerCase->updateFormationNamesData();
setFormationCellResultAndLegend( activeView, legendName );
ownerCase->updateConnectedEditors();
}
}
}
if ( formationName )
if ( formationNames )
{
Riu3DMainWindowTools::selectAsCurrentItem( formationName );
Riu3DMainWindowTools::selectAsCurrentItem( formationNames );
}
}
}
@ -130,5 +150,74 @@ void RicImportFormationNamesFeature::onActionTriggered( bool isChecked )
void RicImportFormationNamesFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/FormationCollection16x16.png" ) );
actionToSetup->setText( "Import Formation Names" );
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;
RimColorLegend* colorLegend = new RimColorLegend;
colorLegend->setColorLegendName( name );
for ( size_t i = 0; i < formationColors.size(); i++ )
{
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
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 )
{
RimRegularLegendConfig* legendConfig = nullptr;
RimEclipseView* eclView = dynamic_cast<RimEclipseView*>( activeView );
if ( eclView )
{
eclView->cellResult()->setResultType( RiaDefines::ResultCatType::FORMATION_NAMES );
eclView->cellResult()->setResultVariable( RiaDefines::activeFormationNamesResultName() );
legendConfig = eclView->cellResult()->legendConfig();
eclView->cellResult()->updateUiFieldsFromActiveResult();
eclView->cellResult()->loadDataAndUpdate();
eclView->updateAllRequiredEditors();
eclView->updateDisplayModelForCurrentTimeStepAndRedraw();
}
RimGeoMechView* geoMechView = dynamic_cast<RimGeoMechView*>( activeView );
if ( geoMechView )
{
legendConfig = geoMechView->cellResult().p()->legendConfig;
// geoMechView->cellResult().p()->setResultType( RiaDefines::ResultCatType::FORMATION_NAMES );
// geoMechView->cellResult().p()->setResultVariable( RiaDefines::activeFormationNamesResultName() );
}
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
RimColorLegend* legend = colorLegendCollection->findByName( legendName );
legendConfig->setColorLegend( legend );
}

View File

@ -19,7 +19,10 @@
#pragma once
#include "cafCmdFeature.h"
class RimColorLegend;
class RimFormationNames;
class Rim3dView;
//==================================================================================================
///
@ -35,4 +38,12 @@ protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
static void addCustomColorLegend( QString& name, RimFormationNames* formationNames );
void setFormationCellResultAndLegend( Rim3dView* activeView, QString& legendName );
private:
RimColorLegend* m_lastCustomColorLegendCreated;
};

View File

@ -60,7 +60,7 @@ void RimFormationNamesCollection::readAllFormationNames()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFormationNames* RimFormationNamesCollection::importFiles( const QStringList& fileNames )
std::vector<RimFormationNames*> RimFormationNamesCollection::importFiles( const QStringList& fileNames )
{
QStringList newFileNames;
std::vector<RimFormationNames*> formNamesObjsToReload;
@ -111,14 +111,7 @@ RimFormationNames* RimFormationNamesCollection::importFiles( const QStringList&
QMessageBox::warning( nullptr, "Import Formation Names", totalErrorMessage );
}
if ( m_formationNamesList.size() > formationListBeforeImportCount )
{
return m_formationNamesList[m_formationNamesList.size() - 1];
}
else
{
return nullptr;
}
return m_formationNamesList.childObjects();
}
//--------------------------------------------------------------------------------------------------

View File

@ -37,7 +37,8 @@ public:
void readAllFormationNames();
RimFormationNames* importFiles( const QStringList& fileNames );
std::vector<RimFormationNames*> importFiles( const QStringList& fileNames );
void updateFilePathsFromProjectPath( const QString& newProjectPath, const QString& oldProjectPath );
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,