-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathRimcCornerPointCase.cpp
More file actions
117 lines (97 loc) · 4.74 KB
/
RimcCornerPointCase.cpp
File metadata and controls
117 lines (97 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimcCornerPointCase.h"
#include "RiaApplication.h"
#include "RiaKeyValueStoreUtil.h"
#include "RiaViewRedrawScheduler.h"
#include "Rim3dView.h"
#include "RimCornerPointCase.h"
#include "RimEclipseView.h"
#include "cafPdmFieldScriptingCapability.h"
#include <expected>
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimCornerPointCase, RimcCornerPointCase_replaceCornerPointGridInternal, "replace_corner_point_grid_internal" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcCornerPointCase_replaceCornerPointGridInternal::RimcCornerPointCase_replaceCornerPointGridInternal( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Replace Corner Point Grid", "", "", "Replace Corner Point Grid" );
CAF_PDM_InitScriptableFieldNoDefault( &m_nx, "Nx", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_ny, "Ny", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_nz, "Nz", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_coordKey, "CoordKey", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_zcornKey, "ZcornKey", "" );
CAF_PDM_InitScriptableFieldNoDefault( &m_actnumKey, "ActnumKey", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimcCornerPointCase_replaceCornerPointGridInternal::execute()
{
auto cornerPointCase = self<RimCornerPointCase>();
if ( !cornerPointCase )
{
return std::unexpected( "Unable to get corner point case." );
}
int nx = m_nx();
int ny = m_ny();
int nz = m_nz();
if ( nx <= 0 || ny <= 0 || nz <= 0 )
{
return std::unexpected( "Invalid grid dimensions. nx, ny and nz must be positive." );
}
auto keyValueStore = RiaApplication::instance()->keyValueStore();
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 unexpected empty coord, zcorn or actnum array." );
}
// Block view updates while the grid is being replaced.
RiaViewRedrawScheduler::instance()->clearViewsScheduledForUpdate();
RiaViewRedrawScheduler::instance()->blockUpdate( true );
// Create a new corner point grid from the provided geometry
auto result = RimCornerPointCase::replaceGridFromCoordinatesArray( *cornerPointCase, nx, ny, nz, coord, zcorn, actnum );
if ( !result.has_value() )
{
RiaViewRedrawScheduler::instance()->blockUpdate( false );
return std::unexpected( "Failed to replace grid" );
}
// Update all 3D views to reflect the new grid
// We must completely reinitialize the views because the grid size has changed
std::vector<Rim3dView*> views = cornerPointCase->views();
for ( Rim3dView* view : views )
{
if ( RimEclipseView* eclView = dynamic_cast<RimEclipseView*>( view ) )
{
// Force complete regeneration by calling loadDataAndUpdate
// This will reinitialize all geometry managers with the new grid size
eclView->loadDataAndUpdate();
}
}
RiaViewRedrawScheduler::instance()->blockUpdate( false );
// Update connected editors
cornerPointCase->updateConnectedEditors();
// Clean up key-value store
keyValueStore->remove( m_coordKey().toStdString() );
keyValueStore->remove( m_zcornKey().toStdString() );
keyValueStore->remove( m_actnumKey().toStdString() );
return nullptr;
}