mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3967 Summary : Add simulation file name helper
This commit is contained in:
parent
190b88547e
commit
4e6add0c37
@ -12,6 +12,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaRftPltCurveDefinition.h
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set (SOURCE_GROUP_SOURCE_FILES
|
set (SOURCE_GROUP_SOURCE_FILES
|
||||||
@ -28,6 +29,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaRftPltCurveDefinition.cpp
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND CODE_HEADER_FILES
|
list(APPEND CODE_HEADER_FILES
|
||||||
|
149
ApplicationCode/Application/RiaEclipseFileNameTools.cpp
Normal file
149
ApplicationCode/Application/RiaEclipseFileNameTools.cpp
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 "RiaEclipseFileNameTools.h"
|
||||||
|
|
||||||
|
#include "QFileInfo"
|
||||||
|
|
||||||
|
namespace caf
|
||||||
|
{
|
||||||
|
template<>
|
||||||
|
void caf::AppEnum<RiaEclipseFileNameTools::EclipseFileType>::setUp()
|
||||||
|
{
|
||||||
|
addItem(RiaEclipseFileNameTools::ECLIPSE_DATA, "DATA", "Data Deck");
|
||||||
|
addItem(RiaEclipseFileNameTools::ECLIPSE_GRID, "GRID", "Grid");
|
||||||
|
addItem(RiaEclipseFileNameTools::ECLIPSE_EGRID, "EGRIRD", "Grid");
|
||||||
|
addItem(RiaEclipseFileNameTools::ECLIPSE_UNRST, "UNRST", "Unified Restart");
|
||||||
|
addItem(RiaEclipseFileNameTools::ECLIPSE_SMSPEC, "SMSPEC", "Summary Specification");
|
||||||
|
addItem(RiaEclipseFileNameTools::ECLIPSE_UNSMRY, "UNSMR", "Summary Vectors");
|
||||||
|
|
||||||
|
addItem(RiaEclipseFileNameTools::RESINSIGHT_PROJECT, "rsp", "ResInsight Project");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End namespace caf
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RiaEclipseFileNameTools::RiaEclipseFileNameTools(const QString& inputFilePath)
|
||||||
|
{
|
||||||
|
m_baseName = findBaseName(inputFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaEclipseFileNameTools::findRelatedSummarySpecFile()
|
||||||
|
{
|
||||||
|
return relatedFilePath(ECLIPSE_SMSPEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaEclipseFileNameTools::findRelatedGridFile()
|
||||||
|
{
|
||||||
|
QString candidate = relatedFilePath(ECLIPSE_EGRID);
|
||||||
|
if (!candidate.isEmpty())
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return relatedFilePath(ECLIPSE_GRID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaEclipseFileNameTools::findRelatedDataFile()
|
||||||
|
{
|
||||||
|
return relatedFilePath(ECLIPSE_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RiaEclipseFileNameTools::isProjectFile(const QString& fileName)
|
||||||
|
{
|
||||||
|
return hasMatchingSuffix(fileName, RESINSIGHT_PROJECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RiaEclipseFileNameTools::isGridFile(const QString& fileName)
|
||||||
|
{
|
||||||
|
if (hasMatchingSuffix(fileName, ECLIPSE_EGRID))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasMatchingSuffix(fileName, ECLIPSE_GRID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RiaEclipseFileNameTools::isSummarySpecFile(const QString& fileName)
|
||||||
|
{
|
||||||
|
return hasMatchingSuffix(fileName, ECLIPSE_SMSPEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaEclipseFileNameTools::findBaseName(const QString& inputFilePath) const
|
||||||
|
{
|
||||||
|
QFileInfo fi(inputFilePath);
|
||||||
|
|
||||||
|
return fi.baseName();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaEclipseFileNameTools::relatedFilePath(EclipseFileType fileType) const
|
||||||
|
{
|
||||||
|
const QString extension = caf::AppEnum<EclipseFileType>::text(fileType);
|
||||||
|
const QString completeFilePath = m_baseName + "." + extension;
|
||||||
|
|
||||||
|
QFileInfo fi(completeFilePath);
|
||||||
|
if (fi.exists())
|
||||||
|
{
|
||||||
|
return fi.absoluteFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RiaEclipseFileNameTools::hasMatchingSuffix(const QString& fileName, EclipseFileType fileType)
|
||||||
|
{
|
||||||
|
QFileInfo fi(fileName);
|
||||||
|
|
||||||
|
QString suffix = fi.completeSuffix();
|
||||||
|
|
||||||
|
if (suffix.compare(caf::AppEnum<EclipseFileType>::text(fileType), Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
64
ApplicationCode/Application/RiaEclipseFileNameTools.h
Normal file
64
ApplicationCode/Application/RiaEclipseFileNameTools.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 "cafAppEnum.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
class RiaEclipseFileNameTools
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum EclipseFileType
|
||||||
|
{
|
||||||
|
ECLIPSE_DATA,
|
||||||
|
ECLIPSE_GRID,
|
||||||
|
ECLIPSE_EGRID,
|
||||||
|
ECLIPSE_UNRST,
|
||||||
|
ECLIPSE_SMSPEC,
|
||||||
|
ECLIPSE_UNSMRY,
|
||||||
|
RESINSIGHT_PROJECT,
|
||||||
|
UNKNOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RiaEclipseFileNameTools(const QString& fileName);
|
||||||
|
|
||||||
|
QString findRelatedGridFile();
|
||||||
|
QString findRelatedSummarySpecFile();
|
||||||
|
QString findRelatedDataFile();
|
||||||
|
|
||||||
|
static bool isProjectFile(const QString& fileName);
|
||||||
|
static bool isGridFile(const QString& fileName);
|
||||||
|
static bool isSummarySpecFile(const QString& fileName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString findBaseName(const QString& inputFilePath) const;
|
||||||
|
QString relatedFilePath(EclipseFileType fileType) const;
|
||||||
|
|
||||||
|
static bool hasMatchingSuffix(const QString& fileName, EclipseFileType fileType);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_baseName;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user