summaryrefslogtreecommitdiff
path: root/lib/elements
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2025-01-29 12:04:07 -0500
committerGitHub <noreply@github.com>2025-01-29 12:04:07 -0500
commit913c2700d1486284dba0583ae1b280b1aa237570 (patch)
treec165b29d0794981b5e44ab46f9838baab16b06a4 /lib/elements
parentefe3b27f17686094f74462bd81763a8197b54c6e (diff)
Sew Stack first steps (#3133)
* handle more recursive cases * scaffolding for stitch layers * scaffolding for SewStack * always use DotDict when parsing json params * add DefaultDotDict + DotDict fixes * first working SewStack (no UI yet) * ignore inkstitch_debug.log and .svg * refactor * early WIP: property grid display temporarily in stitch plan preview * start of sew stack editor extension * add layer properties panel and splitter * spacing and better icon * handle checkbox * add layer action buttons * show selected property help text in an HtmlWindow * rename * rephrase help text for tolerance * refactor into separate file * simplify structure * better property type handling * add randomization button * add random seed re-roll button * simulator preview * update preview in a few more cases * always DotDict * avoid ridiculously slow simulations * preview selected layer or all layers * edit multiple objects and save only modified properties into the SVG * better preview handling * add reverse and jitter * add stitch path jitter * fix types * fix random shuffle button * fixes * fix repeats * type hinting to please pycharm * show layer description * avoid exception in properties with multiple values * fix typing * fix new layer * draw a box around property grid and help box * confirm before closing * rename properties and fix seed * fix close/cancel logic * add buttons to undo changes and reset to default value * set not modified if default is original setting * fix invisible icon * more space for properties * fix random properties * better regulation of simulator rendering speed * Fixed timer being passed a float * fix get_json_param() default handling * fix tests * add checkbox for sew stack only * fix property help * adjustable stitch layer editor help box size, with persistence * repeat exact stitches * "fix" style * adjust for new next_element stuff --------- Co-authored-by: CapellanCitizen <thecapellancitizen@gmail.com>
Diffstat (limited to 'lib/elements')
-rw-r--r--lib/elements/element.py17
-rw-r--r--lib/elements/utils.py29
2 files changed, 34 insertions, 12 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 0846b7ab..ea2d5d6b 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -2,6 +2,7 @@
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+import json
import sys
from contextlib import contextmanager
from copy import deepcopy
@@ -25,7 +26,7 @@ from ..stitch_plan.lock_stitch import (LOCK_DEFAULTS, AbsoluteLock, CustomLock,
from ..svg import (PIXELS_PER_MM, apply_transforms, convert_length,
get_node_transform)
from ..svg.tags import INKSCAPE_LABEL, INKSTITCH_ATTRIBS
-from ..utils import Point, cache
+from ..utils import DotDict, Point, cache
from ..utils.cache import (CacheKeyGenerator, get_stitch_plan_cache,
is_cache_disabled)
@@ -159,6 +160,20 @@ class EmbroideryElement(object):
return [int(default)]
return params
+ def get_json_param(self, param, default=None):
+ json_value = self.get_param(param, None)
+ try:
+ return json.loads(json_value, object_hook=DotDict)
+ except (json.JSONDecodeError, TypeError):
+ if default is None:
+ return DotDict()
+ else:
+ return DotDict(default)
+
+ def set_json_param(self, param, value):
+ json_value = json.dumps(value)
+ self.set_param(param, json_value)
+
def set_param(self, name, value):
# Sets a param on the node backing this element. Used by params dialog.
# After calling, this element is invalid due to caching and must be re-created to use the new value.
diff --git a/lib/elements/utils.py b/lib/elements/utils.py
index 09d24935..a3de62e9 100644
--- a/lib/elements/utils.py
+++ b/lib/elements/utils.py
@@ -37,18 +37,25 @@ def node_to_elements(node, clone_to_element=False) -> List[EmbroideryElement]:
return [MarkerObject(node)]
elif node.tag in EMBROIDERABLE_TAGS or is_clone(node):
- element = EmbroideryElement(node)
-
elements = []
- if element.get_style("fill", "black") and not element.get_style('fill-opacity', 1) == "0":
- elements.append(FillStitch(node))
- if element.get_style("stroke"):
- if element.get_boolean_param("satin_column") and len(element.path) > 1:
- elements.append(SatinColumn(node))
- elif not is_command(element.node):
- elements.append(Stroke(node))
- if element.get_boolean_param("stroke_first", False):
- elements.reverse()
+
+ from ..sew_stack import SewStack
+ sew_stack = SewStack(node)
+
+ if not sew_stack.sew_stack_only:
+ element = EmbroideryElement(node)
+ if element.get_style("fill", "black") and not element.get_style('fill-opacity', 1) == "0":
+ elements.append(FillStitch(node))
+ if element.get_style("stroke"):
+ if element.get_boolean_param("satin_column") and len(element.path) > 1:
+ elements.append(SatinColumn(node))
+ elif not is_command(element.node):
+ elements.append(Stroke(node))
+ if element.get_boolean_param("stroke_first", False):
+ elements.reverse()
+
+ elements.append(sew_stack)
+
return elements
elif node.tag == SVG_IMAGE_TAG: