pcb 4.1.1
An interactive printed circuit board layout editor.
|
Implementation of printf wrapper to output pcb coords and angles. More...
Go to the source code of this file.
Defines | |
#define | MM_TO_COORD3(a, b, c) MM_TO_COORD (a), MM_TO_COORD (b), MM_TO_COORD (c) |
#define | MIL_TO_COORD3(a, b, c) MIL_TO_COORD (a), MIL_TO_COORD (b), MIL_TO_COORD (c) |
#define | MM_TO_COORD5(a, b, c, d, e) |
#define | MIL_TO_COORD5(a, b, c, d, e) |
#define | N_UNITS ((int) (sizeof Units / sizeof Units[0])) |
Functions | |
void | initialize_units () |
Initialize non-static data for pcb-printf. | |
enum e_allow | set_allow_readable (enum e_allow new_mask) |
Get/set a mask of units to use when saving .pcb files. | |
const Unit * | get_unit_struct (const char *const_suffix) |
Obtain a unit object from its suffix. | |
void | copy_nonzero_increments (Increments *dst, const Increments *src) |
const Unit * | get_unit_list (void) |
Returns the master unit list. | |
int | get_n_units (void) |
Returns the length of the master unit list. | |
Increments * | get_increments_struct (enum e_family family) |
Obtain the increment values for a given family of units. | |
double | coord_to_unit (const Unit *unit, Coord x) |
Convert a pcb coord to the given unit. | |
Coord | unit_to_coord (const Unit *unit, double x) |
Convert a given unit to pcb coords. | |
static int | min_sig_figs (double d) |
static gchar * | CoordsToString (Coord coord[], int n_coords, const char *printf_spec, enum e_allow allow, enum e_suffix suffix_type) |
Internal coord-to-string converter for pcb-printf. | |
gchar * | pcb_vprintf (const char *fmt, va_list args) |
Main pcb-printf function. | |
int | pcb_snprintf (char *string, size_t size, const char *fmt,...) |
Wrapper for pcb_vprintf that outputs to a string. | |
int | pcb_fprintf (FILE *fh, const char *fmt,...) |
Wrapper for pcb_vprintf that outputs to a file. | |
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. | |
Variables | |
static Unit | Units [] |
| |
static Increments | increments_metric |
static Increments | increments_imperial |
Implementation of printf wrapper to output pcb coords and angles.
For details of all supported specifiers, see the comment at the top of pcb-printf.h
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 St, 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.c.
Definition at line 49 of file pcb-printf.c.
#define MIL_TO_COORD5 | ( | a, | |
b, | |||
c, | |||
d, | |||
e | |||
) |
MIL_TO_COORD (a), MIL_TO_COORD (b), MIL_TO_COORD (c), \ MIL_TO_COORD (d), MIL_TO_COORD (e)
Definition at line 52 of file pcb-printf.c.
Definition at line 48 of file pcb-printf.c.
#define MM_TO_COORD5 | ( | a, | |
b, | |||
c, | |||
d, | |||
e | |||
) |
MM_TO_COORD (a), MM_TO_COORD (b), MM_TO_COORD (c), \ MM_TO_COORD (d), MM_TO_COORD (e)
Definition at line 50 of file pcb-printf.c.
Definition at line 102 of file pcb-printf.c.
Referenced by CoordsToString(), get_n_units(), get_unit_struct(), initialize_units(), and pcb_vprintf().
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().
static gchar* CoordsToString | ( | Coord | coord[], |
int | n_coords, | ||
const char * | printf_spec, | ||
enum e_allow | allow, | ||
enum e_suffix | suffix_type | ||
) | [static] |
Internal coord-to-string converter for pcb-printf.
Converts a (group of) measurement(s) to a comma-deliminated string, with appropriate units. If more than one coord is given, the list is enclosed in parens to make the scope of the unit suffix clear.
[in] | coord | Array of coords to convert. |
[in] | n_coords | Number of coords in array. |
[in] | printf_spec | printf sub-specifier to use with f. |
[in] | e_allow | Bitmap of units the function may use. |
[in] | suffix_type | Whether to add a suffix. |
Definition at line 334 of file pcb-printf.c.
References ALLOW_ALL, ALLOW_IMPERIAL, ALLOW_METRIC, COORD_TO_MIL, COORD_TO_MM, FALSE, FILE_MODE, FILE_MODE_NO_SUFFIX, IMPERIAL, malloc(), METRIC, min_sig_figs(), n, N_UNITS, NO_SUFFIX, SUFFIX, and unit::suffix.
Referenced by pcb_vprintf().
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().
static int min_sig_figs | ( | double | d | ) | [static] |
Definition at line 301 of file pcb-printf.c.
Referenced by CoordsToString().
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().
Increments increments_imperial [static] |
{ "mil", MIL_TO_COORD3 (5, 1, 25), MIL_TO_COORD3 (10, 1, 10), MIL_TO_COORD3 (5, 0.5, 10), }
Definition at line 156 of file pcb-printf.c.
Referenced by get_increments_struct().
Increments increments_metric [static] |
{ "mm", MM_TO_COORD3 (0.1, 0.01, 1.0), MM_TO_COORD3 (0.2, 0.01, 0.5), MM_TO_COORD3 (0.1, 0.005, 0.5), }
Definition at line 149 of file pcb-printf.c.
Referenced by get_increments_struct().
These should be kept in order of smallest scale_factor to largest -- the code uses this ordering when finding the best scale to use for a group of measures.
Definition at line 62 of file pcb-printf.c.
Referenced by get_unit_list().