#5538 Python : Add methods at correct inheritance level

This commit is contained in:
Magne Sjaastad 2020-04-01 09:03:45 +02:00 committed by Gaute Lindkvist
parent 66081790dd
commit bd5ce912fb
3 changed files with 68 additions and 63 deletions

View File

@ -33,6 +33,7 @@
// for more details.
//
//##################################################################################################
#include "cafPdmObjectMethod.h"
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 )
{
QString className = self->xmlCapability()->classKeyword();
auto stack = self->xmlCapability()->classInheritanceStack();
for ( auto className : stack )
{
auto classIt = m_factoryMap.find( className );
if ( classIt != m_factoryMap.end() )
{
@ -61,17 +64,17 @@ std::shared_ptr<PdmObjectMethod> PdmObjectMethodFactory::createMethod( PdmObject
return methodIt->second->create( self );
}
}
}
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;
QString className = self->xmlCapability()->classKeyword();
auto classIt = m_factoryMap.find( className );
if ( classIt != m_factoryMap.end() )
{

View File

@ -117,7 +117,7 @@ public:
return true;
}
std::vector<QString> registeredMethodNames( const PdmObjectHandle* self ) const;
std::vector<QString> registeredMethodNames( const QString& className ) const;
private:
PdmObjectMethodFactory() = default;

View File

@ -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 =
PdmObjectMethodFactory::instance()->createMethod( object.get(), methodName );
@ -246,6 +248,9 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
QString methodComment = method->uiCapability()->uiWhatsThis();
QString snake_method_name = camelToSnakeCase( methodName );
if ( classMethodsGenerated[classKeyword][snake_method_name].count() ) continue;
QStringList inputArgumentStrings;
QStringList outputArgumentStrings;
QStringList argumentComments;
@ -267,10 +272,8 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
if ( isList ) dataType = "List of " + dataType;
inputArgumentStrings.push_back( QString( "%1=%2" ).arg( argumentName ).arg( defaultValue ) );
outputArgumentStrings.push_back( QString( "%1=%1" ).arg( argumentName ) );
argumentComments.push_back( QString( "%1 (%2): %3" )
.arg( argumentName )
.arg( dataType )
.arg( field->uiCapability()->uiWhatsThis() ) );
argumentComments.push_back(
QString( "%1 (%2): %3" ).arg( argumentName ).arg( dataType ).arg( field->uiCapability()->uiWhatsThis() ) );
}
QString fullComment = QString( " \"\"\"\n %1\n Arguments:\n "
"%2\n Returns:\n %3\n \"\"\"" )
@ -284,9 +287,8 @@ QString PdmPythonGenerator::generate( PdmObjectFactory* factory ) const
.arg( inputArgumentStrings.join( ", " ) )
.arg( fullComment )
.arg( outputArgumentStrings.join( ", " ) );
classMethodsGenerated[field->ownerClass()][snake_method_name] = methodCode;
}
}
classMethodsGenerated[classKeyword][snake_method_name] = methodCode;
}
}
}