Skip to content

Commit

Permalink
Box : Transfer metadata for children of promoted plugs too.
Browse files Browse the repository at this point in the history
This fixes a problem whereby presets were not being transferred when promoting a compound plug on a RenderManAttributes node.

Fixes #1468
  • Loading branch information
johnhaddon authored and davidsminor committed Sep 8, 2015
1 parent d347ccc commit 5ceb118
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
53 changes: 53 additions & 0 deletions python/GafferRenderManUITest/RenderManAttributesUITest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##########################################################################
#
# Copyright (c) 2015, Image Engine Design Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# * Neither the name of John Haddon nor the names of
# any other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import Gaffer
import GafferRenderMan
import GafferRenderManTest
import GafferRenderManUI

class RenderManAttributesUITest( GafferRenderManTest.RenderManTestCase ) :

def testPromotedCameraHitMode( self ) :

b = Gaffer.Box()
b["a"] = GafferRenderMan.RenderManAttributes()

p = b.promotePlug( b["a"]["attributes"]["cameraHitMode"] )
self.assertEqual( Gaffer.NodeAlgo.presets( p["value" ] ), [ "Shader", "Primitive" ] )

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions python/GafferRenderManUITest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from DocumentationTest import DocumentationTest
from RenderManShaderUITest import RenderManShaderUITest
from RenderManAttributesUITest import RenderManAttributesUITest

if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions python/GafferTest/BoxTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,5 +984,29 @@ def testPromotionIncludesArbitraryMetadata( self ) :
self.assertEqual( Gaffer.Metadata.plugValue( s2["b"]["p"], "testInt" ), 10 )
self.assertEqual( Gaffer.Metadata.plugValue( s2["b"]["p"], "testString" ), "test" )

def testPromotionIncludesArbitraryChildMetadata( self ) :

s = Gaffer.ScriptNode()

s["b"] = Gaffer.Box()
s["b"]["n"] = Gaffer.Node()
s["b"]["n"]["user"]["p"] = Gaffer.Plug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
s["b"]["n"]["user"]["p"]["i"] = Gaffer.IntPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

Gaffer.Metadata.registerPlugValue( s["b"]["n"]["user"]["p"], "testInt", 10 )
Gaffer.Metadata.registerPlugValue( s["b"]["n"]["user"]["p"]["i"], "testString", "test" )

p = s["b"].promotePlug( s["b"]["n"]["user"]["p"] )
p.setName( "p" )

self.assertEqual( Gaffer.Metadata.plugValue( p, "testInt" ), 10 )
self.assertEqual( Gaffer.Metadata.plugValue( p["i"], "testString" ), "test" )

s2 = Gaffer.ScriptNode()
s2.execute( s.serialise() )

self.assertEqual( Gaffer.Metadata.plugValue( s2["b"]["p"], "testInt" ), 10 )
self.assertEqual( Gaffer.Metadata.plugValue( s2["b"]["p"]["i"], "testString" ), "test" )

if __name__ == "__main__":
unittest.main()
8 changes: 8 additions & 0 deletions src/Gaffer/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,12 @@ void Box::copyMetadata( const Plug *from, Plug *to )
}
Metadata::registerPlugValue( to, *it, Metadata::plugValue<IECore::Data>( from, *it ) );
}

for( PlugIterator it( from ); it != it.end(); ++it )
{
if( Plug *childTo = to->getChild<Plug>( (*it)->getName() ) )
{
copyMetadata( it->get(), childTo );
}
}
}

0 comments on commit 5ceb118

Please sign in to comment.