mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make scriptability a CAF-feature
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
#include "RiaTextStringTools.h"
|
||||
#include "cafPdmPythonGenerator.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -40,7 +40,7 @@ RicfCommandObject::~RicfCommandObject()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfCommandObject::pythonHelpString( const QString& existingTooltip, const QString& keyword )
|
||||
{
|
||||
QString snake_case = RiaTextStringTools::camelToSnakeCase( keyword );
|
||||
QString snake_case = caf::PdmPythonGenerator::camelToSnakeCase( keyword );
|
||||
|
||||
QString helpString = QString( "Available through python/rips as the attribute '%1'" ).arg( snake_case );
|
||||
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
#include "RicfCommandResponse.h"
|
||||
#include "RicfFieldCapability.h"
|
||||
#include "RicfObjectCapability.h"
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmObjectScriptabilityRegister.h"
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -77,14 +79,6 @@ public:
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
#define RICF_InitObject( uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitObject( uiName, iconResourceName, toolTip, whatsThis ); \
|
||||
RicfObjectCapability::addCapabilityToObject( this, classKeyword(), whatsThis );
|
||||
|
||||
#define RICF_InitObjectWithScriptNameAndComment( uiName, iconResourceName, toolTip, whatsThis, scriptClassName, scriptComment ) \
|
||||
CAF_PDM_InitObject( uiName, iconResourceName, toolTip, whatsThis ); \
|
||||
RicfObjectCapability::addCapabilityToObject( this, scriptClassName, scriptComment );
|
||||
|
||||
#define RICF_HEADER_INIT \
|
||||
CAF_CMD_HEADER_INIT; \
|
||||
CAF_PDM_HEADER_INIT
|
||||
|
||||
@@ -22,12 +22,9 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fieldName, bool giveOwnership )
|
||||
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& scriptFieldName, bool giveOwnership )
|
||||
: caf::PdmFieldScriptability( owner, scriptFieldName, giveOwnership )
|
||||
{
|
||||
m_IOWriteable = true;
|
||||
m_owner = owner;
|
||||
m_fieldName = fieldName;
|
||||
owner->addCapability( this, giveOwnership );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -36,11 +33,3 @@ RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fie
|
||||
RicfFieldHandle::~RicfFieldHandle()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RicfFieldHandle::fieldName() const
|
||||
{
|
||||
return m_fieldName;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
#include "cafPdmFieldCapability.h"
|
||||
#include "cafPdmFieldScriptability.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
@@ -36,18 +36,12 @@ class QTextStream;
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfFieldHandle : public caf::PdmFieldCapability
|
||||
class RicfFieldHandle : public caf::PdmFieldScriptability
|
||||
{
|
||||
public:
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fieldName, bool giveOwnership );
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& scriptFieldName, bool giveOwnership );
|
||||
~RicfFieldHandle() override;
|
||||
|
||||
const QString& fieldName() const;
|
||||
|
||||
bool isIOWriteable() const { return m_IOWriteable; }
|
||||
|
||||
void setIOWriteable( bool writeable ) { m_IOWriteable = writeable; }
|
||||
|
||||
virtual void readFieldData( QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory,
|
||||
RicfMessages* errorMessageContainer,
|
||||
|
||||
@@ -26,10 +26,6 @@
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
std::map<QString, QString> RicfObjectCapability::s_classKeywordToScriptClassName;
|
||||
std::map<QString, QString> RicfObjectCapability::s_scriptClassNameToClassKeyword;
|
||||
std::map<QString, QString> RicfObjectCapability::s_scriptClassComments;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -223,76 +219,3 @@ void RicfObjectCapability::writeFields( QTextStream& outputStream ) const
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfObjectCapability::registerScriptClassNameAndComment( const QString& classKeyword,
|
||||
const QString& scriptClassName,
|
||||
const QString& scriptClassComment )
|
||||
{
|
||||
s_classKeywordToScriptClassName[classKeyword] = scriptClassName;
|
||||
s_scriptClassNameToClassKeyword[scriptClassName] = classKeyword;
|
||||
s_scriptClassComments[classKeyword] = scriptClassComment;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfObjectCapability::scriptClassNameFromClassKeyword( const QString& classKeyword )
|
||||
{
|
||||
auto it = s_classKeywordToScriptClassName.find( classKeyword );
|
||||
if ( it != s_classKeywordToScriptClassName.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return classKeyword;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfObjectCapability::classKeywordFromScriptClassName( const QString& scriptClassName )
|
||||
{
|
||||
auto it = s_scriptClassNameToClassKeyword.find( scriptClassName );
|
||||
if ( it != s_scriptClassNameToClassKeyword.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return scriptClassName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfObjectCapability::scriptClassComment( const QString& classKeyword )
|
||||
{
|
||||
auto it = s_scriptClassComments.find( classKeyword );
|
||||
if ( it != s_scriptClassComments.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicfObjectCapability::isScriptable( const caf::PdmObject* object )
|
||||
{
|
||||
return s_classKeywordToScriptClassName.find( object->classKeyword() ) != s_classKeywordToScriptClassName.end();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfObjectCapability::addCapabilityToObject( caf::PdmObject* object,
|
||||
const QString& scriptClassName,
|
||||
const QString& scriptClassComment )
|
||||
{
|
||||
if ( !object->capability<RicfObjectCapability>() )
|
||||
{
|
||||
new RicfObjectCapability( object, true );
|
||||
}
|
||||
RicfObjectCapability::registerScriptClassNameAndComment( object->classKeyword(), scriptClassName, scriptClassComment );
|
||||
}
|
||||
|
||||
@@ -48,21 +48,6 @@ public:
|
||||
void readFields( QTextStream& inputStream, caf::PdmObjectFactory* objectFactory, RicfMessages* errorMessageContainer );
|
||||
void writeFields( QTextStream& outputStream ) const;
|
||||
|
||||
static void registerScriptClassNameAndComment( const QString& classKeyword,
|
||||
const QString& scriptClassName,
|
||||
const QString& scriptClassComment );
|
||||
static QString scriptClassNameFromClassKeyword( const QString& classKeyword );
|
||||
static QString classKeywordFromScriptClassName( const QString& scriptClassName );
|
||||
static QString scriptClassComment( const QString& classKeyword );
|
||||
|
||||
static bool isScriptable( const caf::PdmObject* object );
|
||||
static void
|
||||
addCapabilityToObject( caf::PdmObject* object, const QString& scriptClassName, const QString& scriptClassComment );
|
||||
|
||||
private:
|
||||
caf::PdmObjectHandle* m_owner;
|
||||
|
||||
static std::map<QString, QString> s_classKeywordToScriptClassName;
|
||||
static std::map<QString, QString> s_scriptClassNameToClassKeyword;
|
||||
static std::map<QString, QString> s_scriptClassComments;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user