#8747 MultiPlot : Duplicate and append plots for selected objects

This commit is contained in:
Magne Sjaastad 2022-03-31 08:57:52 +02:00
parent 28dcd47d73
commit 15f17234c8
9 changed files with 422 additions and 61 deletions

View File

@ -96,6 +96,14 @@ bool RiaSummaryCurveDefinition::isEnsembleCurve() const
return m_isEnsembleCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaSummaryCurveDefinition::setSummaryAddress( const RifEclipseSummaryAddress& address )
{
m_summaryAddress = address;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -46,6 +46,7 @@ public:
const RifEclipseSummaryAddress& summaryAddress() const;
RimSummaryCaseCollection* ensemble() const;
bool isEnsembleCurve() const;
void setSummaryAddress( const RifEclipseSummaryAddress& address );
bool operator<( const RiaSummaryCurveDefinition& other ) const;

View File

@ -5,6 +5,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromDataVectorFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryMultiPlotFromDataVectorFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromCurveFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicAppendSummaryPlotsForObjectsFeature.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -14,6 +15,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromDataVectorFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryMultiPlotFromDataVectorFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromCurveFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicAppendSummaryPlotsForObjectsFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,294 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 Equinor ASA
//
// 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.
//
// 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>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicAppendSummaryPlotsForObjectsFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaStdStringTools.h"
#include "RiaSummaryAddressAnalyzer.h"
#include "RicSummaryPlotBuilder.h"
#include "RimEnsembleCurveSet.h"
#include "RimSummaryAddressCollection.h"
#include "RimSummaryCurve.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
#include "RimSummaryPlot.h"
#include "cafAssert.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicAppendSummaryPlotsForObjectsFeature, "RicAppendSummaryPlotsForObjectsFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicAppendSummaryPlotsForObjectsFeature::isCommandEnabled()
{
return !selectedCollections().empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicAppendSummaryPlotsForObjectsFeature::onActionTriggered( bool isChecked )
{
// - Select a set of objects in Data Source (wells, well groups, regions, ..)
// - Use context menu to activate action
// - For each plot in the current active plot, create a duplicate plot and replace the object name
auto sumAddressCollections = selectedCollections();
if ( sumAddressCollections.empty() ) return;
RiaGuiApplication* app = RiaGuiApplication::instance();
auto activePlotWindow = dynamic_cast<RimSummaryMultiPlot*>( app->activePlotWindow() );
if ( activePlotWindow )
{
if ( !isSelectionCompatibleWithPlot( sumAddressCollections, activePlotWindow ) ) return;
std::vector<RimSummaryPlot*> sourcePlots;
{
auto plots = activePlotWindow->plots();
for ( auto p : plots )
{
auto sumPlot = dynamic_cast<RimSummaryPlot*>( p );
if ( p ) sourcePlots.push_back( sumPlot );
}
}
for ( auto summaryAdrCollection : sumAddressCollections )
{
auto duplicatedPlots = RicSummaryPlotBuilder::duplicateSummaryPlots( sourcePlots );
for ( auto duplicatedPlot : duplicatedPlots )
{
auto curveSets = duplicatedPlot->curveSets();
if ( !curveSets.empty() )
{
for ( auto curveSet : curveSets )
{
auto sourceAddress = curveSet->summaryAddress();
auto modifiedAdr = modifyAddress( sourceAddress, summaryAdrCollection );
curveSet->setSummaryAddress( modifiedAdr );
}
}
else
{
auto curves = duplicatedPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS );
for ( auto c : curves )
{
auto sourceAddress = c->summaryAddressY();
auto modifiedAdr = modifyAddress( sourceAddress, summaryAdrCollection );
c->setSummaryAddressY( modifiedAdr );
}
}
activePlotWindow->addPlot( duplicatedPlot );
duplicatedPlot->resolveReferencesRecursively();
}
}
activePlotWindow->loadDataAndUpdate();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicAppendSummaryPlotsForObjectsFeature::setupActionLook( QAction* actionToSetup )
{
QString objectType = "Objects";
auto addresses = selectedCollections();
if ( !addresses.empty() )
{
auto firstAdr = addresses.front();
if ( firstAdr->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL )
{
objectType = "Wells";
}
else if ( firstAdr->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP )
{
objectType = "Well Groups";
}
else if ( firstAdr->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION )
{
objectType = "Regions";
}
}
auto text = QString( "Append Plots For " ) + objectType;
actionToSetup->setText( text );
actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryAddressCollection*> RicAppendSummaryPlotsForObjectsFeature::selectedCollections()
{
std::vector<RimSummaryAddressCollection*> sumAddressCollections;
caf::SelectionManager::instance()->objectsByType( &sumAddressCollections );
if ( sumAddressCollections.size() == 1 )
{
auto coll = sumAddressCollections[0];
if ( coll->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_FOLDER ||
coll->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP_FOLDER ||
coll->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION_FOLDER )
{
// If a folder is selected, return all sub items in folder
auto childObjects = coll->subFolders();
return childObjects;
}
}
return sumAddressCollections;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicAppendSummaryPlotsForObjectsFeature::isSelectionCompatibleWithPlot(
const std::vector<RimSummaryAddressCollection*>& selection,
RimSummaryMultiPlot* summaryMultiPlot )
{
if ( !summaryMultiPlot ) return false;
if ( selection.empty() ) return false;
RiaSummaryAddressAnalyzer analyzer;
bool sourcePlotHasEnsembleData = false;
{
std::set<RifEclipseSummaryAddress> allAddresses;
auto curveSets = summaryMultiPlot->curveSets();
if ( !curveSets.empty() )
{
for ( auto curveSet : curveSets )
{
allAddresses.insert( curveSet->summaryAddress() );
}
sourcePlotHasEnsembleData = true;
}
else
{
auto curves = summaryMultiPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS );
for ( auto c : curves )
{
allAddresses.insert( c->summaryAddressY() );
}
}
analyzer.appendAddresses( allAddresses );
}
QString errorText;
auto selectionType = selection.front()->contentType();
if ( selectionType == RimSummaryAddressCollection::CollectionContentType::WELL )
{
if ( analyzer.wellNames().size() != 1 )
{
errorText = "Source plot must contain one well only to be able to duplicate a selection of wells";
}
}
else if ( selectionType == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP )
{
if ( analyzer.wellGroupNames().size() != 1 )
{
errorText =
"Source plot must contain one well group only to be able to duplicate a selection of well groups";
}
}
else if ( selectionType == RimSummaryAddressCollection::CollectionContentType::REGION )
{
if ( analyzer.regionNumbers().size() != 1 )
{
errorText = "Source plot must contain one region only to be able to duplicate a selection of regions";
}
}
if ( sourcePlotHasEnsembleData && selection.front()->ensembleId() == -1 )
{
errorText = "Source plot must contain single cases to be able to duplicate a selection of single cases";
}
else if ( !sourcePlotHasEnsembleData && selection.front()->caseId() == -1 )
{
errorText =
"Source plot must contain ensemble case plots to be able to duplicate a selection of ensemble cases";
}
if ( !errorText.isEmpty() )
{
RiaLogging::error( errorText );
return false;
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifEclipseSummaryAddress
RicAppendSummaryPlotsForObjectsFeature::modifyAddress( const RifEclipseSummaryAddress& sourceAddress,
RimSummaryAddressCollection* summaryAddressCollection )
{
CAF_ASSERT( summaryAddressCollection );
auto adr = sourceAddress;
auto objectName = summaryAddressCollection->name().toStdString();
if ( summaryAddressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL )
{
adr.setWellName( objectName );
}
else if ( summaryAddressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP )
{
adr.setWellGroupName( objectName );
}
else if ( summaryAddressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION )
{
int intValue = RiaStdStringTools::toInt( objectName );
if ( intValue == -1 )
{
QString errorText = QString( "Failed to convert region text to region integer value "
"for region text : " ) +
summaryAddressCollection->name();
RiaLogging::error( errorText );
}
else
{
adr.setRegion( intValue );
}
}
return adr;
}

View File

@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 Equinor ASA
//
// 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.
//
// 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>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
#include <vector>
class RimSummaryAddressCollection;
class RimSummaryMultiPlot;
class RifEclipseSummaryAddress;
//==================================================================================================
///
//==================================================================================================
class RicAppendSummaryPlotsForObjectsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
static std::vector<RimSummaryAddressCollection*> selectedCollections();
static bool isSelectionCompatibleWithPlot( const std::vector<RimSummaryAddressCollection*>& selection,
RimSummaryMultiPlot* summaryMultiPlot );
RifEclipseSummaryAddress modifyAddress( const RifEclipseSummaryAddress& sourceAddress,
RimSummaryAddressCollection* summaryAddressCollection );
};

View File

@ -1119,6 +1119,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicCloseObservedDataFeature";
menuBuilder << "RicNewMultiPlotFeature";
menuBuilder << "RicAppendSummaryPlotsForObjectsFeature";
// Work in progress -- End

View File

@ -129,9 +129,9 @@ void RimSummaryAddressCollection::updateFolderStructure( const std::set<RifEclip
RimSummaryAddressCollection* misc = getOrCreateSubfolder( "Miscellaneous", CollectionContentType::MISC );
RimSummaryAddressCollection* fields = getOrCreateSubfolder( "Field", CollectionContentType::FIELD );
RimSummaryAddressCollection* regions = getOrCreateSubfolder( "Regions" );
RimSummaryAddressCollection* wells = getOrCreateSubfolder( "Wells" );
RimSummaryAddressCollection* groups = getOrCreateSubfolder( "Well Groups" );
RimSummaryAddressCollection* regions = getOrCreateSubfolder( "Regions", CollectionContentType::REGION_FOLDER );
RimSummaryAddressCollection* wells = getOrCreateSubfolder( "Wells", CollectionContentType::WELL_FOLDER );
RimSummaryAddressCollection* groups = getOrCreateSubfolder( "Well Groups", CollectionContentType::WELL_GROUP_FOLDER );
for ( const auto& address : addresses )
{
@ -219,7 +219,6 @@ bool RimSummaryAddressCollection::isEmpty() const
bool RimSummaryAddressCollection::canBeDragged() const
{
bool ok = m_subfolders.size() == 0;
ok = ok && !isEnsemble();
ok = ok && ( m_contentType == CollectionContentType::WELL || m_contentType == CollectionContentType::WELL_GROUP ||
m_contentType == CollectionContentType::REGION );
@ -291,6 +290,14 @@ int RimSummaryAddressCollection::ensembleId() const
return m_ensembleId;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryAddressCollection*> RimSummaryAddressCollection::subFolders() const
{
return m_subfolders.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -40,7 +40,10 @@ public:
WELL_GROUP,
REGION,
FIELD,
MISC
MISC,
WELL_FOLDER,
WELL_GROUP_FOLDER,
REGION_FOLDER
};
public:
@ -66,6 +69,8 @@ public:
void setEnsembleId( int ensembleId );
int ensembleId() const;
std::vector<RimSummaryAddressCollection*> subFolders() const;
private:
RimSummaryAddressCollection*
getOrCreateSubfolder( const QString folderName,

View File

@ -1941,75 +1941,69 @@ int RimSummaryPlot::handleAddressCollectionDrop( RimSummaryAddressCollection* ad
int newCurves = 0;
auto droppedName = addressCollection->name().toStdString();
if ( addressCollection->isEnsemble() ) return 0;
auto summaryCase = RiaSummaryTools::summaryCaseById( addressCollection->caseId() );
auto ensembleCase = RiaSummaryTools::ensembleById( addressCollection->ensembleId() );
auto summaryCase = RiaSummaryTools::summaryCaseById( addressCollection->caseId() );
if ( summaryCase )
std::vector<RiaSummaryCurveDefinition> sourceCurveDefs;
std::map<RiaSummaryCurveDefinition, std::set<std::string>> newCurveDefsWithObjectNames;
if ( summaryCase && !ensembleCase )
{
for ( auto& curve : summaryCurves() )
{
sourceCurveDefs.push_back( curve->curveDefinitionY() );
}
}
if ( ensembleCase )
{
auto curveSets = m_ensembleCurveSetCollection->curveSets();
for ( auto curveSet : curveSets )
{
sourceCurveDefs.push_back( RiaSummaryCurveDefinition( ensembleCase, curveSet->summaryAddress() ) );
}
}
for ( auto& curveDef : sourceCurveDefs )
{
auto newCurveDef = curveDef;
auto curveAdr = newCurveDef.summaryAddress();
if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL )
{
std::map<std::string, std::set<std::string>> dataVectorMap;
for ( auto& curve : summaryCurves() )
{
const auto curveAddress = curve->summaryAddressY();
if ( curveAddress.category() == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_WELL )
{
dataVectorMap[curveAddress.quantityName()].insert( curveAddress.wellName() );
}
}
for ( auto& [vectorName, wellNames] : dataVectorMap )
{
if ( wellNames.count( droppedName ) > 0 ) continue;
addNewCurveY( RifEclipseSummaryAddress::wellAddress( vectorName, droppedName ), summaryCase );
newCurves++;
}
curveAdr.setWellName( droppedName );
newCurveDef.setSummaryAddress( curveAdr );
newCurveDefsWithObjectNames[newCurveDef].insert( curveAdr.wellName() );
}
else if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP )
{
std::map<std::string, std::set<std::string>> dataVectorMap;
for ( auto& curve : summaryCurves() )
{
const auto curveAddress = curve->summaryAddressY();
if ( curveAddress.category() == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_WELL_GROUP )
{
dataVectorMap[curveAddress.quantityName()].insert( curveAddress.wellGroupName() );
}
}
for ( auto& [vectorName, wellGroupNames] : dataVectorMap )
{
if ( wellGroupNames.count( droppedName ) > 0 ) continue;
addNewCurveY( RifEclipseSummaryAddress::wellGroupAddress( vectorName, droppedName ), summaryCase );
newCurves++;
}
curveAdr.setWellGroupName( droppedName );
newCurveDef.setSummaryAddress( curveAdr );
newCurveDefsWithObjectNames[newCurveDef].insert( curveAdr.wellGroupName() );
}
else if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION )
{
std::map<std::string, std::set<int>> dataVectorMap;
for ( auto& curve : summaryCurves() )
{
const auto curveAddress = curve->summaryAddressY();
if ( curveAddress.category() == RifEclipseSummaryAddress::SummaryVarCategory::SUMMARY_REGION )
{
dataVectorMap[curveAddress.quantityName()].insert( curveAddress.regionNumber() );
}
}
int droppedRegion = std::stoi( droppedName );
for ( auto& [vectorName, regionNumbers] : dataVectorMap )
{
if ( regionNumbers.count( droppedRegion ) > 0 ) continue;
curveAdr.setRegion( droppedRegion );
newCurveDef.setSummaryAddress( curveAdr );
newCurveDefsWithObjectNames[newCurveDef].insert( std::to_string( curveAdr.regionNumber() ) );
}
}
addNewCurveY( RifEclipseSummaryAddress::regionAddress( vectorName, droppedRegion ), summaryCase );
newCurves++;
}
for ( auto& [curveDef, objectNames] : newCurveDefsWithObjectNames )
{
// Skip adding new curves if the object name is already present for the curve definition
if ( objectNames.count( droppedName ) > 0 ) continue;
if ( curveDef.ensemble() )
{
addNewEnsembleCurveY( curveDef.summaryAddress(), curveDef.ensemble() );
newCurves++;
}
else if ( curveDef.summaryCase() )
{
addNewCurveY( curveDef.summaryAddress(), curveDef.summaryCase() );
newCurves++;
}
}