gerbv  2.6A
gerbv.h
Go to the documentation of this file.
1 /*
2  * gEDA - GNU Electronic Design Automation
3  * This file is a part of gerbv.
4  *
5  * Copyright (C) 2000-2003 Stefan Petersen (spe@stacken.kth.se)
6  *
7  * $Id$
8  *
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.
13  *
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.
18  *
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
22  */
23 
30 
33 
36 
61 #ifndef __GERBV_H__
62 #define __GERBV_H__
63 
64 #if defined(__cplusplus)
65 extern "C" {
66 #endif
67 
68 #ifdef HAVE_CONFIG_H
69 # include "config.h"
70 #endif
71 
72 #include <glib.h>
73 #include <gtk/gtk.h>
74 #include <gdk/gdk.h>
75 #include <gdk/gdkkeysyms.h>
76 
77 #ifndef RENDER_USING_GDK
78 # include <cairo.h>
79 #endif
80 
81 #define APERTURE_MIN 10
82 #define APERTURE_MAX 9999
83 
84 /*
85  * Maximum number of aperture parameters is set by the outline aperture
86  * macro. There (p. 28) is defined up to 50 points in polygon.
87  * So 50 points with x and y plus two for holding extra data gives...
88  */
89 #define APERTURE_PARAMETERS_MAX 102
90 #define INITIAL_SCALE 200
91 #define MAX_ERRMSGLEN 25
92 #define MAX_COORDLEN 28
93 #define MAX_DISTLEN 180
94 #define MAX_STATUSMSGLEN (MAX_ERRMSGLEN+MAX_COORDLEN+MAX_DISTLEN)
95 
96 /* Macros to convert between unscaled gerber coordinates and other units */
97 /* XXX NOTE: Currently unscaled units are assumed as inch, this is not
98  XXX necessarily true for all files */
99 #define COORD2INS(c) (c)
100 #define COORD2MILS(c) ((c)*1000.0)
101 #define COORD2MMS(c) ((c)*25.4)
102 
103 #define GERB_FATAL_ERROR(...) g_log(NULL, G_LOG_LEVEL_ERROR, __VA_ARGS__)
104 #define GERB_COMPILE_ERROR(...) g_log(NULL, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
105 #define GERB_COMPILE_WARNING(...) g_log(NULL, G_LOG_LEVEL_WARNING, __VA_ARGS__)
106 #define GERB_MESSAGE(...) g_log(NULL, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
107 
109 typedef enum {GERBV_OPCODE_NOP,
119 
121 typedef enum {GERBV_MESSAGE_FATAL,
126 
130 typedef enum {GERBV_APTYPE_NONE,
145 
151 
153 typedef enum {GERBV_UNIT_INCH,
156 } gerbv_unit_t;
157 
159 typedef enum {GERBV_POLARITY_POSITIVE,
164 
171 
176 
188 
189 typedef enum {GERBV_ENCODING_NONE,
190  GERBV_ENCODING_ASCII,
191  GERBV_ENCODING_EBCDIC,
192  GERBV_ENCODING_BCD,
193  GERBV_ENCODING_ISO_ASCII,
194  GERBV_ENCODING_EIA
195 } gerbv_encoding_t;
196 
198 typedef enum {
204 
205 typedef enum {GERBV_KNOCKOUT_TYPE_NOKNOCKOUT,
206  GERBV_KNOCKOUT_TYPE_FIXEDKNOCK,
207  GERBV_KNOCKOUT_TYPE_BORDER
208 } gerbv_knockout_type_t;
209 
210 typedef enum {GERBV_MIRROR_STATE_NOMIRROR,
211  GERBV_MIRROR_STATE_FLIPA,
212  GERBV_MIRROR_STATE_FLIPB,
213  GERBV_MIRROR_STATE_FLIPAB
214 } gerbv_mirror_state_t;
215 
216 typedef enum {GERBV_AXIS_SELECT_NOSELECT,
217  GERBV_AXIS_SELECT_SWAPAB
218 } gerbv_axis_select_t;
219 
220 typedef enum {GERBV_JUSTIFY_NOJUSTIFY,
221  GERBV_JUSTIFY_LOWERLEFT,
222  GERBV_JUSTIFY_CENTERJUSTIFY
223 } gerbv_image_justify_type_t;
224 
226 typedef enum {GERBV_SELECTION_EMPTY,
230 
232 typedef enum {GERBV_RENDER_TYPE_GDK,
238 
239 /*
240  * The following typedef's are taken directly from src/hid.h in the
241  * pcb project. The names are kept the same to make it easier to
242  * compare to pcb's sources.
243  */
244 
245 /* Used for HID attributes (exporting and printing, mostly).
246  HA_boolean uses int_value, HA_enum sets int_value to the index and
247  str_value to the enumeration string. HID_Label just shows the
248  default str_value. HID_Mixed is a real_value followed by an enum,
249  like 0.5in or 100mm.
250 */
251 typedef struct {
252  int int_value;
253  char *str_value;
254  double real_value;
255 } gerbv_HID_Attr_Val;
256 
257 typedef struct {
258  char *name;
259  char *help_text;
260  enum
261  { HID_Label, HID_Integer, HID_Real, HID_String,
262  HID_Boolean, HID_Enum, HID_Mixed, HID_Path
263  } type;
264  int min_val, max_val; /* for integer and real */
265  gerbv_HID_Attr_Val default_val; /* Also actual value for global attributes. */
266  const char **enumerations;
267  /* If set, this is used for global attributes (i.e. those set
268  statically with REGISTER_ATTRIBUTES below) instead of changing
269  the default_val. Note that a HID_Mixed attribute must specify a
270  pointer to gerbv_HID_Attr_Val here, and HID_Boolean assumes this is
271  "char *" so the value should be initialized to zero, and may be
272  set to non-zero (not always one). */
273  void *value;
274  int hash; /* for detecting changes. */
275 } gerbv_HID_Attribute;
276 /* end of HID attributes from PCB */
277 
279 typedef struct error_list {
280  int layer;
281  gchar *error_text;
283  struct error_list *next;
285 
286 typedef struct instruction {
287  gerbv_opcodes_t opcode;
288  union {
289  int ival;
290  float fval;
291  } data;
292  struct instruction *next;
293 } gerbv_instruction_t;
294 
295 typedef struct amacro {
296  gchar *name;
297  gerbv_instruction_t *program;
298  unsigned int nuf_push; /* Nuf pushes in program to estimate stack size */
299  struct amacro *next;
300 } gerbv_amacro_t;
301 
302 typedef struct gerbv_simplified_amacro {
304  double parameter[APERTURE_PARAMETERS_MAX];
305  struct gerbv_simplified_amacro *next;
306 } gerbv_simplified_amacro_t;
307 
308 typedef struct gerbv_aperture {
310  gerbv_amacro_t *amacro;
311  gerbv_simplified_amacro_t *simplified;
312  double parameter[APERTURE_PARAMETERS_MAX];
313  int nuf_parameters;
314  gerbv_unit_t unit;
315 } gerbv_aperture_t;
316 
317 /* the gerb_aperture_list is used to keep track of
318  * apertures used in stats reporting */
319 typedef struct gerbv_aperture_list {
320  int number;
321  int layer;
322  int count;
324  double parameter[5];
325  struct gerbv_aperture_list *next;
326 } gerbv_aperture_list_t;
327 
329 typedef struct {
331  gerbv_aperture_list_t *aperture_list;
332  gerbv_aperture_list_t *D_code_list;
333 
334  int layer_count;
335  int G0;
336  int G1;
337  int G2;
338  int G3;
339  int G4;
340  int G10;
341  int G11;
342  int G12;
343  int G36;
344  int G37;
345  int G54;
346  int G55;
347  int G70;
348  int G71;
349  int G74;
350  int G75;
351  int G90;
352  int G91;
353  int G_unknown;
354 
355  int D1;
356  int D2;
357  int D3;
358 /* GHashTable *D_user_defined; */
359  int D_unknown;
360  int D_error;
361 
362  int M0;
363  int M1;
364  int M2;
365  int M_unknown;
366 
367  int X;
368  int Y;
369  int I;
370  int J;
371 
372  /* Must include % RS-274 codes */
373  int star;
374  int unknown;
375 
376 } gerbv_stats_t;
377 
379 typedef struct drill_list {
380  int drill_num;
381  double drill_size;
382  gchar *drill_unit;
383  int drill_count;
384  struct drill_list *next;
386 
388 typedef struct {
389  int layer_count;
390 
393  int comment;
394  int F;
395 
396  int G00;
397  int G01;
398  int G02;
399  int G03;
400  int G04;
401  int G05;
402  int G85;
403  int G90;
404  int G91;
405  int G93;
406  int G_unknown;
407 
408  int M00;
409  int M01;
410  int M18;
411  int M25;
412  int M30;
413  int M31;
414  int M45;
415  int M47;
416  int M48;
417  int M71;
418  int M72;
419  int M95;
420  int M97;
421  int M98;
422  int M_unknown;
423 
424  int R;
425 
426  int unknown;
427 
428  /* used to total up the drill count across all layers/sizes */
429  int total_count;
430 
431  char *detect;
432 
434 
435 typedef struct {
436  gpointer image;
437  gpointer net;
438 } gerbv_selection_item_t;
439 
441 typedef struct {
442  gerbv_selection_t type;
443  gdouble lowerLeftX;
444  gdouble lowerLeftY;
445  gdouble upperRightX;
446  gdouble upperRightY;
447  GArray *selectedNodeArray;
449 
452 typedef struct {
453  gdouble translateX;
454  gdouble translateY;
455  gdouble scaleX;
456  gdouble scaleY;
457  gdouble rotation;
458  gboolean mirrorAroundX;
459  gboolean mirrorAroundY;
460  gboolean inverted;
462 
464 typedef struct {
465  double left;
466  double right;
467  double bottom;
468  double top;
470 
471 typedef struct gerbv_cirseg {
472  double cp_x; /* center point x */
473  double cp_y; /* center point y */
474  double width; /* of oval */
475  double height; /* of oval */
476  double angle1;
477  double angle2;
478 } gerbv_cirseg_t;
479 
480 typedef struct gerbv_step_and_repeat { /* SR parameters */
481  int X;
482  int Y;
483  double dist_X;
484  double dist_Y;
485 } gerbv_step_and_repeat_t;
486 
487 typedef struct {
488  gboolean firstInstance;
489  gerbv_knockout_type_t type;
490  gerbv_polarity_t polarity;
491  gdouble lowerLeftX;
492  gdouble lowerLeftY;
493  gdouble width;
494  gdouble height;
495  gdouble border;
496 } gerbv_knockout_t;
497 
499 typedef struct {
500  gerbv_step_and_repeat_t stepAndRepeat;
501  gerbv_knockout_t knockout;
502  gdouble rotation;
504  gchar *name;
505  gpointer next;
506 } gerbv_layer_t;
507 
509 typedef struct {
510  gerbv_axis_select_t axisSelect;
511  gerbv_mirror_state_t mirrorState;
513  gdouble offsetA;
514  gdouble offsetB;
515  gdouble scaleA;
516  gdouble scaleB;
517  gpointer next;
519 
521 typedef struct gerbv_net {
522  double start_x;
523  double start_y;
524  double stop_x;
525  double stop_y;
527  int aperture;
530  gerbv_cirseg_t *cirseg;
531  struct gerbv_net *next;
532  GString *label;
535 } gerbv_net_t;
536 
539 typedef struct gerbv_format {
540  gerbv_omit_zeros_t omit_zeros;
541  gerbv_coordinate_t coordinate;
542  int x_int;
543  int x_dec;
544  int y_int;
545  int y_dec;
546  int lim_seqno; /* Length limit for codes of sequence number */
547  int lim_gf; /* Length limit for codes of general function */
548  int lim_pf; /* Length limit for codes of plot function */
549  int lim_mf; /* Length limit for codes of miscellaneous function */
551 
552 
554 typedef struct gerbv_image_info {
555  char *name;
556  gerbv_polarity_t polarity;
557  double min_x; /* Always in inches */
558  double min_y;
559  double max_x;
560  double max_y;
561  double offsetA;
562  double offsetB;
563  gerbv_encoding_t encoding;
564  double imageRotation;
565  gerbv_image_justify_type_t imageJustifyTypeA;
566  gerbv_image_justify_type_t imageJustifyTypeB;
567  gdouble imageJustifyOffsetA;
568  gdouble imageJustifyOffsetB;
569  gdouble imageJustifyOffsetActualA;
570  gdouble imageJustifyOffsetActualB;
571  gchar *plotterFilm;
572 
573  /* Descriptive string for the type of file (rs274-x, drill, etc)
574  * that this is
575  */
576  gchar *type;
577 
578  /* Attribute list that is used to hold all sorts of information
579  * about how the layer is to be parsed.
580  */
581  gerbv_HID_Attribute *attr_list;
582  int n_attr;
584 
586 typedef struct {
588  gerbv_aperture_t *aperture[APERTURE_MAX];
591  gerbv_amacro_t *amacro;
597 } gerbv_image_t;
598 
600 typedef struct {
602  GdkColor color;
603  guint16 alpha;
604  gboolean isVisible;
605  gpointer privateRenderData;
606  gchar *fullPathname;
607  gchar *name;
609  gboolean layer_dirty;
611 
612 typedef struct {
613  double x1, y1;
614  double x2, y2;
615 } gerbv_bbox_t;
616 
619 typedef struct {
620  GdkColor background;
621  int max_files;
627  gchar *path;
628  gchar *execpath;
629  gchar *execname;
630  gchar *project;
632 
634 typedef struct{
635  unsigned char red;
636  unsigned char green;
637  unsigned char blue;
638  unsigned char alpha;
640 
642 typedef struct {
643  gdouble scaleFactorX;
644  gdouble scaleFactorY;
645  gdouble lowerLeftX;
646  gdouble lowerLeftY;
651 
655  const gchar *type
656 );
657 
660 );
661 
663 void
665  gerbv_user_transformation_t *transform,
666  gerbv_image_t *destinationImage
667 );
668 
673  gerbv_user_transformation_t *transform
674 );
675 
677 void
679 );
680 
681 void
682 gerbv_image_delete_selected_nets (gerbv_image_t *sourceImage, GArray *selectedNodeArray);
683 
684 gboolean
685 gerbv_image_reduce_area_of_selected_objects (GArray *selectionArray, gdouble areaReduction, gint paneRows,
686  gint paneColumns, gdouble paneSeparation);
687 
688 gboolean
689 gerbv_image_move_selected_objects (GArray *selectionArray, gdouble translationX,
690  gdouble translationY);
691 
693 gerbv_net_t *
695 
698 gerbv_create_project (void);
699 
701 void
703 );
704 
706 void
708  gerbv_project_t *gerbvProject,
709  gchar *filename
710 );
711 
713 void
715  gchar *filename,
716  guint16 red,
717  guint16 green,
718  guint16 blue,
719  guint16 alpha
720 );
721 
723 void
725 );
726 
727 gboolean
728 gerbv_save_layer_from_index(gerbv_project_t *gerbvProject, gint index, gchar *filename);
729 
730 int
731 gerbv_revert_file(gerbv_project_t *gerbvProject, int idx);
732 
733 void
734 gerbv_revert_all_files(gerbv_project_t *gerbvProject);
735 
736 void
737 gerbv_unload_layer(gerbv_project_t *gerbvProject, int index);
738 
739 void
740 gerbv_unload_all_layers (gerbv_project_t *gerbvProject);
741 
742 void
743 gerbv_change_layer_order(gerbv_project_t *gerbvProject, gint oldPosition, gint newPosition);
744 
745 gint
746 gerbv_add_parsed_image_to_project (gerbv_project_t *gerbvProject, gerbv_image_t *parsed_image,
747  gchar *filename, gchar *baseName, int idx, int reload);
748 int
749 gerbv_open_image(gerbv_project_t *gerbvProject, char *filename, int idx, int reload,
750  gerbv_HID_Attribute *fattr, int n_fattr, gboolean forceLoadFile);
751 
752 void
753 gerbv_render_get_boundingbox(gerbv_project_t *gerbvProject, gerbv_render_size_t *boundingbox);
754 
756 void
758  gerbv_render_info_t *renderInfo
759 );
760 
761 void
762 gerbv_render_translate_to_fit_display (gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo);
763 
764 void
765 gerbv_render_to_pixmap_using_gdk (gerbv_project_t *gerbvProject, GdkPixmap *pixmap,
766  gerbv_render_info_t *renderInfo, gerbv_selection_info_t *selectionInfo,
767  GdkColor *selectionColor);
768 
769 #ifndef RENDER_USING_GDK
770 void
771 gerbv_render_all_layers_to_cairo_target_for_vector_output (gerbv_project_t *gerbvProject,
772  cairo_t *cr, gerbv_render_info_t *renderInfo);
773 
774 void
775 gerbv_render_all_layers_to_cairo_target (gerbv_project_t *gerbvProject, cairo_t *cr,
776  gerbv_render_info_t *renderInfo);
777 
779 void
781  gerbv_fileinfo_t *fileInfo,
782  gerbv_render_info_t *renderInfo
783 );
784 
785 void
786 gerbv_render_cairo_set_scale_and_translation(cairo_t *cr, gerbv_render_info_t *renderInfo);
787 
788 void
789 gerbv_render_layer_to_cairo_target_without_transforming(cairo_t *cr, gerbv_fileinfo_t *fileInfo, gerbv_render_info_t *renderInfo, gboolean pixelOutput );
790 #endif
791 
792 double
793 gerbv_get_tool_diameter(int toolNumber
794 );
795 
796 int
797 gerbv_process_tools_file(const char *toolFileName
798 );
799 
801 void
803  gerbv_project_t *gerbvProject,
804  int widthInPixels,
805  int heightInPixels,
806  gchar const* filename
807 );
808 
810 void
812  gerbv_project_t *gerbvProject,
813  gerbv_render_info_t *renderInfo,
814  gchar const* filename
815 );
816 
818 void
820  gerbv_project_t *gerbvProject,
821  gchar const* filename
822 );
823 
825 void
827  gerbv_project_t *gerbvProject,
828  gerbv_render_info_t *renderInfo,
829  gchar const* filename
830 );
831 
833 void
835  gerbv_project_t *gerbvProject,
836  gchar const* filename
837 );
838 
840 void
842  gerbv_project_t *gerbvProject,
843  gerbv_render_info_t *renderInfo,
844  gchar const* filename
845 );
846 
848 void
850  gerbv_project_t *gerbvProject,
851  gchar const* filename
852 );
853 
855 void
857  gerbv_project_t *gerbvProject,
858  gerbv_render_info_t *renderInfo,
859  gchar const* filename
860 );
861 
866 );
867 
870 gboolean
871 gerbv_export_rs274x_file_from_image (gchar *filename,
872  gerbv_image_t *image,
873  gerbv_user_transformation_t *transform
874 );
875 
878 gboolean
879 gerbv_export_drill_file_from_image (gchar *filename,
880  gerbv_image_t *image,
881  gerbv_user_transformation_t *transform
882 );
883 
885 void
887  gdouble startX,
888  gdouble startY,
889  gdouble endX,
890  gdouble endY,
891  gdouble lineWidth,
892  gerbv_aperture_type_t apertureType
893 );
894 
896 void
898  gdouble centerX,
899  gdouble centerY,
900  gdouble radius,
901  gdouble startAngle,
902  gdouble endAngle,
903  gdouble lineWidth,
904  gerbv_aperture_type_t apertureType
905 );
906 
908 void
910  gdouble coordinateX,
911  gdouble coordinateY,
912  gdouble width,
913  gdouble height
914 );
915 
917 void
919 );
920 
924 
926 void
928 
931 void
933  gerbv_drill_stats_t *input_stats,
934  int this_layer
935 );
936 
939 gerbv_stats_new(void);
940 
942 void
944 
947 void
949  gerbv_stats_t *input_stats,
950  int this_layer
951 );
952 
953 void
954 gerbv_attribute_destroy_HID_attribute (gerbv_HID_Attribute *attributeList, int n_attr);
955 
956 gerbv_HID_Attribute *
957 gerbv_attribute_dup (gerbv_HID_Attribute *, int);
958 
959 #if defined(__cplusplus)
960 }
961 #endif
962 
963 #endif /* __GERBV_H__ */