diff options
| author | George Steel <george.steel@gmail.com> | 2023-06-04 20:26:39 -0400 |
|---|---|---|
| committer | George Steel <george.steel@gmail.com> | 2023-06-15 12:25:15 -0400 |
| commit | 7dcb253d9b444ffadda389eca0b18280c7f428c4 (patch) | |
| tree | f654ff1594305092ab46b920e2a72a12a283d50c | |
| parent | 92623d460d82f01c01353a5a5c992ec53baf7f41 (diff) | |
Add panelization options to zip export
| -rw-r--r-- | lib/extensions/zip.py | 15 | ||||
| -rw-r--r-- | lib/stitch_plan/color_block.py | 19 | ||||
| -rw-r--r-- | lib/stitch_plan/stitch.py | 10 | ||||
| -rw-r--r-- | lib/stitch_plan/stitch_plan.py | 7 | ||||
| -rw-r--r-- | templates/zip.xml | 13 |
5 files changed, 63 insertions, 1 deletions
diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index e80bc34c..155478f3 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -18,6 +18,8 @@ from ..i18n import _ from ..output import write_embroidery_file from ..stitch_plan import stitch_groups_to_stitch_plan from ..threads import ThreadCatalog +from ..svg import PIXELS_PER_MM +from ..utils.geometry import Point from .base import InkstitchExtension @@ -34,6 +36,10 @@ class Zip(InkstitchExtension): self.formats.append(extension) self.arg_parser.add_argument('--format-svg', type=Boolean, dest='svg') self.arg_parser.add_argument('--format-threadlist', type=Boolean, dest='threadlist') + self.arg_parser.add_argument('--x-repeats', type=int, dest='x_repeats', default=1) + self.arg_parser.add_argument('--y-repeats', type=int, dest='y_repeats', default=1) + self.arg_parser.add_argument('--x-spacing', type=float, dest='x_spacing', default=100) + self.arg_parser.add_argument('--y-spacing', type=float, dest='y_spacing', default=100) self.formats.append('svg') self.formats.append('threadlist') @@ -47,6 +53,15 @@ class Zip(InkstitchExtension): patches = self.elements_to_stitch_groups(self.elements) stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) + if self.options.x_repeats != 1 or self.options.y_repeats != 1: + dx = self.options.x_spacing * PIXELS_PER_MM + dy = self.options.y_spacing * PIXELS_PER_MM + offsets = [] + for x in range(self.options.x_repeats): + for y in range(self.options.y_repeats): + offsets.append(Point(x * dx, y * dy)) + stitch_plan = stitch_plan.make_offsets(offsets) + base_file_name = self.get_base_file_name() path = tempfile.mkdtemp() diff --git a/lib/stitch_plan/color_block.py b/lib/stitch_plan/color_block.py index 9d474f80..a888dc80 100644 --- a/lib/stitch_plan/color_block.py +++ b/lib/stitch_plan/color_block.py @@ -3,6 +3,8 @@ # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. +from typing import List + from .stitch import Stitch from ..threads import ThreadColor from ..utils.geometry import Point @@ -155,3 +157,20 @@ class ColorBlock(object): maxy = max(stitch.y for stitch in self) return minx, miny, maxx, maxy + + def make_offsets(self, offsets: List[Point]): + first_final_stitch = len(self.stitches) + while (first_final_stitch > 0 and self.stitches[first_final_stitch-1].is_terminator): + first_final_stitch -= 1 + if first_final_stitch == 0: + return self + final_stitches = self.stitches[first_final_stitch:] + block_stitches = self.stitches[:first_final_stitch] + + out = ColorBlock(self.color) + for i, offset in enumerate(offsets): + out.add_stitches([s.offset(offset) for s in block_stitches]) + if i != len(offsets) - 1: + out.add_stitch(trim=True) + out.add_stitches(final_stitches) + return out diff --git a/lib/stitch_plan/stitch.py b/lib/stitch_plan/stitch.py index 90af58c0..8ad699c7 100644 --- a/lib/stitch_plan/stitch.py +++ b/lib/stitch_plan/stitch.py @@ -68,6 +68,10 @@ class Stitch(Point): if value or base_stitch is None: setattr(self, attribute, value) + @property + def is_terminator(self) -> bool: + return self.trim or self.stop or self.color_change + def add_tags(self, tags): for tag in tags: self.add_tag(tag) @@ -93,6 +97,12 @@ class Stitch(Point): def copy(self): return Stitch(self.x, self.y, self.color, self.jump, self.stop, self.trim, self.color_change, self.tags) + def offset(self, offset: Point): + out = self.copy() + out.x += offset.x + out.y += offset.y + return out + def __json__(self): attributes = dict(vars(self)) attributes['tags'] = list(attributes['tags']) diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index 25571578..b9ce902a 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -4,6 +4,7 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from sys import exit +from typing import List from inkex import errormsg @@ -11,6 +12,7 @@ from ..i18n import _ from ..svg import PIXELS_PER_MM from .color_block import ColorBlock from ..utils.threading import check_stop_flag +from ..utils.geometry import Point def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_len=0.1, disable_ties=False): # noqa: C901 @@ -207,3 +209,8 @@ class StitchPlan(object): return self.color_blocks[-1] else: return None + + def make_offsets(self, offsets: List[Point]): + out = StitchPlan() + out.color_blocks = [block.make_offsets(offsets) for block in self] + return out diff --git a/templates/zip.xml b/templates/zip.xml index 0018cb19..1eafd662 100644 --- a/templates/zip.xml +++ b/templates/zip.xml @@ -5,17 +5,28 @@ <output> <extension>.zip</extension> <mimetype>application/zip</mimetype> - <filetypename>Ink/Stitch: ZIP export multiple formats (.zip)</filetypename> + <filetypename>Ink/Stitch: ZIP export multiple formats and extra options (.zip)</filetypename> <filetypetooltip>Create a ZIP with multiple embroidery file formats using Ink/Stitch</filetypetooltip> <dataloss>true</dataloss> </output> + <label>Panelization options (defaults to single design):</label> + <param name="x-repeats" type="int" min="1" max="20" gui-text="Horizontal repeats">1</param> + <param name="x-spacing" type="float" min="-1000" max="1000" gui-text="Horizontal spacing (mm)">100</param> + <param name="y-repeats" type="int" min="1" max="20" gui-text="Vertical repeats">1</param> + <param name="y-spacing" type="float" min="-1000" max="1000" gui-text="Vertical spacing (mm)">100</param> + + + <spacer/> + <label>Output formats:</label> {%- for format, description, mimetype, category in formats %} {%- if category != "vector" and category != "debug" %} <param name="format-{{ format }}" type="boolean" _gui-text=".{{ format | upper }}: {{ description }}">false</param> {%- endif %} {%- endfor %} + <param name="format-threadlist" type="boolean" gui-text=".TXT: Threadlist [COLOR]">false</param> <param name="format-svg" type="boolean" gui-text=".SVG: Scalable Vector Graphic">false</param> + <param name="extension" type="string" gui-hidden="true">zip</param> <script> {{ command_tag | safe }} |
