pcb-rnd knowledge pool
Local grid on GTK
local_grid by Tibor 'Igor2' Palinkas on 2016-09-25
Tags: howto, ui, gui, grid, slow, speed, rendering
Abstract: The local grid reduces number of grid points drawn, showing the grid only around the cursor, like a flashlight. It helps a lot with software rendering on large screen.
Problem with the original gtk grid
The original code draws every grid point on screen, even the ones that are off the board. When the user zooms out with a dense grid, it can become too dense - the original code turns the grid off in this case.
If the grid is very dense, on a large screen the software render may slow down. This is noticeable in pan and zoom mostly. The bottleneck is the gtk call that draws the grid points: if there are too many of them, it's slow.
To overcome this problem, pcb-rnd offers configuration settings to limit the number of dots to be drawn. There are mainly two parallel approaches: using a local grid or draw less dots in a global grid . The old code defined only a global grid and did not have runtime settings for the properties of the grid.
There's a new "Grid properties" submenu in the view menu in the default gtk hid menu file. Screenshots were taken with this menu teared-down to demonstrate the settings.
Global grid improvements
The most trivial optimization is that grid points off the board are simply not drawn:
Next, the compile-time configurable "minimum distance between grid points before it is too dense" setting is user configurable now. The default value can be changed in any of the usual configuration sources . However, when the configured density is reached while zooming out, there are two options.
The first, default option is to do the same that the original code did: just hide the grid:
An alternative is to use sparse global grid which means only every 2nd, 3rd, 4th, ... Nth grid point is drawn. The cursor still snaps to every real grid point, so the grid got sparse only on the display. Note how the line is drawn on invisible grid points:
Introduction of the local grid
Another approach is to use a local grid. The grid helps finding whether existing objects are aligned or where the next move/click would end up. These are usually interesting only in a small range around the crosshair and less interesting on the other end of the board. Local grid draws the grid points only near the crosshair. Such local grid follows the crosshair everywhere:
The user can configure or interactively set the radius in which the grid points are drawn:
The radius is given in "number of grid points", thus the local grid yields a constant number of points that is independent of the actual grid size. When a local grid gets too dense, it is hidden - there's no sparse option, since local grids usually have too few points to make reasonable skips.