multisim2kicad 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import { type MdbJson } from "electronics-workbench-decoder";
2
+ import type { Board, Component } from "../ir/types.ts";
3
+ export interface EwDatabase {
4
+ source: string;
5
+ tables: MdbJson["tables"];
6
+ }
7
+ export declare function readEwDatabase(bytes: Uint8Array, source?: string): EwDatabase;
8
+ export interface DatabaseFootprints {
9
+ components: Component[];
10
+ /** Objects not turned into footprints, with the reason. */
11
+ skipped: {
12
+ name: string;
13
+ reason: string;
14
+ }[];
15
+ }
16
+ /** Every Ultiboard footprint in the database, named after its library object. */
17
+ export declare function databaseFootprints(db: EwDatabase): DatabaseFootprints;
18
+ /** A board holding the database's footprints, for the footprint-library emitter. */
19
+ export declare function footprintBoard(components: Component[], name: string): Board;
@@ -0,0 +1,33 @@
1
+ import type { LibrarySymbolSpec } from "../emit/kicad-sch.ts";
2
+ import type { SchGraphic, SchPoint } from "../ir/types.ts";
3
+ import type { EwDatabase } from "./ewdb.ts";
4
+ /**
5
+ * A symbol picture's XML. The stored image is a 5-byte prefix followed by
6
+ * EW's usual compressed stream (as after a compressed file's header).
7
+ */
8
+ export declare function symbolPictureXml(image: Uint8Array, size: number): string;
9
+ export interface PicturePin {
10
+ /** 1-based index into the section's pin list. */
11
+ index: number;
12
+ at: SchPoint;
13
+ dir: SchPoint;
14
+ length: number;
15
+ }
16
+ export interface SymbolPicture {
17
+ graphics: SchGraphic[];
18
+ pins: PicturePin[];
19
+ showPinNames: boolean;
20
+ }
21
+ export declare function parseSymbolPicture(xml: string): SymbolPicture;
22
+ export interface DatabaseSymbols {
23
+ specs: LibrarySymbolSpec[];
24
+ warnings: string[];
25
+ }
26
+ /**
27
+ * One library symbol per database component: sections as units, pin
28
+ * numbers from the package (several pads -> stacked pins; no package -> the
29
+ * pin name), electrical types from `Pin_Type`. `footprintFor` maps a
30
+ * package name to a KiCad footprint id when the footprint is in this
31
+ * database.
32
+ */
33
+ export declare function databaseSymbols(db: EwDatabase, footprintFor: (pkg: string) => string | undefined): DatabaseSymbols;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Project-local footprint library (phase E3): one `.kicad_mod` per EW
3
+ * footprint, drawn the way a library has it: unrotated, top side.
4
+ *
5
+ * Ultiboard stores every part already placed. A placed part is turned back
6
+ * into its library drawing with the C6 placement rules (see Component in
7
+ * ir/types.ts): top = origin + R(rot) * local, bottom = origin + R(-rot) *
8
+ * mirrorX(local).
9
+ *
10
+ * Ultiboard rounds each placed copy to the nanometre after rotating it, so
11
+ * two copies of one footprint can differ by a nanometre once un-rotated,
12
+ * and KiCad compares footprints with their library copy exactly (DRC
13
+ * lib_footprint_mismatch). So the library drawing is taken once per name
14
+ * (rounded to whole nanometres) and every copy that agrees with it to within
15
+ * a few nanometres is placed from it. Copies that really differ (edited on
16
+ * the board) keep their own geometry and show up as mismatches, as they
17
+ * should.
18
+ */
19
+ import type { Board, Component } from "../ir/types.ts";
20
+ /** The part as its library drawing: origin (0, 0), unrotated, top side. */
21
+ export declare function libraryComponent(c: Component): Component;
22
+ /**
23
+ * The board's footprint library, and the board with every copy placed from
24
+ * its library drawing. Copies are taken top-side first. A copy matching an
25
+ * existing drawing of its name (at some quarter-turn: pad 1 may sit at the
26
+ * other end of a 2-pin part) is placed from it; one that matches none (a
27
+ * silkscreen mark moved on that copy, say) becomes a variant `<name>_2`, ...
28
+ * so every board footprint is exactly its library entry.
29
+ */
30
+ export declare function harmonizeFootprints(board: Board): {
31
+ board: Board;
32
+ library: Map<string, Component>;
33
+ };
34
+ /** `<name>.kicad_mod` files for a harmonized board's library. */
35
+ export declare function emitFootprintLibrary(board: Board, library: ReadonlyMap<string, Component>): Map<string, string>;
@@ -0,0 +1,34 @@
1
+ import type { Board, Component, Point } from "../ir/types.ts";
2
+ import { LayerMap } from "./pcb-layers.ts";
3
+ /** Footprint name for a part: EW's footprint (shape) name, file-name safe. */
4
+ export declare function footprintName(c: Component): string;
5
+ /** Schematic link fields for a footprint (KiCad's path / sheetname / sheetfile). */
6
+ export interface FootprintLink {
7
+ path: string;
8
+ sheetname: string;
9
+ sheetfile: string;
10
+ /** The symbol's value; KiCad treats the schematic as the master copy. */
11
+ value: string;
12
+ }
13
+ export interface PcbOptions {
14
+ /** Emit a library footprint: no position, nets or board links. */
15
+ library?: boolean;
16
+ /** Footprint library nickname for the footprints' lib ids (default "ew"). */
17
+ footprintLib?: string;
18
+ /** Reference -> schematic symbol, to link the board to its schematic. */
19
+ links?: ReadonlyMap<string, FootprintLink>;
20
+ }
21
+ /** One footprint on its own (library files): no nets. */
22
+ export declare function emitFootprintFor(c: Component, lm: LayerMap, opts?: PcbOptions): string;
23
+ /** Library name of a mounting hole footprint: by drill size. */
24
+ export declare const mountingHoleName: (drillNm: number) => string;
25
+ /**
26
+ * A mechanical mounting hole: KiCad models it as a footprint holding one
27
+ * np_thru_hole pad with size == drill (no copper). `at` is omitted for the
28
+ * library copy.
29
+ */
30
+ export declare function mountingHoleFootprint(drillNm: number, lib: string, place?: {
31
+ at: Point;
32
+ n: number;
33
+ }): string;
34
+ export declare function emitKicadPcb(board: Board, opts?: PcbOptions): string;
@@ -0,0 +1,18 @@
1
+ import type { Board } from "../ir/types.ts";
2
+ /** Name of the net class holding nets with this clearance and track width. */
3
+ export declare const netClassName: (clearance: number, width: number) => string;
4
+ /**
5
+ * The parts of a `.kicad_pro` the board's rules decide: `board.design_settings`
6
+ * rules and `net_settings` (classes + patterns). Undefined when the board
7
+ * has no rules (hand-built boards in tests).
8
+ */
9
+ export declare function boardProjectSettings(board: Board): {
10
+ rules: Record<string, number>;
11
+ netSettings: Record<string, unknown>;
12
+ } | undefined;
13
+ /**
14
+ * Custom rules for board-wide clearances KiCad's net classes can't hold:
15
+ * Ultiboard sets clearance to pads and to vias separately from clearance to
16
+ * traces. Undefined when they all agree (most boards).
17
+ */
18
+ export declare function boardCustomRules(board: Board): string | undefined;
@@ -0,0 +1,59 @@
1
+ import type { Schematic, SchGraphic, SymbolPin } from "../ir/types.ts";
2
+ /**
3
+ * One Multisim schematic unit in mm. Multisim's nominal unit is 0.25 mm; we
4
+ * use 10 mil (0.254 mm) so every integer coordinate is on a KiCad grid, and
5
+ * set the project's connection grid to match (decision 2026-11-11).
6
+ */
7
+ export declare const MM_PER_UNIT = 0.254;
8
+ /** A library symbol described directly (EW database parts), not from placements. */
9
+ export interface LibrarySymbolSpec {
10
+ name: string;
11
+ /** Reference prefix ("U"). */
12
+ reference: string;
13
+ value: string;
14
+ footprint?: string;
15
+ fields?: [string, string][];
16
+ showPinNames: boolean;
17
+ showPinNumbers: boolean;
18
+ /** Unit 1..n: its drawing, its pins, and pins drawn as plain stems (kept on another unit). */
19
+ units: {
20
+ graphics: SchGraphic[];
21
+ pins: SymbolPin[];
22
+ stems?: SymbolPin[];
23
+ }[];
24
+ }
25
+ /** A `.kicad_sym` file of directly described symbols; each unit centred on its pins. */
26
+ export declare function librarySymbolsFile(specs: LibrarySymbolSpec[]): string;
27
+ /**
28
+ * Emit a KiCad schematic project: file name -> contents. The root page goes
29
+ * to `<baseName>.kicad_sch`; every other Multisim page gets its own file,
30
+ * shared by all instances of its sheet, with per-instance references.
31
+ */
32
+ /** Where a schematic part lives, for the matching PCB footprint's link fields. */
33
+ export interface SymbolLink {
34
+ path: string;
35
+ sheetname: string;
36
+ sheetfile: string;
37
+ value: string;
38
+ unit: number;
39
+ }
40
+ export interface SchProjectOptions {
41
+ /** Reference -> "lib:footprint" for the symbols' Footprint field. */
42
+ footprints?: ReadonlyMap<string, string>;
43
+ /** Nickname of the project symbol library (default "ew"). */
44
+ library?: string;
45
+ }
46
+ export declare function emitKicadSchProject(source: Schematic, baseName: string, opts?: SchProjectOptions): {
47
+ files: Map<string, string>;
48
+ links: Map<string, SymbolLink>;
49
+ symbolLibrary: string;
50
+ };
51
+ /** Single-file convenience (tests): the root page's contents. */
52
+ export declare function emitKicadSch(sch: Schematic): string;
53
+ /**
54
+ * Project-file settings the schematic needs: a 10 mil connection grid so the
55
+ * integer Multisim grid is on-grid for ERC.
56
+ */
57
+ export declare function kicadProSchematicSettings(): {
58
+ connection_grid_size: number;
59
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Ultiboard layer numbers -> KiCad layers, per board.
3
+ *
4
+ * Copper comes from the board's stackup (EW 0 = F.Cu, EW 1..n = In1..In n.Cu,
5
+ * EW 63 = B.Cu). Technical layers map one to one. Layers with no KiCad
6
+ * counterpart that carry drawings (3D outlines, mechanical layers, the
7
+ * per-design custom layers 93+) get KiCad user layers named after the EW
8
+ * layer, in EW layer order. EW-internal layers (ratsnest, DRC markers, force
9
+ * vectors) are dropped. See plans/converter.md, phase C3.
10
+ */
11
+ import type { Board } from "../ir/types.ts";
12
+ export type KicadLayerType = "signal" | "user";
13
+ export interface KicadLayer {
14
+ /** KiCad 8 layer id (F.Cu 0, In1..In30 1..30, B.Cu 31, technical 32+). */
15
+ id: number;
16
+ name: string;
17
+ type: KicadLayerType;
18
+ /** Display name shown in KiCad (user layers carry the EW layer name). */
19
+ userName?: string;
20
+ }
21
+ /** EW bottom-side layers and their top-side twins (library footprints are top-side). */
22
+ export declare const TOP_TWIN: Readonly<Record<number, number>>;
23
+ export declare class LayerMap {
24
+ /** Copper layer names, top to bottom. */
25
+ readonly copper: string[];
26
+ /** Layer table for the board file. */
27
+ readonly table: KicadLayer[];
28
+ /** EW layers that carried drawings but were not emitted, with counts. */
29
+ readonly dropped: Map<number, number>;
30
+ private readonly map;
31
+ constructor(board: Board);
32
+ /** KiCad layer for an EW layer, or undefined if it is not emitted. */
33
+ kicad(ew: number): string | undefined;
34
+ /**
35
+ * KiCad layer for a drawing inside a part. EW draws courtyards of both
36
+ * sides on its one courtyard layer (92); bottom parts get B.CrtYd.
37
+ */
38
+ kicadInPart(ew: number, bottom: boolean): string | undefined;
39
+ isCopper(name: string | undefined): boolean;
40
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * multisim2kicad as a library: Electronics Workbench (Multisim / Ultiboard) designs
3
+ * and component databases -> KiCad.
4
+ *
5
+ * The high-level entry points write a KiCad project or library to a folder;
6
+ * the parsers and emitters underneath work on the format-neutral IR in
7
+ * `./ir/types.ts`, so other front or back ends can plug in.
8
+ */
9
+ export { convertDatabase, convertFile, convertPcb, convertProject, convertSch, groupProjects, main, type ProjectInput, } from "./main.ts";
10
+ export { designBaseName, loadDesign, type DesignKind, type LoadedDesign } from "./load.ts";
11
+ export { parseSchematicXml } from "./parse/sch.ts";
12
+ export { parsePcbXml, parseUbLibraryXml } from "./parse/pcb.ts";
13
+ export { emitKicadPcb, footprintName, type PcbOptions } from "./emit/kicad-pcb.ts";
14
+ export { emitKicadSch, emitKicadSchProject, librarySymbolsFile, type LibrarySymbolSpec } from "./emit/kicad-sch.ts";
15
+ export { emitFootprintLibrary, harmonizeFootprints } from "./emit/footprint-lib.ts";
16
+ export { boardCustomRules, boardProjectSettings } from "./emit/kicad-pro.ts";
17
+ export { databaseFootprints, footprintBoard, readEwDatabase, type EwDatabase } from "./db/ewdb.ts";
18
+ export { databaseSymbols, parseSymbolPicture, symbolPictureXml } from "./db/symbols.ts";
19
+ export type * from "./ir/types.ts";