diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationMatrixPlotFeature.cpp b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationMatrixPlotFeature.cpp index 66abf4b991..4c3bb436ed 100644 --- a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationMatrixPlotFeature.cpp +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationMatrixPlotFeature.cpp @@ -18,9 +18,13 @@ #include "RicNewCorrelationMatrixPlotFeature.h" +#include "RicNewCorrelationPlotFeature.h" + #include "RimCorrelationMatrixPlot.h" #include "RimCorrelationPlot.h" #include "RimCorrelationPlotCollection.h" +#include "RimProject.h" +#include "RimSummaryPlot.h" #include "RiuPlotMainWindowTools.h" @@ -45,6 +49,10 @@ bool RicNewCorrelationMatrixPlotFeature::isCommandEnabled() if ( correlationPlotColl ) return true; + RimSummaryPlot* summaryPlot = nullptr; + selObj->firstAncestorOrThisOfType( summaryPlot ); + if ( summaryPlot ) return true; + return false; } @@ -61,9 +69,32 @@ void RicNewCorrelationMatrixPlotFeature::onActionTriggered( bool isChecked ) selObj->firstAncestorOrThisOfType( correlationPlotColl ); } - if ( !correlationPlotColl ) return; + RimSummaryCaseCollection* ensemble = nullptr; + std::time_t timeStep = 0; + + RimCorrelationMatrixPlot* newPlot = nullptr; + if ( !correlationPlotColl ) + { + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + std::vector correlationPlotCollections; + RimProject::current()->descendantsOfType( correlationPlotCollections ); + CAF_ASSERT( !correlationPlotCollections.empty() ); + correlationPlotColl = correlationPlotCollections.front(); + + CorrelationPlotParams params = userData.value(); + ensemble = params.ensemble; + timeStep = params.timeStep; + + newPlot = correlationPlotColl->createCorrelationMatrixPlot( ensemble, timeStep ); + } + } + else + { + newPlot = correlationPlotColl->createCorrelationMatrixPlot(); + } - auto newPlot = correlationPlotColl->createCorrelationMatrixPlot(); newPlot->loadDataAndUpdate(); correlationPlotColl->updateConnectedEditors(); diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.cpp b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.cpp index 4757708498..f50a0f8a21 100644 --- a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.cpp +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.cpp @@ -20,6 +20,8 @@ #include "RimCorrelationPlot.h" #include "RimCorrelationPlotCollection.h" +#include "RimProject.h" +#include "RimSummaryPlot.h" #include "RiuPlotMainWindowTools.h" @@ -44,6 +46,10 @@ bool RicNewCorrelationPlotFeature::isCommandEnabled() if ( correlationPlotColl ) return true; + RimSummaryPlot* summaryPlot = nullptr; + selObj->firstAncestorOrThisOfType( summaryPlot ); + if ( summaryPlot ) return true; + return false; } @@ -60,9 +66,34 @@ void RicNewCorrelationPlotFeature::onActionTriggered( bool isChecked ) selObj->firstAncestorOrThisOfType( correlationPlotColl ); } - if ( !correlationPlotColl ) return; + RimSummaryCaseCollection* ensemble = nullptr; + QString quantityName; + std::time_t timeStep = 0; + + RimCorrelationPlot* newPlot = nullptr; + if ( !correlationPlotColl ) + { + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + std::vector correlationPlotCollections; + RimProject::current()->descendantsOfType( correlationPlotCollections ); + CAF_ASSERT( !correlationPlotCollections.empty() ); + correlationPlotColl = correlationPlotCollections.front(); + + CorrelationPlotParams params = userData.value(); + ensemble = params.ensemble; + quantityName = params.quantityName; + timeStep = params.timeStep; + + newPlot = correlationPlotColl->createCorrelationPlot( ensemble, quantityName, timeStep ); + } + } + else + { + newPlot = correlationPlotColl->createCorrelationPlot(); + } - auto newPlot = correlationPlotColl->createCorrelationPlot(); newPlot->loadDataAndUpdate(); correlationPlotColl->updateConnectedEditors(); @@ -79,3 +110,27 @@ void RicNewCorrelationPlotFeature::setupActionLook( QAction* actionToSetup ) actionToSetup->setText( "New Correlation Tornado Plot" ); actionToSetup->setIcon( QIcon( ":/CorrelationTornadoPlot16x16.png" ) ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CorrelationPlotParams::CorrelationPlotParams() + : ensemble( nullptr ) + , quantityName( "" ) + , ensembleParameter( "" ) + , timeStep( 0 ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +CorrelationPlotParams::CorrelationPlotParams( RimSummaryCaseCollection* ensemble, + const QString& quantityName, + const std::time_t& timeStep ) + : ensemble( ensemble ) + , quantityName( quantityName ) + , ensembleParameter( "" ) + , timeStep( timeStep ) +{ +} diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h index e6b8b6bd0e..777a73cd10 100644 --- a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h @@ -20,6 +20,27 @@ #include "cafCmdFeature.h" +#include + +class RimSummaryCaseCollection; + +class CorrelationPlotParams +{ +public: + RimSummaryCaseCollection* ensemble; + QString quantityName; + QString ensembleParameter; + std::time_t timeStep; + + CorrelationPlotParams(); + CorrelationPlotParams( const CorrelationPlotParams& rhs ) = default; + + CorrelationPlotParams( RimSummaryCaseCollection* ensemble, const QString& quantityName, const std::time_t& timeStep ); + ~CorrelationPlotParams() = default; +}; + +Q_DECLARE_METATYPE( CorrelationPlotParams ); + //================================================================================================== /// //================================================================================================== diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp index 75b0213eef..e4e88ceebb 100644 --- a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp @@ -17,9 +17,12 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RicNewCorrelationReportPlotFeature.h" +#include "RicNewCorrelationPlotFeature.h" #include "RimCorrelationPlotCollection.h" #include "RimCorrelationReportPlot.h" +#include "RimProject.h" +#include "RimSummaryPlot.h" #include "RiuPlotMainWindowTools.h" @@ -44,6 +47,10 @@ bool RicNewCorrelationReportPlotFeature::isCommandEnabled() if ( correlationPlotColl ) return true; + RimSummaryPlot* summaryPlot = nullptr; + selObj->firstAncestorOrThisOfType( summaryPlot ); + if ( summaryPlot ) return true; + return false; } @@ -60,9 +67,33 @@ void RicNewCorrelationReportPlotFeature::onActionTriggered( bool isChecked ) selObj->firstAncestorOrThisOfType( correlationPlotColl ); } - if ( !correlationPlotColl ) return; + RimSummaryCaseCollection* ensemble = nullptr; + QString quantityName; + std::time_t timeStep = 0; - auto newPlot = correlationPlotColl->createCorrelationReportPlot(); + RimCorrelationReportPlot* newPlot = nullptr; + if ( !correlationPlotColl ) + { + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + std::vector correlationPlotCollections; + RimProject::current()->descendantsOfType( correlationPlotCollections ); + CAF_ASSERT( !correlationPlotCollections.empty() ); + correlationPlotColl = correlationPlotCollections.front(); + + CorrelationPlotParams params = userData.value(); + ensemble = params.ensemble; + quantityName = params.quantityName; + timeStep = params.timeStep; + + newPlot = correlationPlotColl->createCorrelationReportPlot( ensemble, quantityName, timeStep ); + } + } + else + { + newPlot = correlationPlotColl->createCorrelationReportPlot(); + } newPlot->loadDataAndUpdate(); correlationPlotColl->updateConnectedEditors(); diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewParameterResultCrossPlotFeature.cpp b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewParameterResultCrossPlotFeature.cpp index f2b9b2ff19..7a88370c7c 100644 --- a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewParameterResultCrossPlotFeature.cpp +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewParameterResultCrossPlotFeature.cpp @@ -18,8 +18,12 @@ #include "RicNewParameterResultCrossPlotFeature.h" +#include "RicNewCorrelationPlotFeature.h" + #include "RimCorrelationPlotCollection.h" #include "RimParameterResultCrossPlot.h" +#include "RimProject.h" +#include "RimSummaryPlot.h" #include "RiuPlotMainWindowTools.h" @@ -44,6 +48,10 @@ bool RicNewParameterResultCrossPlotFeature::isCommandEnabled() if ( correlationPlotColl ) return true; + RimSummaryPlot* summaryPlot = nullptr; + selObj->firstAncestorOrThisOfType( summaryPlot ); + if ( summaryPlot ) return true; + return false; } @@ -60,9 +68,38 @@ void RicNewParameterResultCrossPlotFeature::onActionTriggered( bool isChecked ) selObj->firstAncestorOrThisOfType( correlationPlotColl ); } - if ( !correlationPlotColl ) return; + RimSummaryCaseCollection* ensemble = nullptr; + QString quantityName; + QString ensembleParameter; + std::time_t timeStep = 0; + + RimParameterResultCrossPlot* newPlot = nullptr; + if ( !correlationPlotColl ) + { + QVariant userData = this->userData(); + if ( !userData.isNull() && userData.canConvert() ) + { + std::vector correlationPlotCollections; + RimProject::current()->descendantsOfType( correlationPlotCollections ); + CAF_ASSERT( !correlationPlotCollections.empty() ); + correlationPlotColl = correlationPlotCollections.front(); + + CorrelationPlotParams params = userData.value(); + ensemble = params.ensemble; + quantityName = params.quantityName; + ensembleParameter = params.ensembleParameter; + + timeStep = params.timeStep; + + newPlot = + correlationPlotColl->createParameterResultCrossPlot( ensemble, ensembleParameter, quantityName, timeStep ); + } + } + else + { + newPlot = correlationPlotColl->createParameterResultCrossPlot(); + } - auto newPlot = correlationPlotColl->createParameterResultCrossPlot(); newPlot->loadDataAndUpdate(); correlationPlotColl->updateConnectedEditors(); diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp index 297351aba9..b500e4f564 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp @@ -80,12 +80,20 @@ void RimAbstractCorrelationPlot::setCurveDefinitions( const std::vector +#include + class RiaSummaryCurveDefinition; class RiaSummaryCurveDefinitionAnalyser; class RimAnalysisPlotDataEntry; @@ -43,6 +45,7 @@ public: public: std::vector curveDefinitions() const; void setCurveDefinitions( const std::vector& curveDefinitions ); + void setTimeStep( std::time_t timeStep ); std::set ensembles(); RiuQwtPlotWidget* viewer() override; void detachAllCurves() override; diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp index 92f9933f6f..d0dd867b88 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp @@ -64,6 +64,24 @@ RimCorrelationPlot* RimCorrelationPlotCollection::createCorrelationPlot( bool de return plot; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationPlot* RimCorrelationPlotCollection::createCorrelationPlot( RimSummaryCaseCollection* ensemble, + const QString& quantityName, + std::time_t timeStep ) +{ + RimCorrelationPlot* plot = new RimCorrelationPlot(); + plot->setAsPlotMdiWindow(); + + applyEnsembleFieldAndTimeStepToPlot( plot, ensemble, quantityName.toStdString(), timeStep ); + plot->selectAllParameters(); + + m_correlationPlots.push_back( plot ); + + return plot; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -79,6 +97,22 @@ RimCorrelationMatrixPlot* RimCorrelationPlotCollection::createCorrelationMatrixP return plot; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationMatrixPlot* RimCorrelationPlotCollection::createCorrelationMatrixPlot( RimSummaryCaseCollection* ensemble, + std::time_t timeStep ) +{ + RimCorrelationMatrixPlot* plot = new RimCorrelationMatrixPlot(); + plot->setAsPlotMdiWindow(); + applyEnsembleFieldAndTimeStepToPlot( plot, ensemble, "", timeStep ); + plot->selectAllParameters(); + + m_correlationPlots.push_back( plot ); + + return plot; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -92,6 +126,23 @@ RimParameterResultCrossPlot* RimCorrelationPlotCollection::createParameterResult return plot; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimParameterResultCrossPlot* RimCorrelationPlotCollection::createParameterResultCrossPlot( RimSummaryCaseCollection* ensemble, + const QString& paramName, + const QString& quantityName, + std::time_t timeStep ) +{ + RimParameterResultCrossPlot* plot = new RimParameterResultCrossPlot; + plot->setAsPlotMdiWindow(); + applyEnsembleFieldAndTimeStepToPlot( plot, ensemble, quantityName.toStdString(), timeStep ); + plot->setEnsembleParameter( paramName ); + + m_correlationPlots.push_back( plot ); + return plot; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -102,6 +153,23 @@ RimCorrelationReportPlot* report->setAsPlotMdiWindow(); if ( defaultToFirstEnsembleFopt ) applyFirstEnsembleFieldAddressesToReport( report, "FOPT" ); report->matrixPlot()->selectAllParameters(); + report->correlationPlot()->selectAllParameters(); + m_correlationReports.push_back( report ); + return report; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationReportPlot* RimCorrelationPlotCollection::createCorrelationReportPlot( RimSummaryCaseCollection* ensemble, + const QString& quantityName, + std::time_t timeStep ) +{ + RimCorrelationReportPlot* report = new RimCorrelationReportPlot; + report->setAsPlotMdiWindow(); + applyEnsembleFieldAndTimeStepToReport( report, ensemble, quantityName.toStdString(), timeStep ); + report->matrixPlot()->selectAllParameters(); + report->correlationPlot()->selectAllParameters(); m_correlationReports.push_back( report ); return report; } @@ -171,6 +239,33 @@ void RimCorrelationPlotCollection::applyFirstEnsembleFieldAddressesToPlot( RimAb } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationPlotCollection::applyEnsembleFieldAndTimeStepToPlot( RimAbstractCorrelationPlot* plot, + RimSummaryCaseCollection* ensemble, + const std::string& quantityName, + std::time_t timeStep ) +{ + if ( ensemble ) + { + std::set allAddresses = ensemble->ensembleSummaryAddresses(); + std::vector curveDefs; + for ( auto address : allAddresses ) + { + if ( address.category() == RifEclipseSummaryAddress::SUMMARY_FIELD ) + { + if ( quantityName.empty() || quantityName == address.quantityName() ) + { + curveDefs.push_back( RiaSummaryCurveDefinition( nullptr, address, ensemble ) ); + } + } + } + plot->setCurveDefinitions( curveDefs ); + plot->setTimeStep( timeStep ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -199,6 +294,40 @@ void RimCorrelationPlotCollection::applyFirstEnsembleFieldAddressesToReport( Rim plot->matrixPlot()->setCurveDefinitions( curveDefsMatrix ); plot->correlationPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot ); plot->crossPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot ); - plot->crossPlot()->setEnsembleParameter( ensembles.front()->alphabeticEnsembleParameters().front().name ); + plot->crossPlot()->setEnsembleParameter( ensembles.front()->variationSortedEnsembleParameters().front().name ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationPlotCollection::applyEnsembleFieldAndTimeStepToReport( RimCorrelationReportPlot* plot, + RimSummaryCaseCollection* ensemble, + const std::string& quantityName, + std::time_t timeStep ) +{ + if ( ensemble ) + { + std::set allAddresses = ensemble->ensembleSummaryAddresses(); + std::vector curveDefsMatrix; + std::vector curveDefsTornadoAndCrossPlot; + for ( auto address : allAddresses ) + { + if ( address.category() == RifEclipseSummaryAddress::SUMMARY_FIELD ) + { + curveDefsMatrix.push_back( RiaSummaryCurveDefinition( nullptr, address, ensemble ) ); + if ( quantityName.empty() || quantityName == address.quantityName() ) + { + curveDefsTornadoAndCrossPlot.push_back( RiaSummaryCurveDefinition( nullptr, address, ensemble ) ); + } + } + } + plot->matrixPlot()->setCurveDefinitions( curveDefsMatrix ); + plot->matrixPlot()->setTimeStep( timeStep ); + plot->correlationPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot ); + plot->correlationPlot()->setTimeStep( timeStep ); + plot->crossPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot ); + plot->crossPlot()->setTimeStep( timeStep ); + plot->crossPlot()->setEnsembleParameter( ensemble->variationSortedEnsembleParameters().front().name ); } } diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h index 8e744c074a..63d55c4b68 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h @@ -21,11 +21,14 @@ #include "cafPdmChildArrayField.h" #include "cafPdmObject.h" +#include + class RimAbstractCorrelationPlot; class RimCorrelationPlot; class RimCorrelationMatrixPlot; class RimCorrelationReportPlot; class RimParameterResultCrossPlot; +class RimSummaryCaseCollection; //================================================================================================== /// @@ -39,12 +42,26 @@ public: RimCorrelationPlotCollection(); ~RimCorrelationPlotCollection() override; - RimCorrelationPlot* createCorrelationPlot( bool defaultToFirstEnsembleFopt = true ); - RimCorrelationMatrixPlot* createCorrelationMatrixPlot( bool defaultToFirstEnsembleField = true ); + RimCorrelationPlot* createCorrelationPlot( bool defaultToFirstEnsembleFopt = true ); + RimCorrelationPlot* + createCorrelationPlot( RimSummaryCaseCollection* ensemble, const QString& quantityName, std::time_t timeStep ); + + RimCorrelationMatrixPlot* createCorrelationMatrixPlot( bool defaultToFirstEnsembleField = true ); + RimCorrelationMatrixPlot* createCorrelationMatrixPlot( RimSummaryCaseCollection* ensemble, std::time_t timeStep ); + RimParameterResultCrossPlot* createParameterResultCrossPlot( bool defaultToFirstEnsembleFopt = true ); - RimCorrelationReportPlot* createCorrelationReportPlot( bool defaultToFirstEnsembleFopt = true ); - void removePlot( RimAbstractCorrelationPlot* correlationPlot ); - void removeReport( RimCorrelationReportPlot* correlationReport ); + RimParameterResultCrossPlot* createParameterResultCrossPlot( RimSummaryCaseCollection* ensemble, + const QString& paramName, + const QString& quantityName, + std::time_t timeStep ); + + RimCorrelationReportPlot* createCorrelationReportPlot( bool defaultToFirstEnsembleFopt = true ); + RimCorrelationReportPlot* createCorrelationReportPlot( RimSummaryCaseCollection* ensemble, + const QString& quantityName, + std::time_t timeStep ); + + void removePlot( RimAbstractCorrelationPlot* correlationPlot ); + void removeReport( RimCorrelationReportPlot* correlationReport ); std::vector plots(); std::vector reports(); @@ -53,7 +70,15 @@ public: private: void applyFirstEnsembleFieldAddressesToPlot( RimAbstractCorrelationPlot* plot, const std::string& quantityName = "" ); + void applyEnsembleFieldAndTimeStepToPlot( RimAbstractCorrelationPlot* plot, + RimSummaryCaseCollection* ensemble, + const std::string& quantityName, + std::time_t timeStep ); void applyFirstEnsembleFieldAddressesToReport( RimCorrelationReportPlot* plot, const std::string& quantityName = "" ); + void applyEnsembleFieldAndTimeStepToReport( RimCorrelationReportPlot* plot, + RimSummaryCaseCollection* ensemble, + const std::string& quantityName, + std::time_t timeStep ); private: caf::PdmChildArrayField m_correlationPlots; diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp index d5383fd6e5..eecd845fde 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp @@ -63,7 +63,7 @@ #include #include -#include +#include //-------------------------------------------------------------------------------------------------- /// @@ -968,7 +968,7 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos, // Force empty defaults *closestItem = nullptr; *closestCurvePoint = -1; - *distanceFromClick = DBL_MAX; + *distanceFromClick = std::numeric_limits::infinity(); const QwtPlotItemList& itmList = itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++ ) @@ -976,7 +976,7 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos, if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve ) { QwtPlotCurve* candidateCurve = static_cast( *it ); - double dist = DBL_MAX; + double dist = std::numeric_limits::infinity(); int curvePoint = candidateCurve->closestPoint( pos, &dist ); if ( dist < *distanceFromClick ) { @@ -1023,7 +1023,7 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos, void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItemInSelection /*= false*/ ) { QwtPlotItem* closestItem = nullptr; - double distanceFromClick = DBL_MAX; + double distanceFromClick = std::numeric_limits::infinity(); int closestCurvePoint = -1; findClosestPlotItem( pos, &closestItem, &closestCurvePoint, &distanceFromClick ); diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h index fe828ae565..a7aa71ecef 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h @@ -161,12 +161,12 @@ protected: virtual bool isZoomerActive() const; virtual void endZoomOperations(); -private: void findClosestPlotItem( const QPoint& pos, QwtPlotItem** closestItem, int* closestCurvePoint, double* distanceFromClick ) const; +private: void selectClosestPlotItem( const QPoint& pos, bool toggleItemInSelection = false ); static int defaultMinimumWidth(); void replot() override; diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index 5e54ad5978..4b1f519fe6 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -20,12 +20,16 @@ #include "RiaApplication.h" #include "RiaPreferences.h" +#include "Commands/CorrelationPlotCommands/RicNewCorrelationPlotFeature.h" + #include "RimEnsembleCurveSet.h" #include "RimEnsembleCurveSetCollection.h" +#include "RimEnsembleStatisticsCase.h" #include "RimMainPlotCollection.h" #include "RimPlot.h" #include "RimRegularLegendConfig.h" #include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" #include "RimSummaryCurve.h" #include "RimSummaryCurveCollection.h" #include "RimSummaryPlot.h" @@ -46,6 +50,7 @@ #include "RimProject.h" #include "cafCmdFeatureMenuBuilder.h" +#include "cafIconProvider.h" #include "cafSelectionManager.h" #include "cafTitledOverlayFrame.h" @@ -66,6 +71,8 @@ #include #include +#include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -176,6 +183,73 @@ void RiuSummaryQwtPlot::contextMenuEvent( QContextMenuEvent* event ) menuBuilder << "RicShowPlotDataFeature"; menuBuilder << "RicSavePlotTemplateFeature"; + QwtPlotItem* closestItem = nullptr; + double distanceFromClick = std::numeric_limits::infinity(); + int closestCurvePoint = -1; + QPoint globalPos = event->globalPos(); + QPoint localPos = this->canvas()->mapFromGlobal( globalPos ); + + findClosestPlotItem( localPos, &closestItem, &closestCurvePoint, &distanceFromClick ); + if ( closestItem && closestCurvePoint >= 0 ) + { + RiuRimQwtPlotCurve* plotCurve = dynamic_cast( closestItem ); + if ( plotCurve ) + { + RimSummaryCurve* summaryCurve = dynamic_cast( plotCurve->ownerRimCurve() ); + if ( summaryCurve && closestCurvePoint < (int)summaryCurve->timeStepsY().size() ) + { + std::time_t timeStep = summaryCurve->timeStepsY()[closestCurvePoint]; + + RimEnsembleCurveSet* ensembleCurveSet = nullptr; + summaryCurve->firstAncestorOrThisOfType( ensembleCurveSet ); + + if ( ensembleCurveSet ) + { + RimSummaryCaseCollection* ensemble = ensembleCurveSet->summaryCaseCollection(); + if ( ensemble && ensemble->isEnsemble() ) + { + CorrelationPlotParams params( ensemble, + QString::fromStdString( + ensembleCurveSet->summaryAddress().quantityName() ), + timeStep ); + QVariant variant = QVariant::fromValue( params ); + menuBuilder.subMenuStart( "Create Correlation Plot From Curve Point", + *caf::IconProvider( ":/CorrelationPlots16x16.png" ).icon() ); + { + menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationPlotFeature", + "New Tornado Plot", + variant ); + menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationMatrixPlotFeature", + "New Matrix Plot", + variant ); + menuBuilder.addCmdFeatureWithUserData( "RicNewCorrelationReportPlotFeature", + "New Report Plot", + variant ); + menuBuilder.subMenuStart( "Cross Plots", + *caf::IconProvider( ":/CorrelationCrossPlot16x16.png" ).icon() ); + std::vector ensembleParameters = + ensemble->variationSortedEnsembleParameters(); + for ( const EnsembleParameter& param : ensembleParameters ) + { + if ( param.variationBin >= (int)EnsembleParameter::LOW_VARIATION ) + { + params.ensembleParameter = param.name; + variant = QVariant::fromValue( params ); + menuBuilder.addCmdFeatureWithUserData( "RicNewParameterResultCrossPlotFeature", + QString( "New Cross Plot Against %1" ) + .arg( param.uiName() ), + variant ); + } + } + menuBuilder.subMenuEnd(); + } + menuBuilder.subMenuEnd(); + } + } + } + } + } + menuBuilder.appendToMenu( &menu ); if ( menu.actions().size() > 0 )