emit module#

Serialize a GerberFile to RS-274X text.

The header order is fixed: TF file attributes, FS, MO, AM macros, AD apertures with their TA runs, then the body, then M02. The body is a state machine over polarity, the current aperture, the plot mode, the attribute dictionary and the current point; every one of those is modal, and several of the defects this format is prone to are a missed modal update rather than a malformed word.

Output is deterministic: no clock is read here (the creation date is injected), D-codes come from a sorted key, and macros are emitted in name order.

emit_gerber(file, meta)[source]#

The complete text of one Gerber file, M02* included.

Return type:

str

Parameters:
UNDELETABLE = frozenset({'.C'})#

Attribute names that cannot be spelled in a TD.

.C is the one. The spec’s formal grammar guards it with a lookahead - ‘.C’ &’,’, commented “To prevent this rule from parsing .CRot etc.” - so .C only matches when a comma follows it. That is what keeps %TO.C,U1*% from being read as the start of .CRot, but it also means %TD.C*%, where a * follows, matches no alternative at all: the other names are plain literals and user_name “cannot start with a dot”.

5.5’s prose allows it (“the name of the attribute to delete”) and the grammar does not, and the grammar is what the Reference Gerber Viewer’s syntax checker implements - it rejects %TD.C*% and then aborts, leaving the rest of the file unchecked. So the command is never emitted; see _diff.

needs_reset(current, desired)[source]#

Whether getting from current to desired needs a bare %TD*%.

True when an attribute that has to go cannot be named in a TD.

Return type:

bool

Parameters: