UNPKG

@typecad/typecad

Version:

🤖programmatically 💥create 🛰️hardware

174 lines (173 loc) 4.68 kB
/// <reference types="node" /> import { Component } from "./component"; import { Pin } from "./pin"; import { UUID } from "node:crypto"; /** * Type representing available BOM fields. */ export type BomField = 'Reference' | 'Value' | 'Datasheet' | 'Footprint' | 'MPN' | 'Description' | 'Voltage' | 'Wattage'; /** * Interface representing Schematic options. * * @interface ISchematicOptions * @property {string} net_prefix - Prefix for auto-generated net names. Defaults to 'net'. * @property {BomField[]} bom_fields - Fields to include in BOM. Defaults to ['Reference', 'Value', 'Datasheet', 'Footprint', 'MPN']. * @property {string} bom_separator - Separator for BOM CSV. Defaults to ','. */ export interface ISchematicOptions { net_prefix: string; bom_fields: BomField[]; bom_separator: string; } /** * The main class for typeCAD. Holds all {@link Component} classes, creates work files, and creates nets. * * @export * @class Schematic * @typedef {Schematic} */ export declare class Schematic { #private; Components: Component[]; Sheetname: string; uuid: UUID; private sxexp_components; private sxexp_nets; private code_counter; Nodes: { name: string; code: number; nodes: Pin[]; owner: Component | null; }[]; merged_nets: { old_name: string; merged_to_number: number; }[]; private _chained_name; /** * Getter for Schematic options. * * @example * ```ts * let schematic = new Schematic('sheetname'); * schematic.option.safe_write = false; * schematic.option.build_dir = './custom_build/'; * ``` */ get option(): ISchematicOptions; /** * Used internally * @ignore */ private _storeNetParams; bom(output_folder?: string): boolean; /** * Initializes a new schematic with a given sheet name. * * @param {string} Sheetname - Name and filename of generated files. * @example * ```ts * let typecad = new Schematic('sheetname'); * ``` */ constructor(Sheetname: string); /** * Adds components to the schematic. * * @param {...Component[]} components - Components to add to the schematic. * @example * ```ts * let typecad = new Schematic('sheetname'); * let r1 = new Component({}); * let r2 = new Component({}); * typecad.add(r1, r2); * ``` */ add(...components: Component[]): void; /** * Adds a no-connection flag to a pin. * * @param {...Pin[]} pins - Pins to mark as no-connect. * @example * ```ts * let typecad = new Schematic('sheetname'); * let r1 = new Resistor({ symbol: "Device:R_Small", reference: 'R1' }); * typecad.dnc(r1.pin(1)); * ``` */ dnc(...pins: Pin[]): void; /** * Sets a name for a net. * * @param {{pins: Pin[]}} pins: Pin[]} * @example * ```ts * let typecad = new Schematic('sheetname'); * let r1 = new Component({}); * let r2 = new Component({}); * * // named net * typecad.named('vin').net(r1.pin(1), r2.pin(1)); * * // unnamed net * typecad.net(r1.pin(1), r2.pin(1)); * ``` */ named(name: string): this; /** * Connects a group of pins together. * * @param {...Pin[]} pins - Pins to connect. * @example * ```ts * let typecad = new Schematic('sheetname'); * let r1 = new Component({}); * let r2 = new Component({}); * * // named net * typecad.named('vin').net(r1.pin(1), r2.pin(1)); * * // unnamed net * typecad.net(r1.pin(1), r2.pin(1)); * ``` */ net(...pins: Pin[]): void; /** * Used internally * @ignore */ private make_sexp_net; /** * Creates schematic files. * * @param {...Component[]} components - All the components to be included in the schematic. * @example * ```ts * let typecad = new Schematic('sheetname'); * let r1 = new Component({}); * let r2 = new Component({}); * typecad.create(r1, r2); * ``` */ create(...component: Component[]): boolean; /** * Performs electrical rule checks. */ erc(): void; /** * Logs an error message and exits. * * @param {string} error - The error message to log. */ error(error: string): void; /** * Logs a warning message. * * @param {string} warning - The warning message to log. */ warn(warning: string): void; private getComponentIcon; private formatComponentDisplay; private displayGroupHierarchy; }