mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Move to use a static registry of scriptable classes
This commit is contained in:
@@ -77,6 +77,14 @@ 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
|
||||
|
||||
@@ -19,16 +19,23 @@
|
||||
#include "RicfObjectCapability.h"
|
||||
#include "RicfFieldHandle.h"
|
||||
#include "RicfMessages.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmXmlFieldHandle.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
std::map<QString, QString> RicfObjectCapability::s_classKeywordToScriptClassName;
|
||||
std::map<QString, QString> RicfObjectCapability::s_scriptClassNameToClassKeyword;
|
||||
std::map<QString, QString> RicfObjectCapability::s_scriptClassComments;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfObjectCapability::RicfObjectCapability( caf::PdmObjectHandle* owner, bool giveOwnership )
|
||||
: m_owner( owner )
|
||||
{
|
||||
m_owner = owner;
|
||||
m_owner->addCapability( this, giveOwnership );
|
||||
}
|
||||
|
||||
@@ -216,3 +223,76 @@ 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 );
|
||||
}
|
||||
|
||||
@@ -19,8 +19,13 @@
|
||||
#pragma once
|
||||
#include "cafPdmObjectCapability.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObject;
|
||||
class PdmObjectHandle;
|
||||
class PdmObjectFactory;
|
||||
} // namespace caf
|
||||
@@ -43,6 +48,21 @@ 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