mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
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.
125 lines
4.7 KiB
C++
125 lines
4.7 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2020- 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 "RiaGrpcHelper.h"
|
|
|
|
#include "RiaApplication.h"
|
|
#include "RimCase.h"
|
|
#include "RimCommandRouter.h"
|
|
#include "RimProject.h"
|
|
#include "Tools/RimTemporaryObjectCollection.h"
|
|
|
|
#include "PdmObject.pb.h"
|
|
|
|
#include "cafPdmObjectScriptingCapabilityRegister.h"
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
/// Convert internal ResInsight representation of cells with negative depth to positive depth.
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiaGrpcHelper::convertVec3dToPositiveDepth( cvf::Vec3d* vec )
|
|
{
|
|
double& z = vec->z();
|
|
z *= -1;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RiaGrpcHelper::setCornerValues( rips::Vec3d* out, const cvf::Vec3d& in )
|
|
{
|
|
out->set_x( in.x() );
|
|
out->set_y( in.y() );
|
|
out->set_z( in.z() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::PdmObject* RiaGrpcHelper::findCafObjectFromRipsObject( const rips::PdmObject& ripsObject )
|
|
{
|
|
QString scriptClassName = QString::fromStdString( ripsObject.class_keyword() );
|
|
uint64_t address = ripsObject.address();
|
|
return findCafObjectFromScriptNameAndAddress( scriptClassName, address );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::PdmObject* RiaGrpcHelper::findCafObjectFromScriptNameAndAddress( const QString& scriptClassName, uint64_t address )
|
|
{
|
|
QString classKeyword = caf::PdmObjectScriptingCapabilityRegister::classKeywordFromScriptClassName( scriptClassName );
|
|
|
|
if ( classKeyword == RimCommandRouter::classKeywordStatic() ) return RiaApplication::instance()->commandRouter();
|
|
|
|
{
|
|
RimProject* project = RimProject::current();
|
|
std::vector<caf::PdmObject*> objectsOfCurrentClass;
|
|
|
|
project->descendantsIncludingThisFromClassKeyword( classKeyword, objectsOfCurrentClass );
|
|
for ( caf::PdmObject* testObject : objectsOfCurrentClass )
|
|
{
|
|
if ( reinterpret_cast<uint64_t>( testObject ) == address )
|
|
{
|
|
return testObject;
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
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;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
size_t RiaGrpcHelper::numberOfDataUnitsInPackage( size_t dataUnitSize, size_t packageByteCount /*= 64 * 1024u */ )
|
|
{
|
|
size_t dataUnitCount = packageByteCount / dataUnitSize;
|
|
return dataUnitCount;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimCase* RiaGrpcHelper::findCase( int caseId )
|
|
{
|
|
std::vector<RimCase*> cases = RimProject::current()->allGridCases();
|
|
for ( RimCase* rimCase : cases )
|
|
{
|
|
if ( caseId == rimCase->caseId() )
|
|
{
|
|
return rimCase;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|