pcb 4.1.1
An interactive printed circuit board layout editor.

gsvit.c File Reference

HID exporter for gsvit. More...

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "global.h"
#include "error.h"
#include "data.h"
#include "misc.h"
#include "rats.h"
#include "find.h"
#include "hid.h"
#include "hid_draw.h"
#include "../hidint.h"
#include "hid/common/hidnogui.h"
#include "hid/common/draw_helpers.h"
#include <gd.h>
#include "xmlout.h"
#include "hid/common/hidinit.h"
#include "pcb-printf.h"
Include dependency graph for gsvit.c:

Go to the source code of this file.

Data Structures

struct  color_struct
struct  hid_gc_struct
struct  gsvit_net_layer
struct  gsvit_netlist
struct  drill_hole
 Structure to represent a single hole. More...
struct  single_size_drills
 Structure to represent all holes of a given size. More...
struct  _StringList
struct  _BomList

Defines

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

Typedefs

typedef struct _StringList StringList
typedef struct _BomList BomList

Functions

 REGISTER_ATTRIBUTES (gsvit_attribute_list)
void gsvit_build_net_from_selected (struct gsvit_netlist *currNet)
void gsvit_create_netlist (void)
void gsvit_destroy_netlist (void)
static int pcb_to_gsvit (Coord pcb)
 Convert from default PCB units to gsvit units.
static char * gsvit_get_png_name (const char *basename, const char *suffix)
static void gsvit_write_xspace (void)
static void gsvit_write_xnets (void)
static StringListstring_insert (char *str, StringList *list)
static BomListbom_insert (char *refdes, char *descr, char *value, BomList *bom)
static double xyToAngle (double x, double y, bool morethan2pins)
static void gsvit_parse_arguments (int *argc, char ***argv)
 Main export callback.
static HID_Attributegsvit_get_export_options (int *n)
static char * CleanXBOMString (char *in)
static void gsvit_write_xdrills (void)
static void gsvit_write_xcentroids (void)
void gsvit_choose_groups ()
 Populates gsvit_export_group array.
static void gsvit_alloc_colors ()
 Allocate colors.
static void gsvit_start_png (const char *basename, const char *suffix)
static void gsvit_finish_png ()
void gsvit_start_png_export ()
static void gsvit_do_export (HID_Attr_Val *options)
void gsvit_xml_out (char *gsvit_basename)
static int gsvit_set_layer (const char *name, int group, int empty)
static hidGC gsvit_make_gc (void)
static void gsvit_destroy_gc (hidGC gc)
static void gsvit_use_mask (enum mask_mode mode)
static void gsvit_set_color (hidGC gc, const char *name)
static void gsvit_set_line_cap (hidGC gc, EndCapStyle style)
static void gsvit_set_line_width (hidGC gc, Coord width)
static void gsvit_set_draw_xor (hidGC gc, int xor_)
static void gsvit_set_draw_faded (hidGC gc, int faded)
static void use_gc (hidGC gc)
static void gsvit_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void gsvit_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
struct gsvit_netlistgsvit_lookup_net_from_arc (ArcType *targetArc)
struct gsvit_netlistgsvit_lookup_net_from_line (LineType *targetLine)
struct gsvit_netlistgsvit_lookup_net_from_polygon (PolygonType *targetPolygon)
struct gsvit_netlistgsvit_lookup_net_from_pad (PadType *targetPad)
struct gsvit_netlistgsvit_lookup_net_from_pv (PinType *targetPv)
static void add_hole (struct single_size_drills *drill, int cx, int cy)
static int _drill_size_comparator (const void *_size0, const void *_size1)
 Given a hole size, return the structure that currently holds the data for that hole size.
static struct single_size_drillsget_drill (double diameter_inches, Coord radius)
static void gsvit_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void gsvit_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height, Angle start_angle, Angle delta_angle)
static void gsvit_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
static void gsvit_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
static void gsvit_calibrate (double xval, double yval)
static void gsvit_set_crosshair (int x, int y, int a)
static void gsvit_draw_pcb_arc (hidGC gc, ArcType *arc)
static void gsvit_draw_pcb_line (hidGC gc, LineType *line)
void gsvit_fill_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
void gsvit_fill_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
void gsvit_fill_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask)
void hid_gsvit_init ()

