diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2020-05-27 16:08:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-27 16:08:19 +0200 |
| commit | 455b02847f14983ef8c2463849981f5e9fc44063 (patch) | |
| tree | d4ed8df3fbf9d57bdda366dbc71bfd58b0b2ce0b | |
| parent | b461b2d85b10951f700d8f5c51b050bed8468cd2 (diff) | |
cleanup extension (#713)
Co-authored-by: Lex Neva <github.com@lexneva.name>
| -rw-r--r-- | lib/elements/stroke.py | 7 | ||||
| -rw-r--r-- | lib/extensions/__init__.py | 2 | ||||
| -rw-r--r-- | lib/extensions/cleanup.py | 39 | ||||
| -rw-r--r-- | templates/cleanup.inx | 24 |
4 files changed, 71 insertions, 1 deletions
diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py index 65e30634..36d1048e 100644 --- a/lib/elements/stroke.py +++ b/lib/elements/stroke.py @@ -76,11 +76,16 @@ class Stroke(EmbroideryElement): @property def paths(self): path = self.parse_path() + flattened = self.flatten(path) + + # manipulate invalid path + if len(flattened[0]) == 1: + return [[[flattened[0][0][0], flattened[0][0][1]], [flattened[0][0][0]+1.0, flattened[0][0][1]]]] if self.manual_stitch_mode: return [self.strip_control_points(subpath) for subpath in path] else: - return self.flatten(path) + return flattened @property @cache diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index 3c67700b..a5388f19 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -1,5 +1,6 @@ from auto_satin import AutoSatin from break_apart import BreakApart +from cleanup import Cleanup from convert_to_satin import ConvertToSatin from cut_satin import CutSatin from embroider import Embroider @@ -38,6 +39,7 @@ __all__ = extensions = [Embroider, Lettering, Troubleshoot, RemoveEmbroiderySettings, + Cleanup, BreakApart, ImportThreadlist, Simulator] diff --git a/lib/extensions/cleanup.py b/lib/extensions/cleanup.py new file mode 100644 index 00000000..f8cb7d9a --- /dev/null +++ b/lib/extensions/cleanup.py @@ -0,0 +1,39 @@ +import sys + +from ..elements import Fill, Stroke +from ..i18n import _ +from .base import InkstitchExtension + + +class Cleanup(InkstitchExtension): + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.OptionParser.add_option("-f", "--rm_fill", dest="rm_fill", type="inkbool", default=True) + self.OptionParser.add_option("-s", "--rm_stroke", dest="rm_stroke", type="inkbool", default=True) + self.OptionParser.add_option("-a", "--fill_threshold", dest="fill_threshold", type="int", default=20) + self.OptionParser.add_option("-l", "--stroke_threshold", dest="stroke_threshold", type="int", default=5) + + def effect(self): + self.rm_fill = self.options.rm_fill + self.rm_stroke = self.options.rm_stroke + self.fill_threshold = self.options.fill_threshold + self.stroke_threshold = self.options.stroke_threshold + + # Remove selection, we want every element in the document + self.selected = {} + + if not self.get_elements(): + return + + count = 0 + for element in self.elements: + if (isinstance(element, Fill) and self.rm_fill and + element.shape.area < self.fill_threshold): + element.node.getparent().remove(element.node) + count += 1 + if (isinstance(element, Stroke) and self.rm_stroke and + element.shape.length < self.stroke_threshold and element.node.getparent() is not None): + element.node.getparent().remove(element.node) + count += 1 + + print >> sys.stderr, _("%s elements removed" % count) diff --git a/templates/cleanup.inx b/templates/cleanup.inx new file mode 100644 index 00000000..4cf11ce1 --- /dev/null +++ b/templates/cleanup.inx @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> + <name>{% trans %}Cleanup Document{% endtrans %}</name> + <id>org.inkstitch.cleanup.{{ locale }}</id> + <param name="description" type="description">{% trans %}Use this extension to remove small objects from the document.{% endtrans %}</param> + <param name="rm_fill" type="boolean" _gui-text="{% trans %}Remove Small Fill Areas{% endtrans %}" + _gui-description="{% trans %}Removes areas smaller than dedined by threshold.{% endtrans %}">true</param> + <param name="fill_threshold" type="int" _gui-text="{% trans %}Fill area threshold{% endtrans %}" min="1" max="800">20</param> + <param name="rm_stroke" type="boolean" _gui-text="Remove Small strokes" + _gui-description="{% trans %}Removes small strokes shorter than defined by threshold.{% endtrans %}">true</param> + <param name="stroke_threshold" type="int" _gui-text="{% trans %}Stroke threshold{% endtrans %}" min="2" max="800">5</param> + <param name="extension" type="string" gui-hidden="true">cleanup</param> + <effect> + <object-type>all</object-type> + <effects-menu> + <submenu name="Ink/Stitch"> + <submenu name="{% trans %}Troubleshoot{% endtrans %}" /> + </submenu> + </effects-menu> + </effect> + <script> + {{ command_tag | safe }} + </script> +</inkscape-extension> |
