summaryrefslogtreecommitdiff
path: root/lib/elements
diff options
context:
space:
mode:
authorKaalleen <reni@allenka.de>2021-06-30 14:05:13 +0200
committerKaalleen <reni@allenka.de>2021-06-30 14:05:13 +0200
commit52d9ee6a6d97b2ea752f5fdd3080a160a3574f82 (patch)
tree8d68fed81c1771b73bded23eef69b0969a1702e9 /lib/elements
parenta152e1edea19ae16f8226032f9cd2ded004b168c (diff)
structuring
Diffstat (limited to 'lib/elements')
-rw-r--r--lib/elements/element.py50
-rw-r--r--lib/elements/pattern.py7
-rw-r--r--lib/elements/utils.py3
3 files changed, 4 insertions, 56 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index aa0c4795..dc466fbf 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -9,10 +9,10 @@ from copy import deepcopy
import inkex
import tinycss2
from inkex import bezier
-from shapely import geometry as shgeo
from ..commands import find_commands
from ..i18n import _
+from ..patterns import apply_patterns
from ..svg import (PIXELS_PER_MM, apply_transforms, convert_length,
get_node_transform)
from ..svg.tags import (EMBROIDERABLE_TAGS, INKSCAPE_LABEL, INKSTITCH_ATTRIBS,
@@ -331,52 +331,6 @@ class EmbroideryElement(object):
else:
return None
- @cache
- def get_patterns(self):
- xpath = "./parent::svg:g/*[contains(@style, 'marker-start:url(#inkstitch-pattern-marker)')]"
- patterns = self.node.xpath(xpath, namespaces=inkex.NSS)
- line_strings = []
- for pattern in patterns:
- if pattern.tag not in EMBROIDERABLE_TAGS:
- continue
- d = pattern.get_path()
- path = inkex.paths.Path(d).to_superpath()
- path = apply_transforms(path, pattern)
- path = self.flatten(path)
- lines = [shgeo.LineString(p) for p in path]
- for line in lines:
- line_strings.append(line)
- return shgeo.MultiLineString(line_strings)
-
- def _apply_patterns(self, patches):
- patterns = self.get_patterns()
- if not patterns:
- return patches
-
- patch_points = []
- for patch in patches:
- for i, stitch in enumerate(patch.stitches):
- patch_points.append(stitch)
- if i == len(patch.stitches) - 1:
- continue
- intersection_points = self._get_pattern_points(stitch, patch.stitches[i+1], patterns)
- for point in intersection_points:
- patch_points.append(point)
- patch.stitches = patch_points
-
- def _get_pattern_points(self, first, second, patterns):
- points = []
- for pattern in patterns:
- intersection = shgeo.LineString([first, second]).intersection(pattern)
- if isinstance(intersection, shgeo.Point):
- points.append(Point(intersection.x, intersection.y))
- if isinstance(intersection, shgeo.MultiPoint):
- for point in intersection:
- points.append(Point(point.x, point.y))
- # sort points after their distance to left
- points.sort(key=lambda point: point.distance(first))
- return points
-
def strip_control_points(self, subpath):
return [point for control_before, point, control_after in subpath]
@@ -409,7 +363,7 @@ class EmbroideryElement(object):
self.validate()
patches = self.to_patches(last_patch)
- self._apply_patterns(patches)
+ apply_patterns(patches, self.node)
for patch in patches:
patch.tie_modus = self.ties
diff --git a/lib/elements/pattern.py b/lib/elements/pattern.py
index fa54b7ba..98f29456 100644
--- a/lib/elements/pattern.py
+++ b/lib/elements/pattern.py
@@ -6,7 +6,6 @@
import inkex
from ..i18n import _
-from ..svg.tags import EMBROIDERABLE_TAGS
from .element import EmbroideryElement
from .validation import ObjectTypeWarning
@@ -31,9 +30,3 @@ class PatternObject(EmbroideryElement):
def to_patches(self, last_patch):
return []
-
-
-def is_pattern(node):
- if node.tag not in EMBROIDERABLE_TAGS:
- return False
- return "marker-start:url(#inkstitch-pattern-marker)" in node.get('style', '')
diff --git a/lib/elements/utils.py b/lib/elements/utils.py
index cd87cec8..99df7002 100644
--- a/lib/elements/utils.py
+++ b/lib/elements/utils.py
@@ -4,6 +4,7 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
from ..commands import is_command
+from ..patterns import is_pattern
from ..svg.tags import (EMBROIDERABLE_TAGS, SVG_IMAGE_TAG, SVG_PATH_TAG,
SVG_POLYLINE_TAG, SVG_TEXT_TAG)
from .auto_fill import AutoFill
@@ -12,7 +13,7 @@ from .element import EmbroideryElement
from .empty_d_object import EmptyDObject
from .fill import Fill
from .image import ImageObject
-from .pattern import PatternObject, is_pattern
+from .pattern import PatternObject
from .polyline import Polyline
from .satin_column import SatinColumn
from .stroke import Stroke