mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 00:05:59 +08:00
Merge pull request #2333 from fieldOfView/feature_xmlmaterials_cura_settings
Cura-specific settings in xmlmaterials
This commit is contained in:
commit
76b837e1cb
@ -126,6 +126,7 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
|
|
||||||
root = builder.start("fdmmaterial",
|
root = builder.start("fdmmaterial",
|
||||||
{"xmlns": "http://www.ultimaker.com/material",
|
{"xmlns": "http://www.ultimaker.com/material",
|
||||||
|
"xmlns:cura": "http://www.ultimaker.com/cura",
|
||||||
"version": self.CurrentFdmMaterialVersion})
|
"version": self.CurrentFdmMaterialVersion})
|
||||||
|
|
||||||
## Begin Metadata Block
|
## Begin Metadata Block
|
||||||
@ -561,6 +562,18 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
elif key in self.__unmapped_settings:
|
elif key in self.__unmapped_settings:
|
||||||
if key == "hardware compatible":
|
if key == "hardware compatible":
|
||||||
common_compatibility = self._parseCompatibleValue(entry.text)
|
common_compatibility = self._parseCompatibleValue(entry.text)
|
||||||
|
|
||||||
|
# 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] = value
|
||||||
|
|
||||||
self._cached_values = common_setting_values # from InstanceContainer ancestor
|
self._cached_values = common_setting_values # from InstanceContainer ancestor
|
||||||
|
|
||||||
meta_data["compatible"] = common_compatibility
|
meta_data["compatible"] = common_compatibility
|
||||||
@ -585,6 +598,17 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
else:
|
else:
|
||||||
Logger.log("d", "Unsupported material setting %s", key)
|
Logger.log("d", "Unsupported material setting %s", key)
|
||||||
|
|
||||||
|
# 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] = value
|
||||||
|
|
||||||
cached_machine_setting_properties = common_setting_values.copy()
|
cached_machine_setting_properties = common_setting_values.copy()
|
||||||
cached_machine_setting_properties.update(machine_setting_values)
|
cached_machine_setting_properties.update(machine_setting_values)
|
||||||
|
|
||||||
@ -691,6 +715,17 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
else:
|
else:
|
||||||
Logger.log("d", "Unsupported material setting %s", key)
|
Logger.log("d", "Unsupported material setting %s", key)
|
||||||
|
|
||||||
|
# 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] = value
|
||||||
|
|
||||||
new_hotend_specific_material_id = self.getId() + "_" + machine_id + "_" + hotend_name.replace(" ", "_")
|
new_hotend_specific_material_id = self.getId() + "_" + machine_id + "_" + hotend_name.replace(" ", "_")
|
||||||
|
|
||||||
# Same as machine compatibility, keep the derived material containers consistent with the parent material
|
# Same as machine compatibility, keep the derived material containers consistent with the parent material
|
||||||
@ -912,14 +947,28 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
return result_metadata
|
return result_metadata
|
||||||
|
|
||||||
def _addSettingElement(self, builder, instance):
|
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)
|
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
|
return
|
||||||
|
|
||||||
builder.start("setting", { "key": key })
|
if instance.value is True:
|
||||||
builder.data(str(instance.value))
|
data = "yes"
|
||||||
builder.end("setting")
|
elif instance.value is False:
|
||||||
|
data = "no"
|
||||||
|
else:
|
||||||
|
data = str(instance.value)
|
||||||
|
|
||||||
|
builder.start(tag_name, { "key": key })
|
||||||
|
builder.data(data)
|
||||||
|
builder.end(tag_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _profile_name(cls, material_name, color_name):
|
def _profile_name(cls, material_name, color_name):
|
||||||
@ -999,7 +1048,8 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
|
|
||||||
# Map of recognised namespaces with a proper prefix.
|
# Map of recognised namespaces with a proper prefix.
|
||||||
__namespaces = {
|
__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
|
## Helper function for pretty-printing XML because ETree is stupid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user