From 8cead6e3d9f9223bd4d74b30ec6964802f52d9b2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 25 Aug 2022 23:10:16 -0400 Subject: add smoothness option for contour fill --- lib/elements/fill_stitch.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 77b4ac7c..fb8838cc 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -137,6 +137,20 @@ class FillStitch(EmbroideryElement): def avoid_self_crossing(self): return self.get_boolean_param('avoid_self_crossing', False) + @property + @param('smoothness_mm', _('Smoothness'), + tooltip=_( + 'Smooth the stitch path. Smoothness limits how far the smoothed stitch path ' + + 'is allowed to deviate from the original path. Hint: a lower stitchc tolerance may be needed too.' + ), + type='integer', + unit='mm', + default=0, + select_items=[('fill_method', 1)], + sort_index=5) + def smoothness(self): + return self.get_float_param('smoothness_mm', 0) + @property @param('clockwise', _('Clockwise'), type='boolean', default=True, select_items=[('fill_method', 1)], sort_index=5) def clockwise(self): @@ -651,9 +665,11 @@ class FillStitch(EmbroideryElement): if self.contour_strategy == 0: stitches = contour_fill.inner_to_outer( tree, + polygon, self.row_spacing, self.max_stitch_length, self.running_stitch_tolerance, + self.smoothness, starting_point, self.avoid_self_crossing ) -- cgit v1.2.3 From ba835b4f5e33f404b7bed9369a1b425a67b312c5 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 16 Jan 2023 14:27:06 -0500 Subject: meander fill: initial version --- lib/elements/fill_stitch.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index fb8838cc..fbaab0c2 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -17,8 +17,10 @@ from ..i18n import _ from ..marker import get_marker_elements from ..stitch_plan import StitchGroup from ..stitches import auto_fill, contour_fill, guided_fill, legacy_fill +from ..stitches.meander_fill import meander_fill from ..svg import PIXELS_PER_MM from ..svg.tags import INKSCAPE_LABEL +from .. import tiles from ..utils import cache, version from .element import EmbroideryElement, param from .validation import ValidationError, ValidationWarning @@ -107,7 +109,7 @@ class FillStitch(EmbroideryElement): @property @param('fill_method', _('Fill method'), type='dropdown', default=0, - options=[_("Auto Fill"), _("Contour Fill"), _("Guided Fill"), _("Legacy Fill")], sort_index=2) + options=[_("Auto Fill"), _("Contour Fill"), _("Guided Fill"), _("Legacy Fill"), _("Meander Fill")], sort_index=2) def fill_method(self): return self.get_int_param('fill_method', 0) @@ -146,7 +148,7 @@ class FillStitch(EmbroideryElement): type='integer', unit='mm', default=0, - select_items=[('fill_method', 1)], + select_items=[('fill_method', 1), ('fill_method', 4)], sort_index=5) def smoothness(self): return self.get_float_param('smoothness_mm', 0) @@ -156,6 +158,12 @@ class FillStitch(EmbroideryElement): def clockwise(self): return self.get_boolean_param('clockwise', True) + @property + @param('meander_pattern', _('Meander Pattern'), type='dropdown', default=0, + options=[tile.name for tile in tiles.all_tiles()], select_items=[('fill_method', 4)], sort_index=3) + def meander_pattern(self): + return self.get_param('meander_pattern', None) + @property @param('angle', _('Angle of lines of stitches'), @@ -592,6 +600,8 @@ class FillStitch(EmbroideryElement): stitch_groups.extend(self.do_contour_fill(fill_shape, previous_stitch_group, start)) elif self.fill_method == 2: stitch_groups.extend(self.do_guided_fill(fill_shape, previous_stitch_group, start, end)) + elif self.fill_method == 4: + stitch_groups.extend(self.do_meander_fill(fill_shape, start, end)) except ExitThread: raise except Exception: @@ -723,6 +733,13 @@ class FillStitch(EmbroideryElement): )) return [stitch_group] + def do_meander_fill(self, shape, starting_point, ending_point): + stitch_group = StitchGroup( + color=self.color, + tags=("meander_fill", "meander_fill_top"), + stitches=meander_fill(self, shape, starting_point, ending_point)) + return [stitch_group] + @cache def _get_guide_lines(self, multiple=False): guide_lines = get_marker_elements(self.node, "guide-line", False, True) -- cgit v1.2.3 From 847e133f97d570e2967dfa7dcfc16a212dc2bbbc Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 17 Jan 2023 21:44:23 -0500 Subject: meander fill: more work --- lib/elements/fill_stitch.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index fbaab0c2..790eec5c 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -5,6 +5,7 @@ import logging import math +import numpy as np import re import sys import traceback @@ -142,7 +143,7 @@ class FillStitch(EmbroideryElement): @property @param('smoothness_mm', _('Smoothness'), tooltip=_( - 'Smooth the stitch path. Smoothness limits how far the smoothed stitch path ' + + 'Smooth the stitch path. Smoothness limits approximately how far the smoothed stitch path ' + 'is allowed to deviate from the original path. Hint: a lower stitchc tolerance may be needed too.' ), type='integer', @@ -159,11 +160,21 @@ class FillStitch(EmbroideryElement): return self.get_boolean_param('clockwise', True) @property - @param('meander_pattern', _('Meander Pattern'), type='dropdown', default=0, + @param('meander_pattern', _('Meander Pattern'), type='select', default=0, options=[tile.name for tile in tiles.all_tiles()], select_items=[('fill_method', 4)], sort_index=3) def meander_pattern(self): return self.get_param('meander_pattern', None) + @property + @param('meander_scale_percent', _('Meander pattern scale'), type='float', unit="%", default=100, select_items=[('fill_method', 4)], sort_index=4) + def meander_scale(self): + return np.maximum(self.get_split_float_param('meander_scale_percent', (100, 100)), (10, 10)) / 100 + + @property + @param('meander_padding_mm', _('Meander padding'), type='float', unit="mm", default=0, select_items=[('fill_method', 4)], sort_index=5) + def meander_padding(self): + return self.get_float_param('meander_padding_mm', 0) + @property @param('angle', _('Angle of lines of stitches'), @@ -593,7 +604,7 @@ class FillStitch(EmbroideryElement): stitch_groups.extend(underlay_stitch_groups) fill_shapes = self.fill_shape(shape) - for fill_shape in fill_shapes.geoms: + for i, fill_shape in enumerate(fill_shapes.geoms): if self.fill_method == 0: stitch_groups.extend(self.do_auto_fill(fill_shape, previous_stitch_group, start, end)) if self.fill_method == 1: @@ -601,7 +612,7 @@ class FillStitch(EmbroideryElement): elif self.fill_method == 2: stitch_groups.extend(self.do_guided_fill(fill_shape, previous_stitch_group, start, end)) elif self.fill_method == 4: - stitch_groups.extend(self.do_meander_fill(fill_shape, start, end)) + stitch_groups.extend(self.do_meander_fill(fill_shape, i, start, end)) except ExitThread: raise except Exception: @@ -733,11 +744,11 @@ class FillStitch(EmbroideryElement): )) return [stitch_group] - def do_meander_fill(self, shape, starting_point, ending_point): + def do_meander_fill(self, shape, i, starting_point, ending_point): stitch_group = StitchGroup( color=self.color, tags=("meander_fill", "meander_fill_top"), - stitches=meander_fill(self, shape, starting_point, ending_point)) + stitches=meander_fill(self, shape, i, starting_point, ending_point)) return [stitch_group] @cache -- cgit v1.2.3 From 6612d10689e8f5238f34d68e9a9cde53371685a5 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 28 Jan 2023 21:30:45 -0500 Subject: avoid super-dense meander graph --- lib/elements/fill_stitch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 790eec5c..46f04edc 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -168,7 +168,7 @@ class FillStitch(EmbroideryElement): @property @param('meander_scale_percent', _('Meander pattern scale'), type='float', unit="%", default=100, select_items=[('fill_method', 4)], sort_index=4) def meander_scale(self): - return np.maximum(self.get_split_float_param('meander_scale_percent', (100, 100)), (10, 10)) / 100 + return np.maximum(self.get_split_float_param('meander_scale_percent', (100, 100)), (30, 30)) / 100 @property @param('meander_padding_mm', _('Meander padding'), type='float', unit="mm", default=0, select_items=[('fill_method', 4)], sort_index=5) -- cgit v1.2.3 From 86f806238239ed4b2d54b9239704eb1f519ea429 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 28 Jan 2023 23:54:46 -0500 Subject: expose running stitch length in meander --- lib/elements/fill_stitch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 46f04edc..07da3211 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -413,7 +413,7 @@ class FillStitch(EmbroideryElement): unit='mm', type='float', default=1.5, - select_items=[('fill_method', 0), ('fill_method', 2)], + select_items=[('fill_method', 0), ('fill_method', 2), ('fill_method', 4)], sort_index=6) def running_stitch_length(self): return max(self.get_float_param("running_stitch_length_mm", 1.5), 0.01) -- cgit v1.2.3 From 8dde33d867afce7ea4aa212dfce60e9e526bbc1c Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 5 Feb 2023 22:58:17 -0500 Subject: make meander interruptible --- lib/elements/fill_stitch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 07da3211..8de169e0 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -168,7 +168,7 @@ class FillStitch(EmbroideryElement): @property @param('meander_scale_percent', _('Meander pattern scale'), type='float', unit="%", default=100, select_items=[('fill_method', 4)], sort_index=4) def meander_scale(self): - return np.maximum(self.get_split_float_param('meander_scale_percent', (100, 100)), (30, 30)) / 100 + return self.get_split_float_param('meander_scale_percent', (100, 100)) / 100 @property @param('meander_padding_mm', _('Meander padding'), type='float', unit="mm", default=0, select_items=[('fill_method', 4)], sort_index=5) -- cgit v1.2.3 From 9ea61ef3f33b76f199843fff82d1d624903aa11d Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 8 Feb 2023 14:39:25 -0500 Subject: remove buffer concept --- lib/elements/fill_stitch.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 8de169e0..7c214798 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -170,11 +170,6 @@ class FillStitch(EmbroideryElement): def meander_scale(self): return self.get_split_float_param('meander_scale_percent', (100, 100)) / 100 - @property - @param('meander_padding_mm', _('Meander padding'), type='float', unit="mm", default=0, select_items=[('fill_method', 4)], sort_index=5) - def meander_padding(self): - return self.get_float_param('meander_padding_mm', 0) - @property @param('angle', _('Angle of lines of stitches'), -- cgit v1.2.3 From 49d39d6169268ad81ec5ada19982c234b4657fd3 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 8 Feb 2023 14:44:26 -0500 Subject: expose Expand setting in meander --- lib/elements/fill_stitch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 7c214798..466e7efb 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -503,12 +503,12 @@ class FillStitch(EmbroideryElement): @property @param('expand_mm', _('Expand'), - tooltip=_('Expand the shape before fill stitching, to compensate for gaps between shapes.'), + tooltip=_('Expand the shape before fill stitching, to compensate for gaps between shapes. Negative values contract instead.'), unit='mm', type='float', default=0, sort_index=5, - select_items=[('fill_method', 0), ('fill_method', 2)]) + select_items=[('fill_method', 0), ('fill_method', 2), ('fill_method', 4)]) def expand(self): return self.get_float_param('expand_mm', 0) -- cgit v1.2.3 From f2344375df9364f33b957d46e9cea508e1b32c67 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 8 Feb 2023 14:46:43 -0500 Subject: clarify running stitch params for meander --- lib/elements/fill_stitch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 466e7efb..a0d89915 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -144,7 +144,7 @@ class FillStitch(EmbroideryElement): @param('smoothness_mm', _('Smoothness'), tooltip=_( 'Smooth the stitch path. Smoothness limits approximately how far the smoothed stitch path ' + - 'is allowed to deviate from the original path. Hint: a lower stitchc tolerance may be needed too.' + 'is allowed to deviate from the original path. Hint: a lower stitch tolerance may be needed too.' ), type='integer', unit='mm', @@ -404,7 +404,8 @@ class FillStitch(EmbroideryElement): @property @param('running_stitch_length_mm', _('Running stitch length (traversal between sections)'), - tooltip=_('Length of stitches around the outline of the fill region used when moving from section to section.'), + tooltip=_( + 'Length of stitches around the outline of the fill region used when moving from section to section. Also used for meander fill.'), unit='mm', type='float', default=1.5, -- cgit v1.2.3 From 3b1a161532fb641f904c8697ac3597ecef0b4110 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 12 Feb 2023 23:09:42 -0500 Subject: sort tiles by name --- lib/elements/fill_stitch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index a0d89915..40e720ae 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -161,7 +161,7 @@ class FillStitch(EmbroideryElement): @property @param('meander_pattern', _('Meander Pattern'), type='select', default=0, - options=[tile.name for tile in tiles.all_tiles()], select_items=[('fill_method', 4)], sort_index=3) + options=sorted(tile.name for tile in tiles.all_tiles()), select_items=[('fill_method', 4)], sort_index=3) def meander_pattern(self): return self.get_param('meander_pattern', None) -- cgit v1.2.3 From 3da70348b03d8d40ef71d2f515bb9f179977e693 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 16 Feb 2023 22:53:51 -0500 Subject: change wording of smoothness tooltip --- lib/elements/fill_stitch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 40e720ae..9b36497e 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -143,8 +143,9 @@ class FillStitch(EmbroideryElement): @property @param('smoothness_mm', _('Smoothness'), tooltip=_( - 'Smooth the stitch path. Smoothness limits approximately how far the smoothed stitch path ' + - 'is allowed to deviate from the original path. Hint: a lower stitch tolerance may be needed too.' + 'Smooth the stitch path. Smoothness limits how far the smoothed stitch path ' + + 'is allowed to deviate from the original path. Try low numbers like 0.2. ' + + 'Hint: a lower running stitch tolerance may be needed too.' ), type='integer', unit='mm', -- cgit v1.2.3 From be699bf89255d98729b1d10f426acf8e852709b4 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 18 Feb 2023 16:43:18 -0500 Subject: fix params for meander --- lib/elements/fill_stitch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 9b36497e..34588ba0 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -223,6 +223,7 @@ class FillStitch(EmbroideryElement): unit='mm', sort_index=6, type='float', + select_items=[('fill_method', 0), ('fill_method', 1), ('fill_method', 2), ('fill_method', 3)], default=0.25) def row_spacing(self): return max(self.get_float_param("row_spacing_mm", 0.25), 0.1 * PIXELS_PER_MM) @@ -239,6 +240,7 @@ class FillStitch(EmbroideryElement): unit='mm', sort_index=6, type='float', + select_items=[('fill_method', 0), ('fill_method', 1), ('fill_method', 2), ('fill_method', 3)], default=3.0) def max_stitch_length(self): return max(self.get_float_param("max_stitch_length_mm", 3.0), 0.1 * PIXELS_PER_MM) @@ -404,7 +406,7 @@ class FillStitch(EmbroideryElement): @property @param('running_stitch_length_mm', - _('Running stitch length (traversal between sections)'), + _('Running stitch length'), tooltip=_( 'Length of stitches around the outline of the fill region used when moving from section to section. Also used for meander fill.'), unit='mm', -- cgit v1.2.3 From 315866de9ade249cab8db81d880d255f33f851f3 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 18 Feb 2023 21:51:22 -0500 Subject: use new combo param type --- lib/elements/fill_stitch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 34588ba0..9d86aa36 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -161,8 +161,8 @@ class FillStitch(EmbroideryElement): return self.get_boolean_param('clockwise', True) @property - @param('meander_pattern', _('Meander Pattern'), type='select', default=0, - options=sorted(tile.name for tile in tiles.all_tiles()), select_items=[('fill_method', 4)], sort_index=3) + @param('meander_pattern', _('Meander Pattern'), type='combo', default=0, + options=sorted(tiles.all_tiles()), select_items=[('fill_method', 4)], sort_index=3) def meander_pattern(self): return self.get_param('meander_pattern', None) -- cgit v1.2.3 From 92dff9f359f19c57ce63046a85cbd40746e50a32 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 20 Feb 2023 15:30:18 -0500 Subject: remove unused import --- lib/elements/fill_stitch.py | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/elements/fill_stitch.py') diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 9d86aa36..c6762ad1 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -5,7 +5,6 @@ import logging import math -import numpy as np import re import sys import traceback -- cgit v1.2.3