From ef7d056173cc6d7782d6120c031dae9276725a3d Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:19:35 +0100 Subject: End points (#3370) * end at nearest point to next element (if requested and possible) --- lib/elements/clone.py | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'lib/elements/clone.py') diff --git a/lib/elements/clone.py b/lib/elements/clone.py index 770fcc0c..0db8bf4c 100644 --- a/lib/elements/clone.py +++ b/lib/elements/clone.py @@ -35,7 +35,8 @@ class CloneWarning(ValidationWarning): class Clone(EmbroideryElement): - element_name = "Clone" + name = "Clone" + element_name = _("Clone") def __init__(self, *args, **kwargs): super(Clone, self).__init__(*args, **kwargs) @@ -66,10 +67,10 @@ class Clone(EmbroideryElement): def flip_angle(self): return self.get_boolean_param('flip_angle', False) - def get_cache_key_data(self, previous_stitch): + def get_cache_key_data(self, previous_stitch, next_element): source_node = self.node.href source_elements = self.clone_to_elements(source_node) - return [element.get_cache_key(previous_stitch) for element in source_elements] + return [element.get_cache_key(previous_stitch, next_element) for element in source_elements] def clone_to_elements(self, node) -> List[EmbroideryElement]: # Only used in get_cache_key_data, actual embroidery uses nodes_to_elements+iterate_nodes @@ -82,22 +83,53 @@ class Clone(EmbroideryElement): elements.extend(node_to_elements(child, True)) return elements - def to_stitch_groups(self, last_stitch_group=None) -> List[StitchGroup]: + def to_stitch_groups(self, last_stitch_group=None, next_element=None) -> List[StitchGroup]: if not self.clone: return [] with self.clone_elements() as elements: + if not elements: + return [] stitch_groups = [] - for element in elements: + next_elements = [next_element] + if len(elements) > 1: + next_elements = elements[1:] + next_elements + for element, next_element in zip(elements, next_elements): # Using `embroider` here to get trim/stop after commands, etc. - element_stitch_groups = element.embroider(last_stitch_group) + element_stitch_groups = element.embroider(last_stitch_group, next_element) if len(element_stitch_groups): last_stitch_group = element_stitch_groups[-1] stitch_groups.extend(element_stitch_groups) return stitch_groups + @property + def first_stitch(self): + first, last = self.first_and_last_element() + if first: + return first.first_stitch + return None + + def uses_previous_stitch(self): + first, last = self.first_and_last_element() + if first: + return first.uses_previous_stitch() + return None + + def uses_next_element(self): + first, last = self.first_and_last_element() + if last: + return last.uses_next_element() + return None + + @cache + def first_and_last_element(self): + with self.clone_elements() as elements: + if len(elements): + return elements[0], elements[-1] + return None, None + @contextmanager def clone_elements(self) -> Generator[List[EmbroideryElement], None, None]: """ -- cgit v1.2.3