#usage "PostScript output
\n"
"This program creates a Postscript file from a board or a sheet.
"
"Author: support@cadsoft.de"
int LayerActive[];
string fileName;
void PSopen(void)
{
printf("gsave\n");
printf("30 30 translate\n");
printf("1 setlinecap 1 setlinejoin\n");
}
void PSscale(real f)
{
printf("%f %f scale\n", f * u2inch(72), f * u2inch(72));
}
void PSclose(void)
{
printf("showpage\n");
printf("grestore\n");
}
void DrawArc(UL_ARC A)
{
if (LayerActive[A.layer])
printf("newpath %d %d %d %f %f arc %d setlinewidth stroke\n",
A.xc, A.yc, A.radius, A.angle1, A.angle2, A.width);
}
void DrawCircle(UL_CIRCLE C)
{
if (LayerActive[C.layer])
printf("newpath %d %d %d 0 360 arc %d setlinewidth stroke\n",
C.x, C.y, C.radius, C.width);
}
void DrawWire(UL_WIRE W)
{
if (LayerActive[W.layer])
printf("newpath %d %d moveto %d %d lineto %d setlinewidth stroke\n",
W.x1, W.y1, W.x2, W.y2, W.width);
}
void DrawVia(UL_VIA V) {
if (LayerActive[LAYER_VIAS])
printf("newpath %d %d moveto %d %d %d 0 360 arc closepath fill\n",
V.x + V.diameter[LAYER_TOP] / 2, V.y, V.x, V.y, V.diameter[LAYER_TOP] / 2);
}
void DrawContact(UL_CONTACT C)
{
if (C.pad) {
if (LayerActive[LAYER_PADS])
printf("newpath %d %d moveto %d %d %d 0 360 arc closepath fill\n",
C.x + C.pad.diameter[LAYER_TOP] / 2, C.y, C.x, C.y, C.pad.diameter[LAYER_TOP] / 2);
}
else if (C.smd) {
if (LayerActive[C.smd.layer]) {
int dx2 = C.smd.dx / 2;
int dy2 = C.smd.dy / 2;
printf("newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath fill\n",
C.x - dx2, C.y - dy2,
C.x - dx2, C.y + dy2,
C.x + dx2, C.y + dy2,
C.x + dx2, C.y - dy2);
}
}
}
void DrawJunction(UL_JUNCTION J)
{
if (LayerActive[LAYER_NETS])
printf("newpath %d %d moveto %d %d %d 0 360 arc closepath fill\n",
J.x + J.diameter / 2, J.y, J.x, J.y, J.diameter / 2);
}
void DrawText(UL_TEXT T)
{
if (LayerActive[T.layer]) {
/*
printf("/Helvetica findfont %d scalefont setfont %d %d moveto (%s) show\n",
T.size, T.x, T.y, T.value);
*/
T.wires(W) DrawWire(W);
}
}
void DrawRectangle(UL_RECTANGLE R)
{
if (LayerActive[R.layer]) {
printf("newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath fill\n",
R.x1, R.y1, R.x2, R.y1, R.x2, R.y2, R.x1, R.y2);
}
}
void DrawPin(UL_PIN P)
{
P.circles(X) DrawCircle(X);
P.wires(X) DrawWire(X);
P.texts(X) DrawText(X);
}
void DrawSymbol(UL_SYMBOL S)
{
S.circles(C) DrawCircle(C);
S.rectangles(R) DrawRectangle(R);
S.wires(W) DrawWire(W);
S.arcs(A) DrawArc(A);
S.pins(P) DrawPin(P);
S.texts(T) DrawText(T);
}
void DrawPackage(UL_PACKAGE P)
{
P.circles(C) DrawCircle(C);
P.rectangles(R) DrawRectangle(R);
P.wires(W) DrawWire(W);
P.arcs(A) DrawArc(A);
P.contacts(C) DrawContact(C);
P.texts(T) DrawText(T);
}
if (board) board(B) {
B.layers(L) LayerActive[L.number] = L.visible;
fileName = dlgFileSave("Save File", filesetext(B.name, ".ps"), "*.ps");
if (fileName == "") exit(0);
output(fileName) {
PSopen();
PSscale(1.0);
B.elements(E) {
E.texts(T) DrawText(T);
DrawPackage(E.package);
}
B.signals(S) {
S.wires(W) DrawWire(W);
S.vias(V) DrawVia(V);
}
PSclose();
}
}
if (schematic) schematic(SCH) {
SCH.layers(L) LayerActive[L.number] = L.visible;
sheet(SH) {
fileName = dlgFileSave("Save File", filesetext(SCH.name, ".ps"), "*.ps");
if (fileName == "") exit(0);
output(fileName) {
PSopen();
PSscale(1.0);
SH.parts(P) {
P.instances(I) {
DrawSymbol(I.gate.symbol);
I.texts(T) DrawText(T);
}
}
SH.nets(N) N.segments(S) {
S.wires(W) DrawWire(W);
S.texts(T) DrawText(T);
S.junctions(J) DrawJunction(J);
}
SH.busses(B) B.segments(S) {
S.wires(W) DrawWire(W);
S.texts(T) DrawText(T);
}
PSclose();
}
}
}