From fc97a4ecd66b53d7ec24ac4324f1746ca9afb914 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 30 Aug 2021 17:43:35 +0300 Subject: [PATCH] - add HUD rectangle auto size for 3D Graphic Engine --- CHANGELOG.md | 1 + appCommon/Common.py | 7 ++- appEditors/AppExcEditor.py | 7 ++- appEditors/AppGeoEditor.py | 7 ++- appEditors/AppGerberEditor.py | 7 ++- appGUI/PlotCanvas.py | 95 +++++++++++++++++++++++--------- appPlugins/ToolCopperThieving.py | 7 ++- appPlugins/ToolDistance.py | 7 ++- appPlugins/ToolFollow.py | 7 ++- appPlugins/ToolIsolation.py | 7 ++- appPlugins/ToolNCC.py | 7 ++- appPlugins/ToolPaint.py | 7 ++- app_Main.py | 25 +++++---- 13 files changed, 124 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34705a45..4425139b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG for FlatCAM beta - disabled the selection of a Graphic Engine until matplotlib will have support for PyQt6 framework - removed patch to fix scaling on HIDPI displays since now the fix is implemented in VisPy v0.8.1 - modified a patch for VisPy Infinite Line Visual that set the line width, in order to make it compliant with newer versions of OpenGL +- add HUD rectangle auto size for 3D Graphic Engine 29.08.2021 diff --git a/appCommon/Common.py b/appCommon/Common.py index 04970e44..d9a8d257 100644 --- a/appCommon/Common.py +++ b/appCommon/Common.py @@ -603,9 +603,10 @@ class ExclusionAreas(QtCore.QObject): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) if self.obj_type == 'excellon': color = "#FF7400" diff --git a/appEditors/AppExcEditor.py b/appEditors/AppExcEditor.py index 755fd96c..f5668def 100644 --- a/appEditors/AppExcEditor.py +++ b/appEditors/AppExcEditor.py @@ -3430,9 +3430,10 @@ class AppExcEditor(QtCore.QObject): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, x, units, y, units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, x, units, y, units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, x, y) # ## Utility geometry (animated) self.update_utility_geometry(data=(x, y)) diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index 9bab4429..b6003eb7 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -4795,9 +4795,10 @@ class AppGeoEditor(QtCore.QObject): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, x, units, y, units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, x, units, y, units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, x, y) if event.button == 1 and event_is_dragging and isinstance(self.active_tool, FCEraser): pass diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index 0010197e..69adaa1c 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -5415,9 +5415,10 @@ class AppGerberEditor(QtCore.QObject): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, x, units, y, units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, x, units, y, units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, x, y) self.update_utility_geometry(data=(x, y)) diff --git a/appGUI/PlotCanvas.py b/appGUI/PlotCanvas.py index 970cc451..358e2ca6 100644 --- a/appGUI/PlotCanvas.py +++ b/appGUI/PlotCanvas.py @@ -5,15 +5,13 @@ # MIT Licence # # ########################################################## -from PyQt6 import QtCore +from PyQt6 import QtCore, QtGui import logging from appGUI.VisPyCanvas import VisPyCanvas, Color from appGUI.VisPyVisuals import ShapeGroup, ShapeCollection, TextCollection, TextGroup, Cursor from vispy.scene.visuals import InfiniteLine, Line, Rectangle, Text -from PyQt6 import QtWidgets - import gettext import appTranslation as fcTranslate import builtins @@ -156,34 +154,18 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): self.cursor_h_line = InfiniteLine(pos=None, color=c_color, vertical=False, parent=self.line_parent) - # font size - qsettings = QtCore.QSettings("Open Source", "FlatCAM") - if qsettings.contains("hud_font_size"): - fsize = qsettings.value('hud_font_size', type=int) - else: - fsize = 8 + # setup HUD - # units - units = self.fcapp.defaults["units"].lower() - - # coordinates and anchors - height = fsize * 11 # 90. Constant 11 is something that works - width = height * 2 # width is double the height = it is something that works - center_x = (width / 2) + 5 - center_y = (height / 2) + 5 - - # text - self.text_hud = Text('', color=self.text_hud_color, pos=(10, center_y), method='gpu', anchor_x='left', + # TEXT HUD + self.text_hud = Text('', color=self.text_hud_color, method='gpu', anchor_x='left', parent=None) - self.text_hud.font_size = fsize - self.text_hud.text = 'Dx:\t%s [%s]\nDy:\t%s [%s]\n\nX: \t%s [%s]\nY: \t%s [%s]' % \ - ('0.0000', units, '0.0000', units, '0.0000', units, '0.0000', units) - - # rectangle - self.rect_hud = Rectangle(center=(center_x, center_y), width=width, height=height, radius=[5, 5, 5, 5], + # RECT HUD + 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) + self.on_update_text_hud() + # 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 if self.fcapp.defaults['global_workspace'] is True: @@ -315,6 +297,67 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas): if silent is None: self.fcapp.inform[str, bool].emit(_("HUD disabled."), False) + def on_update_text_hud(self, dx=None, dy=None, x=None, y=None): + """ + + :param dx: + :param dy: + :param x: + :param y: + :return: + """ + # units + units = self.fcapp.defaults["units"].lower() + + dx_dec = str(self.fcapp.dec_format(dx, self.fcapp.decimals)) if dx else '0.0' + dy_dec = str(self.fcapp.dec_format(dy, self.fcapp.decimals)) if dy else '0.0' + x_dec = str(self.fcapp.dec_format(x, self.fcapp.decimals)) if x else '0.0' + y_dec = str(self.fcapp.dec_format(y, self.fcapp.decimals)) if y else '0.0' + l1_hud_text = 'Dx:\t%s [%s]' % (dx_dec, units) + l2_hud_text = 'Dy:\t%s [%s]' % (dy_dec, units) + l3_hud_text = 'X: \t%s [%s]' % (x_dec, units) + l4_hud_text = 'Y: \t%s [%s]' % (y_dec, units) + hud_text = '%s\n%s\n\n%s\n%s' % (l1_hud_text, l2_hud_text, l3_hud_text, l4_hud_text) + + # font size + qsettings = QtCore.QSettings("Open Source", "FlatCAM") + if qsettings.contains("hud_font_size"): + fsize = qsettings.value('hud_font_size', type=int) + else: + fsize = 8 + + c_font = QtGui.QFont() + c_font_metrics = QtGui.QFontMetrics(c_font) + l1_length = c_font_metrics.horizontalAdvance(l1_hud_text, len(l1_hud_text)) + l2_length = c_font_metrics.horizontalAdvance(l2_hud_text, len(l2_hud_text)) + l3_length = c_font_metrics.horizontalAdvance(l3_hud_text, len(l3_hud_text)) + l4_length = c_font_metrics.horizontalAdvance(l4_hud_text, len(l4_hud_text)) + + l1_height = c_font_metrics.boundingRect(l1_hud_text).height() + l2_height = c_font_metrics.boundingRect(l2_hud_text).height() + l3_height = c_font_metrics.boundingRect(l3_hud_text).height() + l4_height = c_font_metrics.boundingRect(l4_hud_text).height() + + # coordinates and anchors + # height = fsize * 11 # 90. Constant 11 is something that works + height = l1_height + l2_height + l3_height + l4_height + (2 * c_font_metrics.lineSpacing()) + # width = height * 2 # width is double the height = it is something that works + width = max(l1_length, l2_length, l3_length, l4_length) + center_x = (width / 2) + 5 + center_y = (height / 2) + 5 + + # text + self.text_hud.font_size = fsize + self.text_hud.text = hud_text + self.text_hud.pos = 10, center_y + self.text_hud.anchors = 'left', 'center' + + # rectangle + self.rect_hud.center = center_x, center_y + self.rect_hud.width = width + self.rect_hud.height = height + self.rect_hud.radius = [5, 5, 5, 5] + def on_toggle_grid_lines(self, signal=None, silent=None): state = not self.grid_lines_enabled diff --git a/appPlugins/ToolCopperThieving.py b/appPlugins/ToolCopperThieving.py index cac5c94d..c7939e47 100644 --- a/appPlugins/ToolCopperThieving.py +++ b/appPlugins/ToolCopperThieving.py @@ -518,9 +518,10 @@ class ToolCopperThieving(AppTool): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) # draw the utility geometry if self.first_click: diff --git a/appPlugins/ToolDistance.py b/appPlugins/ToolDistance.py index 20cd418b..a6ff3564 100644 --- a/appPlugins/ToolDistance.py +++ b/appPlugins/ToolDistance.py @@ -488,9 +488,10 @@ class Distance(AppTool): ) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - 0.0000, units, 0.0000, units, pos[0], units, pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # 0.0000, units, 0.0000, units, pos[0], units, pos[1], units) + self.app.plotcanvas.on_update_text_hud('0.0', '0.0', pos[0], pos[1]) if self.rel_point1 is not None: dx = pos[0] - float(self.rel_point1[0]) diff --git a/appPlugins/ToolFollow.py b/appPlugins/ToolFollow.py index 61edee31..3e0b7805 100644 --- a/appPlugins/ToolFollow.py +++ b/appPlugins/ToolFollow.py @@ -584,9 +584,10 @@ class ToolFollow(AppTool, Gerber): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) # draw the utility geometry if shape_type == "square": diff --git a/appPlugins/ToolIsolation.py b/appPlugins/ToolIsolation.py index cb33a812..aa2d786c 100644 --- a/appPlugins/ToolIsolation.py +++ b/appPlugins/ToolIsolation.py @@ -2656,9 +2656,10 @@ class ToolIsolation(AppTool, Gerber): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) # draw the utility geometry if shape_type == "square": diff --git a/appPlugins/ToolNCC.py b/appPlugins/ToolNCC.py index ffcae397..cbdd49f3 100644 --- a/appPlugins/ToolNCC.py +++ b/appPlugins/ToolNCC.py @@ -1840,9 +1840,10 @@ class NonCopperClear(AppTool, Gerber): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) # draw the utility geometry if shape_type == "square": diff --git a/appPlugins/ToolPaint.py b/appPlugins/ToolPaint.py index df1968bb..c7c72d83 100644 --- a/appPlugins/ToolPaint.py +++ b/appPlugins/ToolPaint.py @@ -1509,9 +1509,10 @@ class ToolPaint(AppTool, Gerber): "%.4f    " % (self.app.dx, self.app.dy)) units = self.app.defaults["units"].lower() - self.app.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + # self.app.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.app.dx, units, self.app.dy, units, curr_pos[0], units, curr_pos[1], units) + self.app.plotcanvas.on_update_text_hud(self.app.dx, self.app.dy, curr_pos[0], curr_pos[1]) # draw the utility geometry if shape_type == "square": diff --git a/app_Main.py b/app_Main.py index e1a108a5..8e4b0b87 100644 --- a/app_Main.py +++ b/app_Main.py @@ -5628,10 +5628,11 @@ class App(QtCore.QObject): self.ui.rel_position_label.setText("Dx: %.4f   Dy: " "%.4f    " % (dx, dy)) - units = self.defaults["units"].lower() - self.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - dx, units, dy, units, location[0], units, location[1], units) + # units = self.defaults["units"].lower() + # self.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # dx, units, dy, units, location[0], units, location[1], units) + self.plotcanvas.on_update_text_hud(dx, dy, location[0], location[1]) self.inform.emit('[success] %s' % _("Done.")) return location @@ -5782,10 +5783,11 @@ class App(QtCore.QObject): self.ui.rel_position_label.setText("Dx: %.4f   Dy: " "%.4f    " % (self.dx, self.dy)) - units = self.defaults["units"].lower() - self.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.dx, units, self.dy, units, location[0], units, location[1], units) + # units = self.defaults["units"].lower() + # self.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.dx, units, self.dy, units, location[0], units, location[1], units) + self.plotcanvas.on_update_text_hud(self.dx, self.dy, location[0], location[1]) self.inform.emit('[success] %s' % _("Done.")) return location @@ -7229,9 +7231,10 @@ class App(QtCore.QObject): "%.4f    " % (self.dx, self.dy)) units = self.defaults["units"].lower() - self.plotcanvas.text_hud.text = \ - 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( - self.dx, units, self.dy, units, pos[0], units, pos[1], units) + # self.plotcanvas.text_hud.text = \ + # 'Dx:\t{:<.4f} [{:s}]\nDy:\t{:<.4f} [{:s}]\n\nX: \t{:<.4f} [{:s}]\nY: \t{:<.4f} [{:s}]'.format( + # self.dx, units, self.dy, units, pos[0], units, pos[1], units) + self.plotcanvas.on_update_text_hud(self.dx, self.dy, pos[0], pos[1]) self.mouse = [pos[0], pos[1]]