pub struct GerberDoc {
pub units: Option<Unit>,
pub format_specification: Option<CoordinateFormat>,
pub apertures: HashMap<i32, Aperture>,
pub commands: Vec<Result<Command, GerberParserErrorWithContext>>,
pub image_name: Option<String>,
}Expand description
Representation of a Gerber document
Fields§
§units: Option<Unit>unit type, defined once per document
format_specification: Option<CoordinateFormat>format specification for coordinates, defined once per document
apertures: HashMap<i32, Aperture>map of apertures which can be used in draw commands later on in the document.
commands: Vec<Result<Command, GerberParserErrorWithContext>>Everything else - draw commands, comments, attributes, etc.
image_name: Option<String>Image Name, 8.1.3. Deprecated, but still used by fusion 360.
Implementations§
Source§impl GerberDoc
impl GerberDoc
pub fn new() -> GerberDoc
Sourcepub fn into_commands(self) -> Vec<Command>
pub fn into_commands(self) -> Vec<Command>
Convert Self into a representation of a gerber document purely in terms of elements provided in the gerber-types rust crate.
This will ignore any errors encountered during parsing, to access errors, use errors first.
Examples found in repository?
6pub fn main() -> anyhow::Result<()> {
7 use std::fs::File;
8 use std::io::BufReader;
9
10 let path = "assets/reference_files/two_square_boxes.gbr";
11
12 // open a .gbr file from system
13 let file = File::open(path).unwrap();
14 let reader = BufReader::new(file);
15
16 // Now we parse the file to a GerberDoc, if io errors occur a partial gerber_doc will be returned along with the error
17 let gerber_doc = gerber_parser::parse(reader)
18 .map_err(|(_doc, parse_error)| anyhow!("Error parsing file: {:?}", parse_error))?;
19
20 let commands: Vec<&Command> = gerber_doc.commands();
21
22 // Now you can use the commands as you wish
23 println!("Parsed document. command_count: {} ", commands.len());
24 dump_commands(&commands);
25
26 // there are other methods that consume the document to yield an 'atomic' representation purely
27 // in terms of types defined in the gerber-types crate
28 let _commands: Vec<Command> = gerber_doc.into_commands();
29
30 Ok(())
31}Sourcepub fn commands(&self) -> Vec<&Command>
pub fn commands(&self) -> Vec<&Command>
Get a representation of a gerber document purely in terms of elements provided in the gerber-types rust crate.
Similar to into_commands(), but does not consume the Self, and returns references to Commands
This will ignore any errors encountered during parsing, to access errors, use errors.
Examples found in repository?
6pub fn main() -> anyhow::Result<()> {
7 use std::fs::File;
8 use std::io::BufReader;
9
10 let path = "assets/reference_files/two_square_boxes.gbr";
11
12 // open a .gbr file from system
13 let file = File::open(path).unwrap();
14 let reader = BufReader::new(file);
15
16 // Now we parse the file to a GerberDoc, if io errors occur a partial gerber_doc will be returned along with the error
17 let gerber_doc = gerber_parser::parse(reader)
18 .map_err(|(_doc, parse_error)| anyhow!("Error parsing file: {:?}", parse_error))?;
19
20 let commands: Vec<&Command> = gerber_doc.commands();
21
22 // Now you can use the commands as you wish
23 println!("Parsed document. command_count: {} ", commands.len());
24 dump_commands(&commands);
25
26 // there are other methods that consume the document to yield an 'atomic' representation purely
27 // in terms of types defined in the gerber-types crate
28 let _commands: Vec<Command> = gerber_doc.into_commands();
29
30 Ok(())
31}pub fn into_errors(self) -> Vec<GerberParserErrorWithContext>
Sourcepub fn errors(&self) -> Vec<&GerberParserErrorWithContext>
pub fn errors(&self) -> Vec<&GerberParserErrorWithContext>
Similar to into_errors(), but does not consume the Self, and returns references to errors