Plot Template updates (#9002)

* Ensemble plot templates now have .erpt extension and new icon
* Default plot templates are given a checkmark overlay on the icon
* Context menu has been cleaned up a bit
* Old default template is really just the last used template. Rename it.
* Add max. recursive depth setting in preferences for plot template searches
* Only create plots based on correct template type when importing ensembles or single cases
* Support creating new plot from template explorer
* Update last used template when creating a new plot from a template
This commit is contained in:
jonjenssen
2022-06-01 10:45:44 +02:00
committed by GitHub
parent 92afb11a76
commit 9f4d242a5d
24 changed files with 532 additions and 71 deletions

View File

@@ -10,6 +10,8 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateNewPlotFromTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSelectCaseOrEnsembleUi.h
)
set(SOURCE_GROUP_SOURCE_FILES
@@ -24,6 +26,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateNewPlotFromTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSelectCaseOrEnsembleUi.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@@ -0,0 +1,145 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicCreateNewPlotFromTemplateFeature.h"
#include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "RiaGuiApplication.h"
#include "RiaPreferences.h"
#include "RicSelectCaseOrEnsembleUi.h"
#include "RicSummaryPlotTemplateTools.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryMultiPlot.h"
#include "RiuPlotMainWindow.h"
#include "RiuPlotMainWindowTools.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QString>
CAF_CMD_SOURCE_INIT( RicCreateNewPlotFromTemplateFeature, "RicCreateNewPlotFromTemplateFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCreateNewPlotFromTemplateFeature::isCommandEnabled()
{
std::vector<caf::PdmUiItem*> uiItems;
caf::SelectionManager::instance()->selectedItems( uiItems );
if ( uiItems.size() != 1 ) return false;
RimPlotTemplateFileItem* file = dynamic_cast<RimPlotTemplateFileItem*>( uiItems[0] );
return ( file != nullptr );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateNewPlotFromTemplateFeature::onActionTriggered( bool isChecked )
{
std::vector<caf::PdmUiItem*> uiItems;
caf::SelectionManager::instance()->selectedItems( uiItems );
if ( uiItems.size() != 1 ) return;
RimPlotTemplateFileItem* file = dynamic_cast<RimPlotTemplateFileItem*>( uiItems[0] );
if ( file == nullptr ) return;
RimSummaryMultiPlot* plot = nullptr;
if ( file->isEnsembleTemplate() )
{
auto ensemble = selectEnsemble();
if ( !ensemble ) return;
plot = RicSummaryPlotTemplateTools::create( file->absoluteFilePath(), {}, { ensemble } );
}
else
{
auto sumCase = selectSummaryCase();
if ( !sumCase ) return;
plot = RicSummaryPlotTemplateTools::create( file->absoluteFilePath(), { sumCase }, {} );
}
if ( plot != nullptr )
{
RiaPreferences::current()->setLastUsedPlotTemplatePath( file->absoluteFilePath() );
RiaPreferences::current()->writePreferencesToApplicationStore();
}
RiuPlotMainWindowTools::selectAsCurrentItem( plot );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateNewPlotFromTemplateFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Create New Plot" );
actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryCase* RicCreateNewPlotFromTemplateFeature::selectSummaryCase()
{
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
RicSelectCaseOrEnsembleUi ui;
ui.setEnsembleSelectionMode( false );
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, &ui, "Create New Plot - Select Summary Case", "" );
propertyDialog.resize( QSize( 400, 200 ) );
if ( propertyDialog.exec() == QDialog::Accepted )
{
return ui.selectedSummaryCase();
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryCaseCollection* RicCreateNewPlotFromTemplateFeature::selectEnsemble()
{
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
RicSelectCaseOrEnsembleUi ui;
ui.setEnsembleSelectionMode( true );
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, &ui, "Create New Plot - Select Ensemble", "" );
propertyDialog.resize( QSize( 400, 200 ) );
if ( propertyDialog.exec() == QDialog::Accepted )
{
return ui.selectedEnsemble();
}
return nullptr;
}

View File

@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
class RimSummaryCase;
class RimSummaryCaseCollection;
//==================================================================================================
///
//==================================================================================================
class RicCreateNewPlotFromTemplateFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
RimSummaryCase* selectSummaryCase();
RimSummaryCaseCollection* selectEnsemble();
};

View File

@@ -47,7 +47,7 @@ bool RicCreatePlotFromTemplateByShortcutFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicCreatePlotFromTemplateByShortcutFeature::onActionTriggered( bool isChecked )
{
QString fileName = RiaPreferences::current()->defaultPlotTemplateAbsolutePath();
QString fileName = RiaPreferences::current()->lastUsedPlotTemplateAbsolutePath();
if ( !QFile::exists( fileName ) )
{

View File

@@ -88,5 +88,4 @@ void RicEditPlotTemplateFeature::onActionTriggered( bool isChecked )
void RicEditPlotTemplateFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Edit" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}

View File

@@ -95,5 +95,4 @@ void RicRenamePlotTemplateFeature::onActionTriggered( bool isChecked )
void RicRenamePlotTemplateFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Rename" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}

View File

@@ -89,7 +89,13 @@ void RicSaveMultiPlotTemplateFeature::onActionTriggered( bool isChecked )
caf::PdmUiPropertyViewDialog propertyDialog( RiuPlotMainWindow::instance(), &settings, "Export Plot Template", "" );
if ( propertyDialog.exec() != QDialog::Accepted ) return;
QString fileName = settings.filePath() + "/" + settings.name() + ".rpt";
auto plot = selectedSummaryPlot();
if ( !plot ) return;
QString ext = ".rpt";
if ( selectedSummaryPlot()->curveSets().size() > 0 ) ext = ".erpt";
QString fileName = settings.filePath() + "/" + settings.name() + ext;
if ( !fileName.isEmpty() )
{
QFile exportFile( fileName );

View File

@@ -0,0 +1,134 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicSelectCaseOrEnsembleUi.h"
#include "RimProject.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
CAF_PDM_SOURCE_INIT( RicSelectCaseOrEnsembleUi, "RicSelectCaseOrEnsembleUi" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSelectCaseOrEnsembleUi::RicSelectCaseOrEnsembleUi()
: m_useEnsembleMode( false )
{
CAF_PDM_InitObject( "RicSelectCaseOrEnsembleUi" );
CAF_PDM_InitFieldNoDefault( &m_selectedSummaryCase, "SelectedSummaryCase", "Summary Case" );
m_selectedSummaryCase.uiCapability()->setAutoAddingOptionFromValue( false );
CAF_PDM_InitFieldNoDefault( &m_selectedEnsemble, "SelectedEnsemble", "Ensemble" );
m_selectedEnsemble.uiCapability()->setAutoAddingOptionFromValue( false );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectCaseOrEnsembleUi::setEnsembleSelectionMode( bool ensembleMode )
{
m_useEnsembleMode = ensembleMode;
RimProject* proj = RimProject::current();
if ( ensembleMode )
{
std::vector<RimSummaryCaseCollection*> groups = proj->summaryGroups();
for ( RimSummaryCaseCollection* group : groups )
{
if ( group->isEnsemble() )
{
m_selectedEnsemble = group;
break;
}
}
}
else
{
std::vector<RimSummaryCase*> cases = proj->allSummaryCases();
if ( cases.size() > 0 ) m_selectedSummaryCase = cases.front();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo>
RicSelectCaseOrEnsembleUi::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
{
QList<caf::PdmOptionItemInfo> options;
if ( fieldNeedingOptions == &m_selectedSummaryCase )
{
RimProject* proj = RimProject::current();
std::vector<RimSummaryCase*> cases = proj->allSummaryCases();
for ( RimSummaryCase* rimCase : cases )
{
options.push_back( caf::PdmOptionItemInfo( rimCase->displayCaseName(), rimCase ) );
}
}
else if ( fieldNeedingOptions == &m_selectedEnsemble )
{
RimProject* proj = RimProject::current();
std::vector<RimSummaryCaseCollection*> groups = proj->summaryGroups();
for ( RimSummaryCaseCollection* group : groups )
{
if ( group->isEnsemble() ) options.push_back( caf::PdmOptionItemInfo( group->name(), group ) );
}
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectCaseOrEnsembleUi::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
if ( m_useEnsembleMode )
uiOrdering.add( &m_selectedEnsemble );
else
uiOrdering.add( &m_selectedSummaryCase );
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryCase* RicSelectCaseOrEnsembleUi::selectedSummaryCase() const
{
if ( m_useEnsembleMode ) return nullptr;
return m_selectedSummaryCase();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryCaseCollection* RicSelectCaseOrEnsembleUi::selectedEnsemble() const
{
if ( !m_useEnsembleMode ) return nullptr;
return m_selectedEnsemble();
}

View File

@@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
#include <QList>
#include <QString>
#include <vector>
class RimSummaryCase;
class RimSummaryCaseCollection;
//==================================================================================================
///
//==================================================================================================
class RicSelectCaseOrEnsembleUi : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RicSelectCaseOrEnsembleUi();
void setEnsembleSelectionMode( bool selectEnsemble );
RimSummaryCase* selectedSummaryCase() const;
RimSummaryCaseCollection* selectedEnsemble() const;
protected:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
private:
caf::PdmPtrField<RimSummaryCase*> m_selectedSummaryCase;
caf::PdmPtrField<RimSummaryCaseCollection*> m_selectedEnsemble;
bool m_useEnsembleMode;
};

View File

@@ -53,6 +53,8 @@ void RicSetAsDefaultTemplateFeature::onActionTriggered( bool isChecked )
RiaPreferencesSummary::current()->addToDefaultPlotTemplates( file->absoluteFilePath() );
else
RiaPreferencesSummary::current()->removeFromDefaultPlotTemplates( file->absoluteFilePath() );
file->updateIconState();
}
//--------------------------------------------------------------------------------------------------
@@ -67,8 +69,7 @@ void RicSetAsDefaultTemplateFeature::setupActionLook( QAction* actionToSetup )
if ( file != nullptr )
{
actionToSetup->setCheckable( true );
actionToSetup->setChecked(
RiaPreferencesSummary::current()->isDefaultSummaryPlotTemplate( file->absoluteFilePath() ) );
actionToSetup->setChecked( file->isDefaultTemplate() );
}
}

View File

@@ -444,7 +444,7 @@ QString RicSummaryPlotTemplateTools::selectPlotTemplatePath()
{
QString fileName = ui.selectedPlotTemplates().front()->absoluteFilePath();
RiaPreferences::current()->setDefaultPlotTemplatePath( fileName );
RiaPreferences::current()->setLastUsedPlotTemplatePath( fileName );
RiaPreferences::current()->writePreferencesToApplicationStore();
return fileName;