r5458 - trunk/eda/fped
werner at docs.openmoko.org
werner at docs.openmoko.org
Sun Aug 16 03:51:22 CEST 2009
Author: werner
Date: 2009-08-16 03:51:21 +0200 (Sun, 16 Aug 2009)
New Revision: 5458
Modified:
trunk/eda/fped/kicad.c
trunk/eda/fped/postscript.c
Log:
- added KiCad export of arcs
- added pad names to Postscript export
Modified: trunk/eda/fped/kicad.c
===================================================================
--- trunk/eda/fped/kicad.c 2009-08-15 23:25:05 UTC (rev 5457)
+++ trunk/eda/fped/kicad.c 2009-08-16 01:51:21 UTC (rev 5458)
@@ -153,7 +153,30 @@
static void kicad_arc(FILE *file, const struct inst *inst)
{
- fprintf(stderr, "NOT YET IMPLEMENTED\n");
+ struct coord p;
+ double a;
+
+ /*
+ * The documentation says:
+ * Xstart, Ystart, Xend, Yend, Angle, Width, Layer
+ *
+ * But it's really:
+ * Xcenter, Ycenter, Xend, Yend, ...
+ */
+ p = rotate_r(inst->base, inst->u.arc.r, inst->u.arc.a2);
+ a = inst->u.arc.a2-inst->u.arc.a1;
+ while (a <= 0)
+ a += 360;
+ while (a > 360)
+ a -= 360;
+ fprintf(file, "DA %d %d %d %d %d %d %d\n",
+ units_to_kicad(inst->base.x),
+ -units_to_kicad(inst->base.y),
+ units_to_kicad(p.x),
+ -units_to_kicad(p.y),
+ (int) (a*10.0),
+ units_to_kicad(inst->u.arc.width),
+ layer_silk_top);
}
@@ -176,6 +199,10 @@
kicad_arc(file, inst);
break;
default:
+ /*
+ * Don't try to export vectors, frame references, or
+ * measurements.
+ */
break;
}
}
Modified: trunk/eda/fped/postscript.c
===================================================================
--- trunk/eda/fped/postscript.c 2009-08-15 23:25:05 UTC (rev 5457)
+++ trunk/eda/fped/postscript.c 2009-08-16 01:51:21 UTC (rev 5458)
@@ -23,32 +23,58 @@
#define DOT_DIAM mm_to_units(0.01)
#define HATCH mm_to_units(0.1)
#define HATCH_LINE mm_to_units(0.02)
+#define FONT_OUTLINE mm_to_units(0.025)
struct postscript_params postscript_params = {
.zoom = 10.0,
- .show_pad_names = 0,
+ .show_pad_names = 1,
.show_stuff = 0,
.label_vecs = 0,
.show_meas = 0,
};
-static void ps_pad(FILE *file, const struct inst *inst)
+static void ps_pad_name(FILE *file, const struct inst *inst)
{
struct coord a = inst->base;
struct coord b = inst->u.pad.other;
+ unit_type h, w;
+ h = a.y-b.y;
+ w = a.x-b.x;
+ if (h < 0)
+ h = -h;
+ if (w < 0)
+ w = -w;
+ fprintf(file, "0 setgray /Helvetica-Bold findfont dup\n");
+ fprintf(file, " (%s) %d %d\n", inst->u.pad.name, w/2, h/2);
+ fprintf(file, " 4 copy 100 maxfont\n");
+ fprintf(file, " maxfont scalefont setfont\n");
+ fprintf(file, " %d %d moveto\n", (a.x+b.x)/2, (a.y+b.y)/2);
+ fprintf(file, " (%s) center %d showoutlined newpath\n",
+ inst->u.pad.name, FONT_OUTLINE);
+}
+
+
+static void ps_pad(FILE *file, const struct inst *inst, int show_name)
+{
+ struct coord a = inst->base;
+ struct coord b = inst->u.pad.other;
+
fprintf(file, "0 setgray %d setlinewidth\n", HATCH_LINE);
fprintf(file, " %d %d moveto\n", a.x, a.y);
fprintf(file, " %d %d lineto\n", b.x, a.y);
fprintf(file, " %d %d lineto\n", b.x, b.y);
fprintf(file, " %d %d lineto\n", a.x, b.y);
fprintf(file, " closepath gsave hatchpath grestore stroke\n");
+
+ if (show_name)
+ ps_pad_name(file, inst);
}
-static void ps_rpad(FILE *file, const struct inst *inst)
+static void ps_rpad(FILE *file, const struct inst *inst, int show_name)
{
struct coord a = inst->base;
struct coord b = inst->u.pad.other;
@@ -72,6 +98,9 @@
fprintf(file, " %d %d %d 90 270 arc\n", a.x+r, a.y+r, r);
}
fprintf(file, " closepath gsave hatchpath grestore stroke\n");
+
+ if (show_name)
+ ps_pad_name(file, inst);
}
@@ -159,9 +188,9 @@
switch (prio) {
case ip_pad:
if (inst->obj->u.pad.rounded)
- ps_rpad(file, inst);
+ ps_rpad(file, inst, postscript_params.show_pad_names);
else
- ps_pad(file, inst);
+ ps_pad(file, inst, postscript_params.show_pad_names);
break;
case ip_vec:
if (postscript_params.show_stuff)
@@ -202,9 +231,9 @@
" 1 setlinecap %d setlinewidth\n"
" /ury exch def /urx exch def /lly exch def /llx exch def\n"
" llx %d urx {\n"
-" lly %d ury {\n"
+" lly %d ury {\n"
" 1 index exch moveto 0 0 rlineto stroke\n"
-" } for\n"
+" } for\n"
" } for\n"
" grestore newpath } def\n", DOT_DIAM, DOT_DIST, DOT_DIST);
@@ -213,11 +242,46 @@
" gsave pathbbox clip newpath\n"
" /ury exch def /urx exch def /lly exch def /llx exch def\n"
" lly ury sub %d urx llx sub {\n" /* for -(ury-lly) to urx-llx */
-" llx add dup lly moveto\n"
-" ury lly sub add ury lineto stroke\n"
+" llx add dup lly moveto\n"
+" ury lly sub add ury lineto stroke\n"
" } for\n"
" grestore newpath } def\n", HATCH);
+ /*
+ * Stack: font string width height factor -> factor
+ */
+
+ fprintf(file,
+"/maxfont {\n"
+" gsave 0 0 moveto\n"
+" /f exch def /h exch def /w exch def\n"
+" exch f scalefont setfont\n"
+" false charpath pathbbox\n"
+" /ury exch def /urx exch def /lly exch def /llx exch def\n"
+" w urx llx sub div h ury lly sub div 2 copy gt { exch } if pop\n"
+" f mul grestore } def\n");
+
+ /*
+ * Stack: string -> string
+ */
+
+ fprintf(file,
+"/center {\n"
+" gsave dup false charpath pathbbox\n"
+" /ury exch def /urx exch def /lly exch def /llx exch def\n"
+" grestore\n"
+" llx urx sub 2 div lly ury sub 2 div rmoveto } def\n");
+
+ /*
+ * Stack: string outline_width -> -
+ */
+
+ fprintf(file,
+"/showoutlined {\n"
+" gsave 2 mul setlinewidth 1 setgray\n"
+" dup false charpath stroke grestore\n"
+" show } def\n");
+
FOR_INSTS_UP(prio, inst)
ps_background(file, prio, inst);
FOR_INSTS_UP(prio, inst)
More information about the commitlog
mailing list