1 /* gEDA - GPL Electronic Design Automation
2  * libgeda - gEDA's Library
3  * Copyright (C) 1998-2010 Ales Hvezda
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02111-1301 USA.
19  */
20 
21 #ifndef STRUCT_H
22 #define STRUCT_H
23 
24 #include <glib.h>  /* Include needed to make GList work. */
25 
26 /* Wrappers around a new list mechanism */
27 typedef struct _GedaList SELECTION;
28 typedef struct _GedaList GedaPageList;
29 
30 /* gschem structures (gschem) */
31 typedef struct st_complex COMPLEX;
32 typedef struct st_line LINE;
33 typedef struct st_path_section PATH_SECTION;
34 typedef struct st_path PATH;
35 typedef struct st_circle CIRCLE;
36 typedef struct st_arc ARC;
37 typedef struct st_box BOX;
38 typedef struct st_picture PICTURE;
39 typedef struct st_text TEXT;
40 typedef struct st_point sPOINT;
41 typedef struct st_transform TRANSFORM;
42 typedef struct st_bezier BEZIER;
43 
44 typedef struct st_object OBJECT;
45 typedef struct st_page PAGE;
46 typedef struct st_toplevel TOPLEVEL;
47 typedef struct st_color COLOR;
48 typedef struct st_undo UNDO;
49 typedef struct st_tile TILE;
50 typedef struct st_bounds BOUNDS;
51 
52 typedef struct st_conn CONN;
53 typedef struct st_bus_ripper BUS_RIPPER;
54 
55 /* netlist structures (gnetlist) */
56 typedef struct st_netlist NETLIST;
57 typedef struct st_cpinlist CPINLIST;
58 typedef struct st_net NET;
59 
60 /* sch check structures (gschcheck) */
61 typedef struct st_schcheck SCHCHECK;
62 typedef struct st_chkerrs CHKERRS;
63 
64 /* Managed text buffers */
65 typedef struct _TextBuffer TextBuffer;
66 
67 /* Component library objects */
68 typedef struct _CLibSource CLibSource;
69 typedef struct _CLibSymbol CLibSymbol;
70 
71 /* Component library search modes */
72 typedef enum { CLIB_EXACT=0, CLIB_GLOB } CLibSearchMode;
73 
74 /* f_open behaviour flags.  See documentation for f_open_flags() in
75    f_basic.c. */
76 typedef enum { F_OPEN_RC           = 1,
77                F_OPEN_CHECK_BACKUP = 2,
78                F_OPEN_RESTORE_CWD  = 4,
79 } FOpenFlags;
80 
81 /*! \brief line end style for an open line of an object */
82 typedef enum {END_NONE, END_SQUARE, END_ROUND} OBJECT_END;
83 
84 /*! \brief line style of lines, rect, circles, arcs */
85 typedef enum {TYPE_SOLID, TYPE_DOTTED, TYPE_DASHED, TYPE_CENTER, TYPE_PHANTOM, TYPE_ERASE} OBJECT_TYPE;
86 
87 /*! \brief fill style of objects like cirle, rect, path */
88 typedef enum {FILLING_HOLLOW, FILLING_FILL, FILLING_MESH, FILLING_HATCH, FILLING_VOID} OBJECT_FILLING;
89 
90 struct st_line {
91   int x[2];
92   int y[2];
93 };
94 
95 struct st_point {
96   gint x;
97   gint y;
98 };
99 
100 #define LINE_END1 0
101 #define LINE_END2 1
102 
103 typedef enum {
104     PATH_MOVETO,
105     PATH_MOVETO_OPEN,
106     PATH_CURVETO,
107     PATH_LINETO,
108     PATH_END
109 } PATH_CODE;
110 
111 struct st_path_section {
112   PATH_CODE code;
113   int x1;
114   int y1;
115   int x2;
116   int y2;
117   int x3;
118   int y3;
119 };
120 
121 struct st_path {
122   PATH_SECTION *sections; /* Bezier path segments  */
123   int num_sections;       /* Number with data      */
124   int num_sections_max;   /* Number allocated      */
125 };
126 
127 struct st_arc {
128   int x, y; /* world */
129 
130   int width;
131   int height;
132 
133   int start_angle;
134   int end_angle;
135 };
136 
137 #define ARC_CENTER 0
138 #define ARC_RADIUS 1
139 #define ARC_START_ANGLE 2
140 #define ARC_END_ANGLE 3
141 
142 struct st_bezier {
143   int x[4];
144   int y[4];
145 };
146 
147 struct st_box {
148   /* upper is considered the origin */
149   int upper_x, upper_y; /* world */
150   int lower_x, lower_y;
151 
152 };
153 
154 #define BOX_UPPER_LEFT 0
155 #define BOX_LOWER_RIGHT 1
156 #define BOX_UPPER_RIGHT 2
157 #define BOX_LOWER_LEFT 3
158 
159 struct st_picture {
160   GdkPixbuf *pixbuf;
161   gchar *file_content;
162   gsize file_length;
163 
164   double ratio;
165   char *filename;
166   int angle;
167   char mirrored;
168   char embedded;
169 
170   /* upper is considered the origin */
171   int upper_x, upper_y; /* world */
172   int lower_x, lower_y;
173 
174 };
175 
176 #define PICTURE_UPPER_LEFT 0
177 #define PICTURE_LOWER_RIGHT 1
178 #define PICTURE_UPPER_RIGHT 2
179 #define PICTURE_LOWER_LEFT 3
180 
181 
182 struct st_text {
183   int x, y;		/* world origin */
184 
185   char *string;			/* text stuff */
186   char *disp_string;
187   int length;
188   int size;
189   int alignment;
190   int angle;
191 };
192 
193 struct st_complex {
194   int x, y;		/* world origin */
195 
196   int angle;				/* orientation, only multiples
197                                          * of 90 degrees allowed */
198   /* in degrees */
199   int mirror;
200 
201   GList *prim_objs;			/* Primitive objects */
202   /* objects which make up the */
203   /* complex */
204 };
205 
206 struct st_circle {
207   int center_x, center_y; /* world */
208   int radius;
209 };
210 
211 #define CIRCLE_CENTER 0
212 #define CIRCLE_RADIUS 1
213 
214 struct st_object {
215   int type;				/* Basic information */
216   int sid;
217   char *name;
218 
219   PAGE *page; /* Parent page */
220 
221   int w_top;				/* Bounding box information */
222   int w_left;				/* in world coords */
223   int w_right;
224   int w_bottom;
225   gboolean w_bounds_valid;
226 
227   COMPLEX *complex;
228   LINE *line;
229   CIRCLE *circle;
230   ARC *arc;
231   BOX *box;
232   TEXT *text;
233   PICTURE *picture;
234   PATH *path;
235 
236   GList *tiles;			/* tiles */
237 
238   GList *conn_list;			/* List of connections */
239   /* to and from this object */
240 
241   /* every graphical primitive have more or less the same options. */
242   /* depending on its nature a primitive is concerned with one or more */
243   /* of these fields. If not, value must be ignored. */
244   OBJECT_END line_end;
245   OBJECT_TYPE line_type;
246   int line_width;
247   int line_space;
248   int line_length;
249 
250   OBJECT_FILLING fill_type;
251   int fill_width;
252   int fill_angle1, fill_pitch1;
253   int fill_angle2, fill_pitch2;
254 
255   gboolean complex_embedded;                    /* is embedded component? */
256   gchar *complex_basename;              /* Component Library Symbol name */
257   OBJECT *parent;                       /* Parent object pointer */
258 
259   int color; 				/* Which color */
260   int dont_redraw;			/* Flag to skip redrawing */
261   int selectable;			/* object selectable flag */
262   int selected;				/* object selected flag */
263   int locked_color; 			/* Locked color (used to save */
264   /* the object's real color */
265   /* when the object is locked) */
266 
267   /* controls which direction bus rippers go */
268   /* it is either 0 for un-inited, */
269   /* 1 for right, -1 for left (horizontal bus) */
270   /* 1 for up, -1 for down (vertial bus) */
271   int bus_ripper_direction;             /* only valid on buses */
272 
273 
274   int font_text_size;			/* used only with fonts defs */
275   GList *font_prim_objs;			/* used only with fonts defs */
276 
277   int whichend;    /* for pins only, either 0 or 1 */
278   int pin_type;    /* for pins only, either NET or BUS */
279 
280   /* Tracking total number of entities connected by this net */
281   int net_num_connected;          /* for nets only */
282   gboolean valid_num_connected;   /* for nets only */
283 
284   GList *attribs;       /* attribute stuff */
285   int show_name_value;
286   int visibility;
287   OBJECT *attached_to;  /* when object is an attribute */
288   OBJECT *copied_to;    /* used when copying attributes */
289 
290   GList *weak_refs; /* Weak references */
291 
292   /* Attribute notification handling */
293   int attrib_notify_freeze_count;
294   int attrib_notify_pending;
295 
296   /* Connection notification handling */
297   int conn_notify_freeze_count;
298   int conn_notify_pending;
299 };
300 
301 
302 /*! \brief Structure for connections between OBJECTs
303  *
304  * The st_conn structure contains a single connection
305  * to another object.
306  * The connection system in s_conn.c uses this struct
307  */
308 struct st_conn {
309   /*! \brief The "other" object connected to this one */
310   OBJECT *other_object;
311   /*! \brief type of connection. Always in reference to how the "other"
312     object is connected to the current one */
313   int type;
314   /*! \brief x coord of the connection position */
315   int x;
316   /*! \brief y coord of the connection position */
317   int y;
318   /*! \brief which endpoint of the current object caused this connection */
319   int whichone;
320   /*! \brief which endpoint of the "other" object caused this connection */
321   int other_whichone;
322 };
323 
324 /* this structure is used in gschem to add rippers when drawing nets */
325 /* it is never stored in any object, it is only temporary */
326 struct st_bus_ripper
327 {
328   int x[2];
329   int y[2];
330 };
331 
332 struct st_bounds {
333   gint min_x;
334   gint min_y;
335   gint max_x;
336   gint max_y;
337 };
338 
339 /** A structure to store a 2D affine transform.
340  *
341  *  The transforms get stored in a 3x3 matrix. Code assumes the bottom row to
342  *  remain constant at [0 0 1].
343  */
344 struct st_transform {
345   gdouble m[2][3];    /* m[row][column] */
346 };
347 
348 struct st_undo {
349 
350   /* one of these is used, depending on if you are doing in-memory */
351   /* or file based undo state saving */
352   char *filename;
353   GList *object_list;
354 
355   /* either UNDO_ALL or UNDO_VIEWPORT_ONLY */
356   int type;
357 
358   /* viewport information */
359   int left, top, right, bottom;
360 
361   /* up and down the hierarchy */
362   int up;
363   /* used to control which pages are viewable when moving around */
364   int page_control;
365 
366   UNDO *prev;
367   UNDO *next;
368 };
369 
370 
371 /*! \brief structure to split a page into tiles
372  *
373  *  This structure is used to track objects that are inside
374  *  a smaller TILE of o a page.
375  *  See s_tile.c for further informations.
376  */
377 struct st_tile {
378   GList *objects;
379 
380   int top, left, right, bottom;
381 };
382 
383 struct st_page {
384 
385   int pid;
386 
387   GList *_object_list;
388   SELECTION *selection_list; /* new selection mechanism */
389   GList *place_list;
390   OBJECT *object_lastplace; /* the last found item */
391 
392   char *page_filename;
393   int CHANGED;			/* changed flag */
394   /*int zoom_factor; no longer used*/
395   int left, right, top, bottom;		/* World coord limits */
396   double coord_aspectratio;		/* Real worldcoords ratio (?) */
397 
398   float to_screen_x_constant;
399   float to_screen_y_constant;
400 
401   float to_world_x_constant;
402   float to_world_y_constant;
403 
404   TILE world_tiles[MAX_TILES_X][MAX_TILES_Y];
405 
406   /* Undo/Redo Stacks and pointers */
407   /* needs to go into page mechanism actually */
408   UNDO *undo_bottom;
409   UNDO *undo_current;
410   UNDO *undo_tos; 	/* Top Of Stack */
411 
412   /* up and down the hierarchy */
413   /* this holds the pid of the parent page */
414   int up;
415   /* int down; not needed */
416 
417   /* used to control which pages are viewable when moving around */
418   int page_control;
419 
420   /* backup variables */
421   GTimeVal last_load_or_save_time;
422   char saved_since_first_loaded;
423   gint ops_since_last_backup;
424   gchar do_autosave_backup;
425 
426   GList *weak_refs; /* Weak references */
427 };
428 
429 /*! \brief Type of callback function for calculating text bounds */
430 typedef int(*RenderedBoundsFunc)(void *, OBJECT *, int *, int *, int *, int *);
431 
432 /*! \brief Type of callback function for object damage notification */
433 typedef int(*ChangeNotifyFunc)(void *, OBJECT *);
434 
435 /*! \brief Type of callback function for notification when a new TOPLEVEL is created */
436 typedef void(*NewToplevelFunc)(TOPLEVEL *, void *);
437 
438 /*! \brief Type of callback function for notification when an object's attributes change */
439 typedef void(*AttribsChangedFunc)(void *, OBJECT *);
440 
441 /*! \brief Type of callback function for notification when an object's connections change */
442 typedef void(*ConnsChangedFunc)(void *, OBJECT *);
443 
444 /*! \brief Type of callback function for querying loading of backups */
445 typedef gboolean(*LoadBackupQueryFunc)(void *, GString *);
446 
447 struct st_toplevel {
448 
449   /* have to decided on component list stuff */
450   /* if it should go in here or not */
451   /* leave outside for now */
452 
453   GList *RC_list;                       /* List of RC files which have been read in. */
454 
455   char *untitled_name;			/* untitled sch basename */
456   char *bitmap_directory; 		/* path of the bitmaps */
457 
458   int init_left, init_right; 		/* Starting values for above */
459   int init_top, init_bottom;
460 
461   int width, height;			/* height, width of window */
462 
463   int override_color;			/* used in doing selections */
464 
465   int last_ps_color;                    /* used in print code */
466 
467   /* page system */
468   PAGE *page_current;
469   GedaPageList *pages;
470 
471   /* show_hidden_text is used to control which text is hidden in gschem */
472   int show_hidden_text;
473 
474   GList* major_changed_refdes;          /* A list of all refdes's that have */
475                                         /* major symbol version changes */
476 
477   /* backup variables */
478   int auto_save_interval;
479   gint auto_save_timeout;
480 
481   /* BLOCK SET IN GSCHEM, BUT USED IN LIBGEDA - NEEDS A RETHINK */
482   int background_color;
483   int override_net_color;
484   int override_bus_color;
485   int override_pin_color;
486   int pin_style;
487   int net_style;
488   int bus_style;
489   int line_style;
490   /* END BLOCK - ALTHOUGH THERE ARE MORE CASES! */
491 
492   /* controls whether objects are clipped */
493   int object_clipping;
494 
495   /* either landscape or portrait */
496   int print_orientation;
497 
498   /* either TRUE or FALSE (color or no color) */
499   int image_color;
500 
501   /* either TRUE or FALSE (color or no color) */
502   int print_color;
503 
504   /* color used color ouput for background */
505   int print_color_background;
506 
507   /* setpagedevice orientation option enable (TRUE or FALSE) */
508   int setpagedevice_orientation;
509 
510   /* setpagedevice pagesize option enable (TRUE or FALSE) */
511   int setpagedevice_pagesize;
512 
513   /* The name of the prolog file to paste into the Postscript output */
514   char *postscript_prolog;
515 
516   /* controls if the net consolidation code is used */
517   int net_consolidate;
518 
519   /*controls if attribute promotion happens */
520   int attribute_promotion;
521 
522   /* controls if invisible attribs are promoted */
523   int promote_invisible;
524 
525   /* controls if invisible attribs are kept and not deleted */
526   int keep_invisible;
527 
528   /* controls the generation of backup (~) files */
529   int make_backup_files;
530 
531   /* either window or limits */
532   int print_output_type;
533 
534   /* BUTT, ROUND, SQUARE caps */
535   int print_output_capstyle;
536 
537   /* landscape printing only */
538   int paper_width, paper_height;
539 
540   /* filename of the bus ripper component if set above */
541   char *bus_ripper_symname;
542 
543   /* controls if the whole bounding box is used in the auto whichend code */
544   int force_boundingbox;
545 
546   /* List of attributes to always promote */
547   GList *always_promote_attributes;
548 
549   /* gnetlist specific */
550   int net_naming_priority;
551   int hierarchy_traversal;
552   int hierarchy_uref_mangle;
553   int hierarchy_netname_mangle;
554   int hierarchy_netattrib_mangle;
555   char *hierarchy_uref_separator;
556   char *hierarchy_netname_separator;
557   char *hierarchy_netattrib_separator;
558   int hierarchy_netattrib_order;
559   int hierarchy_netname_order;
560   int hierarchy_uref_order;
561   char *unnamed_netname;
562   char *unnamed_busname;
563 
564   /* Callback function for calculating text bounds */
565   RenderedBoundsFunc rendered_text_bounds_func;
566   void *rendered_text_bounds_data;
567 
568   /* Callback functions for object change notification */
569   GList *change_notify_funcs;
570 
571   /* Callback functions for object attribute change notification */
572   GList *attribs_changed_hooks;
573 
574   /* Callback functions for object connections change notification */
575   GList *conns_changed_hooks;
576 
577   /* Callback function for deciding whether to load a backup file. */
578   LoadBackupQueryFunc load_newer_backup_func;
579   void *load_newer_backup_data;
580 
581   GList *weak_refs; /* Weak references */
582 };
583 
584 /* structures below are for gnetlist */
585 
586 /* for every component in the object database */
587 struct st_netlist {
588 
589   int nlid;
590 
591   char *component_uref;
592 
593   OBJECT *object_ptr;
594 
595   CPINLIST *cpins;
596 
597   char *hierarchy_tag;
598   int composite_component;
599 
600   NETLIST *prev;
601   NETLIST *next;
602 };
603 
604 
605 /* for every pin on a component */
606 struct st_cpinlist {
607   int plid;
608   int type;                             /* PIN_TYPE_NET or PIN_TYPE_BUS */
609 
610   char *pin_number;
611   char *net_name;			/* this is resolved at very end */
612   char *pin_label;
613 
614   NET *nets;
615 
616   CPINLIST *prev;
617   CPINLIST *next;
618 };
619 
620 /* the net run connected to a pin */
621 struct st_net {
622 
623   int nid;
624 
625   int net_name_has_priority;
626   char *net_name;
627   char *pin_label;
628 
629   char *connected_to; /* new to replace above */
630 
631   NET *prev;
632   NET *next;
633 };
634 
635 /* By Jamil Khatib */
636 /* typedef struct st_chkerrs CHKERRS; */
637 
638 /* Schem check struct */
639 struct st_schcheck {
640   int no_errors;                /* No of Errors */
641   int no_warnings;              /* No of Warinings */
642 
643   CHKERRS * sheet_errs;
644 
645   CHKERRS *float_nets;           /* Header of the list of floating nets */
646   int net_errs;                 /* No of floating nets */
647 
648   OBJECT *float_pins;           /* Header of List of floating pins*/
649   int pin_errs;                 /* No of floating pins */
650 
651   int net_names;                /* No of mismatched net names */
652 };
653 
654 
655 struct st_chkerrs{
656 
657   OBJECT * err_obj;
658   CHKERRS * next;
659 
660 };
661 
662 
663 
664 struct st_color {
665   guint8 r, g, b, a;
666   gboolean enabled;
667 };
668 
669 
670 struct st_attrib_smob {
671   TOPLEVEL *world;   /* We need this when updating schematic */
672   OBJECT   *attribute;
673 };
674 
675 struct st_object_smob {
676   TOPLEVEL *world;   /* We need this when updating schematic */
677   OBJECT   *object;
678 };
679 
680 struct st_page_smob {
681   TOPLEVEL *world;   /* We need this when updating schematic */
682   PAGE   *page;
683 };
684 
685 /* used by the rc loading mechanisms */
686 typedef struct {
687   int   m_val;
688   char *m_str;
689 } vstbl_entry;
690 
691 /* Used by g_rc_parse_handler() */
692 typedef void (*ConfigParseErrorFunc)(GError **, void *);
693 
694 #endif
695