Variables

static char * reference_pin_names [] = {"1", "2", "A1", "A2", "B1", "B2", 0}
static struct single_size_drillsdrills = NULL
static int n_drills = 0
static int n_drills_allocated = 0
static int save_drill = 0
static int is_plated = 0
struct gsvit_netlistgsvit_netlist = NULL
int hashColor = gdBrushed
static struct color_structcolor_array [0x100]
static HID gsvit_hid
static HID_DRAW gsvit_graphics
static struct color_structblack = NULL
static struct color_structwhite = NULL
static Coord linewidth = -1
static gdImagePtr lastbrush = (gdImagePtr)((void *) -1)
static gdImagePtr gsvit_im = NULL
 gd image for PNG export.
static FILE * gsvit_f = NULL
 file for PNG export.
static int is_mask
static int is_drill
static int gsvit_export_group [MAX_GROUP]
 Which groups of layers to export into PNG layer masks.
static int gsvit_cur_group
 Group that is currently exported.
static const char * gsvit_basename = NULL
 Filename prefix that will be used when saving files.
static int gsvit_dpi = -1
 Horizontal DPI (grid points per inch).
HID_Attribute gsvit_attribute_list []

Detailed Description

HID exporter for gsvit.

This HID exports a PCB layout into:

  • One layer mask file (PNG format) per copper layer.
  • a gsvit configuration file that contains netlist and pin information.
Bug:
If you have a section of a net that does not contain any pins then that section will be missing from the gsvit's copper geometry.
Note:
Single layer layouts are always exported correctly.

Copyright.


PCB, interactive printed circuit board design

Copyright (C) 1994, 1995, 1996, 2004 Thomas Nau

Based on the NELMA (Numerical capacitance calculator) export HID Copyright (C) 2006 Tomaz Solc (tomaz.solc@tablix.org)

PNG export code is based on the PNG export HID Copyright (C) 2006 Dan McMahill

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: Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany Thomas.Nau@rz.uni-ulm.de


Definition in file gsvit.c.


Define Documentation

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

Definition at line 86 of file gsvit.c.

Referenced by gsvit_calibrate().

#define MAXREFPINS   32

Maximum length of following list.

Definition at line 87 of file gsvit.c.

Referenced by gsvit_write_xcentroids(), and PrintBOM().


Typedef Documentation

typedef struct _BomList BomList
typedef struct _StringList StringList

Function Documentation

static int _drill_size_comparator ( const void *  _size0,
const void *  _size1 
) [static]

Given a hole size, return the structure that currently holds the data for that hole size.

If there isn't one, make it.

Definition at line 1737 of file gsvit.c.

Referenced by get_drill().

static void add_hole ( struct single_size_drills drill,
int  cx,
int  cy 
) [static]
static BomList* bom_insert ( char *  refdes,
char *  descr,
char *  value,
BomList bom 
) [static]

Definition at line 670 of file gsvit.c.

References _BomList::descr, malloc(), _BomList::next, NSTRCMP, _BomList::num, _BomList::refdes, string_insert(), and _BomList::value.

Referenced by gsvit_write_xcentroids().

Here is the call graph for this function:

static char* CleanXBOMString ( char *  in) [static]

Definition at line 802 of file gsvit.c.

References malloc().

Referenced by gsvit_write_xcentroids().

Here is the call graph for this function:

static struct single_size_drills* get_drill ( double  diameter_inches,
Coord  radius 
) [static, read]
static void gsvit_alloc_colors ( ) [static]

Allocate colors.

White and black, the first color allocated becomes the background color.

Definition at line 1139 of file gsvit.c.

References color_struct::b, color_struct::c, gsvit_netlist::color, gsvit_netlist::colorIndex, color_struct::g, malloc(), LibraryType::MenuN, PCBType::NetlistLib, PCB, color_struct::r, rgb(), and white.

Referenced by gsvit_start_png().

Here is the call graph for this function:

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

Definition at line 1904 of file gsvit.c.

References CRASH.

Referenced by hid_gsvit_init().

void gsvit_choose_groups ( )

Populates gsvit_export_group array.

Todo:
Is this check necessary? It seems that special layers have negative indexes?

