ToolDblSided.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from appTool import AppTool
  3. from appGUI.GUIElements import RadioSet, FCDoubleSpinner, EvalEntry, FCEntry, FCButton, FCComboBox, FCCheckBox
  4. from numpy import Inf
  5. from shapely.geometry import Point
  6. from shapely import affinity
  7. import logging
  8. import gettext
  9. import appTranslation as fcTranslate
  10. import builtins
  11. fcTranslate.apply_language('strings')
  12. if '_' not in builtins.__dict__:
  13. _ = gettext.gettext
  14. log = logging.getLogger('base')
  15. class DblSidedTool(AppTool):
  16. def __init__(self, app):
  17. AppTool.__init__(self, app)
  18. self.decimals = self.app.decimals
  19. # #############################################################################
  20. # ######################### Tool GUI ##########################################
  21. # #############################################################################
  22. self.ui = DsidedUI(layout=self.layout, app=self.app)
  23. self.toolName = self.ui.toolName
  24. # ## Signals
  25. self.ui.mirror_gerber_button.clicked.connect(self.on_mirror_gerber)
  26. self.ui.mirror_exc_button.clicked.connect(self.on_mirror_exc)
  27. self.ui.mirror_geo_button.clicked.connect(self.on_mirror_geo)
  28. self.ui.add_point_button.clicked.connect(self.on_point_add)
  29. self.ui.add_drill_point_button.clicked.connect(self.on_drill_add)
  30. self.ui.delete_drill_point_button.clicked.connect(self.on_drill_delete_last)
  31. self.ui.box_type_radio.activated_custom.connect(self.on_combo_box_type)
  32. self.ui.axis_location.group_toggle_fn = self.on_toggle_pointbox
  33. self.ui.point_entry.textChanged.connect(lambda val: self.ui.align_ref_label_val.set_value(val))
  34. self.ui.xmin_btn.clicked.connect(self.on_xmin_clicked)
  35. self.ui.ymin_btn.clicked.connect(self.on_ymin_clicked)
  36. self.ui.xmax_btn.clicked.connect(self.on_xmax_clicked)
  37. self.ui.ymax_btn.clicked.connect(self.on_ymax_clicked)
  38. self.ui.center_btn.clicked.connect(
  39. lambda: self.ui.point_entry.set_value(self.ui.center_entry.get_value())
  40. )
  41. self.ui.create_alignment_hole_button.clicked.connect(self.on_create_alignment_holes)
  42. self.ui.calculate_bb_button.clicked.connect(self.on_bbox_coordinates)
  43. self.ui.reset_button.clicked.connect(self.set_tool_ui)
  44. self.drill_values = ""
  45. def install(self, icon=None, separator=None, **kwargs):
  46. AppTool.install(self, icon, separator, shortcut='Alt+D', **kwargs)
  47. def run(self, toggle=True):
  48. self.app.defaults.report_usage("Tool2Sided()")
  49. if toggle:
  50. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  51. if self.app.ui.splitter.sizes()[0] == 0:
  52. self.app.ui.splitter.setSizes([1, 1])
  53. else:
  54. try:
  55. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  56. # if tab is populated with the tool but it does not have the focus, focus on it
  57. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  58. # focus on Tool Tab
  59. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  60. else:
  61. self.app.ui.splitter.setSizes([0, 1])
  62. except AttributeError:
  63. pass
  64. else:
  65. if self.app.ui.splitter.sizes()[0] == 0:
  66. self.app.ui.splitter.setSizes([1, 1])
  67. AppTool.run(self)
  68. self.set_tool_ui()
  69. self.app.ui.notebook.setTabText(2, _("2-Sided Tool"))
  70. def set_tool_ui(self):
  71. self.reset_fields()
  72. self.ui.point_entry.set_value("")
  73. self.ui.alignment_holes.set_value("")
  74. self.ui.mirror_axis.set_value(self.app.defaults["tools_2sided_mirror_axis"])
  75. self.ui.axis_location.set_value(self.app.defaults["tools_2sided_axis_loc"])
  76. self.ui.drill_dia.set_value(self.app.defaults["tools_2sided_drilldia"])
  77. self.ui.align_axis_radio.set_value(self.app.defaults["tools_2sided_allign_axis"])
  78. self.ui.xmin_entry.set_value(0.0)
  79. self.ui.ymin_entry.set_value(0.0)
  80. self.ui.xmax_entry.set_value(0.0)
  81. self.ui.ymax_entry.set_value(0.0)
  82. self.ui.center_entry.set_value('')
  83. self.ui.align_ref_label_val.set_value('%.*f' % (self.decimals, 0.0))
  84. # run once to make sure that the obj_type attribute is updated in the FCComboBox
  85. self.ui.box_type_radio.set_value('grb')
  86. self.on_combo_box_type('grb')
  87. def on_combo_box_type(self, val):
  88. obj_type = {'grb': 0, 'exc': 1, 'geo': 2}[val]
  89. self.ui.box_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  90. self.ui.box_combo.setCurrentIndex(0)
  91. self.ui.box_combo.obj_type = {
  92. "grb": "Gerber", "exc": "Excellon", "geo": "Geometry"}[val]
  93. def on_create_alignment_holes(self):
  94. axis = self.ui.align_axis_radio.get_value()
  95. mode = self.ui.axis_location.get_value()
  96. if mode == "point":
  97. try:
  98. px, py = self.ui.point_entry.get_value()
  99. except TypeError:
  100. self.app.inform.emit('[WARNING_NOTCL] %s' % _("'Point' reference is selected and 'Point' coordinates "
  101. "are missing. Add them and retry."))
  102. return
  103. else:
  104. selection_index = self.ui.box_combo.currentIndex()
  105. model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex())
  106. try:
  107. bb_obj = model_index.internalPointer().obj
  108. except AttributeError:
  109. model_index = self.app.collection.index(selection_index, 0, self.ui.exc_object_combo.rootModelIndex())
  110. try:
  111. bb_obj = model_index.internalPointer().obj
  112. except AttributeError:
  113. model_index = self.app.collection.index(selection_index, 0,
  114. self.ui.geo_object_combo.rootModelIndex())
  115. try:
  116. bb_obj = model_index.internalPointer().obj
  117. except AttributeError:
  118. self.app.inform.emit(
  119. '[WARNING_NOTCL] %s' % _("There is no Box reference object loaded. Load one and retry."))
  120. return
  121. xmin, ymin, xmax, ymax = bb_obj.bounds()
  122. px = 0.5 * (xmin + xmax)
  123. py = 0.5 * (ymin + ymax)
  124. xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
  125. dia = float(self.drill_dia.get_value())
  126. if dia == '':
  127. self.app.inform.emit('[WARNING_NOTCL] %s' %
  128. _("No value or wrong format in Drill Dia entry. Add it and retry."))
  129. return
  130. tools = {}
  131. tools[1] = {}
  132. tools[1]["tooldia"] = dia
  133. tools[1]['solid_geometry'] = []
  134. # holes = self.alignment_holes.get_value()
  135. holes = eval('[{}]'.format(self.ui.alignment_holes.text()))
  136. if not holes:
  137. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There are no Alignment Drill Coordinates to use. "
  138. "Add them and retry."))
  139. return
  140. for hole in holes:
  141. point = Point(hole)
  142. point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
  143. tools[1]['drills'] = [point, point_mirror]
  144. tools[1]['solid_geometry'].append(point)
  145. tools[1]['solid_geometry'].append(point_mirror)
  146. def obj_init(obj_inst, app_inst):
  147. obj_inst.tools = tools
  148. obj_inst.create_geometry()
  149. obj_inst.source_file = app_inst.export_excellon(obj_name=obj_inst.options['name'], local_use=obj_inst,
  150. filename=None, use_thread=False)
  151. self.app.app_obj.new_object("excellon", "Alignment Drills", obj_init)
  152. self.drill_values = ''
  153. self.app.inform.emit('[success] %s' % _("Excellon object with alignment drills created..."))
  154. def on_mirror_gerber(self):
  155. selection_index = self.ui.gerber_object_combo.currentIndex()
  156. # fcobj = self.app.collection.object_list[selection_index]
  157. model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex())
  158. try:
  159. fcobj = model_index.internalPointer().obj
  160. except Exception:
  161. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
  162. return
  163. if fcobj.kind != 'gerber':
  164. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber, Excellon and Geometry objects can be mirrored."))
  165. return
  166. axis = self.ui.mirror_axis.get_value()
  167. mode = self.ui.axis_location.get_value()
  168. if mode == "point":
  169. try:
  170. px, py = self.ui.point_entry.get_value()
  171. except TypeError:
  172. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There are no Point coordinates in the Point field. "
  173. "Add coords and try again ..."))
  174. return
  175. else:
  176. selection_index_box = self.ui.box_combo.currentIndex()
  177. model_index_box = self.app.collection.index(selection_index_box, 0, self.ui.box_combo.rootModelIndex())
  178. try:
  179. bb_obj = model_index_box.internalPointer().obj
  180. except Exception:
  181. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
  182. return
  183. xmin, ymin, xmax, ymax = bb_obj.bounds()
  184. px = 0.5 * (xmin + xmax)
  185. py = 0.5 * (ymin + ymax)
  186. fcobj.mirror(axis, [px, py])
  187. self.app.app_obj.object_changed.emit(fcobj)
  188. fcobj.plot()
  189. self.app.inform.emit('[success] Gerber %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
  190. def on_mirror_exc(self):
  191. selection_index = self.ui.exc_object_combo.currentIndex()
  192. # fcobj = self.app.collection.object_list[selection_index]
  193. model_index = self.app.collection.index(selection_index, 0, self.ui.exc_object_combo.rootModelIndex())
  194. try:
  195. fcobj = model_index.internalPointer().obj
  196. except Exception:
  197. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Excellon object loaded ..."))
  198. return
  199. if fcobj.kind != 'excellon':
  200. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber, Excellon and Geometry objects can be mirrored."))
  201. return
  202. axis = self.ui.mirror_axis.get_value()
  203. mode = self.ui.axis_location.get_value()
  204. if mode == "point":
  205. try:
  206. px, py = self.ui.point_entry.get_value()
  207. except Exception as e:
  208. log.debug("DblSidedTool.on_mirror_geo() --> %s" % str(e))
  209. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There are no Point coordinates in the Point field. "
  210. "Add coords and try again ..."))
  211. return
  212. else:
  213. selection_index_box = self.ui.box_combo.currentIndex()
  214. model_index_box = self.app.collection.index(selection_index_box, 0, self.ui.box_combo.rootModelIndex())
  215. try:
  216. bb_obj = model_index_box.internalPointer().obj
  217. except Exception as e:
  218. log.debug("DblSidedTool.on_mirror_geo() --> %s" % str(e))
  219. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
  220. return
  221. xmin, ymin, xmax, ymax = bb_obj.bounds()
  222. px = 0.5 * (xmin + xmax)
  223. py = 0.5 * (ymin + ymax)
  224. fcobj.mirror(axis, [px, py])
  225. self.app.app_obj.object_changed.emit(fcobj)
  226. fcobj.plot()
  227. self.app.inform.emit('[success] Excellon %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
  228. def on_mirror_geo(self):
  229. selection_index = self.ui.geo_object_combo.currentIndex()
  230. # fcobj = self.app.collection.object_list[selection_index]
  231. model_index = self.app.collection.index(selection_index, 0, self.ui.geo_object_combo.rootModelIndex())
  232. try:
  233. fcobj = model_index.internalPointer().obj
  234. except Exception:
  235. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Geometry object loaded ..."))
  236. return
  237. if fcobj.kind != 'geometry':
  238. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber, Excellon and Geometry objects can be mirrored."))
  239. return
  240. axis = self.ui.mirror_axis.get_value()
  241. mode = self.ui.axis_location.get_value()
  242. if mode == "point":
  243. px, py = self.ui.point_entry.get_value()
  244. else:
  245. selection_index_box = self.ui.box_combo.currentIndex()
  246. model_index_box = self.app.collection.index(selection_index_box, 0, self.ui.box_combo.rootModelIndex())
  247. try:
  248. bb_obj = model_index_box.internalPointer().obj
  249. except Exception:
  250. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
  251. return
  252. xmin, ymin, xmax, ymax = bb_obj.bounds()
  253. px = 0.5 * (xmin + xmax)
  254. py = 0.5 * (ymin + ymax)
  255. fcobj.mirror(axis, [px, py])
  256. self.app.app_obj.object_changed.emit(fcobj)
  257. fcobj.plot()
  258. self.app.inform.emit('[success] Geometry %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
  259. def on_point_add(self):
  260. val = self.app.defaults["global_point_clipboard_format"] % \
  261. (self.decimals, self.app.pos[0], self.decimals, self.app.pos[1])
  262. self.ui.point_entry.set_value(val)
  263. def on_drill_add(self):
  264. self.drill_values += (self.app.defaults["global_point_clipboard_format"] %
  265. (self.decimals, self.app.pos[0], self.decimals, self.app.pos[1])) + ','
  266. self.ui.alignment_holes.set_value(self.drill_values)
  267. def on_drill_delete_last(self):
  268. drill_values_without_last_tupple = self.drill_values.rpartition('(')[0]
  269. self.drill_values = drill_values_without_last_tupple
  270. self.ui.alignment_holes.set_value(self.drill_values)
  271. def on_toggle_pointbox(self):
  272. val = self.ui.axis_location.get_value()
  273. if val == "point":
  274. self.ui.point_entry.show()
  275. self.ui.add_point_button.show()
  276. self.ui.box_type_label.hide()
  277. self.ui.box_type_radio.hide()
  278. self.ui.box_combo.hide()
  279. self.ui.exc_hole_lbl.hide()
  280. self.ui.exc_combo.hide()
  281. self.ui.pick_hole_button.hide()
  282. self.ui.align_ref_label_val.set_value(self.ui.point_entry.get_value())
  283. elif val == 'box':
  284. self.ui.point_entry.hide()
  285. self.ui.add_point_button.hide()
  286. self.ui.box_type_label.show()
  287. self.ui.box_type_radio.show()
  288. self.ui.box_combo.show()
  289. self.ui.exc_hole_lbl.hide()
  290. self.ui.exc_combo.hide()
  291. self.ui.pick_hole_button.hide()
  292. self.ui.align_ref_label_val.set_value("Box centroid")
  293. elif val == 'hole':
  294. self.ui.point_entry.show()
  295. self.ui.add_point_button.hide()
  296. self.ui.box_type_label.hide()
  297. self.ui.box_type_radio.hide()
  298. self.ui.box_combo.hide()
  299. self.ui.exc_hole_lbl.show()
  300. self.ui.exc_combo.show()
  301. self.ui.pick_hole_button.show()
  302. def on_bbox_coordinates(self):
  303. xmin = Inf
  304. ymin = Inf
  305. xmax = -Inf
  306. ymax = -Inf
  307. obj_list = self.app.collection.get_selected()
  308. if not obj_list:
  309. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed. No object(s) selected..."))
  310. return
  311. for obj in obj_list:
  312. try:
  313. gxmin, gymin, gxmax, gymax = obj.bounds()
  314. xmin = min([xmin, gxmin])
  315. ymin = min([ymin, gymin])
  316. xmax = max([xmax, gxmax])
  317. ymax = max([ymax, gymax])
  318. except Exception as e:
  319. log.warning("DEV WARNING: Tried to get bounds of empty geometry in DblSidedTool. %s" % str(e))
  320. self.ui.xmin_entry.set_value(xmin)
  321. self.ui.ymin_entry.set_value(ymin)
  322. self.ui.xmax_entry.set_value(xmax)
  323. self.ui.ymax_entry.set_value(ymax)
  324. cx = '%.*f' % (self.decimals, (((xmax - xmin) / 2.0) + xmin))
  325. cy = '%.*f' % (self.decimals, (((ymax - ymin) / 2.0) + ymin))
  326. val_txt = '(%s, %s)' % (cx, cy)
  327. self.ui.center_entry.set_value(val_txt)
  328. self.ui.axis_location.set_value('point')
  329. self.ui.point_entry.set_value(val_txt)
  330. self.app.delete_selection_shape()
  331. def on_xmin_clicked(self):
  332. xmin = self.ui.xmin_entry.get_value()
  333. self.ui.axis_location.set_value('point')
  334. try:
  335. px, py = self.ui.point_entry.get_value()
  336. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmin, self.decimals, py)
  337. except TypeError:
  338. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmin, self.decimals, 0.0)
  339. self.ui.point_entry.set_value(val)
  340. def on_ymin_clicked(self):
  341. ymin = self.ui.ymin_entry.get_value()
  342. self.ui.axis_location.set_value('point')
  343. try:
  344. px, py = self.ui.point_entry.get_value()
  345. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, px, self.decimals, ymin)
  346. except TypeError:
  347. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, 0.0, self.decimals, ymin)
  348. self.ui.point_entry.set_value(val)
  349. def on_xmax_clicked(self):
  350. xmax = self.ui.xmax_entry.get_value()
  351. self.ui.axis_location.set_value('point')
  352. try:
  353. px, py = self.ui.point_entry.get_value()
  354. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmax, self.decimals, py)
  355. except TypeError:
  356. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmax, self.decimals, 0.0)
  357. self.ui.point_entry.set_value(val)
  358. def on_ymax_clicked(self):
  359. ymax = self.ui.ymax_entry.get_value()
  360. self.ui.axis_location.set_value('point')
  361. try:
  362. px, py = self.ui.point_entry.get_value()
  363. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, px, self.decimals, ymax)
  364. except TypeError:
  365. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, 0.0, self.decimals, ymax)
  366. self.ui.point_entry.set_value(val)
  367. def reset_fields(self):
  368. self.ui.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  369. self.ui.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  370. self.ui.geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  371. self.ui.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  372. self.ui.gerber_object_combo.setCurrentIndex(0)
  373. self.ui.exc_object_combo.setCurrentIndex(0)
  374. self.ui.geo_object_combo.setCurrentIndex(0)
  375. self.ui.box_combo.setCurrentIndex(0)
  376. self.ui.box_type_radio.set_value('grb')
  377. self.drill_values = ""
  378. self.ui.align_ref_label_val.set_value('')
  379. class DsidedUI:
  380. toolName = _("2-Sided PCB")
  381. def __init__(self, layout, app):
  382. self.app = app
  383. self.decimals = self.app.decimals
  384. self.layout = layout
  385. # ## Title
  386. title_label = QtWidgets.QLabel("%s" % self.toolName)
  387. title_label.setStyleSheet("""
  388. QLabel
  389. {
  390. font-size: 16px;
  391. font-weight: bold;
  392. }
  393. """)
  394. self.layout.addWidget(title_label)
  395. self.layout.addWidget(QtWidgets.QLabel(""))
  396. # ## Grid Layout
  397. grid_lay = QtWidgets.QGridLayout()
  398. grid_lay.setColumnStretch(0, 1)
  399. grid_lay.setColumnStretch(1, 0)
  400. self.layout.addLayout(grid_lay)
  401. # Objects to be mirrored
  402. self.m_objects_label = QtWidgets.QLabel("<b>%s:</b>" % _("Mirror Operation"))
  403. self.m_objects_label.setToolTip('%s.' % _("Objects to be mirrored"))
  404. grid_lay.addWidget(self.m_objects_label, 0, 0, 1, 2)
  405. # ## Gerber Object to mirror
  406. self.gerber_object_combo = FCComboBox()
  407. self.gerber_object_combo.setModel(self.app.collection)
  408. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  409. self.gerber_object_combo.is_last = True
  410. self.gerber_object_combo.obj_type = "Gerber"
  411. self.botlay_label = QtWidgets.QLabel("%s:" % _("GERBER"))
  412. self.botlay_label.setToolTip('%s.' % _("Gerber to be mirrored"))
  413. self.mirror_gerber_button = QtWidgets.QPushButton(_("Mirror"))
  414. self.mirror_gerber_button.setToolTip(
  415. _("Mirrors (flips) the specified object around \n"
  416. "the specified axis. Does not create a new \n"
  417. "object, but modifies it.")
  418. )
  419. self.mirror_gerber_button.setStyleSheet("""
  420. QPushButton
  421. {
  422. font-weight: bold;
  423. }
  424. """)
  425. self.mirror_gerber_button.setMinimumWidth(60)
  426. grid_lay.addWidget(self.botlay_label, 1, 0)
  427. grid_lay.addWidget(self.gerber_object_combo, 2, 0)
  428. grid_lay.addWidget(self.mirror_gerber_button, 2, 1)
  429. # ## Excellon Object to mirror
  430. self.exc_object_combo = FCComboBox()
  431. self.exc_object_combo.setModel(self.app.collection)
  432. self.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  433. self.exc_object_combo.is_last = True
  434. self.exc_object_combo.obj_type = "Excellon"
  435. self.excobj_label = QtWidgets.QLabel("%s:" % _("EXCELLON"))
  436. self.excobj_label.setToolTip(_("Excellon Object to be mirrored."))
  437. self.mirror_exc_button = QtWidgets.QPushButton(_("Mirror"))
  438. self.mirror_exc_button.setToolTip(
  439. _("Mirrors (flips) the specified object around \n"
  440. "the specified axis. Does not create a new \n"
  441. "object, but modifies it.")
  442. )
  443. self.mirror_exc_button.setStyleSheet("""
  444. QPushButton
  445. {
  446. font-weight: bold;
  447. }
  448. """)
  449. self.mirror_exc_button.setMinimumWidth(60)
  450. grid_lay.addWidget(self.excobj_label, 3, 0)
  451. grid_lay.addWidget(self.exc_object_combo, 4, 0)
  452. grid_lay.addWidget(self.mirror_exc_button, 4, 1)
  453. # ## Geometry Object to mirror
  454. self.geo_object_combo = FCComboBox()
  455. self.geo_object_combo.setModel(self.app.collection)
  456. self.geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  457. self.geo_object_combo.is_last = True
  458. self.geo_object_combo.obj_type = "Geometry"
  459. self.geoobj_label = QtWidgets.QLabel("%s:" % _("GEOMETRY"))
  460. self.geoobj_label.setToolTip(
  461. _("Geometry Obj to be mirrored.")
  462. )
  463. self.mirror_geo_button = QtWidgets.QPushButton(_("Mirror"))
  464. self.mirror_geo_button.setToolTip(
  465. _("Mirrors (flips) the specified object around \n"
  466. "the specified axis. Does not create a new \n"
  467. "object, but modifies it.")
  468. )
  469. self.mirror_geo_button.setStyleSheet("""
  470. QPushButton
  471. {
  472. font-weight: bold;
  473. }
  474. """)
  475. self.mirror_geo_button.setMinimumWidth(60)
  476. # grid_lay.addRow("Bottom Layer:", self.object_combo)
  477. grid_lay.addWidget(self.geoobj_label, 5, 0)
  478. grid_lay.addWidget(self.geo_object_combo, 6, 0)
  479. grid_lay.addWidget(self.mirror_geo_button, 6, 1)
  480. separator_line = QtWidgets.QFrame()
  481. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  482. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  483. grid_lay.addWidget(separator_line, 7, 0, 1, 2)
  484. self.layout.addWidget(QtWidgets.QLabel(""))
  485. # ## Grid Layout
  486. grid_lay1 = QtWidgets.QGridLayout()
  487. grid_lay1.setColumnStretch(0, 0)
  488. grid_lay1.setColumnStretch(1, 1)
  489. self.layout.addLayout(grid_lay1)
  490. # Objects to be mirrored
  491. self.param_label = QtWidgets.QLabel("<b>%s:</b>" % _("Mirror Parameters"))
  492. self.param_label.setToolTip('%s.' % _("Parameters for the mirror operation"))
  493. grid_lay1.addWidget(self.param_label, 0, 0, 1, 2)
  494. # ## Axis
  495. self.mirax_label = QtWidgets.QLabel('%s:' % _("Mirror Axis"))
  496. self.mirax_label.setToolTip(_("Mirror vertically (X) or horizontally (Y)."))
  497. self.mirror_axis = RadioSet([{'label': 'X', 'value': 'X'},
  498. {'label': 'Y', 'value': 'Y'}])
  499. grid_lay1.addWidget(self.mirax_label, 2, 0)
  500. grid_lay1.addWidget(self.mirror_axis, 2, 1, 1, 2)
  501. # ## Axis Location
  502. self.axloc_label = QtWidgets.QLabel('%s:' % _("Reference"))
  503. self.axloc_label.setToolTip(
  504. _("The coordinates used as reference for the mirror operation.\n"
  505. "Can be:\n"
  506. "- Point -> a set of coordinates (x,y) around which the object is mirrored\n"
  507. "- Box -> a set of coordinates (x, y) obtained from the center of the\n"
  508. "bounding box of another object selected below\n"
  509. "- Hole Snap -> a point defined by the center of a drill hone in a Excellon object")
  510. )
  511. self.axis_location = RadioSet(
  512. [
  513. {'label': _('Point'), 'value': 'point'},
  514. {'label': _('Box'), 'value': 'box'},
  515. {'label': _('Hole Snap'), 'value': 'hole'},
  516. ]
  517. )
  518. grid_lay1.addWidget(self.axloc_label, 4, 0)
  519. grid_lay1.addWidget(self.axis_location, 4, 1, 1, 2)
  520. # ## Point/Box
  521. self.point_entry = EvalEntry()
  522. self.point_entry.setPlaceholderText(_("Point coordinates"))
  523. # Add a reference
  524. self.add_point_button = QtWidgets.QPushButton(_("Add"))
  525. self.add_point_button.setToolTip(
  526. _("Add the coordinates in format <b>(x, y)</b> through which the mirroring axis\n "
  527. "selected in 'MIRROR AXIS' pass.\n"
  528. "The (x, y) coordinates are captured by pressing SHIFT key\n"
  529. "and left mouse button click on canvas or you can enter the coordinates manually.")
  530. )
  531. self.add_point_button.setStyleSheet("""
  532. QPushButton
  533. {
  534. font-weight: bold;
  535. }
  536. """)
  537. self.add_point_button.setMinimumWidth(60)
  538. grid_lay1.addWidget(self.point_entry, 7, 0, 1, 2)
  539. grid_lay1.addWidget(self.add_point_button, 7, 2)
  540. self.exc_hole_lbl = QtWidgets.QLabel('%s:' % _("Excellon"))
  541. self.exc_hole_lbl.setToolTip(
  542. _("Object that holds holes that can be picked as reference for mirroing.")
  543. )
  544. # Excellon Object that holds the holes
  545. self.exc_combo = FCComboBox()
  546. self.exc_combo.setModel(self.app.collection)
  547. self.exc_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  548. self.exc_combo.is_last = True
  549. self.exc_hole_lbl.hide()
  550. self.exc_combo.hide()
  551. grid_lay1.addWidget(self.exc_hole_lbl, 10, 0)
  552. grid_lay1.addWidget(self.exc_combo, 10, 1, 1, 2)
  553. self.pick_hole_button = FCButton(_("Pick hole"))
  554. self.pick_hole_button.setToolTip(
  555. _("Click inside a drill hole that belong to the selected Excellon object,\n"
  556. "and the hole center coordinates will be copied to the Point field.")
  557. )
  558. self.pick_hole_button.hide()
  559. grid_lay1.addWidget(self.pick_hole_button, 12, 0, 1, 3)
  560. # ## Grid Layout
  561. grid_lay3 = QtWidgets.QGridLayout()
  562. grid_lay3.setColumnStretch(0, 0)
  563. grid_lay3.setColumnStretch(1, 1)
  564. self.layout.addLayout(grid_lay3)
  565. self.box_type_label = QtWidgets.QLabel('%s:' % _("Reference Object"))
  566. self.box_type_label.setToolTip(
  567. _("It can be of type: Gerber or Excellon or Geometry.\n"
  568. "The coordinates of the center of the bounding box are used\n"
  569. "as reference for mirror operation.")
  570. )
  571. # Type of object used as BOX reference
  572. self.box_type_radio = RadioSet([{'label': _('Gerber'), 'value': 'grb'},
  573. {'label': _('Excellon'), 'value': 'exc'},
  574. {'label': _('Geometry'), 'value': 'geo'}])
  575. self.box_type_label.hide()
  576. self.box_type_radio.hide()
  577. grid_lay3.addWidget(self.box_type_label, 0, 0, 1, 2)
  578. grid_lay3.addWidget(self.box_type_radio, 1, 0, 1, 2)
  579. # Object used as BOX reference
  580. self.box_combo = FCComboBox()
  581. self.box_combo.setModel(self.app.collection)
  582. self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  583. self.box_combo.is_last = True
  584. self.box_combo.hide()
  585. grid_lay3.addWidget(self.box_combo, 3, 0, 1, 2)
  586. separator_line = QtWidgets.QFrame()
  587. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  588. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  589. grid_lay3.addWidget(separator_line, 4, 0, 1, 2)
  590. grid_lay3.addWidget(QtWidgets.QLabel(""), 5, 0, 1, 2)
  591. # ## Title Bounds Values
  592. self.bv_label = QtWidgets.QLabel("<b>%s:</b>" % _('Bounds Values'))
  593. self.bv_label.setToolTip(
  594. _("Select on canvas the object(s)\n"
  595. "for which to calculate bounds values.")
  596. )
  597. grid_lay3.addWidget(self.bv_label, 6, 0, 1, 2)
  598. # Xmin value
  599. self.xmin_entry = FCDoubleSpinner(callback=self.confirmation_message)
  600. self.xmin_entry.set_precision(self.decimals)
  601. self.xmin_entry.set_range(-9999.9999, 9999.9999)
  602. self.xmin_btn = FCButton('%s:' % _("X min"))
  603. self.xmin_btn.setToolTip(
  604. _("Minimum location.")
  605. )
  606. self.xmin_entry.setReadOnly(True)
  607. grid_lay3.addWidget(self.xmin_btn, 7, 0)
  608. grid_lay3.addWidget(self.xmin_entry, 7, 1)
  609. # Ymin value
  610. self.ymin_entry = FCDoubleSpinner(callback=self.confirmation_message)
  611. self.ymin_entry.set_precision(self.decimals)
  612. self.ymin_entry.set_range(-9999.9999, 9999.9999)
  613. self.ymin_btn = FCButton('%s:' % _("Y min"))
  614. self.ymin_btn.setToolTip(
  615. _("Minimum location.")
  616. )
  617. self.ymin_entry.setReadOnly(True)
  618. grid_lay3.addWidget(self.ymin_btn, 8, 0)
  619. grid_lay3.addWidget(self.ymin_entry, 8, 1)
  620. # Xmax value
  621. self.xmax_entry = FCDoubleSpinner(callback=self.confirmation_message)
  622. self.xmax_entry.set_precision(self.decimals)
  623. self.xmax_entry.set_range(-9999.9999, 9999.9999)
  624. self.xmax_btn = FCButton('%s:' % _("X max"))
  625. self.xmax_btn.setToolTip(
  626. _("Maximum location.")
  627. )
  628. self.xmax_entry.setReadOnly(True)
  629. grid_lay3.addWidget(self.xmax_btn, 9, 0)
  630. grid_lay3.addWidget(self.xmax_entry, 9, 1)
  631. # Ymax value
  632. self.ymax_entry = FCDoubleSpinner(callback=self.confirmation_message)
  633. self.ymax_entry.set_precision(self.decimals)
  634. self.ymax_entry.set_range(-9999.9999, 9999.9999)
  635. self.ymax_btn = FCButton('%s:' % _("Y max"))
  636. self.ymax_btn.setToolTip(
  637. _("Maximum location.")
  638. )
  639. self.ymax_entry.setReadOnly(True)
  640. grid_lay3.addWidget(self.ymax_btn, 10, 0)
  641. grid_lay3.addWidget(self.ymax_entry, 10, 1)
  642. # Center point value
  643. self.center_entry = FCEntry()
  644. self.center_entry.setPlaceholderText(_("Center point coordinates"))
  645. self.center_btn = FCButton('%s:' % _("Centroid"))
  646. self.center_btn.setToolTip(
  647. _("The center point location for the rectangular\n"
  648. "bounding shape. Centroid. Format is (x, y).")
  649. )
  650. self.center_entry.setReadOnly(True)
  651. grid_lay3.addWidget(self.center_btn, 12, 0)
  652. grid_lay3.addWidget(self.center_entry, 12, 1)
  653. # Calculate Bounding box
  654. self.calculate_bb_button = QtWidgets.QPushButton(_("Calculate Bounds Values"))
  655. self.calculate_bb_button.setToolTip(
  656. _("Calculate the enveloping rectangular shape coordinates,\n"
  657. "for the selection of objects.\n"
  658. "The envelope shape is parallel with the X, Y axis.")
  659. )
  660. self.calculate_bb_button.setStyleSheet("""
  661. QPushButton
  662. {
  663. font-weight: bold;
  664. }
  665. """)
  666. grid_lay3.addWidget(self.calculate_bb_button, 13, 0, 1, 2)
  667. separator_line = QtWidgets.QFrame()
  668. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  669. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  670. grid_lay3.addWidget(separator_line, 14, 0, 1, 2)
  671. grid_lay3.addWidget(QtWidgets.QLabel(""), 15, 0, 1, 2)
  672. # ## Alignment holes
  673. self.alignment_label = QtWidgets.QLabel("<b>%s:</b>" % _('PCB Alignment'))
  674. self.alignment_label.setToolTip(
  675. _("Creates an Excellon Object containing the\n"
  676. "specified alignment holes and their mirror\n"
  677. "images.")
  678. )
  679. grid_lay3.addWidget(self.alignment_label, 25, 0, 1, 2)
  680. # ## Drill diameter for alignment holes
  681. self.dt_label = QtWidgets.QLabel("%s:" % _('Drill Diameter'))
  682. self.dt_label.setToolTip(
  683. _("Diameter of the drill for the alignment holes.")
  684. )
  685. self.drill_dia = FCDoubleSpinner(callback=self.confirmation_message)
  686. self.drill_dia.setToolTip(
  687. _("Diameter of the drill for the alignment holes.")
  688. )
  689. self.drill_dia.set_precision(self.decimals)
  690. self.drill_dia.set_range(0.0000, 9999.9999)
  691. grid_lay3.addWidget(self.dt_label, 26, 0)
  692. grid_lay3.addWidget(self.drill_dia, 26, 1)
  693. # ## Alignment Axis
  694. self.align_ax_label = QtWidgets.QLabel('%s:' % _("Align Axis"))
  695. self.align_ax_label.setToolTip(
  696. _("Mirror vertically (X) or horizontally (Y).")
  697. )
  698. self.align_axis_radio = RadioSet([{'label': 'X', 'value': 'X'},
  699. {'label': 'Y', 'value': 'Y'}])
  700. grid_lay3.addWidget(self.align_ax_label, 27, 0)
  701. grid_lay3.addWidget(self.align_axis_radio, 27, 1)
  702. # ## Alignment Reference Point
  703. self.align_ref_label = QtWidgets.QLabel('%s:' % _("Reference"))
  704. self.align_ref_label.setToolTip(
  705. _("The reference point used to create the second alignment drill\n"
  706. "from the first alignment drill, by doing mirror.\n"
  707. "It can be modified in the Mirror Parameters -> Reference section")
  708. )
  709. self.align_ref_label_val = EvalEntry()
  710. self.align_ref_label_val.setToolTip(
  711. _("The reference point used to create the second alignment drill\n"
  712. "from the first alignment drill, by doing mirror.\n"
  713. "It can be modified in the Mirror Parameters -> Reference section")
  714. )
  715. self.align_ref_label_val.setDisabled(True)
  716. grid_lay3.addWidget(self.align_ref_label, 28, 0)
  717. grid_lay3.addWidget(self.align_ref_label_val, 28, 1)
  718. grid_lay4 = QtWidgets.QGridLayout()
  719. self.layout.addLayout(grid_lay4)
  720. # ## Alignment holes
  721. self.ah_label = QtWidgets.QLabel("%s:" % _('Alignment Drill Coordinates'))
  722. self.ah_label.setToolTip(
  723. _("Alignment holes (x1, y1), (x2, y2), ... "
  724. "on one side of the mirror axis. For each set of (x, y) coordinates\n"
  725. "entered here, a pair of drills will be created:\n\n"
  726. "- one drill at the coordinates from the field\n"
  727. "- one drill in mirror position over the axis selected above in the 'Align Axis'.")
  728. )
  729. self.alignment_holes = EvalEntry()
  730. self.alignment_holes.setPlaceholderText(_("Drill coordinates"))
  731. grid_lay4.addWidget(self.ah_label, 0, 0, 1, 2)
  732. grid_lay4.addWidget(self.alignment_holes, 1, 0, 1, 2)
  733. self.add_drill_point_button = FCButton(_("Add"))
  734. self.add_drill_point_button.setToolTip(
  735. _("Add alignment drill holes coordinates in the format: (x1, y1), (x2, y2), ... \n"
  736. "on one side of the alignment axis.\n\n"
  737. "The coordinates set can be obtained:\n"
  738. "- press SHIFT key and left mouse clicking on canvas. Then click Add.\n"
  739. "- press SHIFT key and left mouse clicking on canvas. Then Ctrl+V in the field.\n"
  740. "- press SHIFT key and left mouse clicking on canvas. Then RMB click in the field and click Paste.\n"
  741. "- by entering the coords manually in the format: (x1, y1), (x2, y2), ...")
  742. )
  743. # self.add_drill_point_button.setStyleSheet("""
  744. # QPushButton
  745. # {
  746. # font-weight: bold;
  747. # }
  748. # """)
  749. self.delete_drill_point_button = FCButton(_("Delete Last"))
  750. self.delete_drill_point_button.setToolTip(
  751. _("Delete the last coordinates tuple in the list.")
  752. )
  753. drill_hlay = QtWidgets.QHBoxLayout()
  754. drill_hlay.addWidget(self.add_drill_point_button)
  755. drill_hlay.addWidget(self.delete_drill_point_button)
  756. grid_lay4.addLayout(drill_hlay, 2, 0, 1, 2)
  757. # ## Buttons
  758. self.create_alignment_hole_button = QtWidgets.QPushButton(_("Create Excellon Object"))
  759. self.create_alignment_hole_button.setToolTip(
  760. _("Creates an Excellon Object containing the\n"
  761. "specified alignment holes and their mirror\n"
  762. "images.")
  763. )
  764. self.create_alignment_hole_button.setStyleSheet("""
  765. QPushButton
  766. {
  767. font-weight: bold;
  768. }
  769. """)
  770. self.layout.addWidget(self.create_alignment_hole_button)
  771. self.layout.addStretch()
  772. # ## Reset Tool
  773. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  774. self.reset_button.setIcon(QtGui.QIcon(self.app.resource_location + '/reset32.png'))
  775. self.reset_button.setToolTip(
  776. _("Will reset the tool parameters.")
  777. )
  778. self.reset_button.setStyleSheet("""
  779. QPushButton
  780. {
  781. font-weight: bold;
  782. }
  783. """)
  784. self.layout.addWidget(self.reset_button)
  785. # #################################### FINSIHED GUI ###########################
  786. # #############################################################################
  787. def confirmation_message(self, accepted, minval, maxval):
  788. if accepted is False:
  789. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
  790. self.decimals,
  791. minval,
  792. self.decimals,
  793. maxval), False)
  794. else:
  795. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  796. def confirmation_message_int(self, accepted, minval, maxval):
  797. if accepted is False:
  798. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
  799. (_("Edited value is out of range"), minval, maxval), False)
  800. else:
  801. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)