ToolCalibrateExcellon.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # File Author: Marius Adrian Stanciu (c) #
  4. # Date: 3/10/2019 #
  5. # MIT Licence #
  6. # ##########################################################
  7. from PyQt5 import QtWidgets, QtCore
  8. from FlatCAMTool import FlatCAMTool
  9. from flatcamGUI.GUIElements import FCDoubleSpinner, EvalEntry, FCCheckBox
  10. from shapely.geometry import Point
  11. from shapely.geometry.base import *
  12. import math
  13. from datetime import datetime
  14. import logging
  15. import gettext
  16. import FlatCAMTranslation as fcTranslate
  17. import builtins
  18. fcTranslate.apply_language('strings')
  19. if '_' not in builtins.__dict__:
  20. _ = gettext.gettext
  21. log = logging.getLogger('base')
  22. class ToolCalibrateExcellon(FlatCAMTool):
  23. toolName = _("Calibrate Excellon")
  24. def __init__(self, app):
  25. FlatCAMTool.__init__(self, app)
  26. self.app = app
  27. self.canvas = self.app.plotcanvas
  28. self.decimals = 4
  29. # ## Title
  30. title_label = QtWidgets.QLabel("%s" % self.toolName)
  31. title_label.setStyleSheet("""
  32. QLabel
  33. {
  34. font-size: 16px;
  35. font-weight: bold;
  36. }
  37. """)
  38. self.layout.addWidget(title_label)
  39. # ## Grid Layout
  40. i_grid_lay = QtWidgets.QGridLayout()
  41. self.layout.addLayout(i_grid_lay)
  42. i_grid_lay.setColumnStretch(0, 0)
  43. i_grid_lay.setColumnStretch(1, 1)
  44. i_grid_lay.setColumnStretch(2, 1)
  45. self.exc_object_combo = QtWidgets.QComboBox()
  46. self.exc_object_combo.setModel(self.app.collection)
  47. self.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  48. self.exc_object_combo.setCurrentIndex(1)
  49. self.excobj_label = QtWidgets.QLabel("<b>%s:</b>" % _("EXCELLON"))
  50. self.excobj_label.setToolTip(
  51. _("Excellon Object to be used as a source for reference points.")
  52. )
  53. i_grid_lay.addWidget(self.excobj_label, 0, 0)
  54. i_grid_lay.addWidget(self.exc_object_combo, 0, 1, 1, 2)
  55. i_grid_lay.addWidget(QtWidgets.QLabel(''), 1, 0)
  56. self.gcode_title_label = QtWidgets.QLabel('<b>%s</b>' % _('GCode Parameters'))
  57. self.gcode_title_label.setToolTip(
  58. _("Parameters used when creating the GCode in this tool.")
  59. )
  60. i_grid_lay.addWidget(self.gcode_title_label, 1, 0, 1, 3)
  61. # Travel Z entry
  62. travelz_lbl = QtWidgets.QLabel('%s:' % _("Travel Z"))
  63. self.travelz_entry = FCDoubleSpinner()
  64. self.travelz_entry.set_range(-9999.9999, 9999.9999)
  65. self.travelz_entry.set_precision(self.decimals)
  66. self.travelz_entry.setSingleStep(0.1)
  67. i_grid_lay.addWidget(travelz_lbl, 2, 0)
  68. i_grid_lay.addWidget(self.travelz_entry, 2, 1, 1, 2)
  69. # Verification Z entry
  70. verz_lbl = QtWidgets.QLabel('%s:' % _("Verification Z"))
  71. self.verz_entry = FCDoubleSpinner()
  72. self.verz_entry.set_range(-9999.9999, 9999.9999)
  73. self.verz_entry.set_precision(self.decimals)
  74. self.verz_entry.setSingleStep(0.1)
  75. i_grid_lay.addWidget(verz_lbl, 3, 0)
  76. i_grid_lay.addWidget(self.verz_entry, 3, 1, 1, 2)
  77. # Zero the Z of the verification tool
  78. self.zeroz_cb = FCCheckBox('%s' % _("Zero Z tool"))
  79. self.zeroz_cb.setToolTip(
  80. _("Include a secquence to zero the height (Z)\n"
  81. "of the verification tool.")
  82. )
  83. i_grid_lay.addWidget(self.zeroz_cb, 4, 0, 1, 3)
  84. i_grid_lay.addWidget(QtWidgets.QLabel(''), 5, 0, 1, 3)
  85. # ## Grid Layout
  86. grid_lay = QtWidgets.QGridLayout()
  87. self.layout.addLayout(grid_lay)
  88. grid_lay.setColumnStretch(0, 0)
  89. grid_lay.setColumnStretch(1, 1)
  90. grid_lay.setColumnStretch(2, 1)
  91. self.points_table_label = QtWidgets.QLabel('<b>%s</b>' % _('Calibration Points'))
  92. self.points_table_label.setToolTip(
  93. _("Contain the expected calibration points and the\n"
  94. "ones measured.")
  95. )
  96. grid_lay.addWidget(self.points_table_label, 2, 0, 1, 3)
  97. # BOTTOM LEFT
  98. self.bottom_left_lbl = QtWidgets.QLabel('<b>%s</b>' % _('Bottom Left'))
  99. grid_lay.addWidget(self.bottom_left_lbl, 3, 0)
  100. self.bottom_left_tgt_lbl = QtWidgets.QLabel('%s' % _('Target'))
  101. grid_lay.addWidget(self.bottom_left_tgt_lbl, 3, 1)
  102. self.bottom_left_found_lbl = QtWidgets.QLabel('%s' % _('Cal. Origin'))
  103. grid_lay.addWidget(self.bottom_left_found_lbl, 3, 2)
  104. self.bottom_left_coordx_lbl = QtWidgets.QLabel('%s' % _('X'))
  105. grid_lay.addWidget(self.bottom_left_coordx_lbl, 4, 0)
  106. self.bottom_left_coordx_tgt = EvalEntry()
  107. self.bottom_left_coordx_tgt.setReadOnly(True)
  108. grid_lay.addWidget(self.bottom_left_coordx_tgt, 4, 1)
  109. self.bottom_left_coordx_found = EvalEntry()
  110. grid_lay.addWidget(self.bottom_left_coordx_found, 4, 2)
  111. self.bottom_left_coordy_lbl = QtWidgets.QLabel('%s' % _('Y'))
  112. grid_lay.addWidget(self.bottom_left_coordy_lbl, 5, 0)
  113. self.bottom_left_coordy_tgt = EvalEntry()
  114. self.bottom_left_coordy_tgt.setReadOnly(True)
  115. grid_lay.addWidget(self.bottom_left_coordy_tgt, 5, 1)
  116. self.bottom_left_coordy_found = EvalEntry()
  117. grid_lay.addWidget(self.bottom_left_coordy_found, 5, 2)
  118. self.bottom_left_coordx_found.set_value(_('Set Origin'))
  119. self.bottom_left_coordy_found.set_value(_('Set Origin'))
  120. self.bottom_left_coordx_found.setDisabled(True)
  121. self.bottom_left_coordy_found.setDisabled(True)
  122. # BOTTOM RIGHT
  123. self.bottom_right_lbl = QtWidgets.QLabel('<b>%s</b>' % _('Bottom Right'))
  124. grid_lay.addWidget(self.bottom_right_lbl, 6, 0)
  125. self.bottom_right_tgt_lbl = QtWidgets.QLabel('%s' % _('Target'))
  126. grid_lay.addWidget(self.bottom_right_tgt_lbl, 6, 1)
  127. self.bottom_right_found_lbl = QtWidgets.QLabel('%s' % _('Found Delta'))
  128. grid_lay.addWidget(self.bottom_right_found_lbl, 6, 2)
  129. self.bottom_right_coordx_lbl = QtWidgets.QLabel('%s' % _('X'))
  130. grid_lay.addWidget(self.bottom_right_coordx_lbl, 7, 0)
  131. self.bottom_right_coordx_tgt = EvalEntry()
  132. self.bottom_right_coordx_tgt.setReadOnly(True)
  133. grid_lay.addWidget(self.bottom_right_coordx_tgt, 7, 1)
  134. self.bottom_right_coordx_found = EvalEntry()
  135. grid_lay.addWidget(self.bottom_right_coordx_found, 7, 2)
  136. self.bottom_right_coordy_lbl = QtWidgets.QLabel('%s' % _('Y'))
  137. grid_lay.addWidget(self.bottom_right_coordy_lbl, 8, 0)
  138. self.bottom_right_coordy_tgt = EvalEntry()
  139. self.bottom_right_coordy_tgt.setReadOnly(True)
  140. grid_lay.addWidget(self.bottom_right_coordy_tgt, 8, 1)
  141. self.bottom_right_coordy_found = EvalEntry()
  142. grid_lay.addWidget(self.bottom_right_coordy_found, 8, 2)
  143. # TOP LEFT
  144. self.top_left_lbl = QtWidgets.QLabel('<b>%s</b>' % _('Top Left'))
  145. grid_lay.addWidget(self.top_left_lbl, 9, 0)
  146. self.top_left_tgt_lbl = QtWidgets.QLabel('%s' % _('Target'))
  147. grid_lay.addWidget(self.top_left_tgt_lbl, 9, 1)
  148. self.top_left_found_lbl = QtWidgets.QLabel('%s' % _('Found Delta'))
  149. grid_lay.addWidget(self.top_left_found_lbl, 9, 2)
  150. self.top_left_coordx_lbl = QtWidgets.QLabel('%s' % _('X'))
  151. grid_lay.addWidget(self.top_left_coordx_lbl, 10, 0)
  152. self.top_left_coordx_tgt = EvalEntry()
  153. self.top_left_coordx_tgt.setReadOnly(True)
  154. grid_lay.addWidget(self.top_left_coordx_tgt, 10, 1)
  155. self.top_left_coordx_found = EvalEntry()
  156. grid_lay.addWidget(self.top_left_coordx_found, 10, 2)
  157. self.top_left_coordy_lbl = QtWidgets.QLabel('%s' % _('Y'))
  158. grid_lay.addWidget(self.top_left_coordy_lbl, 11, 0)
  159. self.top_left_coordy_tgt = EvalEntry()
  160. self.top_left_coordy_tgt.setReadOnly(True)
  161. grid_lay.addWidget(self.top_left_coordy_tgt, 11, 1)
  162. self.top_left_coordy_found = EvalEntry()
  163. grid_lay.addWidget(self.top_left_coordy_found, 11, 2)
  164. # TOP RIGHT
  165. self.top_right_lbl = QtWidgets.QLabel('<b>%s</b>' % _('Top Right'))
  166. grid_lay.addWidget(self.top_right_lbl, 12, 0)
  167. self.top_right_tgt_lbl = QtWidgets.QLabel('%s' % _('Target'))
  168. grid_lay.addWidget(self.top_right_tgt_lbl, 12, 1)
  169. self.top_right_found_lbl = QtWidgets.QLabel('%s' % _('Found Delta'))
  170. grid_lay.addWidget(self.top_right_found_lbl, 12, 2)
  171. self.top_right_coordx_lbl = QtWidgets.QLabel('%s' % _('X'))
  172. grid_lay.addWidget(self.top_right_coordx_lbl, 13, 0)
  173. self.top_right_coordx_tgt = EvalEntry()
  174. self.top_right_coordx_tgt.setReadOnly(True)
  175. grid_lay.addWidget(self.top_right_coordx_tgt, 13, 1)
  176. self.top_right_coordx_found = EvalEntry()
  177. grid_lay.addWidget(self.top_right_coordx_found, 13, 2)
  178. self.top_right_coordy_lbl = QtWidgets.QLabel('%s' % _('Y'))
  179. grid_lay.addWidget(self.top_right_coordy_lbl, 14, 0)
  180. self.top_right_coordy_tgt = EvalEntry()
  181. self.top_right_coordy_tgt.setReadOnly(True)
  182. grid_lay.addWidget(self.top_right_coordy_tgt, 14, 1)
  183. self.top_right_coordy_found = EvalEntry()
  184. grid_lay.addWidget(self.top_right_coordy_found, 14, 2)
  185. # STEP 1 #
  186. step_1 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 1"))
  187. step_1.setToolTip(
  188. _("Pick four points by clicking inside the drill holes.\n"
  189. "Those four points should be in the four\n"
  190. "(as much as possible) corners of the Excellon object.")
  191. )
  192. grid_lay.addWidget(step_1, 15, 0, 1, 3)
  193. # ## Start Button
  194. self.start_button = QtWidgets.QPushButton(_("Acquire Calibration Points"))
  195. self.start_button.setToolTip(
  196. _("Pick four points by clicking inside the drill holes.\n"
  197. "Those four points should be in the four squares of\n"
  198. "the Excellon object.")
  199. )
  200. grid_lay.addWidget(self.start_button, 16, 0, 1, 3)
  201. # STEP 2 #
  202. step_2 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 2"))
  203. step_2.setToolTip(
  204. _("Generate GCode file to locate and align the PCB by using\n"
  205. "the four points acquired above.")
  206. )
  207. grid_lay.addWidget(step_2, 17, 0, 1, 3)
  208. # ## GCode Button
  209. self.gcode_button = QtWidgets.QPushButton(_("Generate GCode"))
  210. self.gcode_button.setToolTip(
  211. _("Generate GCode file to locate and align the PCB by using\n"
  212. "the four points acquired above.")
  213. )
  214. grid_lay.addWidget(self.gcode_button, 18, 0, 1, 3)
  215. # STEP 3 #
  216. step_3 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 3"))
  217. step_3.setToolTip(
  218. _("Calculate Scale and Skew factors based on the differences (delta)\n"
  219. "found when checking the PCB pattern. The differences must be filled\n"
  220. "in the fields Found (Delta).")
  221. )
  222. grid_lay.addWidget(step_3, 19, 0, 1, 3)
  223. # ## Factors Button
  224. self.generate_factors_button = QtWidgets.QPushButton(_("Calculate Factors"))
  225. self.generate_factors_button.setToolTip(
  226. _("Calculate Scale and Skew factors based on the differences (delta)\n"
  227. "found when checking the PCB pattern. The differences must be filled\n"
  228. "in the fields Found (Delta).")
  229. )
  230. grid_lay.addWidget(self.generate_factors_button, 20, 0, 1, 3)
  231. scale_lbl = QtWidgets.QLabel('<b>%s</b>' % _("Scale"))
  232. grid_lay.addWidget(scale_lbl, 21, 0, 1, 3)
  233. self.scalex_label = QtWidgets.QLabel(_("Factor X:"))
  234. self.scalex_label.setToolTip(
  235. _("Factor for Scale action over X axis.")
  236. )
  237. self.scalex_entry = FCDoubleSpinner()
  238. self.scalex_entry.set_range(0, 9999.9999)
  239. self.scalex_entry.set_precision(self.decimals)
  240. self.scalex_entry.setSingleStep(0.1)
  241. grid_lay.addWidget(self.scalex_label, 22, 0)
  242. grid_lay.addWidget(self.scalex_entry, 22, 1, 1, 2)
  243. self.scaley_label = QtWidgets.QLabel(_("Factor Y:"))
  244. self.scaley_label.setToolTip(
  245. _("Factor for Scale action over Y axis.")
  246. )
  247. self.scaley_entry = FCDoubleSpinner()
  248. self.scaley_entry.set_range(0, 9999.9999)
  249. self.scaley_entry.set_precision(self.decimals)
  250. self.scaley_entry.setSingleStep(0.1)
  251. grid_lay.addWidget(self.scaley_label, 23, 0)
  252. grid_lay.addWidget(self.scaley_entry, 23, 1, 1, 2)
  253. skew_lbl = QtWidgets.QLabel('<b>%s</b>' % _("Skew"))
  254. grid_lay.addWidget(skew_lbl, 24, 0, 1, 3)
  255. self.skewx_label = QtWidgets.QLabel(_("Angle X:"))
  256. self.skewx_label.setToolTip(
  257. _("Angle for Skew action, in degrees.\n"
  258. "Float number between -360 and 359.")
  259. )
  260. self.skewx_entry = FCDoubleSpinner()
  261. self.skewx_entry.set_range(-360, 360)
  262. self.skewx_entry.set_precision(self.decimals)
  263. self.skewx_entry.setSingleStep(0.1)
  264. grid_lay.addWidget(self.skewx_label, 25, 0)
  265. grid_lay.addWidget(self.skewx_entry, 25, 1, 1, 2)
  266. self.skewy_label = QtWidgets.QLabel(_("Angle Y:"))
  267. self.skewy_label.setToolTip(
  268. _("Angle for Skew action, in degrees.\n"
  269. "Float number between -360 and 359.")
  270. )
  271. self.skewy_entry = FCDoubleSpinner()
  272. self.skewy_entry.set_range(-360, 360)
  273. self.skewy_entry.set_precision(self.decimals)
  274. self.skewy_entry.setSingleStep(0.1)
  275. grid_lay.addWidget(self.skewy_label, 26, 0)
  276. grid_lay.addWidget(self.skewy_entry, 26, 1, 1, 2)
  277. # STEP 4 #
  278. step_4 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 4"))
  279. step_4.setToolTip(
  280. _("Generate verification GCode file adjusted with\n"
  281. "the factors above.")
  282. )
  283. grid_lay.addWidget(step_4, 27, 0, 1, 3)
  284. # ## Adjusted GCode Button
  285. self.adj_gcode_button = QtWidgets.QPushButton(_("Generate Adjusted GCode"))
  286. self.adj_gcode_button.setToolTip(
  287. _("Generate verification GCode file adjusted with\n"
  288. "the factors above.")
  289. )
  290. grid_lay.addWidget(self.adj_gcode_button, 28, 0, 1, 3)
  291. # STEP 5 #
  292. step_5 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 5"))
  293. step_5.setToolTip(
  294. _("Ajust the Excellon and Cutout Geometry objects\n"
  295. "with the factors determined, and verified, above.")
  296. )
  297. grid_lay.addWidget(step_5, 29, 0, 1, 3)
  298. self.adj_exc_object_combo = QtWidgets.QComboBox()
  299. self.adj_exc_object_combo.setModel(self.app.collection)
  300. self.adj_exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  301. self.adj_exc_object_combo.setCurrentIndex(1)
  302. self.adj_excobj_label = QtWidgets.QLabel("<b>%s:</b>" % _("EXCELLON"))
  303. self.adj_excobj_label.setToolTip(
  304. _("Excellon Object to be adjusted.")
  305. )
  306. grid_lay.addWidget(self.adj_excobj_label, 30, 0)
  307. grid_lay.addWidget(self.adj_exc_object_combo, 30, 1, 1, 2)
  308. self.adj_geo_object_combo = QtWidgets.QComboBox()
  309. self.adj_geo_object_combo.setModel(self.app.collection)
  310. self.adj_geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  311. self.adj_geo_object_combo.setCurrentIndex(1)
  312. self.adj_geoobj_label = QtWidgets.QLabel("<b>%s:</b>" % _("GEOMETRY"))
  313. self.adj_geoobj_label.setToolTip(
  314. _("Geometry Object to be adjusted.")
  315. )
  316. grid_lay.addWidget(self.adj_geoobj_label, 31, 0)
  317. grid_lay.addWidget(self.adj_geo_object_combo, 31, 1, 1, 2)
  318. # ## Adjust Objects Button
  319. self.adj_obj_button = QtWidgets.QPushButton(_("Adjust Objects"))
  320. self.adj_obj_button.setToolTip(
  321. _("Adjust (scale and / or skew) the objects\n"
  322. "with the factors determined above.")
  323. )
  324. grid_lay.addWidget(self.adj_obj_button, 32, 0, 1, 3)
  325. grid_lay.addWidget(QtWidgets.QLabel(''), 33, 0)
  326. self.layout.addStretch()
  327. self.mr = None
  328. self.units = ''
  329. # here store 4 points to be used for calibration
  330. self.click_points = list()
  331. self.exc_obj = None
  332. # ## Signals
  333. self.start_button.clicked.connect(self.on_start_collect_points)
  334. def run(self, toggle=True):
  335. self.app.report_usage("ToolCalibrateExcellon()")
  336. if toggle:
  337. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  338. if self.app.ui.splitter.sizes()[0] == 0:
  339. self.app.ui.splitter.setSizes([1, 1])
  340. else:
  341. try:
  342. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  343. # if tab is populated with the tool but it does not have the focus, focus on it
  344. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  345. # focus on Tool Tab
  346. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  347. else:
  348. self.app.ui.splitter.setSizes([0, 1])
  349. except AttributeError:
  350. pass
  351. else:
  352. if self.app.ui.splitter.sizes()[0] == 0:
  353. self.app.ui.splitter.setSizes([1, 1])
  354. FlatCAMTool.run(self)
  355. self.set_tool_ui()
  356. self.app.ui.notebook.setTabText(2, _("Cal Exc Tool"))
  357. def install(self, icon=None, separator=None, **kwargs):
  358. FlatCAMTool.install(self, icon, separator, shortcut='ALT+E', **kwargs)
  359. def set_tool_ui(self):
  360. self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
  361. # ## Initialize form
  362. # self.mm_entry.set_value('%.*f' % (self.decimals, 0))
  363. def on_start_collect_points(self):
  364. self.mr = self.canvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
  365. if self.app.is_legacy is False:
  366. self.canvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
  367. else:
  368. self.canvas.graph_event_disconnect(self.app.mr)
  369. selection_index = self.exc_object_combo.currentIndex()
  370. model_index = self.app.collection.index(selection_index, 0, self.exc_object_combo.rootModelIndex())
  371. try:
  372. self.exc_obj = model_index.internalPointer().obj
  373. except Exception as e:
  374. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Excellon object loaded ..."))
  375. return
  376. self.app.inform.emit(_("Click inside the First drill point. Bottom Left..."))
  377. def on_mouse_click_release(self, event):
  378. if event.button == 1:
  379. if self.app.is_legacy is False:
  380. event_pos = event.pos
  381. else:
  382. event_pos = (event.xdata, event.ydata)
  383. pos_canvas = self.canvas.translate_coords(event_pos)
  384. click_pt = Point([pos_canvas[0], pos_canvas[1]])
  385. for tool, tool_dict in self.exc_obj.tools.items():
  386. for geo in tool_dict['solid_geometry']:
  387. if click_pt.within(geo):
  388. center_pt = geo.centroid
  389. self.click_points.append(
  390. (
  391. float('%.*f' % (self.decimals, center_pt.x)),
  392. float('%.*f' % (self.decimals, center_pt.y))
  393. )
  394. )
  395. self.check_points()
  396. def check_points(self):
  397. if len(self.click_points) == 1:
  398. self.bottom_left_coordx_tgt.set_value(self.click_points[0][0])
  399. self.bottom_left_coordy_tgt.set_value(self.click_points[0][1])
  400. self.app.inform.emit(_("Click inside the Second drill point. Bottom Right..."))
  401. elif len(self.click_points) == 2:
  402. self.bottom_right_coordx_tgt.set_value(self.click_points[1][0])
  403. self.bottom_right_coordy_tgt.set_value(self.click_points[1][1])
  404. self.app.inform.emit(_("Click inside the Third drill point. Top Left..."))
  405. elif len(self.click_points) == 3:
  406. self.top_left_coordx_tgt.set_value(self.click_points[2][0])
  407. self.top_left_coordy_tgt.set_value(self.click_points[2][1])
  408. self.app.inform.emit(_("Click inside the Fourth drill point. Top Right..."))
  409. elif len(self.click_points) == 4:
  410. self.top_right_coordx_tgt.set_value(self.click_points[3][0])
  411. self.top_right_coordy_tgt.set_value(self.click_points[3][1])
  412. self.app.inform.emit('[success] %s' % _("Done. All four points have been acquired."))
  413. self.disconnect_cal_events()
  414. def generate_verification_gcode(self):
  415. pass
  416. def gcode_header(self):
  417. log.debug("ToolCalibrateExcellon.gcode_header()")
  418. time_str = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
  419. gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
  420. (str(self.app.version), str(self.app.version_date)) + '\n'
  421. gcode += '(Name: ' + _('Verification GCode') + ')\n'
  422. gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
  423. gcode += '(Created on ' + time_str + ')\n' + '\n'
  424. return gcode
  425. def disconnect_cal_events(self):
  426. self.app.mr = self.canvas.graph_event_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
  427. if self.app.is_legacy is False:
  428. self.canvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
  429. else:
  430. self.canvas.graph_event_disconnect(self.mr)
  431. def reset_fields(self):
  432. self.exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  433. # end of file