mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5538 Python : Add methods at correct inheritance level
This commit is contained in:
parent
66081790dd
commit
bd5ce912fb
@ -33,6 +33,7 @@
|
|||||||
// for more details.
|
// for more details.
|
||||||
//
|
//
|
||||||
//##################################################################################################
|
//##################################################################################################
|
||||||
|
|
||||||
#include "cafPdmObjectMethod.h"
|
#include "cafPdmObjectMethod.h"
|
||||||
|
|
||||||
using namespace caf;
|
using namespace caf;
|
||||||
@ -47,11 +48,13 @@ PdmObjectMethodFactory* PdmObjectMethodFactory::instance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
/// Check the object and the inheritance stack for the specified method name
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
std::shared_ptr<PdmObjectMethod> PdmObjectMethodFactory::createMethod( PdmObjectHandle* self, const QString& methodName )
|
std::shared_ptr<PdmObjectMethod> PdmObjectMethodFactory::createMethod( PdmObjectHandle* self, const QString& methodName )
|
||||||
{
|
{
|
||||||
QString className = self->xmlCapability()->classKeyword();
|
auto stack = self->xmlCapability()->classInheritanceStack();
|
||||||
|
for ( auto className : stack )
|
||||||
|
{
|
||||||
auto classIt = m_factoryMap.find( className );
|
auto classIt = m_factoryMap.find( className );
|
||||||
if ( classIt != m_factoryMap.end() )
|
if ( classIt != m_factoryMap.end() )
|
||||||
{
|
{
|
||||||
@ -61,17 +64,17 @@ std::shared_ptr<PdmObjectMethod> PdmObjectMethodFactory::createMethod( PdmObject
|
|||||||
return methodIt->second->create( self );
|
return methodIt->second->create( self );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return std::shared_ptr<PdmObjectMethod>();
|
return std::shared_ptr<PdmObjectMethod>();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
/// Return the methods registered for the className. Does not investigate the inheritance stack
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
std::vector<QString> PdmObjectMethodFactory::registeredMethodNames( const PdmObjectHandle* self ) const
|
std::vector<QString> caf::PdmObjectMethodFactory::registeredMethodNames( const QString& className ) const
|
||||||
{
|
{
|
||||||
std::vector<QString> methods;
|
std::vector<QString> methods;
|
||||||
|
|
||||||
QString className = self->xmlCapability()->classKeyword();
|
|
||||||
auto classIt = m_factoryMap.find( className );
|
auto classIt = m_factoryMap.find( className );
|
||||||
if ( classIt != m_factoryMap.end() )
|
if ( classIt != m_factoryMap.end() )
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QString> registeredMethodNames( const PdmObjectHandle* self ) const;
|
std::vector<QString> registeredMethodNames( const QString& className ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PdmObjectMethodFactory() = default;
|
PdmObjectMethodFactory() = default;
|
||||||
|
@ -235,8 +235,10 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( QString methodName : PdmObjectMethodFactory::instance()->registeredMethodNames( object.get() ) )
|
for ( QString methodName : PdmObjectMethodFactory::instance()->registeredMethodNames( classKeyword ) )
|
||||||
{
|
{
|
||||||
std::shared_ptr<PdmObjectMethod> method =
|
std::shared_ptr<PdmObjectMethod> method =
|
||||||
PdmObjectMethodFactory::instance()->createMethod( object.get(), methodName );
|
PdmObjectMethodFactory::instance()->createMethod( object.get(), methodName );
|
||||||
@ -246,6 +248,9 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
|
|||||||
QString methodComment = method->uiCapability()->uiWhatsThis();
|
QString methodComment = method->uiCapability()->uiWhatsThis();
|
||||||
|
|
||||||
QString snake_method_name = camelToSnakeCase( methodName );
|
QString snake_method_name = camelToSnakeCase( methodName );
|
||||||
|
|
||||||
|
if ( classMethodsGenerated[classKeyword][snake_method_name].count() ) continue;
|
||||||
|
|
||||||
QStringList inputArgumentStrings;
|
QStringList inputArgumentStrings;
|
||||||
QStringList outputArgumentStrings;
|
QStringList outputArgumentStrings;
|
||||||
QStringList argumentComments;
|
QStringList argumentComments;
|
||||||
@ -267,10 +272,8 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
|
|||||||
if ( isList ) dataType = "List of " + dataType;
|
if ( isList ) dataType = "List of " + dataType;
|
||||||
inputArgumentStrings.push_back( QString( "%1=%2" ).arg( argumentName ).arg( defaultValue ) );
|
inputArgumentStrings.push_back( QString( "%1=%2" ).arg( argumentName ).arg( defaultValue ) );
|
||||||
outputArgumentStrings.push_back( QString( "%1=%1" ).arg( argumentName ) );
|
outputArgumentStrings.push_back( QString( "%1=%1" ).arg( argumentName ) );
|
||||||
argumentComments.push_back( QString( "%1 (%2): %3" )
|
argumentComments.push_back(
|
||||||
.arg( argumentName )
|
QString( "%1 (%2): %3" ).arg( argumentName ).arg( dataType ).arg( field->uiCapability()->uiWhatsThis() ) );
|
||||||
.arg( dataType )
|
|
||||||
.arg( field->uiCapability()->uiWhatsThis() ) );
|
|
||||||
}
|
}
|
||||||
QString fullComment = QString( " \"\"\"\n %1\n Arguments:\n "
|
QString fullComment = QString( " \"\"\"\n %1\n Arguments:\n "
|
||||||
"%2\n Returns:\n %3\n \"\"\"" )
|
"%2\n Returns:\n %3\n \"\"\"" )
|
||||||
@ -284,9 +287,8 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
|
|||||||
.arg( inputArgumentStrings.join( ", " ) )
|
.arg( inputArgumentStrings.join( ", " ) )
|
||||||
.arg( fullComment )
|
.arg( fullComment )
|
||||||
.arg( outputArgumentStrings.join( ", " ) );
|
.arg( outputArgumentStrings.join( ", " ) );
|
||||||
classMethodsGenerated[field->ownerClass()][snake_method_name] = methodCode;
|
|
||||||
}
|
classMethodsGenerated[classKeyword][snake_method_name] = methodCode;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user