ToolCalculators.py 17 KB

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