Ejemplo n.º 1
0
    def testObservableScene(self):
        # Setup
        ca = ufe.PathComponent("a")
        cb = ufe.PathComponent("b")
        cc = ufe.PathComponent("c")

        sa = ufe.PathSegment([ca], 3, '/')
        sab = ufe.PathSegment([ca, cb], 1, '|')
        sc = ufe.PathSegment([cc], 2, '/')

        a = ufe.Path(sa)
        b = ufe.Path(sab)
        c = ufe.Path([sab, sc])

        itemA = TestSceneItem(a)
        itemB = TestSceneItem(b)
        itemC = TestSceneItem(c)
        # End Setup

        # No observers from the test yet, but Maya could have observers
        # created on startup
        initialNbObservers = ufe.Scene.nbObservers()

        snObs = TestObserver()

        # Add observer to the scene.
        ufe.Scene.addObserver(snObs)

        # Order of expected notifications. No notifications yet.
        self.checkNotifications(snObs, [0, 0, 0, 0, 0, 0])

        self.assertEqual(ufe.Scene.nbObservers() - initialNbObservers, 1)
        self.assertTrue(ufe.Scene.hasObserver(snObs))

        ufe.Scene.notify(ufe.ObjectAdd(itemA))

        # we should now have an ObjectAdd notification
        self.checkNotifications(snObs, [1, 0, 0, 0, 0, 0])
Ejemplo n.º 2
0
    def testUsdGroup(self):
        '''Creation of USD group objects.'''

        # Get parent of new group.
        propsPath = ufe.Path([
            mayaUtils.createUfePathSegment("|world|transform1|proxyShape1"),
            usdUtils.createUfePathSegment("/Room_set/Props")
        ])
        propsItem = ufe.Hierarchy.createItem(propsPath)
        propsHierarchy = ufe.Hierarchy.hierarchy(propsItem)
        propsChildrenPre = propsHierarchy.children()

        groupPath = propsPath + "newGroup"

        # Create new group.
        group = propsHierarchy.createGroupCmd(ufe.PathComponent("newGroup"))

        self.assertIsNotNone(group.item)
        # MAYA-92350: must re-create hierarchy interface object.  Fix ASAP.
        # PPT, 19-Nov-2018.
        propsHierarchy = ufe.Hierarchy.hierarchy(propsItem)
        propsChildrenPost = propsHierarchy.children()
        self.assertEqual(len(propsChildrenPre) + 1, len(propsChildrenPost))
        childrenPaths = set([child.path() for child in propsChildrenPost])
        self.assertTrue(groupPath in childrenPaths)

        # Undo
        group.undoableCommand.undo()

        # MAYA-92350: must re-create hierarchy interface object.  Fix ASAP.
        # PPT, 19-Nov-2018.
        propsHierarchy = ufe.Hierarchy.hierarchy(propsItem)
        propsChildrenPostUndo = propsHierarchy.children()
        self.assertEqual(len(propsChildrenPre), len(propsChildrenPostUndo))
        childrenPaths = set([child.path() for child in propsChildrenPostUndo])
        self.assertFalse(groupPath in childrenPaths)
Ejemplo n.º 3
0
    def testUsdGroup(self):
        '''Creation of USD group objects.'''

        mayaPathSegment = mayaUtils.createUfePathSegment(
            "|world|transform1|proxyShape1")

        usdSegmentBall5 = usdUtils.createUfePathSegment(
            "/Ball_set/Props/Ball_5")
        ball5Path = ufe.Path([mayaPathSegment, usdSegmentBall5])
        ball5Item = ufe.Hierarchy.createItem(ball5Path)

        usdSegmentBall3 = usdUtils.createUfePathSegment(
            "/Ball_set/Props/Ball_3")
        ball3Path = ufe.Path([mayaPathSegment, usdSegmentBall3])
        ball3Item = ufe.Hierarchy.createItem(ball3Path)

        usdSegmentProps = usdUtils.createUfePathSegment("/Ball_set/Props")
        parentPath = ufe.Path([mayaPathSegment, usdSegmentProps])
        parentItem = ufe.Hierarchy.createItem(parentPath)

        parentHierarchy = ufe.Hierarchy.hierarchy(parentItem)
        parentChildrenPre = parentHierarchy.children()
        self.assertEqual(len(parentChildrenPre), 6)

        newGroupName = ufe.PathComponent("newGroup")

        # get the USD stage
        stage = mayaUsd.ufe.getStage(str(mayaPathSegment))

        # set the edit target to balls.usda
        layer = stage.GetLayerStack()[1]
        self.assertEqual("ballset.usda", layer.GetDisplayName())
        stage.SetEditTarget(layer)

        ufeSelectionList = ufe.Selection()
        ufeSelectionList.append(ball5Item)
        ufeSelectionList.append(ball3Item)

        groupCmd = parentHierarchy.createGroupCmd(ufeSelectionList,
                                                  newGroupName)
        groupCmd.execute()

        parentChildrenPost = parentHierarchy.children()
        self.assertEqual(len(parentChildrenPost), 5)

        # The command will now append a number 1 at the end to match the naming
        # convention in Maya.
        newGroupPath = parentPath + ufe.PathComponent("newGroup1")

        # Make sure the new group item has the correct Usd type
        newGroupItem = ufe.Hierarchy.createItem(newGroupPath)
        newGroupPrim = usdUtils.getPrimFromSceneItem(newGroupItem)
        newGroupType = newGroupPrim.GetTypeName()
        self.assertEqual(newGroupType, 'Xform')

        childPaths = set([child.path() for child in parentChildrenPost])

        self.assertTrue(newGroupPath in childPaths)
        self.assertTrue(ball5Path not in childPaths)
        self.assertTrue(ball3Path not in childPaths)

        groupCmd.undo()

        parentChildrenUndo = parentHierarchy.children()
        self.assertEqual(len(parentChildrenUndo), 6)

        childPathsUndo = set([child.path() for child in parentChildrenUndo])
        self.assertTrue(newGroupPath not in childPathsUndo)
        self.assertTrue(ball5Path in childPathsUndo)
        self.assertTrue(ball3Path in childPathsUndo)

        groupCmd.redo()

        parentChildrenRedo = parentHierarchy.children()
        self.assertEqual(len(parentChildrenRedo), 5)

        childPathsRedo = set([child.path() for child in parentChildrenRedo])
        self.assertTrue(newGroupPath in childPathsRedo)
        self.assertTrue(ball5Path not in childPathsRedo)
        self.assertTrue(ball3Path not in childPathsRedo)