mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Send materials asynchronously
This way we won't block the interface while those materials are sending. Contributes to issue CURA-5034.
This commit is contained in:
parent
63f5c8346a
commit
ddb80be1ec
@ -4,6 +4,7 @@
|
|||||||
from UM.FileHandler.FileWriter import FileWriter #To choose based on the output file mode (text vs. binary).
|
from UM.FileHandler.FileWriter import FileWriter #To choose based on the output file mode (text vs. binary).
|
||||||
from UM.FileHandler.WriteFileJob import WriteFileJob #To call the file writer asynchronously.
|
from UM.FileHandler.WriteFileJob import WriteFileJob #To call the file writer asynchronously.
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.JobQueue import JobQueue #To send material profiles in the background.
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
@ -20,6 +21,7 @@ from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
|||||||
from cura.PrinterOutput.NetworkCamera import NetworkCamera
|
from cura.PrinterOutput.NetworkCamera import NetworkCamera
|
||||||
|
|
||||||
from .ClusterUM3PrinterOutputController import ClusterUM3PrinterOutputController
|
from .ClusterUM3PrinterOutputController import ClusterUM3PrinterOutputController
|
||||||
|
from .SendMaterialJob import SendMaterialJob
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
|
from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
@ -27,7 +29,7 @@ from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject
|
|||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, Dict, List
|
from typing import Optional, Dict, List, Set
|
||||||
|
|
||||||
import io #To create the correct buffers for sending data to the printer.
|
import io #To create the correct buffers for sending data to the printer.
|
||||||
import json
|
import json
|
||||||
@ -554,16 +556,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
continue #If there's no base file then there was no file for it (such as empty_material).
|
continue #If there's no base file then there was no file for it (such as empty_material).
|
||||||
base_files.add(material_metadata["base_file"])
|
base_files.add(material_metadata["base_file"])
|
||||||
|
|
||||||
for file in base_files:
|
job = SendMaterialJob(material_ids = base_files, device = self)
|
||||||
Logger.log("d", "Syncing material profile with printer: {file}".format(file = file))
|
job.run()
|
||||||
|
|
||||||
parts = []
|
|
||||||
material = container_registry.findContainers(id = file)[0]
|
|
||||||
serialized_material = material.serialize().encode("utf-8")
|
|
||||||
parts.append(self._createFormPart("name=\"file\"; filename=\"{file_name}.xml.fdm_material\"".format(file_name = file), serialized_material))
|
|
||||||
parts.append(self._createFormPart("name=\"filename\"", (file + ".xml.fdm_material").encode("utf-8"), "text/plain"))
|
|
||||||
|
|
||||||
self.postFormWithParts(target = "/materials", parts = parts)
|
|
||||||
|
|
||||||
def loadJsonFromReply(reply):
|
def loadJsonFromReply(reply):
|
||||||
try:
|
try:
|
||||||
|
33
plugins/UM3NetworkPrinting/SendMaterialJob.py
Normal file
33
plugins/UM3NetworkPrinting/SendMaterialJob.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from typing import Set, TYPE_CHECKING
|
||||||
|
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry #To get the material profiles we need to send.
|
||||||
|
from UM.Job import Job #The interface we're implementing.
|
||||||
|
from UM.Logger import Logger
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
||||||
|
|
||||||
|
## Asynchronous job to send material profiles to the printer.
|
||||||
|
#
|
||||||
|
# This way it won't freeze up the interface while sending those materials.
|
||||||
|
class SendMaterialJob(Job):
|
||||||
|
def __init__(self, material_ids: Set[str], device: "NetworkedPrinterDevice"):
|
||||||
|
super().__init__()
|
||||||
|
self.material_ids = material_ids
|
||||||
|
self.device = device
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
container_registry = ContainerRegistry.getInstance()
|
||||||
|
for material_id in self.material_ids:
|
||||||
|
Logger.log("d", "Syncing material profile with printer: {material_id}".format(material_id = material_id))
|
||||||
|
|
||||||
|
parts = []
|
||||||
|
material = container_registry.findContainers(id = material_id)[0]
|
||||||
|
serialized_material = material.serialize().encode("utf-8")
|
||||||
|
parts.append(self.device._createFormPart("name=\"file\"; filename=\"{file_name}.xml.fdm_material\"".format(file_name = material_id), serialized_material))
|
||||||
|
parts.append(self.device._createFormPart("name=\"filename\"", (material_id + ".xml.fdm_material").encode("utf-8"), "text/plain"))
|
||||||
|
|
||||||
|
self.device.postFormWithParts(target = "/materials", parts = parts)
|
Loading…
x
Reference in New Issue
Block a user