ToolDblSided.py 24 KB

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