mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 05:25:56 +08:00
Merge pull request #4966 from Ultimaker/CL-1160_fix_materials_none_type
CL-1160 Replace fix for 'None' materials
This commit is contained in:
commit
1f26b55731
@ -607,7 +607,24 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
|
|
||||||
def _createMaterialOutputModel(self, material_data: Dict[str, Any]) -> "MaterialOutputModel":
|
def _createMaterialOutputModel(self, material_data: Dict[str, Any]) -> "MaterialOutputModel":
|
||||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
material_manager = CuraApplication.getInstance().getMaterialManager()
|
||||||
material_group_list = material_manager.getMaterialGroupListByGUID(material_data["guid"])
|
material_group_list = None
|
||||||
|
|
||||||
|
# Avoid crashing if there is no "guid" field in the metadata
|
||||||
|
material_guid = material_data.get("guid")
|
||||||
|
if material_guid:
|
||||||
|
material_group_list = material_manager.getMaterialGroupListByGUID(material_guid)
|
||||||
|
|
||||||
|
# This can happen if the connected machine has no material in one or more extruders (if GUID is empty), or the
|
||||||
|
# material is unknown to Cura, so we should return an "empty" or "unknown" material model.
|
||||||
|
if material_group_list is None:
|
||||||
|
material_name = i18n_catalog.i18nc("@label:material", "Empty") if len(material_data.get("guid", "")) == 0 \
|
||||||
|
else i18n_catalog.i18nc("@label:material", "Unknown")
|
||||||
|
return MaterialOutputModel(guid = material_data.get("guid", ""),
|
||||||
|
type = material_data.get("type", ""),
|
||||||
|
color = material_data.get("color", ""),
|
||||||
|
brand = material_data.get("brand", ""),
|
||||||
|
name = material_data.get("name", material_name)
|
||||||
|
)
|
||||||
|
|
||||||
# Sort the material groups by "is_read_only = True" first, and then the name alphabetically.
|
# 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))
|
read_only_material_group_list = list(filter(lambda x: x.is_read_only, material_group_list))
|
||||||
@ -633,7 +650,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
color = material_data["color"]
|
color = material_data["color"]
|
||||||
brand = material_data["brand"]
|
brand = material_data["brand"]
|
||||||
material_type = material_data["material"]
|
material_type = material_data["material"]
|
||||||
name = "Empty" if material_data["material"] == "empty" else "Unknown"
|
name = i18n_catalog.i18nc("@label:material", "Empty") if material_data["material"] == "empty" \
|
||||||
|
else i18n_catalog.i18nc("@label:material", "Unknown")
|
||||||
return MaterialOutputModel(guid = material_data["guid"], type = material_type,
|
return MaterialOutputModel(guid = material_data["guid"], type = material_type,
|
||||||
brand = brand, color = color, name = name)
|
brand = brand, color = color, name = name)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user