-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileFunction.java
More file actions
1637 lines (1542 loc) · 55.2 KB
/
FileFunction.java
File metadata and controls
1637 lines (1542 loc) · 55.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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
/*
* Copyright (C) 2025 Tony Luken <tonyluken62+gerberfilereader.gmail.com>
*
* This file is part of GerberFileReader.
*
* GerberFileReader is free software: you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* GerberFileReader is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with GerberFileReader. If
* not, see <http://www.gnu.org/licenses/>.
*/
package standardAttributes;
import gerberFileReader.GerberLayerFormatException;
/**
* A class to represent the Gerber Standard Attribute {@value #GERBER_STANDARD_ATTRIBUTE_NAME}
*/
public class FileFunction extends StandardAttribute {
/**
* The string used in Gerber files as the name for File Function Standard Attributes:
* {@value #GERBER_STANDARD_ATTRIBUTE_NAME}
*/
public static final String GERBER_STANDARD_ATTRIBUTE_NAME = ".FileFunction";
/**
* Constructs an empty File Function Standard Attribute, call
* {@link StandardAttribute#initialize(Attribute)} to initialize the contents of this File
* Function Standard Attribute
*/
public FileFunction() {
super();
}
/**
* Constructs a File Function Standard Attribute from a Gerber TF extended command
* @param cmd the Gerber command
* @throws GerberLayerFormatException if the command does not properly define a File Function
* Standard Attribute
*/
public FileFunction(String cmd) throws GerberLayerFormatException {
super(cmd);
validate();
}
/**
* An enumeration of possible file functions: {@link #Copper}, {@link #Plated},
* {@link #NonPlated}, {@link #Profile}, {@link #Soldermask}, {@link #Legend},
* {@link #Component}, {@link #Paste}, {@link #Glue}, {@link #Carbonmask}, {@link #Goldmask},
* {@link #Heatsinkmask}, {@link #Peelablemask}, {@link #Silvermask}, {@link #Tinmask},
* {@link #Depthrout}, {@link #Vcut}, {@link #Viafill}, {@link #Pads}, {@link #Other},
* {@link #Drillmap}, {@link #FabricationDrawing}, {@link #Vcutmap}, {@link #AssemblyDrawing},
* {@link #ArrayDrawing}, {@link #OtherDrawing}, and {@link #Unknown}.
*/
public enum Function {
/**
* Defines the layout of a copper layer of the PCB.
*/
Copper,
/**
* Defines the size and location of plated drill holes and routed slots.
*/
Plated,
/**
* Defines the size and location of non-plated drill holes and routed slots.
*/
NonPlated,
/**
* Defines the shape (AKA outline or edge cuts) of the PCB.
*/
Profile,
/**
* Defines a solder mask for the PCB.
*/
Soldermask,
/**
* Defines a legend or silk screen for the PCB.
*/
Legend,
/**
* Defines the orientation, location, and type of components to install on the PCB
*/
Component,
/**
* Defines where solder paste should be applied to the PCB prior to component assembly.
*/
Paste,
/**
* Defines where glue should be applied to the PCB prior to component assembly.
*/
Glue,
/**
* Defines a carbon mask for the PCB.
*/
Carbonmask,
/**
* Defines a gold mask for the PCB.
*/
Goldmask,
/**
* Defines a heatsink mask for the PCB.
*/
Heatsinkmask,
/**
* Defines a peelable mask for the PCB.
*/
Peelablemask,
/**
* Defines a silver mask for the PCB.
*/
Silvermask,
/**
* Defines a tin mask for the PCB.
*/
Tinmask,
/**
* Defines areas that must be routed to a given depth rather than going through the whole
* board.
*/
Depthrout,
/**
* Defines lines to be v-cut or scored.
*/
Vcut,
/**
* Defines the vias that are to be filled.
*/
Viafill,
/**
* Defines the pads (footprints) of the PCB's components.
*/
Pads,
/**
* Defines some function not otherwise specified by the Gerber Layer Format Specification.
*/
Other,
/**
* A drawing with the locations of the drilled holes. It often also contains the hole sizes,
* tolerances and plated/non-plated info.
*/
Drillmap,
/**
* An auxiliary drawing with additional information for the fabrication of the bare PCB: the
* location of holes and slots, the board outline, sizes and tolerances, layer stack,
* material, finish, etc.
*/
FabricationDrawing,
/**
* A drawing with v-cut or scoring information.
*/
Vcutmap,
/**
* An auxiliary drawing with the locations and reference designators of the components. It
* is mainly used in PCB assembly.
*/
AssemblyDrawing,
/**
* A drawing of the array (biscuit, assembly panel, shipment panel, customer panel).
*/
ArrayDrawing,
/**
* Any other drawing whose function is not otherwise specified by the Gerber Layer Format
* Specification.
*/
OtherDrawing,
/**
* This value is only used to indicate the Gerber file contains an invalid or unknown
* function.
*/
Unknown;
public static Function fromAttributeValue(String attributeValue) {
try {
return valueOf(Function.class, attributeValue);
}
catch (IllegalArgumentException e) {
return Unknown;
}
}
}
/**
* Gets the file's function.
*
* @return the file's function
*/
public Function getFunction() {
return Function.fromAttributeValue(getValues().get(0));
}
/**
* Checks if the file describes a copper layer.
*
* @return true if the file describes a copper layer
*
* @see #getFunction()
* @see #getCopperLayerNumber()
* @see #getCopperSide()
* @see #isCopperTop()
* @see #isCopperInner()
* @see #isCopperBottom()
* @see #hasCopperType()
* @see #getCopperType()
*/
public boolean isCopperLayer() {
return getFunction() == Function.Copper;
}
/**
* For copper layers, gets the copper layer number within the PCB. For an N layer board, the
* layers are numbered 1 to N with 1 being the top layer.
*
* @return the copper layer number
* @throws UnsupportedOperationException if the file does not describe a copper layer
* @see #isCopperLayer()
*/
public int getCopperLayerNumber() {
if (!isCopperLayer()) {
throw new UnsupportedOperationException("Method getCopperLayerNumber() is not available for " + toString());
}
return Integer.parseInt(getValues().get(1).substring(1)); //Strip the leading 'L'
}
/**
* For copper layers, gets the the PCB side of the copper layer.
*
* @return the side
* @throws UnsupportedOperationException if the file does not describe a copper layer
* @see #isCopperLayer()
*/
public BoardSide getCopperSide() {
if (!isCopperLayer()) {
throw new UnsupportedOperationException("Method getCopperSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(2));
}
/**
* Checks if the file describes the top copper layer.
*
* @return true if the file describes the top copper layer
* @see #isCopperLayer()
* @see #getCopperSide()
* @see #isCopperInner()
* @see #isCopperBottom()
*/
public boolean isCopperTop() {
return isCopperLayer() && getCopperSide() == BoardSide.Top;
}
/**
* Checks if the file describes an inner copper layer.
*
* @return true if the file describes an inner copper layer
* @see #isCopperLayer()
* @see #getCopperSide()
* @see #isCopperTop()
* @see #isCopperBottom()
*/
public boolean isCopperInner() {
return isCopperLayer() && getCopperSide() == BoardSide.Inner;
}
/**
* Checks if the file describes the bottom copper layer.
*
* @return true if the file describes the bottom copper layer
* @see #isCopperLayer()
* @see #getCopperSide()
* @see #isCopperTop()
* @see #isCopperInner()
*/
public boolean isCopperBottom() {
return isCopperLayer() && getCopperSide() == BoardSide.Bottom;
}
/**
* For copper layers, checks if a copper type is specified. If so, {@link #getCopperType()}
* returns the copper type.
*
* @return true if a copper type is specified
* @throws UnsupportedOperationException if the file does not describe a copper layer
* @see #isCopperLayer()
*/
public boolean hasCopperType() {
if (!isCopperLayer()) {
throw new UnsupportedOperationException("Method hasCopperType() is not available for " + toString());
}
return getValues().size() > 3;
}
/**
* For copper layers, gets the copper type.
*
* @return the copper type if a copper type is specified, otherwise returns null
* @throws UnsupportedOperationException if the file does not describe a copper layer
* @see #isCopperLayer()
* @see #hasCopperType()
*/
public CopperType getCopperType() {
if (!isCopperLayer()) {
throw new UnsupportedOperationException("Method getCopperType() is not available for " + toString());
}
if (hasCopperType()) {
return CopperType.fromAttributeValue(getValues().get(3));
}
return null;
}
/**
* Checks if the file describes plated holes and routed slots in the PCB.
*
* @return true if the file describes plated holes and routed slots
* @see #getFunction()
* @see #isNonPlatedHoles()
* @see #getHoleFromLayerNumber()
* @see #getHoleToLayerNumber()
* @see #getHoleType()
* @see #hasHoleFabricationMethod()
* @see #getHoleFabricationMethod()
*/
public boolean isPlatedHoles() {
return getFunction() == Function.Plated;
}
/**
* Checks if the file describes non-plated holes and routed slots in the PCB.
*
* @return true if the file describes the non-plated holes and routed slots
* @see #getFunction()
* @see #isPlatedHoles()
* @see #getHoleFromLayerNumber()
* @see #getHoleToLayerNumber()
* @see #getHoleType()
* @see #hasHoleFabricationMethod()
* @see #getHoleFabricationMethod()
*/
public boolean isNonPlatedHoles() {
return getFunction() == Function.NonPlated;
}
/**
* Gets the drill/rout span from layer number for the holes and routed slots.
*
* @return the from layer number
* @throws UnsupportedOperationException if the file does not describe holes and routed slots.
* @see #getHoleToLayerNumber()
* @see #isPlatedHoles()
* @see #isNonPlatedHoles()
*/
public int getHoleFromLayerNumber() {
if (!isPlatedHoles() && !isNonPlatedHoles()) {
throw new UnsupportedOperationException("Method getHoleFromLayerNumber() is not available for " + toString());
}
return Integer.parseInt(getValues().get(1));
}
/**
* Gets the drill/rout span to layer number for the holes and routed slots.
*
* @return the to layer number
* @throws UnsupportedOperationException if the file does not describe holes and routed slots.
* @see #getHoleFromLayerNumber()
* @see #isPlatedHoles()
* @see #isNonPlatedHoles()
*/
public int getHoleToLayerNumber() {
if (!isPlatedHoles() && !isNonPlatedHoles()) {
throw new UnsupportedOperationException("Method getHoleToLayerNumber() is not available for " + toString());
}
return Integer.parseInt(getValues().get(2));
}
/**
* Gets the hole type defined by the file.
*
* @return the hole type
* @throws UnsupportedOperationException if the file does not describe holes and routed slots.
* @see #isPlatedHoles()
* @see #isNonPlatedHoles()
*/
public HoleType getHoleType() {
if (!isPlatedHoles() && !isNonPlatedHoles()) {
throw new UnsupportedOperationException("Method getHoleType() is not available for " + toString());
}
return HoleType.fromAttributeValue(getValues().get(3));
}
/**
* Checks if a hole fabrication method is specified by the file. If so,
* {@link #getHoleFabricationMethod()} returns the hole fabrication method.
*
* @return true if a hole fabrication method is specified
* @throws UnsupportedOperationException if the file does not describe holes and routed slots.
* @see #isPlatedHoles()
* @see #isNonPlatedHoles()
*/
public boolean hasHoleFabricationMethod() {
if (!isPlatedHoles() && !isNonPlatedHoles()) {
throw new UnsupportedOperationException("Method hasHoleFabricationMethod() is not available for " + toString());
}
return getValues().size() > 4;
}
/**
* Gets the hole fabrication method.
*
* @return the hole fabrication method if one is specified, null otherwise
* @throws UnsupportedOperationException if the file does not describe holes and routed slots.
*
* @see #hasHoleFabricationMethod()
* @see #isPlatedHoles()
* @see #isNonPlatedHoles()
*/
public HoleFabricationMethod getHoleFabricationMethod() {
if (!isPlatedHoles() && !isNonPlatedHoles()) {
throw new UnsupportedOperationException("Method getHoleFabricationMethod() is not available for " + toString());
}
if (hasHoleFabricationMethod()) {
return HoleFabricationMethod.fromAttributeValue(getValues().get(4));
}
return null;
}
/**
* Checks if the file defines the profile (outline or edge cuts) of the PCB.
*
* @return true if the file defines the profile
*
* @see #getFunction()
* @see #isProfileEdgePlated()
* @see #isProfileNonEdgePlated()
*/
public boolean isProfile() {
return getFunction() == Function.Profile;
}
/**
* An enumeration of PCB profile edge treatments: {@link #Plated}, {@link #NonPlated}, and
* {@link #Unknown}.
*/
public enum ProfileEdgeTreatment {
/**
* Indicated the PCB edges are to be copper plated
*/
Plated,
/**
* Indicated the PCB edges are to not be copper plated
*/
NonPlated,
/**
* This value is only used to indicate the Gerber file contains an invalid or unknown
* value.
*/
Unknown;
public static ProfileEdgeTreatment fromAttributeValue(String attributeValue) {
switch (attributeValue) {
case "P" :
return Plated;
case "NP" :
return NonPlated;
default :
return Unknown;
}
}
}
/**
* Gets the profile's edge treatment.
*
* @return the edge treatment
* @throws UnsupportedOperationException if the file doesn't defines the profile
* @see #isProfile()
* @see #isProfileEdgePlated()
* @see #isProfileNonEdgePlated()
*/
public ProfileEdgeTreatment getProfileEdgeTreatment() {
if (!isProfile()) {
throw new UnsupportedOperationException("Method getProfileEdgeTreatment() is not available for " + toString());
}
return ProfileEdgeTreatment.fromAttributeValue(getValues().get(1));
}
/**
* For files defining the profile, checks if the profile is to be edge plated.
*
* @return true if the file defines the profile and its edges are to be plated
*
* @see #isProfile()
* @see #getProfileEdgeTreatment()
* @see #isProfileNonEdgePlated()
*/
public boolean isProfileEdgePlated() {
return isProfile() && getProfileEdgeTreatment() == ProfileEdgeTreatment.Plated;
}
/**
* For files defining the profile, checks if the profile is to not be edge plated.
*
* @return true if the file defines the profile and its edges are not to be plated
*
* @see #isProfile()
* @see #getProfileEdgeTreatment()
* @see #isProfileEdgePlated()
*/
public boolean isProfileNonEdgePlated() {
return isProfile() && getProfileEdgeTreatment() == ProfileEdgeTreatment.NonPlated;
}
/**
* Checks if the file defines one of the known PCB mask types.
*
* @return true if the file defines one of the known mask types
*
* @see #getFunction()
* @see #getMaskType()
* @see #isSolderMask()
* @see #getMaskSide()
* @see #isMaskTop()
* @see #isMaskBottom()
* @see #hasMaskIndex()
* @see #getMaskIndex()
*/
public boolean isMask() {
if (getValues().size() < 1) {
return false;
}
return MaskType.fromAttributeValue(getValues().get(0)) != MaskType.Unknown;
}
/**
* Gets the PCB mask type defined by the file
*
* @return the mask type
* @throws UnsupportedOperationException if the file does not define a mask
* @see #isMask()
* @see #isSolderMask()
*/
public MaskType getMaskType() {
if (!isMask()) {
throw new UnsupportedOperationException("Method getMaskType() is not available for " + toString());
}
return MaskType.fromAttributeValue(getValues().get(0));
}
/**
* Checks if the file defines a solder mask for the PCB.
*
* @return true if the file defines a solder mask
* @see #getFunction()
* @see #isMask()
* @see #getMaskType()
*/
public boolean isSolderMask() {
return getFunction() == Function.Soldermask;
}
/**
* Gets the side of the PCB on which the mask is to be applied.
*
* @return the side
* @throws UnsupportedOperationException if the file does not describe a mask
* @see #isMask()
* @see #isMaskTop()
* @see #isMaskBottom()
*/
public BoardSide getMaskSide() {
if (!isMask()) {
throw new UnsupportedOperationException("Mehtod getMaskSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(1));
}
/**
* Checks if the file defines a mask for the top side of the PCB.
*
* @return true if the file defines a mask for the top side
* @see #isMask()
* @see #getMaskSide()
* @see #isMaskBottom()
*/
public boolean isMaskTop() {
return isMask() && getMaskSide() == BoardSide.Top;
}
/**
* Checks if the file defines a mask for the bottom side of the PCB.
*
* @return true if the file defines a mask for the bottom side
* @see #isMask()
* @see #getMaskSide()
* @see #isMaskTop()
*/
public boolean isMaskBottom() {
return isMask() && getMaskSide() == BoardSide.Bottom;
}
/**
* Checks if the file has an optional index that indicates the order in which the mask is
* to be applied to the PCB. If so, {@link #getMaskIndex()} returns the value of the index.
*
* @return true if the file has the optional index
* @throws UnsupportedOperationException if the file does not describe a mask
* @see #isMask()
* @see #getMaskIndex()
*/
public boolean hasMaskIndex() {
if (!isMask()) {
throw new UnsupportedOperationException("Method hasMaskIndex() is not available for " + toString());
}
return getValues().size() > 2;
}
/**
* Gets the value of the optional mask index that indicates the order in which the mask is to be
* applied to the PCB. Masks with lower indices are applied before ones with higher indices.
*
* @return the value of the mask index if the file has one, otherwise returns -1
* @throws UnsupportedOperationException if the file does not describe a mask.
* @see #isMask()
* @see #hasMaskIndex()
*/
public int getMaskIndex() {
if (!isMask()) {
throw new UnsupportedOperationException("Method getMaskIndex() is not available for " + toString());
}
if (hasMaskIndex()) {
return Integer.parseInt(getValues().get(2));
}
return -1;
}
/**
* Checks if the file defines a legend (also known as a silkscreen) for the PCB.
*
* @return true if the file defines a legend
* @see #getFunction()
* @see #getLegendSide()
* @see #isLegendTop()
* @see #isLegendBottom()
* @see #hasLegendIndex()
* @see #getLegendIndex()
*/
public boolean isLegend() {
return getFunction() == Function.Legend;
}
/**
* Gets the side of the PCB on which the legend is to be applied.
*
* @return the side
* @throws UnsupportedOperationException if the file does not describe a legend
* @see #isLegend()
* @see #isLegendTop()
* @see #isLegendBottom()
*/
public BoardSide getLegendSide() {
if (!isLegend()) {
throw new UnsupportedOperationException("Method getLegendSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(1));
}
/**
* Checks if the file defines a legend for the top side of the PCB.
*
* @return true if the file defines a legend for the top side of the PCB.
* @see #isLegend()
* @see #getLegendSide()
* @see #isLegendBottom()
*/
public boolean isLegendTop() {
return isLegend() && getLegendSide() == BoardSide.Top;
}
/**
* Checks if the file defines a legend for the bottom side of the PCB.
*
* @return true if the file defines a legend for the bottom side of the PCB.
* @see #isLegend()
* @see #getLegendSide()
* @see #isLegendTop()
*/
public boolean isLegendBottom() {
return isLegend() && getLegendSide() == BoardSide.Bottom;
}
/**
* Checks if the file has the optional index that defines the order in which the legend
* is to be applied to the PCB. If so, {@link #getLegendIndex()} returns the value of the index.
*
* @return true if the file has the optional index
* @throws UnsupportedOperationException if the file does not describe a legend
* @see #isLegend()
* @see #getLegendIndex()
*/
public boolean hasLegendIndex() {
if (!isLegend()) {
throw new UnsupportedOperationException("Method hasLegendIndex() is not available for " + toString());
}
return getValues().size() > 2;
}
/**
* Gets the value of the legend index that defines the order in which the legend is to be
* applied to the PCB. Legends with lower indices are applied to the PCB before legends with
* higher indices.
*
* @return the value of the legend index if one is specified, otherwise returns -1
* @throws UnsupportedOperationException if the file does not describe a legend
* @see #isLegend()
* @see #hasLegendIndex()
*/
public int getLegendIndex() {
if (!isLegend()) {
throw new UnsupportedOperationException("Method getLegendIndex() is not available for " + toString());
}
if (hasLegendIndex()) {
return Integer.parseInt(getValues().get(2));
}
return -1;
}
/**
* Checks if the file describes components, their location, and orientation on the
* PCB.
*
* @return true if the file describes components
* @see #getFunction()
* @see #getComponentSide()
* @see #isComponentSideTop()
* @see #isComponentSideBottom()
* @see #getComponentLayerNumber()
*/
public boolean isComponent() {
return getFunction() == Function.Component;
}
/**
* Gets the side of the PCB on which the components are to be installed.
*
* @return the side
* @throws UnsupportedOperationException if the file does not describe components.
* @see #isComponent()
* @see #isComponentSideTop()
* @see #isComponentSideBottom()
*/
public BoardSide getComponentSide() {
if (!isComponent()) {
throw new UnsupportedOperationException("Method getComponentSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(2));
}
/**
* Checks if the file describes components for the top side of the PCB.
*
* @return true if the file describes components and they are to be installed on the top side
* @see #isComponent()
* @see #getComponentSide()
* @see #isComponentSideBottom()
*/
public boolean isComponentSideTop() {
return isComponent() && getComponentSide() == BoardSide.Top;
}
/**
* Checks if the file describes components for the bottom side of the PCB.
*
* @return true if the file describes components and they are to be installed on the bottom side
* @see #isComponent()
* @see #getComponentSide()
* @see #isComponentSideTop()
*/
public boolean isComponentSideBottom() {
return isComponent() && getComponentSide() == BoardSide.Bottom;
}
/**
* Gets the layer number (where 1 is the top copper layer) of the PCB where the components
* reside. Note, this information is somewhat redundant with the information returned by
* {@link #getComponentSide()}. However, for embedded components, the layer number is important.
*
* @return the layer number
* @throws UnsupportedOperationException if the file does not describe components
* @see #isComponent()
*/
public int getComponentLayerNumber() {
if (!isComponent()) {
throw new UnsupportedOperationException("Method getComponentLayerNumber() is not available for " + toString());
}
return Integer.parseInt(getValues().get(1).substring(1)); //Strip leading 'L'
}
/**
* Checks if the file describes where solder paste should be applied to the PCB.
*
* @return true if the file describes where solder paste should be applied
* @see #getFunction()
* @see #getPasteSide()
* @see #isPasteTop()
* @see #isPasteBottom()
*/
public boolean isPaste() {
return getFunction() == Function.Paste;
}
/**
* Gets the side of the PCB to which solder paste should be applied.
*
* @return the side
* @throws UnsupportedOperationException if the file doesn't describe where solder paste should
* be applied
* @see #isPaste()
*/
public BoardSide getPasteSide() {
if (!isPaste()) {
throw new UnsupportedOperationException("Method getPasteSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(1));
}
/**
* Checks if the file describes solder paste for the top side of the PCB.
*
* @return true if the file describes solder paste for the top side
* @see #isPaste()
* @see #getPasteSide()
* @see #isPasteBottom()
*/
public boolean isPasteTop() {
return isPaste() && getPasteSide() == BoardSide.Top;
}
/**
* Checks if the file describes solder paste for the bottom side of the PCB.
*
* @return true if the file describes solder paste for the bottom side
* @see #isPaste()
* @see #getPasteSide()
* @see #isPasteBottom()
*/
public boolean isPasteBottom() {
return isPaste() && getPasteSide() == BoardSide.Bottom;
}
/**
* Checks if the file describes where glue should be applied to the PCB.
*
* @return true if the file describes where glue should be applied
* @see #getFunction()
* @see #getGlueSide()
* @see #isGlueTop()
* @see #isGlueBottom()
*/
public boolean isGlue() {
return getFunction() == Function.Glue;
}
/**
* Gets the side of the PCB on which glue is to be applied.
*
* @return the side
* @throws UnsupportedOperationException if the file doesn't describe where glue should be
* applied to the PCB
* @see #isGlue()
* @see #isGlueTop()
* @see #isGlueBottom()
*/
public BoardSide getGlueSide() {
if (!isGlue()) {
throw new UnsupportedOperationException("Method getGlueSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(1));
}
/**
* Checks if the file describes where glue should be applied to the top of the PCB.
*
* @return true if the file describes where glue should be applied to the top
* @see #isGlue()
* @see #getGlueSide()
* @see #isGlueBottom()
*/
public boolean isGlueTop() {
return isGlue() && getGlueSide() == BoardSide.Top;
}
/**
* Checks if the file describes where glue should be applied to the bottom of the PCB.
*
* @return true if the file describes where glue should be applied to the bottom
* @see #isGlue()
* @see #getGlueSide()
* @see #isGlueTop()
*/
public boolean isGlueBottom() {
return isGlue() && getGlueSide() == BoardSide.Bottom;
}
/**
* Checks if the file describes areas of the PCB that are to be routed to a specific depth (not
* all the way through the board).
*
* @return true if the file describes areas of the PCB that are to be routed to a specific depth
* @see #getFunction()
* @see #getDepthRoutSide()
* @see #isDepthRoutTop()
* @see #isDepthRoutBottom()
*/
public boolean isDepthRout() {
return getFunction() == Function.Depthrout;
}
/**
* Gets the side of the PCB to be routed to a specific depth.
*
* @return the side
* @throws UnsupportedOperationException if the file doesn't describe where the PCB is to be
* routed to a specific depth
* @see #isDepthRout()
* @see #isDepthRoutTop()
* @see #isDepthRoutBottom()
*/
public BoardSide getDepthRoutSide() {
if (!isDepthRout()) {
throw new UnsupportedOperationException("Method getDepthRoutSide() is not available for " + toString());
}
return BoardSide.fromAttributeValue(getValues().get(1));
}
/**
* Checks if the file describes where the top side of the PCB is to be routed to a specific
* depth.
*
* @return true if the file describes where the top side of the PCB is to be routed to a
* specific depth
* @see #isDepthRout()
* @see #getDepthRoutSide()
* @see #isDepthRoutBottom()
*/
public boolean isDepthRoutTop() {
return isDepthRout() && getDepthRoutSide() == BoardSide.Top;
}
/**
* Checks if the file describes where the bottom side of the PCB is to be routed to a specific
* depth.
*
* @return true if the file describes where the bottom side of the PCB is to be routed to a
* specific depth
* @see #isDepthRout()
* @see #getDepthRoutSide()
* @see #isDepthRoutTop()
*/
public boolean isDepthRoutBottom() {
return isDepthRout() && getDepthRoutSide() == BoardSide.Bottom;
}
/**
* Checks if the file describes v-cuts (also known as scoring).
*
* @return true if the file describes v-cuts
* @see #getFunction()
* @see #getVCutSide()
* @see #isVCutTop()
* @see #isVCutBottom()
* @see #isVCutBoth()
*/
public boolean isVCut() {
return getFunction() == Function.Vcut;
}
/**
* Gets the side of the PCB that is to be v-cut or scored.
*
* @return the side
* @throws UnsupportedOperationException if the file doesn't describe v-cuts
* @see #isVCut()
* @see #isVCutTop()
* @see #isVCutBottom()
* @see #isVCutBoth()
*/
public BoardSide getVCutSide() {
if (!isVCut()) {
throw new UnsupportedOperationException("Method getVCutSide() is not available for " + toString());
}
if (getValues().size() > 1) {
return BoardSide.fromAttributeValue(getValues().get(1));
}
return BoardSide.Both;
}