From a3f9d7c248cbc7f3b28bdc5835f3d98df7d43d91 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 29 Mar 2022 02:14:44 +0300 Subject: [PATCH] - added ability to change the mouse cursor color on the fly - in Distance Plugin made sure that the 'big cursor' (when is used) is black in color (visible in most situations) - in Distance Plugin, for the 2D graphic mode activated the utility line --- CHANGELOG.md | 6 ++ appEditors/AppExcEditor.py | 4 +- appEditors/AppGeoEditor.py | 2 +- appEditors/AppGerberEditor.py | 4 +- appGUI/PlotCanvas.py | 22 ++++- appGUI/PlotCanvasLegacy.py | 141 +++++++++++++++++++------------ appMain.py | 6 +- appPlugins/ToolCopperThieving.py | 2 +- appPlugins/ToolDistance.py | 34 +++++--- appPlugins/ToolFollow.py | 2 +- appPlugins/ToolIsolation.py | 2 +- appPlugins/ToolNCC.py | 2 +- appPlugins/ToolPaint.py | 2 +- 13 files changed, 145 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19ff0990..e0d23859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ CHANGELOG for FlatCAM Evo beta ================================================= +29.03.2022 + +- added ability to change the mouse cursor color on the fly +- in Distance Plugin made sure that the 'big cursor' (when is used) is black in color (visible in most situations) +- in Distance Plugin, for the 2D graphic mode activated the utility line + 28.03.2022 - in Distance Plugin added the ability to use a big cursor; not finished: when the grid is off it is not displayed diff --git a/appEditors/AppExcEditor.py b/appEditors/AppExcEditor.py index d1af8c52..8d174faf 100644 --- a/appEditors/AppExcEditor.py +++ b/appEditors/AppExcEditor.py @@ -3432,7 +3432,7 @@ class AppExcEditor(QtCore.QObject): x, y = self.app.geo_editor.snap(x, y) # Update cursor - self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D, + self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) @@ -3483,7 +3483,7 @@ class AppExcEditor(QtCore.QObject): self.app.selection_type = None # Update cursor - self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D, + self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index 5323095d..7a280fe8 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -4766,7 +4766,7 @@ class AppGeoEditor(QtCore.QObject): x, y = self.snap(x, y) # Update cursor - self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D, + self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index 71e7654c..1c050994 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -2945,7 +2945,7 @@ class ImportEditorGrb(QtCore.QObject, DrawTool): x, y = self.app.geo_editor.snap(x, y) # Update cursor - self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D, + self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) @@ -5506,7 +5506,7 @@ class AppGerberEditor(QtCore.QObject): x, y = self.app.geo_editor.snap(x, y) # Update cursor - self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D, + self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appGUI/PlotCanvas.py b/appGUI/PlotCanvas.py index 7f8e59f3..ee144540 100644 --- a/appGUI/PlotCanvas.py +++ b/appGUI/PlotCanvas.py @@ -160,7 +160,7 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): # TEXT HUD self.text_hud = Text('', color=self.text_hud_color, method='gpu', anchor_x='left', parent=None) # RECT HUD - self.rect_hud = Rectangle(width=10, height=10, radius=[5, 5, 5, 5], center = (20, 20), + self.rect_hud = Rectangle(width=10, height=10, radius=[5, 5, 5, 5], center=(20, 20), border_color=self.rect_hud_color, color=self.rect_hud_color, parent=None) self.rect_hud.set_gl_state(depth_test=False) @@ -196,8 +196,10 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.text_collection.enabled = True + # Mouse Custom Cursor self.c = None self.big_cursor = None + self._cursor_color = self.fcapp.cursor_color_3D # Parent container # self.container = container @@ -525,6 +527,19 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): return self.c + @property + def cursor_color(self): + return self._cursor_color + + @cursor_color.setter + def cursor_color(self, color): + self._cursor_color = Color(color).rgba + if self.big_cursor is True: + self.cursor_h_line.set_data(color=self._cursor_color) + self.cursor_v_line.set_data(color=self._cursor_color) + else: + self.fcapp.cursor_color_3D = self._cursor_color + def on_mouse_state(self, state): if state: self.cursor_h_line.parent = self.view.scene @@ -536,7 +551,8 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): def on_mouse_position(self, pos): if self.fcapp.options['global_cursor_color_enabled']: - color = Color(self.fcapp.options['global_cursor_color']).rgba + # color = Color(self.fcapp.options['global_cursor_color']).rgba + color = self.cursor_color else: color = self.line_color @@ -578,7 +594,7 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): # Update cursor self.fcapp.app_cursor.set_data(np.asarray([(pos[0], pos[1])]), - symbol='++', edge_color=self.fcapp.cursor_color_3D, + symbol='++', edge_color=self.cursor_color, edge_width=self.fcapp.options["global_cursor_width"], size=self.fcapp.options["global_cursor_size"]) diff --git a/appGUI/PlotCanvasLegacy.py b/appGUI/PlotCanvasLegacy.py index 15a4a2b5..497724f0 100644 --- a/appGUI/PlotCanvasLegacy.py +++ b/appGUI/PlotCanvasLegacy.py @@ -247,6 +247,8 @@ class PlotCanvasLegacy(QtCore.QObject): axis_color = self.color_hex2tuple(axis_default_color) axis_color = axis_color[0], axis_color[1], axis_color[2] + self._cursor_color = self.app.options["global_cursor_color"] + # self.h_line = self.axes.axhline(color=(0.70, 0.3, 0.3), linewidth=2) self.h_line = None self.v_line = None @@ -572,7 +574,7 @@ class PlotCanvasLegacy(QtCore.QObject): self.app.ui.wplace_label.set_value(workspace_size[:3]) self.app.ui.wplace_label.setToolTip(workspace_size) - self.fcapp.ui.wplace_label.setStyleSheet(""" + self.app.ui.wplace_label.setStyleSheet(""" QLabel { color: black; @@ -586,7 +588,7 @@ class PlotCanvasLegacy(QtCore.QObject): self.canvas.draw() except Exception: pass - self.fcapp.ui.wplace_label.setStyleSheet("") + self.app.ui.wplace_label.setStyleSheet("") def graph_event_connect(self, event_name, callback): """ @@ -653,6 +655,26 @@ class PlotCanvasLegacy(QtCore.QObject): return c + @property + def cursor_color(self): + return self._cursor_color + + @cursor_color.setter + def cursor_color(self, color): + self._cursor_color = color + if self.big_cursor is True: + try: + self.ch_line.remove() + self.cv_line.remove() + self.canvas.draw_idle() + except Exception as e: + self.app.log.error("PlotCanvasLegacy.cursor_color() --> %s" % str(e)) + + self.ch_line = self.axes.axhline(color=color, linewidth=self.app.options["global_cursor_width"]) + self.cv_line = self.axes.axvline(color=color, linewidth=self.app.options["global_cursor_width"]) + else: + self.app.cursor_color_3D = color + def draw_cursor(self, x_pos, y_pos, color=None): """ Draw a cursor at the mouse grid snapped position @@ -664,70 +686,73 @@ class PlotCanvasLegacy(QtCore.QObject): """ # there is no point in drawing mouse cursor when panning as it jumps in a confusing way - if self.app.app_cursor.enabled is True and self.panning is False: - if color: - color = color + if self.app.app_cursor.enabled is False or self.panning is True: + return + + if color: + color = color + else: + if self.app.options['global_theme'] == 'white': + color = '#000000' else: - if self.app.options['global_theme'] == 'white': - color = '#000000' - else: - color = '#FFFFFF' + color = '#FFFFFF' - if self.big_cursor is False: - try: - x, y = self.snap(x_pos, y_pos) + if self.big_cursor is False: + try: + x, y = self.snap(x_pos, y_pos) - # Pointer (snapped) - # The size of the cursor is multiplied by 1.65 because that value made the cursor similar with the - # one in the OpenGL(3D) graphic engine - pointer_size = int(float(self.app.options["global_cursor_size"]) * 1.65) - elements = self.axes.plot(x, y, '+', color=color, ms=pointer_size, - mew=self.app.options["global_cursor_width"], animated=True) - for el in elements: - self.axes.draw_artist(el) - except Exception as e: - # this happen at app initialization since self.app.geo_editor does not exist yet - # I could reshuffle the object instantiating order but what's the point? - # I could crash something else and that's pythonic, too - self.app.log.error("PlotCanvasLegacy.draw_cursor() big_cursor is False --> %s" % str(e)) - else: - try: - self.ch_line.set_markeredgewidth(self.app.options["global_cursor_width"]) - self.cv_line.set_markeredgewidth(self.app.options["global_cursor_width"]) - except Exception: - pass + # Pointer (snapped) + # The size of the cursor is multiplied by 1.65 because that value made the cursor similar with the + # one in the OpenGL(3D) graphic engine + pointer_size = int(float(self.app.options["global_cursor_size"]) * 1.65) + elements = self.axes.plot(x, y, '+', color=color, ms=pointer_size, + mew=self.app.options["global_cursor_width"], animated=True) + for el in elements: + self.axes.draw_artist(el) + except Exception as e: + # this happen at app initialization since self.app.geo_editor does not exist yet + # I could reshuffle the object instantiating order but what's the point? + # I could crash something else and that's pythonic, too + self.app.log.error("PlotCanvasLegacy.draw_cursor() big_cursor is False --> %s" % str(e)) + else: + try: + self.ch_line.set_markeredgewidth(self.app.options["global_cursor_width"]) + self.cv_line.set_markeredgewidth(self.app.options["global_cursor_width"]) + except Exception: + pass - try: - x, y = self.app.geo_editor.snap(x_pos, y_pos) - self.ch_line.set_ydata(y) - self.cv_line.set_xdata(x) - except Exception: - # this happen at app initialization since self.app.geo_editor does not exist yet - # I could reshuffle the object instantiating order but what's the point? - # I could crash something else and that's pythonic, too - pass - self.canvas.draw_idle() + try: + x, y = self.app.geo_editor.snap(x_pos, y_pos) + self.ch_line.set_ydata(y) + self.cv_line.set_xdata(x) + except Exception: + # this happen at app initialization since self.app.geo_editor does not exist yet + # I could reshuffle the object instantiating order but what's the point? + # I could crash something else and that's pythonic, too + pass + self.canvas.draw_idle() - self.canvas.blit(self.axes.bbox) + self.canvas.blit(self.axes.bbox) def clear_cursor(self, state): + if self.app.options['global_theme'] == 'white': + color = '#000000' + else: + color = '#FFFFFF' + if state is True: if self.big_cursor is True and self.big_cursor_isdisabled is True: if self.app.options["global_cursor_color_enabled"]: - color = self.app.options["global_cursor_color"] - else: - if self.app.options['global_theme'] == 'white': - color = '#000000' - else: - color = '#FFFFFF' - + color = self.cursor_color self.ch_line = self.axes.axhline(color=color, linewidth=self.app.options["global_cursor_width"]) self.cv_line = self.axes.axvline(color=color, linewidth=self.app.options["global_cursor_width"]) self.big_cursor_isdisabled = False + if self.app.options["global_cursor_color_enabled"] is True: - self.draw_cursor(x_pos=self.mouse[0], y_pos=self.mouse[1], color=self.app.cursor_color_3D) + color = self.cursor_color + self.draw_cursor(x_pos=self.mouse[0], y_pos=self.mouse[1], color=color) else: - self.draw_cursor(x_pos=self.mouse[0], y_pos=self.mouse[1]) + self.draw_cursor(x_pos=self.mouse[0], y_pos=self.mouse[1], color=None) else: if self.big_cursor is True: self.big_cursor_isdisabled = True @@ -1118,9 +1143,10 @@ class PlotCanvasLegacy(QtCore.QObject): # self.update_screen_request.emit([0, 0, 0, 0, 0]) if self.app.options["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) + self.draw_cursor(x_pos=x, y_pos=y, color=self.cursor_color) else: - self.draw_cursor(x_pos=x, y_pos=y) + self.draw_cursor(x_pos=x, y_pos=y, color=None) # self.canvas.blit(self.axes.bbox) @staticmethod @@ -1571,7 +1597,8 @@ class ShapeCollectionLegacy: self.axes.add_patch(patch) except Exception as e: - self.app.log.error("ShapeCollectionLegacy.redraw() utility poly with face_color --> %s" % str(e)) + self.app.log.error( + "ShapeCollectionLegacy.redraw() utility poly with face_color --> %s" % str(e)) else: if isinstance(local_shapes[element]['shape'], Polygon): try: @@ -1586,7 +1613,8 @@ class ShapeCollectionLegacy: self.axes.plot(x, y, local_shapes[element]['color'], linestyle='-', linewidth=local_shapes[element]['linewidth']) except Exception as e: - self.app.log.error("ShapeCollectionLegacy.redraw() utility poly no face_color --> %s" % str(e)) + self.app.log.error( + "ShapeCollectionLegacy.redraw() utility poly no face_color --> %s" % str(e)) else: try: if local_shapes[element]['shape'] is not None: @@ -1594,7 +1622,8 @@ class ShapeCollectionLegacy: self.axes.plot(x, y, local_shapes[element]['color'], linestyle='-', linewidth=local_shapes[element]['linewidth']) except Exception as e: - self.app.log.error("ShapeCollectionLegacy.redraw() utility lines no face_color --> %s" % str(e)) + self.app.log.error( + "ShapeCollectionLegacy.redraw() utility lines no face_color --> %s" % str(e)) self.app.plotcanvas.auto_adjust_axes() def set(self, text, pos, visible=True, font_size=16, color=None): diff --git a/appMain.py b/appMain.py index f79740bd..bbdeb672 100644 --- a/appMain.py +++ b/appMain.py @@ -5741,7 +5741,7 @@ class App(QtCore.QObject): if self.grid_status(): # Update cursor self.app_cursor.set_data(np.asarray([(location[0], location[1])]), - symbol='++', edge_color=self.cursor_color_3D, + symbol='++', edge_color=self.plotcanvas.cursor_color, edge_width=self.options["global_cursor_width"], size=self.options["global_cursor_size"]) @@ -5857,7 +5857,7 @@ class App(QtCore.QObject): if self.grid_status(): # Update cursor self.app_cursor.set_data(np.asarray([(location[0], location[1])]), - symbol='++', edge_color=self.cursor_color_3D, + symbol='++', edge_color=self.plotcanvas.cursor_color, edge_width=self.options["global_cursor_width"], size=self.options["global_cursor_size"]) @@ -7394,7 +7394,7 @@ class App(QtCore.QObject): # Update cursor self.app_cursor.set_data(np.asarray([(pos[0], pos[1])]), - symbol='++', edge_color=self.cursor_color_3D, + symbol='++', edge_color=self.plotcanvas.cursor_color, edge_width=self.options["global_cursor_width"], size=self.options["global_cursor_size"]) else: diff --git a/appPlugins/ToolCopperThieving.py b/appPlugins/ToolCopperThieving.py index 36306dc5..a126e03d 100644 --- a/appPlugins/ToolCopperThieving.py +++ b/appPlugins/ToolCopperThieving.py @@ -505,7 +505,7 @@ class ToolCopperThieving(AppTool): curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1]) self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appPlugins/ToolDistance.py b/appPlugins/ToolDistance.py index 1516cb16..1c7723d7 100644 --- a/appPlugins/ToolDistance.py +++ b/appPlugins/ToolDistance.py @@ -74,6 +74,9 @@ class Distance(AppTool): # store the grid status here self.grid_status_memory = False + # store here the cursor color + self.cursor_color_memory = None + # store here if the snap button was clicked self.snap_toggled = None @@ -188,8 +191,13 @@ class Distance(AppTool): self.initial_view() if self.ui.big_cursor_cb.get_value(): - self.app.app_cursor.enabled = True self.app.on_cursor_type(val="big", control_cursor=True) + self.cursor_color_memory = self.app.plotcanvas.cursor_color + if self.app.use_3d_engine is True: + self.app.plotcanvas.cursor_color = '#000000FF' + else: + self.app.plotcanvas.cursor_color = '#000000' + self.app.app_cursor.enabled = True self.app.call_source = 'measurement' @@ -208,9 +216,6 @@ class Distance(AppTool): if self.app.ui.grid_snap_btn.isChecked(): self.app.ui.grid_snap_btn.trigger() - if self.ui.big_cursor_cb.get_value(): - self.app.on_cursor_type(val="big", control_cursor=True) - def on_start_measuring(self): # ENABLE the Measuring TOOL self.active = True @@ -329,6 +334,7 @@ class Distance(AppTool): # restore cursor self.app.on_cursor_type(val=self.old_cursor_type, control_cursor=False) + self.app.plotcanvas.cursor_color = self.cursor_color_memory # restore the grid status if (self.app.ui.grid_snap_btn.isChecked() and self.grid_status_memory is False) or \ @@ -553,7 +559,7 @@ class Distance(AppTool): pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1]) # Update cursor self.app.app_cursor.set_data(np.asarray([(pos[0], pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) else: @@ -567,7 +573,7 @@ class Distance(AppTool): pos = (pos_canvas[0], pos_canvas[1]) # Update cursor self.app.app_cursor.set_data(np.asarray([(pos[0], pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) @@ -689,15 +695,19 @@ class Distance(AppTool): else: theme = 'white' - if theme == 'white': - color = '#000000FF' + if self.app.use_3d_engine: + if theme == 'white': + color = '#000000FF' + else: + color = '#FFFFFFFF' else: - color = '#FFFFFFFF' + if theme == 'white': + color = '#000000' + else: + color = '#FFFFFF' self.last_shape = self.sel_shapes.add(meas_line, color=color, update=True, layer=0, tolerance=None, linewidth=2) - - if self.app.use_3d_engine: - self.sel_shapes.redraw() + self.sel_shapes.redraw() def delete_all_shapes(self): self.sel_shapes.clear() diff --git a/appPlugins/ToolFollow.py b/appPlugins/ToolFollow.py index 42fd3b00..9919cfa5 100644 --- a/appPlugins/ToolFollow.py +++ b/appPlugins/ToolFollow.py @@ -559,7 +559,7 @@ class ToolFollow(AppTool, Gerber): curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1]) self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appPlugins/ToolIsolation.py b/appPlugins/ToolIsolation.py index d11ed3a1..7c5ff54a 100644 --- a/appPlugins/ToolIsolation.py +++ b/appPlugins/ToolIsolation.py @@ -2812,7 +2812,7 @@ class ToolIsolation(AppTool, Gerber): curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1]) self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appPlugins/ToolNCC.py b/appPlugins/ToolNCC.py index 422b0470..08c3afe8 100644 --- a/appPlugins/ToolNCC.py +++ b/appPlugins/ToolNCC.py @@ -1767,7 +1767,7 @@ class NonCopperClear(AppTool, Gerber): curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1]) self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"]) diff --git a/appPlugins/ToolPaint.py b/appPlugins/ToolPaint.py index a357a04e..59ede318 100644 --- a/appPlugins/ToolPaint.py +++ b/appPlugins/ToolPaint.py @@ -1489,7 +1489,7 @@ class ToolPaint(AppTool, Gerber): curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1]) self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]), - symbol='++', edge_color=self.app.cursor_color_3D, + symbol='++', edge_color=self.app.plotcanvas.cursor_color, edge_width=self.app.options["global_cursor_width"], size=self.app.options["global_cursor_size"])