Stricter locking (lock contained ndarrays and turn lists into tuples)
This commit is contained in:
parent
79990e3806
commit
c79eee2a8c
@ -80,7 +80,7 @@ class Label:
|
||||
offset: vector2 = (0.0, 0.0),
|
||||
layer: layer_t = 0,
|
||||
locked: bool = False):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.identifier = ()
|
||||
self.string = string
|
||||
self.offset = numpy.array(offset, dtype=float, copy=True)
|
||||
@ -156,6 +156,7 @@ class Label:
|
||||
Return:
|
||||
self
|
||||
"""
|
||||
self.offset.flags.writeable = False
|
||||
object.__setattr__(self, 'locked', True)
|
||||
return self
|
||||
|
||||
@ -167,4 +168,5 @@ class Label:
|
||||
self
|
||||
"""
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.offset.flags.writeable = True
|
||||
return self
|
||||
|
@ -71,7 +71,7 @@ class Pattern:
|
||||
name: An identifier for the Pattern
|
||||
locked: Whether to lock the pattern after construction
|
||||
"""
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
if isinstance(shapes, list):
|
||||
self.shapes = shapes
|
||||
else:
|
||||
@ -715,6 +715,9 @@ class Pattern:
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
self.shapes = tuple(self.shapes)
|
||||
self.labels = tuple(self.labels)
|
||||
self.subpatterns = tuple(self.subpatterns)
|
||||
object.__setattr__(self, 'locked', True)
|
||||
return self
|
||||
|
||||
@ -726,6 +729,9 @@ class Pattern:
|
||||
self
|
||||
"""
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.shapes = list(self.shapes)
|
||||
self.labels = list(self.labels)
|
||||
self.subpatterns = list(self.subpatterns)
|
||||
return self
|
||||
|
||||
def deeplock(self) -> 'Pattern':
|
||||
|
@ -121,7 +121,8 @@ class GridRepetition:
|
||||
if b_count < 1:
|
||||
raise PatternError('Repetition has too-small b_count: '
|
||||
'{}'.format(b_count))
|
||||
self.unlock()
|
||||
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.a_vector = a_vector
|
||||
self.b_vector = b_vector
|
||||
self.a_count = a_count
|
||||
@ -481,6 +482,11 @@ class GridRepetition:
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
self.offset.flags.writeable = False
|
||||
self.a_vector.flags.writeable = False
|
||||
self.mirrored.flags.writeable = False
|
||||
if self.b_vector is not None:
|
||||
self.b_vector.flags.writeable = False
|
||||
object.__setattr__(self, 'locked', True)
|
||||
return self
|
||||
|
||||
@ -491,6 +497,11 @@ class GridRepetition:
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
self.offset.flags.writeable = True
|
||||
self.a_vector.flags.writeable = True
|
||||
self.mirrored.flags.writeable = True
|
||||
if self.b_vector is not None:
|
||||
self.b_vector.flags.writeable = True
|
||||
object.__setattr__(self, 'locked', False)
|
||||
return self
|
||||
|
||||
|
@ -158,7 +158,7 @@ class Arc(Shape):
|
||||
layer: layer_t = 0,
|
||||
dose: float = 1.0,
|
||||
locked: bool = False):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.identifier = ()
|
||||
self.radii = radii
|
||||
self.angles = angles
|
||||
@ -386,3 +386,15 @@ class Arc(Shape):
|
||||
|
||||
a.append((a0, a1))
|
||||
return numpy.array(a)
|
||||
|
||||
def lock(self) -> 'Arc':
|
||||
self.radii.flags.writeable = False
|
||||
self.angles.flags.writeable = False
|
||||
Shape.lock(self)
|
||||
return self
|
||||
|
||||
def unlock(self) -> 'Arc':
|
||||
Shape.unlock(self)
|
||||
self.radii.flags.writeable = True
|
||||
self.angles.flags.writeable = True
|
||||
return self
|
||||
|
@ -46,7 +46,7 @@ class Circle(Shape):
|
||||
layer: layer_t = 0,
|
||||
dose: float = 1.0,
|
||||
locked: bool = False):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.identifier = ()
|
||||
self.offset = numpy.array(offset, dtype=float)
|
||||
self.layer = layer
|
||||
|
@ -93,7 +93,7 @@ class Ellipse(Shape):
|
||||
layer: layer_t = 0,
|
||||
dose: float = 1.0,
|
||||
locked: bool = False):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.identifier = ()
|
||||
self.radii = radii
|
||||
self.offset = offset
|
||||
@ -180,3 +180,12 @@ class Ellipse(Shape):
|
||||
(self.offset, scale/norm_value, angle, False, self.dose), \
|
||||
lambda: Ellipse(radii=radii*norm_value, layer=self.layer)
|
||||
|
||||
def lock(self) -> 'Ellipse':
|
||||
self.radii.flags.writeable = False
|
||||
Shape.lock(self)
|
||||
return self
|
||||
|
||||
def unlock(self) -> 'Ellipse':
|
||||
Shape.unlock(self)
|
||||
self.radii.flags.writeable = True
|
||||
return self
|
||||
|
@ -149,7 +149,7 @@ class Path(Shape):
|
||||
dose: float = 1.0,
|
||||
locked: bool = False,
|
||||
):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self._cap_extensions = None # Since .cap setter might access it
|
||||
|
||||
self.identifier = ()
|
||||
@ -394,3 +394,16 @@ class Path(Shape):
|
||||
extensions = numpy.zeros(2)
|
||||
return extensions
|
||||
|
||||
def lock(self) -> 'Path':
|
||||
self.vertices.flags.writeable = False
|
||||
if self.cap_extensions is not None:
|
||||
self.cap_extensions.flags.writeable = False
|
||||
Shape.lock(self)
|
||||
return self
|
||||
|
||||
def unlock(self) -> 'Path':
|
||||
Shape.unlock(self)
|
||||
self.vertices.flags.writeable = True
|
||||
if self.cap_extensions is not None:
|
||||
self.cap_extensions.flags.writeable = True
|
||||
return self
|
||||
|
@ -76,7 +76,7 @@ class Polygon(Shape):
|
||||
dose: float = 1.0,
|
||||
locked: bool = False,
|
||||
):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.identifier = ()
|
||||
self.layer = layer
|
||||
self.dose = dose
|
||||
@ -329,3 +329,13 @@ class Polygon(Shape):
|
||||
'''
|
||||
self.vertices = remove_colinear_vertices(self.vertices, closed_path=True)
|
||||
return self
|
||||
|
||||
def lock(self) -> 'Polygon':
|
||||
self.vertices.flags.writeable = False
|
||||
Shape.lock(self)
|
||||
return self
|
||||
|
||||
def unlock(self) -> 'Polygon':
|
||||
Shape.unlock(self)
|
||||
self.vertices.flags.writeable = True
|
||||
return self
|
||||
|
@ -443,6 +443,7 @@ class Shape(metaclass=ABCMeta):
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
self.offset.flags.writeable = False
|
||||
object.__setattr__(self, 'locked', True)
|
||||
return self
|
||||
|
||||
@ -454,4 +455,5 @@ class Shape(metaclass=ABCMeta):
|
||||
self
|
||||
"""
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.offset.flags.writeable = True
|
||||
return self
|
||||
|
@ -77,7 +77,7 @@ class Text(Shape):
|
||||
dose: float = 1.0,
|
||||
locked: bool = False,
|
||||
):
|
||||
self.unlock()
|
||||
object.__setattr__(self, 'locked', False)
|
||||
self.identifier = ()
|
||||
self.offset = offset
|
||||
self.layer = layer
|
||||
@ -243,3 +243,13 @@ def get_char_as_polygons(font_path: str,
|
||||
polygons = path.to_polygons()
|
||||
|
||||
return polygons, advance
|
||||
|
||||
def lock(self) -> 'Text':
|
||||
self.mirrored.flags.writeable = False
|
||||
Shape.lock(self)
|
||||
return self
|
||||
|
||||
def unlock(self) -> 'Text':
|
||||
Shape.unlock(self)
|
||||
self.mirrored.flags.writeable = True
|
||||
return self
|
||||
|
@ -296,6 +296,8 @@ class SubPattern:
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
self.offset.flags.writeable = False
|
||||
self.mirrored.flags.writeable = False
|
||||
object.__setattr__(self, 'locked', True)
|
||||
return self
|
||||
|
||||
@ -306,6 +308,8 @@ class SubPattern:
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
self.offset.flags.writeable = True
|
||||
self.mirrored.flags.writeable = True
|
||||
object.__setattr__(self, 'locked', False)
|
||||
return self
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user