← Back to team overview

kicad-developers team mailing list archive

Snap to pad (proof of concept patch)


Picking up the discussion at and around
I've made a quick and dirty proof of concept implementation
of a snap to pad feature.

This patch has a number of limitations:

- high CPU usage: the CPU load roughly doubles for a not very
complex board (about 100 pads). A better solution would
maintain a sorted structure of pads (e.g., a radix priority
search tree, a nice implementation of which can be found in
the Linux kernel, lib/prio_tree.c), and do the pad search on
that structure.

- it would be nice if the same mechanism also worked with
traces, e.g., with a 50x50 grid, if the mouse is at
(1010,2020) and we have a 12 mil trace at x=1015, the
cursor would snap to (1015,2000).

Note: "pcb" doesn't do this, which occasionally forces
one to delete and redraw traces, because it's not possible
to connect to them cleanly.

- as an extension to the above, one may even completely ignore
the grid in some cases if drawing a trace, e.g., if we're
at (1010,2020), drawing a trace with y=2025, we should
snap to (1015,2025). This sort of heuristic can mis-fire and
may be difficult to work around, so it should be possible to
turn it off.

- idem for vias, which should be treated just like pads

- there should probably be a way to turn snap to pad off

- the mouse cursor may jump off the screen if the center of the
pad is outside. If the cursor still remains visible, this
isn't particularly bad, but it may be confusing if the cursor
vanishes completely. Snap to pad should probably just revert
to snap to grid in such cases.

- didn't do much testing, so there may be surprises

Anyway, with this change, I can make traces as neatly aligned
as in "pcb", without juggling with grid sizes.

- Werner

--- kicad-dev/pcbnew/controle.cpp.orig	2006-04-10 17:36:01.000000000 -0300
+++ kicad-dev/pcbnew/controle.cpp	2006-04-10 17:52:23.000000000 -0300
@@ -107,6 +107,7 @@ wxSize delta;
int zoom = GetScreen()->GetZoom();
wxPoint curpos, oldpos;
int hotkey = 0;
+D_PAD *pad;

ActiveScreen = GetScreen();

@@ -252,8 +253,13 @@ int CurrentTime = time(NULL);
/* Recalcul de la position du curseur schema */
GetScreen()->m_Curseur = curpos;
-	/* Placement sur la grille generale */
-	PutOnGrid( & GetScreen()->m_Curseur);
+	pad = Locate_Any_Pad(m_Pcb,CURSEUR_OFF_GRILLE);
+	if (pad)
+	GetScreen()->m_Curseur = pad->ReturnShapePos();
+	else {
+	/* Placement sur la grille generale */
+	PutOnGrid( & GetScreen()->m_Curseur);
+	}

if( GetScreen()->IsRefreshReq() )

/ Werner Almesberger, Buenos Aires, Argentina werner@... /

Follow ups