mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 08:17:49 -06:00
Don't use deprecated material manager any more
Contributes to issue CURA-6600.
This commit is contained in:
parent
ae7c717636
commit
443495973f
1 changed files with 23 additions and 27 deletions
|
@ -1,8 +1,9 @@
|
||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from cura.PrinterOutput.Models.MaterialOutputModel import MaterialOutputModel
|
from cura.PrinterOutput.Models.MaterialOutputModel import MaterialOutputModel
|
||||||
|
|
||||||
from ..BaseModel import BaseModel
|
from ..BaseModel import BaseModel
|
||||||
|
@ -24,32 +25,27 @@ class ClusterPrinterConfigurationMaterial(BaseModel):
|
||||||
self.material = material
|
self.material = material
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
## Creates a material output model based on this cloud printer material.
|
## Creates a material output model based on this cloud printer material.
|
||||||
|
#
|
||||||
|
# A material is chosen that matches the current GUID. If multiple such
|
||||||
|
# materials are available, read-only materials are preferred and the
|
||||||
|
# material with the earliest alphabetical name will be selected.
|
||||||
|
# \return A material output model that matches the current GUID.
|
||||||
def createOutputModel(self) -> MaterialOutputModel:
|
def createOutputModel(self) -> MaterialOutputModel:
|
||||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
material_group_list = material_manager.getMaterialGroupListByGUID(self.guid) or []
|
same_guid = container_registry.findInstanceContainersMetadata(guid = self.guid)
|
||||||
|
if same_guid:
|
||||||
# Sort the material groups by "is_read_only = True" first, and then the name alphabetically.
|
read_only = sorted(filter(lambda metadata: container_registry.isReadOnly(metadata["id"]), same_guid), key = lambda metadata: metadata["name"])
|
||||||
read_only_material_group_list = list(filter(lambda x: x.is_read_only, material_group_list))
|
if read_only:
|
||||||
non_read_only_material_group_list = list(filter(lambda x: not x.is_read_only, material_group_list))
|
material_metadata = read_only[0]
|
||||||
material_group = None
|
else:
|
||||||
if read_only_material_group_list:
|
material_metadata = min(same_guid, key = lambda metadata: metadata["name"])
|
||||||
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.container
|
|
||||||
color = container.getMetaDataEntry("color_code")
|
|
||||||
brand = container.getMetaDataEntry("brand")
|
|
||||||
material_type = container.getMetaDataEntry("material")
|
|
||||||
name = container.getName()
|
|
||||||
else:
|
else:
|
||||||
color = self.color
|
material_metadata = {
|
||||||
brand = self.brand
|
"color_code": self.color,
|
||||||
material_type = self.material
|
"brand": self.brand,
|
||||||
name = "Empty" if self.material == "empty" else "Unknown"
|
"material": self.material,
|
||||||
|
"name": "Empty" if self.material == "empty" else "Unknown"
|
||||||
|
}
|
||||||
|
|
||||||
return MaterialOutputModel(guid=self.guid, type=material_type, brand=brand, color=color, name=name)
|
return MaterialOutputModel(guid = self.guid, type = material_metadata["material"], brand = material_metadata["brand"], color = material_metadata["color_code"], name = material_metadata["name"])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue