Ejemplo n.º 1
0
    def testCompatibilityWithIntPlugs(self):

        s = Gaffer.ScriptNode()
        s["p"] = GafferScene.PathFilter()

        s["d"] = Gaffer.Dot()
        s["d"].setup(Gaffer.IntPlug())
        s["d"]["in"].setInput(s["p"]["out"])
        s["s"] = GafferScene.FilterSwitch()
        s["s"]["in"][0].setInput(s["d"]["out"])

        s["b"] = Gaffer.Box()
        s["b"]["filter"] = Gaffer.IntPlug()
        s["b"]["filter"].setInput(s["p"]["out"])
        s["b"]["s"] = GafferScene.FilterSwitch()
        s["b"]["s"]["in"][0].setInput(s["b"]["filter"])
Ejemplo n.º 2
0
    def testCompatibilityWithIntPlugs(self):

        s = Gaffer.ScriptNode()
        s["p"] = GafferScene.PathFilter()

        s["d"] = Gaffer.Dot()
        s["d"].setup(Gaffer.IntPlug())
        s["d"]["in"].setInput(s["p"]["out"])
        s["s"] = GafferScene.FilterSwitch()

        # We use `execute()` here because the compatibility with int
        # plugs only applies when loading.
        s.execute("""script["s"]["in"][0].setInput( script["d"]["out"] )""")

        s["b"] = Gaffer.Box()
        s["b"]["filter"] = Gaffer.IntPlug()
        s["b"]["filter"].setInput(s["p"]["out"])
        s["b"]["s"] = GafferScene.FilterSwitch()

        s.execute(
            """script["b"]["s"]["in"][0].setInput( script["b"]["filter"] )""")
Ejemplo n.º 3
0
    def testConnectWithoutInputs(self):

        s = Gaffer.ScriptNode()

        s["i"] = GafferScene.Isolate()
        s["p"] = GafferScene.PathFilter()

        s["s"] = GafferScene.FilterSwitch()
        s["s"]["in"][0].setInput(s["p"]["out"])
        s["s"]["in"][0].setInput(None)

        s["i"]["filter"].setInput(s["s"]["out"])
Ejemplo n.º 4
0
    def testSwitchConnectionSerializationProblem(self):

        s = Gaffer.ScriptNode()
        b1 = Gaffer.Box()
        s.addChild(b1)
        b2 = Gaffer.Box()
        b1.addChild(b2)

        fs = GafferScene.FilterSwitch()
        b2.addChild(fs)

        f1 = GafferScene.PathFilter()
        b2.addChild(f1)

        f2 = GafferScene.PathFilter()
        b2.addChild(f2)

        fs["in"]["in0"].setInput(f1["out"])
        fs["in"]["in1"].setInput(f2["out"])

        promoted = Gaffer.PlugAlgo.promote(fs["index"])
        promoted = Gaffer.PlugAlgo.promote(promoted)
        promoted.setValue(1)

        # correctly connected internally:
        self.assertEqual(fs["out"].getInput(), fs["in"]["in1"])

        # serialize/deserialize:
        ss = s.serialise()

        s = Gaffer.ScriptNode()
        s.execute(ss)
        fs = s["Box"]["Box"]["FilterSwitch"]

        # should still be correctly connected internally:
        self.assertEqual(fs["out"].getInput(), fs["in"]["in1"])
Ejemplo n.º 5
0
    def testSwitch(self):

        # Build a scene with a sphere, a plane, and
        # a filter switch controlling an attribute
        # assignment. Index 0 should assign to the
        # plane and index 1 should assign to the
        # sphere.

        script = Gaffer.ScriptNode()

        script["plane"] = GafferScene.Plane()
        script["sphere"] = GafferScene.Sphere()
        script["group"] = GafferScene.Group()
        script["group"]["in"][0].setInput(script["plane"]["out"])
        script["group"]["in"][1].setInput(script["sphere"]["out"])

        script["planeSet"] = GafferScene.Set()
        script["planeSet"]["paths"].setValue(
            IECore.StringVectorData(["/group/plane"]))
        script["planeSet"]["in"].setInput(script["group"]["out"])

        script["attributes"] = GafferScene.StandardAttributes()
        script["attributes"]["attributes"]["visibility"]["enabled"].setValue(
            True)
        script["attributes"]["in"].setInput(script["planeSet"]["out"])

        script["setFilter"] = GafferScene.SetFilter()
        script["setFilter"]["setExpression"].setValue("set")

        script["pathFilter"] = GafferScene.PathFilter()
        script["pathFilter"]["paths"].setValue(
            IECore.StringVectorData(["/group/sphere"]))

        script["switchFilter"] = GafferScene.FilterSwitch()
        script["switchFilter"]["in"][0].setInput(script["setFilter"]["out"])
        script["switchFilter"]["in"][1].setInput(script["pathFilter"]["out"])

        script["attributes"]["filter"].setInput(script["switchFilter"]["out"])

        # Check that we get the assignments we expect for each index.

        self.assertEqual(
            len(script["attributes"]["out"].attributes("/group/plane")), 1)
        self.assertEqual(
            len(script["attributes"]["out"].attributes("/group/sphere")), 0)

        script["switchFilter"]["index"].setValue(1)

        self.assertEqual(
            len(script["attributes"]["out"].attributes("/group/plane")), 0)
        self.assertEqual(
            len(script["attributes"]["out"].attributes("/group/sphere")), 1)

        # Check that we get dirtiness signalled when changing the
        # index.

        cs = GafferTest.CapturingSlot(script["attributes"].plugDirtiedSignal())
        self.assertEqual(len(cs), 0)

        script["switchFilter"]["index"].setValue(0)
        self.assertTrue(script["attributes"]["out"] in [c[0] for c in cs])

        # Check that we get dirtiness signalled for the attributes
        # when changing the set used by the set filter.

        del cs[:]
        script["planeSet"]["paths"].setValue(
            IECore.StringVectorData(["/group", "/group/plane"]))
        self.assertTrue(
            script["attributes"]["out"]["attributes"] in [c[0] for c in cs])

        # But also check that we don't get it signalled unnecessarily when
        # the set filter isn't the current index.

        script["switchFilter"]["index"].setValue(1)
        del cs[:]
        script["planeSet"]["paths"].setValue(
            IECore.StringVectorData(["/group/plane"]))
        self.assertFalse(
            script["attributes"]["out"]["attributes"] in [c[0] for c in cs])

        # Now check that we can use expressions successfully on the index.

        script["expression"] = Gaffer.Expression()
        script["expression"].setExpression(
            'parent["switchFilter"]["index"] = int( context.getFrame() )')

        with script.context():

            script.context().setFrame(0)
            self.assertEqual(
                len(script["attributes"]["out"].attributes("/group/plane")), 1)
            self.assertEqual(
                len(script["attributes"]["out"].attributes("/group/sphere")),
                0)

            script.context().setFrame(1)
            self.assertEqual(
                len(script["attributes"]["out"].attributes("/group/plane")), 0)
            self.assertEqual(
                len(script["attributes"]["out"].attributes("/group/sphere")),
                1)

        # Now we have an expression based on the context, changing the upstream set should
        # always signal dirtiness for the attributes, because we don't know which index
        # the switch will use until we actually compute.

        del cs[:]
        script["planeSet"]["paths"].setValue(
            IECore.StringVectorData(["/group", "/group/plane"]))
        self.assertTrue(
            script["attributes"]["out"]["attributes"] in [c[0] for c in cs])
Ejemplo n.º 6
0
    def testConstruct(self):

        f = GafferScene.FilterSwitch()
        self.assertEqual(f.getName(), "FilterSwitch")