1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
|
#usage "<qt><b>Find elements in schematic/board and zoom in</b>\n"
"<p>"
"Centers the object and zooms into the drawing."
"<p>"
"Usage: RUN find [ <i>name</i> [ count | * ] [ pin | pad | CH new_value]]"
"<p>"
"<h3>You can also run this ULP from the command line:</h3><p>"
"RUN find<br>"
"RUN find name<br>"
"RUN find name counter<br>"
"RUN find name all PIN|PAD|DEV<b> ***</b><br>"
"RUN find value * CH new-value<br>"
"Search string is the <b>name</b> of the Device/Package/Net/Bus/Pin/Signal/Value<p>"
"<b>counter</b> specifies the number of elements that should be found before ending the search, "
"<b>*</b> sets the counter to 1000. PIN | PAD search also for Pin- and Pad-Name<p>"
"<b>CH</b> value; change the value of element if found (CH are case sensitiv)<p>"
"<hr> "
"Searching order:<p>"
"<table>"
"<tr><td><u>Schematic</u>:</td><td><u>Board</u>:</td></tr>"
"<tr><td>1. Part name</td><td>1. Element</td></tr>"
"<tr><td>2. Device name</td><td>1. Element</td></tr>"
"<tr><td>3. Net name</td><td>2. Signal/Wires/Vias</td><tr>"
"<tr><td>4. Bus name</td><td>3. Pads</td></tr>"
"<tr><td>5. Pin/Pad name if option PIN | PAD <b>***</b> is given.</td><td>4. Value</td></tr>"
"<tr><td>6. Value</td><td> Searching for values is not case sensitive.</td></tr>"
"</table>"
"<b>Restriction:</b> Due to the bus name convention it is not possible"
"to search for bus members like address or data nets named, for example, D0, D1, D3."
"The net name does not occur in a bus name like D[0..n], so we can't search for it.<br>"
"<author>Author: support@cadsoft.de</author></qt>"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
string Hilfe = "<qt><h3>Starten Sie dieses ULP auch aus der Kommandozeile mit:</h3><p>" +
"RUN find<br>" +
"RUN find name<br>" +
"RUN find name Zähler<br>" +
"RUN find name * PIN|PAD|DEV<b> ***</b><br>" +
"RUN find alter-value * CH neuer-value<p>" +
"Suchbegriff ist der <b>name</b> des Device/Package/Net/Bus/Pin/Pad/Signal/Value<br>" +
"<b>Zähler</b> ist die Anzahl der gefundenen Elemente, nach der die Suche beendet wird.<br>"
"<b>*</b> setzt den Zähler im Programm auf 1000.<br>" +
"<b>PIN</b> | <b>PAD</b> sucht zusätzlich nach PIN oder PAD Namen.<br>" +
"<b>CH</b> value ersetzt den Value das gefundenen Elements (CH ist Case sensitiv)<p>" +
" <hr> " +
"Find sucht in der Reihenfolge:<p>" +
"<table>" +
"<tr><td><u>Schaltplan</u>:</td><td><u>Board</u>:</td></tr>" +
"<tr><td>1. Part-Name</td><td>1. Element</td></tr>" +
"<tr><td>2. Device-Name</td><td>1. Element</td></tr>" +
"<tr><td>3. Netz-Name</td><td>2. Signal/Wires</td><tr>" +
"<tr><td>4. Bus-Name</td><td>3. Pads</td><tr>" +
"<tr><td>5. Pin/Pad-Name falls PIN | PAD <b>***</b> gesetzt ist.</td><td>4. Value</td></tr>" +
"<tr><td>6. Value </td><td>In Values, wird in der Schreibweise, so wie mit Großschreibung gesucht. </td></tr>" +
"</table>" +
"<b>Einschränkung:</b> Netznamen von Daten- und Adressbussen wie D0, D1, D3..." +
"werden innerhalb des Busses in der Schreibweise D[0..n] abgelegt. " +
"Somit kann das Netz D1 innerhalb eines Busses nicht gefunden werden.</qt>";
// Revision 1.1 2005.06.15 - CH : search an replace Value / Suchen und ersetzen das Value alf@cadsoft.de
// Zuweisung von vfind berichtigt, es konnten nur Values mit Groschreibung gefunden werden.
// durchsuchen von Netz-Namen in Bussen berichtigt.
// Revision 1.2 2005.07.19 - Search also in Polygon - contour - wire
//
// Revision 1.3 2005.11.14 - Search Part_Name
//
string find;
string vfind;
string NewValue;
string ChangeValue;
int change_value = 0;
string again;
string fpin;
string fndpin = "Element";
string foundelement = "";
string fPinPad[] = { "", "PIN", "PAD", "DEV" };
int fcnt = 0;
int all;
int cnt;
int Result;
int mx, my;
real lastZoom = 0;
int lastSheet = 0;
int test = 0;
string fileName = argv[0];
string scriptfile = filesetext(fileName, "$$$.scr");
int gridunit;
string unit[] = { "Micron", "mm", "Mil", "Inch" };
real u2u(int val) {
switch (gridunit) {
case GRID_UNIT_MIC : return u2mic(val);
case GRID_UNIT_MM : return u2mm(val);
case GRID_UNIT_MIL : return u2mil(val);
case GRID_UNIT_INCH : return u2inch(val);
}
}
string dpbacksl(string fs) {
int l = 0;
do {
if (fs[l] == '\\') {
string fs1 = strsub(fs, 0 , l + 1);
string fs2 = strsub(fs, l + 1 );
fs = fs1 + "\\" + fs2;
l += 2;
}
l++;
} while (fs[l]);
return fs;
}
void showrepeat(string text) {
dlgDialog("FIND.ULP") {
dlgHBoxLayout dlgSpacing(600);
dlgHBoxLayout {
dlgVBoxLayout dlgSpacing(300);
dlgTextEdit(text);
}
dlgHBoxLayout {
dlgPushButton("+&OK") dlgAccept();
dlgStretch(1);
}
};
return;
}
string returnfind(void) {
string rs;
if (!fpin) fndpin = "Element";
sprintf(rs, "run ulpmessage.ulp '%d %s(s) %s found!' '%s';\n", fcnt, fndpin, find, foundelement );
return dpbacksl(rs);
}
void check(string repeat) {
repeat += returnfind();
if (test) showrepeat(repeat);
exit (repeat);
}
void helpULP(void) {
if (language() == "de") dlgMessageBox(Hilfe, "OK");
else dlgMessageBox(usage, "OK");
return;
}
string getfind() {
string f;
if (!all) all = 1;
int pin = 0;
Result = dlgDialog("Find Element"){
dlgHBoxLayout {
dlgVBoxLayout {
dlgHBoxLayout {
dlgLabel("&Name ");
dlgStringEdit(f);
dlgStretch(1);
dlgSpacing(10);
dlgPushButton("&Help") helpULP();
}
dlgHBoxLayout {
dlgLabel("&Counts");
dlgIntEdit(all, 0, 2000);
dlgStretch(1);
dlgSpacing(280);
}
dlgHBoxLayout {
dlgGroup("Find PIN | PAD | DEV name in SCH") {
dlgRadioButton("n&o", pin);
dlgRadioButton("P&IN", pin);
dlgRadioButton("P&AD", pin);
dlgRadioButton("&DEV", pin);
}
dlgGroup("Value") {
dlgHBoxLayout {
dlgCheckBox("&change", change_value);
dlgLabel(" to new &Value ");
dlgStringEdit(NewValue);
}
dlgLabel("if value found.");
}
dlgStretch(1);
}
dlgStretch(0);
dlgHBoxLayout {
dlgPushButton("+&Find") {
dlgAccept(1);
fpin = fPinPad[pin];
all--;
if (change_value) ChangeValue = "CH";
}
dlgStretch(1);
dlgPushButton("-Cancel") dlgReject();
}
dlgStretch(1);
}
}
};
if (Result && !f) {
if (ChangeValue = "CH");
else dlgMessageBox("No search string!", "OK");
f = "";
}
return f;
}
string show_B(real x, real y, real zoom1, real zoom2, string findb, int fist) {
fcnt++;
string cmd = "";
if (lastZoom) {
sprintf(cmd, "\n;WINDOW (%.6f %.6f) (%.6f %.6f) (%.6f %.6f);\n"
"SHOW '%s';\n",
x, y,
x, y,
x, y,
findb
);
}
else {
sprintf(cmd, "WINDOW FIT;\n"
"WINDOW (%.6f %.6f) (%.6f %.6f) (%.6f %.6f);\n"
"SHOW '%s';\n",
x, y,
x + zoom1, y,
x + zoom2, y,
findb
);
lastZoom = zoom2;
}
if (ChangeValue == "CH") {
string chval;
sprintf(chval, "VALUE %s '%s';\n", findb, NewValue);
cmd += chval;
}
return cmd;
}
string show_S(int s, real x, real y, real zoom1, real zoom2, string finds) {
fcnt++;
string cmd = "";
if (s != lastSheet) {
lastSheet = s;
sprintf(cmd, "EDIT .s%d;\nWINDOW (%.6f %.6f) (%.6f %.6f) (%.6f %.6f);\nSHOW '%s';\n", s,
x, y,
x + zoom1, y,
x + zoom2, y,
finds
);
}
else {
sprintf(cmd, "WINDOW (%.6f %.6f) (%.6f %.6f) (%.6f %.6f);\nSHOW '%s';\n",
x, y,
x, y,
x, y,
finds
);
}
if (ChangeValue == "CH") {
string chval;
sprintf(chval, "VALUE %s '%s';\n", finds, NewValue);
cmd += chval;
}
return cmd;
}
real zfactor(real x1, real y1, real x2, real y2) {
return sqrt( pow(x2 - x1, 2) + pow(y2 - y1, 2) );
}
// *** split bus-name from net-name ***
int findBus(string name, string sfind) {
string bn[];
int b;
b = strsplit(bn, name, ':');
string nn[];
if (b == 2) {
b = strsplit(nn, bn[1], ',');
}
else {
b = strsplit(nn, name, ',');
}
for (int x = 0; x < b; x++) {
if(nn[x] == sfind) return 1;
}
return 0;
}
// ****** Main ******
find = strupr(argv[1]);
vfind = argv[1];
again = strupr(argv[2]);
if (again == "*") all = 1000;
else all = strtol(again) - 1;
if ( strupr(argv[2]) == "PAD" || strupr(argv[3]) == "PAD") fpin = "PAD";
if ( strupr(argv[2]) == "PIN" || strupr(argv[3]) == "PIN") fpin = "PIN";
if ( strupr(argv[2]) == "DEV" || strupr(argv[3]) == "DEV") fpin = "DEV";
if (argv[3] == "CH") {
ChangeValue = argv[3];
change_value = 1;
NewValue = argv[4];
}
if (!find) {
vfind = getfind();
find = strupr(vfind);
}
if (!find && !change_value) exit (0);
cnt = all + 1;
string repeat = "";
// *** Board coord. ***
if (board) {
board(B) {
gridunit = (B.grid.unit);
mx = B.area.x2 + (B.area.x1 * -1);
my = B.area.y2 + (B.area.y1 * -1);
B.elements(E) {
if (E.name == find) {
repeat += show_B(u2u(E.x), u2u(E.y), 2, 5, find, all);
sprintf(foundelement, "Element %s on (%.3f %.3f)", E.name ,u2u(E.x), u2u(E.y) );
check (repeat);
}
}
B.signals(S) {
if (S.name == find) {
S.contactrefs(C) {
repeat += show_B(u2u(C.contact.x), u2u(C.contact.y), 2, 5, find, all);
if (all <= 0) check(repeat);
all--;
}
}
}
B.signals(S) {
if (S.name == find ) {
S.wires(W) {
real z = zfactor(u2u(W.x1), u2u(W.y1), u2u(W.x2), u2u(W.y2) );
repeat += show_B( u2u((W.x1 + W.x2)/2), u2u((W.y1 + W.y2)/2), z/(z/2) , z/(z/5), find, all);
if (all <= 0) check(repeat);
all--;
}
}
}
B.signals(S) {
if (S.name == find ) {
S.polygons(P) {
P.contours(W) {
real z = zfactor(u2u(W.x1), u2u(W.y1), u2u(W.x2), u2u(W.y2) );
repeat += show_B( u2u((W.x1 + W.x2)/2), u2u((W.y1 + W.y2)/2), z/(z/2) , z/(z/5), find, all);
if (all <= 0) check(repeat);
all--;
;break;
}
}
}
}
B.signals(S) {
if (S.name == find ) {
S.vias(V) {
repeat += show_B(u2u(V.x), u2u(V.y), 1, 5, find, all);
fndpin = "VIA";
sprintf(foundelement, "Element on (%.3f %.3f) %s<br><b>VIA</b><br><table><tr><td>Layer</td><td>Diameter</td><td>Restring</td></tr><tr><td>Top</td><td>%.3f</td><td>%.3f</td></tr><tr><td>Inner</td><td>%.3f</td><td>%.3f</td></tr><tr><td>Bottom</td><td>%.3f</td><td>%.3f</td></tr><tr><td>Drill</td><td>%.3f</td></tr></table>",
u2u(V.x), u2u(V.y),
unit[gridunit],
u2u(V.diameter[1]),
u2u( (V.diameter[1] - V.drill) / 2),
u2u(V.diameter[2]),
u2u( (V.diameter[2] - V.drill) / 2),
u2u(V.diameter[16]),
u2u( (V.diameter[16] - V.drill) / 2),
u2u(V.drill)
);
if (all <= 0) check(repeat);
all--;
}
}
}
B.elements(E) {
if (E.value == vfind || E.value == find) {
repeat += show_B(u2u(E.x), u2u(E.y), 2, 5, E.name, all);
sprintf(foundelement, "Element %s on (%.3f %.3f)", E.name ,u2u(E.x), u2u(E.y) );
if (all <= 0) check(repeat);
all--;
}
}
B.elements(E) {
if (fpin == "PAD") {
E.package.contacts(C) {
if (C.pad) {
if (C.pad.name == find) {
fndpin = "PAD";
repeat += show_B(u2u(C.pad.x), u2u(C.pad.y), 2, 5, E.name, all);
sprintf(foundelement, "<br>PAD <b>%s</b> on (%.3f %.3f) %s [Element %s]<br><table><tr><td>Layer</td><td>Diameter</td><td>Restring</td></tr><tr><td>Top</td><td>%.3f</td><td>%.3f</td></tr><tr><td>Inner</td><td>%.3f</td><td>%.3f</td></tr><tr><td>Bottom</td><td>%.3f</td><td>%.3f</td></tr><tr><td>Drill</td><td>%.3f</td></tr></table>",
C.pad.name,
u2u(C.pad.x), u2u(C.pad.y),
unit[gridunit],
E.name,
u2u(C.pad.diameter[1]),
u2u( (C.pad.diameter[1] - C.pad.drill) / 2),
u2u(C.pad.diameter[2]),
u2u( (C.pad.diameter[2] - C.pad.drill) / 2),
u2u(C.pad.diameter[16]),
u2u( (C.pad.diameter[16] - C.pad.drill) / 2),
u2u(C.pad.drill)
);
if (all <= 0) check(repeat);
all--;
}
}
if (C.smd) {
if (C.smd.name == find) {
fndpin = "SMD";
repeat += show_B(u2u(C.smd.x), u2u(C.smd.y), 2, 5, E.name, all);
sprintf(foundelement, "<br>SMD <b>%s</b> on (%.3f %.3f) %s [Element %s]",
C.smd.name,
u2u(C.smd.x), u2u(C.smd.y),
unit[gridunit],
E.name
);
if (all <= 0) check(repeat);
all--;
}
}
}
}
}
}
if (repeat) check (repeat);
dlgMessageBox("<b>" + dpbacksl(find) + "</b> not found!", "OK");
exit (0);
}
// *** Schematic coord. ***
if (schematic) {
lastSheet = 0;
schematic(S) {
gridunit = (S.grid.unit);
S.sheets(SH) {
mx = SH.area.x2 + (SH.area.x1 * -1);
my = SH.area.y2 + (SH.area.y1 * -1);
if (fpin == "PIN" || fpin == "DEV") {
SH.parts(PA) {
if (fpin == "DEV") {
if (PA.device.name == find) { // 2005.11.14 alf@cadsoft.de
PA.instances(IN) {
IN.gate.symbol.pins(P) { // Pin
fndpin = "Dev";
real sym = zfactor( u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1), u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2) );
real z = zfactor( u2u(mx), u2u(my), 1.0, 1.0 );
sprintf(foundelement, "DEVices %s in sheet %d on (%.3f %.3f)", IN.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
repeat += show_S(IN.sheet, u2u(IN.x), u2u(IN.y), sym , z, PA.name);
if (all <= 0) check(repeat);
all--;
}
}
}
}
else {
PA.instances(IN) {
IN.gate.symbol.pins(P) { // Pin
if (P.name == find) {
fndpin = "Pin";
real sym = zfactor( u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1), u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2) );
real z = zfactor( u2u(mx), u2u(my), 1.0, 1.0 );
sprintf(foundelement, "PIN %s in sheet %d on (%.3f %.3f)", P.name , IN.sheet, u2u(P.x), u2u(P.y) );
repeat += show_S(IN.sheet, u2u(P.x), u2u(P.y), sym , z, PA.name);
if (all <= 0) check(repeat);
all--;
}
}
}
}
}
}
if (fpin == "PAD") {
SH.parts(PA) {
PA.instances(IN) {
IN.gate.symbol.pins(P) {
if (P.contact) {
if (P.contact.name == find) {
fndpin = "Pad";
real sym = zfactor( u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1), u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2) );
real z = zfactor( u2u(mx), u2u(my), 1.0, 1.0 );
sprintf(foundelement, "PAD %s (PIN %s) in sheet %d on (%.3f %.3f)", PA.name, P.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
repeat += show_S(IN.sheet, u2u(P.x), u2u(P.y), sym, z, PA.name);
if (all <= 0) check(repeat);
all--;
}
}
}
}
}
}
SH.parts(PA) {
if (PA.name == find) {
PA.instances(IN) { // Gate
if (IN.sheet) {
real sym = zfactor( u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1), u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2) );
real z = zfactor( u2u(mx), u2u(my), 1.0, 1.0 );
sprintf(foundelement, "Device %s in sheet %d on (%.3f %.3f)", PA.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
repeat += show_S(IN.sheet, u2u(IN.x), u2u(IN.y), sym , z, PA.name);
if (all <= 0) check(repeat);
all--;
}
}
}
}
SH.nets(N) {
if (N.name == find) {
N.segments(SEG) {
SEG.wires(W) {
fndpin = "NET";
real z = zfactor(u2u(W.x1), u2u(W.y1), u2u(W.x2), u2u(W.y2) );
repeat += show_S(SH.number, u2u((W.x1 + W.x2) /2), u2u((W.y1 + W.y2) / 2), z, u2u(mx), find);
if (all <= 0) check(repeat);
all--;
}
}
}
}
SH.busses(B) {
if (findBus(B.name, find)) {
B.segments(SEG) {
SEG.wires(W) {
fndpin = "BUS";
real z = zfactor(u2u(W.x1), u2u(W.y1), u2u(W.x2), u2u(W.y2) );
repeat += show_S(SH.number, u2u((W.x1 + W.x2) /2), u2u((W.y1 + W.y2) / 2), z, u2u(mx), B.name);
if (all <= 0) check(repeat);
all--;
}
}
}
}
SH.parts(PA) {
PA.instances(IN) { // Gate
if (PA.value == vfind) { // *** || PA.value == find) {
real sym = zfactor( u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1), u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2) );
real z = zfactor( u2u(mx), u2u(my), 1.0, 1.0 );
sprintf(foundelement, "Device %s in sheet %d on (%.3f %.3f)", PA.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
repeat += show_S(IN.sheet, u2u(IN.x), u2u(IN.y), sym, z, PA.name);
if (all <= 0) check(repeat);
all--;
}
}
}
}
}
check(repeat);
}
else {
dlgMessageBox("Start this ULP from schematic or board!", "OK");
exit (0);
}
|