diff --git a/lib/commands.py b/lib/commands.py index 371969902..a9b97b356 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 ae15ce4e3..92f09963f 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) diff --git a/messages.po b/messages.po index 2d082dd5f..367aee234 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-08-24 20:54-0400\n" +"POT-Creation-Date: 2018-08-24 20:56-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,40 +18,94 @@ msgstr "" "Generated-By: Babel 2.5.3\n" #. command attached to an object -#: lib/commands.py:12 +#: lib/commands.py:13 +msgid "fill_start" +msgstr "" + +#: lib/commands.py:13 msgid "Fill stitch starting position" msgstr "" #. command attached to an object -#: lib/commands.py:15 +#: lib/commands.py:16 +msgid "fill_end" +msgstr "" + +#: lib/commands.py:16 msgid "Fill stitch ending position" msgstr "" #. command attached to an object -#: lib/commands.py:18 +#: lib/commands.py:19 +msgid "stop" +msgstr "" + +#: lib/commands.py:19 msgid "Stop (pause machine) after sewing this object" msgstr "" #. command attached to an object -#: lib/commands.py:21 +#: lib/commands.py:22 +msgid "trim" +msgstr "" + +#: lib/commands.py:22 msgid "Trim thread after sewing this object" msgstr "" #. command attached to an object -#: lib/commands.py:24 +#: lib/commands.py:25 +msgid "ignore_object" +msgstr "" + +#: lib/commands.py:25 msgid "Ignore this object (do not stitch)" msgstr "" #. command that affects a layer -#: lib/commands.py:27 +#: lib/commands.py:28 +msgid "ignore_layer" +msgstr "" + +#: lib/commands.py:28 msgid "Ignore layer (do not stitch any objects in this layer)" msgstr "" #. command that affects entire document -#: lib/commands.py:30 +#: lib/commands.py:31 +msgid "origin" +msgstr "" + +#: lib/commands.py:31 msgid "Origin for exported embroidery files" msgstr "" +#. command that affects entire document +#: lib/commands.py:34 +msgid "stop_point" +msgstr "" + +#: lib/commands.py:34 +msgid "Jump destination for Stop commands (a.k.a. \"Frame Out position\")." +msgstr "" + +#: lib/commands.py:188 +#, python-format +msgid "" +"Error: there is more than one %(command)s command in the document, but " +"there can only be one. Please remove all but one." +msgstr "" + +#. 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. +#: lib/commands.py:195 +#, python-format +msgid "%(command)s: %(description)s" +msgstr "" + #: lib/elements/auto_fill.py:11 msgid "Auto-Fill" msgstr ""