Add temporary object collection for dynamically created Pdm objects

Adds a mechanism to manage temporary objects and ensures they are cleared when a project is closed. If a Pdm object is created and not stored in the project, the object can be added to the temporary object collection. This makes the object available from Python.
This commit is contained in:
Magne Sjaastad committed 2025-08-18 08:58:38 +02:00
1 parent a646b53ca6
commit fd4075dd97
6 files changed
+136 -11

No files matched your search

@@ -106,6 +106,7 @@
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RimWellPathFracture.h"
#include "Tools/RimTemporaryObjectCollection.h"
#include "VerticalFlowPerformance/RimVfpDataCollection.h"
#include "VerticalFlowPerformance/RimVfpPlotCollection.h"
@@ -1002,6 +1003,8 @@ void RiaApplication::closeProject()
RiaWellNameComparer::clearCache();
RimTemporaryObjectCollection::instance()->clearTemporaryObjects();
onProjectClosed();
caf::PdmUiModelChangeDetector::instance()->reset();
@@ -2,12 +2,14 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaVariableMapper.h
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisTools.h
${CMAKE_CURRENT_LIST_DIR}/RimAutomationSettings.h
${CMAKE_CURRENT_LIST_DIR}/RimTemporaryObjectCollection.h
)
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaVariableMapper.cpp
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RimAutomationSettings.cpp
${CMAKE_CURRENT_LIST_DIR}/RimTemporaryObjectCollection.cpp
)
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
@@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimTemporaryObjectCollection.h"
CAF_PDM_SOURCE_INIT( RimTemporaryObjectCollection, "RimTemporaryObjectCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimTemporaryObjectCollection::RimTemporaryObjectCollection()
{
CAF_PDM_InitObject( "Temporary Object Collection" );
CAF_PDM_InitFieldNoDefault( &m_temporaryObjects, "TemporaryObjects", "Temporary Objects" );
m_temporaryObjects.xmlCapability()->disableIO();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimTemporaryObjectCollection* RimTemporaryObjectCollection::instance()
{
static RimTemporaryObjectCollection staticInstance;
return &staticInstance;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimTemporaryObjectCollection::addTemporaryObject( caf::PdmObject* object )
{
m_temporaryObjects.push_back( object );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimTemporaryObjectCollection::clearTemporaryObjects()
{
m_temporaryObjects.deleteChildren();
}
@@ -0,0 +1,42 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafPdmChildArrayField.h"
#include "cafPdmObject.h"
//==================================================================================================
///
///
//==================================================================================================
class RimTemporaryObjectCollection : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimTemporaryObjectCollection();
static RimTemporaryObjectCollection* instance();
void addTemporaryObject( caf::PdmObject* object );
void clearTemporaryObjects();
private:
caf::PdmChildArrayField<caf::PdmObject*> m_temporaryObjects;
};
@@ -25,6 +25,7 @@
#include "RimProject.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "Tools/RimTemporaryObjectCollection.h"
#include "WellPathCommands/RicImportWellPaths.h"
@@ -89,7 +90,7 @@ CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimWellPathCollection, RimcWellPathCollection
///
//--------------------------------------------------------------------------------------------------
RimcWellPathCollection_wellCompletions::RimcWellPathCollection_wellCompletions( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self, PdmObjectMethod::NullPointerType::NULL_IS_INVALID, PdmObjectMethod::ResultType::PERSISTENT_FALSE )
: caf::PdmObjectMethod( self, PdmObjectMethod::NullPointerType::NULL_IS_INVALID, PdmObjectMethod::ResultType::PERSISTENT_TRUE )
{
CAF_PDM_InitObject( "Well Completions" );
CAF_PDM_InitScriptableFieldNoDefault( &m_wellName, "WellName", "Name of Well" );
@@ -129,6 +130,8 @@ std::expected<caf::PdmObjectHandle*, QString> RimcWellPathCollection_wellComplet
{
if ( auto completionData = modWellPath->completionData( eCase ) )
{
RimTemporaryObjectCollection::instance()->addTemporaryObject( completionData );
return completionData;
}
else
+27 -10
View File
@@ -22,6 +22,7 @@
#include "RimCase.h"
#include "RimCommandRouter.h"
#include "RimProject.h"
#include "Tools/RimTemporaryObjectCollection.h"
#include "PdmObject.pb.h"
@@ -65,20 +66,36 @@ caf::PdmObject* RiaGrpcHelper::findCafObjectFromScriptNameAndAddress( const QStr
if ( classKeyword == RimCommandRouter::classKeywordStatic() ) return RiaApplication::instance()->commandRouter();
RimProject* project = RimProject::current();
std::vector<caf::PdmObject*> objectsOfCurrentClass;
project->descendantsIncludingThisFromClassKeyword( classKeyword, objectsOfCurrentClass );
caf::PdmObject* matchingObject = nullptr;
for ( caf::PdmObject* testObject : objectsOfCurrentClass )
{
if ( reinterpret_cast<uint64_t>( testObject ) == address )
RimProject* project = RimProject::current();
std::vector<caf::PdmObject*> objectsOfCurrentClass;
project->descendantsIncludingThisFromClassKeyword( classKeyword, objectsOfCurrentClass );
for ( caf::PdmObject* testObject : objectsOfCurrentClass )
{
matchingObject = testObject;
if ( reinterpret_cast<uint64_t>( testObject ) == address )
{
return testObject;
}
}
}
return matchingObject;
{
std::vector<caf::PdmObject*> objectsOfCurrentClass;
RimTemporaryObjectCollection::instance()->descendantsIncludingThisFromClassKeyword( classKeyword,
objectsOfCurrentClass );
for ( caf::PdmObject* testObject : objectsOfCurrentClass )
{
if ( reinterpret_cast<uint64_t>( testObject ) == address )
{
return testObject;
}
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------