mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Add some documentation to XmlMaterialProfile
Contributes to CURA-342
This commit is contained in:
parent
eb48a4e768
commit
c9b1c36cc3
1 changed files with 14 additions and 6 deletions
|
@ -13,33 +13,32 @@ import UM.Dictionary
|
||||||
|
|
||||||
import UM.Settings
|
import UM.Settings
|
||||||
|
|
||||||
# The namespace is prepended to the tag name but between {}.
|
## Handles serializing and deserializing material containers from an XML file
|
||||||
# We are only interested in the actual tag name, so discard everything
|
|
||||||
# before the last }
|
|
||||||
def _tag_without_namespace(element):
|
|
||||||
return element.tag[element.tag.rfind("}") + 1:]
|
|
||||||
|
|
||||||
class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
||||||
def __init__(self, container_id, *args, **kwargs):
|
def __init__(self, container_id, *args, **kwargs):
|
||||||
super().__init__(container_id, *args, **kwargs)
|
super().__init__(container_id, *args, **kwargs)
|
||||||
|
|
||||||
|
## Overridden from InstanceContainer
|
||||||
def duplicate(self, new_id, new_name = None):
|
def duplicate(self, new_id, new_name = None):
|
||||||
result = super().duplicate(self.getMetaDataEntry("brand") + "_" + new_id, new_name)
|
result = super().duplicate(self.getMetaDataEntry("brand") + "_" + new_id, new_name)
|
||||||
result.setMetaDataEntry("GUID", str(uuid.uuid4()))
|
result.setMetaDataEntry("GUID", str(uuid.uuid4()))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
## Overridden from InstanceContainer
|
||||||
def setMetaDataEntry(self, key, value):
|
def setMetaDataEntry(self, key, value):
|
||||||
super().setMetaDataEntry(key, value)
|
super().setMetaDataEntry(key, value)
|
||||||
|
|
||||||
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID")):
|
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID")):
|
||||||
container.setMetaData(copy.deepcopy(self._metadata))
|
container.setMetaData(copy.deepcopy(self._metadata))
|
||||||
|
|
||||||
|
## Overridden from InstanceContainer
|
||||||
def setProperty(self, key, property_name, property_value, container = None):
|
def setProperty(self, key, property_name, property_value, container = None):
|
||||||
super().setProperty(key, property_name, property_value)
|
super().setProperty(key, property_name, property_value)
|
||||||
|
|
||||||
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID")):
|
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID")):
|
||||||
container._dirty = True
|
container._dirty = True
|
||||||
|
|
||||||
|
## Overridden from InstanceContainer
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
registry = UM.Settings.ContainerRegistry.getInstance()
|
registry = UM.Settings.ContainerRegistry.getInstance()
|
||||||
|
|
||||||
|
@ -186,6 +185,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
||||||
|
|
||||||
return stream.getvalue()
|
return stream.getvalue()
|
||||||
|
|
||||||
|
## Overridden from InstanceContainer
|
||||||
def deserialize(self, serialized):
|
def deserialize(self, serialized):
|
||||||
data = ET.fromstring(serialized)
|
data = ET.fromstring(serialized)
|
||||||
|
|
||||||
|
@ -359,6 +359,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
||||||
"Ultimaker Original+": "ultimaker_original_plus"
|
"Ultimaker Original+": "ultimaker_original_plus"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Map of recognised namespaces with a proper prefix.
|
||||||
__namespaces = {
|
__namespaces = {
|
||||||
"um": "http://www.ultimaker.com/material"
|
"um": "http://www.ultimaker.com/material"
|
||||||
}
|
}
|
||||||
|
@ -378,3 +379,10 @@ def _indent(elem, level = 0):
|
||||||
else:
|
else:
|
||||||
if level and (not elem.tail or not elem.tail.strip()):
|
if level and (not elem.tail or not elem.tail.strip()):
|
||||||
elem.tail = i
|
elem.tail = i
|
||||||
|
|
||||||
|
|
||||||
|
# The namespace is prepended to the tag name but between {}.
|
||||||
|
# We are only interested in the actual tag name, so discard everything
|
||||||
|
# before the last }
|
||||||
|
def _tag_without_namespace(element):
|
||||||
|
return element.tag[element.tag.rfind("}") + 1:]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue