Date:2012-07-19 03:09:47 (7 years 4 months ago)
Author:Werner Almesberger
Commit:d250ed236c8eb28eeacced1867510eff42fc0f17
Message:postscript.c: show key for pad types at bottom of fullpage drawings (-P -K)

Files: fped.c (4 diffs)
postscript.c (6 diffs)
postscript.h (1 diff)

Change Details

fped.c
7373" write gnuplot output, then exit\n"
7474" -k write KiCad output, then exit\n"
7575" -p write Postscript output, then exit\n"
76" -P [-s scale] [-1 package]\n"
76" -P [-K] [-s scale] [-1 package]\n"
7777" write Postscript output (full page), then exit\n"
7878" -T test mode. Load file, then exit\n"
7979" -T -T test mode. Load file, dump to stdout, then exit\n\n"
8080"Common options:\n"
8181" -1 name output only the specified package\n"
82" -K show the pad type key\n"
8283" -s scale scale factor for -P (default: auto-scale)\n"
8384" -s [width]x[heigth]\n"
8485" auto-scale to fit within specified box. Dimensions in mm.\n"
...... 
132133    const char *one = NULL;
133134    int c;
134135
135    while ((c = getopt(argc, argv, "1:gkps:D:I:PTU:")) != EOF)
136    while ((c = getopt(argc, argv, "1:gkps:D:I:KPTU:")) != EOF)
136137        switch (c) {
137138        case '1':
138139            one = optarg;
...... 
157158                usage(*argv);
158159            batch = batch_ps_fullpage;
159160            break;
161        case 'K':
162            postscript_params.show_key = 1;
163            break;
160164        case 's':
161165            if (batch != batch_ps_fullpage)
162166                usage(*argv);
...... 
181185    if (one && batch != batch_ps && batch != batch_ps_fullpage &&
182186        batch != batch_gnuplot)
183187        usage(name);
188    if (postscript_params.show_key && batch != batch_ps_fullpage)
189        usage(name);
184190
185191    if (!batch) {
186192        args[0] = name;
postscript.c
1414#include <stdlib.h>
1515#include <stdio.h>
1616#include <string.h>
17#include <ctype.h>
1718#include <errno.h>
1819
1920#include "util.h"
...... 
8889#define PS_CROSS_WIDTH mm_to_units(0.01)
8990#define PS_CROSS_DASH mm_to_units(0.1)
9091
92#define PS_KEY_GAP mm_to_units(8)
93#define PS_KEY_HEIGTH mm_to_units(8)
94
9195#define TEXT_HEIGHT_FACTOR 1.5 /* height/width of typical text */
9296
9397
...... 
99103    .show_stuff = 0,
100104    .label_vecs = 0,
101105    .show_meas = 1,
106    .show_key = 0,
102107};
103108
104109static const struct postscript_params minimal_params;
...... 
806811}
807812
808813
814static void ps_key(FILE *file, double w, double h, enum pad_type type)
815{
816    char tmp[20]; /* @@@ plenty :) */
817    double f = 32;
818    struct coord a, b;
819    unit_type key_w;
820
821    key_w = (w-2*PS_KEY_GAP-PS_KEY_GAP*(pt_n-1))/pt_n;
822    a.x = b.x = (key_w+PS_KEY_GAP)*type-w/2+PS_KEY_GAP;
823    a.y = b.y = -h/2-PS_KEY_GAP;
824    b.x += key_w;
825    b.y -= PS_KEY_HEIGTH;
826
827    a.x /= f;
828    a.y /= f;
829    b.x /= f;
830    b.y /= f;
831
832    strcpy(tmp, pad_type_name(type));
833    tmp[0] = toupper(tmp[0]);
834    fprintf(file, "gsave %f %f scale\n", f, f);
835    ps_filled_box(file, a, b, hatch(type));
836    ps_outlined_text_in_rect(file, tmp, a, b);
837    fprintf(file, "grestore\n");
838}
839
840
841static void ps_keys(FILE *file, double w, double h)
842{
843    enum pad_type i;
844
845    for (i = 0; i != pt_n; i++)
846        ps_key(file, w, h, i);
847}
848
849
809850static void ps_package(FILE *file, const struct pkg *pkg, int page)
810851{
811852    struct bbox bbox;
...... 
11411182    unit_type cx, cy;
11421183    struct bbox bbox;
11431184    double fx, fy, f;
1144    double d;
1185    double w = 2.0*PAGE_HALF_WIDTH;
1186    double h = 2.0*PAGE_HALF_HEIGHT;
11451187
11461188    ps_page(file, page, pkg);
11471189    active_params = postscript_params;
...... 
11511193    if (active_params.zoom) {
11521194        f = active_params.zoom;
11531195    } else {
1154        d = active_params.max_width ? active_params.max_width :
1155            2.0*PAGE_HALF_WIDTH;
1156        fx = d/(bbox.max.x-bbox.min.x);
1157        d = active_params.max_height ? active_params.max_height :
1158            2.0*PAGE_HALF_HEIGHT;
1159        fy = d/(bbox.max.y-bbox.min.y);
1196        if (active_params.max_width)
1197            w = active_params.max_width;
1198        fx = w/(bbox.max.x-bbox.min.x);
1199        if (active_params.max_height)
1200            h = active_params.max_height;
1201        if (active_params.show_key)
1202            h -= 2*PS_KEY_HEIGTH;
1203        fy = h/(bbox.max.y-bbox.min.y);
11601204        f = fx < fy ? fx : fy;
11611205    }
1206    fprintf(file, "gsave\n");
11621207    fprintf(file, "%d %d translate\n", (int) (-cx*f), (int) (-cy*f));
11631208    ps_draw_package(file, pkg, f, 0);
1209    fprintf(file, "grestore\n");
1210    if (active_params.show_key)
1211        ps_keys(file, w, h);
11641212    fprintf(file, "showpage\n");
11651213}
11661214
postscript.h
2525        int show_stuff; /* vecs and frames */
2626        int label_vecs;
2727        int show_meas;
28    int show_key;
2829} postscript_params;
2930
3031

Archive Download the corresponding diff file

Branches:
master



interactive