use super::elements::PcbSmtPadElm;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum CopperLayer {
Top,
Inner(u8),
Bottom,
}
impl CopperLayer {
pub fn parse(name: Option<&str>) -> Result<Self, String> {
match name {
Some("top") => Ok(Self::Top),
Some("bottom") => Ok(Self::Bottom),
Some(other) => other
.strip_prefix("inner")
.and_then(|n| n.parse::<u8>().ok())
.filter(|n| *n >= 1)
.map(Self::Inner)
.ok_or_else(|| format!("unsupported copper layer '{other}'")),
None => Err("missing layer".to_string()),
}
}
pub fn file_name(self) -> String {
match self {
Self::Top => "F_Cu.gbr".to_string(),
Self::Inner(n) => format!("In{n}_Cu.gbr"),
Self::Bottom => "B_Cu.gbr".to_string(),
}
}
pub(super) fn title_and_function(self, layer_count: u8) -> (String, String) {
match self {
Self::Top => ("Top Copper (F_Cu)".to_string(), "Copper,L1,Top".to_string()),
Self::Inner(n) => (
format!("Inner Copper {n} (In{n}_Cu)"),
format!("Copper,L{},Inr", n + 1),
),
Self::Bottom => (
"Bottom Copper (B_Cu)".to_string(),
format!("Copper,L{layer_count},Bot"),
),
}
}
}
pub(super) fn pad_is_top(pad: &PcbSmtPadElm) -> Result<bool, String> {
match pad.layer.as_deref() {
Some("top") => Ok(true),
Some("bottom") => Ok(false),
Some(other) => Err(format!("unsupported copper layer '{other}'")),
None => Err("missing layer".to_string()),
}
}
pub(super) fn pad_exposed(pad: &PcbSmtPadElm, is_top: bool) -> Result<bool, String> {
Ok(pad_is_top(pad)? == is_top && pad.is_covered_with_solder_mask != Some(true))
}