pcb 4.1.1
An interactive printed circuit board layout editor.

pcb-printf.h File Reference

This file defines a wrapper around sprintf, that defines new specifiers that take pcb Coord objects as input. More...

This graph shows which files directly or indirectly include this file:

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 Unitget_unit_struct (const char *suffix)
 Obtain a unit object from its suffix.
const Unitget_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.
Incrementsget_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.

Detailed Description

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


Copyright.


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.


Enumeration Type Documentation

enum e_allow
Enumerator:
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
Enumerator:
METRIC 
IMPERIAL 

Definition at line 113 of file pcb-printf.h.

enum e_suffix
Enumerator:
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.


Function Documentation

double coord_to_unit ( const Unit unit,
Coord  x 
)

Convert a pcb coord to the given unit.

Parameters:
[in]unitThe unit to convert to.
[in]xThe quantity to convert.
Returns:
The converted measure.

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().

Increments* get_increments_struct ( enum e_family  family)

Obtain the increment values for a given family of units.

Parameters:
[in]familyOne of METRIC or IMPERIAL.
Returns:
A pointer to the appropriate increments structure.

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.

Parameters:
[in]const_suffixThe suffix to look up.
Returns:
A const pointer to the Unit struct, or NULL if none was found.

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().

char* pcb_g_strdup_printf ( const char *  fmt,
  ... 
)

Wrapper for pcb_vprintf that outputs to a newly allocated string.

Parameters:
[in]fmtFormat specifier.
Returns:
The newly allocated string. Must be freed with g_free.

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().

Here is the call graph for this function:

int pcb_printf ( const char *  fmt,
  ... 
)
int pcb_snprintf ( char *  string,
size_t  size,
const char *  fmt,
  ... 
)

Wrapper for pcb_vprintf that outputs to a string.

Parameters:
[in]stringPointer to string to output into.
[in]sizeMaximum length of this string, including the terminating null byte.
[in]fmtFormat specifier.
Returns:
The length of the written string. In case the string was truncated due to the size limit, it's the length of the string which would have been written if enough space had been available.

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().

Here is the call graph for this function:

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.

Parameters:
[in]fmtFormat specifier.
[in]argsArguments to specifier.
Returns:
A formatted string. Must be freed with g_free.

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().

Here is the call graph for this function:

enum e_allow set_allow_readable ( enum e_allow  new_mask)

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.)

Returns:
the current mask.

Definition at line 134 of file pcb-printf.c.

References ALLOW_READABLE.

Referenced by pcb_vprintf(), and WritePCB().

Coord unit_to_coord ( const Unit unit,
double  x 
)

Convert a given unit to pcb coords.

Parameters:
[in]unitThe unit to convert from.
[in]xThe quantity to convert.
Returns:
The converted measure.

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().