Skip to content

Commit

Permalink
BoxIO : Don't create redundant metadata in setup()
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Oct 25, 2023
1 parent 39ef62b commit 00e260a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 20 additions & 0 deletions python/GafferUITest/BoxIOUITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

import unittest

import imath

import Gaffer
import GafferTest
import GafferUI
Expand All @@ -57,5 +59,23 @@ def testNoRedundantMetadata( self ) :
Gaffer.BoxIO.insert( box )
self.assertEqual( Gaffer.Metadata.registeredValues( box["BoxIn"]["__in"], Gaffer.Metadata.RegistrationTypes.Instance ), [] )

oldColor = GafferUI.Metadata.value( box["add"]["op1"], "nodule:color", Gaffer.Metadata.RegistrationTypes.TypeId )
self.addCleanup( Gaffer.Metadata.registerValue, Gaffer.IntPlug, "nodule:color", oldColor )

newColor = imath.Color3f( 1, 0, 0 )
Gaffer.Metadata.registerValue( Gaffer.IntPlug, "nodule:color", newColor )
self.assertEqual( Gaffer.Metadata.value( box["add"]["op1"], "nodule:color" ), newColor )

promoted = Gaffer.BoxIO.promote( box["switch"]["out"] )
self.assertEqual(
set( Gaffer.Metadata.registeredValues( box["BoxOut"]["__out"], Gaffer.Metadata.RegistrationTypes.Instance ) ),
# We allow `description` and `plugValueWidget:type` because we do want those to be transferred through to
# the promoted plug, even though `description` doesn't always make sense in the new context. But we definitely
# don't want `nodule:color` to be promoted to instance metadata, because it is inherited from the type anyway.
{ "description", "plugValueWidget:type" }
)
self.assertEqual( Gaffer.Metadata.value( promoted, "nodule:color" ), newColor )
self.assertEqual( Gaffer.Metadata.value( box["BoxOut"]["__out"], "nodule:color" ), newColor )

if __name__ == "__main__":
unittest.main()
15 changes: 14 additions & 1 deletion src/Gaffer/BoxIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,20 @@ void BoxIO::setup( const Plug *plug )
/// individual exclusions.
return false;
}
return MetadataAlgo::isPromotable( from, to, name );
if( !MetadataAlgo::isPromotable( from, to, name ) )
{
return false;
}
// Only copy if the destination doesn't already have the metadata.
// This avoids making unnecessary instance-level metadata when the
// same value is registered statically (against the plug type).
ConstDataPtr fromValue = Gaffer::Metadata::value( from, name );
ConstDataPtr toValue = Gaffer::Metadata::value( to, name );
if( fromValue && toValue )
{
return !toValue->isEqualTo( fromValue.get() );
}
return (bool)fromValue != (bool)toValue;
}
);

Expand Down

0 comments on commit 00e260a

Please sign in to comment.