(no commit message)
[geda-pcb/pcjc2.git] / src / pcb-printf.h
blobed547a0ed589d9885c8c2d22dcff6c75c9d50702
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 2011 Andrew Poelstra
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Andrew Poelstra, 16966 60A Ave, V3S 8X5 Surrey, BC, Canada
23 * asp11@sfu.ca
27 /* This file defines a wrapper around sprintf, that
28 * defines new specifiers that take pcb Coord objects
29 * as input.
31 * There is a fair bit of nasty (repetitious) code in
32 * here, but I feel the gain in clarity for output
33 * code elsewhere in the project will make it worth
34 * it.
36 * The new specifiers are:
37 * %mk output a measure in km
38 * %mf output a measure in meters
39 * %me output a measure in cm
40 * %mm output a measure in mm
41 * %mu output a measure in um
42 * %mn output a measure in nm
43 * %mM output a measure in scaled (mm/um) metric
44 * %ml output a measure in mil
45 * %mc output a measure in cmil
46 * %mt output a measure in 1/10 of mils (for Excellon drill files)
47 * %mL output a measure in scaled (mil/in) imperial
48 * %ms output a measure in most natural mm/mil units
49 * %mS output a measure in most natural scaled units
50 * %md output a pair of measures in most natural mm/mil units
51 * %mD output a pair of measures in most natural scaled units
52 * %m3 output 3 measures in most natural scaled units
53 * ...
54 * %m9 output 9 measures in most natural scaled units
55 * %m* output a measure with unit given as an additional
56 * const char* parameter
57 * %m+ accepts an e_allow parameter that masks all subsequent
58 * "natural" (S/D/3/.../9) specifiers to only use certain
59 * units
60 * %mr output a measure in a unit readable by parse_l.l
61 * (this will always append a unit suffix)
62 * %ma output an angle in degrees (expects degrees)
64 * These accept the usual printf modifiers for %f, as well as
65 * $ output a unit suffix after the measure
66 * # prevents all scaling for %mS/D/1/.../9 (this should
67 * ONLY be used for debug code since its output exposes
68 * pcb's base units).
69 * ` always use '.' as decimal separator (note that %mr uses
70 * this by default).
72 * KNOWN ISSUES:
73 * No support for %zu size_t printf spec
76 #ifndef PCB_PCB_PRINTF_H
77 #define PCB_PCB_PRINTF_H
79 enum e_allow {
80 NO_PRINT = 0, /* suffixes we can read but not print (i.e., "inch") */
81 ALLOW_NM = 1,
82 ALLOW_UM = 2,
83 ALLOW_MM = 4,
84 ALLOW_CM = 8,
85 ALLOW_M = 16,
86 ALLOW_KM = 32,
88 ALLOW_CMIL = 1024,
89 ALLOW_DMIL = 2048,
90 ALLOW_MIL = 4096,
91 ALLOW_IN = 8192,
93 ALLOW_METRIC = ALLOW_NM | ALLOW_UM | ALLOW_MM |
94 ALLOW_CM | ALLOW_M | ALLOW_KM,
95 ALLOW_IMPERIAL = ALLOW_CMIL | ALLOW_DMIL | ALLOW_MIL | ALLOW_IN,
96 /* This is all units allowed in parse_l.l */
97 #if 0
98 ALLOW_READABLE = ALLOW_NM | ALLOW_UM | ALLOW_MM |
99 ALLOW_M | ALLOW_KM | ALLOW_CMIL |
100 ALLOW_MIL | ALLOW_IN,
101 #else
102 ALLOW_READABLE = ALLOW_MIL | ALLOW_MM,
103 #endif
105 ALLOW_ALL = ~ALLOW_DMIL
108 enum e_family { METRIC, IMPERIAL };
109 enum e_suffix {
110 NO_SUFFIX, /* no suffix */
111 SUFFIX, /* suffix, prefixed with ' ' */
112 FILE_MODE_NO_SUFFIX, /* no suffix, force '.' as decimal */
113 FILE_MODE /* suffix, force '.' as decimal */
116 struct unit {
117 int index; /* Index into Unit[] list */
118 const char *suffix;
119 const char *in_suffix; /* internationalized suffix */
120 char printf_code;
121 double scale_factor;
122 enum e_family family;
123 enum e_allow allow;
124 int default_prec;
125 /* used for gui spinboxes */
126 double step_tiny;
127 double step_small;
128 double step_medium;
129 double step_large;
130 double step_huge;
131 /* aliases -- right now we only need 1 ("inch"->"in"), add as needed */
132 const char *alias[1];
135 struct increments {
136 const char *suffix;
137 /* key g and <shift>g value */
138 Coord grid;
139 Coord grid_min;
140 Coord grid_max;
141 /* key s and <shift>s value */
142 Coord size;
143 Coord size_min;
144 Coord size_max;
145 /* key l and <shift>l value */
146 Coord line;
147 Coord line_min;
148 Coord line_max;
149 /* key k and <shift>k value */
150 Coord clear;
151 Coord clear_min;
152 Coord clear_max;
155 void initialize_units();
157 const Unit *get_unit_struct (const char *suffix);
158 const Unit *get_unit_list (void);
159 int get_n_units (void);
160 double coord_to_unit (const Unit *, Coord);
161 Coord unit_to_coord (const Unit *, double);
162 Increments *get_increments_struct (enum e_family family);
163 void copy_nonzero_increments (Increments *dst, const Increments *src);
164 enum e_allow set_allow_readable(enum e_allow new_mask);
166 int pcb_fprintf(FILE *f, const char *fmt, ...);
167 int pcb_sprintf(char *string, const char *fmt, ...);
168 int pcb_printf(const char *fmt, ...);
169 char *pcb_g_strdup_printf(const char *fmt, ...);
170 gchar *pcb_vprintf(const char *fmt, va_list args);
172 #endif