mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Default summaryplot improvements (#8950)
* Add summary default plot type selection in preferences * Create plots as set in preferences when loading summary cases. Allow selecting default plot templates from templates explorer tree * Do not create plot if data vector setting is empty
This commit is contained in:
@@ -9,6 +9,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicRenamePlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -22,6 +23,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicRenamePlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicEditPlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicDeletePlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSetAsDefaultTemplateFeature.cpp
|
||||
)
|
||||
|
||||
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
||||
@@ -36,7 +36,7 @@ void RicReloadPlotTemplatesFeature::rebuildFromDisc()
|
||||
RiaPreferences* prefs = RiaPreferences::current();
|
||||
|
||||
proj->setPlotTemplateFolders( prefs->plotTemplateFolders() );
|
||||
proj->rootPlotTemlateItem()->updateConnectedEditors();
|
||||
proj->rootPlotTemplateItem()->updateConnectedEditors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -36,6 +36,7 @@ CAF_PDM_SOURCE_INIT( RicSelectPlotTemplateUi, "RicSelectPlotTemplateUi" );
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicSelectPlotTemplateUi::RicSelectPlotTemplateUi()
|
||||
: m_useMultiSelect( false )
|
||||
{
|
||||
CAF_PDM_InitObject( "RicSelectPlotTemplateUi" );
|
||||
|
||||
@@ -44,6 +45,21 @@ RicSelectPlotTemplateUi::RicSelectPlotTemplateUi()
|
||||
m_selectedPlotTemplates.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSelectPlotTemplateUi::setMultiSelectMode( bool multiSelect )
|
||||
{
|
||||
m_useMultiSelect = multiSelect;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSelectPlotTemplateUi::setInitialSelection( std::vector<QString> selectedTemplates )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -72,7 +88,7 @@ QList<caf::PdmOptionItemInfo>
|
||||
|
||||
if ( fieldNeedingOptions == &m_selectedPlotTemplates )
|
||||
{
|
||||
auto plotTemplateRoot = RimProject::current()->rootPlotTemlateItem();
|
||||
auto plotTemplateRoot = RimProject::current()->rootPlotTemplateItem();
|
||||
|
||||
RimPlotTemplateFolderItem::appendOptionItemsForPlotTemplates( options, plotTemplateRoot );
|
||||
}
|
||||
@@ -92,7 +108,7 @@ void RicSelectPlotTemplateUi::defineEditorAttribute( const caf::PdmFieldHandle*
|
||||
auto a = dynamic_cast<caf::PdmUiTreeSelectionEditorAttribute*>( attribute );
|
||||
if ( a )
|
||||
{
|
||||
a->singleSelectionMode = true;
|
||||
a->singleSelectionMode = !m_useMultiSelect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmPtrArrayField.h"
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
class RimPlotTemplateFileItem;
|
||||
class RimPlotTemplateFolderItem;
|
||||
|
||||
@@ -35,6 +38,9 @@ class RicSelectPlotTemplateUi : public caf::PdmObject
|
||||
public:
|
||||
RicSelectPlotTemplateUi();
|
||||
|
||||
void setMultiSelectMode( bool multiSelect );
|
||||
void setInitialSelection( std::vector<QString> selectedTemplates );
|
||||
|
||||
std::vector<RimPlotTemplateFileItem*> selectedPlotTemplates();
|
||||
|
||||
private:
|
||||
@@ -47,4 +53,5 @@ private:
|
||||
|
||||
private:
|
||||
caf::PdmPtrArrayField<RimPlotTemplateFileItem*> m_selectedPlotTemplates;
|
||||
bool m_useMultiSelect;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RicSetAsDefaultTemplateFeature.h"
|
||||
|
||||
#include "PlotTemplates/RimPlotTemplateFileItem.h"
|
||||
|
||||
#include "RiaPreferencesSummary.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicSetAsDefaultTemplateFeature, "RicSetAsDefaultTemplateFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicSetAsDefaultTemplateFeature::isCommandEnabled()
|
||||
{
|
||||
return selectedTemplate() != nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSetAsDefaultTemplateFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RimPlotTemplateFileItem* file = selectedTemplate();
|
||||
if ( file == nullptr ) return;
|
||||
|
||||
if ( isChecked )
|
||||
RiaPreferencesSummary::current()->addToDefaultPlotTemplates( file->absoluteFilePath() );
|
||||
else
|
||||
RiaPreferencesSummary::current()->removeFromDefaultPlotTemplates( file->absoluteFilePath() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSetAsDefaultTemplateFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setText( "Default Template" );
|
||||
// actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
|
||||
|
||||
RimPlotTemplateFileItem* file = selectedTemplate();
|
||||
if ( file != nullptr )
|
||||
{
|
||||
actionToSetup->setCheckable( true );
|
||||
actionToSetup->setChecked(
|
||||
RiaPreferencesSummary::current()->isDefaultSummaryPlotTemplate( file->absoluteFilePath() ) );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimPlotTemplateFileItem* RicSetAsDefaultTemplateFeature::selectedTemplate()
|
||||
{
|
||||
std::vector<caf::PdmUiItem*> uiItems;
|
||||
caf::SelectionManager::instance()->selectedItems( uiItems );
|
||||
if ( uiItems.size() != 1 ) return nullptr;
|
||||
|
||||
RimPlotTemplateFileItem* file = dynamic_cast<RimPlotTemplateFileItem*>( uiItems[0] );
|
||||
return file;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 RimPlotTemplateFileItem;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicSetAsDefaultTemplateFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
private:
|
||||
RimPlotTemplateFileItem* selectedTemplate();
|
||||
};
|
||||
@@ -175,6 +175,60 @@ RimSummaryMultiPlot* RicSummaryPlotTemplateTools::create( const QString& fileNam
|
||||
return newSummaryPlot;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryMultiPlot* RicSummaryPlotTemplateTools::create( const QString& fileName,
|
||||
const std::vector<RimSummaryCase*>& sumCases,
|
||||
const std::vector<RimSummaryCaseCollection*>& ensembles )
|
||||
{
|
||||
std::vector<QString> wellNames;
|
||||
std::vector<QString> groupNames;
|
||||
std::vector<QString> regions;
|
||||
|
||||
RiaSummaryAddressAnalyzer analyzer;
|
||||
|
||||
if ( !sumCases.empty() )
|
||||
{
|
||||
auto firstCase = sumCases.front();
|
||||
|
||||
analyzer.appendAddresses( firstCase->summaryReader()->allResultAddresses() );
|
||||
}
|
||||
else if ( !ensembles.empty() )
|
||||
{
|
||||
auto caseCollection = ensembles.front();
|
||||
|
||||
auto firstCase = caseCollection->firstSummaryCase();
|
||||
if ( firstCase != nullptr )
|
||||
{
|
||||
analyzer.appendAddresses( firstCase->summaryReader()->allResultAddresses() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !analyzer.wellNames().empty() )
|
||||
wellNames.push_back( QString::fromStdString( *( analyzer.wellNames().begin() ) ) );
|
||||
if ( !analyzer.groupNames().empty() )
|
||||
groupNames.push_back( QString::fromStdString( *( analyzer.groupNames().begin() ) ) );
|
||||
if ( !analyzer.regionNumbers().empty() )
|
||||
regions.push_back( QString::number( *( analyzer.regionNumbers().begin() ) ) );
|
||||
|
||||
auto proj = RimProject::current();
|
||||
auto collections = proj->mainPlotCollection()->summaryMultiPlotCollection();
|
||||
|
||||
auto newSummaryPlot = RicSummaryPlotTemplateTools::createMultiPlotFromTemplateFile( fileName );
|
||||
if ( !newSummaryPlot ) return nullptr;
|
||||
|
||||
collections->addSummaryMultiPlot( newSummaryPlot );
|
||||
newSummaryPlot->resolveReferencesRecursively();
|
||||
|
||||
RicSummaryPlotTemplateTools::setValuesForPlaceholders( newSummaryPlot, sumCases, ensembles, wellNames, groupNames, regions );
|
||||
newSummaryPlot->initAfterReadRecursively();
|
||||
newSummaryPlot->loadDataAndUpdate();
|
||||
collections->updateConnectedEditors();
|
||||
|
||||
return newSummaryPlot;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -399,6 +453,32 @@ QString RicSummaryPlotTemplateTools::selectPlotTemplatePath()
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QString> RicSummaryPlotTemplateTools::selectDefaultPlotTemplates( std::vector<QString> currentSelection )
|
||||
{
|
||||
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
|
||||
RicSelectPlotTemplateUi ui;
|
||||
ui.setMultiSelectMode( true );
|
||||
ui.setInitialSelection( currentSelection );
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, &ui, "Select Default Plot Templates", "" );
|
||||
propertyDialog.resize( QSize( 500, 600 ) );
|
||||
|
||||
std::vector<QString> selection;
|
||||
|
||||
if ( propertyDialog.exec() == QDialog::Accepted && !ui.selectedPlotTemplates().empty() )
|
||||
{
|
||||
for ( auto item : ui.selectedPlotTemplates() )
|
||||
{
|
||||
selection.push_back( item->absoluteFilePath() );
|
||||
}
|
||||
}
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -34,6 +34,7 @@ class RimSummaryCaseCollection;
|
||||
class RifEclipseSummaryAddress;
|
||||
class RimSummaryMultiPlot;
|
||||
class RimSummaryAddressCollection;
|
||||
class RimPlotTemplateFileItem;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -43,7 +44,12 @@ class RicSummaryPlotTemplateTools
|
||||
public:
|
||||
static RimSummaryMultiPlot* create( const QString& fileName );
|
||||
|
||||
static QString selectPlotTemplatePath();
|
||||
static RimSummaryMultiPlot* create( const QString& fileName,
|
||||
const std::vector<RimSummaryCase*>& cases,
|
||||
const std::vector<RimSummaryCaseCollection*>& ensembles );
|
||||
|
||||
static QString selectPlotTemplatePath();
|
||||
static std::vector<QString> selectDefaultPlotTemplates( std::vector<QString> currentSelection );
|
||||
|
||||
static QString summaryCaseFieldKeyword();
|
||||
static QString summaryGroupFieldKeyword();
|
||||
|
||||
Reference in New Issue
Block a user