From 038875f876d79d0f1e971886fe42f5bee4f9f31e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 21 Aug 2018 20:32:50 -0400 Subject: autopep8 --- lib/output.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lib/output.py') diff --git a/lib/output.py b/lib/output.py index 0d7f9918..eed665ed 100644 --- a/lib/output.py +++ b/lib/output.py @@ -19,6 +19,7 @@ def get_command(stitch): else: return pyembroidery.NEEDLE_AT + def _string_to_floats(string): floats = string.split(',') return [float(num) for num in floats] @@ -32,7 +33,7 @@ def get_origin(svg): 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 guide.get(label_attribute, "").startswith("embroidery origin")] # document size used below doc_size = list(get_doc_size(svg)) @@ -57,7 +58,6 @@ def get_origin(svg): 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')) @@ -98,17 +98,17 @@ def write_embroidery_file(file_path, stitch_plan, svg): # also multiply by 10 to get tenths of a millimeter as required by pyembroidery scale = 10 / PIXELS_PER_MM - settings = { - # correct for the origin - "translate": -origin, + settings = { + # correct for the origin + "translate": -origin, - # convert from pixels to millimeters - # also multiply by 10 to get tenths of a millimeter as required by pyembroidery - "scale": (scale, scale), + # convert from pixels to millimeters + # also multiply by 10 to get tenths of a millimeter as required by pyembroidery + "scale": (scale, scale), - # This forces a jump at the start of the design and after each trim, - # even if we're close enough not to need one. - "full_jump": True, - } + # This forces a jump at the start of the design and after each trim, + # even if we're close enough not to need one. + "full_jump": True, + } pyembroidery.write(pattern, file_path, settings) -- cgit v1.2.3 From a448b2c0ea4e61b28dccd406ffcc5a5ebb96cdd2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 22:13:51 -0400 Subject: add origin command and remove guides method --- lib/output.py | 59 ++++++++++++++--------------------------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) (limited to 'lib/output.py') diff --git a/lib/output.py b/lib/output.py index eed665ed..ae15ce4e 100644 --- a/lib/output.py +++ b/lib/output.py @@ -5,6 +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 def get_command(stitch): @@ -26,57 +27,25 @@ 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_commands = list(global_commands(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_commands: + origin = origin_commands[0].point - # document size used below - 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) - - 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 + return origin + else: + # default: center of the canvas - # 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]) + doc_size = list(get_doc_size(svg)) - # 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))) + # convert the size from viewbox-relative to real-world pixels + viewbox_transform = get_viewbox_transform(svg) + simpletransform.applyTransformToPoint(simpletransform.invertTransform(viewbox_transform), doc_size) - intersection = lines[0].intersection(lines[1]) + default = [doc_size[0] / 2.0, doc_size[1] / 2.0] + simpletransform.applyTransformToPoint(viewbox_transform, default) + default = Point(*default) - 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 -- cgit v1.2.3 From a8ac170e87cf9db1b976ca1a068b67f5a70cc571 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 22:48:40 -0400 Subject: implement stop position --- lib/output.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/output.py') 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) -- cgit v1.2.3 From 7f9208ae2a97026019ff36d28faf37a5c1b9b270 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 23 Aug 2018 21:46:22 -0400 Subject: style fixes --- lib/output.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/output.py') diff --git a/lib/output.py b/lib/output.py index 92f09963..d5c513e2 100644 --- a/lib/output.py +++ b/lib/output.py @@ -1,7 +1,5 @@ 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 -- cgit v1.2.3