ToolDblSided.py 24 KB

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