Machines are now flattened before merging them

This ensures that machines are overwritten correctly

CURA-2108
This commit is contained in:
Jaime van Kessel 2016-09-01 11:18:15 +02:00
parent ad22cf4861
commit cb1a36577c
2 changed files with 40 additions and 5 deletions

View File

@ -272,9 +272,44 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
self._inherited_files.append(path) self._inherited_files.append(path)
return ET.fromstring(contents) 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): def _mergeXML(self, first, second):
result = copy.deepcopy(first) result = copy.deepcopy(first)
self._combineElement(result, second) self._combineElement(self._flattenMachinesXML(result), self._flattenMachinesXML(second))
return result return result
def _createKey(self, element): def _createKey(self, element):

View File

@ -3,6 +3,7 @@
Automatically generated PLA profile. Data in this file may not be not correct. Automatically generated PLA profile. Data in this file may not be not correct.
--> -->
<fdmmaterial xmlns="http://www.ultimaker.com/material"> <fdmmaterial xmlns="http://www.ultimaker.com/material">
<inherits>generic_pla</inherits>
<metadata> <metadata>
<name> <name>
<brand>Ultimaker</brand> <brand>Ultimaker</brand>
@ -36,16 +37,15 @@ Automatically generated PLA profile. Data in this file may not be not correct.
<machine_identifier manufacturer="Ultimaker" product="Ultimaker 2"/> <machine_identifier manufacturer="Ultimaker" product="Ultimaker 2"/>
<machine_identifier manufacturer="Ultimaker" product="Ultimaker 2 Go"/> <machine_identifier manufacturer="Ultimaker" product="Ultimaker 2 Go"/>
<machine_identifier manufacturer="Ultimaker" product="Ultimaker 2 Extended"/> <machine_identifier manufacturer="Ultimaker" product="Ultimaker 2 Extended"/>
<setting key="standby temperature">150</setting>
<setting key="processing temperature graph"> <setting key="processing temperature graph">
<point flow="2" temperature="180"/> <point flow="2" temperature="20"/>
<point flow="10" temperature="230"/> <point flow="10" temperature="20"/>
</setting> </setting>
</machine> </machine>
<machine> <machine>
<machine_identifier manufacturer="Ultimaker" product="Ultimaker Original"/> <machine_identifier manufacturer="Ultimaker" product="Ultimaker Original"/>
<setting key="standby temperature">150</setting> <setting key="standby temperature">180</setting>
</machine> </machine>
</settings> </settings>
</fdmmaterial> </fdmmaterial>