static int ReportNetLengthByName (char *tofind, int x, int y) { int result; char *netname = 0; Coord length = 0; int found = 0; int i; LibraryMenuType *net; ConnectionType conn; int net_found = 0; #if defined(USE_RE) int use_re = 0; #endif #if defined(HAVE_REGCOMP) regex_t elt_pattern; regmatch_t match; #endif #if defined(HAVE_RE_COMP) char *elt_pattern; #endif if (!PCB) return 1; if (!tofind) return 1; #if defined(USE_RE) use_re = 1; for (i = 0; i < PCB->NetlistLib.MenuN; i++) { net = PCB->NetlistLib.Menu + i; if (strcasecmp (tofind, net->Name + 2) == 0) use_re = 0; } if (use_re) { #if defined(HAVE_REGCOMP) result = regcomp (&elt_pattern, tofind, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (result) { char errorstring[128]; regerror (result, &elt_pattern, errorstring, 128); Message (_("regexp error: %s\n"), errorstring); regfree (&elt_pattern); return (1); } #endif #if defined(HAVE_RE_COMP) if ((elt_pattern = re_comp (tofind)) != NULL) { Message (_("re_comp error: %s\n"), elt_pattern); return (1); } #endif } #endif for (i = 0; i < PCB->NetlistLib.MenuN; i++) { net = PCB->NetlistLib.Menu + i; #if defined(USE_RE) if (use_re) { #if defined(HAVE_REGCOMP) if (regexec (&elt_pattern, net->Name + 2, 1, &match, 0) != 0) continue; #endif #if defined(HAVE_RE_COMP) if (re_exec (net->Name + 2) != 1) continue; #endif } else #endif if (strcasecmp (net->Name + 2, tofind)) continue; if (SeekPad (net->Entry, &conn, false)) { switch (conn.type) { case PIN_TYPE: x = ((PinType *) (conn.ptr2))->X; y = ((PinType *) (conn.ptr2))->Y; net_found=1; break; case PAD_TYPE: x = ((PadType *) (conn.ptr2))->Point1.X; y = ((PadType *) (conn.ptr2))->Point1.Y; net_found=1; break; } if (net_found) break; } } if (!net_found) { gui->log (_("No net named %s\n"), tofind); return 1; } #ifdef HAVE_REGCOMP if (use_re) regfree (&elt_pattern); #endif /* Reset all connection flags and save an undo-state to get back * to the state the board was in when we started. * * After this, we don't add any changes to the undo system, but * ensure we get back to a point where we can Undo() our changes * by resetting the connections with ClearFlagOnAllObjects() before * calling Undo() when we are finished. */ ClearFlagOnAllObjects (true, FOUNDFLAG); IncrementUndoSerialNumber (); length = XYtoNetLength (x, y, &found); netname = net->Name + 2; ClearFlagOnAllObjects (false, FOUNDFLAG); Undo (true); if (!found) { if (net_found) gui->log (_("Net found, but no lines or arcs were flagged.\n")); else gui->log (_("Net not found.\n")); return 1; } { char buf[50]; pcb_snprintf(buf, 50, _("%$m*"), Settings.grid_unit->suffix, length); if (netname) gui->log (_("Net \"%s\" length: %s\n"), netname, buf); else gui->log (_("Net length: %s\n"), buf); } return 0; }
static int ReportNetLength (int argc, char **argv, Coord x, Coord y) { Coord length = 0; char *netname = 0; int found = 0; gui->get_coords (_("Click on a connection"), &x, &y); /* Reset all connection flags and save an undo-state to get back * to the state the board was in when we started this function. * * After this, we don't add any changes to the undo system, but * ensure we get back to a point where we can Undo() our changes * by resetting the connections with ClearFlagOnAllObjects() before * calling Undo() at the end of the procedure. */ ClearFlagOnAllObjects (true, FOUNDFLAG); IncrementUndoSerialNumber (); length = XYtoNetLength (x, y, &found); if (!found) { ClearFlagOnAllObjects (false, FOUNDFLAG); Undo (true); gui->log (_("No net under cursor.\n")); return 1; } ELEMENT_LOOP (PCB->Data); { PIN_LOOP (element); { if (TEST_FLAG (FOUNDFLAG, pin)) { int ni, nei; char *ename = element->Name[NAMEONPCB_INDEX].TextString; char *pname = pin->Number; char *n; if (ename && pname) { n = Concat (ename, _("-"), pname, NULL); for (ni = 0; ni < PCB->NetlistLib.MenuN; ni++) for (nei = 0; nei < PCB->NetlistLib.Menu[ni].EntryN; nei++) { if (strcmp (PCB->NetlistLib.Menu[ni].Entry[nei].ListEntry, n) == 0) { netname = PCB->NetlistLib.Menu[ni].Name + 2; goto got_net_name; /* four for loops deep */ } } } } } END_LOOP; PAD_LOOP (element); { if (TEST_FLAG (FOUNDFLAG, pad)) { int ni, nei; char *ename = element->Name[NAMEONPCB_INDEX].TextString; char *pname = pad->Number; char *n; if (ename && pname) { n = Concat (ename, _("-"), pname, NULL); for (ni = 0; ni < PCB->NetlistLib.MenuN; ni++) for (nei = 0; nei < PCB->NetlistLib.Menu[ni].EntryN; nei++) { if (strcmp (PCB->NetlistLib.Menu[ni].Entry[nei].ListEntry, n) == 0) { netname = PCB->NetlistLib.Menu[ni].Name + 2; goto got_net_name; /* four for loops deep */ } } } } } END_LOOP; } END_LOOP; got_net_name: ClearFlagOnAllObjects (false, FOUNDFLAG); Undo (true); { char buf[50]; pcb_snprintf(buf, sizeof (buf), _("%$m*"), Settings.grid_unit->suffix, length); if (netname) gui->log (_("Net \"%s\" length: %s\n"), netname, buf); else gui->log (_("Net length: %s\n"), buf); } return 0; }
static int ReportNetLength (int argc, char **argv, int x, int y) { double length = 0; char *netname = 0; int found = 0; if (ResetConnections (true)) Draw (); /* NB: XYtoNetLength calls LookupConnection, which performs an undo * serial number update, so we don't need to add one here. */ gui->get_coords ("Click on a connection", &x, &y); length = XYtoNetLength (x, y, &found); if (!found) { gui->log ("No net under cursor.\n"); return 1; } ELEMENT_LOOP (PCB->Data); { PIN_LOOP (element); { if (TEST_FLAG (FOUNDFLAG, pin)) { int ni, nei; char *ename = element->Name[NAMEONPCB_INDEX].TextString; char *pname = pin->Number; char *n; if (ename && pname) { n = Concat (ename, "-", pname, NULL); for (ni = 0; ni < PCB->NetlistLib.MenuN; ni++) for (nei = 0; nei < PCB->NetlistLib.Menu[ni].EntryN; nei++) { if (strcmp (PCB->NetlistLib.Menu[ni].Entry[nei].ListEntry, n) == 0) { netname = PCB->NetlistLib.Menu[ni].Name + 2; goto got_net_name; /* four for loops deep */ } } } } } END_LOOP; PAD_LOOP (element); { if (TEST_FLAG (FOUNDFLAG, pad)) { int ni, nei; char *ename = element->Name[NAMEONPCB_INDEX].TextString; char *pname = pad->Number; char *n; if (ename && pname) { n = Concat (ename, "-", pname, NULL); for (ni = 0; ni < PCB->NetlistLib.MenuN; ni++) for (nei = 0; nei < PCB->NetlistLib.Menu[ni].EntryN; nei++) { if (strcmp (PCB->NetlistLib.Menu[ni].Entry[nei].ListEntry, n) == 0) { netname = PCB->NetlistLib.Menu[ni].Name + 2; goto got_net_name; /* four for loops deep */ } } } } } END_LOOP; } END_LOOP; got_net_name: HideCrosshair (false); { int prec = Settings.grid_units_mm? 4: 2; if (netname) gui->log ("Net \"%s\" length: %.*f %s\n", netname, prec, UNIT (length)); else gui->log ("Net length: %.*f %s\n", prec, UNIT (length)); } RestoreCrosshair (false); return 0; }
static int ReportAllNetLengths (int argc, char **argv, Coord x, Coord y) { int ni; int found; /* Reset all connection flags and save an undo-state to get back * to the state the board was in when we started this function. * * After this, we don't add any changes to the undo system, but * ensure we get back to a point where we can Undo() our changes * by resetting the connections with ClearFlagOnAllObjects() before * calling Undo() at the end of the procedure. */ ClearFlagOnAllObjects (true, FOUNDFLAG); IncrementUndoSerialNumber (); for (ni = 0; ni < PCB->NetlistLib.MenuN; ni++) { char *netname = PCB->NetlistLib.Menu[ni].Name + 2; char *ename = PCB->NetlistLib.Menu[ni].Entry[0].ListEntry; char *pname; bool got_one = 0; ename = strdup (ename); pname = strchr (ename, '-'); if (! pname) { free (ename); continue; } *pname++ = 0; ELEMENT_LOOP (PCB->Data); { char *es = element->Name[NAMEONPCB_INDEX].TextString; if (es && strcmp (es, ename) == 0) { PIN_LOOP (element); { if (strcmp (pin->Number, pname) == 0) { x = pin->X; y = pin->Y; got_one = 1; break; } } END_LOOP; PAD_LOOP (element); { if (strcmp (pad->Number, pname) == 0) { x = (pad->Point1.X + pad->Point2.X) / 2; y = (pad->Point1.Y + pad->Point2.Y) / 2; got_one = 1; break; } } END_LOOP; } } END_LOOP; if (got_one) { char buf[50]; const char *units_name = argv[0]; Coord length; if (argc < 1) units_name = Settings.grid_unit->suffix; length = XYtoNetLength (x, y, &found); /* Reset connectors for the next lookup */ ClearFlagOnAllObjects (false, FOUNDFLAG); pcb_snprintf(buf, sizeof (buf), _("%$m*"), units_name, length); gui->log(_("Net %s length %s\n"), netname, buf); } } ClearFlagOnAllObjects (false, FOUNDFLAG); Undo (true); return 0; }
static int ReportAllNetLengths (int argc, char **argv, int x, int y) { int ni; int found; double length; int prec; double scale; const char *units_name; units_name = argv[0]; if (argc < 1) units_name = Settings.grid_units_mm ? "mm" : "mil"; if (strcasecmp (units_name, "mm") == 0) { prec = 4; scale = COOR_TO_MM; } else if (strcasecmp (units_name, "mil") == 0) { prec = 2; scale = .01; } else if (strcasecmp (units_name, "in") == 0) { prec = 5; scale = 1./100000; } else { prec = 0; units_name = "pcb"; scale = 1; } for (ni = 0; ni < PCB->NetlistLib.MenuN; ni++) { char *netname = PCB->NetlistLib.Menu[ni].Name + 2; char *ename = PCB->NetlistLib.Menu[ni].Entry[0].ListEntry; char *pname; ename = strdup (ename); pname = strchr (ename, '-'); if (! pname) { free (ename); continue; } *pname++ = 0; ELEMENT_LOOP (PCB->Data); { char *es = element->Name[NAMEONPCB_INDEX].TextString; if (es && strcmp (es, ename) == 0) { PIN_LOOP (element); { if (strcmp (pin->Number, pname) == 0) { x = pin->X; y = pin->Y; goto got_one; } } END_LOOP; PAD_LOOP (element); { if (strcmp (pad->Number, pname) == 0) { x = (pad->Point1.X + pad->Point2.X) / 2; y = (pad->Point1.Y + pad->Point2.Y) / 2; goto got_one; } } END_LOOP; } } END_LOOP; continue; got_one: if (ResetConnections (true)) Draw (); /* NB: XYtoNetLength calls LookupConnection, which performs an undo * serial number update, so we don't need to add one here. */ length = XYtoNetLength (x, y, &found); gui->log("Net %s length %.*f %s\n", netname, prec, length*scale, units_name); } return 0; }