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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 532 additions and 71 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

View File

@ -146,6 +146,7 @@
<file>SummaryPlots16x16.png</file> <file>SummaryPlots16x16.png</file>
<file>SummaryPlotsLight16x16.png</file> <file>SummaryPlotsLight16x16.png</file>
<file>SummaryTemplate16x16.png</file> <file>SummaryTemplate16x16.png</file>
<file>SummaryEnsembleTemplate16x16.png</file>
<file>SummaryXPlotLight16x16.png</file> <file>SummaryXPlotLight16x16.png</file>
<file>SummaryXPlotsLight16x16.png</file> <file>SummaryXPlotsLight16x16.png</file>
<file>Swap.png</file> <file>Swap.png</file>
@ -267,6 +268,7 @@
<file>AppendPrevCurve.svg</file> <file>AppendPrevCurve.svg</file>
<file>AppendNextCurve.png</file> <file>AppendNextCurve.png</file>
<file>AppendPrevCurve.png</file> <file>AppendPrevCurve.png</file>
<file>CheckOverlay16x16.png</file>
</qresource> </qresource>
<qresource prefix="/Shader"> <qresource prefix="/Shader">
<file>fs_CellFace.glsl</file> <file>fs_CellFace.glsl</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

View File

@ -213,13 +213,12 @@ RiaPreferences::RiaPreferences()
CAF_PDM_InitFieldNoDefault( &m_plotTemplateFolders, "plotTemplateFolders", "Plot Template Folder(s)" ); CAF_PDM_InitFieldNoDefault( &m_plotTemplateFolders, "plotTemplateFolders", "Plot Template Folder(s)" );
m_plotTemplateFolders.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() ); m_plotTemplateFolders.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
CAF_PDM_InitField( &m_searchPlotTemplateFoldersRecursively, CAF_PDM_InitField( &m_maxPlotTemplateFoldersDepth,
"SearchPlotTemplateFoldersRecursively", "MaxPlotTemplateFoldersDepth",
true, 2,
"Search Plot Templates Recursively" ); "Maximum Plot Template Folder Search Depth" );
caf::PdmUiNativeCheckBoxEditor::configureFieldForEditor( &m_searchPlotTemplateFoldersRecursively );
CAF_PDM_InitFieldNoDefault( &m_defaultPlotTemplate, "defaultPlotTemplate", "Default Plot Template" ); CAF_PDM_InitFieldNoDefault( &m_lastUsedPlotTemplate, "defaultPlotTemplate", "Default Plot Template" );
CAF_PDM_InitFieldNoDefault( &m_pageSize, "pageSize", "Page Size" ); CAF_PDM_InitFieldNoDefault( &m_pageSize, "pageSize", "Page Size" );
CAF_PDM_InitFieldNoDefault( &m_pageOrientation, "pageOrientation", "Page Orientation" ); CAF_PDM_InitFieldNoDefault( &m_pageOrientation, "pageOrientation", "Page Orientation" );
@ -383,7 +382,7 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
caf::PdmUiGroup* group = summaryGrp->addNewGroup( "Plot Templates" ); caf::PdmUiGroup* group = summaryGrp->addNewGroup( "Plot Templates" );
group->add( &m_plotTemplateFolders ); group->add( &m_plotTemplateFolders );
group->add( &m_searchPlotTemplateFoldersRecursively ); group->add( &m_maxPlotTemplateFoldersDepth );
caf::PdmUiGroup* generalGrp = uiOrdering.addNewGroup( "General" ); caf::PdmUiGroup* generalGrp = uiOrdering.addNewGroup( "General" );
@ -671,9 +670,9 @@ QString RiaPreferences::dateTimeFormat( RiaDefines::DateFormatComponents dateCom
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RiaPreferences::searchPlotTemplateFoldersRecursively() const int RiaPreferences::maxPlotTemplateFoldersDepth() const
{ {
return m_searchPlotTemplateFoldersRecursively(); return m_maxPlotTemplateFoldersDepth();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -714,17 +713,17 @@ void RiaPreferences::appendPlotTemplateFolders( const QString& folder )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QString RiaPreferences::defaultPlotTemplateAbsolutePath() const QString RiaPreferences::lastUsedPlotTemplateAbsolutePath() const
{ {
return m_defaultPlotTemplate().path(); return m_lastUsedPlotTemplate().path();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiaPreferences::setDefaultPlotTemplatePath( const QString& templatePath ) void RiaPreferences::setLastUsedPlotTemplatePath( const QString& templatePath )
{ {
m_defaultPlotTemplate = templatePath; m_lastUsedPlotTemplate = templatePath;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -76,11 +76,11 @@ public:
RiaDefines::DateFormatComponents dateComponents = RiaDefines::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY, RiaDefines::DateFormatComponents dateComponents = RiaDefines::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY,
RiaDefines::TimeFormatComponents timeComponents = RiaDefines::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE_SECOND ) const; RiaDefines::TimeFormatComponents timeComponents = RiaDefines::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE_SECOND ) const;
bool searchPlotTemplateFoldersRecursively() const; int maxPlotTemplateFoldersDepth() const;
QStringList plotTemplateFolders() const; QStringList plotTemplateFolders() const;
void appendPlotTemplateFolders( const QString& folder ); void appendPlotTemplateFolders( const QString& folder );
QString defaultPlotTemplateAbsolutePath() const; QString lastUsedPlotTemplateAbsolutePath() const;
void setDefaultPlotTemplatePath( const QString& templatePath ); void setLastUsedPlotTemplatePath( const QString& templatePath );
bool openExportedPdfInViewer() const; bool openExportedPdfInViewer() const;
bool useQtChartsAsDefaultPlotType() const; bool useQtChartsAsDefaultPlotType() const;
@ -182,8 +182,8 @@ private:
caf::PdmField<bool> m_openExportedPdfInViewer; caf::PdmField<bool> m_openExportedPdfInViewer;
caf::PdmField<QString> m_plotTemplateFolders; caf::PdmField<QString> m_plotTemplateFolders;
caf::PdmField<bool> m_searchPlotTemplateFoldersRecursively; caf::PdmField<int> m_maxPlotTemplateFoldersDepth;
caf::PdmField<caf::FilePath> m_defaultPlotTemplate; caf::PdmField<caf::FilePath> m_lastUsedPlotTemplate;
caf::PdmField<bool> m_useQtChartsPlotByDefault; caf::PdmField<bool> m_useQtChartsPlotByDefault;
// Script paths // Script paths

View File

@ -31,6 +31,7 @@
#include "cafPdmUiPushButtonEditor.h" #include "cafPdmUiPushButtonEditor.h"
#include <algorithm> #include <algorithm>
#include <vector>
namespace caf namespace caf
{ {
@ -535,9 +536,20 @@ RiaPreferencesSummary::DefaultSummaryPlotType RiaPreferencesSummary::defaultSumm
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::vector<QString> RiaPreferencesSummary::defaultSummaryPlotTemplates() const std::vector<QString> RiaPreferencesSummary::defaultSummaryPlotTemplates( bool returnEnsembleTemplates ) const
{ {
return m_selectedDefaultTemplates(); std::vector<QString> templatesToUse;
for ( auto& fileName : m_selectedDefaultTemplates() )
{
bool singleTemplate = fileName.toLower().endsWith( ".rpt" );
if ( singleTemplate && returnEnsembleTemplates ) continue;
if ( !singleTemplate && !returnEnsembleTemplates ) continue;
if ( std::count( templatesToUse.begin(), templatesToUse.end(), fileName ) == 0 )
templatesToUse.push_back( fileName );
}
return templatesToUse;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -84,7 +84,7 @@ public:
int createH5SummaryDataThreadCount() const; int createH5SummaryDataThreadCount() const;
DefaultSummaryPlotType defaultSummaryPlotType() const; DefaultSummaryPlotType defaultSummaryPlotType() const;
std::vector<QString> defaultSummaryPlotTemplates() const; std::vector<QString> defaultSummaryPlotTemplates( bool returnEnsembleTemplates ) const;
bool isDefaultSummaryPlotTemplate( QString filename ) const; bool isDefaultSummaryPlotTemplate( QString filename ) const;
void addToDefaultPlotTemplates( QString filename ); void addToDefaultPlotTemplates( QString filename );
void removeFromDefaultPlotTemplates( QString filename ); void removeFromDefaultPlotTemplates( QString filename );

View File

@ -416,8 +416,9 @@ RimSummaryMultiPlot*
if ( prefs->defaultSummaryPlotType() == RiaPreferencesSummary::DefaultSummaryPlotType::PLOT_TEMPLATES ) if ( prefs->defaultSummaryPlotType() == RiaPreferencesSummary::DefaultSummaryPlotType::PLOT_TEMPLATES )
{ {
RimSummaryMultiPlot* plotToSelect = nullptr; RimSummaryMultiPlot* plotToSelect = nullptr;
for ( auto& filename : prefs->defaultSummaryPlotTemplates() ) bool ensembleTemplates = ( ensembles.size() > 0 );
for ( auto& filename : prefs->defaultSummaryPlotTemplates( ensembleTemplates ) )
{ {
plotToSelect = RicSummaryPlotTemplateTools::create( filename, cases, ensembles ); plotToSelect = RicSummaryPlotTemplateTools::create( filename, cases, ensembles );
} }

View File

@ -10,6 +10,8 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateNewPlotFromTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSelectCaseOrEnsembleUi.h
) )
set(SOURCE_GROUP_SOURCE_FILES set(SOURCE_GROUP_SOURCE_FILES
@ -24,6 +26,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.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}) 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 ) void RicCreatePlotFromTemplateByShortcutFeature::onActionTriggered( bool isChecked )
{ {
QString fileName = RiaPreferences::current()->defaultPlotTemplateAbsolutePath(); QString fileName = RiaPreferences::current()->lastUsedPlotTemplateAbsolutePath();
if ( !QFile::exists( fileName ) ) if ( !QFile::exists( fileName ) )
{ {

View File

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

View File

@ -95,5 +95,4 @@ void RicRenamePlotTemplateFeature::onActionTriggered( bool isChecked )
void RicRenamePlotTemplateFeature::setupActionLook( QAction* actionToSetup ) void RicRenamePlotTemplateFeature::setupActionLook( QAction* actionToSetup )
{ {
actionToSetup->setText( "Rename" ); 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", "" ); caf::PdmUiPropertyViewDialog propertyDialog( RiuPlotMainWindow::instance(), &settings, "Export Plot Template", "" );
if ( propertyDialog.exec() != QDialog::Accepted ) return; 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() ) if ( !fileName.isEmpty() )
{ {
QFile exportFile( fileName ); 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() ); RiaPreferencesSummary::current()->addToDefaultPlotTemplates( file->absoluteFilePath() );
else else
RiaPreferencesSummary::current()->removeFromDefaultPlotTemplates( file->absoluteFilePath() ); RiaPreferencesSummary::current()->removeFromDefaultPlotTemplates( file->absoluteFilePath() );
file->updateIconState();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -67,8 +69,7 @@ void RicSetAsDefaultTemplateFeature::setupActionLook( QAction* actionToSetup )
if ( file != nullptr ) if ( file != nullptr )
{ {
actionToSetup->setCheckable( true ); actionToSetup->setCheckable( true );
actionToSetup->setChecked( actionToSetup->setChecked( file->isDefaultTemplate() );
RiaPreferencesSummary::current()->isDefaultSummaryPlotTemplate( file->absoluteFilePath() ) );
} }
} }

View File

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

View File

@ -20,6 +20,7 @@
#include "RiaFieldHandleTools.h" #include "RiaFieldHandleTools.h"
#include "RiaLogging.h" #include "RiaLogging.h"
#include "RiaPreferencesSummary.h"
#include "cafPdmField.h" #include "cafPdmField.h"
#include "cafPdmUiFilePathEditor.h" #include "cafPdmUiFilePathEditor.h"
@ -55,6 +56,9 @@ void RimPlotTemplateFileItem::setFilePath( const QString& filePath )
this->uiCapability()->setUiName( fi.baseName() ); this->uiCapability()->setUiName( fi.baseName() );
m_absoluteFileName = filePath; m_absoluteFileName = filePath;
if ( isEnsembleTemplate() )
this->uiCapability()->setUiIcon( caf::IconProvider( ":/SummaryEnsembleTemplate16x16.png" ) );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -64,3 +68,39 @@ QString RimPlotTemplateFileItem::absoluteFilePath() const
{ {
return m_absoluteFileName(); return m_absoluteFileName();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFileItem::isEnsembleTemplate() const
{
return m_absoluteFileName().toLower().endsWith( ".erpt" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFileItem::updateIconState()
{
caf::IconProvider iconProvider = this->uiIconProvider();
if ( !iconProvider.valid() ) return;
if ( isDefaultTemplate() )
{
iconProvider.setOverlayResourceString( ":/CheckOverlay16x16.png" );
}
else
{
iconProvider.setOverlayResourceString( "" );
}
this->setUiIcon( iconProvider );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFileItem::isDefaultTemplate() const
{
return RiaPreferencesSummary::current()->isDefaultSummaryPlotTemplate( absoluteFilePath() );
}

View File

@ -36,6 +36,12 @@ public:
void setFilePath( const QString& filePath ); void setFilePath( const QString& filePath );
QString absoluteFilePath() const; QString absoluteFilePath() const;
bool isEnsembleTemplate() const;
bool isDefaultTemplate() const;
void updateIconState();
private: private:
caf::PdmField<QString> m_absoluteFileName; caf::PdmField<QString> m_absoluteFileName;
}; };

View File

@ -38,6 +38,7 @@ RimPlotTemplateFolderItem::RimPlotTemplateFolderItem()
CAF_PDM_InitObject( "Plot Templates", ":/Folder.png" ); CAF_PDM_InitObject( "Plot Templates", ":/Folder.png" );
CAF_PDM_InitFieldNoDefault( &m_folderName, "FolderName", "Folder" ); CAF_PDM_InitFieldNoDefault( &m_folderName, "FolderName", "Folder" );
m_folderName.uiCapability()->setUiReadOnly( true );
CAF_PDM_InitFieldNoDefault( &m_fileNames, "FileNames", "" ); CAF_PDM_InitFieldNoDefault( &m_fileNames, "FileNames", "" );
m_fileNames.uiCapability()->setUiTreeHidden( true ); m_fileNames.uiCapability()->setUiTreeHidden( true );
CAF_PDM_InitFieldNoDefault( &m_subFolders, "SubFolders", "" ); CAF_PDM_InitFieldNoDefault( &m_subFolders, "SubFolders", "" );
@ -59,7 +60,24 @@ void RimPlotTemplateFolderItem::createRootFolderItemsFromFolderPaths( const QStr
m_fileNames.deleteChildren(); m_fileNames.deleteChildren();
m_subFolders.deleteChildren(); m_subFolders.deleteChildren();
createSubFolderItemsFromFolderPaths( folderPaths ); createSubFolderItemsFromFolderPaths( folderPaths, RiaPreferences::current()->maxPlotTemplateFoldersDepth() );
updateIconState();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::updateIconState() const
{
for ( auto& folder : m_subFolders() )
{
folder->updateIconState();
}
for ( auto& item : m_fileNames() )
{
item->updateIconState();
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -101,16 +119,19 @@ void RimPlotTemplateFolderItem::setFolderPath( const QString& path )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::searchForFileAndFolderNames() void RimPlotTemplateFolderItem::searchForFileAndFolderNames( int levelsLeft )
{ {
m_fileNames.deleteChildren(); m_fileNames.deleteChildren();
m_subFolders.deleteChildren(); m_subFolders.deleteChildren();
levelsLeft--;
if ( levelsLeft < 0 ) return;
if ( m_folderName().path().isEmpty() ) if ( m_folderName().path().isEmpty() )
{ {
for ( size_t i = 0; i < m_subFolders.size(); ++i ) for ( size_t i = 0; i < m_subFolders.size(); ++i )
{ {
if ( m_subFolders[i] ) m_subFolders[i]->searchForFileAndFolderNames(); if ( m_subFolders[i] ) m_subFolders[i]->searchForFileAndFolderNames( levelsLeft );
} }
return; return;
} }
@ -121,10 +142,11 @@ void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
return; return;
} }
// Build a list of all scripts in the specified directory // Build a list of all templates in the specified directory
{ {
QStringList nameFilters; QStringList nameFilters;
nameFilters << "*.rpt"; nameFilters << "*.rpt";
nameFilters << "*.erpt";
QStringList fileList = caf::Utils::getFilesInDirectory( m_folderName().path(), nameFilters, true ); QStringList fileList = caf::Utils::getFilesInDirectory( m_folderName().path(), nameFilters, true );
for ( int i = 0; i < fileList.size(); i++ ) for ( int i = 0; i < fileList.size(); i++ )
@ -140,7 +162,7 @@ void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
} }
} }
if ( searchSubFoldersRecursively() ) if ( levelsLeft > 0 )
{ {
QStringList folderPaths; QStringList folderPaths;
@ -152,23 +174,7 @@ void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
folderPaths.push_back( fi.absoluteFilePath() ); folderPaths.push_back( fi.absoluteFilePath() );
} }
createSubFolderItemsFromFolderPaths( folderPaths ); createSubFolderItemsFromFolderPaths( folderPaths, levelsLeft );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( &m_folderName == changedField )
{
QFileInfo fi( m_folderName().path() );
this->setUiName( fi.baseName() );
this->searchForFileAndFolderNames();
} }
} }
@ -189,6 +195,19 @@ void RimPlotTemplateFolderItem::defineEditorAttribute( const caf::PdmFieldHandle
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
if ( !m_folderName().path().isEmpty() )
{
uiOrdering.add( &m_folderName );
}
uiOrdering.skipRemainingFields( true );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -209,11 +228,15 @@ void RimPlotTemplateFolderItem::appendOptionItemsForPlotTemplatesRecursively( QL
} }
caf::IconProvider templateIcon( ":/SummaryTemplate16x16.png" ); caf::IconProvider templateIcon( ":/SummaryTemplate16x16.png" );
caf::IconProvider ensTemplateIcon( ":/SummaryEnsembleTemplate16x16.png" );
auto files = templateFolderItem->fileNames(); auto files = templateFolderItem->fileNames();
for ( auto file : files ) for ( auto file : files )
{ {
caf::PdmOptionItemInfo optionInfo( file->uiName(), file, false, templateIcon ); caf::IconProvider icon = templateIcon;
if ( file->isEnsembleTemplate() ) icon = ensTemplateIcon;
caf::PdmOptionItemInfo optionInfo( file->uiName(), file, false, icon );
optionInfo.setLevel( menuLevel ); optionInfo.setLevel( menuLevel );
@ -224,22 +247,14 @@ void RimPlotTemplateFolderItem::appendOptionItemsForPlotTemplatesRecursively( QL
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::createSubFolderItemsFromFolderPaths( const QStringList& folderPaths ) void RimPlotTemplateFolderItem::createSubFolderItemsFromFolderPaths( const QStringList& folderPaths, int levelsLeft )
{ {
for ( const auto& path : folderPaths ) for ( const auto& path : folderPaths )
{ {
RimPlotTemplateFolderItem* scriptLocation = new RimPlotTemplateFolderItem(); RimPlotTemplateFolderItem* templateLocation = new RimPlotTemplateFolderItem();
scriptLocation->setFolderPath( path ); templateLocation->setFolderPath( path );
scriptLocation->searchForFileAndFolderNames(); templateLocation->searchForFileAndFolderNames( levelsLeft );
m_subFolders.push_back( scriptLocation ); m_subFolders.push_back( templateLocation );
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFolderItem::searchSubFoldersRecursively() const
{
return RiaPreferences::current()->searchPlotTemplateFoldersRecursively();
}

View File

@ -48,18 +48,17 @@ public:
static void appendOptionItemsForPlotTemplates( QList<caf::PdmOptionItemInfo>& options, static void appendOptionItemsForPlotTemplates( QList<caf::PdmOptionItemInfo>& options,
RimPlotTemplateFolderItem* templateFolderItem ); RimPlotTemplateFolderItem* templateFolderItem );
void updateIconState() const;
private: private:
void searchForFileAndFolderNames(); void searchForFileAndFolderNames( int levelsLeft );
void setFolderPath( const QString& path ); void setFolderPath( const QString& path );
void createSubFolderItemsFromFolderPaths( const QStringList& folderPaths ); void createSubFolderItemsFromFolderPaths( const QStringList& folderPaths, int levelsLeft );
bool searchSubFoldersRecursively() const;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field, void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName, QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override; caf::PdmUiEditorAttribute* attribute ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
static void appendOptionItemsForPlotTemplatesRecursively( QList<caf::PdmOptionItemInfo>& options, static void appendOptionItemsForPlotTemplatesRecursively( QList<caf::PdmOptionItemInfo>& options,
RimPlotTemplateFolderItem* templateFolderItem, RimPlotTemplateFolderItem* templateFolderItem,

View File

@ -1024,6 +1024,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if ( dynamic_cast<RimPlotTemplateFolderItem*>( firstUiItem ) || else if ( dynamic_cast<RimPlotTemplateFolderItem*>( firstUiItem ) ||
dynamic_cast<RimPlotTemplateFileItem*>( firstUiItem ) ) dynamic_cast<RimPlotTemplateFileItem*>( firstUiItem ) )
{ {
menuBuilder << "RicCreateNewPlotFromTemplateFeature";
menuBuilder << "Separator";
menuBuilder << "RicRenamePlotTemplateFeature"; menuBuilder << "RicRenamePlotTemplateFeature";
menuBuilder << "RicDeletePlotTemplateFeature"; menuBuilder << "RicDeletePlotTemplateFeature";
menuBuilder << "RicEditPlotTemplateFeature"; menuBuilder << "RicEditPlotTemplateFeature";