ToolPunchGerber.py 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # File Author: Marius Adrian Stanciu (c) #
  4. # Date: 1/24/2020 #
  5. # MIT Licence #
  6. # ##########################################################
  7. from PyQt5 import QtCore, QtWidgets, QtGui
  8. from appTool import AppTool
  9. from appGUI.GUIElements import RadioSet, FCDoubleSpinner, FCCheckBox, FCComboBox, FCTable
  10. from copy import deepcopy
  11. import logging
  12. from shapely.geometry import MultiPolygon, Point
  13. import gettext
  14. import appTranslation as fcTranslate
  15. import builtins
  16. fcTranslate.apply_language('strings')
  17. if '_' not in builtins.__dict__:
  18. _ = gettext.gettext
  19. log = logging.getLogger('base')
  20. class ToolPunchGerber(AppTool):
  21. def __init__(self, app):
  22. AppTool.__init__(self, app)
  23. self.app = app
  24. self.decimals = self.app.decimals
  25. self.units = self.app.defaults['units']
  26. # #############################################################################
  27. # ######################### Tool GUI ##########################################
  28. # #############################################################################
  29. self.ui = PunchUI(layout=self.layout, app=self.app)
  30. self.toolName = self.ui.toolName
  31. # ## Signals
  32. self.ui.method_punch.activated_custom.connect(self.on_method)
  33. self.ui.reset_button.clicked.connect(self.set_tool_ui)
  34. self.ui.punch_object_button.clicked.connect(self.on_generate_object)
  35. self.ui.gerber_object_combo.currentIndexChanged.connect(self.build_tool_ui)
  36. self.ui.circular_cb.stateChanged.connect(
  37. lambda state:
  38. self.ui.circular_ring_entry.setDisabled(False) if state else
  39. self.ui.circular_ring_entry.setDisabled(True)
  40. )
  41. self.ui.oblong_cb.stateChanged.connect(
  42. lambda state:
  43. self.ui.oblong_ring_entry.setDisabled(False) if state else self.ui.oblong_ring_entry.setDisabled(True)
  44. )
  45. self.ui.square_cb.stateChanged.connect(
  46. lambda state:
  47. self.ui.square_ring_entry.setDisabled(False) if state else self.ui.square_ring_entry.setDisabled(True)
  48. )
  49. self.ui.rectangular_cb.stateChanged.connect(
  50. lambda state:
  51. self.ui.rectangular_ring_entry.setDisabled(False) if state else
  52. self.ui.rectangular_ring_entry.setDisabled(True)
  53. )
  54. self.ui.other_cb.stateChanged.connect(
  55. lambda state:
  56. self.ui.other_ring_entry.setDisabled(False) if state else self.ui.other_ring_entry.setDisabled(True)
  57. )
  58. def run(self, toggle=True):
  59. self.app.defaults.report_usage("ToolPunchGerber()")
  60. if toggle:
  61. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  62. if self.app.ui.splitter.sizes()[0] == 0:
  63. self.app.ui.splitter.setSizes([1, 1])
  64. else:
  65. try:
  66. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  67. # if tab is populated with the tool but it does not have the focus, focus on it
  68. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  69. # focus on Tool Tab
  70. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  71. else:
  72. self.app.ui.splitter.setSizes([0, 1])
  73. except AttributeError:
  74. pass
  75. else:
  76. if self.app.ui.splitter.sizes()[0] == 0:
  77. self.app.ui.splitter.setSizes([1, 1])
  78. AppTool.run(self)
  79. self.set_tool_ui()
  80. self.build_tool_ui()
  81. self.app.ui.notebook.setTabText(2, _("Punch Tool"))
  82. def install(self, icon=None, separator=None, **kwargs):
  83. AppTool.install(self, icon, separator, shortcut='Alt+H', **kwargs)
  84. def set_tool_ui(self):
  85. self.reset_fields()
  86. self.ui_disconnect()
  87. self.ui_connect()
  88. self.ui.method_punch.set_value(self.app.defaults["tools_punch_hole_type"])
  89. self.ui.select_all_cb.set_value(False)
  90. self.ui.dia_entry.set_value(float(self.app.defaults["tools_punch_hole_fixed_dia"]))
  91. self.ui.circular_ring_entry.set_value(float(self.app.defaults["tools_punch_circular_ring"]))
  92. self.ui.oblong_ring_entry.set_value(float(self.app.defaults["tools_punch_oblong_ring"]))
  93. self.ui.square_ring_entry.set_value(float(self.app.defaults["tools_punch_square_ring"]))
  94. self.ui.rectangular_ring_entry.set_value(float(self.app.defaults["tools_punch_rectangular_ring"]))
  95. self.ui.other_ring_entry.set_value(float(self.app.defaults["tools_punch_others_ring"]))
  96. self.ui.circular_cb.set_value(self.app.defaults["tools_punch_circular"])
  97. self.ui.oblong_cb.set_value(self.app.defaults["tools_punch_oblong"])
  98. self.ui.square_cb.set_value(self.app.defaults["tools_punch_square"])
  99. self.ui.rectangular_cb.set_value(self.app.defaults["tools_punch_rectangular"])
  100. self.ui.other_cb.set_value(self.app.defaults["tools_punch_others"])
  101. self.ui.factor_entry.set_value(float(self.app.defaults["tools_punch_hole_prop_factor"]))
  102. def build_tool_ui(self):
  103. # get the Gerber file who is the source of the punched Gerber
  104. selection_index = self.ui.gerber_object_combo.currentIndex()
  105. model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex())
  106. obj = None
  107. try:
  108. obj = model_index.internalPointer().obj
  109. sort = [int(k) for k in obj.apertures.keys()]
  110. sorted_apertures = sorted(sort)
  111. except Exception:
  112. # no object loaded
  113. sorted_apertures = []
  114. n = len(sorted_apertures)
  115. self.ui.apertures_table.setRowCount(n)
  116. row = 0
  117. for ap_code in sorted_apertures:
  118. ap_code = str(ap_code)
  119. ap_code_item = QtWidgets.QTableWidgetItem(ap_code)
  120. ap_code_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  121. ap_type_item = QtWidgets.QTableWidgetItem(str(obj.apertures[ap_code]['type']))
  122. ap_type_item.setFlags(QtCore.Qt.ItemIsEnabled)
  123. try:
  124. if obj.apertures[ap_code]['size'] is not None:
  125. size_val = self.app.dec_format(float(obj.apertures[ap_code]['size']), self.decimals)
  126. ap_size_item = QtWidgets.QTableWidgetItem(str(size_val))
  127. else:
  128. ap_size_item = QtWidgets.QTableWidgetItem('')
  129. except KeyError:
  130. ap_size_item = QtWidgets.QTableWidgetItem('')
  131. ap_size_item.setFlags(QtCore.Qt.ItemIsEnabled)
  132. self.ui.apertures_table.setItem(row, 0, ap_code_item) # Aperture Code
  133. self.ui.apertures_table.setItem(row, 1, ap_type_item) # Aperture Type
  134. self.ui.apertures_table.setItem(row, 2, ap_size_item) # Aperture Dimensions
  135. # increment row
  136. row += 1
  137. self.ui.apertures_table.resizeColumnsToContents()
  138. self.ui.apertures_table.resizeRowsToContents()
  139. vertical_header = self.ui.apertures_table.verticalHeader()
  140. vertical_header.hide()
  141. # self.ui.apertures_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  142. horizontal_header = self.ui.apertures_table.horizontalHeader()
  143. horizontal_header.setMinimumSectionSize(10)
  144. horizontal_header.setDefaultSectionSize(70)
  145. horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
  146. horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
  147. horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
  148. self.ui.apertures_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  149. self.ui.apertures_table.setSortingEnabled(False)
  150. # self.ui.apertures_table.setMinimumHeight(self.ui.apertures_table.getHeight())
  151. # self.ui.apertures_table.setMaximumHeight(self.ui.apertures_table.getHeight())
  152. def on_select_all(self, state):
  153. self.ui_disconnect()
  154. if state:
  155. self.ui.circular_cb.setChecked(True)
  156. self.ui.oblong_cb.setChecked(True)
  157. self.ui.square_cb.setChecked(True)
  158. self.ui.rectangular_cb.setChecked(True)
  159. self.ui.other_cb.setChecked(True)
  160. else:
  161. self.ui.circular_cb.setChecked(False)
  162. self.ui.oblong_cb.setChecked(False)
  163. self.ui.square_cb.setChecked(False)
  164. self.ui.rectangular_cb.setChecked(False)
  165. self.ui.other_cb.setChecked(False)
  166. self.ui_connect()
  167. def on_method(self, val):
  168. self.ui.exc_label.hide()
  169. self.ui.exc_combo.hide()
  170. self.ui.fixed_label.hide()
  171. self.ui.dia_label.hide()
  172. self.ui.dia_entry.hide()
  173. self.ui.ring_frame.hide()
  174. self.ui.prop_label.hide()
  175. self.ui.factor_label.hide()
  176. self.ui.factor_entry.hide()
  177. if val == 'exc':
  178. self.ui.exc_label.show()
  179. self.ui.exc_combo.show()
  180. elif val == 'fixed':
  181. self.ui.fixed_label.show()
  182. self.ui.dia_label.show()
  183. self.ui.dia_entry.show()
  184. elif val == 'ring':
  185. self.ui.ring_frame.show()
  186. elif val == 'prop':
  187. self.ui.prop_label.show()
  188. self.ui.factor_label.show()
  189. self.ui.factor_entry.show()
  190. def ui_connect(self):
  191. self.ui.select_all_cb.stateChanged.connect(self.on_select_all)
  192. def ui_disconnect(self):
  193. try:
  194. self.ui.select_all_cb.stateChanged.disconnect()
  195. except (AttributeError, TypeError):
  196. pass
  197. def on_generate_object(self):
  198. # get the Gerber file who is the source of the punched Gerber
  199. selection_index = self.ui.gerber_object_combo.currentIndex()
  200. model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex())
  201. try:
  202. grb_obj = model_index.internalPointer().obj
  203. except Exception:
  204. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
  205. return
  206. name = grb_obj.options['name'].rpartition('.')[0]
  207. outname = name + "_punched"
  208. punch_method = self.ui.method_punch.get_value()
  209. if punch_method == 'exc':
  210. self.on_excellon_method(grb_obj, outname)
  211. elif punch_method == 'fixed':
  212. self.on_fixed_method(grb_obj, outname)
  213. elif punch_method == 'ring':
  214. self.on_ring_method(grb_obj, outname)
  215. elif punch_method == 'prop':
  216. self.on_proportional_method(grb_obj, outname)
  217. def on_excellon_method(self, grb_obj, outname):
  218. # get the Excellon file whose geometry will create the punch holes
  219. selection_index = self.ui.exc_combo.currentIndex()
  220. model_index = self.app.collection.index(selection_index, 0, self.ui.exc_combo.rootModelIndex())
  221. try:
  222. exc_obj = model_index.internalPointer().obj
  223. except Exception:
  224. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Excellon object loaded ..."))
  225. return
  226. new_options = {}
  227. for opt in grb_obj.options:
  228. new_options[opt] = deepcopy(grb_obj.options[opt])
  229. # this is the punching geometry
  230. exc_solid_geometry = MultiPolygon(exc_obj.solid_geometry)
  231. if isinstance(grb_obj.solid_geometry, list):
  232. grb_solid_geometry = MultiPolygon(grb_obj.solid_geometry)
  233. else:
  234. grb_solid_geometry = grb_obj.solid_geometry
  235. # create the punched Gerber solid_geometry
  236. punched_solid_geometry = grb_solid_geometry.difference(exc_solid_geometry)
  237. # update the gerber apertures to include the clear geometry so it can be exported successfully
  238. new_apertures = deepcopy(grb_obj.apertures)
  239. new_apertures_items = new_apertures.items()
  240. # find maximum aperture id
  241. new_apid = max([int(x) for x, __ in new_apertures_items])
  242. # store here the clear geometry, the key is the drill size
  243. holes_apertures = {}
  244. for apid, val in new_apertures_items:
  245. for elem in val['geometry']:
  246. # make it work only for Gerber Flashes who are Points in 'follow'
  247. if 'solid' in elem and isinstance(elem['follow'], Point):
  248. for tool in exc_obj.tools:
  249. clear_apid_size = exc_obj.tools[tool]['tooldia']
  250. if 'drills' in exc_obj.tools[tool]['drills']:
  251. for drill_pt in exc_obj.tools[tool]['drills']:
  252. # since there may be drills that do not drill into a pad we test only for
  253. # drills in a pad
  254. if drill_pt.within(elem['solid']):
  255. geo_elem = {}
  256. geo_elem['clear'] = drill_pt
  257. if clear_apid_size not in holes_apertures:
  258. holes_apertures[clear_apid_size] = {}
  259. holes_apertures[clear_apid_size]['type'] = 'C'
  260. holes_apertures[clear_apid_size]['size'] = clear_apid_size
  261. holes_apertures[clear_apid_size]['geometry'] = []
  262. holes_apertures[clear_apid_size]['geometry'].append(deepcopy(geo_elem))
  263. # add the clear geometry to new apertures; it's easier than to test if there are apertures with the same
  264. # size and add there the clear geometry
  265. for hole_size, ap_val in holes_apertures.items():
  266. new_apid += 1
  267. new_apertures[str(new_apid)] = deepcopy(ap_val)
  268. def init_func(new_obj, app_obj):
  269. new_obj.options.update(new_options)
  270. new_obj.options['name'] = outname
  271. new_obj.fill_color = deepcopy(grb_obj.fill_color)
  272. new_obj.outline_color = deepcopy(grb_obj.outline_color)
  273. new_obj.apertures = deepcopy(new_apertures)
  274. new_obj.solid_geometry = deepcopy(punched_solid_geometry)
  275. new_obj.source_file = self.app.f_handlers.export_gerber(obj_name=outname, filename=None,
  276. local_use=new_obj, use_thread=False)
  277. self.app.app_obj.new_object('gerber', outname, init_func)
  278. def on_fixed_method(self, grb_obj, outname):
  279. punch_size = float(self.ui.dia_entry.get_value())
  280. if punch_size == 0.0:
  281. self.app.inform.emit('[WARNING_NOTCL] %s' % _("The value of the fixed diameter is 0.0. Aborting."))
  282. return 'fail'
  283. fail_msg = _("Could not generate punched hole Gerber because the punch hole size is bigger than"
  284. " some of the apertures in the Gerber object.")
  285. new_options = {}
  286. for opt in grb_obj.options:
  287. new_options[opt] = deepcopy(grb_obj.options[opt])
  288. # selected codes in thre apertures UI table
  289. sel_apid = []
  290. for it in self.ui.apertures_table.selectedItems():
  291. sel_apid.append(it.text())
  292. punching_geo = []
  293. for apid in grb_obj.apertures:
  294. if apid in sel_apid:
  295. if grb_obj.apertures[apid]['type'] == 'C' and self.ui.circular_cb.get_value():
  296. for elem in grb_obj.apertures[apid]['geometry']:
  297. if 'follow' in elem:
  298. if isinstance(elem['follow'], Point):
  299. if punch_size >= float(grb_obj.apertures[apid]['size']):
  300. self.app.inform.emit('[ERROR_NOTCL] %s' % fail_msg)
  301. return 'fail'
  302. punching_geo.append(elem['follow'].buffer(punch_size / 2))
  303. elif grb_obj.apertures[apid]['type'] == 'R':
  304. if round(float(grb_obj.apertures[apid]['width']), self.decimals) == \
  305. round(float(grb_obj.apertures[apid]['height']), self.decimals) and \
  306. self.ui.square_cb.get_value():
  307. for elem in grb_obj.apertures[apid]['geometry']:
  308. if 'follow' in elem:
  309. if isinstance(elem['follow'], Point):
  310. if punch_size >= float(grb_obj.apertures[apid]['width']) or \
  311. punch_size >= float(grb_obj.apertures[apid]['height']):
  312. self.app.inform.emit('[ERROR_NOTCL] %s' % fail_msg)
  313. return 'fail'
  314. punching_geo.append(elem['follow'].buffer(punch_size / 2))
  315. elif round(float(grb_obj.apertures[apid]['width']), self.decimals) != \
  316. round(float(grb_obj.apertures[apid]['height']), self.decimals) and \
  317. self.ui.rectangular_cb.get_value():
  318. for elem in grb_obj.apertures[apid]['geometry']:
  319. if 'follow' in elem:
  320. if isinstance(elem['follow'], Point):
  321. if punch_size >= float(grb_obj.apertures[apid]['width']) or \
  322. punch_size >= float(grb_obj.apertures[apid]['height']):
  323. self.app.inform.emit('[ERROR_NOTCL] %s' % fail_msg)
  324. return 'fail'
  325. punching_geo.append(elem['follow'].buffer(punch_size / 2))
  326. elif grb_obj.apertures[apid]['type'] == 'O' and self.ui.oblong_cb.get_value():
  327. for elem in grb_obj.apertures[apid]['geometry']:
  328. if 'follow' in elem:
  329. if isinstance(elem['follow'], Point):
  330. if punch_size >= float(grb_obj.apertures[apid]['size']):
  331. self.app.inform.emit('[ERROR_NOTCL] %s' % fail_msg)
  332. return 'fail'
  333. punching_geo.append(elem['follow'].buffer(punch_size / 2))
  334. elif grb_obj.apertures[apid]['type'] not in ['C', 'R', 'O'] and self.ui.other_cb.get_value():
  335. for elem in grb_obj.apertures[apid]['geometry']:
  336. if 'follow' in elem:
  337. if isinstance(elem['follow'], Point):
  338. if punch_size >= float(grb_obj.apertures[apid]['size']):
  339. self.app.inform.emit('[ERROR_NOTCL] %s' % fail_msg)
  340. return 'fail'
  341. punching_geo.append(elem['follow'].buffer(punch_size / 2))
  342. punching_geo = MultiPolygon(punching_geo)
  343. if isinstance(grb_obj.solid_geometry, list):
  344. temp_solid_geometry = MultiPolygon(grb_obj.solid_geometry)
  345. else:
  346. temp_solid_geometry = grb_obj.solid_geometry
  347. punched_solid_geometry = temp_solid_geometry.difference(punching_geo)
  348. if punched_solid_geometry == temp_solid_geometry:
  349. self.app.inform.emit('[WARNING_NOTCL] %s' %
  350. _("Could not generate punched hole Gerber because the newly created object "
  351. "geometry is the same as the one in the source object geometry..."))
  352. return 'fail'
  353. # update the gerber apertures to include the clear geometry so it can be exported successfully
  354. new_apertures = deepcopy(grb_obj.apertures)
  355. new_apertures_items = new_apertures.items()
  356. # find maximum aperture id
  357. new_apid = max([int(x) for x, __ in new_apertures_items])
  358. # store here the clear geometry, the key is the drill size
  359. holes_apertures = {}
  360. for apid, val in new_apertures_items:
  361. for elem in val['geometry']:
  362. # make it work only for Gerber Flashes who are Points in 'follow'
  363. if 'solid' in elem and isinstance(elem['follow'], Point):
  364. for geo in punching_geo:
  365. clear_apid_size = punch_size
  366. # since there may be drills that do not drill into a pad we test only for drills in a pad
  367. if geo.within(elem['solid']):
  368. geo_elem = {}
  369. geo_elem['clear'] = geo.centroid
  370. if clear_apid_size not in holes_apertures:
  371. holes_apertures[clear_apid_size] = {}
  372. holes_apertures[clear_apid_size]['type'] = 'C'
  373. holes_apertures[clear_apid_size]['size'] = clear_apid_size
  374. holes_apertures[clear_apid_size]['geometry'] = []
  375. holes_apertures[clear_apid_size]['geometry'].append(deepcopy(geo_elem))
  376. # add the clear geometry to new apertures; it's easier than to test if there are apertures with the same
  377. # size and add there the clear geometry
  378. for hole_size, ap_val in holes_apertures.items():
  379. new_apid += 1
  380. new_apertures[str(new_apid)] = deepcopy(ap_val)
  381. def init_func(new_obj, app_obj):
  382. new_obj.options.update(new_options)
  383. new_obj.options['name'] = outname
  384. new_obj.fill_color = deepcopy(grb_obj.fill_color)
  385. new_obj.outline_color = deepcopy(grb_obj.outline_color)
  386. new_obj.apertures = deepcopy(new_apertures)
  387. new_obj.solid_geometry = deepcopy(punched_solid_geometry)
  388. new_obj.source_file = self.app.f_handlers.export_gerber(obj_name=outname, filename=None,
  389. local_use=new_obj, use_thread=False)
  390. self.app.app_obj.new_object('gerber', outname, init_func)
  391. def on_ring_method(self, grb_obj, outname):
  392. circ_r_val = self.ui.circular_ring_entry.get_value()
  393. oblong_r_val = self.ui.oblong_ring_entry.get_value()
  394. square_r_val = self.ui.square_ring_entry.get_value()
  395. rect_r_val = self.ui.rectangular_ring_entry.get_value()
  396. other_r_val = self.ui.other_ring_entry.get_value()
  397. dia = None
  398. new_options = {}
  399. for opt in grb_obj.options:
  400. new_options[opt] = deepcopy(grb_obj.options[opt])
  401. if isinstance(grb_obj.solid_geometry, list):
  402. temp_solid_geometry = MultiPolygon(grb_obj.solid_geometry)
  403. else:
  404. temp_solid_geometry = grb_obj.solid_geometry
  405. punched_solid_geometry = temp_solid_geometry
  406. new_apertures = deepcopy(grb_obj.apertures)
  407. new_apertures_items = new_apertures.items()
  408. # find maximum aperture id
  409. new_apid = max([int(x) for x, __ in new_apertures_items])
  410. # selected codes in the apertures UI table
  411. sel_apid = []
  412. for it in self.ui.apertures_table.selectedItems():
  413. sel_apid.append(it.text())
  414. # store here the clear geometry, the key is the new aperture size
  415. holes_apertures = {}
  416. for apid, apid_value in grb_obj.apertures.items():
  417. ap_type = apid_value['type']
  418. punching_geo = []
  419. if apid in sel_apid:
  420. if ap_type == 'C' and self.ui.circular_cb.get_value():
  421. dia = float(apid_value['size']) - (2 * circ_r_val)
  422. for elem in apid_value['geometry']:
  423. if 'follow' in elem and isinstance(elem['follow'], Point):
  424. punching_geo.append(elem['follow'].buffer(dia / 2))
  425. elif ap_type == 'O' and self.ui.oblong_cb.get_value():
  426. width = float(apid_value['width'])
  427. height = float(apid_value['height'])
  428. if width > height:
  429. dia = float(apid_value['height']) - (2 * oblong_r_val)
  430. else:
  431. dia = float(apid_value['width']) - (2 * oblong_r_val)
  432. for elem in grb_obj.apertures[apid]['geometry']:
  433. if 'follow' in elem:
  434. if isinstance(elem['follow'], Point):
  435. punching_geo.append(elem['follow'].buffer(dia / 2))
  436. elif ap_type == 'R':
  437. width = float(apid_value['width'])
  438. height = float(apid_value['height'])
  439. # if the height == width (float numbers so the reason for the following)
  440. if round(width, self.decimals) == round(height, self.decimals):
  441. if self.ui.square_cb.get_value():
  442. dia = float(apid_value['height']) - (2 * square_r_val)
  443. for elem in grb_obj.apertures[apid]['geometry']:
  444. if 'follow' in elem:
  445. if isinstance(elem['follow'], Point):
  446. punching_geo.append(elem['follow'].buffer(dia / 2))
  447. elif self.ui.rectangular_cb.get_value():
  448. if width > height:
  449. dia = float(apid_value['height']) - (2 * rect_r_val)
  450. else:
  451. dia = float(apid_value['width']) - (2 * rect_r_val)
  452. for elem in grb_obj.apertures[apid]['geometry']:
  453. if 'follow' in elem:
  454. if isinstance(elem['follow'], Point):
  455. punching_geo.append(elem['follow'].buffer(dia / 2))
  456. elif self.ui.other_cb.get_value():
  457. try:
  458. dia = float(apid_value['size']) - (2 * other_r_val)
  459. except KeyError:
  460. if ap_type == 'AM':
  461. pol = apid_value['geometry'][0]['solid']
  462. x0, y0, x1, y1 = pol.bounds
  463. dx = x1 - x0
  464. dy = y1 - y0
  465. if dx <= dy:
  466. dia = dx - (2 * other_r_val)
  467. else:
  468. dia = dy - (2 * other_r_val)
  469. for elem in grb_obj.apertures[apid]['geometry']:
  470. if 'follow' in elem:
  471. if isinstance(elem['follow'], Point):
  472. punching_geo.append(elem['follow'].buffer(dia / 2))
  473. # if dia is None then none of the above applied so we skip the following
  474. if dia is None:
  475. continue
  476. punching_geo = MultiPolygon(punching_geo)
  477. if punching_geo is None or punching_geo.is_empty:
  478. continue
  479. punched_solid_geometry = punched_solid_geometry.difference(punching_geo)
  480. # update the gerber apertures to include the clear geometry so it can be exported successfully
  481. for elem in apid_value['geometry']:
  482. # make it work only for Gerber Flashes who are Points in 'follow'
  483. if 'solid' in elem and isinstance(elem['follow'], Point):
  484. clear_apid_size = dia
  485. for geo in punching_geo:
  486. # since there may be drills that do not drill into a pad we test only for geos in a pad
  487. if geo.within(elem['solid']):
  488. geo_elem = {}
  489. geo_elem['clear'] = geo.centroid
  490. if clear_apid_size not in holes_apertures:
  491. holes_apertures[clear_apid_size] = {}
  492. holes_apertures[clear_apid_size]['type'] = 'C'
  493. holes_apertures[clear_apid_size]['size'] = clear_apid_size
  494. holes_apertures[clear_apid_size]['geometry'] = []
  495. holes_apertures[clear_apid_size]['geometry'].append(deepcopy(geo_elem))
  496. # add the clear geometry to new apertures; it's easier than to test if there are apertures with the same
  497. # size and add there the clear geometry
  498. for hole_size, ap_val in holes_apertures.items():
  499. new_apid += 1
  500. new_apertures[str(new_apid)] = deepcopy(ap_val)
  501. def init_func(new_obj, app_obj):
  502. new_obj.options.update(new_options)
  503. new_obj.options['name'] = outname
  504. new_obj.fill_color = deepcopy(grb_obj.fill_color)
  505. new_obj.outline_color = deepcopy(grb_obj.outline_color)
  506. new_obj.apertures = deepcopy(new_apertures)
  507. new_obj.solid_geometry = deepcopy(punched_solid_geometry)
  508. new_obj.source_file = self.app.f_handlers.export_gerber(obj_name=outname, filename=None,
  509. local_use=new_obj, use_thread=False)
  510. self.app.app_obj.new_object('gerber', outname, init_func)
  511. def on_proportional_method(self, grb_obj, outname):
  512. prop_factor = self.ui.factor_entry.get_value() / 100.0
  513. dia = None
  514. new_options = {}
  515. for opt in grb_obj.options:
  516. new_options[opt] = deepcopy(grb_obj.options[opt])
  517. if isinstance(grb_obj.solid_geometry, list):
  518. temp_solid_geometry = MultiPolygon(grb_obj.solid_geometry)
  519. else:
  520. temp_solid_geometry = grb_obj.solid_geometry
  521. punched_solid_geometry = temp_solid_geometry
  522. new_apertures = deepcopy(grb_obj.apertures)
  523. new_apertures_items = new_apertures.items()
  524. # find maximum aperture id
  525. new_apid = max([int(x) for x, __ in new_apertures_items])
  526. # selected codes in the apertures UI table
  527. sel_apid = []
  528. for it in self.ui.apertures_table.selectedItems():
  529. sel_apid.append(it.text())
  530. # store here the clear geometry, the key is the new aperture size
  531. holes_apertures = {}
  532. for apid, apid_value in grb_obj.apertures.items():
  533. ap_type = apid_value['type']
  534. punching_geo = []
  535. if apid in sel_apid:
  536. if ap_type == 'C' and self.ui.circular_cb.get_value():
  537. dia = float(apid_value['size']) * prop_factor
  538. for elem in apid_value['geometry']:
  539. if 'follow' in elem and isinstance(elem['follow'], Point):
  540. punching_geo.append(elem['follow'].buffer(dia / 2))
  541. elif ap_type == 'O' and self.ui.oblong_cb.get_value():
  542. width = float(apid_value['width'])
  543. height = float(apid_value['height'])
  544. if width > height:
  545. dia = float(apid_value['height']) * prop_factor
  546. else:
  547. dia = float(apid_value['width']) * prop_factor
  548. for elem in grb_obj.apertures[apid]['geometry']:
  549. if 'follow' in elem:
  550. if isinstance(elem['follow'], Point):
  551. punching_geo.append(elem['follow'].buffer(dia / 2))
  552. elif ap_type == 'R':
  553. width = float(apid_value['width'])
  554. height = float(apid_value['height'])
  555. # if the height == width (float numbers so the reason for the following)
  556. if round(width, self.decimals) == round(height, self.decimals):
  557. if self.ui.square_cb.get_value():
  558. dia = float(apid_value['height']) * prop_factor
  559. for elem in grb_obj.apertures[apid]['geometry']:
  560. if 'follow' in elem:
  561. if isinstance(elem['follow'], Point):
  562. punching_geo.append(elem['follow'].buffer(dia / 2))
  563. elif self.ui.rectangular_cb.get_value():
  564. if width > height:
  565. dia = float(apid_value['height']) * prop_factor
  566. else:
  567. dia = float(apid_value['width']) * prop_factor
  568. for elem in grb_obj.apertures[apid]['geometry']:
  569. if 'follow' in elem:
  570. if isinstance(elem['follow'], Point):
  571. punching_geo.append(elem['follow'].buffer(dia / 2))
  572. elif self.ui.other_cb.get_value():
  573. try:
  574. dia = float(apid_value['size']) * prop_factor
  575. except KeyError:
  576. if ap_type == 'AM':
  577. pol = apid_value['geometry'][0]['solid']
  578. x0, y0, x1, y1 = pol.bounds
  579. dx = x1 - x0
  580. dy = y1 - y0
  581. if dx <= dy:
  582. dia = dx * prop_factor
  583. else:
  584. dia = dy * prop_factor
  585. for elem in grb_obj.apertures[apid]['geometry']:
  586. if 'follow' in elem:
  587. if isinstance(elem['follow'], Point):
  588. punching_geo.append(elem['follow'].buffer(dia / 2))
  589. # if dia is None then none of the above applied so we skip the following
  590. if dia is None:
  591. continue
  592. punching_geo = MultiPolygon(punching_geo)
  593. if punching_geo is None or punching_geo.is_empty:
  594. continue
  595. punched_solid_geometry = punched_solid_geometry.difference(punching_geo)
  596. # update the gerber apertures to include the clear geometry so it can be exported successfully
  597. for elem in apid_value['geometry']:
  598. # make it work only for Gerber Flashes who are Points in 'follow'
  599. if 'solid' in elem and isinstance(elem['follow'], Point):
  600. clear_apid_size = dia
  601. for geo in punching_geo:
  602. # since there may be drills that do not drill into a pad we test only for geos in a pad
  603. if geo.within(elem['solid']):
  604. geo_elem = {}
  605. geo_elem['clear'] = geo.centroid
  606. if clear_apid_size not in holes_apertures:
  607. holes_apertures[clear_apid_size] = {}
  608. holes_apertures[clear_apid_size]['type'] = 'C'
  609. holes_apertures[clear_apid_size]['size'] = clear_apid_size
  610. holes_apertures[clear_apid_size]['geometry'] = []
  611. holes_apertures[clear_apid_size]['geometry'].append(deepcopy(geo_elem))
  612. # add the clear geometry to new apertures; it's easier than to test if there are apertures with the same
  613. # size and add there the clear geometry
  614. for hole_size, ap_val in holes_apertures.items():
  615. new_apid += 1
  616. new_apertures[str(new_apid)] = deepcopy(ap_val)
  617. def init_func(new_obj, app_obj):
  618. new_obj.options.update(new_options)
  619. new_obj.options['name'] = outname
  620. new_obj.fill_color = deepcopy(grb_obj.fill_color)
  621. new_obj.outline_color = deepcopy(grb_obj.outline_color)
  622. new_obj.apertures = deepcopy(new_apertures)
  623. new_obj.solid_geometry = deepcopy(punched_solid_geometry)
  624. new_obj.source_file = self.app.f_handlers.export_gerber(obj_name=outname, filename=None,
  625. local_use=new_obj, use_thread=False)
  626. self.app.app_obj.new_object('gerber', outname, init_func)
  627. def reset_fields(self):
  628. self.ui.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  629. self.ui.exc_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  630. self.ui_disconnect()
  631. class PunchUI:
  632. toolName = _("Punch Gerber")
  633. def __init__(self, layout, app):
  634. self.app = app
  635. self.decimals = self.app.decimals
  636. self.layout = layout
  637. # ## Title
  638. title_label = QtWidgets.QLabel("%s" % self.toolName)
  639. title_label.setStyleSheet("""
  640. QLabel
  641. {
  642. font-size: 16px;
  643. font-weight: bold;
  644. }
  645. """)
  646. self.layout.addWidget(title_label)
  647. # Punch Drill holes
  648. self.layout.addWidget(QtWidgets.QLabel(""))
  649. # ## Grid Layout
  650. grid_lay = QtWidgets.QGridLayout()
  651. self.layout.addLayout(grid_lay)
  652. grid_lay.setColumnStretch(0, 1)
  653. grid_lay.setColumnStretch(1, 0)
  654. # ## Gerber Object
  655. self.gerber_object_combo = FCComboBox()
  656. self.gerber_object_combo.setModel(self.app.collection)
  657. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  658. self.gerber_object_combo.is_last = True
  659. self.gerber_object_combo.obj_type = "Gerber"
  660. self.grb_label = QtWidgets.QLabel("<b>%s:</b>" % _("GERBER"))
  661. self.grb_label.setToolTip('%s.' % _("Gerber into which to punch holes"))
  662. grid_lay.addWidget(self.grb_label, 0, 0, 1, 2)
  663. grid_lay.addWidget(self.gerber_object_combo, 1, 0, 1, 2)
  664. separator_line = QtWidgets.QFrame()
  665. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  666. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  667. grid_lay.addWidget(separator_line, 2, 0, 1, 2)
  668. self.padt_label = QtWidgets.QLabel("<b>%s</b>" % _("Processed Pads Type"))
  669. self.padt_label.setToolTip(
  670. _("The type of pads shape to be processed.\n"
  671. "If the PCB has many SMD pads with rectangular pads,\n"
  672. "disable the Rectangular aperture.")
  673. )
  674. grid_lay.addWidget(self.padt_label, 3, 0, 1, 2)
  675. pad_all_grid = QtWidgets.QGridLayout()
  676. pad_all_grid.setColumnStretch(0, 0)
  677. pad_all_grid.setColumnStretch(1, 1)
  678. grid_lay.addLayout(pad_all_grid, 5, 0, 1, 2)
  679. pad_grid = QtWidgets.QGridLayout()
  680. pad_grid.setColumnStretch(0, 0)
  681. pad_all_grid.addLayout(pad_grid, 0, 0)
  682. # Select all
  683. self.select_all_cb = FCCheckBox('%s' % _("ALL"))
  684. pad_grid.addWidget(self.select_all_cb, 0, 0)
  685. # Circular Aperture Selection
  686. self.circular_cb = FCCheckBox('%s' % _("Circular"))
  687. self.circular_cb.setToolTip(
  688. _("Process Circular Pads.")
  689. )
  690. pad_grid.addWidget(self.circular_cb, 1, 0)
  691. # Oblong Aperture Selection
  692. self.oblong_cb = FCCheckBox('%s' % _("Oblong"))
  693. self.oblong_cb.setToolTip(
  694. _("Process Oblong Pads.")
  695. )
  696. pad_grid.addWidget(self.oblong_cb, 2, 0)
  697. # Square Aperture Selection
  698. self.square_cb = FCCheckBox('%s' % _("Square"))
  699. self.square_cb.setToolTip(
  700. _("Process Square Pads.")
  701. )
  702. pad_grid.addWidget(self.square_cb, 3, 0)
  703. # Rectangular Aperture Selection
  704. self.rectangular_cb = FCCheckBox('%s' % _("Rectangular"))
  705. self.rectangular_cb.setToolTip(
  706. _("Process Rectangular Pads.")
  707. )
  708. pad_grid.addWidget(self.rectangular_cb, 4, 0)
  709. # Others type of Apertures Selection
  710. self.other_cb = FCCheckBox('%s' % _("Others"))
  711. self.other_cb.setToolTip(
  712. _("Process pads not in the categories above.")
  713. )
  714. pad_grid.addWidget(self.other_cb, 5, 0)
  715. # Aperture Table
  716. self.apertures_table = FCTable()
  717. pad_all_grid.addWidget(self.apertures_table, 0, 1)
  718. self.apertures_table.setColumnCount(3)
  719. self.apertures_table.setHorizontalHeaderLabels([_('Code'), _('Type'), _('Size')])
  720. self.apertures_table.setSortingEnabled(False)
  721. self.apertures_table.setRowCount(0)
  722. self.apertures_table.resizeColumnsToContents()
  723. self.apertures_table.resizeRowsToContents()
  724. self.apertures_table.horizontalHeaderItem(0).setToolTip(
  725. _("Aperture Code"))
  726. self.apertures_table.horizontalHeaderItem(1).setToolTip(
  727. _("Type of aperture: circular, rectangle, macros etc"))
  728. self.apertures_table.horizontalHeaderItem(2).setToolTip(
  729. _("Aperture Size:"))
  730. sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Preferred)
  731. self.apertures_table.setSizePolicy(sizePolicy)
  732. self.apertures_table.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
  733. separator_line = QtWidgets.QFrame()
  734. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  735. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  736. grid_lay.addWidget(separator_line, 10, 0, 1, 2)
  737. # Grid Layout
  738. grid0 = QtWidgets.QGridLayout()
  739. self.layout.addLayout(grid0)
  740. grid0.setColumnStretch(0, 0)
  741. grid0.setColumnStretch(1, 1)
  742. self.method_label = QtWidgets.QLabel('<b>%s:</b>' % _("Method"))
  743. self.method_label.setToolTip(
  744. _("The punch hole source can be:\n"
  745. "- Excellon Object-> the Excellon object drills center will serve as reference.\n"
  746. "- Fixed Diameter -> will try to use the pads center as reference adding fixed diameter holes.\n"
  747. "- Fixed Annular Ring -> will try to keep a set annular ring.\n"
  748. "- Proportional -> will make a Gerber punch hole having the diameter a percentage of the pad diameter.")
  749. )
  750. self.method_punch = RadioSet(
  751. [
  752. {'label': _('Excellon'), 'value': 'exc'},
  753. {'label': _("Fixed Diameter"), 'value': 'fixed'},
  754. {'label': _("Fixed Annular Ring"), 'value': 'ring'},
  755. {'label': _("Proportional"), 'value': 'prop'}
  756. ],
  757. orientation='vertical',
  758. stretch=False)
  759. grid0.addWidget(self.method_label, 0, 0, 1, 2)
  760. grid0.addWidget(self.method_punch, 1, 0, 1, 2)
  761. separator_line = QtWidgets.QFrame()
  762. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  763. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  764. grid0.addWidget(separator_line, 2, 0, 1, 2)
  765. self.exc_label = QtWidgets.QLabel('<b>%s</b>' % _("Excellon"))
  766. self.exc_label.setToolTip(
  767. _("Remove the geometry of Excellon from the Gerber to create the holes in pads.")
  768. )
  769. self.exc_combo = FCComboBox()
  770. self.exc_combo.setModel(self.app.collection)
  771. self.exc_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  772. self.exc_combo.is_last = True
  773. self.exc_combo.obj_type = "Excellon"
  774. grid0.addWidget(self.exc_label, 3, 0, 1, 2)
  775. grid0.addWidget(self.exc_combo, 4, 0, 1, 2)
  776. # Fixed Dia
  777. self.fixed_label = QtWidgets.QLabel('<b>%s</b>' % _("Fixed Diameter"))
  778. grid0.addWidget(self.fixed_label, 6, 0, 1, 2)
  779. # Diameter value
  780. self.dia_entry = FCDoubleSpinner(callback=self.confirmation_message)
  781. self.dia_entry.set_precision(self.decimals)
  782. self.dia_entry.set_range(0.0000, 9999.9999)
  783. self.dia_label = QtWidgets.QLabel('%s:' % _("Value"))
  784. self.dia_label.setToolTip(
  785. _("Fixed hole diameter.")
  786. )
  787. grid0.addWidget(self.dia_label, 8, 0)
  788. grid0.addWidget(self.dia_entry, 8, 1)
  789. # #############################################################################################################
  790. # RING FRAME
  791. # #############################################################################################################
  792. self.ring_frame = QtWidgets.QFrame()
  793. self.ring_frame.setContentsMargins(0, 0, 0, 0)
  794. grid0.addWidget(self.ring_frame, 10, 0, 1, 2)
  795. self.ring_box = QtWidgets.QVBoxLayout()
  796. self.ring_box.setContentsMargins(0, 0, 0, 0)
  797. self.ring_frame.setLayout(self.ring_box)
  798. # Annular Ring value
  799. self.ring_label = QtWidgets.QLabel('<b>%s</b>' % _("Fixed Annular Ring"))
  800. self.ring_label.setToolTip(
  801. _("The size of annular ring.\n"
  802. "The copper sliver between the hole exterior\n"
  803. "and the margin of the copper pad.")
  804. )
  805. self.ring_box.addWidget(self.ring_label)
  806. # ## Grid Layout
  807. self.grid1 = QtWidgets.QGridLayout()
  808. self.grid1.setColumnStretch(0, 0)
  809. self.grid1.setColumnStretch(1, 1)
  810. self.ring_box.addLayout(self.grid1)
  811. # Circular Annular Ring Value
  812. self.circular_ring_label = QtWidgets.QLabel('%s:' % _("Circular"))
  813. self.circular_ring_label.setToolTip(
  814. _("The size of annular ring for circular pads.")
  815. )
  816. self.circular_ring_entry = FCDoubleSpinner(callback=self.confirmation_message)
  817. self.circular_ring_entry.set_precision(self.decimals)
  818. self.circular_ring_entry.set_range(0.0000, 9999.9999)
  819. self.grid1.addWidget(self.circular_ring_label, 3, 0)
  820. self.grid1.addWidget(self.circular_ring_entry, 3, 1)
  821. # Oblong Annular Ring Value
  822. self.oblong_ring_label = QtWidgets.QLabel('%s:' % _("Oblong"))
  823. self.oblong_ring_label.setToolTip(
  824. _("The size of annular ring for oblong pads.")
  825. )
  826. self.oblong_ring_entry = FCDoubleSpinner(callback=self.confirmation_message)
  827. self.oblong_ring_entry.set_precision(self.decimals)
  828. self.oblong_ring_entry.set_range(0.0000, 9999.9999)
  829. self.grid1.addWidget(self.oblong_ring_label, 4, 0)
  830. self.grid1.addWidget(self.oblong_ring_entry, 4, 1)
  831. # Square Annular Ring Value
  832. self.square_ring_label = QtWidgets.QLabel('%s:' % _("Square"))
  833. self.square_ring_label.setToolTip(
  834. _("The size of annular ring for square pads.")
  835. )
  836. self.square_ring_entry = FCDoubleSpinner(callback=self.confirmation_message)
  837. self.square_ring_entry.set_precision(self.decimals)
  838. self.square_ring_entry.set_range(0.0000, 9999.9999)
  839. self.grid1.addWidget(self.square_ring_label, 5, 0)
  840. self.grid1.addWidget(self.square_ring_entry, 5, 1)
  841. # Rectangular Annular Ring Value
  842. self.rectangular_ring_label = QtWidgets.QLabel('%s:' % _("Rectangular"))
  843. self.rectangular_ring_label.setToolTip(
  844. _("The size of annular ring for rectangular pads.")
  845. )
  846. self.rectangular_ring_entry = FCDoubleSpinner(callback=self.confirmation_message)
  847. self.rectangular_ring_entry.set_precision(self.decimals)
  848. self.rectangular_ring_entry.set_range(0.0000, 9999.9999)
  849. self.grid1.addWidget(self.rectangular_ring_label, 6, 0)
  850. self.grid1.addWidget(self.rectangular_ring_entry, 6, 1)
  851. # Others Annular Ring Value
  852. self.other_ring_label = QtWidgets.QLabel('%s:' % _("Others"))
  853. self.other_ring_label.setToolTip(
  854. _("The size of annular ring for other pads.")
  855. )
  856. self.other_ring_entry = FCDoubleSpinner(callback=self.confirmation_message)
  857. self.other_ring_entry.set_precision(self.decimals)
  858. self.other_ring_entry.set_range(0.0000, 9999.9999)
  859. self.grid1.addWidget(self.other_ring_label, 7, 0)
  860. self.grid1.addWidget(self.other_ring_entry, 7, 1)
  861. # #############################################################################################################
  862. # Proportional value
  863. self.prop_label = QtWidgets.QLabel('<b>%s</b>' % _("Proportional Diameter"))
  864. grid0.addWidget(self.prop_label, 12, 0, 1, 2)
  865. # Diameter value
  866. self.factor_entry = FCDoubleSpinner(callback=self.confirmation_message, suffix='%')
  867. self.factor_entry.set_precision(self.decimals)
  868. self.factor_entry.set_range(0.0000, 100.0000)
  869. self.factor_entry.setSingleStep(0.1)
  870. self.factor_label = QtWidgets.QLabel('%s:' % _("Value"))
  871. self.factor_label.setToolTip(
  872. _("Proportional Diameter.\n"
  873. "The hole diameter will be a fraction of the pad size.")
  874. )
  875. grid0.addWidget(self.factor_label, 13, 0)
  876. grid0.addWidget(self.factor_entry, 13, 1)
  877. separator_line3 = QtWidgets.QFrame()
  878. separator_line3.setFrameShape(QtWidgets.QFrame.HLine)
  879. separator_line3.setFrameShadow(QtWidgets.QFrame.Sunken)
  880. grid0.addWidget(separator_line3, 14, 0, 1, 2)
  881. # Buttons
  882. self.punch_object_button = QtWidgets.QPushButton(_("Punch Gerber"))
  883. self.punch_object_button.setToolTip(
  884. _("Create a Gerber object from the selected object, within\n"
  885. "the specified box.")
  886. )
  887. self.punch_object_button.setStyleSheet("""
  888. QPushButton
  889. {
  890. font-weight: bold;
  891. }
  892. """)
  893. self.layout.addWidget(self.punch_object_button)
  894. self.layout.addStretch()
  895. # ## Reset Tool
  896. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  897. self.reset_button.setIcon(QtGui.QIcon(self.app.resource_location + '/reset32.png'))
  898. self.reset_button.setToolTip(
  899. _("Will reset the tool parameters.")
  900. )
  901. self.reset_button.setStyleSheet("""
  902. QPushButton
  903. {
  904. font-weight: bold;
  905. }
  906. """)
  907. self.layout.addWidget(self.reset_button)
  908. self.circular_ring_entry.setEnabled(False)
  909. self.oblong_ring_entry.setEnabled(False)
  910. self.square_ring_entry.setEnabled(False)
  911. self.rectangular_ring_entry.setEnabled(False)
  912. self.other_ring_entry.setEnabled(False)
  913. self.dia_entry.hide()
  914. self.dia_label.hide()
  915. self.factor_label.hide()
  916. self.factor_entry.hide()
  917. # #################################### FINSIHED GUI ###########################
  918. # #############################################################################
  919. def confirmation_message(self, accepted, minval, maxval):
  920. if accepted is False:
  921. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
  922. self.decimals,
  923. minval,
  924. self.decimals,
  925. maxval), False)
  926. else:
  927. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  928. def confirmation_message_int(self, accepted, minval, maxval):
  929. if accepted is False:
  930. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
  931. (_("Edited value is out of range"), minval, maxval), False)
  932. else:
  933. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)