diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp index d40cdd8f7c..b1c8174ad4 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp @@ -18,28 +18,18 @@ #include "RicCreatePlotFromSelectionFeature.h" +#include "RiaGuiApplication.h" + #include "RicSelectPlotTemplateUi.h" #include "RicSummaryPlotTemplateTools.h" -#include "RiaGuiApplication.h" -#include "RiaLogging.h" -#include "RiaSummaryTools.h" - -#include "RifSummaryReaderInterface.h" - #include "PlotTemplates/RimPlotTemplateFileItem.h" #include "RimDialogData.h" -#include "RimMainPlotCollection.h" #include "RimProject.h" #include "RimSummaryCase.h" -#include "RimSummaryCurve.h" -#include "RimSummaryPlot.h" -#include "RimSummaryPlotCollection.h" -#include "RimWellPath.h" #include "RiuPlotMainWindow.h" -#include "cafPdmObject.h" #include "cafPdmUiPropertyViewDialog.h" #include "cafSelectionManager.h" @@ -61,8 +51,7 @@ bool RicCreatePlotFromSelectionFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked ) { - RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow(); - + RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow(); RicSelectPlotTemplateUi* ui = RiaGuiApplication::instance()->project()->dialogData()->selectPlotTemplateUi(); caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, ui, "Select Plot Template", "" ); @@ -75,60 +64,7 @@ void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked ) std::vector sumCases = selectedSummaryCases(); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); - if ( newSummaryPlot ) - { - RimSummaryPlotCollection* plotColl = - RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); - - plotColl->summaryPlots.push_back( newSummaryPlot ); - newSummaryPlot->resolveReferencesRecursively(); - newSummaryPlot->initAfterReadRecursively(); - - auto summaryCurves = newSummaryPlot->summaryCurves(); - - for ( const auto& curve : summaryCurves ) - { - auto fieldHandle = curve->findField( "SummaryCase" ); - if ( fieldHandle ) - { - auto referenceString = fieldHandle->xmlCapability()->referenceString(); - auto stringList = referenceString.split( " " ); - if ( stringList.size() == 2 ) - { - QString indexAsString = stringList[1]; - - bool conversionOk = false; - auto index = indexAsString.toUInt( &conversionOk ); - - if ( conversionOk && index < sumCases.size() ) - { - auto summaryCaseY = sumCases[index]; - curve->setSummaryCaseY( summaryCaseY ); - - auto currentAddressY = curve->summaryAddressY(); - if ( summaryCaseY->summaryReader() && - !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) ) - { - auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses(); - - auto candidate = RicCreatePlotFromSelectionFeature::firstAddressByQuantity( currentAddressY, - allAddresses ); - if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID ) - { - curve->setSummaryAddressY( candidate ); - } - } - } - } - } - } - - // TODO: Create additional curves in selected case count is larger than template count - - plotColl->updateConnectedEditors(); - - newSummaryPlot->loadDataAndUpdate(); - } + RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases ); } //-------------------------------------------------------------------------------------------------- @@ -150,21 +86,3 @@ std::vector RicCreatePlotFromSelectionFeature::selectedSummaryC return objects; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RifEclipseSummaryAddress - RicCreatePlotFromSelectionFeature::firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, - const std::set& allAddresses ) -{ - for ( const auto& a : allAddresses ) - { - if ( sourceAddress.quantityName() == a.quantityName() ) - { - return a; - } - } - - return RifEclipseSummaryAddress(); -} diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h index 57e39ed5cd..65a18dcfef 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h @@ -18,12 +18,8 @@ #pragma once -#include "RifEclipseSummaryAddress.h" - #include "cafCmdFeature.h" -#include - class RimSummaryCase; //================================================================================================== @@ -39,7 +35,5 @@ protected: void setupActionLook( QAction* actionToSetup ) override; private: - std::vector selectedSummaryCases() const; - static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, - const std::set& allAddresses ); + std::vector selectedSummaryCases() const; }; diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp index 91882c1fe7..d78f3b9b30 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp @@ -18,33 +18,12 @@ #include "RicCreatePlotFromTemplateFeature.h" -#include "RicSelectPlotTemplateUi.h" #include "RicSummaryPlotTemplateTools.h" - -#include "RiaGuiApplication.h" -#include "RiaLogging.h" -#include "RiaSummaryTools.h" - -#include "RifSummaryReaderInterface.h" - -#include "PlotTemplates/RimPlotTemplateFileItem.h" -#include "RimDialogData.h" -#include "RimMainPlotCollection.h" -#include "RimProject.h" #include "RimSummaryCase.h" -#include "RimSummaryCurve.h" -#include "RimSummaryPlot.h" -#include "RimSummaryPlotCollection.h" -#include "RimWellPath.h" -#include "RiuPlotMainWindow.h" - -#include "cafPdmObject.h" -#include "cafPdmUiPropertyViewDialog.h" #include "cafSelectionManager.h" #include -#include CAF_CMD_SOURCE_INIT( RicCreatePlotFromTemplateFeature, "RicCreatePlotFromTemplateFeature" ); @@ -65,60 +44,7 @@ void RicCreatePlotFromTemplateFeature::onActionTriggered( bool isChecked ) std::vector sumCases = selectedSummaryCases(); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); - if ( newSummaryPlot ) - { - RimSummaryPlotCollection* plotColl = - RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); - - plotColl->summaryPlots.push_back( newSummaryPlot ); - newSummaryPlot->resolveReferencesRecursively(); - newSummaryPlot->initAfterReadRecursively(); - - auto summaryCurves = newSummaryPlot->summaryCurves(); - - for ( const auto& curve : summaryCurves ) - { - auto fieldHandle = curve->findField( "SummaryCase" ); - if ( fieldHandle ) - { - auto referenceString = fieldHandle->xmlCapability()->referenceString(); - auto stringList = referenceString.split( " " ); - if ( stringList.size() == 2 ) - { - QString indexAsString = stringList[1]; - - bool conversionOk = false; - auto index = indexAsString.toUInt( &conversionOk ); - - if ( conversionOk && index < sumCases.size() ) - { - auto summaryCaseY = sumCases[index]; - curve->setSummaryCaseY( summaryCaseY ); - - auto currentAddressY = curve->summaryAddressY(); - if ( summaryCaseY->summaryReader() && - !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) ) - { - auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses(); - - auto candidate = RicCreatePlotFromTemplateFeature::firstAddressByQuantity( currentAddressY, - allAddresses ); - if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID ) - { - curve->setSummaryAddressY( candidate ); - } - } - } - } - } - } - - // TODO: Create additional curves in selected case count is larger than template count - - plotColl->updateConnectedEditors(); - - newSummaryPlot->loadDataAndUpdate(); - } + RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases ); } //-------------------------------------------------------------------------------------------------- @@ -140,21 +66,3 @@ std::vector RicCreatePlotFromTemplateFeature::selectedSummaryCa return objects; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RifEclipseSummaryAddress - RicCreatePlotFromTemplateFeature::firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, - const std::set& allAddresses ) -{ - for ( const auto& a : allAddresses ) - { - if ( sourceAddress.quantityName() == a.quantityName() ) - { - return a; - } - } - - return RifEclipseSummaryAddress(); -} diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h index 6a21ee19c0..a3194b4412 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h @@ -18,11 +18,9 @@ #pragma once -#include "RifEclipseSummaryAddress.h" - #include "cafCmdFeature.h" -#include +#include class RimSummaryCase; @@ -39,7 +37,5 @@ protected: void setupActionLook( QAction* actionToSetup ) override; private: - std::vector selectedSummaryCases() const; - static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, - const std::set& allAddresses ); + std::vector selectedSummaryCases() const; }; diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp index b8fd3a59c9..f246d9f7e0 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp @@ -18,11 +18,17 @@ #include "RicSummaryPlotTemplateTools.h" +#include "RiaApplication.h" #include "RiaLogging.h" #include "RiaSummaryCurveAnalyzer.h" +#include "RifSummaryReaderInterface.h" +#include "RimMainPlotCollection.h" +#include "RimProject.h" +#include "RimSummaryCase.h" #include "RimSummaryCurve.h" #include "RimSummaryPlot.h" +#include "RimSummaryPlotCollection.h" #include @@ -56,6 +62,68 @@ RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const Q return nullptr; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( + RimSummaryPlot* summaryPlot, const std::vector& selectedSummaryCases ) +{ + if ( summaryPlot ) + { + RimSummaryPlotCollection* plotColl = + RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); + + plotColl->summaryPlots.push_back( summaryPlot ); + summaryPlot->resolveReferencesRecursively(); + summaryPlot->initAfterReadRecursively(); + + auto summaryCurves = summaryPlot->summaryCurves(); + + for ( const auto& curve : summaryCurves ) + { + auto fieldHandle = curve->findField( "SummaryCase" ); + if ( fieldHandle ) + { + auto referenceString = fieldHandle->xmlCapability()->referenceString(); + auto stringList = referenceString.split( " " ); + if ( stringList.size() == 2 ) + { + QString indexAsString = stringList[1]; + + bool conversionOk = false; + auto index = indexAsString.toUInt( &conversionOk ); + + if ( conversionOk && index < selectedSummaryCases.size() ) + { + auto summaryCaseY = selectedSummaryCases[index]; + curve->setSummaryCaseY( summaryCaseY ); + + auto currentAddressY = curve->summaryAddressY(); + if ( summaryCaseY->summaryReader() && + !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) ) + { + auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses(); + + auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY, + allAddresses ); + if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID ) + { + curve->setSummaryAddressY( candidate ); + } + } + } + } + } + } + + // TODO: Create additional curves in selected case count is larger than template count + + plotColl->updateConnectedEditors(); + + summaryPlot->loadDataAndUpdate(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -156,3 +224,21 @@ QString RicSummaryPlotTemplateTools::htmlTextFromCount( const QString& itemText, return text; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RifEclipseSummaryAddress + RicSummaryPlotTemplateTools::firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, + const std::set& allAddresses ) +{ + for ( const auto& a : allAddresses ) + { + if ( sourceAddress.quantityName() == a.quantityName() ) + { + return a; + } + } + + return RifEclipseSummaryAddress(); +} diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h index 9b6df007ec..3b1ae85bb3 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h @@ -29,7 +29,7 @@ class PdmObject; } class RimSummaryPlot; -class RimSummaryPlot; +class RimSummaryCase; class RifEclipseSummaryAddress; //================================================================================================== @@ -39,9 +39,16 @@ class RicSummaryPlotTemplateTools { public: static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName ); - static QString htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot, - const std::set& selectedSummaryAddresses, - const std::vector& selectedSources ); + static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot, + const std::vector& selectedSummaryCases ); + + static QString htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot, + const std::set& selectedSummaryAddresses, + const std::vector& selectedSources ); static QString htmlTextFromCount( const QString& itemText, size_t requiredItemCount, size_t selectionCount ); + +private: + static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, + const std::set& allAddresses ); };