ToolRulesCheck.py 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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 objects 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 Top Gerber Copper object 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 Bottom Gerber Copper object 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 Top Gerber Solder Mask object 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 Bottom Gerber Solder Mask object 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 Top Gerber Silkscreen object 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 Bottom Gerber Silkscreen object 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) object 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 Objects"))
  141. self.excellon_title_lbl.setToolTip(
  142. _("Excellon objects 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. _("Excellon object for which to check rules.\n"
  152. "Holds the plated holes or a general Excellon file content.")
  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. _("Excellon object for which to check rules.\n"
  163. "Holds the non-plated holes.")
  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. self.decimals = 4
  390. # def on_object_loaded(self, index, row):
  391. # print(index.internalPointer().child_items[row].obj.options['name'], index.data())
  392. def on_all_cb_changed(self, state):
  393. cb_items = [self.form_layout_1.itemAt(i).widget() for i in range(self.form_layout_1.count())
  394. if isinstance(self.form_layout_1.itemAt(i).widget(), FCCheckBox)]
  395. for cb in cb_items:
  396. if state:
  397. cb.setChecked(True)
  398. else:
  399. cb.setChecked(False)
  400. def on_all_objects_cb_changed(self, state):
  401. cb_items = [self.grid_layout.itemAt(i).widget() for i in range(self.grid_layout.count())
  402. if isinstance(self.grid_layout.itemAt(i).widget(), FCCheckBox)]
  403. for cb in cb_items:
  404. if state:
  405. cb.setChecked(True)
  406. else:
  407. cb.setChecked(False)
  408. def run(self, toggle=True):
  409. self.app.report_usage("ToolRulesCheck()")
  410. if toggle:
  411. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  412. if self.app.ui.splitter.sizes()[0] == 0:
  413. self.app.ui.splitter.setSizes([1, 1])
  414. else:
  415. try:
  416. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  417. # if tab is populated with the tool but it does not have the focus, focus on it
  418. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  419. # focus on Tool Tab
  420. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  421. else:
  422. self.app.ui.splitter.setSizes([0, 1])
  423. except AttributeError:
  424. pass
  425. else:
  426. if self.app.ui.splitter.sizes()[0] == 0:
  427. self.app.ui.splitter.setSizes([1, 1])
  428. FlatCAMTool.run(self)
  429. self.set_tool_ui()
  430. self.app.ui.notebook.setTabText(2, _("Rules Tool"))
  431. def install(self, icon=None, separator=None, **kwargs):
  432. FlatCAMTool.install(self, icon, separator, shortcut='ALT+R', **kwargs)
  433. def set_tool_ui(self):
  434. # all object combobox default as disabled
  435. self.copper_t_object.setDisabled(True)
  436. self.copper_b_object.setDisabled(True)
  437. self.sm_t_object.setDisabled(True)
  438. self.sm_b_object.setDisabled(True)
  439. self.ss_t_object.setDisabled(True)
  440. self.ss_b_object.setDisabled(True)
  441. self.outline_object.setDisabled(True)
  442. self.e1_object.setDisabled(True)
  443. self.e2_object.setDisabled(True)
  444. self.reset_fields()
  445. @staticmethod
  446. def check_inside_gerber_clearance(gerber_obj, size, rule):
  447. rule_title = rule
  448. violations = list()
  449. obj_violations = dict()
  450. obj_violations.update({
  451. 'name': '',
  452. 'points': list()
  453. })
  454. if not gerber_obj:
  455. return 'Fail. Not enough Gerber objects to check Gerber 2 Gerber clearance'
  456. obj_violations['name'] = gerber_obj['name']
  457. solid_geo = list()
  458. clear_geo = list()
  459. for apid in gerber_obj['apertures']:
  460. if 'geometry' in gerber_obj['apertures'][apid]:
  461. geometry = gerber_obj['apertures'][apid]['geometry']
  462. for geo_el in geometry:
  463. if 'solid' in geo_el and geo_el['solid'] is not None:
  464. solid_geo.append(geo_el['solid'])
  465. if 'clear' in geo_el and geo_el['clear'] is not None:
  466. clear_geo.append(geo_el['clear'])
  467. if clear_geo:
  468. total_geo = list()
  469. for geo_c in clear_geo:
  470. for geo_s in solid_geo:
  471. if geo_c.within(geo_s):
  472. total_geo.append(geo_s.difference(geo_c))
  473. else:
  474. total_geo = MultiPolygon(solid_geo)
  475. total_geo = total_geo.buffer(0.000001)
  476. if isinstance(total_geo, Polygon):
  477. iterations = 1
  478. obj_violations['points'] =['Failed. Only one polygon.']
  479. return rule_title, [obj_violations]
  480. else:
  481. iterations = len(total_geo)
  482. iterations = (iterations * (iterations - 1)) / 2
  483. log.debug("RulesCheck.check_gerber_clearance(). Iterations: %s" % str(iterations))
  484. min_dict = dict()
  485. idx = 1
  486. for geo in total_geo:
  487. for s_geo in total_geo[idx:]:
  488. # minimize the number of distances by not taking into considerations those that are too small
  489. dist = geo.distance(s_geo)
  490. if float(dist) < float(size):
  491. loc_1, loc_2 = nearest_points(geo, s_geo)
  492. dx = loc_1.x - loc_2.x
  493. dy = loc_1.y - loc_2.y
  494. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  495. if dist in min_dict:
  496. min_dict[dist].append(loc)
  497. else:
  498. min_dict[dist] = [loc]
  499. idx += 1
  500. points_list = set()
  501. for dist in min_dict.keys():
  502. for location in min_dict[dist]:
  503. points_list.add(location)
  504. obj_violations['points'] = list(points_list)
  505. violations.append(deepcopy(obj_violations))
  506. return rule_title, violations
  507. @staticmethod
  508. def check_gerber_clearance(gerber_list, size, rule):
  509. rule_title = rule
  510. violations = list()
  511. obj_violations = dict()
  512. obj_violations.update({
  513. 'name': '',
  514. 'points': list()
  515. })
  516. if len(gerber_list) == 2:
  517. gerber_1 = gerber_list[0]
  518. # added it so I won't have errors of using before declaring
  519. gerber_2 = dict()
  520. gerber_3 = gerber_list[1]
  521. elif len(gerber_list) == 3:
  522. gerber_1 = gerber_list[0]
  523. gerber_2 = gerber_list[1]
  524. gerber_3 = gerber_list[2]
  525. else:
  526. return 'Fail. Not enough Gerber objects to check Gerber 2 Gerber clearance'
  527. total_geo_grb_1 = list()
  528. for apid in gerber_1['apertures']:
  529. if 'geometry' in gerber_1['apertures'][apid]:
  530. geometry = gerber_1['apertures'][apid]['geometry']
  531. for geo_el in geometry:
  532. if 'solid' in geo_el and geo_el['solid'] is not None:
  533. total_geo_grb_1.append(geo_el['solid'])
  534. if len(gerber_list) == 3:
  535. # add the second Gerber geometry to the first one if it exists
  536. for apid in gerber_2['apertures']:
  537. if 'geometry' in gerber_2['apertures'][apid]:
  538. geometry = gerber_2['apertures'][apid]['geometry']
  539. for geo_el in geometry:
  540. if 'solid' in geo_el and geo_el['solid'] is not None:
  541. total_geo_grb_1.append(geo_el['solid'])
  542. total_geo_grb_3 = list()
  543. for apid in gerber_3['apertures']:
  544. if 'geometry' in gerber_3['apertures'][apid]:
  545. geometry = gerber_3['apertures'][apid]['geometry']
  546. for geo_el in geometry:
  547. if 'solid' in geo_el and geo_el['solid'] is not None:
  548. total_geo_grb_3.append(geo_el['solid'])
  549. total_geo_grb_1 = MultiPolygon(total_geo_grb_1)
  550. total_geo_grb_1 = total_geo_grb_1.buffer(0)
  551. total_geo_grb_3 = MultiPolygon(total_geo_grb_3)
  552. total_geo_grb_3 = total_geo_grb_3.buffer(0)
  553. if isinstance(total_geo_grb_1, Polygon):
  554. len_1 = 1
  555. else:
  556. len_1 = len(total_geo_grb_1)
  557. if isinstance(total_geo_grb_3, Polygon):
  558. len_3 = 1
  559. else:
  560. len_3 = len(total_geo_grb_3)
  561. iterations = len_1 * len_3
  562. log.debug("RulesCheck.check_gerber_clearance(). Iterations: %s" % str(iterations))
  563. min_dict = dict()
  564. for geo in total_geo_grb_1:
  565. for s_geo in total_geo_grb_3:
  566. # minimize the number of distances by not taking into considerations those that are too small
  567. dist = geo.distance(s_geo)
  568. if float(dist) < float(size):
  569. loc_1, loc_2 = nearest_points(geo, s_geo)
  570. dx = loc_1.x - loc_2.x
  571. dy = loc_1.y - loc_2.y
  572. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  573. if dist in min_dict:
  574. min_dict[dist].append(loc)
  575. else:
  576. min_dict[dist] = [loc]
  577. points_list = set()
  578. for dist in min_dict.keys():
  579. for location in min_dict[dist]:
  580. points_list.add(location)
  581. name_list = list()
  582. if gerber_1:
  583. name_list.append(gerber_1['name'])
  584. if gerber_2:
  585. name_list.append(gerber_2['name'])
  586. if gerber_3:
  587. name_list.append(gerber_3['name'])
  588. obj_violations['name'] = name_list
  589. obj_violations['points'] = list(points_list)
  590. violations.append(deepcopy(obj_violations))
  591. return rule_title, violations
  592. @staticmethod
  593. def check_holes_size(elements, size):
  594. rule = _("Hole Size")
  595. violations = list()
  596. obj_violations = dict()
  597. obj_violations.update({
  598. 'name': '',
  599. 'dia': list()
  600. })
  601. for elem in elements:
  602. dia_list = []
  603. name = elem['name']
  604. for tool in elem['tools']:
  605. tool_dia = float(elem['tools'][tool]['C'])
  606. if tool_dia < float(size):
  607. dia_list.append(tool_dia)
  608. obj_violations['name'] = name
  609. obj_violations['dia'] = dia_list
  610. violations.append(deepcopy(obj_violations))
  611. return rule, violations
  612. @staticmethod
  613. def check_holes_clearance(elements, size):
  614. rule = _("Hole to Hole Clearance")
  615. violations = list()
  616. obj_violations = dict()
  617. obj_violations.update({
  618. 'name': '',
  619. 'points': list()
  620. })
  621. total_geo = list()
  622. for elem in elements:
  623. for tool in elem['tools']:
  624. if 'solid_geometry' in elem['tools'][tool]:
  625. geometry = elem['tools'][tool]['solid_geometry']
  626. for geo in geometry:
  627. total_geo.append(geo)
  628. min_dict = dict()
  629. idx = 1
  630. for geo in total_geo:
  631. for s_geo in total_geo[idx:]:
  632. # minimize the number of distances by not taking into considerations those that are too small
  633. dist = geo.distance(s_geo)
  634. loc_1, loc_2 = nearest_points(geo, s_geo)
  635. dx = loc_1.x - loc_2.x
  636. dy = loc_1.y - loc_2.y
  637. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  638. if dist in min_dict:
  639. min_dict[dist].append(loc)
  640. else:
  641. min_dict[dist] = [loc]
  642. idx += 1
  643. points_list = set()
  644. for dist in min_dict.keys():
  645. if float(dist) < size:
  646. for location in min_dict[dist]:
  647. points_list.add(location)
  648. name_list = list()
  649. for elem in elements:
  650. name_list.append(elem['name'])
  651. obj_violations['name'] = name_list
  652. obj_violations['points'] = list(points_list)
  653. violations.append(deepcopy(obj_violations))
  654. return rule, violations
  655. @staticmethod
  656. def check_traces_size(elements, size):
  657. rule = _("Trace Size")
  658. violations = list()
  659. obj_violations = dict()
  660. obj_violations.update({
  661. 'name': '',
  662. 'size': list(),
  663. 'points': list()
  664. })
  665. for elem in elements:
  666. dia_list = []
  667. points_list = []
  668. name = elem['name']
  669. for apid in elem['apertures']:
  670. tool_dia = float(elem['apertures'][apid]['size'])
  671. if tool_dia < float(size) and tool_dia != 0.0:
  672. dia_list.append(tool_dia)
  673. for geo_el in elem['apertures'][apid]['geometry']:
  674. if 'solid' in geo_el.keys():
  675. geo = geo_el['solid']
  676. pt = geo.representative_point()
  677. points_list.append((pt.x, pt.y))
  678. obj_violations['name'] = name
  679. obj_violations['size'] = dia_list
  680. obj_violations['points'] = points_list
  681. violations.append(deepcopy(obj_violations))
  682. return rule, violations
  683. @staticmethod
  684. def check_gerber_annular_ring(obj_list, size, rule):
  685. rule_title = rule
  686. violations = list()
  687. obj_violations = dict()
  688. obj_violations.update({
  689. 'name': '',
  690. 'points': list()
  691. })
  692. # added it so I won't have errors of using before declaring
  693. gerber_obj = dict()
  694. gerber_extra_obj = dict()
  695. exc_obj = dict()
  696. exc_extra_obj = dict()
  697. if len(obj_list) == 2:
  698. gerber_obj = obj_list[0]
  699. exc_obj = obj_list[1]
  700. if 'apertures' in gerber_obj and 'tools' in exc_obj:
  701. pass
  702. else:
  703. return 'Fail. At least one Gerber and one Excellon object is required to check Minimum Annular Ring'
  704. elif len(obj_list) == 3:
  705. o1 = obj_list[0]
  706. o2 = obj_list[1]
  707. o3 = obj_list[2]
  708. if 'apertures' in o1 and 'apertures' in o2:
  709. gerber_obj = o1
  710. gerber_extra_obj = o2
  711. exc_obj = o3
  712. elif 'tools' in o2 and 'tools' in o3:
  713. gerber_obj = o1
  714. exc_obj = o2
  715. exc_extra_obj = o3
  716. elif len(obj_list) == 4:
  717. gerber_obj = obj_list[0]
  718. gerber_extra_obj = obj_list[1]
  719. exc_obj = obj_list[2]
  720. exc_extra_obj = obj_list[3]
  721. else:
  722. return 'Fail. Not enough objects to check Minimum Annular Ring'
  723. total_geo_grb = list()
  724. for apid in gerber_obj['apertures']:
  725. if 'geometry' in gerber_obj['apertures'][apid]:
  726. geometry = gerber_obj['apertures'][apid]['geometry']
  727. for geo_el in geometry:
  728. if 'solid' in geo_el and geo_el['solid'] is not None:
  729. total_geo_grb.append(geo_el['solid'])
  730. if len(obj_list) == 3 and gerber_extra_obj:
  731. # add the second Gerber geometry to the first one if it exists
  732. for apid in gerber_extra_obj['apertures']:
  733. if 'geometry' in gerber_extra_obj['apertures'][apid]:
  734. geometry = gerber_extra_obj['apertures'][apid]['geometry']
  735. for geo_el in geometry:
  736. if 'solid' in geo_el and geo_el['solid'] is not None:
  737. total_geo_grb.append(geo_el['solid'])
  738. total_geo_grb = MultiPolygon(total_geo_grb)
  739. total_geo_grb = total_geo_grb.buffer(0)
  740. total_geo_exc = list()
  741. for tool in exc_obj['tools']:
  742. if 'solid_geometry' in exc_obj['tools'][tool]:
  743. geometry = exc_obj['tools'][tool]['solid_geometry']
  744. for geo in geometry:
  745. total_geo_exc.append(geo)
  746. if len(obj_list) == 3 and exc_extra_obj:
  747. # add the second Excellon geometry to the first one if it exists
  748. for tool in exc_extra_obj['tools']:
  749. if 'solid_geometry' in exc_extra_obj['tools'][tool]:
  750. geometry = exc_extra_obj['tools'][tool]['solid_geometry']
  751. for geo in geometry:
  752. total_geo_exc.append(geo)
  753. if isinstance(total_geo_grb, Polygon):
  754. len_1 = 1
  755. else:
  756. len_1 = len(total_geo_grb)
  757. if isinstance(total_geo_exc, Polygon):
  758. len_2 = 1
  759. else:
  760. len_2 = len(total_geo_exc)
  761. iterations = len_1 * len_2
  762. log.debug("RulesCheck.check_gerber_annular_ring(). Iterations: %s" % str(iterations))
  763. min_dict = dict()
  764. for geo in total_geo_grb:
  765. for s_geo in total_geo_exc:
  766. # minimize the number of distances by not taking into considerations those that are too small
  767. dist = geo.exterior.distance(s_geo)
  768. if float(dist) < float(size):
  769. loc_1, loc_2 = nearest_points(geo.exterior, s_geo)
  770. dx = loc_1.x - loc_2.x
  771. dy = loc_1.y - loc_2.y
  772. loc = min(loc_1.x, loc_2.x) + (abs(dx) / 2), min(loc_1.y, loc_2.y) + (abs(dy) / 2)
  773. if dist in min_dict:
  774. min_dict[dist].append(loc)
  775. else:
  776. min_dict[dist] = [loc]
  777. points_list = list()
  778. for dist in min_dict.keys():
  779. for location in min_dict[dist]:
  780. points_list.append(location)
  781. name_list = list()
  782. if gerber_obj:
  783. name_list.append(gerber_obj['name'])
  784. if gerber_extra_obj:
  785. name_list.append(gerber_extra_obj['name'])
  786. if exc_obj:
  787. name_list.append(exc_obj['name'])
  788. if exc_extra_obj:
  789. name_list.append(exc_extra_obj['name'])
  790. obj_violations['name'] = name_list
  791. obj_violations['points'] = points_list
  792. violations.append(deepcopy(obj_violations))
  793. return rule_title, violations
  794. def execute(self):
  795. self.results = list()
  796. log.debug("RuleCheck() executing")
  797. def worker_job(app_obj):
  798. proc = self.app.proc_container.new(_("Working..."))
  799. # RULE: Check Trace Size
  800. if self.trace_size_cb.get_value():
  801. copper_list = list()
  802. copper_name_1 = self.copper_t_object.currentText()
  803. if copper_name_1 is not '' and self.copper_t_cb.get_value():
  804. elem_dict = dict()
  805. elem_dict['name'] = deepcopy(copper_name_1)
  806. elem_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_name_1).apertures)
  807. copper_list.append(elem_dict)
  808. copper_name_2 = self.copper_b_object.currentText()
  809. if copper_name_2 is not '' and self.copper_b_cb.get_value():
  810. elem_dict = dict()
  811. elem_dict['name'] = deepcopy(copper_name_2)
  812. elem_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_name_2).apertures)
  813. copper_list.append(elem_dict)
  814. trace_size = float(self.trace_size_entry.get_value())
  815. self.results.append(self.pool.apply_async(self.check_traces_size, args=(copper_list, trace_size)))
  816. # RULE: Check Copper to Copper Clearance
  817. if self.clearance_copper2copper_cb.get_value():
  818. try:
  819. copper_copper_clearance = float(self.clearance_copper2copper_entry.get_value())
  820. except Exception as e:
  821. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  822. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  823. _("Copper to Copper clearance"),
  824. _("Value is not valid.")))
  825. return
  826. if self.copper_t_cb.get_value():
  827. copper_t_obj = self.copper_t_object.currentText()
  828. copper_t_dict = dict()
  829. if copper_t_obj is not '':
  830. copper_t_dict['name'] = deepcopy(copper_t_obj)
  831. copper_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_t_obj).apertures)
  832. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  833. args=(copper_t_dict,
  834. copper_copper_clearance,
  835. _("TOP -> Copper to Copper clearance"))))
  836. if self.copper_b_cb.get_value():
  837. copper_b_obj = self.copper_b_object.currentText()
  838. copper_b_dict = dict()
  839. if copper_b_obj is not '':
  840. copper_b_dict['name'] = deepcopy(copper_b_obj)
  841. copper_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_b_obj).apertures)
  842. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  843. args=(copper_b_dict,
  844. copper_copper_clearance,
  845. _("BOTTOM -> Copper to Copper clearance"))))
  846. if self.copper_t_cb.get_value() is False and self.copper_b_cb.get_value() is False:
  847. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  848. _("Copper to Copper clearance"),
  849. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  850. return
  851. # RULE: Check Copper to Outline Clearance
  852. if self.clearance_copper2ol_cb.get_value():
  853. top_dict = dict()
  854. bottom_dict = dict()
  855. outline_dict = dict()
  856. copper_top = self.copper_t_object.currentText()
  857. if copper_top is not '' and self.copper_t_cb.get_value():
  858. top_dict['name'] = deepcopy(copper_top)
  859. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_top).apertures)
  860. copper_bottom = self.copper_b_object.currentText()
  861. if copper_bottom is not '' and self.copper_b_cb.get_value():
  862. bottom_dict['name'] = deepcopy(copper_bottom)
  863. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_bottom).apertures)
  864. copper_outline = self.outline_object.currentText()
  865. if copper_outline is not '' and self.out_cb.get_value():
  866. outline_dict['name'] = deepcopy(copper_outline)
  867. outline_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_outline).apertures)
  868. try:
  869. copper_outline_clearance = float(self.clearance_copper2ol_entry.get_value())
  870. except Exception as e:
  871. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  872. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  873. _("Copper to Outline clearance"),
  874. _("Value is not valid.")))
  875. return
  876. if not top_dict and not bottom_dict or not outline_dict:
  877. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  878. _("Copper to Outline clearance"),
  879. _("One of the copper Gerber objects or the Outline Gerber object is not valid.")))
  880. return
  881. objs = []
  882. if top_dict:
  883. objs.append(top_dict)
  884. if bottom_dict:
  885. objs.append(bottom_dict)
  886. if outline_dict:
  887. objs.append(outline_dict)
  888. else:
  889. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  890. _("Copper to Outline clearance"),
  891. _("Outline Gerber object presence is mandatory for this rule but it is not selected.")))
  892. return
  893. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  894. args=(objs,
  895. copper_outline_clearance,
  896. _("Copper to Outline clearance"))))
  897. # RULE: Check Silk to Silk Clearance
  898. if self.clearance_silk2silk_cb.get_value():
  899. silk_dict = dict()
  900. try:
  901. silk_silk_clearance = float(self.clearance_silk2silk_entry.get_value())
  902. except Exception as e:
  903. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  904. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  905. _("Silk to Silk clearance"),
  906. _("Value is not valid.")))
  907. return
  908. if self.ss_t_cb.get_value():
  909. silk_obj = self.ss_t_object.currentText()
  910. if silk_obj is not '':
  911. silk_dict['name'] = deepcopy(silk_obj)
  912. silk_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_obj).apertures)
  913. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  914. args=(silk_dict,
  915. silk_silk_clearance,
  916. _("TOP -> Silk to Silk clearance"))))
  917. if self.ss_b_cb.get_value():
  918. silk_obj = self.ss_b_object.currentText()
  919. if silk_obj is not '':
  920. silk_dict['name'] = deepcopy(silk_obj)
  921. silk_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_obj).apertures)
  922. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  923. args=(silk_dict,
  924. silk_silk_clearance,
  925. _("BOTTOM -> Silk to Silk clearance"))))
  926. if self.ss_t_cb.get_value() is False and self.ss_b_cb.get_value() is False:
  927. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  928. _("Silk to Silk clearance"),
  929. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  930. return
  931. # RULE: Check Silk to Solder Mask Clearance
  932. if self.clearance_silk2sm_cb.get_value():
  933. silk_t_dict = dict()
  934. sm_t_dict = dict()
  935. silk_b_dict = dict()
  936. sm_b_dict = dict()
  937. top_ss = False
  938. bottom_ss = False
  939. top_sm = False
  940. bottom_sm = False
  941. silk_top = self.ss_t_object.currentText()
  942. if silk_top is not '' and self.ss_t_cb.get_value():
  943. silk_t_dict['name'] = deepcopy(silk_top)
  944. silk_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_top).apertures)
  945. top_ss = True
  946. silk_bottom = self.ss_b_object.currentText()
  947. if silk_bottom is not '' and self.ss_b_cb.get_value():
  948. silk_b_dict['name'] = deepcopy(silk_bottom)
  949. silk_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_bottom).apertures)
  950. bottom_ss = True
  951. sm_top = self.sm_t_object.currentText()
  952. if sm_top is not '' and self.sm_t_cb.get_value():
  953. sm_t_dict['name'] = deepcopy(sm_top)
  954. sm_t_dict['apertures'] = deepcopy(self.app.collection.get_by_name(sm_top).apertures)
  955. top_sm = True
  956. sm_bottom = self.sm_b_object.currentText()
  957. if sm_bottom is not '' and self.sm_b_cb.get_value():
  958. sm_b_dict['name'] = deepcopy(sm_bottom)
  959. sm_b_dict['apertures'] = deepcopy(self.app.collection.get_by_name(sm_bottom).apertures)
  960. bottom_sm = True
  961. try:
  962. silk_sm_clearance = float(self.clearance_silk2sm_entry.get_value())
  963. except Exception as e:
  964. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  965. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  966. _("Silk to Solder Mask Clearance"),
  967. _("Value is not valid.")))
  968. return
  969. if (not silk_t_dict and not silk_b_dict) or (not sm_t_dict and not sm_b_dict):
  970. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  971. _("Silk to Solder Mask Clearance"),
  972. _("One or more of the Gerber objects is not valid.")))
  973. return
  974. if top_ss is True and top_sm is True:
  975. objs = [silk_t_dict, sm_t_dict]
  976. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  977. args=(objs,
  978. silk_sm_clearance,
  979. _("TOP -> Silk to Solder Mask Clearance"))))
  980. elif bottom_ss is True and bottom_sm is True:
  981. objs = [silk_b_dict, sm_b_dict]
  982. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  983. args=(objs,
  984. silk_sm_clearance,
  985. _("BOTTOM -> Silk to Solder Mask Clearance"))))
  986. else:
  987. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  988. _("Silk to Solder Mask Clearance"),
  989. _("Both Silk and Solder Mask Gerber objects has to be either both Top or both Bottom.")))
  990. return
  991. # RULE: Check Silk to Outline Clearance
  992. if self.clearance_silk2ol_cb.get_value():
  993. top_dict = dict()
  994. bottom_dict = dict()
  995. outline_dict = dict()
  996. silk_top = self.ss_t_object.currentText()
  997. if silk_top is not '' and self.ss_t_cb.get_value():
  998. top_dict['name'] = deepcopy(silk_top)
  999. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_top).apertures)
  1000. silk_bottom = self.ss_b_object.currentText()
  1001. if silk_bottom is not '' and self.ss_b_cb.get_value():
  1002. bottom_dict['name'] = deepcopy(silk_bottom)
  1003. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(silk_bottom).apertures)
  1004. copper_outline = self.outline_object.currentText()
  1005. if copper_outline is not '' and self.out_cb.get_value():
  1006. outline_dict['name'] = deepcopy(copper_outline)
  1007. outline_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_outline).apertures)
  1008. try:
  1009. copper_outline_clearance = float(self.clearance_copper2ol_entry.get_value())
  1010. except Exception as e:
  1011. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1012. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1013. _("Silk to Outline Clearance"),
  1014. _("Value is not valid.")))
  1015. return
  1016. if not top_dict and not bottom_dict or not outline_dict:
  1017. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1018. _("Silk to Outline Clearance"),
  1019. _("One of the Silk Gerber objects or the Outline Gerber object is not valid.")))
  1020. return
  1021. objs = []
  1022. if top_dict:
  1023. objs.append(top_dict)
  1024. if bottom_dict:
  1025. objs.append(bottom_dict)
  1026. if outline_dict:
  1027. objs.append(outline_dict)
  1028. else:
  1029. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1030. _("Silk to Outline Clearance"),
  1031. _("Outline Gerber object presence is mandatory for this rule but it is not selected.")))
  1032. return
  1033. self.results.append(self.pool.apply_async(self.check_gerber_clearance,
  1034. args=(objs,
  1035. copper_outline_clearance,
  1036. _("Silk to Outline Clearance"))))
  1037. # RULE: Check Minimum Solder Mask Sliver
  1038. if self.clearance_silk2silk_cb.get_value():
  1039. sm_dict = dict()
  1040. try:
  1041. sm_sm_clearance = float(self.clearance_sm2sm_entry.get_value())
  1042. except Exception as e:
  1043. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1044. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1045. _("Minimum Solder Mask Sliver"),
  1046. _("Value is not valid.")))
  1047. return
  1048. if self.sm_t_cb.get_value():
  1049. solder_obj = self.sm_t_object.currentText()
  1050. if solder_obj is not '':
  1051. sm_dict['name'] = deepcopy(solder_obj)
  1052. sm_dict['apertures'] = deepcopy(self.app.collection.get_by_name(solder_obj).apertures)
  1053. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  1054. args=(sm_dict,
  1055. sm_sm_clearance,
  1056. _("TOP -> Minimum Solder Mask Sliver"))))
  1057. if self.sm_b_cb.get_value():
  1058. solder_obj = self.sm_b_object.currentText()
  1059. if solder_obj is not '':
  1060. sm_dict['name'] = deepcopy(solder_obj)
  1061. sm_dict['apertures'] = deepcopy(self.app.collection.get_by_name(solder_obj).apertures)
  1062. self.results.append(self.pool.apply_async(self.check_inside_gerber_clearance,
  1063. args=(sm_dict,
  1064. sm_sm_clearance,
  1065. _("BOTTOM -> Minimum Solder Mask Sliver"))))
  1066. if self.sm_t_cb.get_value() is False and self.sm_b_cb.get_value() is False:
  1067. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1068. _("Minimum Solder Mask Sliver"),
  1069. _("At least one Gerber object has to be selected for this rule but none is selected.")))
  1070. return
  1071. # RULE: Check Minimum Annular Ring
  1072. if self.ring_integrity_cb.get_value():
  1073. top_dict = dict()
  1074. bottom_dict = dict()
  1075. exc_1_dict = dict()
  1076. exc_2_dict = dict()
  1077. copper_top = self.copper_t_object.currentText()
  1078. if copper_top is not '' and self.copper_t_cb.get_value():
  1079. top_dict['name'] = deepcopy(copper_top)
  1080. top_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_top).apertures)
  1081. copper_bottom = self.copper_b_object.currentText()
  1082. if copper_bottom is not '' and self.copper_b_cb.get_value():
  1083. bottom_dict['name'] = deepcopy(copper_bottom)
  1084. bottom_dict['apertures'] = deepcopy(self.app.collection.get_by_name(copper_bottom).apertures)
  1085. excellon_1 = self.e1_object.currentText()
  1086. if excellon_1 is not '' and self.e1_cb.get_value():
  1087. exc_1_dict['name'] = deepcopy(excellon_1)
  1088. exc_1_dict['tools'] = deepcopy(
  1089. self.app.collection.get_by_name(excellon_1).tools)
  1090. excellon_2 = self.e2_object.currentText()
  1091. if excellon_2 is not '' and self.e2_cb.get_value():
  1092. exc_2_dict['name'] = deepcopy(excellon_2)
  1093. exc_2_dict['tools'] = deepcopy(
  1094. self.app.collection.get_by_name(excellon_2).tools)
  1095. try:
  1096. ring_val = float(self.ring_integrity_entry.get_value())
  1097. except Exception as e:
  1098. log.debug("RulesCheck.execute.worker_job() --> %s" % str(e))
  1099. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1100. _("Minimum Annular Ring"),
  1101. _("Value is not valid.")))
  1102. return
  1103. if (not top_dict and not bottom_dict) or (not exc_1_dict and not exc_2_dict):
  1104. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1105. _("Minimum Annular Ring"),
  1106. _("One of the Copper Gerber objects or the Excellon objects is not valid.")))
  1107. return
  1108. objs = []
  1109. if top_dict:
  1110. objs.append(top_dict)
  1111. elif bottom_dict:
  1112. objs.append(bottom_dict)
  1113. if exc_1_dict:
  1114. objs.append(exc_1_dict)
  1115. elif exc_2_dict:
  1116. objs.append(exc_2_dict)
  1117. else:
  1118. self.app.inform.emit('[ERROR_NOTCL] %s. %s' % (
  1119. _("Minimum Annular Ring"),
  1120. _("Excellon object presence is mandatory for this rule but none is selected.")))
  1121. return
  1122. self.results.append(self.pool.apply_async(self.check_gerber_annular_ring,
  1123. args=(objs,
  1124. ring_val,
  1125. _("Minimum Annular Ring"))))
  1126. # RULE: Check Hole to Hole Clearance
  1127. if self.clearance_d2d_cb.get_value():
  1128. exc_list = list()
  1129. exc_name_1 = self.e1_object.currentText()
  1130. if exc_name_1 is not '' and self.e1_cb.get_value():
  1131. elem_dict = dict()
  1132. elem_dict['name'] = deepcopy(exc_name_1)
  1133. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_1).tools)
  1134. exc_list.append(elem_dict)
  1135. exc_name_2 = self.e2_object.currentText()
  1136. if exc_name_2 is not '' and self.e2_cb.get_value():
  1137. elem_dict = dict()
  1138. elem_dict['name'] = deepcopy(exc_name_2)
  1139. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_2).tools)
  1140. exc_list.append(elem_dict)
  1141. hole_clearance = float(self.clearance_d2d_entry.get_value())
  1142. self.results.append(self.pool.apply_async(self.check_holes_clearance, args=(exc_list, hole_clearance)))
  1143. # RULE: Check Holes Size
  1144. if self.drill_size_cb.get_value():
  1145. exc_list = list()
  1146. exc_name_1 = self.e1_object.currentText()
  1147. if exc_name_1 is not '' and self.e1_cb.get_value():
  1148. elem_dict = dict()
  1149. elem_dict['name'] = deepcopy(exc_name_1)
  1150. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_1).tools)
  1151. exc_list.append(elem_dict)
  1152. exc_name_2 = self.e2_object.currentText()
  1153. if exc_name_2 is not '' and self.e2_cb.get_value():
  1154. elem_dict = dict()
  1155. elem_dict['name'] = deepcopy(exc_name_2)
  1156. elem_dict['tools'] = deepcopy(self.app.collection.get_by_name(exc_name_2).tools)
  1157. exc_list.append(elem_dict)
  1158. drill_size = float(self.drill_size_entry.get_value())
  1159. self.results.append(self.pool.apply_async(self.check_holes_size, args=(exc_list, drill_size)))
  1160. output = list()
  1161. for p in self.results:
  1162. output.append(p.get())
  1163. self.tool_finished.emit(output)
  1164. log.debug("RuleCheck() finished")
  1165. self.app.worker_task.emit({'fcn': worker_job, 'params': [self.app]})
  1166. def on_tool_finished(self, res):
  1167. def init(new_obj, app_obj):
  1168. txt = ''
  1169. for el in res:
  1170. txt += '<b>RULE NAME:</b>&nbsp;&nbsp;&nbsp;&nbsp;%s<BR>' % str(el[0]).upper()
  1171. if isinstance(el[1][0]['name'], list):
  1172. for name in el[1][0]['name']:
  1173. txt += 'File name: %s<BR>' % str(name)
  1174. else:
  1175. txt += 'File name: %s<BR>' % str(el[1][0]['name'])
  1176. point_txt = ''
  1177. if el[1][0]['points']:
  1178. txt += '{title}: <span style="color:{color};">{status}</span>.<BR>'.format(title=_("STATUS"),
  1179. color='red',
  1180. status=_("FAILED"))
  1181. if 'Failed' in el[1][0]['points'][0]:
  1182. point_txt = el[1][0]['points'][0]
  1183. else:
  1184. for pt in el[1][0]['points']:
  1185. point_txt += '(%.*f, %.*f)' % (self.decimals, float(pt[0]), self.decimals, float(pt[1]))
  1186. point_txt += ', '
  1187. txt += 'Violations: %s<BR>' % str(point_txt)
  1188. else:
  1189. txt += '{title}: <span style="color:{color};">{status}</span>.<BR>'.format(title=_("STATUS"),
  1190. color='green',
  1191. status=_("PASSED"))
  1192. txt += '%s<BR>' % _("Violations: There are no violations for the current rule.")
  1193. txt += '<BR><BR>'
  1194. new_obj.source_file = txt
  1195. new_obj.read_only = True
  1196. self.app.new_object('document', name='Rules Check results', initialize=init, plot=False )
  1197. def reset_fields(self):
  1198. # self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1199. # self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1200. pass