- fix issue in Legacy2D graphic mode where the snap function was not accessible when the PlotCanvasLegacy class was created

- modified the HUD in Legacy2D when using Dark Theme to use different colors
- modified how the graphic engine change act in Preferences: now only by clicking Apply(or Save) the change will happen. And there is also a message asking for confirmation
This commit is contained in:
Marius Stanciu
2020-05-12 01:09:00 +03:00
committed by Marius
parent 40c52455e1
commit 3a337212f0
4 changed files with 93 additions and 27 deletions

View File

@@ -18,6 +18,9 @@ CHANGELOG for FlatCAM beta
- fixed some minor issues (in the HUD added a separating line, missing an icon in toolbars on first launch) - fixed some minor issues (in the HUD added a separating line, missing an icon in toolbars on first launch)
- made sure that the corner snap buttons are shown only in Editors - made sure that the corner snap buttons are shown only in Editors
- changed the HUD color when using Dark theme - changed the HUD color when using Dark theme
- fix issue in Legacy2D graphic mode where the snap function was not accessible when the PlotCanvasLegacy class was created
- modified the HUD in Legacy2D when using Dark Theme to use different colors
- modified how the graphic engine change act in Preferences: now only by clicking Apply(or Save) the change will happen. And there is also a message asking for confirmation
10.05.2020 10.05.2020

View File

@@ -981,7 +981,6 @@ class App(QtCore.QObject):
# ########################################################################################################### # ###########################################################################################################
# ######################################## GUI SETTINGS SIGNALS ############################################# # ######################################## GUI SETTINGS SIGNALS #############################################
# ########################################################################################################### # ###########################################################################################################
self.ui.general_defaults_form.general_app_group.ge_radio.activated_custom.connect(self.on_app_restart)
self.ui.general_defaults_form.general_app_set_group.cursor_radio.activated_custom.connect(self.on_cursor_type) self.ui.general_defaults_form.general_app_set_group.cursor_radio.activated_custom.connect(self.on_cursor_type)
# ######################################## Tools related signals ############################################ # ######################################## Tools related signals ############################################
@@ -4621,7 +4620,7 @@ class App(QtCore.QObject):
if self.is_legacy is False: if self.is_legacy is False:
# HACK: enabling/disabling the cursor seams to somehow update the shapes on screen # HACK: enabling/disabling the cursor seams to somehow update the shapes on screen
# - perhaps is a bug in VisPy implementation # - perhaps is a bug in VisPy implementation
if self.grid_status() is True: if self.grid_status():
self.app_cursor.enabled = False self.app_cursor.enabled = False
self.app_cursor.enabled = True self.app_cursor.enabled = True
else: else:

View File

