diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/apply_threadlist.py | 30 | ||||
| -rw-r--r-- | lib/extensions/cutwork_segmentation.py | 1 | ||||
| -rw-r--r-- | lib/extensions/jump_to_stroke.py | 10 |
3 files changed, 28 insertions, 13 deletions
diff --git a/lib/extensions/apply_threadlist.py b/lib/extensions/apply_threadlist.py index 2779a901..e17b4a3c 100644 --- a/lib/extensions/apply_threadlist.py +++ b/lib/extensions/apply_threadlist.py @@ -8,9 +8,11 @@ import re import sys import inkex + import pyembroidery from ..i18n import _ +from ..svg.tags import INKSTITCH_ATTRIBS from ..threads import ThreadCatalog from .base import InkstitchExtension @@ -41,6 +43,7 @@ class ApplyThreadlist(InkstitchExtension): method = self.options.method + # colors: [[color, cutwork_needle],[...]] if path.endswith(('col', 'inf', 'edr')): colors = self.parse_color_format(path) elif method == 1: @@ -62,9 +65,13 @@ class ApplyThreadlist(InkstitchExtension): if i == len(colors): break - style = element.node.get('style').replace("%s" % element_color, "%s" % colors[i]) + style = element.node.get('style').replace("%s" % element_color, "%s" % colors[i][0]) element.node.set('style', style) + # apply cutwork + if colors[i][1] is not None: + element.node.set(INKSTITCH_ATTRIBS['cutwork_needle'], colors[i][1]) + def verify_path(self, path): if not os.path.exists(path): inkex.errormsg(_("File not found.")) @@ -89,17 +96,21 @@ class ApplyThreadlist(InkstitchExtension): if line[0].isdigit(): m = re.search(r"\((#[0-9A-Fa-f]{6})\)", line) if m: - colors.append(m.group(1)) + colors.append([m.group(1), None]) else: # Color not found - colors.append(None) + colors.append([None, None]) return colors def parse_color_format(self, path): colors = [] threads = pyembroidery.read(path).threadlist for color in threads: - colors.append(color.hex_color()) + if color.description.startswith("Cut"): + # there is a maximum of 4 needles, we can simply take the last element from the description string + colors.append([color.hex_color(), color.description[-1]]) + else: + colors.append([color.hex_color(), None]) return colors def parse_threadlist_by_catalog_number(self, path): @@ -116,19 +127,14 @@ class ApplyThreadlist(InkstitchExtension): with open(path) as threadlist: for line in threadlist: if line[0].isdigit(): - # some threadlists may add a # in front of the catalof number + # some threadlists may add a # in front of the catalog number # let's remove it from the entire string before splitting it up thread = line.replace('#', '').split() catalog_number = set(thread[1:]).intersection(palette_numbers) if catalog_number: color_index = palette_numbers.index(next(iter(catalog_number))) - colors.append(palette_colors[color_index]) + colors.append([palette_colors[color_index], None]) else: # No color found - colors.append(None) + colors.append([None, None]) return colors - - def find_elements(self, xpath): - svg = self.document.getroot() - elements = svg.xpath(xpath, namespaces=inkex.NSS) - return elements diff --git a/lib/extensions/cutwork_segmentation.py b/lib/extensions/cutwork_segmentation.py index 22b39e4b..537cfadf 100644 --- a/lib/extensions/cutwork_segmentation.py +++ b/lib/extensions/cutwork_segmentation.py @@ -147,6 +147,7 @@ class CutworkSegmentation(InkstitchExtension): "transform": get_correction_transform(element.node), INKSTITCH_ATTRIBS["ties"]: "3", INKSTITCH_ATTRIBS["running_stitch_length_mm"]: "1", + INKSTITCH_ATTRIBS["cutwork_needle"]: str(sector['id']), "d": d }) self.new_elements.append([stroke_element, sector['id']]) diff --git a/lib/extensions/jump_to_stroke.py b/lib/extensions/jump_to_stroke.py index 7cf6ff17..ce29a928 100644 --- a/lib/extensions/jump_to_stroke.py +++ b/lib/extensions/jump_to_stroke.py @@ -1,12 +1,13 @@ # Authors: see git history # -# Copyright (c) 2010 Authors +# Copyright (c) 2023 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from inkex import DirectedLineSegment, PathElement, errormsg from ..i18n import _ from ..svg import PIXELS_PER_MM, get_correction_transform +from ..svg.tags import INKSTITCH_ATTRIBS from .base import InkstitchExtension @@ -14,6 +15,11 @@ class JumpToStroke(InkstitchExtension): """Adds a running stitch as a connection between two (or more) selected elements. The elements must have the same color and a minimum distance (collapse_len).""" + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("-l", "--stitch-length", type=float, default=2.5, dest="running_stitch_length_mm") + self.arg_parser.add_argument("-t", "--tolerance", type=float, default=2.0, dest="running_stitch_tolerance_mm") + def effect(self): if not self.svg.selection or not self.get_elements() or len(self.elements) < 2: errormsg(_("Please select at least two elements to convert the jump stitch to a running stitch.")) @@ -49,6 +55,8 @@ class JumpToStroke(InkstitchExtension): style = f'stroke:{color};stroke-width:1px;stroke-dasharray:3, 1;fill:none;' line = PathElement(d=path, style=style, transform=get_correction_transform(node)) + line.set(INKSTITCH_ATTRIBS['running_stitch_length_mm'], self.options.running_stitch_length_mm) + line.set(INKSTITCH_ATTRIBS['running_stitch_tolerance_mm'], self.options.running_stitch_tolerance_mm) parent.insert(index, line) |
