def test_removeComputedProp(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) dm.setComputedProp(stage.foo_bbox) dm.addComputedProp(stage.foo_xform) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox, stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Remove a property. dm.removeComputedProp(stage.foo_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Try to remove a property not in the selection. Nothing should happen. dm.removeComputedProp(stage.foo_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Remove the last property. dm.removeComputedProp(stage.foo_xform) self.assertListEqual(dm.getComputedProps(), []) self.assertEqual(dm.getFocusComputedProp(), None) # Test validation. with self.assertRaises(ValueError): dm.removeComputedProp(stage.foo)
def test_computedPropBatchedChanges(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) counter = PropSignalCounter(dm.signalComputedPropSelectionChanged) # Add some props in a batch. with dm.batchComputedPropChanges: dm.addComputedProp(stage.foo_bbox) dm.addComputedProp(stage.foo_xform) # Signal shouldn't be emitted yet! self.assertEqual(counter.getAndClearNumSignals(), 0) self.assertEqual(counter.getAndClearNumSignals(), 1) # Add a prop, then remove it immediately. A signal will still be # emitted. with dm.batchComputedPropChanges: dm.addComputedProp(stage.bar_bbox) dm.removeComputedProp(stage.bar_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) # Clear the props then add some back. with dm.batchComputedPropChanges: dm.clearComputedProps() dm.addComputedProp(stage.foo_xform) dm.addComputedProp(stage.bar_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1)
def test_computedPropBatchedChanges(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) counter = PropSignalCounter(dm.signalComputedPropSelectionChanged) # Add some props in a batch. with dm.batchComputedPropChanges: dm.addComputedProp(stage.foo_bbox) dm.addComputedProp(stage.foo_xform) # Signal shouldn't be emitted yet! self.assertEqual(counter.getAndClearNumSignals(), 0) self.assertEqual(counter.getAndClearNumSignals(), 1) # Add a prop, then remove it immediately. A signal will still be # emitted. with dm.batchComputedPropChanges: dm.addComputedProp(stage.bar_bbox) dm.removeComputedProp(stage.bar_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) # Clear the props then add some back. with dm.batchComputedPropChanges: dm.clearComputedProps() dm.addComputedProp(stage.foo_xform) dm.addComputedProp(stage.bar_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1)
def test_removeComputedProp(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) dm.setComputedProp(stage.foo_bbox) dm.addComputedProp(stage.foo_xform) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox, stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Remove a property. dm.removeComputedProp(stage.foo_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Try to remove a property not in the selection. Nothing should happen. dm.removeComputedProp(stage.foo_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Remove the last property. dm.removeComputedProp(stage.foo_xform) self.assertListEqual(dm.getComputedProps(), []) self.assertEqual(dm.getFocusComputedProp(), None) # Test validation. with self.assertRaises(ValueError): dm.removeComputedProp(stage.foo)
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_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_clearComputedProps(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) dm.setComputedProp(stage.foo_bbox) dm.addComputedProp(stage.foo_xform) dm.addComputedProp(stage.bar_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox, stage.foo_xform, stage.bar_bbox]) self.assertEqual(dm.getFocusComputedProp(), stage.bar_bbox) # Clear the property selection. dm.clearComputedProps() self.assertListEqual(dm.getComputedProps(), []) self.assertEqual(dm.getFocusComputedProp(), None)
def test_clearComputedProps(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) dm.setComputedProp(stage.foo_bbox) dm.addComputedProp(stage.foo_xform) dm.addComputedProp(stage.bar_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox, stage.foo_xform, stage.bar_bbox]) self.assertEqual(dm.getFocusComputedProp(), stage.bar_bbox) # Clear the property selection. dm.clearComputedProps() self.assertListEqual(dm.getComputedProps(), []) self.assertEqual(dm.getFocusComputedProp(), None)
def test_addComputedProp(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) # Property selection starts empty. self.assertListEqual(dm.getComputedProps(), []) self.assertEqual(dm.getFocusComputedProp(), None) # Add a property. dm.addComputedProp(stage.foo_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_bbox) # Properties remain in the order they are added. dm.addComputedProp(stage.foo_xform) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox, stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Test validation. with self.assertRaises(ValueError): dm.addComputedProp(stage.foo)
def test_addComputedProp(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) # Property selection starts empty. self.assertListEqual(dm.getComputedProps(), []) self.assertEqual(dm.getFocusComputedProp(), None) # Add a property. dm.addComputedProp(stage.foo_bbox) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_bbox) # Properties remain in the order they are added. dm.addComputedProp(stage.foo_xform) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox, stage.foo_xform]) self.assertEqual(dm.getFocusComputedProp(), stage.foo_xform) # Test validation. with self.assertRaises(ValueError): dm.addComputedProp(stage.foo)
def test_computedPropNonBatchedChanges(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) counter = PropSignalCounter(dm.signalComputedPropSelectionChanged) # Adding/removing/setting/clearing props all emit a single signal. dm.addComputedProp(stage.foo_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.removeComputedProp(stage.foo_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.setComputedProp(stage.foo_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.clearComputedProps() self.assertEqual(counter.getAndClearNumSignals(), 1)
def test_computedPropNonBatchedChanges(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) counter = PropSignalCounter(dm.signalComputedPropSelectionChanged) # Adding/removing/setting/clearing props all emit a single signal. dm.addComputedProp(stage.foo_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.removeComputedProp(stage.foo_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.setComputedProp(stage.foo_bbox) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.clearComputedProps() self.assertEqual(counter.getAndClearNumSignals(), 1)