From 7dcb253d9b444ffadda389eca0b18280c7f428c4 Mon Sep 17 00:00:00 2001 From: George Steel Date: Sun, 4 Jun 2023 20:26:39 -0400 Subject: Add panelization options to zip export --- lib/extensions/zip.py | 15 +++++++++++++++ lib/stitch_plan/color_block.py | 19 +++++++++++++++++++ lib/stitch_plan/stitch.py | 10 ++++++++++ lib/stitch_plan/stitch_plan.py | 7 +++++++ 4 files changed, 51 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3 From 233340c0e72e96ba4c2b80fe0737c0a13884dcf7 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Sat, 22 Jul 2023 06:43:40 +0200 Subject: zip: add input field for custom file names (#2426) --- lib/extensions/zip.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index 155478f3..65e31b6c 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -27,6 +27,11 @@ class Zip(InkstitchExtension): def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self) + self.arg_parser.add_argument('--notebook', type=Boolean, default=True) + self.arg_parser.add_argument('--file-formats', type=Boolean, default=True) + self.arg_parser.add_argument('--panelization', type=Boolean, default=True) + self.arg_parser.add_argument('--output-options', type=Boolean, default=True) + # it's kind of obnoxious that I have to do this... self.formats = [] for format in pyembroidery.supported_formats(): @@ -35,13 +40,16 @@ class Zip(InkstitchExtension): self.arg_parser.add_argument('--format-%s' % extension, type=Boolean, dest=extension) self.formats.append(extension) self.arg_parser.add_argument('--format-svg', type=Boolean, dest='svg') + self.formats.append('svg') self.arg_parser.add_argument('--format-threadlist', type=Boolean, dest='threadlist') + self.formats.append('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') + + self.arg_parser.add_argument('--custom-file-name', type=str, dest='custom_file_name', default='') def effect(self): if not self.get_elements(): @@ -54,15 +62,9 @@ class Zip(InkstitchExtension): 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() + stitch_plan = self._make_offsets(stitch_plan) + + base_file_name = self._get_file_name() path = tempfile.mkdtemp() files = [] @@ -108,6 +110,22 @@ class Zip(InkstitchExtension): # don't let inkex output the SVG! sys.exit(0) + def _get_file_name(self): + if self.options.custom_file_name: + base_file_name = self.options.custom_file_name + else: + base_file_name = self.get_base_file_name() + return base_file_name + + def _make_offsets(self, stitch_plan): + 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)) + return stitch_plan.make_offsets(offsets) + def get_threadlist(self, stitch_plan, design_name): ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette']) thread_used = [] -- cgit v1.2.3 From 15ee5c458ba5cf3abfe2162d8eb4e8e1d13c6f91 Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Sat, 22 Jul 2023 06:46:50 +0200 Subject: sort imports --- lib/stitch_plan/color_block.py | 4 ++-- lib/stitch_plan/stitch_plan.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/stitch_plan/color_block.py b/lib/stitch_plan/color_block.py index a888dc80..fdef5eb8 100644 --- a/lib/stitch_plan/color_block.py +++ b/lib/stitch_plan/color_block.py @@ -5,10 +5,10 @@ from typing import List -from .stitch import Stitch +from ..svg import PIXELS_PER_MM from ..threads import ThreadColor from ..utils.geometry import Point -from ..svg import PIXELS_PER_MM +from .stitch import Stitch class ColorBlock(object): diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index b9ce902a..caea9c09 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -10,9 +10,9 @@ from inkex import errormsg 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 +from ..utils.threading import check_stop_flag +from .color_block import ColorBlock def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_len=0.1, disable_ties=False): # noqa: C901 -- cgit v1.2.3 From 160284d21dcadddfb5e4b22dc2f71073d012b96c Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Sat, 22 Jul 2023 06:48:37 +0200 Subject: sort more imports --- lib/extensions/zip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index 65e31b6c..b3183a9a 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -9,16 +9,16 @@ import tempfile from copy import deepcopy from zipfile import ZipFile +from inkex import Boolean from lxml import etree import pyembroidery -from inkex import Boolean 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 ..threads import ThreadCatalog from ..utils.geometry import Point from .base import InkstitchExtension -- cgit v1.2.3