diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 4c18ecaa02..dba69133fd 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -47,6 +47,7 @@ #include "RimCommandObject.h" #include "RimCorrelationPlot.h" #include "RimCorrelationPlotCollection.h" +#include "RimCorrelationReportPlot.h" #include "RimEclipseCaseCollection.h" #include "RimEclipseView.h" #include "RimFlowPlotCollection.h" @@ -333,7 +334,7 @@ bool RiaApplication::openFile( const QString& fileName ) } else if ( int( fileType ) & int( RiaDefines::ImportFileType::ANY_ECLIPSE_FILE ) ) { - loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{fileName}, true ); + loadingSucceded = RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{ fileName }, true ); lastUsedDialogTag = RiaDefines::defaultDirectoryLabel( fileType ); } @@ -1609,7 +1610,7 @@ void RiaApplication::loadAndUpdatePlotData() plotCount += gcpColl ? gcpColl->gridCrossPlots().size() : 0; plotCount += sppColl ? sppColl->plots().size() : 0; plotCount += alsColl ? alsColl->plots().size() : 0; - plotCount += corrColl ? corrColl->plots().size() : 0; + plotCount += corrColl ? corrColl->plots().size() + corrColl->reports().size() : 0; plotCount += gpwColl ? gpwColl->multiPlots().size() : 0; if ( plotCount > 0 ) @@ -1701,6 +1702,11 @@ void RiaApplication::loadAndUpdatePlotData() corrPlot->loadDataAndUpdate(); plotProgress.incrementProgress(); } + for ( const auto& reports : corrColl->reports() ) + { + reports->loadDataAndUpdate(); + plotProgress.incrementProgress(); + } } if ( gpwColl ) @@ -1824,7 +1830,7 @@ bool RiaApplication::generateCode( const QString& fileName, QString* errMsg ) std::vector> commandObjects; - QStringList excludedClassNames{"TestCommand1", "TC2"}; // See RifCommandCore-Text.cpp + QStringList excludedClassNames{ "TestCommand1", "TC2" }; // See RifCommandCore-Text.cpp auto allObjects = caf::PdmMarkdownBuilder::createAllObjects( caf::PdmDefaultObjectFactory::instance() ); for ( auto classObject : allObjects ) diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/CorrelationPlotCommands/CMakeLists_files.cmake index 4bfba7d1ef..49c7ee4935 100644 --- a/ApplicationCode/Commands/CorrelationPlotCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CorrelationPlotCommands/CMakeLists_files.cmake @@ -1,6 +1,7 @@ set (SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewCorrelationPlotFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicNewCorrelationReportPlotFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewCorrelationMatrixPlotFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewParameterResultCrossPlotFeature.h ) @@ -9,6 +10,7 @@ set (SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicNewCorrelationPlotFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewCorrelationMatrixPlotFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewParameterResultCrossPlotFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicNewCorrelationReportPlotFeature.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp new file mode 100644 index 0000000000..9469f3c6ce --- /dev/null +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.cpp @@ -0,0 +1,81 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicNewCorrelationReportPlotFeature.h" + +#include "RimCorrelationPlotCollection.h" +#include "RimCorrelationReportPlot.h" + +#include "RiuPlotMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicNewCorrelationReportPlotFeature, "RicNewCorrelationReportPlotFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicNewCorrelationReportPlotFeature::isCommandEnabled() +{ + RimCorrelationPlotCollection* correlationPlotColl = nullptr; + + caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + if ( selObj ) + { + selObj->firstAncestorOrThisOfType( correlationPlotColl ); + } + + if ( correlationPlotColl ) return true; + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewCorrelationReportPlotFeature::onActionTriggered( bool isChecked ) +{ + RimCorrelationPlotCollection* correlationPlotColl = nullptr; + + caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + if ( selObj ) + { + selObj->firstAncestorOrThisOfType( correlationPlotColl ); + } + + if ( !correlationPlotColl ) return; + + auto newPlot = correlationPlotColl->createCorrelationReportPlot(); + newPlot->loadDataAndUpdate(); + + correlationPlotColl->updateConnectedEditors(); + + RiuPlotMainWindowTools::setExpanded( newPlot ); + RiuPlotMainWindowTools::selectAsCurrentItem( newPlot ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewCorrelationReportPlotFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "New Correlation Report Plot" ); + actionToSetup->setIcon( QIcon( ":/AnalysisPlot16x16.png" ) ); +} diff --git a/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.h b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.h new file mode 100644 index 0000000000..e0f720d934 --- /dev/null +++ b/ApplicationCode/Commands/CorrelationPlotCommands/RicNewCorrelationReportPlotFeature.h @@ -0,0 +1,35 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicNewCorrelationReportPlotFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CorrelationPlots/CMakeLists_files.cmake index e7ad3f4920..69c8aedc0c 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/CMakeLists_files.cmake @@ -5,6 +5,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlot.h ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationMatrixPlot.h ${CMAKE_CURRENT_LIST_DIR}/RimParameterResultCrossPlot.h ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlotCollection.h +${CMAKE_CURRENT_LIST_DIR}/RimCorrelationReportPlot.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -13,6 +14,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlot.cpp ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationMatrixPlot.cpp ${CMAKE_CURRENT_LIST_DIR}/RimParameterResultCrossPlot.cpp ${CMAKE_CURRENT_LIST_DIR}/RimCorrelationPlotCollection.cpp +${CMAKE_CURRENT_LIST_DIR}/RimCorrelationReportPlot.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp index 1d70efea1b..c6b09cb1f9 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.cpp @@ -357,6 +357,14 @@ void RimAbstractCorrelationPlot::detachAllCurves() if ( m_plotWidget ) m_plotWidget->detachItems(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QDateTime RimAbstractCorrelationPlot::timeStep() const +{ + return m_timeStep(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.h b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.h index f1a47b901c..4355cde33c 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.h +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimAbstractCorrelationPlot.h @@ -41,8 +41,12 @@ public: ~RimAbstractCorrelationPlot() override; public: + std::vector curveDefinitions() const; void setCurveDefinitions( const std::vector& curveDefinitions ); std::set ensembles(); + RiuQwtPlotWidget* viewer() override; + void detachAllCurves() override; + QDateTime timeStep() const; protected: // Overridden PDM methods @@ -56,9 +60,8 @@ protected: QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly ) override; - std::set allAvailableTimeSteps(); - std::vector curveDefinitions() const; - RiaSummaryCurveDefinitionAnalyser* getOrCreateSelectedCurveDefAnalyser(); + std::set allAvailableTimeSteps(); + RiaSummaryCurveDefinitionAnalyser* getOrCreateSelectedCurveDefAnalyser(); std::set addresses(); std::set ensembleParameters(); @@ -80,9 +83,7 @@ protected: // RimPlot Overrides RiuQwtPlotWidget* doCreatePlotViewWidget( QWidget* mainWindowParent = nullptr ) override; - RiuQwtPlotWidget* viewer() override; - void detachAllCurves() override; void reattachAllCurves() override {} void doRemoveFromCollection() override {} void updateZoomInQwt() override {} diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.cpp index 7ec2a7a349..064081fc6a 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.cpp @@ -91,17 +91,23 @@ public: { if ( RiaCurveDataTools::isValidValue( value, false ) ) { - m_correlationSum += value * value; + m_correlationSum += value; + m_correlationMagnitude += value * value; anyValid = true; } } - if ( !anyValid ) m_correlationSum = std::numeric_limits::infinity(); + if ( !anyValid ) + { + m_correlationSum = std::numeric_limits::infinity(); + m_correlationMagnitude = std::numeric_limits::infinity(); + } } QString m_label; std::vector m_values; std::vector m_entryLabels; double m_correlationSum; + double m_correlationMagnitude; }; //-------------------------------------------------------------------------------------------------- @@ -116,6 +122,7 @@ RimCorrelationMatrixPlot::RimCorrelationMatrixPlot() m_correlationFactor.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() ); CAF_PDM_InitField( &m_showAbsoluteValues, "CorrelationAbsValues", true, "Show Absolute Values", "", "", "" ); CAF_PDM_InitField( &m_sortByValues, "CorrelationSorting", true, "Sort Matrix by Values", "", "", "" ); + CAF_PDM_InitField( &m_sortByAbsoluteValues, "CorrelationAbsSorting", true, "Sort by Absolute Values", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_legendConfig, "LegendConfig", "", "", "", "" ); m_legendConfig = new RimRegularLegendConfig(); @@ -129,11 +136,35 @@ RimCorrelationMatrixPlot::RimCorrelationMatrixPlot() //-------------------------------------------------------------------------------------------------- RimCorrelationMatrixPlot::~RimCorrelationMatrixPlot() { - removeMdiWindowFromMdiArea(); + if ( isMdiWindow() ) removeMdiWindowFromMdiArea(); cleanupBeforeClose(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationMatrixPlot::CorrelationFactor RimCorrelationMatrixPlot::correlationFactor() const +{ + return m_correlationFactor(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimCorrelationMatrixPlot::showAbsoluteValues() const +{ + return m_showAbsoluteValues; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimCorrelationMatrixPlot::sortByAbsoluteValues() const +{ + return m_sortByAbsoluteValues; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -142,7 +173,8 @@ void RimCorrelationMatrixPlot::fieldChangedByUi( const caf::PdmFieldHandle* chan const QVariant& newValue ) { RimAbstractCorrelationPlot::fieldChangedByUi( changedField, oldValue, newValue ); - if ( changedField == &m_correlationFactor || changedField == &m_showAbsoluteValues || changedField == &m_sortByValues ) + if ( changedField == &m_correlationFactor || changedField == &m_showAbsoluteValues || + changedField == &m_sortByValues || changedField == &m_sortByAbsoluteValues ) { this->updateLegend(); this->loadDataAndUpdate(); @@ -159,6 +191,7 @@ void RimCorrelationMatrixPlot::defineUiOrdering( QString uiConfigName, caf::PdmU correlationGroup->add( &m_correlationFactor ); correlationGroup->add( &m_showAbsoluteValues ); correlationGroup->add( &m_sortByValues ); + correlationGroup->add( &m_sortByAbsoluteValues ); caf::PdmUiGroup* curveDataGroup = uiOrdering.addNewGroup( "Summary Vector" ); m_selectedVarsUiField = selectedVarsText(); @@ -167,12 +200,15 @@ void RimCorrelationMatrixPlot::defineUiOrdering( QString uiConfigName, caf::PdmU curveDataGroup->add( &m_pushButtonSelectSummaryAddress, { false, 1, 0 } ); curveDataGroup->add( &m_timeStep ); - caf::PdmUiGroup* plotGroup = uiOrdering.addNewGroup( "Plot Settings" ); - plotGroup->add( &m_showPlotTitle ); - plotGroup->add( &m_useAutoPlotTitle ); - plotGroup->add( &m_description ); - m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() ); - RimPlot::defineUiOrdering( uiConfigName, *plotGroup ); + if ( uiConfigName != "report" ) + { + caf::PdmUiGroup* plotGroup = uiOrdering.addNewGroup( "Plot Settings" ); + plotGroup->add( &m_showPlotTitle ); + plotGroup->add( &m_useAutoPlotTitle ); + plotGroup->add( &m_description ); + m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() ); + RimPlot::defineUiOrdering( uiConfigName, *plotGroup ); + } uiOrdering.skipRemainingFields( true ); } @@ -289,12 +325,16 @@ void eraseInvalidEntries( std::vector& matrix ) matrix.end() ); } -void sortEntries( std::vector& matrix ) +void sortEntries( std::vector& matrix, bool sortByAbsoluteValues ) { std::sort( matrix.begin(), matrix.end(), - []( const CorrelationMatrixRowOrColumn& lhs, const CorrelationMatrixRowOrColumn& rhs ) { - return lhs.m_correlationSum > rhs.m_correlationSum; + [&sortByAbsoluteValues]( const CorrelationMatrixRowOrColumn& lhs, + const CorrelationMatrixRowOrColumn& rhs ) -> bool { + if ( sortByAbsoluteValues ) + return lhs.m_correlationMagnitude > rhs.m_correlationMagnitude; + else + return lhs.m_correlationSum > rhs.m_correlationSum; } ); } @@ -413,12 +453,12 @@ void RimCorrelationMatrixPlot::createMatrix() } eraseInvalidEntries( correlationMatrixColumns ); - if ( m_sortByValues() ) sortEntries( correlationMatrixColumns ); + if ( m_sortByValues() ) sortEntries( correlationMatrixColumns, m_sortByAbsoluteValues() ); auto correlationMatrixRows = transpose( correlationMatrixColumns ); eraseInvalidEntries( correlationMatrixRows ); - if ( m_sortByValues() ) sortEntries( correlationMatrixRows ); + if ( m_sortByValues() ) sortEntries( correlationMatrixRows, m_sortByAbsoluteValues() ); for ( size_t rowIdx = 0u; rowIdx < correlationMatrixRows.size(); ++rowIdx ) { diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.h b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.h index 7a8b6a81ea..063d3c7068 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.h +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.h @@ -43,6 +43,10 @@ public: RimCorrelationMatrixPlot(); ~RimCorrelationMatrixPlot() override; + CorrelationFactor correlationFactor() const; + bool showAbsoluteValues() const; + bool sortByAbsoluteValues() const; + private: // Overridden PDM methods @@ -65,9 +69,11 @@ private: void updateLegend() override; private: - caf::PdmField m_correlationFactor; - caf::PdmField m_showAbsoluteValues; - caf::PdmField m_sortByValues; + caf::PdmField m_correlationFactor; + caf::PdmField m_showAbsoluteValues; + caf::PdmField m_sortByValues; + caf::PdmField m_sortByAbsoluteValues; + caf::PdmChildField m_legendConfig; std::map m_paramLabels; diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.cpp index eb434620f1..48001a95ff 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.cpp @@ -77,7 +77,7 @@ RimCorrelationPlot::RimCorrelationPlot() //-------------------------------------------------------------------------------------------------- RimCorrelationPlot::~RimCorrelationPlot() { - removeMdiWindowFromMdiArea(); + if ( isMdiWindow() ) removeMdiWindowFromMdiArea(); cleanupBeforeClose(); } @@ -293,3 +293,51 @@ void RimCorrelationPlot::updatePlotTitle() m_plotWidget->setPlotTitle( m_description ); m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && isMdiWindow() ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationPlot::CorrelationFactor RimCorrelationPlot::correlationFactor() const +{ + return m_correlationFactor(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationPlot::setCorrelationFactor( CorrelationFactor factor ) +{ + m_correlationFactor = factor; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimCorrelationPlot::showAbsoluteValues() const +{ + m_showAbsoluteValues; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationPlot::setShowAbsoluteValues( bool showAbsoluteValues ) +{ + m_showAbsoluteValues = showAbsoluteValues; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimCorrelationPlot::sortByAbsoluteValues() const +{ + return m_sortByAbsoluteValues; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationPlot::setSortByAbsoluteValues( bool sortByAbsoluteValues ) +{ + m_sortByAbsoluteValues = sortByAbsoluteValues; +} diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.h b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.h index 2c704f9a0b..367e25b037 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.h +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.h @@ -46,6 +46,15 @@ public: RimCorrelationPlot(); ~RimCorrelationPlot() override; + CorrelationFactor correlationFactor() const; + void setCorrelationFactor( CorrelationFactor factor ); + + bool showAbsoluteValues() const; + void setShowAbsoluteValues( bool showAbsoluteValues ); + + bool sortByAbsoluteValues() const; + void setSortByAbsoluteValues( bool sortByAbsoluteValues ); + private: // Overridden PDM methods diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp index 2e8b09f645..f593a90740 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp @@ -21,6 +21,7 @@ #include "RiaSummaryCurveDefinition.h" #include "RimCorrelationMatrixPlot.h" #include "RimCorrelationPlot.h" +#include "RimCorrelationReportPlot.h" #include "RimParameterResultCrossPlot.h" #include "RimProject.h" @@ -34,7 +35,10 @@ RimCorrelationPlotCollection::RimCorrelationPlotCollection() CAF_PDM_InitObject( "Correlation Plots", ":/AnalysisPlots16x16.png", "", "" ); CAF_PDM_InitFieldNoDefault( &m_correlationPlots, "CorrelationPlots", "Correlation Plots", "", "", "" ); + CAF_PDM_InitFieldNoDefault( &m_correlationReports, "CorrelationReports", "Correlation Reports", "", "", "" ); + m_correlationPlots.uiCapability()->setUiHidden( true ); + m_correlationReports.uiCapability()->setUiHidden( true ); } //-------------------------------------------------------------------------------------------------- @@ -86,6 +90,20 @@ RimParameterResultCrossPlot* RimCorrelationPlotCollection::createParameterResult return plot; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationReportPlot* + RimCorrelationPlotCollection::createCorrelationReportPlot( bool defaultToFirstEnsembleFopt /*= true */ ) +{ + RimCorrelationReportPlot* report = new RimCorrelationReportPlot; + report->setAsPlotMdiWindow(); + if ( defaultToFirstEnsembleFopt ) applyFirstEnsembleFieldAddressesToReport( report, "FOPT" ); + + m_correlationReports.push_back( report ); + return report; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -102,12 +120,21 @@ std::vector RimCorrelationPlotCollection::plots() return m_correlationPlots.childObjects(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimCorrelationPlotCollection::reports() +{ + return m_correlationReports.childObjects(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimCorrelationPlotCollection::deleteAllChildObjects() { m_correlationPlots.deleteAllChildObjects(); + m_correlationReports.deleteAllChildObjects(); } //-------------------------------------------------------------------------------------------------- @@ -141,3 +168,35 @@ void RimCorrelationPlotCollection::applyFirstEnsembleFieldAddressesToPlot( RimAb } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationPlotCollection::applyFirstEnsembleFieldAddressesToReport( RimCorrelationReportPlot* plot, + const std::string& quantityName /*= "" */ ) +{ + std::vector ensembles; + RimProject::current()->descendantsIncludingThisOfType( ensembles ); + if ( !ensembles.empty() ) + { + std::set allAddresses = ensembles.front()->ensembleSummaryAddresses(); + std::vector curveDefsMatrix; + std::vector curveDefsTornadoAndCrossPlot; + for ( auto address : allAddresses ) + { + if ( address.category() == RifEclipseSummaryAddress::SUMMARY_FIELD ) + { + curveDefsMatrix.push_back( RiaSummaryCurveDefinition( nullptr, address, ensembles.front() ) ); + if ( quantityName.empty() || quantityName == address.quantityName() ) + { + curveDefsTornadoAndCrossPlot.push_back( + RiaSummaryCurveDefinition( nullptr, address, ensembles.front() ) ); + } + } + } + plot->matrixPlot()->setCurveDefinitions( curveDefsMatrix ); + plot->correlationPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot ); + plot->crossPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot ); + plot->crossPlot()->setEnsembleParameter( ensembles.front()->alphabeticEnsembleParameters().front().name ); + } +} diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h index 8c5cfd1284..8e744c074a 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.h @@ -24,6 +24,7 @@ class RimAbstractCorrelationPlot; class RimCorrelationPlot; class RimCorrelationMatrixPlot; +class RimCorrelationReportPlot; class RimParameterResultCrossPlot; //================================================================================================== @@ -41,15 +42,20 @@ public: RimCorrelationPlot* createCorrelationPlot( bool defaultToFirstEnsembleFopt = true ); RimCorrelationMatrixPlot* createCorrelationMatrixPlot( bool defaultToFirstEnsembleField = true ); RimParameterResultCrossPlot* createParameterResultCrossPlot( bool defaultToFirstEnsembleFopt = true ); - void removePlot( RimAbstractCorrelationPlot* CorrelationPlot ); + RimCorrelationReportPlot* createCorrelationReportPlot( bool defaultToFirstEnsembleFopt = true ); + void removePlot( RimAbstractCorrelationPlot* correlationPlot ); + void removeReport( RimCorrelationReportPlot* correlationReport ); std::vector plots(); + std::vector reports(); void deleteAllChildObjects(); private: void applyFirstEnsembleFieldAddressesToPlot( RimAbstractCorrelationPlot* plot, const std::string& quantityName = "" ); + void applyFirstEnsembleFieldAddressesToReport( RimCorrelationReportPlot* plot, const std::string& quantityName = "" ); private: caf::PdmChildArrayField m_correlationPlots; + caf::PdmChildArrayField m_correlationReports; }; diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.cpp new file mode 100644 index 0000000000..33e6dec300 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.cpp @@ -0,0 +1,296 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// +#include "RimCorrelationReportPlot.h" + +#include "RiaSummaryCurveDefinition.h" + +#include "RimCorrelationMatrixPlot.h" +#include "RimParameterResultCrossPlot.h" + +#include "RiuMultiPlotPage.h" + +#include "cafAssert.h" +#include "cafPdmUiOrdering.h" +#include "cafPdmUiTreeOrdering.h" + +#include +#include +#include + +//================================================================================================== +// +// +// +//================================================================================================== +CAF_PDM_SOURCE_INIT( RimCorrelationReportPlot, "CorrelationReportPlot" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationReportPlot::RimCorrelationReportPlot() +{ + CAF_PDM_InitObject( "Correlation Report Plot", ":/CorrelationPlot16x16.png", "", "" ); + + CAF_PDM_InitFieldNoDefault( &m_plotWindowTitle, "PlotWindowTitle", "Title", "", "", "" ); + m_plotWindowTitle.registerGetMethod( this, &RimCorrelationReportPlot::createPlotWindowTitle ); + + CAF_PDM_InitFieldNoDefault( &m_correlationMatrixPlot, "MatrixPlot", "Matrix Plot", "", "", "" ); + CAF_PDM_InitFieldNoDefault( &m_correlationPlot, "CorrelationPlot", "Correlation Plot", "", "", "" ); + CAF_PDM_InitFieldNoDefault( &m_parameterResultCrossPlot, "CrossPlot", "Cross Plot", "", "", "" ); + + setAsPlotMdiWindow(); + + m_showWindow = true; + m_correlationMatrixPlot = new RimCorrelationMatrixPlot; + m_correlationMatrixPlot->setColSpan( RimPlot::TWO ); + m_correlationMatrixPlot->setRowSpan( RimPlot::TWO ); + m_correlationPlot = new RimCorrelationPlot; + m_parameterResultCrossPlot = new RimParameterResultCrossPlot; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationReportPlot::~RimCorrelationReportPlot() +{ + removeMdiWindowFromMdiArea(); + cleanupBeforeClose(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* RimCorrelationReportPlot::viewWidget() +{ + return m_viewer; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimCorrelationReportPlot::description() const +{ + return m_plotWindowTitle(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QImage RimCorrelationReportPlot::snapshotWindowContent() +{ + QImage image; + + if ( m_viewer ) + { + QPixmap pix( m_viewer->size() ); + m_viewer->renderTo( &pix ); + image = pix.toImage(); + } + + return image; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::zoomAll() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmFieldHandle* RimCorrelationReportPlot::userDescriptionField() +{ + return &m_plotWindowTitle; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationMatrixPlot* RimCorrelationReportPlot::matrixPlot() const +{ + return m_correlationMatrixPlot(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimCorrelationPlot* RimCorrelationReportPlot::correlationPlot() const +{ + return m_correlationPlot(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimParameterResultCrossPlot* RimCorrelationReportPlot::crossPlot() const +{ + return m_parameterResultCrossPlot(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RimCorrelationReportPlot::columnCount() const +{ + return 3; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimCorrelationReportPlot::createPlotWindowTitle() const +{ + QStringList ensembles; + for ( auto entry : m_correlationMatrixPlot->curveDefinitions() ) + { + if ( entry.ensemble() ) + { + ensembles.push_back( entry.ensemble()->uiName() ); + } + } + ensembles.removeDuplicates(); + QString ensembleNames = ensembles.join( ", " ); + QString timeStep = m_correlationMatrixPlot->timeStep().toString( Qt::ISODate ); + + return QString( "Correlation Report for %1 at %2" ).arg( ensembleNames ).arg( timeStep ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::recreatePlotWidgets() +{ + CAF_ASSERT( m_viewer ); + m_correlationMatrixPlot->createPlotWidget(); + m_correlationPlot->createPlotWidget(); + m_parameterResultCrossPlot->createPlotWidget(); + + m_viewer->addPlot( m_correlationMatrixPlot->viewer() ); + m_viewer->addPlot( m_correlationPlot->viewer() ); + m_viewer->addPlot( m_parameterResultCrossPlot->viewer() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::cleanupBeforeClose() +{ + m_correlationMatrixPlot->detachAllCurves(); + m_correlationPlot->detachAllCurves(); + m_parameterResultCrossPlot->detachAllCurves(); + + if ( m_viewer ) + { + m_viewer->setParent( nullptr ); + delete m_viewer; + m_viewer = nullptr; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::doRenderWindowContent( QPaintDevice* paintDevice ) +{ + if ( m_viewer ) + { + m_viewer->renderTo( paintDevice ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* RimCorrelationReportPlot::createViewWidget( QWidget* mainWindowParent /*= nullptr */ ) +{ + m_viewer = new RiuMultiPlotPage( this, mainWindowParent ); + m_viewer->setPlotTitle( m_plotWindowTitle() ); + m_viewer->setSubTitlesVisible( true ); + recreatePlotWidgets(); + + return m_viewer; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::deleteViewWidget() +{ + cleanupBeforeClose(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::onLoadDataAndUpdate() +{ + updateMdiWindowVisibility(); + if ( m_showWindow ) + { + // auto curveDefs = m_correlationMatrixPlot->curveDefinitions(); + // m_correlationPlot->setCurveDefinitions( curveDefs ); + // m_parameterResultCrossPlot->setCurveDefinitions( curveDefs ); + + m_correlationPlot->setCorrelationFactor( m_correlationMatrixPlot->correlationFactor() ); + m_correlationPlot->setShowAbsoluteValues( m_correlationMatrixPlot->showAbsoluteValues() ); + m_correlationPlot->setSortByAbsoluteValues( m_correlationMatrixPlot->sortByAbsoluteValues() ); + + m_correlationMatrixPlot->loadDataAndUpdate(); + m_correlationPlot->loadDataAndUpdate(); + m_parameterResultCrossPlot->loadDataAndUpdate(); + } + updateLayout(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) +{ + m_correlationMatrixPlot->uiOrdering( "report", uiOrdering ); + uiOrdering.skipRemainingFields( true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, + QString uiConfigName /*= "" */ ) +{ + uiTreeOrdering.skipRemainingChildren( true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField, + const QVariant& oldValue, + const QVariant& newValue ) +{ + this->loadDataAndUpdate(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimCorrelationReportPlot::childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) +{ + this->loadDataAndUpdate(); +} diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.h b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.h new file mode 100644 index 0000000000..529c0b1b84 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.h @@ -0,0 +1,82 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// +#pragma once + +#include "RimCorrelationPlot.h" +#include "RimPlotWindow.h" + +#include "cafPdmChildField.h" +#include "cafPdmProxyValueField.h" +#include "cafPdmPtrField.h" + +#include +#include + +class RimAnalysisPlotDataEntry; +class RimCorrelationMatrixPlot; +class RimParameterResultCrossPlot; +class RimSummaryCaseCollection; + +class RiuMultiPlotPage; + +class RimCorrelationReportPlot : public RimPlotWindow +{ + CAF_PDM_HEADER_INIT; + using CorrelationFactor = RimCorrelationPlot::CorrelationFactor; + using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum; + +public: + RimCorrelationReportPlot(); + ~RimCorrelationReportPlot() override; + + QWidget* viewWidget() override; + QString description() const override; + QImage snapshotWindowContent() override; + void zoomAll() override; + + caf::PdmFieldHandle* userDescriptionField() override; + + RimCorrelationMatrixPlot* matrixPlot() const; + RimCorrelationPlot* correlationPlot() const; + RimParameterResultCrossPlot* crossPlot() const; + + int columnCount() const override; + +private: + QString createPlotWindowTitle() const; + void recreatePlotWidgets(); + void cleanupBeforeClose(); + + void doRenderWindowContent( QPaintDevice* paintDevice ) override; + QWidget* createViewWidget( QWidget* mainWindowParent = nullptr ) override; + void deleteViewWidget() override; + void onLoadDataAndUpdate() override; + void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; + void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override; + void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; + void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override; + +private: + caf::PdmProxyValueField m_plotWindowTitle; + + caf::PdmChildField m_correlationMatrixPlot; + caf::PdmChildField m_correlationPlot; + caf::PdmChildField m_parameterResultCrossPlot; + + QPointer m_viewer; +}; diff --git a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimParameterResultCrossPlot.cpp b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimParameterResultCrossPlot.cpp index 6cb4161914..3d5b90db5b 100644 --- a/ApplicationCode/ProjectDataModel/CorrelationPlots/RimParameterResultCrossPlot.cpp +++ b/ApplicationCode/ProjectDataModel/CorrelationPlots/RimParameterResultCrossPlot.cpp @@ -69,7 +69,7 @@ RimParameterResultCrossPlot::RimParameterResultCrossPlot() //-------------------------------------------------------------------------------------------------- RimParameterResultCrossPlot::~RimParameterResultCrossPlot() { - removeMdiWindowFromMdiArea(); + if ( isMdiWindow() ) removeMdiWindowFromMdiArea(); cleanupBeforeClose(); } diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index a00737c62b..fe1e86799f 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -534,6 +534,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicNewCorrelationPlotFeature"; menuBuilder << "RicNewCorrelationMatrixPlotFeature"; menuBuilder << "RicNewParameterResultCrossPlotFeature"; + menuBuilder << "RicNewCorrelationReportPlotFeature"; } else if ( dynamic_cast( firstUiItem ) ) {