mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Store the base material file as a metadata property of XmlMaterialProfile
And use the base_file property to check if we should serialize or not. Contributes to CURA-342
This commit is contained in:
parent
1f6e99f641
commit
f21079b763
1 changed files with 9 additions and 12 deletions
|
@ -52,16 +52,8 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
def serialize(self):
|
||||
registry = UM.Settings.ContainerRegistry.getInstance()
|
||||
|
||||
all_containers = registry.findInstanceContainers(GUID = self.getMetaDataEntry("GUID"))
|
||||
most_generic = all_containers[0]
|
||||
for container in all_containers:
|
||||
# Find the "most generic" version of this material
|
||||
# This is a bit of a nasty implementation because of the naive assumption that anything with a shorter
|
||||
# id is more generic. It holds for the current implementation though.
|
||||
if len(most_generic.id) > len(container.id):
|
||||
most_generic = container
|
||||
|
||||
if most_generic and self.id != most_generic.id:
|
||||
base_file = self.getMetaDataEntry("base_file", "")
|
||||
if base_file and self.id != base_file:
|
||||
# Since we create an instance of XmlMaterialProfile for each machine and nozzle in the profile,
|
||||
# we should only serialize the "base" material definition, since that can then take care of
|
||||
# serializing the machine/nozzle specific profiles.
|
||||
|
@ -81,6 +73,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
metadata.pop("status", "")
|
||||
metadata.pop("variant", "")
|
||||
metadata.pop("type", "")
|
||||
metadata.pop("base_file", "")
|
||||
|
||||
## Begin Name Block
|
||||
builder.start("name")
|
||||
|
@ -129,6 +122,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
machine_container_map = {}
|
||||
machine_nozzle_map = {}
|
||||
|
||||
all_containers = registry.findInstanceContainers(GUID = self.getMetaDataEntry("GUID"))
|
||||
for container in all_containers:
|
||||
definition_id = container.getDefinition().id
|
||||
if definition_id == "fdmprinter":
|
||||
|
@ -136,8 +130,6 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
|
||||
if definition_id not in machine_container_map:
|
||||
machine_container_map[definition_id] = container
|
||||
elif len(container.id) < len(machine_container_map[definition_id].id):
|
||||
machine_container_map[definition_id] = container
|
||||
|
||||
if definition_id not in machine_nozzle_map:
|
||||
machine_nozzle_map[definition_id] = {}
|
||||
|
@ -145,6 +137,9 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
variant = container.getMetaDataEntry("variant")
|
||||
if variant:
|
||||
machine_nozzle_map[definition_id][variant] = container
|
||||
continue
|
||||
|
||||
machine_container_map[definition_id] = container
|
||||
|
||||
for definition_id, container in machine_container_map.items():
|
||||
definition = container.getDefinition()
|
||||
|
@ -278,6 +273,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
new_material.setName(self.getName())
|
||||
new_material.setMetaData(copy.deepcopy(self.getMetaData()))
|
||||
new_material.setDefinition(definition)
|
||||
new_material.addMetaDataEntry("base_file", self.id)
|
||||
|
||||
for key, value in global_setting_values.items():
|
||||
new_material.setProperty(key, "value", value, definition)
|
||||
|
@ -308,6 +304,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||
new_hotend_material.setName(self.getName())
|
||||
new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
|
||||
new_hotend_material.setDefinition(definition)
|
||||
new_hotend_material.addMetaDataEntry("base_file", self.id)
|
||||
|
||||
new_hotend_material.addMetaDataEntry("variant", variant_containers[0].id)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue