Beispiel #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:
            self.activeToolChanged.emit()
Beispiel #2
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:
            self.activeToolChanged.emit()
Beispiel #3
0
    def _pixelSelection(self, event):
        pixel_id = self._renderer.getIdAtCoordinate(event.x, event.y)

        if not pixel_id:
            Selection.clear()
            return
        for node in BreadthFirstIterator(self._scene.getRoot()):
            if id(node) == pixel_id:
                
                if self._ctrl_is_active:
                    if Selection.isSelected(node):
                        if node.getParent():
                            if node.getParent().callDecoration("isGroup"):
                                Selection.remove(node.getParent())
                            else:
                                Selection.remove(node)
                    else: 
                        Selection.add(node)
                        if node.getParent():
                            if node.getParent().callDecoration("isGroup"):
                                Selection.add(node.getParent())
                            else:
                                Selection.add(node)
                else:
                    if not Selection.isSelected(node) or Selection.getCount() > 1:
                        Selection.clear()
                        if node.getParent():
                            if node.getParent().callDecoration("isGroup"):
                                Selection.add(node.getParent())
                            else: 
                                Selection.add(node)
Beispiel #4
0
    def event(self, event):
        super().event(event)

        if event.type == Event.MousePressEvent and self._controller.getToolsEnabled():
            # Initialise a mirror operation
            if MouseEvent.LeftButton not in event.buttons:
                return False

            id = self._selection_pass.getIdAtPosition(event.x, event.y)
            if not id:
                return False

            if ToolHandle.isAxis(id):
                self.setLockedAxis(id)
                self._operation_started = True
                self.operationStarted.emit(self)
                return True

        if event.type == Event.MouseReleaseEvent:
            if self._operation_started:
                self._operation_started = False
                self.operationStopped.emit(self)

            # Perform a mirror operation
            if self.getLockedAxis():
                op = None
                if Selection.getCount() == 1:
                    node = Selection.getSelectedObject(0)
                    if self.getLockedAxis() == ToolHandle.XAxis:
                        mirror = Vector(-1, 1, 1)
                    elif self.getLockedAxis() == ToolHandle.YAxis:
                        mirror = Vector(1, -1, 1)
                    elif self.getLockedAxis() == ToolHandle.ZAxis:
                        mirror = Vector(1, 1, -1)
                    else:
                        mirror = Vector(1, 1, 1)
                    op = MirrorOperation(node, mirror, mirror_around_center = True)
                else:
                    op = GroupedOperation()

                    for node in Selection.getAllSelectedObjects():
                        if self.getLockedAxis() == ToolHandle.XAxis:
                            mirror = Vector(-1, 1, 1)
                        elif self.getLockedAxis() == ToolHandle.YAxis:
                            mirror = Vector(1, -1, 1)
                        elif self.getLockedAxis() == ToolHandle.ZAxis:
                            mirror = Vector(1, 1, -1)
                        else:
                            mirror = Vector(1, 1, 1)

                        op.addOperation(MirrorOperation(node, mirror, mirror_around_center = True))

                op.push()

                self.setLockedAxis(None)
                return True

        return False
Beispiel #5
0
    def _pixelSelection(self, event):
        # Find a node id by looking at a pixel value at the requested location
        if self._selection_pass:
            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.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 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
Beispiel #6
0
    def event(self, event):
        super().event(event)

        if event.type == Event.MousePressEvent and self._controller.getToolsEnabled():
            # Initialise a mirror operation
            if MouseEvent.LeftButton not in event.buttons:
                return False

            id = self._selection_pass.getIdAtPosition(event.x, event.y)
            if not id:
                return False

            if self._handle.isAxis(id):
                self.setLockedAxis(id)
                self._operation_started = True
                self.operationStarted.emit(self)
                return True

        if event.type == Event.MouseReleaseEvent:
            if self._operation_started:
                self._operation_started = False
                self.operationStopped.emit(self)

            # Perform a mirror operation
            if self.getLockedAxis() != ToolHandle.NoAxis:
                if Selection.getCount() == 1:
                    node = Selection.getSelectedObject(0)
                    if self.getLockedAxis() == ToolHandle.XAxis:
                        mirror = Vector(-1, 1, 1)
                    elif self.getLockedAxis() == ToolHandle.YAxis:
                        mirror = Vector(1, -1, 1)
                    elif self.getLockedAxis() == ToolHandle.ZAxis:
                        mirror = Vector(1, 1, -1)
                    else:
                        mirror = Vector(1, 1, 1)
                    op = MirrorOperation(node, mirror, mirror_around_center = True)
                else:
                    op = GroupedOperation()

                    for node in self._getSelectedObjectsWithoutSelectedAncestors():
                        if self.getLockedAxis() == ToolHandle.XAxis:
                            mirror = Vector(-1, 1, 1)
                        elif self.getLockedAxis() == ToolHandle.YAxis:
                            mirror = Vector(1, -1, 1)
                        elif self.getLockedAxis() == ToolHandle.ZAxis:
                            mirror = Vector(1, 1, -1)
                        else:
                            mirror = Vector(1, 1, 1)

                        op.addOperation(MirrorOperation(node, mirror, mirror_around_center = True))

                op.push()

                self.setLockedAxis(ToolHandle.NoAxis)
                return True

        return False
Beispiel #7
0
    def subdivide(self):
        if Selection.getCount() != 2:
            Logger.log(
                "w",
                i18n_catalog.i18n(
                    "Cannot subdivide: number of selected objects is not equal 2. Plane and object need to be selected. Current selected objects: %i"
                ) % Selection.getCount())
            return
        object1 = Selection.getSelectedObject(0)
        object2 = Selection.getSelectedObject(1)
        if type(object1) is SceneNode and type(object2) is Plane:
            obj = object1
            plane = object2
        elif type(object2) is SceneNode and type(object1) is Plane:
            obj = object2
            plane = object1
        else:
            Logger.log(
                "w",
                i18n_catalog.i18n(
                    "Cannot subdivide: object and plane need to be selected. Current selection: %s and %s"
                ) % (str(object1), str(object2)))
            return

        result = self._subdivide(obj, plane)
        if type(result) is tuple:
            operation = GroupedOperation()
            operation.addOperation(RemoveSceneNodeOperation(plane))
            operation.addOperation(RemoveSceneNodeOperation(obj))
            operation.addOperation(
                AddSceneNodeOperation(result[0], obj.getParent()))
            operation.addOperation(
                TranslateOperation(result[0], obj.getPosition()))
            if len(result) == 2:
                operation.addOperation(
                    AddSceneNodeOperation(result[1], obj.getParent()))
                operation.addOperation(
                    TranslateOperation(result[1], obj.getPosition()))
            operation.push()
        else:
            Logger.log("w",
                       i18n_catalog.i18n("Cannot subdivide: Internal error"))
Beispiel #8
0
    def event(self, event):
        super().event(event)

        if event.type == Event.MousePressEvent:
            if MouseEvent.LeftButton not in event.buttons:
                return False

            id = self._renderer.getIdAtCoordinate(event.x, event.y)
            if not id:
                return False

            if ToolHandle.isAxis(id):
                self.setLockedAxis(id)
                return True

        if event.type == Event.MouseReleaseEvent:
            if self.getLockedAxis():
                op = None
                if Selection.getCount() == 1:
                    node = Selection.getSelectedObject(0)
                    scale = node.getScale()
                    if self.getLockedAxis() == ToolHandle.XAxis:
                        scale.setX(-scale.x)
                    elif self.getLockedAxis() == ToolHandle.YAxis:
                        scale.setY(-scale.y)
                    elif self.getLockedAxis() == ToolHandle.ZAxis:
                        scale.setZ(-scale.z)

                    op = ScaleOperation(node, scale, set_scale=True)
                else:
                    op = GroupedOperation()

                    for node in Selection.getAllSelectedObjects():
                        scale = node.getScale()
                        if self.getLockedAxis() == ToolHandle.XAxis:
                            scale.setX(-scale.x)
                        elif self.getLockedAxis() == ToolHandle.YAxis:
                            scale.setY(-scale.y)
                        elif self.getLockedAxis() == ToolHandle.ZAxis:
                            scale.setZ(-scale.z)

                        op.addOperation(
                            ScaleOperation(node, scale, set_scale=True))

                op.push()

                self.setLockedAxis(None)
                return True

        return False
