ToolDblSided.py 36 KB

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