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 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
|
#usage "<b>Export milling data for a board layout</b>\n"
"<br>"
"<author>Author: support@cadsoft.de</author>"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
// 08.05.2002 alf@cadsoft.de - reverse milling
// 23.06.2002 alf@cadsoft.de - Polygon:CHANGE THERMAL OFF
// 14.05.2003 alf@cadsoft.de - With REFERENCE-Drill to mirror for drilling machine
// - Switch On/Off 2. isolate/cupper pouring
// 02.09.2003 - Switch On/Off drills
// 24.04.2004 alf@cadsoft.de - String ulp_path no longer necessary
string Version = "Outlines generator for PCB milling. ULP-Version 4.1.03";
/*
Complete the following steps to add a new output device definition:
1. Add a new member to the 'enum { devScript = 1, ...'
2. Add the new (unique!) device name to 'DeviceNames[]'
3. Add the necessary 'case dev...' branches to
'DeviceInit()',
'DeviceReInit()',
'DeviceDraw()',
'CircleDraw()',
'ArcDraw()'
and 'DeviceEnd()'
4. Add also new Tool values to
'toolFiles()'
and 'ValueInit()'
*/
string DRCinfo = "<qt><b>Distance info:</b><br>Distance Copper/Dimension (see <b>DRC</b>) this is the distance between <br>"
"the polygon and outline of the board. If the value for 'Copper/Dimension' <br>"
"in the DRC settings is set higher than the radius of the mill tool#2, the <br>"
"board dimensions will be milled larger by the difference of these two <br>"
"respective values. For the best result, make sure the value for <br>"
"<b>Copper/Dimension</b> in <b>DRC Distance</b> is set on <b>0.01 mm</b>, or use the <br>"
"same value in the Design Rule's settings as the radius of the milling tool#2 <br>"
"is, before running this ULP!<p>"
"Press button <b>Reference</b> to generate a reference Package to place<br>"
"refernece holes on PCB for exact mirroring the bottom side of PCB on milling machine.<br>"
"</qt>";
string infoREFERENCE = "<nobr>Generate a special package with<br>" +
"REFERENCE circles in Layer Holes.<br>" +
"Place it in the layout for milling and <br>" +
"mirroring (bottom side) with offset and <br>" +
"start this ULP again.<br>";
"The position of the circles are defined<br>" +
"in the NC drill data file which comes<br>" +
"from the NC machine (eg. Excellon).</nobr><p>";
//
// The various output devices
//
int defaultdevice = 2; // set default device
int SelectedDevice = 0;
string Device;
enum { devScript = 1, devHPGL };
string DeviceNames[] = { "Select a device", "SCRIPT", "HPGL" };
string DeviceExt[] = { ".$$$" , ".scr", ".plt" };
string DrillExt[] = { ".$$$" , "_drl.scr" , "" };
string DefaultSuffix = DeviceExt[0];
string DrlDefaultSuffix = DrillExt[0];
string DrillLabel = "D&rill file";
string DrBrowse = "Bro&wse";
//
// Parmameters
//
// *** The milling tool diameter ***
real MillToolOutl = 0.2;
real MillToolIsolate = 0.0; //
int OverlapOutlPercent = 20; // percent, to avoid fine copper lines while milling out the area
real MillToolFree = 0.8; // Blow up & free pouring
int millfreeyes = 1; // free pouring on/off
int OverlapRubOut = 20; // percent, to avoid fine copper lines while milling out the area
real DrillPad = 0.8;
real DrillVia = 0.8;
real DrillHole = 0.8;
int onlydrill = 0; // output only drill on HPGL
int generatedrills = 1; // aktivate drills only in one export file
// while drills crashed in 2. run.
real DimensionMillTool = 2.0; // milling board outline from holder
real Distance_Copper_Dimension = 1.016; // default value
real Holder_Spacing = 10.0; // in mm, the distance to make a holder spacing for outline miling.
// The HPGL PEN list
enum { PadDrill = 1, ViaDrill, Contour, BlowUp_RubOut, HoleDrill, DimensionLine } // HPGL Pen select "SP.."
string PenList[];
PenList[PadDrill] = "PadDrill";
PenList[ViaDrill] = "ViaDrill";
PenList[Contour] = "Contour";
PenList[BlowUp_RubOut] = "Blow-Up/Rub-Out";
//PenList[RubOut] = "Rub-Out";
PenList[HoleDrill] = "HoleDrill";
PenList[DimensionLine] = "DimensionLine";
string sToolValue[]; // Tool diameter as String
enum { HPGLsolution = 1016 } // Inch/1016 = 0.025 mm
real Mirror = 1.0;
string ref_pac = "_REFERENCE_HOLE_"; // special package for mirror milling data
int mirr_offsetx = 0;
int ref_null_offsetX = 0;
int ref_null_offsetY = 0;
int ref_offsetX[];
int ref_offsetY[];
int ref_cnto = 0;
int Layer = 0;
string fillstyle = "Interleave"; // 9 Interleave
string lOutl;
string trueOutline_coordinate; // the generatet polygon outlines for the milling polygon
string OutlinesSignalName = "_OUTLINES_"; // reserved Signal name for special polygon
string OutlineMillSignal = "$_OUTLINEMILL_$";
string PassDimensionPoly = "PASSDIMESION"; // the true output line defined by Layer 20 Dimension
string Pass2 = "PASS_2";
string PassPour = "PASS_POUR";
string PassOutmill = "PASS_OUTLINE";
string InPassDimensionPoly;
string InPass2;
string InPassPour;
string InPassOutmill;
int menu = 0;
string showpic[];
string info;
string infotext;
string path;
string File, FileName;
string DrFile, DrillFile;
int test = 0;
// *** Functions ***
void viewtest(string txt) {
dlgDialog("test") {
dlgHBoxLayout {
dlgTextEdit(txt);
dlgVBoxLayout dlgSpacing(150);
}
dlgHBoxLayout {
dlgPushButton("OK") dlgAccept();
dlgPushButton("Cancel") { dlgReject(); exit(0); }
dlgSpacing(400);
}
};
return;
}
void Warning(string Message, string Details) {
dlgMessageBox("<b>Warning: " + Message + "</b> " + Details, "OK");
return;
}
void Fatal(string Message, string Details) {
dlgMessageBox("<b>ERROR: " + Message + "</b><hr><p>\n" + Details);
exit(1);
}
void Error(string Message, string Details) {
dlgMessageBox("<b>ERROR: " + Message + "</b><p>\n" + Details);
}
if (!board) Fatal("No board!", "This program can only work in the board editor.");
void dirtest(void) {
string a[];
int n = fileglob(a, "*.*");
if (n) {
dlgMessageBox("Working directory:\n" + filedir(a[0]), "OK");
}
return;
}
string vunit(int val, int unit) {
string s;
if (unit) sprintf(s, "%.4f", u2mm(val));
else sprintf(s, "%.6f",u2inch(val));
return s;
}
string getval(string line, real exf, real refholediameter) {
int Y = strchr(line, 'Y');
string s;
sprintf(s, "(%.4f %.4f) (%.4f %.4f);\n",
strtol(strsub(line, 1)) * exf,
strtol(strsub(line, Y+1)) * exf,
strtol(strsub(line, 1)) * exf + refholediameter/2 * exf,
strtol(strsub(line,Y+1)) * exf );
return s;
}
void setZerroReference(void) {
int refunit = 0;
int format = 0;
string ReferenceUnit[] = { "INCH", "MM", "INCH", "MM" };
real exf[] = { 0.001, 0.0001, 0.001, 0.0001 };
// Drillformat 2.3 2.4 2.3 2.4
// Unit Inch Inch MM MM
real refhdiameter[] = { 118, 1180, 3000, 30000 };
int Result = dlgDialog(filename(argv[0]) + " - generate refernece and place on Board") {
dlgLabel(showpic[17]);
dlgLabel(infoREFERENCE);
dlgHBoxLayout {
dlgGroup("Unit") {
dlgHBoxLayout {
dlgRadioButton("INCH", refunit);
dlgRadioButton("MM", refunit);
dlgStretch(1);
}
}
dlgStretch(1);
}
dlgGroup("Format") {
dlgHBoxLayout {
dlgRadioButton("2.3", format);
dlgRadioButton("2.4", format);
dlgStretch(1);
}
}
dlgHBoxLayout {
dlgPushButton("+OK") dlgAccept();
dlgStretch(1);
dlgPushButton("-Cancel") dlgReject();
}
};
if (Result) {
board(B) {
string usedlibraries = "USE -*;\n";
int u = 0;
do {
if (used_libraries[u]) {
usedlibraries += "USE '" + used_libraries[u] + "';\n";
u++;
}
} while(used_libraries[u]);
string used_scr = filedir(B.name) + "used-lbrs-" + filesetext(filename(B.name), ".scr");
output(used_scr, "wt") {
printf("%s", usedlibraries);
}
dlgMessageBox("<nobr>After reference package placing start the<br>" +
used_scr +
"<br>to set the used libraries back.", "OK");
string cmd;
string ref[];
string reference_file = dlgFileOpen("Select drill reference file (Holes)", "", "*.ncd\n*.*");
if (!reference_file) return;
int unit_format = refunit * 2 + format;
int l;
l = fileread(ref, reference_file);
string lbrname;
lbrname = filesetext(B.name, "$$$ref_tmp.lbr");
sprintf( cmd, "OPEN '%s';\n", lbrname );
cmd += "Edit '" + ref_pac + ".PAC';\nCHANGE LAYER 45;\nGRID " + ReferenceUnit[refunit] + ";\n";
for (int n = 0; n <= l; n++) {
string s = ref[n];
if(s[0] == 'X') cmd += "CIRCLE 0 " + getval(ref[n], exf[unit_format], refhdiameter[unit_format]);
}
cmd += "WRITE;\n";
cmd += "EDIT '" + B.name + "';\n";
cmd += "DISPLAY 45;\n";
cmd += "GRID " + ReferenceUnit[refunit] + ";\n";
cmd += "WIN FIT; WIN (" +
vunit((B.area.x1 + B.area.x2 )/2, refunit) + " " +
vunit((B.area.y1 + B.area.y2 )/2, refunit) + ") (" +
vunit((B.area.x1 + B.area.x2 )/2 + 1000, refunit) + " " +
vunit((B.area.y1 + B.area.y2 )/2 + 1000, refunit) + ") (" +
vunit((B.area.x1 + B.area.x2 )/2 + 150 , refunit) + " " +
vunit((B.area.y1 + B.area.y2 )/2 + 150 , refunit) + ");\n",
cmd += "USE -*; USE '" + lbrname + "';\n";
cmd += "ADD " + ref_pac + "\n";
if (test) viewtest(cmd);
exit(cmd);
}
}
return;
}
// *** Tools in EXCELLON and GERBER (mm)
void toolFiles(void) {
board(B) {
output(filesetext(B.name, ".rac")) {
printf("T01 %.1f mm\n", DrillPad);
printf("T02 %.1f mm\n", DrillVia);
printf("T03 %.1f mm\n", MillToolOutl);
printf("T04 %.1f mm\n", MillToolFree);
printf("T05 %.1f mm\n", DrillHole);
printf("T06 %.1f mm\n", DimensionMillTool);
}
output(filesetext(B.name, ".whl")) {
printf(";aperture wheel file generated by %s %s\n", EAGLE_SIGNATURE, filename(argv[0]) );
printf(";remove the above line to prevent this file from being overwritten!\n");
printf("D11 round %6.4fmm\n", DrillPad);
printf("D12 round %6.4fmm\n", DrillVia);
printf("D13 round %6.4fmm\n", MillToolOutl);
printf("D14 round %6.4fmm\n", MillToolFree);
printf("D15 round %6.4fmm\n", DrillHole);
printf("D16 round %6.4fmm\n", DimensionMillTool);
}
}
return;
}
void showRackFile(void) {
board(B) {
string text;
int nChars = fileread(text, filesetext(B.name, ".rac"));
dlgDialog("Show rack file") {
dlgTextView(text);
dlgHBoxLayout {
dlgPushButton("+&OK") dlgAccept();
dlgStretch(1);
}
};
}
return;
}
void showHPGLinfo(void) {
string text;
int nChars = fileread(text, filesetext(FileName, ".pli"));
dlgDialog("Show plot info") {
dlgTextView(text);
dlgHBoxLayout {
dlgPushButton("+&OK") dlgAccept();
dlgStretch(1);
dlgSpacing(200);
}
};
return;
}
void ValueInit(void) {
sprintf( sToolValue[PadDrill], "%.2f", DrillPad);
sprintf( sToolValue[ViaDrill], "%.2f", DrillVia);
sprintf( sToolValue[Contour], "%.2f", MillToolOutl);
sprintf( sToolValue[BlowUp_RubOut], "%.2f", MillToolFree);
// sprintf( sToolValue[RubOut], "%.2f", MillToolFree);
sprintf( sToolValue[HoleDrill], "%.2f", DrillHole);
sprintf( sToolValue[DimensionLine], "%.2f", DimensionMillTool);
return;
}
void startlineprint( int x1, int y1, int x2, int y2) {
printf("\nPA%.0f,%.0f;PD;\nPA%.0f,%.0f;", Mirror * u2inch(x1 + mirr_offsetx)*HPGLsolution, u2inch(y1 + ref_null_offsetY)*HPGLsolution, Mirror * u2inch(x2 + mirr_offsetx)*HPGLsolution, u2inch(y2 + ref_null_offsetY)*HPGLsolution);
return;
}
void nextlineprint( int x2, int y2) {
printf("\nPA%.0f,%.0f;", Mirror * u2inch(x2 + mirr_offsetx)*HPGLsolution, u2inch(y2 + ref_null_offsetY)*HPGLsolution );
return;
}
void endlineprint( int x2, int y2) {
printf("\nPA%.0f,%.0f;PU;", Mirror * u2inch(x2 + mirr_offsetx)*HPGLsolution, u2inch(y2 + ref_null_offsetY)*HPGLsolution);
return;
}
void fullineprint( int x1, int y1, int x2, int y2) {
printf("\nPA%.0f,%.0f;PD;\nPA%.0f,%.0f;PU;", Mirror * u2inch(x1 + mirr_offsetx)*HPGLsolution, u2inch(y1 + ref_null_offsetY)*HPGLsolution, Mirror * u2inch(x2 + mirr_offsetx)*HPGLsolution, u2inch(y2 + ref_null_offsetY)*HPGLsolution );
return;
}
real WireLength(real x1,real x2,real y1,real y2) {
real WL = sqrt(pow(x2-x1,2) + pow(y2-y1,2)); // calculate Wire length WL
return WL;
}
// if the wire longer as longdistance and vertical or horizontal
// then make a holder spacing
void checkBridge(int x1, int y1, int x2, int y2, int state) {
real WL = WireLength(u2mm(x2),u2mm(x1),u2mm(y2),u2mm(y1));
if (WL >= Holder_Spacing && (x1 == x2 || y1 == y2) ) {
int bridgewidth = DimensionMillTool * 10000;
int xa, xb, ya, yb;
switch (state) {
case 0:
startlineprint(x1, y1, x2, y2);
break;
case 1:
if (x2 > x1 && x2 >= 0) {
xa = x2 - (2.5 * bridgewidth);
xb = x2 - bridgewidth;
}
if (x2 < x1 && x2 >= 0) {
xa = x2 + (2.5 * bridgewidth);
xb = x2 + bridgewidth;
}
if (x2 > x1 && x2 < 0) {
xa = x2 - (2.5 * bridgewidth);
xb = x2 - bridgewidth;
}
if (x2 < x1 && x2 < 0) {
xa = x2 + (2.5 * bridgewidth);
xb = x2 + bridgewidth;
}
if (y2 > y1 && y2 >= 0 ) {
ya = y2 - (2.5 * bridgewidth);
yb = y2 - bridgewidth;
}
if (y2 < y1 && y2 >= 0) {
ya = y2 + (2.5 * bridgewidth);
yb = y2 + bridgewidth;
}
if (y2 > y1 && y2 < 0 ) {
ya = y2 - (2.5 * bridgewidth);
yb = y2 - bridgewidth;
}
if (y2 < y1 && y2 < 0) {
ya = y2 + (2.5 * bridgewidth);
yb = y2 + bridgewidth;
}
if (x1 == x2) {
endlineprint(x1, ya);
startlineprint(x1, yb, x1, y2);
}
else {
endlineprint(xa, y1);
startlineprint(xb, y1, x2, y2);
}
break;
case 2:
endlineprint(x2, y2);
break;
}
return;
}
else {
switch (state) {
case 0:
startlineprint(x1, y1, x2, y2);
break;
case 1:
nextlineprint(x2, y2);
break;
case 2:
endlineprint(x2, y2);
break;
}
return;
}
}
void DeviceDraw(int x1, int y1, int x2, int y2, int state) {
// Actually draw a line on the output device.
// 'state' is defined as
// 0 = this is the first line of a partial polygon
// 1 = this is a "normal" line (neither the first nor the last one)
// 2 = this is the last line of a partial polygon
// 3 = this is a drill coordinate
// 4 = this is one line
switch (SelectedDevice) {
case devScript:
switch (state) {
case 0:
printf("WIRE (%.4f %.4f) (%.4f %.4f)\n", Mirror * u2mm(x1 + mirr_offsetx), u2mm(y1 + ref_null_offsetY), Mirror * u2mm(x2 + mirr_offsetx) , u2mm(y2 + ref_null_offsetY));
break;
case 1:
printf("(%.4f %.4f)\n", Mirror * u2mm(x2 + mirr_offsetx), u2mm(y2 + ref_null_offsetY));
break;
case 2:
printf("(%.4f %.4f);\n", Mirror * u2mm(x2 + mirr_offsetx), u2mm(y2 + ref_null_offsetY));
break;
case 3:
printf("HOLE (%.4f %.4f);\n", Mirror * u2mm(x2 + mirr_offsetx), u2mm(y2 + ref_null_offsetY));
break;
case 4:
printf("WIRE (%.4f %.4f) (%.4f %.4f)\n", Mirror * u2mm(x1 + mirr_offsetx), u2mm(y1 + ref_null_offsetY), Mirror * u2mm(x2 + mirr_offsetx), u2mm(y2 + ref_null_offsetY));
break;
}
break;
case devHPGL:
switch (state) {
case 0:
if (InPassOutmill) checkBridge(x1, y1, x2, y2, state);
else startlineprint(x1, y1, x2, y2);
break;
case 1:
if (InPassOutmill) checkBridge(x1, y1, x2, y2, state);
else nextlineprint(x2, y2);
break;
case 2:
if (InPassOutmill) checkBridge(x1, y1, x2, y2, state);
else endlineprint(x2, y2);
break;
case 3: // drilling tool
printf("\nPA%.0f,%.0f;PD;", Mirror * u2inch(x2 + mirr_offsetx)*HPGLsolution, u2inch(y2 + ref_null_offsetY)*HPGLsolution);
printf("\nPA%.0f,%.0f;PU;", Mirror * u2inch(x2 + mirr_offsetx)*HPGLsolution, u2inch(y2 + ref_null_offsetY)*HPGLsolution);
break;
case 4: // polygon filling
fullineprint(x1, y1, x2, y2);
break;
}
break;
}
return;
}
void CircleDraw(int centerx, int centery, int diam, int drilltool) {
switch (SelectedDevice) {
case devScript:
printf("CHANGE WIDTH %.4f;\n", DrillHole);
printf("CIRCLE (%.4f %.4f) (%.4f %.4f);\n", Mirror * u2mm(centerx + mirr_offsetx), u2mm(centery + ref_null_offsetY), Mirror * u2mm((centerx + diam / 2 - drilltool/2) + mirr_offsetx), u2mm(centery + ref_null_offsetY));
break;
case devHPGL:
// for HPGL 1. Start point arc,
// 2. Center point arc
// 3. angel
printf("\nPA%.0f,%.0f;PD;", Mirror * (u2inch((centerx + diam / 2 - drilltool / 2) + mirr_offsetx)) * HPGLsolution, u2inch(centery + ref_null_offsetY) * HPGLsolution);
printf("\nAA%.0f,%.0f,360;PU;", Mirror * u2inch(centerx + mirr_offsetx) * HPGLsolution, u2inch(centery + ref_null_offsetY) * HPGLsolution );
break;
}
return;
}
/*
void ArcDraw(int startarcx, int startarcy, int endarcx, int endarcy, int centerarcx, int centerarcy, real angle) {
switch (SelectedDevice) {
case devScript:
int rx = 2 * (startarcx - centerarcx);
int ry = 2 * (startarcy - centerarcy);
if (Mirror == 1) printf("ARC CCW ");
else printf("ARC CW ");
printf("(%.4f %.4f) (%.4f %.4f) (%.4f %.4f);\n",
Mirror * u2mm(startarcx + mirr_offsetx), u2mm(startarcy + ref_null_offsetY),
Mirror * u2mm(startarcx - rx + mirr_offsetx), u2mm(startarcy - ry + ref_null_offsetY),
Mirror * u2mm(endarcx + mirr_offsetx), u2mm(endarcy + ref_null_offsetY) );
break;
case devHPGL:
printf("\nPA%.0f,%.0f;PD;", Mirror * u2inch(startarcx + mirr_offsetx)*HPGLsolution, u2inch(startarcy + ref_null_offsetY)*HPGLsolution);
printf("\nAA%.0f,%.0f,%.2f;PU;", Mirror * u2inch(centerarcx + mirr_offsetx)*HPGLsolution, u2inch(centerarcy + ref_null_offsetY)*HPGLsolution, Mirror * angle);
break;
}
return;
}
*/
void scriptHeader(void) {
printf("GRID mm;\n");
printf("SET OPTIMIZING OFF;\nSET UNDO_LOG OFF;\nSET WIRE_BEND 2;\n");
printf("LAYER %d %s;\nSET FILL_LAYER %d %s;\n",
Layer + 100, lOutl, Layer + 100, fillstyle);
printf("CHANGE LAYER %d;\n", Layer + 100 );
return;
}
void DeviceInit(int tool) {
// Do anything necessary to initialize the output device
switch (SelectedDevice) {
case devScript:
// TODO make the layer user definable?
if (InPassPour) {
real overlap = MillToolFree * OverlapOutlPercent / 100;
printf("CHANGE WIDTH %.3f;\n", MillToolFree);
printf("SET FILL_LAYER %d %s;\n", Layer + 100, fillstyle);
}
break;
case devHPGL:
output(filesetext(FileName,".pli"), "at") {
// printf("Pen #%d = %s mm\t%s\n", tool, sToolValue[tool], PenList[tool]);
}
if (tool = Contour) {
printf ("IN; IP 0,0,100,100;SC 0,100,0,100;");
}
break;
}
}
void DeviceReInit(int tool) {
// Do anything necessary the secondary initialize the output device
switch (SelectedDevice) {
case devScript:
// TODO make the layer user definable?
switch (tool) {
case PadDrill:
printf("\nCHANGE DRILL %.2f;\n", DrillPad);
break;
case ViaDrill:
printf("\nCHANGE DRILL %.2f;\n", DrillVia);
break;
case HoleDrill:
printf("\nCHANGE DRILL %.2f;\n", DrillHole );
break;
case Contour:
printf("\nCHANGE WIDTH %.3f;\n", MillToolOutl);
break;
case BlowUp_RubOut:
printf("\nCHANGE WIDTH %.3f;\n", MillToolFree);
break;
// case RubOut:
// printf("\nCHANGE WIDTH %.3f;\n", MillToolFree);
// break;
case DimensionLine:
printf("\nCHANGE WIDTH %.3f;\n", DimensionMillTool);
break;
default:
;
break;
}
break;
case devHPGL:
printf ("\nPU;\nSP%d;\nPA0,0;", tool); // pen select
if(test) printf(" # %s", PenList[tool]);
output(filesetext(FileName,".pli"), "at") {
if (onlydrill && tool == Contour);
printf("Pen #%d = %s mm\t%s\n", tool, sToolValue[tool], PenList[tool]);
}
break;
}
return;
}
void DeviceEnd(void) {
// Do anything necessary to end output to the device
switch (SelectedDevice) {
case devScript:
break;
case devHPGL:
printf("\nPU;\nSP0;");
break;
}
}
// TRUE OUTLINE ***
void trueOutlineDraw(string SignalName) {
board(B) {
B.signals(S) {
if (S.name == SignalName) {
S.polygons(P) {
int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN;
int x0, y0, first = 1;
int FrameWire;
string s;
P.wires(W) {
x1 = min(x1, W.x1);
x2 = max(x2, W.x1);
y1 = min(y1, W.y1);
y2 = max(y2, W.y1);
}
string lasts;
P.contours(W) {
if (first) {
// a new partial polygon is starting
x0 = W.x1;
y0 = W.y1;
FrameWire = (x1 == x0 || x2 == x0) && (y1 == y0 || y2 == y0);
sprintf(s, " (%.4f %.4f)", u2mm(W.x1), u2mm(W.y1) );
trueOutline_coordinate = s;
lasts = s;
first = 0;
}
else if (W.x2 == x0 && W.y2 == y0) {
// this was the last wire of the partial polygon,
// so the next wire (if any) will be the first wire
// of the next partial polygon
sprintf(s, " (%.4f %.4f)", u2mm(W.x2), u2mm(W.y2) );
if (lasts != s) trueOutline_coordinate += s;
lasts = s;
first = 1;
}
else ;
if (!FrameWire) {
sprintf(s, " (%.4f %.4f)", u2mm(W.x2), u2mm(W.y2) );
if (lasts != s) trueOutline_coordinate += s;
lasts = s;
}
}
}
}
}
return ;
}
}
// *** the return string to start rekursiv ***
string RUN_pass(string run_Pass) {
string s;
sprintf(s, "RUN '%s' '%s' '%.4f' '%.4f' '%.4f' '%d' '%s' '%s' '%s' '%.1f' '%.2f' '%.2f' '%.2f' '%d' '%d' '%.2f' '%.4f' '%d' '%.4f' '%d' '%d' '%s';\n",
argv[0], Device, MillToolOutl, MillToolIsolate, MillToolFree, Layer, FileName, DrillFile, run_Pass,
Mirror, DrillPad, DrillVia, DrillHole, OverlapOutlPercent, OverlapRubOut, Distance_Copper_Dimension,
DimensionMillTool, millfreeyes, Holder_Spacing, onlydrill, generatedrills, trueOutline_coordinate);
return s;
}
// place a VIA outside the board with the same signal name
// for used polygon to calculate the filling with orpahns off
// and get no more polygon contours
void generateTruePolygonOutlines() { // the true outlines of board
board(B) {
real x1 = u2mm(B.area.x1) - DimensionMillTool, y1 = u2mm(B.area.y1) - DimensionMillTool,
x2 = u2mm(B.area.x2) + DimensionMillTool, y2 = u2mm(B.area.y2) + DimensionMillTool;
real distanceDimension = (DimensionMillTool / 2 - Distance_Copper_Dimension) * 2;
if (distanceDimension < 0) distanceDimension = 0.001;
string Cmd;
sprintf(Cmd, "GRID mm FINEST;\n"
"CHANGE DRILL 0.3;\nCHANGE DIAMETER 0.5;\nCHANGE SHAPE ROUND;\n"
"SET POLYGON_RATSNEST ON;\n"
"SET WIRE_BEND 0;\n"
"CHANGE RANK 6;\n"
"CHANGE POUR SOLID;\n"
"CHANGE THERMAL OFF;\n"
"CHANGE LAYER %d;\n"
"DISPLAY NONE 17 %d;\n",
Layer, Layer);
// make the 1st virtual Net for Normal Polygon Orphens OFF
// to generate the true outline for place the spacial polygon
// make a partial WIA for generate Polygon with orphans off
string millout;
sprintf(millout, "VIA '%s' (%.4f %.4f);\n", OutlineMillSignal, x1 - Distance_Copper_Dimension - 1, y1 - Distance_Copper_Dimension - 1);
Cmd += millout;
// Width = MillFree-Diameter/2 minus "Distance Copper/Dimension"
sprintf(millout, "CHANGE ISOLATE 0;\n");
Cmd += millout;
sprintf(millout, "CHANGE ORPHANS OFF;\n");
Cmd += millout;
sprintf(millout, "POLYGON '%s' %.4f (%.4f %.4f) (%.4f %.4f)(%.4f %.4f);\nRATSNEST;\n",
OutlineMillSignal, distanceDimension,
x1 - DimensionMillTool - Distance_Copper_Dimension - 2,
y1 - DimensionMillTool - Distance_Copper_Dimension - 2,
x2 + DimensionMillTool + Distance_Copper_Dimension,
y2 + DimensionMillTool + Distance_Copper_Dimension,
x1 - DimensionMillTool - Distance_Copper_Dimension - 2,
y1 - DimensionMillTool - Distance_Copper_Dimension - 2);
Cmd += millout;
Cmd += "WINDOW FIT;\n";
Cmd += RUN_pass(PassDimensionPoly);
if (test) output(filesetext(B.name, "-cmd.txt"), "wt") printf("%s", Cmd);
exit (Cmd);
}
}
//
// The actual outlines generator
void GenerateOutlines(void) {
board(B) {
trueOutlineDraw(OutlineMillSignal);
string s;
real x1 = u2mm(B.area.x1) - MillToolFree, y1 = u2mm(B.area.y1) - MillToolFree,
x2 = u2mm(B.area.x2) + MillToolFree, y2 = u2mm(B.area.y2) + MillToolFree;
real distanceDimension = MillToolFree / 2 - Distance_Copper_Dimension;
if (distanceDimension < 0) distanceDimension = 0.001;
// delete virtual Polygon and VIA
sprintf( s, "DELETE (%.4f %.4f) (%.4f %.4f) (%.4f %.4f);\n",
x1 - MillToolFree - Distance_Copper_Dimension,
y1 - MillToolFree - Distance_Copper_Dimension,
x2 + MillToolFree + Distance_Copper_Dimension,
y2 + MillToolFree + Distance_Copper_Dimension,
x1 - distanceDimension, y1 - distanceDimension);
string Cmd = s + "SET WIRE_BEND 2;\n";
sprintf(s, "CHANGE ISOLATE %.3f;\n", MillToolIsolate);
Cmd += s;
sprintf(s, "POLYGOn %s %.3f %s;\nRATSNEST;\n",
OutlinesSignalName, MillToolOutl, trueOutline_coordinate);
Cmd += s;
Cmd += RUN_pass(Pass2);
if (test) output(filesetext(B.name, "-cmd.txt"), "at") printf("%s", Cmd);
if (test) viewtest(Cmd);
exit(Cmd);
}
}
string WriteOutlines(string SignalName) { // OutlinesSignalName
board(B) {
if (InPassPour && MillToolFree == 0) return "";
if (InPassOutmill && !DimensionMillTool) return ""; // 0 = generate no Dimension with spacing
string Cmd;
B.signals(S) {
if (S.name == SignalName && !onlydrill) {
S.polygons(P) {
int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN;
int x0, y0, first = 1;
int FrameWire;
int State;
P.wires(W) {
x1 = min(x1, W.x1);
x2 = max(x2, W.x1);
y1 = min(y1, W.y1);
y2 = max(y2, W.y1);
}
if (InPass2) {
DeviceReInit(Contour);
}
if (InPassPour) DeviceReInit(BlowUp_RubOut);
if (InPassOutmill) DeviceReInit(DimensionLine);
P.contours(W) {
if (first) {
// a new partial polygon is starting
x0 = W.x1;
y0 = W.y1;
FrameWire = (x1 == x0 || x2 == x0) && (y1 == y0 || y2 == y0);
State = 0;
first = 0;
}
else if (W.x2 == x0 && W.y2 == y0) {
// this was the last wire of the partial polygon,
// so the next wire (if any) will be the first wire
// of the next partial polygon
State = 2;
first = 1;
}
else State = 1;
if (!FrameWire) {
DeviceDraw(W.x1, W.y1, W.x2, W.y2, State);
}
}
if (InPassPour && millfreeyes) {
if (SelectedDevice == devScript) {
printf("# pouring\n");
}
DeviceReInit(BlowUp_RubOut);
State = 4;
int fx1[], fy1[], fx2[], fy2[];
int fcnt = 0;
P.fillings(F) {
fx1[fcnt] = F.x1;
fy1[fcnt] = F.y1;
fx2[fcnt] = F.x2;
fy2[fcnt] = F.y2;
fcnt++;
}
int diry = fy1[0];
for (int m = 0; m <= fcnt; m++) {
if (diry == fy1[m]) {
DeviceDraw(fx1[m], fy1[m], fx2[m], fy2[m], State);
}
else {
// ****** milling reverse ******
diry = fy1[m]; // next y_line
for (int mb = m; mb <= fcnt; mb++) {
if (diry == fy1[mb]);
else break;
}
for(int mback = mb -1 ; mback >= m; mback--) {
DeviceDraw(fx2[mback], fy2[mback], fx1[mback], fy1[mback], State);
// reverse milling 08.05.2002 alf@cadsoft.de
}
m = mb;
diry = fy1[m]; // next y_line
m--;
}
}
}
DeviceEnd();
}
break;
}
}
return Cmd;
}
}
void Pad(UL_PAD P) {
DeviceDraw(0, 0, P.x, P.y, 3);
}
void Package(UL_PACKAGE P) {
P.contacts(C) {
if (C.pad) Pad(C.pad);
}
}
void Element(UL_ELEMENT E) {
Package(E.package);
}
void PackageHole(UL_PACKAGE P) {
P.holes(H) {
if (u2mm(H.drill) > DrillHole) {
CircleDraw(H.x, H.y, H.drill, DrillHole);
}
else DeviceDraw(0, 0, H.x, H.y, 3);
}
}
void ElementHole(UL_ELEMENT E) {
PackageHole(E.package);
}
void WriteDrills(void) {
board(B) {
DeviceReInit(PadDrill);
B.elements(E) Element(E);
DeviceReInit(ViaDrill);
B.signals(S) {
S.vias(V) {
DeviceDraw(0, 0, V.x, V.y, 3);
}
}
}
return;
}
void WriteHoles(void) {
board(B) {
DeviceReInit(HoleDrill);
B.elements(E) ElementHole(E);
B.holes(H) {
if (u2mm(H.drill) > DrillHole) {
CircleDraw(H.x, H.y, H.drill, DrillHole*10000); // internal unit
}
else DeviceDraw(0, 0, H.x, H.y, 3);
}
}
return;
}
// *** Pen assaign
void penAssign(void) {
dlgDialog("Mill outlines: HPGL Pen Assignment") {
string pen_assign = "<table>\n";
string t;
PenList[PadDrill] = "PadDrill";
PenList[ViaDrill] = "ViaDrill";
PenList[Contour] = "Contour";
PenList[BlowUp_RubOut] = "Blow-Up/Rub-Out";
//PenList[RubOut] = "Rub-Out";
PenList[HoleDrill] = "HoleDrill";
PenList[DimensionLine] = "DimensionLine";
sprintf(t, "<tr><td>PadDrill:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", PadDrill, DrillPad);
pen_assign += t;
sprintf(t, "<tr><td>ViaDrill:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", ViaDrill, DrillVia);
pen_assign += t;
sprintf(t, "<tr><td>Contour:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", Contour, MillToolOutl);
pen_assign += t;
sprintf(t, "<tr><td>BlowUp/RubOut:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", BlowUp_RubOut, MillToolFree);
pen_assign += t;
// sprintf(t, "<tr><td>RubOut:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", RubOut, MillToolFree);
// pen_assign += t;
sprintf(t, "<tr><td>HoleDrill:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", HoleDrill, DrillHole);
pen_assign += t;
sprintf(t, "<tr><td>Mill outline (Dimension):</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", DimensionLine, DimensionMillTool);
pen_assign += t;
pen_assign += "</table>";
dlgLabel(pen_assign);
dlgHBoxLayout {
dlgStretch(0);
dlgPushButton("OK") dlgAccept();
dlgStretch(1);
}
};
return;
}
void selectDevice(void) {
File = filesetext(FileName, DeviceExt[SelectedDevice]);
if (SelectedDevice != devHPGL) {
info = showpic[12 + SelectedDevice];
DrFile = filesetext(DrillFile, DrillExt[SelectedDevice]);
DrillLabel = "D&rill file";
DrBrowse = "Bro&wse";
}
else {
info = showpic[12 + SelectedDevice];
DrFile ="";
DrillLabel = "D&rill file";
DrBrowse = "Bro&wse";
}
return;
}
void setMillOffset(void) {
board(B) {
path = filedir(B.name);
B.elements(E) {
if (E.package.name == ref_pac) {
ref_offsetX[ref_cnto] = E.x;
ref_offsetY[ref_cnto] = E.y;
ref_cnto++;
E.package.circles(C) {
if (C.layer == 45) {
ref_offsetX[ref_cnto] = C.x;
ref_offsetY[ref_cnto] = C.y;
ref_cnto++;
}
}
if(ref_offsetX[1] > ref_offsetX[2]) { // if first X > second X then swap
ref_offsetX[3] = ref_offsetX[2];
ref_offsetX[2] = ref_offsetX[1];
ref_offsetX[1] = ref_offsetX[3];
}
if (ref_cnto == 3) {
ref_null_offsetX = ref_offsetX[0] * -1;
ref_null_offsetY = ref_offsetY[0] * -1;
if (Mirror == -1) {
mirr_offsetx = (ref_offsetX[2] + ref_offsetX[1] + ref_null_offsetX) * -1;
}
else {
mirr_offsetx = ref_null_offsetX;
}
}
else {
ref_cnto = 0; // more then 2 circles can't use as reference
if (dlgMessageBox("The reference Hole-Package contains more then 2 Holes\n" +
"generate outlines without reference-offset", "accept", "break") != 0) exit(0);
}
}
}
}
return;
}
void setblowinfo(void) {
if (MillToolFree) {
if (millfreeyes) { // 14.05.2002 alf
info = showpic[18];
infotext = "<nobr>Tool diameter for Blow-Up/Rub-Out<br>If value set to <b>0</b>, <b>no</b> Blow-Up (second isolate)<br>and Rub-Out (free milling) is generated.</nobr>";
}
else {
info = showpic[20];
infotext = "<nobr>Rub-Out is off!<br>Tool diameter for sec. isolate<br>If value set, Blow-Up (second isolate) is generated.</nobr>";
}
}
else {
if(millfreeyes) {
info = showpic[19];
infotext = "<nobr>You must set value to Blow-Up.</nobr>";
}
else {
info = showpic[19];
infotext = "<nobr>No blow up and Rub-Out is generated while value is set to 0.</nobr>";
} // 14.05.2002 alf
}
return;
}
//
// Main program:
//
// get Command-Line parameter if use RUN
if (argv[1]) {
Device = argv[1];
if (argv[2]) {
MillToolOutl = strtod(argv[2]);
if (MillToolOutl <= 0)
Fatal("Illegal diameter for milling tool #1: " + argv[2], "The <i>diameter</i> must be greater than zero.");
MillToolIsolate = strtod(argv[3]);
MillToolFree = strtod(argv[4]);
if (argv[4]) {
Layer = strtol(argv[5]);
sprintf(lOutl, "outmil%d", Layer);
if (Layer < 0 || Layer > 16)
Fatal("Illegal layer: " + argv[5], "The <i>layer</i> must be one of 1..16 or 0 to use the current layer.");
if (argv[6]) {
FileName = argv[6];
DrillFile = argv[7];
}
Mirror = strtod(argv[9]);
if (Mirror == 0)
Fatal("Illegal mirror value: " + argv[9], "The <i> mirror</i> must be -1 or 1.");
DrillPad = strtod(argv[10]);
if (DrillPad <= 0)
Fatal("Illegal diameter for Pad drill tool: " + argv[10], "The <i>diameter</i> must be greater than zero.");
DrillVia = strtod(argv[11]);
if (DrillVia <= 0)
Fatal("Illegal diameter for Via drill tool: " + argv[11], "The <i>diameter</i> must be greater than zero.");
DrillHole = strtod(argv[12]);
if (DrillHole <= 0)
Fatal("Illegal diameter for Hole drill tool: " + argv[12], "The <i>diameter</i> must be greater than zero.");
OverlapOutlPercent = strtol(argv[13]);
OverlapRubOut = strtol(argv[14]);
Distance_Copper_Dimension = strtod(argv[15]);
DimensionMillTool = strtod(argv[16]);
millfreeyes = strtol(argv[17]);
Holder_Spacing = strtod(argv[18]);
onlydrill = strtol(argv[19]);
generatedrills = strtol(argv[20]);
trueOutline_coordinate = (argv[21]);
}
}
}
if (!FileName) board(B) FileName = filesetext(B.name, DefaultSuffix);
if (!DrillFile) board(B) DrillFile = filesetext(B.name, DrlDefaultSuffix);
if (Device) {
ValueInit();
int n;
while (DeviceNames[n]) { // upper case
if (strupr(DeviceNames[n]) == strupr(Device)) {
SelectedDevice = n;
break;
}
n++;
}
if (!SelectedDevice)
Fatal("Illegal device: " + Device, "Please select one of the known devices.");
}
if (argv[8] == PassDimensionPoly) InPassDimensionPoly = argv[8]; // generate true outlines
if (argv[8] == Pass2) InPass2 = argv[8];
if (argv[8] == PassPour) InPassPour = argv[8];
if (argv[8] == PassOutmill) InPassOutmill = argv[8];
// *** run passes ***
if ( !InPass2 && !InPassPour && !InPassOutmill && !InPassDimensionPoly) {
showpic[0] = "<img src=\"mill-outlines-eagle.bmp\">";
showpic[1] = "<img src=\"mill-outlines-free.bmp\">";
showpic[2] = "<img src=\"mill-outlines-ovrlpfp.bmp\">";
showpic[3] = "<img src=\"mill-outlines-pour.bmp\">";
showpic[4] = "<img src=\"mill-outlines-ovrlppp.bmp\">";
showpic[5] = "<img src=\"mill-outlines-drill.bmp\">";
showpic[6] = "<img src=\"mill-outlines-via.bmp\">";
showpic[7] = "<img src=\"mill-outlines-hole.bmp\">";
showpic[8] = "<img src=\"mill-outlines-top.bmp\">";
showpic[9] = "<img src=\"mill-outlines-bott.bmp\">";
showpic[10] = "<img src=\"mill-outlines-coppdim.bmp\">";
showpic[11] = "<img src=\"mill-outlines-nomir.bmp\">";
showpic[12] = "<img src=\"mill-outlines-mirror.bmp\">";
showpic[13] = "<img src=\"mill-outlines-script.bmp\">";
showpic[14] = "<img src=\"mill-outlines-hpgl.bmp\">";
showpic[15] = "<img src=\"mill-outlines-spacing.bmp\">";
showpic[16] = "<img src=\"mill-outlines-mildimension.bmp\">";
showpic[17] = "<img src=\"mill-outlines-null_reference.bmp\">";
showpic[18] = "<img src=\"mill-outlines-isol-pour.bmp\">";
showpic[19] = "<img src=\"mill-outlines-no-blowup.bmp\">";
showpic[20] = "<img src=\"mill-outlines-sec-isolate.bmp\">";
info = showpic[10];
infotext = DRCinfo + usage + "<br><img src=\"mill-outlines-drc-info.bmp\">";
string Layers[];
int SelectedLayer = -1;
int ForceDialog = (!Device || !MillToolOutl);
board(B) {
B.signals(S) {
if (S.name == OutlinesSignalName)
Fatal("There is already a signal named " + OutlinesSignalName + " in this board!", "Please make sure that there is no such signal in this board.");
}
int n;
B.layers(L) {
if (L.number <= 16 && L.visible) {
if (Layer == L.number) SelectedLayer = n;
sprintf(Layers[n++], "%d %s", L.number, L.name);
}
}
if (n == 0) Fatal("No signal layer active!", "Please activate the signal layer to generate outlines for.");
if (!Layer) {
if (n > 1) ForceDialog = 1;
SelectedLayer = 0;
}
if (SelectedLayer < 0) {
string s;
sprintf(s, "%d", Layer);
Fatal("Invalid layer: " + s, "The <i>layer</i> was not found or is not active.");
}
if (ForceDialog) {
SelectedDevice = defaultdevice;
File = FileName;
DrFile = DrillFile;
DrillLabel = "D&rill file";
selectDevice();
int mir = 0;
dlgDialog(Version) {
dlgHBoxLayout {
dlgGridLayout {
dlgCell(0, 0) dlgLabel("&Device");
dlgCell(0, 1) dlgComboBox(DeviceNames, SelectedDevice) {
if (SelectedDevice) selectDevice();
else {
File = "";
DrFile = "";
}
infotext = "";
}
dlgCell(0, 3) dlgCheckBox("onl&y drills (HPGL)", onlydrill) {
if (onlydrill) {
generatedrills = 1;
infotext = "<nobr>Generate only drill file if HPGL selected.</nobr>";
}
else {
infotext = "";
}
}
dlgCell(0, 4) dlgPushButton("Pen &Assignment") { penAssign(); };
dlgCell(1, 0) dlgLabel("&Layer");
dlgCell(1, 1) dlgComboBox(Layers, SelectedLayer) {
if (SelectedLayer == 0) info = showpic[8];
if (SelectedLayer == 1) info = showpic[9];
infotext = "";
}
dlgCell(1, 3) dlgCheckBox("&Mirror", mir) {
if (mir) {
info = showpic[12];
infotext = "<nobr>Milling BOTTOM side (set mirror).</nobr>";
Mirror = -1.0;
}
else {
info = showpic[11];
infotext = "<nobr>Milling TOP side.</nobr>";
Mirror = 1.0;
}
}
dlgCell(1, 4) dlgPushButton("Refere&nce") {
info = showpic[17];
infotext = infoREFERENCE;
setZerroReference();
}
dlgCell(2, 0) dlgLabel("tool#&1 Isolate");
dlgCell(2, 1) dlgRealEdit(MillToolOutl, 0.1, 10);
dlgCell(2, 2) dlgLabel("mm");
dlgCell(2, 4) dlgPushButton("Isolate info") {
info = showpic[1];infotext = "<nobr>Tool diameter for isolate.</nobr>";
}
dlgCell(3, 0) dlgLabel("&Overlap\nisolate/blow-up");
dlgCell(3, 1) dlgIntEdit(OverlapOutlPercent, 0, 99);
dlgCell(3, 2) dlgLabel("%");
dlgCell(3, 4) dlgPushButton("Overlap info") {
info = showpic[2];
infotext = "<nobr>Overlap isolate - blow up in percent %.</nobr>";
}
dlgCell(4, 0) dlgLabel("tool#&2 blow-up");
dlgCell(4, 1) dlgRealEdit(MillToolFree, 0.0, 10);
dlgCell(4, 2) dlgLabel("mm");
dlgCell(4, 3) dlgCheckBox("Rub ou&t", millfreeyes) setblowinfo();
dlgCell(4, 4) dlgPushButton("Blow up/Rub out info") {
info = showpic[18];
setblowinfo();
}
dlgCell(5, 0) dlgLabel("Overlap rub-o&ut");
dlgCell(5, 1) dlgIntEdit(OverlapRubOut, 0, 99);
dlgCell(5, 2) dlgLabel("%");
dlgCell(5, 4) dlgPushButton("Overlap info") {
info = showpic[4];
infotext = "Overlap rub-out diameter in percent %.";
}
dlgCell(6, 0) dlgLabel("&Pad drill");
dlgCell(6, 1) dlgRealEdit(DrillPad, 0.1, 10);
dlgCell(6, 2) dlgLabel("mm");
dlgCell(6, 3) dlgCheckBox("Gen. drills", generatedrills) {
if (generatedrills) {
infotext = "<nobr>Generate drill data.</nobr>";
}
else {
infotext = "<nobr>Drills (PAD, VIA, HOLE) are disabled.<br>";
}
}
dlgCell(6, 4) dlgPushButton("Pad info") { info = showpic[5]; infotext = "Pad drill diameter"; };
dlgCell(7, 0) dlgLabel("&Via drill");
dlgCell(7, 1) dlgRealEdit(DrillVia, 0.1, 10);
dlgCell(7, 2) dlgLabel("mm");
dlgCell(7, 4) dlgPushButton("Via info"){
info = showpic[6];
infotext = "Via drill diameter.";
}
dlgCell(8, 0) dlgLabel("&Hole drill");
dlgCell(8, 1) dlgRealEdit(DrillHole, 0.1, 10);
dlgCell(8, 2) dlgLabel("mm");
dlgCell(8, 4) dlgPushButton("Hole info"){
info = showpic[7];
infotext = "Hole drill diameter.";
}
dlgCell(9, 0) dlgLabel("Dist. &Copper/Dim");
dlgCell(9, 1) dlgRealEdit(Distance_Copper_Dimension, 0.0, 20);
dlgCell(9, 2) dlgLabel("mm");
dlgCell(9, 4) dlgPushButton("Distance info") {
info = showpic[10];
infotext = infotext = DRCinfo + usage +
"<br><img src=\"mill-outlines-drc-info.bmp\">";
}
dlgCell(10, 0) dlgLabel("Mill Board/D&im");
dlgCell(10, 1) dlgRealEdit(DimensionMillTool, 0.0, 5);
dlgCell(10, 2) dlgLabel("mm");
dlgCell(10, 3) dlgLabel(" (0 = OFF)");
dlgCell(10, 4) dlgPushButton("Dimension info") {
info = showpic[16];
if (DimensionMillTool) {
infotext = "<nobr>Mill diameter for cut out.<br>Set value 0 for switch <b>OFF</b> this function.</nobr>";
}
else {
infotext = "<nobr>Mill diameter for cut out.<br>Set value for switch <b>ON</b> this function.</nobr>";
}
}
dlgCell(11, 0) dlgLabel("Holder spac&ing");
dlgCell(11, 1) dlgRealEdit(Holder_Spacing, 1.0, 500);
dlgCell(11, 2) dlgLabel("mm");
dlgCell(11, 4) dlgPushButton("Spacing info") {
info = showpic[15];
infotext = "This value determins the minimum length of a edge where a spacer will be set.<p>" +
"Spacers will be set on vertical & horizontal and in HPGL-Format only.<p>" +
"The width of the spacer depends on the diameter of tool#2.";
}
}
dlgVBoxLayout dlgSpacing (400); // high of Cell
dlgStretch(0);
dlgVBoxLayout {
dlgStretch(0);
dlgLabel(info, 1);
dlgStretch(0);
dlgLabel(infotext, 1);
dlgStretch(1);
}
dlgStretch(1);
}
dlgStretch(1);
dlgHBoxLayout {
dlgStretch(0);
dlgLabel("Mill fil&e");
dlgStretch(0);
dlgStringEdit(File);
dlgStretch(0);
dlgPushButton("&Browse") {
string fn = dlgFileSave("Save Outlines file", File);
if (fn) {
File = fn;
FileName = fn;
info = showpic[1];
}
}
dlgStretch(0);
}
dlgHBoxLayout {
dlgStretch(0);
dlgLabel(DrillLabel);
dlgStretch(0);
dlgStringEdit(DrFile);
dlgStretch(0);
dlgPushButton(DrBrowse) {
string fd = dlgFileSave("Save Drill file", DrFile);
if (fd) {
DrFile = fd;
DrillFile = fd;
info = showpic[3];
}
}
dlgStretch(0);
}
dlgStretch(1);
dlgHBoxLayout dlgSpacing(600);
dlgHBoxLayout {
dlgStretch(0);
dlgPushButton("+OK") {
if (!SelectedDevice) Error("No device selected!", "Please select a device.");
else {
int fault = 0;
real distanceDimension = DimensionMillTool / 2 - Distance_Copper_Dimension;
if (DimensionMillTool) { // **** if used ? ****
if (distanceDimension < 0) {
string d;
sprintf(d, "%.3f", distanceDimension * -1);
fault = dlgMessageBox("<qt><nobr>The value for Copper/Dimension "
"is greater than the mill tool (free pouring) diameter.<p>"
"Check/change Distance Copper/Dimension in Design Rules <b>DRC</b><p>"
"or accept a distance of " + d +
"mm to board dimension.</nobr></qt>",
"Accept", "Cancel");
}
}
if (SelectedDevice != devHPGL && onlydrill) {
Error("only drill (HPGL)", "used without HPGL device");
fault = 1;
}
if (!MillToolOutl) {
Error("Illegal diameter: 0", "The <i>Isolate diameter</i> must be greater than zero.");
fault = 1;
}
if (!fault) {
FileName = File;
if (test) output(filesetext(B.name, "-cmd.txt"), "at");
DrillFile = DrFile;
sprintf(lOutl, "%d", SelectedLayer + 100);
if (mir) Mirror = -1;
dlgAccept();
}
}
}
dlgStretch(0);
dlgPushButton("-Cancel") { dlgReject(); exit(1); }
dlgStretch(1);
}
};
}
Device = DeviceNames[SelectedDevice];
Layer = strtol(Layers[SelectedLayer]);
fileerror();
output(FileName, "wt"); // creat new file
if (fileerror()) exit (1);
output(filesetext(B.name, "_display$tmp-.scr"), "wt") {
printf("DISPLAY NONE 17 ");
board(B) {
B.layers(L) {
if (L.visible) printf("%d ",L.number);
}
}
switch (SelectedDevice) {
case devScript:
printf(" %d", Layer + 100);
printf(";\n");
break;
case devHPGL:
output(filesetext(FileName,".pli"), "wt") {
printf("# Plot info generated by %s\n# from %s\n# at %s\n# Used tools\n", argv[0], B.name, t2string(time()) );
}
break;
}
}
toolFiles(); // generate Rack and Wheel file
generateTruePolygonOutlines(); // generate the true Dimension outline as polygon.
}
}
// *** pass runs ****
setMillOffset(); // get info of special package if placed
if (InPassDimensionPoly) {
GenerateOutlines(); // for milling isolate
}
if (InPass2) {
board(B) {
real x1 = u2mm(B.area.x1) - MillToolFree/4 , y1 = u2mm(B.area.y1) - MillToolFree/2 ;
output(FileName, "at") {
DeviceInit(Contour);
switch (SelectedDevice) {
case devScript:
scriptHeader();
output(DrillFile, "wt") {
DeviceInit(PadDrill);
WriteDrills();
}
break;
case devHPGL:
if (generatedrills) WriteDrills();
break;
}
printf("%s", WriteOutlines(OutlinesSignalName)); // the isolated contour
}
if (MillToolFree < 0) MillToolFree = 0.2;
real overlapfree = MillToolFree * OverlapRubOut / 100;
real overlapoutl = MillToolOutl * OverlapOutlPercent / 100;
string Cmd;
sprintf(Cmd, "CHANGE WIDTH %.3f (%.4f %.4f);\n"
"CHANGE ISOLATE %.3f (%.4f %.4f);\n"
"RATSNEST;\n",
MillToolFree - overlapfree, x1, y1,
MillToolOutl + ( (overlapfree / 2 ) - overlapoutl), x1, y1 );
Cmd += RUN_pass(PassPour);
if (test) output(filesetext(B.name, "-cmd.txt"), "at") printf("%s", Cmd);
if (test) viewtest(Cmd);
exit (Cmd);
}
}
if (InPassPour) {
board(B) {
output(FileName, "at") {
if (SelectedDevice == devScript) printf("# 2. isolate\n");
printf("%s", WriteOutlines( OutlinesSignalName)) ;
switch (SelectedDevice) {
case devScript:
output(DrillFile, "at") {
WriteHoles();
}
break;
case devHPGL:
if(generatedrills) WriteHoles();
break;
default:
DeviceEnd();
break;
}
}
real x1 = u2mm(B.area.x1) - MillToolFree/4, y1 = u2mm(B.area.y1) - MillToolFree/2;
real x2 = u2mm(B.area.x2) + MillToolFree/4, y2 = u2mm(B.area.y2) + MillToolFree/2;
string Cmd;
string millout;
sprintf(Cmd, "DISPLAY NONE 17 %d;\nDELETE ", Layer); // Delete Outline Polygon
string deloutline[];
int n = strsplit(deloutline, trueOutline_coordinate, ' ');
string s;
for (int x = 0; x < n-6; x++) { // true polygon coorinates
sprintf(s, "%s ", deloutline[x]);
Cmd += s;
}
Cmd += ";\n";
// make virtual Net for Normal Polygon Orphen OFF
Cmd += "SET WIRE_BEND 2;\n";
sprintf(millout, "VIA '%s' (%.4f %.4f);\n", OutlineMillSignal, x1 - Distance_Copper_Dimension, y1 - Distance_Copper_Dimension);
Cmd += millout;
real distanceDimension = DimensionMillTool / 2 - Distance_Copper_Dimension;
if (distanceDimension < 0) {
distanceDimension = 0.001;
}
// Width = MillFree-Diameter/2 minus "Distance Copper/Dimension"
sprintf(millout, "CHANGE ISOLATE 0;\n");
Cmd += millout;
sprintf(millout, "CHANGE ORPHANS OFF;\n");
Cmd += millout;
Cmd += "SET WIRE_BEND 0;\n";
real dimensionwidth = DimensionMillTool - 2*distanceDimension;
if (dimensionwidth < 0) dimensionwidth = 0.1;
sprintf(millout, "POLyGON '%s' %.3f (%.4f %.4f) (%.4f %.4f) (%.4f %.4f);\nRATSNEST;\n", OutlineMillSignal, dimensionwidth,
x1 - DimensionMillTool - Distance_Copper_Dimension,
y1 - DimensionMillTool - Distance_Copper_Dimension,
x2 + DimensionMillTool + Distance_Copper_Dimension,
y2 + DimensionMillTool + Distance_Copper_Dimension,
x1 - DimensionMillTool - Distance_Copper_Dimension,
y1 - DimensionMillTool - Distance_Copper_Dimension);
Cmd += millout;
Cmd += RUN_pass(PassOutmill);
if (test) output(filesetext(B.name, "-cmd.txt"), "at") printf("%s", Cmd);
if (test) viewtest(Cmd);
exit (Cmd);
}
}
if (InPassOutmill) {
board(B) {
string Cmd;
real x1 = u2mm(B.area.x1) - DimensionMillTool/4, y1 = u2mm(B.area.y1) - MillToolFree/2,
x2 = u2mm(B.area.x2) + DimensionMillTool/4, y2 = u2mm(B.area.y2) + MillToolFree/2;
// delete Virtual Polygon and VIA
sprintf(Cmd, "DELETE (%.4f %.4f) (%.4f %.4f) (%.4f %.4f);\n",
x1, y1, x2, y2, x1, y1 );
output(FileName, "at") {
if (SelectedDevice == devScript) printf("# milling dimension\n");
printf("%s", WriteOutlines( OutlineMillSignal)) ;
}
switch (SelectedDevice) {
case devScript:
Cmd += "SCRIPT '" + FileName + "';\n"; // execute script
Cmd += "SCRIPT '" + filesetext(B.name, "_display$tmp-.scr") + "';\n";
break;
case devHPGL:
Cmd += "script '" + filesetext(B.name, "_display$tmp-.scr") + "';\n";
break;
}
if (test) output(filesetext(B.name, "-cmd.txt"), "at") printf("%s", Cmd);
Cmd += "GRID LAST;\nSET UNDO_LOG ON;\nSET OPTIMIZING ON;\nWIN;\n";
switch (SelectedDevice) {
case devScript:
break;
case devHPGL:
if (test) showHPGLinfo();
break;
}
// if (test) showRackFile();
if (test) viewtest(Cmd);
exit (Cmd);
}
}
|