Beispiel #9
0
    def event(self, event):
        super().event(event)

        if event.type == Event.MousePressEvent:
            if MouseEvent.LeftButton not in event.buttons:
                return False

            id = self._selection_pass.getIdAtPosition(event.x, event.y)
            if not id:
                return False

            if ToolHandle.isAxis(id):
                self.setLockedAxis(id)
                return True

        if event.type == Event.MouseReleaseEvent:
            if self.getLockedAxis():
                op = None
                if Selection.getCount() == 1:
                    node = Selection.getSelectedObject(0)
                    mirror = node.getMirror()
                    if self.getLockedAxis() == ToolHandle.XAxis:
                        mirror.setX(-mirror.x)
                    elif self.getLockedAxis() == ToolHandle.YAxis:
                        mirror.setY(-mirror.y)
                    elif self.getLockedAxis() == ToolHandle.ZAxis:
                        mirror.setZ(-mirror.z)

                    op = MirrorOperation(node, mirror, set_mirror=True)
                else:
                    op = GroupedOperation()

                    for node in Selection.getAllSelectedObjects():
                        mirror = node.getMirror()
                        if self.getLockedAxis() == ToolHandle.XAxis:
                            mirror.setX(-mirror.x)
                        elif self.getLockedAxis() == ToolHandle.YAxis:
                            mirror.setY(-mirror.y)
                        elif self.getLockedAxis() == ToolHandle.ZAxis:
                            mirror.setZ(-mirror.z)

                        op.addOperation(MirrorOperation(node, mirror, set_mirror = True))

                op.push()

                self.setLockedAxis(None)
                return True

        return False
Beispiel #10
0
    def event(self, event):
        super().event(event)

        if event.type == Event.MousePressEvent:
            if MouseEvent.LeftButton not in event.buttons:
                return False

            id = self._renderer.getIdAtCoordinate(event.x, event.y)
            if not id:
                return False

            if ToolHandle.isAxis(id):
                self.setLockedAxis(id)
                return True

        if event.type == Event.MouseReleaseEvent:
            if self.getLockedAxis():
                op = None
                if Selection.getCount() == 1:
                    node = Selection.getSelectedObject(0)
                    scale = node.getScale()
                    if self.getLockedAxis() == ToolHandle.XAxis:
                        scale.setX(-scale.x)
                    elif self.getLockedAxis() == ToolHandle.YAxis:
                        scale.setY(-scale.y)
                    elif self.getLockedAxis() == ToolHandle.ZAxis:
                        scale.setZ(-scale.z)

                    op = ScaleOperation(node, scale, set_scale=True)
                else:
                    op = GroupedOperation()

                    for node in Selection.getAllSelectedObjects():
                        scale = node.getScale()
                        if self.getLockedAxis() == ToolHandle.XAxis:
                            scale.setX(-scale.x)
                        elif self.getLockedAxis() == ToolHandle.YAxis:
                            scale.setY(-scale.y)
                        elif self.getLockedAxis() == ToolHandle.ZAxis:
                            scale.setZ(-scale.z)

                        op.addOperation(ScaleOperation(node, scale, set_scale = True))

                op.push()

                self.setLockedAxis(None)
                return True

        return False
