ToolCalibration.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  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 Excellon and Cutout Geometry objects\n"
  475. "with the factors determined, and verified, above.")
  476. )
  477. grid_lay.addWidget(step_5, 38, 0, 1, 3)
  478. self.adj_exc_object_combo = QtWidgets.QComboBox()
  479. self.adj_exc_object_combo.setModel(self.app.collection)
  480. self.adj_exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  481. self.adj_exc_object_combo.setCurrentIndex(1)
  482. self.adj_excobj_label = QtWidgets.QLabel("%s:" % _("EXCELLON"))
  483. self.adj_excobj_label.setToolTip(
  484. _("Excellon Object to be adjusted.")
  485. )
  486. grid_lay.addWidget(self.adj_excobj_label, 39, 0, 1, 3)
  487. grid_lay.addWidget(self.adj_exc_object_combo, 40, 0, 1, 3)
  488. self.adj_geo_object_combo = QtWidgets.QComboBox()
  489. self.adj_geo_object_combo.setModel(self.app.collection)
  490. self.adj_geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  491. self.adj_geo_object_combo.setCurrentIndex(1)
  492. self.adj_geoobj_label = QtWidgets.QLabel("%s:" % _("GEOMETRY"))
  493. self.adj_geoobj_label.setToolTip(
  494. _("Geometry Object to be adjusted.")
  495. )
  496. grid_lay.addWidget(self.adj_geoobj_label, 41, 0, 1, 3)
  497. grid_lay.addWidget(self.adj_geo_object_combo, 42, 0, 1, 3)
  498. # ## Adjust Objects Button
  499. self.adj_obj_button = QtWidgets.QPushButton(_("Calibrate"))
  500. self.adj_obj_button.setToolTip(
  501. _("Adjust (scale and/or skew) the objects\n"
  502. "with the factors determined above.")
  503. )
  504. self.adj_obj_button.setStyleSheet("""
  505. QPushButton
  506. {
  507. font-weight: bold;
  508. }
  509. """)
  510. grid_lay.addWidget(self.adj_obj_button, 43, 0, 1, 3)
  511. separator_line2 = QtWidgets.QFrame()
  512. separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
  513. separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
  514. grid_lay.addWidget(separator_line2, 44, 0, 1, 3)
  515. grid_lay.addWidget(QtWidgets.QLabel(''), 45, 0, 1, 3)
  516. self.layout.addStretch()
  517. # ## Reset Tool
  518. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  519. self.reset_button.setToolTip(
  520. _("Will reset the tool parameters.")
  521. )
  522. self.reset_button.setStyleSheet("""
  523. QPushButton
  524. {
  525. font-weight: bold;
  526. }
  527. """)
  528. self.layout.addWidget(self.reset_button)
  529. self.mr = None
  530. self.units = ''
  531. # here store 4 points to be used for calibration
  532. self.click_points = list()
  533. # store the status of the grid
  534. self.grid_status_memory = None
  535. self.target_obj = None
  536. # if the mouse events are connected to a local method set this True
  537. self.local_connected = False
  538. # ## Signals
  539. self.start_button.clicked.connect(self.on_start_collect_points)
  540. self.gcode_button.clicked.connect(self.generate_verification_gcode)
  541. self.generate_factors_button.clicked.connect(self.calculate_factors)
  542. self.reset_button.clicked.connect(self.set_tool_ui)
  543. self.cal_source_radio.activated_custom.connect(self.on_cal_source_radio)
  544. self.obj_type_combo.currentIndexChanged.connect(self.on_obj_type_combo)
  545. def run(self, toggle=True):
  546. self.app.report_usage("ToolCalibration()")
  547. if toggle:
  548. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  549. if self.app.ui.splitter.sizes()[0] == 0:
  550. self.app.ui.splitter.setSizes([1, 1])
  551. else:
  552. try:
  553. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  554. # if tab is populated with the tool but it does not have the focus, focus on it
  555. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  556. # focus on Tool Tab
  557. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  558. else:
  559. self.app.ui.splitter.setSizes([0, 1])
  560. except AttributeError:
  561. pass
  562. else:
  563. if self.app.ui.splitter.sizes()[0] == 0:
  564. self.app.ui.splitter.setSizes([1, 1])
  565. FlatCAMTool.run(self)
  566. self.set_tool_ui()
  567. self.app.ui.notebook.setTabText(2, _("Calibrate Tool"))
  568. def install(self, icon=None, separator=None, **kwargs):
  569. FlatCAMTool.install(self, icon, separator, shortcut='ALT+E', **kwargs)
  570. def set_tool_ui(self):
  571. self.units = self.app.defaults['units'].upper()
  572. if self.local_connected is True:
  573. self.disconnect_cal_events()
  574. self.reset_calibration_points()
  575. self.cal_source_radio.set_value(self.app.defaults['tools_cal_calsource'])
  576. self.travelz_entry.set_value(self.app.defaults['tools_cal_travelz'])
  577. self.verz_entry.set_value(self.app.defaults['tools_cal_verz'])
  578. self.zeroz_cb.set_value(self.app.defaults['tools_cal_zeroz'])
  579. self.toolchangez_entry.set_value(self.app.defaults['tools_cal_toolchangez'])
  580. self.scalex_entry.set_value(1.0)
  581. self.scaley_entry.set_value(1.0)
  582. self.skewx_entry.set_value(0.0)
  583. self.skewy_entry.set_value(0.0)
  584. self.app.inform.emit('%s...' % _("Tool initialized"))
  585. def on_obj_type_combo(self):
  586. obj_type = self.obj_type_combo.currentIndex()
  587. self.object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  588. self.object_combo.setCurrentIndex(0)
  589. def on_cal_source_radio(self, val):
  590. if val == 'object':
  591. self.obj_type_label.setDisabled(False)
  592. self.obj_type_combo.setDisabled(False)
  593. self.object_label.setDisabled(False)
  594. self.object_combo.setDisabled(False)
  595. else:
  596. self.obj_type_label.setDisabled(True)
  597. self.obj_type_combo.setDisabled(True)
  598. self.object_label.setDisabled(True)
  599. self.object_combo.setDisabled(True)
  600. def on_start_collect_points(self):
  601. # disengage the grid snapping since it will be hard to find the drills on grid
  602. if self.app.ui.grid_snap_btn.isChecked():
  603. self.grid_status_memory = True
  604. self.app.ui.grid_snap_btn.trigger()
  605. else:
  606. self.grid_status_memory = False
  607. self.mr = self.canvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
  608. if self.app.is_legacy is False:
  609. self.canvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
  610. else:
  611. self.canvas.graph_event_disconnect(self.app.mr)
  612. self.local_connected = True
  613. if self.cal_source_radio.get_value() == 'object':
  614. selection_index = self.object_combo.currentIndex()
  615. model_index = self.app.collection.index(selection_index, 0, self.object_combo.rootModelIndex())
  616. try:
  617. self.target_obj = model_index.internalPointer().obj
  618. except Exception:
  619. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no target object loaded ..."))
  620. return
  621. self.reset_calibration_points()
  622. self.app.inform.emit(_("Get First calibration point. Bottom Left..."))
  623. def on_mouse_click_release(self, event):
  624. if event.button == 1:
  625. if self.app.is_legacy is False:
  626. event_pos = event.pos
  627. else:
  628. event_pos = (event.xdata, event.ydata)
  629. pos_canvas = self.canvas.translate_coords(event_pos)
  630. click_pt = Point([pos_canvas[0], pos_canvas[1]])
  631. if self.cal_source_radio.get_value() == 'object':
  632. if self.target_obj.kind.lower() == 'excellon':
  633. for tool, tool_dict in self.target_obj.tools.items():
  634. for geo in tool_dict['solid_geometry']:
  635. if click_pt.within(geo):
  636. center_pt = geo.centroid
  637. self.click_points.append(
  638. (
  639. float('%.*f' % (self.decimals, center_pt.x)),
  640. float('%.*f' % (self.decimals, center_pt.y))
  641. )
  642. )
  643. self.check_points()
  644. else:
  645. for apid, apid_val in self.target_obj.apertures.items():
  646. for geo_el in apid_val['geometry']:
  647. if 'solid' in geo_el:
  648. if click_pt.within(geo_el['solid']):
  649. if isinstance(geo_el['follow'], Point):
  650. center_pt = geo_el['solid'].centroid
  651. self.click_points.append(
  652. (
  653. float('%.*f' % (self.decimals, center_pt.x)),
  654. float('%.*f' % (self.decimals, center_pt.y))
  655. )
  656. )
  657. self.check_points()
  658. else:
  659. self.click_points.append(
  660. (
  661. float('%.*f' % (self.decimals, click_pt.x)),
  662. float('%.*f' % (self.decimals, click_pt.y))
  663. )
  664. )
  665. self.check_points()
  666. def check_points(self):
  667. if len(self.click_points) == 1:
  668. self.bottom_left_coordx_tgt.set_value(self.click_points[0][0])
  669. self.bottom_left_coordy_tgt.set_value(self.click_points[0][1])
  670. self.app.inform.emit(_("Get Second calibration point. Bottom Right..."))
  671. elif len(self.click_points) == 2:
  672. self.bottom_right_coordx_tgt.set_value(self.click_points[1][0])
  673. self.bottom_right_coordy_tgt.set_value(self.click_points[1][1])
  674. self.app.inform.emit(_("Get Third calibration point. Top Left..."))
  675. elif len(self.click_points) == 3:
  676. self.top_left_coordx_tgt.set_value(self.click_points[2][0])
  677. self.top_left_coordy_tgt.set_value(self.click_points[2][1])
  678. self.app.inform.emit(_("Get Forth calibration point. Top Right..."))
  679. elif len(self.click_points) == 4:
  680. self.top_right_coordx_tgt.set_value(self.click_points[3][0])
  681. self.top_right_coordy_tgt.set_value(self.click_points[3][1])
  682. self.app.inform.emit('[success] %s' % _("Done. All four points have been acquired."))
  683. self.disconnect_cal_events()
  684. def reset_calibration_points(self):
  685. self.click_points = list()
  686. self.bottom_left_coordx_tgt.set_value('')
  687. self.bottom_left_coordy_tgt.set_value('')
  688. self.bottom_right_coordx_tgt.set_value('')
  689. self.bottom_right_coordy_tgt.set_value('')
  690. self.top_left_coordx_tgt.set_value('')
  691. self.top_left_coordy_tgt.set_value('')
  692. self.top_right_coordx_tgt.set_value('')
  693. self.top_right_coordy_tgt.set_value('')
  694. def gcode_header(self):
  695. log.debug("ToolCalibration.gcode_header()")
  696. time_str = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
  697. gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
  698. (str(self.app.version), str(self.app.version_date)) + '\n'
  699. gcode += '(Name: ' + _('Verification GCode for FlatCAM Calibrate Tool') + ')\n'
  700. gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
  701. gcode += '(Created on ' + time_str + ')\n' + '\n'
  702. gcode += 'G20\n' if self.units.upper() == 'IN' else 'G21\n'
  703. gcode += 'G90\n'
  704. gcode += 'G17\n'
  705. gcode += 'G94\n\n'
  706. return gcode
  707. def close_tab(self):
  708. for idx in range(self.app.ui.plot_tab_area.count()):
  709. if self.app.ui.plot_tab_area.tabText(idx) == _("Gcode Viewer"):
  710. wdg = self.app.ui.plot_tab_area.widget(idx)
  711. wdg.deleteLater()
  712. self.app.ui.plot_tab_area.removeTab(idx)
  713. def generate_verification_gcode(self):
  714. travel_z = '%.*f' % (self.decimals, self.travelz_entry.get_value())
  715. toolchange_z = '%.*f' % (self.decimals, self.toolchangez_entry.get_value())
  716. verification_z = '%.*f' % (self.decimals, self.verz_entry.get_value())
  717. if len(self.click_points) != 4:
  718. self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled. Four points are needed for GCode generation."))
  719. return 'fail'
  720. gcode = self.gcode_header()
  721. if self.zeroz_cb.get_value():
  722. gcode += 'M5\n'
  723. gcode += f'G00 Z{toolchange_z}\n'
  724. gcode += 'M0\n'
  725. gcode += 'G01 Z0\n'
  726. gcode += 'M0\n'
  727. gcode += f'G00 Z{toolchange_z}\n'
  728. gcode += 'M0\n'
  729. gcode += f'G00 Z{travel_z}\n'
  730. gcode += f'G00 X{self.click_points[0][0]} Y{self.click_points[0][1]}\n'
  731. gcode += f'G01 Z{verification_z}\n'
  732. gcode += 'M0\n'
  733. gcode += f'G00 Z{travel_z}\n'
  734. gcode += f'G00 X{self.click_points[2][0]} Y{self.click_points[2][1]}\n'
  735. gcode += f'G01 Z{verification_z}\n'
  736. gcode += 'M0\n'
  737. gcode += f'G00 Z{travel_z}\n'
  738. gcode += f'G00 X{self.click_points[3][0]} Y{self.click_points[3][1]}\n'
  739. gcode += f'G01 Z{verification_z}\n'
  740. gcode += 'M0\n'
  741. gcode += f'G00 Z{travel_z}\n'
  742. gcode += f'G00 X{self.click_points[1][0]} Y{self.click_points[1][1]}\n'
  743. gcode += f'G01 Z{verification_z}\n'
  744. gcode += 'M0\n'
  745. gcode += f'G00 Z{travel_z}\n'
  746. gcode += f'G00 X0 Y0\n'
  747. gcode += f'G00 Z{toolchange_z}\n'
  748. gcode += 'M2'
  749. self.gcode_editor_tab = TextEditor(app=self.app, plain_text=True)
  750. # add the tab if it was closed
  751. self.app.ui.plot_tab_area.addTab(self.gcode_editor_tab, '%s' % _("Gcode Viewer"))
  752. self.gcode_editor_tab.setObjectName('gcode_viewer_tab')
  753. # delete the absolute and relative position and messages in the infobar
  754. self.app.ui.position_label.setText("")
  755. self.app.ui.rel_position_label.setText("")
  756. # first clear previous text in text editor (if any)
  757. self.gcode_editor_tab.code_editor.clear()
  758. self.gcode_editor_tab.code_editor.setReadOnly(False)
  759. self.gcode_editor_tab.code_editor.completer_enable = False
  760. self.gcode_editor_tab.buttonRun.hide()
  761. # Switch plot_area to CNCJob tab
  762. self.app.ui.plot_tab_area.setCurrentWidget(self.gcode_editor_tab)
  763. self.gcode_editor_tab.t_frame.hide()
  764. # then append the text from GCode to the text editor
  765. try:
  766. self.gcode_editor_tab.code_editor.setPlainText(gcode)
  767. except Exception as e:
  768. self.app.inform.emit('[ERROR] %s %s' % ('ERROR -->', str(e)))
  769. return
  770. self.gcode_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
  771. self.gcode_editor_tab.t_frame.show()
  772. self.app.proc_container.view.set_idle()
  773. self.app.inform.emit('[success] %s...' % _('Loaded Machine Code into Code Editor'))
  774. _filter_ = "G-Code Files (*.nc);;All Files (*.*)"
  775. self.gcode_editor_tab.buttonSave.clicked.disconnect()
  776. self.gcode_editor_tab.buttonSave.clicked.connect(
  777. lambda: self.gcode_editor_tab.handleSaveGCode(name='fc_ver_gcode', filt=_filter_, callback=self.close_tab))
  778. #
  779. # try:
  780. # dir_file_to_save = self.app.get_last_save_folder() + '/' + 'ver_gcode'
  781. # filename, _f = QtWidgets.QFileDialog.getSaveFileName(
  782. # caption=_("Export Machine Code ..."),
  783. # directory=dir_file_to_save,
  784. # filter=_filter_
  785. # )
  786. # except TypeError:
  787. # filename, _f = QtWidgets.QFileDialog.getSaveFileName(caption=_("Export Machine Code ..."), filter=_filter_)
  788. #
  789. # filename = str(filename)
  790. #
  791. # if filename == '':
  792. # self.app.inform.emit('[WARNING_NOTCL] %s' % _("Export Machine Code cancelled ..."))
  793. # return
  794. #
  795. # with open(filename, 'w') as f:
  796. # f.write(gcode)
  797. def calculate_factors(self):
  798. origin_x = self.click_points[0][0]
  799. origin_y = self.click_points[0][1]
  800. top_left_x = float('%.*f' % (self.decimals, self.click_points[2][0]))
  801. top_left_y = float('%.*f' % (self.decimals, self.click_points[2][1]))
  802. try:
  803. top_left_dx = float('%.*f' % (self.decimals, self.top_left_coordx_found.get_value()))
  804. except TypeError:
  805. top_left_dx = top_left_x
  806. try:
  807. top_left_dy = float('%.*f' % (self.decimals, self.top_left_coordy_found.get_value()))
  808. except TypeError:
  809. top_left_dy = top_left_y
  810. # top_right_x = float('%.*f' % (self.decimals, self.click_points[3][0]))
  811. # top_right_y = float('%.*f' % (self.decimals, self.click_points[3][1]))
  812. # try:
  813. # top_right_dx = float('%.*f' % (self.decimals, self.top_right_coordx_found.get_value()))
  814. # except TypeError:
  815. # top_right_dx = top_right_x
  816. #
  817. # try:
  818. # top_right_dy = float('%.*f' % (self.decimals, self.top_right_coordy_found.get_value()))
  819. # except TypeError:
  820. # top_right_dy = top_right_y
  821. bot_right_x = float('%.*f' % (self.decimals, self.click_points[1][0]))
  822. bot_right_y = float('%.*f' % (self.decimals, self.click_points[1][1]))
  823. try:
  824. bot_right_dx = float('%.*f' % (self.decimals, self.bottom_right_coordx_found.get_value()))
  825. except TypeError:
  826. bot_right_dx = bot_right_x
  827. try:
  828. bot_right_dy = float('%.*f' % (self.decimals, self.bottom_right_coordy_found.get_value()))
  829. except TypeError:
  830. bot_right_dy = bot_right_y
  831. # ------------------------------------------------------------------------------- #
  832. # --------------------------- FACTORS CALCULUS ---------------------------------- #
  833. # ------------------------------------------------------------------------------- #
  834. if top_left_dy != float('%.*f' % (self.decimals, 0.0)):
  835. # we have scale on Y
  836. scale_y = (top_left_dy + top_left_y - origin_y) / (top_left_y - origin_y)
  837. self.scaley_entry.set_value(scale_y)
  838. if top_left_dx != float('%.*f' % (self.decimals, 0.0)):
  839. # we have skew on X
  840. dx = top_left_dx
  841. dy = top_left_y - origin_y
  842. skew_angle_x = math.degrees(math.atan(dx / dy))
  843. self.skewx_entry.set_value(skew_angle_x)
  844. if bot_right_dx != float('%.*f' % (self.decimals, 0.0)):
  845. # we have scale on X
  846. scale_x = (bot_right_dx + bot_right_x - origin_x) / (bot_right_x - origin_x)
  847. self.scalex_entry.set_value(scale_x)
  848. if bot_right_dy != float('%.*f' % (self.decimals, 0.0)):
  849. # we have skew on Y
  850. dx = bot_right_x - origin_x
  851. dy = bot_right_dy + origin_y
  852. skew_angle_y = math.degrees(math.atan(dy / dx))
  853. self.skewy_entry.set_value(skew_angle_y)
  854. def disconnect_cal_events(self):
  855. # restore the Grid snapping if it was active before
  856. if self.grid_status_memory is True:
  857. self.app.ui.grid_snap_btn.trigger()
  858. self.app.mr = self.canvas.graph_event_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
  859. if self.app.is_legacy is False:
  860. self.canvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
  861. else:
  862. self.canvas.graph_event_disconnect(self.mr)
  863. self.local_connected = False
  864. def reset_fields(self):
  865. self.object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  866. self.adj_exc_object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  867. self.adj_geo_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
  868. # end of file