mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-18 04:07:57 -06:00
Add a plugin that loads XML materials and an example material
This commit is contained in:
parent
b452cf7ba4
commit
e0c7ed8561
3 changed files with 164 additions and 0 deletions
84
plugins/XmlMaterialProfile/XmlMaterialProfile.py
Normal file
84
plugins/XmlMaterialProfile/XmlMaterialProfile.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
|
import math
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
import UM.Settings
|
||||||
|
|
||||||
|
def _tag_without_namespace(element):
|
||||||
|
return element.tag[element.tag.rfind("}") + 1:]
|
||||||
|
|
||||||
|
class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
||||||
|
def __init__(self, container_id, *args, **kwargs):
|
||||||
|
super().__init__(container_id, *args, **kwargs)
|
||||||
|
|
||||||
|
def serialize(self):
|
||||||
|
raise NotImplementedError("Writing material profiles has not yet been implemented")
|
||||||
|
|
||||||
|
def deserialize(self, serialized):
|
||||||
|
print("deserialize material profile")
|
||||||
|
data = ET.fromstring(serialized)
|
||||||
|
|
||||||
|
self.addMetaDataEntry("type", "material")
|
||||||
|
|
||||||
|
# TODO: Add material verfication
|
||||||
|
self.addMetaDataEntry("status", "Unknown")
|
||||||
|
|
||||||
|
metadata = data.iterfind("./um:metadata/*", self.__namespaces)
|
||||||
|
for entry in metadata:
|
||||||
|
# The namespace is prepended to the tag name but between {}.
|
||||||
|
# We are only interested in the actual tag name.
|
||||||
|
tag_name = entry.tag[entry.tag.rfind("}") + 1:]
|
||||||
|
|
||||||
|
if tag_name == "name":
|
||||||
|
brand = entry.find("./um:brand", self.__namespaces)
|
||||||
|
material = entry.find("./um:material", self.__namespaces)
|
||||||
|
color = entry.find("./um:color", self.__namespaces)
|
||||||
|
|
||||||
|
self.setName("{0} {1} ({2})".format(brand.text, material.text, color.text))
|
||||||
|
|
||||||
|
self.addMetaDataEntry("brand", brand.text)
|
||||||
|
self.addMetaDataEntry("material", material.text)
|
||||||
|
self.addMetaDataEntry("color_name", color.text)
|
||||||
|
|
||||||
|
self.addMetaDataEntry(tag_name, entry.text)
|
||||||
|
|
||||||
|
property_values = {}
|
||||||
|
properties = data.iterfind("./um:properties/*", self.__namespaces)
|
||||||
|
for entry in properties:
|
||||||
|
tag_name = entry.tag[entry.tag.rfind("}") + 1:]
|
||||||
|
property_values[tag_name] = entry.text
|
||||||
|
|
||||||
|
diameter = float(property_values.get("diameter", 2.85)) # In mm
|
||||||
|
density = float(property_values.get("density", 1.3)) # In g/cm3
|
||||||
|
|
||||||
|
weight_per_cm = (math.pi * (diameter / 20) ** 2 * 0.1) * density
|
||||||
|
|
||||||
|
spool_weight = property_values.get("spool_weight")
|
||||||
|
spool_length = property_values.get("spool_length")
|
||||||
|
if spool_weight:
|
||||||
|
length = float(spool_weight) / weight_per_cm
|
||||||
|
property_values["spool_length"] = str(length / 100)
|
||||||
|
elif spool_length:
|
||||||
|
weight = (float(spool_length) * 100) * weight_per_cm
|
||||||
|
property_values["spool_weight"] = str(weight)
|
||||||
|
|
||||||
|
self.addMetaDataEntry("properties", property_values)
|
||||||
|
|
||||||
|
settings = data.iterfind("./um:settings/um:setting", self.__namespaces)
|
||||||
|
for entry in settings:
|
||||||
|
tag_name = _tag_without_namespace(entry)
|
||||||
|
|
||||||
|
if tag_name in self.__material_property_setting_map:
|
||||||
|
self.setProperty(self.__material_property_setting_map[tag_name], "value", entry.text)
|
||||||
|
|
||||||
|
__material_property_setting_map = {
|
||||||
|
"print temperature": "material_print_temperature",
|
||||||
|
"heated bed temperature": "material_bed_temperature",
|
||||||
|
"standby temperature": "material_standby_temperature",
|
||||||
|
}
|
||||||
|
|
||||||
|
__namespaces = {
|
||||||
|
"um": "http://www.ultimaker.com/material"
|
||||||
|
}
|
32
plugins/XmlMaterialProfile/__init__.py
Normal file
32
plugins/XmlMaterialProfile/__init__.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
|
from . import XmlMaterialProfile
|
||||||
|
|
||||||
|
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
def getMetaData():
|
||||||
|
return {
|
||||||
|
"plugin": {
|
||||||
|
"name": catalog.i18nc("@label", "Material Profiles"),
|
||||||
|
"author": "Ultimaker",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": catalog.i18nc("@info:whatsthis", "Provides capabilities to read and write XML-based material profiles."),
|
||||||
|
"api": 3
|
||||||
|
},
|
||||||
|
"settings_container": {
|
||||||
|
"mimetype": "application/x-ultimaker-material-profile"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def register(app):
|
||||||
|
mime_type = MimeType(
|
||||||
|
name = "application/x-ultimaker-material-profile",
|
||||||
|
comment = "Ultimaker Material Profile",
|
||||||
|
suffixes = [ "xml.fdm_material" ]
|
||||||
|
)
|
||||||
|
MimeTypeDatabase.addMimeType(mime_type)
|
||||||
|
return { "settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile") }
|
||||||
|
|
48
resources/materials/generic_pla.xml.fdm_material
Normal file
48
resources/materials/generic_pla.xml.fdm_material
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Generic PLA profile. Serves as an example file, data in this file is not correct.
|
||||||
|
-->
|
||||||
|
<fdmmaterial xmlns="http://www.ultimaker.com/material">
|
||||||
|
<metadata>
|
||||||
|
<name>
|
||||||
|
<brand>Generic</brand>
|
||||||
|
<material>PLA</material>
|
||||||
|
<color>Generic</color>
|
||||||
|
</name>
|
||||||
|
<GUID>506c9f0d-e3aa-4bd4-b2d2-23e2425b1aa9</GUID>
|
||||||
|
<version>0</version>
|
||||||
|
<color_code>#FFFFFF</color_code>
|
||||||
|
</metadata>
|
||||||
|
<properties>
|
||||||
|
<density>1.3</density>
|
||||||
|
<diameter>2.85</diameter>
|
||||||
|
<spool_weight>750</spool_weight>
|
||||||
|
</properties>
|
||||||
|
<settings>
|
||||||
|
<setting key="print temperature">210</setting>
|
||||||
|
<setting key="heated bed temperature">60</setting>
|
||||||
|
<setting key="standby temperature">175</setting>
|
||||||
|
|
||||||
|
<machine>
|
||||||
|
<machine_identifier manufacturer="Ultimaker" product="Ultimaker2"/>
|
||||||
|
<machine_identifier manufacturer="Ultimaker" product="Ultimaker2go"/>
|
||||||
|
<machine_identifier manufacturer="Ultimaker" product="Ultimaker2extended"/>
|
||||||
|
<setting key="standby temperature">150</setting>
|
||||||
|
<setting key="processing temperature graph">
|
||||||
|
<point flow="2" temperature="180"/>
|
||||||
|
<point flow="10" temperature="230"/>
|
||||||
|
</setting>
|
||||||
|
</machine>
|
||||||
|
|
||||||
|
<machine>
|
||||||
|
<machine_identifier manufacturer="Ultimaker" product="Ultimaker Original"/>
|
||||||
|
<setting key="standby temperature">150</setting>
|
||||||
|
<hotend id="0.8mm">
|
||||||
|
<setting key="standby temperature">80</setting>
|
||||||
|
</hotend>
|
||||||
|
<hotend id="0.6mm">
|
||||||
|
<setting key="standby temperature">100</setting>
|
||||||
|
</hotend>
|
||||||
|
</machine>
|
||||||
|
</settings>
|
||||||
|
</fdmmaterial>
|
Loading…
Add table
Add a link
Reference in a new issue