ToolDblSided.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. from PyQt5 import QtWidgets, QtCore
  2. from appTool import AppTool
  3. from appGUI.GUIElements import RadioSet, FCDoubleSpinner, EvalEntry, FCEntry, FCButton, FCComboBox
  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. if self.ui.axis_location.get_value() == "point":
  273. self.ui.point_entry.show()
  274. self.ui.add_point_button.show()
  275. self.ui.box_type_label.hide()
  276. self.ui.box_type_radio.hide()
  277. self.ui.box_combo.hide()
  278. self.ui.align_ref_label_val.set_value(self.ui.point_entry.get_value())
  279. else:
  280. self.ui.point_entry.hide()
  281. self.ui.add_point_button.hide()
  282. self.ui.box_type_label.show()
  283. self.ui.box_type_radio.show()
  284. self.ui.box_combo.show()
  285. self.ui.align_ref_label_val.set_value("Box centroid")
  286. def on_bbox_coordinates(self):
  287. xmin = Inf
  288. ymin = Inf
  289. xmax = -Inf
  290. ymax = -Inf
  291. obj_list = self.app.collection.get_selected()
  292. if not obj_list:
  293. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed. No object(s) selected..."))
  294. return
  295. for obj in obj_list:
  296. try:
  297. gxmin, gymin, gxmax, gymax = obj.bounds()
  298. xmin = min([xmin, gxmin])
  299. ymin = min([ymin, gymin])
  300. xmax = max([xmax, gxmax])
  301. ymax = max([ymax, gymax])
  302. except Exception as e:
  303. log.warning("DEV WARNING: Tried to get bounds of empty geometry in DblSidedTool. %s" % str(e))
  304. self.ui.xmin_entry.set_value(xmin)
  305. self.ui.ymin_entry.set_value(ymin)
  306. self.ui.xmax_entry.set_value(xmax)
  307. self.ui.ymax_entry.set_value(ymax)
  308. cx = '%.*f' % (self.decimals, (((xmax - xmin) / 2.0) + xmin))
  309. cy = '%.*f' % (self.decimals, (((ymax - ymin) / 2.0) + ymin))
  310. val_txt = '(%s, %s)' % (cx, cy)
  311. self.ui.center_entry.set_value(val_txt)
  312. self.ui.axis_location.set_value('point')
  313. self.ui.point_entry.set_value(val_txt)
  314. self.app.delete_selection_shape()
  315. def on_xmin_clicked(self):
  316. xmin = self.ui.xmin_entry.get_value()
  317. self.ui.axis_location.set_value('point')
  318. try:
  319. px, py = self.ui.point_entry.get_value()
  320. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmin, self.decimals, py)
  321. except TypeError:
  322. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmin, self.decimals, 0.0)
  323. self.ui.point_entry.set_value(val)
  324. def on_ymin_clicked(self):
  325. ymin = self.ui.ymin_entry.get_value()
  326. self.ui.axis_location.set_value('point')
  327. try:
  328. px, py = self.ui.point_entry.get_value()
  329. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, px, self.decimals, ymin)
  330. except TypeError:
  331. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, 0.0, self.decimals, ymin)
  332. self.ui.point_entry.set_value(val)
  333. def on_xmax_clicked(self):
  334. xmax = self.ui.xmax_entry.get_value()
  335. self.ui.axis_location.set_value('point')
  336. try:
  337. px, py = self.ui.point_entry.get_value()
  338. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmax, self.decimals, py)
  339. except TypeError:
  340. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, xmax, self.decimals, 0.0)
  341. self.ui.point_entry.set_value(val)
  342. def on_ymax_clicked(self):
  343. ymax = self.ui.ymax_entry.get_value()
  344. self.ui.axis_location.set_value('point')
  345. try:
  346. px, py = self.ui.point_entry.get_value()
  347. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, px, self.decimals, ymax)
  348. except TypeError:
  349. val = self.app.defaults["global_point_clipboard_format"] % (self.decimals, 0.0, self.decimals, ymax)
  350. self.ui.point_entry.set_value(val)
  351. def reset_fields(self):
  352. self.ui.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  353. self.ui.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  354. self.ui.geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  355. self.ui.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  356. self.ui.gerber_object_combo.setCurrentIndex(0)
  357. self.ui.exc_object_combo.setCurrentIndex(0)
  358. self.ui.geo_object_combo.setCurrentIndex(0)
  359. self.ui.box_combo.setCurrentIndex(0)
  360. self.ui.box_type_radio.set_value('grb')
  361. self.drill_values = ""
  362. self.ui.align_ref_label_val.set_value('')
  363. class DsidedUI:
  364. toolName = _("2-Sided PCB")
  365. def __init__(self, layout, app):
  366. self.app = app
  367. self.decimals = self.app.decimals
  368. self.layout = layout
  369. # ## Title
  370. title_label = QtWidgets.QLabel("%s" % self.toolName)
  371. title_label.setStyleSheet("""
  372. QLabel
  373. {
  374. font-size: 16px;
  375. font-weight: bold;
  376. }
  377. """)
  378. self.layout.addWidget(title_label)
  379. self.layout.addWidget(QtWidgets.QLabel(""))
  380. # ## Grid Layout
  381. grid_lay = QtWidgets.QGridLayout()
  382. grid_lay.setColumnStretch(0, 1)
  383. grid_lay.setColumnStretch(1, 0)
  384. self.layout.addLayout(grid_lay)
  385. # Objects to be mirrored
  386. self.m_objects_label = QtWidgets.QLabel("<b>%s:</b>" % _("Mirror Operation"))
  387. self.m_objects_label.setToolTip('%s.' % _("Objects to be mirrored"))
  388. grid_lay.addWidget(self.m_objects_label, 0, 0, 1, 2)
  389. # ## Gerber Object to mirror
  390. self.gerber_object_combo = FCComboBox()
  391. self.gerber_object_combo.setModel(self.app.collection)
  392. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  393. self.gerber_object_combo.is_last = True
  394. self.gerber_object_combo.obj_type = "Gerber"
  395. self.botlay_label = QtWidgets.QLabel("%s:" % _("GERBER"))
  396. self.botlay_label.setToolTip('%s.' % _("Gerber to be mirrored"))
  397. self.mirror_gerber_button = QtWidgets.QPushButton(_("Mirror"))
  398. self.mirror_gerber_button.setToolTip(
  399. _("Mirrors (flips) the specified object around \n"
  400. "the specified axis. Does not create a new \n"
  401. "object, but modifies it.")
  402. )
  403. self.mirror_gerber_button.setStyleSheet("""
  404. QPushButton
  405. {
  406. font-weight: bold;
  407. }
  408. """)
  409. self.mirror_gerber_button.setMinimumWidth(60)
  410. grid_lay.addWidget(self.botlay_label, 1, 0)
  411. grid_lay.addWidget(self.gerber_object_combo, 2, 0)
  412. grid_lay.addWidget(self.mirror_gerber_button, 2, 1)
  413. # ## Excellon Object to mirror
  414. self.exc_object_combo = FCComboBox()
  415. self.exc_object_combo.setModel(self.app.collection)
  416. self.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  417. self.exc_object_combo.is_last = True
  418. self.exc_object_combo.obj_type = "Excellon"
  419. self.excobj_label = QtWidgets.QLabel("%s:" % _("EXCELLON"))
  420. self.excobj_label.setToolTip(_("Excellon Object to be mirrored."))
  421. self.mirror_exc_button = QtWidgets.QPushButton(_("Mirror"))
  422. self.mirror_exc_button.setToolTip(
  423. _("Mirrors (flips) the specified object around \n"
  424. "the specified axis. Does not create a new \n"
  425. "object, but modifies it.")
  426. )
  427. self.mirror_exc_button.setStyleSheet("""
  428. QPushButton
  429. {
  430. font-weight: bold;
  431. }
  432. """)
  433. self.mirror_exc_button.setMinimumWidth(60)
  434. grid_lay.addWidget(self.excobj_label, 3, 0)
  435. grid_lay.addWidget(self.exc_object_combo, 4, 0)
  436. grid_lay.addWidget(self.mirror_exc_button, 4, 1)
  437. # ## Geometry Object to mirror
  438. self.geo_object_combo = FCComboBox()
  439. self.geo_object_combo.setModel(self.app.collection)
  440. self.geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  441. self.geo_object_combo.is_last = True
  442. self.geo_object_combo.obj_type = "Geometry"
  443. self.geoobj_label = QtWidgets.QLabel("%s:" % _("GEOMETRY"))
  444. self.geoobj_label.setToolTip(
  445. _("Geometry Obj to be mirrored.")
  446. )
  447. self.mirror_geo_button = QtWidgets.QPushButton(_("Mirror"))
  448. self.mirror_geo_button.setToolTip(
  449. _("Mirrors (flips) the specified object around \n"
  450. "the specified axis. Does not create a new \n"
  451. "object, but modifies it.")
  452. )
  453. self.mirror_geo_button.setStyleSheet("""
  454. QPushButton
  455. {
  456. font-weight: bold;
  457. }
  458. """)
  459. self.mirror_geo_button.setMinimumWidth(60)
  460. # grid_lay.addRow("Bottom Layer:", self.object_combo)
  461. grid_lay.addWidget(self.geoobj_label, 5, 0)
  462. grid_lay.addWidget(self.geo_object_combo, 6, 0)
  463. grid_lay.addWidget(self.mirror_geo_button, 6, 1)
  464. separator_line = QtWidgets.QFrame()
  465. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  466. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  467. grid_lay.addWidget(separator_line, 7, 0, 1, 2)
  468. self.layout.addWidget(QtWidgets.QLabel(""))
  469. # ## Grid Layout
  470. grid_lay1 = QtWidgets.QGridLayout()
  471. grid_lay1.setColumnStretch(0, 0)
  472. grid_lay1.setColumnStretch(1, 1)
  473. self.layout.addLayout(grid_lay1)
  474. # Objects to be mirrored
  475. self.param_label = QtWidgets.QLabel("<b>%s:</b>" % _("Mirror Parameters"))
  476. self.param_label.setToolTip('%s.' % _("Parameters for the mirror operation"))
  477. grid_lay1.addWidget(self.param_label, 0, 0, 1, 2)
  478. # ## Axis
  479. self.mirax_label = QtWidgets.QLabel('%s:' % _("Mirror Axis"))
  480. self.mirax_label.setToolTip(_("Mirror vertically (X) or horizontally (Y)."))
  481. self.mirror_axis = RadioSet([{'label': 'X', 'value': 'X'},
  482. {'label': 'Y', 'value': 'Y'}])
  483. grid_lay1.addWidget(self.mirax_label, 2, 0)
  484. grid_lay1.addWidget(self.mirror_axis, 2, 1, 1, 2)
  485. # ## Axis Location
  486. self.axloc_label = QtWidgets.QLabel('%s:' % _("Reference"))
  487. self.axloc_label.setToolTip(
  488. _("The coordinates used as reference for the mirror operation.\n"
  489. "Can be:\n"
  490. "- Point -> a set of coordinates (x,y) around which the object is mirrored\n"
  491. "- Box -> a set of coordinates (x, y) obtained from the center of the\n"
  492. "bounding box of another object selected below")
  493. )
  494. self.axis_location = RadioSet([{'label': _('Point'), 'value': 'point'},
  495. {'label': _('Box'), 'value': 'box'}])
  496. grid_lay1.addWidget(self.axloc_label, 4, 0)
  497. grid_lay1.addWidget(self.axis_location, 4, 1, 1, 2)
  498. # ## Point/Box
  499. self.point_entry = EvalEntry()
  500. self.point_entry.setPlaceholderText(_("Point coordinates"))
  501. # Add a reference
  502. self.add_point_button = QtWidgets.QPushButton(_("Add"))
  503. self.add_point_button.setToolTip(
  504. _("Add the coordinates in format <b>(x, y)</b> through which the mirroring axis\n "
  505. "selected in 'MIRROR AXIS' pass.\n"
  506. "The (x, y) coordinates are captured by pressing SHIFT key\n"
  507. "and left mouse button click on canvas or you can enter the coordinates manually.")
  508. )
  509. self.add_point_button.setStyleSheet("""
  510. QPushButton
  511. {
  512. font-weight: bold;
  513. }
  514. """)
  515. self.add_point_button.setMinimumWidth(60)
  516. grid_lay1.addWidget(self.point_entry, 7, 0, 1, 2)
  517. grid_lay1.addWidget(self.add_point_button, 7, 2)
  518. # ## Grid Layout
  519. grid_lay2 = QtWidgets.QGridLayout()
  520. grid_lay2.setColumnStretch(0, 0)
  521. grid_lay2.setColumnStretch(1, 1)
  522. self.layout.addLayout(grid_lay2)
  523. self.box_type_label = QtWidgets.QLabel('%s:' % _("Reference Object"))
  524. self.box_type_label.setToolTip(
  525. _("It can be of type: Gerber or Excellon or Geometry.\n"
  526. "The coordinates of the center of the bounding box are used\n"
  527. "as reference for mirror operation.")
  528. )
  529. # Type of object used as BOX reference
  530. self.box_type_radio = RadioSet([{'label': _('Gerber'), 'value': 'grb'},
  531. {'label': _('Excellon'), 'value': 'exc'},
  532. {'label': _('Geometry'), 'value': 'geo'}])
  533. self.box_type_label.hide()
  534. self.box_type_radio.hide()
  535. grid_lay2.addWidget(self.box_type_label, 0, 0, 1, 2)
  536. grid_lay2.addWidget(self.box_type_radio, 1, 0, 1, 2)
  537. # Object used as BOX reference
  538. self.box_combo = FCComboBox()
  539. self.box_combo.setModel(self.app.collection)
  540. self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  541. self.box_combo.is_last = True
  542. self.box_combo.hide()
  543. grid_lay2.addWidget(self.box_combo, 3, 0, 1, 2)
  544. separator_line = QtWidgets.QFrame()
  545. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  546. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  547. grid_lay2.addWidget(separator_line, 4, 0, 1, 2)
  548. grid_lay2.addWidget(QtWidgets.QLabel(""), 5, 0, 1, 2)
  549. # ## Title Bounds Values
  550. self.bv_label = QtWidgets.QLabel("<b>%s:</b>" % _('Bounds Values'))
  551. self.bv_label.setToolTip(
  552. _("Select on canvas the object(s)\n"
  553. "for which to calculate bounds values.")
  554. )
  555. grid_lay2.addWidget(self.bv_label, 6, 0, 1, 2)
  556. # Xmin value
  557. self.xmin_entry = FCDoubleSpinner(callback=self.confirmation_message)
  558. self.xmin_entry.set_precision(self.decimals)
  559. self.xmin_entry.set_range(-9999.9999, 9999.9999)
  560. self.xmin_btn = FCButton('%s:' % _("X min"))
  561. self.xmin_btn.setToolTip(
  562. _("Minimum location.")
  563. )
  564. self.xmin_entry.setReadOnly(True)
  565. grid_lay2.addWidget(self.xmin_btn, 7, 0)
  566. grid_lay2.addWidget(self.xmin_entry, 7, 1)
  567. # Ymin value
  568. self.ymin_entry = FCDoubleSpinner(callback=self.confirmation_message)
  569. self.ymin_entry.set_precision(self.decimals)
  570. self.ymin_entry.set_range(-9999.9999, 9999.9999)
  571. self.ymin_btn = FCButton('%s:' % _("Y min"))
  572. self.ymin_btn.setToolTip(
  573. _("Minimum location.")
  574. )
  575. self.ymin_entry.setReadOnly(True)
  576. grid_lay2.addWidget(self.ymin_btn, 8, 0)
  577. grid_lay2.addWidget(self.ymin_entry, 8, 1)
  578. # Xmax value
  579. self.xmax_entry = FCDoubleSpinner(callback=self.confirmation_message)
  580. self.xmax_entry.set_precision(self.decimals)
  581. self.xmax_entry.set_range(-9999.9999, 9999.9999)
  582. self.xmax_btn = FCButton('%s:' % _("X max"))
  583. self.xmax_btn.setToolTip(
  584. _("Maximum location.")
  585. )
  586. self.xmax_entry.setReadOnly(True)
  587. grid_lay2.addWidget(self.xmax_btn, 9, 0)
  588. grid_lay2.addWidget(self.xmax_entry, 9, 1)
  589. # Ymax value
  590. self.ymax_entry = FCDoubleSpinner(callback=self.confirmation_message)
  591. self.ymax_entry.set_precision(self.decimals)
  592. self.ymax_entry.set_range(-9999.9999, 9999.9999)
  593. self.ymax_btn = FCButton('%s:' % _("Y max"))
  594. self.ymax_btn.setToolTip(
  595. _("Maximum location.")
  596. )
  597. self.ymax_entry.setReadOnly(True)
  598. grid_lay2.addWidget(self.ymax_btn, 10, 0)
  599. grid_lay2.addWidget(self.ymax_entry, 10, 1)
  600. # Center point value
  601. self.center_entry = FCEntry()
  602. self.center_entry.setPlaceholderText(_("Center point coordinates"))
  603. self.center_btn = FCButton('%s:' % _("Centroid"))
  604. self.center_btn.setToolTip(
  605. _("The center point location for the rectangular\n"
  606. "bounding shape. Centroid. Format is (x, y).")
  607. )
  608. self.center_entry.setReadOnly(True)
  609. grid_lay2.addWidget(self.center_btn, 12, 0)
  610. grid_lay2.addWidget(self.center_entry, 12, 1)
  611. # Calculate Bounding box
  612. self.calculate_bb_button = QtWidgets.QPushButton(_("Calculate Bounds Values"))
  613. self.calculate_bb_button.setToolTip(
  614. _("Calculate the enveloping rectangular shape coordinates,\n"
  615. "for the selection of objects.\n"
  616. "The envelope shape is parallel with the X, Y axis.")
  617. )
  618. self.calculate_bb_button.setStyleSheet("""
  619. QPushButton
  620. {
  621. font-weight: bold;
  622. }
  623. """)
  624. grid_lay2.addWidget(self.calculate_bb_button, 13, 0, 1, 2)
  625. separator_line = QtWidgets.QFrame()
  626. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  627. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  628. grid_lay2.addWidget(separator_line, 14, 0, 1, 2)
  629. grid_lay2.addWidget(QtWidgets.QLabel(""), 15, 0, 1, 2)
  630. # ## Alignment holes
  631. self.alignment_label = QtWidgets.QLabel("<b>%s:</b>" % _('PCB Alignment'))
  632. self.alignment_label.setToolTip(
  633. _("Creates an Excellon Object containing the\n"
  634. "specified alignment holes and their mirror\n"
  635. "images.")
  636. )
  637. grid_lay2.addWidget(self.alignment_label, 25, 0, 1, 2)
  638. # ## Drill diameter for alignment holes
  639. self.dt_label = QtWidgets.QLabel("%s:" % _('Drill Diameter'))
  640. self.dt_label.setToolTip(
  641. _("Diameter of the drill for the alignment holes.")
  642. )
  643. self.drill_dia = FCDoubleSpinner(callback=self.confirmation_message)
  644. self.drill_dia.setToolTip(
  645. _("Diameter of the drill for the alignment holes.")
  646. )
  647. self.drill_dia.set_precision(self.decimals)
  648. self.drill_dia.set_range(0.0000, 9999.9999)
  649. grid_lay2.addWidget(self.dt_label, 26, 0)
  650. grid_lay2.addWidget(self.drill_dia, 26, 1)
  651. # ## Alignment Axis
  652. self.align_ax_label = QtWidgets.QLabel('%s:' % _("Align Axis"))
  653. self.align_ax_label.setToolTip(
  654. _("Mirror vertically (X) or horizontally (Y).")
  655. )
  656. self.align_axis_radio = RadioSet([{'label': 'X', 'value': 'X'},
  657. {'label': 'Y', 'value': 'Y'}])
  658. grid_lay2.addWidget(self.align_ax_label, 27, 0)
  659. grid_lay2.addWidget(self.align_axis_radio, 27, 1)
  660. # ## Alignment Reference Point
  661. self.align_ref_label = QtWidgets.QLabel('%s:' % _("Reference"))
  662. self.align_ref_label.setToolTip(
  663. _("The reference point used to create the second alignment drill\n"
  664. "from the first alignment drill, by doing mirror.\n"
  665. "It can be modified in the Mirror Parameters -> Reference section")
  666. )
  667. self.align_ref_label_val = EvalEntry()
  668. self.align_ref_label_val.setToolTip(
  669. _("The reference point used to create the second alignment drill\n"
  670. "from the first alignment drill, by doing mirror.\n"
  671. "It can be modified in the Mirror Parameters -> Reference section")
  672. )
  673. self.align_ref_label_val.setDisabled(True)
  674. grid_lay2.addWidget(self.align_ref_label, 28, 0)
  675. grid_lay2.addWidget(self.align_ref_label_val, 28, 1)
  676. grid_lay4 = QtWidgets.QGridLayout()
  677. self.layout.addLayout(grid_lay4)
  678. # ## Alignment holes
  679. self.ah_label = QtWidgets.QLabel("%s:" % _('Alignment Drill Coordinates'))
  680. self.ah_label.setToolTip(
  681. _("Alignment holes (x1, y1), (x2, y2), ... "
  682. "on one side of the mirror axis. For each set of (x, y) coordinates\n"
  683. "entered here, a pair of drills will be created:\n\n"
  684. "- one drill at the coordinates from the field\n"
  685. "- one drill in mirror position over the axis selected above in the 'Align Axis'.")
  686. )
  687. self.alignment_holes = EvalEntry()
  688. self.alignment_holes.setPlaceholderText(_("Drill coordinates"))
  689. grid_lay4.addWidget(self.ah_label, 0, 0, 1, 2)
  690. grid_lay4.addWidget(self.alignment_holes, 1, 0, 1, 2)
  691. self.add_drill_point_button = FCButton(_("Add"))
  692. self.add_drill_point_button.setToolTip(
  693. _("Add alignment drill holes coordinates in the format: (x1, y1), (x2, y2), ... \n"
  694. "on one side of the alignment axis.\n\n"
  695. "The coordinates set can be obtained:\n"
  696. "- press SHIFT key and left mouse clicking on canvas. Then click Add.\n"
  697. "- press SHIFT key and left mouse clicking on canvas. Then Ctrl+V in the field.\n"
  698. "- press SHIFT key and left mouse clicking on canvas. Then RMB click in the field and click Paste.\n"
  699. "- by entering the coords manually in the format: (x1, y1), (x2, y2), ...")
  700. )
  701. # self.add_drill_point_button.setStyleSheet("""
  702. # QPushButton
  703. # {
  704. # font-weight: bold;
  705. # }
  706. # """)
  707. self.delete_drill_point_button = FCButton(_("Delete Last"))
  708. self.delete_drill_point_button.setToolTip(
  709. _("Delete the last coordinates tuple in the list.")
  710. )
  711. drill_hlay = QtWidgets.QHBoxLayout()
  712. drill_hlay.addWidget(self.add_drill_point_button)
  713. drill_hlay.addWidget(self.delete_drill_point_button)
  714. grid_lay4.addLayout(drill_hlay, 2, 0, 1, 2)
  715. # ## Buttons
  716. self.create_alignment_hole_button = QtWidgets.QPushButton(_("Create Excellon Object"))
  717. self.create_alignment_hole_button.setToolTip(
  718. _("Creates an Excellon Object containing the\n"
  719. "specified alignment holes and their mirror\n"
  720. "images.")
  721. )
  722. self.create_alignment_hole_button.setStyleSheet("""
  723. QPushButton
  724. {
  725. font-weight: bold;
  726. }
  727. """)
  728. self.layout.addWidget(self.create_alignment_hole_button)
  729. self.layout.addStretch()
  730. # ## Reset Tool
  731. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  732. self.reset_button.setToolTip(
  733. _("Will reset the tool parameters.")
  734. )
  735. self.reset_button.setStyleSheet("""
  736. QPushButton
  737. {
  738. font-weight: bold;
  739. }
  740. """)
  741. self.layout.addWidget(self.reset_button)
  742. # #################################### FINSIHED GUI ###########################
  743. # #############################################################################
  744. def confirmation_message(self, accepted, minval, maxval):
  745. if accepted is False:
  746. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
  747. self.decimals,
  748. minval,
  749. self.decimals,
  750. maxval), False)
  751. else:
  752. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  753. def confirmation_message_int(self, accepted, minval, maxval):
  754. if accepted is False:
  755. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
  756. (_("Edited value is out of range"), minval, maxval), False)
  757. else:
  758. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)