ToolCalculators.py 18 KB

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