ToolCalculators.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. # if the splitter us hidden, display it
  174. if self.app.ui.splitter.sizes()[0] == 0:
  175. self.app.ui.splitter.setSizes([1, 1])
  176. self.app.ui.notebook.setTabText(2, "Calc. Tool")
  177. def install(self, icon=None, separator=None, **kwargs):
  178. FlatCAMTool.install(self, icon, separator, shortcut='ALT+C', **kwargs)
  179. def set_tool_ui(self):
  180. self.units = self.app.general_options_form.general_app_group.units_radio.get_value().upper()
  181. ## Initialize form
  182. self.mm_entry.set_value('0')
  183. self.inch_entry.set_value('0')
  184. length = self.app.defaults["tools_calc_electro_length"]
  185. width = self.app.defaults["tools_calc_electro_width"]
  186. density = self.app.defaults["tools_calc_electro_cdensity"]
  187. growth = self.app.defaults["tools_calc_electro_growth"]
  188. self.pcblength_entry.set_value(length)
  189. self.pcbwidth_entry.set_value(width)
  190. self.cdensity_entry.set_value(density)
  191. self.growth_entry.set_value(growth)
  192. self.cvalue_entry.set_value(0.00)
  193. self.time_entry.set_value(0.0)
  194. tip_dia = self.app.defaults["tools_calc_vshape_tip_dia"]
  195. tip_angle = self.app.defaults["tools_calc_vshape_tip_angle"]
  196. cut_z = self.app.defaults["tools_calc_vshape_cut_z"]
  197. self.tipDia_entry.set_value(tip_dia)
  198. self.tipAngle_entry.set_value(tip_angle)
  199. self.cutDepth_entry.set_value(cut_z)
  200. self.effectiveToolDia_entry.set_value('0.0000')
  201. def on_calculate_tool_dia(self):
  202. # Calculation:
  203. # Manufacturer gives total angle of the the tip but we need only half of it
  204. # tangent(half_tip_angle) = opposite side / adjacent = part_of _real_dia / depth_of_cut
  205. # effective_diameter = tip_diameter + part_of_real_dia_left_side + part_of_real_dia_right_side
  206. # tool is symmetrical therefore: part_of_real_dia_left_side = part_of_real_dia_right_side
  207. # effective_diameter = tip_diameter + (2 * part_of_real_dia_left_side)
  208. # effective diameter = tip_diameter + (2 * depth_of_cut * tangent(half_tip_angle))
  209. try:
  210. tip_diameter = float(self.tipDia_entry.get_value())
  211. except ValueError:
  212. # try to convert comma to decimal point. if it's still not working error message and return
  213. try:
  214. tip_diameter = float(self.tipDia_entry.get_value().replace(',', '.'))
  215. except ValueError:
  216. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  217. "use a number.")
  218. return
  219. try:
  220. half_tip_angle = float(self.tipAngle_entry.get_value())
  221. except ValueError:
  222. # try to convert comma to decimal point. if it's still not working error message and return
  223. try:
  224. half_tip_angle = float(self.tipAngle_entry.get_value().replace(',', '.'))
  225. except ValueError:
  226. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  227. "use a number.")
  228. return
  229. half_tip_angle /= 2
  230. try:
  231. cut_depth = float(self.cutDepth_entry.get_value())
  232. except ValueError:
  233. # try to convert comma to decimal point. if it's still not working error message and return
  234. try:
  235. cut_depth = float(self.cutDepth_entry.get_value().replace(',', '.'))
  236. except ValueError:
  237. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  238. "use a number.")
  239. return
  240. tool_diameter = tip_diameter + (2 * cut_depth * math.tan(math.radians(half_tip_angle)))
  241. self.effectiveToolDia_entry.set_value("%.4f" % tool_diameter)
  242. def on_calculate_inch_units(self):
  243. try:
  244. mm_val = float(self.mm_entry.get_value())
  245. except ValueError:
  246. # try to convert comma to decimal point. if it's still not working error message and return
  247. try:
  248. mm_val = float(self.mm_entry.get_value().replace(',', '.'))
  249. except ValueError:
  250. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  251. "use a number.")
  252. return
  253. self.inch_entry.set_value('%.6f' % (mm_val / 25.4))
  254. def on_calculate_mm_units(self):
  255. try:
  256. inch_val = float(self.inch_entry.get_value())
  257. except ValueError:
  258. # try to convert comma to decimal point. if it's still not working error message and return
  259. try:
  260. inch_val = float(self.inch_entry.get_value().replace(',', '.'))
  261. except ValueError:
  262. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  263. "use a number.")
  264. return
  265. self.mm_entry.set_value('%.6f' % (inch_val * 25.4))
  266. def on_calculate_eplate(self):
  267. try:
  268. length = float(self.pcblength_entry.get_value())
  269. except ValueError:
  270. # try to convert comma to decimal point. if it's still not working error message and return
  271. try:
  272. length = float(self.pcblength_entry.get_value().replace(',', '.'))
  273. except ValueError:
  274. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  275. "use a number.")
  276. return
  277. try:
  278. width = float(self.pcbwidth_entry.get_value())
  279. except ValueError:
  280. # try to convert comma to decimal point. if it's still not working error message and return
  281. try:
  282. width = float(self.pcbwidth_entry.get_value().replace(',', '.'))
  283. except ValueError:
  284. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  285. "use a number.")
  286. return
  287. try:
  288. density = float(self.cdensity_entry.get_value())
  289. except ValueError:
  290. # try to convert comma to decimal point. if it's still not working error message and return
  291. try:
  292. density = float(self.cdensity_entry.get_value().replace(',', '.'))
  293. except ValueError:
  294. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  295. "use a number.")
  296. return
  297. try:
  298. copper = float(self.growth_entry.get_value())
  299. except ValueError:
  300. # try to convert comma to decimal point. if it's still not working error message and return
  301. try:
  302. copper = float(self.growth_entry.get_value().replace(',', '.'))
  303. except ValueError:
  304. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  305. "use a number.")
  306. return
  307. calculated_current = (length * width * density) * 0.0021527820833419
  308. calculated_time = copper * 2.142857142857143 * float(20 / density)
  309. self.cvalue_entry.set_value('%.2f' % calculated_current)
  310. self.time_entry.set_value('%.1f' % calculated_time)
  311. # end of file