From eb0f687bdc848fb16611ffe503d1a2c8e6187759 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 31 May 2023 13:46:17 +0300 Subject: [PATCH] - Pdf Import plugin: fixed an issue with assigning a wrong property to a Qtimer - Extract Plugin and Punch gerber Plugin: fixed a wrong build of the UI triggered even those tools where not launched yet --- CHANGELOG.md | 5 ++ Utils/VisPy_New_Grid_Turntable.py | 131 ++++++++++++++++++++++++++++++ appPlugins/ToolExtract.py | 3 +- appPlugins/ToolPDF.py | 2 +- appPlugins/ToolPunchGerber.py | 3 +- 5 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 Utils/VisPy_New_Grid_Turntable.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf9c51b..2e1afe20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ CHANGELOG for FlatCAM Evo beta ================================================= +31.05.2023 + +- Pdf Import plugin: fixed an issue with assigning a wrong property to a Qtimer +- Extract Plugin and Punch gerber Plugin: fixed a wrong build of the UI triggered even those tools where not launched yet + 25.05.2023 - Geometry Editor: subtool Path: fixed issue of not registering the new click when using the Shift modifier diff --git a/Utils/VisPy_New_Grid_Turntable.py b/Utils/VisPy_New_Grid_Turntable.py new file mode 100644 index 00000000..59bf977f --- /dev/null +++ b/Utils/VisPy_New_Grid_Turntable.py @@ -0,0 +1,131 @@ +""" +Grid 3D +============================ + +Test for GridLines inside 3D view. +""" +from __future__ import division + +import sys +import numpy as np + +from vispy import scene, app + +from vispy.visuals.image import ImageVisual +from vispy.color import Color +from vispy.visuals.shaders import Function + +_GRID_COLOR = """ +vec4 grid_color(vec2 pos) { + vec4 px_pos = $map_to_doc(vec4(pos, 0, 1)); + px_pos /= px_pos.w; + + // Compute vectors representing width, height of pixel in local coords + float s = 1.; + vec4 local_pos = $map_doc_to_local(px_pos); + vec4 dx = $map_doc_to_local(px_pos + vec4(1.0 / s, 0, 0, 0)); + vec4 dy = $map_doc_to_local(px_pos + vec4(0, 1.0 / s, 0, 0)); + local_pos /= local_pos.w; + dx = dx / dx.w - local_pos; + dy = dy / dy.w - local_pos; + + // Pixel length along each axis, rounded to the nearest power of 10 + vec2 px = s * vec2(abs(dx.x) + abs(dy.x), abs(dx.y) + abs(dy.y)); + float log10 = log(10.0); + float sx = pow(10.0, floor(log(px.x) / log10) + 1.) * $scale.x; + float sy = pow(10.0, floor(log(px.y) / log10) + 1.) * $scale.y; + + float max_alpha = 0.6; + float x_alpha = 0.0; + + if (mod(local_pos.x, 1000. * sx) < px.x) { + x_alpha = clamp(1. * sx/px.x, 0., max_alpha); + } + else if (mod(local_pos.x, 100. * sx) < px.x) { + x_alpha = clamp(.1 * sx/px.x, 0., max_alpha); + } + else if (mod(local_pos.x, 10. * sx) < px.x) { + x_alpha = clamp(0.01 * sx/px.x, 0., max_alpha); + } + + float y_alpha = 0.0; + if (mod(local_pos.y, 1000. * sy) < px.y) { + y_alpha = clamp(1. * sy/px.y, 0., max_alpha); + } + else if (mod(local_pos.y, 100. * sy) < px.y) { + y_alpha = clamp(.1 * sy/px.y, 0., max_alpha); + } + else if (mod(local_pos.y, 10. * sy) < px.y) { + y_alpha = clamp(0.01 * sy/px.y, 0., max_alpha); + } + + float alpha = (((log(max(x_alpha, y_alpha))/log(10.)) + 2.) / 3.); + if (alpha == 0.) { + discard; + } + return vec4($color.rgb, $color.a * alpha); +} +""" + + +class GridLinesVisual(ImageVisual): + """Displays regularly spaced grid lines in any coordinate system and at + any scale. + + Parameters + ---------- + scale : tuple + The scale factors to apply when determining the spacing of grid lines. + color : Color + The base color for grid lines. The final color may have its alpha + channel modified. + """ + + def __init__(self, scale=(1, 1), color='w'): + # todo: PlaneVisual should support subdivide/impostor methods from + # image and gridlines should inherit from plane instead. + self._grid_color_fn = Function(_GRID_COLOR) + self._grid_color_fn['color'] = Color(color).rgba + self._grid_color_fn['scale'] = scale + ImageVisual.__init__(self, method='subdivide') + self.set_gl_state('additive', cull_face=False) + self.shared_program.frag['get_data'] = self._grid_color_fn + cfun = Function('vec4 null(vec4 x) { return x; }') + self.shared_program.frag['color_transform'] = cfun + + @property + def size(self): + return (1., 1.) + + def _prepare_transforms(self, view): + fn = self._grid_color_fn + fn['map_to_doc'] = self.get_transform('visual', 'document') + fn['map_doc_to_local'] = self.get_transform('document', 'visual') + ImageVisual._prepare_transforms(self, view) + + def _prepare_draw(self, view): + if self._need_vertex_update: + self._build_vertex_data() + + if view._need_method_update: + self._update_method(view) + + +canvas = scene.SceneCanvas(keys='interactive') +canvas.size = 600, 600 +canvas.show() + +# This is the top-level widget that will hold three ViewBoxes, which will +# be automatically resized whenever the grid is resized. +grid = canvas.central_widget.add_grid() + +# Add 4 ViewBoxes to the grid +b2 = grid.add_view(row=0, col=0) +b2.camera = 'turntable' + +# Bottom-left grid cell shows the same data with log-transformed X +grid_lines = scene.visuals.create_visual_node(GridLinesVisual)() +b2.add(grid_lines) + +if __name__ == '__main__' and sys.flags.interactive == 0: + app.run() \ No newline at end of file diff --git a/appPlugins/ToolExtract.py b/appPlugins/ToolExtract.py index ae28bc38..b1c0ce9f 100644 --- a/appPlugins/ToolExtract.py +++ b/appPlugins/ToolExtract.py @@ -79,6 +79,8 @@ class ToolExtract(AppTool): self.old_name = grb_obj.obj_options['name'] + self.build_tool_ui() + def install(self, icon=None, separator=None, **kwargs): AppTool.install(self, icon, separator, shortcut='Alt+I', **kwargs) @@ -181,7 +183,6 @@ class ToolExtract(AppTool): self.ui.other_cb.stateChanged.connect(self.build_tool_ui) self.ui.gerber_object_combo.currentIndexChanged.connect(self.on_object_combo_changed) - self.ui.gerber_object_combo.currentIndexChanged.connect(self.build_tool_ui) def set_tool_ui(self): self.clear_ui(self.layout) diff --git a/appPlugins/ToolPDF.py b/appPlugins/ToolPDF.py index d26ea143..83eb7df3 100644 --- a/appPlugins/ToolPDF.py +++ b/appPlugins/ToolPDF.py @@ -404,7 +404,7 @@ class ToolPDF(AppTool): pass self.check_thread.timeout.connect(self.periodic_check_handler) - self.check_thread.start(QtCore.QThread.Priority.HighPriority) # noqa + self.check_thread.start() def periodic_check_handler(self): """ diff --git a/appPlugins/ToolPunchGerber.py b/appPlugins/ToolPunchGerber.py index 075a5928..263d2bd8 100644 --- a/appPlugins/ToolPunchGerber.py +++ b/appPlugins/ToolPunchGerber.py @@ -109,6 +109,8 @@ class ToolPunchGerber(AppTool, Gerber): self.old_name = grb_obj.obj_options['name'] + self.build_tool_ui() + def run(self, toggle=True): self.app.defaults.report_usage("ToolPunchGerber()") @@ -209,7 +211,6 @@ class ToolPunchGerber(AppTool, Gerber): self.ui.rectangular_cb.stateChanged.connect(self.build_tool_ui) self.ui.other_cb.stateChanged.connect(self.build_tool_ui) - self.ui.gerber_object_combo.currentIndexChanged.connect(self.build_tool_ui) self.ui.gerber_object_combo.currentIndexChanged.connect(self.on_object_combo_changed) self.ui.punch_type_radio.activated_custom.connect(self.on_punch_type)