TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
tmk::io Namespace Reference

Classes

class  BoardEditor
struct  LoadedBoard
struct  SrjPoint
struct  SrjObstacle
struct  SrjConnection
struct  SrjNet
 One electrical net: the connections and obstacles that tscircuit's connectivity map (lib/utils/getConnectivityMapFromSimpleRouteJson.ts) puts in one group. More...
struct  SrjRules
struct  SrjPlane
 A bus whose termination is a plane: every connection of the bus ends in a plane on layer. More...
struct  SrjProblem
struct  SrjImportOptions
struct  SrjBoardFiles
struct  SrjExport

Functions

bool flip_supported (const LoadedBoard &board, std::size_t index, std::string *why=nullptr)
 True if BoardEditor::flip_footprint mirrors every item of footprint index exactly: no copper on inner layers, no padstacks, no text on copper, and nothing it does not know (zones, text boxes, dimensions, private layers, ...).
std::string flip_layer_name (const model::Board &board, std::string_view name)
 KiCad's FlipLayer for outer layers: the first and last copper layer of board (by their names in the file) and F.X <-> B.X for the other side-specific layers; any other name unchanged.
std::string format_angle (double deg)
 Formats an angle the way KiCad writes it: shortest decimal, no trailing zeros ("90", "45.5").
LoadedBoard read_board_file (const std::string &path)
 Throws sexpr::ParseError or std::runtime_error on malformed files.
model::Board read_board (const sexpr::Document &doc)
 Reads the board as the document would be written: pending edits are applied first (the returned board's node ids then refer to the re-parsed text, so do not use them to edit doc further).
model::Netlist read_netlist_file (const std::string &path)
 Parses a KiCad s-expression netlist (format "E", from kicad-cli sch export netlist –format kicadsexpr).
model::Netlist netlist_from_schematic (const std::string &sch_path, const std::string &tmp_dir)
 Runs kicad-cli sch export netlist on a schematic and parses the result. Throws if kicad-cli fails.
model::DesignRules read_design_rules (const std::string &board_path)
 board_path is the .kicad_pcb; the project and rule files are looked up next to it with the same stem.
std::optional< Coord > parse_length (std::string_view s)
 Parses a KiCad length with an optional unit suffix ("0.2mm", "8mil", "0.01in", "150um", "0.2") to nm.
SrjProblem read_srj (const std::string &text)
 Parses SRJ text.
SrjProblem read_srj_file (const std::string &path)
std::string srj_layer_name (int z, int layer_count)
 "top", "inner1", ..., "bottom" for a stack index, and back (-1 if the name is not a layer of the stack).
int srj_layer_index (const std::string &name, int layer_count)
SrjBoardFiles srj_to_kicad (const SrjProblem &problem, const SrjImportOptions &opt={})
 The board is the problem mirrored in y at the same coordinates (x, -y), one footprint per componentId.
SrjExport srj_export (const std::string &problem_text, const model::Board &routed)
 Writes the tracks and vias of routed (a board made by srj_to_kicad from problem_text, then routed) as SRJ traces: one trace per pair of consecutive points of a connection, following the copper between their pads, then the copper no such path used.

Variables

constexpr double kSrjDefaultClearanceMm = 0.15
 tscircuit's fallbacks for what a problem leaves out: its router's default obstacle margin (defaultObstacleMargin ?
constexpr double kSrjDefaultViaPadMm = 0.3

Function Documentation

◆ flip_layer_name()

std::string tmk::io::flip_layer_name ( const model::Board & board,
std::string_view name )

KiCad's FlipLayer for outer layers: the first and last copper layer of board (by their names in the file) and F.X <-> B.X for the other side-specific layers; any other name unchanged.

◆ flip_supported()

bool tmk::io::flip_supported ( const LoadedBoard & board,
std::size_t index,
std::string * why = nullptr )

True if BoardEditor::flip_footprint mirrors every item of footprint index exactly: no copper on inner layers, no padstacks, no text on copper, and nothing it does not know (zones, text boxes, dimensions, private layers, ...).

why receives the first reason it cannot.

◆ format_angle()

std::string tmk::io::format_angle ( double deg)

Formats an angle the way KiCad writes it: shortest decimal, no trailing zeros ("90", "45.5").

◆ netlist_from_schematic()

model::Netlist tmk::io::netlist_from_schematic ( const std::string & sch_path,
const std::string & tmp_dir )

Runs kicad-cli sch export netlist on a schematic and parses the result. Throws if kicad-cli fails.

◆ parse_length()

std::optional< Coord > tmk::io::parse_length ( std::string_view s)

Parses a KiCad length with an optional unit suffix ("0.2mm", "8mil", "0.01in", "150um", "0.2") to nm.

◆ read_board()

model::Board tmk::io::read_board ( const sexpr::Document & doc)

Reads the board as the document would be written: pending edits are applied first (the returned board's node ids then refer to the re-parsed text, so do not use them to edit doc further).

◆ read_board_file()

LoadedBoard tmk::io::read_board_file ( const std::string & path)

Throws sexpr::ParseError or std::runtime_error on malformed files.

◆ read_design_rules()

model::DesignRules tmk::io::read_design_rules ( const std::string & board_path)

board_path is the .kicad_pcb; the project and rule files are looked up next to it with the same stem.

Missing files give KiCad's defaults and a warning, never an exception.

◆ read_netlist_file()

model::Netlist tmk::io::read_netlist_file ( const std::string & path)

Parses a KiCad s-expression netlist (format "E", from kicad-cli sch export netlist –format kicadsexpr).

◆ read_srj()

SrjProblem tmk::io::read_srj ( const std::string & text)

Parses SRJ text.

Throws std::runtime_error on malformed input or a field whose meaning is unknown where it matters (e.g. a layer name outside top/innerN/bottom).

◆ read_srj_file()

SrjProblem tmk::io::read_srj_file ( const std::string & path)

◆ srj_export()

SrjExport tmk::io::srj_export ( const std::string & problem_text,
const model::Board & routed )

Writes the tracks and vias of routed (a board made by srj_to_kicad from problem_text, then routed) as SRJ traces: one trace per pair of consecutive points of a connection, following the copper between their pads, then the copper no such path used.

Nets are matched by name, pads by position.

◆ srj_layer_index()

int tmk::io::srj_layer_index ( const std::string & name,
int layer_count )

◆ srj_layer_name()

std::string tmk::io::srj_layer_name ( int z,
int layer_count )

"top", "inner1", ..., "bottom" for a stack index, and back (-1 if the name is not a layer of the stack).

◆ srj_to_kicad()

SrjBoardFiles tmk::io::srj_to_kicad ( const SrjProblem & problem,
const SrjImportOptions & opt = {} )

The board is the problem mirrored in y at the same coordinates (x, -y), one footprint per componentId.

The output depends only on the problem and the options (UUIDs are counted, not drawn), so it is byte-identical across runs.

Variable Documentation

◆ kSrjDefaultClearanceMm

double tmk::io::kSrjDefaultClearanceMm = 0.15
inlineconstexpr

tscircuit's fallbacks for what a problem leaves out: its router's default obstacle margin (defaultObstacleMargin ?

? 0.15) and getViaDimensions' pad diameter.

Definition at line 92 of file srj.hpp.

◆ kSrjDefaultViaPadMm

double tmk::io::kSrjDefaultViaPadMm = 0.3
inlineconstexpr

Definition at line 93 of file srj.hpp.