-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkipadcheck.py
2969 lines (2705 loc) · 111 KB
/
kipadcheck.py
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
# kipadcheck.py
#
# Hopefully fixed nightly compatibility and some other improvements.
# Removed references to pcbnew colors.
# Disabled non-functional buttons on GUI.
# Removed unused GeomPoint class.
# Modified SilkInfo to work with progress bar.
# Fixed the 'Silk Slow Check' to incorporate text thickness and graphical item width
# One step closer to working with nightly re: LAYER_ID_COUNT => PCB_LAYER_ID_COUNT
#
# Eliminate dependence on class variable _board.
# Pad and drill lists not already ordered by number are ordered by area
#
# Original Author: Greg Smith, June-August 2017
#
# Naming conventions (from PEP8):
# Short python naming guide (from PEP8):
# ClassName
# function_name
# function_parameter
# parameter_disambiguation_
# variable_name
# _nonpublic_function
# _nonpublic_global_variable
# CONSTANT_VALUE_NAME
#
# This is beta. Not thoroughly tested.
#
# Inputs and outputs are in varying non-changable units (mils, inches, mm, nm)
# Only tested on KiCAD 4.06, Windows 7.
#
# Install: In Windows, place file in
# C:\Program Files\KiCad\share\kicad\scripting\plugins\kipadcheck.py
# In pcbnew, open scripting console (Tools > Scripting Console)
# Type "import kipadcheck".
#
# ABOUT:
# This python script provides additional basic DRC checks to KiCAD and lists
# to make tweaking pads easier for drill compliance, silk compliance, and
# stencil creation. It adds a menu item to "Tools" called kipadcheck which
# brings up a dialog for control.
#
# KiPadCheck
# https://github.com/HiGregSmith/KiPadCheck
# KiPadCheck provides additional basic DRC checks to KiCAD
# and lists to make tweaking pads for stencil creation easier. Functions include pad list, drill list, drill to drill spacing check, drill to track spacing check, stencil aperture check vs. stencil thicknesses, stencil aperture width vs. paste type, silk overlap of copper.
# THERE ARE BUGS:
#
# Preliminary support is included for more than 2 layers.
# Pads are not verified for shape, currently assumes rectangle bounding box.
# Assumes all pads are on the front.
# Does not mix via drill and pad drill checks.
# Does not check annular ring size.
#
# TODO list, aside from fixing the BUGS above.
# Support all layers for all checks. Currently SilkInfo does check layers
# appropriately: F.Cu vs. F.SilkS and B.Cu vs. B.SilkS
# Support more than just through drills (i.e. buried/blind self._vias).
# Label units and make consistent.
# Mask Info: Check solder mask dam sizes.
# Silk Info: Check silk screen character sizes.
# Check Annular Rings.
# Update progress bar when doing SilkInfo
#
# Pad Info: Produces two lists:
# 1) detailed list of pads by footprint reference with paste/mask properties
# 2) quantity of pads by size
# Drill Info: Generates multiple lists:
# 1) Hole quantity by specified pad drill sizes
# 2) Quantity by closest larger standard drill size
# (future option will be to pick among defined drill sets)
# 3) Drill list
# 4) Distance from each via to next closest via
# 5) Checks via drill to via drill clearance
# 6) Checks via drill to track clearance
# Stencil Info:
# 1) Lists quantity of apertures by aperture size
# 2) Summary of aperture ratios by stencil thickness
# 3) Checks AspectRatio and AreaRatio against a variety
# of stencil thicknesses (2 mil-7 mil, all currently hardcoded)
# 4) Lists solder paste sizes for calculating appropriate.
# SilkInfo has several options:
# 1) Fast check of silkscreen bounding boxes and line segments.
# 2) Slower check includes line thicknesses.
#
# EXAMPLES:
#
# Pad Info: Produces two lists:
# 1) detailed list of pads by footprint reference with paste/mask properties
# Number of pads: 293
#
# ***** Pads By Footprint Reference, Alphabetical *****
# # 4 (BT1.) X=113.665086 Y=147.423648 P=CIRC (2.64, 2.64) D=CIRC
# (2.64, 2.64) Layers=F.Cu,B.Cu,B.Mask,F.Mask lc=0.0000 c=0.1530
# Paste: spm=0.0000,0.0000 lspm=0.0000 lspmr=0.0000
# | Mask : smm=0.0000 lsmm=0.0000
# ...
# 2) quantity of pads by size
# ***** Quantity of Pads By Size *****
# Size: 0.900 0.900, Quantity 4
# Size: 0.875 1.250, Quantity 2
# Size: 0.800 1.200, Quantity 2
# Size: 0.900 1.700, Quantity 1
# Size: 0.300 0.800, Quantity 24
# ...
#
# Drill Info: Generates multiple lists:
# 1) Hole quantity by specified pad drill sizes
# ***** Quantity of Pads By Specified Drill Size *****
# Size: 1.020mm, Quantity 2
# Size: 4.826mm, Quantity 6
# Size: 1.000mm, Quantity 54
# Size: 2.640mm, Quantity 2
# Size: 1.097mm, Quantity 8
#
# 2) Hole quantity by closest larger standard drill size
# (future option will be to pick among defined drill sets)
# ***** Quantity of Pads By Standard Drill Size *****
# Size: 1.020mm (25.908in), Drill: 0.041 (59), Quantity 2
# Size: 4.826mm (122.580in), Drill: 0.191 (11), Quantity 6
# Size: 1.000mm (25.400in), Drill: 0.04 (60), Quantity 54
# Size: 2.640mm (67.056in), Drill: 0.104 (37), Quantity 2
# Size: 1.097mm (27.871in), Drill: 0.0465 (56), Quantity 8
#
# 3) Drill list
# ***** Drill Holes List
# (pad #, position (nm), Type, Drill, Drill Value, Via Width) *****
# 0 (152661291, 138048648) 3 294000 294000 600000
# 1 (113725000, 140800000) 3 294000 294000 600000
# ...
#
# 4) Distance from each via to next closest via
# ***** Distance to next closest via *****
# (looking only *forward* through the list)
#
# Minimum Via to Via = 20.000 mils (0.508 mm)
# 0 3.692 mm
# 1 1.205 mm
# ...
#
# 5) Checks via drill to via drill clearance
# ***** Vias too close to another via *****
# 29
# 44
# ...
# 6) Checks via drill to track clearance
# ***** Vias too close to track *****
# 31 Via (/IOC_RB6) at (125934690, 138137006) is 306005 away from track
# (/IOC_RB5)
# ((126280790, 137531001) ; (125660499, 137531001)). Shoud be 508000
# 23 Via (/GND) at (150540086, 141423648) is 307472 away from track (/RE2)
# ((149487558, 140816176) ; (152110941, 140816176)). Shoud be 508000
# ...
#
#
# Stencil Info:
# 1) Lists quantity of apertures by aperture size:
# (Aperture in mm, triplets of:
# stencil mil thickness, area ratio, aspect ratio)
# (qty 24) Aperture=0.225,0.725 (2.0 1.69 4.43) (3.0 1.13 2.95)
# (4.0 0.85 2.21) (5.0 0.68 1.77) (6.0 0.56 1.48) (7.0 0.48 1.27)
# Pads: [20, 45, 80, 98, 99, 100, 101, 109, 113, 121, 125, 140,
# 143, 165, 205, 208, 209, 210, 233, 234, 238, 239, 241, 244]
# From: CONN_01X24
# ...
#
# 2) Summary of aperture ratios by stencil thickness
# ***** Aperture Ratio Ranges *****
# 2.0 mil Aspect: 4.429 14.764 Area : 1.471 4.318
# 3.0 mil Aspect: 2.953 9.843 Area : 0.981 2.879
# 4.0 mil Aspect: 2.215 7.382 Area : 0.735 2.159
# 5.0 mil Aspect: 1.772 5.906 Area : 0.588 1.727
# 6.0 mil Aspect: 1.476 4.921 Area : 0.490 1.439
# 7.0 mil Aspect: 1.265 4.218 Area : 0.420 1.234
#
# 3) Checks AspectRatio and AreaRatio against a variety
# of stencil thicknesses (2 mil-7 mil, all currently hardcoded):
# ***** Failed Aperture Test *****
# Failed 5.0 mil thickness:
# Failed Area : 0.445 0.225
# Failed Area : 0.300 0.350
# Failed 6.0 mil thickness:
# Failed Area : 0.555 0.245
# Failed Area : 0.445 0.225
# Failed Area : 0.300 0.350
# Failed Area : 0.225 0.725
# Failed Aspect: 0.445 0.225
# Failed Aspect: 0.225 0.725
# Failed 7.0 mil thickness:
# Failed Area : 0.555 0.245
# Failed Area : 0.325 0.725
# Failed Area : 0.445 0.225
# Failed Area : 0.300 0.350
# Failed Area : 0.225 0.725
# Failed Aspect: 0.555 0.245
# Failed Aspect: 0.445 0.225
# Failed Aspect: 0.225 0.725
#
#
# Nevertheless, there are some examples of using python code to interact
# with KiCAD:
# Install Tools menu, replace if already existing
# (allows reloading python file after changes)
# Iterate over tracks, identify self._vias, get sizes of
# via and pad copper, mask, and paste
# Identify which layers a pad is on.
# Generate basic interactive window.
# Display multi-threaded wx.Gauge (self._progress bar).
# Get Paste (stencil) Aperture size calculated from pad properties.
#
#
# Programmer's Notes:
# pcbnew.Iu2Mils and pcbnew.Iu2DMils do not seem to work on Windows/ KiCad 4.06
# Here, we use pcbnew.IU_PER_MILS and IU_PER_MM (not used: IU_PER_DECIMILS)
# I cannot seem to figure out LSET structure. Workarounds are applied in code.
import time
import threading
import Queue
from operator import itemgetter
import math
import itertools
import wx
import pcbnew
import random # for testing
# Action Plugin information here:
# https://forum.kicad.info/t/
# howto-register-a-python-plugin-inside-pcbnew-tools-menu/
# 5540/22
# ds = board.GetDesignSettings()
# ugly. exposes a public member not via an accessor method
# nc = ds.m_NetClasses
# foo = pcbnew.NETCLASSPTR("foo")
# nc.Add(foo)
# References for stencil information
# BEST:
# http://prod.semicontaiwan.org/zh/sites/semicontaiwan.org
# /files/data15/docs/7_5_semicon_taiwan_2015_ppt_senju_akita.pdf
# http://www.circuitnet.com/experts/56418.html
# https://www.linkedin.com/pulse/
# how-choose-correct-stencil-suits-your-smt-requirement-lisa-chu
# http://www.photostencil.com/pdf/choosing_a_stencil.pdf
# https://www.smta.org/chapters/files/
# SMTA_India_05_SMTA_Presentation_Workshop_on_SMT_Stencil(R1).pdf
# https://ise.lehigh.edu/sites/ise.lehigh.edu/files/99t_005.pdf
# Minimum Aspect Ratio based on stencil production method:
# 1.5;
# 1.8: chemical etched;
# 1.2 Electropolished laser-cut or electroformed
#
# http://www.indium.com/blog/
# stencil-coach-calculates-optimal-solder-paste-printing-aperture-
# parameters-now-available-online.php
#
class wxPointUtil:
"""A variety of utilities and geometric calculations for
operating on wxPoint objects. Will work on other objects with
x,y attributes"""
atts=('x','y','z')
d=[]
#
# Possible functions to implement for point class:
# __add__(), __radd__(), __iadd__(), __mul__(), __rmul__() and __imul__()
#
@staticmethod
def dot(v,w):
"""return the dot product of point and w"""
return v.x*w.x + v.y*w.y
@staticmethod
def distance2(v,w):
"""return the distance squared between point and w"""
#sub=w-v
wvx = w.x - v.x
wvy = w.y - v.y
return wvx*wvx+wvy*wvy #abs(wxPointUtil.dot(sub,sub))
@staticmethod
def distance(v,w):
"""return the distance between point and w"""
p = v - w
return (p.x*p.x+p.y*p.y)**(1/2.0)
@staticmethod
def scale(w,factor):
""" scale (multiply) the point x and y by a specific factor"""
# self.x *= factor
# self.y *= factor
return w.__class__(float(w.x)*factor,float(w.y)*factor)
@staticmethod
def projection_axis(v, axis):
"""Project the point onto axis specified by w.
w must be a vector on the unit circle (for example: (1,0) or (0,1)
to project on the x axis or y axis, respectively)"""
# Consider the line extending the segment,
# parameterized as v + t (w - v).
# We find projection of point p onto the line.
# It falls where t = [(p-v) . (w-v)] / |w-v|^2
t = wxPointUtil.dot(v,axis);
return t
# v,w are points defining the line segment
@staticmethod
def projection_line(p, v, w):
"""project point onto the line segment v,w"""
# Return minimum distance between line segment vw and point p
# Consider the line extending the segment,
# parameterized as v + t (w - v).
# We find projection of point p onto the line.
# It falls where t = [(p-v) . (w-v)] / |w-v|^2
# We clamp t from [0,1] to handle points outside the segment vw.
# if w.x == v.x and w.y == v.y:
# return self.distance(w); # v == w case
#print "divisor=",w.distance(v)
wv=w-v
wvx = w.x - v.x
wvy = w.y - v.y
pvx = p.x - v.x
pvy = p.y - v.y
#t=0.5
t = max(0, min(1, abs(pvx*wvx+pvy*wvy) / float(wvx*wvx+wvy*wvy)));
#t = max(0, min(1, wxPointUtil.dot(p - v,wv) / float(wxPointUtil.distance2(w,v))));
projection = v + wxPointUtil.scale(wv,t); # Projection falls on the segment
return projection
@staticmethod
def normal(v, w):
"""NOT FINISHED
get normals of line formed with point w
This is the left normal if w is clockwise of self
This is the right normal if w is counter-clockwise of self"""
w.x - v.x,
w.y - v.y
# var normals:Vector.<Vector2d> = new Vector.<Vector2d>
# for (var i:int = 1; i < dots.length-1; i++)
# {
# var currentNormal:Vector2d = new Vector2d(
# dots[i + 1].x - dots[i].x,
# dots[i + 1].y - dots[i].y
# ).normL //left normals
# normals.push(currentNormal);
# }
# normals.push(
# new Vector2d(
# dots[1].x - dots[dots.length-1].x,
# dots[1].y - dots[dots.length-1].y
# ).normL
# )
# return normals;
@staticmethod
def mindistance2(u, v, w):
"""Return minimum distance squared between point and line segment v,w.
Perhaps obviously, this is faster than mindistance because sqrt()
is not called."""
#L2 = wxPointUtil.distance2(v,w)
if w.x == v.x and w.y == v.y:
#if L2 == 0.0:
return wxPointUtil.distance2(u,w); # v == w case
return wxPointUtil.distance2(u,wxPointUtil.projection_line(u,v,w))
@staticmethod
def mindistance(u, v, w):
"""return minimum distance squared between point and line segment v,w"""
L2 = wxPointUtil.distance2(w,v)
#if w.x == v.x and w.y == v.y:
if L2 == 0.0:
return wxPointUtil.distance(u,w); # v == w case
return wxPointUtil.distance(u,wxPointUtil.projection_line(u,v,w))
# L2 = v.distance2(w); # i.e. |w-v|^2 - avoid a sqrt
# if (L2 == 0.0):
# return p.distance(w); # v == w case
# return p.distance(self.projection_line(v,w));
# p = self
# # Return minimum distance between line segment vw and point p
# L2 = self.distance2(v, w); # i.e. |w-v|^2 - avoid a sqrt
# if (L2 == 0.0):
# return p.distance(v); # v == w case
# # Consider the line extending the segment,
# # parameterized as v + t (w - v).
# # We find projection of point p onto the line.
# # It falls where t = [(p-v) . (w-v)] / |w-v|^2
# # We clamp t from [0,1] to handle points outside the segment vw.
# t = max(0, min(1, (p - v).dot(w - v) / float(L2)));
# # SavePrint = "L2 %d; t %.3f"%(L2,t)
# #t = max(0, min(1, (v - p).dot(v - w) / float(L2)));
# projection = v + (w-v).scale(t); # Projection falls on the segment
# return p.distance(projection);
#https://stackoverflow.com/questions/2272179/a-simple-algorithm-for-polygon-intersection
# NB: The algorithm only works for convex polygons, specified in either clockwise, or counterclockwise order.
# 1)For each edge in both polygons, check if it can be used as a separating line. If so, you are done: No intersection.
# 2) If no separation line was found, you have an intersection
@staticmethod
def check_polygons_intersecting(poly_a, poly_b,closed=True):
"""Returns boolean indicating whether the indicated polygons are intersecting.
closed=True indicates the last point is equal to the first point.
if closed=False, the first and last point are checked as if they represent
the last polygon edge."""
for polygon in (poly_a, poly_b):
#print "\nPolygon",
# This loop is assuming last point is not the repeated first point:
# for i1 in range(len(polygon)):
# i2 = (i1 + 1) % len(polygon)
# This loop assumes the last point is the repeated first point to form closed polygon:
# for i1 in range(len(polygon)-1):
# i2 = (i1 + 1)
# This loop combines both loops above:
for i1 in range(len(polygon)-1*closed):
i2 = (i1 + 1) % len(polygon)
#print("i1={} i2={}".format(polygon[i1], i2))
p1 = polygon[i1]
p2 = polygon[i2]
normal = pcbnew.wxPoint(p2.y - p1.y, p1.x - p2.x)
minA, maxA, minB, maxB = (None,) * 4
for p in poly_a:
projected = normal.x * p.x + normal.y * p.y
if not minA or projected < minA:
minA = projected
if not maxA or projected > maxA:
maxA = projected
for p in poly_b:
projected = normal.x * p.x + normal.y * p.y
if not minB or projected < minB:
minB = projected
if not maxB or projected > maxB:
maxB = projected
#print("maxA={} minB={} -- maxB={} minA={}".format(maxA, minB, maxB, minA))
if maxA < minB or maxB < minA:
return False
#print(" Nope\n")
return True
# To find orientation of ordered triplet (p, q, r).
# The function returns following values
# 0 --> p, q and r are colinear
# 1 --> Clockwise
# 2 --> Counterclockwise
# sign = lambda x: x and (1, -1)[x < 0]
# Get leftmost point
# i, value = min(enumerate(vector), key=attrgetter('x'))
# nextpoint = vector[(i+1)%len(vector)]
# @staticmethod
# def orientation(p, q, r)
# {
# int val = (q.y - p.y) * (r.x - q.x) -
# (q.x - p.x) * (r.y - q.y);
# if (val == 0) return 0; // colinear
# return (val > 0)? 1: 2; // clock or counterclock wise
# }
@staticmethod
def convex_hull(self,line,vector):
"""NOT IMPLEMENTED.
Currently returns bounding box, best used on orthogonal.
Return the convex hull of point list vector
A fast algorithm using Jarvis's Algorithm (aka Wrapping)."""
minx = vector[0].x
miny = vector[0].y
maxx = minx
maxy = miny
for v in vector:
minx = min(minx,v.x)
maxx = max(minx,v.x)
miny = min(miny,v.y)
maxy = max(miny,v.y)
return (
pcbnew.wxPoint(minx,maxy), # upper left
pcbnew.wxPoint(maxx,maxy), # upper right
pcbnew.wxPoint(maxx,miny), # lower right
pcbnew.wxPoint(minx,miny)) # lower left
# ds = board.GetDesignSettings()
# ugly. exposes a public member not via an accessor method
# nc = ds.m_NetClasses
# foo = pcbnew.NETCLASSPTR("foo")
# nc.Add(foo)
# References for stencil information
# BEST:
# http://prod.semicontaiwan.org/zh/sites/semicontaiwan.org
# /files/data15/docs/7_5_semicon_taiwan_2015_ppt_senju_akita.pdf
# http://www.circuitnet.com/experts/56418.html
# https://www.linkedin.com/pulse/
# how-choose-correct-stencil-suits-your-smt-requirement-lisa-chu
# http://www.photostencil.com/pdf/choosing_a_stencil.pdf
# https://www.smta.org/chapters/files/
# SMTA_India_05_SMTA_Presentation_Workshop_on_SMT_Stencil(R1).pdf
# https://ise.lehigh.edu/sites/ise.lehigh.edu/files/99t_005.pdf
# Minimum Aspect Ratio based on stencil production method:
# 1.5;
# 1.8: chemical etched;
# 1.2 Electropolished laser-cut or electroformed
#
# http://www.indium.com/blog/
# stencil-coach-calculates-optimal-solder-paste-printing-aperture-
# parameters-now-available-online.php
#
class KiPadCheck( pcbnew.ActionPlugin ):
"""Contains user interface and calculations for a variety
of KiCad layers and objects. Includes information and checks on:
Pads, Silk, Stencil Apertures (Paste), and Drills."""
# LAYERCOUNT = 0
# while (0 <= pcbnew.GetBoard().GetLayerID(pcbnew.GetBoard().GetLayerName(LAYERCOUNT)) <= 254):
# LAYERCOUNT += 1
# num = 0
# while (0 <= pcbnew.GetBoard().GetLayerID(pcbnew.GetBoard().GetLayerName(num)) <= 254):
# num += 1
# num
try:
LAYERCOUNT = pcbnew.PCB_LAYER_ID_COUNT # nightlies, post 4.0.6
except:
LAYERCOUNT = pcbnew.LAYER_ID_COUNT # KiCad 4.0.6 stable
# Some threading support for self._progress bar (wx.Gauge)
# This allows stopping the thread from outside the thread.
_progress_stop = False
"""Allows stopping the progress thread from outside the thread."""
# These provide communication from inside the thread to the main GUI thread:
_progress_value_queue = Queue.Queue()
"""Place values in the queue to set the progress value, which is set
in the main GUI thread."""
_console_text_queue = Queue.Queue()
"""Place values in the queue to write as console text in the pcbnew window,
which is written in the main GUI thread."""
def defaults( self ):
"""Support for ActionPlugins, though that is not working at the moment"""
self.name = "Check pads and related layers"
self.category = "Check PCB"
self.description = "Check pads, holes, stencil apertures, and silkscreen"
def ProgressThreadFunction(self,WorkerThread):
value = self._progress.GetValue()
while(WorkerThread.is_alive()):
# take stuff from queue here
# take all you can, then call UpdateProgress
while (not self._progress_value_queue.empty()):
value = self._progress_value_queue.get()
self.UpdateProgress(value)
while (not self._console_text_queue.empty()):
self._consoleText.AppendText(self._console_text_queue.get())
time.sleep(0.25)
# process any remaining from the queues.
while (not self._progress_value_queue.empty()):
value = self._progress_value_queue.get()
self.UpdateProgress(value)
while (not self._console_text_queue.empty()):
self._consoleText.AppendText(self._console_text_queue.get())
# def GraphThreadFunction():
# while(not GraphStop):
# # put stuff in queue here
# DataQueue.put("1")
# sleep(1)
#from scipy import reshape, sqrt, identity
#import numpy
_consoleText = None
_pcbnewWindow = None
_frame = None
_progress = None
_DrillSet = 0
"""The index within StandardDrill to use in DrillInfo() checks."""
_StandardDrill = []
"""Tables of standard drill sets. Each member of the list is itself a list
of tuples (float Size, string Name)."""
_StandardDrillInfo = []
"""Information about the standard drill array member.
Description, Scale, Source (link)
Scale is multiplied by Size to get the drill size in nanameters."""
# self._StandardDrillInfo is a list of tuples (Drill Set Name, scale factor)
# scale factor is used to convert to nm (which are currently nm).
# self._StandardDrillInfo is in parallel order with self._StandardDrill
# self._StandardDrill is a list of lists of tuples. Each tuple is
# (Size in scale units, printable name)
#http://www.engineersedge.com/drill_sizes.htm
_StandardDrillInfo.append(
("Fractional per ANSI/ASME B94.11M-1993",
pcbnew.IU_PER_MILS*1000,
"http://www.engineersedge.com/drill_sizes.htm"))
_StandardDrill.append([
(.0135,"80"),
(.0145,"79"),
(.0156,"1/64"),
(.0160,"78"),
(.0180,"77"),
(.0200,"76"),
(.0210,"75"),
(.0225,"74"),
(.0240,"73"),
(.0250,"72"),
(.0260,"71"),
(.0280,"70"),
(.0292,"69"),
(.0310,"68"),
(.0313,"1/32"),
(.0320,"67"),
(.0330,"66"),
(.0350,"65"),
(.0360,"64"),
(.0370,"63"),
(.0380,"62"),
(.0390,"61"),
(.0400,"60"),
(.0410,"59"),
(.0420,"58"),
(.0430,"57"),
(.0465,"56"),
(.0469,"3/64"),
(.0520,"55"),
(.0550,"54"),
(.0595,"53"),
(.0625,"1/16"),
(.0635,"52"),
(.0670,"51"),
(.0700,"50"),
(.0730,"49"),
(.0760,"48"),
(.0781,"5/64"),
(.0785,"47"),
(.0810,"46"),
(.0820,"45"),
(.0860,"44"),
(.0890,"43"),
(.0935,"42"),
(.0937,"3/32"),
(.0960,"41"),
(.0980,"40"),
(.0995,"39"),
(.1015,"38"),
(.1040,"37"),
(.1065,"36"),
(.1093,"7/64"),
(.1100,"35"),
(.1110,"34"),
(.1130,"33"),
(.1160,"32"),
(.1200,"31"),
(.1250,"1/8"),
(.1285,"30"),
(.1360,"29"),
(.1405,"28"),
(.1406,"9/64"),
(.1440,"27"),
(.1470,"26"),
(.1495,"25"),
(.1520,"24"),
(.1540,"23"),
(.1562,"5/32"),
(.1570,"22"),
(.1590,"21"),
(.1610,"20"),
(.1660,"19"),
(.1695,"18"),
(.1719,"11/64"),
(.1730,"17"),
(.1770,"16"),
(.1800,"15"),
(.1820,"14"),
(.1850,"13"),
(.1875,"3/16"),
(.1890,"12"),
(.1910,"11"),
(.1935,"10"),
(.1960,"9"),
(.1990,"8"),
(.2010,"7"),
(.2031,"13/64"),
(.2040,"6"),
(.2055,"5"),
(.2090,"4"),
(.2130,"3"),
(.2187,"7/32"),
(.2210,"2"),
(.2280,"1"),
(.2340,"A"),
(.2344,"15/64"),
(.2380,"B"),
(.2420,"C"),
(.2460,"D"),
(.2500,"E"),
(.2500,"1/4"),
(.2570,"F"),
(.2610,"G"),
(.2656,"17/64"),
(.2660,"H"),
(.2720,"I"),
(.2770,"J"),
(.2811,"K"),
(.2812,"9/32"),
(.2900,"L"),
(.2950,"M"),
(.2968,"19/64"),
(.3020,"N"),
(.3125,"5/16"),
(.3160,"O"),
(.3230,"P"),
(.3281,"21/64"),
(.3320,"Q"),
(.3390,"R"),
(.3437,"11/32"),
(.3480,"S"),
(.3580,"T"),
(.3594,"23/64"),
(.3680,"U"),
(.3750,"3/8"),
(.3770,"V"),
(.3860,"W"),
(.3906,"25/64"),
(.3970,"X"),
(.4040,"Y"),
(.4062,"13/32"),
(.4130,"Z"),
(.4219,"27/64"),
(.4375,"7/16"),
(.4531,"29/64"),
(.4687,"15/32"),
(.4844,"31/64"),
(.5000,"1/2"),
(.5156,"33/64"),
(.5312,"17/32"),
(.5469,"35/64"),
(.5625,"9/16"),
(.5781,"37/64"),
(.5937,"19/32"),
(.6094,"39/64"),
(.6250,"5/8"),
(.6406,"41/64"),
(.6562,"21/32"),
(.6719,"43/64"),
(.6875,"11/16"),
(.7031,"45/64"),
(.7187,"23/32"),
(.7344,"47/64"),
(.7500,"3/4"),
(.7656,"49/64"),
(.7812,"25/32"),
(.7969,"51/64"),
(.8125,"13/16"),
(.8281,"53/64"),
(.8437,"27/32"),
(.8594,"55/64"),
(.8750,"7/8"),
(.8906,"57/64"),
(.9062,"29/32"),
(.9219,"59/64"),
(.9375,"15/16"),
(.9531,"61/64"),
(.9687,"31/32"),
(.9844,"63/64"),
(1.000,"1")])
_StandardDrillInfo.append(
("ISO Metric per ANSI/ASME B94.11M-1993 (preconverted to mils)",
pcbnew.IU_PER_MILS*1000,
"http://www.engineersedge.com/drill_sizes.htm"))
_StandardDrill.append([
(.0138,".35"),
(.0157,".4"),
(.0177,".45"),
(.0197,".5"),
(.0217,".55"),
(.0236,".6"),
(.0256,".65"),
(.0276,".7"),
(.0295,".75"),
(.0315,".8"),
(.0335,".85"),
(.0355,".9"),
(.0374,".95"),
(.0394,"1.0"),
(.0413,"1.05"),
(.0433,"1.1"),
(.0453,"1.15"),
(.0472,"1.2"),
(.0492,"1.25"),
(.0512,"1.3"),
(.0531,"1.35"),
(.0551,"1.4"),
(.0571,"1.45"),
(.0591,"1.5"),
(.0610,"1.55"),
(.0629,"1.6"),
(.0650,"1.65"),
(.0669,"1.7"),
(.0689,"1.75"),
(.0709,"1.8"),
(.0728,"1.85"),
(.0748,"1.9"),
(.0768,"1.95"),
(.0787,"2.0"),
(.0807,"2.05"),
(.0827,"2.1"),
(.0846,"2.15"),
(.0866,"2.2"),
(.0886,"2.25"),
(.0905,"2.3"),
(.0925,"2.35"),
(.0945,"2.4"),
(.0965,"2.45"),
(.0984,"2.5"),
(.1004,"2.55"),
(.1024,"2.6"),
(.1043,"2.65"),
(.1063,"2.7"),
(.1083,"2.75"),
(.1102,"2.8"),
(.1142,"2.9"),
(.1181,"3.0"),
(.1220,"3.1"),
(.1260,"3.2"),
(.1280,"3.25"),
(.1299,"3.3"),
(.1339,"3.4"),
(.1378,"3.5"),
(.1417,"3.6"),
(.1457,"3.7"),
(.1477,"3.75"),
(.1496,"3.8"),
(.1535,"3.9"),
(.1575,"4.0"),
(.1614,"4.1"),
(.1654,"4.2"),
(.1674,"4.25"),
(.1693,"4.3"),
(.1732,"4.4"),
(.1771,"4.5"),
(.1811,"4.6"),
(.1850,"4.7"),
(.1870,"4.75"),
(.1890,"4.8"),
(.1929,"4.9"),
(.1968,"5.0"),
(.2008,"5.1"),
(.2047,"5.2"),
(.2067,"5.25"),
(.2087,"5.3"),
(.2126,"5.4"),
(.2165,"5.5"),
(.2205,"5.6"),
(.2244,"5.7"),
(.2264,"5.75"),
(.2283,"5.8"),
(.2323,"5.9"),
(.2362,"6.0"),
(.2401,"6.1"),
(.2441,"6.2"),
(.2461,"6.25"),
(.2480,"6.3"),
(.2520,"6.4"),
(.2559,"6.5"),
(.2598,"6.6"),
(.2638,"6.7"),
(.2658,"6.75"),
(.2677,"6.8"),
(.2716,"6.9"),
(.2756,"7.0"),
(.2795,"7.1"),
(.2835,"7.2"),
(.2855,"7.25"),
(.2874,"7.3"),
(.2913,"7.4"),
(.2953,"7.5"),
(.2990,"7.6"),
(.3031,"7.7"),
(.3051,"7.75"),
(.3071,"7.8"),
(.3110,"7.9"),
(.3150,"8.0"),
(.3189,"8.1"),
(.3228,"8.2"),
(.3248,"8.25"),
(.3267,"8.3"),
(.3307,"8.4"),
(.3346,"8.5"),
(.3386,"8.6"),
(.3425,"8.7"),
(.3445,"8.75"),
(.3465,"8.8"),
(.3504,"8.9"),
(.3543,"9.0"),
(.3583,"9.1"),
(.3622,"9.2"),
(.3642,"9.25"),
(.3661,"9.35"),
(.3701,"9.4"),
(.3740,"9.5"),
(.3780,"9.6"),
(.3819,"9.7"),
(.3839,"9.75"),
(.3858,"9.8"),
(.3898,"9.9"),
(.3937,"10.0"),
(.4133,"10.5"),
(.4331,"11.0"),
(.4528,"11.5"),
(.4724,"12.0"),
(.4921,"12.5"),
(.5118,"13.0"),
(.5315,"13.5"),
(.5512,"14.0"),
(.5708,"14.5"),
(.5906,"15.0"),
(.6102,"15.5"),
(.6300,"16.0"),
(.6496,"16.5"),
(.6693,"17.0"),
(.6889,"17.5"),
(.7087,"18.0"),
(.7283,"18.5"),
(.7480,"19.0"),
(.7677,"19.5"),
(.7874,"20.0"),
(.8071,"20.5"),
(.8268,"21.0"),
(.8465,"21.5"),
(.8661,"22.0"),
(.8858,"22.5"),
(.9055,"23.0"),
(.9252,"23.5"),
(.9449,"24.0"),
(.9646,"24.5"),
(.9843,"25.0")
])
# http://www.pcbwizards.com/Drillchart.htm
_StandardDrillInfo.append(("Standard PCB drill sizes",
pcbnew.IU_PER_MILS*1000,
"http://www.pcbwizards.com/Drillchart.htm"))
_StandardDrill.append([
(0.011,"85"),
(0.0115,"84"),
(0.012,"83"),
(0.0125,"82"),
(0.013,"81"),
(0.0135,"80"),
(0.0145,"79"),
(0.015625,"1/64"),