kicad2ems.core.shapeops

Editing several drawn shapes at once (kicad2ems.core.shapes), with no Qt: what
the Draw page's selection, its exact edits, its snapping and its measure tool
do, as data.

    bounds_of(shapes); centre_of(shapes)          # of them all, model mm
    rotated(shapes, 30, about=(x, y))             # copies (about=None: their
    mirrored(shapes, 'x')                         #  centre)
    offsets = aligned(shapes, 'left', keep={2})   # (dx, dy) each; kept ones
    offsets = distributed(shapes, 'x')            #  0, as anchors
    copies = array_row(shapes, 5, dx, dy)         # the new copies alone
    copies = array_grid(shapes, nx, ny, dx, dy)
    copies = array_circle(shapes, 12, (cx, cy), angle=360, turn=True)
    text = to_clipboard(shapes); shapes = from_clipboard(text)  # or None
    snap = Snapper(layout)                        # the board's pads, vias,
    snap.set_shapes(drawing.shapes)               #  track ends and edges,
    hit = snap.find(x, y, tol, skip={3})          #  the shapes' corners...
    m = measure([(x0, y0), (x1, y1), (x2, y2)])   # lengths and angles
    new = combined(shapes, 'union' | 'subtract' | 'intersect')
                                                  # polygons (shapely)
    s = rounded(shape, 0.5) ; s = rounded(shape, 0.5, 'chamfer')
                                                  # its corners
    idx = alike(shapes, i, 'material' | 'layer' | 'net' | 'kind')
    pts = ring_points(polygon)                    # a Shape's points, holes
                                                  #  joined in (a keyhole)

Coordinates are the model's (mm, y up), as core.shapes's; angles are degrees,
anticlockwise.
class kicad2ems.core.shapeops.Snap(x: float, y: float, what: str, label: str)[source]
Where a point snapped to: (x, y), what it is ('pad', 'via', 'track
end', 'board corner', 'board edge', or a shape's: 'corner', 'midpoint',
'centre', 'end', 'rim', 'port') and a label to show.
class kicad2ems.core.shapeops.Snapper(layout=None)[source]
The points a click snaps to: the board's (pads' centres, vias, every
point of its tracks, its outline's corners, and anywhere on its edges)
and the drawn shapes' (Shape.snap_points). A point beats an edge; the
nearest point within the tolerance wins.
find(x, y, tol, skip=(), board=True, shapes=True)[source]
The Snap nearest (x, y) within tol mm, or None; the points of the
shapes of index in `skip` (those being moved) are left out.
set_shapes(shapes)[source]
The drawn shapes to snap to (hidden ones are left out).
kicad2ems.core.shapeops.aligned(shapes, how, keep=())[source]
[(dx, dy)] that line the shapes up (ALIGN's keys: left, right,
hcentre, top, bottom, vcentre) on the bounds of them all; the shapes of
index in `keep` (locked ones) stay, and count in the bounds.
kicad2ems.core.shapeops.alike(shapes, i, by)[source]
The indices of the shapes like shape i by `by` (ALIKE: the same
material, copper layer (a solid: any solid), net (copper), or kind);
hidden ones left out.
kicad2ems.core.shapeops.array_circle(shapes, n, centre, angle=360.0, turn=True)[source]
n round `centre` (the shapes themselves the first), `angle` degrees
from the first to the last (360: the whole way round, evenly), each copy
turned with it (turn) or only carried round: the new copies.
kicad2ems.core.shapeops.array_grid(shapes, nx, ny, dx, dy)[source]
nx by ny (the shapes themselves at the corner), dx along x, dy along
y: the new copies, row by row.
kicad2ems.core.shapeops.array_row(shapes, n, dx, dy)[source]
n in a row (the shapes themselves the first), each step (dx, dy) mm
from the last: the n - 1 new copies of them all.
kicad2ems.core.shapeops.bounds_of(shapes)[source]
(x0, y0, x1, y1) of the shapes together, or None for none.
kicad2ems.core.shapeops.centre_of(shapes)[source]
The centre of their bounds (x, y), or None.
kicad2ems.core.shapeops.combined(shapes, op)[source]
The shapes' outlines combined into polygons with the first's
properties: 'union' (all of them), 'subtract' (the first less the
others), 'intersect' (where they all overlap). A hole is joined to the
outline by a cut of no width (ring_points: a Shape has one ring). [] when
nothing is left; ValueError for fewer than two, or shapes not of one
material and layer (or heights).
kicad2ems.core.shapeops.distributed(shapes, axis, keep=())[source]
[(dx, dy)] that space the shapes' centres evenly along 'x' or 'y'
between the first and the last (in that order along it), which stay;
those of index in `keep` stay too (the rest spread round them as if they
had moved).
kicad2ems.core.shapeops.from_clipboard(text)[source]
The shapes in a clipboard's text (a kicad2ems-shapes file's), shown
and unlocked; None when it holds none.
kicad2ems.core.shapeops.measure(points)[source]
What the measure tool says of its points [(x, y), ...]: dict(length
(along them all), dx, dy (first to last), distance (first to last),
angle (the first leg's direction, degrees anticlockwise from +x) and,
with three points, turn: the angle at the second between the legs to the
first and the third (0-180).
kicad2ems.core.shapeops.mirrored(shapes, axis, at=None)[source]
Copies mirrored together ('x': x reversed, 'y': y reversed) about the
line at `at` (None: their centre).
kicad2ems.core.shapeops.ring_points(g, ndigits=6)[source]
A shapely Polygon as one ring of points [[x, y], ...] (anticlockwise,
not closed): its holes joined to it each by a cut of no width (Shape's
outline, Polygon(points).buffer(0), gives the holes back). The holes are
joined nearest the outline first, each from its corner nearest a corner
of the outline or of a hole joined before it (a k-d tree of the corners:
a plate less 300 posts is 0.11 s, the subtract and all; each hole
against the ring so far took 6.5 s).
kicad2ems.core.shapeops.rotated(shapes, angle, about=None)[source]
Copies turned `angle` degrees about `about` (None: their centre).
kicad2ems.core.shapeops.rounded(shape, r, how='fillet', segments=64)[source]
A copy of a rectangle, polygon or trace with its corners rounded to
radius r mm (how 'fillet') or cut r mm along each leg ('chamfer'): a
rectangle becomes a polygon; a trace's centre line is rounded (a curved
bend, or a mitred one) and its ends kept. ValueError for a circle or a
port (no corners) or r <= 0.
kicad2ems.core.shapeops.to_clipboard(shapes)[source]
The shapes as a kicad2ems-shapes file's text (what Copy puts on the
clipboard: it pastes into any drawing, and saves as one).