ToolCalculators.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. def __init__(self, app):
  11. FlatCAMTool.__init__(self, app)
  12. self.app = app
  13. ## Title
  14. title_label = QtWidgets.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
  15. self.layout.addWidget(title_label)
  16. ## V-shape Tool Calculator
  17. self.v_shape_spacer_label = QtWidgets.QLabel(" ")
  18. self.layout.addWidget(self.v_shape_spacer_label)
  19. ## Title of the V-shape Tools Calculator
  20. v_shape_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.v_shapeName)
  21. self.layout.addWidget(v_shape_title_label)
  22. ## Form Layout
  23. form_layout = QtWidgets.QFormLayout()
  24. self.layout.addLayout(form_layout)
  25. self.tipDia_label = QtWidgets.QLabel("Tip Diameter:")
  26. self.tipDia_entry = FCEntry()
  27. self.tipDia_entry.setFixedWidth(70)
  28. self.tipDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  29. self.tipDia_entry.setToolTip('This is the diameter of the tool tip.\n'
  30. 'The manufacturer specifies it.')
  31. self.tipAngle_label = QtWidgets.QLabel("Tip Angle:")
  32. self.tipAngle_entry = FCEntry()
  33. self.tipAngle_entry.setFixedWidth(70)
  34. self.tipAngle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  35. self.tipAngle_entry.setToolTip("This is the angle of the tip of the tool.\n"
  36. "It is specified by manufacturer.")
  37. self.cutDepth_label = QtWidgets.QLabel("Cut Z:")
  38. self.cutDepth_entry = FCEntry()
  39. self.cutDepth_entry.setFixedWidth(70)
  40. self.cutDepth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  41. self.cutDepth_entry.setToolTip("This is the depth to cut into the material.\n"
  42. "In the CNCJob is the CutZ parameter.")
  43. self.effectiveToolDia_label = QtWidgets.QLabel("Tool Diameter:")
  44. self.effectiveToolDia_entry = FCEntry()
  45. self.effectiveToolDia_entry.setFixedWidth(70)
  46. self.effectiveToolDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  47. self.effectiveToolDia_entry.setToolTip("This is the tool diameter to be entered into\n"
  48. "FlatCAM Gerber section.\n"
  49. "In the CNCJob section it is called >Tool dia<.")
  50. # self.effectiveToolDia_entry.setEnabled(False)
  51. form_layout.addRow(self.tipDia_label, self.tipDia_entry)
  52. form_layout.addRow(self.tipAngle_label, self.tipAngle_entry)
  53. form_layout.addRow(self.cutDepth_label, self.cutDepth_entry)
  54. form_layout.addRow(self.effectiveToolDia_label, self.effectiveToolDia_entry)
  55. ## Buttons
  56. self.calculate_button = QtWidgets.QPushButton("Calculate")
  57. self.calculate_button.setFixedWidth(70)
  58. self.calculate_button.setToolTip(
  59. "Calculate either the Cut Z or the effective tool diameter,\n "
  60. "depending on which is desired and which is known. "
  61. )
  62. self.empty_label = QtWidgets.QLabel(" ")
  63. form_layout.addRow(self.empty_label, self.calculate_button)
  64. ## Units Calculator
  65. self.unists_spacer_label = QtWidgets.QLabel(" ")
  66. self.layout.addWidget(self.unists_spacer_label)
  67. ## Title of the Units Calculator
  68. units_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.unitsName)
  69. self.layout.addWidget(units_label)
  70. #Form Layout
  71. form_units_layout = QtWidgets.QFormLayout()
  72. self.layout.addLayout(form_units_layout)
  73. inch_label = QtWidgets.QLabel("INCH")
  74. mm_label = QtWidgets.QLabel("MM")
  75. self.inch_entry = FCEntry()
  76. self.inch_entry.setFixedWidth(70)
  77. self.inch_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  78. self.inch_entry.setToolTip("Here you enter the value to be converted from INCH to MM")
  79. self.mm_entry = FCEntry()
  80. self.mm_entry.setFixedWidth(70)
  81. self.mm_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  82. self.mm_entry.setToolTip("Here you enter the value to be converted from MM to INCH")
  83. form_units_layout.addRow(mm_label, inch_label)
  84. form_units_layout.addRow(self.mm_entry, self.inch_entry)
  85. self.layout.addStretch()
  86. ## Signals
  87. self.cutDepth_entry.textChanged.connect(self.on_calculate_tool_dia)
  88. self.cutDepth_entry.editingFinished.connect(self.on_calculate_tool_dia)
  89. self.tipDia_entry.editingFinished.connect(self.on_calculate_tool_dia)
  90. self.tipAngle_entry.editingFinished.connect(self.on_calculate_tool_dia)
  91. self.calculate_button.clicked.connect(self.on_calculate_tool_dia)
  92. self.mm_entry.editingFinished.connect(self.on_calculate_inch_units)
  93. self.inch_entry.editingFinished.connect(self.on_calculate_mm_units)
  94. ## Initialize form
  95. if self.app.defaults["units"] == 'MM':
  96. self.tipDia_entry.set_value('0.2')
  97. self.tipAngle_entry.set_value('45')
  98. self.cutDepth_entry.set_value('0.25')
  99. self.effectiveToolDia_entry.set_value('0.39')
  100. else:
  101. self.tipDia_entry.set_value('7.87402')
  102. self.tipAngle_entry.set_value('45')
  103. self.cutDepth_entry.set_value('9.84252')
  104. self.effectiveToolDia_entry.set_value('15.35433')
  105. self.mm_entry.set_value('0')
  106. self.inch_entry.set_value('0')
  107. def run(self):
  108. FlatCAMTool.run(self)
  109. self.app.ui.notebook.setTabText(2, "Calc. Tool")
  110. def on_calculate_tool_dia(self):
  111. # Calculation:
  112. # Manufacturer gives total angle of the the tip but we need only half of it
  113. # tangent(half_tip_angle) = opposite side / adjacent = part_of _real_dia / depth_of_cut
  114. # effective_diameter = tip_diameter + part_of_real_dia_left_side + part_of_real_dia_right_side
  115. # tool is symmetrical therefore: part_of_real_dia_left_side = part_of_real_dia_right_side
  116. # effective_diameter = tip_diameter + (2 * part_of_real_dia_left_side)
  117. # effective diameter = tip_diameter + (2 * depth_of_cut * tangent(half_tip_angle))
  118. try:
  119. tip_diameter = float(self.tipDia_entry.get_value())
  120. half_tip_angle = float(self.tipAngle_entry.get_value()) / 2
  121. cut_depth = float(self.cutDepth_entry.get_value())
  122. except TypeError:
  123. return
  124. tool_diameter = tip_diameter + (2 * cut_depth * math.tan(math.radians(half_tip_angle)))
  125. self.effectiveToolDia_entry.set_value("%.4f" % tool_diameter)
  126. def on_calculate_inch_units(self):
  127. self.inch_entry.set_value('%.6f' % (float(self.mm_entry.get_value()) / 25.4))
  128. def on_calculate_mm_units(self):
  129. self.mm_entry.set_value('%.6f' % (float(self.inch_entry.get_value()) * 25.4))
  130. # end of file