Definition at line 1103 of file gsvit.c.

References LayerType::ArcN, PCBType::Data, GetLayerGroupNumberByNumber(), DataType::Layer, layer, LayerType::LineN, m, max_copper_layer, n, PCB, LayerType::PolygonN, SL_TYPE, and LayerType::TextN.

Referenced by gsvit_do_export().

Here is the call graph for this function:

static void gsvit_destroy_gc ( hidGC  gc) [static]

Definition at line 1395 of file gsvit.c.

Referenced by hid_gsvit_init().

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

Definition at line 1813 of file gsvit.c.

References color_struct::c, hid_gc_struct::color, im, linewidth, NormalizeAngle(), pcb_to_gsvit(), SCALE, SCALE_X, SCALE_Y, start_angle, and use_gc().

Referenced by hid_gsvit_init().

Here is the call graph for this function:

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

Definition at line 1793 of file gsvit.c.

References gsvit_fill_rect(), linewidth, pcb_to_gsvit(), use_gc(), and hid_gc_struct::width.

Referenced by hid_gsvit_init().

Here is the call graph for this function:

static void gsvit_draw_pcb_arc ( hidGC  gc,
ArcType arc 
) [static]

Definition at line 1918 of file gsvit.c.

References gsvit_netlist::colorIndex, common_draw_pcb_arc(), gsvit_lookup_net_from_arc(), hashColor, LibraryType::MenuN, PCBType::NetlistLib, and PCB.

Referenced by hid_gsvit_init().

Here is the call graph for this function:

static void gsvit_draw_pcb_line ( hidGC  gc,
LineType line 
) [static]

Definition at line 1937 of file gsvit.c.

References gsvit_netlist::colorIndex, common_draw_pcb_line(), gsvit_lookup_net_from_line(), hashColor, LibraryType::MenuN, PCBType::NetlistLib, and PCB.

Referenced by hid_gsvit_init().

Here is the call graph for this function:

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

Definition at line 1561 of file gsvit.c.

References color_struct::c, hid_gc_struct::color, pcb_to_gsvit(), and use_gc().

Referenced by hid_gsvit_init().

Here is the call graph for this function:

static void gsvit_fill_circle ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  radius 
) [static]

Definition at line 1853 of file gsvit.c.

References add_hole(), c, COORD_TO_INCH, single_size_drills::diameter_inches, get_drill(), hashColor, linewidth, pcb_to_gsvit(), save_drill, and use_gc().

Referenced by hid_gsvit_init().

Here is the call graph for this function:

void gsvit_fill_pcb_pad ( hidGC  gc,
PadType pad,
bool  clear,
bool  mask 
)

Definition at line 1979 of file gsvit.c.

References gsvit_netlist::colorIndex, common_fill_pcb_pad(), gsvit_lookup_net_from_pad(), hashColor, LibraryType::MenuN, PCBType::NetlistLib, and PCB.

Referenced by hid_gsvit_init().

Here is the call graph for this function:

void gsvit_fill_pcb_polygon ( hidGC  gc,
PolygonType poly,
const BoxType clip_box 
)

Definition at line 1957 of file gsvit.c.

References gsvit_netlist::colorIndex, common_fill_pcb_polygon(), gsvit_lookup_net_from_polygon(), hashColor, LibraryType::MenuN, PCBType::NetlistLib, and PCB.

Referenced by hid_gsvit_init().

Here is the call graph for this function:

void gsvit_fill_pcb_pv ( hidGC  fg_gc,
hidGC  bg_gc,
PinType pv,
bool  drawHole,
bool  mask 
)

Definition at line 1998 of file gsvit.c.

References gsvit_netlist::colorIndex, common_fill_pcb_pv(), gsvit_lookup_net_from_pv(), hashColor, LibraryType::MenuN, PCBType::NetlistLib, and PCB.

Referenced by hid_gsvit_init().

Here is the call graph for this function:

static void gsvit_fill_polygon ( hidGC  gc,
int  n_coords,
Coord x,
Coord y 
) [static]

Definition at line 1876 of file gsvit.c.

References c, hashColor, linewidth, malloc(), pcb_to_gsvit(), and use_gc().

Referenced by hid_gsvit_init().

