Skip to content

WIP: [kicad-parser] write a KicadBoard #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mkovaxx
Copy link
Collaborator

@mkovaxx mkovaxx commented Mar 16, 2025

No description provided.

@mkovaxx mkovaxx self-assigned this Mar 16, 2025
@mkovaxx
Copy link
Collaborator Author

mkovaxx commented Mar 16, 2025

@bschwind The current data model seems to assume that the FootprintX and GraphicX structures are identical.
That seems not to be the case:
https://dev-docs.kicad.org/en/file-formats/sexpr-intro/index.html#_footprint_graphics_items
https://dev-docs.kicad.org/en/file-formats/sexpr-intro/index.html#_graphic_items

@mkovaxx mkovaxx requested a review from bschwind March 20, 2025 05:22
@bschwind
Copy link
Owner

The current data model seems to assume that the FootprintX and GraphicX structures are identical.
That seems not to be the case:

Yep, let's keep these as separate types.

Copy link
Owner

@bschwind bschwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good so far! A few questions:

  • What's the scope for this PR, or when do we consider it "done"? When we can write out a fully-functioning *.kicad_pcb file?
  • It would make sense to have a write_to_file<P: AsRef<Path>>(file: P) convenience function
  • Pretty printing of the S-expressions would be nice, maybe the sexp crate doesn't support that though
  • Just for fun I tried exporting a kicad_pcb file by reading the sample.kicad_pcb file and immediately serializing it again. When trying to read it into KiCAD, I got:
Screenshot 2025-03-20 at 15 38 38


pub fn write_board<W: std::io::Write>(
writer: &mut W,
board: &KicadBoard,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead be KicadPcb? I think my original plan was for KicadBoard to hold the actual board data like copper, footprints, silkscreens, etc, while KicadPcb would hold a KicadBoard, as well as extra data like the version and other metadata.

fn circle_to_sexp(circle: &GraphicCircle) -> Sexp {
let items = vec![
atom_s("gr_circle"),
cons_s("start", point_to_sexp(circle.center_point)),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cons_s("start", point_to_sexp(circle.center_point)),
cons_s("center", point_to_sexp(circle.center_point)),

atom_s(layer_str)
}

fn position_to_sexp(location: (f64, f64), rotation_degrees: f64) -> Sexp {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might call this orientation_to_sexp or transform_to_sexp, as I expected position to just mean an XY coordinate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants