kicad2ems.core.shapes

Drawn shapes: arbitrary 2D and 3D geometry added to a board (or drawn on its
own), from the window's Draw page or by hand. No Qt here: the drawing as data,
its geometry, what it does to a Board, and the triangles a 3D view draws.

    d = Drawing([Shape('rect', [[0, 0], [5, 2]], layer='F.Cu', net='RF'),
                 Shape('circle', [[2, 1]], radius=0.4, material='cut',
                       layer='F.Cu'),
                 Shape('polygon', [[0, 0], [4, 0], [2, 3]], material='metal',
                       z0=1.6, z1=3.0)])
    d.save('drawing.json');  d = Drawing.load('drawing.json')
    notes = apply(board, d)          # its copper into board.copper, its cuts
                                     # out of it; its solids as board.solids
    v, f = prism(polygon, z0, z1)    # a closed triangle mesh, outward normals
    i, t = pick(meshes, origin, direction)
                                     # the mesh a ray meets first (a 3D view's
                                     # click), and how far along it

Coordinates are the model's (mm, y up: board.json's, the 3D view's); a setting
in KiCad's coordinates (a region, a port at a point) has y negated
(region_setting, port_settings).

The kinds of shape (`kind`) and what their points are:

    rect     two opposite corners
    circle   the centre (radius: `radius`)
    polygon  three or more corners
    path     two or more points of a centre line `width` wide (round ends:
             a trace)
    port     one point: a port there (the `ports` setting, P<n>@x,y,layer)

and what they are made of (`material`):

    copper      on a copper layer (`layer`): merged with that layer's copper
                of the same net (`net`; empty: the net of the copper it
                overlaps most, else a net of its own)
    cut         on a copper layer: taken out of every net's copper there
    metal       a solid from z0 to z1 (mm): a shield, a block, a post
    dielectric  a solid of permittivity er and loss tangent tand
    air         a solid of air (a cavity, a slot through the substrate)
    ferrite     a microwave ferrite (er, tand; saturation magnetisation `ms`,
                4 pi Ms in gauss; FMR linewidth `dh`, oersted at 9.4 GHz, the
                datasheets'): magnetised by the drawn magnets, gyrotropic
                (core.magnets has the bias, gfdtd the ferrite)
    magnet      a permanent magnet of remanence `br` (tesla; + magnetised up,
                along +z, - down): a rigid magnetisation for the bias, and to
                the RF a metal (rare-earth magnets conduct; a ceramic magnet's
                RF is a dielectric drawn after it)

Every solver reads board.copper, so drawn copper and cuts reach them all; the
line model builds its sections from the board's own tracks and does not see
them. The solids are kept on the board (board.solids, board.json's 'solids')
and drawn in the 3D view. The FDTD (openems, gfdtd) and Palace mesh them: a
later solid over an earlier one, a solid over the board's dielectric unless it
encloses the whole board (core.solids has the rules). mom25d's layers are
laterally infinite: it refuses a board with solids. The line model and pcbqs
leave them out (apply's notes say so). A ferrite needs gfdtd: openEMS and
Palace refuse it (neither has a gyrotropic medium).
class kicad2ems.core.shapes.Drawing(shapes: list = <factory>)[source]
Shapes in the order they are applied (a cut takes out what was drawn
before it on its layer, not after).
class kicad2ems.core.shapes.Shape(kind: str, points: list, material: str = 'copper', layer: str = 'F.Cu', net: str = '', width: float = 0.5, radius: float = 1.0, z0: float = 0.0, z1: float = 1.0, er: float = 4.3, tand: float = 0.0, ms: float = 1800.0, dh: float = 30.0, br: float = 1.2, rot: float = None, name: str = '', hidden: bool = False, locked: bool = False)[source]
One drawn shape (the module docstring has the kinds and materials).
bounds()[source]
(x0, y0, x1, y1) mm.
drag_handle(i, x, y)[source]
Handle i moved to (x, y).
handles()[source]
The points to drag to reshape it: its own points, and a circle's
rim (radius) east of the centre.
lifted(dz, face=None)[source]
A copy of a solid raised by dz mm: both faces, or only its 'top'
(z1) or 'bottom' (z0) face (`face`), never past the other one.
mirrored(axis, at=None)[source]
A copy mirrored: axis 'x' reverses x (left-right, about the line x
= at), 'y' reverses y (about y = at); at None: its own centre. A
port's direction is mirrored too.
moved(dx, dy)[source]
A copy moved by (dx, dy) mm.
outline(segments=64)[source]
Its area as a shapely Polygon (model mm), or None (a port; a shape
with no area).
rotated(angle, about=None)[source]
A copy turned `angle` degrees anticlockwise about the point `about`
(None: its own centre). A rectangle turned off a right angle becomes
a polygon; a port's direction turns with it.
snap_points()[source]
[(x, y, what)]: the points a click snaps to on it, what one of
'corner', 'midpoint', 'centre', 'end' (a trace's), 'rim' (a circle's
quarter points), 'port'.
property solid[source]
Whether it is a solid between z0 and z1 (else a sheet on a copper
layer).
kicad2ems.core.shapes.apply(board, drawing, log=None)[source]
The drawing's copper merged into board.copper (and copper_nets), its
cuts taken out, each clipped to the board outline, in the drawing's order;
its solids as board.solids (dicts: shape, material, z0, z1, er, tand,
polygon as GeoJSON; a ferrite's ms and dh, a magnet's br). Returns notes (what was done, and which solvers do
not see what). ValueError: a shape on a layer the board has no copper
layer of.
kicad2ems.core.shapes.pick(meshes, origin, direction)[source]
(key, t): the mesh of {key: (vertices, faces)} the ray meets first, and
how far along it; (None, None) for none.
kicad2ems.core.shapes.port_settings(drawing, first=1, taken=())[source]
The `ports` setting of the drawing's ports: P<n>@x,y,layer[,rot] (KiCad
mm), numbered from `first`, skipping the numbers in `taken`.
kicad2ems.core.shapes.prism(g, z0, z1)[source]
Polygon g (holes allowed) extruded from z0 to z1: (vertices (n, 3),
faces (m, 3)), the faces wound outward (top +z, bottom -z, walls away from
the solid).
kicad2ems.core.shapes.ray_hit(v, f, origin, direction)[source]
How far along the ray origin + t direction (t > 0) it first meets the
triangles (vertices v (n, 3), faces f (m, 3)), or None (Moller-Trumbore,
every triangle at once).
kicad2ems.core.shapes.region_setting(shape)[source]
The `region` setting a shape outlines (KiCad mm, y down): x0,y0,x1,y1
for a rectangle, [[x, y], ...] corners for anything else.
kicad2ems.core.shapes.shape_mesh(s, stack)[source]
The triangles a 3D view draws for a shape (vertices, faces), or None:
a sheet as a thin slab at its layer's height, a solid from z0 to z1, a port
as a small marker post. stack: stack_of's dict.
kicad2ems.core.shapes.stack_of(layout)[source]
cu_z, cu_t and the dielectric layers of a board's dict (Board.to_dict,
core.layout.board_layout), or the default two-layer stack for None.