pcb 4.1.1
An interactive printed circuit board layout editor.

gerber.c File Reference

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "config.h"
#include "global.h"
#include "data.h"
#include "misc.h"
#include "error.h"
#include "draw.h"
#include "pcb-printf.h"
#include "hid.h"
#include "hid_draw.h"
#include "../hidint.h"
#include "hid/common/hidnogui.h"
#include "hid/common/draw_helpers.h"
#include "hid/common/hidinit.h"
Include dependency graph for gerber.c:

Go to the source code of this file.

Data Structures

struct  aperture
struct  ApertureList
struct  PendingDrills
struct  hid_gc_struct

Defines

#define CRASH   fprintf(stderr, "HID error: pcb called unimplemented Gerber function %s.\n", __FUNCTION__); abort()
#define gerberX(pcb, x)   ((Coord) (x))
#define gerberY(pcb, y)   ((Coord) ((pcb)->MaxHeight - (y)))
#define gerberXOffset(pcb, x)   ((Coord) (x))
#define gerberYOffset(pcb, y)   ((Coord) (-(y)))
#define gerberDrX(pcb, x)   ((Coord) (x))
#define gerberDrY(pcb, y)   ((Coord) ((pcb)->MaxHeight - (y)))
#define print_xcoord(file, pcb, val)   pcb_fprintf(file, x_convspec, gerberX(pcb, val))
#define print_ycoord(file, pcb, val)   pcb_fprintf(file, y_convspec, gerberY(pcb, val))
#define DCODE_BASE   11
#define AUTO_OUTLINE_WIDTH   MIL_TO_COORD(8)
#define COPY_OUTLINE_NONE   0
#define COPY_OUTLINE_MASK   1
#define COPY_OUTLINE_SILK   2
#define COPY_OUTLINE_ALL   3
#define NAME_STYLE_FIXED   0
#define NAME_STYLE_SINGLE   1
#define NAME_STYLE_FIRST   2
#define NAME_STYLE_EAGLE   3
#define NAME_STYLE_HACKVANA   4
#define NAME_STYLE_OSHPARK   5

Typedefs

typedef enum ApertureShape ApertureShape
typedef struct aperture Aperture
typedef struct hid_gc_struct hid_gc_struct

Enumerations

enum  ApertureShape {
  ROUND, OCTAGON, SQUARE, ROUNDCLEAR,
  SQUARECLEAR, THERMAL
}

Functions

static HID_Attributegerber_get_export_options (int *n)
static void gerber_do_export (HID_Attr_Val *options)
static void gerber_parse_arguments (int *argc, char ***argv)
static int gerber_set_layer (const char *name, int group, int empty)
static hidGC gerber_make_gc (void)
static void gerber_destroy_gc (hidGC gc)
static void gerber_use_mask (enum mask_mode mode)
static void gerber_set_color (hidGC gc, const char *name)
static void gerber_set_line_cap (hidGC gc, EndCapStyle style)
static void gerber_set_line_width (hidGC gc, Coord width)
static void gerber_set_draw_xor (hidGC gc, int _xor)
static void gerber_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void gerber_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height, Angle start_angle, Angle delta_angle)
static void gerber_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void gerber_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
static void gerber_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void gerber_calibrate (double xval, double yval)
static void gerber_set_crosshair (int x, int y, int action)
static void gerber_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
static void initApertureList (ApertureList *list)
static void deinitApertureList (ApertureList *list)
static void resetApertures ()
static ApertureaddAperture (ApertureList *list, Coord width, ApertureShape shape)
static AperturefindAperture (ApertureList *list, Coord width, ApertureShape shape)
static void fprintAperture (FILE *f, Aperture *aptr)
static ApertureListsetLayerApertureList (int layer_idx)
static int layer_stack_sort (const void *va, const void *vb)
static void maybe_close_f (FILE *f)
static void assign_eagle_file_suffix (char *dest, int idx)
static void assign_hackvana_file_suffix (char *dest, int idx)
static void assign_oshpark_file_suffix (char *dest, int idx)
 Very similar to layer_type_to_file_name() but appends only a three-character suffix compatible with OSH Park's naming requirements.
static void assign_file_suffix (char *dest, int idx, const char *layer_name)
static int drill_sort (const void *va, const void *vb)
static void use_gc (hidGC gc, int radius)
void hid_gerber_init ()

Variables

static int verbose
static int all_layers
static int metric
static char * x_convspec
static char * y_convspec
static int is_mask
static int was_drill
static int is_drill
static enum mask_mode current_mask
static int flash_drills
static int copy_outline_mode
static int name_style
static LayerTypeoutline_layer
static ApertureListlayer_aptr_list
static ApertureListcurr_aptr_list
static int layer_list_max
static int layer_list_idx
PendingDrillspending_drills = NULL
int n_pending_drills = 0
int max_pending_drills = 0
static int aperture_count
static HID gerber_hid
static HID_DRAW gerber_graphics
static FILE * f = NULL
static char * filename = NULL
static char * filesuff = NULL
static char * layername = NULL
static int lncount = 0
static int finding_apertures = 0
static int pagecount = 0
static int linewidth = -1
static int lastgroup = -1
static int lastcap = -1
static int print_group [MAX_GROUP]
static int print_layer [MAX_ALL_LAYER]
static int lastX
static int lastY
static const char * copy_outline_names []
static const char * name_style_names []
static HID_Attribute gerber_options []
static HID_Attr_Val gerber_values [NUM_OPTIONS]
static BoxType region

Define Documentation

#define AUTO_OUTLINE_WIDTH   MIL_TO_COORD(8)

Definition at line 149 of file gerber.c.

Referenced by gerber_set_layer().

#define COPY_OUTLINE_ALL   3

Referenced by gerber_set_layer().

#define COPY_OUTLINE_MASK   1

Referenced by gerber_set_layer().

#define COPY_OUTLINE_NONE   0
#define COPY_OUTLINE_SILK   2

Referenced by gerber_set_layer().

#define CRASH   fprintf(stderr, "HID error: pcb called unimplemented Gerber function %s.\n", __FUNCTION__); abort()

Definition at line 40 of file gerber.c.

Referenced by gerber_calibrate().

#define DCODE_BASE   11

Definition at line 115 of file gerber.c.

Referenced by addAperture().

#define gerberDrX (   pcb,
  x 
)    ((Coord) (x))

Definition at line 77 of file gerber.c.

Referenced by gerber_set_layer().

#define gerberDrY (   pcb,
  y 
)    ((Coord) ((pcb)->MaxHeight - (y)))

Definition at line 78 of file gerber.c.

Referenced by gerber_set_layer().

#define gerberX (   pcb,
  x 
)    ((Coord) (x))

Definition at line 71 of file gerber.c.

Referenced by gerber_draw_arc().

#define gerberXOffset (   pcb,
  x 
)    ((Coord) (x))

Definition at line 73 of file gerber.c.

Referenced by gerber_draw_arc().

#define gerberY (   pcb,
  y 
)    ((Coord) ((pcb)->MaxHeight - (y)))

Definition at line 72 of file gerber.c.

Referenced by gerber_draw_arc().

#define gerberYOffset (   pcb,
  y 
)    ((Coord) (-(y)))

Definition at line 74 of file gerber.c.

Referenced by gerber_draw_arc().

#define NAME_STYLE_EAGLE   3

Referenced by assign_file_suffix().

#define NAME_STYLE_FIRST   2

Referenced by assign_file_suffix().

#define NAME_STYLE_FIXED   0

Referenced by assign_file_suffix().

#define NAME_STYLE_HACKVANA   4

Referenced by assign_file_suffix().

#define NAME_STYLE_OSHPARK   5

Referenced by assign_file_suffix().

#define NAME_STYLE_SINGLE   1

Referenced by assign_file_suffix().

#define print_xcoord (   file,
  pcb,
  val 
)    pcb_fprintf(file, x_convspec, gerberX(pcb, val))
#define print_ycoord (   file,
  pcb,
  val 
)    pcb_fprintf(file, y_convspec, gerberY(pcb, val))

Typedef Documentation

typedef struct aperture Aperture

Definition at line 111 of file gerber.c.

typedef struct hid_gc_struct hid_gc_struct

Enumeration Type Documentation

Enumerator:
ROUND 
OCTAGON 
SQUARE 
ROUNDCLEAR 
SQUARECLEAR 
THERMAL 

Definition at line 102 of file gerber.c.


Function Documentation

static Aperture* addAperture ( ApertureList list,
Coord  width,
ApertureShape  shape 
) [static]

Definition at line 194 of file gerber.c.

