mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Move some more scriptability to caf
This commit is contained in:
@@ -34,16 +34,3 @@ RicfCommandObject::RicfCommandObject()
|
||||
RicfCommandObject::~RicfCommandObject()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfCommandObject::pythonHelpString( const QString& existingTooltip, const QString& keyword )
|
||||
{
|
||||
QString snake_case = caf::PdmPythonGenerator::camelToSnakeCase( keyword );
|
||||
|
||||
QString helpString = QString( "Available through python/rips as the attribute '%1'" ).arg( snake_case );
|
||||
|
||||
if ( !existingTooltip.isEmpty() ) return existingTooltip + "\n\n" + helpString;
|
||||
return helpString;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmObjectScriptabilityRegister.h"
|
||||
#include "cafPdmPythonGenerator.h"
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -37,8 +38,6 @@ public:
|
||||
~RicfCommandObject() override;
|
||||
|
||||
virtual RicfCommandResponse execute() = 0;
|
||||
|
||||
static QString pythonHelpString( const QString& existingTooltip, const QString& keyword );
|
||||
};
|
||||
|
||||
#define RICF_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
@@ -47,7 +46,7 @@ public:
|
||||
default, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, keyword ), \
|
||||
caf::PdmPythonGenerator::pythonHelpString( toolTip, keyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, keyword )
|
||||
|
||||
@@ -56,7 +55,7 @@ public:
|
||||
keyword, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, keyword ), \
|
||||
caf::PdmPythonGenerator::pythonHelpString( toolTip, keyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, keyword )
|
||||
|
||||
@@ -66,7 +65,7 @@ public:
|
||||
default, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
caf::PdmPythonGenerator::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
@@ -75,7 +74,7 @@ public:
|
||||
keyword, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
caf::PdmPythonGenerator::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
template <typename DataType>
|
||||
struct RicfFieldIOHandler
|
||||
{
|
||||
static void writeToField( DataType& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
static void writeToField( DataType& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true )
|
||||
bool stringsAreQuoted = true )
|
||||
{
|
||||
inputStream >> fieldValue;
|
||||
if ( inputStream.status() == QTextStream::ReadCorruptData )
|
||||
@@ -72,10 +72,10 @@ struct RicfFieldIOHandler<QString>
|
||||
template <>
|
||||
struct RicfFieldIOHandler<bool>
|
||||
{
|
||||
static void writeToField( bool& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
static void writeToField( bool& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true );
|
||||
bool stringsAreQuoted = true );
|
||||
static void readFromField( const bool& fieldValue,
|
||||
QTextStream& outputStream,
|
||||
bool quoteStrings = true,
|
||||
@@ -85,10 +85,10 @@ struct RicfFieldIOHandler<bool>
|
||||
template <>
|
||||
struct RicfFieldIOHandler<cvf::Color3f>
|
||||
{
|
||||
static void writeToField( cvf::Color3f& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
static void writeToField( cvf::Color3f& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true );
|
||||
bool stringsAreQuoted = true );
|
||||
static void readFromField( const cvf::Color3f& fieldValue,
|
||||
QTextStream& outputStream,
|
||||
bool quoteStrings = true,
|
||||
@@ -98,10 +98,10 @@ struct RicfFieldIOHandler<cvf::Color3f>
|
||||
template <typename T>
|
||||
struct RicfFieldIOHandler<caf::AppEnum<T>>
|
||||
{
|
||||
static void writeToField( caf::AppEnum<T>& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
static void writeToField( caf::AppEnum<T>& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true )
|
||||
bool stringsAreQuoted = true )
|
||||
{
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
||||
QString accumulatedFieldValue;
|
||||
@@ -149,10 +149,10 @@ struct RicfFieldIOHandler<caf::AppEnum<T>>
|
||||
template <typename T>
|
||||
struct RicfFieldIOHandler<std::vector<T>>
|
||||
{
|
||||
static void writeToField( std::vector<T>& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
static void writeToField( std::vector<T>& fieldValue,
|
||||
QTextStream& inputStream,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true )
|
||||
bool stringsAreQuoted = true )
|
||||
{
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
||||
QChar chr = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
||||
@@ -221,10 +221,10 @@ public:
|
||||
|
||||
// Xml Serializing
|
||||
public:
|
||||
void readFieldData( QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true ) override
|
||||
void writeToField( QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true ) override
|
||||
{
|
||||
typename FieldType::FieldDataType value;
|
||||
RicfFieldIOHandler<typename FieldType::FieldDataType>::writeToField( value,
|
||||
@@ -238,7 +238,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void writeFieldData( QTextStream& outputStream, bool quoteStrings = true, bool quoteNonBuiltins = false ) const override
|
||||
void readFromField( QTextStream& outputStream, bool quoteStrings = true, bool quoteNonBuiltins = false ) const override
|
||||
{
|
||||
RicfFieldIOHandler<typename FieldType::FieldDataType>::readFromField( m_field->value(),
|
||||
outputStream,
|
||||
|
||||
@@ -41,11 +41,6 @@ public:
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& scriptFieldName, bool giveOwnership );
|
||||
~RicfFieldHandle() override;
|
||||
|
||||
virtual void readFieldData( QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory,
|
||||
caf::PdmScriptIOMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true ) = 0;
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* m_owner;
|
||||
QString m_fieldName;
|
||||
|
||||
@@ -136,7 +136,7 @@ void RicfObjectCapability::readFields( QTextStream& inputStream,
|
||||
if ( xmlFieldHandle->isIOReadable() )
|
||||
{
|
||||
errorMessageContainer->currentArgument = keyword;
|
||||
rcfField->readFieldData( inputStream, objectFactory, errorMessageContainer );
|
||||
rcfField->writeToField( inputStream, objectFactory, errorMessageContainer );
|
||||
errorMessageContainer->currentArgument = keyword;
|
||||
}
|
||||
}
|
||||
@@ -213,7 +213,7 @@ void RicfObjectCapability::writeFields( QTextStream& outputStream ) const
|
||||
}
|
||||
|
||||
outputStream << keyword << " = ";
|
||||
rcfField->writeFieldData( outputStream );
|
||||
rcfField->readFromField( outputStream );
|
||||
|
||||
writtenFieldCount++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user