mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add separate scriptKeyword to RICF capability and a Python help tooltip system
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -54,3 +55,17 @@ QString RiaTextStringTools::trimAndRemoveDoubleSpaces( const QString& s )
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaTextStringTools::camelToSnakeCase( const QString& camelString )
|
||||
{
|
||||
static QRegularExpression re1( "(.)([A-Z][a-z]+)" );
|
||||
static QRegularExpression re2( "([a-z0-9])([A-Z])" );
|
||||
|
||||
QString snake_case = camelString;
|
||||
snake_case.replace( re1, "\\1_\\2" );
|
||||
snake_case.replace( re2, "\\1_\\2" );
|
||||
return snake_case.toLower();
|
||||
}
|
||||
|
||||
@@ -27,4 +27,5 @@ namespace RiaTextStringTools
|
||||
{
|
||||
bool compare( const QString& expected, const QString& actual );
|
||||
QString trimAndRemoveDoubleSpaces( const QString& s );
|
||||
QString camelToSnakeCase( const QString& camelString );
|
||||
} // namespace RiaTextStringTools
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -32,3 +34,16 @@ RicfCommandObject::RicfCommandObject()
|
||||
RicfCommandObject::~RicfCommandObject()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfCommandObject::pythonHelpString( const QString& existingTooltip, const QString& keyword )
|
||||
{
|
||||
QString snake_case = RiaTextStringTools::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;
|
||||
}
|
||||
|
||||
@@ -23,13 +23,59 @@
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCommandObject : public caf::PdmObject, public RicfObjectCapability
|
||||
{
|
||||
public:
|
||||
RicfCommandObject();
|
||||
~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 ) \
|
||||
CAF_PDM_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ); \
|
||||
AddRicfCapabilityToField( field )
|
||||
CAF_PDM_InitField( field, \
|
||||
keyword, \
|
||||
default, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, keyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, keyword )
|
||||
|
||||
#define RICF_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ); \
|
||||
AddRicfCapabilityToField( field )
|
||||
CAF_PDM_InitFieldNoDefault( field, \
|
||||
keyword, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, keyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, keyword )
|
||||
|
||||
#define RICF_InitFieldTranslated( field, keyword, scriptKeyword, default, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitField( field, \
|
||||
keyword, \
|
||||
default, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
#define RICF_InitFieldNoDefaultTranslated( field, keyword, scriptKeyword, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitFieldNoDefault( field, \
|
||||
keyword, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
#define RICF_HEADER_INIT \
|
||||
CAF_CMD_HEADER_INIT; \
|
||||
@@ -44,17 +90,3 @@
|
||||
} \
|
||||
CAF_FACTORY_REGISTER2( caf::CmdFeature, ClassName, std::string, ClassName::idNameStatic() ); \
|
||||
CAF_PDM_SOURCE_INIT( ClassName, CommandKeyword )
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCommandObject : public caf::PdmObject, public RicfObjectCapability
|
||||
{
|
||||
public:
|
||||
RicfCommandObject();
|
||||
~RicfCommandObject() override;
|
||||
|
||||
virtual RicfCommandResponse execute() = 0;
|
||||
};
|
||||
|
||||
@@ -215,8 +215,8 @@ template <typename FieldType>
|
||||
class RicfFieldCapability : public RicfFieldHandle
|
||||
{
|
||||
public:
|
||||
RicfFieldCapability( FieldType* field, bool giveOwnership )
|
||||
: RicfFieldHandle( field, giveOwnership )
|
||||
RicfFieldCapability( FieldType* field, const QString& fieldName, bool giveOwnership )
|
||||
: RicfFieldHandle( field, fieldName, giveOwnership )
|
||||
{
|
||||
m_field = field;
|
||||
}
|
||||
@@ -250,10 +250,10 @@ private:
|
||||
};
|
||||
|
||||
template <typename FieldType>
|
||||
void AddRicfCapabilityToField( FieldType* field )
|
||||
void AddRicfCapabilityToField( FieldType* field, const QString& fieldName )
|
||||
{
|
||||
if ( field->template capability<RicfFieldCapability<FieldType>>() == nullptr )
|
||||
{
|
||||
new RicfFieldCapability<FieldType>( field, true );
|
||||
new RicfFieldCapability<FieldType>( field, fieldName, true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership )
|
||||
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fieldName, bool giveOwnership )
|
||||
{
|
||||
m_IOWriteable = true;
|
||||
m_owner = owner;
|
||||
m_fieldName = fieldName;
|
||||
owner->addCapability( this, giveOwnership );
|
||||
}
|
||||
|
||||
@@ -35,3 +36,11 @@ RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership
|
||||
RicfFieldHandle::~RicfFieldHandle()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RicfFieldHandle::fieldName() const
|
||||
{
|
||||
return m_fieldName;
|
||||
}
|
||||
|
||||
@@ -39,9 +39,11 @@ class QTextStream;
|
||||
class RicfFieldHandle : public caf::PdmFieldCapability
|
||||
{
|
||||
public:
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership );
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fieldName, bool giveOwnership );
|
||||
~RicfFieldHandle() override;
|
||||
|
||||
const QString& fieldName() const;
|
||||
|
||||
bool isIOWriteable() const { return m_IOWriteable; }
|
||||
|
||||
void setIOWriteable( bool writeable ) { m_IOWriteable = writeable; }
|
||||
@@ -54,5 +56,6 @@ public:
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* m_owner;
|
||||
QString m_fieldName;
|
||||
bool m_IOWriteable;
|
||||
};
|
||||
|
||||
@@ -100,7 +100,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips( const caf::PdmObjectHa
|
||||
QString text;
|
||||
QTextStream outStream( &text );
|
||||
ricfHandle->writeFieldData( outStream, false );
|
||||
( *parametersMap )[keyword.toStdString()] = text.toStdString();
|
||||
( *parametersMap )[ricfHandle->fieldName().toStdString()] = text.toStdString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips( const caf::PdmObjectHa
|
||||
void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject* source, caf::PdmObjectHandle* destination )
|
||||
{
|
||||
CAF_ASSERT( source && destination && destination->xmlCapability() );
|
||||
CAF_ASSERT( source->class_keyword() == destination->xmlCapability()->classKeyword().toStdString() );
|
||||
CAF_ASSERT( destination->xmlCapability()->matchesClassKeyword( QString::fromStdString( source->class_keyword() ) ) );
|
||||
|
||||
if ( destination->uiCapability() && destination->uiCapability()->objectToggleField() )
|
||||
{
|
||||
@@ -139,7 +139,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject*
|
||||
auto ricfHandle = pdmValueField->template capability<RicfFieldHandle>();
|
||||
if ( ricfHandle )
|
||||
{
|
||||
QString keyword = pdmValueField->keyword();
|
||||
QString keyword = ricfHandle->fieldName();
|
||||
QString value = QString::fromStdString( parametersMap[keyword.toStdString()] );
|
||||
|
||||
QVariant oldValue, newValue;
|
||||
|
||||
Reference in New Issue
Block a user