#8761 Multiplot template support

This commit is contained in:
Magne Sjaastad 2022-04-01 14:04:46 +02:00 committed by GitHub
parent b822996fc3
commit 46a8bd58b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 970 additions and 4 deletions

View File

@ -6,6 +6,9 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromTemplateByShortcutFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSaveMultiPlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSaveMultiPlotTemplateFeatureSettings.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateMultiPlotFromSelectionFeature.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -16,6 +19,9 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromTemplateByShortcutFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSaveMultiPlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSaveMultiPlotTemplateFeatureSettings.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateMultiPlotFromSelectionFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,129 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicCreateMultiPlotFromSelectionFeature.h"
#include "RiaGuiApplication.h"
#include "RiaSummaryTools.h"
#include "RicSummaryPlotTemplateTools.h"
#include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimSummaryAddressCollection.h"
#include "RimSummaryCase.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
#include "RiuPlotMainWindow.h"
#include "RiuPlotMainWindowTools.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicCreateMultiPlotFromSelectionFeature, "RicCreateMultiPlotFromSelectionFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCreateMultiPlotFromSelectionFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateMultiPlotFromSelectionFeature::onActionTriggered( bool isChecked )
{
QString fileName = RicSummaryPlotTemplateTools::selectPlotTemplatePath();
auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
auto summaryAddressCollections = RicSummaryPlotTemplateTools::selectedSummaryAddressCollections();
std::vector<QString> wellNames;
std::vector<QString> wellGroupNames;
std::vector<QString> regions;
std::set<RimSummaryCase*> caseSet;
std::set<RimSummaryCaseCollection*> caseCollectionSet;
for ( auto a : summaryAddressCollections )
{
if ( a->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL )
{
wellNames.push_back( a->name() );
}
else if ( a->contentType() == RimSummaryAddressCollection::CollectionContentType::WELL_GROUP )
{
wellGroupNames.push_back( a->name() );
}
else if ( a->contentType() == RimSummaryAddressCollection::CollectionContentType::REGION )
{
regions.push_back( a->name() );
}
auto sumCase = RiaSummaryTools::summaryCaseById( a->caseId() );
if ( sumCase ) caseSet.insert( sumCase );
auto ensemble = RiaSummaryTools::ensembleById( a->ensembleId() );
if ( ensemble ) caseCollectionSet.insert( ensemble );
}
for ( auto sumCase : caseSet )
{
sumCases.push_back( sumCase );
}
for ( auto sumCaseCollection : caseCollectionSet )
{
sumCaseCollections.push_back( sumCaseCollection );
}
auto proj = RimProject::current();
auto collections = proj->mainPlotCollection()->summaryMultiPlotCollection();
auto newSummaryPlot = RicSummaryPlotTemplateTools::createMultiPlotFromTemplateFile( fileName );
if ( !newSummaryPlot ) return;
collections->addSummaryMultiPlot( newSummaryPlot );
newSummaryPlot->resolveReferencesRecursively();
RicSummaryPlotTemplateTools::setValuesForPlaceholders( newSummaryPlot,
sumCases,
sumCaseCollections,
wellNames,
wellGroupNames,
regions );
newSummaryPlot->initAfterReadRecursively();
newSummaryPlot->loadDataAndUpdate();
collections->updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( newSummaryPlot );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateMultiPlotFromSelectionFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Create Summary MultiPlot from Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}

View File

