Ejemplo n.º 1
0
 def getZ(self):
     # We want to display based on the bottom instead of the actual coordinate.
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().bottom)
     return 0.0
Ejemplo n.º 2
0
    def event(self, event: Event):
        if self._selection_tool and self._selection_tool.event(event):
            return

        if self._active_tool and self._active_tool.event(event):
            return

        if self._camera_tool and self._camera_tool.event(event):
            return

        if self._tools and event.type == Event.KeyPressEvent:
            event = cast(KeyEvent, event)
            from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
            if Selection.hasSelection():
                for key, tool in self._tools.items():
                    if tool.getShortcutKey() is not None and event.key == tool.getShortcutKey():
                        self.setActiveTool(tool)

        if self._active_view:
            self._active_view.event(event)

        if event.type == Event.MouseReleaseEvent:
            event = cast(MouseEvent, event)
            if MouseEvent.RightButton in event.buttons:
                self.contextMenuRequested.emit(event.x, event.y)
Ejemplo n.º 3
0
    def event(self, event: Event) -> bool:
        if not self._selection_pass:
            self._selection_pass = cast(SelectionPass, UM.Application.Application.getInstance().getRenderer().getRenderPass("selection"))
            if not self._selection_pass:
                return False

        if event.type == Event.ToolActivateEvent:
            if Selection.hasSelection() and self._handle:
                self._handle.setParent(self.getController().getScene().getRoot())
                self._handle.setEnabled(True)

        if event.type == Event.MouseMoveEvent and self._handle:
            event = cast(MouseEvent, event)
            if self._locked_axis != ToolHandle.NoAxis:
                return False

            tool_id = self._selection_pass.getIdAtPosition(event.x, event.y)

            if self._handle.isAxis(tool_id):
                self._handle.setActiveAxis(tool_id)
            else:
                self._handle.setActiveAxis(None)

        if event.type == Event.ToolDeactivateEvent and self._handle:
            self._handle.setParent(None)
            self._handle.setEnabled(False)
        return False
Ejemplo n.º 4
0
 def _onSelectionChanged(self):
     # When selection is passed from one object to another object, first the selection is cleared
     # and then it is set to the new object. We are only interested in the change from no selection
     # to a selection or vice-versa, not in a change from one object to another. A timer is used to
     # "merge" a possible clear/select action in a single frame
     if Selection.hasSelection() != self._had_selection:
         self._had_selection_timer.start()
Ejemplo n.º 5
0
    def _selectionChangeDelay(self):
        has_selection = Selection.hasSelection()
        if not has_selection and self._had_selection:
            self._skip_press = True
        else:
            self._skip_press = False

        self._had_selection = has_selection
Ejemplo n.º 6
0
    def removeSelection(self):
        if not Selection.hasSelection():
            return

        op = GroupedOperation()
        for node in Selection.getAllSelectedObjects():
            op.addOperation(RemoveSceneNodeOperation(node))
        op.push()
        Selection.clear()
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def requestWriteSelectionToDevice(self, device_id, file_name):
        if not Selection.hasSelection():
            return

        # On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
        # handler attached to a QML MenuItem. So instead, defer the call to the next run of the event 
        # loop, since that does work.
        event = CallFunctionEvent(self._writeToDevice, [Selection.getSelectedObject(0), device_id, file_name], {})
        Application.getInstance().functionEvent(event)
Ejemplo n.º 9
0
    def requestWriteSelectionToDevice(self, device_id, file_name, kwargs):
        if not Selection.hasSelection():
            return

        filter_by_machine = kwargs.get("filter_by_machine", False)
        # On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
        # handler attached to a QML MenuItem. So instead, defer the call to the next run of the event 
        # loop, since that does work.
        Application.getInstance().callLater(self._writeToDevice, Selection.getSelectedObject(0), device_id, file_name, filter_by_machine)
Ejemplo n.º 10
0
    def requestWriteSelectionToDevice(self, device_id: str, file_name: str, kwargs: Mapping[str, str]) -> None:
        if not Selection.hasSelection():
            return

        limit_mimetypes = kwargs.get("limit_mimetypes", False)
        preferred_mimetypes = kwargs.get("preferred_mimetypes", None)
        # On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
        # handler attached to a QML MenuItem. So instead, defer the call to the next run of the event 
        # loop, since that does work.
        Application.getInstance().callLater(self._writeToDevice, Selection.getAllSelectedObjects(), device_id, file_name, limit_mimetypes, preferred_mimetypes = preferred_mimetypes)
