Files
ResInsight/ApplicationLibCode/ProjectDataModelCommands/RimcRegularSurface.cpp
T
Magne Sjaastad 0eb980e8e1 Sets depth property for regular file surfaces
Ensures that the depth property is correctly set for regular file surfaces after loading data. This allows the property to
be utilized as a depth value.
2026-01-14 11:15:28 +01:00

110 lines
4.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025- 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 "RimcRegularSurface.h"
#include "KeyValueStore/RiaKeyValueStoreUtil.h"
#include "RiaApplication.h"
#include "RimRegularSurface.h"
#include "RimSurfaceCollection.h"
#include "RifSurfaceExporter.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimRegularSurface, RimcRegularSurface_setPropertyFromKey, "SetPropertyFromKey" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcRegularSurface_setPropertyFromKey::RimcRegularSurface_setPropertyFromKey( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Set property from key", "", "", "Set property from key." );
CAF_PDM_InitScriptableFieldNoDefault( &m_name, "Name", "", "", "", "Name" );
CAF_PDM_InitScriptableFieldNoDefault( &m_valueKey, "ValueKey", "", "", "", "Key Value" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcRegularSurface_setPropertyFromKey::execute()
{
RimRegularSurface* surface = self<RimRegularSurface>();
if ( !surface ) return std::unexpected( "No surface found" );
auto keyValueStore = RiaApplication::instance()->keyValueStore();
std::vector<float> values = RiaKeyValueStoreUtil::convertToFloatVector( keyValueStore->get( m_valueKey().toStdString() ) );
if ( values.empty() ) return std::unexpected( "Found unexcepted empty property." );
if ( values.size() != static_cast<size_t>( surface->nx() * surface->ny() ) )
return std::unexpected( "Failed to set property: incorrect dimensions." );
surface->setProperty( m_name, values );
surface->onLoadData();
if ( auto coll = surface->firstAncestorOrThisOfType<RimSurfaceCollection>() )
{
coll->updateUiIconFromToggleField();
coll->updateViews();
}
keyValueStore->remove( m_valueKey().toStdString() );
return nullptr;
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimRegularSurface, RimcRegularSurface_setPropertyAsDepth, "SetPropertyAsDepth" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcRegularSurface_setPropertyAsDepth::RimcRegularSurface_setPropertyAsDepth( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Set property as depth", "", "", "Set property as depth." );
CAF_PDM_InitScriptableFieldNoDefault( &m_name, "Name", "", "", "", "Name" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcRegularSurface_setPropertyAsDepth::execute()
{
RimRegularSurface* surface = self<RimRegularSurface>();
if ( !surface ) return std::unexpected( "No surface found" );
surface->setPropertyAsDepth( m_name );
surface->onLoadData();
if ( auto coll = surface->firstAncestorOrThisOfType<RimSurfaceCollection>() )
{
coll->updateUiIconFromToggleField();
coll->updateViews();
coll->updateConnectedEditors();
}
surface->updateConnectedEditors();
return nullptr;
}