Beispiel #11
0
    def _pixelSelection(self, event):
        # Find a node id by looking at a pixel value at the requested location
        item_id = self._selection_pass.getIdAtPosition(event.x, event.y)

        if not item_id:
            Selection.clear()
            return

        # Find the scene-node which matches the node-id
        for node in BreadthFirstIterator(self._scene.getRoot()):
            if id(node) == item_id:
                if self._isNodeInGroup(node):
                    is_selected = Selection.isSelected(
                        self._findTopGroupNode(node))
                else:
                    is_selected = Selection.isSelected(node)

                if self._ctrl_is_active:
                    if is_selected:
                        # Deselect the scenenode and its sibblings in a group
                        if node.getParent():
                            if self._alt_is_active or not self._isNodeInGroup(
                                    node):
                                Selection.remove(node)
                            else:
                                Selection.remove(self._findTopGroupNode(node))
                    else:
                        # Select the scenenode and its sibblings in a group
                        if node.getParent():
                            if self._alt_is_active or not self._isNodeInGroup(
                                    node):
                                Selection.add(node)
                            else:
                                Selection.add(self._findTopGroupNode(node))
                else:
                    if not is_selected or Selection.getCount() > 1:
                        # Select only the scenenode and its sibblings in a group
                        Selection.clear()
                        if node.getParent():
                            if self._alt_is_active or not self._isNodeInGroup(
                                    node):
                                Selection.add(node)
                            else:
                                Selection.add(self._findTopGroupNode(node))
                    elif self._isNodeInGroup(node) and self._alt_is_active:
                        Selection.clear()
                        Selection.add(node)
Beispiel #12
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()
Beispiel #13
0
    def getLockPosition(self) -> Union[str, bool]:
        total_size = Selection.getCount()
        false_state_counter = 0
        true_state_counter = 0
        if not Selection.hasSelection():
            return False

        for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
            if selected_node.getSetting(SceneNodeSettings.LockPosition, "False") != "False":
                true_state_counter += 1
            else:
                false_state_counter += 1

        if total_size == false_state_counter:  # No locked positions
            return False
        elif total_size == true_state_counter:  # All selected objects are locked
            return True
        else:
            return "partially"  # At least one, but not all are locked
Beispiel #14
0
    def setActiveTool(self, 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:
            self._active_tool = tool
        else:
            self._active_tool = self.getTool(tool)

        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.
            self._active_tool = self._tools["TranslateTool"]  # Then default to the translation tool.
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        self.activeToolChanged.emit()
Beispiel #15
0
    def getLockPosition(self) -> Union[str, bool]:
        total_size = Selection.getCount()
        false_state_counter = 0
        true_state_counter = 0
        if Selection.hasSelection():
            for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
                if selected_node.getSetting(SceneNodeSettings.LockPosition, "False") != "False":
                    true_state_counter += 1
                else:
                    false_state_counter += 1

            if total_size == false_state_counter: # if no locked positions
                return False
            elif total_size == true_state_counter: # if all selected objects are locked
                return True
            else:
                return "partially"  # if at least one is locked

        return False
Beispiel #16
0
    def _pixelSelection(self, event):
        # Find a node id by looking at a pixel value at the requested location
        item_id = self._selection_pass.getIdAtPosition(event.x, event.y)

        if not item_id and not self._shift_is_active:
            Selection.clear()
            return

        # Find the scene-node which matches the node-id
        for node in BreadthFirstIterator(self._scene.getRoot()):
            if id(node) == item_id:
                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 sibblings 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))
                    else:
                        # Select the scenenode and its sibblings 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))
                else:
                    if not is_selected or Selection.getCount() > 1:
                        # Select only the scenenode and its sibblings 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))
                    elif self._isNodeInGroup(node) and self._ctrl_is_active:
                        Selection.clear()
                        Selection.add(node)
