From e163871360973506f20cd0b9ee048f16348119ba Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Sat, 12 Aug 2017 15:58:32 +0200 Subject: [PATCH 1/4] Add support for deserialising namespaced Cura settings in XML materials --- .../XmlMaterialProfile/XmlMaterialProfile.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 41d45cfc9b..32d998e1af 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -123,6 +123,7 @@ class XmlMaterialProfile(InstanceContainer): root = builder.start("fdmmaterial", {"xmlns": "http://www.ultimaker.com/material", + "xmlns:cura": "http://www.ultimaker.com/cura", "version": self.CurrentFdmMaterialVersion}) ## Begin Metadata Block @@ -505,6 +506,13 @@ class XmlMaterialProfile(InstanceContainer): 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) + for entry in settings: + key = entry.get("key") + common_setting_values[key] = entry.text + self._cached_values = common_setting_values # from InstanceContainer ancestor meta_data["compatible"] = common_compatibility @@ -526,6 +534,12 @@ class XmlMaterialProfile(InstanceContainer): else: Logger.log("d", "Unsupported material setting %s", key) + # Add namespaced Cura-specific settings + settings = machine.iterfind("./cura:setting", self.__namespaces) + for entry in settings: + key = entry.get("key") + machine_setting_values[key] = entry.text + cached_machine_setting_properties = common_setting_values.copy() cached_machine_setting_properties.update(machine_setting_values) @@ -592,6 +606,12 @@ class XmlMaterialProfile(InstanceContainer): else: Logger.log("d", "Unsupported material setting %s", key) + # Add namespaced Cura-specific settings + settings = hotend.iterfind("./cura:setting", self.__namespaces) + for entry in settings: + key = entry.get("key") + hotend_setting_values[key] = entry.text + new_hotend_id = self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_") new_hotend_material = XmlMaterialProfile(new_hotend_id) @@ -671,7 +691,8 @@ class XmlMaterialProfile(InstanceContainer): # Map of recognised namespaces with a proper prefix. __namespaces = { - "um": "http://www.ultimaker.com/material" + "um": "http://www.ultimaker.com/material", + "cura": "http://www.ultimaker.com/cura" } ## Helper function for pretty-printing XML because ETree is stupid From 0f8a57e785d2e623e87d448bcc9c4c3d3e143d24 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Sat, 12 Aug 2017 16:20:45 +0200 Subject: [PATCH 2/4] Add support for serialising namespaced Cura settings in XML materials --- plugins/XmlMaterialProfile/XmlMaterialProfile.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 32d998e1af..a814776cef 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -635,14 +635,21 @@ class XmlMaterialProfile(InstanceContainer): ContainerRegistry.getInstance().addContainer(new_hotend_material) def _addSettingElement(self, builder, instance): - try: + key = instance.definition.key + if key in self.__material_settings_setting_map.values(): + # Setting has a key in the stabndard namespace key = UM.Dictionary.findKey(self.__material_settings_setting_map, instance.definition.key) - except ValueError: + tag_name = "setting" + elif key not in self.__material_properties_setting_map.values() and key not in self.__material_metadata_setting_map.values(): + # Setting is not in the standard namespace, and not a material property (eg diameter) or metadata (eg GUID) + tag_name = "cura:setting" + else: + # Skip material properties (eg diameter) or metadata (eg GUID) return - builder.start("setting", { "key": key }) + builder.start(tag_name, { "key": key }) builder.data(str(instance.value)) - builder.end("setting") + builder.end(tag_name) def _profile_name(self, material_name, color_name): if color_name != "Generic": From a65edda6be087a6dabb0b860c7607cd0990fb505 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 18 Dec 2017 12:50:46 +0100 Subject: [PATCH 3/4] Fix merge error --- plugins/XmlMaterialProfile/XmlMaterialProfile.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index e590c30666..03fc3b5521 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -617,6 +617,12 @@ class XmlMaterialProfile(InstanceContainer): else: Logger.log("d", "Unsupported material setting %s", key) + # Add namespaced Cura-specific settings + settings = hotend.iterfind("./cura:setting", self.__namespaces) + for entry in settings: + key = entry.get("key") + hotend_setting_values[key] = entry.text + new_hotend_id = self.getId() + "_" + machine_id + "_" + hotend_id.replace(" ", "_") # Same as machine compatibility, keep the derived material containers consistent with the parent @@ -638,14 +644,6 @@ class XmlMaterialProfile(InstanceContainer): new_hotend_material.getMetaData()["machine_manufacturer"] = machine_manufacturer new_hotend_material.getMetaData()["definition"] = machine_id - # Add namespaced Cura-specific settings - settings = hotend.iterfind("./cura:setting", self.__namespaces) - for entry in settings: - key = entry.get("key") - hotend_setting_values[key] = entry.text - - new_hotend_id = self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_") - cached_hotend_setting_properties = cached_machine_setting_properties.copy() cached_hotend_setting_properties.update(hotend_setting_values) From e7ca4f327e4e8720a049f288b3035c61aa71132e Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Thu, 22 Mar 2018 16:55:12 +0100 Subject: [PATCH 4/4] Fix reading and writing yes/no as boolean values --- .../XmlMaterialProfile/XmlMaterialProfile.py | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 5f4f765f77..c51ef97bf0 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -566,8 +566,13 @@ class XmlMaterialProfile(InstanceContainer): # Add namespaced Cura-specific settings settings = data.iterfind("./um:settings/cura:setting", self.__namespaces) for entry in settings: + value = entry.text + if value.lower() == "yes": + value = True + elif value.lower() == "no": + value = False key = entry.get("key") - common_setting_values[key] = entry.text + common_setting_values[key] = value self._cached_values = common_setting_values # from InstanceContainer ancestor @@ -596,8 +601,13 @@ class XmlMaterialProfile(InstanceContainer): # Add namespaced Cura-specific settings settings = machine.iterfind("./cura:setting", self.__namespaces) for entry in settings: + value = entry.text + if value.lower() == "yes": + value = True + elif value.lower() == "no": + value = False key = entry.get("key") - machine_setting_values[key] = entry.text + machine_setting_values[key] = value cached_machine_setting_properties = common_setting_values.copy() cached_machine_setting_properties.update(machine_setting_values) @@ -708,8 +718,13 @@ class XmlMaterialProfile(InstanceContainer): # Add namespaced Cura-specific settings settings = hotend.iterfind("./cura:setting", self.__namespaces) for entry in settings: + value = entry.text + if value.lower() == "yes": + value = True + elif value.lower() == "no": + value = False key = entry.get("key") - hotend_setting_values[key] = entry.text + hotend_setting_values[key] = value new_hotend_specific_material_id = self.getId() + "_" + machine_id + "_" + hotend_name.replace(" ", "_") @@ -944,8 +959,15 @@ class XmlMaterialProfile(InstanceContainer): # Skip material properties (eg diameter) or metadata (eg GUID) return + if instance.value is True: + data = "yes" + elif instance.value is False: + data = "no" + else: + data = str(instance.value) + builder.start(tag_name, { "key": key }) - builder.data(str(instance.value)) + builder.data(data) builder.end(tag_name) @classmethod