示例#1
0
    def testUncacheabilityPropagates(self):

        n = GafferTest.CachingTestNode()
        n["in"].setValue("pig")

        p1 = Gaffer.ObjectPlug("p1", Gaffer.Plug.Direction.In,
                               IECore.IntData(10))
        p2 = Gaffer.ObjectPlug("p2", Gaffer.Plug.Direction.In,
                               IECore.IntData(20))
        p3 = Gaffer.ObjectPlug("p3", Gaffer.Plug.Direction.In,
                               IECore.IntData(30))

        p1.setInput(n["out"])
        p2.setInput(p1)
        p3.setInput(p2)

        o2 = p2.getValue(_copy=False)
        o3 = p3.getValue(_copy=False)

        self.assertEqual(o2, IECore.StringData("pig"))
        self.assertEqual(o3, IECore.StringData("pig"))
        self.failUnless(o2.isSame(o3))  # they share cache entries

        n["out"].setFlags(Gaffer.Plug.Flags.Cacheable, False)

        o2 = p2.getValue(_copy=False)
        o3 = p3.getValue(_copy=False)

        self.assertEqual(o2, IECore.StringData("pig"))
        self.assertEqual(o3, IECore.StringData("pig"))
        self.failIf(o2.isSame(o3))  # they shouldn't share cache entries
