@@ -2,13 +2,13 @@ use crate::document::GerberDoc;
22use crate :: error:: ContentError ;
33use crate :: gerber_types:: {
44 Aperture , ApertureAttribute , ApertureFunction , ApertureMacro , CenterLinePrimitive , Circle ,
5- CirclePrimitive , Command , CoordinateFormat , Coordinates , DCode , ExtendedCode , FiducialScope ,
6- FileAttribute , FileFunction , FilePolarity , FunctionCode , GCode , InterpolationMode , MCode ,
7- MacroBoolean , MacroContent , MacroDecimal , MacroInteger , Operation , OutlinePrimitive , Part ,
8- Polarity , Polygon , PolygonPrimitive , QuadrantMode , Rectangular , SmdPadType , StepAndRepeat ,
9- Unit , VectorLinePrimitive ,
5+ CirclePrimitive , Command , CoordinateFormat , DCode , ExtendedCode , FiducialScope , FileAttribute ,
6+ FileFunction , FilePolarity , FunctionCode , GCode , InterpolationMode , MCode , MacroBoolean ,
7+ MacroContent , MacroDecimal , MacroInteger , Operation , OutlinePrimitive , Part , Polarity , Polygon ,
8+ PolygonPrimitive , QuadrantMode , Rectangular , SmdPadType , StepAndRepeat , Unit ,
9+ VectorLinePrimitive ,
1010} ;
11- use crate :: util:: { coordinates_offset_from_gerber , partial_coordinates_from_gerber } ;
11+ use crate :: util:: { partial_coordinates_from_gerber , partial_coordinates_offset_from_gerber } ;
1212use crate :: ParseError ;
1313use gerber_types:: {
1414 ApertureBlock , ComponentCharacteristics , ComponentDrill , ComponentMounting , ComponentOutline ,
@@ -375,7 +375,6 @@ fn parse_line<T: Read>(
375375 Ok ( vec ! [ parse_aperture_selection_or_command(
376376 line,
377377 linechars. clone( ) ,
378- gerber_doc,
379378 ) ] )
380379 }
381380 'M' => Ok ( vec ! [ Ok ( FunctionCode :: MCode ( MCode :: EndOfFile ) . into( ) ) ] ) ,
@@ -1202,35 +1201,24 @@ fn parse_aperture_code(code_str: &str) -> Result<i32, ContentError> {
12021201fn parse_aperture_selection_or_command (
12031202 line : & str ,
12041203 linechars : Chars ,
1205- gerber_doc : & GerberDoc ,
12061204) -> Result < Command , ContentError > {
12071205 let aperture_str = linechars. as_str ( ) ;
12081206 if let Ok ( aperture_code) = parse_aperture_code ( aperture_str) {
12091207 Ok ( FunctionCode :: DCode ( DCode :: SelectAperture ( aperture_code) ) . into ( ) )
12101208 } else {
1211- parse_command ( line, gerber_doc )
1209+ parse_command ( line)
12121210 }
12131211}
12141212
1215- fn parse_command ( command_str : & str , gerber_doc : & GerberDoc ) -> Result < Command , ContentError > {
1213+ fn parse_command ( command_str : & str ) -> Result < Command , ContentError > {
12161214 static RE_STANDALONE_D : Lazy < Regex > = lazy_regex ! ( r"D(0)?([1-3])\*" ) ;
12171215 if let Some ( captures) = RE_STANDALONE_D . captures ( command_str) {
12181216 let command_code = captures. get ( 2 ) . unwrap ( ) . as_str ( ) ;
12191217 {
1220- let format = gerber_doc
1221- . format_specification
1222- . ok_or ( ContentError :: OperationBeforeFormat { } ) ?;
1223-
1224- let coords = Coordinates {
1225- x : None ,
1226- y : None ,
1227- format,
1228- } ;
1229-
12301218 let operation = match command_code {
1231- "1" => Operation :: Interpolate ( coords , None ) ,
1232- "2" => Operation :: Move ( coords ) ,
1233- "3" => Operation :: Flash ( coords ) ,
1219+ "1" => Operation :: Interpolate ( None , None ) ,
1220+ "2" => Operation :: Move ( None ) ,
1221+ "3" => Operation :: Flash ( None ) ,
12341222 _ => unreachable ! ( ) ,
12351223 } ;
12361224 Ok ( Command :: FunctionCode ( FunctionCode :: DCode (
@@ -1254,54 +1242,40 @@ fn parse_interpolation(line: &str, gerber_doc: &GerberDoc) -> Result<Command, Co
12541242 . get ( 2 )
12551243 . map ( |y| parse_coord :: < i64 > ( y. as_str ( ) ) )
12561244 . transpose ( ) ?;
1245+ let i_coord = regmatch
1246+ . get ( 3 )
1247+ . map ( |i| parse_coord :: < i64 > ( i. as_str ( ) ) )
1248+ . transpose ( ) ?;
1249+ let j_coord = regmatch
1250+ . get ( 4 )
1251+ . map ( |i| parse_coord :: < i64 > ( i. as_str ( ) ) )
1252+ . transpose ( ) ?;
12571253
1258- if let Some ( ( i_offset_raw, j_offset_raw) ) = regmatch. get ( 3 ) . zip ( regmatch. get ( 4 ) ) {
1259- // we have X,Y,I,J parameters and we are doing circular interpolation
1260- let i_offset = parse_coord :: < i64 > ( i_offset_raw. as_str ( ) ) ?;
1261- let j_offset = parse_coord :: < i64 > ( j_offset_raw. as_str ( ) ) ?;
1262-
1263- let fs = gerber_doc
1264- . format_specification
1265- . ok_or ( ContentError :: OperationBeforeFormat { } ) ?;
1254+ let fs = gerber_doc
1255+ . format_specification
1256+ . ok_or ( ContentError :: OperationBeforeFormat { } ) ?;
12661257
1267- let coordinates =
1268- partial_coordinates_from_gerber ( x_coord, y_coord, fs) . map_err ( |error| {
1269- ContentError :: CoordinateFormatMismatch {
1270- format : fs,
1271- cause : error,
1272- }
1273- } ) ?;
1258+ let coordinates =
1259+ partial_coordinates_from_gerber ( x_coord, y_coord, fs) . map_err ( |error| {
1260+ ContentError :: CoordinateFormatMismatch {
1261+ format : fs,
1262+ cause : error,
1263+ }
1264+ } ) ?;
12741265
1275- let offset =
1276- coordinates_offset_from_gerber ( i_offset , j_offset , fs) . map_err ( |error| {
1277- ContentError :: CoordinateFormatMismatch {
1278- format : fs,
1279- cause : error,
1280- }
1281- } ) ?;
1266+ let offset =
1267+ partial_coordinates_offset_from_gerber ( i_coord , j_coord , fs) . map_err ( |error| {
1268+ ContentError :: CoordinateFormatMismatch {
1269+ format : fs,
1270+ cause : error,
1271+ }
1272+ } ) ?;
12821273
1283- Ok ( FunctionCode :: DCode ( DCode :: Operation ( Operation :: Interpolate (
1284- coordinates,
1285- Some ( offset) ,
1286- ) ) )
1287- . into ( ) )
1288- } else {
1289- let fs = gerber_doc
1290- . format_specification
1291- . ok_or ( ContentError :: OperationBeforeFormat { } ) ?;
1292-
1293- // linear interpolation, only X,Y parameters
1294- Ok ( FunctionCode :: DCode ( DCode :: Operation ( Operation :: Interpolate (
1295- partial_coordinates_from_gerber ( x_coord, y_coord, fs) . map_err ( |error| {
1296- ContentError :: CoordinateFormatMismatch {
1297- format : fs,
1298- cause : error,
1299- }
1300- } ) ?,
1301- None ,
1302- ) ) )
1303- . into ( ) )
1304- }
1274+ Ok ( FunctionCode :: DCode ( DCode :: Operation ( Operation :: Interpolate (
1275+ coordinates,
1276+ offset,
1277+ ) ) )
1278+ . into ( ) )
13051279 }
13061280 None => Err ( ContentError :: NoRegexMatch {
13071281 regex : RE_INTERPOLATION . clone ( ) ,
0 commit comments