def setBuildPlateForSelection(self, build_plate_nr: int) -> None: Logger.log("d", "Setting build plate number... %d" % build_plate_nr) operation = GroupedOperation() root = cura.CuraApplication.CuraApplication.getInstance( ).getController().getScene().getRoot() nodes_to_change = [] for node in Selection.getAllSelectedObjects(): parent_node = node # Find the parent node to change instead while parent_node.getParent() != root: parent_node = parent_node.getParent() for single_node in BreadthFirstIterator( parent_node ): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax. nodes_to_change.append(single_node) if not nodes_to_change: Logger.log("d", "Nothing to change.") return for node in nodes_to_change: operation.addOperation( SetBuildPlateNumberOperation(node, build_plate_nr)) operation.push() Selection.clear()
def deleteAll(self, only_selectable = True) -> None: Logger.log("i", "Clearing scene") if not self.getController().getToolsEnabled(): return nodes = [] for node in DepthFirstIterator(self.getController().getScene().getRoot()): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax. if not isinstance(node, SceneNode): continue if (not node.getMeshData() and not node.callDecoration("getLayerData")) and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if only_selectable and not node.isSelectable(): continue if not node.callDecoration("isSliceable") and not node.callDecoration("getLayerData") and not node.callDecoration("isGroup"): continue # Only remove nodes that are selectable. if node.getParent() and cast(SceneNode, node.getParent()).callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) nodes.append(node) if nodes: op = GroupedOperation() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) # Reset the print information self.getController().getScene().sceneChanged.emit(node) op.push() Selection.clear()
def changeSelection(self, index): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier shift_is_active = modifiers & Qt.ShiftModifier if ctrl_is_active: item = self._objects_model.getItem(index) node = item["node"] if Selection.isSelected(node): Selection.remove(node) else: Selection.add(node) elif shift_is_active: polarity = 1 if index + 1 > self._last_selected_index else -1 for i in range(self._last_selected_index, index + polarity, polarity): item = self._objects_model.getItem(i) node = item["node"] Selection.add(node) else: # Single select item = self._objects_model.getItem(index) node = item["node"] build_plate_number = node.callDecoration("getBuildPlateNumber") if build_plate_number is not None and build_plate_number != -1: self.setActiveBuildPlate(build_plate_number) Selection.clear() Selection.add(node) self._last_selected_index = index
def deleteAllNodesWithMeshData(self, only_selectable:bool = True) -> None: Logger.log("i", "Clearing scene") if not self.getToolsEnabled(): return nodes = [] for node in DepthFirstIterator(self.getScene().getRoot()): if not node.getMeshData() and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if only_selectable and not node.isSelectable(): continue # Only remove nodes that are selectable. if node.getParent() and cast(SceneNode, node.getParent()).callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) nodes.append(node) if nodes: from UM.Operations.GroupedOperation import GroupedOperation op = GroupedOperation() for node in nodes: from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation op.addOperation(RemoveSceneNodeOperation(node)) # Reset the print information self.getScene().sceneChanged.emit(node) op.push() from UM.Scene.Selection import Selection Selection.clear()
def _boundingBoxSelection(self, event): """Handle mouse and keyboard events for bounding box selection :param event: type(Event) passed from self.event() """ root = self._scene.getRoot() ray = self._scene.getActiveCamera().getRay(event.x, event.y) intersections = [] for node in BreadthFirstIterator(root): if node.isEnabled() and not node.isLocked(): intersection = node.getBoundingBox().intersectsRay(ray) if intersection: intersections.append((node, intersection[0], intersection[1])) if intersections: intersections.sort(key=lambda k: k[1]) node = intersections[0][0] if not Selection.isSelected(node): if not self._shift_is_active: Selection.clear() Selection.add(node) else: Selection.clear()
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)
def deleteAll(self, only_selectable=True) -> None: Logger.log("i", "Clearing scene") if not self.getController().getToolsEnabled(): return nodes = [] for node in DepthFirstIterator( self.getController().getScene().getRoot() ): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax. if not isinstance(node, SceneNode): continue if (not node.getMeshData() and not node.callDecoration("getLayerData") ) and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if only_selectable and not node.isSelectable(): continue if not node.callDecoration( "isSliceable") and not node.callDecoration( "getLayerData") and not node.callDecoration("isGroup"): continue # Only remove nodes that are selectable. if node.getParent() and node.getParent().callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) nodes.append(node) if nodes: op = GroupedOperation() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) # Reset the print information self.getController().getScene().sceneChanged.emit(node) op.push() Selection.clear()
def setActiveBuildPlate(self, nr): if nr == self._active_build_plate: return Logger.log("d", "Select build plate: %s" % nr) self._active_build_plate = nr Selection.clear() self._build_plate_model.setActiveBuildPlate(nr) self._objects_model.setActiveBuildPlate(nr)
def removeSelection(self): if not Selection.hasSelection(): return op = GroupedOperation() for node in Selection.getAllSelectedObjects(): op.addOperation(RemoveSceneNodeOperation(node)) op.push() Selection.clear()
def setActiveBuildPlate(self, nr): if nr == self._active_build_plate: return Logger.log("d", "Select build plate: %s" % nr) self._active_build_plate = nr Selection.clear() self._multi_build_plate_model.setActiveBuildPlate(nr) self._objects_model.setActiveBuildPlate(nr) self.activeBuildPlateChanged.emit()
def test_clearSelection(self): node_1 = SceneNode() node_2 = SceneNode() Selection.add(node_1) Selection.add(node_2) # Ensure that the objects we want selected are selected assert Selection.getAllSelectedObjects() == [node_1, node_2] Selection.clear() assert Selection.getAllSelectedObjects() == []
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 not Selection.isSelected(node): Selection.clear() Selection.add(node)
def selectAll(self): if not self.getController().getToolsEnabled(): return Selection.clear() for node in DepthFirstIterator(self.getController().getScene().getRoot()): if type(node) is not SceneNode: continue if not node.getMeshData() and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if node.getParent() and node.getParent().callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) Selection.add(node)
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 _boundingBoxSelection(self, event): root = self._scene.getRoot() ray = self._scene.getActiveCamera().getRay(event.x, event.y) intersections = [] for node in BreadthFirstIterator(root): if node.getSelectionMask() == self._selectionMask and not node.isLocked(): intersection = node.getBoundingBox().intersectsRay(ray) if intersection: intersections.append((node, intersection[0], intersection[1])) if intersections: intersections.sort(key=lambda k: k[1]) node = intersections[0][0] if not Selection.isSelected(node): Selection.clear() Selection.add(node) else: Selection.clear()
def onStageSelected(self): application = CuraApplication.getInstance() controller = application.getController() Selection.clear() printable_node = self._exit_stage_if_scene_is_invalid() if not printable_node: return self._previous_view = controller.getActiveView().name # When the Smart Slice stage is active we want to use our SmartSliceView # to control the rendering of various nodes. Views are referred to by their # plugin name. controller.setActiveView('SmartSlicePlugin') if not Selection.hasSelection(): Selection.add(printable_node) # Ensure we have tools defined and apply them here use_tool = self._our_toolset[0] self.setToolVisibility(True) controller.setFallbackTool(use_tool) self._previous_tool = controller.getActiveTool() if self._previous_tool: controller.setActiveTool(use_tool) # Set the Active Extruder for the Cloud interactions self._connector._proxy._activeMachineManager = CuraApplication.getInstance( ).getMachineManager() self._connector._proxy._activeExtruder = self._connector._proxy._activeMachineManager._global_container_stack.extruderList[ 0] if not self._connector.propertyHandler._initialized: self._connector.propertyHandler.cacheChanges() self._connector.propertyHandler._initialized = True self._connector.updateSliceWidget()
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)
def deleteAll(self): Logger.log("i", "Clearing scene") if not self.getController().getToolsEnabled(): return nodes = [] for node in DepthFirstIterator(self.getController().getScene().getRoot()): if type(node) is not SceneNode: continue if not node.getMeshData() and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if node.getParent() and node.getParent().callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) nodes.append(node) if nodes: op = GroupedOperation() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) op.push() Selection.clear()
def _boundingBoxSelection(self, event): root = self._scene.getRoot() ray = self._scene.getActiveCamera().getRay(event.x, event.y) intersections = [] for node in BreadthFirstIterator(root): if node.isEnabled() and not node.isLocked(): intersection = node.getBoundingBox().intersectsRay(ray) if intersection: intersections.append((node, intersection[0], intersection[1])) if intersections: intersections.sort(key=lambda k: k[1]) node = intersections[0][0] if not Selection.isSelected(node): if not self._ctrl_is_active: Selection.clear() Selection.add(node) else: Selection.clear()
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
def setBuildPlateForSelection(self, build_plate_nr: int) -> None: Logger.log("d", "Setting build plate number... %d" % build_plate_nr) operation = GroupedOperation() root = Application.getInstance().getController().getScene().getRoot() nodes_to_change = [] for node in Selection.getAllSelectedObjects(): parent_node = node # Find the parent node to change instead while parent_node.getParent() != root: parent_node = parent_node.getParent() for single_node in BreadthFirstIterator(parent_node): nodes_to_change.append(single_node) if not nodes_to_change: Logger.log("d", "Nothing to change.") return for node in nodes_to_change: operation.addOperation(SetBuildPlateNumberOperation(node, build_plate_nr)) operation.push() Selection.clear()
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)
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)
def setUp(self): Selection.clear() self.proxy = SelectionProxy()
def clearAll(self): Selection.clearFace() Selection.clear()
def setUp(self): Selection.clear()
def tearDown(self): Selection.clear()
def onStageSelected(self): if not SmartSliceStage.getSelectFaceSupported(): error_message = Message( title="Smart Slice: OpenGL error", text= "You are running an outdated version of OpenGL which may not" " support selecting faces in Smart Slice. Please update OpenGL to at least version 4.1" ) error_message.show() application = CuraApplication.getInstance() controller = application.getController() extruderManager = application.getExtruderManager() Selection.clear() printable_node = self._exit_stage_if_scene_is_invalid() if not printable_node: return self._previous_view = controller.getActiveView().name self._connector.api_connection.openConnection() # When the Smart Slice stage is active we want to use our SmartSliceView # to control the rendering of various nodes. Views are referred to by their # plugin name. controller.setActiveView('SmartSlicePlugin') self._connector.propertyHandler.jobCheck() if not Selection.hasSelection(): Selection.add(printable_node) aabb = printable_node.getBoundingBox() if aabb: controller.getCameraTool().setOrigin(aabb.center) smart_slice_node = findChildSceneNode(printable_node, SmartSliceScene.Root) if not smart_slice_node: smart_slice_node = SmartSliceScene.Root() try: smart_slice_node.initialize(printable_node) except Exception as exc: Logger.logException("e", "Unable to analyze geometry") self._scene_not_ready( i18n_catalog.i18n( "Smart Slice could not analyze the geometry for face selection. It may be ill-formed." )) if smart_slice_node: printable_node.removeChild(smart_slice_node) return self.smartSliceNodeChanged.emit(smart_slice_node) for c in controller.getScene().getRoot().getAllChildren(): if isinstance(c, SmartSliceScene.Root): c.setVisible(True) for mesh in getModifierMeshes(): mesh.setSelectable(False) # Remove any HighlightFace if they exist for node in mesh.getChildren(): if isinstance(node, SmartSliceScene.HighlightFace): mesh.removeChild(node) elif isinstance(node, SmartSliceScene.Root): mesh.removeChild(node) # Ensure we have tools defined and apply them here use_tool = self._our_toolset[0] self.setToolVisibility(True) controller.setFallbackTool(use_tool) self._previous_tool = controller.getActiveTool() if self._previous_tool: controller.setActiveTool(use_tool) self._connector.propertyHandler.cacheChanges() self._connector.updateSliceWidget() if self._invalid_scene_message and self._invalid_scene_message.visible: self._invalid_scene_message.hide()