References aperture_count, ApertureList::count, ApertureList::data, aperture::dCode, DCODE_BASE, malloc(), aperture::next, aperture::shape, and aperture::width.

Referenced by findAperture().

Here is the call graph for this function:

static void assign_eagle_file_suffix ( char *  dest,
int  idx 
) [static]
static void assign_file_suffix ( char *  dest,
int  idx,
const char *  layer_name 
) [static]
static void assign_hackvana_file_suffix ( char *  dest,
int  idx 
) [static]
static void assign_oshpark_file_suffix ( char *  dest,
int  idx 
) [static]

Very similar to layer_type_to_file_name() but appends only a three-character suffix compatible with OSH Park's naming requirements.

Note:
The unplated drill file with the ".TXT" extension will be merged when the zip file is processed by OSH Park (after uploading).
Warning:
Blind and buried vias are not supported by OSH Park.
Currently 4 layer boards is the maximum OSH Park supports.

Definition at line 585 of file gerber.c.

References BOTTOM_SIDE, PCBType::Data, GetLayerGroupNumberByNumber(), GetLayerGroupNumberBySide(), DataType::Layer, PCBType::LayerGroups, LayerType::Name, LayerGroupType::Number, PCB, SL, and TOP_SIDE.

Referenced by assign_file_suffix().

Here is the call graph for this function:

static void deinitApertureList ( ApertureList list) [static]

Definition at line 164 of file gerber.c.

References ApertureList::data, initApertureList(), and aperture::next.

Referenced by resetApertures().

Here is the call graph for this function:

static int drill_sort ( const void *  va,
const void *  vb 
) [static]

Definition at line 793 of file gerber.c.

References PendingDrills::diam, PendingDrills::x, and PendingDrills::y.

Referenced by gerber_set_layer().

static Aperture* findAperture ( ApertureList list,
Coord  width,
ApertureShape  shape 
) [static]

Definition at line 215 of file gerber.c.

References addAperture(), ApertureList::data, aperture::next, aperture::shape, and aperture::width.

Referenced by gerber_set_layer(), and use_gc().

Here is the call graph for this function:

static void fprintAperture ( FILE *  f,
Aperture aptr 
) [static]

Definition at line 234 of file gerber.c.

References COS_22_5_DEGREE, aperture::dCode, metric, OCTAGON, pcb_fprintf(), ROUND, ROUNDCLEAR, aperture::shape, SQUARE, SQUARECLEAR, THERMAL, and aperture::width.

Referenced by gerber_set_layer().

Here is the call graph for this function:

static void gerber_calibrate ( double  xval,
double  yval 
) [static]

Definition at line 1398 of file gerber.c.

References CRASH.

Referenced by hid_gerber_init().

static void gerber_destroy_gc ( hidGC  gc) [static]

Definition at line 1032 of file gerber.c.

Referenced by hid_gerber_init().

static void gerber_draw_arc ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  width,
Coord  height,
Angle  start_angle,
Angle  delta_angle 
) [static]

Definition at line 1202 of file gerber.c.

References abs, f, gerber_draw_line(), gerberX, gerberXOffset, gerberY, gerberYOffset, lastX, lastY, m, M_PI, max, metric, PCB, pcb_fprintf(), print_xcoord, print_ycoord, start_angle, TO_RADIANS, use_gc(), and hid_gc_struct::width.

Referenced by hid_gerber_init().

Here is the call graph for this function:

static void gerber_draw_line ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]

Definition at line 1138 of file gerber.c.

References hid_gc_struct::cap, f, gerber_fill_polygon(), lastX, lastY, m, M_PI, PCB, print_xcoord, print_ycoord, Square_Cap, use_gc(), hid_gc_struct::width, x, and y.

Referenced by gerber_draw_arc(), gerber_draw_rect(), and hid_gerber_init().

Here is the call graph for this function:

static void gerber_draw_rect ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]

Definition at line 1129 of file gerber.c.

References gerber_draw_line().

Referenced by hid_gerber_init().

Here is the call graph for this function:

static void gerber_fill_circle ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  radius 
) [static]
static void gerber_fill_polygon ( hidGC  gc,
int  n_coords,
Coord x,
Coord y 
) [static]

Definition at line 1324 of file gerber.c.

References current_mask, f, HID_MASK_BEFORE, is_mask, lastX, lastY, m, PCB, print_xcoord, print_ycoord, and use_gc().