Here is the call graph for this function:

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

Definition at line 1571 of file gsvit.c.

References color_struct::c, hid_gc_struct::color, linewidth, pcb_to_gsvit(), and use_gc().

Referenced by gsvit_draw_line(), and hid_gsvit_init().

Here is the call graph for this function:

static void gsvit_finish_png ( ) [static]

Definition at line 1197 of file gsvit.c.

References Message().

Referenced by gsvit_do_export().

Here is the call graph for this function:

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

Definition at line 785 of file gsvit.c.

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

Referenced by gsvit_do_export(), and hid_gsvit_init().

Here is the call graph for this function:

static char* gsvit_get_png_name ( const char *  basename,
const char *  suffix 
) [static]

Definition at line 512 of file gsvit.c.

References len, and malloc().

Referenced by gsvit_start_png(), and gsvit_write_xspace().

Here is the call graph for this function:

struct gsvit_netlist* gsvit_lookup_net_from_arc ( ArcType targetArc) [read]
struct gsvit_netlist* gsvit_lookup_net_from_line ( LineType targetLine) [read]
struct gsvit_netlist* gsvit_lookup_net_from_pad ( PadType targetPad) [read]

Definition at line 1666 of file gsvit.c.

References END_LOOP, LibraryType::MenuN, PCBType::NetlistLib, PAD_LOOP, and PCB.

Referenced by gsvit_fill_pcb_pad().

struct gsvit_netlist* gsvit_lookup_net_from_polygon ( PolygonType targetPolygon) [read]
struct gsvit_netlist* gsvit_lookup_net_from_pv ( PinType targetPv) [read]

Definition at line 1688 of file gsvit.c.

References END_LOOP, LibraryType::MenuN, PCBType::NetlistLib, PCB, pin, PIN_LOOP, and VIA_LOOP.

Referenced by gsvit_fill_pcb_pv().

static hidGC gsvit_make_gc ( void  ) [static]
static void gsvit_parse_arguments ( int *  argc,
char ***  argv 
) [static]

Main export callback.

Definition at line 775 of file gsvit.c.

References hid_parse_command_line(), and hid_register_attributes().

Referenced by hid_gsvit_init().

Here is the call graph for this function:

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

Todo:
Should be background, not white.

Definition at line 1409 of file gsvit.c.

References black, hid_gc_struct::color, hid_gc_struct::erase, and white.

Referenced by hid_gsvit_init().

static void gsvit_set_crosshair ( int  x,
int  y,
int  a 
) [static]

Definition at line 1911 of file gsvit.c.

Referenced by hid_gsvit_init().

static void gsvit_set_draw_faded ( hidGC  gc,
int  faded 
) [static]

Definition at line 1460 of file gsvit.c.

Referenced by hid_gsvit_init().

static void gsvit_set_draw_xor ( hidGC  gc,
int  xor_ 
) [static]

Definition at line 1453 of file gsvit.c.

Referenced by hid_gsvit_init().

static int gsvit_set_layer ( const char *  name,
int  group,
int  empty 
) [static]
static void gsvit_set_line_cap ( hidGC  gc,
EndCapStyle  style 
) [static]

Definition at line 1439 of file gsvit.c.

References hid_gc_struct::cap, and style.

Referenced by hid_gsvit_init().

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

Definition at line 1446 of file gsvit.c.

References hid_gc_struct::width.

Referenced by hid_gsvit_init().

static void gsvit_start_png ( const char *  basename,
const char *  suffix 
) [static]

Definition at line 1176 of file gsvit.c.

References gsvit_alloc_colors(), gsvit_get_png_name(), PCBType::MaxHeight, PCBType::MaxWidth, PCB, and pcb_to_gsvit().

Referenced by gsvit_do_export().

Here is the call graph for this function:

void gsvit_start_png_export ( )

Definition at line 1218 of file gsvit.c.

References hid_expose_callback(), lastbrush, linewidth, PCBType::MaxHeight, PCBType::MaxWidth, PCB, region, BoxType::X1, BoxType::X2, BoxType::Y1, and BoxType::Y2.

Referenced by gsvit_do_export().

Here is the call graph for this function:

static void gsvit_use_mask ( enum mask_mode  mode) [static]

