mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#7940 Python : Traverse inheritance stack to find correct script class name
This commit is contained in:
parent
16ec5f793a
commit
b397c230ac
@ -2082,6 +2082,8 @@ std::vector<double> RimEclipseView::currentCellResultData() const
|
||||
std::vector<double> resultData;
|
||||
if ( currentGridCellResults() && cellResult() )
|
||||
{
|
||||
if ( !currentGridCellResults()->hasResultEntry( cellResult()->eclipseResultAddress() ) ) return {};
|
||||
|
||||
int timeStep = 0;
|
||||
if ( cellResult()->hasDynamicResult() )
|
||||
{
|
||||
@ -2097,7 +2099,7 @@ std::vector<double> RimEclipseView::currentCellResultData() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseView::setCurrentCellResultData( const std::vector<double>& values )
|
||||
{
|
||||
if ( currentGridCellResults() && cellResult() )
|
||||
if ( !values.empty() && currentGridCellResults() && cellResult() )
|
||||
{
|
||||
int timeStep = 0;
|
||||
if ( cellResult()->hasDynamicResult() )
|
||||
|
@ -520,7 +520,6 @@ const RigActiveCellInfo* RigCaseCellResultsData::activeCellInfo() const
|
||||
void RigCaseCellResultsData::recalculateStatistics( const RigEclipseResultAddress& resVarAddr )
|
||||
{
|
||||
size_t scalarResultIndex = findScalarResultIndexFromAddress( resVarAddr );
|
||||
CVF_TIGHT_ASSERT( scalarResultIndex < m_cellScalarResults.size() );
|
||||
if ( scalarResultIndex < m_cellScalarResults.size() )
|
||||
{
|
||||
m_statisticsDataCache[scalarResultIndex]->clearAllStatistics();
|
||||
|
@ -99,5 +99,13 @@ QString PdmObjectScriptingCapabilityRegister::scriptClassComment( const QString&
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmObjectScriptingCapabilityRegister::isScriptable( const caf::PdmObject* object )
|
||||
{
|
||||
return s_classKeywordToScriptClassName.find( object->classKeyword() ) != s_classKeywordToScriptClassName.end();
|
||||
return isScriptable( object->classKeyword() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmObjectScriptingCapabilityRegister::isScriptable( const QString& classKeyword )
|
||||
{
|
||||
return s_classKeywordToScriptClassName.find( classKeyword ) != s_classKeywordToScriptClassName.end();
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
static QString scriptClassComment( const QString& classKeyword );
|
||||
|
||||
static bool isScriptable( const caf::PdmObject* object );
|
||||
static bool isScriptable( const QString& classKeyword );
|
||||
|
||||
private:
|
||||
static std::map<QString, QString> s_classKeywordToScriptClassName;
|
||||
|
@ -73,15 +73,39 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips( const caf::PdmObjectHa
|
||||
CAF_ASSERT( source && destination && source->xmlCapability() );
|
||||
|
||||
QString classKeyword = source->xmlCapability()->classKeyword();
|
||||
QString scriptName = caf::PdmObjectScriptingCapabilityRegister::scriptClassNameFromClassKeyword( classKeyword );
|
||||
destination->set_class_keyword( scriptName.toStdString() );
|
||||
|
||||
QString scriptClassName;
|
||||
|
||||
// Find first scriptable object in inheritance stack
|
||||
{
|
||||
auto pdmObject = dynamic_cast<const caf::PdmObject*>( source );
|
||||
auto classKeywordStack = pdmObject->classInheritanceStack();
|
||||
|
||||
// Reverse to get leaf node first
|
||||
classKeywordStack.reverse();
|
||||
|
||||
for ( const auto& candidateClassKeyword : classKeywordStack )
|
||||
{
|
||||
if ( caf::PdmObjectScriptingCapabilityRegister::isScriptable( candidateClassKeyword ) )
|
||||
{
|
||||
scriptClassName =
|
||||
caf::PdmObjectScriptingCapabilityRegister::scriptClassNameFromClassKeyword( candidateClassKeyword );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to source object class name
|
||||
if ( scriptClassName.isEmpty() ) scriptClassName = classKeyword;
|
||||
}
|
||||
|
||||
destination->set_class_keyword( scriptClassName.toStdString() );
|
||||
destination->set_address( reinterpret_cast<uint64_t>( source ) );
|
||||
|
||||
bool visible = true;
|
||||
if ( source->uiCapability() && source->uiCapability()->objectToggleField() )
|
||||
{
|
||||
const caf::PdmField<bool>* boolField =
|
||||
dynamic_cast<const caf::PdmField<bool>*>( source->uiCapability()->objectToggleField() );
|
||||
const auto* boolField = dynamic_cast<const caf::PdmField<bool>*>( source->uiCapability()->objectToggleField() );
|
||||
if ( boolField )
|
||||
{
|
||||
visible = boolField->value();
|
||||
@ -124,8 +148,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject*
|
||||
|
||||
if ( destination->uiCapability() && destination->uiCapability()->objectToggleField() )
|
||||
{
|
||||
caf::PdmField<bool>* boolField =
|
||||
dynamic_cast<caf::PdmField<bool>*>( destination->uiCapability()->objectToggleField() );
|
||||
auto* boolField = dynamic_cast<caf::PdmField<bool>*>( destination->uiCapability()->objectToggleField() );
|
||||
if ( boolField )
|
||||
{
|
||||
QVariant oldValue = boolField->toQVariant();
|
||||
@ -185,7 +208,7 @@ bool RiaGrpcServiceInterface::assignFieldValue( const QString& stringValue
|
||||
auto scriptability = field->template capability<caf::PdmAbstractFieldScriptingCapability>();
|
||||
if ( field && scriptability != nullptr )
|
||||
{
|
||||
caf::PdmValueField* valueField = dynamic_cast<caf::PdmValueField*>( field );
|
||||
auto* valueField = dynamic_cast<caf::PdmValueField*>( field );
|
||||
QTextStream stream( stringValue.toLatin1() );
|
||||
caf::PdmScriptIOMessages messages;
|
||||
if ( valueField ) *oldValue = valueField->toQVariant();
|
||||
|
Loading…
Reference in New Issue
Block a user