Skip to content

formatter

formatter

pygerber.gerberx3.formatter module contains implementation Formatter class which implements configurable Gerber code formatting.

FormatterError

Bases: Exception

Formatter error.

Source code in src/pygerber/gerberx3/formatter/formatter.py
class FormatterError(Exception):
    """Formatter error."""

Formatter

Bases: AstVisitor

Gerber X3 compatible formatter.

Source code in src/pygerber/gerberx3/formatter/formatter.py
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
class Formatter(AstVisitor):
    """Gerber X3 compatible formatter."""

    class MacroSplitMode(Enum):
        """Macro split mode."""

        NONE = "none"
        PRIMITIVES = "primitives"
        PARAMETERS = "parameters"

    def __init__(  # noqa: PLR0913
        self,
        *,
        indent_character: Literal[" ", "\t"] = " ",
        macro_body_indent: str | int = 0,
        macro_param_indent: str | int = 0,
        macro_split_mode: MacroSplitMode = MacroSplitMode.PRIMITIVES,
        macro_end_in_new_line: bool = False,
        block_aperture_body_indent: str | int = 0,
        step_and_repeat_body_indent: str | int = 0,
        float_decimal_places: int = -1,
        float_trim_trailing_zeros: bool = True,
        d01_indent: int | str = 0,
        d02_indent: int | str = 0,
        d03_indent: int | str = 0,
        line_end: Literal["\n", "\r\n"] = "\n",
        empty_line_before_polarity_switch: bool = False,
        keep_non_standalone_codes: bool = True,
        remove_g54: bool = False,
        remove_g55: bool = False,
        explicit_parenthesis: bool = False,
        strip_whitespace: bool = False,
    ) -> None:
        r"""Initialize Formatter instance.

        Parameters
        ----------
        indent_character: Literal[" ", "\t"], optional
            Character used for indentation, by default " "
        macro_body_indent : str | int, optional
            Indentation of macro body, by default 0
        macro_param_indent: str | int, optional
            Indentation of macro parameters, by default 0
            This indentation is added on top of macro body indentation.
            This has effect only when `macro_split_mode` is `PARAMETERS`.
        macro_split_mode : `Formatter.MacroSplitMode`, optional
            Changes how macro definitions are formatted, by default `NONE`
            When `NONE` is selected, macro will be formatted as a single line.
            ```gerber
            %AMDonut*1,1,$1,$2,$3*$4=$1x0.75*1,0,$4,$2,$3*%
            ```
            When `PRIMITIVES` is selected, macro will be formatted with each primitive
            on a new line.
            ```gerber
            %AMDonut*
            1,1,$1,$2,$3*
            $4=$1x0.75*
            1,0,$4,$2,$3*%
            ```
            When `PARAMETERS` is selected, macro will be formatted with each primitive
            on a new line and each parameter of a primitive on a new line.
            ```gerber
            %AMDonut*
            1,
            1,
            $1,
            $2,
            $3*
            $4=$1x0.75*
            1,
            0,
            $4,
            $2,
            $3*%
            ```
            Use `macro_body_indent` and `macro_param_indent` to control indentation.
        macro_end_in_new_line: bool, optional
            Place % sign which marks the end of macro in new line, by default False
        block_aperture_body_indent : str | int, optional
            Indentation of block aperture definition body, by default 0
            This indentations stacks for nested block apertures.
        step_and_repeat_body_indent : str | int, optional
            Indentation of step and repeat definition body, by default 0
            This indentations stacks for nested step and repeat blocks.
        float_decimal_places : int, optional
            Limit number of decimal places shown for float values, by default -1
            Negative values are interpreted as no limit.
        float_trim_trailing_zeros : bool, optional
            Remove trailing zeros from floats, by default True
            When this is enabled, after floating point number is formatted with respect
            to `float_decimal_places`, trailing zeros are removed. If all zeros after
            decimal point are removed, decimal point is also removed.
        d01_indent : str | int, optional
            Custom indentation of D01 command, by default 0
        d02_indent : str | int, optional
            Custom indentation of D02 command, by default 0
        d03_indent : str | int, optional
            Custom indentation of D03 command, by default 0
        line_end : Literal["\n", "\r\n"], optional
            Line ending character, Unix or Windows style, by default "\n" (Unix style)
            If `strip_whitespace` is enabled, no line end will be used.
        empty_line_before_polarity_switch : bool, optional
            Add empty line before polarity switch, by default False
            This enhances visibility of sequences of commands with different
            polarities.
        keep_non_standalone_codes: bool, optional
            Keep non-standalone codes in the output, by default True
            If this option is disabled, codes that are not standalone, ie. `G70D02*`
            will be divided into two separate commands, `G70*` and `D02*`, otherwise
            they will be kept as is.
        remove_g54: bool, optional
            Remove G54 code from output, by default False
            G54 code has no effect on the output, it was used in legacy files to
            prefix select aperture command.
        remove_g55: bool, optional
            Remove G55 code from output, by default False
            G55 code has no effect on the output, it was used in legacy files to
            prefix flash command.
        explicit_parenthesis: bool, optional
            Add explicit parenthesis around all mathematical
            expressions within macro, by default False
            When false, original parenthesis are kept.
        strip_whitespace : bool, optional
            Remove all semantically insignificant whitespace, by default False

        """
        super().__init__()
        self.indent_character = indent_character

        if isinstance(macro_body_indent, int):
            macro_body_indent = indent_character * macro_body_indent
        self.macro_body_indent = macro_body_indent

        if isinstance(macro_param_indent, int):
            macro_param_indent = indent_character * macro_param_indent
        self.macro_param_indent = macro_param_indent

        self.macro_split_mode = macro_split_mode
        self.macro_end_in_new_line = macro_end_in_new_line

        if isinstance(block_aperture_body_indent, int):
            block_aperture_body_indent = indent_character * block_aperture_body_indent
        self.block_aperture_body_indent = block_aperture_body_indent

        if isinstance(step_and_repeat_body_indent, int):
            step_and_repeat_body_indent = indent_character * step_and_repeat_body_indent
        self.step_and_repeat_body_indent = step_and_repeat_body_indent

        self.float_decimal_places = float_decimal_places

        self.float_trim_trailing_zeros = float_trim_trailing_zeros

        if isinstance(d01_indent, int):
            d01_indent = indent_character * d01_indent
        self.d01_indent = d01_indent

        if isinstance(d02_indent, int):
            d02_indent = indent_character * d02_indent
        self.d02_indent = d02_indent

        if isinstance(d03_indent, int):
            d03_indent = indent_character * d03_indent
        self.d03_indent = d03_indent

        self.lf = line_end
        self.empty_line_before_polarity_switch = (
            self.lf if empty_line_before_polarity_switch else ""
        )
        self.keep_non_standalone_codes = keep_non_standalone_codes
        self.remove_g54 = remove_g54
        self.remove_g55 = remove_g55
        self.explicit_parenthesis = explicit_parenthesis
        self.strip_whitespace = strip_whitespace

        if self.strip_whitespace:
            self.lf = ""  # type: ignore[assignment]
            self.indent_character = ""  # type: ignore[assignment]
            self.macro_body_indent = ""
            self.macro_param_indent = ""
            self.block_aperture_body_indent = ""
            self.step_and_repeat_body_indent = ""
            self.d01_indent = ""
            self.d02_indent = ""
            self.d03_indent = ""
            self.empty_line_before_polarity_switch = ""

        self._output: Optional[StringIO] = None
        self._base_indent: str = ""

    def format(self, source: File, output: StringIO) -> None:
        """Format Gerber AST according to rules specified in Formatter constructor."""
        self._output = output
        try:
            self.on_file(source)
        finally:
            self._output = None
            self._base_indent = ""

    def formats(self, source: File) -> str:
        """Format Gerber AST according to rules specified in Formatter constructor."""
        out = StringIO()
        self.format(source, out)
        return out.getvalue()

    def format_node(self, node: Node, output: StringIO) -> None:
        """Format single node according to rules specified in Formatter constructor."""
        self._output = output
        try:
            node.visit(self)
        finally:
            self._output = None
            self._base_indent = ""

    def formats_node(self, node: File) -> str:
        """Format single node according to rules specified in Formatter constructor."""
        out = StringIO()
        self.format_node(node, out)
        return out.getvalue()

    @property
    def output(self) -> StringIO:
        """Get output buffer."""
        if self._output is None:
            msg = "Output buffer is not set."
            raise FormatterError(msg)

        return self._output

    def _fmt_double(self, value: Double) -> str:
        if self.float_decimal_places < 0:
            return str(value)
        double = f"{value:.{self.float_decimal_places}f}"
        if self.float_trim_trailing_zeros:
            return double.rstrip("0").rstrip(".")
        return double

    def _insert_base_indent(self) -> None:
        self._write(self._base_indent)

    def _insert_extra_indent(self, value: str) -> None:
        self._write(value)

    @contextmanager
    def _command(
        self, cmd: str, *, asterisk: bool = True, lf: bool = True
    ) -> Generator[None, None, None]:
        self._write(cmd)
        yield
        if asterisk:
            self._write("*")
        if lf:
            self._write(self.lf)

    @contextmanager
    def _extended_command(self, cmd: str) -> Generator[None, None, None]:
        self._write(f"%{cmd}")
        yield
        self._write(f"*%{self.lf}")

    def _write(self, value: str) -> None:
        self.output.write(value)

    @_decrease_base_indent("block_aperture_body_indent")
    @_decorator_insert_base_indent
    def on_ab_close(self, node: ABclose) -> ABclose:
        """Handle `ABclose` node."""
        with self._extended_command("AB"):
            pass
        return node

    @_decorator_insert_base_indent
    @_increase_base_indent("block_aperture_body_indent")
    def on_ab_open(self, node: ABopen) -> ABopen:
        """Handle `ABopen` node."""
        with self._extended_command("AB"):
            self._write(node.aperture_id)
        return node

    @_decorator_insert_base_indent
    def on_adc(self, node: ADC) -> ADC:
        """Handle `AD` circle node."""
        with self._extended_command(f"AD{node.aperture_id}C,"):
            self._write(self._fmt_double(node.diameter))

            if node.hole_diameter is not None:
                self._write(f"X{self._fmt_double(node.hole_diameter)}")
        return node

    @_decorator_insert_base_indent
    def on_adr(self, node: ADR) -> ADR:
        """Handle `AD` rectangle node."""
        with self._extended_command(f"AD{node.aperture_id}R,"):
            self._write(self._fmt_double(node.width))
            self._write(f"X{self._fmt_double(node.height)}")

            if node.hole_diameter is not None:
                self._write(f"X{self._fmt_double(node.hole_diameter)}")
        return node

    @_decorator_insert_base_indent
    def on_ado(self, node: ADO) -> ADO:
        """Handle `AD` obround node."""
        with self._extended_command(f"AD{node.aperture_id}O,"):
            self._write(self._fmt_double(node.width))
            self._write(f"X{self._fmt_double(node.height)}")

            if node.hole_diameter is not None:
                self._write(f"X{self._fmt_double(node.hole_diameter)}")
        return node

    @_decorator_insert_base_indent
    def on_adp(self, node: ADP) -> ADP:
        """Handle `AD` polygon node."""
        with self._extended_command(f"AD{node.aperture_id}P,"):
            self._write(self._fmt_double(node.outer_diameter))
            self._write(f"X{node.vertices}")

            if node.rotation is not None:
                self._write(f"X{self._fmt_double(node.rotation)}")

            if node.hole_diameter is not None:
                self._write(f"X{self._fmt_double(node.hole_diameter)}")
        return node

    @_decorator_insert_base_indent
    def on_ad_macro(self, node: ADmacro) -> ADmacro:
        """Handle `AD` macro node."""
        with self._extended_command(f"AD{node.aperture_id}{node.name}"):
            if node.params is not None:
                first, *rest = node.params
                self._write(f",{first}")
                for param in rest:
                    self._write(f"X{param}")
        return node

    @_decorator_insert_base_indent
    def on_am_close(self, node: AMclose) -> AMclose:
        """Handle `AMclose` node."""
        super().on_am_close(node)
        if self.macro_end_in_new_line:
            self._write(f"{self.lf}")
        self._write(f"%{self.lf}")
        return node

    @_decorator_insert_base_indent
    def on_am_open(self, node: AMopen) -> AMopen:
        """Handle `AMopen` node."""
        super().on_am_open(node)
        self._write(f"%AM{node.name}*")
        return node

    @_decrease_base_indent("step_and_repeat_body_indent")
    @_decorator_insert_base_indent
    def on_sr_close(self, node: SRclose) -> SRclose:
        """Handle `SRclose` node."""
        with self._extended_command("SR"):
            pass
        return node

    @_decorator_insert_base_indent
    @_increase_base_indent("step_and_repeat_body_indent")
    def on_sr_open(self, node: SRopen) -> SRopen:
        """Handle `SRopen` node."""
        with self._extended_command("SR"):
            if node.x is not None:
                self._write(f"X{node.x}")

            if node.x is not None:
                self._write(f"Y{node.y}")

            if node.x is not None:
                self._write(f"I{node.i}")

            if node.x is not None:
                self._write(f"J{node.j}")

        return node

    # Attribute

    @_decorator_insert_base_indent
    def on_ta_user_name(self, node: TA_UserName) -> TA_UserName:
        """Handle `TA_UserName` node."""
        with self._extended_command(f"TA{node.user_name}"):
            for field in node.fields:
                self._write(",")
                self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_ta_aper_function(self, node: TA_AperFunction) -> TA_AperFunction:
        """Handle `TA_AperFunction` node."""
        with self._extended_command("TA.AperFunction"):
            if node.function is not None:
                self._write(",")
                self._write(node.function.value)

            for field in node.fields:
                self._write(",")
                self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_ta_drill_tolerance(self, node: TA_DrillTolerance) -> TA_DrillTolerance:
        """Handle `TA_DrillTolerance` node."""
        with self._extended_command("TA.DrillTolerance"):
            if node.plus_tolerance is not None:
                self._write(",")
                self._write(self._fmt_double(node.plus_tolerance))

            if node.minus_tolerance is not None:
                self._write(",")
                self._write(self._fmt_double(node.minus_tolerance))

        return node

    @_decorator_insert_base_indent
    def on_ta_flash_text(self, node: TA_FlashText) -> TA_FlashText:
        """Handle `TA_FlashText` node."""
        with self._extended_command("TA.FlashText"):
            self._write(",")
            self._write(node.string)

            self._write(",")
            self._write(node.mode)

            self._write(",")
            self._write(node.mirroring)

            if len(node.comments) == 0:
                if node.font is not None:
                    self._write(",")
                    self._write(node.font)

                if node.size is not None:
                    self._write(",")
                    self._write(node.size)

                for comment in node.comments:
                    self._write(",")
                    self._write(comment)
            else:
                self._write(",")
                if node.font is not None:
                    self._write(node.font)

                self._write(",")
                if node.size is not None:
                    self._write(node.size)

                for comment in node.comments:
                    self._write(",")
                    self._write(comment)

        return node

    @_decorator_insert_base_indent
    def on_td(self, node: TD) -> TD:
        """Handle `TD` node."""
        with self._extended_command("TD"):
            if node.name is not None:
                self._write(node.name)

        return node

    @_decorator_insert_base_indent
    def on_tf_user_name(self, node: TF_UserName) -> TF_UserName:
        """Handle `TF_UserName` node."""
        with self._extended_command(f"TF{node.user_name}"):
            for field in node.fields:
                self._write(",")
                self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_tf_part(self, node: TF_Part) -> TF_Part:
        """Handle `TF_Part` node."""
        with self._extended_command("TF.Part,"):
            self._write(node.part.value)
            if len(node.fields) != 0:
                for field in node.fields:
                    self._write(",")
                    self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_tf_file_function(self, node: TF_FileFunction) -> TF_FileFunction:
        """Handle `TF_FileFunction` node."""
        with self._extended_command("TF.FileFunction,"):
            self._write(node.file_function.value)
            if len(node.fields) != 0:
                for field in node.fields:
                    self._write(",")
                    self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_tf_file_polarity(self, node: TF_FilePolarity) -> TF_FilePolarity:
        """Handle `TF_FilePolarity` node."""
        with self._extended_command("TF.FilePolarity,"):
            self._write(node.polarity)

        return node

    @_decorator_insert_base_indent
    def on_tf_same_coordinates(self, node: TF_SameCoordinates) -> TF_SameCoordinates:
        """Handle `TF_SameCoordinates` node."""
        with self._extended_command("TF.SameCoordinates"):
            if node.identifier is not None:
                self._write(",")
                self._write(node.identifier)

        return node

    @_decorator_insert_base_indent
    def on_tf_creation_date(self, node: TF_CreationDate) -> TF_CreationDate:
        """Handle `TF_CreationDate` node."""
        with self._extended_command("TF.CreationDate"):
            if node.creation_date is not None:
                self._write(",")
                self._write(node.creation_date.isoformat())

        return node

    @_decorator_insert_base_indent
    def on_tf_generation_software(
        self, node: TF_GenerationSoftware
    ) -> TF_GenerationSoftware:
        """Handle `TF_GenerationSoftware` node."""
        with self._extended_command("TF.GenerationSoftware"):
            self._write(",")
            if node.vendor is not None:
                self._write(node.vendor)

            self._write(",")
            if node.application is not None:
                self._write(node.application)

            self._write(",")
            if node.version is not None:
                self._write(node.version)

        return node

    @_decorator_insert_base_indent
    def on_tf_project_id(self, node: TF_ProjectId) -> TF_ProjectId:
        """Handle `TF_ProjectId` node."""
        with self._extended_command("TF.ProjectId"):
            self._write(",")
            if node.name is not None:
                self._write(node.name)

            self._write(",")
            if node.guid is not None:
                self._write(node.guid)

            self._write(",")
            if node.revision is not None:
                self._write(node.revision)

        return node

    @_decorator_insert_base_indent
    def on_tf_md5(self, node: TF_MD5) -> TF_MD5:
        """Handle `TF_MD5` node."""
        with self._extended_command("TF.MD5"):
            self._write(",")
            self._write(node.md5)

        return node

    @_decorator_insert_base_indent
    def on_to_user_name(self, node: TO_UserName) -> TO_UserName:
        """Handle `TO_UserName` node."""
        with self._extended_command(f"TO{node.user_name}"):
            for field in node.fields:
                self._write(",")
                self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_to_n(self, node: TO_N) -> TO_N:
        """Handle `TO_N` node."""
        with self._extended_command("TO.N"):
            for field in node.net_names:
                self._write(",")
                self._write(field)

        return node

    @_decorator_insert_base_indent
    def on_to_p(self, node: TO_P) -> TO_P:
        """Handle `TO_P` node`."""
        with self._extended_command("TO.P"):
            self._write(",")
            self._write(node.refdes)
            self._write(",")
            self._write(node.number)
            if node.function is not None:
                self._write(",")
                self._write(node.function)

        return node

    @_decorator_insert_base_indent
    def on_to_c(self, node: TO_C) -> TO_C:
        """Handle `TO_C` node."""
        with self._extended_command("TO.C"):
            self._write(",")
            self._write(node.refdes)

        return node

    @_decorator_insert_base_indent
    def on_to_crot(self, node: TO_CRot) -> TO_CRot:
        """Handle `TO_CRot` node."""
        with self._extended_command("TO.CRot"):
            self._write(",")
            self._write(self._fmt_double(node.angle))

        return node

    @_decorator_insert_base_indent
    def on_to_cmfr(self, node: TO_CMfr) -> TO_CMfr:
        """Handle `TO_CMfr` node."""
        with self._extended_command("TO.CMfr"):
            self._write(",")
            self._write(node.manufacturer)

        return node

    @_decorator_insert_base_indent
    def on_to_cmnp(self, node: TO_CMNP) -> TO_CMNP:
        """Handle `TO_CMNP` node."""
        with self._extended_command("TO.CMPN"):
            self._write(",")
            self._write(node.part_number)

        return node

    @_decorator_insert_base_indent
    def on_to_cval(self, node: TO_CVal) -> TO_CVal:
        """Handle `TO_CVal` node."""
        with self._extended_command("TO.CVal"):
            self._write(",")
            self._write(node.value)

        return node

    @_decorator_insert_base_indent
    def on_to_cmnt(self, node: TO_CMnt) -> TO_CMnt:
        """Handle `TO_CVal` node."""
        with self._extended_command("TO.CMnt"):
            self._write(",")
            self._write(node.mount.value)

        return node

    @_decorator_insert_base_indent
    def on_to_cftp(self, node: TO_CFtp) -> TO_CFtp:
        """Handle `TO_Cftp` node."""
        with self._extended_command("TO.CFtp"):
            self._write(",")
            self._write(node.footprint)

        return node

    @_decorator_insert_base_indent
    def on_to_cpgn(self, node: TO_CPgN) -> TO_CPgN:
        """Handle `TO_CPgN` node."""
        with self._extended_command("TO.CPgN"):
            self._write(",")
            self._write(node.name)

        return node

    @_decorator_insert_base_indent
    def on_to_cpgd(self, node: TO_CPgD) -> TO_CPgD:
        """Handle `TO_CPgD` node."""
        with self._extended_command("TO.CPgD"):
            self._write(",")
            self._write(node.description)

        return node

    @_decorator_insert_base_indent
    def on_to_chgt(self, node: TO_CHgt) -> TO_CHgt:
        """Handle `TO_CHgt` node."""
        with self._extended_command("TO.CHgt"):
            self._write(",")
            self._write(self._fmt_double(node.height))

        return node

    @_decorator_insert_base_indent
    def on_to_clbn(self, node: TO_CLbN) -> TO_CLbN:
        """Handle `TO_CLbN` node."""
        with self._extended_command("TO.CLbn"):
            self._write(",")
            self._write(node.name)

        return node

    @_decorator_insert_base_indent
    def on_to_clbd(self, node: TO_CLbD) -> TO_CLbD:
        """Handle `TO_CLbD` node."""
        with self._extended_command("TO.CLbD"):
            self._write(",")
            self._write(node.description)

        return node

    @_decorator_insert_base_indent
    def on_to_csup(self, node: TO_CSup) -> TO_CSup:
        """Handle `TO_CSup` node."""
        with self._extended_command("TO.CSup"):
            self._write(",")
            self._write(node.supplier)
            self._write(",")
            self._write(node.supplier_part)
            for field in node.other_suppliers:
                self._write(",")
                self._write(field)

        return node

    # D codes

    def on_d01(self, node: D01) -> D01:
        """Handle `D01` node."""
        if node.is_standalone or not self.keep_non_standalone_codes:
            self._insert_base_indent()
            self._insert_extra_indent(self.d01_indent)

        super().on_d01(node)
        with self._command("D01"):
            pass

        return node

    def on_d02(self, node: D02) -> D02:
        """Handle `D02` node."""
        if node.is_standalone or not self.keep_non_standalone_codes:
            self._insert_base_indent()
            self._insert_extra_indent(self.d02_indent)

        super().on_d02(node)
        with self._command("D02"):
            pass

        return node

    def on_d03(self, node: D03) -> D03:
        """Handle `D03` node."""
        if node.is_standalone or not self.keep_non_standalone_codes:
            self._insert_base_indent()
            self._insert_extra_indent(self.d03_indent)

        super().on_d03(node)
        with self._command("D03"):
            pass

        return node

    def on_dnn(self, node: Dnn) -> Dnn:
        """Handle `Dnn` node."""
        if node.is_standalone or not self.keep_non_standalone_codes:
            self._insert_base_indent()

        with self._command(node.aperture_id):
            pass

        return node

    # G codes

    def _handle_g(self, node: G, cls: Type[G]) -> None:
        if node.is_standalone or not self.keep_non_standalone_codes:
            with self._command(cls.__qualname__):
                pass
            return

        self._write(cls.__qualname__)

    @_decorator_insert_base_indent
    def on_g01(self, node: G01) -> G01:
        """Handle `G01` node."""
        self._handle_g(node, G01)
        return node

    @_decorator_insert_base_indent
    def on_g02(self, node: G02) -> G02:
        """Handle `G02` node."""
        self._handle_g(node, G02)
        return node

    @_decorator_insert_base_indent
    def on_g03(self, node: G03) -> G03:
        """Handle `G03` node."""
        self._handle_g(node, G03)
        return node

    @_decorator_insert_base_indent
    def on_g04(self, node: G04) -> G04:
        """Handle `G04` node."""
        with self._command(f"G04{node.string or ''}"):
            pass
        return node

    @_decorator_insert_base_indent
    def on_g36(self, node: G36) -> G36:
        """Handle `G36` node."""
        self._handle_g(node, G36)
        return node

    @_decorator_insert_base_indent
    def on_g37(self, node: G37) -> G37:
        """Handle `G37` node."""
        self._handle_g(node, G37)
        return node

    @_decorator_insert_base_indent
    def on_g54(self, node: G54) -> G54:
        """Handle `G54` node."""
        if self.remove_g54:
            return node
        self._handle_g(node, G54)
        return node

    @_decorator_insert_base_indent
    def on_g55(self, node: G55) -> G55:
        """Handle `G55` node."""
        if self.remove_g55:
            return node
        self._handle_g(node, G55)
        return node

    @_decorator_insert_base_indent
    def on_g70(self, node: G70) -> G70:
        """Handle `G70` node."""
        self._handle_g(node, G70)
        return node

    @_decorator_insert_base_indent
    def on_g71(self, node: G71) -> G71:
        """Handle `G71` node."""
        self._handle_g(node, G71)
        return node

    @_decorator_insert_base_indent
    def on_g74(self, node: G74) -> G74:
        """Handle `G74` node."""
        self._handle_g(node, G74)
        return node

    @_decorator_insert_base_indent
    def on_g75(self, node: G75) -> G75:
        """Handle `G75` node."""
        self._handle_g(node, G75)
        return node

    @_decorator_insert_base_indent
    def on_g90(self, node: G90) -> G90:
        """Handle `G90` node."""
        self._handle_g(node, G90)
        return node

    @_decorator_insert_base_indent
    def on_g91(self, node: G91) -> G91:
        """Handle `G91` node."""
        self._handle_g(node, G91)
        return node

    # Load

    @_decorator_insert_base_indent
    def on_lm(self, node: LM) -> LM:
        """Handle `LM` node."""
        with self._extended_command(f"LM{node.mirroring.value}"):
            pass
        return node

    @_decorator_insert_base_indent
    def on_ln(self, node: LN) -> LN:
        """Handle `LN` node."""
        with self._extended_command(f"LN{node.name}"):
            pass
        return node

    @_insert_var("empty_line_before_polarity_switch")
    @_decorator_insert_base_indent
    def on_lp(self, node: LP) -> LP:
        """Handle `LP` node."""
        with self._extended_command(f"LP{node.polarity.value}"):
            pass
        return node

    @_decorator_insert_base_indent
    def on_lr(self, node: LR) -> LR:
        """Handle `LR` node."""
        with self._extended_command(f"LR{self._fmt_double(node.rotation)}"):
            pass
        return node

    @_decorator_insert_base_indent
    def on_ls(self, node: LS) -> LS:
        """Handle `LS` node."""
        with self._extended_command(f"LS{self._fmt_double(node.scale)}"):
            pass
        return node

    # M Codes

    @_decorator_insert_base_indent
    def on_m00(self, node: M00) -> M00:
        """Handle `M00` node."""
        with self._command("M00"):
            pass
        return node

    @_decorator_insert_base_indent
    def on_m01(self, node: M01) -> M01:
        """Handle `M01` node."""
        with self._command("M01"):
            pass
        return node

    @_decorator_insert_base_indent
    def on_m02(self, node: M02) -> M02:
        """Handle `M02` node."""
        with self._command("M02"):
            pass
        return node

    # Math

    # Math :: Operators :: Binary
    def on_add(self, node: Add) -> Add:
        """Handle `Add` node."""
        if self.explicit_parenthesis:
            self._write("(")

        node.head.visit(self)

        for operand in node.tail:
            self._write("+")
            operand.visit(self)

        if self.explicit_parenthesis:
            self._write(")")

        return node

    def on_div(self, node: Div) -> Div:
        """Handle `Div` node."""
        if self.explicit_parenthesis:
            self._write("(")

        node.head.visit(self)

        for operand in node.tail:
            self._write("/")
            operand.visit(self)

        if self.explicit_parenthesis:
            self._write(")")

        return node

    def on_mul(self, node: Mul) -> Mul:
        """Handle `Mul` node."""
        if self.explicit_parenthesis:
            self._write("(")

        node.head.visit(self)

        for operand in node.tail:
            self._write("x")
            operand.visit(self)

        if self.explicit_parenthesis:
            self._write(")")

        return node

    def on_sub(self, node: Sub) -> Sub:
        """Handle `Sub` node."""
        if self.explicit_parenthesis:
            self._write("(")

        node.head.visit(self)

        for operand in node.tail:
            self._write("-")
            operand.visit(self)

        if self.explicit_parenthesis:
            self._write(")")

        return node

    # Math :: Operators :: Unary

    def on_neg(self, node: Neg) -> Neg:
        """Handle `Neg` node."""
        self._write("-")
        node.operand.visit(self)
        return node

    def on_pos(self, node: Pos) -> Pos:
        """Handle `Pos` node."""
        self._write("+")
        node.operand.visit(self)
        return node

    @_decorator_insert_base_indent
    def on_assignment(self, node: Assignment) -> Assignment:
        """Handle `Assignment` node."""
        self._write(self._macro_primitive_lf)
        node.variable.visit(self)
        self._write("=")
        node.expression.visit(self)
        self._write("*")

        return node

    def on_constant(self, node: Constant) -> Constant:
        """Handle `Constant` node."""
        self._write(self._fmt_double(node.constant))
        return node

    def on_parenthesis(self, node: Parenthesis) -> Parenthesis:
        """Handle `Parenthesis` node."""
        if not self.explicit_parenthesis:
            self._write("(")

        node.inner.visit(self)

        if not self.explicit_parenthesis:
            self._write(")")

        return node

    def on_point(self, node: Point) -> Point:
        """Handle `Point` node."""
        node.x.visit(self)
        self._write(",")
        node.y.visit(self)
        return node

    def on_variable(self, node: Variable) -> Variable:
        """Handle `Variable` node."""
        self._write(node.variable)
        return node

    # Other

    def on_coordinate_x(self, node: CoordinateX) -> CoordinateX:
        """Handle `Coordinate` node."""
        self._write(f"X{node.value}")
        return node

    def on_coordinate_y(self, node: CoordinateY) -> CoordinateY:
        """Handle `Coordinate` node."""
        self._write(f"Y{node.value}")
        return node

    def on_coordinate_i(self, node: CoordinateI) -> CoordinateI:
        """Handle `Coordinate` node."""
        self._write(f"I{node.value}")
        return node

    def on_coordinate_j(self, node: CoordinateJ) -> CoordinateJ:
        """Handle `Coordinate` node."""
        self._write(f"J{node.value}")
        return node

    # Primitives

    @_decorator_insert_base_indent
    def on_code_0(self, node: Code0) -> Code0:
        """Handle `Code0` node."""
        self._write(f"{self._macro_primitive_lf}0{node.string}*")
        return node

    @_decorator_insert_base_indent
    def on_code_1(self, node: Code1) -> Code1:
        """Handle `Code1` node."""
        self._write(f"{self._macro_primitive_lf}1,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.diameter.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_y.visit(self)

        if node.rotation is not None:
            self._write(f",{self._macro_param_lf}")
            node.rotation.visit(self)

        self._write("*")
        return node

    @cached_property
    def _macro_primitive_lf(self) -> str:
        if self.macro_split_mode == self.MacroSplitMode.NONE:
            return ""

        if self.macro_split_mode in (
            self.MacroSplitMode.PRIMITIVES,
            self.MacroSplitMode.PARAMETERS,
        ):
            return self.lf + self.macro_body_indent

        msg = f"Unsupported macro split mode: {self.macro_split_mode}"
        raise NotImplementedError(msg)

    @cached_property
    def _macro_param_lf(self) -> str:
        if self.macro_split_mode in (
            self.MacroSplitMode.NONE,
            self.MacroSplitMode.PRIMITIVES,
        ):
            return ""

        if self.macro_split_mode == self.MacroSplitMode.PARAMETERS:
            return self.lf + self.macro_param_indent + self.macro_body_indent

        msg = f"Unsupported macro split mode: {self.macro_split_mode}"
        raise NotImplementedError(msg)

    @_decorator_insert_base_indent
    def on_code_2(self, node: Code2) -> Code2:
        """Handle `Code2` node."""
        self._write(f"{self._macro_primitive_lf}2,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.width.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.start_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.start_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.end_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.end_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_4(self, node: Code4) -> Code4:
        """Handle `Code4` node."""
        self._write(f"{self._macro_primitive_lf}4,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.number_of_points.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.start_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.start_y.visit(self)

        for point in node.points:
            self._write(f",{self._macro_param_lf}")
            point.visit(self)

        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_5(self, node: Code5) -> Code5:
        """Handle `Code5` node."""
        self._write(f"{self._macro_primitive_lf}5,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.number_of_vertices.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.diameter.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_6(self, node: Code6) -> Code6:
        """Handle `Code6` node."""
        self._write(f"{self._macro_primitive_lf}6,{self._macro_param_lf}")
        node.center_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.outer_diameter.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.ring_thickness.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.gap_between_rings.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.max_ring_count.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.crosshair_thickness.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.crosshair_length.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_7(self, node: Code7) -> Code7:
        """Handle `Code7` node."""
        self._write(f"{self._macro_primitive_lf}7,{self._macro_param_lf}")
        node.center_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.outer_diameter.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.inner_diameter.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.gap_thickness.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_20(self, node: Code20) -> Code20:
        """Handle `Code20` node."""
        self._write(f"{self._macro_primitive_lf}20,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.width.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.start_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.start_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.end_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.end_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_21(self, node: Code21) -> Code21:
        """Handle `Code21` node."""
        self._write(f"{self._macro_primitive_lf}21,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.width.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.height.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_x.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.center_y.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    @_decorator_insert_base_indent
    def on_code_22(self, node: Code22) -> Code22:
        """Handle `Code22` node."""
        self._write(f"{self._macro_primitive_lf}22,{self._macro_param_lf}")
        node.exposure.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.width.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.height.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.x_lower_left.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.y_lower_left.visit(self)
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)
        self._write("*")
        return node

    # Properties

    @_decorator_insert_base_indent
    def on_as(self, node: AS) -> AS:
        """Handle `AS` node."""
        with self._extended_command("AS"):
            self._write(node.correspondence.value)
        return node

    @_decorator_insert_base_indent
    def on_fs(self, node: FS) -> FS:
        """Handle `FS` node."""
        with self._extended_command("FS"):
            self._write(node.zeros.value)
            self._write(node.coordinate_mode.value)
            self._write(f"X{node.x_integral}{node.x_decimal}")
            self._write(f"Y{node.y_integral}{node.y_decimal}")
        return node

    @_decorator_insert_base_indent
    def on_in(self, node: IN) -> IN:
        """Handle `IN` node."""
        with self._extended_command("IN"):
            self._write(node.name)
        return node

    @_decorator_insert_base_indent
    def on_ip(self, node: IP) -> IP:
        """Handle `IP` node."""
        with self._extended_command("IP"):
            self._write(node.polarity.value)
        return node

    @_decorator_insert_base_indent
    def on_ir(self, node: IR) -> IR:
        """Handle `IR` node."""
        with self._extended_command("IR"):
            self._write(self._fmt_double(node.rotation_degrees))
        return node

    @_decorator_insert_base_indent
    def on_mi(self, node: MI) -> MI:
        """Handle `MI` node."""
        with self._extended_command("MI"):
            self._write(f"A{node.a_mirroring}")
            self._write(f"B{node.b_mirroring}")
        return node

    @_decorator_insert_base_indent
    def on_mo(self, node: MO) -> MO:
        """Handle `MO` node."""
        with self._extended_command("MO"):
            self._write(node.mode.value)
        return node

    @_decorator_insert_base_indent
    def on_of(self, node: OF) -> OF:
        """Handle `OF` node."""
        with self._extended_command("OF"):
            if node.a_offset is not None:
                self._write(f"A{node.a_offset}")
            if node.b_offset is not None:
                self._write(f"B{node.b_offset}")
        return node

    @_decorator_insert_base_indent
    def on_sf(self, node: SF) -> SF:
        """Handle `SF` node."""
        with self._extended_command("SF"):
            self._write("A")
            self._write(self._fmt_double(node.a_scale))
            self._write("B")
            self._write(self._fmt_double(node.b_scale))
        return node

output property

output: StringIO

Get output buffer.

MacroSplitMode

Bases: Enum

Macro split mode.

Source code in src/pygerber/gerberx3/formatter/formatter.py
class MacroSplitMode(Enum):
    """Macro split mode."""

    NONE = "none"
    PRIMITIVES = "primitives"
    PARAMETERS = "parameters"

__init__

__init__(
    *,
    indent_character: Literal[" ", "\t"] = " ",
    macro_body_indent: str | int = 0,
    macro_param_indent: str | int = 0,
    macro_split_mode: MacroSplitMode = MacroSplitMode.PRIMITIVES,
    macro_end_in_new_line: bool = False,
    block_aperture_body_indent: str | int = 0,
    step_and_repeat_body_indent: str | int = 0,
    float_decimal_places: int = -1,
    float_trim_trailing_zeros: bool = True,
    d01_indent: int | str = 0,
    d02_indent: int | str = 0,
    d03_indent: int | str = 0,
    line_end: Literal["\n", "\r\n"] = "\n",
    empty_line_before_polarity_switch: bool = False,
    keep_non_standalone_codes: bool = True,
    remove_g54: bool = False,
    remove_g55: bool = False,
    explicit_parenthesis: bool = False,
    strip_whitespace: bool = False
) -> None

Initialize Formatter instance.

Parameters:

Name Type Description Default
indent_character Literal[' ', '\t']

Character used for indentation, by default " "

' '
macro_body_indent str | int

Indentation of macro body, by default 0

0
macro_param_indent str | int

Indentation of macro parameters, by default 0 This indentation is added on top of macro body indentation. This has effect only when macro_split_mode is PARAMETERS.

0
macro_split_mode `Formatter.MacroSplitMode`

Changes how macro definitions are formatted, by default NONE When NONE is selected, macro will be formatted as a single line.

%AMDonut*1,1,$1,$2,$3*$4=$1x0.75*1,0,$4,$2,$3*%
When PRIMITIVES is selected, macro will be formatted with each primitive on a new line.
%AMDonut*
1,1,$1,$2,$3*
$4=$1x0.75*
1,0,$4,$2,$3*%
When PARAMETERS is selected, macro will be formatted with each primitive on a new line and each parameter of a primitive on a new line.
%AMDonut*
1,
1,
$1,
$2,
$3*
$4=$1x0.75*
1,
0,
$4,
$2,
$3*%
Use macro_body_indent and macro_param_indent to control indentation.

PRIMITIVES
macro_end_in_new_line bool

Place % sign which marks the end of macro in new line, by default False

False
block_aperture_body_indent str | int

Indentation of block aperture definition body, by default 0 This indentations stacks for nested block apertures.

0
step_and_repeat_body_indent str | int

Indentation of step and repeat definition body, by default 0 This indentations stacks for nested step and repeat blocks.

0
float_decimal_places int

Limit number of decimal places shown for float values, by default -1 Negative values are interpreted as no limit.

-1
float_trim_trailing_zeros bool

Remove trailing zeros from floats, by default True When this is enabled, after floating point number is formatted with respect to float_decimal_places, trailing zeros are removed. If all zeros after decimal point are removed, decimal point is also removed.

True
d01_indent str | int

Custom indentation of D01 command, by default 0

0
d02_indent str | int

Custom indentation of D02 command, by default 0

0
d03_indent str | int

Custom indentation of D03 command, by default 0

0
line_end Literal['\n', '\r\n']

Line ending character, Unix or Windows style, by default "\n" (Unix style) If strip_whitespace is enabled, no line end will be used.

'\n'
empty_line_before_polarity_switch bool

Add empty line before polarity switch, by default False This enhances visibility of sequences of commands with different polarities.

False
keep_non_standalone_codes bool

Keep non-standalone codes in the output, by default True If this option is disabled, codes that are not standalone, ie. G70D02* will be divided into two separate commands, G70* and D02*, otherwise they will be kept as is.

True
remove_g54 bool

Remove G54 code from output, by default False G54 code has no effect on the output, it was used in legacy files to prefix select aperture command.

False
remove_g55 bool

Remove G55 code from output, by default False G55 code has no effect on the output, it was used in legacy files to prefix flash command.

False
explicit_parenthesis bool

Add explicit parenthesis around all mathematical expressions within macro, by default False When false, original parenthesis are kept.

False
strip_whitespace bool

Remove all semantically insignificant whitespace, by default False

False
Source code in src/pygerber/gerberx3/formatter/formatter.py
def __init__(  # noqa: PLR0913
    self,
    *,
    indent_character: Literal[" ", "\t"] = " ",
    macro_body_indent: str | int = 0,
    macro_param_indent: str | int = 0,
    macro_split_mode: MacroSplitMode = MacroSplitMode.PRIMITIVES,
    macro_end_in_new_line: bool = False,
    block_aperture_body_indent: str | int = 0,
    step_and_repeat_body_indent: str | int = 0,
    float_decimal_places: int = -1,
    float_trim_trailing_zeros: bool = True,
    d01_indent: int | str = 0,
    d02_indent: int | str = 0,
    d03_indent: int | str = 0,
    line_end: Literal["\n", "\r\n"] = "\n",
    empty_line_before_polarity_switch: bool = False,
    keep_non_standalone_codes: bool = True,
    remove_g54: bool = False,
    remove_g55: bool = False,
    explicit_parenthesis: bool = False,
    strip_whitespace: bool = False,
) -> None:
    r"""Initialize Formatter instance.

    Parameters
    ----------
    indent_character: Literal[" ", "\t"], optional
        Character used for indentation, by default " "
    macro_body_indent : str | int, optional
        Indentation of macro body, by default 0
    macro_param_indent: str | int, optional
        Indentation of macro parameters, by default 0
        This indentation is added on top of macro body indentation.
        This has effect only when `macro_split_mode` is `PARAMETERS`.
    macro_split_mode : `Formatter.MacroSplitMode`, optional
        Changes how macro definitions are formatted, by default `NONE`
        When `NONE` is selected, macro will be formatted as a single line.
        ```gerber
        %AMDonut*1,1,$1,$2,$3*$4=$1x0.75*1,0,$4,$2,$3*%
        ```
        When `PRIMITIVES` is selected, macro will be formatted with each primitive
        on a new line.
        ```gerber
        %AMDonut*
        1,1,$1,$2,$3*
        $4=$1x0.75*
        1,0,$4,$2,$3*%
        ```
        When `PARAMETERS` is selected, macro will be formatted with each primitive
        on a new line and each parameter of a primitive on a new line.
        ```gerber
        %AMDonut*
        1,
        1,
        $1,
        $2,
        $3*
        $4=$1x0.75*
        1,
        0,
        $4,
        $2,
        $3*%
        ```
        Use `macro_body_indent` and `macro_param_indent` to control indentation.
    macro_end_in_new_line: bool, optional
        Place % sign which marks the end of macro in new line, by default False
    block_aperture_body_indent : str | int, optional
        Indentation of block aperture definition body, by default 0
        This indentations stacks for nested block apertures.
    step_and_repeat_body_indent : str | int, optional
        Indentation of step and repeat definition body, by default 0
        This indentations stacks for nested step and repeat blocks.
    float_decimal_places : int, optional
        Limit number of decimal places shown for float values, by default -1
        Negative values are interpreted as no limit.
    float_trim_trailing_zeros : bool, optional
        Remove trailing zeros from floats, by default True
        When this is enabled, after floating point number is formatted with respect
        to `float_decimal_places`, trailing zeros are removed. If all zeros after
        decimal point are removed, decimal point is also removed.
    d01_indent : str | int, optional
        Custom indentation of D01 command, by default 0
    d02_indent : str | int, optional
        Custom indentation of D02 command, by default 0
    d03_indent : str | int, optional
        Custom indentation of D03 command, by default 0
    line_end : Literal["\n", "\r\n"], optional
        Line ending character, Unix or Windows style, by default "\n" (Unix style)
        If `strip_whitespace` is enabled, no line end will be used.
    empty_line_before_polarity_switch : bool, optional
        Add empty line before polarity switch, by default False
        This enhances visibility of sequences of commands with different
        polarities.
    keep_non_standalone_codes: bool, optional
        Keep non-standalone codes in the output, by default True
        If this option is disabled, codes that are not standalone, ie. `G70D02*`
        will be divided into two separate commands, `G70*` and `D02*`, otherwise
        they will be kept as is.
    remove_g54: bool, optional
        Remove G54 code from output, by default False
        G54 code has no effect on the output, it was used in legacy files to
        prefix select aperture command.
    remove_g55: bool, optional
        Remove G55 code from output, by default False
        G55 code has no effect on the output, it was used in legacy files to
        prefix flash command.
    explicit_parenthesis: bool, optional
        Add explicit parenthesis around all mathematical
        expressions within macro, by default False
        When false, original parenthesis are kept.
    strip_whitespace : bool, optional
        Remove all semantically insignificant whitespace, by default False

    """
    super().__init__()
    self.indent_character = indent_character

    if isinstance(macro_body_indent, int):
        macro_body_indent = indent_character * macro_body_indent
    self.macro_body_indent = macro_body_indent

    if isinstance(macro_param_indent, int):
        macro_param_indent = indent_character * macro_param_indent
    self.macro_param_indent = macro_param_indent

    self.macro_split_mode = macro_split_mode
    self.macro_end_in_new_line = macro_end_in_new_line

    if isinstance(block_aperture_body_indent, int):
        block_aperture_body_indent = indent_character * block_aperture_body_indent
    self.block_aperture_body_indent = block_aperture_body_indent

    if isinstance(step_and_repeat_body_indent, int):
        step_and_repeat_body_indent = indent_character * step_and_repeat_body_indent
    self.step_and_repeat_body_indent = step_and_repeat_body_indent

    self.float_decimal_places = float_decimal_places

    self.float_trim_trailing_zeros = float_trim_trailing_zeros

    if isinstance(d01_indent, int):
        d01_indent = indent_character * d01_indent
    self.d01_indent = d01_indent

    if isinstance(d02_indent, int):
        d02_indent = indent_character * d02_indent
    self.d02_indent = d02_indent

    if isinstance(d03_indent, int):
        d03_indent = indent_character * d03_indent
    self.d03_indent = d03_indent

    self.lf = line_end
    self.empty_line_before_polarity_switch = (
        self.lf if empty_line_before_polarity_switch else ""
    )
    self.keep_non_standalone_codes = keep_non_standalone_codes
    self.remove_g54 = remove_g54
    self.remove_g55 = remove_g55
    self.explicit_parenthesis = explicit_parenthesis
    self.strip_whitespace = strip_whitespace

    if self.strip_whitespace:
        self.lf = ""  # type: ignore[assignment]
        self.indent_character = ""  # type: ignore[assignment]
        self.macro_body_indent = ""
        self.macro_param_indent = ""
        self.block_aperture_body_indent = ""
        self.step_and_repeat_body_indent = ""
        self.d01_indent = ""
        self.d02_indent = ""
        self.d03_indent = ""
        self.empty_line_before_polarity_switch = ""

    self._output: Optional[StringIO] = None
    self._base_indent: str = ""

format

format(source: File, output: StringIO) -> None

Format Gerber AST according to rules specified in Formatter constructor.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def format(self, source: File, output: StringIO) -> None:
    """Format Gerber AST according to rules specified in Formatter constructor."""
    self._output = output
    try:
        self.on_file(source)
    finally:
        self._output = None
        self._base_indent = ""

formats

formats(source: File) -> str

Format Gerber AST according to rules specified in Formatter constructor.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def formats(self, source: File) -> str:
    """Format Gerber AST according to rules specified in Formatter constructor."""
    out = StringIO()
    self.format(source, out)
    return out.getvalue()

format_node

format_node(node: Node, output: StringIO) -> None

Format single node according to rules specified in Formatter constructor.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def format_node(self, node: Node, output: StringIO) -> None:
    """Format single node according to rules specified in Formatter constructor."""
    self._output = output
    try:
        node.visit(self)
    finally:
        self._output = None
        self._base_indent = ""

formats_node

formats_node(node: File) -> str

Format single node according to rules specified in Formatter constructor.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def formats_node(self, node: File) -> str:
    """Format single node according to rules specified in Formatter constructor."""
    out = StringIO()
    self.format_node(node, out)
    return out.getvalue()

on_ab_close

on_ab_close(node: ABclose) -> ABclose

Handle ABclose node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decrease_base_indent("block_aperture_body_indent")
@_decorator_insert_base_indent
def on_ab_close(self, node: ABclose) -> ABclose:
    """Handle `ABclose` node."""
    with self._extended_command("AB"):
        pass
    return node

on_ab_open

on_ab_open(node: ABopen) -> ABopen

Handle ABopen node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
@_increase_base_indent("block_aperture_body_indent")
def on_ab_open(self, node: ABopen) -> ABopen:
    """Handle `ABopen` node."""
    with self._extended_command("AB"):
        self._write(node.aperture_id)
    return node

on_adc

on_adc(node: ADC) -> ADC

Handle AD circle node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_adc(self, node: ADC) -> ADC:
    """Handle `AD` circle node."""
    with self._extended_command(f"AD{node.aperture_id}C,"):
        self._write(self._fmt_double(node.diameter))

        if node.hole_diameter is not None:
            self._write(f"X{self._fmt_double(node.hole_diameter)}")
    return node

on_adr

on_adr(node: ADR) -> ADR

Handle AD rectangle node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_adr(self, node: ADR) -> ADR:
    """Handle `AD` rectangle node."""
    with self._extended_command(f"AD{node.aperture_id}R,"):
        self._write(self._fmt_double(node.width))
        self._write(f"X{self._fmt_double(node.height)}")

        if node.hole_diameter is not None:
            self._write(f"X{self._fmt_double(node.hole_diameter)}")
    return node

on_ado

on_ado(node: ADO) -> ADO

Handle AD obround node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ado(self, node: ADO) -> ADO:
    """Handle `AD` obround node."""
    with self._extended_command(f"AD{node.aperture_id}O,"):
        self._write(self._fmt_double(node.width))
        self._write(f"X{self._fmt_double(node.height)}")

        if node.hole_diameter is not None:
            self._write(f"X{self._fmt_double(node.hole_diameter)}")
    return node

on_adp

on_adp(node: ADP) -> ADP

Handle AD polygon node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_adp(self, node: ADP) -> ADP:
    """Handle `AD` polygon node."""
    with self._extended_command(f"AD{node.aperture_id}P,"):
        self._write(self._fmt_double(node.outer_diameter))
        self._write(f"X{node.vertices}")

        if node.rotation is not None:
            self._write(f"X{self._fmt_double(node.rotation)}")

        if node.hole_diameter is not None:
            self._write(f"X{self._fmt_double(node.hole_diameter)}")
    return node

on_ad_macro

on_ad_macro(node: ADmacro) -> ADmacro

Handle AD macro node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ad_macro(self, node: ADmacro) -> ADmacro:
    """Handle `AD` macro node."""
    with self._extended_command(f"AD{node.aperture_id}{node.name}"):
        if node.params is not None:
            first, *rest = node.params
            self._write(f",{first}")
            for param in rest:
                self._write(f"X{param}")
    return node

on_am_close

on_am_close(node: AMclose) -> AMclose

Handle AMclose node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_am_close(self, node: AMclose) -> AMclose:
    """Handle `AMclose` node."""
    super().on_am_close(node)
    if self.macro_end_in_new_line:
        self._write(f"{self.lf}")
    self._write(f"%{self.lf}")
    return node

on_am_open

on_am_open(node: AMopen) -> AMopen

Handle AMopen node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_am_open(self, node: AMopen) -> AMopen:
    """Handle `AMopen` node."""
    super().on_am_open(node)
    self._write(f"%AM{node.name}*")
    return node

on_sr_close

on_sr_close(node: SRclose) -> SRclose

Handle SRclose node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decrease_base_indent("step_and_repeat_body_indent")
@_decorator_insert_base_indent
def on_sr_close(self, node: SRclose) -> SRclose:
    """Handle `SRclose` node."""
    with self._extended_command("SR"):
        pass
    return node

on_sr_open

on_sr_open(node: SRopen) -> SRopen

Handle SRopen node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
@_increase_base_indent("step_and_repeat_body_indent")
def on_sr_open(self, node: SRopen) -> SRopen:
    """Handle `SRopen` node."""
    with self._extended_command("SR"):
        if node.x is not None:
            self._write(f"X{node.x}")

        if node.x is not None:
            self._write(f"Y{node.y}")

        if node.x is not None:
            self._write(f"I{node.i}")

        if node.x is not None:
            self._write(f"J{node.j}")

    return node

on_ta_user_name

on_ta_user_name(node: TA_UserName) -> TA_UserName

Handle TA_UserName node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ta_user_name(self, node: TA_UserName) -> TA_UserName:
    """Handle `TA_UserName` node."""
    with self._extended_command(f"TA{node.user_name}"):
        for field in node.fields:
            self._write(",")
            self._write(field)

    return node

on_ta_aper_function

on_ta_aper_function(
    node: TA_AperFunction,
) -> TA_AperFunction

Handle TA_AperFunction node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ta_aper_function(self, node: TA_AperFunction) -> TA_AperFunction:
    """Handle `TA_AperFunction` node."""
    with self._extended_command("TA.AperFunction"):
        if node.function is not None:
            self._write(",")
            self._write(node.function.value)

        for field in node.fields:
            self._write(",")
            self._write(field)

    return node

on_ta_drill_tolerance

on_ta_drill_tolerance(
    node: TA_DrillTolerance,
) -> TA_DrillTolerance

Handle TA_DrillTolerance node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ta_drill_tolerance(self, node: TA_DrillTolerance) -> TA_DrillTolerance:
    """Handle `TA_DrillTolerance` node."""
    with self._extended_command("TA.DrillTolerance"):
        if node.plus_tolerance is not None:
            self._write(",")
            self._write(self._fmt_double(node.plus_tolerance))

        if node.minus_tolerance is not None:
            self._write(",")
            self._write(self._fmt_double(node.minus_tolerance))

    return node

on_ta_flash_text

on_ta_flash_text(node: TA_FlashText) -> TA_FlashText

Handle TA_FlashText node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ta_flash_text(self, node: TA_FlashText) -> TA_FlashText:
    """Handle `TA_FlashText` node."""
    with self._extended_command("TA.FlashText"):
        self._write(",")
        self._write(node.string)

        self._write(",")
        self._write(node.mode)

        self._write(",")
        self._write(node.mirroring)

        if len(node.comments) == 0:
            if node.font is not None:
                self._write(",")
                self._write(node.font)

            if node.size is not None:
                self._write(",")
                self._write(node.size)

            for comment in node.comments:
                self._write(",")
                self._write(comment)
        else:
            self._write(",")
            if node.font is not None:
                self._write(node.font)

            self._write(",")
            if node.size is not None:
                self._write(node.size)

            for comment in node.comments:
                self._write(",")
                self._write(comment)

    return node

on_td

on_td(node: TD) -> TD

Handle TD node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_td(self, node: TD) -> TD:
    """Handle `TD` node."""
    with self._extended_command("TD"):
        if node.name is not None:
            self._write(node.name)

    return node

on_tf_user_name

on_tf_user_name(node: TF_UserName) -> TF_UserName

Handle TF_UserName node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_user_name(self, node: TF_UserName) -> TF_UserName:
    """Handle `TF_UserName` node."""
    with self._extended_command(f"TF{node.user_name}"):
        for field in node.fields:
            self._write(",")
            self._write(field)

    return node

on_tf_part

on_tf_part(node: TF_Part) -> TF_Part

Handle TF_Part node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_part(self, node: TF_Part) -> TF_Part:
    """Handle `TF_Part` node."""
    with self._extended_command("TF.Part,"):
        self._write(node.part.value)
        if len(node.fields) != 0:
            for field in node.fields:
                self._write(",")
                self._write(field)

    return node

on_tf_file_function

on_tf_file_function(
    node: TF_FileFunction,
) -> TF_FileFunction

Handle TF_FileFunction node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_file_function(self, node: TF_FileFunction) -> TF_FileFunction:
    """Handle `TF_FileFunction` node."""
    with self._extended_command("TF.FileFunction,"):
        self._write(node.file_function.value)
        if len(node.fields) != 0:
            for field in node.fields:
                self._write(",")
                self._write(field)

    return node

on_tf_file_polarity

on_tf_file_polarity(
    node: TF_FilePolarity,
) -> TF_FilePolarity

Handle TF_FilePolarity node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_file_polarity(self, node: TF_FilePolarity) -> TF_FilePolarity:
    """Handle `TF_FilePolarity` node."""
    with self._extended_command("TF.FilePolarity,"):
        self._write(node.polarity)

    return node

on_tf_same_coordinates

on_tf_same_coordinates(
    node: TF_SameCoordinates,
) -> TF_SameCoordinates

Handle TF_SameCoordinates node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_same_coordinates(self, node: TF_SameCoordinates) -> TF_SameCoordinates:
    """Handle `TF_SameCoordinates` node."""
    with self._extended_command("TF.SameCoordinates"):
        if node.identifier is not None:
            self._write(",")
            self._write(node.identifier)

    return node

on_tf_creation_date

on_tf_creation_date(
    node: TF_CreationDate,
) -> TF_CreationDate

Handle TF_CreationDate node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_creation_date(self, node: TF_CreationDate) -> TF_CreationDate:
    """Handle `TF_CreationDate` node."""
    with self._extended_command("TF.CreationDate"):
        if node.creation_date is not None:
            self._write(",")
            self._write(node.creation_date.isoformat())

    return node

on_tf_generation_software

on_tf_generation_software(
    node: TF_GenerationSoftware,
) -> TF_GenerationSoftware

Handle TF_GenerationSoftware node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_generation_software(
    self, node: TF_GenerationSoftware
) -> TF_GenerationSoftware:
    """Handle `TF_GenerationSoftware` node."""
    with self._extended_command("TF.GenerationSoftware"):
        self._write(",")
        if node.vendor is not None:
            self._write(node.vendor)

        self._write(",")
        if node.application is not None:
            self._write(node.application)

        self._write(",")
        if node.version is not None:
            self._write(node.version)

    return node

on_tf_project_id

on_tf_project_id(node: TF_ProjectId) -> TF_ProjectId

Handle TF_ProjectId node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_project_id(self, node: TF_ProjectId) -> TF_ProjectId:
    """Handle `TF_ProjectId` node."""
    with self._extended_command("TF.ProjectId"):
        self._write(",")
        if node.name is not None:
            self._write(node.name)

        self._write(",")
        if node.guid is not None:
            self._write(node.guid)

        self._write(",")
        if node.revision is not None:
            self._write(node.revision)

    return node

on_tf_md5

on_tf_md5(node: TF_MD5) -> TF_MD5

Handle TF_MD5 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_tf_md5(self, node: TF_MD5) -> TF_MD5:
    """Handle `TF_MD5` node."""
    with self._extended_command("TF.MD5"):
        self._write(",")
        self._write(node.md5)

    return node

on_to_user_name

on_to_user_name(node: TO_UserName) -> TO_UserName

Handle TO_UserName node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_user_name(self, node: TO_UserName) -> TO_UserName:
    """Handle `TO_UserName` node."""
    with self._extended_command(f"TO{node.user_name}"):
        for field in node.fields:
            self._write(",")
            self._write(field)

    return node

on_to_n

on_to_n(node: TO_N) -> TO_N

Handle TO_N node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_n(self, node: TO_N) -> TO_N:
    """Handle `TO_N` node."""
    with self._extended_command("TO.N"):
        for field in node.net_names:
            self._write(",")
            self._write(field)

    return node

on_to_p

on_to_p(node: TO_P) -> TO_P

Handle TO_P node`.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_p(self, node: TO_P) -> TO_P:
    """Handle `TO_P` node`."""
    with self._extended_command("TO.P"):
        self._write(",")
        self._write(node.refdes)
        self._write(",")
        self._write(node.number)
        if node.function is not None:
            self._write(",")
            self._write(node.function)

    return node

on_to_c

on_to_c(node: TO_C) -> TO_C

Handle TO_C node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_c(self, node: TO_C) -> TO_C:
    """Handle `TO_C` node."""
    with self._extended_command("TO.C"):
        self._write(",")
        self._write(node.refdes)

    return node

on_to_crot

on_to_crot(node: TO_CRot) -> TO_CRot

Handle TO_CRot node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_crot(self, node: TO_CRot) -> TO_CRot:
    """Handle `TO_CRot` node."""
    with self._extended_command("TO.CRot"):
        self._write(",")
        self._write(self._fmt_double(node.angle))

    return node

on_to_cmfr

on_to_cmfr(node: TO_CMfr) -> TO_CMfr

Handle TO_CMfr node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cmfr(self, node: TO_CMfr) -> TO_CMfr:
    """Handle `TO_CMfr` node."""
    with self._extended_command("TO.CMfr"):
        self._write(",")
        self._write(node.manufacturer)

    return node

on_to_cmnp

on_to_cmnp(node: TO_CMNP) -> TO_CMNP

Handle TO_CMNP node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cmnp(self, node: TO_CMNP) -> TO_CMNP:
    """Handle `TO_CMNP` node."""
    with self._extended_command("TO.CMPN"):
        self._write(",")
        self._write(node.part_number)

    return node

on_to_cval

on_to_cval(node: TO_CVal) -> TO_CVal

Handle TO_CVal node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cval(self, node: TO_CVal) -> TO_CVal:
    """Handle `TO_CVal` node."""
    with self._extended_command("TO.CVal"):
        self._write(",")
        self._write(node.value)

    return node

on_to_cmnt

on_to_cmnt(node: TO_CMnt) -> TO_CMnt

Handle TO_CVal node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cmnt(self, node: TO_CMnt) -> TO_CMnt:
    """Handle `TO_CVal` node."""
    with self._extended_command("TO.CMnt"):
        self._write(",")
        self._write(node.mount.value)

    return node

on_to_cftp

on_to_cftp(node: TO_CFtp) -> TO_CFtp

Handle TO_Cftp node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cftp(self, node: TO_CFtp) -> TO_CFtp:
    """Handle `TO_Cftp` node."""
    with self._extended_command("TO.CFtp"):
        self._write(",")
        self._write(node.footprint)

    return node

on_to_cpgn

on_to_cpgn(node: TO_CPgN) -> TO_CPgN

Handle TO_CPgN node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cpgn(self, node: TO_CPgN) -> TO_CPgN:
    """Handle `TO_CPgN` node."""
    with self._extended_command("TO.CPgN"):
        self._write(",")
        self._write(node.name)

    return node

on_to_cpgd

on_to_cpgd(node: TO_CPgD) -> TO_CPgD

Handle TO_CPgD node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_cpgd(self, node: TO_CPgD) -> TO_CPgD:
    """Handle `TO_CPgD` node."""
    with self._extended_command("TO.CPgD"):
        self._write(",")
        self._write(node.description)

    return node

on_to_chgt

on_to_chgt(node: TO_CHgt) -> TO_CHgt

Handle TO_CHgt node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_chgt(self, node: TO_CHgt) -> TO_CHgt:
    """Handle `TO_CHgt` node."""
    with self._extended_command("TO.CHgt"):
        self._write(",")
        self._write(self._fmt_double(node.height))

    return node

on_to_clbn

on_to_clbn(node: TO_CLbN) -> TO_CLbN

Handle TO_CLbN node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_clbn(self, node: TO_CLbN) -> TO_CLbN:
    """Handle `TO_CLbN` node."""
    with self._extended_command("TO.CLbn"):
        self._write(",")
        self._write(node.name)

    return node

on_to_clbd

on_to_clbd(node: TO_CLbD) -> TO_CLbD

Handle TO_CLbD node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_clbd(self, node: TO_CLbD) -> TO_CLbD:
    """Handle `TO_CLbD` node."""
    with self._extended_command("TO.CLbD"):
        self._write(",")
        self._write(node.description)

    return node

on_to_csup

on_to_csup(node: TO_CSup) -> TO_CSup

Handle TO_CSup node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_to_csup(self, node: TO_CSup) -> TO_CSup:
    """Handle `TO_CSup` node."""
    with self._extended_command("TO.CSup"):
        self._write(",")
        self._write(node.supplier)
        self._write(",")
        self._write(node.supplier_part)
        for field in node.other_suppliers:
            self._write(",")
            self._write(field)

    return node

on_d01

on_d01(node: D01) -> D01

Handle D01 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_d01(self, node: D01) -> D01:
    """Handle `D01` node."""
    if node.is_standalone or not self.keep_non_standalone_codes:
        self._insert_base_indent()
        self._insert_extra_indent(self.d01_indent)

    super().on_d01(node)
    with self._command("D01"):
        pass

    return node

on_d02

on_d02(node: D02) -> D02

Handle D02 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_d02(self, node: D02) -> D02:
    """Handle `D02` node."""
    if node.is_standalone or not self.keep_non_standalone_codes:
        self._insert_base_indent()
        self._insert_extra_indent(self.d02_indent)

    super().on_d02(node)
    with self._command("D02"):
        pass

    return node

on_d03

on_d03(node: D03) -> D03

Handle D03 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_d03(self, node: D03) -> D03:
    """Handle `D03` node."""
    if node.is_standalone or not self.keep_non_standalone_codes:
        self._insert_base_indent()
        self._insert_extra_indent(self.d03_indent)

    super().on_d03(node)
    with self._command("D03"):
        pass

    return node

on_dnn

on_dnn(node: Dnn) -> Dnn

Handle Dnn node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_dnn(self, node: Dnn) -> Dnn:
    """Handle `Dnn` node."""
    if node.is_standalone or not self.keep_non_standalone_codes:
        self._insert_base_indent()

    with self._command(node.aperture_id):
        pass

    return node

on_g01

on_g01(node: G01) -> G01

Handle G01 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g01(self, node: G01) -> G01:
    """Handle `G01` node."""
    self._handle_g(node, G01)
    return node

on_g02

on_g02(node: G02) -> G02

Handle G02 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g02(self, node: G02) -> G02:
    """Handle `G02` node."""
    self._handle_g(node, G02)
    return node

on_g03

on_g03(node: G03) -> G03

Handle G03 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g03(self, node: G03) -> G03:
    """Handle `G03` node."""
    self._handle_g(node, G03)
    return node

on_g04

on_g04(node: G04) -> G04

Handle G04 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g04(self, node: G04) -> G04:
    """Handle `G04` node."""
    with self._command(f"G04{node.string or ''}"):
        pass
    return node

on_g36

on_g36(node: G36) -> G36

Handle G36 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g36(self, node: G36) -> G36:
    """Handle `G36` node."""
    self._handle_g(node, G36)
    return node

on_g37

on_g37(node: G37) -> G37

Handle G37 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g37(self, node: G37) -> G37:
    """Handle `G37` node."""
    self._handle_g(node, G37)
    return node

on_g54

on_g54(node: G54) -> G54

Handle G54 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g54(self, node: G54) -> G54:
    """Handle `G54` node."""
    if self.remove_g54:
        return node
    self._handle_g(node, G54)
    return node

on_g55

on_g55(node: G55) -> G55

Handle G55 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g55(self, node: G55) -> G55:
    """Handle `G55` node."""
    if self.remove_g55:
        return node
    self._handle_g(node, G55)
    return node

on_g70

on_g70(node: G70) -> G70

Handle G70 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g70(self, node: G70) -> G70:
    """Handle `G70` node."""
    self._handle_g(node, G70)
    return node

on_g71

on_g71(node: G71) -> G71

Handle G71 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g71(self, node: G71) -> G71:
    """Handle `G71` node."""
    self._handle_g(node, G71)
    return node

on_g74

on_g74(node: G74) -> G74

Handle G74 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g74(self, node: G74) -> G74:
    """Handle `G74` node."""
    self._handle_g(node, G74)
    return node

on_g75

on_g75(node: G75) -> G75

Handle G75 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g75(self, node: G75) -> G75:
    """Handle `G75` node."""
    self._handle_g(node, G75)
    return node

on_g90

on_g90(node: G90) -> G90

Handle G90 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g90(self, node: G90) -> G90:
    """Handle `G90` node."""
    self._handle_g(node, G90)
    return node

on_g91

on_g91(node: G91) -> G91

Handle G91 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_g91(self, node: G91) -> G91:
    """Handle `G91` node."""
    self._handle_g(node, G91)
    return node

on_lm

on_lm(node: LM) -> LM

Handle LM node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_lm(self, node: LM) -> LM:
    """Handle `LM` node."""
    with self._extended_command(f"LM{node.mirroring.value}"):
        pass
    return node

on_ln

on_ln(node: LN) -> LN

Handle LN node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ln(self, node: LN) -> LN:
    """Handle `LN` node."""
    with self._extended_command(f"LN{node.name}"):
        pass
    return node

on_lp

on_lp(node: LP) -> LP

Handle LP node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_insert_var("empty_line_before_polarity_switch")
@_decorator_insert_base_indent
def on_lp(self, node: LP) -> LP:
    """Handle `LP` node."""
    with self._extended_command(f"LP{node.polarity.value}"):
        pass
    return node

on_lr

on_lr(node: LR) -> LR

Handle LR node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_lr(self, node: LR) -> LR:
    """Handle `LR` node."""
    with self._extended_command(f"LR{self._fmt_double(node.rotation)}"):
        pass
    return node

on_ls

on_ls(node: LS) -> LS

Handle LS node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ls(self, node: LS) -> LS:
    """Handle `LS` node."""
    with self._extended_command(f"LS{self._fmt_double(node.scale)}"):
        pass
    return node

on_m00

on_m00(node: M00) -> M00

Handle M00 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_m00(self, node: M00) -> M00:
    """Handle `M00` node."""
    with self._command("M00"):
        pass
    return node

on_m01

on_m01(node: M01) -> M01

Handle M01 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_m01(self, node: M01) -> M01:
    """Handle `M01` node."""
    with self._command("M01"):
        pass
    return node

on_m02

on_m02(node: M02) -> M02

Handle M02 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_m02(self, node: M02) -> M02:
    """Handle `M02` node."""
    with self._command("M02"):
        pass
    return node

on_add

on_add(node: Add) -> Add

Handle Add node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_add(self, node: Add) -> Add:
    """Handle `Add` node."""
    if self.explicit_parenthesis:
        self._write("(")

    node.head.visit(self)

    for operand in node.tail:
        self._write("+")
        operand.visit(self)

    if self.explicit_parenthesis:
        self._write(")")

    return node

on_div

on_div(node: Div) -> Div

Handle Div node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_div(self, node: Div) -> Div:
    """Handle `Div` node."""
    if self.explicit_parenthesis:
        self._write("(")

    node.head.visit(self)

    for operand in node.tail:
        self._write("/")
        operand.visit(self)

    if self.explicit_parenthesis:
        self._write(")")

    return node

on_mul

on_mul(node: Mul) -> Mul

Handle Mul node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_mul(self, node: Mul) -> Mul:
    """Handle `Mul` node."""
    if self.explicit_parenthesis:
        self._write("(")

    node.head.visit(self)

    for operand in node.tail:
        self._write("x")
        operand.visit(self)

    if self.explicit_parenthesis:
        self._write(")")

    return node

on_sub

on_sub(node: Sub) -> Sub

Handle Sub node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_sub(self, node: Sub) -> Sub:
    """Handle `Sub` node."""
    if self.explicit_parenthesis:
        self._write("(")

    node.head.visit(self)

    for operand in node.tail:
        self._write("-")
        operand.visit(self)

    if self.explicit_parenthesis:
        self._write(")")

    return node

on_neg

on_neg(node: Neg) -> Neg

Handle Neg node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_neg(self, node: Neg) -> Neg:
    """Handle `Neg` node."""
    self._write("-")
    node.operand.visit(self)
    return node

on_pos

on_pos(node: Pos) -> Pos

Handle Pos node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_pos(self, node: Pos) -> Pos:
    """Handle `Pos` node."""
    self._write("+")
    node.operand.visit(self)
    return node

on_assignment

on_assignment(node: Assignment) -> Assignment

Handle Assignment node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_assignment(self, node: Assignment) -> Assignment:
    """Handle `Assignment` node."""
    self._write(self._macro_primitive_lf)
    node.variable.visit(self)
    self._write("=")
    node.expression.visit(self)
    self._write("*")

    return node

on_constant

on_constant(node: Constant) -> Constant

Handle Constant node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_constant(self, node: Constant) -> Constant:
    """Handle `Constant` node."""
    self._write(self._fmt_double(node.constant))
    return node

on_parenthesis

on_parenthesis(node: Parenthesis) -> Parenthesis

Handle Parenthesis node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_parenthesis(self, node: Parenthesis) -> Parenthesis:
    """Handle `Parenthesis` node."""
    if not self.explicit_parenthesis:
        self._write("(")

    node.inner.visit(self)

    if not self.explicit_parenthesis:
        self._write(")")

    return node

on_point

on_point(node: Point) -> Point

Handle Point node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_point(self, node: Point) -> Point:
    """Handle `Point` node."""
    node.x.visit(self)
    self._write(",")
    node.y.visit(self)
    return node

on_variable

on_variable(node: Variable) -> Variable

Handle Variable node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_variable(self, node: Variable) -> Variable:
    """Handle `Variable` node."""
    self._write(node.variable)
    return node

on_coordinate_x

on_coordinate_x(node: CoordinateX) -> CoordinateX

Handle Coordinate node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_coordinate_x(self, node: CoordinateX) -> CoordinateX:
    """Handle `Coordinate` node."""
    self._write(f"X{node.value}")
    return node

on_coordinate_y

on_coordinate_y(node: CoordinateY) -> CoordinateY

Handle Coordinate node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_coordinate_y(self, node: CoordinateY) -> CoordinateY:
    """Handle `Coordinate` node."""
    self._write(f"Y{node.value}")
    return node

on_coordinate_i

on_coordinate_i(node: CoordinateI) -> CoordinateI

Handle Coordinate node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_coordinate_i(self, node: CoordinateI) -> CoordinateI:
    """Handle `Coordinate` node."""
    self._write(f"I{node.value}")
    return node

on_coordinate_j

on_coordinate_j(node: CoordinateJ) -> CoordinateJ

Handle Coordinate node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
def on_coordinate_j(self, node: CoordinateJ) -> CoordinateJ:
    """Handle `Coordinate` node."""
    self._write(f"J{node.value}")
    return node

on_code_0

on_code_0(node: Code0) -> Code0

Handle Code0 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_0(self, node: Code0) -> Code0:
    """Handle `Code0` node."""
    self._write(f"{self._macro_primitive_lf}0{node.string}*")
    return node

on_code_1

on_code_1(node: Code1) -> Code1

Handle Code1 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_1(self, node: Code1) -> Code1:
    """Handle `Code1` node."""
    self._write(f"{self._macro_primitive_lf}1,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.diameter.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_y.visit(self)

    if node.rotation is not None:
        self._write(f",{self._macro_param_lf}")
        node.rotation.visit(self)

    self._write("*")
    return node

on_code_2

on_code_2(node: Code2) -> Code2

Handle Code2 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_2(self, node: Code2) -> Code2:
    """Handle `Code2` node."""
    self._write(f"{self._macro_primitive_lf}2,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.width.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.start_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.start_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.end_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.end_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_4

on_code_4(node: Code4) -> Code4

Handle Code4 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_4(self, node: Code4) -> Code4:
    """Handle `Code4` node."""
    self._write(f"{self._macro_primitive_lf}4,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.number_of_points.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.start_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.start_y.visit(self)

    for point in node.points:
        self._write(f",{self._macro_param_lf}")
        point.visit(self)

    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_5

on_code_5(node: Code5) -> Code5

Handle Code5 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_5(self, node: Code5) -> Code5:
    """Handle `Code5` node."""
    self._write(f"{self._macro_primitive_lf}5,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.number_of_vertices.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.diameter.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_6

on_code_6(node: Code6) -> Code6

Handle Code6 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_6(self, node: Code6) -> Code6:
    """Handle `Code6` node."""
    self._write(f"{self._macro_primitive_lf}6,{self._macro_param_lf}")
    node.center_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.outer_diameter.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.ring_thickness.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.gap_between_rings.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.max_ring_count.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.crosshair_thickness.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.crosshair_length.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_7

on_code_7(node: Code7) -> Code7

Handle Code7 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_7(self, node: Code7) -> Code7:
    """Handle `Code7` node."""
    self._write(f"{self._macro_primitive_lf}7,{self._macro_param_lf}")
    node.center_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.outer_diameter.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.inner_diameter.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.gap_thickness.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_20

on_code_20(node: Code20) -> Code20

Handle Code20 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_20(self, node: Code20) -> Code20:
    """Handle `Code20` node."""
    self._write(f"{self._macro_primitive_lf}20,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.width.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.start_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.start_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.end_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.end_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_21

on_code_21(node: Code21) -> Code21

Handle Code21 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_21(self, node: Code21) -> Code21:
    """Handle `Code21` node."""
    self._write(f"{self._macro_primitive_lf}21,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.width.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.height.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_x.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.center_y.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_code_22

on_code_22(node: Code22) -> Code22

Handle Code22 node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_code_22(self, node: Code22) -> Code22:
    """Handle `Code22` node."""
    self._write(f"{self._macro_primitive_lf}22,{self._macro_param_lf}")
    node.exposure.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.width.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.height.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.x_lower_left.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.y_lower_left.visit(self)
    self._write(f",{self._macro_param_lf}")
    node.rotation.visit(self)
    self._write("*")
    return node

on_as

on_as(node: AS) -> AS

Handle AS node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_as(self, node: AS) -> AS:
    """Handle `AS` node."""
    with self._extended_command("AS"):
        self._write(node.correspondence.value)
    return node

on_fs

on_fs(node: FS) -> FS

Handle FS node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_fs(self, node: FS) -> FS:
    """Handle `FS` node."""
    with self._extended_command("FS"):
        self._write(node.zeros.value)
        self._write(node.coordinate_mode.value)
        self._write(f"X{node.x_integral}{node.x_decimal}")
        self._write(f"Y{node.y_integral}{node.y_decimal}")
    return node

on_in

on_in(node: IN) -> IN

Handle IN node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_in(self, node: IN) -> IN:
    """Handle `IN` node."""
    with self._extended_command("IN"):
        self._write(node.name)
    return node

on_ip

on_ip(node: IP) -> IP

Handle IP node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ip(self, node: IP) -> IP:
    """Handle `IP` node."""
    with self._extended_command("IP"):
        self._write(node.polarity.value)
    return node

on_ir

on_ir(node: IR) -> IR

Handle IR node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_ir(self, node: IR) -> IR:
    """Handle `IR` node."""
    with self._extended_command("IR"):
        self._write(self._fmt_double(node.rotation_degrees))
    return node

on_mi

on_mi(node: MI) -> MI

Handle MI node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_mi(self, node: MI) -> MI:
    """Handle `MI` node."""
    with self._extended_command("MI"):
        self._write(f"A{node.a_mirroring}")
        self._write(f"B{node.b_mirroring}")
    return node

on_mo

on_mo(node: MO) -> MO

Handle MO node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_mo(self, node: MO) -> MO:
    """Handle `MO` node."""
    with self._extended_command("MO"):
        self._write(node.mode.value)
    return node

on_of

on_of(node: OF) -> OF

Handle OF node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_of(self, node: OF) -> OF:
    """Handle `OF` node."""
    with self._extended_command("OF"):
        if node.a_offset is not None:
            self._write(f"A{node.a_offset}")
        if node.b_offset is not None:
            self._write(f"B{node.b_offset}")
    return node

on_sf

on_sf(node: SF) -> SF

Handle SF node.

Source code in src/pygerber/gerberx3/formatter/formatter.py
@_decorator_insert_base_indent
def on_sf(self, node: SF) -> SF:
    """Handle `SF` node."""
    with self._extended_command("SF"):
        self._write("A")
        self._write(self._fmt_double(node.a_scale))
        self._write("B")
        self._write(self._fmt_double(node.b_scale))
    return node