def setPrim(self, prim): prim_index = prim.GetPrimIndex() self.index_box.setText(prim_index.DumpToString()) tree = self.composition_tree tree.clear() query = Usd.PrimCompositionQuery(prim) tree_items = dict() # Sdf.Layer: QTreeWidgetItem for arc in query.GetCompositionArcs(): strings = [str(getter(arc)) for getter in _COLUMNS.values()] intro_layer = arc.GetIntroducingLayer() if intro_layer and intro_layer in tree_items: parent = tree_items[intro_layer] else: parent = tree target_layer = arc.GetTargetNode().layerStack.identifier.rootLayer tree_items[target_layer] = QtWidgets.QTreeWidgetItem( parent, strings) tree.expandAll() fd, fp = tempfile.mkstemp() prim_index.DumpToDotGraph(fp) self._dot_view.setDotPath(fp)
def test_PrimCompositionQuery(self): self.maxDiff = None layerFile = 'test.usda' layer = Sdf.Layer.FindOrOpen(layerFile) assert layer, 'failed to find "test.usda' stage = Usd.Stage.Open(layerFile) assert stage, 'failed to create stage for %s' % layerFile prim = stage.GetPrimAtPath('/Sarah') assert prim, 'failed to find prim /Sarah' # Explicit set of expected values that should match the unfiltered query expectedValues = [{ 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah'), 'arcType': Pcp.ArcTypeRoot, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': None, 'introPath': Sdf.Path(), 'introInListEdit': None, 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/_class_Sarah'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Path('/_class_Sarah'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': False, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub1.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'isImplicit': True, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': False, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_root.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref'), 'isImplicit': True, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah{displayColor=red}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': 'displayColor', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah{standin=render}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': 'standin', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah{standin=render}{lod=full}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah{standin=render}'), 'introInListEdit': 'lod', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Defaults'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Reference('test.usda', '/Sarah_Defaults'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Defaults'), 'introInListEdit': Sdf.Reference('test.usda', '/Sarah_Base'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base{displayColor=red}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Base'), 'introInListEdit': 'displayColor', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Defaults'), 'introInListEdit': Sdf.Reference('test.usda', '/Sarah_Base', Sdf.LayerOffset(10)), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base{displayColor=red}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Base'), 'introInListEdit': 'displayColor', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Ref'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Reference('testAPI_root.usda', '/Sarah_Ref'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': True, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub1.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': True, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_root.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Internal_Payload'), 'arcType': Pcp.ArcTypePayload, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Payload(primPath='/Sarah_Internal_Payload'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Payload'), 'arcType': Pcp.ArcTypePayload, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Payload('testAPI_root.usda', '/Sarah_Payload'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'arcType': Pcp.ArcTypeSpecialize, 'hasSpecs': True, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub2.usda'), 'introPath': Sdf.Path('/Sarah_Payload'), 'introInListEdit': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'isImplicit': True, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Container/_class_Sarah_Inherited'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': False, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'introInListEdit': Sdf.Path('/Sarah_Container/_class_Sarah_Inherited'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Container_Ref/_class_Sarah_Inherited'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Container'), 'introInListEdit': Sdf.Reference('testAPI_root.usda', '/Sarah_Container_Ref'), 'isImplicit': False, 'isAncestral': True, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Container_Ref/_class_Sarah_Specialized'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Container'), 'introInListEdit': Sdf.Reference('testAPI_root.usda', '/Sarah_Container_Ref'), 'isImplicit': False, 'isAncestral': True, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'arcType': Pcp.ArcTypeSpecialize, 'hasSpecs': False, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub2.usda'), 'introPath': Sdf.Path('/Sarah_Payload'), 'introInListEdit': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }] # Create the query on the prim. query = Usd.PrimCompositionQuery(prim) # Can use this to print out the unfiltered arcs if desired. Can be # useful in updating expectedValues if need be. #self.PrintExpectedValues(query.GetCompositionArcs()) # Verify the arcs match the expected arcs def _VerifyExpectedArcs(arcs, expectedArcValues): self.assertEqual(len(arcs), len(expectedArcValues)) for arc, expected in zip(arcs, expectedArcValues): self.assertEqual(self._GetArcValuesDict(arc), expected) # Helper function for verifying that the introducing layer and path # for an arc actually introduce the arc. def _VerifyArcIntroducingInfo(arc): listEditor, entry = arc.GetIntroducingListEditor() if arc.GetArcType() == Pcp.ArcTypeRoot: assert listEditor is None assert entry is None self.assertEqual(arc.GetTargetNode(), arc.GetIntroducingNode()) self.assertFalse(arc.GetIntroducingLayer()) self.assertFalse(arc.GetIntroducingPrimPath()) else: # The introducing prim spec is obtained from the introducing layer # and prim path. primSpec = arc.GetIntroducingLayer().GetPrimAtPath( arc.GetIntroducingPrimPath()) assert primSpec assert listEditor assert entry listEntries = listEditor.ApplyEditsToList([]) assert listEntries self.assertIn(entry, listEntries) if arc.GetArcType() == Pcp.ArcTypeReference: self.assertEqual( listEntries, primSpec.referenceList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypePayload: self.assertEqual(listEntries, primSpec.payloadList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypeInherit: self.assertEqual( listEntries, primSpec.inheritPathList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypeSpecialize: self.assertEqual( listEntries, primSpec.specializesList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypeVariant: self.assertEqual( listEntries, primSpec.variantSetNameList.ApplyEditsToList([])) # Updates the query with a new filter and compares expected values # while also checking that our introducing layers have specs that # actually introduce the arc. def CheckWithFilter( expectedFilteredValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.All, arcIntroducedFilter=Usd.PrimCompositionQuery. ArcIntroducedFilter.All, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.All, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.All): # Create an updated filter for the query. qFilter = Usd.PrimCompositionQuery.Filter() qFilter.arcTypeFilter = arcTypeFilter qFilter.arcIntroducedFilter = arcIntroducedFilter qFilter.dependencyTypeFilter = dependencyTypeFilter qFilter.hasSpecsFilter = hasSpecsFilter query.filter = qFilter # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs _VerifyExpectedArcs(arcs, expectedFilteredValues) # Verify that the "introducing" APIs return what we expect for # each arc. for arc in arcs: _VerifyArcIntroducingInfo(arc) # First verify the unfiltered query. CheckWithFilter(expectedValues) # Now we verify each single type filter. We filter the expected values # and the results of each query should match. We explicity verify the # the length of the each filtered expected value list as an extra # verification that the test is working as expected. # Arc type filters filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeReference ] self.assertEqual(len(filteredExpectedValues), 6) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Reference) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypePayload ] self.assertEqual(len(filteredExpectedValues), 2) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Payload) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeInherit ] self.assertEqual(len(filteredExpectedValues), 6) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Inherit) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeSpecialize ] self.assertEqual(len(filteredExpectedValues), 2) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Specialize) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeVariant ] print(filteredExpectedValues) self.assertEqual(len(filteredExpectedValues), 5) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Variant) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] in [Pcp.ArcTypeReference, Pcp.ArcTypePayload] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. ReferenceOrPayload) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] in [Pcp.ArcTypeInherit, Pcp.ArcTypeSpecialize] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. InheritOrSpecialize) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] not in [Pcp.ArcTypeReference, Pcp.ArcTypePayload] ] self.assertEqual(len(filteredExpectedValues), 14) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. NotReferenceOrPayload) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] not in [Pcp.ArcTypeInherit, Pcp.ArcTypeSpecialize] ] self.assertEqual(len(filteredExpectedValues), 14) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. NotInheritOrSpecialize) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] != Pcp.ArcTypeVariant ] self.assertEqual(len(filteredExpectedValues), 17) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant) # Arc introduced filters filteredExpectedValues = [ d for d in expectedValues if d['isIntroRootLayer'] ] self.assertEqual(len(filteredExpectedValues), 16) CheckWithFilter(filteredExpectedValues, arcIntroducedFilter=Usd.PrimCompositionQuery. ArcIntroducedFilter.IntroducedInRootLayerStack) filteredExpectedValues = [ d for d in expectedValues if d['isIntroRootLayerPrim'] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter(filteredExpectedValues, arcIntroducedFilter=Usd.PrimCompositionQuery. ArcIntroducedFilter.IntroducedInRootLayerPrimSpec) # Dependency type filters filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] ] self.assertEqual(len(filteredExpectedValues), 20) CheckWithFilter(filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.Direct) filteredExpectedValues = [ d for d in expectedValues if d['isAncestral'] ] self.assertEqual(len(filteredExpectedValues), 2) CheckWithFilter(filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.Ancestral) # Has specs filters filteredExpectedValues = [d for d in expectedValues if d['hasSpecs']] self.assertEqual(len(filteredExpectedValues), 18) CheckWithFilter( filteredExpectedValues, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs) filteredExpectedValues = [ d for d in expectedValues if not d['hasSpecs'] ] self.assertEqual(len(filteredExpectedValues), 4) CheckWithFilter( filteredExpectedValues, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasNoSpecs) # Test combining filter types # Start with a dependency type filter filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] ] self.assertEqual(len(filteredExpectedValues), 20) CheckWithFilter(filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.Direct) # Add an arc type filter. Note that we refilter the already filtered # expected values unlike the cases above. filteredExpectedValues = [ d for d in filteredExpectedValues if d['arcType'] != Pcp.ArcTypeVariant ] self.assertEqual(len(filteredExpectedValues), 15) CheckWithFilter( filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery.DependencyTypeFilter. Direct, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant) # Add a has specs filter filteredExpectedValues = [ d for d in filteredExpectedValues if d['hasSpecs'] ] self.assertEqual(len(filteredExpectedValues), 11) CheckWithFilter( filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery.DependencyTypeFilter. Direct, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs) # Add an arc introduced filter. filteredExpectedValues = [ d for d in filteredExpectedValues if d['isIntroRootLayer'] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter( filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery.DependencyTypeFilter. Direct, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs, arcIntroducedFilter=Usd.PrimCompositionQuery.ArcIntroducedFilter. IntroducedInRootLayerStack) # Test the pre-defined queries # Direct references query = Usd.PrimCompositionQuery.GetDirectReferences(prim) self.assertEqual(query.filter.arcTypeFilter, Usd.PrimCompositionQuery.ArcTypeFilter.Reference) self.assertEqual(query.filter.dependencyTypeFilter, Usd.PrimCompositionQuery.DependencyTypeFilter.Direct) self.assertEqual(query.filter.arcIntroducedFilter, Usd.PrimCompositionQuery.ArcIntroducedFilter.All) self.assertEqual(query.filter.hasSpecsFilter, Usd.PrimCompositionQuery.HasSpecsFilter.All) # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] and d['arcType'] == Pcp.ArcTypeReference ] _VerifyExpectedArcs(arcs, filteredExpectedValues) # Direct inherits query = Usd.PrimCompositionQuery.GetDirectInherits(prim) self.assertEqual(query.filter.arcTypeFilter, Usd.PrimCompositionQuery.ArcTypeFilter.Inherit) self.assertEqual(query.filter.dependencyTypeFilter, Usd.PrimCompositionQuery.DependencyTypeFilter.Direct) self.assertEqual(query.filter.arcIntroducedFilter, Usd.PrimCompositionQuery.ArcIntroducedFilter.All) self.assertEqual(query.filter.hasSpecsFilter, Usd.PrimCompositionQuery.HasSpecsFilter.All) # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] and d['arcType'] == Pcp.ArcTypeInherit ] _VerifyExpectedArcs(arcs, filteredExpectedValues) # Direct root layer arcs query = Usd.PrimCompositionQuery.GetDirectRootLayerArcs(prim) self.assertEqual(query.filter.arcTypeFilter, Usd.PrimCompositionQuery.ArcTypeFilter.All) self.assertEqual(query.filter.dependencyTypeFilter, Usd.PrimCompositionQuery.DependencyTypeFilter.Direct) self.assertEqual( query.filter.arcIntroducedFilter, Usd.PrimCompositionQuery. ArcIntroducedFilter.IntroducedInRootLayerStack) self.assertEqual(query.filter.hasSpecsFilter, Usd.PrimCompositionQuery.HasSpecsFilter.All) # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] and d['isIntroRootLayer'] ] _VerifyExpectedArcs(arcs, filteredExpectedValues) # test to make sure c++ objects are propertly destroyed when # PrimCollectionQuery instance is garbage collection stage = Usd.Stage.CreateInMemory("testCreationAndGarbageCollect.usda") Usd.PrimCompositionQuery(stage.GetPseudoRoot()) sessionLayer = stage.GetSessionLayer() del stage self.assertTrue(sessionLayer.expired)
def setStage(self, stage): """Sets the USD stage the spreadsheet is looking at.""" self._stage = stage for table in self._layers, self._prims: table.model.clear() table.table.setSortingEnabled(False) # labels are on the header widgets self._layers.model.setHorizontalHeaderLabels( [''] * len(_LAYERS_COMPOSITION_LAYER_IDS)) self._prims.model.setHorizontalHeaderLabels( [''] * len(_LAYERS_COMPOSITION_PRIM_PATHS)) self._graph = graph = networkx.DiGraph(tooltip="My label") # legend arcs_to_display = { # should include all? Pcp.ArcTypePayload: dict(color=10, colorscheme="paired12", fontcolor=10), # purple Pcp.ArcTypeReference: dict(color=6, colorscheme="paired12", fontcolor=6), # red Pcp.ArcTypeVariant: dict(color=8, colorscheme="paired12", fontcolor=8), # yellow } legend_node_ids = set() for arc_type, edge_attrs in arcs_to_display.items(): label = f" {arc_type.displayName}" arc_node_indices = {len(legend_node_ids), len(legend_node_ids) + 1} graph.add_nodes_from(arc_node_indices, style='invis') graph.add_edge(*arc_node_indices, label=label, **edge_attrs) legend_node_ids.update(arc_node_indices) layer_stacks_by_node_idx = dict() stack_id_by_node_idx = dict.fromkeys( legend_node_ids) # {42: layer.identifier} self._node_index_by_id = node_index_by_id = dict.fromkeys( legend_node_ids) # {layer.identifier: 42} self._paths = paths = defaultdict( set) # {layer.identifier: {path1, ..., pathN}} def _layer_label(layer): return Path(layer.realPath).stem or layer.identifier def _walk_layer_tree(tree): yield tree.layer for childtree in tree.childTrees: yield from _walk_layer_tree(childtree) def _add_node(pcp_node): layer_stack = pcp_node.layerStack root_layer = layer_stack.identifier.rootLayer root_id = root_layer.identifier if root_id in node_index_by_id: return stack_index = len(stack_id_by_node_idx) node_index_by_id[root_id] = stack_index stack_id_by_node_idx[stack_index] = root_id label = f"{{{_layer_label(root_layer)}" sublayers = [ layer for layer in _walk_layer_tree(layer_stack.layerTree) ] layer_stacks_by_node_idx[stack_index] = sublayers for layer in sublayers: if layer == root_layer: continue node_index_by_id[layer.identifier] = stack_index label += f"|{_layer_label(layer)}" label += "}" ids = '\n'.join(f"{i}: {layer.realPath or layer.identifier}" for i, layer in enumerate(sublayers)) tooltip = f"Layer Stack:\n{ids}" # https://stackoverflow.com/questions/16671966/multiline-tooltip-for-pydot-graph tooltip = tooltip.replace('\n', ' ') graph.add_node(stack_index, style='rounded', shape='record', label=label, tooltip=tooltip, title='world', href=f"node_id_{stack_index}") # only query composition arcs that have specs on our prims. qFilter = Usd.PrimCompositionQuery.Filter() qFilter.hasSpecsFilter = Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs for prim in stage.TraverseAll(): path_str = str(prim.GetPath()) query = Usd.PrimCompositionQuery(prim) query.filter = qFilter for arc in query.GetCompositionArcs(): _add_node(arc.GetTargetNode()) target = arc.GetTargetNode().layerStack.identifier.rootLayer target_id = target.identifier target_stack_idx = node_index_by_id[target_id] for layer in layer_stacks_by_node_idx[ node_index_by_id[target_id]]: paths[layer.identifier].add(path_str) intro = arc.GetIntroducingLayer() if intro: assert intro.identifier in node_index_by_id, f"Expected {intro} to be on {node_index_by_id.keys()}" edge_attrs = arcs_to_display[arc.GetArcType()] source_stack_idx = node_index_by_id[intro.identifier] graph.add_edge(source_stack_idx, target_stack_idx, **edge_attrs) layers_model = self._layers.model def _createItem(layer): item = QtGui.QStandardItem(layer.identifier) item.setData(layer, QtCore.Qt.UserRole) return item items_to_add = [ # QtGui.QStandardItem(layer.identifier) _createItem(layer) for node_id in sorted(set(graph.nodes) - legend_node_ids) for layer in layer_stacks_by_node_idx[node_id] ] layers_model.setRowCount(len(items_to_add)) layers_model.blockSignals( True) # prevent unneeded events from computing for index, item in enumerate(items_to_add): layers_model.setItem(index, 0, item) layers_model.blockSignals(False) for table in self._layers, self._prims: table.table.setSortingEnabled(True)
def getData(self): query = Usd.PrimCompositionQuery(self._prim) arcValueDicList = [ self._getDict(arc) for arc in query.GetCompositionArcs() ] return arcValueDicList