示例#2
0
    def testNoChildrenAccepted(self):

        p1 = Gaffer.ObjectPlug(defaultValue=IECore.IntData(20))
        p2 = Gaffer.ObjectPlug(defaultValue=IECore.IntData(20))

        self.assertFalse(p1.acceptsChild(p2))
        self.assertRaises(RuntimeError, p1.addChild, p2)
	def testSerialisationWithoutRepr( self ) :

		# Check that we can serialise plug values even when the
		# stored `IECore::Object` does not have a suitable
		# implementation of `repr()`.

		v1 = IECore.TransformationMatrixfData(
			IECore.TransformationMatrixf(
				imath.V3f( 1, 2, 3 ),
				imath.Eulerf(),
				imath.V3f( 1, 1, 1 )
			)
		)

		v2 = IECore.TransformationMatrixfData(
			IECore.TransformationMatrixf(
				imath.V3f( 4, 5, 6 ),
				imath.Eulerf(),
				imath.V3f( 2, 2, 2 )
			)
		)

		v3 = IECore.CompoundObject( {
			"a" : IECore.IntData( 10 ),
			"b" : v1,
			"c" : v2,
			"d" : IECore.StringData( "test" ),
		} )

		with self.assertRaises( Exception ) :
			eval( repr( v1 ) )

		s = Gaffer.ScriptNode()
		s["n"] = Gaffer.Node()
		s["n"]["user"]["p1"] = Gaffer.ObjectPlug( defaultValue = v1, flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
		s["n"]["user"]["p2"] = Gaffer.ObjectPlug( defaultValue = v2, flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
		s["n"]["user"]["p3"] = Gaffer.ObjectPlug( defaultValue = v3, flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

		s2 = Gaffer.ScriptNode()
		s2.execute( s.serialise() )
		self.assertEqual( s2["n"]["user"]["p1"].defaultValue(), v1 )
		self.assertEqual( s2["n"]["user"]["p2"].defaultValue(), v2 )
		self.assertEqual( s2["n"]["user"]["p3"].defaultValue(), v3 )
		self.assertEqual( s2["n"]["user"]["p1"].getValue(), v1 )
		self.assertEqual( s2["n"]["user"]["p2"].getValue(), v2 )
		self.assertEqual( s2["n"]["user"]["p3"].getValue(), v3 )

		s["n"]["user"]["p1"].setValue( v2 )
		s["n"]["user"]["p2"].setValue( v3 )
		s["n"]["user"]["p3"].setValue( v1 )

		s2 = Gaffer.ScriptNode()
		s2.execute( s.serialise() )
		self.assertEqual( s2["n"]["user"]["p1"].defaultValue(), v1 )
		self.assertEqual( s2["n"]["user"]["p2"].defaultValue(), v2 )
		self.assertEqual( s2["n"]["user"]["p3"].defaultValue(), v3 )
		self.assertEqual( s2["n"]["user"]["p1"].getValue(), v2 )
		self.assertEqual( s2["n"]["user"]["p2"].getValue(), v3 )
		self.assertEqual( s2["n"]["user"]["p3"].getValue(), v1 )
示例#4
0
        def __init__(self, name="PassThrough"):

            Gaffer.ComputeNode.__init__(self, name)

            self.addChild(
                Gaffer.ObjectPlug("in", Gaffer.Plug.Direction.In,
                                  IECore.NullObject()))
            self.addChild(
                Gaffer.ObjectPlug("out", Gaffer.Plug.Direction.Out,
                                  IECore.NullObject()))
	def testDefaultValue( self ) :

		p = Gaffer.ObjectPlug( "p", defaultValue = IECore.IntVectorData( [ 1, 2, 3 ] ) )
		self.assertEqual( p.defaultValue(), IECore.IntVectorData( [ 1, 2, 3 ] ) )

		self.assertFalse( p.defaultValue().isSame( p.defaultValue() ) )
		self.assertTrue( p.defaultValue( _copy = False ).isSame( p.defaultValue( _copy = False ) ) )
示例#6
0
    def testFactory(self):

        sphere = GafferTest.SphereNode()
        view = GafferUI.View.create(sphere["out"])

        self.assertTrue(isinstance(view, GafferUI.ObjectView))
        self.assertTrue(view["in"].getInput().isSame(sphere["out"]))

        # check that we can make our own view and register it for the node

        class MyView(GafferUI.ObjectView):
            def __init__(self, viewedPlug=None):

                GafferUI.ObjectView.__init__(self)

                self["in"].setInput(viewedPlug)

        GafferUI.View.registerView(GafferTest.SphereNode, "out", MyView)

        view = GafferUI.View.create(sphere["out"])
        self.assertTrue(isinstance(view, MyView))
        self.assertTrue(view["in"].getInput().isSame(sphere["out"]))

        # and check that that registration leaves other nodes alone

        n = Gaffer.Node()
        n["out"] = Gaffer.ObjectPlug(
            direction=Gaffer.Plug.Direction.Out,
            defaultValue=IECore.NullObject.defaultNullObject())

        view = GafferUI.View.create(n["out"])

        self.assertTrue(isinstance(view, GafferUI.ObjectView))
        self.assertTrue(view["in"].getInput().isSame(n["out"]))
示例#7
0
    def __init__(self, name="SphereNode"):

        Gaffer.ComputeNode.__init__(self, name)

        radiusPlug = Gaffer.FloatPlug(name="radius",
                                      defaultValue=1,
                                      minValue=0)
        self.addChild(radiusPlug)

        zMinPlug = Gaffer.FloatPlug(name="zMin",
                                    defaultValue=-1,
                                    minValue=-1,
                                    maxValue=1)
        self.addChild(zMinPlug)

        zMaxPlug = Gaffer.FloatPlug(name="zMax",
                                    defaultValue=1,
                                    minValue=-1,
                                    maxValue=1)
        self.addChild(zMaxPlug)

        thetaPlug = Gaffer.FloatPlug(name="theta",
                                     defaultValue=360,
                                     minValue=0,
                                     maxValue=360)
        self.addChild(thetaPlug)

        resultPlug = Gaffer.ObjectPlug("out", Gaffer.Plug.Direction.Out,
                                       IECore.NullObject.defaultNullObject())
        self.addChild(resultPlug)
示例#8
0
    def __init__(self, name="Sphere", inputs={}, dynamicPlugs=()):

        Gaffer.Node.__init__(self, name)

        radiusPlug = Gaffer.FloatPlug(name="radius",
                                      defaultValue=1,
                                      minValue=0)
        self.addChild(radiusPlug)

        zMinPlug = Gaffer.FloatPlug(name="zMin",
                                    defaultValue=-1,
                                    minValue=-1,
                                    maxValue=1)
        self.addChild(zMinPlug)

        zMaxPlug = Gaffer.FloatPlug(name="zMax",
                                    defaultValue=1,
                                    minValue=-1,
                                    maxValue=1)
        self.addChild(zMaxPlug)

        thetaPlug = Gaffer.FloatPlug(name="theta",
                                     defaultValue=360,
                                     minValue=0,
                                     maxValue=360)
        self.addChild(thetaPlug)

        resultPlug = Gaffer.ObjectPlug("output", Gaffer.Plug.Direction.Out)
        self.addChild(resultPlug)

        self._init(inputs, dynamicPlugs)
示例#9
0
    def testSerialisationOfMeshPrimitives(self):

        # right now we can only serialise types which define __repr__, but that
        # isn't defined for all cortex types. this test should pass when we get round
        # to defining it for MeshPrimitives - we should do the other primitives at the
        # same time, obviously.

        s = Gaffer.ScriptNode()
        s["n"] = Gaffer.Node()
        s["n"]["t"] = Gaffer.ObjectPlug(
            "hello",
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic,
            defaultValue=IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(0), IECore.V2f(10))))
        s["n"]["t"].setValue(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(0), IECore.V2f(1))))

        se = s.serialise()

        s2 = Gaffer.ScriptNode()
        s2.execute(se)

        self.assertEqual(s["n"]["t"].defaultValue(),
                         s2["n"]["t"].defaultValue())
        self.assertEqual(s["n"]["t"].getValue(), s2["n"]["t"].getValue())
		def __init__( self, name="TypedObjectPlugNode" ) :

			Gaffer.Node.__init__( self, name )

			self.addChild(
				Gaffer.ObjectPlug( "p", defaultValue = IECore.IntData( 1 ) ),
			)
