Merge branch 'master' into feature_xmlmaterials_cura_settings

# Conflicts:
#	plugins/XmlMaterialProfile/XmlMaterialProfile.py
This commit is contained in:
fieldOfView 2017-11-16 14:01:40 +01:00
commit 185c2834d2
824 changed files with 44240 additions and 27936 deletions

View file

@ -1,5 +1,5 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
# Cura is released under the terms of the LGPLv3 or higher.
import copy
import io
@ -33,9 +33,10 @@ class XmlMaterialProfile(InstanceContainer):
#
# \param xml_version: The version number found in an XML file.
# \return The corresponding setting_version.
def xmlVersionToSettingVersion(self, xml_version: str) -> int:
@classmethod
def xmlVersionToSettingVersion(cls, xml_version: str) -> int:
if xml_version == "1.3":
return 2
return CuraApplication.SettingVersion
return 0 #Older than 1.3.
def getInheritedFiles(self):
@ -221,10 +222,15 @@ class XmlMaterialProfile(InstanceContainer):
machine_container_map[definition_id] = container
# Map machine human-readable names to IDs
product_id_map = {}
for container in registry.findDefinitionContainers(type = "machine"):
product_id_map[container.getName()] = container.getId()
for definition_id, container in machine_container_map.items():
definition = container.getDefinition()
try:
product = UM.Dictionary.findKey(self.__product_id_map, definition_id)
product = UM.Dictionary.findKey(product_id_map, definition_id)
except ValueError:
# An unknown product id; export it anyway
product = definition_id
@ -403,20 +409,22 @@ class XmlMaterialProfile(InstanceContainer):
def getConfigurationTypeFromSerialized(self, serialized: str) -> Optional[str]:
return "materials"
def getVersionFromSerialized(self, serialized: str) -> Optional[int]:
@classmethod
def getVersionFromSerialized(cls, serialized: str) -> Optional[int]:
data = ET.fromstring(serialized)
version = 1
version = XmlMaterialProfile.Version
# get setting version
if "version" in data.attrib:
setting_version = self.xmlVersionToSettingVersion(data.attrib["version"])
setting_version = XmlMaterialProfile.xmlVersionToSettingVersion(data.attrib["version"])
else:
setting_version = self.xmlVersionToSettingVersion("1.2")
setting_version = XmlMaterialProfile.xmlVersionToSettingVersion("1.2")
return version * 1000000 + setting_version
## Overridden from InstanceContainer
def deserialize(self, serialized):
containers_to_add = []
# update the serialized data first
from UM.Settings.Interfaces import ContainerInterface
serialized = ContainerInterface.deserialize(self, serialized)
@ -504,8 +512,6 @@ class XmlMaterialProfile(InstanceContainer):
elif key in self.__unmapped_settings:
if key == "hardware compatible":
common_compatibility = self._parseCompatibleValue(entry.text)
else:
Logger.log("d", "Unsupported material setting %s", key)
# Add namespaced Cura-specific settings
settings = data.iterfind("./um:settings/cura:setting", self.__namespaces)
@ -519,6 +525,11 @@ class XmlMaterialProfile(InstanceContainer):
self.setMetaData(meta_data)
self._dirty = False
# Map machine human-readable names to IDs
product_id_map = {}
for container in ContainerRegistry.getInstance().findDefinitionContainers(type = "machine"):
product_id_map[container.getName()] = container.getId()
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
for machine in machines:
machine_compatibility = common_compatibility
@ -545,7 +556,7 @@ class XmlMaterialProfile(InstanceContainer):
identifiers = machine.iterfind("./um:machine_identifier", self.__namespaces)
for identifier in identifiers:
machine_id = self.__product_id_map.get(identifier.get("product"), None)
machine_id = product_id_map.get(identifier.get("product"), None)
if machine_id is None:
# Lets try again with some naive heuristics.
machine_id = identifier.get("product").replace(" ", "").lower()
@ -562,7 +573,17 @@ class XmlMaterialProfile(InstanceContainer):
if machine_compatibility:
new_material_id = self.id + "_" + machine_id
new_material = XmlMaterialProfile(new_material_id)
# The child or derived material container may already exist. This can happen when a material in a
# project file and the a material in Cura have the same ID.
# In the case if a derived material already exists, override that material container because if
# the data in the parent material has been changed, the derived ones should be updated too.
found_materials = ContainerRegistry.getInstance().findInstanceContainers(id = new_material_id)
is_new_material = False
if found_materials:
new_material = found_materials[0]
else:
new_material = XmlMaterialProfile(new_material_id)
is_new_material = True
# Update the private directly, as we want to prevent the lookup that is done when using setName
new_material._name = self.getName()
@ -576,7 +597,8 @@ class XmlMaterialProfile(InstanceContainer):
new_material._dirty = False
ContainerRegistry.getInstance().addContainer(new_material)
if is_new_material:
containers_to_add.append(new_material)
hotends = machine.iterfind("./um:hotend", self.__namespaces)
for hotend in hotends:
@ -614,7 +636,15 @@ class XmlMaterialProfile(InstanceContainer):
new_hotend_id = self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
new_hotend_material = XmlMaterialProfile(new_hotend_id)
# Same as machine compatibility, keep the derived material containers consistent with the parent
# material
found_materials = ContainerRegistry.getInstance().findInstanceContainers(id = new_hotend_id)
is_new_material = False
if found_materials:
new_hotend_material = found_materials[0]
else:
new_hotend_material = XmlMaterialProfile(new_hotend_id)
is_new_material = True
# Update the private directly, as we want to prevent the lookup that is done when using setName
new_hotend_material._name = self.getName()
@ -632,7 +662,11 @@ class XmlMaterialProfile(InstanceContainer):
new_hotend_material._dirty = False
ContainerRegistry.getInstance().addContainer(new_hotend_material)
if is_new_material:
containers_to_add.append(new_hotend_material)
for container_to_add in containers_to_add:
ContainerRegistry.getInstance().addContainer(container_to_add)
def _addSettingElement(self, builder, instance):
key = instance.definition.key
@ -669,7 +703,9 @@ class XmlMaterialProfile(InstanceContainer):
"processing temperature graph": "material_flow_temp_graph",
"print cooling": "cool_fan_speed",
"retraction amount": "retraction_amount",
"retraction speed": "retraction_speed"
"retraction speed": "retraction_speed",
"adhesion tendency": "material_adhesion_tendency",
"surface energy": "material_surface_energy"
}
__unmapped_settings = [
"hardware compatible"
@ -681,21 +717,6 @@ class XmlMaterialProfile(InstanceContainer):
"GUID": "material_guid"
}
# Map XML file product names to internal ids
# TODO: Move this to definition's metadata
__product_id_map = {
"Ultimaker 3": "ultimaker3",
"Ultimaker 3 Extended": "ultimaker3_extended",
"Ultimaker 2": "ultimaker2",
"Ultimaker 2+": "ultimaker2_plus",
"Ultimaker 2 Go": "ultimaker2_go",
"Ultimaker 2 Extended": "ultimaker2_extended",
"Ultimaker 2 Extended+": "ultimaker2_extended_plus",
"Ultimaker Original": "ultimaker_original",
"Ultimaker Original+": "ultimaker_original_plus",
"IMADE3D JellyBOX": "imade3d_jellybox"
}
# Map of recognised namespaces with a proper prefix.
__namespaces = {
"um": "http://www.ultimaker.com/material",