diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/PlotTemplateCommands/CMakeLists_files.cmake index 293cacdbd1..6b7149beaa 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/CMakeLists_files.cmake @@ -1,5 +1,4 @@ set(SOURCE_GROUP_HEADER_FILES - ${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.h ${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotTemplateTools.h ${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.h @@ -10,7 +9,6 @@ set(SOURCE_GROUP_HEADER_FILES ) set(SOURCE_GROUP_SOURCE_FILES - ${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotTemplateTools.cpp ${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.cpp diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp index 28f3078138..535ec2d959 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp @@ -95,7 +95,9 @@ void RicSaveMultiPlotTemplateFeature::onActionTriggered( bool isChecked ) QFile exportFile( fileName ); if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) { - RiaLogging::error( QString( "Save Plot Template : Could not open the file: %1" ).arg( fileName ) ); + RiaLogging::errorInMessageBox( NULL, + "Save Plot Template", + QString( "Could not save to the file: %1" ).arg( fileName ) ); return; } diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp deleted file mode 100644 index 78947f3647..0000000000 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp +++ /dev/null @@ -1,230 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2019- 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 "RicSavePlotTemplateFeature.h" - -#include "RicReloadPlotTemplatesFeature.h" -#include "RicSummaryPlotTemplateTools.h" - -#include "RiaGuiApplication.h" -#include "RiaLogging.h" -#include "RiaPreferences.h" -#include "RiaSummaryTools.h" - -#include "RimEnsembleCurveSet.h" -#include "RimEnsembleCurveSetCollection.h" -#include "RimProject.h" -#include "RimSummaryCurve.h" -#include "RimSummaryPlot.h" - -#include "RiuFileDialogTools.h" - -#include "cafPdmObject.h" -#include "cafSelectionManager.h" -#include "cafUtils.h" - -#include -#include -#include -#include - -CAF_CMD_SOURCE_INIT( RicSavePlotTemplateFeature, "RicSavePlotTemplateFeature" ); - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RicSavePlotTemplateFeature::isCommandEnabled() -{ - if ( selectedSummaryPlot() ) return true; - - return false; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked ) -{ - if ( !selectedSummaryPlot() ) return; - - RiaGuiApplication* app = RiaGuiApplication::instance(); - - QString fallbackPath; - auto folders = app->preferences()->plotTemplateFolders(); - if ( !folders.empty() ) - { - // Use the last folder from preferences as the default fall back folder - fallbackPath = folders.back(); - } - - QString startPath = app->lastUsedDialogDirectoryWithFallback( "PLOT_TEMPLATE", fallbackPath ); - - QString templateCandidateName = caf::Utils::makeValidFileBasename( selectedSummaryPlot()->description() ); - - startPath = startPath + "/" + templateCandidateName + ".rpt"; - - QString fileName = RiuFileDialogTools::getSaveFileName( nullptr, - tr( "Save Plot Template To File" ), - startPath, - tr( "Plot Template Files (*.rpt);;All files(*.*)" ) ); - if ( !fileName.isEmpty() ) - { - QFile exportFile( fileName ); - if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) - { - RiaLogging::error( QString( "Save Plot Template : Could not open the file: %1" ).arg( fileName ) ); - return; - } - - QString objectAsText = createTextFromObject( selectedSummaryPlot() ); - - QTextStream stream( &exportFile ); - stream << objectAsText; - - QString absPath = QFileInfo( fileName ).absolutePath(); - bool foundPathInPreferences = false; - for ( const auto& f : folders ) - { - if ( absPath.indexOf( f ) != -1 ) - { - foundPathInPreferences = true; - } - } - - if ( !foundPathInPreferences ) - { - QMessageBox msgBox; - msgBox.setIcon( QMessageBox::Question ); - - QString questionText; - questionText = QString( "The path is not part of the search path for templates.\n\nDo you want to append " - "the destination path to the search path?" ); - - msgBox.setText( questionText ); - msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel ); - - int ret = msgBox.exec(); - if ( ret == QMessageBox::Yes ) - { - app->preferences()->appendPlotTemplateFolders( absPath ); - app->preferences()->writePreferencesToApplicationStore(); - } - } - - app->setLastUsedDialogDirectory( "PLOT_TEMPLATE", absPath ); - - RicReloadPlotTemplatesFeature::rebuildFromDisc(); - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summaryPlot ) -{ - if ( !summaryPlot ) return QString(); - - QString objectAsText = summaryPlot->writeObjectToXmlString(); - - caf::PdmObjectHandle* obj = - caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText, - caf::PdmDefaultObjectFactory::instance(), - true ); - - RimSummaryPlot* newSummaryPlot = dynamic_cast( obj ); - if ( newSummaryPlot ) - { - { - std::set caseReferenceStrings; - - const QString summaryFieldKeyword = RicSummaryPlotTemplateTools::summaryCaseFieldKeyword(); - for ( const auto& curve : newSummaryPlot->summaryCurves() ) - { - auto fieldHandle = curve->findField( summaryFieldKeyword ); - if ( fieldHandle ) - { - auto reference = fieldHandle->xmlCapability()->referenceString(); - caseReferenceStrings.insert( reference ); - } - } - - size_t index = 0; - for ( const auto& s : caseReferenceStrings ) - { - QString placeholderText = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase(); - QString caseName = QString( "%1 %2" ).arg( placeholderText ).arg( index++ ); - - objectAsText.replace( s, caseName ); - } - } - - { - std::set ensembleReferenceStrings; - - const QString summaryGroupFieldKeyword = RicSummaryPlotTemplateTools::summaryGroupFieldKeyword(); - - for ( const auto& curveSet : newSummaryPlot->ensembleCurveSetCollection()->curveSets() ) - { - auto fieldHandle = curveSet->findField( summaryGroupFieldKeyword ); - if ( fieldHandle ) - { - auto reference = fieldHandle->xmlCapability()->referenceString(); - ensembleReferenceStrings.insert( reference ); - } - } - - size_t index = 0; - for ( const auto& s : ensembleReferenceStrings ) - { - QString placeholderText = RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup(); - QString ensembleName = QString( "%1 %2" ).arg( placeholderText ).arg( index++ ); - - objectAsText.replace( s, ensembleName ); - } - } - } - - delete obj; - - return objectAsText; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSavePlotTemplateFeature::setupActionLook( QAction* actionToSetup ) -{ - actionToSetup->setText( "Save As Plot Template" ); - actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimSummaryPlot* RicSavePlotTemplateFeature::selectedSummaryPlot() const -{ - RimSummaryPlot* sumPlot = nullptr; - - caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); - if ( selObj ) - { - sumPlot = RiaSummaryTools::parentSummaryPlot( selObj ); - } - - return sumPlot; -} diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.h b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.h deleted file mode 100644 index 35839b4b57..0000000000 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.h +++ /dev/null @@ -1,42 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2019- 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 RimSummaryPlot; - -//================================================================================================== -/// -//================================================================================================== -class RicSavePlotTemplateFeature : public caf::CmdFeature -{ - CAF_CMD_HEADER_INIT; - -protected: - bool isCommandEnabled() override; - void onActionTriggered( bool isChecked ) override; - void setupActionLook( QAction* actionToSetup ) override; - -private: - static QString createTextFromObject( RimSummaryPlot* summaryPlot ); - -private: - RimSummaryPlot* selectedSummaryPlot() const; -}; diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp index 1cdc0ee8bd..5c0e4529ee 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp @@ -278,190 +278,6 @@ void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryPlot* } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const QString& fileName ) -{ - QFile importFile( fileName ); - if ( !importFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) - { - RiaLogging::error( QString( "Create Plot from Template : Could not open the file: %1" ).arg( fileName ) ); - return nullptr; - } - - QTextStream stream( &importFile ); - - QString objectAsText = stream.readAll(); - - caf::PdmObjectHandle* obj = - caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText, - caf::PdmDefaultObjectFactory::instance(), - true ); - - auto* newSummaryPlot = dynamic_cast( obj ); - if ( newSummaryPlot ) - { - bool isTemplateBefore_2021_06 = !objectAsText.contains( "" ); - if ( isTemplateBefore_2021_06 ) - { - for ( auto c : newSummaryPlot->summaryAndEnsembleCurves() ) - { - // Special handling of appearance settings because we do not have any support for file version of - // plot templates - // https://github.com/OPM/ResInsight/issues/8257 - c->updateCurveAppearanceForFilesOlderThan_2021_06(); - } - } - - return newSummaryPlot; - } - - delete obj; - - return nullptr; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( - RimSummaryPlot* summaryPlot, - const std::vector& selectedSummaryCases, - const std::vector& selectedEnsembles ) -{ - if ( !summaryPlot ) return; - - if ( selectedSummaryCases.empty() && selectedEnsembles.empty() ) return; - - RimSummaryMultiPlot* multiPlot = RicSummaryPlotBuilder::createAndAppendSingleSummaryMultiPlot( summaryPlot ); - summaryPlot->resolveReferencesRecursively(); - summaryPlot->initAfterReadRecursively(); - - { - // Replace single summary curves data sources - - auto summaryCurves = summaryPlot->summaryCurves(); - - const QString summaryFieldKeyword = RicSummaryPlotTemplateTools::summaryCaseFieldKeyword(); - - int maximumIndexValue = -1; - for ( const auto& curve : summaryCurves ) - { - auto fieldHandle = curve->findField( summaryFieldKeyword ); - if ( fieldHandle ) - { - bool conversionOk = false; - const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase(); - - auto referenceString = fieldHandle->xmlCapability()->referenceString(); - int indexValue = - RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk ); - - maximumIndexValue = std::max( maximumIndexValue, indexValue ); - - if ( conversionOk && indexValue >= 0 && indexValue < static_cast( selectedSummaryCases.size() ) ) - { - auto summaryCaseY = selectedSummaryCases[static_cast( indexValue )]; - 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 ); - } - } - } - } - } - - if ( selectedSummaryCases.size() > static_cast( maximumIndexValue + 1 ) ) - { - // Use the curve style of the last curve in template, and duplicate this for remaining data sources - - if ( !summaryCurves.empty() ) - { - auto lastSummaryCurve = summaryCurves.back(); - - for ( size_t i = maximumIndexValue; i < selectedSummaryCases.size(); i++ ) - { - auto newCurve = - dynamic_cast( lastSummaryCurve->xmlCapability()->copyByXmlSerialization( - caf::PdmDefaultObjectFactory::instance() ) ); - - auto summaryCaseY = selectedSummaryCases[i]; - newCurve->setSummaryCaseY( summaryCaseY ); - summaryPlot->addCurveAndUpdate( newCurve ); - } - } - } - } - - { - // Replace ensemble data sources - - auto summaryCurveSets = summaryPlot->ensembleCurveSetCollection()->curveSets(); - - const QString summaryGroupFieldKeyword = RicSummaryPlotTemplateTools::summaryGroupFieldKeyword(); - - int maximumIndexValue = -1; - - for ( const auto& curveSet : summaryCurveSets ) - { - auto fieldHandle = curveSet->findField( summaryGroupFieldKeyword ); - if ( fieldHandle ) - { - bool conversionOk = false; - const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup(); - - auto referenceString = fieldHandle->xmlCapability()->referenceString(); - int indexValue = - RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk ); - - maximumIndexValue = std::max( maximumIndexValue, indexValue ); - - if ( conversionOk && indexValue < static_cast( selectedEnsembles.size() ) ) - { - auto summaryCaseY = selectedEnsembles[indexValue]; - curveSet->setSummaryCaseCollection( summaryCaseY ); - } - } - } - - if ( selectedEnsembles.size() > static_cast( maximumIndexValue + 1 ) ) - { - // Use the curve style of the last curve in template, and duplicate this for remaining data sources - - if ( !summaryCurveSets.empty() ) - { - auto lastSummaryCurveSet = summaryCurveSets.back(); - - for ( size_t i = maximumIndexValue; i < selectedEnsembles.size(); i++ ) - { - auto newCurveSet = - dynamic_cast( lastSummaryCurveSet->xmlCapability()->copyByXmlSerialization( - caf::PdmDefaultObjectFactory::instance() ) ); - - auto ensembleDataSource = selectedEnsembles[i]; - newCurveSet->setSummaryCaseCollection( ensembleDataSource ); - - summaryPlot->ensembleCurveSetCollection()->addCurveSet( newCurveSet ); - } - } - } - } - - multiPlot->updateConnectedEditors(); - - summaryPlot->loadDataAndUpdate(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h index 8d7a25cac2..9212c3feb0 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h @@ -41,9 +41,31 @@ class RimSummaryAddressCollection; class RicSummaryPlotTemplateTools { public: + static RimSummaryMultiPlot* create( const QString& fileName ); + + static QString selectPlotTemplatePath(); + + static QString summaryCaseFieldKeyword(); + static QString summaryGroupFieldKeyword(); + + static QString placeholderTextForSummaryCase(); + static QString placeholderTextForSummaryGroup(); + static QString placeholderTextForWell(); + static QString placeholderTextForGroup(); + +private: static RimSummaryMultiPlot* createMultiPlotFromTemplateFile( const QString& fileName ); - static RimSummaryMultiPlot* create( const QString& fileName ); + static std::vector selectedSummaryCases(); + static std::vector selectedSummaryCaseCollections(); + static std::vector selectedSummaryAddressCollections(); + + 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 ); static void setValuesForPlaceholders( RimSummaryMultiPlot* summaryMultiPlot, const std::vector& selectedSummaryCases, @@ -59,33 +81,6 @@ public: const std::vector& groupNames, const std::vector& regions ); - static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName ); - static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot, - const std::vector& selectedSummaryCases, - const std::vector& selectedEnsembles ); - - 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 ); - - static QString selectPlotTemplatePath(); - - static std::vector selectedSummaryCases(); - static std::vector selectedSummaryCaseCollections(); - - static std::vector selectedSummaryAddressCollections(); - - static QString summaryCaseFieldKeyword(); - static QString summaryGroupFieldKeyword(); - - static QString placeholderTextForSummaryCase(); - static QString placeholderTextForSummaryGroup(); - static QString placeholderTextForWell(); - static QString placeholderTextForGroup(); - -private: static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, const std::set& allAddresses ); diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewPlotAxisPropertiesFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewPlotAxisPropertiesFeature.cpp index 09e42f57ac..90356804fe 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewPlotAxisPropertiesFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewPlotAxisPropertiesFeature.cpp @@ -36,8 +36,8 @@ CAF_CMD_SOURCE_INIT( RicNewPlotAxisPropertiesFeature, "RicNewPlotAxisPropertiesF //-------------------------------------------------------------------------------------------------- bool RicNewPlotAxisPropertiesFeature::isCommandEnabled() { - std::vector summaryPlots = caf::selectedObjectsByTypeStrict(); - return summaryPlots.size() == 1; + auto* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject(); + return ( summaryPlot != nullptr ); } //-------------------------------------------------------------------------------------------------- @@ -45,13 +45,13 @@ bool RicNewPlotAxisPropertiesFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicNewPlotAxisPropertiesFeature::onActionTriggered( bool isChecked ) { - std::vector summaryPlots = caf::selectedObjectsByTypeStrict(); - if ( summaryPlots.size() != 1 ) return; - - RimSummaryPlot* summaryPlot = summaryPlots[0]; + auto* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject(); + if ( !summaryPlot ) return; RimPlotAxisProperties* newPlotAxisProperties = summaryPlot->addNewAxisProperties( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, "New Axis" ); + summaryPlot->plotWidget()->ensureAxisIsCreated( newPlotAxisProperties->plotAxisType() ); + newPlotAxisProperties->setNameForUnusedAxis(); summaryPlot->updateConnectedEditors(); RiuPlotMainWindowTools::selectAsCurrentItem( newPlotAxisProperties ); diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index e35e5c92dc..db636871c1 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -100,6 +100,7 @@ #include "RimParameterResultCrossPlot.h" #include "RimPerforationCollection.h" #include "RimPerforationInterval.h" +#include "RimPlotAxisPropertiesInterface.h" #include "RimPlotDataFilterCollection.h" #include "RimPlotDataFilterItem.h" #include "RimPltPlotCollection.h" @@ -680,7 +681,6 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicNewSummaryCrossPlotCurveFeature"; menuBuilder << "RicNewPlotAxisPropertiesFeature"; menuBuilder << "Separator"; - menuBuilder << "RicSavePlotTemplateFeature"; // Export is not supported for cross plot if ( !summaryCrossPlot ) menuBuilder << "RicAsciiExportSummaryPlotFeature"; @@ -1043,6 +1043,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicCreateMultiPlotFromSelectionFeature"; menuBuilder << "RicCreatePlotFromTemplateByShortcutFeature"; } + else if ( dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicNewPlotAxisPropertiesFeature"; + } if ( dynamic_cast( firstUiItem ) ) { diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp b/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp index d3ef5cad76..680cc82bb1 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.cpp @@ -133,6 +133,21 @@ void RimPlotAxisProperties::enableRangeSettings( bool enable ) m_isRangeSettingsEnabled = enable; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPlotAxisProperties::setNameForUnusedAxis() +{ + QString name = "Unused "; + + if ( m_plotAxis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ) + name += "Left"; + else if ( m_plotAxis() == RiaDefines::PlotAxis::PLOT_AXIS_RIGHT ) + name += "Right"; + + m_name = name; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.h b/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.h index b63b4de154..91551fd06d 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.h +++ b/ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.h @@ -61,6 +61,7 @@ public: void setEnableTitleTextSettings( bool enable ); void enableRangeSettings( bool enable ); + void setNameForUnusedAxis(); void setNameAndAxis( const QString& name, RiaDefines::PlotAxis axis, int axisIndex = 0 ); AxisTitlePositionType titlePosition() const override; diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp index bb67b29cc8..eb18e3573d 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp @@ -511,7 +511,10 @@ QList RimSummaryCurve::calculateValueOptions( const caf: for ( auto axis : plot->plotAxes() ) { - options.push_back( caf::PdmOptionItemInfo( axis->name(), axis ) ); + if ( dynamic_cast( axis ) ) + { + options.push_back( caf::PdmOptionItemInfo( axis->name(), axis ) ); + } } } diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index eb10d8e681..8cf3be5e8e 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -127,12 +127,6 @@ RimSummaryPlot::RimSummaryPlot( bool isCrossPlot ) CAF_PDM_InitFieldNoDefault( &m_axisProperties, "AxisProperties", "Axes", ":/Axes16x16.png" ); - auto leftAxis = addNewAxisProperties( RiuPlotAxis::defaultLeft(), "Left" ); - leftAxis->setAlwaysRequired( true ); - - auto rightAxis = addNewAxisProperties( RiuPlotAxis::defaultRight(), "Right" ); - rightAxis->setAlwaysRequired( true ); - if ( m_isCrossPlot ) { addNewAxisProperties( RiuPlotAxis::defaultBottom(), "Bottom" ); @@ -145,6 +139,12 @@ RimSummaryPlot::RimSummaryPlot( bool isCrossPlot ) m_axisProperties.push_back( timeAxisProperties ); } + auto leftAxis = addNewAxisProperties( RiuPlotAxis::defaultLeft(), "Left" ); + leftAxis->setAlwaysRequired( true ); + + auto rightAxis = addNewAxisProperties( RiuPlotAxis::defaultRight(), "Right" ); + rightAxis->setAlwaysRequired( true ); + CAF_PDM_InitFieldNoDefault( &m_textCurveSetEditor, "SummaryPlotFilterTextCurveSetEditor", "Text Filter Curve Creator" ); m_textCurveSetEditor.uiCapability()->setUiTreeHidden( true ); m_textCurveSetEditor = new RimSummaryPlotFilterTextCurveSetEditor; @@ -813,27 +813,37 @@ void RimSummaryPlot::updateAxis( RiaDefines::PlotAxis plotAxis ) if ( riuPlotAxis.axis() == plotAxis ) { auto* axisProperties = dynamic_cast( yAxisProperties ); - if ( yAxisProperties->isActive() && hasVisibleCurvesForAxis( riuPlotAxis ) && axisProperties ) + if ( axisProperties ) { - plotWidget()->enableAxis( riuPlotAxis, true ); - - std::set timeHistoryQuantities; - - for ( auto c : visibleTimeHistoryCurvesForAxis( riuPlotAxis ) ) + if ( yAxisProperties->isActive() && hasVisibleCurvesForAxis( riuPlotAxis ) ) { - timeHistoryQuantities.insert( c->quantityName() ); + plotWidget()->enableAxis( riuPlotAxis, true ); + } + else + { + plotWidget()->enableAxis( riuPlotAxis, false ); } - RimSummaryPlotAxisFormatter calc( axisProperties, - visibleSummaryCurvesForAxis( riuPlotAxis ), - {}, - visibleAsciiDataCurvesForAxis( riuPlotAxis ), - timeHistoryQuantities ); - calc.applyAxisPropertiesToPlot( plotWidget() ); - } - else - { - plotWidget()->enableAxis( riuPlotAxis, false ); + if ( !hasVisibleCurvesForAxis( riuPlotAxis ) ) + { + axisProperties->setNameForUnusedAxis(); + } + else + { + std::set timeHistoryQuantities; + + for ( auto c : visibleTimeHistoryCurvesForAxis( riuPlotAxis ) ) + { + timeHistoryQuantities.insert( c->quantityName() ); + } + + RimSummaryPlotAxisFormatter calc( axisProperties, + visibleSummaryCurvesForAxis( riuPlotAxis ), + {}, + visibleAsciiDataCurvesForAxis( riuPlotAxis ), + timeHistoryQuantities ); + calc.applyAxisPropertiesToPlot( plotWidget() ); + } } plotWidget()->enableAxisNumberLabels( riuPlotAxis, axisProperties->showNumbers() ); diff --git a/ApplicationLibCode/UserInterface/RiuMainWindowBase.cpp b/ApplicationLibCode/UserInterface/RiuMainWindowBase.cpp index 4b4ba20f98..46dc29bb68 100644 --- a/ApplicationLibCode/UserInterface/RiuMainWindowBase.cpp +++ b/ApplicationLibCode/UserInterface/RiuMainWindowBase.cpp @@ -346,11 +346,10 @@ bool RiuMainWindowBase::isBlockingViewSelectionOnSubWindowActivated() const //-------------------------------------------------------------------------------------------------- void RiuMainWindowBase::removeViewerFromMdiArea( QMdiArea* mdiArea, QWidget* viewer ) { - bool wasMaximized = viewer && viewer->isMaximized(); - bool removedSubWindowWasActive = false; QMdiSubWindow* subWindowBeingClosed = findMdiSubWindow( viewer ); + bool wasMaximized = subWindowBeingClosed->isMaximized(); if ( subWindowBeingClosed ) { if ( subWindowBeingClosed->isActiveWindow() ) diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp index 2853fc747b..493c82d7a3 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp @@ -80,7 +80,7 @@ RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent ) { CAF_ASSERT( m_plotDefinition ); - QVBoxLayout* layout = new QVBoxLayout; + auto* layout = new QVBoxLayout; layout->setContentsMargins( 0, 0, 0, 0 ); setLayout( layout ); @@ -275,7 +275,7 @@ void RiuQwtPlotWidget::setInternalLegendVisible( bool visible ) { if ( visible ) { - QwtLegend* legend = new QwtLegend( this ); + auto* legend = new QwtLegend( this ); m_plot->insertLegend( legend, QwtPlot::BottomLegend ); } else @@ -291,7 +291,7 @@ void RiuQwtPlotWidget::insertLegend( RiuPlotWidget::Legend legendPosition ) { CAF_ASSERT( legendPosition == RiuPlotWidget::Legend::BOTTOM ); - QwtLegend* legend = new QwtLegend( this ); + auto* legend = new QwtLegend( this ); m_plot->insertLegend( legend, QwtPlot::BottomLegend ); } @@ -355,7 +355,7 @@ void RiuQwtPlotWidget::enableGridLines( RiuPlotAxis axis, bool majorGridLines, b auto qwtAxis = toQwtPlotAxis( axis ); for ( QwtPlotItem* plotItem : plotItems ) { - QwtPlotGrid* grid = static_cast( plotItem ); + auto* grid = static_cast( plotItem ); if ( qwtAxis == QwtAxis::XTop || qwtAxis == QwtAxis::XBottom ) { grid->setXAxis( qwtAxis ); @@ -382,8 +382,8 @@ void RiuQwtPlotWidget::setMajorAndMinorTickIntervals( RiuPlotAxis axis, double minValue, double maxValue ) { - auto qwtAxis = toQwtPlotAxis( axis ); - RiuQwtLinearScaleEngine* scaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); + auto qwtAxis = toQwtPlotAxis( axis ); + auto* scaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); if ( scaleEngine ) { QwtScaleDiv scaleDiv = @@ -404,8 +404,8 @@ void RiuQwtPlotWidget::setMajorAndMinorTickIntervalsAndRange( RiuPlotAxis axis, double rangeMin, double rangeMax ) { - auto qwtAxis = toQwtPlotAxis( axis ); - RiuQwtLinearScaleEngine* scaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); + auto qwtAxis = toQwtPlotAxis( axis ); + auto* scaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); if ( scaleEngine ) { QwtScaleDiv scaleDiv = scaleEngine->divideScaleWithExplicitIntervalsAndRange( minTickValue, @@ -542,7 +542,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event ) { if ( RiuPlotWidget::handleDragDropEvent( event ) ) return true; - QWheelEvent* wheelEvent = dynamic_cast( event ); + auto* wheelEvent = dynamic_cast( event ); if ( wheelEvent && watched == m_plot->canvas() ) { event->accept(); @@ -551,7 +551,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event ) return true; } - QMouseEvent* mouseEvent = dynamic_cast( event ); + auto* mouseEvent = dynamic_cast( event ); if ( mouseEvent ) { if ( isZoomerActive() ) return false; @@ -571,7 +571,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event ) QWidget* childClicked = m_plot->childAt( m_clickPosition ); if ( childClicked ) { - QwtScaleWidget* scaleWidget = qobject_cast( childClicked ); + auto* scaleWidget = qobject_cast( childClicked ); if ( scaleWidget ) { onAxisSelected( scaleWidget, toggleItemInSelection ); @@ -678,7 +678,7 @@ void RiuQwtPlotWidget::applyAxisTitleToQwt( RiuPlotAxis axis ) //-------------------------------------------------------------------------------------------------- QSize RiuQwtPlotWidget::sizeHint() const { - return QSize( 0, 0 ); + return { 0, 0 }; } //-------------------------------------------------------------------------------------------------- @@ -686,7 +686,7 @@ QSize RiuQwtPlotWidget::sizeHint() const //-------------------------------------------------------------------------------------------------- QSize RiuQwtPlotWidget::minimumSizeHint() const { - return QSize( 0, 0 ); + return { 0, 0 }; } //-------------------------------------------------------------------------------------------------- @@ -787,8 +787,8 @@ void RiuQwtPlotWidget::onAxisSelected( QwtScaleWidget* scale, bool toggleItemInS { for ( int i = 0; i < QwtAxis::AxisPositions; ++i ) { - QwtAxis::Position pos = static_cast( i ); - int count = m_plot->axesCount( pos ); + auto pos = static_cast( i ); + int count = m_plot->axesCount( pos ); for ( int id = 0; id < count; id++ ) { QwtAxisId axisId( pos, id ); @@ -844,13 +844,13 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos, *distanceFromClick = std::numeric_limits::infinity(); const QwtPlotItemList& itmList = m_plot->itemList(); - for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++ ) + for ( auto it : itmList ) { - if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve ) + if ( it->rtti() == QwtPlotItem::Rtti_PlotCurve ) { - QwtPlotCurve* candidateCurve = static_cast( *it ); - double dist = std::numeric_limits::infinity(); - int curvePoint = candidateCurve->closestPoint( pos, &dist ); + auto* candidateCurve = static_cast( it ); + double dist = std::numeric_limits::infinity(); + int curvePoint = candidateCurve->closestPoint( pos, &dist ); if ( dist < *distanceFromClick ) { *closestItem = candidateCurve; @@ -858,21 +858,21 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos, *closestCurvePoint = curvePoint; } } - else if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotShape ) + else if ( it->rtti() == QwtPlotItem::Rtti_PlotShape ) { - QwtPlotShapeItem* shapeItem = static_cast( *it ); - QPointF scalePos( m_plot->invTransform( QwtAxis::XBottom, pos.x() ), + auto* shapeItem = static_cast( it ); + QPointF scalePos( m_plot->invTransform( QwtAxis::XBottom, pos.x() ), m_plot->invTransform( QwtAxis::YLeft, pos.y() ) ); if ( shapeItem->shape().boundingRect().contains( scalePos ) ) { - *closestItem = *it; + *closestItem = it; *distanceFromClick = 0.0; } } - else if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotBarChart ) + else if ( it->rtti() == QwtPlotItem::Rtti_PlotBarChart ) { - QwtPlotBarChart* barChart = static_cast( *it ); - QPointF scalePos( m_plot->invTransform( QwtAxis::XBottom, pos.x() ), + auto* barChart = static_cast( it ); + QPointF scalePos( m_plot->invTransform( QwtAxis::XBottom, pos.x() ), m_plot->invTransform( QwtAxis::YLeft, pos.y() ) ); bool horizontal = barChart->orientation() == Qt::Horizontal; @@ -883,7 +883,7 @@ void RiuQwtPlotWidget::findClosestPlotItem( const QPoint& pos, : std::abs( samplePoint.x() - scalePos.x() ); if ( dist < *distanceFromClick ) { - *closestItem = *it; + *closestItem = it; *closestCurvePoint = (int)i; *distanceFromClick = dist; } @@ -964,8 +964,8 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set& c auto plotItemList = m_plot->itemList(); for ( QwtPlotItem* plotItem : plotItemList ) { - QwtPlotCurve* plotCurve = dynamic_cast( plotItem ); - QwtPlotShapeItem* plotShapeItem = dynamic_cast( plotItem ); + auto* plotCurve = dynamic_cast( plotItem ); + auto* plotShapeItem = dynamic_cast( plotItem ); if ( plotCurve ) { QPen existingPen = plotCurve->pen(); @@ -975,7 +975,7 @@ void RiuQwtPlotWidget::highlightPlotItems( const std::set& c QColor symbolColor; QColor symbolLineColor; - QwtSymbol* symbol = const_cast( plotCurve->symbol() ); + auto* symbol = const_cast( plotCurve->symbol() ); if ( symbol ) { symbolColor = symbol->brush().color(); @@ -1026,8 +1026,8 @@ void RiuQwtPlotWidget::resetPlotItemHighlighting() auto plotItemList = m_plot->itemList(); for ( QwtPlotItem* plotItem : plotItemList ) { - QwtPlotCurve* plotCurve = dynamic_cast( plotItem ); - QwtPlotShapeItem* plotShapeItem = dynamic_cast( plotItem ); + auto* plotCurve = dynamic_cast( plotItem ); + auto* plotShapeItem = dynamic_cast( plotItem ); if ( plotCurve && m_originalCurveColors.count( plotCurve ) ) { const QPen& existingPen = plotCurve->pen(); @@ -1036,7 +1036,7 @@ void RiuQwtPlotWidget::resetPlotItemHighlighting() plotCurve->setPen( colors.lineColor, existingPen.width(), existingPen.style() ); plotCurve->setZ( zValue ); - QwtSymbol* symbol = const_cast( plotCurve->symbol() ); + auto* symbol = const_cast( plotCurve->symbol() ); if ( symbol ) { symbol->setColor( colors.symbolColor ); @@ -1068,7 +1068,7 @@ void RiuQwtPlotWidget::highlightPlotItemsForQwtAxis( QwtAxisId axisId ) auto plotItemList = m_plot->itemList(); for ( QwtPlotItem* plotItem : plotItemList ) { - QwtPlotCurve* plotCurve = dynamic_cast( plotItem ); + auto* plotCurve = dynamic_cast( plotItem ); if ( plotCurve ) { QwtAxisId xAxis = plotCurve->xAxis(); @@ -1143,7 +1143,10 @@ void RiuQwtPlotWidget::enableAxisNumberLabels( RiuPlotAxis axis, bool isEnabled //-------------------------------------------------------------------------------------------------- bool RiuQwtPlotWidget::axisEnabled( RiuPlotAxis axis ) const { - return m_plot->isAxisVisible( toQwtPlotAxis( axis ) ); + auto qwtPlotAxis = toQwtPlotAxis( axis ); + if ( qwtPlotAxis.pos < 0 ) return false; + + return m_plot->isAxisVisible( qwtPlotAxis ); } //-------------------------------------------------------------------------------------------------- @@ -1202,12 +1205,10 @@ RiuQwtPlotWidget::AxisScaleType RiuQwtPlotWidget::axisScaleType( RiuPlotAxis axi { auto qwtAxis = toQwtPlotAxis( axis ); - QwtLogScaleEngine* logScaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); - QwtDateScaleEngine* dateScaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); - if ( logScaleEngine != nullptr ) - return AxisScaleType::LOGARITHMIC; - else if ( dateScaleEngine != nullptr ) - return AxisScaleType::DATE; + auto* logScaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); + auto* dateScaleEngine = dynamic_cast( m_plot->axisScaleEngine( qwtAxis ) ); + if ( logScaleEngine != nullptr ) return AxisScaleType::LOGARITHMIC; + if ( dateScaleEngine != nullptr ) return AxisScaleType::DATE; return AxisScaleType::LINEAR; } @@ -1299,7 +1300,7 @@ void RiuQwtPlotWidget::pruneAxes( const std::set& usedAxes ) } } - for ( auto plotAxis : axesToRemove ) + for ( const auto& plotAxis : axesToRemove ) moveAxis( plotAxis, RiuPlotAxis::defaultLeft() ); } @@ -1388,9 +1389,6 @@ QwtAxisId RiuQwtPlotWidget::toQwtPlotAxis( RiuPlotAxis plotAxis ) const { return it->second; } - else - { - CAF_ASSERT( false ); - return QwtAxisId( 0, 0 ); - } + + return { -1, -1 }; } diff --git a/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp b/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp index 58bdd23988..a1f21d2437 100644 --- a/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuSummaryPlot.cpp @@ -60,7 +60,6 @@ void RiuSummaryPlot::showContextMenu( QPoint pos ) caf::CmdFeatureMenuBuilder menuBuilder; menuBuilder << "RicShowPlotDataFeature"; - menuBuilder << "RicSavePlotTemplateFeature"; double distanceFromClick = std::numeric_limits::infinity(); diff --git a/ResInsightVersion.cmake b/ResInsightVersion.cmake index f61e930b04..9ab0682608 100644 --- a/ResInsightVersion.cmake +++ b/ResInsightVersion.cmake @@ -11,7 +11,7 @@ set(RESINSIGHT_VERSION_TEXT "-dev") # Must be unique and increasing within one combination of major/minor/patch version # The uniqueness of this text is independent of RESINSIGHT_VERSION_TEXT # Format of text must be ".xx" -set(RESINSIGHT_DEV_VERSION ".01") +set(RESINSIGHT_DEV_VERSION ".02") # https://github.com/CRAVA/crava/tree/master/libs/nrlib set(NRLIB_GITHUB_SHA "ba35d4359882f1c6f5e9dc30eb95fe52af50fd6f")