altium_format/lib.rs
1// SPDX-License-Identifier: GPL-3.0-only
2// SPDX-FileCopyrightText: 2026 Alexander Kiselev <alex@akiselev.com>
3//
4//! Altium file format library for Rust.
5//!
6//! This library provides read/write support for Altium Designer files including:
7//! - SchLib (Schematic symbol library)
8//! - PcbLib (PCB footprint library)
9//! - SchDoc (Schematic document)
10//! - PcbDoc (PCB document)
11//!
12//! # Architecture
13//!
14//! The library is organized into several modules:
15//!
16//! - [`types`] - Core data types (coordinates, units, layers, parameters)
17//! - [`traits`] - Serialization traits for derive macros
18//! - [`records`] - Record types for schematic and PCB primitives
19//! - [`io`] - File I/O utilities for CFB format
20//! - [`error`] - Error types
21//!
22//! # Derive Macros
23//!
24//! Record types can be defined using derive macros for automatic serialization:
25//!
26//! ```ignore
27//! use altium_format_derive::AltiumRecord;
28//!
29//! #[derive(AltiumRecord)]
30//! #[altium(record_id = 2, format = "params")]
31//! pub struct SchPin {
32//! #[altium(flatten)]
33//! pub base: SchGraphicalBase,
34//!
35//! #[altium(param = "ELECTRICAL", default)]
36//! pub electrical: PinElectricalType,
37//!
38//! #[altium(unknown)]
39//! pub unknown_params: UnknownFields,
40//! }
41//! ```
42//!
43//! # Quick Start
44//!
45//! ## Reading a Schematic Library
46//!
47//! ```no_run
48//! use altium_format::io::SchLib;
49//! use std::fs::File;
50//! use std::io::BufReader;
51//!
52//! let file = File::open("components.SchLib")?;
53//! let lib = SchLib::open(BufReader::new(file))?;
54//!
55//! for component in &lib.components {
56//! println!("Component: {}", component.name());
57//! println!(" Pins: {}", component.pin_count());
58//! }
59//! # Ok::<(), altium_format::error::AltiumError>(())
60//! ```
61//!
62//! ## Creating a Footprint
63//!
64//! ```no_run
65//! use altium_format::footprint::FootprintBuilder;
66//! use altium_format::records::pcb::PcbPadShape;
67//!
68//! let mut builder = FootprintBuilder::new("SOIC-8");
69//! builder.add_dual_row_smd(
70//! 4, // pads per side
71//! 1.27, // pitch (mm)
72//! 5.3, // row spacing (mm)
73//! 1.5, // pad width (mm)
74//! 0.6, // pad height (mm)
75//! PcbPadShape::Rectangular,
76//! );
77//! let component = builder.build_deterministic(&mut ());
78//! ```
79//!
80//! # Example
81//!
82//! ```ignore
83//! use altium_format::types::{Coord, CoordPoint, ParameterCollection};
84//!
85//! // Parse parameters from Altium format
86//! let params = ParameterCollection::from_string("|RECORD=1|NAME=Test|X=100mil|");
87//! let name = params.get("NAME").unwrap().as_str();
88//! let x = params.get("X").unwrap().as_coord_or(Coord::ZERO);
89//! ```
90
91pub mod api;
92pub mod dump;
93pub mod edit;
94pub mod error;
95pub mod footprint;
96pub mod format;
97pub mod io;
98pub mod ops;
99pub mod query;
100pub mod records;
101pub mod traits;
102pub mod tree;
103pub mod types;
104
105pub use error::{AltiumError, Result};
106pub use query::{
107 Pattern, QueryMatch, Selector, SelectorEngine, SelectorParser, query_records,
108 query_records_with_doc_name,
109};
110pub use traits::{
111 AltiumRecord, FromBinary, FromParamValue, FromParams, PcbPrimitive, SchPrimitive, ToBinary,
112 ToParamValue, ToParams,
113};
114pub use tree::{BreadthFirstWalker, ParentRef, RecordId, RecordTree, TreeRecord, TreeWalker};
115pub use types::{
116 Color, Coord, CoordPoint, CoordPoint3D, CoordRect, Layer, ParameterCollection, ParameterValue,
117 Unit, UnknownFields,
118};
119
120// Re-export derive macros
121pub use altium_format_derive::{AltiumBase, AltiumEnum, AltiumRecord};