def test_primNonBatchedDiffs(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) counter = PrimSignalCounter(dm.signalPrimSelectionChanged) def checkDiff(expectedAdded, expectedRemoved): self.assertEqual(counter.getAndClearNumSignals(), 1) added, removed = counter.getLastSignalParameters() self.assertSetEqual(added, expectedAdded) self.assertSetEqual(removed, expectedRemoved) dm.addPrim(stage.foo) checkDiff({stage.foo.GetPath()}, set()) dm.togglePrim(stage.bar) checkDiff({stage.bar.GetPath()}, set()) dm.removePrim(stage.root) checkDiff(set(), {stage.root.GetPath()}) dm.clearPrims() checkDiff({stage.root.GetPath()}, {stage.foo.GetPath(), stage.bar.GetPath()}) dm.setPrim(stage.foo) checkDiff({stage.foo.GetPath()}, {stage.root.GetPath()})
def test_primNonBatchedDiffs(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) counter = PrimSignalCounter(dm.signalPrimSelectionChanged) def checkDiff(expectedAdded, expectedRemoved): self.assertEqual(counter.getAndClearNumSignals(), 1) added, removed = counter.getLastSignalParameters() self.assertSetEqual(added, expectedAdded) self.assertSetEqual(removed, expectedRemoved) dm.addPrim(stage.foo) checkDiff({stage.foo.GetPath()}, set()) dm.togglePrim(stage.bar) checkDiff({stage.bar.GetPath()}, set()) dm.removePrim(stage.root) checkDiff(set(), {stage.root.GetPath()}) dm.clearPrims() checkDiff( {stage.root.GetPath()}, {stage.foo.GetPath(), stage.bar.GetPath()}) dm.setPrim(stage.foo) checkDiff({stage.foo.GetPath()}, {stage.root.GetPath()})
def test_removePrimInstance(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.setPrim(stage.foo) dm.addPrim(stage.bar, 1) dm.addPrim(stage.bar, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, stage.bar: {1, 2} }) # Remove a prim instance from the selection. dm.removePrim(stage.bar, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, stage.bar: {2} }) # Remove the last instance of a prim from the selection. dm.removePrim(stage.bar, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, }) # Try to remove a prim instance from the selection which does not exist. # Selection should not change. dm.removePrim(stage.bar, 3) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, }) # Remove a single prim instance when all instances of the prim are # selected. dm.removePrim(stage.foo, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES }) # Try to remove a single instance of the root prim when it is the only # selected prim. All instances of the root prim should remain selected. dm.removePrim(stage.root, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES }) # Test validation. with self.assertRaises(ValueError): dm.removePrim(stage.foo, None)
def test_removePrimInstance(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.setPrim(stage.foo) dm.addPrim(stage.bar, 1) dm.addPrim(stage.bar, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, stage.bar: {1, 2} }) # Remove a prim instance from the selection. dm.removePrim(stage.bar, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, stage.bar: {2} }) # Remove the last instance of a prim from the selection. dm.removePrim(stage.bar, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, }) # Try to remove a prim instance from the selection which does not exist. # Selection should not change. dm.removePrim(stage.bar, 3) self.assertDictEqual(dm.getPrimInstances(), { stage.foo: ALL_INSTANCES, }) # Remove a single prim instance when all instances of the prim are # selected. dm.removePrim(stage.foo, 1) self.assertDictEqual(dm.getPrimInstances(), {stage.root: ALL_INSTANCES}) # Try to remove a single instance of the root prim when it is the only # selected prim. All instances of the root prim should remain selected. dm.removePrim(stage.root, 1) self.assertDictEqual(dm.getPrimInstances(), {stage.root: ALL_INSTANCES}) # Test validation. with self.assertRaises(ValueError): dm.removePrim(stage.foo, None)
def test_addPrimInstance(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES }) # Add a single prim instance. dm.addPrim(stage.foo, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: {1} }) # Add a different prim instance. dm.addPrim(stage.foo, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: {1, 2} }) # Add all instances of the prim. dm.addPrim(stage.foo) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: ALL_INSTANCES }) # Add a single instance. This should wipe out ALL_INSTANCES and leave # only the single instance in the prim's selected instances. dm.addPrim(stage.foo, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: {1} }) # Test validation. with self.assertRaises(ValueError): dm.addPrim(stage.foo, None)
def test_addPrimInstance(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) self.assertDictEqual(dm.getPrimInstances(), {stage.root: ALL_INSTANCES}) # Add a single prim instance. dm.addPrim(stage.foo, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: {1} }) # Add a different prim instance. dm.addPrim(stage.foo, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: {1, 2} }) # Add all instances of the prim. dm.addPrim(stage.foo) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: ALL_INSTANCES }) # Add a single instance. This should wipe out ALL_INSTANCES and leave # only the single instance in the prim's selected instances. dm.addPrim(stage.foo, 1) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: {1} }) # Test validation. with self.assertRaises(ValueError): dm.addPrim(stage.foo, None)
def test_switchToPrim(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) dm.setPrim(stage.foo) dm.addProp(stage.foo_one) dm.addProp(stage.foo_two) dm.addComputedProp(stage.foo_bbox) self.assertListEqual(dm.getPrims(), [stage.foo]) self.assertListEqual(dm.getProps(), [stage.foo_one, stage.foo_two]) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox]) # Switch selection to just bar, and convert all of foo's selected # properties to bar. dm.switchToPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.bar]) self.assertListEqual(dm.getProps(), [stage.bar_one, stage.bar_two]) self.assertListEqual(dm.getComputedProps(), [stage.bar_bbox]) # Add foo to the selection. dm.addPrim(stage.foo) # Since two prims are selected, preserve property selection. dm.switchToPrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.foo]) self.assertListEqual(dm.getProps(), [stage.bar_one, stage.bar_two]) self.assertListEqual(dm.getComputedProps(), [stage.bar_bbox]) # Add foo.one to the selection. dm.addProp(stage.foo_one) # Since properties which belong to different prims are selected, # preserve the property selection. dm.switchToPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.bar]) self.assertListEqual(dm.getProps(), [stage.bar_one, stage.bar_two, stage.foo_one]) self.assertListEqual(dm.getComputedProps(), [stage.bar_bbox])
def test_primBatchedDiffs(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) counter = PrimSignalCounter(dm.signalPrimSelectionChanged) def checkDiff(expectedAdded, expectedRemoved): self.assertEqual(counter.getAndClearNumSignals(), 1) added, removed = counter.getLastSignalParameters() self.assertSetEqual(added, expectedAdded) self.assertSetEqual(removed, expectedRemoved) # Clear selection then add a single prim. with dm.batchPrimChanges: # Clearing during a batch should not add the root prim to the # selection unless the selection is still clear at the end of the # batch. dm.clearPrims() # Since we add a prim before the end of the batch, the root prim is # not added to the selection. dm.addPrim(stage.foo) # Signal shouldn't be emitted yet! self.assertEqual(counter.getAndClearNumSignals(), 0) checkDiff({stage.foo.GetPath()}, {stage.root.GetPath()}) # Add a prim then remove it. This should generate an empty diff because # there is no net change in the prim selection. with dm.batchPrimChanges: dm.addPrim(stage.bar) dm.removePrim(stage.bar) checkDiff(set(), set()) # Clear selection without adding any prims back. with dm.batchPrimChanges: # Clearing during a batch should not add the root prim to the # selection unless the selection is still clear at the end of the # batch. dm.clearPrims() # Since we don't add any prim to the empty selection before the end # of the batch, the root prim is added. checkDiff({stage.root.GetPath()}, {stage.foo.GetPath()}) # Clear root from the selection, add it back, then add another prim. with dm.batchPrimChanges: dm.clearPrims() dm.addPrim(stage.root) dm.addPrim(stage.foo) # The root prim existed in the selection before, so it is not in any # part of the diff. checkDiff({stage.foo.GetPath()}, set())
def test_clearPrims(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.addPrim(stage.foo) dm.addPrim(stage.bar, 1) dm.addPrim(stage.bar, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: ALL_INSTANCES, stage.bar: {1, 2} }) # Clear the prim selection. dm.clearPrims() self.assertDictEqual(dm.getPrimInstances(), {stage.root: ALL_INSTANCES})
def test_getLCDPrims(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) # If the root prim is the only selected prim, it is also the only prim # in the LCD prims. This is the only case where the root is in the LCD # prims. self.assertListEqual(dm.getPrims(), [stage.root]) self.assertListEqual(dm.getLCDPrims(), [stage.root]) # LCD prims should exclude the root and any prims whose ancestors are # also in the selection but not the root prim. dm.setPrim(stage.root) dm.addPrim(stage.foo) dm.addPrim(stage.parent) dm.addPrim(stage.child1) self.assertListEqual(dm.getLCDPrims(), [stage.foo, stage.parent]) # Removing a prim from the selection can reveal prims in the LCD prims. dm.togglePrim(stage.parent) self.assertListEqual(dm.getLCDPrims(), [stage.foo, stage.child1]) # If a prim has any instances selected, it may be in the LCD prims. dm.addPrim(stage.child2, 1) self.assertListEqual(dm.getLCDPrims(), [stage.foo, stage.child1, stage.child2])
def test_clearPrims(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.addPrim(stage.foo) dm.addPrim(stage.bar, 1) dm.addPrim(stage.bar, 2) self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES, stage.foo: ALL_INSTANCES, stage.bar: {1, 2} }) # Clear the prim selection. dm.clearPrims() self.assertDictEqual(dm.getPrimInstances(), { stage.root: ALL_INSTANCES })
def test_removePrim(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.setPrim(stage.foo) dm.addPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.foo, stage.bar]) # Remove a prim. dm.removePrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.bar]) # Try to remove a prim that is not in the selection. Selection shouldn't # change. dm.removePrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.bar]) # Remove the last prim in the selection. Root prim should become # selected. dm.removePrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.root]) # Try to remove the root prim when it is the only prim in the selection. # It should remain selected. dm.removePrim(stage.root) self.assertListEqual(dm.getPrims(), [stage.root]) # Test validation. with self.assertRaises(ValueError): dm.removePrim(stage.foo_one)
def test_getFocusPrim(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) # Root should be in focus first. self.assertListEqual(dm.getPrims(), [stage.root]) self.assertEqual(dm.getFocusPrim(), stage.root) # The last set prim should be in focus. dm.setPrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.foo]) self.assertEqual(dm.getFocusPrim(), stage.foo) # Adding a prim does not change the focus. dm.addPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.foo, stage.bar]) self.assertEqual(dm.getFocusPrim(), stage.foo) # Toggling out the focus prim changes the focus to the next available # prim in the selection order. dm.togglePrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.bar]) self.assertEqual(dm.getFocusPrim(), stage.bar) # Setting the prims changes the focus prim to the first in the given # list. dm.setPrim(stage.foo) dm.addPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.foo, stage.bar]) self.assertEqual(dm.getFocusPrim(), stage.foo)
def test_addPrim(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) self.assertListEqual(dm.getPrims(), [stage.root]) # Add a prim. dm.addPrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.root, stage.foo]) # Add a prim that is already selected. Selection shouldn't change. dm.addPrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.root, stage.foo]) # Test validation. with self.assertRaises(ValueError): dm.addPrim(stage.foo_one)
def test_primInstancesNonBatchedDiffs(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) counter = PrimSignalCounter(dm.signalPrimSelectionChanged) def checkDiff(expectedAdded, expectedRemoved): self.assertEqual(counter.getAndClearNumSignals(), 1) added, removed = counter.getLastSignalParameters() self.assertSetEqual(added, expectedAdded) self.assertSetEqual(removed, expectedRemoved) # Add some instances, then remove them. Adding instances to an already- # selected prim does not add it to the diff. Removing instances but # leaving some selected does not add the prim to the diff. dm.addPrim(stage.foo, 1) checkDiff({stage.foo.GetPath()}, set()) dm.addPrim(stage.foo, 2) checkDiff(set(), set()) dm.removePrim(stage.foo, 1) checkDiff(set(), set()) dm.removePrim(stage.foo, 2) checkDiff(set(), {stage.foo.GetPath()}) # Toggle some instances on, then off again. When an instance is toggled # but doesn't change whether the prim is selected, the prim is not added # to the diff. dm.togglePrim(stage.foo, 1) checkDiff({stage.foo.GetPath()}, set()) dm.togglePrim(stage.foo, 2) checkDiff(set(), set()) dm.togglePrim(stage.foo, 1) checkDiff(set(), set()) dm.togglePrim(stage.foo, 2) checkDiff(set(), {stage.foo.GetPath()}) # Toggle all instances of a prim on, then toggle a single instance on, # then toggle all instances on and off. This exercises the diffs for the # less-intuitive behavior of toggling a single instance when all are # selected and vice-versa. # Select all instances. dm.togglePrim(stage.foo) checkDiff({stage.foo.GetPath()}, set()) # Select just a single instance. dm.togglePrim(stage.foo, 1) checkDiff(set(), set()) # Select all instances again. dm.togglePrim(stage.foo) checkDiff(set(), set()) # Deselect the prim. dm.togglePrim(stage.foo) checkDiff(set(), {stage.foo.GetPath()}) # Set some instances. Setting instances on an already-selected prim does # not add the prim to the selection. dm.setPrim(stage.foo, 1)