def test_UnusedVariantChanges(self): layer = Sdf.Layer.CreateAnonymous() parent = Sdf.PrimSpec(layer, 'Root', Sdf.SpecifierDef, 'Scope') vA = Sdf.CreateVariantInLayer(layer, parent.path, 'var', 'A') vB = Sdf.CreateVariantInLayer(layer, parent.path, 'var', 'B') parent.variantSelections['var'] = 'A' layerStackId = Pcp.LayerStackIdentifier(layer) pcp = Pcp.Cache(layerStackId) (pi, err) = pcp.ComputePrimIndex('/Root') self.assertTrue(pi) self.assertEqual(len(err), 0) # Add a new prim spec inside the unused variant and verify that this # does not cause the cached prim index to be blown. with Pcp._TestChangeProcessor(pcp): newPrim = Sdf.PrimSpec(vB.primSpec, 'Child', Sdf.SpecifierDef, 'Scope') self.assertTrue(pcp.FindPrimIndex('/Root'))
def test_RelationshipTargetRemapping(self): """Tests that relationship targets that point to a child of the source path are remapped to the destination path.""" layer = Sdf.Layer.CreateAnonymous() primSpec = Sdf.CreatePrimInLayer(layer, "/Test/Child") relSpec = Sdf.RelationshipSpec(primSpec, "rel") relSpec.targetPathList.explicitItems = \ [ "/Test/Child.attr2", "/Test/Child/Subchild.attr3", "/Test/Sibling.attr" ] relSpec.SetTargetMarker("/Test/Child.attr2", "final") # Copy root prim and verify that targets on the child prim that # point to objects beneath /Test are remapped to /TestCopy. self.assertTrue(Sdf.CopySpec(layer, "/Test", layer, "/TestCopy")) dstRelSpec = layer.GetRelationshipAtPath("/TestCopy/Child.rel") self.assertTrue(dstRelSpec) expectedListOp = Sdf.PathListOp() expectedListOp.explicitItems = \ [ "/TestCopy/Child.attr2", "/TestCopy/Child/Subchild.attr3", "/TestCopy/Sibling.attr" ] self.assertEqual(dstRelSpec.GetInfo("targetPaths"), expectedListOp) self.assertEqual(dstRelSpec.targetMarkers["/TestCopy/Child.attr2"], "final") # Copy prim with relationship and verify that targets that point # to objects beneath the source /Test/Child prim are remapped to # /Dest. self.assertTrue(Sdf.CopySpec(layer, "/Test/Child", layer, "/Dest")) dstRelSpec = layer.GetRelationshipAtPath("/Dest.rel") self.assertTrue(dstRelSpec) expectedListOp = Sdf.PathListOp() expectedListOp.explicitItems = \ [ "/Dest.attr2", "/Dest/Subchild.attr3", "/Test/Sibling.attr" ] self.assertEqual(dstRelSpec.GetInfo("targetPaths"), expectedListOp) self.assertEqual(dstRelSpec.targetMarkers["/Dest.attr2"], "final") # Same as above, but copy to variant to ensure that variant selection # paths aren't authored into the connection list. varSpec = Sdf.CreateVariantInLayer(layer, "/Variant", "version", "a") self.assertTrue( Sdf.CopySpec(layer, "/Test/Child", layer, "/Variant{version=a}")) dstRelSpec = layer.GetRelationshipAtPath("/Variant{version=a}.rel") self.assertTrue(dstRelSpec) expectedListOp = Sdf.PathListOp() expectedListOp.explicitItems = \ [ "/Variant.attr2", "/Variant/Subchild.attr3", "/Test/Sibling.attr" ] self.assertEqual(dstRelSpec.GetInfo("targetPaths"), expectedListOp) self.assertEqual(dstRelSpec.targetMarkers["/Variant.attr2"], "final") # Copy from variant to variant, again to ensure that variant selection # paths aren't authored into the connection list. varSpec2 = Sdf.CreateVariantInLayer(layer, "/Variant", "version", "b") self.assertTrue( Sdf.CopySpec(layer, "/Variant{version=a}", layer, "/Variant{version=b}")) dstRelSpec = layer.GetRelationshipAtPath("/Variant{version=b}.rel") self.assertTrue(dstRelSpec) self.assertEqual(dstRelSpec.GetInfo("targetPaths"), expectedListOp) self.assertEqual(dstRelSpec.targetMarkers["/Variant.attr2"], "final")
def test_AttributeConnectionRemapping(self): """Tests that attribute connections that point to a child of the source path are remapped to the destination path.""" layer = Sdf.Layer.CreateAnonymous() primSpec = Sdf.CreatePrimInLayer(layer, "/Test/Child") attrSpec = Sdf.AttributeSpec(primSpec, "attr", Sdf.ValueTypeNames.Float) attrSpec.connectionPathList.explicitItems = \ [ "/Test/Child.attr2", "/Test/Child/Subchild.attr3", "/Test/Sibling.attr" ] attrSpec.SetConnectionMarker("/Test/Child.attr2", "final") Sdf.MapperSpec(attrSpec, "/Test/Child.attr2", "mapper") # Copy root prim and verify that connections on the child prim that # point to objects beneath /Test are remapped to /TestCopy. self.assertTrue(Sdf.CopySpec(layer, "/Test", layer, "/TestCopy")) dstAttrSpec = layer.GetAttributeAtPath("/TestCopy/Child.attr") self.assertTrue(dstAttrSpec) expectedListOp = Sdf.PathListOp() expectedListOp.explicitItems = \ [ "/TestCopy/Child.attr2", "/TestCopy/Child/Subchild.attr3", "/TestCopy/Sibling.attr" ] self.assertEqual(dstAttrSpec.GetInfo("connectionPaths"), expectedListOp) self.assertEqual( dstAttrSpec.connectionMarkers["/TestCopy/Child.attr2"], "final") # Copy prim with attribute and verify that connections that point # to objects beneath the source /Test/Child prim are remapped to # /Dest. self.assertTrue(Sdf.CopySpec(layer, "/Test/Child", layer, "/Dest")) dstAttrSpec = layer.GetAttributeAtPath("/Dest.attr") self.assertTrue(dstAttrSpec) expectedListOp = Sdf.PathListOp() expectedListOp.explicitItems = \ [ "/Dest.attr2", "/Dest/Subchild.attr3", "/Test/Sibling.attr" ] self.assertEqual(dstAttrSpec.GetInfo("connectionPaths"), expectedListOp) self.assertEqual(dstAttrSpec.connectionMarkers["/Dest.attr2"], "final") self.assertTrue(dstAttrSpec.connectionMappers["/Dest.attr2"].typeName, "mapper") # Same as above, but copy to variant to ensure that variant selection # paths aren't authored into the connection list. varSpec = Sdf.CreateVariantInLayer(layer, "/Variant", "version", "a") self.assertTrue( Sdf.CopySpec(layer, "/Test/Child", layer, "/Variant{version=a}")) dstAttrSpec = layer.GetAttributeAtPath("/Variant{version=a}.attr") self.assertTrue(dstAttrSpec) expectedListOp = Sdf.PathListOp() expectedListOp.explicitItems = \ [ "/Variant.attr2", "/Variant/Subchild.attr3", "/Test/Sibling.attr" ] self.assertEqual(dstAttrSpec.GetInfo("connectionPaths"), expectedListOp) self.assertEqual(dstAttrSpec.connectionMarkers["/Variant.attr2"], "final") self.assertTrue( dstAttrSpec.connectionMappers["/Variant.attr2"].typeName, "mapper") # Copy from variant to variant, again to ensure that variant selection # paths aren't authored into the connection list. varSpec2 = Sdf.CreateVariantInLayer(layer, "/Variant", "version", "b") self.assertTrue( Sdf.CopySpec(layer, "/Variant{version=a}", layer, "/Variant{version=b}")) dstAttrSpec = layer.GetAttributeAtPath("/Variant{version=b}.attr") self.assertTrue(dstAttrSpec) self.assertEqual(dstAttrSpec.GetInfo("connectionPaths"), expectedListOp) self.assertEqual(dstAttrSpec.connectionMarkers["/Variant.attr2"], "final") self.assertTrue( dstAttrSpec.connectionMappers["/Variant.attr2"].typeName, "mapper")