CNCJobGenPrefGroupUI.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtCore import QSettings
  3. from AppGUI.GUIElements import FCCheckBox, RadioSet, FCSpinner, FCDoubleSpinner, FCEntry
  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. # Plot Kind
  35. self.cncplot_method_label = QtWidgets.QLabel('%s:' % _("Plot kind"))
  36. self.cncplot_method_label.setToolTip(
  37. _("This selects the kind of geometries on the canvas to plot.\n"
  38. "Those can be either of type 'Travel' which means the moves\n"
  39. "above the work piece or it can be of type 'Cut',\n"
  40. "which means the moves that cut into the material.")
  41. )
  42. self.cncplot_method_radio = RadioSet([
  43. {"label": _("All"), "value": "all"},
  44. {"label": _("Travel"), "value": "travel"},
  45. {"label": _("Cut"), "value": "cut"}
  46. ], orientation='vertical')
  47. grid0.addWidget(self.cncplot_method_label, 1, 0)
  48. grid0.addWidget(self.cncplot_method_radio, 1, 1)
  49. grid0.addWidget(QtWidgets.QLabel(''), 1, 2)
  50. # Display Annotation
  51. self.annotation_cb = FCCheckBox(_("Display Annotation"))
  52. self.annotation_cb.setToolTip(
  53. _("This selects if to display text annotation on the plot.\n"
  54. "When checked it will display numbers in order for each end\n"
  55. "of a travel line."
  56. )
  57. )
  58. grid0.addWidget(self.annotation_cb, 2, 0, 1, 3)
  59. # ###################################################################
  60. # Number of circle steps for circular aperture linear approximation #
  61. # ###################################################################
  62. self.steps_per_circle_label = QtWidgets.QLabel('%s:' % _("Circle Steps"))
  63. self.steps_per_circle_label.setToolTip(
  64. _("The number of circle steps for <b>GCode</b> \n"
  65. "circle and arc shapes linear approximation.")
  66. )
  67. grid0.addWidget(self.steps_per_circle_label, 3, 0)
  68. self.steps_per_circle_entry = FCSpinner()
  69. self.steps_per_circle_entry.set_range(0, 99999)
  70. grid0.addWidget(self.steps_per_circle_entry, 3, 1)
  71. # Tool dia for plot
  72. tdlabel = QtWidgets.QLabel('%s:' % _('Travel dia'))
  73. tdlabel.setToolTip(
  74. _("The width of the travel lines to be\n"
  75. "rendered in the plot.")
  76. )
  77. self.tooldia_entry = FCDoubleSpinner()
  78. self.tooldia_entry.set_range(0, 99999)
  79. self.tooldia_entry.set_precision(self.decimals)
  80. self.tooldia_entry.setSingleStep(0.1)
  81. self.tooldia_entry.setWrapping(True)
  82. grid0.addWidget(tdlabel, 4, 0)
  83. grid0.addWidget(self.tooldia_entry, 4, 1)
  84. # add a space
  85. grid0.addWidget(QtWidgets.QLabel('<b>%s:</b>' % _("G-code Decimals")), 5, 0, 1, 2)
  86. # Number of decimals to use in GCODE coordinates
  87. cdeclabel = QtWidgets.QLabel('%s:' % _('Coordinates'))
  88. cdeclabel.setToolTip(
  89. _("The number of decimals to be used for \n"
  90. "the X, Y, Z coordinates in CNC code (GCODE, etc.)")
  91. )
  92. self.coords_dec_entry = FCSpinner()
  93. self.coords_dec_entry.set_range(0, 9)
  94. self.coords_dec_entry.setWrapping(True)
  95. grid0.addWidget(cdeclabel, 6, 0)
  96. grid0.addWidget(self.coords_dec_entry, 6, 1)
  97. # Number of decimals to use in GCODE feedrate
  98. frdeclabel = QtWidgets.QLabel('%s:' % _('Feedrate'))
  99. frdeclabel.setToolTip(
  100. _("The number of decimals to be used for \n"
  101. "the Feedrate parameter in CNC code (GCODE, etc.)")
  102. )
  103. self.fr_dec_entry = FCSpinner()
  104. self.fr_dec_entry.set_range(0, 9)
  105. self.fr_dec_entry.setWrapping(True)
  106. grid0.addWidget(frdeclabel, 7, 0)
  107. grid0.addWidget(self.fr_dec_entry, 7, 1)
  108. # The type of coordinates used in the Gcode: Absolute or Incremental
  109. coords_type_label = QtWidgets.QLabel('%s:' % _('Coordinates type'))
  110. coords_type_label.setToolTip(
  111. _("The type of coordinates to be used in Gcode.\n"
  112. "Can be:\n"
  113. "- Absolute G90 -> the reference is the origin x=0, y=0\n"
  114. "- Incremental G91 -> the reference is the previous position")
  115. )
  116. self.coords_type_radio = RadioSet([
  117. {"label": _("Absolute G90"), "value": "G90"},
  118. {"label": _("Incremental G91"), "value": "G91"}
  119. ], orientation='vertical', stretch=False)
  120. grid0.addWidget(coords_type_label, 8, 0)
  121. grid0.addWidget(self.coords_type_radio, 8, 1)
  122. # hidden for the time being, until implemented
  123. coords_type_label.hide()
  124. self.coords_type_radio.hide()
  125. # Line Endings
  126. self.line_ending_cb = FCCheckBox(_("Force Windows style line-ending"))
  127. self.line_ending_cb.setToolTip(
  128. _("When checked will force a Windows style line-ending\n"
  129. "(\\r\\n) on non-Windows OS's.")
  130. )
  131. grid0.addWidget(self.line_ending_cb, 9, 0, 1, 3)
  132. separator_line = QtWidgets.QFrame()
  133. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  134. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  135. grid0.addWidget(separator_line, 12, 0, 1, 2)
  136. # Travel Line Color
  137. self.travel_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Travel Line Color'))
  138. grid0.addWidget(self.travel_color_label, 13, 0, 1, 2)
  139. # Plot Line Color
  140. self.tline_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  141. self.tline_color_label.setToolTip(
  142. _("Set the travel line color for plotted objects.")
  143. )
  144. self.tline_color_entry = FCEntry()
  145. self.tline_color_button = QtWidgets.QPushButton()
  146. self.tline_color_button.setFixedSize(15, 15)
  147. self.form_box_child_2 = QtWidgets.QHBoxLayout()
  148. self.form_box_child_2.addWidget(self.tline_color_entry)
  149. self.form_box_child_2.addWidget(self.tline_color_button)
  150. self.form_box_child_2.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  151. grid0.addWidget(self.tline_color_label, 14, 0)
  152. grid0.addLayout(self.form_box_child_2, 14, 1)
  153. # Plot Fill Color
  154. self.tfill_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  155. self.tfill_color_label.setToolTip(
  156. _("Set the fill color for plotted objects.\n"
  157. "First 6 digits are the color and the last 2\n"
  158. "digits are for alpha (transparency) level.")
  159. )
  160. self.tfill_color_entry = FCEntry()
  161. self.tfill_color_button = QtWidgets.QPushButton()
  162. self.tfill_color_button.setFixedSize(15, 15)
  163. self.form_box_child_1 = QtWidgets.QHBoxLayout()
  164. self.form_box_child_1.addWidget(self.tfill_color_entry)
  165. self.form_box_child_1.addWidget(self.tfill_color_button)
  166. self.form_box_child_1.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  167. grid0.addWidget(self.tfill_color_label, 15, 0)
  168. grid0.addLayout(self.form_box_child_1, 15, 1)
  169. # Plot Fill Transparency Level
  170. self.alpha_label = QtWidgets.QLabel('%s:' % _('Alpha'))
  171. self.alpha_label.setToolTip(
  172. _("Set the fill transparency for plotted objects.")
  173. )
  174. self.tcolor_alpha_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
  175. self.tcolor_alpha_slider.setMinimum(0)
  176. self.tcolor_alpha_slider.setMaximum(255)
  177. self.tcolor_alpha_slider.setSingleStep(1)
  178. self.tcolor_alpha_spinner = FCSpinner()
  179. self.tcolor_alpha_spinner.setMinimumWidth(70)
  180. self.tcolor_alpha_spinner.set_range(0, 255)
  181. self.form_box_child_3 = QtWidgets.QHBoxLayout()
  182. self.form_box_child_3.addWidget(self.tcolor_alpha_slider)
  183. self.form_box_child_3.addWidget(self.tcolor_alpha_spinner)
  184. grid0.addWidget(self.alpha_label, 16, 0)
  185. grid0.addLayout(self.form_box_child_3, 16, 1)
  186. separator_line = QtWidgets.QFrame()
  187. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  188. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  189. grid0.addWidget(separator_line, 17, 0, 1, 2)
  190. # CNCJob Object Color
  191. self.cnc_color_label = QtWidgets.QLabel('<b>%s</b>' % _('CNCJob Object Color'))
  192. grid0.addWidget(self.cnc_color_label, 18, 0, 1, 2)
  193. # Plot Line Color
  194. self.line_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  195. self.line_color_label.setToolTip(
  196. _("Set the color for plotted objects.")
  197. )
  198. self.line_color_entry = FCEntry()
  199. self.line_color_button = QtWidgets.QPushButton()
  200. self.line_color_button.setFixedSize(15, 15)
  201. self.form_box_child_2 = QtWidgets.QHBoxLayout()
  202. self.form_box_child_2.addWidget(self.line_color_entry)
  203. self.form_box_child_2.addWidget(self.line_color_button)
  204. self.form_box_child_2.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  205. grid0.addWidget(self.line_color_label, 19, 0)
  206. grid0.addLayout(self.form_box_child_2, 19, 1)
  207. # Plot Fill Color
  208. self.fill_color_label = QtWidgets.QLabel('%s:' % _('Fill'))
  209. self.fill_color_label.setToolTip(
  210. _("Set the fill color for plotted objects.\n"
  211. "First 6 digits are the color and the last 2\n"
  212. "digits are for alpha (transparency) level.")
  213. )
  214. self.fill_color_entry = FCEntry()
  215. self.fill_color_button = QtWidgets.QPushButton()
  216. self.fill_color_button.setFixedSize(15, 15)
  217. self.form_box_child_1 = QtWidgets.QHBoxLayout()
  218. self.form_box_child_1.addWidget(self.fill_color_entry)
  219. self.form_box_child_1.addWidget(self.fill_color_button)
  220. self.form_box_child_1.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  221. grid0.addWidget(self.fill_color_label, 20, 0)
  222. grid0.addLayout(self.form_box_child_1, 20, 1)
  223. self.layout.addStretch()
  224. # Setting plot colors signals
  225. self.tline_color_entry.editingFinished.connect(self.on_tline_color_entry)
  226. self.tline_color_button.clicked.connect(self.on_tline_color_button)
  227. self.tfill_color_entry.editingFinished.connect(self.on_tfill_color_entry)
  228. self.tfill_color_button.clicked.connect(self.on_tfill_color_button)
  229. self.tcolor_alpha_spinner.valueChanged.connect(self.on_tcolor_spinner)
  230. self.tcolor_alpha_slider.valueChanged.connect(self.on_tcolor_slider)
  231. self.line_color_entry.editingFinished.connect(self.on_line_color_entry)
  232. self.line_color_button.clicked.connect(self.on_line_color_button)
  233. self.fill_color_entry.editingFinished.connect(self.on_fill_color_entry)
  234. self.fill_color_button.clicked.connect(self.on_fill_color_button)
  235. # ------------------------------------------------------
  236. # Setting travel colors handlers
  237. # ------------------------------------------------------
  238. def on_tfill_color_entry(self):
  239. self.app.defaults['cncjob_travel_fill'] = self.tfill_color_entry.get_value()[:7] + \
  240. self.app.defaults['cncjob_travel_fill'][7:9]
  241. self.tfill_color_button.setStyleSheet(
  242. "background-color:%s" % str(self.app.defaults['cncjob_travel_fill'])[:7])
  243. def on_tfill_color_button(self):
  244. current_color = QtGui.QColor(self.app.defaults['cncjob_travel_fill'][:7])
  245. c_dialog = QtWidgets.QColorDialog()
  246. plot_fill_color = c_dialog.getColor(initial=current_color)
  247. if plot_fill_color.isValid() is False:
  248. return
  249. self.tfill_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  250. new_val = str(plot_fill_color.name()) + str(self.app.defaults['cncjob_travel_fill'][7:9])
  251. self.tfill_color_entry.set_value(new_val)
  252. self.app.defaults['cncjob_travel_fill'] = new_val
  253. def on_tcolor_spinner(self):
  254. spinner_value = self.tcolor_alpha_spinner.value()
  255. self.tcolor_alpha_slider.setValue(spinner_value)
  256. self.app.defaults['cncjob_travel_fill'] = \
  257. self.app.defaults['cncjob_travel_fill'][:7] + \
  258. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  259. self.app.defaults['cncjob_travel_line'] = \
  260. self.app.defaults['cncjob_travel_line'][:7] + \
  261. (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  262. def on_tcolor_slider(self):
  263. slider_value = self.tcolor_alpha_slider.value()
  264. self.tcolor_alpha_spinner.setValue(slider_value)
  265. def on_tline_color_entry(self):
  266. self.app.defaults['cncjob_travel_line'] = self.tline_color_entry.get_value()[:7] + \
  267. self.app.defaults['cncjob_travel_line'][7:9]
  268. self.tline_color_button.setStyleSheet(
  269. "background-color:%s" % str(self.app.defaults['cncjob_travel_line'])[:7])
  270. def on_tline_color_button(self):
  271. current_color = QtGui.QColor(self.app.defaults['cncjob_travel_line'][:7])
  272. # print(current_color)
  273. c_dialog = QtWidgets.QColorDialog()
  274. plot_line_color = c_dialog.getColor(initial=current_color)
  275. if plot_line_color.isValid() is False:
  276. return
  277. self.tline_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  278. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['cncjob_travel_line'][7:9])
  279. self.tline_color_entry.set_value(new_val_line)
  280. self.app.defaults['cncjob_travel_line'] = new_val_line
  281. # ------------------------------------------------------
  282. # Setting plot colors handlers
  283. # ------------------------------------------------------
  284. def on_fill_color_entry(self):
  285. self.app.defaults['cncjob_plot_fill'] = self.fill_color_entry.get_value()[:7] + \
  286. self.app.defaults['cncjob_plot_fill'][7:9]
  287. self.fill_color_button.setStyleSheet(
  288. "background-color:%s" % str(self.app.defaults['cncjob_plot_fill'])[:7])
  289. def on_fill_color_button(self):
  290. current_color = QtGui.QColor(self.app.defaults['cncjob_plot_fill'][:7])
  291. c_dialog = QtWidgets.QColorDialog()
  292. plot_fill_color = c_dialog.getColor(initial=current_color)
  293. if plot_fill_color.isValid() is False:
  294. return
  295. self.fill_color_button.setStyleSheet("background-color:%s" % str(plot_fill_color.name()))
  296. new_val = str(plot_fill_color.name()) + str(self.app.defaults['cncjob_plot_fill'][7:9])
  297. self.fill_color_entry.set_value(new_val)
  298. self.app.defaults['cncjob_plot_fill'] = new_val
  299. def on_line_color_entry(self):
  300. self.app.defaults['cncjob_plot_line'] = self.line_color_entry.get_value()[:7] + \
  301. self.app.defaults['cncjob_plot_line'][7:9]
  302. self.line_color_button.setStyleSheet(
  303. "background-color:%s" % str(self.app.defaults['cncjob_plot_line'])[:7])
  304. def on_line_color_button(self):
  305. current_color = QtGui.QColor(self.app.defaults['cncjob_plot_line'][:7])
  306. # print(current_color)
  307. c_dialog = QtWidgets.QColorDialog()
  308. plot_line_color = c_dialog.getColor(initial=current_color)
  309. if plot_line_color.isValid() is False:
  310. return
  311. self.line_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  312. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['cncjob_plot_line'][7:9])
  313. self.line_color_entry.set_value(new_val_line)
  314. self.app.defaults['cncjob_plot_line'] = new_val_line