summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/stitch_plan_preview.py18
-rw-r--r--lib/svg/rendering.py19
2 files changed, 23 insertions, 14 deletions
diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py
index 0a7a4f28..12766ad7 100644
--- a/lib/extensions/stitch_plan_preview.py
+++ b/lib/extensions/stitch_plan_preview.py
@@ -3,19 +3,21 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-from tempfile import TemporaryDirectory
+import sys
from base64 import b64encode
+from tempfile import TemporaryDirectory
from typing import Optional, Tuple
-import sys
-from inkex import errormsg, Boolean, Image, BaseElement
+from inkex import BaseElement, Boolean, Image, errormsg
from inkex.command import inkscape
+from ..commands import add_layer_commands
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_GROUP_TAG, SVG_PATH_TAG, XLINK_HREF)
+ SODIPODI_INSENSITIVE, SVG_GROUP_TAG, SVG_PATH_TAG,
+ XLINK_HREF)
from .base import InkstitchExtension
from .stitch_plan_preview_undo import reset_stitch_plan
@@ -28,8 +30,10 @@ 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")
+ self.arg_parser.add_argument("-j", "--render-jumps", type=Boolean, default=True, dest="render_jumps")
self.arg_parser.add_argument("-m", "--render-mode", type=str, default="simple", dest="mode")
+ self.arg_parser.add_argument("-l", "--ignore-layer", type=Boolean, default=True, dest="ignore_layer")
+ self.arg_parser.add_argument("-o", "--overwrite", type=Boolean, default=True, dest="overwrite")
def effect(self):
realistic, raster_mult = self.parse_mode()
@@ -49,7 +53,9 @@ class StitchPlanPreview(InkstitchExtension):
stitch_groups = self.elements_to_stitch_groups(self.elements)
stitch_plan = stitch_groups_to_stitch_plan(stitch_groups, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
- layer = render_stitch_plan(svg, stitch_plan, realistic, visual_commands)
+ layer = render_stitch_plan(svg, stitch_plan, realistic, visual_commands, render_jumps=self.options.render_jumps)
+ if self.options.ignore_layer:
+ add_layer_commands(layer, ["ignore_layer"])
layer = self.rasterize(svg, layer, raster_mult)
# update layer visibility (unchanged, hidden, lower opacity)
diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py
index 4b9eda49..6696597e 100644
--- a/lib/svg/rendering.py
+++ b/lib/svg/rendering.py
@@ -131,7 +131,7 @@ def realistic_stitch(start, end):
return str(path)
-def color_block_to_point_lists(color_block):
+def color_block_to_point_lists(color_block, render_jumps=True):
point_lists = [[]]
for stitch in color_block:
@@ -139,6 +139,9 @@ def color_block_to_point_lists(color_block):
if point_lists[-1]:
point_lists.append([])
continue
+ if stitch.jump and not render_jumps and point_lists[-1]:
+ point_lists.append([])
+ continue
if not stitch.jump and not stitch.color_change and not stitch.stop:
point_lists[-1].append(stitch.as_tuple())
@@ -159,8 +162,8 @@ def get_correction_transform(svg):
return str(transform)
-def color_block_to_realistic_stitches(color_block, svg, destination):
- for point_list in color_block_to_point_lists(color_block):
+def color_block_to_realistic_stitches(color_block, svg, destination, render_jumps=True):
+ for point_list in color_block_to_point_lists(color_block, render_jumps):
color = color_block.color.visible_on_white.darker.to_hex_str()
start = point_list[0]
for point in point_list[1:]:
@@ -172,7 +175,7 @@ def color_block_to_realistic_stitches(color_block, svg, destination):
start = point
-def color_block_to_paths(color_block, svg, destination, visual_commands):
+def color_block_to_paths(color_block, svg, destination, visual_commands, render_jumps=True):
# If we try to import these above, we get into a mess of circular
# imports.
from ..commands import add_commands
@@ -182,7 +185,7 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
# emitting multiple paths makes it easier for the user to manipulate them.
first = True
path = None
- for point_list in color_block_to_point_lists(color_block):
+ for point_list in color_block_to_point_lists(color_block, render_jumps):
if first:
first = False
elif visual_commands:
@@ -213,7 +216,7 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
path.set(INKSTITCH_ATTRIBS['stop_after'], 'true')
-def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True) -> inkex.Group:
+def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True, render_jumps=True) -> inkex.Group:
layer = svg.findone(".//*[@id='__inkstitch_stitch_plan__']")
if layer is None:
layer = inkex.Group(attrib={
@@ -237,9 +240,9 @@ def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True)
})
layer.append(group)
if realistic:
- color_block_to_realistic_stitches(color_block, svg, group)
+ color_block_to_realistic_stitches(color_block, svg, group, render_jumps)
else:
- color_block_to_paths(color_block, svg, group, visual_commands)
+ color_block_to_paths(color_block, svg, group, visual_commands, render_jumps)
if realistic:
# Remove filter from defs, if any