CNCJobGenPrefGroupUI.py 16 KB

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