diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-06-21 19:48:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-21 19:48:28 +0200 |
| commit | eef2ec232ef45fd608093e22d6103a317da8eab5 (patch) | |
| tree | 7db41b7d8f391c1379dc1f9be82a6a2d7ac71b4e /lib/extensions/stitch_plan_preview_undo.py | |
| parent | edacc3ec7756d5d9c471b252132f942de8b93b52 (diff) | |
Undo stitch plan preview and density map (#1687)
Diffstat (limited to 'lib/extensions/stitch_plan_preview_undo.py')
| -rw-r--r-- | lib/extensions/stitch_plan_preview_undo.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/extensions/stitch_plan_preview_undo.py b/lib/extensions/stitch_plan_preview_undo.py new file mode 100644 index 00000000..381cf549 --- /dev/null +++ b/lib/extensions/stitch_plan_preview_undo.py @@ -0,0 +1,31 @@ +# Authors: see git history +# +# Copyright (c) 2022 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from ..svg.tags import INKSCAPE_GROUPMODE, INKSTITCH_ATTRIBS, SVG_GROUP_TAG +from .base import InkstitchExtension + + +class StitchPlanPreviewUndo(InkstitchExtension): + def effect(self): + reset_stitch_plan(self.document.getroot()) + + +def reset_stitch_plan(svg): + # delete old stitch plan + layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") + # get previously invisible layers (they still should be hidden afterwards) + if layer is not None: + invisible_layers = layer.get(INKSTITCH_ATTRIBS['invisible_layers'], '').split(",") + layer.getparent().remove(layer) + + # if there are layers with reduced opacity, remove opacity attribute or unhide hidden layers + for g in svg.findall(SVG_GROUP_TAG): + style = g.specified_style() + if (g.get(INKSCAPE_GROUPMODE) == "layer" and float(style.get('opacity', 1)) == 0.4 or style.get('display', 'inline') == 'none'): + if g.get_id() in invisible_layers: + continue + + g.style['opacity'] = 1 + g.style['display'] = 'inline' |
