ToolCalculators.py 17 KB

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