[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: Snap-to-pins, was: Stupid newbie question
Hi,
[snip]
>1. Can anybody can help me figure out how to iterate across the available pins
>to find one to snap to.
There are two ways. The easy way or the hard way (or stated another
way: the wrong way or the right way respectively :-). The easy way
is as follows:
...
{
OBJECT *o_current;
/* Start at the beginning of the object list */
/* skip over the head node */
o_current = w_current->page_current->object_head->next;
while (o_current != NULL)
{
switch(o_current->type)
{
case (OBJ_NET):
...
break;
case (OBJ_PIN):
/* coordinate structures for pins and nets are the same */
/* first coordinate point */
o_current->line->x[0] = ...
o_current->line->y[0] = ...
/* second coordinate point */
o_current->line->x[1] = ...
o_current->line->y[2] = ...
/* also relavent to pins only is whichend */
/* which end tells you which point of ...->line->x[ ] is the */
/* active connecting point */
if (o_current->whichend == 0)
...
if (o_current->whichend == 1)
...
break;
}
o_current = o_current->next;
}
...
You will need access to a w_current pointer (TOPLEVEL *), but those are
very easy to come by as almost function has a valid one.
The above code is the easy/wrong way because it iterates over all objects
and this does not scale for large schematics. The hard way uses the
internal tiling mechanism which does scale, but is a little more
complicated. For now get the snap to endpoint working with the easy way
and I'll worry about the hard way when I integrate the patch.
>
>2. Should I add a utility function like snap_grid() so other developers could
>do pin-snaps in the future? Not sure why you would, but it could be done that
>way. Or should I just add it to o_net and keep it simple?
Keep it simple. :) Actually if you look at gschem/noweb/o_net.nw in the
function o_net_start() you will see code like this at the beginning:
#if 0 /* not ready for prime time use, this is the snap any point #if 0 */
...
#endif
this was my attempt at doing exactly what you want to add. Ignore it, it
did not work and was a work in progress.
I would recommend you get the snapping to work as best you can and then
we'll work from there.
>
>Maybe we should take this discussion off list?
Maybe onto the geda-dev mailing list.
Please ask questions and I'll answer them to my best ability.
-Ales