From 63f5c8346a9c3a4cb331e962d67afe2c695d0949 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 8 Jun 2018 14:33:13 +0200 Subject: [PATCH] Implement API call to send material profile It seems to work now. I don't know if the material actually arrives but from this end it seems to send it at least. Contributes to issue CURA-5034. --- plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py index 4d3b065659..4e05847dad 100644 --- a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py @@ -544,7 +544,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): # 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): + def sendMaterialProfiles(self) -> None: container_registry = ContainerRegistry.getInstance() base_files = set() @@ -556,7 +556,14 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): for file in base_files: Logger.log("d", "Syncing material profile with printer: {file}".format(file = file)) - #TODO Call API to send profile. + + 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): try: