ToolCalculators.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. from PyQt5 import QtGui
  2. from GUIElements import FCEntry
  3. from FlatCAMTool import FlatCAMTool
  4. from FlatCAMObj import *
  5. import math
  6. class ToolCalculator(FlatCAMTool):
  7. toolName = "Calculators"
  8. v_shapeName = "V-Shape Tool Calculator"
  9. unitsName = "Units Calculator"
  10. eplateName = "ElectroPlating Calculator"
  11. def __init__(self, app):
  12. FlatCAMTool.__init__(self, app)
  13. self.app = app
  14. ## Title
  15. title_label = QtWidgets.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
  16. self.layout.addWidget(title_label)
  17. ######################
  18. ## Units Calculator ##
  19. ######################
  20. self.unists_spacer_label = QtWidgets.QLabel(" ")
  21. self.layout.addWidget(self.unists_spacer_label)
  22. ## Title of the Units Calculator
  23. units_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.unitsName)
  24. self.layout.addWidget(units_label)
  25. #Grid Layout
  26. grid_units_layout = QtWidgets.QGridLayout()
  27. self.layout.addLayout(grid_units_layout)
  28. inch_label = QtWidgets.QLabel("INCH")
  29. mm_label = QtWidgets.QLabel("MM")
  30. grid_units_layout.addWidget(mm_label, 0, 0)
  31. grid_units_layout.addWidget( inch_label, 0, 1)
  32. self.inch_entry = FCEntry()
  33. # self.inch_entry.setFixedWidth(70)
  34. self.inch_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  35. self.inch_entry.setToolTip("Here you enter the value to be converted from INCH to MM")
  36. self.mm_entry = FCEntry()
  37. # self.mm_entry.setFixedWidth(130)
  38. self.mm_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  39. self.mm_entry.setToolTip("Here you enter the value to be converted from MM to INCH")
  40. grid_units_layout.addWidget(self.mm_entry, 1, 0)
  41. grid_units_layout.addWidget(self.inch_entry, 1, 1)
  42. ############################
  43. ## V-shape Tool Calculator ##
  44. ############################
  45. self.v_shape_spacer_label = QtWidgets.QLabel(" ")
  46. self.layout.addWidget(self.v_shape_spacer_label)
  47. ## Title of the V-shape Tools Calculator
  48. v_shape_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.v_shapeName)
  49. self.layout.addWidget(v_shape_title_label)
  50. ## Form Layout
  51. form_layout = QtWidgets.QFormLayout()
  52. self.layout.addLayout(form_layout)
  53. self.tipDia_label = QtWidgets.QLabel("Tip Diameter:")
  54. self.tipDia_entry = FCEntry()
  55. # self.tipDia_entry.setFixedWidth(70)
  56. self.tipDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  57. self.tipDia_label.setToolTip('This is the diameter of the tool tip.\n'
  58. 'The manufacturer specifies it.')
  59. self.tipAngle_label = QtWidgets.QLabel("Tip Angle:")
  60. self.tipAngle_entry = FCEntry()
  61. # self.tipAngle_entry.setFixedWidth(70)
  62. self.tipAngle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  63. self.tipAngle_label.setToolTip("This is the angle of the tip of the tool.\n"
  64. "It is specified by manufacturer.")
  65. self.cutDepth_label = QtWidgets.QLabel("Cut Z:")
  66. self.cutDepth_entry = FCEntry()
  67. # self.cutDepth_entry.setFixedWidth(70)
  68. self.cutDepth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  69. self.cutDepth_label.setToolTip("This is the depth to cut into the material.\n"
  70. "In the CNCJob is the CutZ parameter.")
  71. self.effectiveToolDia_label = QtWidgets.QLabel("Tool Diameter:")
  72. self.effectiveToolDia_entry = FCEntry()
  73. # self.effectiveToolDia_entry.setFixedWidth(70)
  74. self.effectiveToolDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  75. self.effectiveToolDia_label.setToolTip("This is the tool diameter to be entered into\n"
  76. "FlatCAM Gerber section.\n"
  77. "In the CNCJob section it is called >Tool dia<.")
  78. # self.effectiveToolDia_entry.setEnabled(False)
  79. form_layout.addRow(self.tipDia_label, self.tipDia_entry)
  80. form_layout.addRow(self.tipAngle_label, self.tipAngle_entry)
  81. form_layout.addRow(self.cutDepth_label, self.cutDepth_entry)
  82. form_layout.addRow(self.effectiveToolDia_label, self.effectiveToolDia_entry)
  83. ## Buttons
  84. self.calculate_vshape_button = QtWidgets.QPushButton("Calculate")
  85. # self.calculate_button.setFixedWidth(70)
  86. self.calculate_vshape_button.setToolTip(
  87. "Calculate either the Cut Z or the effective tool diameter,\n "
  88. "depending on which is desired and which is known. "
  89. )
  90. self.empty_label = QtWidgets.QLabel(" ")
  91. form_layout.addRow(self.empty_label, self.calculate_vshape_button)
  92. ####################################
  93. ## ElectroPlating Tool Calculator ##
  94. ####################################
  95. self.plate_spacer_label = QtWidgets.QLabel(" ")
  96. self.layout.addWidget(self.plate_spacer_label)
  97. ## Title of the ElectroPlating Tools Calculator
  98. plate_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.eplateName)
  99. plate_title_label.setToolTip(
  100. "This calculator is useful for those who plate the via/pad/drill holes,\n"
  101. "using a method like grahite ink or calcium hypophosphite ink or palladium chloride."
  102. )
  103. self.layout.addWidget(plate_title_label)
  104. ## Plate Form Layout
  105. plate_form_layout = QtWidgets.QFormLayout()
  106. self.layout.addLayout(plate_form_layout)
  107. self.pcblengthlabel = QtWidgets.QLabel("Board Length:")
  108. self.pcblength_entry = FCEntry()
  109. # self.pcblengthlabel.setFixedWidth(70)
  110. self.pcblength_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  111. self.pcblengthlabel.setToolTip('This is the board length. In centimeters.')
  112. self.pcbwidthlabel = QtWidgets.QLabel("Board Width:")
  113. self.pcbwidth_entry = FCEntry()
  114. # self.pcbwidthlabel.setFixedWidth(70)
  115. self.pcbwidth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  116. self.pcbwidthlabel.setToolTip('This is the board width.In centimeters.')
  117. self.cdensity_label = QtWidgets.QLabel("Current Density:")
  118. self.cdensity_entry = FCEntry()
  119. # self.cdensity_entry.setFixedWidth(70)
  120. self.cdensity_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  121. self.cdensity_label.setToolTip("Current density to pass through the board. \n"
  122. "In Amps per Square Feet ASF.")
  123. self.growth_label = QtWidgets.QLabel("Copper Growth:")
  124. self.growth_entry = FCEntry()
  125. # self.growth_entry.setFixedWidth(70)
  126. self.growth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  127. self.growth_label.setToolTip("How thick the copper growth is intended to be.\n"
  128. "In microns.")
  129. # self.growth_entry.setEnabled(False)
  130. self.cvaluelabel = QtWidgets.QLabel("Current Value:")
  131. self.cvalue_entry = FCEntry()
  132. # self.cvaluelabel.setFixedWidth(70)
  133. self.cvalue_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  134. self.cvaluelabel.setToolTip('This is the current intensity value\n'
  135. 'to be set on the Power Supply. In Amps.')
  136. self.cvalue_entry.setDisabled(True)
  137. self.timelabel = QtWidgets.QLabel("Time:")
  138. self.time_entry = FCEntry()
  139. # self.timelabel.setFixedWidth(70)
  140. self.time_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  141. self.timelabel.setToolTip('This is the calculated time required for the procedure.\n'
  142. 'In minutes.')
  143. self.time_entry.setDisabled(True)
  144. plate_form_layout.addRow(self.pcblengthlabel, self.pcblength_entry)
  145. plate_form_layout.addRow(self.pcbwidthlabel, self.pcbwidth_entry)
  146. plate_form_layout.addRow(self.cdensity_label, self.cdensity_entry)
  147. plate_form_layout.addRow(self.growth_label, self.growth_entry)
  148. plate_form_layout.addRow(self.cvaluelabel, self.cvalue_entry)
  149. plate_form_layout.addRow(self.timelabel, self.time_entry)
  150. ## Buttons
  151. self.calculate_plate_button = QtWidgets.QPushButton("Calculate")
  152. # self.calculate_button.setFixedWidth(70)
  153. self.calculate_plate_button.setToolTip(
  154. "Calculate the current intensity value and the procedure time,\n "
  155. "depending on the parameters above"
  156. )
  157. self.empty_label_2 = QtWidgets.QLabel(" ")
  158. plate_form_layout.addRow(self.empty_label_2, self.calculate_plate_button)
  159. self.layout.addStretch()
  160. ## Signals
  161. self.cutDepth_entry.textChanged.connect(self.on_calculate_tool_dia)
  162. self.cutDepth_entry.editingFinished.connect(self.on_calculate_tool_dia)
  163. self.tipDia_entry.editingFinished.connect(self.on_calculate_tool_dia)
  164. self.tipAngle_entry.editingFinished.connect(self.on_calculate_tool_dia)
  165. self.calculate_vshape_button.clicked.connect(self.on_calculate_tool_dia)
  166. self.mm_entry.editingFinished.connect(self.on_calculate_inch_units)
  167. self.inch_entry.editingFinished.connect(self.on_calculate_mm_units)
  168. self.calculate_plate_button.clicked.connect(self.on_calculate_eplate)
  169. def run(self):
  170. self.app.report_usage("ToolCalculators()")
  171. FlatCAMTool.run(self)
  172. self.set_tool_ui()
  173. self.app.ui.notebook.setTabText(2, "Calc. Tool")
  174. def install(self, icon=None, separator=None, **kwargs):
  175. FlatCAMTool.install(self, icon, separator, shortcut='ALT+C', **kwargs)
  176. def set_tool_ui(self):
  177. self.units = self.app.general_options_form.general_app_group.units_radio.get_value().upper()
  178. ## Initialize form
  179. self.mm_entry.set_value('0')
  180. self.inch_entry.set_value('0')
  181. length = self.app.defaults["tools_calc_electro_length"]
  182. width = self.app.defaults["tools_calc_electro_width"]
  183. density = self.app.defaults["tools_calc_electro_cdensity"]
  184. growth = self.app.defaults["tools_calc_electro_growth"]
  185. self.pcblength_entry.set_value(length)
  186. self.pcbwidth_entry.set_value(width)
  187. self.cdensity_entry.set_value(density)
  188. self.growth_entry.set_value(growth)
  189. self.cvalue_entry.set_value(0.00)
  190. self.time_entry.set_value(0.0)
  191. tip_dia = self.app.defaults["tools_calc_vshape_tip_dia"]
  192. tip_angle = self.app.defaults["tools_calc_vshape_tip_angle"]
  193. cut_z = self.app.defaults["tools_calc_vshape_cut_z"]
  194. self.tipDia_entry.set_value(tip_dia)
  195. self.tipAngle_entry.set_value(tip_angle)
  196. self.cutDepth_entry.set_value(cut_z)
  197. self.effectiveToolDia_entry.set_value('0.0000')
  198. def on_calculate_tool_dia(self):
  199. # Calculation:
  200. # Manufacturer gives total angle of the the tip but we need only half of it
  201. # tangent(half_tip_angle) = opposite side / adjacent = part_of _real_dia / depth_of_cut
  202. # effective_diameter = tip_diameter + part_of_real_dia_left_side + part_of_real_dia_right_side
  203. # tool is symmetrical therefore: part_of_real_dia_left_side = part_of_real_dia_right_side
  204. # effective_diameter = tip_diameter + (2 * part_of_real_dia_left_side)
  205. # effective diameter = tip_diameter + (2 * depth_of_cut * tangent(half_tip_angle))
  206. try:
  207. tip_diameter = float(self.tipDia_entry.get_value())
  208. except ValueError:
  209. # try to convert comma to decimal point. if it's still not working error message and return
  210. try:
  211. tip_diameter = float(self.tipDia_entry.get_value().replace(',', '.'))
  212. except ValueError:
  213. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  214. "use a number.")
  215. return
  216. try:
  217. half_tip_angle = float(self.tipAngle_entry.get_value())
  218. except ValueError:
  219. # try to convert comma to decimal point. if it's still not working error message and return
  220. try:
  221. half_tip_angle = float(self.tipAngle_entry.get_value().replace(',', '.'))
  222. except ValueError:
  223. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  224. "use a number.")
  225. return
  226. half_tip_angle /= 2
  227. try:
  228. cut_depth = float(self.cutDepth_entry.get_value())
  229. except ValueError:
  230. # try to convert comma to decimal point. if it's still not working error message and return
  231. try:
  232. cut_depth = float(self.cutDepth_entry.get_value().replace(',', '.'))
  233. except ValueError:
  234. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  235. "use a number.")
  236. return
  237. tool_diameter = tip_diameter + (2 * cut_depth * math.tan(math.radians(half_tip_angle)))
  238. self.effectiveToolDia_entry.set_value("%.4f" % tool_diameter)
  239. def on_calculate_inch_units(self):
  240. try:
  241. mm_val = float(self.mm_entry.get_value())
  242. except ValueError:
  243. # try to convert comma to decimal point. if it's still not working error message and return
  244. try:
  245. mm_val = float(self.mm_entry.get_value().replace(',', '.'))
  246. except ValueError:
  247. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  248. "use a number.")
  249. return
  250. self.inch_entry.set_value('%.6f' % (mm_val / 25.4))
  251. def on_calculate_mm_units(self):
  252. try:
  253. inch_val = float(self.inch_entry.get_value())
  254. except ValueError:
  255. # try to convert comma to decimal point. if it's still not working error message and return
  256. try:
  257. inch_val = float(self.inch_entry.get_value().replace(',', '.'))
  258. except ValueError:
  259. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  260. "use a number.")
  261. return
  262. self.mm_entry.set_value('%.6f' % (inch_val * 25.4))
  263. def on_calculate_eplate(self):
  264. try:
  265. length = float(self.pcblength_entry.get_value())
  266. except ValueError:
  267. # try to convert comma to decimal point. if it's still not working error message and return
  268. try:
  269. length = float(self.pcblength_entry.get_value().replace(',', '.'))
  270. except ValueError:
  271. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  272. "use a number.")
  273. return
  274. try:
  275. width = float(self.pcbwidth_entry.get_value())
  276. except ValueError:
  277. # try to convert comma to decimal point. if it's still not working error message and return
  278. try:
  279. width = float(self.pcbwidth_entry.get_value().replace(',', '.'))
  280. except ValueError:
  281. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  282. "use a number.")
  283. return
  284. try:
  285. density = float(self.cdensity_entry.get_value())
  286. except ValueError:
  287. # try to convert comma to decimal point. if it's still not working error message and return
  288. try:
  289. density = float(self.cdensity_entry.get_value().replace(',', '.'))
  290. except ValueError:
  291. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  292. "use a number.")
  293. return
  294. try:
  295. copper = float(self.growth_entry.get_value())
  296. except ValueError:
  297. # try to convert comma to decimal point. if it's still not working error message and return
  298. try:
  299. copper = float(self.growth_entry.get_value().replace(',', '.'))
  300. except ValueError:
  301. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  302. "use a number.")
  303. return
  304. calculated_current = (length * width * density) * 0.0021527820833419
  305. calculated_time = copper * 2.142857142857143 * float(20 / density)
  306. self.cvalue_entry.set_value('%.2f' % calculated_current)
  307. self.time_entry.set_value('%.1f' % calculated_time)
  308. # end of file