Ejemplo n.º 11
0
    def onSelectionChanged(self):
        if Selection.hasSelection():
            if not self.getController().getActiveTool():
                self.getController().setActiveTool("TranslateTool")

            self._camera_animation.setStart(self.getController().getTool("CameraTool").getOrigin())
            self._camera_animation.setTarget(Selection.getSelectedObject(0).getWorldPosition())
            self._camera_animation.start()
        else:
            if self.getController().getActiveTool():
                self.getController().setActiveTool(None)
Ejemplo n.º 12
0
 def onSelectionChanged(self):
     if Selection.hasSelection():
         if not self.getController().getActiveTool():
             if self._previous_active_tool:
                 self.getController().setActiveTool(self._previous_active_tool)
                 self._previous_active_tool = None
             else:
                 self.getController().setActiveTool("TranslateTool")
         if Preferences.getInstance().getValue("view/center_on_select"):
             self._center_after_select = True
     else:
         if self.getController().getActiveTool():
             self._previous_active_tool = self.getController().getActiveTool().getPluginId()
             self.getController().setActiveTool(None)
Ejemplo n.º 13
0
 def onSelectionChanged(self):
     if Selection.hasSelection():
         if not self.getController().getActiveTool():
             if self._previous_active_tool:
                 self.getController().setActiveTool(self._previous_active_tool)
                 self._previous_active_tool = None
             else:
                 self.getController().setActiveTool("TranslateTool")
         if Preferences.getInstance().getValue("view/center_on_select"):
             self._camera_animation.setStart(self.getController().getTool("CameraTool").getOrigin())
             self._camera_animation.setTarget(Selection.getSelectedObject(0).getWorldPosition())
             self._camera_animation.start()
     else:
         if self.getController().getActiveTool():
             self._previous_active_tool = self.getController().getActiveTool().getPluginId()
             self.getController().setActiveTool(None)
         else:
             self._previous_active_tool = None
Ejemplo n.º 14
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
Ejemplo n.º 15
0
    def event(self, event):
        if event.type == Event.ToolActivateEvent:
            if Selection.hasSelection() and self._handle:
                self._handle.setParent(self.getController().getScene().getRoot())

        if event.type == Event.MouseMoveEvent and self._handle:
            if self._locked_axis:
                return

            id = self._renderer.getIdAtCoordinate(event.x, event.y)

            if self._handle.isAxis(id):
                self._handle.setActiveAxis(id)
            else:
                self._handle.setActiveAxis(None)

        if event.type == Event.ToolDeactivateEvent and self._handle:
            self._handle.setParent(None)

        return False
Ejemplo n.º 16
0
 def onSelectionChanged(self):
     if Selection.hasSelection():
         if self.getController().getActiveTool():
             # If the tool has been disabled by the new selection
             if not self.getController().getActiveTool().getEnabled():
                 # Default
                 self.getController().setActiveTool("TranslateTool")
         else:
             if self._previous_active_tool:
                 self.getController().setActiveTool(self._previous_active_tool)
                 if not self.getController().getActiveTool().getEnabled():
                     self.getController().setActiveTool("TranslateTool")
                 self._previous_active_tool = None
             else:
                 # Default
                 self.getController().setActiveTool("TranslateTool")
         if Preferences.getInstance().getValue("view/center_on_select"):
             self._center_after_select = True
     else:
         if self.getController().getActiveTool():
             self._previous_active_tool = self.getController().getActiveTool().getPluginId()
             self.getController().setActiveTool(None)
Ejemplo n.º 17
0
    def event(self, event):
        if not self._selection_pass:
            self._selection_pass = UM.Application.Application.getInstance().getRenderer().getRenderPass("selection")

        if event.type == Event.ToolActivateEvent:
            if Selection.hasSelection() and self._handle:
                self._handle.setParent(self.getController().getScene().getRoot())

        if event.type == Event.MouseMoveEvent and self._handle:
            if self._locked_axis:
                return

            id = self._selection_pass.getIdAtPosition(event.x, event.y)

            if self._handle.isAxis(id):
                self._handle.setActiveAxis(id)
            else:
                self._handle.setActiveAxis(None)

        if event.type == Event.ToolDeactivateEvent and self._handle:
            self._handle.setParent(None)

        return False
