Skip to content

Commit

Permalink
feat: add serde feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wowkster committed May 29, 2024
1 parent 72e073f commit 20e7848
Show file tree
Hide file tree
Showing 25 changed files with 395 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.features": "all"
}
31 changes: 27 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions kicad_format/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kicad_format"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "A library for parsing KiCad 7.10 files into a more data driven representation"
authors = ["Adrian Wowk <[email protected]>"]
Expand All @@ -9,9 +9,15 @@ license = "MIT"
[dependencies]
kicad_sexpr = { path = "../kicad_sexpr" }
regex = "1.10.3"
serde = { version = "1.0.130", features = ["derive"], optional = true }
thiserror = "1.0.56"
uuid = { version = "1.7.0", features = ["v4", "fast-rng"] }
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }


[dev-dependencies]
ansi_term = "0.12.1"
diff = "0.1.13"


[features]
serde = ["dep:serde", "uuid/serde"]
11 changes: 11 additions & 0 deletions kicad_format/src/common/footprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub mod text;
/// A footprint inlined within a PCB file.
///
/// TODO: move to pcb module
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintInlined {
pub library_link: LibraryId,
Expand Down Expand Up @@ -299,6 +301,8 @@ impl ToSexpr for FootprintInlined {
// ############################################################################

/// How pads are covered by copper in Zone
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone, Copy)]
#[repr(u8)]
pub enum ZoneConnectKind {
Expand Down Expand Up @@ -331,6 +335,8 @@ impl TryFrom<u8> for ZoneConnectKind {
// ############################################################################

/// Attributes of the footprint (ex. SMD, through-hole, included in BOM, etc.)
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Default, Clone)]
pub struct FootprintAttributes {
pub smd: bool,
Expand Down Expand Up @@ -395,6 +401,9 @@ impl ToSexpr for FootprintAttributes {

/// All the types of graphics items that can be part of a footprint (images,
/// text, text boxes, shapes, etc.)
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
#[derive(Debug, PartialEq, Clone)]
pub enum FootprintGraphicsItem {
Image(Image),
Expand Down Expand Up @@ -462,6 +471,8 @@ impl ToSexpr for FootprintGraphicsItem {
// ############################################################################

/// A 3D model associated with a footprint.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct Model {
pub file: String,
Expand Down
17 changes: 17 additions & 0 deletions kicad_format/src/common/footprint/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::{
};

/// Common properties shared by the different shapes.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintShape {
pub locked: bool,
Expand All @@ -19,6 +21,9 @@ pub struct FootprintShape {
}

/// All the different types of shapes allowed within a footprint.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
#[derive(Debug, PartialEq, Clone)]
pub enum FootprintShapeKind {
Line(FootprintLine),
Expand Down Expand Up @@ -221,39 +226,51 @@ impl ToSexpr for FootprintShape {
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintLine {
pub start: Vec2D,
pub end: Vec2D,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintRectangle {
pub start: Vec2D,
pub end: Vec2D,
pub fill: SimpleFillMode,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintCircle {
pub center: Vec2D,
pub end: Vec2D,
pub fill: SimpleFillMode,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintArc {
pub start: Vec2D,
pub midpoint: Vec2D,
pub end: Vec2D,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintPolygon {
pub points: CoordinatePointList,
pub fill: SimpleFillMode,
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintBezier {
pub points: [Vec2D; 4],
Expand Down
8 changes: 8 additions & 0 deletions kicad_format/src/common/footprint/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::{
};

/// A footprint text element.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintText {
pub kind: FootprintTextKind,
Expand Down Expand Up @@ -81,6 +83,8 @@ impl ToSexpr for FootprintText {
///
/// Reference and value always live on silkscreen (on the footprint side);
/// other texts are planned to go on whatever layer the user wants.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum FootprintTextKind {
Reference,
Expand All @@ -97,6 +101,8 @@ simple_to_from_string! {

/// An extension of the normal [`Position`](crate::common::Position) struct that includes an `unlocked`
/// field
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintTextPosition {
pub x: f32,
Expand Down Expand Up @@ -140,6 +146,8 @@ impl ToSexpr for FootprintTextPosition {
// FIXME: Really should be an enum because there are 2 valid types of text boxes
// (axis aligned and partially rotated)
/// A footprint text box element.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Debug, PartialEq, Clone)]
pub struct FootprintTextBox {
pub locked: bool,
Expand Down
Loading

0 comments on commit 20e7848

Please sign in to comment.