mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Send only original files
When we re-serialize them, the XML file will not be exactly the same so the signature will fail to match. We need to send the original bytes. This changes the behaviour: It now sends all non-default files instead of all files that were loaded fully. Contributes to issue CURA-5034.
This commit is contained in:
parent
ddb80be1ec
commit
4727340ae4
2 changed files with 16 additions and 27 deletions
|
@ -541,22 +541,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
#
|
#
|
||||||
# This gets called when connecting to a printer as well as when sending a
|
# This gets called when connecting to a printer as well as when sending a
|
||||||
# print.
|
# print.
|
||||||
#
|
|
||||||
# TODO: For now we send all material profiles that are fully loaded. See
|
|
||||||
# if that has any performance impact. If not, we can try sending ALL
|
|
||||||
# profiles. If it has, we may need to limit it to the profiles that are
|
|
||||||
# active in the current machine.
|
|
||||||
def sendMaterialProfiles(self) -> None:
|
def sendMaterialProfiles(self) -> None:
|
||||||
container_registry = ContainerRegistry.getInstance()
|
job = SendMaterialJob(device = self)
|
||||||
|
|
||||||
base_files = set()
|
|
||||||
for material_metadata in container_registry.findContainersMetadata(type = "material"):
|
|
||||||
if container_registry.isLoaded(material_metadata["id"]):
|
|
||||||
if "base_file" not in material_metadata:
|
|
||||||
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"])
|
|
||||||
|
|
||||||
job = SendMaterialJob(material_ids = base_files, device = self)
|
|
||||||
job.run()
|
job.run()
|
||||||
|
|
||||||
def loadJsonFromReply(reply):
|
def loadJsonFromReply(reply):
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Set, TYPE_CHECKING
|
import os #To walk over material files.
|
||||||
|
import os.path #To filter on material files.
|
||||||
|
from typing import 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.Job import Job #The interface we're implementing.
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Resources import Resources
|
||||||
|
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
||||||
|
@ -14,20 +18,19 @@ if TYPE_CHECKING:
|
||||||
#
|
#
|
||||||
# This way it won't freeze up the interface while sending those materials.
|
# This way it won't freeze up the interface while sending those materials.
|
||||||
class SendMaterialJob(Job):
|
class SendMaterialJob(Job):
|
||||||
def __init__(self, material_ids: Set[str], device: "NetworkedPrinterDevice"):
|
def __init__(self, device: "NetworkedPrinterDevice"):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.material_ids = material_ids
|
|
||||||
self.device = device
|
self.device = device
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
container_registry = ContainerRegistry.getInstance()
|
for file_path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.MaterialInstanceContainer):
|
||||||
for material_id in self.material_ids:
|
if not file_path.startswith(Resources.getDataStoragePath() + os.sep):
|
||||||
Logger.log("d", "Syncing material profile with printer: {material_id}".format(material_id = material_id))
|
continue
|
||||||
|
_, file_name = os.path.split(file_path)
|
||||||
|
Logger.log("d", "Syncing material profile with printer: {file_name}".format(file_name = file_name))
|
||||||
parts = []
|
parts = []
|
||||||
material = container_registry.findContainers(id = material_id)[0]
|
with open(file_path, "rb") as f:
|
||||||
serialized_material = material.serialize().encode("utf-8")
|
parts.append(self.device._createFormPart("name=\"file\"; filename=\"{file_name}\"".format(file_name = file_name), f.read()))
|
||||||
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\"", file_name.encode("utf-8"), "text/plain"))
|
||||||
parts.append(self.device._createFormPart("name=\"filename\"", (material_id + ".xml.fdm_material").encode("utf-8"), "text/plain"))
|
|
||||||
|
|
||||||
self.device.postFormWithParts(target = "/materials", parts = parts)
|
self.device.postFormWithParts(target = "/materials", parts = parts)
|
Loading…
Add table
Add a link
Reference in a new issue