pub struct Board(/* private fields */);Expand description
A complete PCB stackup: an ordered collection of Layers of any type.
Layers are identified by their LayerType; each type may appear at most
once. Use Board::add_layer to insert or merge a layer, and
LayerMerge::merge to combine two boards that share the same layer set.
Implementations§
Source§impl Board
impl Board
Sourcepub fn load(data: Vec<(&str, BufReader<&mut dyn Read>)>) -> LoadResult
pub fn load(data: Vec<(&str, BufReader<&mut dyn Read>)>) -> LoadResult
Parses a board from a list of (filename, reader) pairs.
The layer type is inferred from the file name (see
LayerType::from_file_name): the extension (e.g. .gtl → Top), or
for .gbr files the KiCad layer name (e.g. -F_Courtyard.gbr). A
specific X2 FileFunction embedded in the Gerber data takes precedence. Files with unrecognised extensions or parse failures are
collected in LoadResult::errors so the caller can inspect them without
losing the layers that did load correctly.
Sourcepub fn comment(&mut self, txt: String)
pub fn comment(&mut self, txt: String)
Appends a comment command to every layer that supports it (Gerber and Excellon).
Sourcepub fn from_folder(path: &Path) -> Result<LoadResult>
pub fn from_folder(path: &Path) -> Result<LoadResult>
Loads every file with a recognised Gerber or Excellon extension from path.
Files with unrecognised extensions are silently skipped.
Returns an Err only if the directory itself cannot be read.
Per-file open and parse failures are captured in LoadResult::errors
so the caller can inspect them without losing the successfully loaded layers.
When the parallel feature is enabled, files are parsed concurrently
using Rayon.
Sourcepub fn layers_mut(&mut self) -> &mut [Layer]
pub fn layers_mut(&mut self) -> &mut [Layer]
Returns mutable references to all layers in insertion order.
Sourcepub fn add_layer(&mut self, layer: impl Into<Layer>) -> Result<(), MergeError>
pub fn add_layer(&mut self, layer: impl Into<Layer>) -> Result<(), MergeError>
Inserts a layer into the board, or merges it into the existing layer of the same type if one is already present.
Accepts anything that converts into a Layer (e.g. GerberLayerData,
ExcellonLayerData).
A failed merge leaves the board unchanged.
Sourcepub fn has_undefined(&self) -> bool
pub fn has_undefined(&self) -> bool
Returns true if any layer has type LayerType::UndefinedGerber.
Sourcepub fn get_undefined(&self) -> Vec<&Layer>
pub fn get_undefined(&self) -> Vec<&Layer>
Returns all layers with type LayerType::UndefinedGerber.
Sourcepub fn get_undefined_mut(&mut self) -> Vec<&mut Layer>
pub fn get_undefined_mut(&mut self) -> Vec<&mut Layer>
Returns mutable references to all layers with type LayerType::UndefinedGerber.
Sourcepub fn get_layer(&self, ty: &LayerType) -> Option<&Layer>
pub fn get_layer(&self, ty: &LayerType) -> Option<&Layer>
Returns the layer with the given type, or None if not present.
Sourcepub fn get_layer_mut(&mut self, ty: &LayerType) -> Option<&mut Layer>
pub fn get_layer_mut(&mut self, ty: &LayerType) -> Option<&mut Layer>
Returns a mutable reference to the layer with the given type, or None if not present.
Sourcepub fn write_to<T>(
&self,
options: &WriteOptions,
f: &mut impl FnMut(&Layer) -> Result<BufWriter<T>>,
) -> Result<(), WriteError>where
T: Write,
pub fn write_to<T>(
&self,
options: &WriteOptions,
f: &mut impl FnMut(&Layer) -> Result<BufWriter<T>>,
) -> Result<(), WriteError>where
T: Write,
Writes every layer through a writer obtained from f.
Unmodified layers are written as their original bytes. Everything is
checked (names, and completeness of edited layers) before f is
called for the first time, so a rejected export opens no writer.
Sourcepub fn check_write(&self, options: &WriteOptions) -> Result<(), WriteError>
pub fn check_write(&self, options: &WriteOptions) -> Result<(), WriteError>
Runs every check write_to performs before
writing, without writing anything.
Sourcepub fn unresolved_edits(&self) -> Vec<(String, LayerDiagnostics)>
pub fn unresolved_edits(&self) -> Vec<(String, LayerDiagnostics)>
Edited layers that would be refused without
WriteOptions::allow_incomplete, with their diagnostics.
Sourcepub fn diagnostics(&self) -> Vec<(String, LayerDiagnostics)>
pub fn diagnostics(&self) -> Vec<(String, LayerDiagnostics)>
Interpretation diagnostics of every layer, by layer name.
Sourcepub fn write_to_folder(
&self,
path: &Path,
options: &WriteOptions,
) -> Result<(), WriteError>
pub fn write_to_folder( &self, path: &Path, options: &WriteOptions, ) -> Result<(), WriteError>
Writes all layers to path, creating the directory if necessary.
Each layer is written to a file named layer.name inside path. Files
are first written to temporary names and only renamed into place once
every layer was written successfully, so a write failure leaves
existing files untouched (the renames themselves are not atomic as a
group).
Trait Implementations§
Source§impl From<ExcellonLayerData> for Board
impl From<ExcellonLayerData> for Board
Source§fn from(data: ExcellonLayerData) -> Self
fn from(data: ExcellonLayerData) -> Self
Creates a board containing a single Excellon drill layer.
Source§impl From<GerberLayerData> for Board
impl From<GerberLayerData> for Board
Source§fn from(data: GerberLayerData) -> Self
fn from(data: GerberLayerData) -> Self
Creates a board containing a single Gerber layer.
Source§impl LayerCorners for Board
impl LayerCorners for Board
Source§fn get_corners(&self) -> (Pos, Pos)
fn get_corners(&self) -> (Pos, Pos)
Returns the bounding box of the board.
Computed as the union of all layer corners (Gerber and Excellon drill),
excluding KeepOut, Info, SidePlating and courtyard layers as they
don’t represent physical board area.
Source§fn get_size(&self) -> Size
fn get_size(&self) -> Size
get_corners.Source§impl LayerMerge for Board
impl LayerMerge for Board
Source§fn merge(&mut self, other: &Self) -> Result<(), MergeError>
fn merge(&mut self, other: &Self) -> Result<(), MergeError>
Merges layers from other into the corresponding layers of self.
Only layers whose LayerType already exists in self are updated.
Layer types present in other but not in self are ignored — use
add_layer to insert a new layer instead.
Every layer pair is checked first, so a failure on any layer leaves the whole board unchanged.
Source§fn check_merge(&self, _other: &Self) -> Result<(), MergeError>
fn check_merge(&self, _other: &Self) -> Result<(), MergeError>
merge would succeed, without
changing anything.