ToolRulesCheck.py 57 KB

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