summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-08-22 22:48:40 -0400
committerLex Neva <github.com@lexneva.name>2018-08-24 20:56:20 -0400
commita8ac170e87cf9db1b976ca1a068b67f5a70cc571 (patch)
tree48cef8f714f6a4749b4df1d25a028f2a0040693b /lib
parentf8a9400fae2f485ab29c153eb017b23d66609503 (diff)
implement stop position
Diffstat (limited to 'lib')
-rw-r--r--lib/commands.py45
-rw-r--r--lib/output.py18
2 files changed, 49 insertions, 14 deletions
diff --git a/lib/commands.py b/lib/commands.py
index 37196990..a9b97b35 100644
--- a/lib/commands.py
+++ b/lib/commands.py
@@ -1,3 +1,4 @@
+import sys
import inkex
import cubicsuperpath
import simpletransform
@@ -9,25 +10,28 @@ from .i18n import _, N_
COMMANDS = {
# L10N command attached to an object
- "fill_start": N_("Fill stitch starting position"),
+ N_("fill_start"): N_("Fill stitch starting position"),
# L10N command attached to an object
- "fill_end": N_("Fill stitch ending position"),
+ N_("fill_end"): N_("Fill stitch ending position"),
# L10N command attached to an object
- "stop": N_("Stop (pause machine) after sewing this object"),
+ N_("stop"): N_("Stop (pause machine) after sewing this object"),
# L10N command attached to an object
- "trim": N_("Trim thread after sewing this object"),
+ N_("trim"): N_("Trim thread after sewing this object"),
# L10N command attached to an object
- "ignore_object": N_("Ignore this object (do not stitch)"),
+ N_("ignore_object"): N_("Ignore this object (do not stitch)"),
# L10N command that affects a layer
- "ignore_layer": N_("Ignore layer (do not stitch any objects in this layer)"),
+ N_("ignore_layer"): N_("Ignore layer (do not stitch any objects in this layer)"),
# L10N command that affects entire document
- "origin": N_("Origin for exported embroidery files"),
+ N_("origin"): N_("Origin for exported embroidery files"),
+
+ # L10N command that affects entire document
+ N_("stop_point"): N_("Jump destination for Stop commands (a.k.a. \"Frame Out position\")."),
}
OBJECT_COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"]
@@ -132,7 +136,7 @@ class StandaloneCommand(BaseCommand):
def get_command_description(command):
- return _(COMMANDS[command])
+ return COMMANDS[command]
def find_commands(node):
@@ -169,6 +173,31 @@ def global_commands(svg, command):
if standalone_command.command == command:
yield standalone_command
+@cache
+def global_command(svg, command):
+ """Find a single command of the specified type.
+
+ If more than one is found, print an error and exit.
+ """
+
+ commands = list(global_commands(svg, command))
+
+ if len(commands) == 1:
+ return commands[0]
+ elif len(commands) > 1:
+ print >> sys.stderr, _("Error: there is more than one %(command)s command in the document, but there can only be one. "
+ "Please remove all but one.") % dict(command=command)
+
+ # L10N This is a continuation of the previous error message, letting the user know
+ # what command we're talking about since we don't normally expose the actual
+ # command name to them. Contents of %(description)s are in a separate translation
+ # string.
+ print >> sys.stderr, _("%(command)s: %(description)s") % dict(command=command, description=_(get_command_description(command)))
+
+ sys.exit(1)
+ else:
+ return None
+
def _standalone_commands(svg):
"""Find all unconnected command symbols in the SVG."""
diff --git a/lib/output.py b/lib/output.py
index ae15ce4e..92f09963 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -5,7 +5,7 @@ import shapely.geometry as shgeo
from .utils import Point
from .svg import PIXELS_PER_MM, get_doc_size, get_viewbox_transform
-from .commands import global_commands
+from .commands import global_command
def get_command(stitch):
@@ -27,12 +27,10 @@ def _string_to_floats(string):
def get_origin(svg):
- origin_commands = list(global_commands(svg, "origin"))
+ origin_command = global_command(svg, "origin")
- if origin_commands:
- origin = origin_commands[0].point
-
- return origin
+ if origin_command:
+ return origin_command.point
else:
# default: center of the canvas
@@ -49,6 +47,12 @@ def get_origin(svg):
return default
+def jump_to_stop_point(pattern, svg):
+ stop_position = global_command(svg, "stop_position")
+ if stop_position:
+ pattern.add_stitch_absolute(pyembroidery.JUMP, stop_position.point.x, stop_position.point.y)
+
+
def write_embroidery_file(file_path, stitch_plan, svg):
origin = get_origin(svg)
@@ -58,6 +62,8 @@ def write_embroidery_file(file_path, stitch_plan, svg):
pattern.add_thread(color_block.color.pyembroidery_thread)
for stitch in color_block:
+ if stitch.stop:
+ jump_to_stop_point(pattern, svg)
command = get_command(stitch)
pattern.add_stitch_absolute(command, stitch.x, stitch.y)