jitxlib.gerber package#
Export Gerber X2/X3 fabrication data from JITX designs.
The package splits in two: format is a standalone Gerber/XNC/gbrjob writer with no JITX dependencies, and extract populates the format model from a captured JITX RuntimeDesign. The plugin module registers the jitx export entry point.
export_gerber is the Python API. It exists alongside the plugin rather than behind it because the plugin registry derives its command-line flags from the signature of export, so everything reachable that way is a flat scalar: a caller that wants to pass a configured naming strategy, or to be told which files were written, needs a door that is not the CLI’s.
See plans/gerber-export-plan.md for the design and §9 for the milestones.
- class Compat(bake_macro_rotation=False)[source]#
Bases:
objectThe set of adjustments in effect for one export.
- Parameters:
bake_macro_rotation (
bool) – write rotated pads as macros with the rotation applied to the primitive coordinates and no rotation parameter, for readers that mishandle the macro rotation argument. Each distinct angle of a shape becomes its own macro.
- classmethod from_names(names)[source]#
The adjustments named, as on the command line (bake-macro-rotation).
- Raises:
ValueError – a name is not a known adjustment, listing the known ones.
- Return type:
- Parameters:
- 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 FileNaming(*args, **kwargs)[source]#
Bases:
ProtocolA strategy that turns a file function into a filename.
Implement name and register the class under a scheme name. A scheme is free to return None for any file it has no convention for; the caller falls back to descriptive rather than inventing a name.
- name(function, stem, file_set)[source]#
The complete filename for one file, or None to defer.
- Parameters:
function (Copper | Soldermask | Legend | Paste | Profile | Drill | Component | Job) – what the file is, as the structured description it already carries for its TF.FileFunction attribute, so a scheme branches on data rather than on a rendered string.
stem (
str) – the scrubbed design name. Conventions that replace the extension entirely need it, which is why the strategy returns a whole filename rather than a suffix.file_set (
Sequence[Copper | Soldermask | Legend | Paste | Profile | Drill | Component | Job]) – every file function in the set being written, in emission order. Real conventions are not per-file functions of one file - whether a drill name needs decorating depends on whether the other drill file exists - so the set is passed even though many schemes will ignore it.
- Return type:
- export_gerber(design, *, output, naming='descriptive', overwrite=False, drill_format=DrillFormat.GERBER, creation_date=None, compat=Compat(bake_macro_rotation=False))[source]#
Write a complete Gerber data set for a captured design.
- Parameters:
output (
Path) – the directory to write into, or a path ending in .zip, which writes exactly that archive with the files at its root - the layout fab upload forms expect - and nothing beside it. Nothing here ever removes a directory; overwrite is permission to replace a previous export of ours, file by file, and never more than that.naming (
str|FileNaming) – a registered scheme name or a FileNaming strategy object.drill_format (
DrillFormat) – which format the drill files are written in. Exactly one, never both.creation_date (
str|None) – ISO 8601 with a time zone, overriding the clock, for reproducible output.compat (
Compat) – output adjustments for readers that deviate from the specification; none by default.design (RuntimeDesign)
overwrite (bool)
- Return type:
- Returns:
The output path, the archive when the output was one, and every file with the file function that describes it.