Ejemplo n.º 1
0
    def setActiveTool(self, tool: Optional[Union["Tool", str]]):
        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            new_tool = cast(Optional[Tool], tool)
        else:
            new_tool = self.getTool(tool)

        tool_changed = False
        if self._active_tool is not new_tool:
            self._active_tool = new_tool
            tool_changed = True

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount() > 0:  # If something is selected, a tool must always be active.
            if "TranslateTool" in self._tools:
                self._active_tool = self._tools["TranslateTool"]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))
                tool_changed = True
            else:
                Logger.log("w", "Controller does not have an active tool and could not default to Translate tool.")

        if tool_changed:
            Selection.setFaceSelectMode(False)
            Selection.clearFace()
            self.activeToolChanged.emit()
Ejemplo n.º 2
0
 def setSelectFaceToLayFlatMode(self, select: bool) -> None:
     if select != self._select_face_mode or select != Selection.getFaceSelectMode(
     ):
         self._select_face_mode = select
         if not select:
             Selection.clearFace()
         Selection.setFaceSelectMode(self._select_face_mode)
         self.propertyChanged.emit()
Ejemplo n.º 3
0
 def _pixelHover(self, event):
     if Selection.getFaceSelectMode():
         face_id = self._selection_pass.getFaceIdAtPosition(event.x, event.y)
         if face_id >= 0:
             Selection.hoverFace(Selection.getSelectedObject(0), face_id)
         else:
             Selection.clearFace()
         return True
     return False
Ejemplo n.º 4
0
    def setSelectFaceToLayFlatMode(self, select: bool) -> None:
        """Set the rotate tool to/from 'Lay flat by face'-Mode."""

        if select != self._select_face_mode or select != Selection.getFaceSelectMode():
            self._select_face_mode = select
            if not select:
                Selection.clearFace()
            Selection.setFaceSelectMode(self._select_face_mode)
            self.propertyChanged.emit()
 def surfaceType(self, value: int):
     if self._active_node.surface_type.value != value:
         self._active_node.surface_type = SmartSliceScene.HighlightFace.SurfaceType(value)
         # self._active_node.facePropertyChanged.emit() # This will get emitted by connections to Selection.selectedFaceChange
         if self._active_node.selection:
             node = self._active_node.selection[0] if self._active_node.selection[0] else Selection.getSelectedObject(0)
             if node:
                 Selection.setFace(node, self._active_node.selection[1])
             else:
                 Selection.clearFace()
         else:
             Selection.clearFace()
Ejemplo n.º 6
0
    def setActiveTool(self, tool: Optional[Union["Tool", str]]):
        """Set the current active tool.

        The tool can be set by name of the tool or directly passing the tool object.
        :param tool: A tool object or the name of a tool.
        """

        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            new_tool = cast(Optional[Tool], tool)
        else:
            new_tool = self.getTool(tool)

        tool_changed = False
        if self._active_tool is not new_tool:
            self._active_tool = new_tool
            tool_changed = True

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount(
        ) > 0:  # If something is selected, a tool must always be active.
            if self._fallback_tool in self._tools:
                self._active_tool = self._tools[
                    self.
                    _fallback_tool]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))
                tool_changed = True
            else:
                Logger.log(
                    "w",
                    "Controller does not have an active tool and could not default to the tool, called \"{}\"."
                    .format(self._fallback_tool))

        if tool_changed:
            Selection.setFaceSelectMode(False)
            Selection.clearFace()
            self.activeToolChanged.emit()
    def add(self):
        Selection.clearFace()
        if not Selection.getFaceSelectMode():
            Selection.setFaceSelectMode(True)

        if len(self._bcs) == 0:
            N = 1
        else:
            N = int(self._bcs[-1].getName().split(" ")[1]) + 1

        if self._bc_type == BoundaryConditionListModel.Anchor:
            bc = SmartSliceScene.AnchorFace('Anchor ' + str(N))
            bc.surface_type = SmartSliceScene.HighlightFace.SurfaceType.Flat
        else:
            bc = SmartSliceScene.LoadFace('Load ' + str(N))
            bc.force.magnitude = 10.0
            bc.force.direction_type = SmartSliceScene.Force.DirectionType.Normal
            bc.surface_type = SmartSliceScene.HighlightFace.SurfaceType.Flat

        self._smart_slice_scene_node.addFace(bc)
Ejemplo n.º 8
0
    def test_hoverFace(self):
        Selection.hoverFaceChanged = MagicMock()
        node_1 = SceneNode()

        assert Selection.getHoverFace() is None

        Selection.hoverFace(node_1, 81)
        Selection.hoverFace(node_1, 81)
        assert Selection.getHoverFace() == (node_1, 81)
        assert Selection.hoverFaceChanged.emit.call_count == 1

        Selection.unhoverFace()
        assert Selection.getHoverFace() is None

        Selection.hoverFace(node_1, 82)
        Selection.hoverFace(node_1, 83)
        assert Selection.hoverFaceChanged.emit.call_count == 4

        Selection.clearFace()
        assert Selection.getHoverFace() is None
        assert Selection.hoverFaceChanged.emit.call_count == 5
Ejemplo n.º 9
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
Ejemplo n.º 10
0
 def setFaceSelectMode(self, select: bool) -> None:
     Selection.setFaceSelectMode(select)
     if not select:
         Selection.clearFace()
Ejemplo n.º 11
0
 def setSelectionMode(self, mode):
     Selection.clearFace()
     self._selection_mode = mode
     Logger.log("d", "Changed selection mode to enum: {}".format(mode))
Ejemplo n.º 12
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
Ejemplo n.º 13
0
 def clearAll(self):
     Selection.clearFace()
     Selection.clear()
Ejemplo n.º 14
0
 def setSelectionMode(self, mode):
     Selection.clearFace()
     self._handle._connector.propertyHandler._selection_mode = mode
     Logger.log("d", "Changed selection mode to enum: {}".format(mode))