don't update min/max bounding box when drawing with CLEAR polarity
[geda-gerbv.git] / src / gerbv.h
blob1c93c5305e26b7c147f75a173e9937cdc10de0ee
1 /*
2 * gEDA - GNU Electronic Design Automation
3 * This file is a part of gerbv.
5 * Copyright (C) 2000-2003 Stefan Petersen (spe@stacken.kth.se)
7 * $Id$
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
24 //! \example example1.c
25 //! \example example2.c
26 //! \example example3.c
27 //! \example example4.c
28 //! \example example5.c
29 //! \example example6.c
31 //! \defgroup libgerbv libgerbv
32 //! \defgroup gerbv Gerbv
34 /** \file gerbv.h
35 \brief The main header file for the libgerbv library
36 \ingroup libgerbv
39 /**
40 \mainpage Gerbv/libgerbv Index Page
42 \section intro_sec Introduction
44 Gerbv is a program which can display, edit, export, and do other manipulation of
45 file formats used in PCB design (RS274X, Excellon drill, and pick-and-place). The core
46 library (libgerbv) is available as a separate library, allowing other software to easily
47 incorporate advanced Gerber functionality.
49 This code documentation is mainly intended to help explain the libgerbv API to developers
50 wishing to use libgerbv in his/her own projects. The easiest way to learn to use libgerbv is
51 by reading through and compiling the example source files (click on "Examples" in the navigation
52 tree in the left pane, or look in the doc/example-code/ directory in CVS).
54 For help with using the standalone Gerbv software, please refer to the man page (using
55 the command "man gerbv") or go to the Gerbv homepage for documentation (http://gerbv.sourceforge.net).
58 #ifndef __GERBV_H__
59 #define __GERBV_H__
61 #if defined(__cplusplus)
62 extern "C" {
63 #endif
65 #ifdef HAVE_CONFIG_H
66 #include "config.h"
67 #endif
69 #include <glib.h>
70 #include <gtk/gtk.h>
71 #include <gdk/gdk.h>
72 #include <gdk/gdkkeysyms.h>
74 #ifndef RENDER_USING_GDK
75 #include <cairo.h>
76 #endif
78 #define APERTURE_MIN 10
79 #define APERTURE_MAX 9999
82 * Maximum number of aperture parameters is set by the outline aperture
83 * macro. There (p. 28) is defined up to 50 points in polygon.
84 * So 50 points with x and y plus two for holding extra data gives...
86 #define APERTURE_PARAMETERS_MAX 102
87 #define INITIAL_SCALE 200
88 #define MAX_ERRMSGLEN 25
89 #define MAX_COORDLEN 28
90 #define MAX_DISTLEN 90
91 #define MAX_STATUSMSGLEN (MAX_ERRMSGLEN+MAX_COORDLEN+MAX_DISTLEN)
93 /* Macros to convert between unscaled gerber coordinates and other units */
94 /* XXX NOTE: Currently unscaled units are assumed as inch, this is not
95 XXX necessarily true for all files */
96 #define COORD2MILS(c) ((c)*1000.0)
97 #define COORD2MMS(c) ((c)*25.4)
99 #define GERB_FATAL_ERROR(t...) g_log(NULL, G_LOG_LEVEL_ERROR, ##t);
100 #define GERB_COMPILE_ERROR(t...) g_log(NULL, G_LOG_LEVEL_CRITICAL, ##t);
101 #define GERB_COMPILE_WARNING(t...) g_log(NULL, G_LOG_LEVEL_WARNING, ##t);
102 #define GERB_MESSAGE(t...) g_log(NULL, G_LOG_LEVEL_MESSAGE, ##t);
104 /*! The aperture macro commands */
105 typedef enum {GERBV_OPCODE_NOP, /*!< no operation */
106 GERBV_OPCODE_PUSH, /*!< push the instruction onto the stack */
107 GERBV_OPCODE_PPUSH, /*!< push parameter onto stack */
108 GERBV_OPCODE_PPOP, /*!< pop parameter from stack */
109 GERBV_OPCODE_ADD, /*!< mathmatical add operation */
110 GERBV_OPCODE_SUB, /*!< mathmatical subtract operation */
111 GERBV_OPCODE_MUL, /*!< mathmatical multiply operation */
112 GERBV_OPCODE_DIV, /*!< mathmatical divide operation */
113 GERBV_OPCODE_PRIM /*!< draw macro primative */
114 } gerbv_opcodes_t;
116 /*! The different message types used in libgerbv */
117 typedef enum {GERBV_MESSAGE_FATAL, /*!< processing cannot continue */
118 GERBV_MESSAGE_ERROR, /*!< something went wrong, but processing can still continue */
119 GERBV_MESSAGE_WARNING, /*!< something was encountered that may provide the wrong output */
120 GERBV_MESSAGE_NOTE /*!< an irregularity was encountered, but needs no intervention */
121 } gerbv_message_type_t;
123 /*! The different aperture types available
124 * Please keep these in sync with the aperture names defined by
125 * ap_names in callbacks.c */
126 typedef enum {GERBV_APTYPE_NONE, /*!< no aperture used */
127 GERBV_APTYPE_CIRCLE, /*!< a round aperture */
128 GERBV_APTYPE_RECTANGLE, /*!< a rectangular aperture */
129 GERBV_APTYPE_OVAL, /*!< an ovular (obround) aperture */
130 GERBV_APTYPE_POLYGON, /*!< a polygon aperture */
131 GERBV_APTYPE_MACRO, /*!< a RS274X macro */
132 GERBV_APTYPE_MACRO_CIRCLE, /*!< a RS274X circle macro */
133 GERBV_APTYPE_MACRO_OUTLINE, /*!< a RS274X outline macro */
134 GERBV_APTYPE_MACRO_POLYGON, /*!< a RS274X polygon macro */
135 GERBV_APTYPE_MACRO_MOIRE, /*!< a RS274X moire macro */
136 GERBV_APTYPE_MACRO_THERMAL, /*!< a RS274X thermal macro */
137 GERBV_APTYPE_MACRO_LINE20, /*!< a RS274X line (code 20) macro */
138 GERBV_APTYPE_MACRO_LINE21, /*!< a RS274X line (code 21) macro */
139 GERBV_APTYPE_MACRO_LINE22 /*!< a RS274X line (code 22) macro */
140 } gerbv_aperture_type_t;
142 /*! the current state of the aperture drawing tool */
143 typedef enum {GERBV_APERTURE_STATE_OFF, /*!< tool drawing is off, and nothing will be drawn */
144 GERBV_APERTURE_STATE_ON, /*!< tool drawing is on, and something will be drawn */
145 GERBV_APERTURE_STATE_FLASH /*!< tool is flashing, and will draw a single aperture */
146 } gerbv_aperture_state_t;
148 /*! the current unit used */
149 typedef enum {GERBV_UNIT_INCH, /*!< inches */
150 GERBV_UNIT_MM, /*!< mm */
151 GERBV_UNIT_UNSPECIFIED /*!< use default units */
152 } gerbv_unit_t;
154 /*! the different drawing polarities available */
155 typedef enum {GERBV_POLARITY_POSITIVE, /*!< draw "positive", using the current layer's polarity */
156 GERBV_POLARITY_NEGATIVE, /*!< draw "negative", reversing the current layer's polarity */
157 GERBV_POLARITY_DARK, /*!< add to the current rendering */
158 GERBV_POLARITY_CLEAR /*!< subtract from the current rendering */
159 } gerbv_polarity_t;
161 /*! the decimal point parsing style used */
162 typedef enum {GERBV_OMIT_ZEROS_LEADING, /*!< omit extra zeros before the decimal point */
163 GERBV_OMIT_ZEROS_TRAILING, /*!< omit extra zeros after the decimal point */
164 GERBV_OMIT_ZEROS_EXPLICIT, /*!< explicitly specify how many decimal places are used */
165 GERBV_OMIT_ZEROS_UNSPECIFIED /*!< use the default parsing style */
166 } gerbv_omit_zeros_t;
168 /*! the coordinate system used */
169 typedef enum {GERBV_COORDINATE_ABSOLUTE, /*!< all coordinates are absolute from a common origin */
170 GERBV_COORDINATE_INCREMENTAL /*!< all coordinates are relative to the previous coordinate */
171 } gerbv_coordinate_t;
173 /*! the interpolation methods available */
174 typedef enum {GERBV_INTERPOLATION_LINEARx1, /*!< draw a line */
175 GERBV_INTERPOLATION_x10, /*!< draw a line */
176 GERBV_INTERPOLATION_LINEARx01, /*!< draw a line */
177 GERBV_INTERPOLATION_LINEARx001, /*!< draw a line */
178 GERBV_INTERPOLATION_CW_CIRCULAR, /*!< draw an arc in the clockwise direction */
179 GERBV_INTERPOLATION_CCW_CIRCULAR, /*!< draw an arc in the counter-clockwise direction */
180 GERBV_INTERPOLATION_PAREA_START, /*!< start a polygon draw */
181 GERBV_INTERPOLATION_PAREA_END, /*!< end a polygon draw */
182 GERBV_INTERPOLATION_DELETED /*!< the net has been deleted by the user, and will not be drawn */
183 } gerbv_interpolation_t;
185 typedef enum {GERBV_ENCODING_NONE,
186 GERBV_ENCODING_ASCII,
187 GERBV_ENCODING_EBCDIC,
188 GERBV_ENCODING_BCD,
189 GERBV_ENCODING_ISO_ASCII,
190 GERBV_ENCODING_EIA
191 } gerbv_encoding_t;
193 /*! The different layer types used */
194 typedef enum {GERBV_LAYERTYPE_RS274X, /*!< the file is a RS274X file */
195 GERBV_LAYERTYPE_DRILL, /*!< the file is an Excellon drill file */
196 GERBV_LAYERTYPE_PICKANDPLACE /*!< the file is a CSV pick and place file */
197 } gerbv_layertype_t;
199 typedef enum {GERBV_KNOCKOUT_TYPE_NOKNOCKOUT,
200 GERBV_KNOCKOUT_TYPE_FIXEDKNOCK,
201 GERBV_KNOCKOUT_TYPE_BORDER
202 } gerbv_knockout_type_t;
204 typedef enum {GERBV_MIRROR_STATE_NOMIRROR,
205 GERBV_MIRROR_STATE_FLIPA,
206 GERBV_MIRROR_STATE_FLIPB,
207 GERBV_MIRROR_STATE_FLIPAB
208 } gerbv_mirror_state_t;
210 typedef enum {GERBV_AXIS_SELECT_NOSELECT,
211 GERBV_AXIS_SELECT_SWAPAB
212 } gerbv_axis_select_t;
214 typedef enum {GERBV_JUSTIFY_NOJUSTIFY,
215 GERBV_JUSTIFY_LOWERLEFT,
216 GERBV_JUSTIFY_CENTERJUSTIFY
217 } gerbv_image_justify_type_t;
219 /*! The different selection modes available */
220 typedef enum {GERBV_SELECTION_EMPTY, /*!< the selection buffer is empty */
221 GERBV_SELECTION_POINT_CLICK, /*!< the user clicked on a single point */
222 GERBV_SELECTION_DRAG_BOX /*!< the user dragged a box to encompass one or more objects */
223 } gerbv_selection_t;
225 /*! The different rendering modes available to libgerbv */
226 typedef enum {GERBV_RENDER_TYPE_GDK, /*!< render using normal GDK drawing functions */
227 GERBV_RENDER_TYPE_GDK_XOR, /*!< use the GDK_XOR mask to draw a pseudo-transparent scene */
228 GERBV_RENDER_TYPE_CAIRO_NORMAL, /*!< use the cairo library */
229 GERBV_RENDER_TYPE_CAIRO_HIGH_QUALITY, /*!< use the cairo library with the smoothest edges */
230 GERBV_RENDER_TYPE_MAX /*!< End-of-enum indicator */
231 } gerbv_render_types_t;
234 * The following typedef's are taken directly from src/hid.h in the
235 * pcb project. The names are kept the same to make it easier to
236 * compare to pcb's sources.
239 /* Used for HID attributes (exporting and printing, mostly).
240 HA_boolean uses int_value, HA_enum sets int_value to the index and
241 str_value to the enumeration string. HID_Label just shows the
242 default str_value. HID_Mixed is a real_value followed by an enum,
243 like 0.5in or 100mm.
245 typedef struct {
246 int int_value;
247 char *str_value;
248 double real_value;
249 } gerbv_HID_Attr_Val;
251 typedef struct {
252 char *name;
253 char *help_text;
254 enum
255 { HID_Label, HID_Integer, HID_Real, HID_String,
256 HID_Boolean, HID_Enum, HID_Mixed, HID_Path
257 } type;
258 int min_val, max_val; /* for integer and real */
259 gerbv_HID_Attr_Val default_val; /* Also actual value for global attributes. */
260 const char **enumerations;
261 /* If set, this is used for global attributes (i.e. those set
262 statically with REGISTER_ATTRIBUTES below) instead of changing
263 the default_val. Note that a HID_Mixed attribute must specify a
264 pointer to gerbv_HID_Attr_Val here, and HID_Boolean assumes this is
265 "char *" so the value should be initialized to zero, and may be
266 set to non-zero (not always one). */
267 void *value;
268 int hash; /* for detecting changes. */
269 } gerbv_HID_Attribute;
270 /* end of HID attributes from PCB */
272 /*! A linked list of errors found in the files */
273 typedef struct error_list {
274 int layer;
275 gchar *error_text;
276 gerbv_message_type_t type;
277 struct error_list *next;
278 } gerbv_error_list_t;
280 typedef struct instruction {
281 gerbv_opcodes_t opcode;
282 union {
283 int ival;
284 float fval;
285 } data;
286 struct instruction *next;
287 } gerbv_instruction_t;
289 typedef struct amacro {
290 gchar *name;
291 gerbv_instruction_t *program;
292 unsigned int nuf_push; /* Nuf pushes in program to estimate stack size */
293 struct amacro *next;
294 } gerbv_amacro_t;
296 typedef struct gerbv_simplified_amacro {
297 gerbv_aperture_type_t type;
298 double parameter[APERTURE_PARAMETERS_MAX];
299 struct gerbv_simplified_amacro *next;
300 } gerbv_simplified_amacro_t;
302 typedef struct gerbv_aperture {
303 gerbv_aperture_type_t type;
304 gerbv_amacro_t *amacro;
305 gerbv_simplified_amacro_t *simplified;
306 double parameter[APERTURE_PARAMETERS_MAX];
307 int nuf_parameters;
308 gerbv_unit_t unit;
309 } gerbv_aperture_t;
311 /* the gerb_aperture_list is used to keep track of
312 * apertures used in stats reporting */
313 typedef struct gerbv_aperture_list {
314 int number;
315 int layer;
316 int count;
317 gerbv_aperture_type_t type;
318 double parameter[5];
319 struct gerbv_aperture_list *next;
320 } gerbv_aperture_list_t;
322 /*! Contains statistics on the various codes used in a RS274X file */
323 typedef struct {
324 gerbv_error_list_t *error_list;
325 gerbv_aperture_list_t *aperture_list;
326 gerbv_aperture_list_t *D_code_list;
328 int layer_count;
329 int G0;
330 int G1;
331 int G2;
332 int G3;
333 int G4;
334 int G10;
335 int G11;
336 int G12;
337 int G36;
338 int G37;
339 int G54;
340 int G55;
341 int G70;
342 int G71;
343 int G74;
344 int G75;
345 int G90;
346 int G91;
347 int G_unknown;
349 int D1;
350 int D2;
351 int D3;
352 /* GHashTable *D_user_defined; */
353 int D_unknown;
354 int D_error;
356 int M0;
357 int M1;
358 int M2;
359 int M_unknown;
361 int X;
362 int Y;
363 int I;
364 int J;
366 /* Must include % RS-274 codes */
367 int star;
368 int unknown;
370 } gerbv_stats_t;
372 /*! Linked list of drills found in active layers. Used in reporting statistics */
373 typedef struct drill_list {
374 int drill_num;
375 double drill_size;
376 gchar *drill_unit;
377 int drill_count;
378 struct drill_list *next;
379 } gerbv_drill_list_t;
381 /*! Struct holding statistics of drill commands used. Used in reporting statistics */
382 typedef struct {
383 int layer_count;
385 gerbv_error_list_t *error_list;
386 gerbv_drill_list_t *drill_list;
387 int comment;
388 int F;
390 int G00;
391 int G01;
392 int G02;
393 int G03;
394 int G04;
395 int G05;
396 int G90;
397 int G91;
398 int G93;
399 int G_unknown;
401 int M00;
402 int M01;
403 int M18;
404 int M25;
405 int M30;
406 int M31;
407 int M45;
408 int M47;
409 int M48;
410 int M71;
411 int M72;
412 int M95;
413 int M97;
414 int M98;
415 int M_unknown;
417 int R;
419 int unknown;
421 /* used to total up the drill count across all layers/sizes */
422 int total_count;
424 char *detect;
426 } gerbv_drill_stats_t;
428 typedef struct {
429 gpointer image;
430 gpointer net;
431 } gerbv_selection_item_t;
433 /*! Struct holding info about the last selection */
434 typedef struct {
435 gerbv_selection_t type;
436 gdouble lowerLeftX;
437 gdouble lowerLeftY;
438 gdouble upperRightX;
439 gdouble upperRightY;
440 GArray *selectedNodeArray;
441 } gerbv_selection_info_t;
443 /*! Stores image transformation information, used to modify the rendered
444 position/scale/etc of an image. */
445 typedef struct {
446 gdouble translateX; /*!< the X translation (in inches) */
447 gdouble translateY; /*!< the Y translation (in inches) */
448 gdouble scaleX; /*!< the X scale factor (1.0 is default) */
449 gdouble scaleY; /*!< the Y scale factor (1.0 is default) */
450 gdouble rotation; /*!< the rotation of the layer around the origin (in radians) */
451 gboolean mirrorAroundX; /*!< TRUE if the layer is mirrored around the X axis (vertical flip) */
452 gboolean mirrorAroundY; /*!< TRUE if the layer is mirrored around the Y axis (vertical flip) */
453 gboolean inverted; /*!< TRUE if the image should be rendered "inverted" (light is dark and vice versa) */
454 } gerbv_user_transformation_t;
456 /*! This defines a box location and size (used to rendering logic) */
457 typedef struct {
458 double left; /*!< the X coordinate of the left side */
459 double right; /*!< the X coordinate of the right side */
460 double bottom; /*!< the Y coordinate of the bottom side */
461 double top; /*!< the Y coordinate of the top side */
462 } gerbv_render_size_t;
464 typedef struct gerbv_cirseg {
465 double cp_x;
466 double cp_y;
467 double width; /* of oval */
468 double height; /* of oval */
469 double angle1;
470 double angle2;
471 } gerbv_cirseg_t;
473 typedef struct gerbv_step_and_repeat { /* SR parameters */
474 int X;
475 int Y;
476 double dist_X;
477 double dist_Y;
478 } gerbv_step_and_repeat_t;
480 typedef struct {
481 gboolean firstInstance;
482 gerbv_knockout_type_t type;
483 gerbv_polarity_t polarity;
484 gdouble lowerLeftX;
485 gdouble lowerLeftY;
486 gdouble width;
487 gdouble height;
488 gdouble border;
489 } gerbv_knockout_t;
491 /*! The structure used to keep track of RS274X layer groups */
492 typedef struct {
493 gerbv_step_and_repeat_t stepAndRepeat; /*!< the current step and repeat group (refer to RS274X spec) */
494 gerbv_knockout_t knockout; /*!< the current knockout group (refer to RS274X spec) */
495 gdouble rotation; /*!< the current rotation around the origin */
496 gerbv_polarity_t polarity; /*!< the polarity of this layer */
497 gchar *name; /*!< the layer name (NULL for none) */
498 gpointer next; /*!< the next layer group in the array */
499 } gerbv_layer_t;
501 /*! The structure used to keep track of RS274X state groups */
502 typedef struct {
503 gerbv_axis_select_t axisSelect; /*!< the AB to XY coordinate mapping (refer to RS274X spec) */
504 gerbv_mirror_state_t mirrorState; /*!< any mirroring around the X or Y axis */
505 gerbv_unit_t unit; /*!< the current length unit */
506 gdouble offsetA; /*!< the offset along the A axis (usually this is the X axis) */
507 gdouble offsetB; /*!< the offset along the B axis (usually this is the Y axis) */
508 gdouble scaleA; /*!< the scale factor in the A axis (usually this is the X axis) */
509 gdouble scaleB; /*!< the scale factor in the B axis (usually this is the Y axis) */
510 gpointer next; /*!< the next state group in the array */
511 } gerbv_netstate_t;
513 /*! The structure used to hold a geometric entity (line/polygon/etc)*/
514 typedef struct gerbv_net {
515 double start_x; /*!< the X coordinate of the start point */
516 double start_y; /*!< the Y coordinate of the start point */
517 double stop_x; /*!< the X coordinate of the end point */
518 double stop_y; /*!< the Y coordinate of the end point */
519 gerbv_render_size_t boundingBox; /*!< the bounding box containing this net (used for rendering optimizations) */
520 int aperture; /*!< the index of the aperture used for this entity */
521 gerbv_aperture_state_t aperture_state; /*!< the state of the aperture tool (on/off/etc) */
522 gerbv_interpolation_t interpolation; /*!< the path interpolation method (linear/etc) */
523 gerbv_cirseg_t *cirseg; /*!< information for arc nets */
524 struct gerbv_net *next; /*!< the next net in the array */
525 GString *label; /*!< a label string for this net */
526 gerbv_layer_t *layer; /*!< the RS274X layer this net belongs to */
527 gerbv_netstate_t *state; /*!< the RS274X state this net belongs to */
528 } gerbv_net_t;
530 /*! Struct holding info about interpreting the Gerber files read
531 * e.g. leading zeros, etc. */
532 typedef struct gerbv_format {
533 gerbv_omit_zeros_t omit_zeros;
534 gerbv_coordinate_t coordinate;
535 int x_int;
536 int x_dec;
537 int y_int;
538 int y_dec;
539 int lim_seqno; /* Length limit for codes of sequence number */
540 int lim_gf; /* Length limit for codes of general function */
541 int lim_pf; /* Length limit for codes of plot function */
542 int lim_mf; /* Length limit for codes of miscellaneous function */
543 } gerbv_format_t;
546 /*! Struct holding info about a particular image */
547 typedef struct gerbv_image_info {
548 char *name;
549 gerbv_polarity_t polarity;
550 double min_x; /* Always in inches */
551 double min_y;
552 double max_x;
553 double max_y;
554 double offsetA;
555 double offsetB;
556 gerbv_encoding_t encoding;
557 double imageRotation;
558 gerbv_image_justify_type_t imageJustifyTypeA;
559 gerbv_image_justify_type_t imageJustifyTypeB;
560 gdouble imageJustifyOffsetA;
561 gdouble imageJustifyOffsetB;
562 gdouble imageJustifyOffsetActualA;
563 gdouble imageJustifyOffsetActualB;
564 gchar *plotterFilm;
566 /* Descriptive string for the type of file (rs274-x, drill, etc)
567 * that this is
569 gchar *type;
571 /* Attribute list that is used to hold all sorts of information
572 * about how the layer is to be parsed.
574 gerbv_HID_Attribute *attr_list;
575 int n_attr;
576 } gerbv_image_info_t;
578 /*! The structure used to hold a layer (RS274X, drill, or pick-and-place data) */
579 typedef struct {
580 gerbv_layertype_t layertype; /*!< the type of layer (RS274X, drill, or pick-and-place) */
581 gerbv_aperture_t *aperture[APERTURE_MAX]; /*!< an array with all apertures used */
582 gerbv_layer_t *layers; /*!< an array of all RS274X layers used (only used in RS274X types) */
583 gerbv_netstate_t *states; /*!< an array of all RS274X states used (only used in RS274X types) */
584 gerbv_amacro_t *amacro; /*!< an array of all macros used (only used in RS274X types) */
585 gerbv_format_t *format; /*!< formatting info */
586 gerbv_image_info_t *info; /*!< miscellaneous info regarding the layer such as overall size, etc */
587 gerbv_net_t *netlist; /*!< an array of all geometric entities in the layer */
588 gerbv_stats_t *gerbv_stats; /*!< RS274X statistics for the layer */
589 gerbv_drill_stats_t *drill_stats; /*!< Excellon drill statistics for the layer */
590 } gerbv_image_t;
592 /*! Holds information related to an individual layer that is part of a project */
593 typedef struct {
594 gerbv_image_t *image; /*!< the image holding all the geometry of the layer */
595 GdkColor color; /*!< the color to render this layer with */
596 guint16 alpha; /*!< the transparency to render this layer with */
597 gboolean isVisible; /*!< TRUE if this layer should be rendered with the project */
598 gpointer privateRenderData; /*!< private data holder for the rendering backend */
599 gchar *fullPathname; /*!< this full pathname to the file */
600 gchar *name; /*!< the name used when referring to this layer (e.g. in a layer selection menu) */
601 gerbv_user_transformation_t transform; /*!< user-specified transformation for this layer (mirroring, translating, etc) */
602 gboolean layer_dirty; /*!< True if layer has been modified since last save */
603 } gerbv_fileinfo_t;
605 typedef struct {
606 double x1, y1;
607 double x2, y2;
608 } gerbv_bbox_t;
610 /*! The top-level structure used in libgerbv. A gerbv_project_t groups together
611 any number of layers, while keeping track of other basic paramters needed for rendering */
612 typedef struct {
613 GdkColor background; /*!< the background color used for rendering */
614 int max_files; /*!< the current number of fileinfos in the file array */
615 gerbv_fileinfo_t **file; /*!< the array for holding the child fileinfos */
616 int curr_index; /*!< the index of the currently active fileinfo */
617 int last_loaded; /*!< the number of fileinfos currently in the project */
618 int renderType; /*!< the type of renderer to use */
619 gboolean check_before_delete; /*!< TRUE to ask before deleting objects */
620 gchar *path; /*!< the default path to load new files from */
621 gchar *execpath; /*!< the path to executed version of gerbv */
622 gchar *execname; /*!< the path plus executible name for gerbv */
623 gchar *project; /*!< the default name for the private project file */
624 } gerbv_project_t;
626 /*! Color of layer */
627 typedef struct{
628 unsigned char red;
629 unsigned char green;
630 unsigned char blue;
631 unsigned char alpha;
632 }gerbv_layer_color;
634 /*! This contains the rendering info for a scene */
635 typedef struct {
636 gdouble scaleFactorX; /*!< the X direction scale factor */
637 gdouble scaleFactorY; /*!< the Y direction scale factor */
638 gdouble lowerLeftX; /*!< the X coordinate of the lower left corner (in real world coordinates, in inches) */
639 gdouble lowerLeftY; /*!< the Y coordinate of the lower left corner (in real world coordinates, in inches) */
640 gerbv_render_types_t renderType; /*!< the type of rendering to use */
641 gint displayWidth; /*!< the width of the scene (in pixels, or points depending on the surface type) */
642 gint displayHeight; /*!< the height of the scene (in pixels, or points depending on the surface type) */
643 } gerbv_render_info_t;
645 //! Allocate a new gerbv_image structure
646 //! \return the newly created image
647 gerbv_image_t *gerbv_create_image(gerbv_image_t *image, /*!< the old image to free or NULL */
648 const gchar *type /*!< the type of image to create */
651 //! Free an image structure
652 void gerbv_destroy_image(gerbv_image_t *image /*!< the image to free */
655 //! Copy an image into an existing image, effectively merging the two together
656 void
657 gerbv_image_copy_image (gerbv_image_t *sourceImage, /*!< the source image */
658 gerbv_user_transformation_t *transform, /*!< the transformation to apply to the new image, or NULL for none */
659 gerbv_image_t *destinationImage /*!< the destination image to copy to */
662 //! Duplicate an existing image and return the new copy
663 //! \return the newly created image
664 gerbv_image_t *
665 gerbv_image_duplicate_image (gerbv_image_t *sourceImage, /*!< the source image */
666 gerbv_user_transformation_t *transform /*!< the transformation to apply to the new image, or NULL for none */
669 //! Delete a net in an existing image
670 void
671 gerbv_image_delete_net (gerbv_net_t *currentNet /*!< the net to delete */
674 void
675 gerbv_image_delete_selected_nets (gerbv_image_t *sourceImage, GArray *selectedNodeArray);
677 gboolean
678 gerbv_image_reduce_area_of_selected_objects (GArray *selectionArray, gdouble areaReduction, gint paneRows,
679 gint paneColumns, gdouble paneSeparation);
681 gboolean
682 gerbv_image_move_selected_objects (GArray *selectionArray, gdouble translationX,
683 gdouble translationY);
685 //! Return the next net entry which corresponds to a unique visible object
686 gerbv_net_t *
687 gerbv_image_return_next_renderable_object (gerbv_net_t *oldNet);
689 //! Create a new project structure and initialize some important variables
690 gerbv_project_t *
691 gerbv_create_project (void);
693 //! Free a project and all related variables
694 void
695 gerbv_destroy_project (gerbv_project_t *gerbvProject /*!< the project to destroy */
698 //! Open a file, parse the contents, and add a new layer to an existing project
699 void
700 gerbv_open_layer_from_filename (
701 gerbv_project_t *gerbvProject, /*!< the existing project to add the new layer to */
702 gchar *filename /*!< the full pathname of the file to be parsed */
705 //! Open a file, parse the contents, and add a new layer to an existing project while setting the color of the layer
706 void
707 gerbv_open_layer_from_filename_with_color(gerbv_project_t *gerbvProject, /*!< the existing project to add the new layer to */
708 gchar *filename, /*!< the full pathname of the file to be parsed */
709 guint16 red, /*!< the value for the red color component */
710 guint16 green, /*!< the value for the green color component */
711 guint16 blue, /*!< the value for the blue color component */
712 guint16 alpha /*!< the value for the alpha color component */
715 //! Free a fileinfo structure
716 void
717 gerbv_destroy_fileinfo (gerbv_fileinfo_t *fileInfo /*!< the fileinfo to free */
720 gboolean
721 gerbv_save_layer_from_index(gerbv_project_t *gerbvProject, gint index, gchar *filename);
724 gerbv_revert_file(gerbv_project_t *gerbvProject, int idx);
726 void
727 gerbv_revert_all_files(gerbv_project_t *gerbvProject);
729 void
730 gerbv_unload_layer(gerbv_project_t *gerbvProject, int index);
732 void
733 gerbv_unload_all_layers (gerbv_project_t *gerbvProject);
735 void
736 gerbv_change_layer_order(gerbv_project_t *gerbvProject, gint oldPosition, gint newPosition);
738 gint
739 gerbv_add_parsed_image_to_project (gerbv_project_t *gerbvProject, gerbv_image_t *parsed_image,
740 gchar *filename, gchar *baseName, int idx, int reload);
742 gerbv_open_image(gerbv_project_t *gerbvProject, char *filename, int idx, int reload,
743 gerbv_HID_Attribute *fattr, int n_fattr, gboolean forceLoadFile);
745 void
746 gerbv_render_get_boundingbox(gerbv_project_t *gerbvProject, gerbv_render_size_t *boundingbox);
748 //! Calculate the zoom and translations to fit the rendered scene inside the given scene size
749 void
750 gerbv_render_zoom_to_fit_display (gerbv_project_t *gerbvProject, /*!< the project to use for calculating */
751 gerbv_render_info_t *renderInfo /*!< the scene render pointer (updates the values in this parameter) */
754 void
755 gerbv_render_translate_to_fit_display (gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo);
757 void
758 gerbv_render_to_pixmap_using_gdk (gerbv_project_t *gerbvProject, GdkPixmap *pixmap,
759 gerbv_render_info_t *renderInfo, gerbv_selection_info_t *selectionInfo,
760 GdkColor *selectionColor);
762 #ifndef RENDER_USING_GDK
763 void
764 gerbv_render_all_layers_to_cairo_target_for_vector_output (gerbv_project_t *gerbvProject,
765 cairo_t *cr, gerbv_render_info_t *renderInfo);
767 void
768 gerbv_render_all_layers_to_cairo_target (gerbv_project_t *gerbvProject, cairo_t *cr,
769 gerbv_render_info_t *renderInfo);
771 //! Render a layer to a cairo context
772 void
773 gerbv_render_layer_to_cairo_target (cairo_t *cr, /*!< the cairo context */
774 gerbv_fileinfo_t *fileInfo, /*!< the layer fileinfo pointer */
775 gerbv_render_info_t *renderInfo /*!< the scene render info */
778 void
779 gerbv_render_cairo_set_scale_and_translation(cairo_t *cr, gerbv_render_info_t *renderInfo);
781 void
782 gerbv_render_layer_to_cairo_target_without_transforming(cairo_t *cr, gerbv_fileinfo_t *fileInfo, gerbv_render_info_t *renderInfo, gboolean pixelOutput );
783 #endif
785 double
786 gerbv_get_tool_diameter(int toolNumber
790 gerbv_process_tools_file(const char *toolFileName
793 //! Render a project to a PNG file, autoscaling the layers to fit inside the specified image dimensions
794 void
795 gerbv_export_png_file_from_project_autoscaled (
796 gerbv_project_t *gerbvProject, /*!< the project to render */
797 int widthInPixels, /*!< the width of the rendered picture (in pixels) */
798 int heightInPixels, /*!< the height of the rendered picture (in pixels) */
799 gchar const* filename /*!< the filename for the exported PNG file */
802 //! Render a project to a PNG file using user-specified render info
803 void
804 gerbv_export_png_file_from_project (
805 gerbv_project_t *gerbvProject, /*!< the project to render */
806 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
807 gchar const* filename /*!< the filename for the exported PNG file */
810 //! Render a project to a PDF file, autoscaling the layers to fit inside the specified image dimensions
811 void
812 gerbv_export_pdf_file_from_project_autoscaled (
813 gerbv_project_t *gerbvProject, /*!< the project to render */
814 gchar const* filename /*!< the filename for the exported PDF file */
817 //! Render a project to a PDF file using user-specified render info
818 void
819 gerbv_export_pdf_file_from_project (
820 gerbv_project_t *gerbvProject, /*!< the project to render */
821 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
822 gchar const* filename /*!< the filename for the exported PDF file */
825 //! Render a project to a Postscript file, autoscaling the layers to fit inside the specified image dimensions
826 void
827 gerbv_export_postscript_file_from_project_autoscaled (
828 gerbv_project_t *gerbvProject, /*!< the project to render */
829 gchar const* filename /*!< the filename for the exported Postscript file */
832 //! Render a project to a Postscript file using user-specified render info
833 void
834 gerbv_export_postscript_file_from_project (
835 gerbv_project_t *gerbvProject, /*!< the project to render */
836 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
837 gchar const* filename /*!< the filename for the exported Postscript file */
840 //! Render a project to a SVG file, autoscaling the layers to fit inside the specified image dimensions
841 void
842 gerbv_export_svg_file_from_project_autoscaled (
843 gerbv_project_t *gerbvProject, /*!< the project to render */
844 gchar const* filename /*!< the filename for the exported file */
847 //! Render a project to a file using user-specified render info
848 void
849 gerbv_export_svg_file_from_project (
850 gerbv_project_t *gerbvProject, /*!< the project to render */
851 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
852 gchar const* filename /*!< the filename for the exported file */
855 //! Parse a RS274X file and return the parsed image
856 //! \return the new gerbv_image_t, or NULL if not successful
857 gerbv_image_t *
858 gerbv_create_rs274x_image_from_filename (gchar *filename /*!< the filename of the file to be parsed*/
861 //! Export an image to a new file in RS274X format
862 //! \return TRUE if successful, or FALSE if not
863 gboolean
864 gerbv_export_rs274x_file_from_image (gchar *filename, /*!< the filename for the new file */
865 gerbv_image_t *image, /*!< the image to export */
866 gerbv_user_transformation_t *transform /*!< the transformation to apply before exporting */
869 //! Export an image to a new file in Excellon drill format
870 //! \return TRUE if successful, or FALSE if not
871 gboolean
872 gerbv_export_drill_file_from_image (gchar *filename, /*!< the filename for the new file */
873 gerbv_image_t *image, /*!< the image to export */
874 gerbv_user_transformation_t *transform /*!< the transformation to apply before exporting */
877 //! Draw a line on the specified image
878 void
879 gerbv_image_create_line_object (gerbv_image_t *image, /*!< the image to draw to */
880 gdouble startX, /*!< the starting X coordinate */
881 gdouble startY, /*!< the starting Y coordinate */
882 gdouble endX, /*!< the ending X coordinate */
883 gdouble endY, /*!< the ending Y coordinate */
884 gdouble lineWidth, /*!< the width of the line to draw */
885 gerbv_aperture_type_t apertureType /*!< the type of aperture to use (e.g. CIRCLE) */
888 //! Draw an arc on the specified image
889 void
890 gerbv_image_create_arc_object (gerbv_image_t *image, /*!< the image to draw to */
891 gdouble centerX, /*!< the center X coordinate */
892 gdouble centerY, /*!< the center Y coordinate */
893 gdouble radius, /*!< the arc radius */
894 gdouble startAngle, /*!< the start angle (in CCW degrees) */
895 gdouble endAngle, /*!< the start angle (in CCW degrees) */
896 gdouble lineWidth, /*!< the width of the line to draw */
897 gerbv_aperture_type_t apertureType /*!< the type of aperture to use (e.g. CIRCLE) */
900 //! Draw a filled rectangle on the specified image
901 void
902 gerbv_image_create_rectangle_object (gerbv_image_t *image, /*!< the image to draw to */
903 gdouble coordinateX, /*!< the X coordinate of the lower left corner */
904 gdouble coordinateY, /*!< the Y coordinate of the lower left corner */
905 gdouble width, /*!< the width of the drawn rectangle */
906 gdouble height /*!< the height of the drawn rectangle */
909 //! Create any missing apertures in the specified image
910 void
911 gerbv_image_create_dummy_apertures (gerbv_image_t *parsed_image /*!< the image to repair */
914 /*! Create new struct for holding drill stats */
915 gerbv_drill_stats_t *
916 gerbv_drill_stats_new(void);
918 /*! Free the memory for a drill stats struct */
919 void
920 gerbv_drill_stats_destroy(gerbv_drill_stats_t *);
922 /*! Add stats gathered from specified layer to accumulatedd drill stats
923 * compiled from all layers */
924 void
925 gerbv_drill_stats_add_layer(gerbv_drill_stats_t *accum_stats,
926 gerbv_drill_stats_t *input_stats,
927 int this_layer
930 /*! Create new struct for holding Gerber stats */
931 gerbv_stats_t *
932 gerbv_stats_new(void);
934 /*! Free the memory for a stats struct */
935 void
936 gerbv_stats_destroy(gerbv_stats_t *);
938 /*! Add stats gathered from specified layer to accumulated Gerber stats
939 * compiled from all layers */
940 void
941 gerbv_stats_add_layer(gerbv_stats_t *accum_stats,
942 gerbv_stats_t *input_stats,
943 int this_layer
946 void
947 gerbv_attribute_destroy_HID_attribute (gerbv_HID_Attribute *attributeList, int n_attr);
949 gerbv_HID_Attribute *
950 gerbv_attribute_dup (gerbv_HID_Attribute *, int);
952 #if defined(__cplusplus)
954 #endif
956 #endif /* __GERBV_H__ */