示例#1
0
    def testValueTypes(self):

        for v in [
                IECore.FloatVectorData([1, 2, 3]),
                IECore.IntVectorData([1, 2, 3]),
                IECore.StringVectorData(["1", "2", "3"]),
                IECore.V3fVectorData([imath.V3f(x) for x in range(1, 5)]),
                IECore.Color3fVectorData(
                    [imath.Color3f(x) for x in range(1, 5)]),
                IECore.M44fVectorData([imath.M44f() * x for x in range(1, 5)]),
                IECore.V2iVectorData([imath.V2i(x) for x in range(1, 5)]),
                IECore.V3fData(imath.V3f(1, 2, 3)),
                IECore.V2fData(imath.V2f(1, 2)),
                IECore.M44fData(imath.M44f(*range(16))),
                IECore.Box2fData(imath.Box2f(imath.V2f(0, 1), imath.V2f(1,
                                                                        2))),
                IECore.Box2iData(
                    imath.Box2i(imath.V2i(-1, 10), imath.V2i(11, 20))),
                IECore.Box3fData(
                    imath.Box3f(imath.V3f(0, 1, 2), imath.V3f(3, 4, 5))),
                IECore.Box3iData(
                    imath.Box3i(imath.V3i(0, 1, 2), imath.V3i(3, 4, 5))),
                IECore.InternedStringVectorData(["a", "b"])
        ]:
            if 'value' in dir(v):
                expected = v.value
            else:
                expected = v
            self.assertEqual(
                expected,
                Gaffer.NameValuePlug("test", v)["value"].getValue())
    def testBoxTypes(self):

        p = IECore.Parameterised("")

        p.parameters().addParameters([
            IECore.Box3iParameter(
                "b",
                "",
                imath.Box3i(
                    imath.V3i(-1, -2, -3),
                    imath.V3i(2, 1, 3),
                ),
            )
        ])

        ph = GafferCortex.ParameterisedHolderNode()
        ph.setParameterised(p)

        self.assertIsInstance(ph["parameters"]["b"], Gaffer.Box3iPlug)
        self.assertIsInstance(ph["parameters"]["b"]["min"], Gaffer.V3iPlug)
        self.assertIsInstance(ph["parameters"]["b"]["max"], Gaffer.V3iPlug)

        self.assertEqual(ph["parameters"]["b"]["min"].getValue(),
                         imath.V3i(-1, -2, -3))
        self.assertEqual(ph["parameters"]["b"]["max"].getValue(),
                         imath.V3i(2, 1, 3))

        ph["parameters"]["b"]["min"].setValue(imath.V3i(-10, -20, -30))
        ph["parameters"]["b"]["max"].setValue(imath.V3i(10, 20, 30))

        ph.parameterHandler().setParameterValue()

        self.assertEqual(
            p["b"].getTypedValue(),
            imath.Box3i(imath.V3i(-10, -20, -30), imath.V3i(10, 20, 30)))

        with ph.parameterModificationContext():

            p["b"].setTypedValue(
                imath.Box3i(imath.V3i(-2, -4, -6), imath.V3i(2, 4, 6)))

        self.assertEqual(ph["parameters"]["b"]["min"].getValue(),
                         imath.V3i(-2, -4, -6))
        self.assertEqual(ph["parameters"]["b"]["max"].getValue(),
                         imath.V3i(2, 4, 6))
示例#3
0
	def testBoxTypes( self ) :

		p = Gaffer.CompoundDataPlug()

		for name, value in [
			( "b2f", IECore.Box2fData( imath.Box2f( imath.V2f( 0, 1 ), imath.V2f( 1, 2 ) ) ) ),
			( "b2i", IECore.Box2iData( imath.Box2i( imath.V2i( -1, 10 ), imath.V2i( 11, 20 ) ) ) ),
			( "b3f", IECore.Box3fData( imath.Box3f( imath.V3f( 0, 1, 2 ), imath.V3f( 3, 4, 5 ) ) ) ),
			( "b3i", IECore.Box3iData( imath.Box3i( imath.V3i( 0, 1, 2 ), imath.V3i( 3, 4, 5 ) ) ) ),
		] :
			p.addChild( Gaffer.NameValuePlug( name, value ) )
			self.assertEqual( p.memberDataAndName( p[-1] ), ( value, name ) )
    def __addMenuDefinition(self):

        result = IECore.MenuDefinition()
        result.append(
            "/Add/Bool", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.BoolData(False))
            })
        result.append(
            "/Add/Float", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.FloatData(0))
            })
        result.append(
            "/Add/Int", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.IntData(0))
            })
        result.append("/Add/NumericDivider", {"divider": True})

        result.append(
            "/Add/String", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.StringData(""))
            })
        result.append("/Add/StringDivider", {"divider": True})

        result.append(
            "/Add/V2i/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2iData(imath.V2i(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V2i/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2iData(imath.V2i(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V2i/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2iData(imath.V2i(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append(
            "/Add/V3i/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3iData(imath.V3i(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V3i/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3iData(imath.V3i(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V3i/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3iData(imath.V3i(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append(
            "/Add/V2f/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2fData(imath.V2f(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V2f/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2fData(imath.V2f(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V2f/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2fData(imath.V2f(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append(
            "/Add/V3f/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3fData(imath.V3f(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V3f/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3fData(imath.V3f(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V3f/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3fData(imath.V3f(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append("/Add/VectorDivider", {"divider": True})

        result.append(
            "/Add/Color3f", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.Color3fData(imath.Color3f(0)))
            })
        result.append(
            "/Add/Color4f", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Color4fData(imath.Color4f(0, 0, 0, 1)))
            })

        result.append("/Add/BoxDivider", {"divider": True})

        result.append(
            "/Add/Box2i", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box2iData(imath.Box2i(imath.V2i(0), imath.V2i(1))))
            })
        result.append(
            "/Add/Box2f", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box2fData(imath.Box2f(imath.V2f(0), imath.V2f(1))))
            })
        result.append(
            "/Add/Box3i", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box3iData(imath.Box3i(imath.V3i(0), imath.V3i(1))))
            })
        result.append(
            "/Add/Box3f", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box3fData(imath.Box3f(imath.V3f(0), imath.V3f(1))))
            })

        result.append("/Add/BoxDivider", {"divider": True})

        for label, plugType in [
            ("Float", Gaffer.FloatVectorDataPlug),
            ("Int", Gaffer.IntVectorDataPlug),
            ("NumericDivider", None),
            ("String", Gaffer.StringVectorDataPlug),
        ]:
            if plugType is not None:
                result.append(
                    "/Add/Array/" + label, {
                        "command":
                        IECore.curry(Gaffer.WeakMethod(self.__addItem), "",
                                     plugType.ValueType())
                    })
            else:
                result.append("/Add/Array/" + label, {"divider": True})

        return result