summaryrefslogtreecommitdiff
path: root/lib/stitch_plan/read_file.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-09-12 20:51:16 -0400
committerLex Neva <github.com@lexneva.name>2018-09-12 20:51:16 -0400
commitd30507171b04f37871db74609c0a521325bddbd1 (patch)
treeac06f38cde84e676f8aa8e91f08b71d45b9f2642 /lib/stitch_plan/read_file.py
parentd398e10b853840261ddf04dc5fca20a05ad74b51 (diff)
parent3fd741a1a4218b6559184aaadcde8abca178bde2 (diff)
Merge remote-tracking branch 'origin/master' into lexelby/bug-fixes
Diffstat (limited to 'lib/stitch_plan/read_file.py')
-rw-r--r--lib/stitch_plan/read_file.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/stitch_plan/read_file.py b/lib/stitch_plan/read_file.py
new file mode 100644
index 00000000..ff5a68ac
--- /dev/null
+++ b/lib/stitch_plan/read_file.py
@@ -0,0 +1,21 @@
+import pyembroidery
+from .stitch_plan import StitchPlan
+
+from ..svg import PIXELS_PER_MM
+
+
+def stitch_plan_from_file(embroidery_file):
+ """Read a machine embroidery file in any supported format and return a stitch plan."""
+ pattern = pyembroidery.read(embroidery_file)
+
+ stitch_plan = StitchPlan()
+ color_block = None
+
+ for raw_stitches, thread in pattern.get_as_colorblocks():
+ color_block = stitch_plan.new_color_block(thread)
+ for x, y, command in raw_stitches:
+ color_block.add_stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0,
+ jump=(command == pyembroidery.JUMP),
+ trim=(command == pyembroidery.TRIM))
+
+ return stitch_plan