mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 14:40:26 -05:00
#12459 Add regular surface domain object.
This commit is contained in:
1 parent
b9ac1bc0c5
commit
1a55fa11c3
23 files changed
+1143
-31
No files matched your search
@@ -29,6 +29,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcPressureTable.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFishbonesCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcPolygonCollection.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcRegularSurface.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -62,6 +63,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcPressureTable.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcFishbonesCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcPolygonCollection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimcRegularSurface.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "RimcProject.h"
|
||||
|
||||
#include "Ensemble/RiaEnsembleImportTools.h"
|
||||
#include "KeyValueStore/RiaKeyValueStoreUtil.h"
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
@@ -271,34 +272,9 @@ std::expected<caf::PdmObjectHandle*, QString> RimProject_createGridFromKeyValues
|
||||
|
||||
auto keyValueStore = RiaApplication::instance()->keyValueStore();
|
||||
|
||||
auto convertToFloatVector = []( const std::optional<std::vector<char>>& input ) -> std::vector<float>
|
||||
{
|
||||
if ( input && !input->empty() )
|
||||
{
|
||||
// Ensure the byte vector size is a multiple of sizeof(float)
|
||||
if ( input->size() % sizeof( float ) != 0 )
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
// Calculate how many floats we'll have
|
||||
size_t float_count = input->size() / sizeof( float );
|
||||
|
||||
// Create a vector of floats with the appropriate size
|
||||
std::vector<float> float_vec( float_count );
|
||||
|
||||
// Copy the binary data from the byte vector to the float vector
|
||||
std::memcpy( float_vec.data(), input->data(), input->size() );
|
||||
|
||||
return float_vec;
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
std::vector<float> coord = convertToFloatVector( keyValueStore->get( m_coordKey().toStdString() ) );
|
||||
std::vector<float> zcorn = convertToFloatVector( keyValueStore->get( m_zcornKey().toStdString() ) );
|
||||
std::vector<float> actnum = convertToFloatVector( keyValueStore->get( m_actnumKey().toStdString() ) );
|
||||
std::vector<float> coord = RiaKeyValueStoreUtil::convertToFloatVector( keyValueStore->get( m_coordKey().toStdString() ) );
|
||||
std::vector<float> zcorn = RiaKeyValueStoreUtil::convertToFloatVector( keyValueStore->get( m_zcornKey().toStdString() ) );
|
||||
std::vector<float> actnum = RiaKeyValueStoreUtil::convertToFloatVector( keyValueStore->get( m_actnumKey().toStdString() ) );
|
||||
if ( coord.empty() || zcorn.empty() || actnum.empty() )
|
||||
{
|
||||
return std::unexpected( "Found unexcepted empty coord, zcorn or actnum array." );
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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::PdmObjectMethod( 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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcRegularSurface_setPropertyFromKey::resultIsPersistent() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimcRegularSurface_setPropertyFromKey::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( nullptr );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcRegularSurface_setPropertyFromKey::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimRegularSurface, RimcRegularSurface_setPropertyAsDepth, "SetPropertyAsDepth" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcRegularSurface_setPropertyAsDepth::RimcRegularSurface_setPropertyAsDepth( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( 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" );
|
||||
|
||||
if ( !surface->setPropertyAsDepth( m_name ) ) return std::unexpected( "Failed to set depth property." );
|
||||
|
||||
surface->onLoadData();
|
||||
|
||||
if ( auto coll = surface->firstAncestorOrThisOfType<RimSurfaceCollection>() )
|
||||
{
|
||||
coll->updateUiIconFromToggleField();
|
||||
coll->updateViews();
|
||||
coll->updateConnectedEditors();
|
||||
}
|
||||
surface->updateConnectedEditors();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcRegularSurface_setPropertyAsDepth::resultIsPersistent() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimcRegularSurface_setPropertyAsDepth::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( nullptr );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcRegularSurface_setPropertyAsDepth::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmObjectMethod.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcRegularSurface_setPropertyFromKey : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcRegularSurface_setPropertyFromKey( caf::PdmObjectHandle* self );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_name;
|
||||
caf::PdmField<QString> m_valueKey;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcRegularSurface_setPropertyAsDepth : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcRegularSurface_setPropertyAsDepth( caf::PdmObjectHandle* self );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_name;
|
||||
};
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "RimCase.h"
|
||||
#include "RimFileSurface.h"
|
||||
#include "RimGridCaseSurface.h"
|
||||
#include "RimRegularSurface.h"
|
||||
#include "RimSurface.h"
|
||||
#include "RimSurfaceCollection.h"
|
||||
|
||||
@@ -33,6 +34,7 @@
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSurfaceCollection, RimcSurfaceCollection_importSurface, "ImportSurface" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSurfaceCollection, RimcSurfaceCollection_addFolder, "AddFolder" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSurfaceCollection, RimcSurfaceCollection_newSurface, "NewSurface" );
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSurfaceCollection, RimcSurfaceCollection_newRegularSurface, "NewRegularSurface" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -182,3 +184,85 @@ bool RimcSurfaceCollection_newSurface::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcSurfaceCollection_newRegularSurface::RimcSurfaceCollection_newRegularSurface( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "New Regular Surface", "", "", "Create a new regular surface" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_name, "Name", QString( "" ), "Name" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_originX, "OriginX", 0.0, "Origin X" );
|
||||
CAF_PDM_InitScriptableField( &m_originY, "OriginY", 0.0, "Origin Y" );
|
||||
CAF_PDM_InitScriptableField( &m_depth, "Depth", 0.0, "Depth" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_nx, "Nx", 10, "Nx" );
|
||||
CAF_PDM_InitScriptableField( &m_ny, "Ny", 10, "Ny" );
|
||||
CAF_PDM_InitScriptableField( &m_incrementX, "IncrementX", 20.0, "Increment X" );
|
||||
CAF_PDM_InitScriptableField( &m_incrementY, "IncrementY", 20.0, "Increment Y" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_rotation, "Rotation", 0.0, "Rotation" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcSurfaceCollection_newRegularSurface::execute()
|
||||
{
|
||||
RimSurfaceCollection* coll = self<RimSurfaceCollection>();
|
||||
if ( !coll ) return std::unexpected( "No surface collection found" );
|
||||
|
||||
if ( m_nx() <= 0 ) return std::unexpected( "Invalid nx. Must be positive." );
|
||||
if ( m_ny() <= 0 ) return std::unexpected( "Invalid ny. Must be positive." );
|
||||
if ( m_incrementX() <= 0.0 ) return std::unexpected( "Invalid increment X. Must be positive." );
|
||||
if ( m_incrementY() <= 0.0 ) return std::unexpected( "Invalid increment Y. Must be positive." );
|
||||
if ( m_rotation() < 0.0 || m_rotation() > 360.0 ) return std::unexpected( "Invalid rotation. Valid range: [0.0-360.0]" );
|
||||
|
||||
RimRegularSurface* surface = new RimRegularSurface;
|
||||
surface->setUserDescription( m_name() );
|
||||
|
||||
surface->setNx( m_nx() );
|
||||
surface->setNy( m_ny() );
|
||||
surface->setOriginX( m_originX() );
|
||||
surface->setOriginY( m_originY() );
|
||||
surface->setDepth( m_depth() );
|
||||
surface->setIncrementX( m_incrementX() );
|
||||
surface->setIncrementY( m_incrementY() );
|
||||
surface->setRotation( m_rotation() );
|
||||
|
||||
surface->setColor( cvf::Color3f::BLUE );
|
||||
surface->setOpacity( true, 0.6f );
|
||||
|
||||
coll->addSurface( surface );
|
||||
coll->updateViews();
|
||||
coll->updateConnectedEditors();
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcSurfaceCollection_newRegularSurface::resultIsPersistent() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::unique_ptr<caf::PdmObjectHandle> RimcSurfaceCollection_newRegularSurface::defaultResult() const
|
||||
{
|
||||
return std::unique_ptr<caf::PdmObjectHandle>( new RimRegularSurface );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimcSurfaceCollection_newRegularSurface::isNullptrValidResult() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -90,3 +90,30 @@ private:
|
||||
caf::PdmPtrField<RimCase*> m_case;
|
||||
caf::PdmField<int> m_kIndex;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimcSurfaceCollection_newRegularSurface : public caf::PdmObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimcSurfaceCollection_newRegularSurface( caf::PdmObjectHandle* self );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
bool resultIsPersistent() const override;
|
||||
std::unique_ptr<PdmObjectHandle> defaultResult() const override;
|
||||
bool isNullptrValidResult() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_name;
|
||||
caf::PdmField<int> m_nx;
|
||||
caf::PdmField<int> m_ny;
|
||||
caf::PdmField<double> m_originX;
|
||||
caf::PdmField<double> m_originY;
|
||||
caf::PdmField<double> m_depth;
|
||||
caf::PdmField<double> m_incrementX;
|
||||
caf::PdmField<double> m_incrementY;
|
||||
caf::PdmField<double> m_rotation;
|
||||
};
|
||||
Reference in new issue
Block a user