mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#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:
@@ -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 )
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user