Definition at line 1402 of file gsvit.c.

Referenced by hid_gsvit_init().

static void gsvit_write_xdrills ( void  ) [static]
void gsvit_xml_out ( char *  gsvit_basename)
void hid_gsvit_init ( )
static int pcb_to_gsvit ( Coord  pcb) [static]
REGISTER_ATTRIBUTES ( gsvit_attribute_list  )

Definition at line 253 of file gsvit.c.

References m, rgb(), s, and X.

Here is the call graph for this function:

static StringList* string_insert ( char *  str,
StringList list 
) [static]

Definition at line 643 of file gsvit.c.

References malloc(), _StringList::next, and _StringList::str.

Referenced by bom_insert().

Here is the call graph for this function:

static double xyToAngle ( double  x,
double  y,
bool  morethan2pins 
) [static]

Definition at line 727 of file gsvit.c.

References M_PI.

Referenced by gsvit_write_xcentroids().


Variable Documentation

struct color_struct* black = NULL [static]

Definition at line 182 of file gsvit.c.

Referenced by gsvit_set_color().

struct color_struct* color_array[0x100] [static]

Definition at line 176 of file gsvit.c.

struct single_size_drills* drills = NULL [static]

Definition at line 147 of file gsvit.c.

Initial value:
 {



  {"basename", "File name prefix",
   HID_String, 0, 0, {0, 0, 0}, 0, 0},
#define HA_basename 0


  {"dpi", "Horizontal scale factor (grid points/inch)",
   HID_Integer, 0, 1000, {1000, 0, 0}, 0, 0}, 
#define HA_dpi 1

}

Definition at line 224 of file gsvit.c.

Referenced by gsvit_get_export_options().

const char* gsvit_basename = NULL [static]

Filename prefix that will be used when saving files.

Definition at line 217 of file gsvit.c.

int gsvit_cur_group [static]

Group that is currently exported.

Definition at line 212 of file gsvit.c.

Referenced by gsvit_lookup_net_from_arc(), gsvit_lookup_net_from_line(), and gsvit_lookup_net_from_polygon().

int gsvit_dpi = -1 [static]

Horizontal DPI (grid points per inch).

Definition at line 222 of file gsvit.c.

Referenced by gsvit_write_xspace(), and pcb_to_gsvit().

int gsvit_export_group[MAX_GROUP] [static]

Which groups of layers to export into PNG layer masks.

1 means export; 0 means do not export.

Definition at line 207 of file gsvit.c.

FILE* gsvit_f = NULL [static]

file for PNG export.

Definition at line 196 of file gsvit.c.

Definition at line 180 of file gsvit.c.

Referenced by hid_gsvit_init().

HID gsvit_hid [static]

Definition at line 178 of file gsvit.c.

Referenced by gsvit_make_gc().

gdImagePtr gsvit_im = NULL [static]

gd image for PNG export.

Definition at line 191 of file gsvit.c.

struct gsvit_netlist* gsvit_netlist = NULL

Definition at line 172 of file gsvit.c.

int is_drill [static]

Definition at line 200 of file gsvit.c.

int is_mask [static]

Definition at line 198 of file gsvit.c.

int is_plated = 0 [static]

Definition at line 170 of file gsvit.c.

Referenced by add_hole(), gsvit_set_layer(), and gsvit_write_xdrills().

gdImagePtr lastbrush = (gdImagePtr)((void *) -1) [static]

Definition at line 186 of file gsvit.c.

Referenced by gsvit_start_png_export(), and use_gc().

int n_drills = 0 [static]

At the start we have no drills at all

Definition at line 164 of file gsvit.c.

Referenced by get_drill(), and gsvit_write_xdrills().

int n_drills_allocated = 0 [static]

Definition at line 166 of file gsvit.c.

Referenced by get_drill().

char* reference_pin_names[] = {"1", "2", "A1", "A2", "B1", "B2", 0} [static]

Definition at line 88 of file gsvit.c.

Referenced by gsvit_write_xcentroids().

int save_drill = 0 [static]

Definition at line 168 of file gsvit.c.

Referenced by gsvit_do_export(), and gsvit_fill_circle().

struct color_struct * white = NULL

Definition at line 182 of file gsvit.c.