Introduction
A legacy footprint library of KiCad, the
electronics design suite, is a text file that holds any number of footprints: the
copper pads, outlines and labels that a component occupies on a circuit board. It
carries the extension .mod, or .emp, and starts with the
words PCBNEW-LibModule-V1.
The newer .kicad_mod footprint is a
different format, written as S-expressions with one footprint to a file. Many
unrelated formats also use .mod; the first line tells this one
apart.
There is no specification here to follow. This page describes what the legacy reader of KiCad 10.0 accepts, with details of what was written taken from the library writer kept, switched off, in the source of KiCad 4.0.0. Footprints are written as in the legacy board file, so their lines are described there.
Layout of the file
| Part | Contents |
|---|---|
PCBNEW-LibModule-V1 | First line, which may go on with other words, such as a date |
| Header lines | Among them Units mm, if the lengths are in millimetres |
$INDEX … $EndINDEX | List of footprint names |
$MODULE name … $EndMODULE | One footprint; repeated |
$EndLIBRARY | Last line as 4.0.0 wrote it |
PCBNEW-LibModule-V1 2013-01-01 00:00:00
# encoding utf-8
Units mm
$INDEX
R_example
$EndINDEX
$MODULE R_example
Po 0 0 0 15 00000000 00000000 ~~
Li R_example
Cd Two-pad example part
Kw resistor
Sc 00000000
Op 0 0 0
At SMD
T0 0 -1.6 1 1 0 0.15 N V 21 N "R**"
T1 0 1.6 1 1 0 0.15 N V 21 N "R_example"
DS -0.4 -0.9 0.4 -0.9 0.15 21
DS -0.4 0.9 0.4 0.9 0.15 21
$PAD
Sh "1" R 1 1.3 0 0 0
Dr 0 0 0
At SMD N 00888000
Ne 0 ""
Po -0.95 0
$EndPAD
$PAD
Sh "2" R 1 1.3 0 0 0
Dr 0 0 0
At SMD N 00888000
Ne 0 ""
Po 0.95 0
$EndPAD
$EndMODULE R_example
$EndLIBRARY
Header and units
- The first line must begin with
PCBNEW-LibModule-V1, in any mix of case, followed by white space; a line end counts. Otherwise KiCad reports that the file is not a legacy library. An empty file is also an error. - The reader then looks through the following lines for
$INDEX. On the way it acts only onUnits: the valuemm, in lower case, makes lengths millimetres. All other lines are passed over. - Without
Units mm, lengths are in the old unit of 0.1 mil (0.0001 inch, or 2.54 µm). - The writer in 4.0.0 puts two spaces and the date after the first words, then the comment
# encoding utf-8andUnits mm. - The rules for lines, values, quoted strings and overbars are those of the board file, except that the unit is set in the header, as there is no
$GENERALsection.
The index
- Between
$INDEXand$EndINDEXstands one footprint name to a line. The writer in 4.0.0 lists them in sorted order and then writes the footprints in the same order. - KiCad 10.0 does not use the names: it skips the whole section and finds footprints by their own
$MODULElines. - Some libraries have several index sections one directly after another, left by a fault in older programs. All of them are skipped.
- A file with no
$INDEXline, or with an index that never ends, gives no footprints in KiCad 10.0, without an error. KiCad 4.0.0 reports a file with no$INDEXas empty or not a legacy library.
Footprints and their names
- After the index, each line that starts with the keyword
$MODULEopens a footprint. Other lines between footprints are passed over, so$EndLIBRARYis not required and does not stop the reading. - A footprint must close with a line starting
$EndMODULE; the end of the file inside a footprint is an error. 4.0.0 repeats the name after the keyword. - The name is the rest of the
$MODULEline, with white space trimmed from both ends. - In the name, each of
\ / : " < > | * ?is replaced by%and the two hexadecimal digits of the character, so/becomes%2f. - Names are compared with regard to case. When one occurs again, the later footprint is kept under the name with
_v2added, or_v3and so on, the first that is free.
Inside a footprint
KiCad reads a library footprint with the same code as a footprint on a legacy board.
| Lines | Described under |
|---|---|
Po, Sc, Li, Cd, Kw, At, AR, Op and the lines starting with . | Footprints |
T0, T1 and further T lines | Footprint text |
DS, DC, DA, DP with its Dl lines | Footprint graphics |
$PAD … $EndPAD | Pads |
$SHAPE3D … $EndSHAPE3D | 3D models |
| Layer numbers and masks | Layers |
Differences in a library
- The unit comes from the library header and applies to every footprint. The three numbers of a 3D model’s scale, offset and rotation are not converted.
- No line states the number of copper layers, and the reader assumes 16. Layer 15 is the front copper, 0 the back, and an inner layer numbered n from 1 to 14 becomes inner layer 15 − n counted from the front.
- Pad names are read as UTF-8.
- A library has no net table. The reader takes the code of a pad’s
Neline as it stands and makes no use of the name. - The position and rotation on the
Poline also place the graphics that follow it, as on a board, so the line comes before them.
What KiCad 4.0.0 wrote
The library writer in the 4.0.0 source is compiled out, but shows the order of a
footprint: $MODULE, Po, Li, then
Cd and Kw if not empty, Sc,
AR, Op, any . lines and At
that differ from the default, the reference and value texts, further texts and
graphics, pads, 3D models that name a file, and $EndMODULE with the
name.
KiCad 10.0 reads these libraries but has no way to save a footprint into one. It can delete the library file.
Recognising and reading the file
- To recognise a library, KiCad requires the extension
.modor.emp, in any case. Leaving out leading spaces and tabs, blank lines and lines starting#, the first line must then begin withPCBNEW-LibModule-Vand a later one with$MODULE, both in any case. - Loading is stricter: the header must be on the very first line and give version
1, and a$MODULEkeyword must stand at the start of its line. - The whole library is read at once and kept in memory, and read again when the file’s modification time changes.
- If an error stops the reading, the footprints completed before it can still be listed.
In the explorer
A dropped .mod or .emp library shows its index and
footprints as a byte tree and a drawing of one footprint, chosen in the options, with
its pads, graphics and texts at the footprint’s own origin without its stored
rotation. Options also choose the layers and the size of the picture. A click in the
picture selects the bytes of the item. Tables list every footprint, name in the
index, pad, text, graphic, 3D model location and header line.
A tracker music file or a Go module file with the extension .mod is
told apart by its contents.
Files up to 400 MB are read; in a library of more than 4,096 footprints the one to draw is chosen by its row number.
Not described
Known, not yet covered
- Viewer, text: text is drawn in the site’s own stick font, not KiCad’s, with ASCII, accented Latin letters and some common signs; other characters are not drawn as themselves.
- Viewer, local settings: solder mask and paste clearances are listed but not applied to the drawing.
Also used for
- Go module file – A Go module's path, Go version and dependencies, as line-oriented UTF-8 text.
- Multichannel module (xCHN, xxCH) – 31 samples and any channel count other than 4, marked 6CHN, 8CHN, 16CH and so on.
- ProTracker 3.6 module (IFF) – An IFF wrapper around a module, with version, song information and a comment.
- ProTracker module (M.K.) – 31 samples and 4 channels, marked M.K. at offset 1080: the standard Amiga module.
- Soundtracker module (15 samples) – The first modules, 1987 to 1989: 15 samples, a 600-byte header and no signature.
- StarTrekker 8-channel module (FLT8) – StarTrekker’s 8 channels, each pattern stored as two 4-channel patterns.
- Tracker module – Amiga tracker songs in four layouts: samples, an order list and patterns of notes.
Links
Software
- KiCad – free electronics design suite that reads legacy footprint libraries (Windows, macOS, Linux)
Developers
- KiCad source – the reference reader, GPL (C++)
Reference
- KiCad 10.0 legacy reader – the library and footprint reading code (C++)
- KiCad 4.0.0 legacy plugin – the older reader and the writer (C++)
- KiCad string functions – quoted strings and the replacement of characters in names (C++)
- KiCad line filters – the lines passed over when a library is recognised (C++)
- KiCad plugin base – the extension test and the operations a reader may leave out (C++)