Beispiel #1
0
    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()
Beispiel #2
0
    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)
Beispiel #3
0
    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()
Beispiel #4
0
    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()
Beispiel #5
0
    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()
Beispiel #6
0
    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()
Beispiel #7
0
    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()
Beispiel #8
0
    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 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()
Beispiel #10
0
    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()
Beispiel #11
0
    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()
Beispiel #12
0
    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()
Beispiel #13
0
 def removeMesh(self, key):
     for node in Application.getInstance().getController().getScene().getRoot().getAllChildren():
         if id(node) == key:
             op = RemoveSceneNodeOperation(node)
             op.push()
             break
Beispiel #14
0
 def removeDuplicatedNodes(self):
     for node in self._duplicated_nodes:
         op = RemoveSceneNodeOperation(node)
         op.redo()
Beispiel #15
0
    def deleteObject(self, object_id):
        object = self.getController().getScene().findObject(object_id)

        if object:
            op = RemoveSceneNodeOperation(object)
            op.push()
Beispiel #16
0
    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)