ToolDblSided.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. from FlatCAMTool import FlatCAMTool
  2. from FlatCAMObj import *
  3. from shapely.geometry import Point
  4. from shapely import affinity
  5. from PyQt5 import QtCore
  6. import gettext
  7. import FlatCAMTranslation as fcTranslate
  8. import builtins
  9. fcTranslate.apply_language('strings')
  10. if '_' not in builtins.__dict__:
  11. _ = gettext.gettext
  12. class DblSidedTool(FlatCAMTool):
  13. toolName = _("2-Sided PCB")
  14. def __init__(self, app):
  15. FlatCAMTool.__init__(self, app)
  16. # ## Title
  17. title_label = QtWidgets.QLabel("%s" % self.toolName)
  18. title_label.setStyleSheet("""
  19. QLabel
  20. {
  21. font-size: 16px;
  22. font-weight: bold;
  23. }
  24. """)
  25. self.layout.addWidget(title_label)
  26. self.empty_lb = QtWidgets.QLabel("")
  27. self.layout.addWidget(self.empty_lb)
  28. # ## Grid Layout
  29. grid_lay = QtWidgets.QGridLayout()
  30. self.layout.addLayout(grid_lay)
  31. # ## Gerber Object to mirror
  32. self.gerber_object_combo = QtWidgets.QComboBox()
  33. self.gerber_object_combo.setModel(self.app.collection)
  34. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  35. self.gerber_object_combo.setCurrentIndex(1)
  36. self.botlay_label = QtWidgets.QLabel("<b>%s:</b>" % _("GERBER"))
  37. self.botlay_label.setToolTip(
  38. "Gerber to be mirrored."
  39. )
  40. self.mirror_gerber_button = QtWidgets.QPushButton(_("Mirror"))
  41. self.mirror_gerber_button.setToolTip(
  42. _("Mirrors (flips) the specified object around \n"
  43. "the specified axis. Does not create a new \n"
  44. "object, but modifies it.")
  45. )
  46. self.mirror_gerber_button.setMinimumWidth(60)
  47. # grid_lay.addRow("Bottom Layer:", self.object_combo)
  48. grid_lay.addWidget(self.botlay_label, 0, 0)
  49. grid_lay.addWidget(self.gerber_object_combo, 1, 0)
  50. grid_lay.addWidget(self.mirror_gerber_button, 1, 1)
  51. # ## Excellon Object to mirror
  52. self.exc_object_combo = QtWidgets.QComboBox()
  53. self.exc_object_combo.setModel(self.app.collection)
  54. self.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  55. self.exc_object_combo.setCurrentIndex(1)
  56. self.excobj_label = QtWidgets.QLabel("<b>%s:</b>" % _("EXCELLON"))
  57. self.excobj_label.setToolTip(
  58. _("Excellon Object to be mirrored.")
  59. )
  60. self.mirror_exc_button = QtWidgets.QPushButton(_("Mirror"))
  61. self.mirror_exc_button.setToolTip(
  62. _("Mirrors (flips) the specified object around \n"
  63. "the specified axis. Does not create a new \n"
  64. "object, but modifies it.")
  65. )
  66. self.mirror_exc_button.setMinimumWidth(60)
  67. # grid_lay.addRow("Bottom Layer:", self.object_combo)
  68. grid_lay.addWidget(self.excobj_label, 2, 0)
  69. grid_lay.addWidget(self.exc_object_combo, 3, 0)
  70. grid_lay.addWidget(self.mirror_exc_button, 3, 1)
  71. # ## Geometry Object to mirror
  72. self.geo_object_combo = QtWidgets.QComboBox()
  73. self.geo_object_combo.setModel(self.app.collection)
  74. self.geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  75. self.geo_object_combo.setCurrentIndex(1)
  76. self.geoobj_label = QtWidgets.QLabel("<b>%s</b>:" % _("GEOMETRY"))
  77. self.geoobj_label.setToolTip(
  78. _("Geometry Obj to be mirrored.")
  79. )
  80. self.mirror_geo_button = QtWidgets.QPushButton(_("Mirror"))
  81. self.mirror_geo_button.setToolTip(
  82. _("Mirrors (flips) the specified object around \n"
  83. "the specified axis. Does not create a new \n"
  84. "object, but modifies it.")
  85. )
  86. self.mirror_geo_button.setMinimumWidth(60)
  87. # grid_lay.addRow("Bottom Layer:", self.object_combo)
  88. grid_lay.addWidget(self.geoobj_label, 4, 0)
  89. grid_lay.addWidget(self.geo_object_combo, 5, 0)
  90. grid_lay.addWidget(self.mirror_geo_button, 5, 1)
  91. # ## Grid Layout
  92. grid_lay1 = QtWidgets.QGridLayout()
  93. self.layout.addLayout(grid_lay1)
  94. # ## Axis
  95. self.mirror_axis = RadioSet([{'label': 'X', 'value': 'X'},
  96. {'label': 'Y', 'value': 'Y'}])
  97. self.mirax_label = QtWidgets.QLabel(_("Mirror Axis:"))
  98. self.mirax_label.setToolTip(
  99. _("Mirror vertically (X) or horizontally (Y).")
  100. )
  101. # grid_lay.addRow("Mirror Axis:", self.mirror_axis)
  102. self.empty_lb1 = QtWidgets.QLabel("")
  103. grid_lay1.addWidget(self.empty_lb1, 6, 0)
  104. grid_lay1.addWidget(self.mirax_label, 7, 0)
  105. grid_lay1.addWidget(self.mirror_axis, 7, 1)
  106. # ## Axis Location
  107. self.axis_location = RadioSet([{'label': _('Point'), 'value': 'point'},
  108. {'label': _('Box'), 'value': 'box'}])
  109. self.axloc_label = QtWidgets.QLabel(_("Axis Ref:"))
  110. self.axloc_label.setToolTip(
  111. _("The axis should pass through a <b>point</b> or cut\n "
  112. "a specified <b>box</b> (in a FlatCAM object) through \n"
  113. "the center.")
  114. )
  115. # grid_lay.addRow("Axis Location:", self.axis_location)
  116. grid_lay1.addWidget(self.axloc_label, 8, 0)
  117. grid_lay1.addWidget(self.axis_location, 8, 1)
  118. self.empty_lb2 = QtWidgets.QLabel("")
  119. grid_lay1.addWidget(self.empty_lb2, 9, 0)
  120. # ## Grid Layout
  121. grid_lay2 = QtWidgets.QGridLayout()
  122. self.layout.addLayout(grid_lay2)
  123. # ## Point/Box
  124. self.point_box_container = QtWidgets.QVBoxLayout()
  125. self.pb_label = QtWidgets.QLabel("<b>%s:</b>" % _('Point/Box Reference'))
  126. self.pb_label.setToolTip(
  127. _("If 'Point' is selected above it store the coordinates (x, y) through which\n"
  128. "the mirroring axis passes.\n"
  129. "If 'Box' is selected above, select here a FlatCAM object (Gerber, Exc or Geo).\n"
  130. "Through the center of this object pass the mirroring axis selected above.")
  131. )
  132. self.add_point_button = QtWidgets.QPushButton(_("Add"))
  133. self.add_point_button.setToolTip(
  134. _("Add the coordinates in format <b>(x, y)</b> through which the mirroring axis \n "
  135. "selected in 'MIRROR AXIS' pass.\n"
  136. "The (x, y) coordinates are captured by pressing SHIFT key\n"
  137. "and left mouse button click on canvas or you can enter the coords manually.")
  138. )
  139. self.add_point_button.setMinimumWidth(60)
  140. grid_lay2.addWidget(self.pb_label, 10, 0)
  141. grid_lay2.addLayout(self.point_box_container, 11, 0)
  142. grid_lay2.addWidget(self.add_point_button, 11, 1)
  143. self.point_entry = EvalEntry()
  144. self.point_box_container.addWidget(self.point_entry)
  145. self.box_combo = QtWidgets.QComboBox()
  146. self.box_combo.setModel(self.app.collection)
  147. self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  148. self.box_combo.setCurrentIndex(1)
  149. self.box_combo_type = QtWidgets.QComboBox()
  150. self.box_combo_type.addItem(_("Gerber Reference Box Object"))
  151. self.box_combo_type.addItem(_("Excellon Reference Box Object"))
  152. self.box_combo_type.addItem(_("Geometry Reference Box Object"))
  153. self.point_box_container.addWidget(self.box_combo_type)
  154. self.point_box_container.addWidget(self.box_combo)
  155. self.box_combo.hide()
  156. self.box_combo_type.hide()
  157. # ## Alignment holes
  158. self.ah_label = QtWidgets.QLabel("<b>%s:</b>" % _('Alignment Drill Coordinates'))
  159. self.ah_label.setToolTip(
  160. _("Alignment holes (x1, y1), (x2, y2), ... "
  161. "on one side of the mirror axis. For each set of (x, y) coordinates\n"
  162. "entered here, a pair of drills will be created:\n\n"
  163. "- one drill at the coordinates from the field\n"
  164. "- one drill in mirror position over the axis selected above in the 'Mirror Axis'.")
  165. )
  166. self.layout.addWidget(self.ah_label)
  167. grid_lay3 = QtWidgets.QGridLayout()
  168. self.layout.addLayout(grid_lay3)
  169. self.alignment_holes = EvalEntry()
  170. self.add_drill_point_button = QtWidgets.QPushButton(_("Add"))
  171. self.add_drill_point_button.setToolTip(
  172. _("Add alignment drill holes coords in the format: (x1, y1), (x2, y2), ... \n"
  173. "on one side of the mirror axis.\n\n"
  174. "The coordinates set can be obtained:\n"
  175. "- press SHIFT key and left mouse clicking on canvas. Then click Add.\n"
  176. "- press SHIFT key and left mouse clicking on canvas. Then CTRL+V in the field.\n"
  177. "- press SHIFT key and left mouse clicking on canvas. Then RMB click in the field and click Paste.\n"
  178. "- by entering the coords manually in the format: (x1, y1), (x2, y2), ...")
  179. )
  180. self.add_drill_point_button.setMinimumWidth(60)
  181. grid_lay3.addWidget(self.alignment_holes, 0, 0)
  182. grid_lay3.addWidget(self.add_drill_point_button, 0, 1)
  183. # ## Drill diameter for alignment holes
  184. self.dt_label = QtWidgets.QLabel("<b>%s:</b>" % _('Alignment Drill Diameter'))
  185. self.dt_label.setToolTip(
  186. _("Diameter of the drill for the "
  187. "alignment holes.")
  188. )
  189. self.layout.addWidget(self.dt_label)
  190. hlay = QtWidgets.QHBoxLayout()
  191. self.layout.addLayout(hlay)
  192. self.drill_dia = FCEntry()
  193. self.dd_label = QtWidgets.QLabel('%s:' % _("Drill dia"))
  194. self.dd_label.setToolTip(
  195. _("Diameter of the drill for the "
  196. "alignment holes.")
  197. )
  198. hlay.addWidget(self.dd_label)
  199. hlay.addWidget(self.drill_dia)
  200. hlay2 = QtWidgets.QHBoxLayout()
  201. self.layout.addLayout(hlay2)
  202. # ## Buttons
  203. self.create_alignment_hole_button = QtWidgets.QPushButton(_("Create Excellon Object"))
  204. self.create_alignment_hole_button.setToolTip(
  205. _("Creates an Excellon Object containing the\n"
  206. "specified alignment holes and their mirror\n"
  207. "images.")
  208. )
  209. hlay2.addWidget(self.create_alignment_hole_button)
  210. self.reset_button = QtWidgets.QPushButton(_("Reset"))
  211. self.reset_button.setToolTip(
  212. _("Resets all the fields.")
  213. )
  214. self.reset_button.setMinimumWidth(60)
  215. hlay2.addWidget(self.reset_button)
  216. self.layout.addStretch()
  217. # ## Signals
  218. self.create_alignment_hole_button.clicked.connect(self.on_create_alignment_holes)
  219. self.mirror_gerber_button.clicked.connect(self.on_mirror_gerber)
  220. self.mirror_exc_button.clicked.connect(self.on_mirror_exc)
  221. self.mirror_geo_button.clicked.connect(self.on_mirror_geo)
  222. self.add_point_button.clicked.connect(self.on_point_add)
  223. self.add_drill_point_button.clicked.connect(self.on_drill_add)
  224. self.reset_button.clicked.connect(self.reset_fields)
  225. self.box_combo_type.currentIndexChanged.connect(self.on_combo_box_type)
  226. self.axis_location.group_toggle_fn = self.on_toggle_pointbox
  227. self.drill_values = ""
  228. def install(self, icon=None, separator=None, **kwargs):
  229. FlatCAMTool.install(self, icon, separator, shortcut='ALT+D', **kwargs)
  230. def run(self, toggle=True):
  231. self.app.report_usage("Tool2Sided()")
  232. if toggle:
  233. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  234. if self.app.ui.splitter.sizes()[0] == 0:
  235. self.app.ui.splitter.setSizes([1, 1])
  236. else:
  237. try:
  238. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  239. # if tab is populated with the tool but it does not have the focus, focus on it
  240. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  241. # focus on Tool Tab
  242. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  243. else:
  244. self.app.ui.splitter.setSizes([0, 1])
  245. except AttributeError:
  246. pass
  247. else:
  248. if self.app.ui.splitter.sizes()[0] == 0:
  249. self.app.ui.splitter.setSizes([1, 1])
  250. FlatCAMTool.run(self)
  251. self.set_tool_ui()
  252. self.app.ui.notebook.setTabText(2, _("2-Sided Tool"))
  253. def set_tool_ui(self):
  254. self.reset_fields()
  255. self.point_entry.set_value("")
  256. self.alignment_holes.set_value("")
  257. self.mirror_axis.set_value(self.app.defaults["tools_2sided_mirror_axis"])
  258. self.axis_location.set_value(self.app.defaults["tools_2sided_axis_loc"])
  259. self.drill_dia.set_value(self.app.defaults["tools_2sided_drilldia"])
  260. def on_combo_box_type(self):
  261. obj_type = self.box_combo_type.currentIndex()
  262. self.box_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  263. self.box_combo.setCurrentIndex(0)
  264. def on_create_alignment_holes(self):
  265. axis = self.mirror_axis.get_value()
  266. mode = self.axis_location.get_value()
  267. if mode == "point":
  268. try:
  269. px, py = self.point_entry.get_value()
  270. except TypeError:
  271. self.app.inform.emit('[WARNING_NOTCL] %s' % _("'Point' reference is selected and 'Point' coordinates "
  272. "are missing. Add them and retry."))
  273. return
  274. else:
  275. selection_index = self.box_combo.currentIndex()
  276. model_index = self.app.collection.index(selection_index, 0, self.gerber_object_combo.rootModelIndex())
  277. try:
  278. bb_obj = model_index.internalPointer().obj
  279. except AttributeError:
  280. model_index = self.app.collection.index(selection_index, 0, self.exc_object_combo.rootModelIndex())
  281. try:
  282. bb_obj = model_index.internalPointer().obj
  283. except AttributeError:
  284. model_index = self.app.collection.index(selection_index, 0,
  285. self.geo_object_combo.rootModelIndex())
  286. try:
  287. bb_obj = model_index.internalPointer().obj
  288. except AttributeError:
  289. self.app.inform.emit(
  290. '[WARNING_NOTCL] %s' % _("There is no Box reference object loaded. Load one and retry."))
  291. return
  292. xmin, ymin, xmax, ymax = bb_obj.bounds()
  293. px = 0.5 * (xmin + xmax)
  294. py = 0.5 * (ymin + ymax)
  295. xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
  296. try:
  297. dia = float(self.drill_dia.get_value())
  298. except ValueError:
  299. # try to convert comma to decimal point. if it's still not working error message and return
  300. try:
  301. dia = float(self.drill_dia.get_value().replace(',', '.'))
  302. self.drill_dia.set_value(dia)
  303. except ValueError:
  304. self.app.inform.emit('[WARNING_NOTCL] %s' % _("Tool diameter value is missing or wrong format. "
  305. "Add it and retry."))
  306. return
  307. if dia is '':
  308. self.app.inform.emit('[WARNING_NOTCL] %s' %
  309. _("No value or wrong format in Drill Dia entry. Add it and retry."))
  310. return
  311. tools = {"1": {"C": dia}}
  312. # holes = self.alignment_holes.get_value()
  313. holes = eval('[{}]'.format(self.alignment_holes.text()))
  314. if not holes:
  315. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There are no Alignment Drill Coordinates to use. "
  316. "Add them and retry."))
  317. return
  318. drills = []
  319. for hole in holes:
  320. point = Point(hole)
  321. point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
  322. drills.append({"point": point, "tool": "1"})
  323. drills.append({"point": point_mirror, "tool": "1"})
  324. if 'solid_geometry' not in tools:
  325. tools["1"]['solid_geometry'] = []
  326. else:
  327. tools["1"]['solid_geometry'].append(point_mirror)
  328. def obj_init(obj_inst, app_inst):
  329. obj_inst.tools = tools
  330. obj_inst.drills = drills
  331. obj_inst.create_geometry()
  332. self.app.new_object("excellon", "Alignment Drills", obj_init)
  333. self.drill_values = ''
  334. self.app.inform.emit('[success] %s' % _("Excellon object with alignment drills created..."))
  335. def on_mirror_gerber(self):
  336. selection_index = self.gerber_object_combo.currentIndex()
  337. # fcobj = self.app.collection.object_list[selection_index]
  338. model_index = self.app.collection.index(selection_index, 0, self.gerber_object_combo.rootModelIndex())
  339. try:
  340. fcobj = model_index.internalPointer().obj
  341. except Exception as e:
  342. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
  343. return
  344. if not isinstance(fcobj, FlatCAMGerber):
  345. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber, Excellon and Geometry objects can be mirrored."))
  346. return
  347. axis = self.mirror_axis.get_value()
  348. mode = self.axis_location.get_value()
  349. if mode == "point":
  350. try:
  351. px, py = self.point_entry.get_value()
  352. except TypeError:
  353. self.app.inform.emit('[WARNING_NOTCL] %s' % _("'Point' coordinates missing. "
  354. "Using Origin (0, 0) as mirroring reference."))
  355. px, py = (0, 0)
  356. else:
  357. selection_index_box = self.box_combo.currentIndex()
  358. model_index_box = self.app.collection.index(selection_index_box, 0, self.box_combo.rootModelIndex())
  359. try:
  360. bb_obj = model_index_box.internalPointer().obj
  361. except Exception as e:
  362. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
  363. return
  364. xmin, ymin, xmax, ymax = bb_obj.bounds()
  365. px = 0.5 * (xmin + xmax)
  366. py = 0.5 * (ymin + ymax)
  367. fcobj.mirror(axis, [px, py])
  368. self.app.object_changed.emit(fcobj)
  369. fcobj.plot()
  370. self.app.inform.emit('[success] Gerber %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
  371. def on_mirror_exc(self):
  372. selection_index = self.exc_object_combo.currentIndex()
  373. # fcobj = self.app.collection.object_list[selection_index]
  374. model_index = self.app.collection.index(selection_index, 0, self.exc_object_combo.rootModelIndex())
  375. try:
  376. fcobj = model_index.internalPointer().obj
  377. except Exception as e:
  378. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Excellon object loaded ..."))
  379. return
  380. if not isinstance(fcobj, FlatCAMExcellon):
  381. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber, Excellon and Geometry objects can be mirrored."))
  382. return
  383. axis = self.mirror_axis.get_value()
  384. mode = self.axis_location.get_value()
  385. if mode == "point":
  386. try:
  387. px, py = self.point_entry.get_value()
  388. except Exception as e:
  389. log.debug("DblSidedTool.on_mirror_geo() --> %s" % str(e))
  390. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There are no Point coordinates in the Point field. "
  391. "Add coords and try again ..."))
  392. return
  393. else:
  394. selection_index_box = self.box_combo.currentIndex()
  395. model_index_box = self.app.collection.index(selection_index_box, 0, self.box_combo.rootModelIndex())
  396. try:
  397. bb_obj = model_index_box.internalPointer().obj
  398. except Exception as e:
  399. log.debug("DblSidedTool.on_mirror_geo() --> %s" % str(e))
  400. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
  401. return
  402. xmin, ymin, xmax, ymax = bb_obj.bounds()
  403. px = 0.5 * (xmin + xmax)
  404. py = 0.5 * (ymin + ymax)
  405. fcobj.mirror(axis, [px, py])
  406. self.app.object_changed.emit(fcobj)
  407. fcobj.plot()
  408. self.app.inform.emit('[success] Excellon %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
  409. def on_mirror_geo(self):
  410. selection_index = self.geo_object_combo.currentIndex()
  411. # fcobj = self.app.collection.object_list[selection_index]
  412. model_index = self.app.collection.index(selection_index, 0, self.geo_object_combo.rootModelIndex())
  413. try:
  414. fcobj = model_index.internalPointer().obj
  415. except Exception as e:
  416. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Geometry object loaded ..."))
  417. return
  418. if not isinstance(fcobj, FlatCAMGeometry):
  419. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber, Excellon and Geometry objects can be mirrored."))
  420. return
  421. axis = self.mirror_axis.get_value()
  422. mode = self.axis_location.get_value()
  423. if mode == "point":
  424. px, py = self.point_entry.get_value()
  425. else:
  426. selection_index_box = self.box_combo.currentIndex()
  427. model_index_box = self.app.collection.index(selection_index_box, 0, self.box_combo.rootModelIndex())
  428. try:
  429. bb_obj = model_index_box.internalPointer().obj
  430. except Exception as e:
  431. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Box object loaded ..."))
  432. return
  433. xmin, ymin, xmax, ymax = bb_obj.bounds()
  434. px = 0.5 * (xmin + xmax)
  435. py = 0.5 * (ymin + ymax)
  436. fcobj.mirror(axis, [px, py])
  437. self.app.object_changed.emit(fcobj)
  438. fcobj.plot()
  439. self.app.inform.emit('[success] Geometry %s %s...' % (str(fcobj.options['name']), _("was mirrored")))
  440. def on_point_add(self):
  441. val = self.app.defaults["global_point_clipboard_format"] % (self.app.pos[0], self.app.pos[1])
  442. self.point_entry.set_value(val)
  443. def on_drill_add(self):
  444. self.drill_values += (self.app.defaults["global_point_clipboard_format"] %
  445. (self.app.pos[0], self.app.pos[1])) + ','
  446. self.alignment_holes.set_value(self.drill_values)
  447. def on_toggle_pointbox(self):
  448. if self.axis_location.get_value() == "point":
  449. self.point_entry.show()
  450. self.box_combo.hide()
  451. self.box_combo_type.hide()
  452. self.add_point_button.setDisabled(False)
  453. else:
  454. self.point_entry.hide()
  455. self.box_combo.show()
  456. self.box_combo_type.show()
  457. self.add_point_button.setDisabled(True)
  458. def reset_fields(self):
  459. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  460. self.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  461. self.geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  462. self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  463. self.gerber_object_combo.setCurrentIndex(0)
  464. self.exc_object_combo.setCurrentIndex(0)
  465. self.geo_object_combo.setCurrentIndex(0)
  466. self.box_combo.setCurrentIndex(0)
  467. self.box_combo_type.setCurrentIndex(0)
  468. self.drill_values = ""