src/puller.c: Converted plain comments into doxygen comments.
[geda-pcb/pcjc2.git] / src / parse_y.y
blobfe14c0ca25191dd9d7778fe7edd2e6b77be874ff
1 /*
2 * ************************** README *******************
4 * If the file format is modified in any way, update
5 * PCB_FILE_VERSION in file.h
6 *
7 * ************************** README *******************
8 */
12 * COPYRIGHT
14 * PCB, interactive printed circuit board design
15 * Copyright (C) 1994,1995,1996 Thomas Nau
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * Contact addresses for paper mail and Email:
32 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
33 * Thomas.Nau@rz.uni-ulm.de
37 /* grammar to parse ASCII input of PCB description
40 #ifdef HAVE_CONFIG_H
41 #include "config.h"
42 #endif
44 #include "global.h"
45 #include "create.h"
46 #include "data.h"
47 #include "error.h"
48 #include "file.h"
49 #include "layerflags.h"
50 #include "mymem.h"
51 #include "misc.h"
52 #include "parse_l.h"
53 #include "polygon.h"
54 #include "remove.h"
55 #include "rtree.h"
56 #include "strflags.h"
57 #include "thermal.h"
58 #include "move.h"
60 #ifdef HAVE_LIBDMALLOC
61 # include <dmalloc.h> /* see http://dmalloc.com */
62 #endif
64 static LayerType *Layer;
65 static PolygonType *Polygon;
66 static SymbolType *Symbol;
67 static int pin_num;
68 static LibraryMenuType *Menu;
69 static bool LayerFlag[MAX_ALL_LAYER];
71 extern char *yytext; /* defined by LEX */
72 extern PCBType *yyPCB;
73 extern DataType *yyData;
74 extern ElementType *yyElement;
75 extern FontType *yyFont;
76 extern int yylineno; /* linenumber */
77 extern char *yyfilename; /* in this file */
79 static AttributeListType *attr_list;
81 int yyerror(const char *s);
82 int yylex();
83 static int check_file_version (int);
85 static void do_measure (PLMeasure *m, Coord i, double d, int u);
86 #define M(r,f,d) do_measure (&(r), f, d, 1)
88 /* Macros for interpreting what "measure" means - integer value only,
89 old units (mil), or new units (cmil). */
90 #define IV(m) integer_value (m)
91 #define OU(m) old_units (m)
92 #define NU(m) new_units (m)
94 static int integer_value (PLMeasure m);
95 static Coord old_units (PLMeasure m);
96 static Coord new_units (PLMeasure m);
98 #define YYDEBUG 1
99 #define YYERROR_VERBOSE 1
101 #include "parse_y.h"
105 %verbose
107 %union /* define YYSTACK type */
109 int integer;
110 double number;
111 char *string;
112 FlagType flagtype;
113 PLMeasure measure;
116 %token <number> FLOATING /* line thickness, coordinates ... */
117 %token <integer> INTEGER CHAR_CONST /* flags ... */
118 %token <string> STRING /* element names ... */
120 %token T_FILEVERSION T_PCB T_LAYER T_VIA T_RAT T_LINE T_ARC T_RECTANGLE T_TEXT T_ELEMENTLINE
121 %token T_ELEMENT T_PIN T_PAD T_GRID T_FLAGS T_SYMBOL T_SYMBOLLINE T_CURSOR
122 %token T_ELEMENTARC T_MARK T_GROUPS T_STYLES T_POLYGON T_POLYGON_HOLE T_NETLIST T_NET T_CONN
123 %token T_AREA T_THERMAL T_DRC T_ATTRIBUTE
124 %token T_UMIL T_CMIL T_MIL T_IN T_NM T_UM T_MM T_M T_KM T_PX
125 %type <integer> symbolid
126 %type <string> opt_string
127 %type <flagtype> flags
128 %type <number> number
129 %type <measure> measure
133 parse
134 : parsepcb
135 | parsedata
136 | parsefont
137 | error { YYABORT; }
140 /* %start-doc pcbfile 00pcb
141 @nodetype subsection
142 @nodename %s syntax
144 A special note about units: Older versions of @code{pcb} used mils
145 (1/1000 inch) as the base unit; a value of 500 in the file meant
146 half an inch. Newer versions uses a "high resolution" syntax,
147 where the base unit is 1/100 of a mil (0.000010 inch); a value of 500 in
148 the file means 5 mils. As a general rule, the variants of each entry
149 listed below which use square brackets are the high resolution formats
150 and use the 1/100 mil units, and the ones with parentheses are the older
151 variants and use 1 mil units. Note that when multiple variants
152 are listed, the most recent (and most preferred) format is the first
153 listed.
155 Symbolic and numeric flags (SFlags and NFlags) are described in
156 @ref{Object Flags}.
158 %end-doc */
160 parsepcb
162 /* reset flags for 'used layers';
163 * init font and data pointers
165 int i;
167 if (!yyPCB)
169 Message(_("illegal fileformat\n"));
170 YYABORT;
172 for (i = 0; i < MAX_ALL_LAYER; i++)
173 LayerFlag[i] = false;
174 yyFont = &yyPCB->Font;
175 yyData = yyPCB->Data;
176 yyData->pcb = yyPCB;
177 yyData->LayerN = 0;
178 /* Parse the default layer group string, just in case the file doesn't have one */
179 if (ParseGroupString (Settings.Groups, &yyPCB->LayerGroups, &yyData->LayerN))
181 Message(_("illegal default layer-group string\n"));
182 YYABORT;
185 pcbfileversion
186 pcbname
187 pcbgrid
188 pcbcursor
189 polyarea
190 pcbthermal
191 pcbdrc
192 pcbflags
193 pcbgroups
194 pcbstyles
195 pcbfont
196 pcbdata
197 pcbnetlist
199 PCBType *pcb_save = PCB;
201 CreateNewPCBPost (yyPCB, 0);
202 /* initialize the polygon clipping now since
203 * we didn't know the layer grouping before.
205 PCB = yyPCB;
206 ALLPOLYGON_LOOP (yyData);
208 InitClip (yyData, layer, polygon);
210 ENDALL_LOOP;
211 PCB = pcb_save;
215 if (yyPCB != NULL)
217 /* This case is when we load a footprint with file->open, or from the command line */
218 yyFont = &yyPCB->Font;
219 yyData = yyPCB->Data;
220 yyData->pcb = yyPCB;
221 yyData->LayerN = 0;
224 element
226 PCBType *pcb_save = PCB;
227 ElementType *e;
228 if (yyPCB != NULL)
230 /* This case is when we load a footprint with file->open, or from the command line */
231 CreateNewPCBPost (yyPCB, 0);
232 ParseGroupString("1,c:2,s", &yyPCB->LayerGroups, &yyData->LayerN);
233 e = yyPCB->Data->Element->data; /* we know there's only one */
234 PCB = yyPCB;
235 MoveElementLowLevel (yyPCB->Data, e, -e->BoundingBox.X1, -e->BoundingBox.Y1);
236 PCB = pcb_save;
237 yyPCB->MaxWidth = e->BoundingBox.X2;
238 yyPCB->MaxHeight = e->BoundingBox.Y2;
239 yyPCB->is_footprint = 1;
244 parsedata
246 /* reset flags for 'used layers';
247 * init font and data pointers
249 int i;
251 if (!yyData || !yyFont)
253 Message(_("illegal fileformat\n"));
254 YYABORT;
256 for (i = 0; i < MAX_ALL_LAYER; i++)
257 LayerFlag[i] = false;
258 yyData->LayerN = 0;
260 pcbdata
263 pcbfont
264 : parsefont
268 parsefont
271 /* mark all symbols invalid */
272 int i;
274 if (!yyFont)
276 Message(_("illegal fileformat\n"));
277 YYABORT;
279 yyFont->Valid = false;
280 for (i = 0; i <= MAX_FONTPOSITION; i++)
281 free (yyFont->Symbol[i].Line);
282 bzero(yyFont->Symbol, sizeof(yyFont->Symbol));
284 symbols
286 yyFont->Valid = true;
287 SetFontInfo(yyFont);
291 /* %start-doc pcbfile FileVersion
293 @syntax
294 FileVersion[Version]
295 @end syntax
297 @table @var
298 @item Version
299 File format version. This version number represents the date when the pcb file
300 format was last changed.
301 @end table
303 Any version of pcb build from sources equal to or newer
304 than this number should be able to read the file. If this line is not present
305 in the input file then file format compatibility is not checked.
308 %end-doc */
310 pcbfileversion
312 T_FILEVERSION '[' INTEGER ']'
314 if (check_file_version ($3) != 0)
316 YYABORT;
321 /* %start-doc pcbfile PCB
323 @syntax
324 PCB ["Name" Width Height]
325 PCB ("Name" Width Height]
326 PCB ("Name")
327 @end syntax
329 @table @var
330 @item Name
331 Name of the PCB project
332 @item Width Height
333 Size of the board
334 @end table
336 If you don't specify the size of the board, a very large default is
337 chosen.
339 %end-doc */
341 pcbname
342 : T_PCB '(' STRING ')'
344 yyPCB->Name = $3;
345 yyPCB->MaxWidth = MAX_COORD;
346 yyPCB->MaxHeight = MAX_COORD;
348 | T_PCB '(' STRING measure measure ')'
350 yyPCB->Name = $3;
351 yyPCB->MaxWidth = OU ($4);
352 yyPCB->MaxHeight = OU ($5);
354 | T_PCB '[' STRING measure measure ']'
356 yyPCB->Name = $3;
357 yyPCB->MaxWidth = NU ($4);
358 yyPCB->MaxHeight = NU ($5);
362 /* %start-doc pcbfile Grid
364 @syntax
365 Grid [Step OffsetX OffsetY Visible]
366 Grid (Step OffsetX OffsetY Visible)
367 Grid (Step OffsetX OffsetY)
368 @end syntax
370 @table @var
371 @item Step
372 Distance from one grid point to adjacent points. This value may be a
373 floating point number for the first two variants.
374 @item OffsetX OffsetY
375 The "origin" of the grid. Normally zero.
376 @item Visible
377 If non-zero, the grid will be visible on the screen.
378 @end table
380 %end-doc */
382 pcbgrid
383 : pcbgridold
384 | pcbgridnew
385 | pcbhigrid
387 pcbgridold
388 : T_GRID '(' measure measure measure ')'
390 yyPCB->Grid = OU ($3);
391 yyPCB->GridOffsetX = OU ($4);
392 yyPCB->GridOffsetY = OU ($5);
395 pcbgridnew
396 : T_GRID '(' measure measure measure INTEGER ')'
398 yyPCB->Grid = OU ($3);
399 yyPCB->GridOffsetX = OU ($4);
400 yyPCB->GridOffsetY = OU ($5);
401 if ($6)
402 Settings.DrawGrid = true;
403 else
404 Settings.DrawGrid = false;
408 pcbhigrid
409 : T_GRID '[' measure measure measure INTEGER ']'
411 yyPCB->Grid = NU ($3);
412 yyPCB->GridOffsetX = NU ($4);
413 yyPCB->GridOffsetY = NU ($5);
414 if ($6)
415 Settings.DrawGrid = true;
416 else
417 Settings.DrawGrid = false;
421 /* %start-doc pcbfile Cursor
423 @syntax
424 Cursor [X Y Zoom]
425 Cursor (X Y Zoom)
426 @end syntax
428 @table @var
429 @item X Y
430 Location of the cursor when the board was saved.
431 As of November 2012 the cursor position is not written to file anymore.
432 Older versions of pcb ignore the absence of this line in the pcb file.
433 @item Zoom
434 The current zoom factor. Note that a zoom factor of "0" means 1 mil
435 per screen pixel, N means @math{2^N} mils per screen pixel, etc. The
436 first variant accepts floating point numbers. The special value
437 "1000" means "zoom to fit"
439 This field is ignored by PCB.
440 @end table
442 %end-doc */
444 pcbcursor
445 : T_CURSOR '(' measure measure number ')'
447 yyPCB->CursorX = OU ($3);
448 yyPCB->CursorY = OU ($4);
450 | T_CURSOR '[' measure measure number ']'
452 yyPCB->CursorX = NU ($3);
453 yyPCB->CursorY = NU ($4);
458 /* %start-doc pcbfile PolyArea
460 @syntax
461 PolyArea [Area]
462 @end syntax
464 @table @var
465 @item Area
466 Minimum area of polygon island to retain. If a polygon has clearances that cause an isolated island to be created, then will only be retained if the area exceeds this minimum area.
467 @end table
469 %end-doc */
471 polyarea
473 | T_AREA '[' number ']'
475 /* Read in cmil^2 for now; in future this should be a noop. */
476 yyPCB->IsleArea = MIL_TO_COORD (MIL_TO_COORD ($3) / 100.0) / 100.0;
481 /* %start-doc pcbfile Thermal
483 @syntax
484 Thermal [Scale]
485 @end syntax
487 @table @var
488 @item Scale
489 Relative size of thermal fingers. A value of 1.0 makes the finger
490 width twice the clearance gap width (measured across the gap, not
491 diameter). The normal value is 0.5, which results in a finger width
492 the same as the clearance gap width.
493 @end table
495 %end-doc */
498 pcbthermal
500 | T_THERMAL '[' number ']'
502 yyPCB->ThermScale = $3;
506 /* %start-doc pcbfile DRC
508 @syntax
509 DRC [Bloat Shrink Line Silk Drill Ring]
510 DRC [Bloat Shrink Line Silk]
511 DRC [Bloat Shrink Line]
512 @end syntax
514 @table @var
515 @item Bloat
516 Minimum spacing between copper.
517 @item Shrink
518 Minimum copper overlap to guarantee connectivity.
519 @item Line
520 Minimum line thickness.
521 @item Silk
522 Minimum silk thickness.
523 @item Drill
524 Minimum drill size.
525 @item Ring
526 Minimum width of the annular ring around pins and vias.
527 @end table
529 %end-doc */
531 pcbdrc
533 | pcbdrc1
534 | pcbdrc2
535 | pcbdrc3
538 pcbdrc1
539 : T_DRC '[' measure measure measure ']'
541 yyPCB->Bloat = NU ($3);
542 yyPCB->Shrink = NU ($4);
543 yyPCB->minWid = NU ($5);
544 yyPCB->minRing = NU ($5);
548 pcbdrc2
549 : T_DRC '[' measure measure measure measure ']'
551 yyPCB->Bloat = NU ($3);
552 yyPCB->Shrink = NU ($4);
553 yyPCB->minWid = NU ($5);
554 yyPCB->minSlk = NU ($6);
555 yyPCB->minRing = NU ($5);
559 pcbdrc3
560 : T_DRC '[' measure measure measure measure measure measure ']'
562 yyPCB->Bloat = NU ($3);
563 yyPCB->Shrink = NU ($4);
564 yyPCB->minWid = NU ($5);
565 yyPCB->minSlk = NU ($6);
566 yyPCB->minDrill = NU ($7);
567 yyPCB->minRing = NU ($8);
571 /* %start-doc pcbfile Flags
573 @syntax
574 Flags(Number)
575 @end syntax
577 @table @var
578 @item Number
579 A number, whose value is normally given in hex, individual bits of which
580 represent pcb-wide flags as defined in @ref{PCBFlags}.
582 @end table
584 %end-doc */
586 pcbflags
587 : T_FLAGS '(' INTEGER ')'
589 yyPCB->Flags = MakeFlags ($3 & PCB_FLAGS);
591 | T_FLAGS '(' STRING ')'
593 yyPCB->Flags = string_to_pcbflags ($3, yyerror);
598 /* %start-doc pcbfile Groups
600 @syntax
601 Groups("String")
602 @end syntax
604 @table @var
605 @item String
607 Encodes the layer grouping information. Each group is separated by a
608 colon, each member of each group is separated by a comma. Group
609 members are either numbers from @code{1}..@var{N} for each layer, and
610 the letters @code{c} or @code{s} representing the component side and
611 solder side of the board. Including @code{c} or @code{s} marks that
612 group as being the top or bottom side of the board.
614 @example
615 Groups("1,2,c:3:4:5,6,s:7,8")
616 @end example
618 @end table
620 %end-doc */
622 pcbgroups
623 : T_GROUPS '(' STRING ')'
625 if (ParseGroupString ($3, &yyPCB->LayerGroups, &yyData->LayerN))
627 Message(_("illegal layer-group string\n"));
628 YYABORT;
634 /* %start-doc pcbfile Styles
636 @syntax
637 Styles("String")
638 @end syntax
640 @table @var
641 @item String
643 Encodes the four routing styles @code{pcb} knows about. The four styles
644 are separated by colons. Each style consists of five parameters as follows:
646 @table @var
647 @item Name
648 The name of the style.
649 @item Thickness
650 Width of lines and arcs.
651 @item Diameter
652 Copper diameter of pins and vias.
653 @item Drill
654 Drill diameter of pins and vias.
655 @item Keepaway
656 Minimum spacing to other nets. If omitted, 10 mils is the default.
658 @end table
660 @end table
662 @example
663 Styles("Signal,10,40,20:Power,25,60,35:Fat,40,60,35:Skinny,8,36,20")
664 Styles["Logic,1000,3600,2000,1000:Power,2500,6000,3500,1000:
665 @ @ @ Line,4000,6000,3500,1000:Breakout,600,2402,1181,600"]
666 @end example
668 @noindent
669 Note that strings in actual files cannot span lines; the above example
670 is split across lines only to make it readable.
672 %end-doc */
674 pcbstyles
675 : T_STYLES '(' STRING ')'
677 if (ParseRouteString($3, &yyPCB->RouteStyle[0], "mil"))
679 Message(_("illegal route-style string\n"));
680 YYABORT;
683 | T_STYLES '[' STRING ']'
685 if (ParseRouteString($3, &yyPCB->RouteStyle[0], "cmil"))
687 Message(_("illegal route-style string\n"));
688 YYABORT;
694 pcbdata
695 : pcbdefinitions
699 pcbdefinitions
700 : pcbdefinition
701 | pcbdefinitions pcbdefinition
704 pcbdefinition
705 : via
706 | { attr_list = & yyPCB->Attributes; } attribute
707 | rats
708 | layer
709 | element
710 | error { YYABORT; }
714 : via_hi_format
715 | via_2.0_format
716 | via_1.7_format
717 | via_newformat
718 | via_oldformat
721 /* %start-doc pcbfile Via
723 @syntax
724 Via [X Y Thickness Clearance Mask Drill "Name" SFlags]
725 Via (X Y Thickness Clearance Mask Drill "Name" NFlags)
726 Via (X Y Thickness Clearance Drill "Name" NFlags)
727 Via (X Y Thickness Drill "Name" NFlags)
728 Via (X Y Thickness "Name" NFlags)
729 @end syntax
731 @table @var
732 @item X Y
733 coordinates of center
734 @item Thickness
735 outer diameter of copper annulus
736 @item Clearance
737 add to thickness to get clearance diameter
738 @item Mask
739 diameter of solder mask opening
740 @item Drill
741 diameter of drill
742 @item Name
743 string, name of via (vias have names?)
744 @item SFlags
745 symbolic or numerical flags
746 @item NFlags
747 numerical flags only
748 @end table
750 %end-doc */
752 via_hi_format
753 /* x, y, thickness, clearance, mask, drilling-hole, name, flags */
754 : T_VIA '[' measure measure measure measure measure measure STRING flags ']'
756 CreateNewVia(yyData, NU ($3), NU ($4), NU ($5), NU ($6), NU ($7),
757 NU ($8), $9, $10);
758 free ($9);
762 via_2.0_format
763 /* x, y, thickness, clearance, mask, drilling-hole, name, flags */
764 : T_VIA '(' measure measure measure measure measure measure STRING INTEGER ')'
766 CreateNewVia(yyData, OU ($3), OU ($4), OU ($5), OU ($6), OU ($7), OU ($8), $9,
767 OldFlags($10));
768 free ($9);
773 via_1.7_format
774 /* x, y, thickness, clearance, drilling-hole, name, flags */
775 : T_VIA '(' measure measure measure measure measure STRING INTEGER ')'
777 CreateNewVia(yyData, OU ($3), OU ($4), OU ($5), OU ($6),
778 OU ($5) + OU($6), OU ($7), $8, OldFlags($9));
779 free ($8);
783 via_newformat
784 /* x, y, thickness, drilling-hole, name, flags */
785 : T_VIA '(' measure measure measure measure STRING INTEGER ')'
787 CreateNewVia(yyData, OU ($3), OU ($4), OU ($5), 2*GROUNDPLANEFRAME,
788 OU($5) + 2*MASKFRAME, OU ($6), $7, OldFlags($8));
789 free ($7);
793 via_oldformat
794 /* old format: x, y, thickness, name, flags */
795 : T_VIA '(' measure measure measure STRING INTEGER ')'
797 Coord hole = (OU($5) * DEFAULT_DRILLINGHOLE);
799 /* make sure that there's enough copper left */
800 if (OU($5) - hole < MIN_PINORVIACOPPER &&
801 OU($5) > MIN_PINORVIACOPPER)
802 hole = OU($5) - MIN_PINORVIACOPPER;
804 CreateNewVia(yyData, OU ($3), OU ($4), OU ($5), 2*GROUNDPLANEFRAME,
805 OU($5) + 2*MASKFRAME, hole, $6, OldFlags($7));
806 free ($6);
810 /* %start-doc pcbfile Rat
812 @syntax
813 Rat [X1 Y1 Group1 X2 Y2 Group2 SFlags]
814 Rat (X1 Y1 Group1 X2 Y2 Group2 NFlags)
815 @end syntax
817 @table @var
818 @item X1 Y1 X2 Y2
819 The endpoints of the rat line.
820 @item Group1 Group2
821 The layer group each end is connected on.
822 @item SFlags
823 Symbolic or numeric flags.
824 @item NFlags
825 Numeric flags.
826 @end table
828 %end-doc */
830 rats
831 : T_RAT '[' measure measure INTEGER measure measure INTEGER flags ']'
833 CreateNewRat(yyData, NU ($3), NU ($4), NU ($6), NU ($7), $5, $8,
834 Settings.RatThickness, $9);
836 | T_RAT '(' measure measure INTEGER measure measure INTEGER INTEGER ')'
838 CreateNewRat(yyData, OU ($3), OU ($4), OU ($6), OU ($7), $5, $8,
839 Settings.RatThickness, OldFlags($9));
843 /* %start-doc pcbfile Layer
845 @syntax
846 Layer (LayerNum "Name" "Flags") (
847 @ @ @ @dots{} contents @dots{}
849 @end syntax
851 @table @var
852 @item LayerNum
853 The layer number. Layers are numbered sequentially, starting with 1.
854 The last two layers (9 and 10 by default) are solder-side silk and
855 component-side silk, in that order. The two silk layers also mark top and
856 bottom side; the layer group where the solder-side silk layer is member in
857 is the solder side group. Analogous for the other side.
858 @item Name
859 The layer name.
861 For layout files predating layer flags the name also defines
862 the layer type in some situations. For example, a layer named @emph{outline}
863 was considered to be the layer defining the extents of the board.
864 @item Flags
865 Layer flags. Currently this is the layer type, like @emph{copper}, @emph{silk}
866 or @emph{outline}. For a complete list see layertype_name[] in layerflags.c.
868 With layer flags missing, the type of layer is guessed at load time, mostly by
869 the layer name. This mechanism ensures compatibility with older layouts.
870 @item contents
871 The contents of the layer, which may include attributes, lines, arcs, rectangles,
872 text, and polygons.
873 @end table
875 %end-doc */
877 layer
878 /* name */
879 : T_LAYER '(' INTEGER STRING opt_string ')' '('
881 if ($3 <= 0 || $3 > MAX_ALL_LAYER)
883 yyerror("Layernumber out of range");
884 YYABORT;
886 if (LayerFlag[$3-1])
888 yyerror("Layernumber used twice");
889 YYABORT;
891 Layer = &yyData->Layer[$3-1];
893 /* memory for name is already allocated */
894 Layer->Name = $4;
895 if (Layer->Name == NULL)
896 Layer->Name = strdup("");
897 LayerFlag[$3-1] = true;
898 if ($5)
899 Layer->Type = string_to_layertype ($5, yyerror);
900 else
901 Layer->Type = guess_layertype ($4, $3, yyData);
903 layerdata ')'
906 layerdata
907 : layerdefinitions
911 layerdefinitions
912 : layerdefinition
913 | layerdefinitions layerdefinition
916 layerdefinition
917 : line_hi_format
918 | line_1.7_format
919 | line_oldformat
920 | arc_hi_format
921 | arc_1.7_format
922 | arc_oldformat
923 /* x1, y1, x2, y2, flags */
924 | T_RECTANGLE '(' measure measure measure measure INTEGER ')'
926 CreateNewPolygonFromRectangle(Layer,
927 OU ($3), OU ($4), OU ($3) + OU ($5), OU ($4) + OU ($6), OldFlags($7));
929 | text_hi_format
930 | text_newformat
931 | text_oldformat
932 | { attr_list = & Layer->Attributes; } attribute
933 | polygon_format
935 /* %start-doc pcbfile Line
937 @syntax
938 Line [X1 Y1 X2 Y2 Thickness Clearance SFlags]
939 Line (X1 Y1 X2 Y2 Thickness Clearance NFlags)
940 Line (X1 Y1 X2 Y2 Thickness NFlags)
941 @end syntax
943 @table @var
944 @item X1 Y1 X2 Y2
945 The end points of the line
946 @item Thickness
947 The width of the line
948 @item Clearance
949 The amount of space cleared around the line when the line passes
950 through a polygon. The clearance is added to the thickness to get the
951 thickness of the clear; thus the space between the line and the
952 polygon is @math{Clearance/2} wide.
953 @item SFlags
954 Symbolic or numeric flags
955 @item NFlags
956 Numeric flags.
957 @end table
959 %end-doc */
961 line_hi_format
962 /* x1, y1, x2, y2, thickness, clearance, flags */
963 : T_LINE '[' measure measure measure measure measure measure flags ']'
965 CreateNewLineOnLayer(Layer, NU ($3), NU ($4), NU ($5), NU ($6),
966 NU ($7), NU ($8), $9);
970 line_1.7_format
971 /* x1, y1, x2, y2, thickness, clearance, flags */
972 : T_LINE '(' measure measure measure measure measure measure INTEGER ')'
974 CreateNewLineOnLayer(Layer, OU ($3), OU ($4), OU ($5), OU ($6),
975 OU ($7), OU ($8), OldFlags($9));
979 line_oldformat
980 /* x1, y1, x2, y2, thickness, flags */
981 : T_LINE '(' measure measure measure measure measure measure ')'
983 /* eliminate old-style rat-lines */
984 if ((IV ($8) & RATFLAG) == 0)
985 CreateNewLineOnLayer(Layer, OU ($3), OU ($4), OU ($5), OU ($6), OU ($7),
986 200*GROUNDPLANEFRAME, OldFlags(IV ($8)));
990 /* %start-doc pcbfile Arc
992 @syntax
993 Arc [X Y RadiusX RadiusY Thickness Clearance StartAngle DeltaAngle SFlags]
994 Arc (X Y RadiusX RadiusY Thickness Clearance StartAngle DeltaAngle NFlags)
995 Arc (X Y RadiusX RadiusY Thickness StartAngle DeltaAngle NFlags)
996 @end syntax
998 @table @var
999 @item X Y
1000 Coordinates of the center of the arc.
1001 @item RadiusX RadiusY
1002 The RadiusX and RadiusY, from the center to the edge (centerline of the
1003 trace). The bounds of the circle of which this arc is a segment, is
1004 thus @math{2*RadiusX} by @math{2*RadiusY}.
1005 @item Thickness
1006 The width of the copper trace which forms the arc.
1007 @item Clearance
1008 The amount of space cleared around the arc when the line passes
1009 through a polygon. The clearance is added to the thickness to get the
1010 thickness of the clear; thus the space between the arc and the polygon
1011 is @math{Clearance/2} wide.
1012 @item StartAngle
1013 The angle of one end of the arc, in degrees. In PCB, an angle of zero
1014 points left (negative X direction), and 90 degrees points down
1015 (positive Y direction).
1016 @item DeltaAngle
1017 The sweep of the arc. This may be negative. Positive angles sweep
1018 counterclockwise.
1019 @item SFlags
1020 Symbolic or numeric flags.
1021 @item NFlags
1022 Numeric flags.
1023 @end table
1025 %end-doc */
1027 arc_hi_format
1028 /* x, y, width, height, thickness, clearance, startangle, delta, flags */
1029 : T_ARC '[' measure measure measure measure measure measure number number flags ']'
1031 CreateNewArcOnLayer(Layer, NU ($3), NU ($4), NU ($5), NU ($6), $9, $10,
1032 NU ($7), NU ($8), $11);
1036 arc_1.7_format
1037 /* x, y, width, height, thickness, clearance, startangle, delta, flags */
1038 : T_ARC '(' measure measure measure measure measure measure number number INTEGER ')'
1040 CreateNewArcOnLayer(Layer, OU ($3), OU ($4), OU ($5), OU ($6), $9, $10,
1041 OU ($7), OU ($8), OldFlags($11));
1045 arc_oldformat
1046 /* x, y, width, height, thickness, startangle, delta, flags */
1047 : T_ARC '(' measure measure measure measure measure measure number INTEGER ')'
1049 CreateNewArcOnLayer(Layer, OU ($3), OU ($4), OU ($5), OU ($5), IV ($8), $9,
1050 OU ($7), 200*GROUNDPLANEFRAME, OldFlags($10));
1054 /* %start-doc pcbfile Text
1056 @syntax
1057 Text [X Y Direction Scale "String" SFlags]
1058 Text (X Y Direction Scale "String" NFlags)
1059 Text (X Y Direction "String" NFlags)
1060 @end syntax
1062 @table @var
1063 @item X Y
1064 The location of the upper left corner of the text.
1065 @item Direction
1066 0 means text is drawn left to right, 1 means up, 2 means right to left
1067 (i.e. upside down), and 3 means down.
1068 @item Scale
1069 Size of the text, as a percentage of the ``default'' size of of the
1070 font (the default font is about 40 mils high). Default is 100 (40
1071 mils).
1072 @item String
1073 The string to draw.
1074 @item SFlags
1075 Symbolic or numeric flags.
1076 @item NFlags
1077 Numeric flags.
1078 @end table
1080 %end-doc */
1082 text_oldformat
1083 /* x, y, direction, text, flags */
1084 : T_TEXT '(' measure measure number STRING INTEGER ')'
1086 /* use a default scale of 100% */
1087 CreateNewText(Layer,yyFont,OU ($3), OU ($4), $5, 100, $6, OldFlags($7));
1088 free ($6);
1092 text_newformat
1093 /* x, y, direction, scale, text, flags */
1094 : T_TEXT '(' measure measure number number STRING INTEGER ')'
1096 if ($8 & ONSILKFLAG)
1098 LayerType *lay = &yyData->Layer[yyData->LayerN +
1099 (($8 & ONSOLDERFLAG) ? BOTTOM_SILK_LAYER : TOP_SILK_LAYER)];
1101 CreateNewText(lay ,yyFont, OU ($3), OU ($4), $5, $6, $7,
1102 OldFlags($8));
1104 else
1105 CreateNewText(Layer, yyFont, OU ($3), OU ($4), $5, $6, $7,
1106 OldFlags($8));
1107 free ($7);
1110 text_hi_format
1111 /* x, y, direction, scale, text, flags */
1112 : T_TEXT '[' measure measure number number STRING flags ']'
1114 /* FIXME: shouldn't know about .f */
1115 /* I don't think this matters because anything with hi_format
1116 * will have the silk on its own layer in the file rather
1117 * than using the ONSILKFLAG and having it in a copper layer.
1118 * Thus there is no need for anything besides the 'else'
1119 * part of this code.
1121 if ($8.f & ONSILKFLAG)
1123 LayerType *lay = &yyData->Layer[yyData->LayerN +
1124 (($8.f & ONSOLDERFLAG) ? BOTTOM_SILK_LAYER : TOP_SILK_LAYER)];
1126 CreateNewText(lay, yyFont, NU ($3), NU ($4), $5, $6, $7, $8);
1128 else
1129 CreateNewText(Layer, yyFont, NU ($3), NU ($4), $5, $6, $7, $8);
1130 free ($7);
1134 /* %start-doc pcbfile Polygon
1136 @syntax
1137 Polygon (SFlags) (
1138 @ @ @ @dots{} (X Y) @dots{}
1139 @ @ @ @dots{} [X Y] @dots{}
1140 @ @ @ Hole (
1141 @ @ @ @ @ @ @dots{} (X Y) @dots{}
1142 @ @ @ @ @ @ @dots{} [X Y] @dots{}
1143 @ @ @ )
1144 @ @ @ @dots{}
1146 @end syntax
1148 @table @var
1149 @item SFlags
1150 Symbolic or numeric flags.
1151 @item X Y
1152 Coordinates of each vertex. You must list at least three coordinates.
1153 @item Hole (...)
1154 Defines a hole within the polygon's outer contour. There may be zero or more such sections.
1155 @end table
1157 %end-doc */
1159 polygon_format
1160 : /* flags are passed in */
1161 T_POLYGON '(' flags ')' '('
1163 Polygon = CreateNewPolygon(Layer, $3);
1165 polygonpoints
1166 polygonholes ')'
1168 Cardinal contour, contour_start, contour_end;
1169 bool bad_contour_found = false;
1170 /* ignore junk */
1171 for (contour = 0; contour <= Polygon->HoleIndexN; contour++)
1173 contour_start = (contour == 0) ?
1174 0 : Polygon->HoleIndex[contour - 1];
1175 contour_end = (contour == Polygon->HoleIndexN) ?
1176 Polygon->PointN :
1177 Polygon->HoleIndex[contour];
1178 if (contour_end - contour_start < 3)
1179 bad_contour_found = true;
1182 if (bad_contour_found)
1184 Message(_("WARNING parsing file '%s'\n"
1185 " line: %i\n"
1186 " description: 'ignored polygon "
1187 "(< 3 points in a contour)'\n"),
1188 yyfilename, yylineno);
1189 DestroyObject(yyData, POLYGON_TYPE, Layer, Polygon, Polygon);
1191 else
1193 SetPolygonBoundingBox (Polygon);
1194 if (!Layer->polygon_tree)
1195 Layer->polygon_tree = r_create_tree (NULL, 0, 0);
1196 r_insert_entry (Layer->polygon_tree, (BoxType *) Polygon, 0);
1201 polygonholes
1202 : /* empty */
1203 | polygonholes polygonhole
1206 polygonhole
1207 : T_POLYGON_HOLE '('
1209 CreateNewHoleInPolygon (Polygon);
1211 polygonpoints ')'
1214 polygonpoints
1215 : /* empty */
1216 | polygonpoint polygonpoints
1219 polygonpoint
1220 /* xcoord ycoord */
1221 : '(' measure measure ')'
1223 CreateNewPointInPolygon(Polygon, OU ($2), OU ($3));
1225 | '[' measure measure ']'
1227 CreateNewPointInPolygon(Polygon, NU ($2), NU ($3));
1231 /* %start-doc pcbfile Element
1233 @syntax
1234 Element [SFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TSFlags] (
1235 Element (NFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TNFlags) (
1236 Element (NFlags "Desc" "Name" "Value" TX TY TDir TScale TNFlags) (
1237 Element (NFlags "Desc" "Name" TX TY TDir TScale TNFlags) (
1238 Element ("Desc" "Name" TX TY TDir TScale TNFlags) (
1239 @ @ @ @dots{} contents @dots{}
1241 @end syntax
1243 @table @var
1244 @item SFlags
1245 Symbolic or numeric flags, for the element as a whole.
1246 @item NFlags
1247 Numeric flags, for the element as a whole.
1248 @item Desc
1249 The description of the element. This is one of the three strings
1250 which can be displayed on the screen.
1251 @item Name
1252 The name of the element, usually the reference designator.
1253 @item Value
1254 The value of the element.
1255 @item MX MY
1256 The location of the element's mark. This is the reference point
1257 for placing the element and its pins and pads.
1258 @item TX TY
1259 The upper left corner of the text (one of the three strings).
1260 @item TDir
1261 The relative direction of the text. 0 means left to right for
1262 an unrotated element, 1 means up, 2 left, 3 down.
1263 @item TScale
1264 Size of the text, as a percentage of the ``default'' size of of the
1265 font (the default font is about 40 mils high). Default is 100 (40
1266 mils).
1267 @item TSFlags
1268 Symbolic or numeric flags, for the text.
1269 @item TNFlags
1270 Numeric flags, for the text.
1271 @end table
1273 Elements may contain pins, pads, element lines, element arcs,
1274 attributes, and (for older elements) an optional mark. Note that
1275 element definitions that have the mark coordinates in the element
1276 line, only support pins and pads which use relative coordinates. The
1277 pin and pad coordinates are relative to the mark. Element definitions
1278 which do not include the mark coordinates in the element line, may
1279 have a Mark definition in their contents, and only use pin and pad
1280 definitions which use absolute coordinates.
1282 %end-doc */
1284 element
1285 : element_oldformat
1286 | element_1.3.4_format
1287 | element_newformat
1288 | element_1.7_format
1289 | element_hi_format
1292 element_oldformat
1293 /* element_flags, description, pcb-name,
1294 * text_x, text_y, text_direction, text_scale, text_flags
1296 : T_ELEMENT '(' STRING STRING measure measure INTEGER ')' '('
1298 yyElement = CreateNewElement(yyData, yyFont, NoFlags(),
1299 $3, $4, NULL, OU ($5), OU ($6), $7, 100, NoFlags(), false);
1300 free ($3);
1301 free ($4);
1302 pin_num = 1;
1304 elementdefinitions ')'
1306 SetElementBoundingBox(yyData, yyElement, yyFont);
1310 element_1.3.4_format
1311 /* element_flags, description, pcb-name,
1312 * text_x, text_y, text_direction, text_scale, text_flags
1314 : T_ELEMENT '(' INTEGER STRING STRING measure measure measure measure INTEGER ')' '('
1316 yyElement = CreateNewElement(yyData, yyFont, OldFlags($3),
1317 $4, $5, NULL, OU ($6), OU ($7), IV ($8), IV ($9), OldFlags($10), false);
1318 free ($4);
1319 free ($5);
1320 pin_num = 1;
1322 elementdefinitions ')'
1324 SetElementBoundingBox(yyData, yyElement, yyFont);
1328 element_newformat
1329 /* element_flags, description, pcb-name, value,
1330 * text_x, text_y, text_direction, text_scale, text_flags
1332 : T_ELEMENT '(' INTEGER STRING STRING STRING measure measure measure measure INTEGER ')' '('
1334 yyElement = CreateNewElement(yyData, yyFont, OldFlags($3),
1335 $4, $5, $6, OU ($7), OU ($8), IV ($9), IV ($10), OldFlags($11), false);
1336 free ($4);
1337 free ($5);
1338 free ($6);
1339 pin_num = 1;
1341 elementdefinitions ')'
1343 SetElementBoundingBox(yyData, yyElement, yyFont);
1347 element_1.7_format
1348 /* element_flags, description, pcb-name, value, mark_x, mark_y,
1349 * text_x, text_y, text_direction, text_scale, text_flags
1351 : T_ELEMENT '(' INTEGER STRING STRING STRING measure measure
1352 measure measure number number INTEGER ')' '('
1354 yyElement = CreateNewElement(yyData, yyFont, OldFlags($3),
1355 $4, $5, $6, OU ($7) + OU ($9), OU ($8) + OU ($10),
1356 $11, $12, OldFlags($13), false);
1357 yyElement->MarkX = OU ($7);
1358 yyElement->MarkY = OU ($8);
1359 free ($4);
1360 free ($5);
1361 free ($6);
1363 relementdefs ')'
1365 SetElementBoundingBox(yyData, yyElement, yyFont);
1369 element_hi_format
1370 /* element_flags, description, pcb-name, value, mark_x, mark_y,
1371 * text_x, text_y, text_direction, text_scale, text_flags
1373 : T_ELEMENT '[' flags STRING STRING STRING measure measure
1374 measure measure number number flags ']' '('
1376 yyElement = CreateNewElement(yyData, yyFont, $3,
1377 $4, $5, $6, NU ($7) + NU ($9), NU ($8) + NU ($10),
1378 $11, $12, $13, false);
1379 yyElement->MarkX = NU ($7);
1380 yyElement->MarkY = NU ($8);
1381 free ($4);
1382 free ($5);
1383 free ($6);
1385 relementdefs ')'
1387 SetElementBoundingBox(yyData, yyElement, yyFont);
1391 /* %start-doc pcbfile ElementLine
1393 @syntax
1394 ElementLine [X1 Y1 X2 Y2 Thickness]
1395 ElementLine (X1 Y1 X2 Y2 Thickness)
1396 @end syntax
1398 @table @var
1399 @item X1 Y1 X2 Y2
1400 Coordinates of the endpoints of the line. These are relative to the
1401 Element's mark point for new element formats, or absolute for older
1402 formats.
1403 @item Thickness
1404 The width of the silk for this line.
1405 @end table
1407 %end-doc */
1409 /* %start-doc pcbfile ElementArc
1411 @syntax
1412 ElementArc [X Y Width Height StartAngle DeltaAngle Thickness]
1413 ElementArc (X Y Width Height StartAngle DeltaAngle Thickness)
1414 @end syntax
1416 @table @var
1417 @item X Y
1418 Coordinates of the center of the arc. These are relative to the
1419 Element's mark point for new element formats, or absolute for older
1420 formats.
1421 @item Width Height
1422 The width and height, from the center to the edge. The bounds of the
1423 circle of which this arc is a segment, is thus @math{2*Width} by
1424 @math{2*Height}.
1425 @item StartAngle
1426 The angle of one end of the arc, in degrees. In PCB, an angle of zero
1427 points left (negative X direction), and 90 degrees points down
1428 (positive Y direction).
1429 @item DeltaAngle
1430 The sweep of the arc. This may be negative. Positive angles sweep
1431 counterclockwise.
1432 @item Thickness
1433 The width of the silk line which forms the arc.
1434 @end table
1436 %end-doc */
1438 /* %start-doc pcbfile Mark
1440 @syntax
1441 Mark [X Y]
1442 Mark (X Y)
1443 @end syntax
1445 @table @var
1446 @item X Y
1447 Coordinates of the Mark, for older element formats that don't have
1448 the mark as part of the Element line.
1449 @end table
1451 %end-doc */
1453 elementdefinitions
1454 : elementdefinition
1455 | elementdefinitions elementdefinition
1458 elementdefinition
1459 : pin_1.6.3_format
1460 | pin_newformat
1461 | pin_oldformat
1462 | pad_newformat
1463 | pad
1464 /* x1, y1, x2, y2, thickness */
1465 | T_ELEMENTLINE '[' measure measure measure measure measure ']'
1467 CreateNewLineInElement(yyElement, NU ($3), NU ($4), NU ($5), NU ($6), NU ($7));
1469 /* x1, y1, x2, y2, thickness */
1470 | T_ELEMENTLINE '(' measure measure measure measure measure ')'
1472 CreateNewLineInElement(yyElement, OU ($3), OU ($4), OU ($5), OU ($6), OU ($7));
1474 /* x, y, width, height, startangle, anglediff, thickness */
1475 | T_ELEMENTARC '[' measure measure measure measure number number measure ']'
1477 CreateNewArcInElement(yyElement, NU ($3), NU ($4), NU ($5), NU ($6), $7, $8, NU ($9));
1479 /* x, y, width, height, startangle, anglediff, thickness */
1480 | T_ELEMENTARC '(' measure measure measure measure number number measure ')'
1482 CreateNewArcInElement(yyElement, OU ($3), OU ($4), OU ($5), OU ($6), $7, $8, OU ($9));
1484 /* x, y position */
1485 | T_MARK '[' measure measure ']'
1487 yyElement->MarkX = NU ($3);
1488 yyElement->MarkY = NU ($4);
1490 | T_MARK '(' measure measure ')'
1492 yyElement->MarkX = OU ($3);
1493 yyElement->MarkY = OU ($4);
1495 | { attr_list = & yyElement->Attributes; } attribute
1498 relementdefs
1499 : relementdef
1500 | relementdefs relementdef
1503 relementdef
1504 : pin_1.7_format
1505 | pin_hi_format
1506 | pad_1.7_format
1507 | pad_hi_format
1508 /* x1, y1, x2, y2, thickness */
1509 | T_ELEMENTLINE '[' measure measure measure measure measure ']'
1511 CreateNewLineInElement(yyElement, NU ($3) + yyElement->MarkX,
1512 NU ($4) + yyElement->MarkY, NU ($5) + yyElement->MarkX,
1513 NU ($6) + yyElement->MarkY, NU ($7));
1515 | T_ELEMENTLINE '(' measure measure measure measure measure ')'
1517 CreateNewLineInElement(yyElement, OU ($3) + yyElement->MarkX,
1518 OU ($4) + yyElement->MarkY, OU ($5) + yyElement->MarkX,
1519 OU ($6) + yyElement->MarkY, OU ($7));
1521 /* x, y, width, height, startangle, anglediff, thickness */
1522 | T_ELEMENTARC '[' measure measure measure measure number number measure ']'
1524 CreateNewArcInElement(yyElement, NU ($3) + yyElement->MarkX,
1525 NU ($4) + yyElement->MarkY, NU ($5), NU ($6), $7, $8, NU ($9));
1527 | T_ELEMENTARC '(' measure measure measure measure number number measure ')'
1529 CreateNewArcInElement(yyElement, OU ($3) + yyElement->MarkX,
1530 OU ($4) + yyElement->MarkY, OU ($5), OU ($6), $7, $8, OU ($9));
1532 | { attr_list = & yyElement->Attributes; } attribute
1535 /* %start-doc pcbfile Pin
1537 @syntax
1538 Pin [rX rY Thickness Clearance Mask Drill "Name" "Number" SFlags]
1539 Pin (rX rY Thickness Clearance Mask Drill "Name" "Number" NFlags)
1540 Pin (aX aY Thickness Drill "Name" "Number" NFlags)
1541 Pin (aX aY Thickness Drill "Name" NFlags)
1542 Pin (aX aY Thickness "Name" NFlags)
1543 @end syntax
1545 @table @var
1546 @item rX rY
1547 coordinates of center, relative to the element's mark
1548 @item aX aY
1549 absolute coordinates of center.
1550 @item Thickness
1551 outer diameter of copper annulus
1552 @item Clearance
1553 add to thickness to get clearance diameter
1554 @item Mask
1555 diameter of solder mask opening
1556 @item Drill
1557 diameter of drill
1558 @item Name
1559 name of pin
1560 @item Number
1561 number of pin
1562 @item SFlags
1563 symbolic or numerical flags
1564 @item NFlags
1565 numerical flags only
1566 @end table
1568 %end-doc */
1570 pin_hi_format
1571 /* x, y, thickness, clearance, mask, drilling hole, name,
1572 number, flags */
1573 : T_PIN '[' measure measure measure measure measure measure STRING STRING flags ']'
1575 CreateNewPin(yyElement, NU ($3) + yyElement->MarkX,
1576 NU ($4) + yyElement->MarkY, NU ($5), NU ($6), NU ($7), NU ($8), $9,
1577 $10, $11);
1578 free ($9);
1579 free ($10);
1582 pin_1.7_format
1583 /* x, y, thickness, clearance, mask, drilling hole, name,
1584 number, flags */
1585 : T_PIN '(' measure measure measure measure measure measure STRING STRING INTEGER ')'
1587 CreateNewPin(yyElement, OU ($3) + yyElement->MarkX,
1588 OU ($4) + yyElement->MarkY, OU ($5), OU ($6), OU ($7), OU ($8), $9,
1589 $10, OldFlags($11));
1590 free ($9);
1591 free ($10);
1595 pin_1.6.3_format
1596 /* x, y, thickness, drilling hole, name, number, flags */
1597 : T_PIN '(' measure measure measure measure STRING STRING INTEGER ')'
1599 CreateNewPin(yyElement, OU ($3), OU ($4), OU ($5), 2*GROUNDPLANEFRAME,
1600 OU ($5) + 2*MASKFRAME, OU ($6), $7, $8, OldFlags($9));
1601 free ($7);
1602 free ($8);
1606 pin_newformat
1607 /* x, y, thickness, drilling hole, name, flags */
1608 : T_PIN '(' measure measure measure measure STRING INTEGER ')'
1610 char p_number[8];
1612 sprintf(p_number, "%d", pin_num++);
1613 CreateNewPin(yyElement, OU ($3), OU ($4), OU ($5), 2*GROUNDPLANEFRAME,
1614 OU ($5) + 2*MASKFRAME, OU ($6), $7, p_number, OldFlags($8));
1616 free ($7);
1620 pin_oldformat
1621 /* old format: x, y, thickness, name, flags
1622 * drilling hole is 40% of the diameter
1624 : T_PIN '(' measure measure measure STRING INTEGER ')'
1626 Coord hole = OU ($5) * DEFAULT_DRILLINGHOLE;
1627 char p_number[8];
1629 /* make sure that there's enough copper left */
1630 if (OU ($5) - hole < MIN_PINORVIACOPPER &&
1631 OU ($5) > MIN_PINORVIACOPPER)
1632 hole = OU ($5) - MIN_PINORVIACOPPER;
1634 sprintf(p_number, "%d", pin_num++);
1635 CreateNewPin(yyElement, OU ($3), OU ($4), OU ($5), 2*GROUNDPLANEFRAME,
1636 OU ($5) + 2*MASKFRAME, hole, $6, p_number, OldFlags($7));
1637 free ($6);
1641 /* %start-doc pcbfile Pad
1643 @syntax
1644 Pad [rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" SFlags]
1645 Pad (rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" NFlags)
1646 Pad (aX1 aY1 aX2 aY2 Thickness "Name" "Number" NFlags)
1647 Pad (aX1 aY1 aX2 aY2 Thickness "Name" NFlags)
1648 @end syntax
1650 @table @var
1651 @item rX1 rY1 rX2 rY2
1652 Coordinates of the endpoints of the pad, relative to the element's
1653 mark. Note that the copper extends beyond these coordinates by half
1654 the thickness. To make a square or round pad, specify the same
1655 coordinate twice.
1656 @item aX1 aY1 aX2 aY2
1657 Same, but absolute coordinates of the endpoints of the pad.
1658 @item Thickness
1659 width of the pad.
1660 @item Clearance
1661 add to thickness to get clearance width.
1662 @item Mask
1663 width of solder mask opening.
1664 @item Name
1665 name of pin
1666 @item Number
1667 number of pin
1668 @item SFlags
1669 symbolic or numerical flags
1670 @item NFlags
1671 numerical flags only
1672 @end table
1674 %end-doc */
1676 pad_hi_format
1677 /* x1, y1, x2, y2, thickness, clearance, mask, name , pad number, flags */
1678 : T_PAD '[' measure measure measure measure measure measure measure STRING STRING flags ']'
1680 CreateNewPad(yyElement, NU ($3) + yyElement->MarkX,
1681 NU ($4) + yyElement->MarkY,
1682 NU ($5) + yyElement->MarkX,
1683 NU ($6) + yyElement->MarkY, NU ($7), NU ($8), NU ($9),
1684 $10, $11, $12);
1685 free ($10);
1686 free ($11);
1690 pad_1.7_format
1691 /* x1, y1, x2, y2, thickness, clearance, mask, name , pad number, flags */
1692 : T_PAD '(' measure measure measure measure measure measure measure STRING STRING INTEGER ')'
1694 CreateNewPad(yyElement,OU ($3) + yyElement->MarkX,
1695 OU ($4) + yyElement->MarkY, OU ($5) + yyElement->MarkX,
1696 OU ($6) + yyElement->MarkY, OU ($7), OU ($8), OU ($9),
1697 $10, $11, OldFlags($12));
1698 free ($10);
1699 free ($11);
1703 pad_newformat
1704 /* x1, y1, x2, y2, thickness, name , pad number, flags */
1705 : T_PAD '(' measure measure measure measure measure STRING STRING INTEGER ')'
1707 CreateNewPad(yyElement,OU ($3),OU ($4),OU ($5),OU ($6),OU ($7), 2*GROUNDPLANEFRAME,
1708 OU ($7) + 2*MASKFRAME, $8, $9, OldFlags($10));
1709 free ($8);
1710 free ($9);
1715 /* x1, y1, x2, y2, thickness, name and flags */
1716 : T_PAD '(' measure measure measure measure measure STRING INTEGER ')'
1718 char p_number[8];
1720 sprintf(p_number, "%d", pin_num++);
1721 CreateNewPad(yyElement,OU ($3),OU ($4),OU ($5),OU ($6),OU ($7), 2*GROUNDPLANEFRAME,
1722 OU ($7) + 2*MASKFRAME, $8,p_number, OldFlags($9));
1723 free ($8);
1727 flags : INTEGER { $$ = OldFlags($1); }
1728 | STRING { $$ = string_to_flags ($1, yyerror); }
1731 symbols
1732 : symbol
1733 | symbols symbol
1736 /* %start-doc pcbfile Symbol
1738 @syntax
1739 Symbol [Char Delta] (
1740 Symbol (Char Delta) (
1741 @ @ @ @dots{} symbol lines @dots{}
1743 @end syntax
1745 @table @var
1746 @item Char
1747 The character or numerical character value this symbol represents.
1748 Characters must be in single quotes.
1749 @item Delta
1750 Additional space to allow after this character.
1751 @end table
1753 %end-doc */
1755 symbol : symbolhead symboldata ')'
1757 symbolhead : T_SYMBOL '[' symbolid measure ']' '('
1759 if ($3 <= 0 || $3 > MAX_FONTPOSITION)
1761 yyerror("fontposition out of range");
1762 YYABORT;
1764 Symbol = &yyFont->Symbol[$3];
1765 if (Symbol->Valid)
1767 yyerror("symbol ID used twice");
1768 YYABORT;
1770 Symbol->Valid = true;
1771 Symbol->Delta = NU ($4);
1773 | T_SYMBOL '(' symbolid measure ')' '('
1775 if ($3 <= 0 || $3 > MAX_FONTPOSITION)
1777 yyerror("fontposition out of range");
1778 YYABORT;
1780 Symbol = &yyFont->Symbol[$3];
1781 if (Symbol->Valid)
1783 yyerror("symbol ID used twice");
1784 YYABORT;
1786 Symbol->Valid = true;
1787 Symbol->Delta = OU ($4);
1791 symbolid
1792 : INTEGER
1793 | CHAR_CONST
1796 symboldata
1797 : /* empty */
1798 | symboldata symboldefinition
1799 | symboldata hiressymbol
1802 /* %start-doc pcbfile SymbolLine
1804 @syntax
1805 SymbolLine [X1 Y1 X2 Y2 Thickness]
1806 SymbolLine (X1 Y1 X2 Y2 Thickness)
1807 @end syntax
1809 @table @var
1810 @item X1 Y1 X2 Y2
1811 The endpoints of this line.
1812 @item Thickness
1813 The width of this line.
1814 @end table
1816 %end-doc */
1818 symboldefinition
1819 /* x1, y1, x2, y2, thickness */
1820 : T_SYMBOLLINE '(' measure measure measure measure measure ')'
1822 CreateNewLineInSymbol(Symbol, OU ($3), OU ($4), OU ($5), OU ($6), OU ($7));
1825 hiressymbol
1826 /* x1, y1, x2, y2, thickness */
1827 : T_SYMBOLLINE '[' measure measure measure measure measure ']'
1829 CreateNewLineInSymbol(Symbol, NU ($3), NU ($4), NU ($5), NU ($6), NU ($7));
1833 /* %start-doc pcbfile Netlist
1835 @syntax
1836 Netlist ( ) (
1837 @ @ @ @dots{} nets @dots{}
1839 @end syntax
1841 %end-doc */
1843 pcbnetlist : pcbnetdef
1846 pcbnetdef
1847 /* net(...) net(...) ... */
1848 : T_NETLIST '(' ')' '('
1849 nets ')'
1852 nets
1853 : netdefs
1857 netdefs
1858 : net
1859 | netdefs net
1862 /* %start-doc pcbfile Net
1864 @syntax
1865 Net ("Name" "Style") (
1866 @ @ @ @dots{} connects @dots{}
1868 @end syntax
1870 @table @var
1871 @item Name
1872 The name of this net.
1873 @item Style
1874 The routing style that should be used when autorouting this net.
1875 @end table
1877 %end-doc */
1880 /* name style pin pin ... */
1881 : T_NET '(' STRING STRING ')' '('
1883 Menu = CreateNewNet(&yyPCB->NetlistLib, $3, $4);
1884 free ($3);
1885 free ($4);
1887 connections ')'
1890 connections
1891 : conndefs
1895 conndefs
1896 : conn
1897 | conndefs conn
1900 /* %start-doc pcbfile Connect
1902 @syntax
1903 Connect ("PinPad")
1904 @end syntax
1906 @table @var
1907 @item PinPad
1908 The name of a pin or pad which is included in this net. Pin and Pad
1909 names are named by the refdes and pin name, like @code{"U14-7"} for
1910 pin 7 of U14, or @code{"T4-E"} for pin E of T4.
1911 @end table
1913 %end-doc */
1915 conn
1916 : T_CONN '(' STRING ')'
1918 CreateNewConnection(Menu, $3);
1919 free ($3);
1923 /* %start-doc pcbfile Attribute
1925 @syntax
1926 Attribute ("Name" "Value")
1927 @end syntax
1929 Attributes allow boards and elements to have arbitrary data attached
1930 to them, which is not directly used by PCB itself but may be of use by
1931 other programs or users.
1933 @table @var
1934 @item Name
1935 The name of the attribute
1937 @item Value
1938 The value of the attribute. Values are always stored as strings, even
1939 if the value is interpreted as, for example, a number.
1941 @end table
1943 %end-doc */
1945 attribute
1946 : T_ATTRIBUTE '(' STRING STRING ')'
1948 CreateNewAttribute (attr_list, $3, $4 ? $4 : (char *)"");
1949 free ($3);
1950 free ($4);
1954 opt_string : STRING { $$ = $1; }
1955 | /* empty */ { $$ = 0; }
1958 number
1959 : FLOATING { $$ = $1; }
1960 | INTEGER { $$ = $1; }
1963 measure
1964 /* Default unit (no suffix) is cmil */
1965 : number { do_measure(&$$, $1, MIL_TO_COORD ($1) / 100.0, 0); }
1966 | number T_UMIL { M ($$, $1, MIL_TO_COORD ($1) / 1000000.0); }
1967 | number T_CMIL { M ($$, $1, MIL_TO_COORD ($1) / 100.0); }
1968 | number T_MIL { M ($$, $1, MIL_TO_COORD ($1)); }
1969 | number T_IN { M ($$, $1, INCH_TO_COORD ($1)); }
1970 | number T_NM { M ($$, $1, MM_TO_COORD ($1) / 1000000.0); }
1971 | number T_PX { M ($$, $1, MM_TO_COORD ($1) / 1000000.0); }
1972 | number T_UM { M ($$, $1, MM_TO_COORD ($1) / 1000.0); }
1973 | number T_MM { M ($$, $1, MM_TO_COORD ($1)); }
1974 | number T_M { M ($$, $1, MM_TO_COORD ($1) * 1000.0); }
1975 | number T_KM { M ($$, $1, MM_TO_COORD ($1) * 1000000.0); }
1980 /* ---------------------------------------------------------------------------
1981 * error routine called by parser library
1983 int yyerror(const char * s)
1985 Message(_("ERROR parsing file '%s'\n"
1986 " line: %i\n"
1987 " description: '%s'\n"),
1988 yyfilename, yylineno, s);
1989 return(0);
1992 int yywrap()
1994 return 1;
1997 static int
1998 check_file_version (int ver)
2000 if ( ver > PCB_FILE_VERSION ) {
2001 Message (_("ERROR: The file you are attempting to load is in a format\n"
2002 "which is too new for this version of pcb. To load this file\n"
2003 "you need a version of pcb which is >= %d. If you are\n"
2004 "using a version built from git source, the source date\n"
2005 "must be >= %d. This copy of pcb can only read files\n"
2006 "up to file version %d.\n"), ver, ver, PCB_FILE_VERSION);
2007 return 1;
2010 return 0;
2013 static void
2014 do_measure (PLMeasure *m, Coord i, double d, int u)
2016 m->ival = i;
2017 m->bval = round (d);
2018 m->dval = d;
2019 m->has_units = u;
2022 static int
2023 integer_value (PLMeasure m)
2025 if (m.has_units)
2026 yyerror("units ignored here");
2027 return m.ival;
2030 static Coord
2031 old_units (PLMeasure m)
2033 if (m.has_units)
2034 return m.bval;
2035 return round (MIL_TO_COORD (m.ival));
2038 static Coord
2039 new_units (PLMeasure m)
2041 if (m.has_units)
2042 return m.bval;
2043 return round (MIL_TO_COORD (m.ival) / 100.0);