pcb 4.1.1
An interactive printed circuit board layout editor.

pcb-printf.c File Reference

Implementation of printf wrapper to output pcb coords and angles. More...

#include "global.h"
#include "pcb-printf.h"
Include dependency graph for pcb-printf.c:

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 Unitget_unit_struct (const char *const_suffix)
 Obtain a unit object from its suffix.
void copy_nonzero_increments (Increments *dst, const Increments *src)
const Unitget_unit_list (void)
 Returns the master unit list.
int get_n_units (void)
 Returns the length of the master unit list.
Incrementsget_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

Detailed Description

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


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


Define Documentation

#define MIL_TO_COORD3 (   a,
  b,
  c 
)    MIL_TO_COORD (a), MIL_TO_COORD (b), MIL_TO_COORD (c)

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

#define MIL_TO_COORD5 (   a,
  b,
  c,
  d,
 
)
Value:

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

#define MM_TO_COORD3 (   a,
  b,
  c 
)    MM_TO_COORD (a), MM_TO_COORD (b), MM_TO_COORD (c)

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

#define MM_TO_COORD5 (   a,
  b,
  c,
  d,
 
)
Value:

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

#define N_UNITS   ((int) (sizeof Units / sizeof Units[0]))

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

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.

Parameters:
[in]coordArray of coords to convert.
[in]n_coordsNumber of coords in array.
[in]printf_specprintf sub-specifier to use with f.
[in]e_allowBitmap of units the function may use.
[in]suffix_typeWhether to add a suffix.
Returns:
A string containing the formatted coords. Must be freed with g_free.

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

Here is the call graph for this function:

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

static int min_sig_figs ( double  d) [static]

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

Referenced by CoordsToString().

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


Variable Documentation

Initial value:
 {
  "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().

Initial value:
 {
  "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().

Unit Units[] [static]

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