ToolRulesCheck.py 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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. total_geo_grb_1 = MultiPolygon(total_geo_grb_1)
  534. total_geo_grb_1 = total_geo_grb_1.buffer(0)
  535. total_geo_grb_3 = MultiPolygon(total_geo_grb_3)
  536. total_geo_grb_3 = total_geo_grb_3.buffer(0)
  537. iterations = len(total_geo_grb_1) * len(total_geo_grb_3)
  538. log.debug("RulesCheck.check_gerber_clearance(). Iterations: %s" % str(iterations))
  539. min_dict = dict()
  540. for geo in total_geo_grb_1:
  541. for s_geo in total_geo_grb_3:
  542. # minimize the number of distances by not taking into considerations those that are too small
  543. dist = geo.distance(s_geo)
  544. if float(dist) < float(size):
  545. loc_1, loc_2 = nearest_points(geo, s_geo)
  546. dx = loc_1.x - loc_2.x
  547. dy = loc_1.y - loc_2.y
  548. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  549. if dist in min_dict:
  550. min_dict[dist].append(loc)
  551. else:
  552. min_dict[dist] = [loc]
  553. points_list = list()
  554. for dist in min_dict.keys():
  555. for location in min_dict[dist]:
  556. points_list.append(location)
  557. name_list = list()
  558. if gerber_1:
  559. name_list.append(gerber_1['name'])
  560. if gerber_2:
  561. name_list.append(gerber_2['name'])
  562. if gerber_3:
  563. name_list.append(gerber_3['name'])
  564. obj_violations['name'] = name_list
  565. obj_violations['points'] = points_list
  566. violations.append(deepcopy(obj_violations))
  567. return rule_title, violations
  568. @staticmethod
  569. def check_holes_size(elements, size):
  570. rule = _("Hole Size")
  571. violations = list()
  572. obj_violations = dict()
  573. obj_violations.update({
  574. 'name': '',
  575. 'dia': list()
  576. })
  577. for elem in elements:
  578. dia_list = []
  579. name = elem['name']
  580. for tool in elem['tools']:
  581. tool_dia = float(elem['tools'][tool]['C'])
  582. if tool_dia < float(size):
  583. dia_list.append(tool_dia)
  584. obj_violations['name'] = name
  585. obj_violations['dia'] = dia_list
  586. violations.append(deepcopy(obj_violations))
  587. return rule, violations
  588. @staticmethod
  589. def check_holes_clearance(elements, size):
  590. rule = _("Hole to Hole Clearance")
  591. violations = list()
  592. obj_violations = dict()
  593. obj_violations.update({
  594. 'name': '',
  595. 'points': list()
  596. })
  597. total_geo = list()
  598. for elem in elements:
  599. for tool in elem['tools']:
  600. if 'solid_geometry' in elem['tools'][tool]:
  601. geometry = elem['tools'][tool]['solid_geometry']
  602. for geo in geometry:
  603. total_geo.append(geo)
  604. min_dict = dict()
  605. idx = 1
  606. for geo in total_geo:
  607. for s_geo in total_geo[idx:]:
  608. # minimize the number of distances by not taking into considerations those that are too small
  609. dist = geo.distance(s_geo)
  610. loc_1, loc_2 = nearest_points(geo, s_geo)
  611. dx = loc_1.x - loc_2.x
  612. dy = loc_1.y - loc_2.y
  613. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  614. if dist in min_dict:
  615. min_dict[dist].append(loc)
  616. else:
  617. min_dict[dist] = [loc]
  618. idx += 1
  619. points_list = list()
  620. for dist in min_dict.keys():
  621. if float(dist) < size:
  622. for location in min_dict[dist]:
  623. points_list.append(location)
  624. name_list = list()
  625. for elem in elements:
  626. name_list.append(elem['name'])
  627. obj_violations['name'] = name_list
  628. obj_violations['points'] = points_list
  629. violations.append(deepcopy(obj_violations))
  630. return rule, violations
  631. @staticmethod
  632. def check_traces_size(elements, size):
  633. rule = _("Trace Size")
  634. violations = list()
  635. obj_violations = dict()
  636. obj_violations.update({
  637. 'name': '',
  638. 'size': list(),
  639. 'points': list()
  640. })
  641. for elem in elements:
  642. dia_list = []
  643. points_list = []
  644. name = elem['name']
  645. for apid in elem['apertures']:
  646. tool_dia = float(elem['apertures'][apid]['size'])
  647. if tool_dia < float(size):
  648. dia_list.append(tool_dia)
  649. for geo_el in elem['apertures'][apid]['geometry']:
  650. if 'solid' in geo_el.keys():
  651. geo = geo_el['solid']
  652. pt = geo.representative_point()
  653. points_list.append((pt.x, pt.y))
  654. obj_violations['name'] = name
  655. obj_violations['size'] = dia_list
  656. obj_violations['points'] = points_list
  657. violations.append(deepcopy(obj_violations))
  658. return rule, violations
  659. @staticmethod
  660. def check_gerber_annular_ring(obj_list, size, rule):
  661. rule_title = rule
  662. violations = list()
  663. obj_violations = dict()
  664. obj_violations.update({
  665. 'name': '',
  666. 'points': list()
  667. })
  668. # added it so I won't have errors of using before declaring
  669. gerber_obj = dict()
  670. gerber_extra_obj = dict()
  671. exc_obj = dict()
  672. exc_extra_obj = dict()
  673. if len(obj_list) == 2:
  674. gerber_obj = obj_list[0]
  675. exc_obj = obj_list[1]
  676. if 'apertures' in gerber_obj and 'tools' in exc_obj:
  677. pass
  678. else:
  679. return 'Fail. At least one Gerber and one Excellon object is required to check Minimum Annular Ring'
  680. elif len(obj_list) == 3:
  681. o1 = obj_list[0]
  682. o2 = obj_list[1]
  683. o3 = obj_list[2]
  684. if 'apertures' in o1 and 'apertures' in o2:
  685. gerber_obj = o1
  686. gerber_extra_obj = o2
  687. exc_obj = o3
  688. elif 'tools' in o2 and 'tools' in o3:
  689. gerber_obj = o1
  690. exc_obj = o2
  691. exc_extra_obj = o3
  692. elif len(obj_list) == 4:
  693. gerber_obj = obj_list[0]
  694. gerber_extra_obj = obj_list[1]
  695. exc_obj = obj_list[2]
  696. exc_extra_obj = obj_list[3]
  697. else:
  698. return 'Fail. Not enough objects to check Minimum Annular Ring'
  699. total_geo_grb = list()
  700. for apid in gerber_obj['apertures']:
  701. if 'geometry' in gerber_obj['apertures'][apid]:
  702. geometry = gerber_obj['apertures'][apid]['geometry']
  703. for geo_el in geometry:
  704. if 'solid' in geo_el and geo_el['solid'] is not None:
  705. total_geo_grb.append(geo_el['solid'])
  706. if len(obj_list) == 3 and gerber_extra_obj:
  707. # add the second Gerber geometry to the first one if it exists
  708. for apid in gerber_extra_obj['apertures']:
  709. if 'geometry' in gerber_extra_obj['apertures'][apid]:
  710. geometry = gerber_extra_obj['apertures'][apid]['geometry']
  711. for geo_el in geometry:
  712. if 'solid' in geo_el and geo_el['solid'] is not None:
  713. total_geo_grb.append(geo_el['solid'])
  714. total_geo_grb = MultiPolygon(total_geo_grb)
  715. total_geo_grb = total_geo_grb.buffer(0)
  716. total_geo_exc = list()
  717. for tool in exc_obj['tools']:
  718. if 'solid_geometry' in exc_obj['tools'][tool]:
  719. geometry = exc_obj['tools'][tool]['solid_geometry']
  720. for geo in geometry:
  721. total_geo_exc.append(geo)
  722. if len(obj_list) == 3 and exc_extra_obj:
  723. # add the second Excellon geometry to the first one if it exists
  724. for tool in exc_extra_obj['tools']:
  725. if 'solid_geometry' in exc_extra_obj['tools'][tool]:
  726. geometry = exc_extra_obj['tools'][tool]['solid_geometry']
  727. for geo in geometry:
  728. total_geo_exc.append(geo)
  729. iterations = len(total_geo_grb) * len(total_geo_exc)
  730. log.debug("RulesCheck.check_gerber_annular_ring(). Iterations: %s" % str(iterations))
  731. min_dict = dict()
  732. for geo in total_geo_grb:
  733. for s_geo in total_geo_exc:
  734. # minimize the number of distances by not taking into considerations those that are too small
  735. dist = geo.exterior.distance(s_geo)
  736. if float(dist) < float(size):
  737. loc_1, loc_2 = nearest_points(geo.exterior, s_geo)
  738. dx = loc_1.x - loc_2.x
  739. dy = loc_1.y - loc_2.y
  740. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  741. if dist in min_dict:
  742. min_dict[dist].append(loc)
  743. else:
  744. min_dict[dist] = [loc]
  745. points_list = list()
  746. for dist in min_dict.keys():
  747. for location in min_dict[dist]:
  748. points_list.append(location)
  749. name_list = list()
  750. if gerber_obj:
  751. name_list.append(gerber_obj['name'])
  752. if gerber_extra_obj:
  753. name_list.append(gerber_obj['name'])
  754. if exc_obj:
  755. name_list.append(gerber_obj['name'])
  756. if exc_extra_obj:
  757. name_list.append(gerber_obj['name'])
  758. obj_violations['name'] = name_list
  759. obj_violations['points'] = points_list
  760. violations.append(deepcopy(obj_violations))
  761. return rule_title, violations
  762. def execute(self):
  763. self.results = list()
  764. log.debug("RuleCheck() executing")
  765. def worker_job(app_obj):
  766. proc = self.app.proc_container.new(_("Working..."))
  767. # RULE: Check Trace Size
  768. if self.trace_size_cb.get_value():
  769. copper_list = list()
  770. copper_name_1 = self.copper_t_object.currentText()
  771. if copper_name_1 is not '' and self.copper_t_cb.get_value():
  772. elem_dict = dict()
  773. elem_dict['name'] = deepcopy(copper_name_1)
  774. elem_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_name_1).apertures)
  775. copper_list.append(elem_dict)
  776. copper_name_2 = self.copper_b_object.currentText()
  777. if copper_name_2 is not '' and self.copper_b_cb.get_value():
  778. elem_dict = dict()
  779. elem_dict['name'] = deepcopy(copper_name_2)
  780. elem_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_name_2).apertures)
  781. copper_list.append(elem_dict)
  782. trace_size = float(self.trace_size_entry.get_value())
  783. self.results.append(self.pool.apply_async(self.check_traces_size, args=(copper_list, trace_size)))
  784. # RULE: Check Copper to Copper Clearance
  785. if self.clearance_copper2copper_cb.get_value():
  786. copper_dict = dict()
  787. try:
  788. copper_copper_clearance = float(self.clearance_copper2copper_entry.get_value())
  789. except Exception as e:
  790. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  791. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  792. _("Copper to Copper clearance"),
  793. _("Value is not valid.")))
  794. return
  795. if self.copper_t_cb.get_value():
  796. copper_obj = self.copper_t_object.currentText()
  797. if copper_obj is not '':
  798. copper_dict['name'] = deepcopy(copper_obj)
  799. copper_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_obj).apertures)
  800. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  801. args=(copper_dict,
  802. copper_copper_clearance,
  803. _("TOP: Copper to Copper clearance"))))
  804. if self.copper_b_cb.get_value():
  805. copper_obj = self.copper_b_object.currentText()
  806. if copper_obj is not '':
  807. copper_dict['name'] = deepcopy(copper_obj)
  808. copper_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_obj).apertures)
  809. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  810. args=(copper_dict,
  811. copper_copper_clearance,
  812. _("BOTTOM: Copper to Copper clearance"))))
  813. if self.copper_t_cb.get_value() is False and self.copper_b_cb.get_value() is False:
  814. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  815. _("Copper to Copper clearance"),
  816. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  817. return
  818. # RULE: Check Copper to Outline Clearance
  819. if self.clearance_copper2ol_cb.get_value():
  820. top_dict = dict()
  821. bottom_dict = dict()
  822. outline_dict = dict()
  823. copper_top = self.copper_t_object.currentText()
  824. if copper_top is not '' and self.copper_t_cb.get_value():
  825. top_dict['name'] = deepcopy(copper_top)
  826. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_top).apertures)
  827. copper_bottom = self.copper_b_object.currentText()
  828. if copper_bottom is not '' and self.copper_b_cb.get_value():
  829. bottom_dict['name'] = deepcopy(copper_bottom)
  830. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_bottom).apertures)
  831. copper_outline = self.outline_object.currentText()
  832. if copper_outline is not '' and self.out_cb.get_value():
  833. outline_dict['name'] = deepcopy(copper_outline)
  834. outline_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_outline).apertures)
  835. try:
  836. copper_outline_clearance = float(self.clearance_copper2ol_entry.get_value())
  837. except Exception as e:
  838. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  839. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  840. _("Copper to Outline clearance"),
  841. _("Value is not valid.")))
  842. return
  843. if not top_dict and not bottom_dict or not outline_dict:
  844. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  845. _("Copper to Outline clearance"),
  846. _("One of the copper Gerber objects or the Outline Gerber object is not valid.")))
  847. return
  848. objs = []
  849. if top_dict:
  850. objs.append(top_dict)
  851. if bottom_dict:
  852. objs.append(bottom_dict)
  853. if outline_dict:
  854. objs.append(outline_dict)
  855. else:
  856. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  857. _("Copper to Outline clearance"),
  858. _("Outline Gerber object presence is mandatory for this rule but it is not selected.")))
  859. return
  860. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  861. args=(objs,
  862. copper_outline_clearance,
  863. _("Copper to Outline clearance"))))
  864. # RULE: Check Silk to Silk Clearance
  865. if self.clearance_silk2silk_cb.get_value():
  866. silk_dict = dict()
  867. try:
  868. silk_silk_clearance = float(self.clearance_silk2silk_entry.get_value())
  869. except Exception as e:
  870. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  871. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  872. _("Silk to Silk clearance"),
  873. _("Value is not valid.")))
  874. return
  875. if self.ss_t_cb.get_value():
  876. silk_obj = self.ss_t_object.currentText()
  877. if silk_obj is not '':
  878. silk_dict['name'] = deepcopy(silk_obj)
  879. silk_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_obj).apertures)
  880. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  881. args=(silk_dict,
  882. silk_silk_clearance,
  883. _("TOP: Silk to Silk clearance"))))
  884. if self.ss_b_cb.get_value():
  885. silk_obj = self.ss_b_object.currentText()
  886. if silk_obj is not '':
  887. silk_dict['name'] = deepcopy(silk_obj)
  888. silk_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_obj).apertures)
  889. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  890. args=(silk_dict,
  891. silk_silk_clearance,
  892. _("BOTTOM: Silk to Silk clearance"))))
  893. if self.ss_t_cb.get_value() is False and self.ss_b_cb.get_value() is False:
  894. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  895. _("Silk to Silk clearance"),
  896. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  897. return
  898. # RULE: Check Silk to Solder Mask Clearance
  899. if self.clearance_silk2sm_cb.get_value():
  900. silk_t_dict = dict()
  901. sm_t_dict = dict()
  902. silk_b_dict = dict()
  903. sm_b_dict = dict()
  904. top_ss = False
  905. bottom_ss = False
  906. top_sm = False
  907. bottom_sm = False
  908. silk_top = self.ss_t_object.currentText()
  909. if silk_top is not '' and self.ss_t_cb.get_value():
  910. silk_t_dict['name'] = deepcopy(silk_top)
  911. silk_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_top).apertures)
  912. top_ss = True
  913. silk_bottom = self.ss_b_object.currentText()
  914. if silk_bottom is not '' and self.ss_b_cb.get_value():
  915. silk_b_dict['name'] = deepcopy(silk_bottom)
  916. silk_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_bottom).apertures)
  917. bottom_ss = True
  918. sm_top = self.sm_t_object.currentText()
  919. if sm_top is not '' and self.sm_t_cb.get_value():
  920. sm_t_dict['name'] = deepcopy(sm_top)
  921. sm_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(sm_top).apertures)
  922. top_sm = True
  923. sm_bottom = self.sm_b_object.currentText()
  924. if sm_bottom is not '' and self.sm_b_cb.get_value():
  925. sm_b_dict['name'] = deepcopy(sm_bottom)
  926. sm_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(sm_bottom).apertures)
  927. bottom_sm = True
  928. try:
  929. silk_sm_clearance = float(self.clearance_silk2sm_entry.get_value())
  930. except Exception as e:
  931. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  932. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  933. _("Silk to Solder Mask Clearance"),
  934. _("Value is not valid.")))
  935. return
  936. if (not silk_t_dict and not silk_b_dict) or (not sm_t_dict and not sm_b_dict):
  937. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  938. _("Silk to Solder Mask Clearance"),
  939. _("One or more of the Gerber objects is not valid.")))
  940. return
  941. if top_ss is True and top_sm is True:
  942. objs = [silk_t_dict, sm_t_dict]
  943. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  944. args=(objs,
  945. silk_sm_clearance,
  946. _("TOP: Silk to Solder Mask Clearance"))))
  947. elif bottom_ss is True and bottom_sm is True:
  948. objs = [silk_b_dict, sm_b_dict]
  949. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  950. args=(objs,
  951. silk_sm_clearance,
  952. _("BOTTOM: Silk to Solder Mask Clearance"))))
  953. else:
  954. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  955. _("Silk to Solder Mask Clearance"),
  956. _("Both Silk and Solder Mask Gerber objects has to be either both Top or both Bottom.")))
  957. return
  958. # RULE: Check Silk to Outline Clearance
  959. if self.clearance_silk2ol_cb.get_value():
  960. top_dict = dict()
  961. bottom_dict = dict()
  962. outline_dict = dict()
  963. silk_top = self.ss_t_object.currentText()
  964. if silk_top is not '' and self.ss_t_cb.get_value():
  965. top_dict['name'] = deepcopy(silk_top)
  966. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_top).apertures)
  967. silk_bottom = self.ss_b_object.currentText()
  968. if silk_bottom is not '' and self.ss_b_cb.get_value():
  969. bottom_dict['name'] = deepcopy(silk_bottom)
  970. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_bottom).apertures)
  971. copper_outline = self.outline_object.currentText()
  972. if copper_outline is not '' and self.out_cb.get_value():
  973. outline_dict['name'] = deepcopy(copper_outline)
  974. outline_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_outline).apertures)
  975. try:
  976. copper_outline_clearance = float(self.clearance_copper2ol_entry.get_value())
  977. except Exception as e:
  978. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  979. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  980. _("Silk to Outline Clearance"),
  981. _("Value is not valid.")))
  982. return
  983. if not top_dict and not bottom_dict or not outline_dict:
  984. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  985. _("Silk to Outline Clearance"),
  986. _("One of the Silk Gerber objects or the Outline Gerber object is not valid.")))
  987. return
  988. objs = []
  989. if top_dict:
  990. objs.append(top_dict)
  991. if bottom_dict:
  992. objs.append(bottom_dict)
  993. if outline_dict:
  994. objs.append(outline_dict)
  995. else:
  996. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  997. _("Silk to Outline Clearance"),
  998. _("Outline Gerber object presence is mandatory for this rule but it is not selected.")))
  999. return
  1000. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  1001. args=(objs,
  1002. copper_outline_clearance,
  1003. _("Silk to Outline Clearance"))))
  1004. # RULE: Check Minimum Solder Mask Sliver
  1005. if self.clearance_silk2silk_cb.get_value():
  1006. sm_dict = dict()
  1007. try:
  1008. sm_sm_clearance = float(self.clearance_sm2sm_entry.get_value())
  1009. except Exception as e:
  1010. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1011. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1012. _("Minimum Solder Mask Sliver"),
  1013. _("Value is not valid.")))
  1014. return
  1015. if self.sm_t_cb.get_value():
  1016. solder_obj = self.sm_t_object.currentText()
  1017. if solder_obj is not '':
  1018. sm_dict['name'] = deepcopy(solder_obj)
  1019. sm_dict['apertures'] = deepcopy(self.app.collection.get_by_name(solder_obj).apertures)
  1020. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  1021. args=(sm_dict,
  1022. sm_sm_clearance,
  1023. _("TOP: Minimum Solder Mask Sliver"))))
  1024. if self.sm_b_cb.get_value():
  1025. solder_obj = self.sm_b_object.currentText()
  1026. if solder_obj is not '':
  1027. sm_dict['name'] = deepcopy(solder_obj)
  1028. sm_dict['apertures'] = deepcopy(self.app.collection.get_by_name(solder_obj).apertures)
  1029. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  1030. args=(sm_dict,
  1031. sm_sm_clearance,
  1032. _("BOTTOM: Minimum Solder Mask Sliver"))))
  1033. if self.sm_t_cb.get_value() is False and self.sm_b_cb.get_value() is False:
  1034. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1035. _("Minimum Solder Mask Sliver"),
  1036. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  1037. return
  1038. # RULE: Check Minimum Annular Ring
  1039. if self.ring_integrity_cb.get_value():
  1040. top_dict = dict()
  1041. bottom_dict = dict()
  1042. exc_1_dict = dict()
  1043. exc_2_dict = dict()
  1044. copper_top = self.copper_t_object.currentText()
  1045. if copper_top is not '' and self.copper_t_cb.get_value():
  1046. top_dict['name'] = deepcopy(copper_top)
  1047. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_top).apertures)
  1048. copper_bottom = self.copper_b_object.currentText()
  1049. if copper_bottom is not '' and self.copper_b_cb.get_value():
  1050. bottom_dict['name'] = deepcopy(copper_bottom)
  1051. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_bottom).apertures)
  1052. excellon_1 = self.e1_object.currentText()
  1053. if excellon_1 is not '' and self.e1_cb.get_value():
  1054. exc_1_dict['name'] = deepcopy(excellon_1)
  1055. exc_1_dict['tools'] = deepcopy(
  1056. self.app.collection.get_by_name(excellon_1).tools)
  1057. excellon_2 = self.e2_object.currentText()
  1058. if excellon_2 is not '' and self.e2_cb.get_value():
  1059. exc_2_dict['name'] = deepcopy(excellon_2)
  1060. exc_2_dict['tools'] = deepcopy(
  1061. self.app.collection.get_by_name(excellon_2).tools)
  1062. try:
  1063. ring_val = float(self.ring_integrity_entry.get_value())
  1064. except Exception as e:
  1065. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1066. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1067. _("Minimum Annular Ring"),
  1068. _("Value is not valid.")))
  1069. return
  1070. if (not top_dict and not bottom_dict) or (not exc_1_dict and not exc_2_dict):
  1071. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1072. _("Minimum Annular Ring"),
  1073. _("One of the Copper Gerber objects or the Excellon objects is not valid.")))
  1074. return
  1075. objs = []
  1076. if top_dict:
  1077. objs.append(top_dict)
  1078. elif bottom_dict:
  1079. objs.append(bottom_dict)
  1080. if exc_1_dict:
  1081. objs.append(exc_1_dict)
  1082. elif exc_2_dict:
  1083. objs.append(exc_2_dict)
  1084. else:
  1085. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1086. _("Minimum Annular Ring"),
  1087. _("Excellon object presence is mandatory for this rule but none is selected.")))
  1088. return
  1089. self.results.append(self.pool.apply_async(self.check_gerber_annular_ring,
  1090. args=(objs,
  1091. ring_val,
  1092. _("Minimum Annular Ring"))))
  1093. # RULE: Check Hole to Hole Clearance
  1094. if self.clearance_d2d_cb.get_value():
  1095. exc_list = list()
  1096. exc_name_1 = self.e1_object.currentText()
  1097. if exc_name_1 is not '' and self.e1_cb.get_value():
  1098. elem_dict = dict()
  1099. elem_dict['name'] = deepcopy(exc_name_1)
  1100. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_1).tools)
  1101. exc_list.append(elem_dict)
  1102. exc_name_2 = self.e2_object.currentText()
  1103. if exc_name_2 is not '' and self.e2_cb.get_value():
  1104. elem_dict = dict()
  1105. elem_dict['name'] = deepcopy(exc_name_2)
  1106. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_2).tools)
  1107. exc_list.append(elem_dict)
  1108. hole_clearance = float(self.clearance_d2d_entry.get_value())
  1109. self.results.append(self.pool.apply_async(self.check_holes_clearance, args=(exc_list, hole_clearance)))
  1110. # RULE: Check Holes Size
  1111. if self.drill_size_cb.get_value():
  1112. exc_list = list()
  1113. exc_name_1 = self.e1_object.currentText()
  1114. if exc_name_1 is not '' and self.e1_cb.get_value():
  1115. elem_dict = dict()
  1116. elem_dict['name'] = deepcopy(exc_name_1)
  1117. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_1).tools)
  1118. exc_list.append(elem_dict)
  1119. exc_name_2 = self.e2_object.currentText()
  1120. if exc_name_2 is not '' and self.e2_cb.get_value():
  1121. elem_dict = dict()
  1122. elem_dict['name'] = deepcopy(exc_name_2)
  1123. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_2).tools)
  1124. exc_list.append(elem_dict)
  1125. drill_size = float(self.drill_size_entry.get_value())
  1126. self.results.append(self.pool.apply_async(self.check_holes_size, args=(exc_list, drill_size)))
  1127. output = list()
  1128. for p in self.results:
  1129. output.append(p.get())
  1130. self.tool_finished.emit(output)
  1131. log.debug("RuleCheck() finished")
  1132. self.app.worker_task.emit({'fcn': worker_job, 'params': [self.app]})
  1133. def on_tool_finished(self, res):
  1134. print(res)
  1135. def reset_fields(self):
  1136. # self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1137. # self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1138. pass