mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Require MaterialGroup to always have a base material
The material group is loaded lazily whenever the base material is not yet in the dictionary. Contributes to issue CURA-4606.
This commit is contained in:
parent
c54679ba2d
commit
1512a8096b
2 changed files with 13 additions and 14 deletions
|
@ -1,9 +1,10 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 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 List
|
||||||
|
from cura.Machines.MaterialNode import MaterialNode #For type checking.
|
||||||
|
|
||||||
#
|
## A MaterialGroup represents a group of material InstanceContainers that are derived from a single material profile.
|
||||||
# A MaterialGroup represents a group of material InstanceContainers that are derived from a single material profile.
|
|
||||||
# The main InstanceContainer which has the ID of the material profile file name is called the "root_material". For
|
# The main InstanceContainer which has the ID of the material profile file name is called the "root_material". For
|
||||||
# example: "generic_abs" is the root material (ID) of "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4",
|
# example: "generic_abs" is the root material (ID) of "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4",
|
||||||
# and "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4" are derived materials of "generic_abs".
|
# and "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4" are derived materials of "generic_abs".
|
||||||
|
@ -17,10 +18,10 @@
|
||||||
class MaterialGroup:
|
class MaterialGroup:
|
||||||
__slots__ = ("name", "root_material_node", "derived_material_node_list")
|
__slots__ = ("name", "root_material_node", "derived_material_node_list")
|
||||||
|
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: str, root_material_node: MaterialNode):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.root_material_node = None
|
self.root_material_node = root_material_node
|
||||||
self.derived_material_node_list = []
|
self.derived_material_node_list = [] #type: List[MaterialNode]
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "%s[%s]" % (self.__class__.__name__, self.name)
|
return "%s[%s]" % (self.__class__.__name__, self.name)
|
||||||
|
|
|
@ -72,29 +72,27 @@ class MaterialManager(QObject):
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
# Find all materials and put them in a matrix for quick search.
|
# Find all materials and put them in a matrix for quick search.
|
||||||
material_metadata_list = self._container_registry.findContainersMetadata(type = "material")
|
material_metadatas = {metadata["id"]: metadata for metadata in self._container_registry.findContainersMetadata(type = "material")}
|
||||||
|
|
||||||
self._material_group_map = dict()
|
self._material_group_map = dict()
|
||||||
|
|
||||||
# Map #1
|
# Map #1
|
||||||
# root_material_id -> MaterialGroup
|
# root_material_id -> MaterialGroup
|
||||||
for material_metadata in material_metadata_list:
|
for material_id, material_metadata in material_metadatas.items():
|
||||||
material_id = material_metadata["id"]
|
|
||||||
# We don't store empty material in the lookup tables
|
# We don't store empty material in the lookup tables
|
||||||
if material_id == "empty_material":
|
if material_id == "empty_material":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
root_material_id = material_metadata.get("base_file")
|
root_material_id = material_metadata.get("base_file")
|
||||||
if root_material_id not in self._material_group_map:
|
if root_material_id not in self._material_group_map:
|
||||||
self._material_group_map[root_material_id] = MaterialGroup(root_material_id)
|
self._material_group_map[root_material_id] = MaterialGroup(root_material_id, MaterialNode(material_metadatas[root_material_id]))
|
||||||
group = self._material_group_map[root_material_id]
|
group = self._material_group_map[root_material_id]
|
||||||
|
|
||||||
# We only add root materials here
|
#Store this material in the group of the appropriate root material.
|
||||||
if material_id == root_material_id:
|
if material_id != root_material_id:
|
||||||
group.root_material_node = MaterialNode(material_metadata)
|
|
||||||
else:
|
|
||||||
new_node = MaterialNode(material_metadata)
|
new_node = MaterialNode(material_metadata)
|
||||||
group.derived_material_node_list.append(new_node)
|
group.derived_material_node_list.append(new_node)
|
||||||
|
|
||||||
# Order this map alphabetically so it's easier to navigate in a debugger
|
# Order this map alphabetically so it's easier to navigate in a debugger
|
||||||
self._material_group_map = OrderedDict(sorted(self._material_group_map.items(), key = lambda x: x[0]))
|
self._material_group_map = OrderedDict(sorted(self._material_group_map.items(), key = lambda x: x[0]))
|
||||||
|
|
||||||
|
@ -179,7 +177,7 @@ class MaterialManager(QObject):
|
||||||
# "machine" -> "variant_name" -> "root material ID" -> specific material InstanceContainer
|
# "machine" -> "variant_name" -> "root material ID" -> specific material InstanceContainer
|
||||||
# Construct the "machine" -> "variant" -> "root material ID" -> specific material InstanceContainer
|
# Construct the "machine" -> "variant" -> "root material ID" -> specific material InstanceContainer
|
||||||
self._diameter_machine_variant_material_map = dict()
|
self._diameter_machine_variant_material_map = dict()
|
||||||
for material_metadata in material_metadata_list:
|
for material_metadata in material_metadatas.values():
|
||||||
# We don't store empty material in the lookup tables
|
# We don't store empty material in the lookup tables
|
||||||
if material_metadata["id"] == "empty_material":
|
if material_metadata["id"] == "empty_material":
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue