From cb1a36577c8ab6686bb1f83ced2f0e61a09bf3e2 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 1 Sep 2016 11:18:15 +0200 Subject: [PATCH] Machines are now flattened before merging them This ensures that machines are overwritten correctly CURA-2108 --- .../XmlMaterialProfile/XmlMaterialProfile.py | 37 ++++++++++++++++++- ...maker_pla_silver-metallic.xml.fdm_material | 8 ++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 15f022d539..58a948c17b 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -272,9 +272,44 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer): self._inherited_files.append(path) return ET.fromstring(contents) + # The XML material profile can have specific settings for machines. + # Some machines share profiles, so they are only created once. + # This function duplicates those elements so that each machine tag only has one identifier. + def _flattenMachinesXML(self, element): + settings_element = element.find("./um:settings", self.__namespaces) + machines = settings_element.iterfind("./um:machine", self.__namespaces) + machines_to_add = [] + machines_to_remove = [] + for machine in machines: + identifiers = list(machine.iterfind("./um:machine_identifier", self.__namespaces)) + has_multiple_identifiers = len(identifiers) > 1 + if has_multiple_identifiers: + # Multiple identifiers found. We need to create a new machine element and copy all it's settings there. + for identifier in identifiers: + new_machine = copy.deepcopy(machine) + # Create list of identifiers that need to be removed from the copied element. + other_identifiers = [self._createKey(other_identifier) for other_identifier in identifiers if other_identifier is not identifier] + # As we can only remove by exact object reference, we need to look through the identifiers of copied machine. + new_machine_identifiers = list(new_machine.iterfind("./um:machine_identifier", self.__namespaces)) + for new_machine_identifier in new_machine_identifiers: + key = self._createKey(new_machine_identifier) + # Key was in identifiers to remove, so this element needs to be purged + if key in other_identifiers: + new_machine.remove(new_machine_identifier) + machines_to_add.append(new_machine) + machines_to_remove.append(machine) + else: + pass # Machine only has one identifier. Nothing to do. + # Remove & add all required machines. + for machine_to_remove in machines_to_remove: + settings_element.remove(machine_to_remove) + for machine_to_add in machines_to_add: + settings_element.append(machine_to_add) + return element + def _mergeXML(self, first, second): result = copy.deepcopy(first) - self._combineElement(result, second) + self._combineElement(self._flattenMachinesXML(result), self._flattenMachinesXML(second)) return result def _createKey(self, element): diff --git a/resources/materials/ultimaker_pla_silver-metallic.xml.fdm_material b/resources/materials/ultimaker_pla_silver-metallic.xml.fdm_material index fd829abf6c..2f250e8e31 100644 --- a/resources/materials/ultimaker_pla_silver-metallic.xml.fdm_material +++ b/resources/materials/ultimaker_pla_silver-metallic.xml.fdm_material @@ -3,6 +3,7 @@ Automatically generated PLA profile. Data in this file may not be not correct. --> + generic_pla Ultimaker @@ -36,16 +37,15 @@ Automatically generated PLA profile. Data in this file may not be not correct. - 150 - - + + - 150 + 180