diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-08-24 21:05:59 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-24 21:05:59 -0400 |
| commit | 6f425f7b3e602e2356ebaba2a5d3b240729c5396 (patch) | |
| tree | 7e29f10f13d63a539b4814a14fecf946ea798f92 /lib/output.py | |
| parent | 1de8487849a3f8f55d126e2687d690226e657fde (diff) | |
| parent | 77177f9b55f57d1373408b3dc619a53fe45d00ce (diff) | |
Merge pull request #293 from inkstitch/lexelby/origin-and-stop-position
origin and stop position
Diffstat (limited to 'lib/output.py')
| -rw-r--r-- | lib/output.py | 65 |
1 files changed, 19 insertions, 46 deletions
diff --git a/lib/output.py b/lib/output.py index eed665ed..d5c513e2 100644 --- a/lib/output.py +++ b/lib/output.py @@ -1,10 +1,9 @@ import pyembroidery -import inkex import simpletransform -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_command def get_command(stitch): @@ -26,58 +25,30 @@ def _string_to_floats(string): def get_origin(svg): - # The user can specify the embroidery origin by defining two guides - # named "embroidery origin" that intersect. + origin_command = global_command(svg, "origin") - namedview = svg.find(inkex.addNS('namedview', 'sodipodi')) - all_guides = namedview.findall(inkex.addNS('guide', 'sodipodi')) - label_attribute = inkex.addNS('label', 'inkscape') - guides = [guide for guide in all_guides - if guide.get(label_attribute, "").startswith("embroidery origin")] + if origin_command: + return origin_command.point + else: + # default: center of the canvas - # document size used below - doc_size = list(get_doc_size(svg)) + doc_size = list(get_doc_size(svg)) - # convert the size from viewbox-relative to real-world pixels - viewbox_transform = get_viewbox_transform(svg) - simpletransform.applyTransformToPoint(simpletransform.invertTransform(viewbox_transform), doc_size) + # convert the size from viewbox-relative to real-world pixels + viewbox_transform = get_viewbox_transform(svg) + simpletransform.applyTransformToPoint(simpletransform.invertTransform(viewbox_transform), doc_size) - default = [doc_size[0] / 2.0, doc_size[1] / 2.0] - simpletransform.applyTransformToPoint(viewbox_transform, default) - default = Point(*default) + default = [doc_size[0] / 2.0, doc_size[1] / 2.0] + simpletransform.applyTransformToPoint(viewbox_transform, default) + default = Point(*default) - if len(guides) < 2: return default - # Find out where the guides intersect. Only pay attention to the first two. - guides = guides[:2] - - lines = [] - for guide in guides: - # inkscape's Y axis is reversed from SVG's, and the guide is in inkscape coordinates - position = Point(*_string_to_floats(guide.get('position'))) - position.y = doc_size[1] - position.y - - # This one baffles me. I think inkscape might have gotten the order of - # their vector wrong? - parts = _string_to_floats(guide.get('orientation')) - direction = Point(parts[1], parts[0]) - - # We have a theoretically infinite line defined by a point on the line - # and a vector direction. Shapely can only deal in concrete line - # segments, so we'll pick points really far in either direction on the - # line and call it good enough. - lines.append(shgeo.LineString((position + 100000 * direction, position - 100000 * direction))) - intersection = lines[0].intersection(lines[1]) - - if isinstance(intersection, shgeo.Point): - origin = [intersection.x, intersection.y] - simpletransform.applyTransformToPoint(viewbox_transform, origin) - return Point(*origin) - else: - # Either the two guides are the same line, or they're parallel. - 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): @@ -89,6 +60,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) |
