#4657 Summary Templates : Application objects

Add file path to preferences
Show templates in project tree
Add pointer to template to RimSummaryPlot
This commit is contained in:
Magne Sjaastad 2019-09-11 09:33:03 +02:00
parent 87afbaf586
commit 020313da91
19 changed files with 963 additions and 7 deletions

View File

@ -1118,6 +1118,7 @@ void RiaApplication::applyPreferences()
if ( this->project() )
{
this->project()->setScriptDirectories( m_preferences->scriptDirectories() );
this->project()->setPlotTemplateFolders( m_preferences->plotTemplateFolders() );
this->project()->updateConnectedEditors();
}
caf::PdmSettings::writeFieldsToApplicationStore( m_preferences );
@ -1415,6 +1416,7 @@ void RiaApplication::initialize()
// Start with a project
m_project = new RimProject;
m_project->setScriptDirectories( m_preferences->scriptDirectories() );
m_project->setPlotTemplateFolders( m_preferences->plotTemplateFolders() );
}
//--------------------------------------------------------------------------------------------------

View File

@ -301,6 +301,17 @@ RiaPreferences::RiaPreferences( void )
CAF_PDM_InitFieldNoDefault( &m_timeFormat, "timeFormat", "Time Format", "", "", "" );
m_timeFormat.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
m_timeFormat = RiaQDateTimeTools::supportedTimeFormats().front();
CAF_PDM_InitFieldNoDefault( &m_plotTemplateFolders, "plotTemplateFolders", "Plot Template Folder(s)", "", "", "" );
m_plotTemplateFolders.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
CAF_PDM_InitField( &m_searchPlotTemplateFoldersRecursively,
"SearchPlotTemplateFoldersRecursively",
true,
"Search Plot Templates Recursively",
"",
"",
"" );
m_searchPlotTemplateFoldersRecursively.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
}
//--------------------------------------------------------------------------------------------------
@ -320,7 +331,7 @@ void RiaPreferences::defineEditorAttribute( const caf::PdmFieldHandle* field,
{
m_readerSettings->defineEditorAttribute( field, uiConfigName, attribute );
if ( field == &scriptDirectories )
if ( field == &scriptDirectories || field == &m_plotTemplateFolders )
{
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>( attribute );
if ( myAttr )
@ -334,7 +345,8 @@ void RiaPreferences::defineEditorAttribute( const caf::PdmFieldHandle* field,
field == &m_appendClassNameToUiText || field == &m_appendFieldKeywordToToolTipText ||
field == &m_showTestToolbar || field == &m_includeFractureDebugInfoFile ||
field == &showLasCurveWithoutTvdWarning || field == &holoLensDisableCertificateVerification ||
field == &m_showProjectChangedDialog || field == &showLegendBackground )
field == &m_showProjectChangedDialog || field == &m_searchPlotTemplateFoldersRecursively ||
field == &showLegendBackground )
{
caf::PdmUiCheckBoxEditorAttribute* myAttr = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>( attribute );
if ( myAttr )
@ -422,6 +434,10 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
uiOrdering.add( &defaultSummaryHistoryCurveStyle );
uiOrdering.add( &m_dateFormat );
uiOrdering.add( &m_timeFormat );
caf::PdmUiGroup* group = uiOrdering.addNewGroup( "Plot Templates" );
group->add( &m_plotTemplateFolders );
group->add( &m_searchPlotTemplateFoldersRecursively );
}
else if ( uiConfigName == RiaPreferences::tabNameScripting() )
{
@ -673,6 +689,33 @@ const QString& RiaPreferences::timeFormat() const
return m_timeFormat();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaPreferences::searchPlotTemplateFoldersRecursively() const
{
return m_searchPlotTemplateFoldersRecursively();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RiaPreferences::plotTemplateFolders() const
{
QStringList filteredFolders;
QStringList pathList = m_plotTemplateFolders().split( ';' );
for ( const auto& path : pathList )
{
QDir dir( path );
if ( !path.isEmpty() && dir.exists() && dir.isReadable() )
{
filteredFolders.push_back( path );
}
}
return filteredFolders;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -79,6 +79,9 @@ public:
const QString& dateFormat() const;
const QString& timeFormat() const;
bool searchPlotTemplateFoldersRecursively() const;
QStringList plotTemplateFolders() const;
std::map<RiaDefines::FontSettingType, RiaFontCache::FontSize> defaultFontSizes() const;
public: // Pdm Fields
@ -162,5 +165,9 @@ private:
caf::PdmField<QString> m_holoLensExportFolder;
caf::PdmField<QString> m_dateFormat;
caf::PdmField<QString> m_timeFormat;
QStringList m_tabNames;
caf::PdmField<QString> m_plotTemplateFolders;
caf::PdmField<bool> m_searchPlotTemplateFoldersRecursively;
QStringList m_tabNames;
};

View File

@ -124,6 +124,7 @@ list( APPEND REFERENCED_CMAKE_FILES
ProjectDataModel/Annotations/CMakeLists_files.cmake
ProjectDataModel/Completions/CMakeLists_files.cmake
ProjectDataModel/Measurement/CMakeLists_files.cmake
ProjectDataModel/PlotTemplates/CMakeLists_files.cmake
GeoMech/GeoMechVisualization/CMakeLists_files.cmake
@ -157,6 +158,7 @@ list( APPEND REFERENCED_CMAKE_FILES
Commands/ViewLink/CMakeLists_files.cmake
Commands/WellLogCommands/CMakeLists_files.cmake
Commands/WellPathCommands/CMakeLists_files.cmake
Commands/PlotTemplateCommands/CMakeLists_files.cmake
CommandFileInterface/CMakeLists_files.cmake
CommandFileInterface/Core/CMakeLists_files.cmake

View File

@ -0,0 +1,24 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicSavePlotTemplateFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreatePlotFromSelectionFeature.cpp
)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)
list(APPEND CODE_SOURCE_FILES
${SOURCE_GROUP_SOURCE_FILES}
)
list(APPEND QT_MOC_HEADERS
)
source_group( "CommandFeature\\PlotTemplate" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )

View File

@ -0,0 +1,198 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiaGuiApplication.h"
#include "RiaSummaryTools.h"
#include "RicCreatePlotFromSelectionFeature.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimSummaryCase.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RimWellPath.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileDialog>
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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
{
{
auto sumCases = selectedSummaryCases();
if ( sumCases.size() == 2 )
{
QString fileName = "d:/projects/ri-plot-templates/one_well_two_cases.rpt";
RimSummaryPlot* newSummaryPlot = createPlotFromTemplateFile( fileName );
if ( newSummaryPlot )
{
RimSummaryPlotCollection* plotColl =
RiaApplication::instance()->project()->mainPlotCollection()->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() == sumCases.size() )
{
for ( size_t i = 0; i < summaryCurves.size(); i++ )
{
auto sumCase = sumCases[i];
summaryCurves[i]->setSummaryCaseY( sumCase );
}
}
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->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();
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreatePlotFromSelectionFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Create Plot from Template" );
// actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCase*> RicCreatePlotFromSelectionFeature::selectedSummaryCases() const
{
std::vector<RimSummaryCase*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RicCreatePlotFromSelectionFeature::selectedWellPaths() const
{
std::vector<RimWellPath*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}

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 "cafCmdFeature.h"
class RimSummaryCase;
class RimWellPath;
//==================================================================================================
///
//==================================================================================================
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;
};

View File

@ -0,0 +1,112 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiaGuiApplication.h"
#include "RiaSummaryTools.h"
#include "RicSavePlotTemplateFeature.h"
#include "RimProject.h"
#include "RimSummaryPlot.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileDialog>
CAF_CMD_SOURCE_INIT( RicSavePlotTemplateFeature, "RicSavePlotTemplateFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSavePlotTemplateFeature::RicSavePlotTemplateFeature() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSavePlotTemplateFeature::isCommandEnabled()
{
if ( selectedSummaryPlot() ) return true;
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSavePlotTemplateFeature::onActionTriggered( bool isChecked )
{
RiaGuiApplication* app = RiaGuiApplication::instance();
QString startPath;
if ( !app->project()->fileName().isEmpty() )
{
startPath = app->project()->fileName();
startPath = startPath.replace( QString( ".rsp" ), QString( ".rpt" ) );
}
else
{
startPath = app->lastUsedDialogDirectory( "PLOT_TEMPLATE" );
startPath += "/ri-plot-template.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 ) )
{
RiaLogging::error( QString( "Save Plot Template : Could not open the file: %1" ).arg( fileName ) );
return;
}
QTextStream stream( &exportFile );
stream << objectAsText;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSavePlotTemplateFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Save As Plot Template" );
// actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicSavePlotTemplateFeature::selectedSummaryPlot() const
{
RimSummaryPlot* sumPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
sumPlot = RiaSummaryTools::parentSummaryPlot( selObj );
}
return sumPlot;
}

View File

@ -0,0 +1,42 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 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:
RimSummaryPlot* selectedSummaryPlot() const;
};

View File

@ -0,0 +1,20 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimPlotTemplateFolderItem.h
${CMAKE_CURRENT_LIST_DIR}/RimPlotTemplateFileItem.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimPlotTemplateFolderItem.cpp
${CMAKE_CURRENT_LIST_DIR}/RimPlotTemplateFileItem.cpp
)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)
list(APPEND CODE_SOURCE_FILES
${SOURCE_GROUP_SOURCE_FILES}
)
source_group( "ProjectDataModel\\PlotTemplates" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )

View File

@ -0,0 +1,65 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// 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 "RimPlotTemplateFileItem.h"
#include "RiaApplication.h"
#include "RiaFieldHandleTools.h"
#include "RiaLogging.h"
#include "cafPdmField.h"
#include "cafPdmUiFilePathEditor.h"
#include <QFileInfo>
CAF_PDM_SOURCE_INIT( RimPlotTemplateFileItem, "PlotTemplateFileItem" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotTemplateFileItem::RimPlotTemplateFileItem()
{
CAF_PDM_InitObject( "PlotTemplateFileItem", ":/OctaveScriptFile16x16.png", "Calc Script", "" );
CAF_PDM_InitField( &m_absoluteFileName, "AbsolutePath", QString(), "Location", "", "", "" );
m_absoluteFileName.uiCapability()->setUiReadOnly( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotTemplateFileItem::~RimPlotTemplateFileItem() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFileItem::setFilePath( const QString& filePath )
{
QFileInfo fi( filePath );
this->uiCapability()->setUiName( fi.baseName() );
m_absoluteFileName = filePath;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPlotTemplateFileItem::absoluteFilePath() const
{
return m_absoluteFileName();
}

View File

@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// 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 "cafPdmField.h"
#include "cafPdmObject.h"
//==================================================================================================
///
///
//==================================================================================================
class RimPlotTemplateFileItem : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimPlotTemplateFileItem();
~RimPlotTemplateFileItem() override;
void setFilePath( const QString& filePath );
QString absoluteFilePath() const;
private:
caf::PdmField<QString> m_absoluteFileName;
};

View File

@ -0,0 +1,200 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimPlotTemplateFolderItem.h"
#include "RiaApplication.h"
#include "RiaPreferences.h"
#include "RimPlotTemplateFileItem.h"
#include "cafPdmUiFilePathEditor.h"
#include "cafUtils.h"
#include <QDir>
#include <QStringList>
CAF_PDM_SOURCE_INIT( RimPlotTemplateFolderItem, "PlotTemplateCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotTemplateFolderItem::RimPlotTemplateFolderItem()
{
CAF_PDM_InitObject( "PlotTemplateCollection", ":/Folder.png", "", "" );
CAF_PDM_InitFieldNoDefault( &m_folderName, "FolderName", "Folder", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_fileNames, "FileNames", "", "", "", "" );
m_fileNames.uiCapability()->setUiHidden( true );
CAF_PDM_InitFieldNoDefault( &m_subFolders, "SubFolders", "", "", "", "" );
m_subFolders.uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotTemplateFolderItem::~RimPlotTemplateFolderItem() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::createRootFolderItemsFromFolderPaths( const QStringList& folderPaths )
{
createSubFolderItemsFromFolderPaths( folderPaths );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotTemplateFileItem*> RimPlotTemplateFolderItem::fileNames() const
{
return m_fileNames.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotTemplateFolderItem*> RimPlotTemplateFolderItem::subFolders() const
{
return m_subFolders.childObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::setFolderPath( const QString& path )
{
m_folderName.v().setPath( path );
QFileInfo fi( path );
this->uiCapability()->setUiName( fi.baseName() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::searchForFileAndFolderNames()
{
m_fileNames.deleteAllChildObjects();
m_subFolders.deleteAllChildObjects();
if ( m_folderName().path().isEmpty() )
{
for ( size_t i = 0; i < m_subFolders.size(); ++i )
{
if ( m_subFolders[i] ) m_subFolders[i]->searchForFileAndFolderNames();
}
return;
}
QDir myDir( this->m_folderName().path() );
if ( !myDir.isReadable() )
{
return;
}
// Build a list of all scripts in the specified directory
{
QStringList nameFilters;
nameFilters << "*.rpt";
QStringList fileList = caf::Utils::getFilesInDirectory( m_folderName().path(), nameFilters, true );
for ( int i = 0; i < fileList.size(); i++ )
{
const QString& fileName = fileList.at( i );
if ( caf::Utils::fileExists( fileName ) )
{
RimPlotTemplateFileItem* fileItem = new RimPlotTemplateFileItem();
fileItem->setFilePath( fileName );
m_fileNames.push_back( fileItem );
}
}
}
if ( searchSubFoldersRecursively() )
{
QStringList folderPaths;
QDir dir( m_folderName().path() );
QFileInfoList fileInfoList = dir.entryInfoList( QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Readable );
for ( const auto& fi : fileInfoList )
{
folderPaths.push_back( fi.absoluteFilePath() );
}
createSubFolderItemsFromFolderPaths( folderPaths );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
if ( &m_folderName == changedField )
{
QFileInfo fi( m_folderName().path() );
this->setUiName( fi.baseName() );
this->searchForFileAndFolderNames();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute )
{
if ( field == &m_folderName )
{
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>( attribute );
if ( myAttr )
{
myAttr->m_selectDirectory = true;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotTemplateFolderItem::createSubFolderItemsFromFolderPaths( const QStringList& folderPaths )
{
for ( const auto& path : folderPaths )
{
RimPlotTemplateFolderItem* scriptLocation = new RimPlotTemplateFolderItem();
scriptLocation->setFolderPath( path );
scriptLocation->searchForFileAndFolderNames();
m_subFolders.push_back( scriptLocation );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotTemplateFolderItem::searchSubFoldersRecursively() const
{
return RiaApplication::instance()->preferences()->searchPlotTemplateFoldersRecursively();
}

View File

@ -0,0 +1,67 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
namespace caf
{
class PdmUiEditorAttribute;
}
class RimPlotTemplateFileItem;
//==================================================================================================
///
///
//==================================================================================================
class RimPlotTemplateFolderItem : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimPlotTemplateFolderItem();
~RimPlotTemplateFolderItem() override;
void createRootFolderItemsFromFolderPaths( const QStringList& folderPaths );
std::vector<RimPlotTemplateFileItem*> fileNames() const;
std::vector<RimPlotTemplateFolderItem*> subFolders() const;
private:
void searchForFileAndFolderNames();
void setFolderPath( const QString& path );
void createSubFolderItemsFromFolderPaths( const QStringList& folderPaths );
bool searchSubFoldersRecursively() const;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute ) override;
private:
caf::PdmField<caf::FilePath> m_folderName;
caf::PdmChildArrayField<RimPlotTemplateFileItem*> m_fileNames;
caf::PdmChildArrayField<RimPlotTemplateFolderItem*> m_subFolders;
};

View File

@ -550,6 +550,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "Separator";
menuBuilder << "RicShowSummaryCurveCalculatorFeature";
menuBuilder << "Separator";
menuBuilder << "RicSavePlotTemplateFeature";
menuBuilder << "Separator";
// Export is not supported for cross plot
if ( !summaryCrossPlot ) menuBuilder << "RicAsciiExportSummaryPlotFeature";
@ -843,6 +845,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicDeleteSummaryCaseCollectionFeature";
menuBuilder << "RicCloseObservedDataFeature";
menuBuilder << "RicCreatePlotFromSelectionFeature";
// Work in progress -- End
appendCreateCompletions( menuBuilder, menuBuilder.itemCount() > 0u );
bool addedExportWellPaths = appendExportWellPaths( menuBuilder, menuBuilder.itemCount() > 0u ) > 0;
@ -1186,4 +1190,4 @@ int RimContextCommandBuilder::appendSubMenuWithCommands( caf::CmdFeatureMenuBuil
menuBuilder.subMenuEnd();
}
return actualCommandsAdded;
}
}

View File

@ -30,6 +30,7 @@
#include "RigEclipseCaseData.h"
#include "RigGridBase.h"
#include "PlotTemplates/RimPlotTemplateFolderItem.h"
#include "RimAdvancedSnapshotExportDefinition.h"
#include "RimAnnotationCollection.h"
#include "RimAnnotationInViewCollection.h"
@ -191,6 +192,10 @@ RimProject::RimProject( void )
mainPlotCollection = new RimMainPlotCollection();
CAF_PDM_InitFieldNoDefault( &m_plotTemplateFolderItem, "PlotTemplateCollection", "Plot Templates", "", "", "" );
m_plotTemplateFolderItem = new RimPlotTemplateFolderItem();
m_plotTemplateFolderItem.xmlCapability()->disableIO();
// For now, create a default first oilfield that contains the rest of the project
oilFields.push_back( new RimOilField );
@ -353,6 +358,17 @@ void RimProject::setScriptDirectories( const QString& scriptDirectories )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimProject::setPlotTemplateFolders( const QStringList& plotTemplateFolders )
{
if ( m_plotTemplateFolderItem() ) delete m_plotTemplateFolderItem();
m_plotTemplateFolderItem = new RimPlotTemplateFolderItem();
m_plotTemplateFolderItem->createRootFolderItemsFromFolderPaths( plotTemplateFolders );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1155,6 +1171,14 @@ RimMeasurement* RimProject::measurement() const
return activeOilField()->measurement;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotTemplateFolderItem* RimProject::rootPlotTemlateItem() const
{
return m_plotTemplateFolderItem;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1237,6 +1261,8 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q
itemCollection->add( mainPlotCollection->saturationPressurePlotCollection() );
}
}
uiTreeOrdering.add( m_plotTemplateFolderItem() );
}
else
{

View File

@ -66,6 +66,7 @@ class RimFractureTemplate;
class RimValveTemplateCollection;
class RimValveTemplate;
class RimCompletionTemplateCollection;
class RimPlotTemplateFolderItem;
namespace caf
{
@ -104,6 +105,7 @@ public:
caf::PdmField<QString> plotWindowCurrentModelIndexPath;
void setScriptDirectories( const QString& scriptDirectories );
void setPlotTemplateFolders( const QStringList& plotTemplateFolders );
QString projectFileVersionString() const;
bool isProjectFileVersionEqualOrOlderThan( const QString& otherProjectFileVersion ) const;
@ -172,6 +174,8 @@ public:
RiaEclipseUnitTools::UnitSystemType commonUnitSystemForAllCases() const;
RimMeasurement* measurement() const;
RimPlotTemplateFolderItem* rootPlotTemlateItem() const;
protected:
// Overridden methods
void initAfterRead() override;
@ -186,7 +190,8 @@ private:
private:
caf::PdmField<QString> m_projectFileVersionString;
caf::PdmChildField<RimDialogData*> m_dialogData;
caf::PdmChildField<RimDialogData*> m_dialogData;
caf::PdmChildField<RimPlotTemplateFolderItem*> m_plotTemplateFolderItem;
caf::PdmField<bool> m_show3DWindow;
caf::PdmField<bool> m_showPlotWindow;

View File

@ -25,6 +25,8 @@
#include "SummaryPlotCommands/RicSummaryCurveCreator.h"
#include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "PlotTemplates/RimPlotTemplateFolderItem.h"
#include "RimAsciiDataCurve.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
@ -194,6 +196,8 @@ RimSummaryPlot::RimSummaryPlot()
CAF_PDM_InitField( &m_isAutoZoom_OBSOLETE, "AutoZoom", true, "Auto Zoom", "", "", "" );
RiaFieldhandleTools::disableWriteAndSetFieldHidden( &m_isAutoZoom_OBSOLETE );
CAF_PDM_InitFieldNoDefault( &m_plotTemplate, "PlotTemplate", "Template", "", "", "" );
m_isCrossPlot = false;
m_nameHelperAllCurves.reset( new RimSummaryPlotNameHelper );
@ -1234,6 +1238,27 @@ QList<caf::PdmOptionItemInfo> RimSummaryPlot::calculateValueOptions( const caf::
options.push_back( caf::PdmOptionItemInfo( text, value ) );
}
}
else if ( fieldNeedingOptions == &m_plotTemplate )
{
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );
auto rootPlotTemplate = RiaApplication::instance()->project()->rootPlotTemlateItem();
if ( rootPlotTemplate )
{
std::vector<caf::PdmObject*> allTemplates;
{
RimPlotTemplateFileItem fileItem;
rootPlotTemplate->descendantsIncludingThisFromClassKeyword( fileItem.classKeyword(), allTemplates );
}
for ( auto t : allTemplates )
{
caf::PdmOptionItemInfo optionItem( t->uiName(), t );
options.push_back( optionItem );
}
}
}
return options;
}
@ -1552,6 +1577,8 @@ void RimSummaryPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
m_userDefinedPlotTitle.uiCapability()->setUiReadOnly( m_useAutoPlotTitle );
uiOrdering.add( &m_plotTemplate );
uiOrdering.skipRemainingFields( true );
}
@ -1842,6 +1869,22 @@ void RimSummaryPlot::showLegend( bool enable )
m_showLegend = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::setPlotTemplate( RimPlotTemplateFileItem* plotTemplate )
{
m_plotTemplate = plotTemplate;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotTemplateFileItem* RimSummaryPlot::plotTemplate() const
{
return m_plotTemplate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -18,8 +18,6 @@
#pragma once
#include "cafPdmChildArrayField.h"
#include "RiaDefines.h"
#include "RiaQDateTimeTools.h"
#include "RiaSummaryCurveDefinition.h"
@ -30,6 +28,10 @@
#include "RimViewWindow.h"
#include "qwt_plot_textlabel.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmPtrField.h"
#include <QPointer>
#include <memory>
@ -49,6 +51,7 @@ class RimPlotAxisPropertiesInterface;
class RimPlotAxisProperties;
class RiuSummaryQwtPlot;
class RimSummaryPlotNameHelper;
class RimPlotTemplateFileItem;
class QwtInterval;
class QwtPlotCurve;
@ -145,6 +148,9 @@ public:
bool isNormalizationEnabled();
void showLegend( bool enable );
void setPlotTemplate( RimPlotTemplateFileItem* plotTemplate );
RimPlotTemplateFileItem* plotTemplate() const;
public:
// Rim2dPlotInterface overrides
void updateAxisScaling() override;
@ -223,6 +229,8 @@ private:
caf::PdmChildField<RimPlotAxisProperties*> m_bottomAxisProperties;
caf::PdmChildField<RimSummaryTimeAxisProperties*> m_timeAxisProperties;
caf::PdmPtrField<RimPlotTemplateFileItem*> m_plotTemplate;
QPointer<RiuSummaryQwtPlot> m_qwtPlot;
std::unique_ptr<QwtPlotTextLabel> m_plotInfoLabel;