mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4733 Summary Template : Add reload of templates
Adjust save and load of templates Add save path to preferences
This commit is contained in:
@@ -3,12 +3,16 @@ set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotTemplateTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSelectPlotTemplateUi.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSummaryPlotTemplateTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicReloadPlotTemplatesFeature.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
|
||||
#include "RicCreatePlotFromSelectionFeature.h"
|
||||
|
||||
#include "RicSelectPlotTemplateUi.h"
|
||||
#include "RicSummaryPlotTemplateTools.h"
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaSummaryTools.h"
|
||||
|
||||
#include "RicSelectPlotTemplateUi.h"
|
||||
|
||||
#include "PlotTemplates/RimPlotTemplateFileItem.h"
|
||||
#include "RimDialogData.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCase.h"
|
||||
@@ -44,20 +46,12 @@
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicCreatePlotFromSelectionFeature, "RicCreatePlotFromSelectionFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicCreatePlotFromSelectionFeature::RicCreatePlotFromSelectionFeature() {}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
|
||||
{
|
||||
if ( selectedSummaryCases().size() == 2 ) return true;
|
||||
if ( selectedWellPaths().size() == 2 ) return true;
|
||||
|
||||
return false;
|
||||
return !selectedSummaryCases().empty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -65,95 +59,59 @@ bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
|
||||
|
||||
RicSelectPlotTemplateUi* ui = RiaGuiApplication::instance()->project()->dialogData()->selectPlotTemplateUi();
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow, ui, "Select Plot Template", "" );
|
||||
|
||||
if ( propertyDialog.exec() != QDialog::Accepted ) return;
|
||||
|
||||
if ( ui->selectedPlotTemplates().empty() ) return;
|
||||
|
||||
QString fileName = ui->selectedPlotTemplates().front()->absoluteFilePath();
|
||||
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases();
|
||||
|
||||
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
|
||||
if ( newSummaryPlot )
|
||||
{
|
||||
RiuPlotMainWindow* plotwindow = RiaGuiApplication::instance()->mainPlotWindow();
|
||||
RimSummaryPlotCollection* plotColl =
|
||||
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
||||
|
||||
RicSelectPlotTemplateUi ui;
|
||||
plotColl->summaryPlots.push_back( newSummaryPlot );
|
||||
newSummaryPlot->resolveReferencesRecursively();
|
||||
newSummaryPlot->initAfterReadRecursively();
|
||||
|
||||
caf::PdmUiPropertyViewDialog propertyDialog( plotwindow,
|
||||
&ui,
|
||||
"Select Case to create Pressure Saturation plots",
|
||||
"" );
|
||||
QString nameOfCopy = QString( "Copy of " ) + newSummaryPlot->description();
|
||||
newSummaryPlot->setDescription( nameOfCopy );
|
||||
|
||||
if ( propertyDialog.exec() != QDialog::Accepted ) return;
|
||||
auto summaryCurves = newSummaryPlot->summaryCurves();
|
||||
|
||||
if ( ui.selectedPlotTemplates().empty() ) return;
|
||||
|
||||
QString fileName = ui.selectedPlotTemplates().front()->absoluteFilePath();
|
||||
for ( const auto& curve : summaryCurves )
|
||||
{
|
||||
auto sumCases = selectedSummaryCases();
|
||||
if ( sumCases.size() == 2 )
|
||||
auto fieldHandle = curve->findField( "SummaryCase" );
|
||||
if ( fieldHandle )
|
||||
{
|
||||
// QString fileName = "d:/projects/ri-plot-templates/one_well_two_cases.rpt";
|
||||
|
||||
RimSummaryPlot* newSummaryPlot = createPlotFromTemplateFile( fileName );
|
||||
if ( newSummaryPlot )
|
||||
auto referenceString = fieldHandle->xmlCapability()->referenceString();
|
||||
auto stringList = referenceString.split( " " );
|
||||
if ( stringList.size() == 2 )
|
||||
{
|
||||
RimSummaryPlotCollection* plotColl =
|
||||
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
||||
QString indexAsString = stringList[1];
|
||||
|
||||
plotColl->summaryPlots.push_back( newSummaryPlot );
|
||||
bool conversionOk = false;
|
||||
int index = indexAsString.toUInt( &conversionOk );
|
||||
|
||||
// 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() == sumCases.size() )
|
||||
if ( conversionOk && index < sumCases.size() )
|
||||
{
|
||||
for ( size_t i = 0; i < summaryCurves.size(); i++ )
|
||||
{
|
||||
auto sumCase = sumCases[i];
|
||||
summaryCurves[i]->setSummaryCaseY( sumCase );
|
||||
}
|
||||
curve->setSummaryCaseY( sumCases[index] );
|
||||
}
|
||||
|
||||
plotColl->updateConnectedEditors();
|
||||
|
||||
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->updateConnectedEditors();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
newSummaryPlot->loadDataAndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,38 +124,6 @@ void RicCreatePlotFromSelectionFeature::setupActionLook( QAction* actionToSetup
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimWellPath*> RicCreatePlotFromSelectionFeature::selectedWellPaths() const
|
||||
{
|
||||
std::vector<RimWellPath*> objects;
|
||||
caf::SelectionManager::instance()->objectsByType( &objects );
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
class RimSummaryCase;
|
||||
class RimSummaryPlot;
|
||||
class RimWellPath;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -31,18 +29,11 @@ class RicCreatePlotFromSelectionFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicCreatePlotFromSelectionFeature();
|
||||
|
||||
protected:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
private:
|
||||
RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName ) const;
|
||||
|
||||
private:
|
||||
std::vector<RimSummaryCase*> selectedSummaryCases() const;
|
||||
std::vector<RimWellPath*> selectedWellPaths() const;
|
||||
};
|
||||
|
||||
@@ -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" ) );
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
@@ -16,28 +16,29 @@
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaSummaryTools.h"
|
||||
|
||||
#include "RicSavePlotTemplateFeature.h"
|
||||
|
||||
#include "RicReloadPlotTemplatesFeature.h"
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaSummaryTools.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafSelectionManager.h"
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicSavePlotTemplateFeature, "RicSavePlotTemplateFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicSavePlotTemplateFeature::RicSavePlotTemplateFeature() {}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -53,28 +54,30 @@ bool RicSavePlotTemplateFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
if ( !selectedSummaryPlot() ) return;
|
||||
|
||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||
|
||||
QString startPath;
|
||||
if ( !app->project()->fileName().isEmpty() )
|
||||
QString fallbackPath;
|
||||
auto folders = app->preferences()->plotTemplateFolders();
|
||||
if ( !folders.empty() )
|
||||
{
|
||||
startPath = app->project()->fileName();
|
||||
startPath = startPath.replace( QString( ".rsp" ), QString( ".rpt" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
startPath = app->lastUsedDialogDirectory( "PLOT_TEMPLATE" );
|
||||
startPath += "/ri-plot-template.rpt";
|
||||
// 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";
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName( nullptr,
|
||||
tr( "Save Plot Template To File" ),
|
||||
startPath,
|
||||
tr( "Plot Template Files (*.rpt);;All files(*.*)" ) );
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
auto objectAsText = selectedSummaryPlot()->writeObjectToXmlString();
|
||||
|
||||
QFile exportFile( fileName );
|
||||
if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
|
||||
{
|
||||
@@ -82,11 +85,87 @@ void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked )
|
||||
return;
|
||||
}
|
||||
|
||||
QString objectAsText = createTextFromObject( selectedSummaryPlot() );
|
||||
|
||||
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->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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -29,14 +29,14 @@ class RicSavePlotTemplateFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicSavePlotTemplateFeature();
|
||||
|
||||
protected:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
private:
|
||||
static QString createTextFromObject( RimSummaryPlot* summaryPlot );
|
||||
|
||||
private:
|
||||
RimSummaryPlot* selectedSummaryPlot() const;
|
||||
};
|
||||
|
||||
@@ -78,3 +78,20 @@ QList<caf::PdmOptionItemInfo>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ private:
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute ) override;
|
||||
|
||||
private:
|
||||
caf::PdmPtrArrayField<RimPlotTemplateFileItem*> m_selectedPlotTemplates;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 );
|
||||
};
|
||||
Reference in New Issue
Block a user