ToolCalculators.py 18 KB

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