model module#
Data model for a Gerber X2/X3 fabrication data set.
Coordinates and sizes are millimeters; the emitters put them on the 1 nm grid (units). Rotations are degrees counter-clockwise, the Gerber convention. Object order within a file is the image order: a clear object erases everything emitted before it, so the order a caller builds is the order that reaches the file.
- AttrSet: TypeAlias = 'tuple[Attribute, ...]'#
Attribute names (with their leading dot for standard names) and values.
A tuple rather than a mapping so it can take part in an aperture key. An empty value tuple emits a bare %TO.Name*%; a single empty string emits the reserved empty value %TO.N,*%.
- escape_field(value)[source]#
Escape a string for use as an attribute field.
Reserved characters and everything outside printable ASCII become uXXXX (or UXXXXXXXX above the BMP), so the whole file stays 7-bit printable ASCII and a user net name cannot break the syntax.
- class FileKind(*values)[source]#
Bases:
StrEnumThe primary branch a naming scheme and the overwrite guard key on.
- COPPER = 'copper'#
- SOLDERMASK = 'soldermask'#
- LEGEND = 'legend'#
- PASTE = 'paste'#
- PROFILE = 'profile'#
- DRILL = 'drill'#
- COMPONENT = 'component'#
- JOB = 'job'#
- class CopperType(*values)[source]#
Bases:
StrEnum- SIGNAL = 'Signal'#
- PLANE = 'Plane'#
- MIXED = 'Mixed'#
- class HoleType(*values)[source]#
Bases:
StrEnum- PTH = 'PTH'#
- NPTH = 'NPTH'#
- BLIND = 'Blind'#
- BURIED = 'Buried'#
- class DrillFormat(*values)[source]#
Bases:
StrEnumWhich format a drill file is written in.
One format per data set, never both: a job file listing an XNC and a Gerber drill file for the same span gives a CAM system every reason to drill the holes twice.
Gerber is the spec’s own recommendation - 6.6, “use Gerber rather than an NC format for drill and rout layers … mixing formats is asking for problems, especially in registration” - with XNC as the NC fallback it endorses, “the only one that is clearly specified and targeted to CAD to CAM data transfer”.
Gerber is the default. XNC remains available for a consumer whose intake wants an NC file, selected with –drill-format xnc.
- XNC = 'xnc'#
- GERBER = 'gerber'#
- class DrillContent(*values)[source]#
Bases:
StrEnum- DRILL = 'Drill'#
- ROUT = 'Rout'#
- MIXED = 'Mixed'#
- class Polarity(*values)[source]#
Bases:
StrEnumObject polarity: dark adds to the image, clear erases from it.
- DARK = 'D'#
- CLEAR = 'C'#
- class Copper(index, side, conductors, type=None)[source]#
Bases:
objectCopper,L<index>,<side>[,<type>].
- Parameters:
index (
int) – 1-based conductor index, counted from the top.side (
Side) – Top for index 1, Bot for the last conductor, Inr otherwise.conductors (
int) – total conductor count, for naming schemes that vary with board size. Not part of the rendered attribute.type (
CopperType|None) – emitted only when set; a plain signal layer leaves it off.
- type: CopperType | None = None#
- kind = 'copper'#
- class Soldermask(side)[source]#
Bases:
objectSoldermask,<side>. Images the openings, so the file is negative.
- Parameters:
side (Side)
- kind = 'soldermask'#
- class Profile(plated=False)[source]#
Bases:
objectProfile,(P|NP). JITX has no edge plating, so NP in practice.
- Parameters:
plated (bool)
- kind = 'profile'#
- class Drill(first, last, hole, plated=True, content=None, format=DrillFormat.GERBER)[source]#
Bases:
object(Plated|NonPlated),<from>,<to>,<hole type>[,<content>].
- Parameters:
first (
int) – 1-based conductor index the span starts at.last (
int) – 1-based conductor index the span ends at.hole (
HoleType) – PTH/NPTH for a span crossing the whole board, Blind or Buried otherwise.plated (
bool) – selects the Plated or NonPlated keyword. Plating is a file attribute by design, which is why plated and non-plated hits cannot share a file.content (
DrillContent|None) – Drill, Rout or Mixed; omitted when the file is plain hits.format (
DrillFormat) – which format the file is written in. Not part of the rendered attribute - it decides the file’s extension and its gbrjob FileFormat, so naming and the job writer branch on it rather than on an extension they would otherwise have to guess.
- content: DrillContent | None = None#
- format: DrillFormat = 'gerber'#
- kind = 'drill'#
- class Component(index, side)[source]#
Bases:
objectComponent,L<index>,<side>, the X3 assembly layer for one side.
- kind = 'component'#
- class Job[source]#
Bases:
objectThe .gbrjob file.
It is not a Gerber file and carries no TF.FileFunction, but it is part of the written set, so naming and the overwrite guard need a handle for it.
- kind = 'job'#
- class Macro(body)[source]#
Bases:
objectAn AM template, named from its content.
- class Aperture(template, params=(), attrs=())[source]#
Bases:
objectAn AD instantiation of a standard template or a macro.
- Parameters:
template (
str|Macro) – a standard template letter (C, R, O, P) or the macro to instantiate.params (
tuple[float,...]) – the AD modifiers in order, joined with X on emission. For a macro this includes the rotation argument.attrs (
tuple[tuple[str,tuple[str,...]],...]) – aperture attributes, applied to this aperture alone.
- class Flash(x, y, aperture, attrs=())[source]#
Bases:
objectA D03: one aperture stamped at a point.
Every pad is a flash and every flash is a pad (spec 4.10), so nothing else may use this.
- class Draw(x1, y1, x2, y2, aperture, attrs=())[source]#
Bases:
objectA D01 in linear mode: a straight stroke with round caps.
- Parameters:
- class ArcObj(x1, y1, x2, y2, cx, cy, ccw, aperture, attrs=())[source]#
Bases:
objectA D01 in circular mode, stroked from (x1, y1) to (x2, y2).
The center is absolute; the emitter derives the signed I/J offsets. ccw selects G03 over G02. A sweep over 180 degrees is split by the emitter, and a coincident start and end is a full circle, which the emitter also splits rather than emitting as the spec’s zero-length form.
- Parameters:
- class CurveSeg(x, y, cx, cy, ccw)[source]#
Bases:
objectAn arc contour segment ending at (x, y) around an absolute center.
- class Region(contours, polarity=Polarity.DARK, attrs=(), aper_attrs=())[source]#
Bases:
objectA G36/G37 statement: the union of its contours’ filled areas.
All contours share one polarity, since polarity is a property of a graphic object. Holes are separate clear regions, not contours here.
- class Surface(island, holes=(), attrs=(), aper_attrs=())[source]#
Bases:
objectAn island with the holes that belong to it, kept together.
The grouping is the unit any ordering moves, so an island can never be separated from a hole that would erase it. The emitter expands it into a dark region followed by one clear region per hole; island is also the outer ring a containment ordering sorts on.
- Parameters:
- class GenerationSoftware(vendor, application, version)[source]#
Bases:
objectTF.GenerationSoftware and the gbrjob Header object of the same name, which spells the same three fields as JSON.
- class ProjectId(name, guid, revision='rev?')[source]#
Bases:
objectTF.ProjectId: a name, an RFC 4122 GUID and a revision.
revision is rev? when the design carries none.
- class FileMeta(software, creation_date, project, compat=Compat(bake_macro_rotation=False))[source]#
Bases:
objectThe per-run identity every file in the set repeats.
Injected by the caller rather than read from a clock inside an emitter, so output is reproducible.
- Parameters:
creation_date (
str) – ISO 8601 with a time zone.compat (
Compat) – the output adjustments in effect, which every file names in a comment so it shows how it was written.software (GenerationSoftware)
project (ProjectId)
- software: GenerationSoftware#
- class GerberFile(function, polarity=FilePolarity.POSITIVE, objects=list())[source]#
Bases:
objectOne Gerber image: its file function, polarity and object list.
There is no aperture table here on purpose. Every object carries the aperture it uses, apertures are values rather than registry entries, and §7 assigns D-codes by sorted key once the set is complete - so the table is derived at emission and cannot drift out of step with the objects.
- Parameters:
- polarity: FilePolarity = 'Positive'#
- class Tool(diameter, attrs=())[source]#
Bases:
objectOne XNC tool.
- Parameters:
diameter (
float) – the finished hole diameter after plating, in mm. The exporter never applies a plating allowance in either direction; the fabricator picks the bit.attrs (
tuple[tuple[str,tuple[str,...]],...]) – tool attributes, chiefly the bare TA.AperFunction value. Plating is not part of it - that is the file’s attribute.
- class Slot(start, segments, tool, attrs=())[source]#
Bases:
objectA rout path: tool down at start, one segment per step, tool up.
Arc segments span at most 180 degrees; XNC carries a radius rather than a center, so the emitter derives it and the direction comes from ccw.
- Parameters: