summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-07-27 20:26:18 -0400
committerLex Neva <github.com@lexneva.name>2018-07-27 20:26:18 -0400
commitcdb8fdb1339476e36ad2e294283eec33d13b2d3d (patch)
tree62a8296f7200484dd54ed301edc05f6a124f72bc
parentd14880db5820ce2175bda7bbe761c21fd6c454d0 (diff)
add bean stitch option
-rw-r--r--lib/elements/stroke.py21
-rw-r--r--lib/stitches/running_stitch.py29
-rw-r--r--messages.po23
3 files changed, 62 insertions, 11 deletions
diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py
index e8eb4783..e086ccd9 100644
--- a/lib/elements/stroke.py
+++ b/lib/elements/stroke.py
@@ -4,7 +4,7 @@ import shapely.geometry
from .element import param, EmbroideryElement, Patch
from ..i18n import _
from ..utils import cache, Point
-from ..stitches import running_stitch
+from ..stitches import running_stitch, bean_stitch
from ..svg import parse_length_with_units
warned_about_legacy_running_stitch = False
@@ -27,18 +27,28 @@ class Stroke(EmbroideryElement):
return self.get_style("stroke-dasharray") is not None
@property
- @param('running_stitch_length_mm', _('Running stitch length'), unit='mm', type='float', default=1.5)
+ @param('running_stitch_length_mm', _('Running stitch length'), unit='mm', type='float', default=1.5, sort_index=3)
def running_stitch_length(self):
return max(self.get_float_param("running_stitch_length_mm", 1.5), 0.01)
@property
- @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), unit='mm', type='float', default=0.4)
+ @param('bean_stitch_repeats',
+ _('Bean stitch number of repeats'),
+ tooltip=_('Backtrack each stitch this many times. A value of 1 would triple each stitch (forward, back, forward). A value of 2 would quintuple each stitch, etc. Only applies to running stitch.'),
+ type='int',
+ default=0,
+ sort_index=2)
+ def bean_stitch_repeats(self):
+ return self.get_int_param("bean_stitch_repeats", 0)
+
+ @property
+ @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), unit='mm', type='float', default=0.4, sort_index=3)
@cache
def zigzag_spacing(self):
return max(self.get_float_param("zigzag_spacing_mm", 0.4), 0.01)
@property
- @param('repeats', _('Repeats'), type='int', default="1")
+ @param('repeats', _('Repeats'), type='int', default="1", sort_index=1)
def repeats(self):
return self.get_int_param("repeats", 1)
@@ -58,7 +68,7 @@ class Stroke(EmbroideryElement):
return shapely.geometry.MultiLineString(line_strings)
@property
- @param('manual_stitch', _('Manual stitch placement'), tooltip=_("Stitch every node in the path. Stitch length and zig-zag spacing are ignored."), type='boolean', default=False)
+ @param('manual_stitch', _('Manual stitch placement'), tooltip=_("Stitch every node in the path. Stitch length and zig-zag spacing are ignored."), type='boolean', default=False, sort_index=0)
def manual_stitch_mode(self):
return self.get_boolean_param('manual_stitch')
@@ -139,6 +149,7 @@ class Stroke(EmbroideryElement):
repeated_path.extend(this_path)
stitches = running_stitch(repeated_path, stitch_length)
+ stitches = bean_stitch(stitches, self.bean_stitch_repeats)
return Patch(self.color, stitches)
diff --git a/lib/stitches/running_stitch.py b/lib/stitches/running_stitch.py
index 96075e7a..5f8ed21e 100644
--- a/lib/stitches/running_stitch.py
+++ b/lib/stitches/running_stitch.py
@@ -1,3 +1,6 @@
+from copy import copy
+
+
""" Utility functions to produce running stitches. """
@@ -64,3 +67,29 @@ def running_stitch(points, stitch_length):
output.append(segment_start)
return output
+
+
+def bean_stitch(stitches, repeats):
+ """Generate bean stitch from a set of stitches.
+
+ "Bean" stitch is made by backtracking each stitch to make it heaver. A
+ simple bean stitch would be two stitches forward, one stitch back, two
+ stitches forward, etc. This would result in each stitch being tripled.
+
+ We'll say that the above counts as 1 repeat. Backtracking each stitch
+ repeatedly will result in a heavier bean stitch. There will always be
+ an odd number of threads piled up for each stitch.
+ """
+
+ if len(stitches) < 2:
+ return stitches
+
+ new_stitches = [stitches[0]]
+
+ for stitch in stitches:
+ new_stitches.append(stitch)
+
+ for i in xrange(repeats):
+ new_stitches.extend(copy(new_stitches[-2:]))
+
+ return new_stitches
diff --git a/messages.po b/messages.po
index 19400443..1e3413fd 100644
--- a/messages.po
+++ b/messages.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2018-07-25 21:18-0400\n"
+"POT-Creation-Date: 2018-07-27 20:26-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -100,7 +100,7 @@ msgstr ""
msgid "Custom satin column"
msgstr ""
-#: lib/elements/satin_column.py:25 lib/elements/stroke.py:35
+#: lib/elements/satin_column.py:25 lib/elements/stroke.py:45
msgid "Zig-zag spacing (peak-to-peak)"
msgstr ""
@@ -195,21 +195,32 @@ msgstr ""
msgid "Running stitch length"
msgstr ""
-#: lib/elements/stroke.py:41
+#: lib/elements/stroke.py:36
+msgid "Bean stitch number of repeats"
+msgstr ""
+
+#: lib/elements/stroke.py:37
+msgid ""
+"Backtrack each stitch this many times. A value of 1 would triple each "
+"stitch (forward, back, forward). A value of 2 would quintuple each "
+"stitch, etc. Only applies to running stitch."
+msgstr ""
+
+#: lib/elements/stroke.py:51
msgid "Repeats"
msgstr ""
-#: lib/elements/stroke.py:61
+#: lib/elements/stroke.py:71
msgid "Manual stitch placement"
msgstr ""
-#: lib/elements/stroke.py:61
+#: lib/elements/stroke.py:71
msgid ""
"Stitch every node in the path. Stitch length and zig-zag spacing are "
"ignored."
msgstr ""
-#: lib/elements/stroke.py:92
+#: lib/elements/stroke.py:102
msgid ""
"Legacy running stitch setting detected!\n"
"\n"