kopia lustrzana https://github.com/inkstitch/inkstitch
Stitch plan preview overwrite option (#2642)
rodzic
c3193c6876
commit
d57bbb0f94
|
@ -3,14 +3,13 @@
|
|||
# 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
|
||||
|
||||
from ..marker import set_marker
|
||||
from ..stitch_plan import stitch_groups_to_stitch_plan
|
||||
from ..svg import render_stitch_plan
|
||||
from ..svg.tags import (INKSCAPE_GROUPMODE, INKSTITCH_ATTRIBS,
|
||||
SODIPODI_INSENSITIVE, SVG_DEFS_TAG, SVG_GROUP_TAG,
|
||||
SVG_PATH_TAG)
|
||||
SODIPODI_INSENSITIVE, SVG_GROUP_TAG, SVG_PATH_TAG)
|
||||
from .base import InkstitchExtension
|
||||
from .stitch_plan_preview_undo import reset_stitch_plan
|
||||
|
||||
|
@ -23,16 +22,17 @@ class StitchPlanPreview(InkstitchExtension):
|
|||
self.arg_parser.add_argument("-n", "--needle-points", type=Boolean, default=False, dest="needle_points")
|
||||
self.arg_parser.add_argument("-i", "--insensitive", type=Boolean, default=False, dest="insensitive")
|
||||
self.arg_parser.add_argument("-c", "--visual-commands", type=Boolean, default="symbols", dest="visual_commands")
|
||||
self.arg_parser.add_argument("-o", "--overwrite", type=Boolean, default=True, dest="overwrite")
|
||||
|
||||
def effect(self):
|
||||
# delete old stitch plan
|
||||
svg = self.document.getroot()
|
||||
reset_stitch_plan(svg)
|
||||
self.remove_old()
|
||||
|
||||
# create new stitch plan
|
||||
if not self.get_elements():
|
||||
return
|
||||
|
||||
svg = self.document.getroot()
|
||||
realistic = False
|
||||
visual_commands = self.options.visual_commands
|
||||
self.metadata = self.get_inkstitch_metadata()
|
||||
|
@ -48,6 +48,31 @@ class StitchPlanPreview(InkstitchExtension):
|
|||
# update layer visibility (unchanged, hidden, lower opacity)
|
||||
groups = self.document.getroot().findall(SVG_GROUP_TAG)
|
||||
self.set_invisible_layers_attribute(groups, layer)
|
||||
self.set_visibility(groups, layer)
|
||||
|
||||
self.set_sensitivity(layer)
|
||||
self.translate(svg, layer)
|
||||
self.set_needle_points(layer)
|
||||
|
||||
def remove_old(self):
|
||||
svg = self.document.getroot()
|
||||
if self.options.overwrite:
|
||||
reset_stitch_plan(svg)
|
||||
else:
|
||||
reset_stitch_plan(svg, False)
|
||||
layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
|
||||
if layer is not None:
|
||||
layer.set('id', svg.get_unique_id('inkstitch_stitch_plan_'))
|
||||
|
||||
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))
|
||||
layer.set(INKSTITCH_ATTRIBS['layer_visibility'], self.options.layer_visibility)
|
||||
|
||||
def set_visibility(self, groups, layer):
|
||||
if self.options.layer_visibility == "hidden":
|
||||
self.hide_all_layers()
|
||||
layer.style['display'] = "inline"
|
||||
|
@ -60,49 +85,23 @@ class StitchPlanPreview(InkstitchExtension):
|
|||
float(style.get('opacity', 1)) > 0.4 and not style.get('display', 'inline') == 'none'):
|
||||
g.style['opacity'] = 0.4
|
||||
|
||||
def set_sensitivity(self, layer):
|
||||
if self.options.insensitive is True:
|
||||
layer.set(SODIPODI_INSENSITIVE, True)
|
||||
else:
|
||||
layer.pop(SODIPODI_INSENSITIVE)
|
||||
|
||||
# translate stitch plan to the right side of the canvas
|
||||
def translate(self, svg, layer):
|
||||
if self.options.move_to_side:
|
||||
layer.set('transform', 'translate(%s)' % svg.get('viewBox', '0 0 800 0').split(' ')[2])
|
||||
# translate stitch plan to the right side of the canvas
|
||||
translate = svg.get('viewBox', '0 0 800 0').split(' ')[2]
|
||||
layer.set('transform', f'translate({ translate })')
|
||||
else:
|
||||
layer.set('transform', None)
|
||||
|
||||
# display needle points
|
||||
def set_needle_points(self, layer):
|
||||
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 = 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))
|
||||
layer.set(INKSTITCH_ATTRIBS['layer_visibility'], self.options.layer_visibility)
|
||||
|
||||
def ensure_marker(self):
|
||||
xpath = ".//svg:marker[@id='inkstitch-needle-point']"
|
||||
point_marker = self.document.getroot().xpath(xpath)
|
||||
|
||||
if not point_marker:
|
||||
# get or create def element
|
||||
defs = self.document.find(SVG_DEFS_TAG)
|
||||
if defs is None:
|
||||
defs = etree.SubElement(self.document, SVG_DEFS_TAG)
|
||||
|
||||
# insert marker
|
||||
marker = """<marker
|
||||
orient="auto"
|
||||
id="inkstitch-needle-point">
|
||||
<circle
|
||||
cx="0" cy="0" r="1.5"
|
||||
style="fill:context-stroke;opacity:0.8;" />
|
||||
</marker>"""
|
||||
defs.append(etree.fromstring(marker))
|
||||
set_marker(element, 'start', 'needle-point')
|
||||
set_marker(element, 'mid', 'needle-point')
|
||||
set_marker(element, 'end', 'needle-point')
|
||||
|
|
|
@ -12,14 +12,15 @@ class StitchPlanPreviewUndo(InkstitchExtension):
|
|||
reset_stitch_plan(self.document.getroot())
|
||||
|
||||
|
||||
def reset_stitch_plan(svg):
|
||||
def reset_stitch_plan(svg, delete_stitch_plan=True):
|
||||
# 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:
|
||||
display_method = layer.get(INKSTITCH_ATTRIBS['layer_visibility'], 'unchanged')
|
||||
invisible_layers = layer.get(INKSTITCH_ATTRIBS['invisible_layers'], '').split(",")
|
||||
layer.getparent().remove(layer)
|
||||
if delete_stitch_plan:
|
||||
layer.getparent().remove(layer)
|
||||
|
||||
if display_method == "unchanged":
|
||||
return
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
from copy import deepcopy
|
||||
from os import path
|
||||
|
||||
from inkex import NSS, Style, load_svg
|
||||
from shapely import geometry as shgeo
|
||||
|
||||
import inkex
|
||||
|
||||
from .svg.tags import EMBROIDERABLE_TAGS
|
||||
from .utils import cache, get_bundled_dir
|
||||
|
||||
|
@ -26,18 +25,16 @@ def ensure_marker(svg, marker):
|
|||
def _marker_svg():
|
||||
marker_path = path.join(get_bundled_dir("symbols"), "marker.svg")
|
||||
with open(marker_path) as marker_file:
|
||||
return inkex.load_svg(marker_file).getroot()
|
||||
return load_svg(marker_file).getroot()
|
||||
|
||||
|
||||
def set_marker(node, position, marker):
|
||||
ensure_marker(node.getroottree().getroot(), marker)
|
||||
|
||||
# attach marker to node
|
||||
style = node.get('style') or ''
|
||||
style = style.split(";")
|
||||
style = [i for i in style if not i.startswith('marker-%s' % position)]
|
||||
style.append('marker-%s:url(#inkstitch-%s-marker)' % (position, marker))
|
||||
node.set('style', ";".join(style))
|
||||
style = node.style
|
||||
style += Style(f'marker-{ position }:url(#inkstitch-{ marker }-marker)')
|
||||
node.set('style', style)
|
||||
|
||||
|
||||
def get_marker_elements(node, marker, get_fills=True, get_strokes=True, get_satins=False):
|
||||
|
@ -52,7 +49,7 @@ def get_marker_elements(node, marker, get_fills=True, get_strokes=True, get_sati
|
|||
# do not close marker-start:url(
|
||||
# if the marker group has been copied and pasted in Inkscape it may have been duplicated with an updated id (e.g. -4)
|
||||
xpath = "./parent::svg:g/*[contains(@style, 'marker-start:url(#inkstitch-%s-marker')]" % marker
|
||||
markers = node.xpath(xpath, namespaces=inkex.NSS)
|
||||
markers = node.xpath(xpath, namespaces=NSS)
|
||||
for marker in markers:
|
||||
if marker.tag not in EMBROIDERABLE_TAGS:
|
||||
continue
|
||||
|
|
|
@ -55,6 +55,13 @@
|
|||
id="inkstitch-guide-line-marker-spiral"
|
||||
d="M 1.7506092,6.2728168 3.4558825,5.2833684 7.1038696,7.400035 8.8193256,6.4046783 M 1.7963222,4.129626 3.4558825,3.1667016 7.1038696,5.2833682 8.8475785,4.2716184 M 1.6318889,5.2833683 3.4558825,4.225035 7.1038696,6.3417016 8.9558408,5.2677331" />
|
||||
</g>
|
||||
</marker>
|
||||
</marker>
|
||||
<marker
|
||||
orient="auto"
|
||||
id="inkstitch-needle-point-marker">
|
||||
<circle
|
||||
cx="0" cy="0" r="1.5"
|
||||
style="fill:context-stroke;opacity:0.8;" />
|
||||
</marker>
|
||||
</defs>
|
||||
</svg>
|
||||
|
|
Przed Szerokość: | Wysokość: | Rozmiar: 3.6 KiB Po Szerokość: | Wysokość: | Rozmiar: 3.8 KiB |
|
@ -11,17 +11,24 @@
|
|||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<param name="move-to-side" type="boolean" gui-text="Move stitch plan beside the canvas">true</param>
|
||||
<param name="layer-visibility" type="optiongroup" appearance="combo" gui-text="Design layer visibility">
|
||||
<option value="unchanged">Unchanged</option>
|
||||
<option value="hidden">Hidden</option>
|
||||
<option value="lower_opacity">Lower opacity</option>
|
||||
</param>
|
||||
<spacer />
|
||||
<separator />
|
||||
<spacer />
|
||||
<param name="move-to-side" type="boolean" gui-text="Move stitch plan beside the canvas">true</param>
|
||||
<param name="needle-points" type="boolean" gui-text="Needle points">false</param>
|
||||
<param name="insensitive" type="boolean" gui-text="Lock"
|
||||
gui-description="Make stitch plan insensitive to mouse interactions">false</param>
|
||||
<param name="visual-commands" type="boolean" gui-text="Display command symbols">false</param>
|
||||
<spacer />
|
||||
<separator />
|
||||
<spacer />
|
||||
<param name="overwrite" type="boolean" gui-text="Override last stitch plan">true</param>
|
||||
<spacer />
|
||||
<script>
|
||||
{{ command_tag | safe }}
|
||||
</script>
|
||||
|
|
Ładowanie…
Reference in New Issue