#include "defs.h" /* * Attach free end-points to the closest line endings. * * h = pointer to the 'w' entry */ gluepin(h) DL h; { REG DL p, q, pe; INT d; chkhd(h, "w"); p=h; while(p=nexta(h->type,p)) if((p->type == 'p') && (q = findpt(h, p)) && (q->flag&(START|END)) && (another(h, 'e', q)!=nil(DL))) { d = xydist(p, q); pe=h; while(pe=nexta(h->type,pe)) { if((pe->type == 'p') && (pe != q) && (xydist(pe, q) < d)) break; } if(pe==nil(DL)) { copypt(q, p); d = getdir(h, findpt(h, p)); p->flag &= ~DIR; p->flag |= d; } } } /* * to label and/or number end-points * * head = 'w' header addr if known, else zero */ DL setpin(head) DL head; { REG DL p, h; DL1 p1; ITEM cv; STRING tp; chkhd(head, "Mwc"); rdname(cv, sizeof(cv)); tp = commasep(cv); if (*cv == 0 && tp == 0) error("no pin name"); if(*cv && number(cv)==0) error("not a number"); while(cursor(p1)==SP){ if( (h = findhead('w', p1)) && (p = findpt(h, p1))) { endpoint(h, p, tp, cv); } else error("wire end not found"); } return(h); } /* * Create a new end-point or modify the existing end-point data. * * h = 'w' entry * p = position (may be existing 'p') * csig = signal name string (null string if keep the same) * cpin = pin number string (null if same) */ LOC endpoint(h, p, csig, cpin) REG DL h; DL p; STRING csig, cpin; { REG DL q; REG INT flg; DL s; chkhd(h, "w"); if(q = findxact('p', h, p)){ if(*cpin == 0) cpin = q->tag; if (csig == 0) csig = q->tag + upbstr(q->tag) + 1; flg = q->flag&DIR; s = q; } else{ s = findpt(h, p); flg = getdir(h, s); if (csig == 0) csig = ""; } if(lastnum) flg=lastnum; showp(h, newdl(BEFORE, succ('w', h), 'p', flg, p, s->styl, cpin, csig)); if(q) delete(q); } /* * Compute the direction of the end of the line closest to a given position. * * h = item header * p = wire 'e' entry * return = direction (0-3) of point closest to z; error if that point * is not an endpoint */ LOC INT getdir(h, p) DL h, p; { REG DL q; if(p->flag&START) { q = succ('e', p); } elif(p->flag&END) { REG DL r=h; q = nil(DL); while(r=nexta('w', r)) { if(p==r) break; q=r; } } else{ error("not an end point"); } if(p->y == q->y) return((p->x > q->x) ? 0 : 2); else return((p->y > q->y) ? 1 : 3); }