|
40 | 40 |
|
41 | 41 | import IECore
|
42 | 42 | import Gaffer
|
| 43 | +import GafferTest |
43 | 44 | import GafferScene
|
44 | 45 | import GafferSceneTest
|
45 | 46 |
|
@@ -1337,5 +1338,92 @@ def testQueryDoubleData( self ) :
|
1337 | 1338 | self.assertTrue( query["exists"].getValue() )
|
1338 | 1339 | self.assertEqual( query["value"].getValue(), 2.5 )
|
1339 | 1340 |
|
| 1341 | + def testInheritedGlobalAttribute( self ) : |
| 1342 | + |
| 1343 | + sphere = GafferScene.Sphere() |
| 1344 | + |
| 1345 | + globalAttributes = GafferScene.CustomAttributes() |
| 1346 | + globalAttributes["in"].setInput( sphere["out"] ) |
| 1347 | + globalAttributes["global"].setValue( True ) |
| 1348 | + globalAttributes["extraAttributes"].setValue( IECore.CompoundObject( { "test" : IECore.DoubleData( 5.0 ) } ) ) |
| 1349 | + |
| 1350 | + attributes = GafferScene.CustomAttributes() |
| 1351 | + attributes["in"].setInput( globalAttributes["out"] ) |
| 1352 | + attributes["extraAttributes"].setValue( IECore.CompoundObject( { "test" : IECore.DoubleData( 2.5 ) } ) ) |
| 1353 | + attributes["enabled"].setValue( False ) |
| 1354 | + |
| 1355 | + query = GafferScene.AttributeQuery() |
| 1356 | + query.setup( Gaffer.FloatPlug() ) |
| 1357 | + query["scene"].setInput( attributes["out"] ) |
| 1358 | + query["location"].setValue( "/sphere" ) |
| 1359 | + query["attribute"].setValue( "test" ) |
| 1360 | + |
| 1361 | + self.assertFalse( query["exists"].getValue() ) |
| 1362 | + self.assertEqual( query["value"].getValue(), 0.0 ) |
| 1363 | + |
| 1364 | + query["inherit"].setValue( True ) |
| 1365 | + |
| 1366 | + self.assertTrue( query["exists"].getValue() ) |
| 1367 | + self.assertEqual( query["value"].getValue(), 5.0 ) |
| 1368 | + |
| 1369 | + globalAttributes["extraAttributes"].setValue( IECore.CompoundObject( { "test" : IECore.DoubleData( 10.0 ) } ) ) |
| 1370 | + |
| 1371 | + self.assertTrue( query["exists"].getValue() ) |
| 1372 | + self.assertEqual( query["value"].getValue(), 10.0 ) |
| 1373 | + |
| 1374 | + attributes["enabled"].setValue( True ) |
| 1375 | + |
| 1376 | + self.assertTrue( query["exists"].getValue() ) |
| 1377 | + self.assertEqual( query["value"].getValue(), 2.5 ) |
| 1378 | + |
| 1379 | + query["inherit"].setValue( False ) |
| 1380 | + |
| 1381 | + self.assertTrue( query["exists"].getValue() ) |
| 1382 | + self.assertEqual( query["value"].getValue(), 2.5 ) |
| 1383 | + |
| 1384 | + def testDirtyPropagation( self ) : |
| 1385 | + |
| 1386 | + sphere = GafferScene.Sphere() |
| 1387 | + |
| 1388 | + globalAttributes = GafferScene.StandardAttributes() |
| 1389 | + globalAttributes["in"].setInput( sphere["out"] ) |
| 1390 | + globalAttributes["global"].setValue( True ) |
| 1391 | + |
| 1392 | + standardAttributes = GafferScene.StandardAttributes() |
| 1393 | + standardAttributes["in"].setInput( globalAttributes["out"] ) |
| 1394 | + |
| 1395 | + query = GafferScene.AttributeQuery() |
| 1396 | + query.setup( Gaffer.BoolPlug() ) |
| 1397 | + query["scene"].setInput( standardAttributes["out"] ) |
| 1398 | + query["location"].setValue( "/sphere" ) |
| 1399 | + |
| 1400 | + cs = GafferTest.CapturingSlot( query.plugDirtiedSignal() ) |
| 1401 | + |
| 1402 | + standardAttributes["attributes"]["scene:visible"]["enabled"].setValue( True ) |
| 1403 | + self.assertIn( query["value"], { x[0] for x in cs } ) |
| 1404 | + |
| 1405 | + standardAttributes["attributes"]["scene:visible"]["enabled"].setValue( False ) |
| 1406 | + del cs[:] |
| 1407 | + query["default"].setValue( True ) |
| 1408 | + self.assertIn( query["value"], { x[0] for x in cs } ) |
| 1409 | + |
| 1410 | + # modifying the globals with the `inherit` plug disabled |
| 1411 | + # should not dirty query["value"] |
| 1412 | + del cs[:] |
| 1413 | + globalAttributes["attributes"]["scene:visible"]["enabled"].setValue( True ) |
| 1414 | + self.assertNotIn( query["value"], { x[0] for x in cs } ) |
| 1415 | + |
| 1416 | + query["inherit"].setValue( True ) |
| 1417 | + self.assertIn( query["value"], { x[0] for x in cs } ) |
| 1418 | + |
| 1419 | + globalAttributes["attributes"]["scene:visible"]["enabled"].setValue( False ) |
| 1420 | + del cs[:] |
| 1421 | + globalAttributes["attributes"]["scene:visible"]["enabled"].setValue( True ) |
| 1422 | + self.assertIn( query["value"], { x[0] for x in cs } ) |
| 1423 | + |
| 1424 | + del cs[:] |
| 1425 | + standardAttributes["attributes"]["scene:visible"]["enabled"].setValue( True ) |
| 1426 | + self.assertIn( query["value"], { x[0] for x in cs } ) |
| 1427 | + |
1340 | 1428 | if __name__ == "__main__":
|
1341 | 1429 | unittest.main()
|
0 commit comments