diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/elements/auto_fill.py | 18 | ||||
| -rw-r--r-- | lib/elements/fill.py | 21 | ||||
| -rw-r--r-- | lib/extensions/params.py | 18 | ||||
| -rw-r--r-- | lib/stitches/auto_fill.py | 33 | ||||
| -rw-r--r-- | lib/stitches/fill.py | 15 | ||||
| -rw-r--r-- | lib/svg/svg.py | 13 |
6 files changed, 84 insertions, 34 deletions
diff --git a/lib/elements/auto_fill.py b/lib/elements/auto_fill.py index 65b11fb1..486243ea 100644 --- a/lib/elements/auto_fill.py +++ b/lib/elements/auto_fill.py @@ -1,8 +1,10 @@ import math + from shapely import geometry as shgeo + from ..i18n import _ -from ..utils import cache from ..stitches import auto_fill +from ..utils import cache from .element import param, Patch from .fill import Fill @@ -93,6 +95,18 @@ class AutoFill(Fill): return self.get_float_param('fill_underlay_inset_mm', 0) @property + @param( + 'fill_underlay_skip_last', + _('Skip last stitch in each row'), + tooltip=_('The last stitch in each row is quite close to the first stitch in the next row. ' + 'Skipping it decreases stitch count and density.'), + group=_('AutoFill Underlay'), + type='boolean', + default=False) + def fill_underlay_skip_last(self): + return self.get_boolean_param("fill_underlay_skip_last", False) + + @property @param('expand_mm', _('Expand'), tooltip=_('Expand the shape before fill stitching, to compensate for gaps between shapes.'), @@ -150,6 +164,7 @@ class AutoFill(Fill): self.fill_underlay_max_stitch_length, self.running_stitch_length, self.staggers, + self.fill_underlay_skip_last, starting_point)) starting_point = stitches[-1] @@ -160,6 +175,7 @@ class AutoFill(Fill): self.max_stitch_length, self.running_stitch_length, self.staggers, + self.skip_last, starting_point, ending_point)) diff --git a/lib/elements/fill.py b/lib/elements/fill.py index 4156a24b..357adf4b 100644 --- a/lib/elements/fill.py +++ b/lib/elements/fill.py @@ -1,11 +1,12 @@ -from shapely import geometry as shgeo import math -from .element import param, EmbroideryElement, Patch +from shapely import geometry as shgeo + from ..i18n import _ +from ..stitches import legacy_fill from ..svg import PIXELS_PER_MM from ..utils import cache -from ..stitches import legacy_fill +from .element import param, EmbroideryElement, Patch class Fill(EmbroideryElement): @@ -42,6 +43,17 @@ class Fill(EmbroideryElement): @property @param( + 'skip_last', + _('Skip last stitch in each row'), + tooltip=_('The last stitch in each row is quite close to the first stitch in the next row. ' + 'Skipping it decreases stitch count and density.'), + type='boolean', + default=False) + def skip_last(self): + return self.get_boolean_param("skip_last", False) + + @property + @param( 'flip', _('Flip fill (start right-to-left)'), tooltip=_('The flip option can help you with routing your stitch path. ' @@ -133,5 +145,6 @@ class Fill(EmbroideryElement): self.end_row_spacing, self.max_stitch_length, self.flip, - self.staggers) + self.staggers, + self.skip_last) return [Patch(stitches=stitch_list, color=self.color) for stitch_list in stitch_lists] diff --git a/lib/extensions/params.py b/lib/extensions/params.py index d3cb154a..8cd0debe 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -3,14 +3,17 @@ from collections import defaultdict from copy import copy from itertools import groupby +import json import os import sys + import wx from wx.lib.scrolledpanel import ScrolledPanel from ..commands import is_command from ..elements import EmbroideryElement, Fill, AutoFill, Stroke, SatinColumn +from ..simulator import EmbroiderySimulator from ..gui import PresetsPanel, SimulatorPreview from ..i18n import _ from ..utils import get_resource_dir @@ -460,15 +463,16 @@ class Params(InkstitchExtension): element = EmbroideryElement(node) classes = [] - if element.get_style("fill"): - classes.append(AutoFill) - classes.append(Fill) + if not is_command(node): + if element.get_style("fill", "black") != "none": + classes.append(AutoFill) + classes.append(Fill) - if element.get_style("stroke") and not is_command(node): - classes.append(Stroke) + if element.get_style("stroke") is not None: + classes.append(Stroke) - if element.get_style("stroke-dasharray") is None: - classes.append(SatinColumn) + if element.get_style("stroke-dasharray") is None: + classes.append(SatinColumn) return classes diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py index 28c79eff..4a0fbed7 100644 --- a/lib/stitches/auto_fill.py +++ b/lib/stitches/auto_fill.py @@ -1,13 +1,14 @@ +from collections import deque +from itertools import groupby, izip import sys -import shapely + import networkx -from itertools import groupby, izip -from collections import deque +import shapely -from .fill import intersect_region_with_grating, row_num, stitch_row -from .running_stitch import running_stitch from ..i18n import _ from ..utils.geometry import Point as InkstitchPoint, cut +from .fill import intersect_region_with_grating, row_num, stitch_row +from .running_stitch import running_stitch class MaxQueueLengthExceeded(Exception): @@ -39,7 +40,16 @@ class PathEdge(object): return self.key == self.SEGMENT_KEY -def auto_fill(shape, angle, row_spacing, end_row_spacing, max_stitch_length, running_stitch_length, staggers, starting_point, ending_point=None): +def auto_fill(shape, + angle, + row_spacing, + end_row_spacing, + max_stitch_length, + running_stitch_length, + staggers, + skip_last, + starting_point, + ending_point=None): stitches = [] rows_of_segments = intersect_region_with_grating(shape, angle, row_spacing, end_row_spacing) @@ -48,7 +58,7 @@ def auto_fill(shape, angle, row_spacing, end_row_spacing, max_stitch_length, run graph = build_graph(shape, segments, angle, row_spacing) path = find_stitch_path(graph, segments, starting_point, ending_point) - stitches.extend(path_to_stitches(graph, path, shape, angle, row_spacing, max_stitch_length, running_stitch_length, staggers)) + stitches.extend(path_to_stitches(graph, path, shape, angle, row_spacing, max_stitch_length, running_stitch_length, staggers, skip_last)) return stitches @@ -513,7 +523,10 @@ def connect_points(shape, start, end, running_stitch_length, row_spacing): # Now do running stitch along the path we've found. running_stitch() will # avoid cutting sharp corners. path = [InkstitchPoint(*p) for p in points] - return running_stitch(path, running_stitch_length) + stitches = running_stitch(path, running_stitch_length) + + # The row of stitches already stitched the first point, so skip it. + return stitches[1:] def trim_end(path): @@ -521,14 +534,14 @@ def trim_end(path): path.pop() -def path_to_stitches(graph, path, shape, angle, row_spacing, max_stitch_length, running_stitch_length, staggers): +def path_to_stitches(graph, path, shape, angle, row_spacing, max_stitch_length, running_stitch_length, staggers, skip_last): path = collapse_sequential_outline_edges(graph, path) stitches = [] for edge in path: if edge.is_segment(): - stitch_row(stitches, edge[0], edge[1], angle, row_spacing, max_stitch_length, staggers) + stitch_row(stitches, edge[0], edge[1], angle, row_spacing, max_stitch_length, staggers, skip_last) else: stitches.extend(connect_points(shape, edge[0], edge[1], running_stitch_length, row_spacing)) diff --git a/lib/stitches/fill.py b/lib/stitches/fill.py index af0a8403..e00d66de 100644 --- a/lib/stitches/fill.py +++ b/lib/stitches/fill.py @@ -1,15 +1,16 @@ -import shapely import math +import shapely + from ..svg import PIXELS_PER_MM from ..utils import cache, Point as InkstitchPoint -def legacy_fill(shape, angle, row_spacing, end_row_spacing, max_stitch_length, flip, staggers): +def legacy_fill(shape, angle, row_spacing, end_row_spacing, max_stitch_length, flip, staggers, skip_last): rows_of_segments = intersect_region_with_grating(shape, angle, row_spacing, end_row_spacing, flip) groups_of_segments = pull_runs(rows_of_segments, shape, row_spacing) - return [section_to_stitches(group, angle, row_spacing, max_stitch_length, staggers) + return [section_to_stitches(group, angle, row_spacing, max_stitch_length, staggers, skip_last) for group in groups_of_segments] @@ -37,7 +38,7 @@ def adjust_stagger(stitch, angle, row_spacing, max_stitch_length, staggers): return stitch - offset * east(angle) -def stitch_row(stitches, beg, end, angle, row_spacing, max_stitch_length, staggers): +def stitch_row(stitches, beg, end, angle, row_spacing, max_stitch_length, staggers, skip_last=False): # We want our stitches to look like this: # # ---*-----------*----------- @@ -81,7 +82,7 @@ def stitch_row(stitches, beg, end, angle, row_spacing, max_stitch_length, stagge stitches.append(beg + offset * row_direction) offset += max_stitch_length - if (end - stitches[-1]).length() > 0.1 * PIXELS_PER_MM: + if (end - stitches[-1]).length() > 0.1 * PIXELS_PER_MM and not skip_last: stitches.append(end) @@ -164,7 +165,7 @@ def intersect_region_with_grating(shape, angle, row_spacing, end_row_spacing=Non return rows -def section_to_stitches(group_of_segments, angle, row_spacing, max_stitch_length, staggers): +def section_to_stitches(group_of_segments, angle, row_spacing, max_stitch_length, staggers, skip_last): stitches = [] swap = False @@ -174,7 +175,7 @@ def section_to_stitches(group_of_segments, angle, row_spacing, max_stitch_length if (swap): (beg, end) = (end, beg) - stitch_row(stitches, beg, end, angle, row_spacing, max_stitch_length, staggers) + stitch_row(stitches, beg, end, angle, row_spacing, max_stitch_length, staggers, skip_last) swap = not swap diff --git a/lib/svg/svg.py b/lib/svg/svg.py index b1cc91d9..3fceebfb 100644 --- a/lib/svg/svg.py +++ b/lib/svg/svg.py @@ -1,12 +1,12 @@ -import simpletransform -import simplestyle import inkex +import simplestyle +import simpletransform -from .units import get_viewbox_transform -from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG -from .realistic_rendering import realistic_stitch, realistic_filter from ..i18n import _ from ..utils import cache +from .realistic_rendering import realistic_stitch, realistic_filter +from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG +from .units import get_viewbox_transform def color_block_to_point_lists(color_block): @@ -21,6 +21,9 @@ def color_block_to_point_lists(color_block): if not stitch.jump and not stitch.color_change: point_lists[-1].append(stitch.as_tuple()) + # filter out empty point lists + point_lists = [p for p in point_lists if p] + return point_lists |
