def deleteSelection(self) -> None: if not cura.CuraApplication.CuraApplication.getInstance( ).getController().getToolsEnabled(): return removed_group_nodes = [] #type: List[SceneNode] op = GroupedOperation() nodes = Selection.getAllSelectedObjects() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) group_node = node.getParent() if group_node and group_node.callDecoration( "isGroup") and group_node not in removed_group_nodes: remaining_nodes_in_group = list( set(group_node.getChildren()) - set(nodes)) if len(remaining_nodes_in_group) == 1: removed_group_nodes.append(group_node) op.addOperation( SetParentOperation(remaining_nodes_in_group[0], group_node.getParent())) op.addOperation(RemoveSceneNodeOperation(group_node)) # Reset the print information cura.CuraApplication.CuraApplication.getInstance().getController( ).getScene().sceneChanged.emit(node) op.push()
def deleteSelection(self) -> None: if not Application.getInstance().getController().getToolsEnabled(): return removed_group_nodes = [] op = GroupedOperation() nodes = Selection.getAllSelectedObjects() for node in nodes: print_mode_enabled = Application.getInstance( ).getGlobalContainerStack().getProperty("print_mode", "enabled") if print_mode_enabled: node_dup = PrintModeManager.getInstance().getDuplicatedNode( node) op.addOperation(RemoveNodesOperation(node_dup)) else: op.addOperation(RemoveSceneNodeOperation(node)) group_node = node.getParent() if group_node and group_node.callDecoration( "isGroup") and group_node not in removed_group_nodes: remaining_nodes_in_group = list( set(group_node.getChildren()) - set(nodes)) if len(remaining_nodes_in_group) == 1: removed_group_nodes.append(group_node) op.addOperation( SetParentOperation(remaining_nodes_in_group[0], group_node.getParent())) op.addOperation(RemoveSceneNodeOperation(group_node)) op.push()
def deleteSelection(self): if not self.getController().getToolsEnabled(): return removed_group_nodes = [] op = GroupedOperation() nodes = Selection.getAllSelectedObjects() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) group_node = node.getParent() if group_node and group_node.callDecoration("isGroup") and group_node not in removed_group_nodes: remaining_nodes_in_group = list(set(group_node.getChildren()) - set(nodes)) if len(remaining_nodes_in_group) == 1: removed_group_nodes.append(group_node) op.addOperation(SetParentOperation(remaining_nodes_in_group[0], group_node.getParent())) op.addOperation(RemoveSceneNodeOperation(group_node)) op.push()
def _replaceSceneNode(self, existing_node, trimeshes): name = existing_node.getName() file_name = existing_node.getMeshData().getFileName() transformation = existing_node.getWorldTransformation() parent = existing_node.getParent() extruder_id = existing_node.callDecoration("getActiveExtruder") build_plate = existing_node.callDecoration("getBuildPlateNumber") selected = Selection.isSelected(existing_node) op = GroupedOperation() op.addOperation(RemoveSceneNodeOperation(existing_node)) for i, tri_node in enumerate(trimeshes): mesh_data = self._toMeshData(tri_node) new_node = CuraSceneNode() new_node.setSelectable(True) new_node.setMeshData(mesh_data) new_node.setName(name if i == 0 else "%s %d" % (name, i)) new_node.callDecoration("setActiveExtruder", extruder_id) new_node.addDecorator(BuildPlateDecorator(build_plate)) new_node.addDecorator(SliceableObjectDecorator()) op.addOperation(AddSceneNodeOperation(new_node, parent)) op.addOperation( SetTransformMatrixOperation(new_node, transformation)) if selected: Selection.add(new_node) op.push()
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 removeMesh(self, key): for node in Application.getInstance().getController().getScene( ).getRoot().getAllChildren(): if id(node) == key: op = RemoveSceneNodeOperation(node) op.push() break
def deleteObject(self, object_id): object = self.getController().getScene().findObject(object_id) if not object and object_id != 0: #Workaround for tool handles overlapping the selected object object = Selection.getSelectedObject(0) if object: if object.getParent(): group_node = object.getParent() if not group_node.callDecoration("isGroup"): op = RemoveSceneNodeOperation(object) else: while group_node.getParent().callDecoration("isGroup"): group_node = group_node.getParent() op = RemoveSceneNodeOperation(group_node) op.push()
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 _replaceSceneNode(self, existing_node, trimeshes) -> None: name = existing_node.getName() file_name = existing_node.getMeshData().getFileName() transformation = existing_node.getWorldTransformation() parent = existing_node.getParent() extruder_id = existing_node.callDecoration("getActiveExtruder") build_plate = existing_node.callDecoration("getBuildPlateNumber") selected = Selection.isSelected(existing_node) children = existing_node.getChildren() new_nodes = [] op = GroupedOperation() op.addOperation(RemoveSceneNodeOperation(existing_node)) for i, tri_node in enumerate(trimeshes): mesh_data = self._toMeshData(tri_node, file_name) new_node = CuraSceneNode() new_node.setSelectable(True) new_node.setMeshData(mesh_data) new_node.setName(name if i==0 else "%s %d" % (name, i)) new_node.callDecoration("setActiveExtruder", extruder_id) new_node.addDecorator(BuildPlateDecorator(build_plate)) new_node.addDecorator(SliceableObjectDecorator()) op.addOperation(AddSceneNodeOperation(new_node, parent)) op.addOperation(SetTransformMatrixOperation(new_node, transformation)) new_nodes.append(new_node) if selected: Selection.add(new_node) for child in children: mesh_data = child.getMeshData() if not mesh_data: continue child_bounding_box = mesh_data.getTransformed(child.getWorldTransformation()).getExtents() if not child_bounding_box: continue new_parent = None for potential_parent in new_nodes: parent_mesh_data = potential_parent.getMeshData() if not parent_mesh_data: continue parent_bounding_box = parent_mesh_data.getTransformed(potential_parent.getWorldTransformation()).getExtents() if not parent_bounding_box: continue intersection = child_bounding_box.intersectsBox(parent_bounding_box) if intersection != AxisAlignedBox.IntersectionResult.NoIntersection: new_parent = potential_parent break if not new_parent: new_parent = new_nodes[0] op.addOperation(SetParentOperationSimplified(child, new_parent)) op.push()
def removeSelection(self): if not Selection.hasSelection(): return op = GroupedOperation() for node in Selection.getAllSelectedObjects(): op.addOperation(RemoveSceneNodeOperation(node)) op.push() Selection.clear()
def deleteObject(self, object_id): object = self.getController().getScene().findObject(object_id) if not object and object_id != 0: #Workaround for tool handles overlapping the selected object object = Selection.getSelectedObject(0) if object: op = RemoveSceneNodeOperation(object) op.push()
def deleteObject(self, object_id): if not self.getController().getToolsEnabled(): return node = self.getController().getScene().findObject(object_id) if not node and object_id != 0: # Workaround for tool handles overlapping the selected object node = Selection.getSelectedObject(0) if node: if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): op = RemoveSceneNodeOperation(node) else: while group_node.getParent().callDecoration("isGroup"): group_node = group_node.getParent() op = RemoveSceneNodeOperation(group_node) op.push()
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"))
def deleteSelection(self): if not self.getController().getToolsEnabled(): return op = GroupedOperation() nodes = Selection.getAllSelectedObjects() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) op.push() pass
def _removeEraserMesh(self, node: CuraSceneNode): parent = node.getParent() if parent == self._controller.getScene().getRoot(): parent = None op = RemoveSceneNodeOperation(node) op.push() if parent and not Selection.isSelected(parent): Selection.add(parent) CuraApplication.getInstance().getController().getScene().sceneChanged.emit(node)
def deleteObject(self, object_id): if not self.getController().getToolsEnabled(): return node = self.getController().getScene().findObject(object_id) if not node and object_id != 0: # Workaround for tool handles overlapping the selected object node = Selection.getSelectedObject(0) if node: group_node = None if node.getParent(): group_node = node.getParent() op = RemoveSceneNodeOperation(node) op.push() if group_node: if len(group_node.getChildren()) == 1 and group_node.callDecoration("isGroup"): op.addOperation(SetParentOperation(group_node.getChildren()[0], group_node.getParent())) op = RemoveSceneNodeOperation(group_node) op.push()
def deleteObject(self, object_id): if not self.getController().getToolsEnabled(): return node = self.getController().getScene().findObject(object_id) if not node and object_id != 0: # Workaround for tool handles overlapping the selected object node = Selection.getSelectedObject(0) if node: op = GroupedOperation() op.addOperation(RemoveSceneNodeOperation(node)) group_node = node.getParent() if group_node: # Note that at this point the node has not yet been deleted if len(group_node.getChildren()) <= 2 and group_node.callDecoration("isGroup"): op.addOperation(SetParentOperation(group_node.getChildren()[0], group_node.getParent())) op.addOperation(RemoveSceneNodeOperation(group_node)) op.push()
def _removeSplittingPlane(self, node: SteSlicerSceneNode): parent = node.getParent() if parent == self._controller.getScene().getRoot(): parent = None op = RemoveSceneNodeOperation(node) op.push() if parent and not Selection.isSelected(parent): Selection.add(parent) SteSlicerApplication.getInstance().getController().getScene( ).sceneChanged.emit(node)
def removeModMeshes(self, msg, action): """ Associated Action for askToRemoveModMesh() """ self._mod_mesh_removal_msg = None msg.hide() if action == "continue": op = GroupedOperation() for node in getModifierMeshes(): node.addDecorator(SmartSliceRemovedDecorator()) op.addOperation(RemoveSceneNodeOperation(node)) op.push() self.connector.status = SmartSliceCloudStatus.RemoveModMesh self.connector.doOptimization() else: self.connector.prepareOptimization()
def deleteAll(self): nodes = [] for node in DepthFirstIterator( self.getController().getScene().getRoot()): if type(node) is not SceneNode or not node.getMeshData(): continue nodes.append(node) if nodes: op = GroupedOperation() for node in nodes: op.addOperation(RemoveSceneNodeOperation(node)) op.push()
def deleteAll(self): 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()
def removeModMeshes(self, msg, action): msg.hide() if action == "continueModMesh": self._cachedModMesh = None self.hasModMesh = False for node in self._sceneRoot.getAllChildren(): stack = node.callDecoration("getStack") if stack is None: continue if stack.getProperty("infill_mesh", "value"): op = GroupedOperation() op.addOperation(RemoveSceneNodeOperation(node)) op.push() #if self.connector.status is SmartSliceCloudStatus.Optimizable: # self.connector.doOptimization() if self.connector.status is SmartSliceCloudStatus.ReadyToVerify: self.connector.doVerfication() else: self.connector.prepareValidation() else: self.connector.onConfirmationCancelClicked()
def removeDuplicatedNodes(self): for node in self._duplicated_nodes: op = RemoveSceneNodeOperation(node) op.redo()
def updateSceneFromOptimizationResult( self, analysis: pywim.smartslice.result.Analysis): our_only_node = getPrintableNodes()[0] active_extruder = getNodeActiveExtruder(our_only_node) # TODO - Move this into a common class or function to apply an am.Config to GlobalStack/ExtruderStack if analysis.print_config.infill: infill_density = analysis.print_config.infill.density infill_pattern = analysis.print_config.infill.pattern if infill_pattern is None or infill_pattern == pywim.am.InfillType.unknown: infill_pattern = pywim.am.InfillType.grid infill_pattern_name = SmartSliceJobHandler.INFILL_SMARTSLICE_CURA[ infill_pattern] extruder_dict = { "wall_line_count": analysis.print_config.walls, "top_layers": analysis.print_config.top_layers, "bottom_layers": analysis.print_config.bottom_layers, "infill_sparse_density": analysis.print_config.infill.density, "infill_pattern": infill_pattern_name } Logger.log("d", "Optimized extruder settings: {}".format(extruder_dict)) for key, value in extruder_dict.items(): if value is not None: active_extruder.setProperty(key, "value", value, set_from_cache=True) Application.getInstance().getMachineManager( ).forceUpdateAllSettings() self.optimizationResultAppliedToScene.emit() # Remove any modifier meshes which are present from a previous result mod_meshes = getModifierMeshes() if len(mod_meshes) > 0: op = GroupedOperation() for node in mod_meshes: node.addDecorator(SmartSliceRemovedDecorator()) op.addOperation(RemoveSceneNodeOperation(node)) op.push() Application.getInstance().getController().getScene( ).sceneChanged.emit(node) # Add in the new modifier meshes for modifier_mesh in analysis.modifier_meshes: # Building the scene node modifier_mesh_node = CuraSceneNode() modifier_mesh_node.setName("SmartSliceMeshModifier") modifier_mesh_node.setSelectable(True) modifier_mesh_node.setCalculateBoundingBox(True) # Use the data from the SmartSlice engine to translate / rotate / scale the mod mesh parent_transformation = our_only_node.getLocalTransformation() modifier_mesh_transform_matrix = parent_transformation.multiply( Matrix(modifier_mesh.transform)) modifier_mesh_node.setTransformation( modifier_mesh_transform_matrix) # Building the mesh # # Preparing the data from pywim for MeshBuilder modifier_mesh_vertices = [[v.x, v.y, v.z] for v in modifier_mesh.vertices] modifier_mesh_indices = [[triangle.v1, triangle.v2, triangle.v3] for triangle in modifier_mesh.triangles] # Doing the actual build modifier_mesh_data = MeshBuilder() modifier_mesh_data.setVertices( numpy.asarray(modifier_mesh_vertices, dtype=numpy.float32)) modifier_mesh_data.setIndices( numpy.asarray(modifier_mesh_indices, dtype=numpy.int32)) modifier_mesh_data.calculateNormals() modifier_mesh_node.setMeshData(modifier_mesh_data.build()) modifier_mesh_node.calculateBoundingBoxMesh() active_build_plate = Application.getInstance( ).getMultiBuildPlateModel().activeBuildPlate modifier_mesh_node.addDecorator( BuildPlateDecorator(active_build_plate)) modifier_mesh_node.addDecorator(SliceableObjectDecorator()) modifier_mesh_node.addDecorator(SmartSliceAddedDecorator()) bottom = modifier_mesh_node.getBoundingBox().bottom z_offset_decorator = ZOffsetDecorator() z_offset_decorator.setZOffset(bottom) modifier_mesh_node.addDecorator(z_offset_decorator) stack = modifier_mesh_node.callDecoration("getStack") settings = stack.getTop() modifier_mesh_node_infill_pattern = SmartSliceJobHandler.INFILL_SMARTSLICE_CURA[ modifier_mesh.print_config.infill.pattern] definition_dict = { "infill_mesh": True, "infill_pattern": modifier_mesh_node_infill_pattern, "infill_sparse_density": modifier_mesh.print_config.infill.density, "wall_line_count": modifier_mesh.print_config.walls, "top_layers": modifier_mesh.print_config.top_layers, "bottom_layers": modifier_mesh.print_config.bottom_layers, } Logger.log( "d", "Optimized modifier mesh settings: {}".format(definition_dict)) for key, value in definition_dict.items(): if value is not None: definition = stack.getSettingDefinition(key) new_instance = SettingInstance(definition, settings) new_instance.setProperty("value", value) new_instance.resetState( ) # Ensure that the state is not seen as a user state. settings.addInstance(new_instance) op = GroupedOperation() # First add node to the scene at the correct position/scale, before parenting, so the eraser mesh does not get scaled with the parent op.addOperation( AddSceneNodeOperation( modifier_mesh_node, Application.getInstance().getController().getScene(). getRoot())) op.addOperation( SetParentOperation( modifier_mesh_node, Application.getInstance().getController().getScene(). getRoot())) op.push() # emit changes and connect error tracker Application.getInstance().getController().getScene( ).sceneChanged.emit(modifier_mesh_node)