2016-11-03 03:17:36 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Update embroidery parameters stored in XML attributes from old to new
|
|
|
|
# format.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.append("/usr/share/inkscape/extensions")
|
|
|
|
import os
|
|
|
|
import inkex
|
2016-11-07 00:28:17 +00:00
|
|
|
import simplestyle
|
2016-11-03 03:17:36 +00:00
|
|
|
|
|
|
|
PIXELS_PER_MM = 10
|
|
|
|
|
2016-11-07 00:30:49 +00:00
|
|
|
|
2016-11-03 03:17:36 +00:00
|
|
|
class EmbroiderParams(inkex.Effect):
|
2016-11-07 00:30:49 +00:00
|
|
|
|
2016-11-03 03:17:36 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
inkex.Effect.__init__(self)
|
|
|
|
|
2016-11-07 00:30:49 +00:00
|
|
|
self.mapping = {"zigzag_spacing": "zigzag_spacing_mm",
|
|
|
|
"row_spacing": "row_spacing_mm",
|
|
|
|
"pull_compensation": "pull_compensation_mm",
|
|
|
|
"max_stitch_length": "max_stitch_length_mm",
|
|
|
|
"satin_underlay": "contour_underlay",
|
|
|
|
"satin_underlay_inset": "contour_underlay_inset_mm",
|
|
|
|
"satin_zigzag_underlay_spacing": "zigzag_underlay_spacing_mm",
|
|
|
|
"satin_center_walk": "center_walk_underlay",
|
|
|
|
"stitch_length": "running_stitch_length_mm",
|
|
|
|
}
|
|
|
|
|
|
|
|
def effect(self):
|
2016-11-03 03:17:36 +00:00
|
|
|
for node in self.document.getroot().iter():
|
|
|
|
for old, new in self.mapping.iteritems():
|
|
|
|
old = "embroider_%s" % old
|
|
|
|
new = "embroider_%s" % new
|
|
|
|
|
|
|
|
value = node.attrib.pop(old, None)
|
|
|
|
if value:
|
|
|
|
if new.endswith('_mm') and value.strip():
|
|
|
|
value = str(float(value) / PIXELS_PER_MM)
|
|
|
|
|
|
|
|
node.set(new, value)
|
|
|
|
|
|
|
|
if 'embroider_zigzag_underlay_spacing_mm' in node.attrib:
|
|
|
|
node.set('embroider_zigzag_underlay', 'yes')
|
|
|
|
|
2016-11-07 00:28:17 +00:00
|
|
|
style = simplestyle.parseStyle(node.get('style'))
|
|
|
|
|
|
|
|
if style.get('fill', 'none') != 'none' and \
|
|
|
|
'embroider_auto_fill' not in node.attrib:
|
2016-11-07 00:30:49 +00:00
|
|
|
node.set('embroider_auto_fill', 'no')
|
2016-11-07 00:28:17 +00:00
|
|
|
|
2016-11-03 03:17:36 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
e = EmbroiderParams()
|
|
|
|
e.affect()
|