1- use :: std:: collections:: HashMap ;
21use gerber_parser:: {
32 coordinates_from_gerber, coordinates_offset_from_gerber, parse, partial_coordinates_from_gerber,
43} ;
@@ -10,11 +9,13 @@ use gerber_types::{
109 CopperType , DCode , DrillFunction , DrillRouteType , ExtendedCode , ExtendedPosition ,
1110 FiducialScope , FileAttribute , FileFunction , FilePolarity , FunctionCode , GCode ,
1211 GenerationSoftware , GerberDate , GerberError , IPC4761ViaProtection , Ident , InterpolationMode ,
13- MCode , MacroBoolean , MacroContent , MacroDecimal , MacroInteger , Net , NonPlatedDrill ,
14- ObjectAttribute , Operation , OutlinePrimitive , Part , Pin , PlatedDrill , Polygon ,
15- PolygonPrimitive , Position , Profile , QuadrantMode , Rectangular , SmdPadType , StepAndRepeat ,
16- ThermalPrimitive , Unit , Uuid , VariableDefinition , VectorLinePrimitive ,
12+ MCode , MacroBoolean , MacroContent , MacroDecimal , MacroInteger , Mirroring , Net , NonPlatedDrill ,
13+ ObjectAttribute , Operation , OutlinePrimitive , Part , Pin , PlatedDrill , Polarity , Polygon ,
14+ PolygonPrimitive , Position , Profile , QuadrantMode , Rectangular , Rotation , Scaling , SmdPadType ,
15+ StepAndRepeat , ThermalPrimitive , Unit , Uuid , VariableDefinition , VectorLinePrimitive ,
1716} ;
17+ use std:: collections:: HashMap ;
18+ use strum:: VariantArray ;
1819mod util;
1920use gerber_parser:: util:: gerber_to_reader;
2021use util:: testing:: logging_init;
@@ -548,6 +549,102 @@ fn omitted_coordinate() {
548549 )
549550}
550551
552+ // See gerber spec 2021-02, section 4.5
553+ #[ test]
554+ fn test_load_polarity_scaling_mirroring_rotation ( ) {
555+ // given
556+ let reader = gerber_to_reader (
557+ r#"
558+ %LPD*%
559+ %LPC*%
560+ %LMN*%
561+ %LMX*%
562+ %LMY*%
563+ %LMXY*%
564+ %LR0*%
565+ %LR359.99*%
566+ %LR-359.99*%
567+ %LS0.5*%
568+ %LS99.99*%
569+ "# ,
570+ ) ;
571+
572+ // when
573+ parse_and_filter ! ( reader, commands, filtered_commands, |cmd| matches!(
574+ cmd,
575+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadPolarity ( _) ) )
576+ | Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadMirroring ( _) ) )
577+ | Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadScaling ( _) ) )
578+ | Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadRotation ( _) ) )
579+ ) ) ;
580+
581+ // then
582+ assert_eq_commands ! (
583+ filtered_commands,
584+ vec![
585+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadPolarity (
586+ Polarity :: Dark
587+ ) ) ) ,
588+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadPolarity (
589+ Polarity :: Clear
590+ ) ) ) ,
591+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadMirroring (
592+ Mirroring :: None
593+ ) ) ) ,
594+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadMirroring (
595+ Mirroring :: X
596+ ) ) ) ,
597+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadMirroring (
598+ Mirroring :: Y
599+ ) ) ) ,
600+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadMirroring (
601+ Mirroring :: XY
602+ ) ) ) ,
603+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadRotation (
604+ Rotation { rotation: 0.0 }
605+ ) ) ) ,
606+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadRotation (
607+ Rotation { rotation: 359.99 }
608+ ) ) ) ,
609+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadRotation (
610+ Rotation { rotation: -359.99 }
611+ ) ) ) ,
612+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadScaling ( Scaling {
613+ scale: 0.5
614+ } ) ) ) ,
615+ Ok ( Command :: ExtendedCode ( ExtendedCode :: LoadScaling ( Scaling {
616+ scale: 99.99
617+ } ) ) ) ,
618+ ]
619+ ) ;
620+ }
621+
622+ // See gerber spec 2021-02, section 4.5
623+ #[ test]
624+ fn test_load_scaling_zero ( ) {
625+ // given
626+ let reader = gerber_to_reader (
627+ r#"
628+ %LS0*%
629+ "# ,
630+ ) ;
631+ // when
632+ let doc = parse ( reader) . unwrap ( ) ;
633+ dump_commands ( & doc. commands ) ;
634+
635+ // then
636+ let errors = doc. into_errors ( ) ;
637+
638+ assert ! ( matches!( errors. first( ) . unwrap( ) ,
639+ GerberParserErrorWithContext {
640+ error: ContentError :: InvalidParameter {
641+ parameter,
642+ } ,
643+ line: Some ( ( number, content) ) ,
644+ } if parameter. eq( "0" ) && * number == 2 && content. eq( "%LS0*%" )
645+ ) ) ;
646+ }
647+
551648/// Test Step and Repeat command (%SR*%)
552649#[ test]
553650fn step_and_repeat ( ) {
@@ -841,7 +938,7 @@ fn TA_aperture_attributes() {
841938 ( $name: ident) => { {
842939 let mut result = vec![ ApertureFunction :: $name( None ) ] ;
843940 result. extend(
844- IPC4761ViaProtection :: values ( )
941+ < IPC4761ViaProtection as VariantArray > :: VARIANTS
845942 . iter( )
846943 . cloned( )
847944 . map( |value| ApertureFunction :: $name( Some ( value) ) )
0 commit comments