ToolCalculators.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. ## V-shape Tool Calculator ##
  19. ############################
  20. self.v_shape_spacer_label = QtWidgets.QLabel(" ")
  21. self.layout.addWidget(self.v_shape_spacer_label)
  22. ## Title of the V-shape Tools Calculator
  23. v_shape_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.v_shapeName)
  24. self.layout.addWidget(v_shape_title_label)
  25. ## Form Layout
  26. form_layout = QtWidgets.QFormLayout()
  27. self.layout.addLayout(form_layout)
  28. self.tipDia_label = QtWidgets.QLabel("Tip Diameter:")
  29. self.tipDia_entry = FCEntry()
  30. # self.tipDia_entry.setFixedWidth(70)
  31. self.tipDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  32. self.tipDia_label.setToolTip('This is the diameter of the tool tip.\n'
  33. 'The manufacturer specifies it.')
  34. self.tipAngle_label = QtWidgets.QLabel("Tip Angle:")
  35. self.tipAngle_entry = FCEntry()
  36. # self.tipAngle_entry.setFixedWidth(70)
  37. self.tipAngle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  38. self.tipAngle_label.setToolTip("This is the angle of the tip of the tool.\n"
  39. "It is specified by manufacturer.")
  40. self.cutDepth_label = QtWidgets.QLabel("Cut Z:")
  41. self.cutDepth_entry = FCEntry()
  42. # self.cutDepth_entry.setFixedWidth(70)
  43. self.cutDepth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  44. self.cutDepth_label.setToolTip("This is the depth to cut into the material.\n"
  45. "In the CNCJob is the CutZ parameter.")
  46. self.effectiveToolDia_label = QtWidgets.QLabel("Tool Diameter:")
  47. self.effectiveToolDia_entry = FCEntry()
  48. # self.effectiveToolDia_entry.setFixedWidth(70)
  49. self.effectiveToolDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  50. self.effectiveToolDia_label.setToolTip("This is the tool diameter to be entered into\n"
  51. "FlatCAM Gerber section.\n"
  52. "In the CNCJob section it is called >Tool dia<.")
  53. # self.effectiveToolDia_entry.setEnabled(False)
  54. form_layout.addRow(self.tipDia_label, self.tipDia_entry)
  55. form_layout.addRow(self.tipAngle_label, self.tipAngle_entry)
  56. form_layout.addRow(self.cutDepth_label, self.cutDepth_entry)
  57. form_layout.addRow(self.effectiveToolDia_label, self.effectiveToolDia_entry)
  58. ## Buttons
  59. self.calculate_vshape_button = QtWidgets.QPushButton("Calculate")
  60. # self.calculate_button.setFixedWidth(70)
  61. self.calculate_vshape_button.setToolTip(
  62. "Calculate either the Cut Z or the effective tool diameter,\n "
  63. "depending on which is desired and which is known. "
  64. )
  65. self.empty_label = QtWidgets.QLabel(" ")
  66. form_layout.addRow(self.empty_label, self.calculate_vshape_button)
  67. ######################
  68. ## Units Calculator ##
  69. ######################
  70. self.unists_spacer_label = QtWidgets.QLabel(" ")
  71. self.layout.addWidget(self.unists_spacer_label)
  72. ## Title of the Units Calculator
  73. units_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.unitsName)
  74. self.layout.addWidget(units_label)
  75. #Grid Layout
  76. grid_units_layout = QtWidgets.QGridLayout()
  77. self.layout.addLayout(grid_units_layout)
  78. inch_label = QtWidgets.QLabel("INCH")
  79. mm_label = QtWidgets.QLabel("MM")
  80. grid_units_layout.addWidget(mm_label, 0, 0)
  81. grid_units_layout.addWidget( inch_label, 0, 1)
  82. self.inch_entry = FCEntry()
  83. # self.inch_entry.setFixedWidth(70)
  84. self.inch_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  85. self.inch_entry.setToolTip("Here you enter the value to be converted from INCH to MM")
  86. self.mm_entry = FCEntry()
  87. # self.mm_entry.setFixedWidth(130)
  88. self.mm_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  89. self.mm_entry.setToolTip("Here you enter the value to be converted from MM to INCH")
  90. grid_units_layout.addWidget(self.mm_entry, 1, 0)
  91. grid_units_layout.addWidget(self.inch_entry, 1, 1)
  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. self.app.ui.notebook.setTabText(2, "Calc. Tool")
  174. def install(self, icon=None, separator=None, **kwargs):
  175. FlatCAMTool.install(self, icon, separator, shortcut='ALT+C', **kwargs)
  176. def set_tool_ui(self):
  177. ## Initialize form
  178. self.mm_entry.set_value('0')
  179. self.inch_entry.set_value('0')
  180. self.pcblength_entry.set_value('10')
  181. self.pcbwidth_entry.set_value('10')
  182. self.cdensity_entry.set_value('13')
  183. self.growth_entry.set_value('10')
  184. self.cvalue_entry.set_value(2.80)
  185. self.time_entry.set_value(33.0)
  186. if self.app.defaults["units"] == 'MM':
  187. self.tipDia_entry.set_value('0.2')
  188. self.tipAngle_entry.set_value('45')
  189. self.cutDepth_entry.set_value('0.25')
  190. self.effectiveToolDia_entry.set_value('0.39')
  191. else:
  192. self.tipDia_entry.set_value('7.87402')
  193. self.tipAngle_entry.set_value('45')
  194. self.cutDepth_entry.set_value('9.84252')
  195. self.effectiveToolDia_entry.set_value('15.35433')
  196. def on_calculate_tool_dia(self):
  197. # Calculation:
  198. # Manufacturer gives total angle of the the tip but we need only half of it
  199. # tangent(half_tip_angle) = opposite side / adjacent = part_of _real_dia / depth_of_cut
  200. # effective_diameter = tip_diameter + part_of_real_dia_left_side + part_of_real_dia_right_side
  201. # tool is symmetrical therefore: part_of_real_dia_left_side = part_of_real_dia_right_side
  202. # effective_diameter = tip_diameter + (2 * part_of_real_dia_left_side)
  203. # effective diameter = tip_diameter + (2 * depth_of_cut * tangent(half_tip_angle))
  204. try:
  205. tip_diameter = float(self.tipDia_entry.get_value())
  206. except ValueError:
  207. # try to convert comma to decimal point. if it's still not working error message and return
  208. try:
  209. tip_diameter = float(self.tipDia_entry.get_value().replace(',', '.'))
  210. except ValueError:
  211. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  212. "use a number.")
  213. return
  214. try:
  215. half_tip_angle = float(self.tipAngle_entry.get_value())
  216. except ValueError:
  217. # try to convert comma to decimal point. if it's still not working error message and return
  218. try:
  219. half_tip_angle = float(self.tipAngle_entry.get_value().replace(',', '.'))
  220. except ValueError:
  221. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  222. "use a number.")
  223. return
  224. half_tip_angle /= 2
  225. try:
  226. cut_depth = float(self.cutDepth_entry.get_value())
  227. except ValueError:
  228. # try to convert comma to decimal point. if it's still not working error message and return
  229. try:
  230. cut_depth = float(self.cutDepth_entry.get_value().replace(',', '.'))
  231. except ValueError:
  232. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  233. "use a number.")
  234. return
  235. tool_diameter = tip_diameter + (2 * cut_depth * math.tan(math.radians(half_tip_angle)))
  236. self.effectiveToolDia_entry.set_value("%.4f" % tool_diameter)
  237. def on_calculate_inch_units(self):
  238. self.inch_entry.set_value('%.6f' % (float(self.mm_entry.get_value()) / 25.4))
  239. def on_calculate_mm_units(self):
  240. self.mm_entry.set_value('%.6f' % (float(self.inch_entry.get_value()) * 25.4))
  241. def on_calculate_eplate(self):
  242. try:
  243. length = float(self.pcblength_entry.get_value())
  244. except ValueError:
  245. # try to convert comma to decimal point. if it's still not working error message and return
  246. try:
  247. length = float(self.pcblength_entry.get_value().replace(',', '.'))
  248. except ValueError:
  249. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  250. "use a number.")
  251. return
  252. try:
  253. width = float(self.pcbwidth_entry.get_value())
  254. except ValueError:
  255. # try to convert comma to decimal point. if it's still not working error message and return
  256. try:
  257. width = float(self.pcbwidth_entry.get_value().replace(',', '.'))
  258. except ValueError:
  259. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  260. "use a number.")
  261. return
  262. try:
  263. density = float(self.cdensity_entry.get_value())
  264. except ValueError:
  265. # try to convert comma to decimal point. if it's still not working error message and return
  266. try:
  267. density = float(self.cdensity_entry.get_value().replace(',', '.'))
  268. except ValueError:
  269. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  270. "use a number.")
  271. return
  272. try:
  273. copper = float(self.growth_entry.get_value())
  274. except ValueError:
  275. # try to convert comma to decimal point. if it's still not working error message and return
  276. try:
  277. copper = float(self.growth_entry.get_value().replace(',', '.'))
  278. except ValueError:
  279. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
  280. "use a number.")
  281. return
  282. calculated_current = (length * width * density) * 0.0021527820833419
  283. calculated_time = copper * 2.142857142857143 * float(20 / density)
  284. self.cvalue_entry.set_value('%.2f' % calculated_current)
  285. self.time_entry.set_value('%.1f' % calculated_time)
  286. # end of file