From 9c457b0d20f9023a8539a6235939ade1a642d40e Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 1 Aug 2024 15:31:04 +0200 Subject: [PATCH] Map internal name reps to .makerbot-file reps. Not only is this more congruent with the file-format as it exists, the Digital Library handles the metadata in this format, and can do little with it otherwise. last step needed for CURA-12005 --- plugins/MakerbotWriter/MakerbotWriter.py | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/plugins/MakerbotWriter/MakerbotWriter.py b/plugins/MakerbotWriter/MakerbotWriter.py index 156a6371eb2..34ef562fd32 100644 --- a/plugins/MakerbotWriter/MakerbotWriter.py +++ b/plugins/MakerbotWriter/MakerbotWriter.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023 UltiMaker +# Copyright (c) 2024 UltiMaker # Cura is released under the terms of the LGPLv3 or higher. from io import StringIO, BufferedIOBase import json @@ -18,6 +18,7 @@ from UM.i18n import i18nCatalog from cura.CuraApplication import CuraApplication +from cura.PrinterOutput.FormatMaps import FormatMaps from cura.Snapshot import Snapshot from cura.Utils.Threading import call_on_qt_thread from cura.CuraVersion import ConanInstalls @@ -138,7 +139,28 @@ def write(self, stream: BufferedIOBase, nodes: List[SceneNode], mode=MeshWriter. file, data = png_file["file"], png_file["data"] zip_stream.writestr(file, data) api = CuraApplication.getInstance().getCuraAPI() - slice_metadata = json.dumps(api.interface.settings.getSliceMetadata(), separators=(", ", ": "), indent=4) + metadata_json = api.interface.settings.getSliceMetadata() + + # All the mapping stuff we have to do: + product_to_id_map = FormatMaps.getProductIdMap() + printer_name_map = FormatMaps.getInversePrinterNameMap() + extruder_type_map = FormatMaps.getInverseExtruderTypeMap() + material_map = FormatMaps.getInverseMaterialMap() + for key, value in metadata_json.items(): + if "all_settings" in value: + if "machine_name" in value["all_settings"]: + machine_name = value["all_settings"]["machine_name"] + if machine_name in product_to_id_map: + machine_name = product_to_id_map[machine_name][0] + value["all_settings"]["machine_name"] = printer_name_map.get(machine_name, machine_name) + if "machine_nozzle_id" in value["all_settings"]: + extruder_type = value["all_settings"]["machine_nozzle_id"] + value["all_settings"]["machine_nozzle_id"] = extruder_type_map.get(extruder_type, extruder_type) + if "material_type" in value["all_settings"]: + material_type = value["all_settings"]["material_type"] + value["all_settings"]["material_type"] = material_map.get(material_type, material_type) + + slice_metadata = json.dumps(metadata_json, separators=(", ", ": "), indent=4) zip_stream.writestr("slicemetadata.json", slice_metadata) except (IOError, OSError, BadZipFile) as ex: Logger.log("e", f"Could not write to (.makerbot) file because: '{ex}'.")