summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/elements/element.py4
-rw-r--r--lib/stitch_plan/lock_stitch.py42
2 files changed, 19 insertions, 27 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 269cbdc2..9363495b 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -476,12 +476,12 @@ class EmbroideryElement(object):
if tie_modus in [0, 1]:
lock_start = LockStitch('start', self.lock_start, scale_percent=self.lock_start_scale_percent, scale_absolute=self.lock_start_scale_mm)
if self.lock_start == "custom":
- lock_start.path = self.lock_custom_start
+ lock_start.set_path(self.lock_custom_start)
if tie_modus in [0, 2] or force:
lock_end = LockStitch('end', self.lock_end, scale_percent=self.lock_end_scale_percent, scale_absolute=self.lock_end_scale_mm)
if self.lock_end == "custom":
- lock_end.path = self.lock_custom_end
+ lock_end.set_path(self.lock_custom_end)
return lock_start, lock_end
diff --git a/lib/stitch_plan/lock_stitch.py b/lib/stitch_plan/lock_stitch.py
index 4e1d347b..bf760923 100644
--- a/lib/stitch_plan/lock_stitch.py
+++ b/lib/stitch_plan/lock_stitch.py
@@ -4,6 +4,7 @@ from math import degrees
from inkex import DirectedLineSegment, Path
from shapely.geometry import LineString
+from ..debug import debug
from ..i18n import _
from ..svg import PIXELS_PER_MM
from ..utils import string_to_floats
@@ -20,7 +21,7 @@ class LockStitchDefinition:
def __repr__(self):
return "LockStitchDefinition(%s, %s, %s, %s)" % (self.id, self.name, self._path, self.preview_image)
- def stitches(self):
+ def stitches(self, stitches, pos, scale):
raise NotImplementedError(f"{self.__class__.__name__} must implement stitches()")
@@ -29,6 +30,9 @@ class LockStitch:
self.lock_stitch_definition = get_lock_stitch_definition_by_id(lock_type, lock_id)
self.scale = LockStitchScale(scale_percent, scale_absolute)
+ def set_path(self, path):
+ self.lock_stitch_definition = CustomLock("custom", _("Custom"), path)
+
def stitches(self, stitches, pos):
return self.lock_stitch_definition.stitches(stitches, pos, self.scale)
@@ -40,43 +44,31 @@ class LockStitchScale:
class CustomLock(LockStitchDefinition):
- @property
- def path(self):
- return self._path
-
- @path.setter
- def path(self, path):
- path_type = self._get_path_type(path)
- if path_type in ['svg', 'absolute']:
- self._path = path
- else:
- self._path = None
-
def stitches(self, stitches, pos, scale):
- if self.path is None:
- return half_stitch.stitches(stitches, pos)
-
- path_type = self._get_path_type(self.path)
+ path_type = self._get_path_type()
+ debug.log(f"CustomLock path={self._path} path_type={path_type}")
if path_type == "svg":
return SVGLock(self.id,
self.name,
- self.path).stitches(stitches, pos, scale.percent)
- else:
+ self._path).stitches(stitches, pos, scale)
+ elif path_type == "absolute":
return AbsoluteLock(self.id,
self.name,
- self.path).stitches(stitches, pos, scale.absolute)
+ self._path).stitches(stitches, pos, scale)
+ else:
+ return half_stitch.stitches(stitches, pos, scale)
- def _get_path_type(self, path):
- if not path:
+ def _get_path_type(self):
+ if not self._path:
return "invalid"
- if not re.match("^ *[0-9 .,-]*$", path):
- path = Path(path)
+ if not re.match("^ *[0-9 .,-]*$", self._path):
+ path = Path(self._path)
if not path or len(list(path.end_points)) < 3:
return None
else:
return "svg"
else:
- path = string_to_floats(path, " ")
+ path = string_to_floats(self._path, " ")
if not path:
return "invalid"
else: