ToolDblSided.py 24 KB

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