diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-06-22 15:22:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-22 15:22:34 +0200 |
| commit | b6bde000fe675ed725d7d5dbd7db3f44fb33af0e (patch) | |
| tree | 2c856ac51c563b6c918ab3041ac29c5106e7a06d | |
| parent | 75fc4ce8695f6fb6c7cc108fcf458ad36bbd00c1 (diff) | |
Option to drop short stitches (#1693)
| -rw-r--r-- | lib/api/stitch_plan.py | 3 | ||||
| -rw-r--r-- | lib/extensions/embroider_settings.py | 5 | ||||
| -rw-r--r-- | lib/extensions/generate_palette.py | 2 | ||||
| -rw-r--r-- | lib/extensions/output.py | 4 | ||||
| -rw-r--r-- | lib/extensions/print_pdf.py | 3 | ||||
| -rw-r--r-- | lib/extensions/stitch_plan_preview.py | 3 | ||||
| -rw-r--r-- | lib/extensions/zip.py | 3 | ||||
| -rw-r--r-- | lib/stitch_plan/color_block.py | 8 | ||||
| -rw-r--r-- | lib/stitch_plan/stitch_plan.py | 8 | ||||
| -rw-r--r-- | templates/embroider_settings.xml | 3 |
10 files changed, 29 insertions, 13 deletions
diff --git a/lib/api/stitch_plan.py b/lib/api/stitch_plan.py index 6d64d781..c70efd98 100644 --- a/lib/api/stitch_plan.py +++ b/lib/api/stitch_plan.py @@ -18,7 +18,8 @@ def get_stitch_plan(): metadata = g.extension.get_inkstitch_metadata() collapse_len = metadata['collapse_len_mm'] + min_stitch_len = metadata['min_stitch_len_mm'] patches = g.extension.elements_to_stitch_groups(g.extension.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) return jsonify(stitch_plan) diff --git a/lib/extensions/embroider_settings.py b/lib/extensions/embroider_settings.py index f504c88f..cdf18991 100644 --- a/lib/extensions/embroider_settings.py +++ b/lib/extensions/embroider_settings.py @@ -16,7 +16,12 @@ class EmbroiderSettings(InkstitchExtension): action="store", type=float, dest="collapse_length_mm", default=3.0, help="max collapse length (mm)") + self.arg_parser.add_argument("-l", "--min_stitch_len_mm", + action="store", type=float, + dest="min_stitch_len_mm", default=0, + help="minimum stitch length (mm)") def effect(self): self.metadata = self.get_inkstitch_metadata() self.metadata['collapse_len_mm'] = self.options.collapse_length_mm + self.metadata['min_stitch_len_mm'] = self.options.min_stitch_len_mm diff --git a/lib/extensions/generate_palette.py b/lib/extensions/generate_palette.py index 280be90f..fdb76735 100644 --- a/lib/extensions/generate_palette.py +++ b/lib/extensions/generate_palette.py @@ -73,7 +73,7 @@ class GeneratePalette(InkstitchExtension): else: number = 0 name = ' '.join(color_name) - color = "\n%s\t%s\t%s\t%s %s" % (str(color[0]).rjust(3), str(color[1]).rjust(3), str(color[2]).rjust(3), name.rjust(30), number) + color = "\n%s\t%s\t%s\t%s %s" % (str(color[0]).rjust(3), str(color[1]).rjust(3), str(color[2]).rjust(3), name.rjust(30), number) colors.append(color) return colors diff --git a/lib/extensions/output.py b/lib/extensions/output.py index 7cc12ee0..a3f35d2f 100644 --- a/lib/extensions/output.py +++ b/lib/extensions/output.py @@ -52,8 +52,10 @@ class Output(InkstitchExtension): self.metadata = self.get_inkstitch_metadata() collapse_len = self.metadata['collapse_len_mm'] + min_stitch_len = self.metadata['min_stitch_len_mm'] patches = self.elements_to_stitch_groups(self.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, disable_ties=self.settings.get('laser_mode', False)) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, disable_ties=self.settings.get('laser_mode', False), + min_stitch_len=min_stitch_len) temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.file_extension, delete=False) diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index 63c3c699..47e68c5d 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -308,8 +308,9 @@ class Print(InkstitchExtension): self.metadata = self.get_inkstitch_metadata() collapse_len = self.metadata['collapse_len_mm'] + min_stitch_len = self.metadata['min_stitch_len_mm'] patches = self.elements_to_stitch_groups(self.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) palette = ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette']) overview_svg, color_block_svgs = self.render_svgs(stitch_plan, realistic=False) diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py index 2a428781..571d5040 100644 --- a/lib/extensions/stitch_plan_preview.py +++ b/lib/extensions/stitch_plan_preview.py @@ -35,8 +35,9 @@ class StitchPlanPreview(InkstitchExtension): visual_commands = True self.metadata = self.get_inkstitch_metadata() collapse_len = self.metadata['collapse_len_mm'] + min_stitch_len = self.metadata['min_stitch_len_mm'] patches = self.elements_to_stitch_groups(self.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) render_stitch_plan(svg, stitch_plan, realistic, visual_commands) # apply options diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index 22654560..280c2a14 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -43,8 +43,9 @@ class Zip(InkstitchExtension): self.metadata = self.get_inkstitch_metadata() collapse_len = self.metadata['collapse_len_mm'] + min_stitch_len = self.metadata['min_stitch_len_mm'] patches = self.elements_to_stitch_groups(self.elements) - stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len) + stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len) 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 cd7b9c6d..2f387460 100644 --- a/lib/stitch_plan/color_block.py +++ b/lib/stitch_plan/color_block.py @@ -98,19 +98,21 @@ class ColorBlock(object): return False - def filter_duplicate_stitches(self): + def filter_duplicate_stitches(self, min_stitch_len=0.1): if not self.stitches: return - stitches = [self.stitches[0]] + if min_stitch_len is None: + min_stitch_len = 0.1 + stitches = [self.stitches[0]] for stitch in self.stitches[1:]: if stitches[-1].jump or stitch.stop or stitch.trim or stitch.color_change: # Don't consider jumps, stops, color changes, or trims as candidates for filtering pass else: length = (stitch - stitches[-1]).length() - if length <= 0.1 * PIXELS_PER_MM: + if length <= min_stitch_len * PIXELS_PER_MM: # duplicate stitch, skip this one continue diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index 4593781a..04d587c2 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -13,7 +13,7 @@ from .color_block import ColorBlock from .ties import add_ties -def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties=False): # noqa: C901 +def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_len=0.1, disable_ties=False): # noqa: C901 """Convert a collection of StitchGroups to a StitchPlan. @@ -71,7 +71,7 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties= # last block ended in a stop, so now we have an empty block del stitch_plan.color_blocks[-1] - stitch_plan.filter_duplicate_stitches() + stitch_plan.filter_duplicate_stitches(min_stitch_len) if not disable_ties: stitch_plan.add_ties() @@ -101,9 +101,9 @@ class StitchPlan(object): def add_color_block(self, color_block): self.color_blocks.append(color_block) - def filter_duplicate_stitches(self): + def filter_duplicate_stitches(self, min_stitch_len): for color_block in self: - color_block.filter_duplicate_stitches() + color_block.filter_duplicate_stitches(min_stitch_len) def add_ties(self): # see ties.py diff --git a/templates/embroider_settings.xml b/templates/embroider_settings.xml index 96339fcb..362aa7f9 100644 --- a/templates/embroider_settings.xml +++ b/templates/embroider_settings.xml @@ -15,6 +15,9 @@ <param name="collapse_len_mm" type="float" precision="1" min="0" max="10" gui-text="Collapse length (mm)" gui-description="Jump stitches smaller than this will be treated as normal stitches.">3</param> + <param name="min_stitch_len_mm" type="float" precision="1" min="0" max="10" + gui-text="Minimal stitch length (mm)" + gui-description="Drop stitches smaller than this value.">0.1</param> <script> {{ command_tag | safe }} </script> |
