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.py | |
| parent | edacc3ec7756d5d9c471b252132f942de8b93b52 (diff) | |
Undo stitch plan preview and density map (#1687)
Diffstat (limited to 'lib/extensions/stitch_plan_preview.py')
| -rw-r--r-- | lib/extensions/stitch_plan_preview.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py index e5e570fb..2a428781 100644 --- a/lib/extensions/stitch_plan_preview.py +++ b/lib/extensions/stitch_plan_preview.py @@ -3,14 +3,16 @@ # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -from inkex import Boolean, Style from lxml import etree +from inkex import Boolean, Style + from ..stitch_plan import stitch_groups_to_stitch_plan from ..svg import render_stitch_plan -from ..svg.tags import (INKSCAPE_GROUPMODE, SVG_DEFS_TAG, SVG_GROUP_TAG, - SVG_PATH_TAG) +from ..svg.tags import (INKSCAPE_GROUPMODE, INKSTITCH_ATTRIBS, SVG_DEFS_TAG, + SVG_GROUP_TAG, SVG_PATH_TAG) from .base import InkstitchExtension +from .stitch_plan_preview_undo import reset_stitch_plan class StitchPlanPreview(InkstitchExtension): @@ -23,37 +25,37 @@ class StitchPlanPreview(InkstitchExtension): def effect(self): # delete old stitch plan svg = self.document.getroot() - layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") - if layer is not None: - del layer[:] + reset_stitch_plan(svg) # create new stitch plan if not self.get_elements(): return realistic = False + visual_commands = True self.metadata = self.get_inkstitch_metadata() collapse_len = self.metadata['collapse_len_mm'] patches = self.elements_to_stitch_groups(self.elements) stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len) - render_stitch_plan(svg, stitch_plan, realistic) + render_stitch_plan(svg, stitch_plan, realistic, visual_commands) # apply options layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") # update layer visibility 0 = unchanged, 1 = hidden, 2 = lower opacity + groups = self.document.getroot().findall(SVG_GROUP_TAG) if self.options.layer_visibility == 1: + self.set_invisible_layers_attribute(groups, layer) self.hide_all_layers() - layer.set('style', None) + layer.style['display'] = "inline" elif self.options.layer_visibility == 2: - for g in self.document.getroot().findall(SVG_GROUP_TAG): + for g in groups: style = g.specified_style() # check groupmode and exclude stitch_plan layer # exclude objects which are not displayed at all or already have opacity < 0.4 if (g.get(INKSCAPE_GROUPMODE) == "layer" and not g == layer and float(style.get('opacity', 1)) > 0.4 and not style.get('display', 'inline') == 'none'): - style += Style('opacity:0.4') - g.set("style", style) + g.style['opacity'] = 0.4 # translate stitch plan to the right side of the canvas if self.options.move_to_side: @@ -65,10 +67,17 @@ class StitchPlanPreview(InkstitchExtension): if self.options.needle_points: markers = 'marker-mid:url(#inkstitch-needle-point);marker-start:url(#inkstitch-needle-point);marker-end:url(#inkstitch-needle-point)' for element in layer.iterdescendants(SVG_PATH_TAG): - style = ';'.join([element.get('style'), markers]) + style = element.style + Style(markers) element.set('style', style) self.ensure_marker() + def set_invisible_layers_attribute(self, groups, layer): + invisible_layers = [] + for g in groups: + if g.get(INKSCAPE_GROUPMODE) == "layer" and 'display' in g.style and g.style['display'] == 'none': + invisible_layers.append(g.get_id()) + layer.set(INKSTITCH_ATTRIBS['invisible_layers'], ",".join(invisible_layers)) + def ensure_marker(self): xpath = ".//svg:marker[@id='inkstitch-needle-point']" point_marker = self.document.getroot().xpath(xpath) |
