Merge pull request #4737 from OPM/plot-templates-rc2

#4733 Summary Template : Add reload of templates
This commit is contained in:
Magne Sjaastad 2019-09-20 07:18:55 +02:00 committed by GitHub
commit 4d82a65d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 535 additions and 174 deletions

View File

@ -716,6 +716,22 @@ QStringList RiaPreferences::plotTemplateFolders() const
return filteredFolders; return filteredFolders;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaPreferences::appendPlotTemplateFolders( const QString& folder )
{
QString folders = m_plotTemplateFolders();
if ( !folders.isEmpty() )
{
folders += ";";
}
folders += folder;
m_plotTemplateFolders = folders;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -81,6 +81,7 @@ public:
bool searchPlotTemplateFoldersRecursively() const; bool searchPlotTemplateFoldersRecursively() const;
QStringList plotTemplateFolders() const; QStringList plotTemplateFolders() const;
void appendPlotTemplateFolders( const QString& folder );
std::map<RiaDefines::FontSettingType, RiaFontCache::FontSize> defaultFontSizes() const; std::map<RiaDefines::FontSettingType, RiaFontCache::FontSize> defaultFontSizes() const;

View File

@ -3,12 +3,16 @@ set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.h ${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.h
${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotTemplateTools.h
${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.h
) )
set (SOURCE_GROUP_SOURCE_FILES set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotTemplateTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.cpp
) )
list(APPEND CODE_HEADER_FILES list(APPEND CODE_HEADER_FILES

View File

@ -18,13 +18,15 @@
#include "RicCreatePlotFromSelectionFeature.h" #include "RicCreatePlotFromSelectionFeature.h"
#include "RicSelectPlotTemplateUi.h"
#include "RicSummaryPlotTemplateTools.h"
#include "RiaGuiApplication.h" #include "RiaGuiApplication.h"
#include "RiaLogging.h" #include "RiaLogging.h"
#include "RiaSummaryTools.h" #include "RiaSummaryTools.h"
#include "RicSelectPlotTemplateUi.h"
#include "PlotTemplates/RimPlotTemplateFileItem.h" #include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "RimDialogData.h"
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryCase.h" #include "RimSummaryCase.h"
@ -44,57 +46,39 @@
CAF_CMD_SOURCE_INIT( RicCreatePlotFromSelectionFeature, "RicCreatePlotFromSelectionFeature" ); CAF_CMD_SOURCE_INIT( RicCreatePlotFromSelectionFeature, "RicCreatePlotFromSelectionFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicCreatePlotFromSelectionFeature::RicCreatePlotFromSelectionFeature() {}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicCreatePlotFromSelectionFeature::isCommandEnabled() bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
{ {
if ( selectedSummaryCases().size() == 2 ) return true; return !selectedSummaryCases().empty();
if ( selectedWellPaths().size() == 2 ) return true;
return false;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked ) void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
{
{ {
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow(); RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
RicSelectPlotTemplateUi ui; RicSelectPlotTemplateUi* ui = RiaGuiApplication::instance()->project()->dialogData()->selectPlotTemplateUi();
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, ui, "Select Plot Template", "" );
&ui,
"Select Case to create Pressure Saturation plots",
"" );
if ( propertyDialog.exec() != QDialog::Accepted ) return; if ( propertyDialog.exec() != QDialog::Accepted ) return;
if ( ui.selectedPlotTemplates().empty() ) return; if ( ui->selectedPlotTemplates().empty() ) return;
QString fileName = ui.selectedPlotTemplates().front()->absoluteFilePath(); QString fileName = ui->selectedPlotTemplates().front()->absoluteFilePath();
{ std::vector<RimSummaryCase*> sumCases = selectedSummaryCases();
auto sumCases = selectedSummaryCases();
if ( sumCases.size() == 2 )
{
// QString fileName = "d:/projects/ri-plot-templates/one_well_two_cases.rpt";
RimSummaryPlot* newSummaryPlot = createPlotFromTemplateFile( fileName ); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
if ( newSummaryPlot ) if ( newSummaryPlot )
{ {
RimSummaryPlotCollection* plotColl = RimSummaryPlotCollection* plotColl =
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
plotColl->summaryPlots.push_back( newSummaryPlot ); plotColl->summaryPlots.push_back( newSummaryPlot );
// Resolve references after object has been inserted into the data model
newSummaryPlot->resolveReferencesRecursively(); newSummaryPlot->resolveReferencesRecursively();
newSummaryPlot->initAfterReadRecursively(); newSummaryPlot->initAfterReadRecursively();
@ -102,12 +86,26 @@ void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
newSummaryPlot->setDescription( nameOfCopy ); newSummaryPlot->setDescription( nameOfCopy );
auto summaryCurves = newSummaryPlot->summaryCurves(); auto summaryCurves = newSummaryPlot->summaryCurves();
if ( summaryCurves.size() == sumCases.size() )
for ( const auto& curve : summaryCurves )
{ {
for ( size_t i = 0; i < summaryCurves.size(); i++ ) auto fieldHandle = curve->findField( "SummaryCase" );
if ( fieldHandle )
{ {
auto sumCase = sumCases[i]; auto referenceString = fieldHandle->xmlCapability()->referenceString();
summaryCurves[i]->setSummaryCaseY( sumCase ); auto stringList = referenceString.split( " " );
if ( stringList.size() == 2 )
{
QString indexAsString = stringList[1];
bool conversionOk = false;
int index = indexAsString.toUInt( &conversionOk );
if ( conversionOk && index < sumCases.size() )
{
curve->setSummaryCaseY( sumCases[index] );
}
}
} }
} }
@ -116,46 +114,6 @@ void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
newSummaryPlot->loadDataAndUpdate(); newSummaryPlot->loadDataAndUpdate();
} }
} }
}
{
auto wellPaths = selectedWellPaths();
if ( wellPaths.size() == 2 )
{
// QString fileName = "d:/projects/ri-plot-templates/one_well_two_cases.rpt";
RimSummaryPlot* newSummaryPlot = createPlotFromTemplateFile( fileName );
if ( newSummaryPlot )
{
RimSummaryPlotCollection* plotColl = RiaSummaryTools::summaryPlotCollection();
plotColl->summaryPlots.push_back( newSummaryPlot );
// Resolve references after object has been inserted into the data model
newSummaryPlot->resolveReferencesRecursively();
newSummaryPlot->initAfterReadRecursively();
QString nameOfCopy = QString( "Copy of " ) + newSummaryPlot->description();
newSummaryPlot->setDescription( nameOfCopy );
auto summaryCurves = newSummaryPlot->summaryCurves();
if ( summaryCurves.size() == wellPaths.size() )
{
for ( size_t i = 0; i < summaryCurves.size(); i++ )
{
auto wellPath = wellPaths[i];
summaryCurves[i]->summaryAddressY().setWellName( wellPath->name().toStdString() );
}
}
plotColl->updateConnectedEditors();
newSummaryPlot->loadDataAndUpdate();
}
}
}
}
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -166,38 +124,6 @@ void RicCreatePlotFromSelectionFeature::setupActionLook( QAction* actionToSetup
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicCreatePlotFromSelectionFeature::createPlotFromTemplateFile( const QString& fileName ) const
{
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() );
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot )
{
return newSummaryPlot;
}
else
{
delete obj;
}
return nullptr;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -208,14 +134,3 @@ std::vector<RimSummaryCase*> RicCreatePlotFromSelectionFeature::selectedSummaryC
return objects; return objects;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RicCreatePlotFromSelectionFeature::selectedWellPaths() const
{
std::vector<RimWellPath*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}

View File

@ -21,8 +21,6 @@
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
class RimSummaryCase; class RimSummaryCase;
class RimSummaryPlot;
class RimWellPath;
//================================================================================================== //==================================================================================================
/// ///
@ -31,18 +29,11 @@ class RicCreatePlotFromSelectionFeature : public caf::CmdFeature
{ {
CAF_CMD_HEADER_INIT; CAF_CMD_HEADER_INIT;
public:
RicCreatePlotFromSelectionFeature();
protected: protected:
bool isCommandEnabled() override; bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
private:
RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName ) const;
private: private:
std::vector<RimSummaryCase*> selectedSummaryCases() const; std::vector<RimSummaryCase*> selectedSummaryCases() const;
std::vector<RimWellPath*> selectedWellPaths() const;
}; };

View File

@ -0,0 +1,66 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicReloadPlotTemplatesFeature.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "PlotTemplates/RimPlotTemplateFolderItem.h"
#include "RimProject.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicReloadPlotTemplatesFeature, "RicReloadPlotTemplatesFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadPlotTemplatesFeature::rebuildFromDisc()
{
RimProject* proj = RiaApplication::instance()->project();
RiaPreferences* prefs = RiaApplication::instance()->preferences();
proj->setPlotTemplateFolders( prefs->plotTemplateFolders() );
proj->rootPlotTemlateItem()->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicReloadPlotTemplatesFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadPlotTemplatesFeature::onActionTriggered( bool isChecked )
{
RicReloadPlotTemplatesFeature::rebuildFromDisc();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadPlotTemplatesFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Reload Templates" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}

View File

@ -0,0 +1,39 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
class RimSummaryPlot;
//==================================================================================================
///
//==================================================================================================
class RicReloadPlotTemplatesFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static void rebuildFromDisc();
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -16,28 +16,29 @@
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaSummaryTools.h"
#include "RicSavePlotTemplateFeature.h" #include "RicSavePlotTemplateFeature.h"
#include "RicReloadPlotTemplatesFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
#include "RiaSummaryTools.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h" #include "RimSummaryPlot.h"
#include "cafPdmObject.h" #include "cafPdmObject.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
#include "cafUtils.h"
#include <QAction> #include <QAction>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox>
CAF_CMD_SOURCE_INIT( RicSavePlotTemplateFeature, "RicSavePlotTemplateFeature" ); CAF_CMD_SOURCE_INIT( RicSavePlotTemplateFeature, "RicSavePlotTemplateFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSavePlotTemplateFeature::RicSavePlotTemplateFeature() {}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -53,28 +54,30 @@ bool RicSavePlotTemplateFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked ) void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked )
{ {
if ( !selectedSummaryPlot() ) return;
RiaGuiApplication* app = RiaGuiApplication::instance(); RiaGuiApplication* app = RiaGuiApplication::instance();
QString startPath; QString fallbackPath;
if ( !app->project()->fileName().isEmpty() ) auto folders = app->preferences()->plotTemplateFolders();
if ( !folders.empty() )
{ {
startPath = app->project()->fileName(); // Use the last folder from preferences as the default fall back folder
startPath = startPath.replace( QString( ".rsp" ), QString( ".rpt" ) ); fallbackPath = folders.back();
}
else
{
startPath = app->lastUsedDialogDirectory( "PLOT_TEMPLATE" );
startPath += "/ri-plot-template.rpt";
} }
QString startPath = app->lastUsedDialogDirectoryWithFallback( "PLOT_TEMPLATE", fallbackPath );
QString templateCandidateName = caf::Utils::makeValidFileBasename( selectedSummaryPlot()->description() );
startPath = startPath + "/" + templateCandidateName + ".rpt";
QString fileName = QFileDialog::getSaveFileName( nullptr, QString fileName = QFileDialog::getSaveFileName( nullptr,
tr( "Save Plot Template To File" ), tr( "Save Plot Template To File" ),
startPath, startPath,
tr( "Plot Template Files (*.rpt);;All files(*.*)" ) ); tr( "Plot Template Files (*.rpt);;All files(*.*)" ) );
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
{ {
auto objectAsText = selectedSummaryPlot()->writeObjectToXmlString();
QFile exportFile( fileName ); QFile exportFile( fileName );
if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
{ {
@ -82,11 +85,87 @@ void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked )
return; return;
} }
QString objectAsText = createTextFromObject( selectedSummaryPlot() );
QTextStream stream( &exportFile ); QTextStream stream( &exportFile );
stream << objectAsText; 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->setLastUsedDialogDirectory( "PLOT_TEMPLATE", absPath );
RicReloadPlotTemplatesFeature::rebuildFromDisc();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summaryPlot )
{
if ( !summaryPlot ) return QString();
QString objectAsText = summaryPlot->writeObjectToXmlString();
caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText, caf::PdmDefaultObjectFactory::instance() );
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot )
{
std::set<QString> caseReferenceStrings;
for ( const auto& curve : newSummaryPlot->summaryCurves() )
{
auto fieldHandle = curve->findField( "SummaryCase" );
if ( fieldHandle )
{
auto reference = fieldHandle->xmlCapability()->referenceString();
caseReferenceStrings.insert( reference );
}
}
size_t index = 0;
for ( const auto& s : caseReferenceStrings )
{
QString caseName = QString( "CASE_NAME %1" ).arg( index++ );
objectAsText.replace( s, caseName );
}
}
delete obj;
return objectAsText;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -29,14 +29,14 @@ class RicSavePlotTemplateFeature : public caf::CmdFeature
{ {
CAF_CMD_HEADER_INIT; CAF_CMD_HEADER_INIT;
public:
RicSavePlotTemplateFeature();
protected: protected:
bool isCommandEnabled() override; bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
private:
static QString createTextFromObject( RimSummaryPlot* summaryPlot );
private: private:
RimSummaryPlot* selectedSummaryPlot() const; RimSummaryPlot* selectedSummaryPlot() const;
}; };

View File

@ -78,3 +78,20 @@ QList<caf::PdmOptionItemInfo>
return options; return options;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectPlotTemplateUi::defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute )
{
if ( &m_selectedPlotTemplates == field )
{
auto a = dynamic_cast<caf::PdmUiTreeSelectionEditorAttribute*>( attribute );
if ( a )
{
a->singleSelectionMode = true;
}
}
}

View File

@ -41,6 +41,10 @@ private:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly ) override; bool* useOptionsOnly ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
private: private:
caf::PdmPtrArrayField<RimPlotTemplateFileItem*> m_selectedPlotTemplates; caf::PdmPtrArrayField<RimPlotTemplateFileItem*> m_selectedPlotTemplates;
}; };

View File

@ -0,0 +1,158 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicSummaryPlotTemplateTools.h"
#include "RiaLogging.h"
#include "RiaSummaryCurveAnalyzer.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h"
#include <QFile>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const QString& fileName )
{
QFile importFile( fileName );
if ( !importFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
RiaLogging::error( QString( "Create Plot from Template : Could not open the file: %1" ).arg( fileName ) );
return nullptr;
}
QTextStream stream( &importFile );
QString objectAsText = stream.readAll();
caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( objectAsText, caf::PdmDefaultObjectFactory::instance() );
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot )
{
return newSummaryPlot;
}
delete obj;
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSummaryPlotTemplateTools::htmlTextFromPlotAndSelection(
const RimSummaryPlot* templatePlot,
const std::set<RifEclipseSummaryAddress>& selectedSummaryAddresses,
const std::vector<caf::PdmObject*>& selectedSources )
{
QString text;
RiaSummaryCurveAnalyzer selectionAnalyzer;
selectionAnalyzer.appendAdresses( selectedSummaryAddresses );
if ( templatePlot )
{
std::set<QString> templateSources;
RiaSummaryCurveAnalyzer templateAnalyzer;
{
std::set<RifEclipseSummaryAddress> templateAddresses;
for ( const auto& curve : templatePlot->summaryCurves() )
{
auto adr = curve->summaryAddressY();
templateAddresses.insert( adr );
auto fieldHandle = curve->findField( "SummaryCase" );
if ( fieldHandle )
{
auto test = fieldHandle->xmlCapability()->referenceString();
templateSources.insert( test );
}
}
templateAnalyzer.appendAdresses( templateAddresses );
}
text += "<b> Requirements </b><br>";
if ( !templateSources.empty() )
{
QString itemText = "Source Cases";
size_t requiredCount = templateSources.size();
size_t selectedCount = selectedSources.size();
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
}
if ( !templateAnalyzer.wellNames().empty() )
{
QString itemText = "Wells";
size_t requiredCount = templateAnalyzer.wellNames().size();
size_t selectedCount = selectionAnalyzer.wellNames().size();
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
}
if ( !templateAnalyzer.wellGroupNames().empty() )
{
QString itemText = "Well Groups";
size_t requiredCount = templateAnalyzer.wellGroupNames().size();
size_t selectedCount = selectionAnalyzer.wellGroupNames().size();
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
}
if ( !templateAnalyzer.regionNumbers().empty() )
{
QString itemText = "Regions";
size_t requiredCount = templateAnalyzer.regionNumbers().size();
size_t selectedCount = selectionAnalyzer.regionNumbers().size();
text += htmlTextFromCount( itemText, requiredCount, selectedCount );
}
}
return text;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSummaryPlotTemplateTools::htmlTextFromCount( const QString& itemText,
size_t requiredItemCount,
size_t selectionCount )
{
QString text;
QString colorString = "green";
if ( selectionCount < requiredItemCount )
colorString = "red";
else if ( selectionCount > requiredItemCount )
colorString = "orange";
text += QString( "<b><font color='%1'>" ).arg( colorString );
text += QString( "%1 : %2 selected (%3 required)\n" ).arg( itemText ).arg( selectionCount ).arg( requiredItemCount );
text += "</font></b>";
text += "<br>";
return text;
}

View File

@ -0,0 +1,47 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QString>
#include <set>
#include <vector>
namespace caf
{
class PdmObject;
}
class RimSummaryPlot;
class RimSummaryPlot;
class RifEclipseSummaryAddress;
//==================================================================================================
///
//==================================================================================================
class RicSummaryPlotTemplateTools
{
public:
static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName );
static QString htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot,
const std::set<RifEclipseSummaryAddress>& selectedSummaryAddresses,
const std::vector<caf::PdmObject*>& selectedSources );
static QString htmlTextFromCount( const QString& itemText, size_t requiredItemCount, size_t selectionCount );
};

View File

@ -55,6 +55,9 @@ RimPlotTemplateFolderItem::~RimPlotTemplateFolderItem() {}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::createRootFolderItemsFromFolderPaths( const QStringList& folderPaths ) void RimPlotTemplateFolderItem::createRootFolderItemsFromFolderPaths( const QStringList& folderPaths )
{ {
m_fileNames.deleteAllChildObjects();
m_subFolders.deleteAllChildObjects();
createSubFolderItemsFromFolderPaths( folderPaths ); createSubFolderItemsFromFolderPaths( folderPaths );
} }

View File

@ -21,6 +21,8 @@
#include "RiaApplication.h" #include "RiaApplication.h"
#include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "PlotTemplates/RimPlotTemplateFolderItem.h"
#include "Rim3dOverlayInfoConfig.h" #include "Rim3dOverlayInfoConfig.h"
#include "Rim3dWellLogCurveCollection.h" #include "Rim3dWellLogCurveCollection.h"
#include "Rim3dWellLogExtractionCurve.h" #include "Rim3dWellLogExtractionCurve.h"
@ -43,6 +45,7 @@
#include "RimEclipsePropertyFilterCollection.h" #include "RimEclipsePropertyFilterCollection.h"
#include "RimEclipseStatisticsCase.h" #include "RimEclipseStatisticsCase.h"
#include "RimEclipseView.h" #include "RimEclipseView.h"
#include "RimEllipseFractureTemplate.h"
#include "RimEnsembleCurveFilterCollection.h" #include "RimEnsembleCurveFilterCollection.h"
#include "RimEnsembleCurveSet.h" #include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h" #include "RimEnsembleCurveSetCollection.h"
@ -55,6 +58,8 @@
#include "RimFlowPlotCollection.h" #include "RimFlowPlotCollection.h"
#include "RimFormationNames.h" #include "RimFormationNames.h"
#include "RimFormationNamesCollection.h" #include "RimFormationNamesCollection.h"
#include "RimFractureTemplate.h"
#include "RimFractureTemplateCollection.h"
#include "RimGeoMechCase.h" #include "RimGeoMechCase.h"
#include "RimGeoMechContourMapViewCollection.h" #include "RimGeoMechContourMapViewCollection.h"
#include "RimGeoMechPropertyFilter.h" #include "RimGeoMechPropertyFilter.h"
@ -68,6 +73,7 @@
#include "RimIntersection.h" #include "RimIntersection.h"
#include "RimIntersectionBox.h" #include "RimIntersectionBox.h"
#include "RimIntersectionCollection.h" #include "RimIntersectionCollection.h"
#include "RimModeledWellPath.h"
#include "RimObservedSummaryData.h" #include "RimObservedSummaryData.h"
#include "RimPerforationCollection.h" #include "RimPerforationCollection.h"
#include "RimPerforationInterval.h" #include "RimPerforationInterval.h"
@ -76,8 +82,10 @@
#include "RimRftPlotCollection.h" #include "RimRftPlotCollection.h"
#include "RimSaturationPressurePlotCollection.h" #include "RimSaturationPressurePlotCollection.h"
#include "RimScriptCollection.h" #include "RimScriptCollection.h"
#include "RimSimWellFracture.h"
#include "RimSimWellInView.h" #include "RimSimWellInView.h"
#include "RimSimWellInViewCollection.h" #include "RimSimWellInViewCollection.h"
#include "RimStimPlanFractureTemplate.h"
#include "RimSummaryCase.h" #include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h" #include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h" #include "RimSummaryCaseMainCollection.h"
@ -87,6 +95,8 @@
#include "RimSummaryCurveCollection.h" #include "RimSummaryCurveCollection.h"
#include "RimSummaryPlot.h" #include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h" #include "RimSummaryPlotCollection.h"
#include "RimValveTemplate.h"
#include "RimValveTemplateCollection.h"
#include "RimViewController.h" #include "RimViewController.h"
#include "RimViewLinker.h" #include "RimViewLinker.h"
#include "RimViewLinkerCollection.h" #include "RimViewLinkerCollection.h"
@ -101,21 +111,11 @@
#include "RimWellPathAttributeCollection.h" #include "RimWellPathAttributeCollection.h"
#include "RimWellPathCollection.h" #include "RimWellPathCollection.h"
#include "RimWellPathCompletions.h" #include "RimWellPathCompletions.h"
#include "RimWellPathFracture.h"
#include "RimWellPathFractureCollection.h" #include "RimWellPathFractureCollection.h"
#include "RimWellPltPlot.h" #include "RimWellPltPlot.h"
#include "RimWellRftPlot.h" #include "RimWellRftPlot.h"
#include "RimEllipseFractureTemplate.h"
#include "RimFractureTemplate.h"
#include "RimFractureTemplateCollection.h"
#include "RimModeledWellPath.h"
#include "RimSimWellFracture.h"
#include "RimStimPlanFractureTemplate.h"
#include "RimValveTemplate.h"
#include "RimValveTemplateCollection.h"
#include "RimWellPathFracture.h"
#include "RimWellPathFractureCollection.h"
#include "RiuMainWindow.h" #include "RiuMainWindow.h"
#include "OctaveScriptCommands/RicExecuteScriptForCasesFeature.h" #include "OctaveScriptCommands/RicExecuteScriptForCasesFeature.h"
@ -548,14 +548,12 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicDuplicateSummaryCrossPlotFeature"; menuBuilder << "RicDuplicateSummaryCrossPlotFeature";
menuBuilder << "RicNewSummaryCrossPlotCurveFeature"; menuBuilder << "RicNewSummaryCrossPlotCurveFeature";
menuBuilder << "Separator"; menuBuilder << "Separator";
menuBuilder << "RicShowSummaryCurveCalculatorFeature";
menuBuilder << "Separator";
menuBuilder << "RicSavePlotTemplateFeature"; menuBuilder << "RicSavePlotTemplateFeature";
menuBuilder << "Separator";
// Export is not supported for cross plot // Export is not supported for cross plot
if ( !summaryCrossPlot ) menuBuilder << "RicAsciiExportSummaryPlotFeature"; if ( !summaryCrossPlot ) menuBuilder << "RicAsciiExportSummaryPlotFeature";
menuBuilder << "RicShowSummaryCurveCalculatorFeature";
menuBuilder << "Separator"; menuBuilder << "Separator";
menuBuilder << "RicCopyReferencesToClipboardFeature"; menuBuilder << "RicCopyReferencesToClipboardFeature";
menuBuilder << "Separator"; menuBuilder << "Separator";
@ -792,6 +790,10 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
{ {
menuBuilder << "RicCreateTextAnnotationFeature"; menuBuilder << "RicCreateTextAnnotationFeature";
} }
else if ( dynamic_cast<RimPlotTemplateFolderItem*>( uiItem ) || dynamic_cast<RimPlotTemplateFileItem*>( uiItem ) )
{
menuBuilder << "RicReloadPlotTemplatesFeature";
}
if ( dynamic_cast<Rim3dView*>( uiItem ) ) if ( dynamic_cast<Rim3dView*>( uiItem ) )
{ {
menuBuilder << "Separator"; menuBuilder << "Separator";

View File

@ -27,6 +27,7 @@
#include "ExportCommands/RicExportWellPathsUi.h" #include "ExportCommands/RicExportWellPathsUi.h"
#include "FractureCommands/RicCreateMultipleFracturesUi.h" #include "FractureCommands/RicCreateMultipleFracturesUi.h"
#include "HoloLensCommands/RicHoloLensExportToFolderUi.h" #include "HoloLensCommands/RicHoloLensExportToFolderUi.h"
#include "PlotTemplateCommands/RicSelectPlotTemplateUi.h"
CAF_PDM_SOURCE_INIT( RimDialogData, "RimDialogData" ); CAF_PDM_SOURCE_INIT( RimDialogData, "RimDialogData" );
@ -65,6 +66,9 @@ RimDialogData::RimDialogData()
CAF_PDM_InitFieldNoDefault( &m_mockModelSettings, "MockModelSettings", "Mock Model Settings", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_mockModelSettings, "MockModelSettings", "Mock Model Settings", "", "", "" );
m_mockModelSettings = new RimMockModelSettings(); m_mockModelSettings = new RimMockModelSettings();
CAF_PDM_InitFieldNoDefault( &m_selectPlotTemplateUi, "SelectPlotTemplateUi", "Select Plot Template", "", "", "" );
m_selectPlotTemplateUi = new RicSelectPlotTemplateUi();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -155,3 +159,11 @@ RimMockModelSettings* RimDialogData::mockModelSettings() const
{ {
return m_mockModelSettings; return m_mockModelSettings;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSelectPlotTemplateUi* RimDialogData::selectPlotTemplateUi() const
{
return m_selectPlotTemplateUi;
}

View File

@ -29,6 +29,7 @@ class RicHoloLensExportToFolderUi;
class RicExportWellPathsUi; class RicExportWellPathsUi;
class RicExportLgrUi; class RicExportLgrUi;
class RimMockModelSettings; class RimMockModelSettings;
class RicSelectPlotTemplateUi;
//================================================================================================== //==================================================================================================
/// ///
@ -62,6 +63,8 @@ public:
RicExportEclipseSectorModelUi* exportSectorModelUi() const; RicExportEclipseSectorModelUi* exportSectorModelUi() const;
RimMockModelSettings* mockModelSettings() const; RimMockModelSettings* mockModelSettings() const;
RicSelectPlotTemplateUi* selectPlotTemplateUi() const;
private: private:
caf::PdmChildField<RicExportCarfinUi*> m_exportCarfin; caf::PdmChildField<RicExportCarfinUi*> m_exportCarfin;
caf::PdmChildField<RicExportCompletionDataSettingsUi*> m_exportCompletionData; caf::PdmChildField<RicExportCompletionDataSettingsUi*> m_exportCompletionData;
@ -71,4 +74,5 @@ private:
caf::PdmChildField<RicExportLgrUi*> m_exportLgrData; caf::PdmChildField<RicExportLgrUi*> m_exportLgrData;
caf::PdmChildField<RicExportEclipseSectorModelUi*> m_exportSectorModelData; caf::PdmChildField<RicExportEclipseSectorModelUi*> m_exportSectorModelData;
caf::PdmChildField<RimMockModelSettings*> m_mockModelSettings; caf::PdmChildField<RimMockModelSettings*> m_mockModelSettings;
caf::PdmChildField<RicSelectPlotTemplateUi*> m_selectPlotTemplateUi;
}; };

View File

@ -363,8 +363,10 @@ void RimProject::setScriptDirectories( const QString& scriptDirectories )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimProject::setPlotTemplateFolders( const QStringList& plotTemplateFolders ) void RimProject::setPlotTemplateFolders( const QStringList& plotTemplateFolders )
{ {
if ( m_plotTemplateFolderItem() ) delete m_plotTemplateFolderItem(); if ( !m_plotTemplateFolderItem() )
{
m_plotTemplateFolderItem = new RimPlotTemplateFolderItem(); m_plotTemplateFolderItem = new RimPlotTemplateFolderItem();
}
m_plotTemplateFolderItem->createRootFolderItemsFromFolderPaths( plotTemplateFolders ); m_plotTemplateFolderItem->createRootFolderItemsFromFolderPaths( plotTemplateFolders );
} }

View File

@ -187,6 +187,7 @@ void RiuSummaryQwtPlot::contextMenuEvent( QContextMenuEvent* event )
caf::SelectionManager::instance()->setSelectedItem( ownerViewWindow() ); caf::SelectionManager::instance()->setSelectedItem( ownerViewWindow() );
menuBuilder << "RicShowPlotDataFeature"; menuBuilder << "RicShowPlotDataFeature";
menuBuilder << "RicSavePlotTemplateFeature";
menuBuilder.appendToMenu( &menu ); menuBuilder.appendToMenu( &menu );