From 85d3f98f9108a1553a0a8bcf2eb568eefca75819 Mon Sep 17 00:00:00 2001 From: Jon Jenssen Date: Mon, 7 Mar 2022 17:02:16 +0100 Subject: [PATCH] Allow drag'n'drop of realizations into summary plots Improve "Create Summary Case Group" feature to not delete selected realizations from the source collection. --- .../RicCreateSummaryCaseCollectionFeature.cpp | 20 +- .../Summary/RimSummaryCaseCollection.cpp | 9 +- .../Summary/RimSummaryMultiPlot.cpp | 1 - .../Summary/RimSummaryPlot.cpp | 191 +++++++++++------- .../ProjectDataModel/Summary/RimSummaryPlot.h | 4 + 5 files changed, 142 insertions(+), 83 deletions(-) diff --git a/ApplicationLibCode/Commands/RicCreateSummaryCaseCollectionFeature.cpp b/ApplicationLibCode/Commands/RicCreateSummaryCaseCollectionFeature.cpp index 0257a0174a..814194cefe 100644 --- a/ApplicationLibCode/Commands/RicCreateSummaryCaseCollectionFeature.cpp +++ b/ApplicationLibCode/Commands/RicCreateSummaryCaseCollectionFeature.cpp @@ -18,6 +18,8 @@ #include "RicCreateSummaryCaseCollectionFeature.h" +#include "RiaSummaryTools.h" + #include "RimSummaryCase.h" #include "RimSummaryCaseCollection.h" #include "RimSummaryCaseMainCollection.h" @@ -38,11 +40,9 @@ RimSummaryCaseCollection* RicCreateSummaryCaseCollectionFeature::groupSummaryCas const QString& groupName, bool isEnsemble ) { - RimSummaryCaseMainCollection* summaryCaseMainCollection = nullptr; + RimSummaryCaseMainCollection* summaryCaseMainCollection = RiaSummaryTools::summaryCaseMainCollection(); if ( !cases.empty() ) { - cases[0]->firstAncestorOrThisOfTypeAsserted( summaryCaseMainCollection ); - auto newGroup = summaryCaseMainCollection->addCaseCollection( cases, groupName, isEnsemble ); summaryCaseMainCollection->updateConnectedEditors(); @@ -84,7 +84,17 @@ void RicCreateSummaryCaseCollectionFeature::onActionTriggered( bool isChecked ) caf::SelectionManager::instance()->objectsByType( &selection ); if ( selection.size() == 0 ) return; - groupSummaryCases( selection, "" ); + std::vector duplicates; + + for ( const auto sumCase : selection ) + { + auto copy = + dynamic_cast( sumCase->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) ); + + duplicates.push_back( copy ); + } + + groupSummaryCases( duplicates, "" ); } //-------------------------------------------------------------------------------------------------- @@ -92,6 +102,6 @@ void RicCreateSummaryCaseCollectionFeature::onActionTriggered( bool isChecked ) //-------------------------------------------------------------------------------------------------- void RicCreateSummaryCaseCollectionFeature::setupActionLook( QAction* actionToSetup ) { - actionToSetup->setText( "Group Summary Cases" ); + actionToSetup->setText( "Create Summary Case Group" ); actionToSetup->setIcon( QIcon( ":/SummaryGroup16x16.png" ) ); } diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp index 6ec9752c3f..15e140f7e8 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp @@ -1005,10 +1005,13 @@ void RimSummaryCaseCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiT } m_dataVectorFolders->updateUiTreeOrdering( uiTreeOrdering ); - auto subnode = uiTreeOrdering.add( "Realizations", ":/Folder.png" ); - for ( auto& smcase : m_cases ) + if ( !m_cases.empty() ) { - subnode->add( smcase ); + auto subnode = uiTreeOrdering.add( "Realizations", ":/Folder.png" ); + for ( auto& smcase : m_cases ) + { + subnode->add( smcase ); + } } uiTreeOrdering.skipRemainingChildren( true ); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp index 1480bf501c..29a29d9f74 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp @@ -36,7 +36,6 @@ #include "RimSummaryPlotNameHelper.h" #include "RimSummaryPlotSourceStepping.h" -#include "PlotBuilderCommands/RicSummaryPlotBuilder.h" #include "RiuSummaryVectorSelectionUi.h" #include "cafPdmUiComboBoxEditor.h" diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index d6a9a20ff8..40679a1773 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -1823,6 +1823,115 @@ bool RimSummaryPlot::autoPlotTitle() const return m_useAutoPlotTitle; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RimSummaryPlot::handleSummaryCaseDrop( RimSummaryCase* summaryCase ) +{ + int newCurves = 0; + + std::map> dataVectorMap; + + for ( auto& curve : summaryCurves() ) + { + const auto curveAddress = curve->summaryAddressY(); + dataVectorMap[curveAddress].insert( curve->summaryCaseY() ); + } + + for ( const auto& [addr, cases] : dataVectorMap ) + { + if ( cases.count( summaryCase ) > 0 ) continue; + + addNewCurveY( addr, summaryCase ); + newCurves++; + } + + return newCurves; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RimSummaryPlot::handleAddressCollectionDrop( RimSummaryAddressCollection* addressCollection ) +{ + int newCurves = 0; + auto droppedName = addressCollection->name().toStdString(); + + if ( addressCollection->isEnsemble() ) return 0; + + auto summaryCase = RiaSummaryTools::summaryCaseById( addressCollection->caseId() ); + if ( summaryCase ) + { + if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL ) + { + std::map> 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++; + } + } + else if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP ) + { + std::map> 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++; + } + } + else if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION ) + { + std::map> 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; + + addNewCurveY( RifEclipseSummaryAddress::regionAddress( vectorName, droppedRegion ), summaryCase ); + newCurves++; + } + } + } + + return newCurves; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1832,6 +1941,13 @@ void RimSummaryPlot::handleDroppedObjects( const std::vector( obj ); + if ( summaryCase ) + { + newCurves += handleSummaryCaseDrop( summaryCase ); + continue; + } + auto summaryAdr = dynamic_cast( obj ); if ( summaryAdr ) { @@ -1843,7 +1959,6 @@ void RimSummaryPlot::handleDroppedObjects( const std::vectoraddress(), ensemble ); newCurves++; } - continue; } @@ -1859,79 +1974,7 @@ void RimSummaryPlot::handleDroppedObjects( const std::vector( obj ); if ( addressCollection ) { - auto droppedName = addressCollection->name().toStdString(); - - if ( addressCollection->isEnsemble() ) continue; - - auto summaryCase = RiaSummaryTools::summaryCaseById( addressCollection->caseId() ); - if ( summaryCase ) - { - if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL ) - { - std::map> 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++; - } - } - else if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP ) - { - std::map> 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++; - } - } - else if ( addressCollection->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION ) - { - std::map> 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; - - addNewCurveY( RifEclipseSummaryAddress::regionAddress( vectorName, droppedRegion ), summaryCase ); - newCurves++; - } - } - } + newCurves += handleAddressCollectionDrop( addressCollection ); continue; } } diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h index 5ba3ee6389..8e91e95ed5 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -41,6 +41,7 @@ class PdmUiTreeOrdering; class RimAsciiDataCurve; class RimGridTimeHistoryCurve; +class RimSummaryAddressCollection; class RimSummaryCase; class RimSummaryCaseCollection; class RimSummaryCurve; @@ -276,6 +277,9 @@ private: bool updateStackedCurveDataForAxis( RiuPlotAxis plotAxis ); bool updateStackedCurveDataForRelevantAxes(); + int handleSummaryCaseDrop( RimSummaryCase* summaryCase ); + int handleAddressCollectionDrop( RimSummaryAddressCollection* addrColl ); + private: #ifdef USE_QTCHARTS caf::PdmField m_useQtChartsPlot;