CNCJobGenPrefGroupUI.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtCore import QSettings
  3. from appGUI.GUIElements import FCCheckBox, RadioSet, FCSpinner, FCDoubleSpinner, FCSliderWithSpinner, FCColorEntry
  4. from appGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. import gettext
  6. import appTranslation as fcTranslate
  7. import builtins
  8. fcTranslate.apply_language('strings')
  9. if '_' not in builtins.__dict__:
  10. _ = gettext.gettext
  11. settings = QSettings("Open Source", "FlatCAM")
  12. if settings.contains("machinist"):
  13. machinist_setting = settings.value('machinist', type=int)
  14. else:
  15. machinist_setting = 0
  16. class CNCJobGenPrefGroupUI(OptionsGroupUI):
  17. def __init__(self, decimals=4, parent=None):
  18. # OptionsGroupUI.__init__(self, "CNC Job General Preferences", parent=None)
  19. super(CNCJobGenPrefGroupUI, self).__init__(self, parent=parent)
  20. self.setTitle(str(_("CNC Job General")))
  21. self.decimals = decimals
  22. # ## Plot options
  23. self.plot_options_label = QtWidgets.QLabel("<b>%s:</b>" % _("Plot Options"))
  24. self.layout.addWidget(self.plot_options_label)
  25. grid0 = QtWidgets.QGridLayout()
  26. self.layout.addLayout(grid0)
  27. grid0.setColumnStretch(0, 0)
  28. grid0.setColumnStretch(1, 1)
  29. # Plot CB
  30. # self.plot_cb = QtWidgets.QCheckBox('Plot')
  31. self.plot_cb = FCCheckBox(_('Plot Object'))
  32. self.plot_cb.setToolTip(_("Plot (show) this object."))
  33. grid0.addWidget(self.plot_cb, 0, 0, 1, 2)
  34. # ###################################################################
  35. # Number of circle steps for circular aperture linear approximation #
  36. # ###################################################################
  37. self.steps_per_circle_label = QtWidgets.QLabel('%s:' % _("Circle Steps"))
  38. self.steps_per_circle_label.setToolTip(
  39. _("The number of circle steps for <b>GCode</b> \n"
  40. "circle and arc shapes linear approximation.")
  41. )
  42. grid0.addWidget(self.steps_per_circle_label, 3, 0)
  43. self.steps_per_circle_entry = FCSpinner()
  44. self.steps_per_circle_entry.set_range(0, 99999)
  45. grid0.addWidget(self.steps_per_circle_entry, 3, 1)
  46. # Tool dia for plot
  47. tdlabel = QtWidgets.QLabel('%s:' % _('Travel dia'))
  48. tdlabel.setToolTip(
  49. _("The width of the travel lines to be\n"
  50. "rendered in the plot.")
  51. )
  52. self.tooldia_entry = FCDoubleSpinner()
  53. self.tooldia_entry.set_range(0, 99999)
  54. self.tooldia_entry.set_precision(self.decimals)
  55. self.tooldia_entry.setSingleStep(0.1)
  56. self.tooldia_entry.setWrapping(True)
  57. grid0.addWidget(tdlabel, 4, 0)
  58. grid0.addWidget(self.tooldia_entry, 4, 1)
  59. # add a space
  60. grid0.addWidget(QtWidgets.QLabel('<b>%s:</b>' % _("G-code Decimals")), 5, 0, 1, 2)
  61. # Number of decimals to use in GCODE coordinates
  62. cdeclabel = QtWidgets.QLabel('%s:' % _('Coordinates'))
  63. cdeclabel.setToolTip(
  64. _("The number of decimals to be used for \n"
  65. "the X, Y, Z coordinates in CNC code (GCODE, etc.)")
  66. )
  67. self.coords_dec_entry = FCSpinner()
  68. self.coords_dec_entry.set_range(0, 9)
  69. self.coords_dec_entry.setWrapping(True)
  70. grid0.addWidget(cdeclabel, 6, 0)
  71. grid0.addWidget(self.coords_dec_entry, 6, 1)
  72. # Number of decimals to use in GCODE feedrate
  73. frdeclabel = QtWidgets.QLabel('%s:' % _('Feedrate'))
  74. frdeclabel.setToolTip(
  75. _("The number of decimals to be used for \n"
  76. "the Feedrate parameter in CNC code (GCODE, etc.)")
  77. )
  78. self.fr_dec_entry = FCSpinner()
  79. self.fr_dec_entry.set_range(0, 9)
  80. self.fr_dec_entry.setWrapping(True)
  81. grid0.addWidget(frdeclabel, 7, 0)
  82. grid0.addWidget(self.fr_dec_entry, 7, 1)
  83. # The type of coordinates used in the Gcode: Absolute or Incremental
  84. coords_type_label = QtWidgets.QLabel('%s:' % _('Coordinates type'))
  85. coords_type_label.setToolTip(
  86. _("The type of coordinates to be used in Gcode.\n"
  87. "Can be:\n"
  88. "- Absolute G90 -> the reference is the origin x=0, y=0\n"
  89. "- Incremental G91 -> the reference is the previous position")
  90. )
  91. self.coords_type_radio = RadioSet([
  92. {"label": _("Absolute G90"), "value": "G90"},
  93. {"label": _("Incremental G91"), "value": "G91"}
  94. ], orientation='vertical', stretch=False)
  95. grid0.addWidget(coords_type_label, 8, 0)
  96. grid0.addWidget(self.coords_type_radio, 8, 1)
  97. # hidden for the time being, until implemented
  98. coords_type_label.hide()
  99. self.coords_type_radio.hide()
  100. # Line Endings
  101. self.line_ending_cb = FCCheckBox(_("Force Windows style line-ending"))
  102. self.line_ending_cb.setToolTip(
  103. _("When checked will force a Windows style line-ending\n"
  104. "(\\r\\n) on non-Windows OS's.")
  105. )
  106. grid0.addWidget(self.line_ending_cb, 9, 0, 1, 3)
  107. separator_line = QtWidgets.QFrame()
  108. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  109. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  110. grid0.addWidget(separator_line, 12, 0, 1, 2)
  111. # Travel Line Color
  112. self.travel_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Travel Line Color'))
  113. grid0.addWidget(self.travel_color_label, 13, 0, 1, 2)
  114. # Plot Line Color
  115. self.tline_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  116. self.tline_color_label.setToolTip(
  117. _("Set the travel line color for plotted objects.")
  118. )
  119. self.tline_color_entry = FCColorEntry()
  120. grid0.addWidget(self.tline_color_label, 14, 0)
  121. grid0.addWidget(self.tline_color_entry, 14, 1)
  122. # Plot Fill Color
  123. self.tfill_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  124. self.tfill_color_label.setToolTip(
  125. _("Set the fill color for plotted objects.\n"
  126. "First 6 digits are the color and the last 2\n"
  127. "digits are for alpha (transparency) level.")
  128. )
  129. self.tfill_color_entry = FCColorEntry()
  130. grid0.addWidget(self.tfill_color_label, 15, 0)
  131. grid0.addWidget(self.tfill_color_entry, 15, 1)
  132. # Plot Fill Transparency Level
  133. self.cncjob_alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  134. self.cncjob_alpha_label.setToolTip(
  135. _("Set the fill transparency for plotted objects.")
  136. )
  137. self.cncjob_alpha_entry = FCSliderWithSpinner(0, 255, 1)
  138. grid0.addWidget(self.cncjob_alpha_label, 16, 0)
  139. grid0.addWidget(self.cncjob_alpha_entry, 16, 1)
  140. separator_line = QtWidgets.QFrame()
  141. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  142. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  143. grid0.addWidget(separator_line, 17, 0, 1, 2)
  144. # CNCJob Object Color
  145. self.cnc_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Object Color'))
  146. grid0.addWidget(self.cnc_color_label, 18, 0, 1, 2)
  147. # Plot Line Color
  148. self.line_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  149. self.line_color_label.setToolTip(
  150. _("Set the color for plotted objects.")
  151. )
  152. self.line_color_entry = FCColorEntry()
  153. grid0.addWidget(self.line_color_label, 19, 0)
  154. grid0.addWidget(self.line_color_entry, 19, 1)
  155. # Plot Fill Color
  156. self.fill_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  157. self.fill_color_label.setToolTip(
  158. _("Set the fill color for plotted objects.\n"
  159. "First 6 digits are the color and the last 2\n"
  160. "digits are for alpha (transparency) level.")
  161. )
  162. self.fill_color_entry = FCColorEntry()
  163. grid0.addWidget(self.fill_color_label, 20, 0)
  164. grid0.addWidget(self.fill_color_entry, 20, 1)
  165. self.layout.addStretch()
  166. # Setting plot colors signals
  167. self.tline_color_entry.editingFinished.connect(self.on_tline_color_entry)
  168. self.tfill_color_entry.editingFinished.connect(self.on_tfill_color_entry)
  169. self.cncjob_alpha_entry.valueChanged.connect(self.on_cncjob_alpha_changed) # alpha
  170. self.line_color_entry.editingFinished.connect(self.on_line_color_entry)
  171. self.fill_color_entry.editingFinished.connect(self.on_fill_color_entry)
  172. # ------------------------------------------------------
  173. # Setting travel colors handlers
  174. # ------------------------------------------------------
  175. def on_tfill_color_entry(self):
  176. self.app.defaults['cncjob_travel_fill'] = self.tfill_color_entry.get_value()[:7] + \
  177. self.app.defaults['cncjob_travel_fill'][7:9]
  178. def on_tline_color_entry(self):
  179. self.app.defaults['cncjob_travel_line'] = self.tline_color_entry.get_value()[:7] + \
  180. self.app.defaults['cncjob_travel_line'][7:9]
  181. def on_cncjob_alpha_changed(self, spinner_value):
  182. self.app.defaults['cncjob_travel_fill'] = \
  183. self.app.defaults['cncjob_travel_fill'][:7] + \
  184. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  185. self.app.defaults['cncjob_travel_line'] = \
  186. self.app.defaults['cncjob_travel_line'][:7] + \
  187. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  188. # ------------------------------------------------------
  189. # Setting plot colors handlers
  190. # ------------------------------------------------------
  191. def on_fill_color_entry(self):
  192. self.app.defaults['cncjob_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
  193. self.app.defaults['cncjob_plot_fill'][7:9]
  194. def on_line_color_entry(self):
  195. self.app.defaults['cncjob_plot_line'] = self.line_color_entry.get_value()[:7] + \
  196. self.app.defaults['cncjob_plot_line'][7:9]