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.
This commit is contained in:
Lipu Fei 2018-11-05 11:48:17 +01:00
parent 90726ecbff
commit fa693aef2b

View file

@ -591,12 +591,26 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
return result return result
def _createMaterialOutputModel(self, material_data) -> MaterialOutputModel: def _createMaterialOutputModel(self, material_data) -> MaterialOutputModel:
containers = ContainerRegistry.getInstance().findInstanceContainers(type="material", GUID=material_data["guid"]) material_manager = CuraApplication.getInstance().getMaterialManager()
if containers: material_group_list = material_manager.getMaterialGroupListByGUID(material_data["guid"])
color = containers[0].getMetaDataEntry("color_code")
brand = containers[0].getMetaDataEntry("brand") # Sort the material groups by "is_read_only = True" first, and then the name alphabetically.
material_type = containers[0].getMetaDataEntry("material") read_only_material_group_list = list(filter(lambda x: x.is_read_only, material_group_list))
name = containers[0].getName() 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: else:
Logger.log("w", Logger.log("w",
"Unable to find material with guid {guid}. Using data as provided by cluster".format( "Unable to find material with guid {guid}. Using data as provided by cluster".format(