pcb 4.1.1
An interactive printed circuit board layout editor.
|
This file defines a wrapper around sprintf, that defines new specifiers that take pcb Coord objects as input. More...
Go to the source code of this file.
Data Structures | |
struct | unit |
struct | increments |
Enumerations | |
enum | e_allow { NO_PRINT = 0, ALLOW_NM = 1, ALLOW_UM = 2, ALLOW_MM = 4, ALLOW_CM = 8, ALLOW_M = 16, ALLOW_KM = 32, ALLOW_CMIL = 1024, ALLOW_DMIL = 2048, ALLOW_MIL = 4096, ALLOW_IN = 8192, ALLOW_METRIC, ALLOW_IMPERIAL = ALLOW_CMIL | ALLOW_DMIL | ALLOW_MIL | ALLOW_IN, ALLOW_READABLE = ALLOW_MIL | ALLOW_MM, ALLOW_ALL = ~ALLOW_DMIL } |
enum | e_family { METRIC, IMPERIAL } |
enum | e_suffix { NO_SUFFIX, SUFFIX, FILE_MODE_NO_SUFFIX, FILE_MODE } |
Functions | |
void | initialize_units () |
Initialize non-static data for pcb-printf. | |
const Unit * | get_unit_struct (const char *suffix) |
Obtain a unit object from its suffix. | |
const Unit * | get_unit_list (void) |
Returns the master unit list. | |
int | get_n_units (void) |
Returns the length of the master unit list. | |
double | coord_to_unit (const Unit *, Coord) |
Convert a pcb coord to the given unit. | |
Coord | unit_to_coord (const Unit *, double) |
Convert a given unit to pcb coords. | |
Increments * | get_increments_struct (enum e_family family) |
Obtain the increment values for a given family of units. | |
void | copy_nonzero_increments (Increments *dst, const Increments *src) |
enum e_allow | set_allow_readable (enum e_allow new_mask) |
Get/set a mask of units to use when saving .pcb files. | |
int | pcb_fprintf (FILE *f, const char *fmt,...) |
Wrapper for pcb_vprintf that outputs to a file. | |
int | pcb_snprintf (char *string, size_t size, const char *fmt,...) |
Wrapper for pcb_vprintf that outputs to a string. | |
int | pcb_printf (const char *fmt,...) |
Wrapper for pcb_vprintf that outputs to stdout. | |
char * | pcb_g_strdup_printf (const char *fmt,...) |
Wrapper for pcb_vprintf that outputs to a newly allocated string. | |
gchar * | pcb_vprintf (const char *fmt, va_list args) |
Main pcb-printf function. |
This file defines a wrapper around sprintf, that defines new specifiers that take pcb Coord objects as input.
There is a fair bit of nasty (repetitious) code in here, but I feel the gain in clarity for output code elsewhere in the project will make it worth it.
The new specifiers are:
mk output a measure in km
mf output a measure in meters
me output a measure in cm
mm output a measure in mm
mu output a measure in um
mn output a measure in nm
mM output a measure in scaled (mm/um) metric
ml output a measure in mil
mc output a measure in cmil
mt output a measure in 1/10 of mils (for Excellon drill files)
mL output a measure in scaled (mil/in) imperial
ms output a measure in most natural mm/mil units
mS output a measure in most natural scaled units
md output a pair of measures in most natural mm/mil units
mD output a pair of measures in most natural scaled units
m3 output 3 measures in most natural scaled units
...
m9 output 9 measures in most natural scaled units
m* output a measure with unit given as an additional const char* parameter
m+ accepts an e_allow parameter that masks all subsequent "natural" (S/D/3/.../9) specifiers to only use certain units
mr output a measure in a unit readable by parse_l.l (this will always append a unit suffix)
ma output an angle in degrees (expects degrees)
These accept the usual printf modifiers for f, as well as
$ output a unit suffix after the measure
# prevents all scaling for mS/D/1/.../9 (this should ONLY be used for debug code since its output exposes pcb's base units). ` always use '.' as decimal separator (note that mr uses this by default).
KNOWN ISSUES:
No support for zu size_t printf spec
PCB, interactive printed circuit board design
Copyright (C) 2011 Andrew Poelstra
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Contact addresses for paper mail and Email: Andrew Poelstra, 16966 60A Ave, V3S 8X5 Surrey, BC, Canada asp11@sfu.ca
Definition in file pcb-printf.h.
enum e_allow |
NO_PRINT | |
ALLOW_NM | |
ALLOW_UM | |
ALLOW_MM | |
ALLOW_CM | |
ALLOW_M | |
ALLOW_KM | |
ALLOW_CMIL | |
ALLOW_DMIL | |
ALLOW_MIL | |
ALLOW_IN | |
ALLOW_METRIC | |
ALLOW_IMPERIAL | |
ALLOW_READABLE | |
ALLOW_ALL |
Definition at line 84 of file pcb-printf.h.
enum e_family |
Definition at line 113 of file pcb-printf.h.
enum e_suffix |
NO_SUFFIX |
no suffix. |
SUFFIX |
suffix, prefixed with ' '. |
FILE_MODE_NO_SUFFIX |
no suffix, force '.' as decimal. |
FILE_MODE |
suffix, force '.' as decimal. |
Definition at line 114 of file pcb-printf.h.
Convert a pcb coord to the given unit.
[in] | unit | The unit to convert to. |
[in] | x | The quantity to convert. |
Definition at line 271 of file pcb-printf.c.
References COORD_TO_MIL, COORD_TO_MM, unit::family, METRIC, and unit::scale_factor.
Referenced by cursor_pos_to_widget(), gcode_do_export(), ghid_coord_entry_change_unit(), ghid_coord_entry_new(), ghid_coord_entry_set_value(), and mark_delta_to_widget().
void copy_nonzero_increments | ( | Increments * | dst, |
const Increments * | src | ||
) |
Definition at line 212 of file pcb-printf.c.
References increments::clear, increments::clear_max, increments::clear_min, increments::grid, increments::grid_max, increments::grid_min, increments::line, increments::line_max, increments::line_min, increments::size, increments::size_max, and increments::size_min.
Referenced by REGISTER_ATTRIBUTES().
Increments* get_increments_struct | ( | enum e_family | family | ) |
Obtain the increment values for a given family of units.
[in] | family | One of METRIC or IMPERIAL. |
Definition at line 251 of file pcb-printf.c.
References IMPERIAL, increments_imperial, increments_metric, and METRIC.
Referenced by config_increments_tab_create(), config_sizes_apply(), real_load_pcb(), REGISTER_ATTRIBUTES(), and SetUnits().
int get_n_units | ( | void | ) |
Returns the length of the master unit list.
Definition at line 239 of file pcb-printf.c.
References N_UNITS.
Referenced by ghid_attribute_dialog(), ghid_coord_entry_popup_cb(), and usage_attr().
const Unit* get_unit_list | ( | void | ) |
Returns the master unit list.
This may not be modified.
Definition at line 231 of file pcb-printf.c.
References Units.
Referenced by bom_do_export(), gcode_do_export(), ghid_attribute_dialog(), ghid_coord_entry_popup_cb(), hid_save_settings(), print_defaults_1(), and usage_attr().
const Unit* get_unit_struct | ( | const char * | const_suffix | ) |
Obtain a unit object from its suffix.
Looks up a given suffix in the main units array. Internationalized unit suffixes are not supported, though pluralized units are, for backward-compatibility.
[in] | const_suffix | The suffix to look up. |
Definition at line 175 of file pcb-printf.c.
References N_UNITS.
Referenced by bom_do_export(), bom_get_export_options(), FlagUnitsMil(), FlagUnitsMm(), FontEdit(), gcode_get_export_options(), GetValueEx(), ghid_coord_text_changed_cb(), grid_units_button_cb(), hid_parse_command_line(), hid_set_attribute(), menu_item_activate_cb(), parse_optionv(), real_load_pcb(), REGISTER_ATTRIBUTES(), SetUnits(), and units_cb().
void initialize_units | ( | ) |
Initialize non-static data for pcb-printf.
Assigns each unit its index for quick access through the main units array, and internationalize the units for GUI display.
Definition at line 111 of file pcb-printf.c.
References _, unit::in_suffix, unit::index, and N_UNITS.
Referenced by main().
int pcb_fprintf | ( | FILE * | fh, |
const char * | fmt, | ||
... | |||
) |
Wrapper for pcb_vprintf that outputs to a file.
[in] | fh | File to output to. |
[in] | fmt | Format specifier. |
Definition at line 723 of file pcb-printf.c.
References args, and pcb_vprintf().
Referenced by ActionRenumber(), corner(), debug_pline(), debug_polygon(), eps_draw_arc(), eps_draw_line(), eps_draw_rect(), eps_fill_circle(), eps_fill_polygon(), eps_fill_rect(), eps_hid_export_to_file(), fill_polyarea(), fprintAperture(), gcode_do_export(), gcode_start_gcode(), gerber_draw_arc(), gerber_set_layer(), ghid_config_files_write(), hid_save_settings(), maybe_pull_1(), plotpolygon(), poly_Valid(), print_defaults_1(), PrintBOM(), ps_draw_arc(), ps_draw_line(), ps_draw_rect(), ps_fill_circle(), ps_fill_polygon(), ps_fill_rect(), ps_set_layer(), ps_start_file(), use_gc(), WriteElementData(), WriteLayerData(), WritePCBDataHeader(), WritePCBFontData(), WritePCBRatData(), and WriteViaData().
char* pcb_g_strdup_printf | ( | const char * | fmt, |
... | |||
) |
Wrapper for pcb_vprintf that outputs to a newly allocated string.
[in] | fmt | Format specifier. |
Definition at line 775 of file pcb-printf.c.
References args, and pcb_vprintf().
Referenced by cursor_pos_to_widget(), ghid_config_handle_units_changed(), ghid_coord_entry_output_cb(), ghid_set_cursor_position_labels(), ghid_set_status_line_label(), ghid_violation_renderer_set_property(), idle_proc(), lesstif_update_status_line(), make_route_string(), mark_delta_to_widget(), and SetGrid().
int pcb_printf | ( | const char * | fmt, |
... | |||
) |
Wrapper for pcb_vprintf that outputs to stdout.
[in] | fmt | Format specifier. |
Definition at line 751 of file pcb-printf.c.
References args, and pcb_vprintf().
Referenced by arc_callback(), arc_endpoint_is(), check_point_in_pad(), create_arc(), create_line(), Debug(), debumpify(), dist_lp(), find_pair(), find_pair_arc_callback(), find_pair_line_callback(), find_pair_padline_callback(), find_pair_pinline_callback(), find_pairs_1(), fix_arc_extra(), gp_point_2(), gp_point_force(), import_clusters(), import_route(), info(), lesstif_draw_arc(), lesstif_draw_line(), lesstif_fill_circle(), line_callback(), mark_line_for_deletion(), maybe_pull_1(), orthopull(), print_extra(), set_gc(), TracePath(), and vianudge().
int pcb_snprintf | ( | char * | string, |
size_t | size, | ||
const char * | fmt, | ||
... | |||
) |
Wrapper for pcb_vprintf that outputs to a string.
[in] | string | Pointer to string to output into. |
[in] | size | Maximum length of this string, including the terminating null byte. |
[in] | fmt | Format specifier. |
The returned string is guaranteed to be null terminated, even if truncated.
Definition at line 696 of file pcb-printf.c.
References args, and pcb_vprintf().
Referenced by ActionImport(), corner_name(), gcode_do_export(), gsvit_write_xcentroids(), idle_proc(), lesstif_attribute_dialog(), ReportAllNetLengths(), ReportDialog(), ReportDrills(), ReportNetLength(), ReportNetLengthByName(), sz_val2str(), and update_one_value().
gchar* pcb_vprintf | ( | const char * | fmt, |
va_list | args | ||
) |
Main pcb-printf function.
This is a printf wrapper that accepts new format specifiers to output pcb coords as various units. See the comment at the top of pcb-printf.h for full details.
[in] | fmt | Format specifier. |
[in] | args | Arguments to specifier. |
Definition at line 484 of file pcb-printf.c.
References unit::allow, ALLOW_ALL, ALLOW_CMIL, ALLOW_IMPERIAL, ALLOW_METRIC, ALLOW_MIL, ALLOW_MM, buffer, CoordsToString(), FALSE, FILE_MODE, FILE_MODE_NO_SUFFIX, N_UNITS, NO_SUFFIX, set_allow_readable(), SUFFIX, and TRUE.
Referenced by append_drc_dialog_message(), ghid_logv(), lesstif_logv(), pcb_fprintf(), pcb_g_strdup_printf(), pcb_printf(), and pcb_snprintf().
Get/set a mask of units to use when saving .pcb files.
If passed 0, returns the current mask of units to use in a .pcb file; if passed anything else, replaces the current mask. This mask should only contain units which are readable by recent versions of pcb; currently this means only ALLOW_MIL and ALLOW_MM. (Versions prior to 20110703 nominally support other units, but in fact the scaling calculations are incorrect so the wrong values will be read! See commit 750a1c5 for more details.)
Definition at line 134 of file pcb-printf.c.
References ALLOW_READABLE.
Referenced by pcb_vprintf(), and WritePCB().
Convert a given unit to pcb coords.
[in] | unit | The unit to convert from. |
[in] | x | The quantity to convert. |
Definition at line 290 of file pcb-printf.c.
References DOUBLE_TO_COORD, unit::family, METRIC, MIL_TO_COORD, MM_TO_COORD, and unit::scale_factor.
Referenced by GetValueEx(), ghid_coord_text_changed_cb(), and ghid_coord_value_changed_cb().