Files

84 lines
2.9 KiB
C++
Raw Permalink Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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
2024-06-05 10:59:04 +02:00
#include "cafPdmField.h"
#include "cafPdmObjectHandle.h"
2025-05-03 08:58:28 +02:00
#include "cafPdmXmlFieldHandle.h"
2024-06-05 10:59:04 +02:00
#include <QString>
2024-06-05 10:59:04 +02:00
#include <vector>
class RiaVariableMapper;
class RimProject;
//==================================================================================================
//
//==================================================================================================
namespace RiaProjectFileTools
{
bool isCandidateVersionNewerThanOther( const QString& candidateProjectFileVersion, const QString& otherProjectFileVersion );
template <typename T>
std::vector<T*> writableFieldContent( const caf::PdmObjectHandle* object )
{
if ( !object ) return {};
2024-06-05 10:59:04 +02:00
std::vector<T*> fieldContents;
2024-06-05 10:59:04 +02:00
std::vector<caf::PdmObjectHandle*> children;
for ( const auto& field : object->fields() )
{
if ( !field ) continue;
2025-05-03 08:58:28 +02:00
if ( field->xmlCapability() && !field->xmlCapability()->isIOWritable() ) continue;
2025-05-03 08:58:28 +02:00
caf::PdmField<T>* typedField = dynamic_cast<caf::PdmField<T>*>( field );
if ( typedField ) fieldContents.push_back( &typedField->v() );
2024-06-05 10:59:04 +02:00
caf::PdmField<std::vector<T>>* typedFieldInVector = dynamic_cast<caf::PdmField<std::vector<T>>*>( field );
if ( typedFieldInVector )
{
for ( T& typedFieldFromVector : typedFieldInVector->v() )
2024-06-05 10:59:04 +02:00
{
fieldContents.push_back( &typedFieldFromVector );
2024-06-05 10:59:04 +02:00
}
}
auto other = field->children();
children.insert( children.end(), other.begin(), other.end() );
}
2025-05-03 08:58:28 +02:00
for ( const auto& child : children )
{
auto childObjects = writableFieldContent<T>( child );
fieldContents.insert( fieldContents.end(), childObjects.begin(), childObjects.end() );
2024-06-05 10:59:04 +02:00
}
return fieldContents;
}
QString transferPathsToGlobalPathList( RimProject* project );
void distributePathsFromGlobalPathList( RimProject* project, const QString& pathList );
QString updatedFilePathFromPathId( QString filePath, RiaVariableMapper* pathListMapper );
// Public to be able to unit test function
void decodeVersionString( const QString& projectFileVersion, int* majorVersion, int* minorVersion, int* patch, int* developmentId );
}; // namespace RiaProjectFileTools