diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 074663032..d7e924334 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -431,7 +431,7 @@ class FillStitch(EmbroideryElement): 'stitch routing. When enabled the last section will end at the defined spot.'), type='boolean', sort_index=33, - select_items=[('fill_method', 'linear_gradient_fill')], + select_items=[('fill_method', 'linear_gradient_fill'), ('fill_method', 'tartan_fill')], default=False ) def stop_at_ending_point(self): @@ -962,20 +962,20 @@ class FillStitch(EmbroideryElement): fill_shapes = self.fill_shape(shape) for i, fill_shape in enumerate(fill_shapes.geoms): if self.fill_method == 'contour_fill': - stitch_groups.extend(self.do_contour_fill(fill_shape, previous_stitch_group, start)) + stitch_groups.extend(self.do_contour_fill(fill_shape, start)) elif self.fill_method == 'guided_fill': - stitch_groups.extend(self.do_guided_fill(fill_shape, previous_stitch_group, start, end)) + stitch_groups.extend(self.do_guided_fill(fill_shape, start, end)) elif self.fill_method == 'meander_fill': stitch_groups.extend(self.do_meander_fill(fill_shape, shape, i, start, end)) elif self.fill_method == 'circular_fill': - stitch_groups.extend(self.do_circular_fill(fill_shape, previous_stitch_group, start, end)) + stitch_groups.extend(self.do_circular_fill(fill_shape, start, end)) elif self.fill_method == 'linear_gradient_fill': - stitch_groups.extend(self.do_linear_gradient_fill(fill_shape, previous_stitch_group, start, end)) + stitch_groups.extend(self.do_linear_gradient_fill(fill_shape, start, end)) elif self.fill_method == 'tartan_fill': - stitch_groups.extend(self.do_tartan_fill(fill_shape, previous_stitch_group, start, end)) + stitch_groups.extend(self.do_tartan_fill(fill_shape, start, end)) else: # auto_fill - stitch_groups.extend(self.do_auto_fill(fill_shape, previous_stitch_group, start, end)) + stitch_groups.extend(self.do_auto_fill(fill_shape, start, end)) if stitch_groups: previous_stitch_group = stitch_groups[-1] @@ -1052,7 +1052,7 @@ class FillStitch(EmbroideryElement): starting_point = underlay.stitches[-1] return [stitch_groups, starting_point] - def do_auto_fill(self, shape, last_stitch_group, starting_point, ending_point): + def do_auto_fill(self, shape, starting_point, ending_point): stitch_group = StitchGroup( color=self.color, tags=("auto_fill", "auto_fill_top"), @@ -1081,7 +1081,7 @@ class FillStitch(EmbroideryElement): ) return [stitch_group] - def do_contour_fill(self, polygon, last_stitch_group, starting_point): + def do_contour_fill(self, polygon, starting_point): if not starting_point: starting_point = (0, 0) starting_point = shgeo.Point(starting_point) @@ -1135,12 +1135,12 @@ class FillStitch(EmbroideryElement): return stitch_groups - def do_guided_fill(self, shape, last_stitch_group, starting_point, ending_point): + def do_guided_fill(self, shape, starting_point, ending_point): guide_line = self._get_guide_lines() # No guide line: fallback to normal autofill if not guide_line: - return self.do_auto_fill(shape, last_stitch_group, starting_point, ending_point) + return self.do_auto_fill(shape, starting_point, ending_point) stitch_group = StitchGroup( color=self.color, @@ -1190,7 +1190,7 @@ class FillStitch(EmbroideryElement): ) return [stitch_group] - def do_circular_fill(self, shape, last_stitch_group, starting_point, ending_point): + def do_circular_fill(self, shape, starting_point, ending_point): # get target position command = self.get_command('target_point') if command: @@ -1229,8 +1229,8 @@ class FillStitch(EmbroideryElement): ) return [stitch_group] - def do_linear_gradient_fill(self, shape, last_stitch_group, start, end): + def do_linear_gradient_fill(self, shape, start, end): return linear_gradient_fill(self, shape, start, end) - def do_tartan_fill(self, shape, last_stitch_group, start, end): + def do_tartan_fill(self, shape, start, end): return tartan_fill(self, shape, start, end) diff --git a/lib/lettering/font.py b/lib/lettering/font.py index 6857c8309..a84329c72 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -557,6 +557,8 @@ class Font(object): for element in element_list: path += element.get("d", "") grouped_elements[0][0].set("d", path) + if grouped_elements[0][0].get("inkstitch:fill_method", False) in ['tartan_fill', 'linear_gradient_fill']: + grouped_elements[0][0].set('inkstitch:stop_at_ending_point', True) color_group.append(grouped_elements[0][0]) group.append(color_group) continue diff --git a/lib/stitches/tartan_fill.py b/lib/stitches/tartan_fill.py index 5eeed473f..1ddd8195d 100644 --- a/lib/stitches/tartan_fill.py +++ b/lib/stitches/tartan_fill.py @@ -104,8 +104,8 @@ def tartan_fill(fill: 'FillStitch', outline: Polygon, starting_point: Union[tupl color_lines, color_runs = sort_fills_and_strokes(color_lines, color_runs) - stitch_groups = _get_fill_stitch_groups(fill, outline, color_lines) - if stitch_groups: + stitch_groups = _get_fill_stitch_groups(fill, outline, color_lines, starting_point, ending_point) + if stitch_groups and not fill.stop_at_ending_point: starting_point = stitch_groups[-1].stitches[-1] stitch_groups += _get_run_stitch_groups(fill, outline, color_runs, starting_point, ending_point) return stitch_groups @@ -694,6 +694,8 @@ def _get_fill_stitch_groups( fill: 'FillStitch', shape: Polygon, color_lines: defaultdict, + starting_point: Union[tuple, Stitch, None], + ending_point: Union[tuple, Stitch, None] ) -> List[StitchGroup]: """ Route fill stitches @@ -701,17 +703,22 @@ def _get_fill_stitch_groups( :param fill: the FillStitch element :param shape: the shape to be filled :param color_lines: lines grouped by color + :param starting_point: the starting_point + :paramt ending_point: the ending_point :returns: a list with StitchGroup objects """ stitch_groups: List[StitchGroup] = [] i = 0 for color, lines in color_lines.items(): - i += 1 - if stitch_groups: - starting_point = stitch_groups[-1].stitches[-1] - else: + if not fill.stop_at_ending_point: + i += 1 + if stitch_groups: + starting_point = stitch_groups[-1].stitches[-1] + if starting_point is None: starting_point = ensure_multi_line_string(shape.boundary).geoms[0].coords[1] - ending_point = ensure_multi_line_string(shape.boundary).geoms[0].coords[1] + if ending_point is None: + ending_point = ensure_multi_line_string(shape.boundary).geoms[0].coords[1] + segments = [list(line.coords) for line in lines if len(line.coords) > 1] if len(segments) == 0: continue @@ -739,14 +746,15 @@ def _get_run_stitch_groups( :param ending_point: the ending point :returns: a list with StitchGroup objects """ - stitch_groups: List[StitchGroup] = [] for color, lines in color_lines.items(): + if not fill.stop_at_ending_point and stitch_groups: + starting_point = stitch_groups[-1].stitches[-1] # get segments and ignore lines smaller than 0.5 mm segments = [list(line.coords) for line in lines if line.length > 0.5 * PIXELS_PER_MM] if len(segments) == 0: continue - stitch_group = _segments_to_stitch_group(fill, shape, segments, None, color, starting_point, ending_point, True) + stitch_group = _segments_to_stitch_group(fill, shape, segments, 0, color, starting_point, ending_point, True) if stitch_group is not None: stitch_groups.append(stitch_group) check_stop_flag() @@ -757,7 +765,7 @@ def _segments_to_stitch_group( fill: 'FillStitch', shape: Polygon, segments: List[List[Tuple[float, float]]], - iteration: Optional[int], + iteration: int, color: str, starting_point: Optional[Union[tuple, Stitch]], ending_point: Optional[Union[tuple, Stitch]], diff --git a/templates/lettering_generate_json.xml b/templates/lettering_generate_json.xml index 698c70154..d9e4b0456 100644 --- a/templates/lettering_generate_json.xml +++ b/templates/lettering_generate_json.xml @@ -105,10 +105,11 @@ - + +