kicad: Make point lists more ergonomic
This commit removes the unnecessary "PointList" wrapper class, and just puts regular python lists in its place.
This commit is contained in:
parent
d7efa57732
commit
754c9557e5
5 changed files with 29 additions and 22 deletions
|
|
@ -270,7 +270,14 @@ class XYCoord:
|
|||
|
||||
@sexp_type('pts')
|
||||
class PointList:
|
||||
xy : List(XYCoord) = field(default_factory=list)
|
||||
@classmethod
|
||||
def __map__(kls, obj, parent=None):
|
||||
_tag, *values = obj
|
||||
return [map_sexp(XYCoord, elem, parent=parent) for elem in values]
|
||||
|
||||
@classmethod
|
||||
def __sexp__(kls, value):
|
||||
yield [kls.name_atom, *(e for elem in value for e in elem.__sexp__(elem))]
|
||||
|
||||
|
||||
@sexp_type('arc')
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ class Arc:
|
|||
|
||||
@sexp_type('fp_poly')
|
||||
class Polygon:
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
layer: Named(str) = None
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
width: Named(float) = None
|
||||
|
|
@ -253,13 +253,13 @@ class Polygon:
|
|||
tstamp: Timestamp = None
|
||||
|
||||
def render(self, variables=None, cache=None):
|
||||
if len(self.pts.xy) < 2:
|
||||
if len(self.pts) < 2:
|
||||
return
|
||||
|
||||
dasher = Dasher(self)
|
||||
start = self.pts.xy[0]
|
||||
start = self.pts[0]
|
||||
dasher.move(start.x, start.y)
|
||||
for point in self.pts.xy[1:]:
|
||||
for point in self.pts[1:]:
|
||||
dasher.line(point.x, point.y)
|
||||
|
||||
if dasher.width > 0:
|
||||
|
|
@ -268,12 +268,12 @@ class Polygon:
|
|||
yield go.Line(x1, -y1, x2, -y2, aperture=aperture, unit=MM)
|
||||
|
||||
if self.fill == Atom.solid:
|
||||
yield go.Region([(pt.x, -pt.y) for pt in self.pts.xy], unit=MM)
|
||||
yield go.Region([(pt.x, -pt.y) for pt in self.pts], unit=MM)
|
||||
|
||||
|
||||
@sexp_type('fp_curve')
|
||||
class Curve:
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
layer: Named(str) = None
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
width: Named(float) = None
|
||||
|
|
@ -314,7 +314,7 @@ class Dimension:
|
|||
layer: Named(str) = None
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
tstamp: Timestamp = None
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
height: Named(float) = None
|
||||
orientation: Named(int) = 0
|
||||
leader_length: Named(float) = None
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class TextBox(BBoxMixin):
|
|||
text: str = ''
|
||||
start: Named(XYCoord) = None
|
||||
end: Named(XYCoord) = None
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
angle: OmitDefault(Named(float)) = 0.0
|
||||
layer: Named(str) = ""
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
|
|
@ -55,7 +55,7 @@ class TextBox(BBoxMixin):
|
|||
raise ValueError('Vector font text with empty render cache')
|
||||
|
||||
for poly in render_cache.polygons:
|
||||
reg = go.Region([(p.x, -p.y) for p in poly.pts.xy], unit=MM)
|
||||
reg = go.Region([(p.x, -p.y) for p in poly.pts], unit=MM)
|
||||
|
||||
if self.stroke:
|
||||
if self.stroke.type not in (None, Atom.default, Atom.solid):
|
||||
|
|
@ -263,12 +263,12 @@ class Polygon(BBoxMixin):
|
|||
yield reg
|
||||
|
||||
def offset(self, x=0, y=0):
|
||||
self.pts = PointList([pt.with_offset(x, y) for pt in self.pts])
|
||||
self.pts = [pt.with_offset(x, y) for pt in self.pts]
|
||||
|
||||
|
||||
@sexp_type('gr_curve')
|
||||
class Curve(BBoxMixin):
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
layer: Named(str) = None
|
||||
width: Named(float) = None
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
|
|
@ -278,7 +278,7 @@ class Curve(BBoxMixin):
|
|||
raise NotImplementedError('Bezier rendering is not yet supported. Please raise an issue and provide an example file.')
|
||||
|
||||
def offset(self, x=0, y=0):
|
||||
self.pts = PointList([pt.with_offset(x, y) for pt in self.pts])
|
||||
self.pts =[pt.with_offset(x, y) for pt in self.pts]
|
||||
|
||||
|
||||
@sexp_type('gr_bbox')
|
||||
|
|
@ -335,7 +335,7 @@ class Dimension:
|
|||
layer: Named(str) = 'Dwgs.User'
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
tstamp: Timestamp = field(default_factory=Timestamp)
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
height: Named(float) = None
|
||||
orientation: Named(int) = None
|
||||
leader_length: Named(float) = None
|
||||
|
|
@ -347,5 +347,5 @@ class Dimension:
|
|||
raise NotImplementedError('Dimension rendering is not yet supported. Please raise an issue.')
|
||||
|
||||
def offset(self, x=0, y=0):
|
||||
self.pts = PointList([pt.with_offset(x, y) for pt in self.pts])
|
||||
self.pts = [pt.with_offset(x, y) for pt in self.pts]
|
||||
|
||||
|
|
|
|||
|
|
@ -135,18 +135,18 @@ class ZoneFill:
|
|||
class FillPolygon:
|
||||
layer: Named(str) = ""
|
||||
island: Wrap(Flag()) = False
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
|
||||
|
||||
@sexp_type('fill_segments')
|
||||
class FillSegment:
|
||||
layer: Named(str) = ""
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
|
||||
|
||||
@sexp_type('polygon')
|
||||
class ZonePolygon:
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
|
||||
|
||||
@sexp_type('zone')
|
||||
|
|
@ -199,7 +199,7 @@ class Zone:
|
|||
|
||||
@sexp_type('polygon')
|
||||
class RenderCachePolygon:
|
||||
pts: PointList = field(default_factory=PointList)
|
||||
pts: PointList = field(default_factory=list)
|
||||
|
||||
|
||||
@sexp_type('render_cache')
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ def _polyline_bounds(self):
|
|||
|
||||
@sexp_type('wire')
|
||||
class Wire:
|
||||
points: PointList = field(default_factory=PointList)
|
||||
points: PointList = field(default_factory=list)
|
||||
stroke: Stroke = field(default_factory=Stroke)
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ class Wire:
|
|||
|
||||
@sexp_type('bus')
|
||||
class Bus:
|
||||
points: PointList = field(default_factory=PointList)
|
||||
points: PointList = field(default_factory=list)
|
||||
stroke: Stroke = field(default_factory=Stroke)
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ class Bus:
|
|||
|
||||
@sexp_type('polyline')
|
||||
class Polyline:
|
||||
points: PointList = field(default_factory=PointList)
|
||||
points: PointList = field(default_factory=list)
|
||||
stroke: Stroke = field(default_factory=Stroke)
|
||||
uuid: UUID = field(default_factory=UUID)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue