pcb 4.1.1
An interactive printed circuit board layout editor.
|
GCODE export HID. 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 "hid.h"
#include "hid_draw.h"
#include "../hidint.h"
#include <gd.h>
#include "hid/common/hidnogui.h"
#include "hid/common/draw_helpers.h"
#include "bitmap.h"
#include "curve.h"
#include "potracelib.h"
#include "trace.h"
#include "decompose.h"
#include "pcb-printf.h"
#include "hid/common/hidinit.h"
Go to the source code of this file.
Data Structures | |
struct | color_struct |
struct | hid_gc_struct |
struct | drill_hole |
Structure to represent a single hole. More... | |
struct | single_size_drills |
Structure to represent all holes of a given size. More... | |
Defines | |
#define | CRASH fprintf(stderr, "HID error: pcb called unimplemented GCODE function %s.\n", __FUNCTION__); abort() |
Functions | |
REGISTER_ATTRIBUTES (gcode_attribute_list) | |
Convert from default PCB units to gcode units. | |
static void | gcode_get_filename (char *filename, const char *layername) |
Fits the given layer name into basename, just before the suffix. | |
static void | sort_drill (struct drill_hole *drill, int n_drill) |
Sorts drills to produce a short tool path. | |
static void | gcode_parse_arguments (int *argc, char ***argv) |
static HID_Attribute * | gcode_get_export_options (int *n) |
static void | gcode_choose_groups () |
Populates gcode_export_group array. | |
static void | gcode_alloc_colors () |
Allocate white and black. | |
static void | gcode_start_png () |
static void | gcode_finish_png (const char *layername) |
static void | gcode_start_png_export () |
static FILE * | gcode_start_gcode (const char *layername, bool metric) |
static void | gcode_do_export (HID_Attr_Val *options) |
static int | gcode_set_layer (const char *name, int group, int empty) |
static hidGC | gcode_make_gc (void) |
static void | gcode_destroy_gc (hidGC gc) |
static void | gcode_use_mask (enum mask_mode mode) |
static void | gcode_set_color (hidGC gc, const char *name) |
static void | gcode_set_line_cap (hidGC gc, EndCapStyle style) |
static void | gcode_set_line_width (hidGC gc, Coord width) |
static void | gcode_set_draw_xor (hidGC gc, int xor_) |
static void | gcode_set_draw_faded (hidGC gc, int faded) |
static void | use_gc (hidGC gc) |
static void | gcode_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) |
static void | gcode_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) |
static void | gcode_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) |
static void | gcode_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height, Angle start_angle, Angle delta_angle) |
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_drills * | get_drill (double diameter_inches) |
static void | add_hole (struct single_size_drills *drill, double cx_inches, double cy_inches) |
static void | gcode_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius) |
static void | gcode_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y) |
static void | gcode_calibrate (double xval, double yval) |
static void | gcode_set_crosshair (int x, int y, int a) |
void | hid_gcode_init () |
Variables | |
static HID | gcode_hid |
static HID_DRAW | gcode_graphics |
static struct color_struct * | black = NULL |
static struct color_struct * | white = NULL |
static int | linewidth = -1 |
static gdImagePtr | lastbrush = (gdImagePtr)((void *) -1) |
static gdImagePtr | gcode_im = NULL |
static FILE * | gcode_f = NULL |
static int | is_mask |
static int | is_drill |
static int | is_bottom |
static int | gcode_export_group [MAX_GROUP] |
static int | gcode_cur_group |
static const char * | gcode_basename = NULL |
static int | gcode_dpi = -1 |
static double | gcode_cutdepth = 0 |
static double | gcode_isoplunge = 0 |
static double | gcode_isofeedrate = 0 |
static char | gcode_predrill |
static double | gcode_drilldepth = 0 |
static double | gcode_drillfeedrate = 0 |
static double | gcode_safeZ = 100 |
static int | gcode_toolradius = 0 |
static char | gcode_drillmill = 0 |
static double | gcode_milldepth = 0 |
static double | gcode_milltoolradius = 0 |
static double | gcode_millplunge = 0 |
static double | gcode_millfeedrate = 0 |
static char | gcode_advanced = 0 |
static int | save_drill = 0 |
static struct single_size_drills * | drills = NULL |
static int | n_drills = 0 |
static int | n_drills_allocated = 0 |
HID_Attribute | gcode_attribute_list [] |
GCODE export HID.
This HID exports a PCB layout into:
The latter is used by a CNC milling machine to mill the pcb.
PCB, interactive printed circuit board design
Copyright (c) 2010 Alberto Maccioni
Copyright (c) 2012 Markus Hitter (mah@jump-ing.de)
This code is based on the NELMA export HID, the PNG export HID, and potrace, a tracing program by Peter Selinger
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.
Definition in file gcode.c.
#define CRASH fprintf(stderr, "HID error: pcb called unimplemented GCODE function %s.\n", __FUNCTION__); abort() |
Definition at line 82 of file gcode.c.
Referenced by gcode_calibrate().
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 1600 of file gcode.c.
Referenced by get_drill().
static void add_hole | ( | struct single_size_drills * | drill, |
double | cx_inches, | ||
double | cy_inches | ||
) | [static] |
Definition at line 1659 of file gcode.c.
References single_size_drills::holes, single_size_drills::n_holes, single_size_drills::n_holes_allocated, realloc(), drill_hole::x, and drill_hole::y.
Referenced by gcode_fill_circle().
static void gcode_alloc_colors | ( | ) | [static] |
Allocate white and black.
The first color allocated becomes the background color.
Definition at line 566 of file gcode.c.
References color_struct::b, color_struct::c, color_struct::g, malloc(), color_struct::r, and white.
Referenced by gcode_start_png().
static void gcode_calibrate | ( | double | xval, |
double | yval | ||
) | [static] |
static void gcode_choose_groups | ( | ) | [static] |
Populates gcode_export_group array.
Definition at line 527 of file gcode.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 gcode_do_export().
static void gcode_destroy_gc | ( | hidGC | gc | ) | [static] |
Definition at line 1344 of file gcode.c.
Referenced by hid_gcode_init().
static void gcode_do_export | ( | HID_Attr_Val * | options | ) | [static] |
Definition at line 660 of file gcode.c.
References abs, color_struct::b, bm_free(), bm_new(), BM_PUT, bm_to_pathlist(), BOTTOM_SIDE, c, COORD_TO_INCH, COORD_TO_MM, coord_to_unit(), HID_Attribute::default_val, single_size_drills::diameter_inches, Distance(), LayerGroupType::Entries, unit::family, FNS_fixed, color_struct::g, gcode_choose_groups(), gcode_dpi, gcode_finish_png(), gcode_get_export_options(), gcode_milltoolradius, gcode_start_gcode(), gcode_start_png(), gcode_start_png_export(), get_unit_list(), GetLayerGroupNumberByNumber(), GetLayerGroupNumberBySide(), hid_restore_layer_ons(), hid_save_and_show_layer_ons(), single_size_drills::holes, INCH_TO_COORD, HID_Attr_Val::int_value, is_bottom, layer_type_to_file_name(), PCBType::LayerGroups, layername, M_PI, malloc(), MAX_ALL_LAYER, max_group, PCBType::MaxHeight, PCBType::MaxWidth, METRIC, metric, MM_TO_COORD, n_drills, single_size_drills::n_holes, pathlist_free(), PCB, pcb_fprintf(), pcb_snprintf(), POTRACE_TURNPOLICY_MINORITY, process_path(), color_struct::r, single_size_drills::radius, HID_Attr_Val::real_value, scale, sort_drill(), HID_Attr_Val::str_value, unit, white, drill_hole::x, and drill_hole::y.
Referenced by hid_gcode_init().
static void gcode_draw_arc | ( | hidGC | gc, |
Coord | cx, | ||
Coord | cy, | ||
Coord | width, | ||
Coord | height, | ||
Angle | start_angle, | ||
Angle | delta_angle | ||
) | [static] |
Definition at line 1547 of file gcode.c.
References color_struct::c, hid_gc_struct::color, im, linewidth, NormalizeAngle(), SCALE, SCALE_X, SCALE_Y, start_angle, and use_gc().
Referenced by hid_gcode_init().
Definition at line 1524 of file gcode.c.
References gcode_fill_rect(), linewidth, use_gc(), and hid_gc_struct::width.
Referenced by hid_gcode_init().
Definition at line 1496 of file gcode.c.
References color_struct::c, hid_gc_struct::color, and use_gc().
Referenced by hid_gcode_init().
Definition at line 1677 of file gcode.c.
References add_hole(), color_struct::c, hid_gc_struct::color, COORD_TO_INCH, get_drill(), linewidth, PCBType::MaxHeight, PCBType::MaxWidth, PCB, and use_gc().
Referenced by hid_gcode_init().
Definition at line 1703 of file gcode.c.
References color_struct::c, hid_gc_struct::color, linewidth, malloc(), and use_gc().
Referenced by hid_gcode_init().
Definition at line 1509 of file gcode.c.
References color_struct::c, hid_gc_struct::color, linewidth, and use_gc().
Referenced by gcode_draw_line(), and hid_gcode_init().
static void gcode_finish_png | ( | const char * | layername | ) | [static] |
Definition at line 586 of file gcode.c.
References filename, gcode_get_filename(), malloc(), Message(), and white.
Referenced by gcode_do_export().
static HID_Attribute* gcode_get_export_options | ( | int * | n | ) | [static] |
Definition at line 496 of file gcode.c.
References HID_Attribute::default_val, derive_default_filename(), PCBType::Filename, gcode_attribute_list, get_unit_struct(), SettingType::grid_unit, unit::index, HID_Attr_Val::int_value, PCB, and Settings.
Referenced by gcode_do_export(), and hid_gcode_init().
static void gcode_get_filename | ( | char * | filename, |
const char * | layername | ||
) | [static] |
Fits the given layer name into basename, just before the suffix.
Definition at line 410 of file gcode.c.
References gcode_basename.
Referenced by gcode_finish_png(), and gcode_start_gcode().
static hidGC gcode_make_gc | ( | void | ) | [static] |
Definition at line 1331 of file gcode.c.
References color_struct::b, color_struct::c, hid_gc_struct::cap, hid_gc_struct::color, color_struct::g, gcode_hid, malloc(), hid_gc_struct::me_pointer, color_struct::r, Trace_Cap, and hid_gc_struct::width.
Referenced by hid_gcode_init().
static void gcode_parse_arguments | ( | int * | argc, |
char *** | argv | ||
) | [static] |
Definition at line 487 of file gcode.c.
References hid_parse_command_line(), and hid_register_attributes().
Referenced by hid_gcode_init().
static void gcode_set_color | ( | hidGC | gc, |
const char * | name | ||
) | [static] |
Definition at line 1356 of file gcode.c.
References black, hid_gc_struct::color, hid_gc_struct::erase, and white.
Referenced by hid_gcode_init().
static void gcode_set_crosshair | ( | int | x, |
int | y, | ||
int | a | ||
) | [static] |
Definition at line 1734 of file gcode.c.
Referenced by hid_gcode_init().
static void gcode_set_draw_faded | ( | hidGC | gc, |
int | faded | ||
) | [static] |
Definition at line 1403 of file gcode.c.
Referenced by hid_gcode_init().
static void gcode_set_draw_xor | ( | hidGC | gc, |
int | xor_ | ||
) | [static] |
Definition at line 1397 of file gcode.c.
Referenced by hid_gcode_init().
static int gcode_set_layer | ( | const char * | name, |
int | group, | ||
int | empty | ||
) | [static] |
Definition at line 1294 of file gcode.c.
References PCBType::Data, LayerGroupType::Entries, DataType::Layer, PCBType::LayerGroups, max_group, LayerType::Name, PCB, SL_MASK, SL_PDRILL, SL_TYPE, and SL_UDRILL.
Referenced by hid_gcode_init().
static void gcode_set_line_cap | ( | hidGC | gc, |
EndCapStyle | style | ||
) | [static] |
Definition at line 1385 of file gcode.c.
References hid_gc_struct::cap, and style.
Referenced by hid_gcode_init().
Definition at line 1391 of file gcode.c.
References hid_gc_struct::width.
Referenced by hid_gcode_init().
static FILE* gcode_start_gcode | ( | const char * | layername, |
bool | metric | ||
) | [static] |
Definition at line 629 of file gcode.c.
References buffer, gcode_get_filename(), PCBType::MaxHeight, PCBType::MaxWidth, Message(), PCB, and pcb_fprintf().
Referenced by gcode_do_export().
static void gcode_start_png | ( | ) | [static] |
Definition at line 578 of file gcode.c.
References gcode_alloc_colors(), PCBType::MaxHeight, PCBType::MaxWidth, and PCB.
Referenced by gcode_do_export().
static void gcode_start_png_export | ( | ) | [static] |
Definition at line 613 of file gcode.c.
References hid_expose_callback(), lastbrush, linewidth, PCBType::MaxHeight, PCBType::MaxWidth, PCB, region, BoxType::X1, BoxType::X2, BoxType::Y1, and BoxType::Y2.
Referenced by gcode_do_export().
static void gcode_use_mask | ( | enum mask_mode | mode | ) | [static] |
Definition at line 1350 of file gcode.c.
Referenced by hid_gcode_init().
static struct single_size_drills* get_drill | ( | double | diameter_inches | ) | [static, read] |
Definition at line 1614 of file gcode.c.
References _drill_size_comparator(), single_size_drills::diameter_inches, single_size_drills::holes, n_drills, single_size_drills::n_holes, single_size_drills::n_holes_allocated, and realloc().
Referenced by gcode_fill_circle().
void hid_gcode_init | ( | ) |
Definition at line 1743 of file gcode.c.
References hid_st::calibrate, common_draw_helpers_init(), common_nogui_init(), hid_st::description, hid_draw_st::destroy_gc, hid_st::do_export, hid_draw_st::draw_arc, hid_draw_st::draw_line, hid_draw_st::draw_rect, hid_st::exporter, hid_draw_st::fill_circle, hid_draw_st::fill_polygon, hid_draw_st::fill_rect, gcode_calibrate(), gcode_destroy_gc(), gcode_do_export(), gcode_draw_arc(), gcode_draw_line(), gcode_draw_rect(), gcode_fill_circle(), gcode_fill_polygon(), gcode_fill_rect(), gcode_get_export_options(), gcode_graphics, gcode_make_gc(), gcode_parse_arguments(), gcode_set_color(), gcode_set_crosshair(), gcode_set_draw_faded(), gcode_set_draw_xor(), gcode_set_layer(), gcode_set_line_cap(), gcode_set_line_width(), gcode_use_mask(), hid_st::get_export_options, hid_st::graphics, hid_register_hid(), hid_draw_st::make_gc, hid_st::name, hid_st::parse_arguments, hid_st::poly_before, hid_draw_st::set_color, hid_st::set_crosshair, hid_draw_st::set_draw_faded, hid_draw_st::set_draw_xor, hid_st::set_layer, hid_draw_st::set_line_cap, hid_draw_st::set_line_width, hid_st::struct_size, and hid_draw_st::use_mask.
REGISTER_ATTRIBUTES | ( | gcode_attribute_list | ) |
Convert from default PCB units to gcode units.
Definition at line 392 of file gcode.c.
References COORD_TO_INCH.
static void sort_drill | ( | struct drill_hole * | drill, |
int | n_drill | ||
) | [static] |
Sorts drills to produce a short tool path.
I start with the hole nearest (0,0) and for each subsequent one, find the hole nearest to the previous.
This isn't guaranteed to find the shortest path, but should be good enough.
Definition at line 446 of file gcode.c.
References x, drill_hole::x, y, and drill_hole::y.
Referenced by gcode_do_export().
static void use_gc | ( | hidGC | gc | ) | [static] |
Definition at line 1408 of file gcode.c.
References color_struct::b, hid_gc_struct::brush, hid_gc_struct::cap, hid_gc_struct::color, color_struct::g, hid_cache_color(), lastbrush, linewidth, hid_gc_struct::me_pointer, hidval::ptr, color_struct::r, Round_Cap, Square_Cap, Trace_Cap, and hid_gc_struct::width.
Referenced by gcode_draw_arc(), gcode_draw_line(), gcode_draw_rect(), gcode_fill_circle(), gcode_fill_polygon(), and gcode_fill_rect().
struct color_struct* black = NULL [static] |
Definition at line 106 of file gcode.c.
Referenced by gcode_set_color().
struct single_size_drills* drills = NULL [static] |
char gcode_advanced = 0 [static] |
Definition at line 170 of file gcode.c.
Referenced by gcode_get_export_options().
const char* gcode_basename = NULL [static] |
Filename prefix and suffix that will be used when saving files.
Definition at line 123 of file gcode.c.
Referenced by gcode_get_filename().
int gcode_cur_group [static] |
double gcode_cutdepth = 0 [static] |
int gcode_dpi = -1 [static] |
Horizontal DPI (grid points per inch).
Definition at line 126 of file gcode.c.
Referenced by gcode_do_export().
double gcode_drilldepth = 0 [static] |
double gcode_drillfeedrate = 0 [static] |
char gcode_drillmill = 0 [static] |
int gcode_export_group[MAX_GROUP] [static] |
HID_DRAW gcode_graphics [static] |
Definition at line 85 of file gcode.c.
Referenced by hid_gcode_init().
Definition at line 84 of file gcode.c.
Referenced by gcode_make_gc().
gdImagePtr gcode_im = NULL [static] |
double gcode_isofeedrate = 0 [static] |
double gcode_isoplunge = 0 [static] |
double gcode_milldepth = 0 [static] |
double gcode_millfeedrate = 0 [static] |
double gcode_millplunge = 0 [static] |
double gcode_milltoolradius = 0 [static] |
Outline-mill tool radius (mm or in).
Definition at line 138 of file gcode.c.
Referenced by gcode_do_export().
char gcode_predrill [static] |
double gcode_safeZ = 100 [static] |
int gcode_toolradius = 0 [static] |
int is_bottom [static] |
Definition at line 115 of file gcode.c.
Referenced by gcode_do_export().
int is_drill [static] |
Definition at line 114 of file gcode.c.
Referenced by REGISTER_ATTRIBUTES().
int is_mask [static] |
Definition at line 113 of file gcode.c.
Referenced by REGISTER_ATTRIBUTES().
gdImagePtr lastbrush = (gdImagePtr)((void *) -1) [static] |
Definition at line 108 of file gcode.c.
Referenced by gcode_start_png_export(), and use_gc().
int linewidth = -1 [static] |
Definition at line 107 of file gcode.c.
Referenced by gcode_draw_arc(), gcode_draw_line(), gcode_fill_circle(), gcode_fill_polygon(), gcode_fill_rect(), gcode_start_png_export(), ps_draw_arc(), ps_fill_rect(), REGISTER_ATTRIBUTES(), and use_gc().
int n_drills = 0 [static] |
Definition at line 167 of file gcode.c.
Referenced by gcode_do_export(), and get_drill().
int n_drills_allocated = 0 [static] |
int save_drill = 0 [static] |
struct color_struct * white = NULL |
Definition at line 106 of file gcode.c.
Referenced by gcode_alloc_colors(), gcode_do_export(), gcode_finish_png(), gcode_set_color(), gsvit_alloc_colors(), gsvit_set_color(), nelma_alloc_colors(), nelma_finish_png(), nelma_set_color(), png_do_export(), png_set_color(), png_set_layer(), and png_use_mask().