Ejemplo n.º 18
0
    def event(self, event: Event):
        # First, try to perform camera control
        if self._camera_tool and self._camera_tool.event(event):
            return

        if self._tools and event.type == Event.KeyPressEvent:
            from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
            if Selection.hasSelection():
                for key, tool in self._tools.items():
                    if tool.getShortcutKey() is not None and event.key == tool.getShortcutKey():
                        self.setActiveTool(tool)

        if self._selection_tool and self._selection_tool.event(event):
            return

        # If we are not doing camera control, pass the event to the active tool.
        if self._active_tool and self._active_tool.event(event):
            return

        if self._active_view:
            self._active_view.event(event)

        if event.type == Event.MouseReleaseEvent and MouseEvent.RightButton in event.buttons:
            self.contextMenuRequested.emit(event.x, event.y)
Ejemplo n.º 19
0
    def getScaleZ(self):
        if Selection.hasSelection():
            ## Ensure that the returned value is positive (mirror causes scale to be negative)
            return abs(round(float(self._getScaleInWorldCoordinates(Selection.getSelectedObject(0)).z), 4))

        return 1.0
Ejemplo n.º 20
0
 def hasSelection(self):
     return Selection.hasSelection()
Ejemplo n.º 21
0
    def getObjectHeight(self):
        if Selection.hasSelection():
            return float(Selection.getSelectedObject(0).getBoundingBox().height)

        return 0.0
Ejemplo n.º 22
0
    def getObjectDepth(self):
        if Selection.hasSelection():
            return float(Selection.getSelectedObject(0).getBoundingBox().depth)

        return 0.0
Ejemplo n.º 23
0
    def getScaleZ(self):
        if Selection.hasSelection():
            return round(float(Selection.getSelectedObject(0).getScale().z), 4)

        return 1.0
Ejemplo n.º 24
0
    def getScaleZ(self):
        if Selection.hasSelection():
            return round(float(Selection.getSelectedObject(0).getScale().z), 4)

        return 1.0
Ejemplo n.º 25
0
    def getScaleY(self):
        if Selection.hasSelection():
            ## Ensure that the returned value is positive (mirror causes scale to be negative)
            return abs(round(float(self._getScaleInWorldCoordinates(Selection.getSelectedObject(0)).y), 4))

        return 1.0
Ejemplo n.º 26
0
 def hasSelection(self):
     return Selection.hasSelection()
Ejemplo n.º 27
0
 def getX(self):
     if Selection.hasSelection():
         return float(Selection.getBoundingBox().center.x)
     return 0.0
Ejemplo n.º 28
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.º 29
0
 def getY(self):
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().center.z)
     return 0.0
Ejemplo n.º 30
0
 def getY(self):
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().center.z)
     return 0.0
Ejemplo n.º 31
0
 def getX(self):
     if Selection.hasSelection():
         return float(Selection.getBoundingBox().center.x)
     return 0.0
Ejemplo n.º 32
0
    def getObjectWidth(self):
        if Selection.hasSelection():
            return float(Selection.getSelectedObject(0).getBoundingBox().width)

        return 0.0
Ejemplo n.º 33
0
 def updateHandlePosition(self):
     if Selection.hasSelection():
         self._handle.setPosition(Selection.getAveragePosition())
Ejemplo n.º 34
0
    def getScaleZ(self):
        if Selection.hasSelection():
            ## Ensure that the returned value is positive (mirror causes scale to be negative)
            return abs(round(float(Selection.getSelectedObject(0).getScale().z), 4))

        return 1.0
Ejemplo n.º 35
0
    def getScaleY(self):
        if Selection.hasSelection():
            ## Ensure that the returned value is positive (mirror causes scale to be negative)
            return abs(round(float(Selection.getSelectedObject(0).getScale().y), 4))

        return 1.0
Ejemplo n.º 36
0
    def getObjectHeight(self):
        if Selection.hasSelection():
            return float(Selection.getSelectedObject(0).getBoundingBox().height)

        return 0.0
Ejemplo n.º 37
0
    def getObjectWidth(self):
        if Selection.hasSelection():
            return round(float(Selection.getSelectedObject(0).getBoundingBox().width), 1)

        return 0.0