mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
#14710 Warn when loading a project with the obsolete formation filter
Keep the removed formation filter fields as obsolete so old projects still parse, and warn that the filter is no longer applied.
This commit is contained in:
1 parent
9911c49d2b
commit
cf75dbf58e
3 files changed
+99
No files matched your search
@@ -221,6 +221,15 @@ RimStatisticsContourMap::RimStatisticsContourMap()
|
||||
CAF_PDM_InitFieldNoDefault( &m_cacheMapSize, "CacheMapSize", "Cache Map Size" );
|
||||
m_cacheMapSize.uiCapability()->setUiHidden( true );
|
||||
|
||||
// Obsolete built-in formation filter, replaced by ensemble data filters (see #14710).
|
||||
CAF_PDM_InitField( &m_enableFormationFilter_OBSOLETE, "EnableFormationFilter", false, "Enable Formation Filter" );
|
||||
m_enableFormationFilter_OBSOLETE.xmlCapability()->setIOWritable( false );
|
||||
m_enableFormationFilter_OBSOLETE.uiCapability()->setUiHidden( true );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_selectedFormations_OBSOLETE, "Formations", "Select Formations" );
|
||||
m_selectedFormations_OBSOLETE.xmlCapability()->setIOWritable( false );
|
||||
m_selectedFormations_OBSOLETE.uiCapability()->setUiHidden( true );
|
||||
|
||||
setDeletable( true );
|
||||
}
|
||||
|
||||
@@ -496,6 +505,19 @@ void RimStatisticsContourMap::defineEditorAttribute( const caf::PdmFieldHandle*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimStatisticsContourMap::initAfterRead()
|
||||
{
|
||||
// Formation filter removed in 2026.09.1 in favor of ensemble data filters (#14710).
|
||||
bool hasObsoleteFormationFilter = m_enableFormationFilter_OBSOLETE() || !m_selectedFormations_OBSOLETE().empty();
|
||||
if ( hasObsoleteFormationFilter && RimProject::current() && RimProject::current()->isProjectFileVersionEqualOrOlderThan( "2026.09.1" ) )
|
||||
{
|
||||
QString formations = QStringList( m_selectedFormations_OBSOLETE().begin(), m_selectedFormations_OBSOLETE().end() ).join( ", " );
|
||||
QString message = QString( "Ensemble contour map '%1' had a formation filter selection ('%2') from an older "
|
||||
"ResInsight version. The built-in formation filter has been removed and is no "
|
||||
"longer applied. Use an ensemble data filter on formation names instead." )
|
||||
.arg( name() )
|
||||
.arg( formations );
|
||||
RiaLogging::warning( message.toStdString() );
|
||||
}
|
||||
|
||||
if ( ensembleCases().empty() ) return;
|
||||
|
||||
switchToSelectedSourceCase();
|
||||
|
||||
@@ -172,6 +172,10 @@ private:
|
||||
|
||||
RimEclipseCase* m_openEclipseCase;
|
||||
|
||||
// Obsolete formation filter, replaced by ensemble data filters (#14710). Kept for the warning in initAfterRead().
|
||||
caf::PdmField<bool> m_enableFormationFilter_OBSOLETE;
|
||||
caf::PdmField<std::vector<QString>> m_selectedFormations_OBSOLETE;
|
||||
|
||||
// Validity key captured when the results were computed or loaded from cache, so that results
|
||||
// from outdated settings are never written to the cache
|
||||
QString m_computedValidityKey;
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaTestDataDirectory.h"
|
||||
|
||||
#include "ContourMap/RigContourMapCalculator.h"
|
||||
#include "ContourMap/RigContourMapGrid.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
#include "RigMainGrid.h"
|
||||
|
||||
@@ -30,11 +32,14 @@
|
||||
#include "RimDataFilterCollection.h"
|
||||
#include "RimEclipseResultCase.h"
|
||||
#include "RimEclipseResultDefinition.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimReservoirGridEnsemble.h"
|
||||
|
||||
#include "cafPdmChildField.h"
|
||||
#include "cafPdmDefaultObjectFactory.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmPtrField.h"
|
||||
#include "cafPdmXmlObjectHandle.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@@ -223,3 +228,71 @@ TEST( RimStatisticsContourMapTest, DataFilterSharedAndIndividualGridsAgree )
|
||||
ASSERT_EQ( shared.size(), individual.size() );
|
||||
EXPECT_EQ( 0u, countDifferentValues( shared, individual ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Minimal logger capturing warning messages, used to verify the obsolete formation filter warning.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RecordingLogger : public RiaLogger
|
||||
{
|
||||
public:
|
||||
int level() const override { return static_cast<int>( RILogLevel::RI_LL_WARNING ); }
|
||||
void setLevel( int ) override {}
|
||||
|
||||
void error( const char* ) override {}
|
||||
void warning( const char* message ) override { warnings.push_back( message ); }
|
||||
void info( const char* ) override {}
|
||||
void debug( const char* ) override {}
|
||||
|
||||
std::vector<std::string> warnings;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Loading a project with the obsolete formation filter fields set (#14710) should warn, not silently drop them.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RimStatisticsContourMapTest, ObsoleteFormationFilterWarnsOnLoad )
|
||||
{
|
||||
auto sourceMap = std::make_unique<RimStatisticsContourMap>();
|
||||
sourceMap->setName( "MyContourMap" );
|
||||
|
||||
auto* enableField = dynamic_cast<caf::PdmField<bool>*>( sourceMap->findField( "EnableFormationFilter" ) );
|
||||
auto* formationsField = dynamic_cast<caf::PdmField<std::vector<QString>>*>( sourceMap->findField( "Formations" ) );
|
||||
ASSERT_TRUE( enableField != nullptr );
|
||||
ASSERT_TRUE( formationsField != nullptr );
|
||||
|
||||
enableField->setValue( true );
|
||||
formationsField->setValue( { "Zone1", "Zone2" } );
|
||||
|
||||
// The obsolete fields are marked non-writable so current projects never persist them again; force
|
||||
// writing here to simulate an XML string produced by an older ResInsight version.
|
||||
enableField->xmlCapability()->setIOWritable( true );
|
||||
formationsField->xmlCapability()->setIOWritable( true );
|
||||
|
||||
QString xml = sourceMap->xmlCapability()->writeObjectToXmlString();
|
||||
|
||||
auto* recordingLogger = new RecordingLogger();
|
||||
RiaLogging::appendLoggerInstance( std::unique_ptr<RiaLogger>( recordingLogger ) );
|
||||
|
||||
// Simulate the project having been saved by an older ResInsight version, so the version guard in
|
||||
// initAfterRead() lets the obsolete-field warning through.
|
||||
auto* versionField = dynamic_cast<caf::PdmField<QString>*>( RimProject::current()->findField( "ProjectFileVersionString" ) );
|
||||
ASSERT_TRUE( versionField != nullptr );
|
||||
QString originalVersion = versionField->value();
|
||||
versionField->setValue( "2026.06.0" );
|
||||
|
||||
auto readMap = std::make_unique<RimStatisticsContourMap>();
|
||||
readMap->xmlCapability()->readObjectFromXmlString( xml, caf::PdmDefaultObjectFactory::instance() );
|
||||
readMap->xmlCapability()->resolveReferencesRecursively();
|
||||
readMap->xmlCapability()->initAfterReadRecursively();
|
||||
|
||||
versionField->setValue( originalVersion );
|
||||
|
||||
bool foundWarning = false;
|
||||
for ( const auto& message : recordingLogger->warnings )
|
||||
{
|
||||
if ( message.find( "Zone1, Zone2" ) != std::string::npos ) foundWarning = true;
|
||||
}
|
||||
EXPECT_TRUE( foundWarning );
|
||||
}
|
||||
Reference in new issue
Block a user