📄 mill-outlines.ulp
字号:
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -