From 4c845df846889e50016bcc0a7d56df5d01102fdf Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Tue, 22 Nov 2022 09:50:21 +0100 Subject: small zigzag warning (#1891) --- lib/elements/stroke.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py index ce973c0e..2854adaf 100644 --- a/lib/elements/stroke.py +++ b/lib/elements/stroke.py @@ -39,6 +39,14 @@ class MultipleGuideLineWarning(ValidationWarning): ] +class SmallZigZagWarning(ValidationWarning): + name = _("Small ZigZag") + description = _("This zig zag stitch has a stroke width smaller than 0.5 units.") + steps_to_solve = [ + _("Set your stroke to be dashed to indicate running stitch. Any kind of dash will work.") + ] + + class Stroke(EmbroideryElement): element_name = _("Stroke") @@ -481,6 +489,15 @@ class Stroke(EmbroideryElement): return guide_lines['satin'][0] return guide_lines['stroke'][0] + def _representative_point(self): + # if we just take the center of a line string we could end up on some point far away from the actual line + try: + coords = list(self.shape.coords) + except NotImplementedError: + # linear rings to not have a coordinate sequence + coords = list(self.shape.exterior.coords) + return coords[int(len(coords)/2)] + def validation_warnings(self): if self.stroke_method == 1 and self.skip_start + self.skip_end >= self.line_count: yield IgnoreSkipValues(self.shape.centroid) @@ -489,4 +506,8 @@ class Stroke(EmbroideryElement): if self.stroke_method == 1: guide_lines = get_marker_elements(self.node, "guide-line", False, True, True) if sum(len(x) for x in guide_lines.values()) > 1: - yield MultipleGuideLineWarning(self.shape.centroid) + yield MultipleGuideLineWarning(self._representative_point()) + + stroke_width, units = parse_length_with_units(self.get_style("stroke-width", "1")) + if not self.dashed and stroke_width <= 0.5: + yield SmallZigZagWarning(self._representative_point()) -- cgit v1.2.3