void Serialisation::walk( const Gaffer::GraphComponent *parent, const std::string &parentIdentifier )
{
    const Serialiser *parentSerialiser = serialiser( parent );

    parentSerialiser->moduleDependencies( parent, m_modules );
    m_hierarchyScript += parentSerialiser->postConstructor( parent, parentIdentifier, *this );
    m_connectionScript += parentSerialiser->postHierarchy( parent, parentIdentifier, *this );
    m_postScript += parentSerialiser->postScript( parent, parentIdentifier, *this );

    for( GraphComponent::ChildIterator it = parent->children().begin(), eIt = parent->children().end(); it != eIt; it++ )
    {
        const GraphComponent *child = it->get();
        if( !parentSerialiser->childNeedsSerialisation( child ) )
        {
            continue;
        }
        if( parentSerialiser->childNeedsConstruction( child ) )
        {
            const Serialiser *childSerialiser = serialiser( child );
            m_hierarchyScript += parentIdentifier + ".addChild( " + childSerialiser->constructor( child ) + " )\n";
        }
        std::string childIdentifier = parentIdentifier + "[\"" + child->getName().string() + "\"]";
        walk( child, childIdentifier );
    }
}
Serialisation::Serialisation( const Gaffer::GraphComponent *parent, const std::string &parentName, const Gaffer::Set *filter )
    :	m_parent( parent ), m_parentName( parentName ), m_filter( filter )
{
    IECorePython::ScopedGILLock gilLock;

    const Serialiser *parentSerialiser = serialiser( parent );
    for( GraphComponent::ChildIterator it = parent->children().begin(), eIt = parent->children().end(); it != eIt; it++ )
    {
        const GraphComponent *child = it->get();
        if( m_filter && !m_filter->contains( child ) )
        {
            continue;
        }
        if( !parentSerialiser->childNeedsSerialisation( child ) )
        {
            continue;
        }

        std::string childIdentifier;
        if( parentSerialiser->childNeedsConstruction( child ) )
        {
            const Serialiser *childSerialiser = serialiser( child );
            childIdentifier = "__children[\"" + child->getName().string() + "\"]";
            m_hierarchyScript += childIdentifier + " = " + childSerialiser->constructor( child ) + "\n";
            m_hierarchyScript += parentName + ".addChild( " + childIdentifier + " )\n";
        }
        else
        {
            childIdentifier = parentName + "[\"" + child->getName().string() + "\"]";
        }
        walk( child, childIdentifier );
    }
}
Exemplo n.º 3
0
void Serialisation::walk( const Gaffer::GraphComponent *parent, const std::string &parentIdentifier, const Serialiser *parentSerialiser )
{	
	for( GraphComponent::ChildIterator it = parent->children().begin(), eIt = parent->children().end(); it != eIt; it++ )
	{
		const GraphComponent *child = it->get();
		if( parent == m_parent && m_filter && !m_filter->contains( child ) )
		{
			continue;
		}
		if( !parentSerialiser->childNeedsSerialisation( child ) )
		{
			continue;
		}
		
		const Serialiser *childSerialiser = acquireSerialiser( child );
		childSerialiser->moduleDependencies( child, m_modules );

		std::string childConstructor;
		if( parentSerialiser->childNeedsConstruction( child ) )
		{
			childConstructor = childSerialiser->constructor( child );
		}
		
		std::string childIdentifier;
		if( parent == m_parent && childConstructor.size() )
		{
			childIdentifier = "__children[\"" + child->getName().string() + "\"]";
		}
		else
		{
			childIdentifier = parentIdentifier + "[\"" + child->getName().string() + "\"]";
		}
		
		if( childConstructor.size() )
		{
			if( parent == m_parent)
			{
				m_hierarchyScript += childIdentifier + " = " + childConstructor + "\n";
				m_hierarchyScript += parentIdentifier + ".addChild( " + childIdentifier + " )\n";
			}
			else
			{
				m_hierarchyScript += parentIdentifier + ".addChild( " + childConstructor + " )\n";
			}
		}
		
		m_hierarchyScript += childSerialiser->postConstructor( child, childIdentifier, *this );
		m_connectionScript += childSerialiser->postHierarchy( child, childIdentifier, *this );
		m_postScript += childSerialiser->postScript( child, childIdentifier, *this );
	
		walk( child, childIdentifier, childSerialiser );
	}
}