From fa693aef2b7b4e85e691c916abd23ad7acc2ca14 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 5 Nov 2018 11:48:17 +0100 Subject: [PATCH 1/2] Fix material shown in print jobs CURA-5887 - Use MaterialManager to get materials - For a GUID with mulitple matches, show the read-only materials first if any. Otherwise, show non-read-only materials. --- .../src/ClusterUM3OutputDevice.py | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index 7504d55ad9..e4cea70f98 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -591,12 +591,26 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): return result def _createMaterialOutputModel(self, material_data) -> MaterialOutputModel: - containers = ContainerRegistry.getInstance().findInstanceContainers(type="material", GUID=material_data["guid"]) - if containers: - color = containers[0].getMetaDataEntry("color_code") - brand = containers[0].getMetaDataEntry("brand") - material_type = containers[0].getMetaDataEntry("material") - name = containers[0].getName() + material_manager = CuraApplication.getInstance().getMaterialManager() + material_group_list = material_manager.getMaterialGroupListByGUID(material_data["guid"]) + + # Sort the material groups by "is_read_only = True" first, and then the name alphabetically. + read_only_material_group_list = list(filter(lambda x: x.is_read_only, material_group_list)) + non_read_only_material_group_list = list(filter(lambda x: not x.is_read_only, material_group_list)) + material_group = None + if read_only_material_group_list: + read_only_material_group_list = sorted(read_only_material_group_list, key = lambda x: x.name) + material_group = read_only_material_group_list[0] + elif non_read_only_material_group_list: + non_read_only_material_group_list = sorted(non_read_only_material_group_list, key = lambda x: x.name) + material_group = non_read_only_material_group_list[0] + + if material_group: + container = material_group.root_material_node.getContainer() + color = container.getMetaDataEntry("color_code") + brand = container.getMetaDataEntry("brand") + material_type = container.getMetaDataEntry("material") + name = container.getName() else: Logger.log("w", "Unable to find material with guid {guid}. Using data as provided by cluster".format( From 88f3325972537eb1d01795e62230d9053d50661e Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 5 Nov 2018 13:11:54 +0100 Subject: [PATCH 2/2] Add typing for _createMaterialOutputModel() CURA-5887 --- plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index e4cea70f98..8314b0f089 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -590,7 +590,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): origin_name=change["origin_name"])) return result - def _createMaterialOutputModel(self, material_data) -> MaterialOutputModel: + def _createMaterialOutputModel(self, material_data: Dict[str, Any]) -> "MaterialOutputModel": material_manager = CuraApplication.getInstance().getMaterialManager() material_group_list = material_manager.getMaterialGroupListByGUID(material_data["guid"])