pub fn process_d_codes(gerber_data: String, flavor: GerberFlavor) -> String
Expand description
Process Gerber data to prepend “G54” to D-codes according to the CAD flavor.
KiCad: process all non-%ADD, non-G54D D-codes. Altium: skip D-codes on lines starting with G01/G02/G36/G37 with coordinates or lines that only contain a single Dxx*; other D-codes (including %ADD/%AM/G04) are processed.
§Arguments
gerber_data
- Raw Gerber file contentflavor
- KiCad or Altium
§Returns
Processed Gerber content with appropriate D-codes prefixed with “G54”
Examples found in repository?
examples/dcode_processing.rs (line 33)
5fn main() {
6 let gerber_sample = r#"
7%FSLAX46Y46*%
8%MOMM*%
9%ADD10C,0.15000*%
10G01*
11X-1125Y-965D02*
12X-1125Y965D01*
13X-1075Y915D01*
14X-1075Y-915D01*
15X1075Y-915D01*
16X1075Y915D01*
17G04 A simple D-code*
18X100Y200D11*
19G04 Multiple D-codes on one line*
20X50D12*Y50D13*
21G04 An already processed line, should be skipped*
22X-175Y-915G54D10*
23G04 A D-code with too few digits, should be skipped*
24X20Y30D3*
25G04 A D-code with too many digits, should be skipped*
26X40Y50D12345*
27M02*"#;
28
29 println!("--- Original Gerber Data ---");
30 println!("{}\n", gerber_sample);
31
32 // Process the Gerber data using the function.
33 let processed_data = process_d_codes(gerber_sample.to_string(), GerberFlavor::KiCad);
34
35 println!("--- Processed Gerber Data ---");
36 println!("{}", processed_data);
37}