Referenced by gerber_draw_line(), gerber_fill_rect(), and hid_gerber_init().

Here is the call graph for this function:

static void gerber_fill_rect ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
) [static]

Definition at line 1382 of file gerber.c.

References gerber_fill_polygon(), x, and y.

Referenced by hid_gerber_init().

Here is the call graph for this function:

static HID_Attribute * gerber_get_export_options ( int *  n) [static]

Definition at line 426 of file gerber.c.

References derive_default_filename(), PCBType::Filename, gerber_options, and PCB.

Referenced by gerber_do_export(), and hid_gerber_init().

Here is the call graph for this function:

static hidGC gerber_make_gc ( void  ) [static]

Definition at line 1024 of file gerber.c.

References hid_gc_struct::cap, and Trace_Cap.

Referenced by hid_gerber_init().

static void gerber_parse_arguments ( int *  argc,
char ***  argv 
) [static]

Definition at line 786 of file gerber.c.

References hid_parse_command_line(), and hid_register_attributes().

Referenced by hid_gerber_init().

Here is the call graph for this function:

static void gerber_set_color ( hidGC  gc,
const char *  name 
) [static]

Definition at line 1044 of file gerber.c.

References hid_gc_struct::color, hid_gc_struct::drill, and hid_gc_struct::erase.

Referenced by hid_gerber_init().

static void gerber_set_crosshair ( int  x,
int  y,
int  action 
) [static]

Definition at line 1404 of file gerber.c.

Referenced by hid_gerber_init().

static void gerber_set_draw_xor ( hidGC  gc,
int  _xor 
) [static]

Definition at line 1079 of file gerber.c.

Referenced by hid_gerber_init().

static void gerber_set_line_cap ( hidGC  gc,
EndCapStyle  style 
) [static]

Definition at line 1067 of file gerber.c.

References hid_gc_struct::cap, and style.

Referenced by hid_gerber_init().

static void gerber_set_line_width ( hidGC  gc,
Coord  width 
) [static]

Definition at line 1073 of file gerber.c.

References hid_gc_struct::width.

Referenced by hid_gerber_init().

static void gerber_use_mask ( enum mask_mode  mode) [static]

Definition at line 1038 of file gerber.c.

References current_mask.

Referenced by hid_gerber_init().

static void initApertureList ( ApertureList list) [static]

Definition at line 157 of file gerber.c.

References ApertureList::count, and ApertureList::data.

Referenced by deinitApertureList(), and setLayerApertureList().

static int layer_stack_sort ( const void *  va,
const void *  vb 
) [static]

Definition at line 437 of file gerber.c.

References GetLayerGroupNumberByNumber().

Referenced by gerber_do_export().

Here is the call graph for this function:

static void maybe_close_f ( FILE *  f) [static]

Definition at line 451 of file gerber.c.

References was_drill.

Referenced by gerber_do_export(), and gerber_set_layer().

static void resetApertures ( ) [static]

Definition at line 179 of file gerber.c.

References aperture_count, deinitApertureList(), layer_list_idx, and layer_list_max.

Referenced by gerber_do_export().

Here is the call graph for this function:

static ApertureList* setLayerApertureList ( int  layer_idx) [static]

Definition at line 276 of file gerber.c.

References curr_aptr_list, initApertureList(), layer_list_max, and realloc().

Referenced by gerber_set_layer().

Here is the call graph for this function:

static void use_gc ( hidGC  gc,
int  radius 
) [static]

Variable Documentation

int all_layers [static]

Definition at line 85 of file gerber.c.

Referenced by gerber_do_export(), and gerber_set_layer().

int aperture_count [static]

Definition at line 177 of file gerber.c.

Referenced by addAperture(), and resetApertures().

int copy_outline_mode [static]

Definition at line 92 of file gerber.c.

Referenced by gerber_do_export(), and gerber_set_layer().

const char* copy_outline_names[] [static]
Initial value:
 {
#define COPY_OUTLINE_NONE
  "none",
#define COPY_OUTLINE_MASK
  "mask",
#define COPY_OUTLINE_SILK
  "silk",
#define COPY_OUTLINE_ALL
  "all",
  NULL
}

Definition at line 320 of file gerber.c.

Definition at line 133 of file gerber.c.

Referenced by setLayerApertureList().

enum mask_mode current_mask [static]

Definition at line 90 of file gerber.c.

Referenced by gerber_fill_polygon(), gerber_set_layer(), and gerber_use_mask().

char* filesuff = NULL [static]

Definition at line 307 of file gerber.c.

Referenced by gerber_do_export(), and gerber_set_layer().

int finding_apertures = 0 [static]

Definition at line 311 of file gerber.c.

Referenced by gerber_do_export(), and gerber_set_layer().

int flash_drills [static]

Definition at line 91 of file gerber.c.

Referenced by gerber_fill_circle(), and gerber_set_layer().

Definition at line 294 of file gerber.c.

Referenced by hid_gerber_init().

HID gerber_hid [static]

Definition at line 293 of file gerber.c.

Referenced by hid_gerber_init().

Definition at line 348 of file gerber.c.

Referenced by gerber_get_export_options().

HID_Attr_Val gerber_values[NUM_OPTIONS] [static]

Definition at line 423 of file gerber.c.

Referenced by gerber_do_export().

int is_drill [static]

Definition at line 89 of file gerber.c.

Referenced by gerber_fill_circle(), gerber_set_layer(), and use_gc().

int is_mask [static]

Definition at line 88 of file gerber.c.

Referenced by gerber_fill_polygon(), and gerber_set_layer().

int lastcap = -1 [static]

Definition at line 315 of file gerber.c.

Referenced by gerber_do_export(), gerber_set_layer(), ps_fill_rect(), and use_gc().

int lastgroup = -1 [static]

Definition at line 314 of file gerber.c.

Referenced by gerber_do_export(), gerber_set_layer(), and ps_set_layer().

Definition at line 132 of file gerber.c.

int layer_list_idx [static]

Definition at line 135 of file gerber.c.

Referenced by gerber_do_export(), gerber_set_layer(), and resetApertures().

int layer_list_max [static]

Definition at line 134 of file gerber.c.

Referenced by resetApertures(), and setLayerApertureList().

char* layername = NULL [static]

Definition at line 308 of file gerber.c.

Referenced by ActionAttributes(), gcode_do_export(), and gerber_set_layer().

int linewidth = -1 [static]

Definition at line 313 of file gerber.c.

Referenced by gerber_do_export(), gerber_set_layer(), and use_gc().

int lncount = 0 [static]

Definition at line 309 of file gerber.c.

Referenced by gerber_set_layer().

Definition at line 144 of file gerber.c.

Referenced by gerber_fill_circle(), and gerber_set_layer().

int metric [static]

Definition at line 144 of file gerber.c.

Referenced by gerber_fill_circle(), and gerber_set_layer().

int name_style [static]

Definition at line 93 of file gerber.c.

Referenced by assign_file_suffix(), and gerber_do_export().

const char* name_style_names[] [static]
Initial value:
 {
#define NAME_STYLE_FIXED
  "fixed",
#define NAME_STYLE_SINGLE
  "single",
#define NAME_STYLE_FIRST
  "first",
#define NAME_STYLE_EAGLE
  "eagle",
#define NAME_STYLE_HACKVANA
  "hackvana",
#define NAME_STYLE_OSHPARK
  "oshpark",
  NULL
}

Definition at line 332 of file gerber.c.

Definition at line 94 of file gerber.c.

Referenced by AssignDefaultLayerTypes(), and REGISTER_ATTRIBUTES().

int pagecount = 0 [static]

Definition at line 312 of file gerber.c.

Referenced by gerber_do_export(), gerber_set_layer(), and REGISTER_ATTRIBUTES().

Definition at line 143 of file gerber.c.

int print_group[MAX_GROUP] [static]

Definition at line 316 of file gerber.c.

Referenced by gerber_do_export(), and REGISTER_ATTRIBUTES().

int print_layer[MAX_ALL_LAYER] [static]

Definition at line 317 of file gerber.c.

Referenced by gerber_do_export(), gerber_set_layer(), and REGISTER_ATTRIBUTES().

int verbose [static]

Definition at line 84 of file gerber.c.

Referenced by gerber_do_export(), and gerber_set_layer().

int was_drill

Definition at line 88 of file gerber.c.

Referenced by gerber_set_layer(), and maybe_close_f().

char* x_convspec [static]

Definition at line 87 of file gerber.c.

Referenced by gerber_do_export().

char * y_convspec

Definition at line 87 of file gerber.c.

Referenced by gerber_do_export().