예제 #1
0
    def test_toggleFace(self):
        Selection.selectedFaceChanged = MagicMock()
        node_1 = SceneNode()
        node_2 = SceneNode()

        assert Selection.getSelectedFace() is None

        Selection.toggleFace(node_1, 91)
        assert Selection.getSelectedFace() == (node_1, 91)
        Selection.toggleFace(node_2, 92)
        assert Selection.getSelectedFace() == (node_2, 92)
        Selection.toggleFace(node_2, 93)
        assert Selection.getSelectedFace() == (node_2, 93)
        Selection.toggleFace(node_2, 93)
        assert Selection.getSelectedFace() is None
        Selection.toggleFace(node_2, 93)
        assert Selection.getSelectedFace() == (node_2, 93)

        Selection.clearFace()
        assert Selection.getSelectedFace() is None

        assert Selection.selectedFaceChanged.emit.call_count == 6
예제 #2
0
    def _pixelSelection(self, event):
        # Find a node id by looking at a pixel value at the requested location
        if self._selection_pass:
            if Selection.getFaceSelectMode():
                item_id = id(Selection.getSelectedObject(0))
            else:
                item_id = self._selection_pass.getIdAtPosition(
                    event.x, event.y)
        else:
            Logger.log(
                "w",
                "Selection pass is None. getRenderPass('selection') returned None"
            )
            return False

        if not item_id and not self._shift_is_active:
            if Selection.hasSelection():
                Selection.clearFace()
                Selection.clear()
                return True
            return False  # Nothing was selected before and the user didn't click on an object.

        # Find the scene-node which matches the node-id
        for node in BreadthFirstIterator(self._scene.getRoot()):
            if id(node) != item_id:
                continue

            if self._isNodeInGroup(node):
                is_selected = Selection.isSelected(
                    self._findTopGroupNode(node))
            else:
                is_selected = Selection.isSelected(node)

            if self._shift_is_active:
                if is_selected:
                    # Deselect the SceneNode and its siblings in a group
                    if node.getParent():
                        if self._ctrl_is_active or not self._isNodeInGroup(
                                node):
                            Selection.remove(node)
                        else:
                            Selection.remove(self._findTopGroupNode(node))
                        return True
                else:
                    # Select the SceneNode and its siblings in a group
                    if node.getParent():
                        if self._ctrl_is_active or not self._isNodeInGroup(
                                node):
                            Selection.add(node)
                        else:
                            Selection.add(self._findTopGroupNode(node))
                        return True
            else:
                if Selection.getFaceSelectMode():
                    face_id = self._selection_pass.getFaceIdAtPosition(
                        event.x, event.y)
                    if face_id >= 0:
                        Selection.toggleFace(node, face_id)
                    else:
                        Selection.clear()
                        Selection.clearFace()
                if not is_selected or Selection.getCount() > 1:
                    # Select only the SceneNode and its siblings in a group
                    Selection.clear()
                    if node.getParent():
                        if self._ctrl_is_active or not self._isNodeInGroup(
                                node):
                            Selection.add(node)
                        else:
                            Selection.add(self._findTopGroupNode(node))
                        return True
                elif self._isNodeInGroup(node) and self._ctrl_is_active:
                    Selection.clear()
                    Selection.add(node)
                    return True

        return False