Beispiel #17
0
    def _pixelSelection(self, event):
        pixel_id = self._renderer.getIdAtCoordinate(event.x, event.y)

        if not pixel_id:
            Selection.clear()
            return
        for node in BreadthFirstIterator(self._scene.getRoot()):
            if id(node) == pixel_id:
                if self._ctrl_is_active:
                    if Selection.isSelected(node):
                        if node.getParent():
                            group_node = node.getParent()
                            if not group_node.callDecoration("isGroup"):
                                Selection.remove(node)
                            else:
                                while group_node.getParent().callDecoration(
                                        "isGroup"):
                                    group_node = group_node.getParent()
                                Selection.remove(group_node)
                    else:
                        if node.getParent():
                            group_node = node.getParent()
                            if not group_node.callDecoration("isGroup"):
                                Selection.add(node)
                            else:
                                while group_node.getParent().callDecoration(
                                        "isGroup"):
                                    group_node = group_node.getParent()
                                Selection.add(group_node)
                else:
                    if not Selection.isSelected(
                            node) or Selection.getCount() > 1:
                        Selection.clear()
                        if node.getParent():
                            group_node = node.getParent()
                            if not group_node.callDecoration("isGroup"):
                                Selection.add(node)
                            else:
                                while group_node.getParent().callDecoration(
                                        "isGroup"):
                                    group_node = group_node.getParent()
                                Selection.add(group_node)
    def setActiveTool(self, name):
        try:
            if self._active_tool:
                self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

            if name:
                self._active_tool = self._tools[name]
            else:
                self._active_tool = None

            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.
                self._active_tool = self._tools["TranslateTool"]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

            self.activeToolChanged.emit()
        except KeyError:
            Logger.log("e", "No tool named %s found.", name)
Beispiel #19
0
    def getLockPosition(self):
        total_size = Selection.getCount()
        false_state_counter = 0
        true_state_counter = 0
        if Selection.hasSelection():
            for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():

                if selected_node.getSetting(SceneNodeSettings.LockPosition, False):
                    true_state_counter += 1
                else:
                    false_state_counter +=1

            if  total_size == false_state_counter: # if no locked positions
                return False
            elif total_size == true_state_counter: # if all selected objects are locked
                return True
            else:
                return "partially"  # if at least one is locked


        return False
Beispiel #20
0
    def _pixelSelection(self, event):
        item_id = self._selection_pass.getIdAtPosition(event.x, event.y)

        if not item_id:
            Selection.clear()
            return

        for node in BreadthFirstIterator(self._scene.getRoot()):
            if id(node) == item_id:
                if self._ctrl_is_active:
                    if Selection.isSelected(node):
                        if node.getParent():
                            group_node = node.getParent()
                            if not group_node.callDecoration("isGroup"):
                                Selection.remove(node)
                            else:
                                while group_node.getParent().callDecoration("isGroup"):
                                    group_node = group_node.getParent()
                                Selection.remove(group_node)
                    else:
                        if node.getParent():
                            group_node = node.getParent()
                            if not group_node.callDecoration("isGroup"):
                                Selection.add(node)
                            else:
                                while group_node.getParent().callDecoration("isGroup"):
                                    group_node = group_node.getParent()
                                Selection.add(group_node)
                else:
                    if not Selection.isSelected(node) or Selection.getCount() > 1:
                        Selection.clear()
                        if node.getParent():
                            group_node = node.getParent()
                            if not group_node.callDecoration("isGroup"):
                                Selection.add(node)
                            else:
                                while group_node.getParent().callDecoration("isGroup"):
                                    group_node = group_node.getParent()
                                Selection.add(group_node)
Beispiel #21
0
    def setActiveTool(self, name):
        try:
            if self._active_tool:
                self._active_tool.event(
                    ToolEvent(ToolEvent.ToolDeactivateEvent))

            if name:
                self._active_tool = self._tools[name]
            else:
                self._active_tool = None

            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.
                self._active_tool = self._tools[
                    "TranslateTool"]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

            self.activeToolChanged.emit()
        except KeyError:
            Logger.log("e", "No tool named %s found.", name)
 def numObjectsSelected(self):
     return Selection.getCount()
Beispiel #23
0
 def selectionCount(self):
     return Selection.getCount()
Beispiel #24
0
 def selectionCount(self):
     return Selection.getCount()
Beispiel #25
0
 def getZ(self):
     if Selection.getCount() > 1:
         self._Z_angle = 0.0
         return self._Z_angle
     self._Z_angle = Selection.getAllSelectedObjects()[0]._rotationZ
     return self._Z_angle