From 913c2700d1486284dba0583ae1b280b1aa237570 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 29 Jan 2025 12:04:07 -0500 Subject: 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 --- lib/sew_stack/__init__.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/sew_stack/__init__.py (limited to 'lib/sew_stack/__init__.py') diff --git a/lib/sew_stack/__init__.py b/lib/sew_stack/__init__.py new file mode 100644 index 00000000..7f6b2edc --- /dev/null +++ b/lib/sew_stack/__init__.py @@ -0,0 +1,77 @@ +import wx + +from . import stitch_layers +from ..debug.debug import debug +from ..elements import EmbroideryElement +from ..utils import DotDict + + +class SewStack(EmbroideryElement): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.config = DotDict(self.get_json_param('sew_stack', default=dict(layers=list()))) + self.sew_stack_only = self.get_boolean_param('sew_stack_only', False) + + self.layers = [] + for layer_config in self.config.layers: + layer_class = stitch_layers.by_id[layer_config.layer_id] + self.layers.append(layer_class(sew_stack=self, config=layer_config)) + debug.log(f"layer name: {self.layers[-1].name}") + + def move_layer(self, from_index, to_index): + layer = self.layers.pop(from_index) + self.layers.insert(to_index, layer) + + def append_layer(self, layer_class): + new_layer = layer_class(sew_stack=self, config={}) + self.layers.append(new_layer) + return new_layer + + def delete_layer(self, index): + del self.layers[index] + + def save(self): + """Save current configuration of layers to sew_stack SVG attribute""" + self.config.layers = [layer.config for layer in self.layers] + self.set_json_param("sew_stack", self.config) + self.set_param("sew_stack_only", self.sew_stack_only) + + def uses_previous_stitch(self): + if self.config.layers: + return self.config.layers[0].uses_previous_stitch_group + else: + return False + + @property + def first_stitch(self): + # For now, we'll return None, but later on we might let the first + # StitchLayer set the first_stitch. + return None + + def uses_next_element(self): + return True + + def get_cache_key_data(self, previous_stitch, next_element): + return self.config.layers + + def get_default_random_seed(self): + return self.node.get_id() or "" + + def to_stitch_groups(self, previous_stitch_group=None, next_element=None): + stitch_groups = [] + for layer in self.layers: + if layer.enabled: + this_layer_previous_stitch_group = this_layer_next_element = None + + if layer is self.layers[0]: + this_layer_previous_stitch_group = previous_stitch_group + else: + this_layer_previous_stitch_group = stitch_groups[-1] + + if layer is self.layers[-1]: + this_layer_next_element = next_element + + stitch_groups.extend(layer.embroider(this_layer_previous_stitch_group, this_layer_next_element)) + + return stitch_groups -- cgit v1.2.3