ToolRulesCheck.py 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. # ########################################################## ##
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Marius Adrian Stanciu (c) #
  5. # Date: 09/27/2019 #
  6. # MIT Licence #
  7. # ########################################################## ##
  8. from FlatCAMTool import FlatCAMTool
  9. from copy import copy, deepcopy
  10. from ObjectCollection import *
  11. import time
  12. from FlatCAMPool import *
  13. from os import getpid
  14. from shapely.ops import nearest_points
  15. from shapely.geometry.base import BaseGeometry
  16. import gettext
  17. import FlatCAMTranslation as fcTranslate
  18. import builtins
  19. fcTranslate.apply_language('strings')
  20. if '_' not in builtins.__dict__:
  21. _ = gettext.gettext
  22. class RulesCheck(FlatCAMTool):
  23. toolName = _("Check Rules")
  24. tool_finished = pyqtSignal(list)
  25. def __init__(self, app):
  26. super(RulesCheck, self).__init__(self)
  27. self.app = app
  28. # ## Title
  29. title_label = QtWidgets.QLabel("%s" % self.toolName)
  30. title_label.setStyleSheet("""
  31. QLabel
  32. {
  33. font-size: 16px;
  34. font-weight: bold;
  35. }
  36. """)
  37. self.layout.addWidget(title_label)
  38. # Form Layout
  39. self.grid_layout = QtWidgets.QGridLayout()
  40. self.layout.addLayout(self.grid_layout)
  41. self.gerber_title_lbl = QtWidgets.QLabel('<b>%s</b>:' % _("Gerber Files"))
  42. self.gerber_title_lbl.setToolTip(
  43. _("Gerber files for which to check rules.")
  44. )
  45. self.all_obj_cb = FCCheckBox()
  46. # Copper Top object
  47. self.copper_t_object = QtWidgets.QComboBox()
  48. self.copper_t_object.setModel(self.app.collection)
  49. self.copper_t_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  50. self.copper_t_object.setCurrentIndex(1)
  51. self.copper_t_object_lbl = QtWidgets.QLabel('%s:' % _("Top"))
  52. self.copper_t_object_lbl.setToolTip(
  53. _("The Gerber Copper Top file for which rules are checked.")
  54. )
  55. self.copper_t_cb = FCCheckBox()
  56. # Copper Bottom object
  57. self.copper_b_object = QtWidgets.QComboBox()
  58. self.copper_b_object.setModel(self.app.collection)
  59. self.copper_b_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  60. self.copper_b_object.setCurrentIndex(1)
  61. self.copper_b_object_lbl = QtWidgets.QLabel('%s:' % _("Bottom"))
  62. self.copper_b_object_lbl.setToolTip(
  63. _("The Gerber Copper Bottom file for which rules are checked.")
  64. )
  65. self.copper_b_cb = FCCheckBox()
  66. # SolderMask Top object
  67. self.sm_t_object = QtWidgets.QComboBox()
  68. self.sm_t_object.setModel(self.app.collection)
  69. self.sm_t_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  70. self.sm_t_object.setCurrentIndex(1)
  71. self.sm_t_object_lbl = QtWidgets.QLabel('%s:' % _("SM Top"))
  72. self.sm_t_object_lbl.setToolTip(
  73. _("The Gerber Solder Mask Top file for which rules are checked.")
  74. )
  75. self.sm_t_cb = FCCheckBox()
  76. # SolderMask Bottom object
  77. self.sm_b_object = QtWidgets.QComboBox()
  78. self.sm_b_object.setModel(self.app.collection)
  79. self.sm_b_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  80. self.sm_b_object.setCurrentIndex(1)
  81. self.sm_b_object_lbl = QtWidgets.QLabel('%s:' % _("SM Bottom"))
  82. self.sm_b_object_lbl.setToolTip(
  83. _("The Gerber Solder Mask Top file for which rules are checked.")
  84. )
  85. self.sm_b_cb = FCCheckBox()
  86. # SilkScreen Top object
  87. self.ss_t_object = QtWidgets.QComboBox()
  88. self.ss_t_object.setModel(self.app.collection)
  89. self.ss_t_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  90. self.ss_t_object.setCurrentIndex(1)
  91. self.ss_t_object_lbl = QtWidgets.QLabel('%s:' % _("Silk Top"))
  92. self.ss_t_object_lbl.setToolTip(
  93. _("The Gerber Silkscreen Top file for which rules are checked.")
  94. )
  95. self.ss_t_cb = FCCheckBox()
  96. # SilkScreen Bottom object
  97. self.ss_b_object = QtWidgets.QComboBox()
  98. self.ss_b_object.setModel(self.app.collection)
  99. self.ss_b_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  100. self.ss_b_object.setCurrentIndex(1)
  101. self.ss_b_object_lbl = QtWidgets.QLabel('%s:' % _("Silk Bottom"))
  102. self.ss_b_object_lbl.setToolTip(
  103. _("The Gerber Silkscreen Bottom file for which rules are checked.")
  104. )
  105. self.ss_b_cb = FCCheckBox()
  106. # Outline object
  107. self.outline_object = QtWidgets.QComboBox()
  108. self.outline_object.setModel(self.app.collection)
  109. self.outline_object.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  110. self.outline_object.setCurrentIndex(1)
  111. self.outline_object_lbl = QtWidgets.QLabel('%s:' % _("Outline"))
  112. self.outline_object_lbl.setToolTip(
  113. _("The Gerber Outline (Cutout) file for which rules are checked.")
  114. )
  115. self.out_cb = FCCheckBox()
  116. self.grid_layout.addWidget(self.gerber_title_lbl, 0, 0, 1, 2)
  117. self.grid_layout.addWidget(self.all_obj_cb, 0, 2)
  118. self.grid_layout.addWidget(self.copper_t_object_lbl, 1, 0)
  119. self.grid_layout.addWidget(self.copper_t_object, 1, 1)
  120. self.grid_layout.addWidget(self.copper_t_cb, 1, 2)
  121. self.grid_layout.addWidget(self.copper_b_object_lbl, 2, 0)
  122. self.grid_layout.addWidget(self.copper_b_object, 2, 1)
  123. self.grid_layout.addWidget(self.copper_b_cb, 2, 2)
  124. self.grid_layout.addWidget(self.sm_t_object_lbl, 3, 0)
  125. self.grid_layout.addWidget(self.sm_t_object, 3, 1)
  126. self.grid_layout.addWidget(self.sm_t_cb, 3, 2)
  127. self.grid_layout.addWidget(self.sm_b_object_lbl, 4, 0)
  128. self.grid_layout.addWidget(self.sm_b_object, 4, 1)
  129. self.grid_layout.addWidget(self.sm_b_cb, 4, 2)
  130. self.grid_layout.addWidget(self.ss_t_object_lbl, 5, 0)
  131. self.grid_layout.addWidget(self.ss_t_object, 5, 1)
  132. self.grid_layout.addWidget(self.ss_t_cb, 5, 2)
  133. self.grid_layout.addWidget(self.ss_b_object_lbl, 6, 0)
  134. self.grid_layout.addWidget(self.ss_b_object, 6, 1)
  135. self.grid_layout.addWidget(self.ss_b_cb, 6, 2)
  136. self.grid_layout.addWidget(self.outline_object_lbl, 7, 0)
  137. self.grid_layout.addWidget(self.outline_object, 7, 1)
  138. self.grid_layout.addWidget(self.out_cb, 7, 2)
  139. self.grid_layout.addWidget(QtWidgets.QLabel(""), 8, 0, 1, 3)
  140. self.excellon_title_lbl = QtWidgets.QLabel('<b>%s</b>:' % _("Excellon Files"))
  141. self.excellon_title_lbl.setToolTip(
  142. _("Excellon files for which to check rules.")
  143. )
  144. # Excellon 1 object
  145. self.e1_object = QtWidgets.QComboBox()
  146. self.e1_object.setModel(self.app.collection)
  147. self.e1_object.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  148. self.e1_object.setCurrentIndex(1)
  149. self.e1_object_lbl = QtWidgets.QLabel('%s:' % _("Excellon 1"))
  150. self.e1_object_lbl.setToolTip(
  151. _("Object to be panelized. This means that it will\n"
  152. "be duplicated in an array of rows and columns.")
  153. )
  154. self.e1_cb = FCCheckBox()
  155. # Excellon 2 object
  156. self.e2_object = QtWidgets.QComboBox()
  157. self.e2_object.setModel(self.app.collection)
  158. self.e2_object.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  159. self.e2_object.setCurrentIndex(1)
  160. self.e2_object_lbl = QtWidgets.QLabel('%s:' % _("Excellon 2"))
  161. self.e2_object_lbl.setToolTip(
  162. _("Object to be panelized. This means that it will\n"
  163. "be duplicated in an array of rows and columns.")
  164. )
  165. self.e2_cb = FCCheckBox()
  166. self.grid_layout.addWidget(self.excellon_title_lbl, 9, 0, 1, 3)
  167. self.grid_layout.addWidget(self.e1_object_lbl, 10, 0)
  168. self.grid_layout.addWidget(self.e1_object, 10, 1)
  169. self.grid_layout.addWidget(self.e1_cb, 10, 2)
  170. self.grid_layout.addWidget(self.e2_object_lbl, 11, 0)
  171. self.grid_layout.addWidget(self.e2_object, 11, 1)
  172. self.grid_layout.addWidget(self.e2_cb, 11, 2)
  173. self.grid_layout.addWidget(QtWidgets.QLabel(""), 12, 0, 1, 3)
  174. self.grid_layout.setColumnStretch(0, 0)
  175. self.grid_layout.setColumnStretch(1, 3)
  176. self.grid_layout.setColumnStretch(2, 0)
  177. # Control All
  178. self.all_cb = FCCheckBox('%s' % _("All Rules"))
  179. self.all_cb.setToolTip(
  180. _("This check/uncheck all the rules below.")
  181. )
  182. self.all_cb.setStyleSheet(
  183. """
  184. QCheckBox {font-weight: bold; color: green}
  185. """
  186. )
  187. self.layout.addWidget(self.all_cb)
  188. # Form Layout
  189. self.form_layout_1 = QtWidgets.QFormLayout()
  190. self.layout.addLayout(self.form_layout_1)
  191. self.form_layout_1.addRow(QtWidgets.QLabel(""))
  192. # Trace size
  193. self.trace_size_cb = FCCheckBox('%s:' % _("Trace Size"))
  194. self.trace_size_cb.setToolTip(
  195. _("This checks if the minimum size for traces is met.")
  196. )
  197. self.form_layout_1.addRow(self.trace_size_cb)
  198. # Copper2copper clearance value
  199. self.trace_size_entry = FCEntry()
  200. self.trace_size_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  201. self.trace_size_lbl.setToolTip(
  202. _("Minimum acceptable clearance value.")
  203. )
  204. self.form_layout_1.addRow(self.trace_size_lbl, self.trace_size_entry)
  205. self.ts = OptionalInputSection(self.trace_size_cb, [self.trace_size_lbl, self.trace_size_entry])
  206. # Copper2copper clearance
  207. self.clearance_copper2copper_cb = FCCheckBox('%s:' % _("Copper to Copper clearance"))
  208. self.clearance_copper2copper_cb.setToolTip(
  209. _("This checks if the minimum clearance between copper\n"
  210. "features is met.")
  211. )
  212. self.form_layout_1.addRow(self.clearance_copper2copper_cb)
  213. # Copper2copper clearance value
  214. self.clearance_copper2copper_entry = FCEntry()
  215. self.clearance_copper2copper_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  216. self.clearance_copper2copper_lbl.setToolTip(
  217. _("Minimum acceptable clearance value.")
  218. )
  219. self.form_layout_1.addRow(self.clearance_copper2copper_lbl, self.clearance_copper2copper_entry)
  220. self.c2c = OptionalInputSection(
  221. self.clearance_copper2copper_cb, [self.clearance_copper2copper_lbl, self.clearance_copper2copper_entry])
  222. # Copper2outline clearance
  223. self.clearance_copper2ol_cb = FCCheckBox('%s:' % _("Copper to Outline clearance"))
  224. self.clearance_copper2ol_cb.setToolTip(
  225. _("This checks if the minimum clearance between copper\n"
  226. "features and the outline is met.")
  227. )
  228. self.form_layout_1.addRow(self.clearance_copper2ol_cb)
  229. # Copper2outline clearance value
  230. self.clearance_copper2ol_entry = FCEntry()
  231. self.clearance_copper2ol_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  232. self.clearance_copper2ol_lbl.setToolTip(
  233. _("Minimum acceptable clearance value.")
  234. )
  235. self.form_layout_1.addRow(self.clearance_copper2ol_lbl, self.clearance_copper2ol_entry)
  236. self.c2ol = OptionalInputSection(
  237. self.clearance_copper2ol_cb, [self.clearance_copper2ol_lbl, self.clearance_copper2ol_entry])
  238. # Silkscreen2silkscreen clearance
  239. self.clearance_silk2silk_cb = FCCheckBox('%s:' % _("Silk to Silk Clearance"))
  240. self.clearance_silk2silk_cb.setToolTip(
  241. _("This checks if the minimum clearance between silkscreen\n"
  242. "features and silkscreen features is met.")
  243. )
  244. self.form_layout_1.addRow(self.clearance_silk2silk_cb)
  245. # Copper2silkscreen clearance value
  246. self.clearance_silk2silk_entry = FCEntry()
  247. self.clearance_silk2silk_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  248. self.clearance_silk2silk_lbl.setToolTip(
  249. _("Minimum acceptable clearance value.")
  250. )
  251. self.form_layout_1.addRow(self.clearance_silk2silk_lbl, self.clearance_silk2silk_entry)
  252. self.s2s = OptionalInputSection(
  253. self.clearance_silk2silk_cb, [self.clearance_silk2silk_lbl, self.clearance_silk2silk_entry])
  254. # Silkscreen2soldermask clearance
  255. self.clearance_silk2sm_cb = FCCheckBox('%s:' % _("Silk to Solder Mask Clearance"))
  256. self.clearance_silk2sm_cb.setToolTip(
  257. _("This checks if the minimum clearance between silkscreen\n"
  258. "features and soldermask features is met.")
  259. )
  260. self.form_layout_1.addRow(self.clearance_silk2sm_cb)
  261. # Silkscreen2soldermask clearance value
  262. self.clearance_silk2sm_entry = FCEntry()
  263. self.clearance_silk2sm_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  264. self.clearance_silk2sm_lbl.setToolTip(
  265. _("Minimum acceptable clearance value.")
  266. )
  267. self.form_layout_1.addRow(self.clearance_silk2sm_lbl, self.clearance_silk2sm_entry)
  268. self.s2sm = OptionalInputSection(
  269. self.clearance_silk2sm_cb, [self.clearance_silk2sm_lbl, self.clearance_silk2sm_entry])
  270. # Silk2outline clearance
  271. self.clearance_silk2ol_cb = FCCheckBox('%s:' % _("Silk to Outline Clearance"))
  272. self.clearance_silk2ol_cb.setToolTip(
  273. _("This checks if the minimum clearance between silk\n"
  274. "features and the outline is met.")
  275. )
  276. self.form_layout_1.addRow(self.clearance_silk2ol_cb)
  277. # Silk2outline clearance value
  278. self.clearance_silk2ol_entry = FCEntry()
  279. self.clearance_silk2ol_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  280. self.clearance_silk2ol_lbl.setToolTip(
  281. _("Minimum acceptable clearance value.")
  282. )
  283. self.form_layout_1.addRow(self.clearance_silk2ol_lbl, self.clearance_silk2ol_entry)
  284. self.s2ol = OptionalInputSection(
  285. self.clearance_silk2ol_cb, [self.clearance_silk2ol_lbl, self.clearance_silk2ol_entry])
  286. # Soldermask2soldermask clearance
  287. self.clearance_sm2sm_cb = FCCheckBox('%s:' % _("Minimum Solder Mask Sliver"))
  288. self.clearance_sm2sm_cb.setToolTip(
  289. _("This checks if the minimum clearance between soldermask\n"
  290. "features and soldermask features is met.")
  291. )
  292. self.form_layout_1.addRow(self.clearance_sm2sm_cb)
  293. # Soldermask2soldermask clearance value
  294. self.clearance_sm2sm_entry = FCEntry()
  295. self.clearance_sm2sm_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  296. self.clearance_sm2sm_lbl.setToolTip(
  297. _("Minimum acceptable clearance value.")
  298. )
  299. self.form_layout_1.addRow(self.clearance_sm2sm_lbl, self.clearance_sm2sm_entry)
  300. self.sm2sm = OptionalInputSection(
  301. self.clearance_sm2sm_cb, [self.clearance_sm2sm_lbl, self.clearance_sm2sm_entry])
  302. # Ring integrity check
  303. self.ring_integrity_cb = FCCheckBox('%s:' % _("Minimum Annular Ring"))
  304. self.ring_integrity_cb.setToolTip(
  305. _("This checks if the minimum copper ring left by drilling\n"
  306. "a hole into a pad is met.")
  307. )
  308. self.form_layout_1.addRow(self.ring_integrity_cb)
  309. # Ring integrity value
  310. self.ring_integrity_entry = FCEntry()
  311. self.ring_integrity_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  312. self.ring_integrity_lbl.setToolTip(
  313. _("Minimum acceptable ring value.")
  314. )
  315. self.form_layout_1.addRow(self.ring_integrity_lbl, self.ring_integrity_entry)
  316. self.anr = OptionalInputSection(
  317. self.ring_integrity_cb, [self.ring_integrity_lbl, self.ring_integrity_entry])
  318. self.form_layout_1.addRow(QtWidgets.QLabel(""))
  319. # Hole2Hole clearance
  320. self.clearance_d2d_cb = FCCheckBox('%s:' % _("Hole to Hole Clearance"))
  321. self.clearance_d2d_cb.setToolTip(
  322. _("This checks if the minimum clearance between a drill hole\n"
  323. "and another drill hole is met.")
  324. )
  325. self.form_layout_1.addRow(self.clearance_d2d_cb)
  326. # Hole2Hole clearance value
  327. self.clearance_d2d_entry = FCEntry()
  328. self.clearance_d2d_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  329. self.clearance_d2d_lbl.setToolTip(
  330. _("Minimum acceptable clearance value.")
  331. )
  332. self.form_layout_1.addRow(self.clearance_d2d_lbl, self.clearance_d2d_entry)
  333. self.d2d = OptionalInputSection(
  334. self.clearance_d2d_cb, [self.clearance_d2d_lbl, self.clearance_d2d_entry])
  335. # Drill holes size check
  336. self.drill_size_cb = FCCheckBox('%s:' % _("Hole Size"))
  337. self.drill_size_cb.setToolTip(
  338. _("This checks if the drill holes\n"
  339. "sizes are above the threshold.")
  340. )
  341. self.form_layout_1.addRow(self.drill_size_cb)
  342. # Drile holes value
  343. self.drill_size_entry = FCEntry()
  344. self.drill_size_lbl = QtWidgets.QLabel('%s:' % _("Min value"))
  345. self.drill_size_lbl.setToolTip(
  346. _("Minimum acceptable clearance value.")
  347. )
  348. self.form_layout_1.addRow(self.drill_size_lbl, self.drill_size_entry)
  349. self.ds = OptionalInputSection(
  350. self.drill_size_cb, [self.drill_size_lbl, self.drill_size_entry])
  351. # Buttons
  352. hlay_2 = QtWidgets.QHBoxLayout()
  353. self.layout.addLayout(hlay_2)
  354. # hlay_2.addStretch()
  355. self.run_button = QtWidgets.QPushButton(_("Run Rules Check"))
  356. self.run_button.setToolTip(
  357. _("Panelize the specified object around the specified box.\n"
  358. "In other words it creates multiple copies of the source object,\n"
  359. "arranged in a 2D array of rows and columns.")
  360. )
  361. hlay_2.addWidget(self.run_button)
  362. self.layout.addStretch()
  363. # #######################################################
  364. # ################ SIGNALS ##############################
  365. # #######################################################
  366. self.copper_t_cb.stateChanged.connect(lambda st: self.copper_t_object.setDisabled(not st))
  367. self.copper_b_cb.stateChanged.connect(lambda st: self.copper_b_object.setDisabled(not st))
  368. self.sm_t_cb.stateChanged.connect(lambda st: self.sm_t_object.setDisabled(not st))
  369. self.sm_b_cb.stateChanged.connect(lambda st: self.sm_b_object.setDisabled(not st))
  370. self.ss_t_cb.stateChanged.connect(lambda st: self.ss_t_object.setDisabled(not st))
  371. self.ss_b_cb.stateChanged.connect(lambda st: self.ss_b_object.setDisabled(not st))
  372. self.out_cb.stateChanged.connect(lambda st: self.outline_object.setDisabled(not st))
  373. self.e1_cb.stateChanged.connect(lambda st: self.e1_object.setDisabled(not st))
  374. self.e2_cb.stateChanged.connect(lambda st: self.e2_object.setDisabled(not st))
  375. self.all_obj_cb.stateChanged.connect(self.on_all_objects_cb_changed)
  376. self.all_cb.stateChanged.connect(self.on_all_cb_changed)
  377. self.run_button.clicked.connect(self.execute)
  378. # self.app.collection.rowsInserted.connect(self.on_object_loaded)
  379. self.tool_finished.connect(self.on_tool_finished)
  380. # list to hold the temporary objects
  381. self.objs = []
  382. # final name for the panel object
  383. self.outname = ""
  384. # flag to signal the constrain was activated
  385. self.constrain_flag = False
  386. # Multiprocessing Process Pool
  387. self.pool = self.app.pool
  388. self.results = None
  389. # def on_object_loaded(self, index, row):
  390. # print(index.internalPointer().child_items[row].obj.options['name'], index.data())
  391. def on_all_cb_changed(self, state):
  392. cb_items = [self.form_layout_1.itemAt(i).widget() for i in range(self.form_layout_1.count())
  393. if isinstance(self.form_layout_1.itemAt(i).widget(), FCCheckBox)]
  394. for cb in cb_items:
  395. if state:
  396. cb.setChecked(True)
  397. else:
  398. cb.setChecked(False)
  399. def on_all_objects_cb_changed(self, state):
  400. cb_items = [self.grid_layout.itemAt(i).widget() for i in range(self.grid_layout.count())
  401. if isinstance(self.grid_layout.itemAt(i).widget(), FCCheckBox)]
  402. for cb in cb_items:
  403. if state:
  404. cb.setChecked(True)
  405. else:
  406. cb.setChecked(False)
  407. def run(self, toggle=True):
  408. self.app.report_usage("ToolRulesCheck()")
  409. if toggle:
  410. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  411. if self.app.ui.splitter.sizes()[0] == 0:
  412. self.app.ui.splitter.setSizes([1, 1])
  413. else:
  414. try:
  415. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  416. # if tab is populated with the tool but it does not have the focus, focus on it
  417. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  418. # focus on Tool Tab
  419. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  420. else:
  421. self.app.ui.splitter.setSizes([0, 1])
  422. except AttributeError:
  423. pass
  424. else:
  425. if self.app.ui.splitter.sizes()[0] == 0:
  426. self.app.ui.splitter.setSizes([1, 1])
  427. FlatCAMTool.run(self)
  428. self.set_tool_ui()
  429. self.app.ui.notebook.setTabText(2, _("Rules Tool"))
  430. def install(self, icon=None, separator=None, **kwargs):
  431. FlatCAMTool.install(self, icon, separator, shortcut='ALT+R', **kwargs)
  432. def set_tool_ui(self):
  433. # all object combobox default as disabled
  434. self.copper_t_object.setDisabled(True)
  435. self.copper_b_object.setDisabled(True)
  436. self.sm_t_object.setDisabled(True)
  437. self.sm_b_object.setDisabled(True)
  438. self.ss_t_object.setDisabled(True)
  439. self.ss_b_object.setDisabled(True)
  440. self.outline_object.setDisabled(True)
  441. self.e1_object.setDisabled(True)
  442. self.e2_object.setDisabled(True)
  443. self.reset_fields()
  444. @staticmethod
  445. def check_inside_gerber_clearance(gerber_obj, size, rule):
  446. rule_title = rule
  447. violations = list()
  448. obj_violations = dict()
  449. obj_violations.update({
  450. 'name': '',
  451. 'points': list()
  452. })
  453. if not gerber_obj:
  454. return 'Fail. Not enough Gerber objects to check Gerber 2 Gerber clearance'
  455. total_geo = list()
  456. for apid in gerber_obj['apertures']:
  457. if 'geometry' in gerber_obj['apertures'][apid]:
  458. geometry = gerber_obj['apertures'][apid]['geometry']
  459. for geo_el in geometry:
  460. if 'solid' in geo_el and geo_el['solid'] is not None:
  461. total_geo.append(geo_el['solid'])
  462. total_geo = MultiPolygon(total_geo)
  463. total_geo = total_geo.buffer(0)
  464. iterations = len(total_geo)
  465. iterations = (iterations * (iterations - 1)) / 2
  466. log.debug("RulesCheck.check_gerber_clearance(). Iterations: %s" % str(iterations))
  467. min_dict = dict()
  468. idx = 1
  469. for geo in total_geo:
  470. for s_geo in total_geo[idx:]:
  471. # minimize the number of distances by not taking into considerations those that are too small
  472. dist = geo.distance(s_geo)
  473. if float(dist) < float(size):
  474. loc_1, loc_2 = nearest_points(geo, s_geo)
  475. dx = loc_1.x - loc_2.x
  476. dy = loc_1.y - loc_2.y
  477. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  478. if dist in min_dict:
  479. min_dict[dist].append(loc)
  480. else:
  481. min_dict[dist] = [loc]
  482. idx += 1
  483. points_list = list()
  484. for dist in min_dict.keys():
  485. for location in min_dict[dist]:
  486. points_list.append(location)
  487. obj_violations['name'] = gerber_obj['name']
  488. obj_violations['points'] = points_list
  489. violations.append(deepcopy(obj_violations))
  490. return rule_title, violations
  491. @staticmethod
  492. def check_gerber_clearance(gerber_list, size, rule):
  493. rule_title = rule
  494. violations = list()
  495. obj_violations = dict()
  496. obj_violations.update({
  497. 'name': '',
  498. 'points': list()
  499. })
  500. if len(gerber_list) == 2:
  501. gerber_1 = gerber_list[0]
  502. # added it so I won't have errors of using before declaring
  503. gerber_2 = dict()
  504. gerber_3 = gerber_list[1]
  505. elif len(gerber_list) == 3:
  506. gerber_1 = gerber_list[0]
  507. gerber_2 = gerber_list[1]
  508. gerber_3 = gerber_list[2]
  509. else:
  510. return 'Fail. Not enough Gerber objects to check Gerber 2 Gerber clearance'
  511. total_geo_grb_1 = list()
  512. for apid in gerber_1['apertures']:
  513. if 'geometry' in gerber_1['apertures'][apid]:
  514. geometry = gerber_1['apertures'][apid]['geometry']
  515. for geo_el in geometry:
  516. if 'solid' in geo_el and geo_el['solid'] is not None:
  517. total_geo_grb_1.append(geo_el['solid'])
  518. if len(gerber_list) == 3:
  519. # add the second Gerber geometry to the first one if it exists
  520. for apid in gerber_2['apertures']:
  521. if 'geometry' in gerber_2['apertures'][apid]:
  522. geometry = gerber_2['apertures'][apid]['geometry']
  523. for geo_el in geometry:
  524. if 'solid' in geo_el and geo_el['solid'] is not None:
  525. total_geo_grb_1.append(geo_el['solid'])
  526. total_geo_grb_3 = list()
  527. for apid in gerber_3['apertures']:
  528. if 'geometry' in gerber_3['apertures'][apid]:
  529. geometry = gerber_3['apertures'][apid]['geometry']
  530. for geo_el in geometry:
  531. if 'solid' in geo_el and geo_el['solid'] is not None:
  532. total_geo_grb_3.append(geo_el['solid'])
  533. iterations = len(total_geo_grb_1) * len(total_geo_grb_3)
  534. log.debug("RulesCheck.check_gerber_clearance(). Iterations: %s" % str(iterations))
  535. min_dict = dict()
  536. for geo in total_geo_grb_1:
  537. for s_geo in total_geo_grb_3:
  538. # minimize the number of distances by not taking into considerations those that are too small
  539. dist = geo.distance(s_geo)
  540. if float(dist) < float(size):
  541. loc_1, loc_2 = nearest_points(geo, s_geo)
  542. dx = loc_1.x - loc_2.x
  543. dy = loc_1.y - loc_2.y
  544. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  545. if dist in min_dict:
  546. min_dict[dist].append(loc)
  547. else:
  548. min_dict[dist] = [loc]
  549. points_list = list()
  550. for dist in min_dict.keys():
  551. for location in min_dict[dist]:
  552. points_list.append(location)
  553. name_list = list()
  554. if gerber_1:
  555. name_list.append(gerber_1['name'])
  556. if gerber_2:
  557. name_list.append(gerber_2['name'])
  558. if gerber_3:
  559. name_list.append(gerber_3['name'])
  560. obj_violations['name'] = name_list
  561. obj_violations['points'] = points_list
  562. violations.append(deepcopy(obj_violations))
  563. return rule_title, violations
  564. @staticmethod
  565. def check_holes_size(elements, size):
  566. rule = _("Hole Size")
  567. violations = list()
  568. obj_violations = dict()
  569. obj_violations.update({
  570. 'name': '',
  571. 'dia': list()
  572. })
  573. for elem in elements:
  574. dia_list = []
  575. name = elem['name']
  576. for tool in elem['tools']:
  577. tool_dia = float(elem['tools'][tool]['C'])
  578. if tool_dia < float(size):
  579. dia_list.append(tool_dia)
  580. obj_violations['name'] = name
  581. obj_violations['dia'] = dia_list
  582. violations.append(deepcopy(obj_violations))
  583. return rule, violations
  584. @staticmethod
  585. def check_holes_clearance(elements, size):
  586. rule = _("Hole to Hole Clearance")
  587. violations = list()
  588. obj_violations = dict()
  589. obj_violations.update({
  590. 'name': '',
  591. 'points': list()
  592. })
  593. total_geo = list()
  594. for elem in elements:
  595. for tool in elem['tools']:
  596. if 'solid_geometry' in elem['tools'][tool]:
  597. geometry = elem['tools'][tool]['solid_geometry']
  598. for geo in geometry:
  599. total_geo.append(geo)
  600. min_dict = dict()
  601. idx = 1
  602. for geo in total_geo:
  603. for s_geo in total_geo[idx:]:
  604. # minimize the number of distances by not taking into considerations those that are too small
  605. dist = geo.distance(s_geo)
  606. loc_1, loc_2 = nearest_points(geo, s_geo)
  607. dx = loc_1.x - loc_2.x
  608. dy = loc_1.y - loc_2.y
  609. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  610. if dist in min_dict:
  611. min_dict[dist].append(loc)
  612. else:
  613. min_dict[dist] = [loc]
  614. idx += 1
  615. points_list = list()
  616. for dist in min_dict.keys():
  617. if float(dist) < size:
  618. for location in min_dict[dist]:
  619. points_list.append(location)
  620. name_list = list()
  621. for elem in elements:
  622. name_list.append(elem['name'])
  623. obj_violations['name'] = name_list
  624. obj_violations['points'] = points_list
  625. violations.append(deepcopy(obj_violations))
  626. return rule, violations
  627. @staticmethod
  628. def check_traces_size(elements, size):
  629. rule = _("Trace Size")
  630. violations = list()
  631. obj_violations = dict()
  632. obj_violations.update({
  633. 'name': '',
  634. 'size': list(),
  635. 'points': list()
  636. })
  637. for elem in elements:
  638. dia_list = []
  639. points_list = []
  640. name = elem['name']
  641. for apid in elem['apertures']:
  642. tool_dia = float(elem['apertures'][apid]['size'])
  643. if tool_dia < float(size):
  644. dia_list.append(tool_dia)
  645. for geo_el in elem['apertures'][apid]['geometry']:
  646. if 'solid' in geo_el.keys():
  647. geo = geo_el['solid']
  648. pt = geo.representative_point()
  649. points_list.append((pt.x, pt.y))
  650. obj_violations['name'] = name
  651. obj_violations['size'] = dia_list
  652. obj_violations['points'] = points_list
  653. violations.append(deepcopy(obj_violations))
  654. return rule, violations
  655. @staticmethod
  656. def check_gerber_annular_ring(obj_list, size, rule):
  657. rule_title = rule
  658. violations = list()
  659. obj_violations = dict()
  660. obj_violations.update({
  661. 'name': '',
  662. 'points': list()
  663. })
  664. # added it so I won't have errors of using before declaring
  665. gerber_obj = dict()
  666. gerber_extra_obj = dict()
  667. exc_obj = dict()
  668. exc_extra_obj = dict()
  669. if len(obj_list) == 2:
  670. gerber_obj = obj_list[0]
  671. exc_obj = obj_list[1]
  672. if 'apertures' in gerber_obj and 'tools' in exc_obj:
  673. pass
  674. else:
  675. return 'Fail. At least one Gerber and one Excellon object is required to check Minimum Annular Ring'
  676. elif len(obj_list) == 3:
  677. o1 = obj_list[0]
  678. o2 = obj_list[1]
  679. o3 = obj_list[2]
  680. if 'apertures' in o1 and 'apertures' in o2:
  681. gerber_obj = o1
  682. gerber_extra_obj = o2
  683. exc_obj = o3
  684. elif 'tools' in o2 and 'tools' in o3:
  685. gerber_obj = o1
  686. exc_obj = o2
  687. exc_extra_obj = o3
  688. elif len(obj_list) == 4:
  689. gerber_obj = obj_list[0]
  690. gerber_extra_obj = obj_list[1]
  691. exc_obj = obj_list[2]
  692. exc_extra_obj = obj_list[3]
  693. else:
  694. return 'Fail. Not enough objects to check Minimum Annular Ring'
  695. total_geo_grb = list()
  696. for apid in gerber_obj['apertures']:
  697. if 'geometry' in gerber_obj['apertures'][apid]:
  698. geometry = gerber_obj['apertures'][apid]['geometry']
  699. for geo_el in geometry:
  700. if 'solid' in geo_el and geo_el['solid'] is not None:
  701. total_geo_grb.append(geo_el['solid'])
  702. if len(obj_list) == 3 and gerber_extra_obj:
  703. # add the second Gerber geometry to the first one if it exists
  704. for apid in gerber_extra_obj['apertures']:
  705. if 'geometry' in gerber_extra_obj['apertures'][apid]:
  706. geometry = gerber_extra_obj['apertures'][apid]['geometry']
  707. for geo_el in geometry:
  708. if 'solid' in geo_el and geo_el['solid'] is not None:
  709. total_geo_grb.append(geo_el['solid'])
  710. total_geo_grb = MultiPolygon(total_geo_grb)
  711. total_geo_grb = total_geo_grb.buffer(0)
  712. total_geo_exc = list()
  713. for tool in exc_obj['tools']:
  714. if 'solid_geometry' in exc_obj['tools'][tool]:
  715. geometry = exc_obj['tools'][tool]['solid_geometry']
  716. for geo in geometry:
  717. total_geo_exc.append(geo)
  718. if len(obj_list) == 3 and exc_extra_obj:
  719. # add the second Excellon geometry to the first one if it exists
  720. for tool in exc_extra_obj['tools']:
  721. if 'solid_geometry' in exc_extra_obj['tools'][tool]:
  722. geometry = exc_extra_obj['tools'][tool]['solid_geometry']
  723. for geo in geometry:
  724. total_geo_exc.append(geo)
  725. iterations = len(total_geo_grb) * len(total_geo_exc)
  726. log.debug("RulesCheck.check_gerber_annular_ring(). Iterations: %s" % str(iterations))
  727. min_dict = dict()
  728. for geo in total_geo_grb:
  729. for s_geo in total_geo_exc:
  730. # minimize the number of distances by not taking into considerations those that are too small
  731. dist = geo.exterior.distance(s_geo)
  732. if float(dist) < float(size):
  733. loc_1, loc_2 = nearest_points(geo.exterior, s_geo)
  734. dx = loc_1.x - loc_2.x
  735. dy = loc_1.y - loc_2.y
  736. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  737. if dist in min_dict:
  738. min_dict[dist].append(loc)
  739. else:
  740. min_dict[dist] = [loc]
  741. points_list = list()
  742. for dist in min_dict.keys():
  743. for location in min_dict[dist]:
  744. points_list.append(location)
  745. name_list = list()
  746. if gerber_obj:
  747. name_list.append(gerber_obj['name'])
  748. if gerber_extra_obj:
  749. name_list.append(gerber_obj['name'])
  750. if exc_obj:
  751. name_list.append(gerber_obj['name'])
  752. if exc_extra_obj:
  753. name_list.append(gerber_obj['name'])
  754. obj_violations['name'] = name_list
  755. obj_violations['points'] = points_list
  756. violations.append(deepcopy(obj_violations))
  757. return rule_title, violations
  758. def execute(self):
  759. self.results = list()
  760. log.debug("RuleCheck() executing")
  761. def worker_job(app_obj):
  762. proc = self.app.proc_container.new(_("Working..."))
  763. # RULE: Check Trace Size
  764. if self.trace_size_cb.get_value():
  765. copper_list = list()
  766. copper_name_1 = self.copper_t_object.currentText()
  767. if copper_name_1 is not '' and self.copper_t_cb.get_value():
  768. elem_dict = dict()
  769. elem_dict['name'] = deepcopy(copper_name_1)
  770. elem_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_name_1).apertures)
  771. copper_list.append(elem_dict)
  772. copper_name_2 = self.copper_b_object.currentText()
  773. if copper_name_2 is not '' and self.copper_b_cb.get_value():
  774. elem_dict = dict()
  775. elem_dict['name'] = deepcopy(copper_name_2)
  776. elem_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_name_2).apertures)
  777. copper_list.append(elem_dict)
  778. trace_size = float(self.trace_size_entry.get_value())
  779. self.results.append(self.pool.apply_async(self.check_traces_size, args=(copper_list, trace_size)))
  780. # RULE: Check Copper to Copper Clearance
  781. if self.clearance_copper2copper_cb.get_value():
  782. copper_dict = dict()
  783. try:
  784. copper_copper_clearance = float(self.clearance_copper2copper_entry.get_value())
  785. except Exception as e:
  786. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  787. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  788. _("Copper to Copper clearance"),
  789. _("Value is not valid.")))
  790. return
  791. if self.copper_t_cb.get_value():
  792. copper_obj = self.copper_t_object.currentText()
  793. if copper_obj is not '':
  794. copper_dict['name'] = deepcopy(copper_obj)
  795. copper_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_obj).apertures)
  796. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  797. args=(copper_dict,
  798. copper_copper_clearance,
  799. _("TOP: Copper to Copper clearance"))))
  800. if self.copper_b_cb.get_value():
  801. copper_obj = self.copper_b_object.currentText()
  802. if copper_obj is not '':
  803. copper_dict['name'] = deepcopy(copper_obj)
  804. copper_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_obj).apertures)
  805. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  806. args=(copper_dict,
  807. copper_copper_clearance,
  808. _("BOTTOM: Copper to Copper clearance"))))
  809. if self.copper_t_cb.get_value() is False and self.copper_b_cb.get_value() is False:
  810. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  811. _("Copper to Copper clearance"),
  812. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  813. return
  814. # RULE: Check Copper to Outline Clearance
  815. if self.clearance_copper2ol_cb.get_value():
  816. top_dict = dict()
  817. bottom_dict = dict()
  818. outline_dict = dict()
  819. copper_top = self.copper_t_object.currentText()
  820. if copper_top is not '' and self.copper_t_cb.get_value():
  821. top_dict['name'] = deepcopy(copper_top)
  822. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_top).apertures)
  823. copper_bottom = self.copper_b_object.currentText()
  824. if copper_bottom is not '' and self.copper_b_cb.get_value():
  825. bottom_dict['name'] = deepcopy(copper_bottom)
  826. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_bottom).apertures)
  827. copper_outline = self.outline_object.currentText()
  828. if copper_outline is not '' and self.out_cb.get_value():
  829. outline_dict['name'] = deepcopy(copper_outline)
  830. outline_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_outline).apertures)
  831. try:
  832. copper_outline_clearance = float(self.clearance_copper2ol_entry.get_value())
  833. except Exception as e:
  834. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  835. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  836. _("Copper to Outline clearance"),
  837. _("Value is not valid.")))
  838. return
  839. if not top_dict and not bottom_dict or not outline_dict:
  840. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  841. _("Copper to Outline clearance"),
  842. _("One of the copper Gerber objects or the Outline Gerber object is not valid.")))
  843. return
  844. objs = []
  845. if top_dict:
  846. objs.append(top_dict)
  847. if bottom_dict:
  848. objs.append(bottom_dict)
  849. if outline_dict:
  850. objs.append(outline_dict)
  851. else:
  852. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  853. _("Copper to Outline clearance"),
  854. _("Outline Gerber object presence is mandatory for this rule but it is not selected.")))
  855. return
  856. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  857. args=(objs,
  858. copper_outline_clearance,
  859. _("Copper to Outline clearance"))))
  860. # RULE: Check Silk to Silk Clearance
  861. if self.clearance_silk2silk_cb.get_value():
  862. silk_dict = dict()
  863. try:
  864. silk_silk_clearance = float(self.clearance_silk2silk_entry.get_value())
  865. except Exception as e:
  866. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  867. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  868. _("Silk to Silk clearance"),
  869. _("Value is not valid.")))
  870. return
  871. if self.ss_t_cb.get_value():
  872. silk_obj = self.ss_t_object.currentText()
  873. if silk_obj is not '':
  874. silk_dict['name'] = deepcopy(silk_obj)
  875. silk_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_obj).apertures)
  876. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  877. args=(silk_dict,
  878. silk_silk_clearance,
  879. _("TOP: Silk to Silk clearance"))))
  880. if self.ss_b_cb.get_value():
  881. silk_obj = self.ss_b_object.currentText()
  882. if silk_obj is not '':
  883. silk_dict['name'] = deepcopy(silk_obj)
  884. silk_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_obj).apertures)
  885. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  886. args=(silk_dict,
  887. silk_silk_clearance,
  888. _("BOTTOM: Silk to Silk clearance"))))
  889. if self.ss_t_cb.get_value() is False and self.ss_b_cb.get_value() is False:
  890. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  891. _("Silk to Silk clearance"),
  892. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  893. return
  894. # RULE: Check Silk to Solder Mask Clearance
  895. if self.clearance_silk2sm_cb.get_value():
  896. silk_t_dict = dict()
  897. sm_t_dict = dict()
  898. silk_b_dict = dict()
  899. sm_b_dict = dict()
  900. top_ss = False
  901. bottom_ss = False
  902. top_sm = False
  903. bottom_sm = False
  904. silk_top = self.ss_t_object.currentText()
  905. if silk_top is not '' and self.ss_t_cb.get_value():
  906. silk_t_dict['name'] = deepcopy(silk_top)
  907. silk_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_top).apertures)
  908. top_ss = True
  909. silk_bottom = self.ss_b_object.currentText()
  910. if silk_bottom is not '' and self.ss_b_cb.get_value():
  911. silk_b_dict['name'] = deepcopy(silk_bottom)
  912. silk_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_bottom).apertures)
  913. bottom_ss = True
  914. sm_top = self.sm_t_object.currentText()
  915. if sm_top is not '' and self.sm_t_cb.get_value():
  916. sm_t_dict['name'] = deepcopy(sm_top)
  917. sm_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(sm_top).apertures)
  918. top_sm = True
  919. sm_bottom = self.sm_b_object.currentText()
  920. if sm_bottom is not '' and self.sm_b_cb.get_value():
  921. sm_b_dict['name'] = deepcopy(sm_bottom)
  922. sm_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(sm_bottom).apertures)
  923. bottom_sm = True
  924. try:
  925. silk_sm_clearance = float(self.clearance_silk2sm_entry.get_value())
  926. except Exception as e:
  927. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  928. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  929. _("Silk to Solder Mask Clearance"),
  930. _("Value is not valid.")))
  931. return
  932. if (not silk_t_dict and not silk_b_dict) or (not sm_t_dict and not sm_b_dict):
  933. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  934. _("Silk to Solder Mask Clearance"),
  935. _("One or more of the Gerber objects is not valid.")))
  936. return
  937. if top_ss is True and top_sm is True:
  938. objs = [silk_t_dict, sm_t_dict]
  939. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  940. args=(objs,
  941. silk_sm_clearance,
  942. _("TOP: Silk to Solder Mask Clearance"))))
  943. elif bottom_ss is True and bottom_sm is True:
  944. objs = [silk_b_dict, sm_b_dict]
  945. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  946. args=(objs,
  947. silk_sm_clearance,
  948. _("BOTTOM: Silk to Solder Mask Clearance"))))
  949. else:
  950. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  951. _("Silk to Solder Mask Clearance"),
  952. _("Both Silk and Solder Mask Gerber objects has to be either both Top or both Bottom.")))
  953. return
  954. # RULE: Check Silk to Outline Clearance
  955. if self.clearance_silk2ol_cb.get_value():
  956. top_dict = dict()
  957. bottom_dict = dict()
  958. outline_dict = dict()
  959. silk_top = self.ss_t_object.currentText()
  960. if silk_top is not '' and self.ss_t_cb.get_value():
  961. top_dict['name'] = deepcopy(silk_top)
  962. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_top).apertures)
  963. silk_bottom = self.ss_b_object.currentText()
  964. if silk_bottom is not '' and self.ss_b_cb.get_value():
  965. bottom_dict['name'] = deepcopy(silk_bottom)
  966. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_bottom).apertures)
  967. copper_outline = self.outline_object.currentText()
  968. if copper_outline is not '' and self.out_cb.get_value():
  969. outline_dict['name'] = deepcopy(copper_outline)
  970. outline_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_outline).apertures)
  971. try:
  972. copper_outline_clearance = float(self.clearance_copper2ol_entry.get_value())
  973. except Exception as e:
  974. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  975. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  976. _("Silk to Outline Clearance"),
  977. _("Value is not valid.")))
  978. return
  979. if not top_dict and not bottom_dict or not outline_dict:
  980. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  981. _("Silk to Outline Clearance"),
  982. _("One of the Silk Gerber objects or the Outline Gerber object is not valid.")))
  983. return
  984. objs = []
  985. if top_dict:
  986. objs.append(top_dict)
  987. if bottom_dict:
  988. objs.append(bottom_dict)
  989. if outline_dict:
  990. objs.append(outline_dict)
  991. else:
  992. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  993. _("Silk to Outline Clearance"),
  994. _("Outline Gerber object presence is mandatory for this rule but it is not selected.")))
  995. return
  996. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  997. args=(objs,
  998. copper_outline_clearance,
  999. _("Silk to Outline Clearance"))))
  1000. # RULE: Check Minimum Solder Mask Sliver
  1001. if self.clearance_silk2silk_cb.get_value():
  1002. sm_dict = dict()
  1003. try:
  1004. sm_sm_clearance = float(self.clearance_sm2sm_entry.get_value())
  1005. except Exception as e:
  1006. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1007. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1008. _("Minimum Solder Mask Sliver"),
  1009. _("Value is not valid.")))
  1010. return
  1011. if self.sm_t_cb.get_value():
  1012. solder_obj = self.sm_t_object.currentText()
  1013. if solder_obj is not '':
  1014. sm_dict['name'] = deepcopy(solder_obj)
  1015. sm_dict['apertures'] = deepcopy(self.app.collection.get_by_name(solder_obj).apertures)
  1016. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  1017. args=(sm_dict,
  1018. sm_sm_clearance,
  1019. _("TOP: Minimum Solder Mask Sliver"))))
  1020. if self.sm_b_cb.get_value():
  1021. solder_obj = self.sm_b_object.currentText()
  1022. if solder_obj is not '':
  1023. sm_dict['name'] = deepcopy(solder_obj)
  1024. sm_dict['apertures'] = deepcopy(self.app.collection.get_by_name(solder_obj).apertures)
  1025. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  1026. args=(sm_dict,
  1027. sm_sm_clearance,
  1028. _("BOTTOM: Minimum Solder Mask Sliver"))))
  1029. if self.sm_t_cb.get_value() is False and self.sm_b_cb.get_value() is False:
  1030. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1031. _("Minimum Solder Mask Sliver"),
  1032. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  1033. return
  1034. # RULE: Check Minimum Annular Ring
  1035. if self.ring_integrity_cb.get_value():
  1036. top_dict = dict()
  1037. bottom_dict = dict()
  1038. exc_1_dict = dict()
  1039. exc_2_dict = dict()
  1040. copper_top = self.copper_t_object.currentText()
  1041. if copper_top is not '' and self.copper_t_cb.get_value():
  1042. top_dict['name'] = deepcopy(copper_top)
  1043. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_top).apertures)
  1044. copper_bottom = self.copper_b_object.currentText()
  1045. if copper_bottom is not '' and self.copper_b_cb.get_value():
  1046. bottom_dict['name'] = deepcopy(copper_bottom)
  1047. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_bottom).apertures)
  1048. excellon_1 = self.e1_object.currentText()
  1049. if excellon_1 is not '' and self.e1_cb.get_value():
  1050. exc_1_dict['name'] = deepcopy(excellon_1)
  1051. exc_1_dict['tools'] = deepcopy(
  1052. self.app.collection.get_by_name(excellon_1).tools)
  1053. excellon_2 = self.e2_object.currentText()
  1054. if excellon_2 is not '' and self.e2_cb.get_value():
  1055. exc_2_dict['name'] = deepcopy(excellon_2)
  1056. exc_2_dict['tools'] = deepcopy(
  1057. self.app.collection.get_by_name(excellon_2).tools)
  1058. try:
  1059. ring_val = float(self.ring_integrity_entry.get_value())
  1060. except Exception as e:
  1061. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1062. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1063. _("Minimum Annular Ring"),
  1064. _("Value is not valid.")))
  1065. return
  1066. if (not top_dict and not bottom_dict) or (not exc_1_dict and not exc_2_dict):
  1067. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1068. _("Minimum Annular Ring"),
  1069. _("One of the Copper Gerber objects or the Excellon objects is not valid.")))
  1070. return
  1071. objs = []
  1072. if top_dict:
  1073. objs.append(top_dict)
  1074. elif bottom_dict:
  1075. objs.append(bottom_dict)
  1076. if exc_1_dict:
  1077. objs.append(exc_1_dict)
  1078. elif exc_2_dict:
  1079. objs.append(exc_2_dict)
  1080. else:
  1081. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1082. _("Minimum Annular Ring"),
  1083. _("Excellon object presence is mandatory for this rule but none is selected.")))
  1084. return
  1085. self.results.append(self.pool.apply_async(self.check_gerber_annular_ring,
  1086. args=(objs,
  1087. ring_val,
  1088. _("Minimum Annular Ring"))))
  1089. # RULE: Check Hole to Hole Clearance
  1090. if self.clearance_d2d_cb.get_value():
  1091. exc_list = list()
  1092. exc_name_1 = self.e1_object.currentText()
  1093. if exc_name_1 is not '' and self.e1_cb.get_value():
  1094. elem_dict = dict()
  1095. elem_dict['name'] = deepcopy(exc_name_1)
  1096. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_1).tools)
  1097. exc_list.append(elem_dict)
  1098. exc_name_2 = self.e2_object.currentText()
  1099. if exc_name_2 is not '' and self.e2_cb.get_value():
  1100. elem_dict = dict()
  1101. elem_dict['name'] = deepcopy(exc_name_2)
  1102. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_2).tools)
  1103. exc_list.append(elem_dict)
  1104. hole_clearance = float(self.clearance_d2d_entry.get_value())
  1105. self.results.append(self.pool.apply_async(self.check_holes_clearance, args=(exc_list, hole_clearance)))
  1106. # RULE: Check Holes Size
  1107. if self.drill_size_cb.get_value():
  1108. exc_list = list()
  1109. exc_name_1 = self.e1_object.currentText()
  1110. if exc_name_1 is not '' and self.e1_cb.get_value():
  1111. elem_dict = dict()
  1112. elem_dict['name'] = deepcopy(exc_name_1)
  1113. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_1).tools)
  1114. exc_list.append(elem_dict)
  1115. exc_name_2 = self.e2_object.currentText()
  1116. if exc_name_2 is not '' and self.e2_cb.get_value():
  1117. elem_dict = dict()
  1118. elem_dict['name'] = deepcopy(exc_name_2)
  1119. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_2).tools)
  1120. exc_list.append(elem_dict)
  1121. drill_size = float(self.drill_size_entry.get_value())
  1122. self.results.append(self.pool.apply_async(self.check_holes_size, args=(exc_list, drill_size)))
  1123. output = list()
  1124. for p in self.results:
  1125. output.append(p.get())
  1126. self.tool_finished.emit(output)
  1127. log.debug("RuleCheck() finished")
  1128. self.app.worker_task.emit({'fcn': worker_job, 'params': [self.app]})
  1129. def on_tool_finished(self, res):
  1130. print(res)
  1131. def reset_fields(self):
  1132. # self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1133. # self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1134. pass