@ -0,0 +1,36 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 RicCreateMultiPlotFromSelectionFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -0,0 +1,294 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSaveMultiPlotTemplateFeature.h"
#include "RicReloadPlotTemplatesFeature.h"
#include "RicSaveMultiPlotTemplateFeatureSettings.h"
#include "RicSummaryPlotTemplateTools.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
#include "RiaSummaryAddressAnalyzer.h"
#include "RiaSummaryTools.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimProject.h"
#include "RimSummaryAddress.h"
#include "RimSummaryCurve.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryPlot.h"
#include "RiuFileDialogTools.h"
#include "cafPdmObject.h"
#include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include "cafUtils.h"
#include <QAction>
#include <QFile>
#include <QFileInfo>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT( RicSaveMultiPlotTemplateFeature, "RicSaveMultiPlotTemplateFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveMultiPlotTemplateFeature::isCommandEnabled()
{
if ( selectedSummaryPlot() ) return true;
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveMultiPlotTemplateFeature::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";
RicSaveMultiPlotTemplateFeatureSettings settings;
settings.setFilePath( startPath );
caf::PdmUiPropertyViewDialog propertyDialog( nullptr, &settings, "Export Plot Template", "" );
if ( propertyDialog.exec() != QDialog::Accepted ) return;
QString fileName = settings.filePath();
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(), settings );
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 RicSaveMultiPlotTemplateFeature::createTextFromObject( RimSummaryMultiPlot* summaryPlot,
const RicSaveMultiPlotTemplateFeatureSettings& settings )
{
if ( !summaryPlot ) return {};
QString objectAsText = summaryPlot->writeObjectToXmlString();
RiaSummaryAddressAnalyzer analyzer;
{
std::vector<RifEclipseSummaryAddress> addresses;
{
std::set<QString> sourceStrings;
const QString summaryFieldKeyword = RicSummaryPlotTemplateTools::summaryCaseFieldKeyword();
for ( const auto& curve : summaryPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ) )
{
auto fieldHandle = curve->findField( summaryFieldKeyword );
if ( fieldHandle )
{
auto reference = fieldHandle->xmlCapability()->referenceString();
sourceStrings.insert( reference );
}
addresses.push_back( curve->summaryAddressY() );
}
replaceStrings( sourceStrings,
summaryFieldKeyword,
RicSummaryPlotTemplateTools::placeholderTextForSummaryCase(),
objectAsText );
}
{
std::set<QString> ensembleReferenceStrings;
const QString summaryGroupFieldKeyword = RicSummaryPlotTemplateTools::summaryGroupFieldKeyword();
for ( const auto& curveSet : summaryPlot->curveSets() )
{
auto fieldHandle = curveSet->findField( summaryGroupFieldKeyword );
if ( fieldHandle )
{
auto reference = fieldHandle->xmlCapability()->referenceString();
ensembleReferenceStrings.insert( reference );
}
addresses.push_back( curveSet->summaryAddress() );
}
replaceStrings( ensembleReferenceStrings,
summaryGroupFieldKeyword,
RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup(),
objectAsText );
}
analyzer.appendAddresses( addresses );
}
RimSummaryAddress dummy;
if ( settings.usePlacholderForWells() )
{
std::set<QString> sourceStrings;
for ( const auto& wellName : analyzer.wellNames() )
{
sourceStrings.insert( QString::fromStdString( wellName ) );
}
replaceStrings( sourceStrings,
dummy.keywordForCategory( RifEclipseSummaryAddress::SUMMARY_WELL ),
RicSummaryPlotTemplateTools::placeholderTextForWell(),
objectAsText );
}
if ( settings.usePlacholderForWellGroups() )
{
std::set<QString> sourceStrings;
for ( const auto& wellGroupName : analyzer.wellGroupNames() )
{
sourceStrings.insert( QString::fromStdString( wellGroupName ) );
}
replaceStrings( sourceStrings,
dummy.keywordForCategory( RifEclipseSummaryAddress::SUMMARY_WELL_GROUP ),
RicSummaryPlotTemplateTools::placeholderTextForWellGroup(),
objectAsText );
}
if ( settings.usePlacholderForRegions() )
{
std::vector<int> regionNumbers;
for ( auto regNumber : analyzer.regionNumbers() )
{
regionNumbers.push_back( regNumber );
}
for ( int i = 0; i < static_cast<int>( regionNumbers.size() ); i++ )
{
// Encode placeholder index. Use negative values below -1 to represent a placeholder index
int index = -( i + 2 );
QString fieldKeyword = dummy.keywordForCategory( RifEclipseSummaryAddress::SUMMARY_REGION );
QString sourceString = QString( "<%1>%2</%1>" ).arg( fieldKeyword ).arg( regionNumbers[i] );
QString replacementTextWithIndex = QString( "<%1>%2</%1>" ).arg( fieldKeyword ).arg( index );
objectAsText.replace( sourceString, replacementTextWithIndex );
}
}
return objectAsText;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveMultiPlotTemplateFeature::replaceStrings( const std::set<QString>& sourceStrings,
const QString& fieldKeyword,
const QString& placeholderText,
QString& objectAsText )
{
size_t index = 0;
for ( const auto& sourceString : sourceStrings )
{
QString sourceTextWithTags = QString( "<%1>%2</%1>" ).arg( fieldKeyword ).arg( sourceString );
QString replacementTextWithIndex =
QString( "<%1>%2 %3</%1>" ).arg( fieldKeyword ).arg( placeholderText ).arg( index++ );
objectAsText.replace( sourceTextWithTags, replacementTextWithIndex );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveMultiPlotTemplateFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Save As Plot Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryMultiPlot* RicSaveMultiPlotTemplateFeature::selectedSummaryPlot() const
{
return dynamic_cast<RimSummaryMultiPlot*>( caf::SelectionManager::instance()->selectedItem() );
}

View File

@ -0,0 +1,51 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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"
#include <set>
class RimSummaryMultiPlot;
class RicSaveMultiPlotTemplateFeatureSettings;
//==================================================================================================
///
//==================================================================================================
class RicSaveMultiPlotTemplateFeature : 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( RimSummaryMultiPlot* summaryPlot,
const RicSaveMultiPlotTemplateFeatureSettings& settings );
static void replaceStrings( const std::set<QString>& sourceStrings,
const QString& fieldKeyword,
const QString& placeholderText,
QString& objectAsText );
private:
RimSummaryMultiPlot* selectedSummaryPlot() const;
};

View File

@ -0,0 +1,108 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSaveMultiPlotTemplateFeatureSettings.h"
#include "cafPdmUiFilePathEditor.h"
CAF_PDM_SOURCE_INIT( RicSaveMultiPlotTemplateFeatureSettings, "RicSaveMultiPlotTemplateFeatureSettings" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSaveMultiPlotTemplateFeatureSettings::RicSaveMultiPlotTemplateFeatureSettings()
{
CAF_PDM_InitObject( "Save Summary Plot", ":/CrossSection16x16.png" );
CAF_PDM_InitFieldNoDefault( &m_filePath, "FilePath", "File Path" );
CAF_PDM_InitField( &m_replaceWells, "ReplaceWells", true, "Wells" );
CAF_PDM_InitField( &m_replaceWellGroups, "ReplaceWellGroups", true, "Well Groups" );
CAF_PDM_InitField( &m_replaceRegions, "ReplaceRegions", true, "Regions" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveMultiPlotTemplateFeatureSettings::setFilePath( const QString& filePath )
{
m_filePath = filePath;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSaveMultiPlotTemplateFeatureSettings::filePath() const
{
return m_filePath().path();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveMultiPlotTemplateFeatureSettings::usePlacholderForWells() const
{
return m_replaceWells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveMultiPlotTemplateFeatureSettings::usePlacholderForWellGroups() const
{
return m_replaceWellGroups;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSaveMultiPlotTemplateFeatureSettings::usePlacholderForRegions() const
{
return m_replaceRegions;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveMultiPlotTemplateFeatureSettings::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
uiOrdering.add( &m_filePath );
{
auto group = uiOrdering.addNewGroup( "Use Placeholders for Objects" );
group->add( &m_replaceWells );
group->add( &m_replaceWellGroups );
group->add( &m_replaceRegions );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSaveMultiPlotTemplateFeatureSettings::defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute )
{
if ( field == &m_filePath )
{
auto attr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>( attribute );
if ( attr )
{
attr->m_selectSaveFileName = true;
attr->m_fileSelectionFilter = "Plot Template Files(*.rpt);; All files(*.*)";
}
}
}

View File

@ -0,0 +1,53 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafFilePath.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
//==================================================================================================
///
//==================================================================================================
class RicSaveMultiPlotTemplateFeatureSettings : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RicSaveMultiPlotTemplateFeatureSettings();
void setFilePath( const QString& filePath );
QString filePath() const;
bool usePlacholderForWells() const;
bool usePlacholderForWellGroups() const;
bool usePlacholderForRegions() const;
private:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
private:
caf::PdmField<caf::FilePath> m_filePath;
caf::PdmField<bool> m_replaceWells;
caf::PdmField<bool> m_replaceWellGroups;
caf::PdmField<bool> m_replaceRegions;
};

View File

@ -33,8 +33,10 @@
#include "RimEnsembleCurveSetCollection.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimSummaryAddressCollection.h"
#include "RimSummaryCase.h"
#include "RimSummaryCurve.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
@ -46,6 +48,132 @@
#include <QFile>
#include <QRegularExpression>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryMultiPlot* RicSummaryPlotTemplateTools::createMultiPlotFromTemplateFile( 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 );
return dynamic_cast<RimSummaryMultiPlot*>( obj );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryMultiPlot* summaryMultiPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles,
const std::vector<QString>& wellNames,
const std::vector<QString>& wellGroupNames,
const std::vector<QString>& regions )
{
// Assumes this plot is inserted into the project. This is required when assigning the ptrFields
RimProject* proj = nullptr;
summaryMultiPlot->firstAncestorOfType( proj );
CAF_ASSERT( proj );
auto plots = summaryMultiPlot->plots();
for ( auto p : plots )
{
auto summaryPlot = dynamic_cast<RimSummaryPlot*>( p );
if ( summaryPlot )
setValuesForPlaceholders( summaryPlot, selectedSummaryCases, selectedEnsembles, wellNames, wellGroupNames, regions );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryPlot* summaryPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles,
const std::vector<QString>& wellNames,
const std::vector<QString>& wellGroupNames,
const std::vector<QString>& regions )
{
// Assumes this plot is inserted into the project. This is required when assigning the ptrFields
RimProject* proj = nullptr;
summaryPlot->firstAncestorOfType( proj );
CAF_ASSERT( proj );
{
// Replace single summary curves data sources
auto summaryCurves = summaryPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS );
for ( const auto& curve : summaryCurves )
{
auto fieldHandle = curve->findField( RicSummaryPlotTemplateTools::summaryCaseFieldKeyword() );
if ( fieldHandle )
{
bool conversionOk = false;
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase();
auto referenceString = fieldHandle->xmlCapability()->referenceString();
int indexValue =
RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk );
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( selectedSummaryCases.size() ) )
{
auto summaryCaseY = selectedSummaryCases[static_cast<int>( indexValue )];
curve->setSummaryCaseY( summaryCaseY );
}
}
// Replace placeholders with object names from selection
auto curveAdr = curve->summaryAddressY();
setPlaceholderWellName( &curveAdr, wellNames );
setPlaceholderWellGroupName( &curveAdr, wellGroupNames );
setPlaceholderRegion( &curveAdr, regions );
curve->setSummaryAddressY( curveAdr );
}
for ( const auto& curveSet : summaryPlot->curveSets() )
{
const QString summaryGroupFieldKeyword = RicSummaryPlotTemplateTools::summaryGroupFieldKeyword();
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 );
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( selectedEnsembles.size() ) )
{
auto ensembleCase = selectedEnsembles[static_cast<int>( indexValue )];
curveSet->setSummaryCaseCollection( ensembleCase );
}
}
// Replace placeholders with object names from selection
auto curveAdr = curveSet->summaryAddress();
setPlaceholderWellName( &curveAdr, wellNames );
setPlaceholderWellGroupName( &curveAdr, wellGroupNames );
setPlaceholderRegion( &curveAdr, regions );
curveSet->setSummaryAddress( curveAdr );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -351,7 +479,7 @@ QString RicSummaryPlotTemplateTools::selectPlotTemplatePath()
return fileName;
}
return QString();
return {};
}
//--------------------------------------------------------------------------------------------------
@ -376,6 +504,17 @@ std::vector<RimSummaryCaseCollection*> RicSummaryPlotTemplateTools::selectedSumm
return objects;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryAddressCollection*> RicSummaryPlotTemplateTools::selectedSummaryAddressCollections()
{
std::vector<RimSummaryAddressCollection*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -397,7 +536,7 @@ QString RicSummaryPlotTemplateTools::summaryGroupFieldKeyword()
//--------------------------------------------------------------------------------------------------
QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCase()
{
return "CASE_NAME";
return "__CASE_NAME__";
}
//--------------------------------------------------------------------------------------------------
@ -405,7 +544,23 @@ QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCase()
//--------------------------------------------------------------------------------------------------
QString RicSummaryPlotTemplateTools::placeholderTextForSummaryGroup()
{
return "ENSEMBLE_NAME";
return "__ENSEMBLE_NAME__";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSummaryPlotTemplateTools::placeholderTextForWell()
{
return "__WELL_NAME__";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSummaryPlotTemplateTools::placeholderTextForWellGroup()
{
return "__WELL_GROUP__";
}
//--------------------------------------------------------------------------------------------------
@ -423,7 +578,7 @@ RifEclipseSummaryAddress
}
}
return RifEclipseSummaryAddress();
return {};
}
//--------------------------------------------------------------------------------------------------
@ -461,3 +616,64 @@ int RicSummaryPlotTemplateTools::findValueForKeyword( const QString& keyword, co
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::setPlaceholderWellName( RifEclipseSummaryAddress* summaryAddress,
const std::vector<QString>& wellNames )
{
if ( wellNames.empty() ) return;
auto sourceWellName = QString::fromStdString( summaryAddress->wellName() );
bool conversionOk = false;
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForWell();
int indexValue = RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, sourceWellName, &conversionOk );
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( wellNames.size() ) )
{
summaryAddress->setWellName( wellNames[indexValue].toStdString() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::setPlaceholderWellGroupName( RifEclipseSummaryAddress* summaryAddress,
const std::vector<QString>& wellGroupNames )
{
if ( wellGroupNames.empty() ) return;
auto sourceWellGroupName = QString::fromStdString( summaryAddress->wellGroupName() );
bool conversionOk = false;
const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForWellGroup();
int indexValue =
RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, sourceWellGroupName, &conversionOk );
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( wellGroupNames.size() ) )
{
summaryAddress->setWellGroupName( wellGroupNames[indexValue].toStdString() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::setPlaceholderRegion( RifEclipseSummaryAddress* summaryAddress,
const std::vector<QString>& regions )
{
CAF_ASSERT( summaryAddress );
if ( regions.empty() ) return;
int indexValue = summaryAddress->regionNumber();
if ( indexValue < -1 )
{
indexValue = -( indexValue - 2 );
bool conversionOk = false;
if ( conversionOk && indexValue >= 0 && indexValue < static_cast<int>( regions.size() ) )
{
summaryAddress->setRegion( regions[indexValue].toInt() );
}
}
}

View File

@ -32,6 +32,8 @@ class RimSummaryPlot;
class RimSummaryCase;
class RimSummaryCaseCollection;
class RifEclipseSummaryAddress;
class RimSummaryMultiPlot;
class RimSummaryAddressCollection;
//==================================================================================================
///
@ -39,6 +41,22 @@ class RifEclipseSummaryAddress;
class RicSummaryPlotTemplateTools
{
public:
static RimSummaryMultiPlot* createMultiPlotFromTemplateFile( const QString& fileName );
static void setValuesForPlaceholders( RimSummaryMultiPlot* summaryMultiPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles,
const std::vector<QString>& wellNames,
const std::vector<QString>& wellGroupNames,
const std::vector<QString>& regions );
static void setValuesForPlaceholders( RimSummaryPlot* summaryPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles,
const std::vector<QString>& wellNames,
const std::vector<QString>& wellGroupNames,
const std::vector<QString>& regions );
static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName );
static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
@ -55,14 +73,24 @@ public:
static std::vector<RimSummaryCase*> selectedSummaryCases();
static std::vector<RimSummaryCaseCollection*> selectedSummaryCaseCollections();
static std::vector<RimSummaryAddressCollection*> selectedSummaryAddressCollections();
static QString summaryCaseFieldKeyword();
static QString summaryGroupFieldKeyword();
static QString placeholderTextForSummaryCase();
static QString placeholderTextForSummaryGroup();
static QString placeholderTextForWell();
static QString placeholderTextForWellGroup();
private:
static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress,
const std::set<RifEclipseSummaryAddress>& allAddresses );
static int findValueForKeyword( const QString& keyword, const QString& valueString, bool* ok );
static void setPlaceholderWellName( RifEclipseSummaryAddress* summaryAddress, const std::vector<QString>& wellNames );
static void setPlaceholderWellGroupName( RifEclipseSummaryAddress* summaryAddress,
const std::vector<QString>& wellGroupNames );
static void setPlaceholderRegion( RifEclipseSummaryAddress* summaryAddress, const std::vector<QString>& regions );
};

View File

@ -119,6 +119,7 @@
#include "RimStimPlanModelTemplateCollection.h"
#include "RimStreamlineInViewCollection.h"
#include "RimSummaryAddress.h"
#include "RimSummaryAddressCollection.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"
@ -1036,6 +1037,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicNewDefaultSummaryPlotFeature";
menuBuilder << "Separator";
menuBuilder << "RicSnapshotViewToPdfFeature";
menuBuilder << "RicSaveMultiPlotTemplateFeature";
}
else if ( dynamic_cast<RimMultiPlot*>( firstUiItem ) )
{
@ -1045,6 +1047,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
{
menuBuilder << "RicNewStreamlineFeature";
}
else if ( dynamic_cast<RimSummaryAddressCollection*>( firstUiItem ) )
{
menuBuilder << "RicCreateMultiPlotFromSelectionFeature";
}
if ( dynamic_cast<Rim3dView*>( firstUiItem ) )
{

View File

@ -20,6 +20,7 @@
#include "RiaPreferences.h"
#include "RiaPreferencesSummary.h"
#include "RiaVersionInfo.h"
#include "RimPlot.h"
#include "RimProject.h"
@ -47,6 +48,9 @@ RimMultiPlot::RimMultiPlot()
{
CAF_PDM_InitObject( "Multi Plot", ":/MultiPlot16x16.png" );
CAF_PDM_InitFieldNoDefault( &m_projectFileVersionString, "ProjectFileVersionString", "" );
m_projectFileVersionString.uiCapability()->setUiHidden( true );
CAF_PDM_InitField( &m_showPlotWindowTitle, "ShowTitleInPlot", true, "Show Title" );
CAF_PDM_InitField( &m_plotWindowTitle, "PlotDescription", QString( "" ), "Name" );
@ -131,6 +135,14 @@ QString RimMultiPlot::description() const
return multiPlotTitle();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimMultiPlot::projectFileVersionString() const
{
return m_projectFileVersionString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -863,6 +875,14 @@ void RimMultiPlot::cleanupBeforeClose()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimMultiPlot::setupBeforeSave()
{
m_projectFileVersionString = STRPRODUCTVER;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -58,6 +58,7 @@ public:
QWidget* viewWidget() override;
QString description() const override;
QString projectFileVersionString() const;
bool isMultiPlotTitleVisible() const;
void setMultiPlotTitleVisible( bool visible );
@ -135,6 +136,7 @@ protected:
private:
void cleanupBeforeClose();
void setupBeforeSave() override;
void doUpdateLayout() override;
void updateSubPlotNames();
void doRenderWindowContent( QPaintDevice* paintDevice ) override;
@ -146,6 +148,7 @@ private:
static void setTickmarkCount( RimPlot* plot, RimPlotAxisPropertiesInterface::LegendTickmarkCountEnum tickmarkCount );
protected:
caf::PdmField<QString> m_projectFileVersionString;
caf::PdmField<bool> m_showPlotWindowTitle;
caf::PdmField<QString> m_plotWindowTitle;
caf::PdmField<ColumnCountEnum> m_columnCount;

View File

@ -198,6 +198,20 @@ RiaDefines::PhaseType RimSummaryAddress::addressPhaseType() const
return RiaDefines::PhaseType::PHASE_NOT_APPLICABLE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimSummaryAddress::keywordForCategory( RifEclipseSummaryAddress::SummaryVarCategory category ) const
{
// Return the keyword text for supported field replacement in plot templates
if ( category == RifEclipseSummaryAddress::SUMMARY_WELL ) return m_wellName.keyword();
if ( category == RifEclipseSummaryAddress::SUMMARY_WELL_GROUP ) return m_wellGroupName.keyword();
if ( category == RifEclipseSummaryAddress::SUMMARY_REGION ) return m_regionNumber.keyword();
return {};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -63,6 +63,8 @@ public:
RiaDefines::PhaseType addressPhaseType() const;
QString keywordForCategory( RifEclipseSummaryAddress::SummaryVarCategory category ) const;
protected:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;