@@ -19,6 +19,8 @@ from shapely.geometry import Polygon, LineString, LinearRing
from copy import deepcopy from copy import deepcopy
import logging import logging
import numpy as np
import gettext import gettext
import FlatCAMTranslation as fcTranslate import FlatCAMTranslation as fcTranslate
import builtins import builtins
@@ -153,8 +155,8 @@ class PlotCanvasLegacy(QtCore.QObject):
else: else:
theme_color = '#000000' theme_color = '#000000'
tick_color = '#FFFFFF' tick_color = '#FFFFFF'
self.rect_hud_color = '#0000FF10' self.rect_hud_color = '#80808040'
self.text_hud_color = '#000000' self.text_hud_color = '#FFFFFF'
# workspace lines; I didn't use the rectangle because I didn't want to add another VisPy Node, # workspace lines; I didn't use the rectangle because I didn't want to add another VisPy Node,
# which might decrease performance # which might decrease performance
@@ -306,11 +308,6 @@ class PlotCanvasLegacy(QtCore.QObject):
self.hud_enabled = False self.hud_enabled = False
self.text_hud = self.Thud(plotcanvas=self) self.text_hud = self.Thud(plotcanvas=self)
# bbox_props = dict(boxstyle="round,pad=0.3", fc="blue", ec="b", lw=0)
# self.text_hud = self.figure.text(0, 0, "Direction", ha="left", va="center", rotation=0,
# size=15,
# bbox=bbox_props)
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area # draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
# all CNC have a limited workspace # all CNC have a limited workspace
if self.app.defaults['global_workspace'] is True: if self.app.defaults['global_workspace'] is True:
@@ -336,19 +333,21 @@ class PlotCanvasLegacy(QtCore.QObject):
self.p = plotcanvas self.p = plotcanvas
units = self.p.app.defaults['units'] units = self.p.app.defaults['units']
self._text = 'Dx: %s [%s]\nDy: %s [%s]\nX: %s [%s]\nY: %s [%s]' % \ self._text = 'Dx: %s [%s]\nDy: %s [%s]\n\nX: %s [%s]\nY: %s [%s]' % \
('0.0000', units, '0.0000', units, '0.0000', units, '0.0000', units) ('0.0000', units, '0.0000', units, '0.0000', units, '0.0000', units)
self.hud_holder = AnchoredText(self._text, self.hud_holder = AnchoredText(self._text, prop=dict(size=20), frameon=True, loc='upper left')
prop=dict(size=20), frameon=True,
loc='upper left',
)
self.hud_holder.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") self.hud_holder.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
self.hud_holder.patch.set_facecolor('blue') fc_color = self.p.rect_hud_color[:-2]
self.hud_holder.patch.set_alpha(0.3) fc_alpha = int(self.p.rect_hud_color[-2:], 16) / 255
text_color = self.p.text_hud_color
self.hud_holder.patch.set_facecolor(fc_color)
self.hud_holder.patch.set_alpha(fc_alpha)
self.hud_holder.patch.set_edgecolor((0, 0, 0, 0)) self.hud_holder.patch.set_edgecolor((0, 0, 0, 0))
self. hud_holder.txt._text.set_color(color=text_color)
self.text_changed.connect(self.on_text_changed) self.text_changed.connect(self.on_text_changed)
@property @property
@@ -496,7 +495,7 @@ class PlotCanvasLegacy(QtCore.QObject):
if self.big_cursor is False: if self.big_cursor is False:
try: try:
x, y = self.app.geo_editor.snap(x_pos, y_pos) x, y = self.snap(x_pos, y_pos)
# Pointer (snapped) # Pointer (snapped)
# The size of the cursor is multiplied by 1.65 because that value made the cursor similar with the # The size of the cursor is multiplied by 1.65 because that value made the cursor similar with the
@@ -931,7 +930,7 @@ class PlotCanvasLegacy(QtCore.QObject):
self.canvas.draw_idle() self.canvas.draw_idle()
# #### Temporary place-holder for cached update ##### # #### Temporary place-holder for cached update #####
self.update_screen_request.emit([0, 0, 0, 0, 0]) # self.update_screen_request.emit([0, 0, 0, 0, 0])
if self.app.defaults["global_cursor_color_enabled"] is True: if self.app.defaults["global_cursor_color_enabled"] is True:
self.draw_cursor(x_pos=x, y_pos=y, color=self.app.cursor_color_3D) self.draw_cursor(x_pos=x, y_pos=y, color=self.app.cursor_color_3D)
@@ -983,6 +982,59 @@ class PlotCanvasLegacy(QtCore.QObject):
return width / xpx, height / ypx return width / xpx, height / ypx
def snap(self, x, y):
"""
Adjusts coordinates to snap settings.
:param x: Input coordinate X
:param y: Input coordinate Y
:return: Snapped (x, y)
"""
snap_x, snap_y = (x, y)
snap_distance = np.Inf
# ### Grid snap
if self.app.grid_status():
if self.app.defaults["global_gridx"] != 0:
try:
snap_x_ = round(x / float(self.app.defaults["global_gridx"])) * \
float(self.app.defaults["global_gridx"])
except TypeError:
snap_x_ = x
else:
snap_x_ = x
# If the Grid_gap_linked on Grid Toolbar is checked then the snap distance on GridY entry will be ignored
# and it will use the snap distance from GridX entry
if self.app.ui.grid_gap_link_cb.isChecked():
if self.app.defaults["global_gridx"] != 0:
try:
snap_y_ = round(y / float(self.app.defaults["global_gridx"])) * \
float(self.app.defaults["global_gridx"])
except TypeError:
snap_y_ = y
else:
snap_y_ = y
else:
if self.app.defaults["global_gridy"] != 0:
try:
snap_y_ = round(y / float(self.app.defaults["global_gridy"])) * \
float(self.app.defaults["global_gridy"])
except TypeError:
snap_y_ = y
else:
snap_y_ = y
nearest_grid_distance = self.distance((x, y), (snap_x_, snap_y_))
if nearest_grid_distance < snap_distance:
snap_x, snap_y = (snap_x_, snap_y_)
return snap_x, snap_y
@staticmethod
def distance(pt1, pt2):
return np.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2)
class FakeCursor(QtCore.QObject): class FakeCursor(QtCore.QObject):
""" """

View File

@@ -921,8 +921,12 @@ class PreferencesUIManager:
theme = 'white' theme = 'white'
should_restart = False should_restart = False
val = self.ui.general_defaults_form.general_gui_group.theme_radio.get_value() theme_new_val = self.ui.general_defaults_form.general_gui_group.theme_radio.get_value()
if val != theme:
ge = self.defaults["global_graphic_engine"]
ge_val = self.ui.general_defaults_form.general_app_group.ge_radio.get_value()
if theme_new_val != theme or ge != ge_val:
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
msgbox.setText(_("Are you sure you want to continue?")) msgbox.setText(_("Are you sure you want to continue?"))
msgbox.setWindowTitle(_("Application restart")) msgbox.setWindowTitle(_("Application restart"))
@@ -935,8 +939,9 @@ class PreferencesUIManager:
msgbox.exec_() msgbox.exec_()
response = msgbox.clickedButton() response = msgbox.clickedButton()
if theme_new_val != theme:
if response == bt_yes: if response == bt_yes:
theme_settings.setValue('theme', val) theme_settings.setValue('theme', theme_new_val)
# This will write the setting to the platform specific storage. # This will write the setting to the platform specific storage.
del theme_settings del theme_settings
@@ -944,6 +949,12 @@ class PreferencesUIManager:
should_restart = True should_restart = True
else: else:
self.ui.general_defaults_form.general_gui_group.theme_radio.set_value(theme) self.ui.general_defaults_form.general_gui_group.theme_radio.set_value(theme)
else:
if response == bt_yes:
self.defaults["global_graphic_engine"] = ge_val
should_restart = True
else:
self.ui.general_defaults_form.general_app_group.ge_radio.set_value(ge)
if save_to_file or should_restart is True: if save_to_file or should_restart is True:
self.save_defaults(silent=False) self.save_defaults(silent=False)
@@ -1035,6 +1046,7 @@ class PreferencesUIManager:
:return: None :return: None
""" """
self.defaults.report_usage("save_defaults") self.defaults.report_usage("save_defaults")
log.debug("App.PreferencesUIManager.save_defaults()")
if data_path is None: if data_path is None:
data_path = self.data_path data_path = self.data_path