ToolCalibration.py 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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, QtGui
  8. from FlatCAMTool import FlatCAMTool
  9. from flatcamGUI.GUIElements import FCDoubleSpinner, EvalEntry, FCCheckBox, OptionalInputSection
  10. from flatcamGUI.GUIElements import FCTable, FCComboBox, RadioSet
  11. from flatcamEditors.FlatCAMTextEditor import TextEditor
  12. from shapely.geometry import Point
  13. from shapely.geometry.base import *
  14. import math
  15. from datetime import datetime
  16. import logging
  17. import gettext
  18. import FlatCAMTranslation as fcTranslate
  19. import builtins
  20. fcTranslate.apply_language('strings')
  21. if '_' not in builtins.__dict__:
  22. _ = gettext.gettext
  23. log = logging.getLogger('base')
  24. class ToolCalibration(FlatCAMTool):
  25. toolName = _("Calibration Tool")
  26. def __init__(self, app):
  27. FlatCAMTool.__init__(self, app)
  28. self.app = app
  29. self.canvas = self.app.plotcanvas
  30. self.decimals = self.app.decimals
  31. # ## Title
  32. title_label = QtWidgets.QLabel("%s" % self.toolName)
  33. title_label.setStyleSheet("""
  34. QLabel
  35. {
  36. font-size: 16px;
  37. font-weight: bold;
  38. }
  39. """)
  40. self.layout.addWidget(title_label)
  41. self.layout.addWidget(QtWidgets.QLabel(''))
  42. # ## Grid Layout
  43. grid_lay = QtWidgets.QGridLayout()
  44. self.layout.addLayout(grid_lay)
  45. grid_lay.setColumnStretch(0, 0)
  46. grid_lay.setColumnStretch(1, 1)
  47. grid_lay.setColumnStretch(2, 0)
  48. step_1 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 1: Acquire Calibration Points"))
  49. step_1.setToolTip(
  50. _("Pick four points by clicking inside the drill holes.\n"
  51. "Those four points should be in the four\n"
  52. "(as much as possible) corners of the Excellon object.")
  53. )
  54. grid_lay.addWidget(step_1, 0, 0, 1, 3)
  55. self.cal_source_lbl = QtWidgets.QLabel("<b>%s:</b>" % _("Source Type"))
  56. self.cal_source_lbl.setToolTip(_("The source of calibration points.\n"
  57. "It can be:\n"
  58. "- Object -> click a hole geo for Excellon or a pad for Gerber\n"
  59. "- Free -> click freely on canvas to acquire the calibration points"))
  60. self.cal_source_radio = RadioSet([{'label': _('Object'), 'value': 'object'},
  61. {'label': _('Free'), 'value': 'free'}],
  62. stretch=False)
  63. grid_lay.addWidget(self.cal_source_lbl, 1, 0)
  64. grid_lay.addWidget(self.cal_source_radio, 1, 1, 1, 2)
  65. self.obj_type_label = QtWidgets.QLabel("%s:" % _("Object Type"))
  66. self.obj_type_combo = FCComboBox()
  67. self.obj_type_combo.addItem(_("Gerber"))
  68. self.obj_type_combo.addItem(_("Excellon"))
  69. self.obj_type_combo.setCurrentIndex(1)
  70. grid_lay.addWidget(self.obj_type_label, 2, 0)
  71. grid_lay.addWidget(self.obj_type_combo, 2, 1, 1, 2)
  72. self.object_combo = FCComboBox()
  73. self.object_combo.setModel(self.app.collection)
  74. self.object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  75. self.object_combo.setCurrentIndex(1)
  76. self.object_label = QtWidgets.QLabel("%s:" % _("Source object selection"))
  77. self.object_label.setToolTip(
  78. _("FlatCAM Object to be used as a source for reference points.")
  79. )
  80. grid_lay.addWidget(self.object_label, 3, 0, 1, 3)
  81. grid_lay.addWidget(self.object_combo, 4, 0, 1, 3)
  82. self.points_table_label = QtWidgets.QLabel('<b>%s</b>' % _('Calibration Points'))
  83. self.points_table_label.setToolTip(
  84. _("Contain the expected calibration points and the\n"
  85. "ones measured.")
  86. )
  87. grid_lay.addWidget(self.points_table_label, 5, 0, 1, 3)
  88. self.points_table = FCTable()
  89. self.points_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
  90. # self.points_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
  91. grid_lay.addWidget(self.points_table, 6, 0, 1, 3)
  92. self.points_table.setColumnCount(4)
  93. self.points_table.setHorizontalHeaderLabels(
  94. [
  95. '#',
  96. _("Name"),
  97. _("Target"),
  98. _("Found Delta")
  99. ]
  100. )
  101. self.points_table.setRowCount(8)
  102. row = 0
  103. # BOTTOM LEFT
  104. id_item_1 = QtWidgets.QTableWidgetItem('%d' % 1)
  105. flags = QtCore.Qt.ItemIsEnabled
  106. id_item_1.setFlags(flags)
  107. self.points_table.setItem(row, 0, id_item_1) # Tool name/id
  108. self.bottom_left_coordx_lbl = QtWidgets.QLabel('%s' % _('Bot Left X'))
  109. self.points_table.setCellWidget(row, 1, self.bottom_left_coordx_lbl)
  110. self.bottom_left_coordx_tgt = EvalEntry()
  111. self.points_table.setCellWidget(row, 2, self.bottom_left_coordx_tgt)
  112. self.bottom_left_coordx_tgt.setReadOnly(True)
  113. self.bottom_left_coordx_found = EvalEntry()
  114. self.points_table.setCellWidget(row, 3, self.bottom_left_coordx_found)
  115. row += 1
  116. self.bottom_left_coordy_lbl = QtWidgets.QLabel('%s' % _('Bot Left Y'))
  117. self.points_table.setCellWidget(row, 1, self.bottom_left_coordy_lbl)
  118. self.bottom_left_coordy_tgt = EvalEntry()
  119. self.points_table.setCellWidget(row, 2, self.bottom_left_coordy_tgt)
  120. self.bottom_left_coordy_tgt.setReadOnly(True)
  121. self.bottom_left_coordy_found = EvalEntry()
  122. self.points_table.setCellWidget(row, 3, self.bottom_left_coordy_found)
  123. self.bottom_left_coordx_found.set_value(_("Origin"))
  124. self.bottom_left_coordy_found.set_value(_("Origin"))
  125. self.bottom_left_coordx_found.setDisabled(True)
  126. self.bottom_left_coordy_found.setDisabled(True)
  127. row += 1
  128. # BOTTOM RIGHT
  129. id_item_2 = QtWidgets.QTableWidgetItem('%d' % 2)
  130. flags = QtCore.Qt.ItemIsEnabled
  131. id_item_2.setFlags(flags)
  132. self.points_table.setItem(row, 0, id_item_2) # Tool name/id
  133. self.bottom_right_coordx_lbl = QtWidgets.QLabel('%s' % _('Bot Right X'))
  134. self.points_table.setCellWidget(row, 1, self.bottom_right_coordx_lbl)
  135. self.bottom_right_coordx_tgt = EvalEntry()
  136. self.points_table.setCellWidget(row, 2, self.bottom_right_coordx_tgt)
  137. self.bottom_right_coordx_tgt.setReadOnly(True)
  138. self.bottom_right_coordx_found = EvalEntry()
  139. self.points_table.setCellWidget(row, 3, self.bottom_right_coordx_found)
  140. row += 1
  141. self.bottom_right_coordy_lbl = QtWidgets.QLabel('%s' % _('Bot Right Y'))
  142. self.points_table.setCellWidget(row, 1, self.bottom_right_coordy_lbl)
  143. self.bottom_right_coordy_tgt = EvalEntry()
  144. self.points_table.setCellWidget(row, 2, self.bottom_right_coordy_tgt)
  145. self.bottom_right_coordy_tgt.setReadOnly(True)
  146. self.bottom_right_coordy_found = EvalEntry()
  147. self.points_table.setCellWidget(row, 3, self.bottom_right_coordy_found)
  148. row += 1
  149. # TOP LEFT
  150. id_item_3 = QtWidgets.QTableWidgetItem('%d' % 3)
  151. flags = QtCore.Qt.ItemIsEnabled
  152. id_item_3.setFlags(flags)
  153. self.points_table.setItem(row, 0, id_item_3) # Tool name/id
  154. self.top_left_coordx_lbl = QtWidgets.QLabel('%s' % _('Top Left X'))
  155. self.points_table.setCellWidget(row, 1, self.top_left_coordx_lbl)
  156. self.top_left_coordx_tgt = EvalEntry()
  157. self.points_table.setCellWidget(row, 2, self.top_left_coordx_tgt)
  158. self.top_left_coordx_tgt.setReadOnly(True)
  159. self.top_left_coordx_found = EvalEntry()
  160. self.points_table.setCellWidget(row, 3, self.top_left_coordx_found)
  161. row += 1
  162. self.top_left_coordy_lbl = QtWidgets.QLabel('%s' % _('Top Left Y'))
  163. self.points_table.setCellWidget(row, 1, self.top_left_coordy_lbl)
  164. self.top_left_coordy_tgt = EvalEntry()
  165. self.points_table.setCellWidget(row, 2, self.top_left_coordy_tgt)
  166. self.top_left_coordy_tgt.setReadOnly(True)
  167. self.top_left_coordy_found = EvalEntry()
  168. self.points_table.setCellWidget(row, 3, self.top_left_coordy_found)
  169. row += 1
  170. # TOP RIGHT
  171. id_item_4 = QtWidgets.QTableWidgetItem('%d' % 4)
  172. flags = QtCore.Qt.ItemIsEnabled
  173. id_item_4.setFlags(flags)
  174. self.points_table.setItem(row, 0, id_item_4) # Tool name/id
  175. self.top_right_coordx_lbl = QtWidgets.QLabel('%s' % _('Top Right X'))
  176. self.points_table.setCellWidget(row, 1, self.top_right_coordx_lbl)
  177. self.top_right_coordx_tgt = EvalEntry()
  178. self.points_table.setCellWidget(row, 2, self.top_right_coordx_tgt)
  179. self.top_right_coordx_tgt.setReadOnly(True)
  180. self.top_right_coordx_found = EvalEntry()
  181. self.points_table.setCellWidget(row, 3, self.top_right_coordx_found)
  182. row += 1
  183. self.top_right_coordy_lbl = QtWidgets.QLabel('%s' % _('Top Right Y'))
  184. self.points_table.setCellWidget(row, 1, self.top_right_coordy_lbl)
  185. self.top_right_coordy_tgt = EvalEntry()
  186. self.points_table.setCellWidget(row, 2, self.top_right_coordy_tgt)
  187. self.top_right_coordy_tgt.setReadOnly(True)
  188. self.top_right_coordy_found = EvalEntry()
  189. self.points_table.setCellWidget(row, 3, self.top_right_coordy_found)
  190. vertical_header = self.points_table.verticalHeader()
  191. vertical_header.hide()
  192. self.points_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  193. horizontal_header = self.points_table.horizontalHeader()
  194. horizontal_header.setMinimumSectionSize(10)
  195. horizontal_header.setDefaultSectionSize(70)
  196. self.points_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
  197. # for x in range(4):
  198. # self.points_table.resizeColumnToContents(x)
  199. self.points_table.resizeColumnsToContents()
  200. self.points_table.resizeRowsToContents()
  201. horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
  202. horizontal_header.resizeSection(0, 20)
  203. horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Fixed)
  204. horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
  205. horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.Stretch)
  206. self.points_table.setMinimumHeight(self.points_table.getHeight() + 2)
  207. self.points_table.setMaximumHeight(self.points_table.getHeight() + 3)
  208. # ## Get Points Button
  209. self.start_button = QtWidgets.QPushButton(_("Get Points"))
  210. self.start_button.setToolTip(
  211. _("Pick four points by clicking on canvas if the source choice\n"
  212. "is 'free' or inside the object geometry if the source is 'object'.\n"
  213. "Those four points should be in the four squares of\n"
  214. "the object.")
  215. )
  216. self.start_button.setStyleSheet("""
  217. QPushButton
  218. {
  219. font-weight: bold;
  220. }
  221. """)
  222. grid_lay.addWidget(self.start_button, 7, 0, 1, 3)
  223. separator_line = QtWidgets.QFrame()
  224. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  225. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  226. grid_lay.addWidget(separator_line, 8, 0, 1, 3)
  227. grid_lay.addWidget(QtWidgets.QLabel(''), 9, 0)
  228. # STEP 2 #
  229. step_2 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 2: Verification GCode"))
  230. step_2.setToolTip(
  231. _("Generate GCode file to locate and align the PCB by using\n"
  232. "the four points acquired above.")
  233. )
  234. grid_lay.addWidget(step_2, 10, 0, 1, 3)
  235. self.gcode_title_label = QtWidgets.QLabel('<b>%s</b>' % _('GCode Parameters'))
  236. self.gcode_title_label.setToolTip(
  237. _("Parameters used when creating the GCode in this tool.")
  238. )
  239. grid_lay.addWidget(self.gcode_title_label, 11, 0, 1, 3)
  240. # Travel Z entry
  241. travelz_lbl = QtWidgets.QLabel('%s:' % _("Travel Z"))
  242. travelz_lbl.setToolTip(
  243. _("Height (Z) for travelling between the points.")
  244. )
  245. self.travelz_entry = FCDoubleSpinner()
  246. self.travelz_entry.set_range(-9999.9999, 9999.9999)
  247. self.travelz_entry.set_precision(self.decimals)
  248. self.travelz_entry.setSingleStep(0.1)
  249. grid_lay.addWidget(travelz_lbl, 12, 0)
  250. grid_lay.addWidget(self.travelz_entry, 12, 1, 1, 2)
  251. # Verification Z entry
  252. verz_lbl = QtWidgets.QLabel('%s:' % _("Verification Z"))
  253. verz_lbl.setToolTip(
  254. _("Height (Z) for checking the point.")
  255. )
  256. self.verz_entry = FCDoubleSpinner()
  257. self.verz_entry.set_range(-9999.9999, 9999.9999)
  258. self.verz_entry.set_precision(self.decimals)
  259. self.verz_entry.setSingleStep(0.1)
  260. grid_lay.addWidget(verz_lbl, 13, 0)
  261. grid_lay.addWidget(self.verz_entry, 13, 1, 1, 2)
  262. # Zero the Z of the verification tool
  263. self.zeroz_cb = FCCheckBox('%s' % _("Zero Z tool"))
  264. self.zeroz_cb.setToolTip(
  265. _("Include a sequence to zero the height (Z)\n"
  266. "of the verification tool.")
  267. )
  268. grid_lay.addWidget(self.zeroz_cb, 14, 0, 1, 3)
  269. # Toochange Z entry
  270. toolchangez_lbl = QtWidgets.QLabel('%s:' % _("Toolchange Z"))
  271. toolchangez_lbl.setToolTip(
  272. _("Height (Z) for mounting the verification probe.")
  273. )
  274. self.toolchangez_entry = FCDoubleSpinner()
  275. self.toolchangez_entry.set_range(0.0000, 9999.9999)
  276. self.toolchangez_entry.set_precision(self.decimals)
  277. self.toolchangez_entry.setSingleStep(0.1)
  278. grid_lay.addWidget(toolchangez_lbl, 15, 0)
  279. grid_lay.addWidget(self.toolchangez_entry, 15, 1, 1, 2)
  280. self.z_ois = OptionalInputSection(self.zeroz_cb, [toolchangez_lbl, self.toolchangez_entry])
  281. # ## GCode Button
  282. self.gcode_button = QtWidgets.QPushButton(_("Generate GCode"))
  283. self.gcode_button.setToolTip(
  284. _("Generate GCode file to locate and align the PCB by using\n"
  285. "the four points acquired above.")
  286. )
  287. self.gcode_button.setStyleSheet("""
  288. QPushButton
  289. {
  290. font-weight: bold;
  291. }
  292. """)
  293. grid_lay.addWidget(self.gcode_button, 16, 0, 1, 3)
  294. separator_line1 = QtWidgets.QFrame()
  295. separator_line1.setFrameShape(QtWidgets.QFrame.HLine)
  296. separator_line1.setFrameShadow(QtWidgets.QFrame.Sunken)
  297. grid_lay.addWidget(separator_line1, 17, 0, 1, 3)
  298. grid_lay.addWidget(QtWidgets.QLabel(''), 18, 0, 1, 3)
  299. # STEP 3 #
  300. step_3 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 3: Adjustments"))
  301. step_3.setToolTip(
  302. _("Calculate Scale and Skew factors based on the differences (delta)\n"
  303. "found when checking the PCB pattern. The differences must be filled\n"
  304. "in the fields Found (Delta).")
  305. )
  306. grid_lay.addWidget(step_3, 19, 0, 1, 3)
  307. # ## Factors Button
  308. self.generate_factors_button = QtWidgets.QPushButton(_("Calculate Factors"))
  309. self.generate_factors_button.setToolTip(
  310. _("Calculate Scale and Skew factors based on the differences (delta)\n"
  311. "found when checking the PCB pattern. The differences must be filled\n"
  312. "in the fields Found (Delta).")
  313. )
  314. self.generate_factors_button.setStyleSheet("""
  315. QPushButton
  316. {
  317. font-weight: bold;
  318. }
  319. """)
  320. grid_lay.addWidget(self.generate_factors_button, 20, 0, 1, 3)
  321. self.scalex_label = QtWidgets.QLabel(_("Scale Factor X:"))
  322. self.scalex_label.setToolTip(
  323. _("Factor for Scale action over X axis.")
  324. )
  325. self.scalex_entry = FCDoubleSpinner()
  326. self.scalex_entry.set_range(0, 9999.9999)
  327. self.scalex_entry.set_precision(self.decimals)
  328. self.scalex_entry.setSingleStep(0.1)
  329. grid_lay.addWidget(self.scalex_label, 21, 0)
  330. grid_lay.addWidget(self.scalex_entry, 21, 1, 1, 2)
  331. self.scaley_label = QtWidgets.QLabel(_("Scale Factor Y:"))
  332. self.scaley_label.setToolTip(
  333. _("Factor for Scale action over Y axis.")
  334. )
  335. self.scaley_entry = FCDoubleSpinner()
  336. self.scaley_entry.set_range(0, 9999.9999)
  337. self.scaley_entry.set_precision(self.decimals)
  338. self.scaley_entry.setSingleStep(0.1)
  339. grid_lay.addWidget(self.scaley_label, 22, 0)
  340. grid_lay.addWidget(self.scaley_entry, 22, 1, 1, 2)
  341. self.scale_button = QtWidgets.QPushButton(_("Apply Scale Factors"))
  342. self.scale_button.setToolTip(
  343. _("Apply Scale factors on the calibration points.")
  344. )
  345. self.scale_button.setStyleSheet("""
  346. QPushButton
  347. {
  348. font-weight: bold;
  349. }
  350. """)
  351. grid_lay.addWidget(self.scale_button, 23, 0, 1, 3)
  352. self.skewx_label = QtWidgets.QLabel(_("Skew Angle X:"))
  353. self.skewx_label.setToolTip(
  354. _("Angle for Skew action, in degrees.\n"
  355. "Float number between -360 and 359.")
  356. )
  357. self.skewx_entry = FCDoubleSpinner()
  358. self.skewx_entry.set_range(-360, 360)
  359. self.skewx_entry.set_precision(self.decimals)
  360. self.skewx_entry.setSingleStep(0.1)
  361. grid_lay.addWidget(self.skewx_label, 24, 0)
  362. grid_lay.addWidget(self.skewx_entry, 24, 1, 1, 2)
  363. self.skewy_label = QtWidgets.QLabel(_("Skew Angle Y:"))
  364. self.skewy_label.setToolTip(
  365. _("Angle for Skew action, in degrees.\n"
  366. "Float number between -360 and 359.")
  367. )
  368. self.skewy_entry = FCDoubleSpinner()
  369. self.skewy_entry.set_range(-360, 360)
  370. self.skewy_entry.set_precision(self.decimals)
  371. self.skewy_entry.setSingleStep(0.1)
  372. grid_lay.addWidget(self.skewy_label, 25, 0)
  373. grid_lay.addWidget(self.skewy_entry, 25, 1, 1, 2)
  374. self.skew_button = QtWidgets.QPushButton(_("Apply Skew Factors"))
  375. self.skew_button.setToolTip(
  376. _("Apply Skew factors on the calibration points.")
  377. )
  378. self.skew_button.setStyleSheet("""
  379. QPushButton
  380. {
  381. font-weight: bold;
  382. }
  383. """)
  384. grid_lay.addWidget(self.skew_button, 26, 0, 1, 3)
  385. # final_factors_lbl = QtWidgets.QLabel('<b>%s</b>' % _("Final Factors"))
  386. # final_factors_lbl.setToolTip(
  387. # _("Generate verification GCode file adjusted with\n"
  388. # "the factors above.")
  389. # )
  390. # grid_lay.addWidget(final_factors_lbl, 27, 0, 1, 3)
  391. #
  392. # self.fin_scalex_label = QtWidgets.QLabel(_("Scale Factor X:"))
  393. # self.fin_scalex_label.setToolTip(
  394. # _("Final factor for Scale action over X axis.")
  395. # )
  396. # self.fin_scalex_entry = FCDoubleSpinner()
  397. # self.fin_scalex_entry.set_range(0, 9999.9999)
  398. # self.fin_scalex_entry.set_precision(self.decimals)
  399. # self.fin_scalex_entry.setSingleStep(0.1)
  400. #
  401. # grid_lay.addWidget(self.fin_scalex_label, 28, 0)
  402. # grid_lay.addWidget(self.fin_scalex_entry, 28, 1, 1, 2)
  403. #
  404. # self.fin_scaley_label = QtWidgets.QLabel(_("Scale Factor Y:"))
  405. # self.fin_scaley_label.setToolTip(
  406. # _("Final factor for Scale action over Y axis.")
  407. # )
  408. # self.fin_scaley_entry = FCDoubleSpinner()
  409. # self.fin_scaley_entry.set_range(0, 9999.9999)
  410. # self.fin_scaley_entry.set_precision(self.decimals)
  411. # self.fin_scaley_entry.setSingleStep(0.1)
  412. #
  413. # grid_lay.addWidget(self.fin_scaley_label, 29, 0)
  414. # grid_lay.addWidget(self.fin_scaley_entry, 29, 1, 1, 2)
  415. #
  416. # self.fin_skewx_label = QtWidgets.QLabel(_("Skew Angle X:"))
  417. # self.fin_skewx_label.setToolTip(
  418. # _("Final value for angle for Skew action, in degrees.\n"
  419. # "Float number between -360 and 359.")
  420. # )
  421. # self.fin_skewx_entry = FCDoubleSpinner()
  422. # self.fin_skewx_entry.set_range(-360, 360)
  423. # self.fin_skewx_entry.set_precision(self.decimals)
  424. # self.fin_skewx_entry.setSingleStep(0.1)
  425. #
  426. # grid_lay.addWidget(self.fin_skewx_label, 30, 0)
  427. # grid_lay.addWidget(self.fin_skewx_entry, 30, 1, 1, 2)
  428. #
  429. # self.fin_skewy_label = QtWidgets.QLabel(_("Skew Angle Y:"))
  430. # self.fin_skewy_label.setToolTip(
  431. # _("Final value for angle for Skew action, in degrees.\n"
  432. # "Float number between -360 and 359.")
  433. # )
  434. # self.fin_skewy_entry = FCDoubleSpinner()
  435. # self.fin_skewy_entry.set_range(-360, 360)
  436. # self.fin_skewy_entry.set_precision(self.decimals)
  437. # self.fin_skewy_entry.setSingleStep(0.1)
  438. #
  439. # grid_lay.addWidget(self.fin_skewy_label, 31, 0)
  440. # grid_lay.addWidget(self.fin_skewy_entry, 31, 1, 1, 2)
  441. separator_line1 = QtWidgets.QFrame()
  442. separator_line1.setFrameShape(QtWidgets.QFrame.HLine)
  443. separator_line1.setFrameShadow(QtWidgets.QFrame.Sunken)
  444. grid_lay.addWidget(separator_line1, 32, 0, 1, 3)
  445. grid_lay.addWidget(QtWidgets.QLabel(''), 32, 0, 1, 3)
  446. # STEP 4 #
  447. step_4 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 4: Adjusted GCode"))
  448. step_4.setToolTip(
  449. _("Generate verification GCode file adjusted with\n"
  450. "the factors above.")
  451. )
  452. grid_lay.addWidget(step_4, 34, 0, 1, 3)
  453. # ## Adjusted GCode Button
  454. self.adj_gcode_button = QtWidgets.QPushButton(_("Generate Adjusted GCode"))
  455. self.adj_gcode_button.setToolTip(
  456. _("Generate verification GCode file adjusted with\n"
  457. "the factors above.")
  458. )
  459. self.adj_gcode_button.setStyleSheet("""
  460. QPushButton
  461. {
  462. font-weight: bold;
  463. }
  464. """)
  465. grid_lay.addWidget(self.adj_gcode_button, 35, 0, 1, 3)
  466. separator_line1 = QtWidgets.QFrame()
  467. separator_line1.setFrameShape(QtWidgets.QFrame.HLine)
  468. separator_line1.setFrameShadow(QtWidgets.QFrame.Sunken)
  469. grid_lay.addWidget(separator_line1, 36, 0, 1, 3)
  470. grid_lay.addWidget(QtWidgets.QLabel(''), 37, 0, 1, 3)
  471. # STEP 5 #
  472. step_5 = QtWidgets.QLabel('<b>%s</b>' % _("STEP 5: Calibrate FlatCAM Objects"))
  473. step_5.setToolTip(
  474. _("Adjust the FlatCAM objects\n"
  475. "with the factors determined and verified above.")
  476. )
  477. grid_lay.addWidget(step_5, 38, 0, 1, 3)
  478. self.adj_object_type_combo = QtWidgets.QComboBox()
  479. self.adj_object_type_combo.addItems([_("Gerber"), _("Excellon"), _("Geometry")])
  480. self.adj_object_type_combo.setCurrentIndex(0)
  481. self.adj_object_type_label = QtWidgets.QLabel("%s:" % _("Adjusted object type"))
  482. self.adj_object_type_label.setToolTip(
  483. _("Type of the FlatCAM Object to be adjusted.")
  484. )
  485. grid_lay.addWidget(self.adj_object_type_label, 39, 0, 1, 3)
  486. grid_lay.addWidget(self.adj_object_type_combo, 40, 0, 1, 3)
  487. self.adj_object_combo = FCComboBox()
  488. self.adj_object_combo.setModel(self.app.collection)
  489. self.adj_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  490. self.adj_object_combo.setCurrentIndex(0)
  491. self.adj_object_label = QtWidgets.QLabel("%s:" % _("Adjusted object selection"))
  492. self.adj_object_label.setToolTip(
  493. _("The FlatCAM Object to be adjusted.")
  494. )
  495. grid_lay.addWidget(self.adj_object_label, 41, 0, 1, 3)
  496. grid_lay.addWidget(self.adj_object_combo, 42, 0, 1, 3)
  497. # ## Adjust Objects Button
  498. self.cal_button = QtWidgets.QPushButton(_("Calibrate"))
  499. self.cal_button.setToolTip(
  500. _("Adjust (scale and/or skew) the objects\n"
  501. "with the factors determined above.")
  502. )
  503. self.cal_button.setStyleSheet("""
  504. QPushButton
  505. {
  506. font-weight: bold;
  507. }
  508. """)
  509. grid_lay.addWidget(self.cal_button, 43, 0, 1, 3)
  510. separator_line2 = QtWidgets.QFrame()
  511. separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
  512. separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
  513. grid_lay.addWidget(separator_line2, 44, 0, 1, 3)
  514. grid_lay.addWidget(QtWidgets.QLabel(''), 45, 0, 1, 3)
  515. self.layout.addStretch()
  516. # ## Reset Tool
  517. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  518. self.reset_button.setToolTip(
  519. _("Will reset the tool parameters.")
  520. )
  521. self.reset_button.setStyleSheet("""
  522. QPushButton
  523. {
  524. font-weight: bold;
  525. }
  526. """)
  527. self.layout.addWidget(self.reset_button)
  528. self.mr = None
  529. self.units = ''
  530. # here store 4 points to be used for calibration
  531. self.click_points = list()
  532. # store the status of the grid
  533. self.grid_status_memory = None
  534. self.target_obj = None
  535. # if the mouse events are connected to a local method set this True
  536. self.local_connected = False
  537. # reference for the tab where to open and view the verification GCode
  538. self.gcode_editor_tab = None
  539. # calibrated object
  540. self.cal_object = None
  541. # ## Signals
  542. self.start_button.clicked.connect(self.on_start_collect_points)
  543. self.gcode_button.clicked.connect(self.generate_verification_gcode)
  544. self.generate_factors_button.clicked.connect(self.calculate_factors)
  545. self.reset_button.clicked.connect(self.set_tool_ui)
  546. self.cal_source_radio.activated_custom.connect(self.on_cal_source_radio)
  547. self.obj_type_combo.currentIndexChanged.connect(self.on_obj_type_combo)
  548. self.adj_object_type_combo.currentIndexChanged.connect(self.on_adj_obj_type_combo)
  549. self.cal_button.clicked.connect(self.on_cal_button_click)
  550. def run(self, toggle=True):
  551. self.app.report_usage("ToolCalibration()")
  552. if toggle:
  553. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  554. if self.app.ui.splitter.sizes()[0] == 0:
  555. self.app.ui.splitter.setSizes([1, 1])
  556. else:
  557. try:
  558. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  559. # if tab is populated with the tool but it does not have the focus, focus on it
  560. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  561. # focus on Tool Tab
  562. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  563. else:
  564. self.app.ui.splitter.setSizes([0, 1])
  565. except AttributeError:
  566. pass
  567. else:
  568. if self.app.ui.splitter.sizes()[0] == 0:
  569. self.app.ui.splitter.setSizes([1, 1])
  570. FlatCAMTool.run(self)
  571. self.set_tool_ui()
  572. self.app.ui.notebook.setTabText(2, _("Calibrate Tool"))
  573. def install(self, icon=None, separator=None, **kwargs):
  574. FlatCAMTool.install(self, icon, separator, shortcut='ALT+E', **kwargs)
  575. def set_tool_ui(self):
  576. self.units = self.app.defaults['units'].upper()
  577. if self.local_connected is True:
  578. self.disconnect_cal_events()
  579. self.reset_calibration_points()
  580. self.cal_source_radio.set_value(self.app.defaults['tools_cal_calsource'])
  581. self.travelz_entry.set_value(self.app.defaults['tools_cal_travelz'])
  582. self.verz_entry.set_value(self.app.defaults['tools_cal_verz'])
  583. self.zeroz_cb.set_value(self.app.defaults['tools_cal_zeroz'])
  584. self.toolchangez_entry.set_value(self.app.defaults['tools_cal_toolchangez'])
  585. self.scalex_entry.set_value(1.0)
  586. self.scaley_entry.set_value(1.0)
  587. self.skewx_entry.set_value(0.0)
  588. self.skewy_entry.set_value(0.0)
  589. # calibrated object
  590. self.cal_object = None
  591. self.app.inform.emit('%s...' % _("Tool initialized"))
  592. def on_obj_type_combo(self):
  593. obj_type = self.obj_type_combo.currentIndex()
  594. self.object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  595. self.object_combo.setCurrentIndex(0)
  596. def on_adj_obj_type_combo(self):
  597. obj_type = self.adj_object_type_combo.currentIndex()
  598. self.adj_object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  599. self.adj_object_combo.setCurrentIndex(0)
  600. def on_cal_source_radio(self, val):
  601. if val == 'object':
  602. self.obj_type_label.setDisabled(False)
  603. self.obj_type_combo.setDisabled(False)
  604. self.object_label.setDisabled(False)
  605. self.object_combo.setDisabled(False)
  606. else:
  607. self.obj_type_label.setDisabled(True)
  608. self.obj_type_combo.setDisabled(True)
  609. self.object_label.setDisabled(True)
  610. self.object_combo.setDisabled(True)
  611. def on_start_collect_points(self):
  612. # disengage the grid snapping since it will be hard to find the drills on grid
  613. if self.app.ui.grid_snap_btn.isChecked():
  614. self.grid_status_memory = True
  615. self.app.ui.grid_snap_btn.trigger()
  616. else:
  617. self.grid_status_memory = False
  618. self.mr = self.canvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
  619. if self.app.is_legacy is False:
  620. self.canvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
  621. else:
  622. self.canvas.graph_event_disconnect(self.app.mr)
  623. self.local_connected = True
  624. if self.cal_source_radio.get_value() == 'object':
  625. selection_index = self.object_combo.currentIndex()
  626. model_index = self.app.collection.index(selection_index, 0, self.object_combo.rootModelIndex())
  627. try:
  628. self.target_obj = model_index.internalPointer().obj
  629. except Exception:
  630. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no target object loaded ..."))
  631. return
  632. self.reset_calibration_points()
  633. self.app.inform.emit(_("Get First calibration point. Bottom Left..."))
  634. def on_mouse_click_release(self, event):
  635. if event.button == 1:
  636. if self.app.is_legacy is False:
  637. event_pos = event.pos
  638. else:
  639. event_pos = (event.xdata, event.ydata)
  640. pos_canvas = self.canvas.translate_coords(event_pos)
  641. click_pt = Point([pos_canvas[0], pos_canvas[1]])
  642. if self.cal_source_radio.get_value() == 'object':
  643. if self.target_obj.kind.lower() == 'excellon':
  644. for tool, tool_dict in self.target_obj.tools.items():
  645. for geo in tool_dict['solid_geometry']:
  646. if click_pt.within(geo):
  647. center_pt = geo.centroid
  648. self.click_points.append(
  649. (
  650. float('%.*f' % (self.decimals, center_pt.x)),
  651. float('%.*f' % (self.decimals, center_pt.y))
  652. )
  653. )
  654. self.check_points()
  655. else:
  656. for apid, apid_val in self.target_obj.apertures.items():
  657. for geo_el in apid_val['geometry']:
  658. if 'solid' in geo_el:
  659. if click_pt.within(geo_el['solid']):
  660. if isinstance(geo_el['follow'], Point):
  661. center_pt = geo_el['solid'].centroid
  662. self.click_points.append(
  663. (
  664. float('%.*f' % (self.decimals, center_pt.x)),
  665. float('%.*f' % (self.decimals, center_pt.y))
  666. )
  667. )
  668. self.check_points()
  669. else:
  670. self.click_points.append(
  671. (
  672. float('%.*f' % (self.decimals, click_pt.x)),
  673. float('%.*f' % (self.decimals, click_pt.y))
  674. )
  675. )
  676. self.check_points()
  677. def check_points(self):
  678. if len(self.click_points) == 1:
  679. self.bottom_left_coordx_tgt.set_value(self.click_points[0][0])
  680. self.bottom_left_coordy_tgt.set_value(self.click_points[0][1])
  681. self.app.inform.emit(_("Get Second calibration point. Bottom Right..."))
  682. elif len(self.click_points) == 2:
  683. self.bottom_right_coordx_tgt.set_value(self.click_points[1][0])
  684. self.bottom_right_coordy_tgt.set_value(self.click_points[1][1])
  685. self.app.inform.emit(_("Get Third calibration point. Top Left..."))
  686. elif len(self.click_points) == 3:
  687. self.top_left_coordx_tgt.set_value(self.click_points[2][0])
  688. self.top_left_coordy_tgt.set_value(self.click_points[2][1])
  689. self.app.inform.emit(_("Get Forth calibration point. Top Right..."))
  690. elif len(self.click_points) == 4:
  691. self.top_right_coordx_tgt.set_value(self.click_points[3][0])
  692. self.top_right_coordy_tgt.set_value(self.click_points[3][1])
  693. self.app.inform.emit('[success] %s' % _("Done. All four points have been acquired."))
  694. self.disconnect_cal_events()
  695. def reset_calibration_points(self):
  696. self.click_points = list()
  697. self.bottom_left_coordx_tgt.set_value('')
  698. self.bottom_left_coordy_tgt.set_value('')
  699. self.bottom_right_coordx_tgt.set_value('')
  700. self.bottom_right_coordy_tgt.set_value('')
  701. self.top_left_coordx_tgt.set_value('')
  702. self.top_left_coordy_tgt.set_value('')
  703. self.top_right_coordx_tgt.set_value('')
  704. self.top_right_coordy_tgt.set_value('')
  705. def gcode_header(self):
  706. log.debug("ToolCalibration.gcode_header()")
  707. time_str = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
  708. gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
  709. (str(self.app.version), str(self.app.version_date)) + '\n'
  710. gcode += '(Name: ' + _('Verification GCode for FlatCAM Calibrate Tool') + ')\n'
  711. gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
  712. gcode += '(Created on ' + time_str + ')\n' + '\n'
  713. gcode += 'G20\n' if self.units.upper() == 'IN' else 'G21\n'
  714. gcode += 'G90\n'
  715. gcode += 'G17\n'
  716. gcode += 'G94\n\n'
  717. return gcode
  718. def close_tab(self):
  719. for idx in range(self.app.ui.plot_tab_area.count()):
  720. if self.app.ui.plot_tab_area.tabText(idx) == _("Gcode Viewer"):
  721. wdg = self.app.ui.plot_tab_area.widget(idx)
  722. wdg.deleteLater()
  723. self.app.ui.plot_tab_area.removeTab(idx)
  724. def generate_verification_gcode(self):
  725. travel_z = '%.*f' % (self.decimals, self.travelz_entry.get_value())
  726. toolchange_z = '%.*f' % (self.decimals, self.toolchangez_entry.get_value())
  727. verification_z = '%.*f' % (self.decimals, self.verz_entry.get_value())
  728. if len(self.click_points) != 4:
  729. self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled. Four points are needed for GCode generation."))
  730. return 'fail'
  731. gcode = self.gcode_header()
  732. if self.zeroz_cb.get_value():
  733. gcode += 'M5\n'
  734. gcode += f'G00 Z{toolchange_z}\n'
  735. gcode += 'M0\n'
  736. gcode += 'G01 Z0\n'
  737. gcode += 'M0\n'
  738. gcode += f'G00 Z{toolchange_z}\n'
  739. gcode += 'M0\n'
  740. gcode += f'G00 Z{travel_z}\n'
  741. gcode += f'G00 X{self.click_points[0][0]} Y{self.click_points[0][1]}\n'
  742. gcode += f'G01 Z{verification_z}\n'
  743. gcode += 'M0\n'
  744. gcode += f'G00 Z{travel_z}\n'
  745. gcode += f'G00 X{self.click_points[2][0]} Y{self.click_points[2][1]}\n'
  746. gcode += f'G01 Z{verification_z}\n'
  747. gcode += 'M0\n'
  748. gcode += f'G00 Z{travel_z}\n'
  749. gcode += f'G00 X{self.click_points[3][0]} Y{self.click_points[3][1]}\n'
  750. gcode += f'G01 Z{verification_z}\n'
  751. gcode += 'M0\n'
  752. gcode += f'G00 Z{travel_z}\n'
  753. gcode += f'G00 X{self.click_points[1][0]} Y{self.click_points[1][1]}\n'
  754. gcode += f'G01 Z{verification_z}\n'
  755. gcode += 'M0\n'
  756. gcode += f'G00 Z{travel_z}\n'
  757. gcode += f'G00 X0 Y0\n'
  758. gcode += f'G00 Z{toolchange_z}\n'
  759. gcode += 'M2'
  760. self.gcode_editor_tab = TextEditor(app=self.app, plain_text=True)
  761. # add the tab if it was closed
  762. self.app.ui.plot_tab_area.addTab(self.gcode_editor_tab, '%s' % _("Gcode Viewer"))
  763. self.gcode_editor_tab.setObjectName('gcode_viewer_tab')
  764. # delete the absolute and relative position and messages in the infobar
  765. self.app.ui.position_label.setText("")
  766. self.app.ui.rel_position_label.setText("")
  767. # first clear previous text in text editor (if any)
  768. self.gcode_editor_tab.code_editor.clear()
  769. self.gcode_editor_tab.code_editor.setReadOnly(False)
  770. self.gcode_editor_tab.code_editor.completer_enable = False
  771. self.gcode_editor_tab.buttonRun.hide()
  772. # Switch plot_area to CNCJob tab
  773. self.app.ui.plot_tab_area.setCurrentWidget(self.gcode_editor_tab)
  774. self.gcode_editor_tab.t_frame.hide()
  775. # then append the text from GCode to the text editor
  776. try:
  777. self.gcode_editor_tab.code_editor.setPlainText(gcode)
  778. except Exception as e:
  779. self.app.inform.emit('[ERROR] %s %s' % ('ERROR -->', str(e)))
  780. return
  781. self.gcode_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
  782. self.gcode_editor_tab.t_frame.show()
  783. self.app.proc_container.view.set_idle()
  784. self.app.inform.emit('[success] %s...' % _('Loaded Machine Code into Code Editor'))
  785. _filter_ = "G-Code Files (*.nc);;All Files (*.*)"
  786. self.gcode_editor_tab.buttonSave.clicked.disconnect()
  787. self.gcode_editor_tab.buttonSave.clicked.connect(
  788. lambda: self.gcode_editor_tab.handleSaveGCode(name='fc_ver_gcode', filt=_filter_, callback=self.close_tab))
  789. def calculate_factors(self):
  790. origin_x = self.click_points[0][0]
  791. origin_y = self.click_points[0][1]
  792. top_left_x = float('%.*f' % (self.decimals, self.click_points[2][0]))
  793. top_left_y = float('%.*f' % (self.decimals, self.click_points[2][1]))
  794. try:
  795. top_left_dx = float('%.*f' % (self.decimals, self.top_left_coordx_found.get_value()))
  796. except TypeError:
  797. top_left_dx = top_left_x
  798. try:
  799. top_left_dy = float('%.*f' % (self.decimals, self.top_left_coordy_found.get_value()))
  800. except TypeError:
  801. top_left_dy = top_left_y
  802. # top_right_x = float('%.*f' % (self.decimals, self.click_points[3][0]))
  803. # top_right_y = float('%.*f' % (self.decimals, self.click_points[3][1]))
  804. # try:
  805. # top_right_dx = float('%.*f' % (self.decimals, self.top_right_coordx_found.get_value()))
  806. # except TypeError:
  807. # top_right_dx = top_right_x
  808. #
  809. # try:
  810. # top_right_dy = float('%.*f' % (self.decimals, self.top_right_coordy_found.get_value()))
  811. # except TypeError:
  812. # top_right_dy = top_right_y
  813. bot_right_x = float('%.*f' % (self.decimals, self.click_points[1][0]))
  814. bot_right_y = float('%.*f' % (self.decimals, self.click_points[1][1]))
  815. try:
  816. bot_right_dx = float('%.*f' % (self.decimals, self.bottom_right_coordx_found.get_value()))
  817. except TypeError:
  818. bot_right_dx = bot_right_x
  819. try:
  820. bot_right_dy = float('%.*f' % (self.decimals, self.bottom_right_coordy_found.get_value()))
  821. except TypeError:
  822. bot_right_dy = bot_right_y
  823. # ------------------------------------------------------------------------------- #
  824. # --------------------------- FACTORS CALCULUS ---------------------------------- #
  825. # ------------------------------------------------------------------------------- #
  826. if top_left_dy != float('%.*f' % (self.decimals, 0.0)):
  827. # we have scale on Y
  828. scale_y = (top_left_dy + top_left_y - origin_y) / (top_left_y - origin_y)
  829. self.scaley_entry.set_value(scale_y)
  830. if top_left_dx != float('%.*f' % (self.decimals, 0.0)):
  831. # we have skew on X
  832. dx = top_left_dx
  833. dy = top_left_y - origin_y
  834. skew_angle_x = math.degrees(math.atan(dx / dy))
  835. self.skewx_entry.set_value(skew_angle_x)
  836. if bot_right_dx != float('%.*f' % (self.decimals, 0.0)):
  837. # we have scale on X
  838. scale_x = (bot_right_dx + bot_right_x - origin_x) / (bot_right_x - origin_x)
  839. self.scalex_entry.set_value(scale_x)
  840. if bot_right_dy != float('%.*f' % (self.decimals, 0.0)):
  841. # we have skew on Y
  842. dx = bot_right_x - origin_x
  843. dy = bot_right_dy + origin_y
  844. skew_angle_y = math.degrees(math.atan(dy / dx))
  845. self.skewy_entry.set_value(skew_angle_y)
  846. def on_cal_button_click(self):
  847. # get the FlatCAM object to calibrate
  848. selection_index = self.adj_object_combo.currentIndex()
  849. model_index = self.app.collection.index(selection_index, 0, self.adj_object_combo.rootModelIndex())
  850. try:
  851. self.cal_object = model_index.internalPointer().obj
  852. except Exception as e:
  853. log.debug("ToolCalibration.on_cal_button_click() --> %s" % str(e))
  854. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no FlatCAM object selected..."))
  855. return 'fail'
  856. # create a new object adjusted (calibrated)
  857. # TODO
  858. def disconnect_cal_events(self):
  859. # restore the Grid snapping if it was active before
  860. if self.grid_status_memory is True:
  861. self.app.ui.grid_snap_btn.trigger()
  862. self.app.mr = self.canvas.graph_event_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
  863. if self.app.is_legacy is False:
  864. self.canvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
  865. else:
  866. self.canvas.graph_event_disconnect(self.mr)
  867. self.local_connected = False
  868. def reset_fields(self):
  869. self.object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  870. self.adj_exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  871. self.adj_geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  872. # end of file