* fix a bug where clicking on the message tab made keyboard accelerators stop working
[geda-gerbv.git] / src / gerbv.h
blob106c049a0ce8031b0a1587ce3879d9b83606dd8c
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 #ifdef HAVE_CONFIG_H
62 #include "config.h"
63 #endif
65 #include <glib.h>
66 #include <gtk/gtk.h>
67 #include <gdk/gdk.h>
68 #include <gdk/gdkkeysyms.h>
70 #ifndef RENDER_USING_GDK
71 #include <cairo.h>
72 #endif
74 #define APERTURE_MIN 10
75 #define APERTURE_MAX 9999
78 * Maximum number of aperture parameters is set by the outline aperture
79 * macro. There (p. 28) is defined up to 50 points in polygon.
80 * So 50 points with x and y plus two for holding extra data gives...
82 #define APERTURE_PARAMETERS_MAX 102
83 #define INITIAL_SCALE 200
84 #define MAX_ERRMSGLEN 25
85 #define MAX_COORDLEN 28
86 #define MAX_DISTLEN 90
87 #define MAX_STATUSMSGLEN (MAX_ERRMSGLEN+MAX_COORDLEN+MAX_DISTLEN)
89 /* Macros to convert between unscaled gerber coordinates and other units */
90 /* XXX NOTE: Currently unscaled units are assumed as inch, this is not
91 XXX necessarily true for all files */
92 #define COORD2MILS(c) ((c)*1000.0)
93 #define COORD2MMS(c) ((c)*25.4)
95 #define GERB_FATAL_ERROR(t...) g_log(NULL, G_LOG_LEVEL_ERROR, ##t);
96 #define GERB_COMPILE_ERROR(t...) g_log(NULL, G_LOG_LEVEL_CRITICAL, ##t);
97 #define GERB_COMPILE_WARNING(t...) g_log(NULL, G_LOG_LEVEL_WARNING, ##t);
98 #define GERB_MESSAGE(t...) g_log(NULL, G_LOG_LEVEL_MESSAGE, ##t);
100 /*! The aperture macro commands */
101 typedef enum {GERBV_OPCODE_NOP, /*!< no operation */
102 GERBV_OPCODE_PUSH, /*!< push the instruction onto the stack */
103 GERBV_OPCODE_PPUSH, /*!< push parameter onto stack */
104 GERBV_OPCODE_PPOP, /*!< pop parameter from stack */
105 GERBV_OPCODE_ADD, /*!< mathmatical add operation */
106 GERBV_OPCODE_SUB, /*!< mathmatical subtract operation */
107 GERBV_OPCODE_MUL, /*!< mathmatical multiply operation */
108 GERBV_OPCODE_DIV, /*!< mathmatical divide operation */
109 GERBV_OPCODE_PRIM /*!< draw macro primative */
110 } gerbv_opcodes_t;
112 /*! The different message types used in libgerbv */
113 typedef enum {GERBV_MESSAGE_FATAL, /*!< processing cannot continue */
114 GERBV_MESSAGE_ERROR, /*!< something went wrong, but processing can still continue */
115 GERBV_MESSAGE_WARNING, /*!< something was encountered that may provide the wrong output */
116 GERBV_MESSAGE_NOTE /*!< an irregularity was encountered, but needs no intervention */
117 } gerbv_message_type_t;
119 /*! The different aperture types available
120 * Please keep these in sync with the aperture names defined by
121 * ap_names in callbacks.c */
122 typedef enum {GERBV_APTYPE_NONE, /*!< no aperture used */
123 GERBV_APTYPE_CIRCLE, /*!< a round aperture */
124 GERBV_APTYPE_RECTANGLE, /*!< a rectangular aperture */
125 GERBV_APTYPE_OVAL, /*!< an ovular (obround) aperture */
126 GERBV_APTYPE_POLYGON, /*!< a polygon aperture */
127 GERBV_APTYPE_MACRO, /*!< a RS274X macro */
128 GERBV_APTYPE_MACRO_CIRCLE, /*!< a RS274X circle macro */
129 GERBV_APTYPE_MACRO_OUTLINE, /*!< a RS274X outline macro */
130 GERBV_APTYPE_MACRO_POLYGON, /*!< a RS274X polygon macro */
131 GERBV_APTYPE_MACRO_MOIRE, /*!< a RS274X moire macro */
132 GERBV_APTYPE_MACRO_THERMAL, /*!< a RS274X thermal macro */
133 GERBV_APTYPE_MACRO_LINE20, /*!< a RS274X line (code 20) macro */
134 GERBV_APTYPE_MACRO_LINE21, /*!< a RS274X line (code 21) macro */
135 GERBV_APTYPE_MACRO_LINE22 /*!< a RS274X line (code 22) macro */
136 } gerbv_aperture_type_t;
138 /*! the current state of the aperture drawing tool */
139 typedef enum {GERBV_APERTURE_STATE_OFF, /*!< tool drawing is off, and nothing will be drawn */
140 GERBV_APERTURE_STATE_ON, /*!< tool drawing is on, and something will be drawn */
141 GERBV_APERTURE_STATE_FLASH /*!< tool is flashing, and will draw a single aperture */
142 } gerbv_aperture_state_t;
144 /*! the current unit used */
145 typedef enum {GERBV_UNIT_INCH, /*!< inches */
146 GERBV_UNIT_MM, /*!< mm */
147 GERBV_UNIT_UNSPECIFIED /*!< use default units */
148 } gerbv_unit_t;
150 /*! the different drawing polarities available */
151 typedef enum {GERBV_POLARITY_POSITIVE, /*!< draw "positive", using the current layer's polarity */
152 GERBV_POLARITY_NEGATIVE, /*!< draw "negative", reversing the current layer's polarity */
153 GERBV_POLARITY_DARK, /*!< add to the current rendering */
154 GERBV_POLARITY_CLEAR /*!< subtract from the current rendering */
155 } gerbv_polarity_t;
157 /*! the decimal point parsing style used */
158 typedef enum {GERBV_OMIT_ZEROS_LEADING, /*!< omit extra zeros before the decimal point */
159 GERBV_OMIT_ZEROS_TRAILING, /*!< omit extra zeros after the decimal point */
160 GERBV_OMIT_ZEROS_EXPLICIT, /*!< explicitly specify how many decimal places are used */
161 GERBV_OMIT_ZEROS_UNSPECIFIED /*!< use the default parsing style */
162 } gerbv_omit_zeros_t;
164 /*! the coordinate system used */
165 typedef enum {GERBV_COORDINATE_ABSOLUTE, /*!< all coordinates are absolute from a common origin */
166 GERBV_COORDINATE_INCREMENTAL /*!< all coordinates are relative to the previous coordinate */
167 } gerbv_coordinate_t;
169 /*! the interpolation methods available */
170 typedef enum {GERBV_INTERPOLATION_LINEARx1, /*!< draw a line */
171 GERBV_INTERPOLATION_x10, /*!< draw a line */
172 GERBV_INTERPOLATION_LINEARx01, /*!< draw a line */
173 GERBV_INTERPOLATION_LINEARx001, /*!< draw a line */
174 GERBV_INTERPOLATION_CW_CIRCULAR, /*!< draw an arc in the clockwise direction */
175 GERBV_INTERPOLATION_CCW_CIRCULAR, /*!< draw an arc in the counter-clockwise direction */
176 GERBV_INTERPOLATION_PAREA_START, /*!< start a polygon draw */
177 GERBV_INTERPOLATION_PAREA_END, /*!< end a polygon draw */
178 GERBV_INTERPOLATION_DELETED /*!< the net has been deleted by the user, and will not be drawn */
179 } gerbv_interpolation_t;
181 typedef enum {GERBV_ENCODING_NONE,
182 GERBV_ENCODING_ASCII,
183 GERBV_ENCODING_EBCDIC,
184 GERBV_ENCODING_BCD,
185 GERBV_ENCODING_ISO_ASCII,
186 GERBV_ENCODING_EIA
187 } gerbv_encoding_t;
189 /*! The different layer types used */
190 typedef enum {GERBV_LAYERTYPE_RS274X, /*!< the file is a RS274X file */
191 GERBV_LAYERTYPE_DRILL, /*!< the file is an Excellon drill file */
192 GERBV_LAYERTYPE_PICKANDPLACE /*!< the file is a CSV pick and place file */
193 } gerbv_layertype_t;
195 typedef enum {GERBV_KNOCKOUT_TYPE_NOKNOCKOUT,
196 GERBV_KNOCKOUT_TYPE_FIXEDKNOCK,
197 GERBV_KNOCKOUT_TYPE_BORDER
198 } gerbv_knockout_type_t;
200 typedef enum {GERBV_MIRROR_STATE_NOMIRROR,
201 GERBV_MIRROR_STATE_FLIPA,
202 GERBV_MIRROR_STATE_FLIPB,
203 GERBV_MIRROR_STATE_FLIPAB
204 } gerbv_mirror_state_t;
206 typedef enum {GERBV_AXIS_SELECT_NOSELECT,
207 GERBV_AXIS_SELECT_SWAPAB
208 } gerbv_axis_select_t;
210 typedef enum {GERBV_JUSTIFY_NOJUSTIFY,
211 GERBV_JUSTIFY_LOWERLEFT,
212 GERBV_JUSTIFY_CENTERJUSTIFY
213 } gerbv_image_justify_type_t;
215 /*! The different selection modes available */
216 typedef enum {GERBV_SELECTION_EMPTY, /*!< the selection buffer is empty */
217 GERBV_SELECTION_POINT_CLICK, /*!< the user clicked on a single point */
218 GERBV_SELECTION_DRAG_BOX /*!< the user dragged a box to encompass one or more objects */
219 } gerbv_selection_t;
221 /*! The different rendering modes available to libgerbv */
222 typedef enum {GERBV_RENDER_TYPE_GDK, /*!< render using normal GDK drawing functions */
223 GERBV_RENDER_TYPE_GDK_XOR, /*!< use the GDK_XOR mask to draw a pseudo-transparent scene */
224 GERBV_RENDER_TYPE_CAIRO_NORMAL, /*!< use the cairo library */
225 GERBV_RENDER_TYPE_CAIRO_HIGH_QUALITY /*!< use the cairo library with the smoothest edges */
226 } gerbv_render_types_t;
229 * The following typedef's are taken directly from src/hid.h in the
230 * pcb project. The names are kept the same to make it easier to
231 * compare to pcb's sources.
234 /* Used for HID attributes (exporting and printing, mostly).
235 HA_boolean uses int_value, HA_enum sets int_value to the index and
236 str_value to the enumeration string. HID_Label just shows the
237 default str_value. HID_Mixed is a real_value followed by an enum,
238 like 0.5in or 100mm.
240 typedef struct {
241 int int_value;
242 char *str_value;
243 double real_value;
244 } gerbv_HID_Attr_Val;
246 typedef struct {
247 char *name;
248 char *help_text;
249 enum
250 { HID_Label, HID_Integer, HID_Real, HID_String,
251 HID_Boolean, HID_Enum, HID_Mixed, HID_Path
252 } type;
253 int min_val, max_val; /* for integer and real */
254 gerbv_HID_Attr_Val default_val; /* Also actual value for global attributes. */
255 const char **enumerations;
256 /* If set, this is used for global attributes (i.e. those set
257 statically with REGISTER_ATTRIBUTES below) instead of changing
258 the default_val. Note that a HID_Mixed attribute must specify a
259 pointer to gerbv_HID_Attr_Val here, and HID_Boolean assumes this is
260 "char *" so the value should be initialized to zero, and may be
261 set to non-zero (not always one). */
262 void *value;
263 int hash; /* for detecting changes. */
264 } gerbv_HID_Attribute;
265 /* end of HID attributes from PCB */
267 /*! A linked list of errors found in the files */
268 typedef struct error_list {
269 int layer;
270 gchar *error_text;
271 gerbv_message_type_t type;
272 struct error_list *next;
273 } gerbv_error_list_t;
275 typedef struct instruction {
276 gerbv_opcodes_t opcode;
277 union {
278 int ival;
279 float fval;
280 } data;
281 struct instruction *next;
282 } gerbv_instruction_t;
284 typedef struct amacro {
285 gchar *name;
286 gerbv_instruction_t *program;
287 unsigned int nuf_push; /* Nuf pushes in program to estimate stack size */
288 struct amacro *next;
289 } gerbv_amacro_t;
291 typedef struct gerbv_simplified_amacro {
292 gerbv_aperture_type_t type;
293 double parameter[APERTURE_PARAMETERS_MAX];
294 struct gerbv_simplified_amacro *next;
295 } gerbv_simplified_amacro_t;
297 typedef struct gerbv_aperture {
298 gerbv_aperture_type_t type;
299 gerbv_amacro_t *amacro;
300 gerbv_simplified_amacro_t *simplified;
301 double parameter[APERTURE_PARAMETERS_MAX];
302 int nuf_parameters;
303 gerbv_unit_t unit;
304 } gerbv_aperture_t;
306 /* the gerb_aperture_list is used to keep track of
307 * apertures used in stats reporting */
308 typedef struct gerbv_aperture_list {
309 int number;
310 int layer;
311 int count;
312 gerbv_aperture_type_t type;
313 double parameter[5];
314 struct gerbv_aperture_list *next;
315 } gerbv_aperture_list_t;
317 /*! Contains statistics on the various codes used in a RS274X file */
318 typedef struct {
319 gerbv_error_list_t *error_list;
320 gerbv_aperture_list_t *aperture_list;
321 gerbv_aperture_list_t *D_code_list;
323 int layer_count;
324 int G0;
325 int G1;
326 int G2;
327 int G3;
328 int G4;
329 int G10;
330 int G11;
331 int G12;
332 int G36;
333 int G37;
334 int G54;
335 int G55;
336 int G70;
337 int G71;
338 int G74;
339 int G75;
340 int G90;
341 int G91;
342 int G_unknown;
344 int D1;
345 int D2;
346 int D3;
347 /* GHashTable *D_user_defined; */
348 int D_unknown;
349 int D_error;
351 int M0;
352 int M1;
353 int M2;
354 int M_unknown;
356 int X;
357 int Y;
358 int I;
359 int J;
361 /* Must include % RS-274 codes */
362 int star;
363 int unknown;
365 } gerbv_stats_t;
367 /*! Linked list of drills found in active layers. Used in reporting statistics */
368 typedef struct drill_list {
369 int drill_num;
370 double drill_size;
371 gchar *drill_unit;
372 int drill_count;
373 struct drill_list *next;
374 } gerbv_drill_list_t;
376 /*! Struct holding statistics of drill commands used. Used in reporting statistics */
377 typedef struct {
378 int layer_count;
380 gerbv_error_list_t *error_list;
381 gerbv_drill_list_t *drill_list;
382 int comment;
383 int F;
385 int G00;
386 int G01;
387 int G02;
388 int G03;
389 int G04;
390 int G05;
391 int G90;
392 int G91;
393 int G93;
394 int G_unknown;
396 int M00;
397 int M01;
398 int M18;
399 int M25;
400 int M30;
401 int M31;
402 int M45;
403 int M47;
404 int M48;
405 int M71;
406 int M72;
407 int M95;
408 int M97;
409 int M98;
410 int M_unknown;
412 int unknown;
414 char *detect;
416 } gerbv_drill_stats_t;
418 typedef struct {
419 gpointer image;
420 gpointer net;
421 } gerbv_selection_item_t;
423 /*! Struct holding info about the last selection */
424 typedef struct {
425 gerbv_selection_t type;
426 gdouble lowerLeftX;
427 gdouble lowerLeftY;
428 gdouble upperRightX;
429 gdouble upperRightY;
430 GArray *selectedNodeArray;
431 } gerbv_selection_info_t;
433 /*! Stores image transformation information, used to modify the rendered
434 position/scale/etc of an image. */
435 typedef struct {
436 gdouble translateX; /*!< the X translation (in inches) */
437 gdouble translateY; /*!< the Y translation (in inches) */
438 gdouble scaleX; /*!< the X scale factor (1.0 is default) */
439 gdouble scaleY; /*!< the Y scale factor (1.0 is default) */
440 gboolean inverted; /*!< TRUE if the image should be rendered "inverted" (light is dark and vice versa) */
441 } gerbv_user_transformation_t;
443 /*! This defines a box location and size (used to rendering logic) */
444 typedef struct {
445 double left; /*!< the X coordinate of the left side */
446 double right; /*!< the X coordinate of the right side */
447 double bottom; /*!< the Y coordinate of the bottom side */
448 double top; /*!< the Y coordinate of the top side */
449 } gerbv_render_size_t;
451 typedef struct gerbv_cirseg {
452 double cp_x;
453 double cp_y;
454 double width; /* of oval */
455 double height; /* of oval */
456 double angle1;
457 double angle2;
458 } gerbv_cirseg_t;
460 typedef struct gerbv_step_and_repeat { /* SR parameters */
461 int X;
462 int Y;
463 double dist_X;
464 double dist_Y;
465 } gerbv_step_and_repeat_t;
467 typedef struct {
468 gboolean firstInstance;
469 gerbv_knockout_type_t type;
470 gerbv_polarity_t polarity;
471 gdouble lowerLeftX;
472 gdouble lowerLeftY;
473 gdouble width;
474 gdouble height;
475 gdouble border;
476 } gerbv_knockout_t;
478 /*! The structure used to keep track of RS274X layer groups */
479 typedef struct {
480 gerbv_step_and_repeat_t stepAndRepeat; /*!< the current step and repeat group (refer to RS274X spec) */
481 gerbv_knockout_t knockout; /*!< the current knockout group (refer to RS274X spec) */
482 gdouble rotation; /*!< the current rotation around the origin */
483 gerbv_polarity_t polarity; /*!< the polarity of this layer */
484 gchar *name; /*!< the layer name (NULL for none) */
485 gpointer next; /*!< the next layer group in the array */
486 } gerbv_layer_t;
488 /*! The structure used to keep track of RS274X state groups */
489 typedef struct {
490 gerbv_axis_select_t axisSelect; /*!< the AB to XY coordinate mapping (refer to RS274X spec) */
491 gerbv_mirror_state_t mirrorState; /*!< any mirroring around the X or Y axis */
492 gerbv_unit_t unit; /*!< the current length unit */
493 gdouble offsetA; /*!< the offset along the A axis (usually this is the X axis) */
494 gdouble offsetB; /*!< the offset along the B axis (usually this is the Y axis) */
495 gdouble scaleA; /*!< the scale factor in the A axis (usually this is the X axis) */
496 gdouble scaleB; /*!< the scale factor in the B axis (usually this is the Y axis) */
497 gpointer next; /*!< the next state group in the array */
498 } gerbv_netstate_t;
500 /*! The structure used to hold a geometric entity (line/polygon/etc)*/
501 typedef struct gerbv_net {
502 double start_x; /*!< the X coordinate of the start point */
503 double start_y; /*!< the Y coordinate of the start point */
504 double stop_x; /*!< the X coordinate of the end point */
505 double stop_y; /*!< the Y coordinate of the end point */
506 gerbv_render_size_t boundingBox; /*!< the bounding box containing this net (used for rendering optimizations) */
507 int aperture; /*!< the index of the aperture used for this entity */
508 gerbv_aperture_state_t aperture_state; /*!< the state of the aperture tool (on/off/etc) */
509 gerbv_interpolation_t interpolation; /*!< the path interpolation method (linear/etc) */
510 gerbv_cirseg_t *cirseg; /*!< information for arc nets */
511 struct gerbv_net *next; /*!< the next net in the array */
512 GString *label; /*!< a label string for this net */
513 gerbv_layer_t *layer; /*!< the RS274X layer this net belongs to */
514 gerbv_netstate_t *state; /*!< the RS274X state this net belongs to */
515 } gerbv_net_t;
517 /*! Struct holding info about interpreting the Gerber files read
518 * e.g. leading zeros, etc. */
519 typedef struct gerbv_format {
520 gerbv_omit_zeros_t omit_zeros;
521 gerbv_coordinate_t coordinate;
522 int x_int;
523 int x_dec;
524 int y_int;
525 int y_dec;
526 int lim_seqno; /* Length limit for codes of sequence number */
527 int lim_gf; /* Length limit for codes of general function */
528 int lim_pf; /* Length limit for codes of plot function */
529 int lim_mf; /* Length limit for codes of miscellaneous function */
530 } gerbv_format_t;
533 /*! Struct holding info about a particular image */
534 typedef struct gerbv_image_info {
535 char *name;
536 gerbv_polarity_t polarity;
537 double min_x; /* Always in inches */
538 double min_y;
539 double max_x;
540 double max_y;
541 double offsetA;
542 double offsetB;
543 gerbv_encoding_t encoding;
544 double imageRotation;
545 gerbv_image_justify_type_t imageJustifyTypeA;
546 gerbv_image_justify_type_t imageJustifyTypeB;
547 gdouble imageJustifyOffsetA;
548 gdouble imageJustifyOffsetB;
549 gdouble imageJustifyOffsetActualA;
550 gdouble imageJustifyOffsetActualB;
551 gchar *plotterFilm;
553 /* Descriptive string for the type of file (rs274-x, drill, etc)
554 * that this is
556 gchar *type;
558 /* Attribute list that is used to hold all sorts of information
559 * about how the layer is to be parsed.
561 gerbv_HID_Attribute *attr_list;
562 int n_attr;
563 } gerbv_image_info_t;
565 /*! The structure used to hold a layer (RS274X, drill, or pick-and-place data) */
566 typedef struct {
567 gerbv_layertype_t layertype; /*!< the type of layer (RS274X, drill, or pick-and-place) */
568 gerbv_aperture_t *aperture[APERTURE_MAX]; /*!< an array with all apertures used */
569 gerbv_layer_t *layers; /*!< an array of all RS274X layers used (only used in RS274X types) */
570 gerbv_netstate_t *states; /*!< an array of all RS274X states used (only used in RS274X types) */
571 gerbv_amacro_t *amacro; /*!< an array of all macros used (only used in RS274X types) */
572 gerbv_format_t *format; /*!< formatting info */
573 gerbv_image_info_t *info; /*!< miscellaneous info regarding the layer such as overall size, etc */
574 gerbv_net_t *netlist; /*!< an array of all geometric entities in the layer */
575 gerbv_stats_t *gerbv_stats; /*!< RS274X statistics for the layer */
576 gerbv_drill_stats_t *drill_stats; /*!< Excellon drill statistics for the layer */
577 } gerbv_image_t;
579 /*! Holds information related to an individual layer that is part of a project */
580 typedef struct {
581 gerbv_image_t *image; /*!< the image holding all the geometry of the layer */
582 GdkColor color; /*!< the color to render this layer with */
583 guint16 alpha; /*!< the transparency to render this layer with */
584 gboolean isVisible; /*!< TRUE if this layer should be rendered with the project */
585 gpointer privateRenderData; /*!< private data holder for the rendering backend */
586 gchar *fullPathname; /*!< this full pathname to the file */
587 gchar *name; /*!< the name used when referring to this layer (e.g. in a layer selection menu) */
588 gerbv_user_transformation_t transform; /*!< user-specified transformation for this layer (mirroring, translating, etc) */
589 gboolean layer_dirty; /*!< True if layer has been modified since last save */
590 } gerbv_fileinfo_t;
592 typedef struct {
593 double x1, y1;
594 double x2, y2;
595 } gerbv_bbox_t;
597 /*! The top-level structure used in libgerbv. A gerbv_project_t groups together
598 any number of layers, while keeping track of other basic paramters needed for rendering */
599 typedef struct {
600 GdkColor background; /*!< the background color used for rendering */
601 int max_files; /*!< the current number of fileinfos in the file array */
602 gerbv_fileinfo_t **file; /*!< the array for holding the child fileinfos */
603 int curr_index; /*!< the index of the currently active fileinfo */
604 int last_loaded; /*!< the number of fileinfos currently in the project */
605 int renderType; /*!< the type of renderer to use */
606 gboolean check_before_delete; /*!< TRUE to ask before deleting objects */
607 gchar *path; /*!< the default path to load new files from */
608 gchar *execpath; /*!< the path to executed version of gerbv */
609 gchar *execname; /*!< the path plus executible name for gerbv */
610 gchar *project; /*!< the default name for the private project file */
611 } gerbv_project_t;
613 /*! Color of layer */
614 typedef struct{
615 unsigned char red;
616 unsigned char green;
617 unsigned char blue;
618 unsigned char alpha;
619 }gerbv_layer_color;
621 /*! This contains the rendering info for a scene */
622 typedef struct {
623 gdouble scaleFactorX; /*!< the X direction scale factor */
624 gdouble scaleFactorY; /*!< the Y direction scale factor */
625 gdouble lowerLeftX; /*!< the X coordinate of the lower left corner (in real world coordinates, in inches) */
626 gdouble lowerLeftY; /*!< the Y coordinate of the lower left corner (in real world coordinates, in inches) */
627 gerbv_render_types_t renderType; /*!< the type of rendering to use */
628 gint displayWidth; /*!< the width of the scene (in pixels, or points depending on the surface type) */
629 gint displayHeight; /*!< the height of the scene (in pixels, or points depending on the surface type) */
630 } gerbv_render_info_t;
632 //! Allocate a new gerbv_image structure
633 //! \return the newly created image
634 gerbv_image_t *gerbv_create_image(gerbv_image_t *image, /*!< the old image to free or NULL */
635 const gchar *type /*!< the type of image to create */
638 //! Free an image structure
639 void gerbv_destroy_image(gerbv_image_t *image /*!< the image to free */
642 //! Copy an image into an existing image, effectively merging the two together
643 void
644 gerbv_image_copy_image (gerbv_image_t *sourceImage, /*!< the source image */
645 gerbv_user_transformation_t *transform, /*!< the transformation to apply to the new image, or NULL for none */
646 gerbv_image_t *destinationImage /*!< the destination image to copy to */
649 //! Duplicate an existing image and return the new copy
650 //! \return the newly created image
651 gerbv_image_t *
652 gerbv_image_duplicate_image (gerbv_image_t *sourceImage, /*!< the source image */
653 gerbv_user_transformation_t *transform /*!< the transformation to apply to the new image, or NULL for none */
656 //! Delete a net in an existing image
657 void
658 gerbv_image_delete_net (gerbv_net_t *currentNet /*!< the net to delete */
661 void
662 gerbv_image_delete_selected_nets (gerbv_image_t *sourceImage, GArray *selectedNodeArray);
664 gboolean
665 gerbv_image_reduce_area_of_selected_objects (GArray *selectionArray, gdouble areaReduction, gint paneRows,
666 gint paneColumns, gdouble paneSeparation);
668 gboolean
669 gerbv_image_move_selected_objects (GArray *selectionArray, gdouble translationX,
670 gdouble translationY);
672 //! Return the next net entry which corresponds to a unique visible object
673 gerbv_net_t *
674 gerbv_image_return_next_renderable_object (gerbv_net_t *oldNet);
676 //! Create a new project structure and initialize some important variables
677 gerbv_project_t *
678 gerbv_create_project (void);
680 //! Free a project and all related variables
681 void
682 gerbv_destroy_project (gerbv_project_t *gerbvProject /*!< the project to destroy */
685 //! Open a file, parse the contents, and add a new layer to an existing project
686 void
687 gerbv_open_layer_from_filename (
688 gerbv_project_t *gerbvProject, /*!< the existing project to add the new layer to */
689 gchar *filename /*!< the full pathname of the file to be parsed */
692 //! Open a file, parse the contents, and add a new layer to an existing project while setting the color of the layer
693 void
694 gerbv_open_layer_from_filename_with_color(gerbv_project_t *gerbvProject, /*!< the existing project to add the new layer to */
695 gchar *filename, /*!< the full pathname of the file to be parsed */
696 guint16 red, /*!< the value for the red color component */
697 guint16 green, /*!< the value for the green color component */
698 guint16 blue, /*!< the value for the blue color component */
699 guint16 alpha /*!< the value for the alpha color component */
702 //! Free a fileinfo structure
703 void
704 gerbv_destroy_fileinfo (gerbv_fileinfo_t *fileInfo /*!< the fileinfo to free */
707 gboolean
708 gerbv_save_layer_from_index(gerbv_project_t *gerbvProject, gint index, gchar *filename);
711 gerbv_revert_file(gerbv_project_t *gerbvProject, int idx);
713 void
714 gerbv_revert_all_files(gerbv_project_t *gerbvProject);
716 void
717 gerbv_unload_layer(gerbv_project_t *gerbvProject, int index);
719 void
720 gerbv_unload_all_layers (gerbv_project_t *gerbvProject);
722 void
723 gerbv_change_layer_order(gerbv_project_t *gerbvProject, gint oldPosition, gint newPosition);
725 gint
726 gerbv_add_parsed_image_to_project (gerbv_project_t *gerbvProject, gerbv_image_t *parsed_image,
727 gchar *filename, gchar *baseName, int idx, int reload);
729 gerbv_open_image(gerbv_project_t *gerbvProject, char *filename, int idx, int reload,
730 gerbv_HID_Attribute *fattr, int n_fattr, gboolean forceLoadFile);
732 void
733 gerbv_render_get_boundingbox(gerbv_project_t *gerbvProject, gerbv_render_size_t *boundingbox);
735 //! Calculate the zoom and translations to fit the rendered scene inside the given scene size
736 void
737 gerbv_render_zoom_to_fit_display (gerbv_project_t *gerbvProject, /*!< the project to use for calculating */
738 gerbv_render_info_t *renderInfo /*!< the scene render pointer (updates the values in this parameter) */
741 void
742 gerbv_render_translate_to_fit_display (gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo);
744 void
745 gerbv_render_to_pixmap_using_gdk (gerbv_project_t *gerbvProject, GdkPixmap *pixmap,
746 gerbv_render_info_t *renderInfo, gerbv_selection_info_t *selectionInfo,
747 GdkColor *selectionColor);
749 #ifndef RENDER_USING_GDK
750 void
751 gerbv_render_all_layers_to_cairo_target_for_vector_output (gerbv_project_t *gerbvProject,
752 cairo_t *cr, gerbv_render_info_t *renderInfo);
754 void
755 gerbv_render_all_layers_to_cairo_target (gerbv_project_t *gerbvProject, cairo_t *cr,
756 gerbv_render_info_t *renderInfo);
758 //! Render a layer to a cairo context
759 void
760 gerbv_render_layer_to_cairo_target (cairo_t *cr, /*!< the cairo context */
761 gerbv_fileinfo_t *fileInfo, /*!< the layer fileinfo pointer */
762 gerbv_render_info_t *renderInfo /*!< the scene render info */
765 void
766 gerbv_render_cairo_set_scale_and_translation(cairo_t *cr, gerbv_render_info_t *renderInfo);
768 void
769 gerbv_render_layer_to_cairo_target_without_transforming(cairo_t *cr, gerbv_fileinfo_t *fileInfo, gerbv_render_info_t *renderInfo );
770 #endif
772 double
773 gerbv_get_tool_diameter(int toolNumber
777 gerbv_process_tools_file(const char *toolFileName
780 //! Render a project to a PNG file, autoscaling the layers to fit inside the specified image dimensions
781 void
782 gerbv_export_png_file_from_project_autoscaled (
783 gerbv_project_t *gerbvProject, /*!< the project to render */
784 int widthInPixels, /*!< the width of the rendered picture (in pixels) */
785 int heightInPixels, /*!< the height of the rendered picture (in pixels) */
786 gchar const* filename /*!< the filename for the exported PNG file */
789 //! Render a project to a PNG file using user-specified render info
790 void
791 gerbv_export_png_file_from_project (
792 gerbv_project_t *gerbvProject, /*!< the project to render */
793 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
794 gchar const* filename /*!< the filename for the exported PNG file */
797 //! Render a project to a PDF file, autoscaling the layers to fit inside the specified image dimensions
798 void
799 gerbv_export_pdf_file_from_project_autoscaled (
800 gerbv_project_t *gerbvProject, /*!< the project to render */
801 int widthInPixels, /*!< the width of the rendered picture (in pixels) */
802 int heightInPixels, /*!< the height of the rendered picture (in pixels) */
803 gchar const* filename /*!< the filename for the exported PDF file */
806 //! Render a project to a PDF file using user-specified render info
807 void
808 gerbv_export_pdf_file_from_project (
809 gerbv_project_t *gerbvProject, /*!< the project to render */
810 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
811 gchar const* filename /*!< the filename for the exported PDF file */
814 //! Render a project to a Postscript file, autoscaling the layers to fit inside the specified image dimensions
815 void
816 gerbv_export_postscript_file_from_project_autoscaled (
817 gerbv_project_t *gerbvProject, /*!< the project to render */
818 int widthInPixels, /*!< the width of the rendered picture (in pixels) */
819 int heightInPixels, /*!< the height of the rendered picture (in pixels) */
820 gchar const* filename /*!< the filename for the exported Postscript file */
823 //! Render a project to a Postscript file using user-specified render info
824 void
825 gerbv_export_postscript_file_from_project (
826 gerbv_project_t *gerbvProject, /*!< the project to render */
827 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
828 gchar const* filename /*!< the filename for the exported Postscript file */
831 //! Render a project to a SVG file, autoscaling the layers to fit inside the specified image dimensions
832 void
833 gerbv_export_svg_file_from_project_autoscaled (
834 gerbv_project_t *gerbvProject, /*!< the project to render */
835 int widthInPixels, /*!< the width of the rendered picture (in pixels) */
836 int heightInPixels, /*!< the height of the rendered picture (in pixels) */
837 gchar const* filename /*!< the filename for the exported file */
840 //! Render a project to a file using user-specified render info
841 void
842 gerbv_export_svg_file_from_project (
843 gerbv_project_t *gerbvProject, /*!< the project to render */
844 gerbv_render_info_t *renderInfo, /*!< the render settings for the rendered image */
845 gchar const* filename /*!< the filename for the exported file */
848 //! Parse a RS274X file and return the parsed image
849 //! \return the new gerbv_image_t, or NULL if not successful
850 gerbv_image_t *
851 gerbv_create_rs274x_image_from_filename (gchar *filename /*!< the filename of the file to be parsed*/
854 //! Export an image to a new file in RS274X format
855 //! \return TRUE if successful, or FALSE if not
856 gboolean
857 gerbv_export_rs274x_file_from_image (gchar *filename, /*!< the filename for the new file */
858 gerbv_image_t *image /*!< the image to export */
861 //! Export an image to a new file in Excellon drill format
862 //! \return TRUE if successful, or FALSE if not
863 gboolean
864 gerbv_export_drill_file_from_image (gchar *filename, /*!< the filename for the new file */
865 gerbv_image_t *image /*!< the image to export */
868 //! Draw a line on the specified image
869 void
870 gerbv_image_create_line_object (gerbv_image_t *image, /*!< the image to draw to */
871 gdouble startX, /*!< the starting X coordinate */
872 gdouble startY, /*!< the starting Y coordinate */
873 gdouble endX, /*!< the ending X coordinate */
874 gdouble endY, /*!< the ending Y coordinate */
875 gdouble lineWidth, /*!< the width of the line to draw */
876 gerbv_aperture_type_t apertureType /*!< the type of aperture to use (e.g. CIRCLE) */
879 //! Draw an arc on the specified image
880 void
881 gerbv_image_create_arc_object (gerbv_image_t *image, /*!< the image to draw to */
882 gdouble centerX, /*!< the center X coordinate */
883 gdouble centerY, /*!< the center Y coordinate */
884 gdouble radius, /*!< the arc radius */
885 gdouble startAngle, /*!< the start angle (in CCW degrees) */
886 gdouble endAngle, /*!< the start angle (in CCW degrees) */
887 gdouble lineWidth, /*!< the width of the line to draw */
888 gerbv_aperture_type_t apertureType /*!< the type of aperture to use (e.g. CIRCLE) */
891 //! Draw a filled rectangle on the specified image
892 void
893 gerbv_image_create_rectangle_object (gerbv_image_t *image, /*!< the image to draw to */
894 gdouble coordinateX, /*!< the X coordinate of the lower left corner */
895 gdouble coordinateY, /*!< the Y coordinate of the lower left corner */
896 gdouble width, /*!< the width of the drawn rectangle */
897 gdouble height /*!< the height of the drawn rectangle */
900 /*! Create new struct for holding drill stats */
901 gerbv_drill_stats_t *
902 gerbv_drill_stats_new(void);
904 /*! Free the memory for a drill stats struct */
905 void
906 gerbv_drill_stats_destroy(gerbv_drill_stats_t *);
908 /*! Add stats gathered from specified layer to accumulatedd drill stats
909 * compiled from all layers */
910 void
911 gerbv_drill_stats_add_layer(gerbv_drill_stats_t *accum_stats,
912 gerbv_drill_stats_t *input_stats,
913 int this_layer
916 /*! Create new struct for holding Gerber stats */
917 gerbv_stats_t *
918 gerbv_stats_new(void);
920 /*! Free the memory for a stats struct */
921 void
922 gerbv_stats_destroy(gerbv_stats_t *);
924 /*! Add stats gathered from specified layer to accumulated Gerber stats
925 * compiled from all layers */
926 void
927 gerbv_stats_add_layer(gerbv_stats_t *accum_stats,
928 gerbv_stats_t *input_stats,
929 int this_layer
932 void
933 gerbv_attribute_destroy_HID_attribute (gerbv_HID_Attribute *attributeList, int n_attr);
935 gerbv_HID_Attribute *
936 gerbv_attribute_dup (gerbv_HID_Attribute *, int);
938 #endif /* __GERBV_H__ */