diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2025-01-29 12:04:07 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-29 12:04:07 -0500 |
| commit | 913c2700d1486284dba0583ae1b280b1aa237570 (patch) | |
| tree | c165b29d0794981b5e44ab46f9838baab16b06a4 /lib/sew_stack/stitch_layers/stitch_layer.py | |
| parent | efe3b27f17686094f74462bd81763a8197b54c6e (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/sew_stack/stitch_layers/stitch_layer.py')
| -rw-r--r-- | lib/sew_stack/stitch_layers/stitch_layer.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/sew_stack/stitch_layers/stitch_layer.py b/lib/sew_stack/stitch_layers/stitch_layer.py new file mode 100644 index 00000000..4b34373a --- /dev/null +++ b/lib/sew_stack/stitch_layers/stitch_layer.py @@ -0,0 +1,85 @@ +from ...utils import coordinate_list_to_point_list +from ...utils.dotdict import DotDict + + +class StitchLayer: + # must be overridden in child classes and set to a subclass of StitchLayerEditor + editor_class = None + + # not to be overridden in child classes + _defaults = None + + def __init__(self, *args, config, sew_stack=None, change_callback=None, **kwargs): + self.config = DotDict(self.defaults) + self.config.layer_id = self.layer_id + self.config.update(config) + self.element = sew_stack + + super().__init__(*args, **kwargs) + + @classmethod + @property + def defaults(cls): + # Implement this in each child class. Return a dict with default + # values for all properties used in this layer. + raise NotImplementedError(f"{cls.__name__} must implement class property: defaults") + + @classmethod + @property + def layer_id(my_class): + """Get the internal layer ID + + Internal layer ID is not shown to users and is used to identify the + layer class when loading a SewStack. + + Example: + class RunningStitchLayer(StitchLayer): ... + layer_id = RunningStitch + """ + + if my_class.__name__.endswith('Layer'): + return my_class.__name__[:-5] + else: + return my_class.__name__ + + @property + def name(self): + return self.config.get('name', self.default_layer_name) + + @name.setter + def name(self, value): + self.config.name = value + + @property + def default_layer_name(self): + # defaults to the same as the layer type name but can be overridden in a child class + return self.layer_type_name + + @property + def layer_type_name(self): + raise NotImplementedError(f"{self.__class__.__name__} must implement type_name property!") + + @property + def enabled(self): + return self.config.get('enabled', True) + + def enable(self, enabled=True): + self.config.enabled = enabled + + @property + def paths(self): + return [coordinate_list_to_point_list(path) for path in self.element.paths] + + @property + def stroke_color(self): + return self.element.get_style("stroke") + + @property + def fill_color(self): + return self.element.get_style("stroke") + + def to_stitch_groups(self, *args): + raise NotImplementedError(f"{self.__class__.__name__} must implement to_stitch_groups()!") + + def embroider(self, last_stitch_group, next_element): + return self.to_stitch_groups(last_stitch_group, next_element) |
