ToolRulesCheck.py 58 KB

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