示例#11
0
    def __init__(self, name="CachingTestNode"):

        Gaffer.ComputeNode.__init__(self, name)

        self.addChild(Gaffer.StringPlug("in", Gaffer.Plug.Direction.In))
        self.addChild(
            Gaffer.ObjectPlug("out", Gaffer.Plug.Direction.Out,
                              IECore.NullObject()))
	def testSerialisationWithConnection( self ) :

		s = Gaffer.ScriptNode()
		s["n"] = Gaffer.Node()
		s["n"]["t"] = Gaffer.ObjectPlug( "hello", defaultValue = IECore.IntData( 0 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

		s["n2"] = Gaffer.Node()
		s["n2"]["t2"] = Gaffer.ObjectPlug( "hello", defaultValue = IECore.IntData( 0 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, direction=Gaffer.Plug.Direction.Out )

		s["n"]["t"].setInput( s["n2"]["t2"] )

		se = s.serialise()

		s2 = Gaffer.ScriptNode()
		s2.execute( se )

		self.assertTrue( s2["n"]["t"].getInput().isSame( s2["n2"]["t2"] ) )
示例#13
0
            def __init__(self, name="In"):

                Gaffer.ComputeNode.__init__(self, name)

                self.addChild(
                    Gaffer.ObjectPlug("oIn", Gaffer.Plug.Direction.In,
                                      IECore.NullObject()))
                self.addChild(Gaffer.IntPlug("iIn", Gaffer.Plug.Direction.In))
    def __init__(self, name="ObjectReader"):

        Gaffer.ComputeNode.__init__(self, name)

        self.addChild(Gaffer.StringPlug("fileName", Gaffer.Plug.Direction.In))
        self.addChild(
            Gaffer.ObjectPlug("out", Gaffer.Plug.Direction.Out,
                              IECore.NullObject.defaultNullObject()))
示例#15
0
            def __init__(self, viewedPlug=None):

                GafferUI.View.__init__(
                    self, "MyView",
                    Gaffer.ObjectPlug(
                        "in",
                        defaultValue=IECore.NullObject.defaultNullObject()))

                self["in"].setInput(viewedPlug)
示例#16
0
            def __init__(self, name="Out"):

                Gaffer.ComputeNode.__init__(self, name)

                self.addChild(
                    Gaffer.ObjectPlug("oOut", Gaffer.Plug.Direction.Out,
                                      IECore.NullObject()))
                self.addChild(
                    Gaffer.FloatPlug("fOut", Gaffer.Plug.Direction.Out))
示例#17
0
    def testCreateCounterpart(self):

        p = Gaffer.ObjectPlug(defaultValue=IECore.IntData(20))
        p2 = p.createCounterpart("c", Gaffer.Plug.Direction.Out)

        self.assertEqual(p2.getName(), "c")
        self.assertEqual(p2.direction(), Gaffer.Plug.Direction.Out)
        self.assertEqual(p2.defaultValue(), p.defaultValue())
        self.assertEqual(p2.getFlags(), p.getFlags())
示例#18
0
    def __init__(self, name="SLONode", inputs={}, dynamicPlugs=()):

        Gaffer.Node.__init__(self, name)

        self.addChild(Gaffer.StringPlug("name"))
        self.addChild(Gaffer.StringPlug("type"))
        self.addChild(Gaffer.CompoundPlug("parameters"))
        self.addChild(
            Gaffer.ObjectPlug("out", direction=Gaffer.Plug.Direction.Out))
        self._init(inputs, dynamicPlugs)
示例#19
0
    def testSetValueCopying(self):

        p = Gaffer.ObjectPlug(defaultValue=IECore.IntData(1))

        i = IECore.IntData(10)
        p.setValue(i)
        self.failIf(p.getValue(_copy=False).isSame(i))

        i = IECore.IntData(20)
        p.setValue(i, _copy=False)
        self.failUnless(p.getValue(_copy=False).isSame(i))
示例#20
0
    def testSetToDefault(self):

        defaultValue = IECore.IntVectorData([1, 2, 3])
        plug = Gaffer.ObjectPlug(defaultValue=defaultValue)
        self.assertEqual(plug.getValue(), defaultValue)

        plug.setValue(IECore.StringData("value"))
        self.assertEqual(plug.getValue(), IECore.StringData("value"))

        plug.setToDefault()
        self.assertEqual(plug.getValue(), defaultValue)
示例#21
0
    def testConstructCantSpecifyBothInputAndValue(self):

        out = Gaffer.ObjectPlug("out",
                                direction=Gaffer.Plug.Direction.Out,
                                defaultValue=IECore.StringData("hi"))

        self.assertRaises(Exception,
                          Gaffer.ObjectPlug,
                          "in",
                          input=out,
                          value=IECore.IntData(10))
    def testSerialisationWithConnection(self):

        s = Gaffer.ScriptNode()
        s["n"] = Gaffer.Node()
        s["n"]["t"] = Gaffer.ObjectPlug("hello",
                                        flags=Gaffer.Plug.Flags.Dynamic)

        s["n2"] = Gaffer.Node()
        s["n2"]["t2"] = Gaffer.ObjectPlug("hello",
                                          flags=Gaffer.Plug.Flags.Dynamic,
                                          direction=Gaffer.Plug.Direction.Out)

        s["n"]["t"].setInput(s["n2"]["t2"])

        se = s.serialise()

        s2 = Gaffer.ScriptNode()
        s2.execute(se)

        self.failUnless(s2["n"]["t"].getInput().isSame(s2["n2"]["t2"]))
示例#23
0
	def testSetToDefault( self ) :

		plane = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( 0 ), IECore.V2f( 10 ) ) )
		plug = Gaffer.ObjectPlug( defaultValue = plane )
		self.assertEqual( plug.getValue(), plane )

		plug.setValue( IECore.SpherePrimitive() )
		self.assertEqual( plug.getValue(), IECore.SpherePrimitive() )

		plug.setToDefault()
		self.assertEqual( plug.getValue(), plane )
示例#24
0
	def __init__( self, name="Read", inputs={}, dynamicPlugs=() ) :
	
		Gaffer.Node.__init__( self, name )
		
		fileNamePlug = Gaffer.StringPlug( "filename", Gaffer.Plug.Direction.In )
		self.addChild( fileNamePlug )
		
		resultPlug = Gaffer.ObjectPlug( "output", Gaffer.Plug.Direction.Out )
		self.addChild( resultPlug )
		
		self._init( inputs, dynamicPlugs )
	def testSerialisation( self ) :

		s = Gaffer.ScriptNode()
		s["n"] = Gaffer.Node()
		s["n"]["t"] = Gaffer.ObjectPlug( "hello", defaultValue = IECore.IntData( 1 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

		se = s.serialise()

		s2 = Gaffer.ScriptNode()
		s2.execute( se )

		self.assertTrue( s2["n"]["t"].isInstanceOf( Gaffer.ObjectPlug.staticTypeId() ) )
示例#26
0
    def testUnsupportedPlugs(self):

        s = Gaffer.ScriptNode()
        s["n"] = Gaffer.Node()
        s["n"]["user"]["o"] = Gaffer.ObjectPlug(
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic,
            defaultValue=IECore.NullObject.defaultNullObject())

        s["e"] = Gaffer.Expression()
        self.assertRaisesRegexp(
            RuntimeError, "Unsupported plug type \"Gaffer::ObjectPlug\"",
            s["e"].setExpression, "parent.n.user.o = 1", "OSL")
示例#27
0
            def __init__(self, viewedPlug=None):

                GafferImageUI.ImageView.__init__(
                    self, "MyView",
                    Gaffer.ObjectPlug(
                        "in",
                        defaultValue=IECore.NullObject.defaultNullObject()))

                self["in"].setInput(viewedPlug)

                self.__preprocessor = Gaffer.Node()
                self.__preprocessor["in"] = Gaffer.ObjectPlug(
                    defaultValue=IECore.NullObject.defaultNullObject())
                self.__preprocessor["out"] = GafferImage.ImagePlug(
                    direction=Gaffer.Plug.Direction.Out)
                self.__preprocessor["constant"] = GafferImage.Constant()
                self.__preprocessor["constant"]["format"].setValue(
                    GafferImage.Format(20, 20, 1))
                self.__preprocessor["out"].setInput(
                    self.__preprocessor["constant"]["out"])

                self._setPreprocessor(self.__preprocessor)
    def testSerialisation(self):

        s = Gaffer.ScriptNode()
        s["n"] = Gaffer.Node()
        s["n"]["t"] = Gaffer.ObjectPlug("hello",
                                        flags=Gaffer.Plug.Flags.Dynamic)

        se = s.serialise()

        s2 = Gaffer.ScriptNode()
        s2.execute(se)

        self.failUnless(s2["n"]["t"].isInstanceOf(
            Gaffer.ObjectPlug.staticTypeId()))
示例#29
0
			def __init__( self, viewedPlug = None ) :

				GafferImageUI.ImageView.__init__( self, "MyView" )

				converter = Gaffer.Node()
				converter["in"] = Gaffer.ObjectPlug( defaultValue = IECore.NullObject.defaultNullObject() )
				converter["out"] = GafferImage.ImagePlug( direction = Gaffer.Plug.Direction.Out )
				converter["constant"] = GafferImage.Constant()
				converter["constant"]["format"].setValue( GafferImage.Format( 20, 20, 1 ) )
				converter["out"].setInput( converter["constant"]["out"] )

				self._insertConverter( converter )

				self["in"].setInput( viewedPlug )
	def testSerialisationWithValueAndDefaultValue( self ) :

		s = Gaffer.ScriptNode()
		s["n"] = Gaffer.Node()
		s["n"]["t"] = Gaffer.ObjectPlug( "hello", flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, defaultValue = IECore.IntData( 10 ) )
		s["n"]["t"].setValue( IECore.CompoundObject( { "a" : IECore.IntData( 20 ) } ) )

		se = s.serialise()

		s2 = Gaffer.ScriptNode()
		s2.execute( se )

		self.assertTrue( s2["n"]["t"].isInstanceOf( Gaffer.ObjectPlug.staticTypeId() ) )
		self.assertEqual( s2["n"]["t"].defaultValue(), IECore.IntData( 10 ) )
		self.assertEqual( s2["n"]["t"].getValue(), IECore.CompoundObject( { "a" : IECore.IntData( 20 ) } ) )