kopia lustrzana https://github.com/inkstitch/inkstitch
StitchGroups now contain only Stitches
rodzic
8fc42628e2
commit
28e394b2ae
|
@ -112,15 +112,11 @@ class ColorBlock(object):
|
|||
args = (self.last_stitch.x, self.last_stitch.y)
|
||||
else:
|
||||
raise ValueError("internal error: can't add a command to an empty stitch block")
|
||||
|
||||
self.stitches.append(Stitch(*args, **kwargs))
|
||||
if isinstance(args[0], Stitch):
|
||||
self.stitches.append(args[0])
|
||||
elif isinstance(args[0], Point):
|
||||
self.stitches.append(Stitch(args[0].x, args[0].y, *args[1:], **kwargs))
|
||||
else:
|
||||
if not args and self.last_stitch:
|
||||
args = (self.last_stitch.x, self.last_stitch.y)
|
||||
self.stitches.append(Stitch(*args, **kwargs))
|
||||
|
||||
def add_stitches(self, stitches, *args, **kwargs):
|
||||
for stitch in stitches:
|
||||
|
|
|
@ -4,13 +4,25 @@
|
|||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||
|
||||
from ..utils.geometry import Point
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
class Stitch(Point):
|
||||
"""A stitch is a Point with extra information telling how to sew it."""
|
||||
|
||||
def __init__(self, x, y=None, color=None, jump=False, stop=False, trim=False, color_change=False, tie_modus=0, no_ties=False, tags=None):
|
||||
Point.__init__(self, x, y)
|
||||
if isinstance(x, Stitch):
|
||||
# Allow creating a Stitch from another Stitch. Attributes passed as
|
||||
# arguments will override any existing attributes.
|
||||
vars(self).update(deepcopy(vars(x)))
|
||||
elif isinstance(x, Point):
|
||||
# Allow creating a Stitch from a Point
|
||||
point = x
|
||||
self.x = point.x
|
||||
self.y = point.y
|
||||
else:
|
||||
Point.__init__(self, x, y)
|
||||
|
||||
self.color = color
|
||||
self.jump = jump
|
||||
self.trim = trim
|
||||
|
@ -22,12 +34,6 @@ class Stitch(Point):
|
|||
|
||||
self.add_tags(tags or [])
|
||||
|
||||
# Allow creating a Stitch from a Point
|
||||
if isinstance(x, Point):
|
||||
point = x
|
||||
self.x = point.x
|
||||
self.y = point.y
|
||||
|
||||
def __repr__(self):
|
||||
return "Stitch(%s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.x,
|
||||
self.y,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from .stitch import Stitch
|
||||
|
||||
|
||||
class StitchGroup:
|
||||
"""A collection of Stitch objects with attached instructions.
|
||||
"""A collection of Stitch objects with attached instructions and attributes.
|
||||
|
||||
StitchGroups will later be combined to make ColorBlocks, which in turn are
|
||||
combined to make a StitchPlan. Jump stitches are allowed between
|
||||
|
@ -11,11 +14,14 @@ class StitchGroup:
|
|||
|
||||
def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, tie_modus=0, stitch_as_is=False):
|
||||
self.color = color
|
||||
self.stitches = stitches or []
|
||||
self.trim_after = trim_after
|
||||
self.stop_after = stop_after
|
||||
self.tie_modus = tie_modus
|
||||
self.stitch_as_is = stitch_as_is
|
||||
self.stitches = []
|
||||
|
||||
if stitches:
|
||||
self.add_stitches(stitches)
|
||||
|
||||
def __add__(self, other):
|
||||
if isinstance(other, StitchGroup):
|
||||
|
@ -27,7 +33,15 @@ class StitchGroup:
|
|||
# This method allows `len(patch)` and `if patch:
|
||||
return len(self.stitches)
|
||||
|
||||
def add_stitches(self, stitches):
|
||||
for stitch in stitches:
|
||||
self.add_stitch(stitch)
|
||||
|
||||
def add_stitch(self, stitch):
|
||||
if not isinstance(stitch, Stitch):
|
||||
# probably a Point
|
||||
stitch = Stitch(stitch)
|
||||
|
||||
self.stitches.append(stitch)
|
||||
|
||||
def reverse(self):
|
||||
|
|
Ładowanie…
Reference in New Issue