2 * ************************** README *******************
4 * If the file format is modified in any way, update
5 * PCB_FILE_VERSION in file.h
7 * ************************** README *******************
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
59 #ifdef HAVE_LIBDMALLOC
60 # include <dmalloc.h> /* see http://dmalloc.com */
63 static LayerType
*Layer
;
64 static PolygonType
*Polygon
;
65 static SymbolType
*Symbol
;
67 static LibraryMenuType
*Menu
;
68 static bool LayerFlag
[MAX_LAYER
+ EXTRA_LAYERS
];
70 extern
char *yytext
; /* defined by LEX */
71 extern PCBType
*yyPCB
;
72 extern DataType
*yyData
;
73 extern ElementType
*yyElement
;
74 extern FontType
*yyFont
;
75 extern
int yylineno
; /* linenumber */
76 extern
char *yyfilename
; /* in this file */
78 static AttributeListType
*attr_list
;
80 int yyerror(const char *s
);
82 static int check_file_version
(int);
84 static void do_measure
(PLMeasure
*m
, Coord i
, double d
, int u
);
85 #define M(r,f,d) do_measure (&(r), f, d, 1)
87 /* Macros for interpreting what "measure" means - integer value only,
88 old units (mil), or new units (cmil). */
89 #define IV(m) integer_value (m)
90 #define OU(m) old_units (m)
91 #define NU(m) new_units (m)
93 static int integer_value
(PLMeasure m
);
94 static Coord old_units
(PLMeasure m
);
95 static Coord new_units
(PLMeasure m
);
98 #define YYERROR_VERBOSE 1
106 %
union /* define YYSTACK type */
115 %token
<number
> FLOATING
/* line thickness, coordinates ... */
116 %token
<integer
> INTEGER CHAR_CONST
/* flags ... */
117 %token
<string> STRING
/* element names ... */
119 %token T_FILEVERSION T_PCB T_LAYER T_VIA T_RAT T_LINE T_ARC T_RECTANGLE T_TEXT T_ELEMENTLINE
120 %token T_ELEMENT T_PIN T_PAD T_GRID T_FLAGS T_SYMBOL T_SYMBOLLINE T_CURSOR
121 %token T_ELEMENTARC T_MARK T_GROUPS T_STYLES T_POLYGON T_POLYGON_HOLE T_NETLIST T_NET T_CONN
122 %token T_AREA T_THERMAL T_DRC T_ATTRIBUTE
123 %token T_UMIL T_CMIL T_MIL T_IN T_NM T_UM T_MM T_M T_KM T_PX
124 %type
<integer
> symbolid
125 %type
<string> opt_string
126 %type
<flagtype
> flags
127 %type
<number
> number
128 %type
<measure
> measure
138 /* %start-doc pcbfile 00pcb
142 A special note about units: Older versions of @code{pcb} used mils
143 (1/1000 inch) as the base unit; a value of 500 in the file meant
144 half an inch. Newer versions uses a "high resolution" syntax,
145 where the base unit is 1/100 of a mil (0.000010 inch); a value of 500 in
146 the file means 5 mils. As a general rule, the variants of each entry
147 listed below which use square brackets are the high resolution formats
148 and use the 1/100 mil units, and the ones with parentheses are the older
149 variants and use 1 mil units. Note that when multiple variants
150 are listed, the most recent (and most preferred) format is the first
153 Symbolic and numeric flags (SFlags and NFlags) are described in
160 /* reset flags for 'used layers';
161 * init font and data pointers
167 Message
(_
("illegal fileformat\n"));
170 for
(i
= 0; i
< MAX_LAYER
+ EXTRA_LAYERS
; i
++)
171 LayerFlag
[i
] = false
;
172 yyFont
= &yyPCB
->Font
;
173 yyData
= yyPCB
->Data
;
176 /* Parse the default layer group string, just in case the file doesn't have one */
177 if
(ParseGroupString
(Settings.Groups
, &yyPCB
->LayerGroups
, &yyData
->LayerN
))
179 Message
(_
("illegal default layer-group string\n"));
197 PCBType
*pcb_save
= PCB
;
199 CreateNewPCBPost
(yyPCB
, 0);
200 /* initialize the polygon clipping now since
201 * we didn't know the layer grouping before.
204 ALLPOLYGON_LOOP
(yyData
);
206 InitClip
(yyData
, layer
, polygon
);
215 /* This case is when we load a footprint with file->open, or from the command line */
216 yyFont
= &yyPCB
->Font
;
217 yyData
= yyPCB
->Data
;
224 PCBType
*pcb_save
= PCB
;
228 /* This case is when we load a footprint with file->open, or from the command line */
229 CreateNewPCBPost
(yyPCB
, 0);
230 ParseGroupString
("1,c:2,s", &yyPCB
->LayerGroups
, &yyData
->LayerN
);
231 e
= yyPCB
->Data
->Element
->data
; /* we know there's only one */
233 MoveElementLowLevel
(yyPCB
->Data
, e
, -e
->BoundingBox.X1
, -e
->BoundingBox.Y1
);
235 yyPCB
->MaxWidth
= e
->BoundingBox.X2
;
236 yyPCB
->MaxHeight
= e
->BoundingBox.Y2
;
237 yyPCB
->is_footprint
= 1;
250 /* mark all symbols invalid */
255 Message
(_
("illegal fileformat\n"));
258 yyFont
->Valid
= false
;
259 for
(i
= 0; i
<= MAX_FONTPOSITION
; i
++)
260 free
(yyFont
->Symbol
[i
].Line
);
261 bzero
(yyFont
->Symbol
, sizeof
(yyFont
->Symbol
));
265 yyFont
->Valid
= true
;
270 /* %start-doc pcbfile FileVersion
278 File format version. This version number represents the date when the pcb file
279 format was last changed.
282 Any version of pcb build from sources equal to or newer
283 than this number should be able to read the file. If this line is not present
284 in the input file then file format compatibility is not checked.
291 T_FILEVERSION
'[' INTEGER
']'
293 if
(check_file_version
($3) != 0)
300 /* %start-doc pcbfile PCB
303 PCB ["Name" Width Height]
304 PCB ("Name" Width Height]
310 Name of the PCB project
315 If you don't specify the size of the board, a very large default is
321 : T_PCB
'(' STRING
')'
324 yyPCB
->MaxWidth
= MAX_COORD
;
325 yyPCB
->MaxHeight
= MAX_COORD
;
327 | T_PCB
'(' STRING measure measure
')'
330 yyPCB
->MaxWidth
= OU
($4);
331 yyPCB
->MaxHeight
= OU
($5);
333 | T_PCB
'[' STRING measure measure
']'
336 yyPCB
->MaxWidth
= NU
($4);
337 yyPCB
->MaxHeight
= NU
($5);
341 /* %start-doc pcbfile Grid
344 Grid [Step OffsetX OffsetY Visible]
345 Grid (Step OffsetX OffsetY Visible)
346 Grid (Step OffsetX OffsetY)
351 Distance from one grid point to adjacent points. This value may be a
352 floating point number for the first two variants.
353 @item OffsetX OffsetY
354 The "origin" of the grid. Normally zero.
356 If non-zero, the grid will be visible on the screen.
367 : T_GRID
'(' measure measure measure
')'
369 yyPCB
->Grid
= OU
($3);
370 yyPCB
->GridOffsetX
= OU
($4);
371 yyPCB
->GridOffsetY
= OU
($5);
375 : T_GRID
'(' measure measure measure INTEGER
')'
377 yyPCB
->Grid
= OU
($3);
378 yyPCB
->GridOffsetX
= OU
($4);
379 yyPCB
->GridOffsetY
= OU
($5);
381 Settings.DrawGrid
= true
;
383 Settings.DrawGrid
= false
;
388 : T_GRID
'[' measure measure measure INTEGER
']'
390 yyPCB
->Grid
= NU
($3);
391 yyPCB
->GridOffsetX
= NU
($4);
392 yyPCB
->GridOffsetY
= NU
($5);
394 Settings.DrawGrid
= true
;
396 Settings.DrawGrid
= false
;
400 /* %start-doc pcbfile Cursor
409 Location of the cursor when the board was saved.
410 As of November 2012 the cursor position is not written to file anymore.
411 Older versions of pcb ignore the absence of this line in the pcb file.
413 The current zoom factor. Note that a zoom factor of "0" means 1 mil
414 per screen pixel, N means @math{2^N} mils per screen pixel, etc. The
415 first variant accepts floating point numbers. The special value
416 "1000" means "zoom to fit"
418 This field is ignored by PCB.
424 : T_CURSOR
'(' measure measure number
')'
426 yyPCB
->CursorX
= OU
($3);
427 yyPCB
->CursorY
= OU
($4);
429 | T_CURSOR
'[' measure measure number
']'
431 yyPCB
->CursorX
= NU
($3);
432 yyPCB
->CursorY
= NU
($4);
437 /* %start-doc pcbfile PolyArea
445 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.
452 | T_AREA
'[' number
']'
454 /* Read in cmil^2 for now; in future this should be a noop. */
455 yyPCB
->IsleArea
= MIL_TO_COORD
(MIL_TO_COORD
($3) / 100.0) / 100.0;
460 /* %start-doc pcbfile Thermal
468 Relative size of thermal fingers. A value of 1.0 makes the finger
469 width twice the clearance gap width (measured across the gap, not
470 diameter). The normal value is 0.5, which results in a finger width
471 the same as the clearance gap width.
479 | T_THERMAL
'[' number
']'
481 yyPCB
->ThermScale
= $3;
485 /* %start-doc pcbfile DRC
488 DRC [Bloat Shrink Line Silk Drill Ring]
489 DRC [Bloat Shrink Line Silk]
490 DRC [Bloat Shrink Line]
495 Minimum spacing between copper.
497 Minimum copper overlap to guarantee connectivity.
499 Minimum line thickness.
501 Minimum silk thickness.
505 Minimum width of the annular ring around pins and vias.
518 : T_DRC
'[' measure measure measure
']'
520 yyPCB
->Bloat
= NU
($3);
521 yyPCB
->Shrink
= NU
($4);
522 yyPCB
->minWid
= NU
($5);
523 yyPCB
->minRing
= NU
($5);
528 : T_DRC
'[' measure measure measure measure
']'
530 yyPCB
->Bloat
= NU
($3);
531 yyPCB
->Shrink
= NU
($4);
532 yyPCB
->minWid
= NU
($5);
533 yyPCB
->minSlk
= NU
($6);
534 yyPCB
->minRing
= NU
($5);
539 : T_DRC
'[' measure measure measure measure measure measure
']'
541 yyPCB
->Bloat
= NU
($3);
542 yyPCB
->Shrink
= NU
($4);
543 yyPCB
->minWid
= NU
($5);
544 yyPCB
->minSlk
= NU
($6);
545 yyPCB
->minDrill
= NU
($7);
546 yyPCB
->minRing
= NU
($8);
550 /* %start-doc pcbfile Flags
558 A number, whose value is normally given in hex, individual bits of which
559 represent pcb-wide flags as defined in @ref{PCBFlags}.
566 : T_FLAGS
'(' INTEGER
')'
568 yyPCB
->Flags
= MakeFlags
($3 & PCB_FLAGS
);
570 | T_FLAGS
'(' STRING
')'
572 yyPCB
->Flags
= string_to_pcbflags
($3, yyerror);
577 /* %start-doc pcbfile Groups
586 Encodes the layer grouping information. Each group is separated by a
587 colon, each member of each group is separated by a comma. Group
588 members are either numbers from @code{1}..@var{N} for each layer, and
589 the letters @code{c} or @code{s} representing the component side and
590 solder side of the board. Including @code{c} or @code{s} marks that
591 group as being the top or bottom side of the board.
594 Groups("1,2,c:3:4:5,6,s:7,8")
602 : T_GROUPS
'(' STRING
')'
604 if
(ParseGroupString
($3, &yyPCB
->LayerGroups
, &yyData
->LayerN
))
606 Message
(_
("illegal layer-group string\n"));
613 /* %start-doc pcbfile Styles
622 Encodes the four routing styles @code{pcb} knows about. The four styles
623 are separated by colons. Each style consists of five parameters as follows:
627 The name of the style.
629 Width of lines and arcs.
631 Copper diameter of pins and vias.
633 Drill diameter of pins and vias.
635 Minimum spacing to other nets. If omitted, 10 mils is the default.
642 Styles("Signal,10,40,20:Power,25,60,35:Fat,40,60,35:Skinny,8,36,20")
643 Styles["Logic,1000,3600,2000,1000:Power,2500,6000,3500,1000:
644 @ @ @ Line,4000,6000,3500,1000:Breakout,600,2402,1181,600"]
648 Note that strings in actual files cannot span lines; the above example
649 is split across lines only to make it readable.
654 : T_STYLES
'(' STRING
')'
656 if
(ParseRouteString
($3, &yyPCB
->RouteStyle
[0], "mil"))
658 Message
(_
("illegal route-style string\n"));
662 | T_STYLES
'[' STRING
']'
664 if
(ParseRouteString
($3, &yyPCB
->RouteStyle
[0], "cmil"))
666 Message
(_
("illegal route-style string\n"));
680 | pcbdefinitions pcbdefinition
685 |
{ attr_list
= & yyPCB
->Attributes
; } attribute
699 /* %start-doc pcbfile Via
702 Via [X Y Thickness Clearance Mask Drill "Name" SFlags]
703 Via (X Y Thickness Clearance Mask Drill "Name" NFlags)
704 Via (X Y Thickness Clearance Drill "Name" NFlags)
705 Via (X Y Thickness Drill "Name" NFlags)
706 Via (X Y Thickness "Name" NFlags)
711 coordinates of center
713 outer diameter of copper annulus
715 add to thickness to get clearance diameter
717 diameter of solder mask opening
721 string, name of via (vias have names?)
723 symbolic or numerical flags
731 /* x, y, thickness, clearance, mask, drilling-hole, name, flags */
732 : T_VIA
'[' measure measure measure measure measure measure STRING flags
']'
734 CreateNewVia
(yyData
, NU
($3), NU
($4), NU
($5), NU
($6), NU
($7),
741 /* x, y, thickness, clearance, mask, drilling-hole, name, flags */
742 : T_VIA
'(' measure measure measure measure measure measure STRING INTEGER
')'
744 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7), OU
($8), $9,
752 /* x, y, thickness, clearance, drilling-hole, name, flags */
753 : T_VIA
'(' measure measure measure measure measure STRING INTEGER
')'
755 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), OU
($6),
756 OU
($5) + OU
($6), OU
($7), $8, OldFlags
($9));
762 /* x, y, thickness, drilling-hole, name, flags */
763 : T_VIA
'(' measure measure measure measure STRING INTEGER
')'
765 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
766 OU
($5) + 2*MASKFRAME
, OU
($6), $7, OldFlags
($8));
772 /* old format: x, y, thickness, name, flags */
773 : T_VIA
'(' measure measure measure STRING INTEGER
')'
775 Coord hole
= (OU
($5) * DEFAULT_DRILLINGHOLE
);
777 /* make sure that there's enough copper left */
778 if
(OU
($5) - hole
< MIN_PINORVIACOPPER
&&
779 OU
($5) > MIN_PINORVIACOPPER
)
780 hole
= OU
($5) - MIN_PINORVIACOPPER
;
782 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
783 OU
($5) + 2*MASKFRAME
, hole
, $6, OldFlags
($7));
788 /* %start-doc pcbfile Rat
791 Rat [X1 Y1 Group1 X2 Y2 Group2 SFlags]
792 Rat (X1 Y1 Group1 X2 Y2 Group2 NFlags)
797 The endpoints of the rat line.
799 The layer group each end is connected on.
801 Symbolic or numeric flags.
809 : T_RAT
'[' measure measure INTEGER measure measure INTEGER flags
']'
811 CreateNewRat
(yyData
, NU
($3), NU
($4), NU
($6), NU
($7), $5, $8,
812 Settings.RatThickness
, $9);
814 | T_RAT
'(' measure measure INTEGER measure measure INTEGER INTEGER
')'
816 CreateNewRat
(yyData
, OU
($3), OU
($4), OU
($6), OU
($7), $5, $8,
817 Settings.RatThickness
, OldFlags
($9));
821 /* %start-doc pcbfile Layer
824 Layer (LayerNum "Name") (
825 @ @ @ @dots{} contents @dots{}
831 The layer number. Layers are numbered sequentially, starting with 1.
832 The last two layers (9 and 10 by default) are solder-side silk and
833 component-side silk, in that order.
837 The contents of the layer, which may include attributes, lines, arcs, rectangles,
845 : T_LAYER
'(' INTEGER STRING opt_string
')' '('
847 if
($3 <= 0 ||
$3 > MAX_LAYER
+ EXTRA_LAYERS
)
849 yyerror("Layernumber out of range");
854 yyerror("Layernumber used twice");
857 Layer
= &yyData
->Layer
[$3-1];
859 /* memory for name is already allocated */
861 if
(Layer
->Name
== NULL
)
862 Layer
->Name
= strdup
("");
863 LayerFlag
[$3-1] = true
;
875 | layerdefinitions layerdefinition
885 /* x1, y1, x2, y2, flags */
886 | T_RECTANGLE
'(' measure measure measure measure INTEGER
')'
888 CreateNewPolygonFromRectangle
(Layer
,
889 OU
($3), OU
($4), OU
($3) + OU
($5), OU
($4) + OU
($6), OldFlags
($7));
894 |
{ attr_list
= & Layer
->Attributes
; } attribute
897 /* %start-doc pcbfile Line
900 Line [X1 Y1 X2 Y2 Thickness Clearance SFlags]
901 Line (X1 Y1 X2 Y2 Thickness Clearance NFlags)
902 Line (X1 Y1 X2 Y2 Thickness NFlags)
907 The end points of the line
909 The width of the line
911 The amount of space cleared around the line when the line passes
912 through a polygon. The clearance is added to the thickness to get the
913 thickness of the clear; thus the space between the line and the
914 polygon is @math{Clearance/2} wide.
916 Symbolic or numeric flags
924 /* x1, y1, x2, y2, thickness, clearance, flags */
925 : T_LINE
'[' measure measure measure measure measure measure flags
']'
927 CreateNewLineOnLayer
(Layer
, NU
($3), NU
($4), NU
($5), NU
($6),
928 NU
($7), NU
($8), $9);
933 /* x1, y1, x2, y2, thickness, clearance, flags */
934 : T_LINE
'(' measure measure measure measure measure measure INTEGER
')'
936 CreateNewLineOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($6),
937 OU
($7), OU
($8), OldFlags
($9));
942 /* x1, y1, x2, y2, thickness, flags */
943 : T_LINE
'(' measure measure measure measure measure measure
')'
945 /* eliminate old-style rat-lines */
946 if
((IV
($8) & RATFLAG
) == 0)
947 CreateNewLineOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7),
948 200*GROUNDPLANEFRAME
, OldFlags
(IV
($8)));
952 /* %start-doc pcbfile Arc
955 Arc [X Y Width Height Thickness Clearance StartAngle DeltaAngle SFlags]
956 Arc (X Y Width Height Thickness Clearance StartAngle DeltaAngle NFlags)
957 Arc (X Y Width Height Thickness StartAngle DeltaAngle NFlags)
962 Coordinates of the center of the arc.
964 The width and height, from the center to the edge. The bounds of the
965 circle of which this arc is a segment, is thus @math{2*Width} by
968 The width of the copper trace which forms the arc.
970 The amount of space cleared around the arc when the line passes
971 through a polygon. The clearance is added to the thickness to get the
972 thickness of the clear; thus the space between the arc and the polygon
973 is @math{Clearance/2} wide.
975 The angle of one end of the arc, in degrees. In PCB, an angle of zero
976 points left (negative X direction), and 90 degrees points down
977 (positive Y direction).
979 The sweep of the arc. This may be negative. Positive angles sweep
982 Symbolic or numeric flags.
990 /* x, y, width, height, thickness, clearance, startangle, delta, flags */
991 : T_ARC
'[' measure measure measure measure measure measure number number flags
']'
993 CreateNewArcOnLayer
(Layer
, NU
($3), NU
($4), NU
($5), NU
($6), $9, $10,
994 NU
($7), NU
($8), $11);
999 /* x, y, width, height, thickness, clearance, startangle, delta, flags */
1000 : T_ARC
'(' measure measure measure measure measure measure number number INTEGER
')'
1002 CreateNewArcOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($6), $9, $10,
1003 OU
($7), OU
($8), OldFlags
($11));
1008 /* x, y, width, height, thickness, startangle, delta, flags */
1009 : T_ARC
'(' measure measure measure measure measure measure number INTEGER
')'
1011 CreateNewArcOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($5), IV
($8), $9,
1012 OU
($7), 200*GROUNDPLANEFRAME
, OldFlags
($10));
1016 /* %start-doc pcbfile Text
1019 Text [X Y Direction Scale "String" SFlags]
1020 Text (X Y Direction Scale "String" NFlags)
1021 Text (X Y Direction "String" NFlags)
1026 The location of the upper left corner of the text.
1028 0 means text is drawn left to right, 1 means up, 2 means right to left
1029 (i.e. upside down), and 3 means down.
1031 Size of the text, as a percentage of the ``default'' size of of the
1032 font (the default font is about 40 mils high). Default is 100 (40
1037 Symbolic or numeric flags.
1045 /* x, y, direction, text, flags */
1046 : T_TEXT
'(' measure measure number STRING INTEGER
')'
1048 /* use a default scale of 100% */
1049 CreateNewText
(Layer
,yyFont
,OU
($3), OU
($4), $5, 100, $6, OldFlags
($7));
1055 /* x, y, direction, scale, text, flags */
1056 : T_TEXT
'(' measure measure number number STRING INTEGER
')'
1058 if
($8 & ONSILKFLAG
)
1060 LayerType
*lay
= &yyData
->Layer
[yyData
->LayerN
+
1061 (($8 & ONSOLDERFLAG
) ? BOTTOM_SILK_LAYER
: TOP_SILK_LAYER
)];
1063 CreateNewText
(lay
,yyFont
, OU
($3), OU
($4), $5, $6, $7,
1067 CreateNewText
(Layer
, yyFont
, OU
($3), OU
($4), $5, $6, $7,
1073 /* x, y, direction, scale, text, flags */
1074 : T_TEXT
'[' measure measure number number STRING flags
']'
1076 /* FIXME: shouldn't know about .f */
1077 /* I don't think this matters because anything with hi_format
1078 * will have the silk on its own layer in the file rather
1079 * than using the ONSILKFLAG and having it in a copper layer.
1080 * Thus there is no need for anything besides the 'else'
1081 * part of this code.
1083 if
($8.f
& ONSILKFLAG
)
1085 LayerType
*lay
= &yyData
->Layer
[yyData
->LayerN
+
1086 (($8.f
& ONSOLDERFLAG
) ? BOTTOM_SILK_LAYER
: TOP_SILK_LAYER
)];
1088 CreateNewText
(lay
, yyFont
, NU
($3), NU
($4), $5, $6, $7, $8);
1091 CreateNewText
(Layer
, yyFont
, NU
($3), NU
($4), $5, $6, $7, $8);
1096 /* %start-doc pcbfile Polygon
1100 @ @ @ @dots{} (X Y) @dots{}
1101 @ @ @ @dots{} [X Y] @dots{}
1103 @ @ @ @ @ @ @dots{} (X Y) @dots{}
1104 @ @ @ @ @ @ @dots{} [X Y] @dots{}
1112 Symbolic or numeric flags.
1114 Coordinates of each vertex. You must list at least three coordinates.
1116 Defines a hole within the polygon's outer contour. There may be zero or more such sections.
1122 : /* flags are passed in */
1123 T_POLYGON
'(' flags
')' '('
1125 Polygon
= CreateNewPolygon
(Layer
, $3);
1130 Cardinal contour
, contour_start
, contour_end
;
1131 bool bad_contour_found
= false
;
1133 for
(contour
= 0; contour
<= Polygon
->HoleIndexN
; contour
++)
1135 contour_start
= (contour
== 0) ?
1136 0 : Polygon
->HoleIndex
[contour
- 1];
1137 contour_end
= (contour
== Polygon
->HoleIndexN
) ?
1139 Polygon
->HoleIndex
[contour
];
1140 if
(contour_end
- contour_start
< 3)
1141 bad_contour_found
= true
;
1144 if
(bad_contour_found
)
1146 Message
(_
("WARNING parsing file '%s'\n"
1148 " description: 'ignored polygon "
1149 "(< 3 points in a contour)'\n"),
1150 yyfilename
, yylineno
);
1151 DestroyObject
(yyData
, POLYGON_TYPE
, Layer
, Polygon
, Polygon
);
1155 SetPolygonBoundingBox
(Polygon
);
1156 if
(!Layer
->polygon_tree
)
1157 Layer
->polygon_tree
= r_create_tree
(NULL
, 0, 0);
1158 r_insert_entry
(Layer
->polygon_tree
, (BoxType
*) Polygon
, 0);
1165 | polygonholes polygonhole
1169 : T_POLYGON_HOLE
'('
1171 CreateNewHoleInPolygon
(Polygon
);
1178 | polygonpoint polygonpoints
1183 : '(' measure measure
')'
1185 CreateNewPointInPolygon
(Polygon
, OU
($2), OU
($3));
1187 |
'[' measure measure
']'
1189 CreateNewPointInPolygon
(Polygon
, NU
($2), NU
($3));
1193 /* %start-doc pcbfile Element
1196 Element [SFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TSFlags] (
1197 Element (NFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TNFlags) (
1198 Element (NFlags "Desc" "Name" "Value" TX TY TDir TScale TNFlags) (
1199 Element (NFlags "Desc" "Name" TX TY TDir TScale TNFlags) (
1200 Element ("Desc" "Name" TX TY TDir TScale TNFlags) (
1201 @ @ @ @dots{} contents @dots{}
1207 Symbolic or numeric flags, for the element as a whole.
1209 Numeric flags, for the element as a whole.
1211 The description of the element. This is one of the three strings
1212 which can be displayed on the screen.
1214 The name of the element, usually the reference designator.
1216 The value of the element.
1218 The location of the element's mark. This is the reference point
1219 for placing the element and its pins and pads.
1221 The upper left corner of the text (one of the three strings).
1223 The relative direction of the text. 0 means left to right for
1224 an unrotated element, 1 means up, 2 left, 3 down.
1226 Size of the text, as a percentage of the ``default'' size of of the
1227 font (the default font is about 40 mils high). Default is 100 (40
1230 Symbolic or numeric flags, for the text.
1232 Numeric flags, for the text.
1235 Elements may contain pins, pads, element lines, element arcs,
1236 attributes, and (for older elements) an optional mark. Note that
1237 element definitions that have the mark coordinates in the element
1238 line, only support pins and pads which use relative coordinates. The
1239 pin and pad coordinates are relative to the mark. Element definitions
1240 which do not include the mark coordinates in the element line, may
1241 have a Mark definition in their contents, and only use pin and pad
1242 definitions which use absolute coordinates.
1248 | element_1.3
.4_format
1250 | element_1.7_format
1255 /* element_flags, description, pcb-name,
1256 * text_x, text_y, text_direction, text_scale, text_flags
1258 : T_ELEMENT
'(' STRING STRING measure measure INTEGER
')' '('
1260 yyElement
= CreateNewElement
(yyData
, yyFont
, NoFlags
(),
1261 $3, $4, NULL
, OU
($5), OU
($6), $7, 100, NoFlags
(), false
);
1266 elementdefinitions
')'
1268 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1272 element_1.3
.4_format
1273 /* element_flags, description, pcb-name,
1274 * text_x, text_y, text_direction, text_scale, text_flags
1276 : T_ELEMENT
'(' INTEGER STRING STRING measure measure measure measure INTEGER
')' '('
1278 yyElement
= CreateNewElement
(yyData
, yyFont
, OldFlags
($3),
1279 $4, $5, NULL
, OU
($6), OU
($7), IV
($8), IV
($9), OldFlags
($10), false
);
1284 elementdefinitions
')'
1286 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1291 /* element_flags, description, pcb-name, value,
1292 * text_x, text_y, text_direction, text_scale, text_flags
1294 : T_ELEMENT
'(' INTEGER STRING STRING STRING measure measure measure measure INTEGER
')' '('
1296 yyElement
= CreateNewElement
(yyData
, yyFont
, OldFlags
($3),
1297 $4, $5, $6, OU
($7), OU
($8), IV
($9), IV
($10), OldFlags
($11), false
);
1303 elementdefinitions
')'
1305 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1310 /* element_flags, description, pcb-name, value, mark_x, mark_y,
1311 * text_x, text_y, text_direction, text_scale, text_flags
1313 : T_ELEMENT
'(' INTEGER STRING STRING STRING measure measure
1314 measure measure number number INTEGER
')' '('
1316 yyElement
= CreateNewElement
(yyData
, yyFont
, OldFlags
($3),
1317 $4, $5, $6, OU
($7) + OU
($9), OU
($8) + OU
($10),
1318 $11, $12, OldFlags
($13), false
);
1319 yyElement
->MarkX
= OU
($7);
1320 yyElement
->MarkY
= OU
($8);
1327 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1332 /* element_flags, description, pcb-name, value, mark_x, mark_y,
1333 * text_x, text_y, text_direction, text_scale, text_flags
1335 : T_ELEMENT
'[' flags STRING STRING STRING measure measure
1336 measure measure number number flags
']' '('
1338 yyElement
= CreateNewElement
(yyData
, yyFont
, $3,
1339 $4, $5, $6, NU
($7) + NU
($9), NU
($8) + NU
($10),
1340 $11, $12, $13, false
);
1341 yyElement
->MarkX
= NU
($7);
1342 yyElement
->MarkY
= NU
($8);
1349 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1353 /* %start-doc pcbfile ElementLine
1356 ElementLine [X1 Y1 X2 Y2 Thickness]
1357 ElementLine (X1 Y1 X2 Y2 Thickness)
1362 Coordinates of the endpoints of the line. These are relative to the
1363 Element's mark point for new element formats, or absolute for older
1366 The width of the silk for this line.
1371 /* %start-doc pcbfile ElementArc
1374 ElementArc [X Y Width Height StartAngle DeltaAngle Thickness]
1375 ElementArc (X Y Width Height StartAngle DeltaAngle Thickness)
1380 Coordinates of the center of the arc. These are relative to the
1381 Element's mark point for new element formats, or absolute for older
1384 The width and height, from the center to the edge. The bounds of the
1385 circle of which this arc is a segment, is thus @math{2*Width} by
1388 The angle of one end of the arc, in degrees. In PCB, an angle of zero
1389 points left (negative X direction), and 90 degrees points down
1390 (positive Y direction).
1392 The sweep of the arc. This may be negative. Positive angles sweep
1395 The width of the silk line which forms the arc.
1400 /* %start-doc pcbfile Mark
1409 Coordinates of the Mark, for older element formats that don't have
1410 the mark as part of the Element line.
1417 | elementdefinitions elementdefinition
1426 /* x1, y1, x2, y2, thickness */
1427 | T_ELEMENTLINE
'[' measure measure measure measure measure
']'
1429 CreateNewLineInElement
(yyElement
, NU
($3), NU
($4), NU
($5), NU
($6), NU
($7));
1431 /* x1, y1, x2, y2, thickness */
1432 | T_ELEMENTLINE
'(' measure measure measure measure measure
')'
1434 CreateNewLineInElement
(yyElement
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7));
1436 /* x, y, width, height, startangle, anglediff, thickness */
1437 | T_ELEMENTARC
'[' measure measure measure measure number number measure
']'
1439 CreateNewArcInElement
(yyElement
, NU
($3), NU
($4), NU
($5), NU
($6), $7, $8, NU
($9));
1441 /* x, y, width, height, startangle, anglediff, thickness */
1442 | T_ELEMENTARC
'(' measure measure measure measure number number measure
')'
1444 CreateNewArcInElement
(yyElement
, OU
($3), OU
($4), OU
($5), OU
($6), $7, $8, OU
($9));
1447 | T_MARK
'[' measure measure
']'
1449 yyElement
->MarkX
= NU
($3);
1450 yyElement
->MarkY
= NU
($4);
1452 | T_MARK
'(' measure measure
')'
1454 yyElement
->MarkX
= OU
($3);
1455 yyElement
->MarkY
= OU
($4);
1457 |
{ attr_list
= & yyElement
->Attributes
; } attribute
1462 | relementdefs relementdef
1470 /* x1, y1, x2, y2, thickness */
1471 | T_ELEMENTLINE
'[' measure measure measure measure measure
']'
1473 CreateNewLineInElement
(yyElement
, NU
($3) + yyElement
->MarkX
,
1474 NU
($4) + yyElement
->MarkY
, NU
($5) + yyElement
->MarkX
,
1475 NU
($6) + yyElement
->MarkY
, NU
($7));
1477 | T_ELEMENTLINE
'(' measure measure measure measure measure
')'
1479 CreateNewLineInElement
(yyElement
, OU
($3) + yyElement
->MarkX
,
1480 OU
($4) + yyElement
->MarkY
, OU
($5) + yyElement
->MarkX
,
1481 OU
($6) + yyElement
->MarkY
, OU
($7));
1483 /* x, y, width, height, startangle, anglediff, thickness */
1484 | T_ELEMENTARC
'[' measure measure measure measure number number measure
']'
1486 CreateNewArcInElement
(yyElement
, NU
($3) + yyElement
->MarkX
,
1487 NU
($4) + yyElement
->MarkY
, NU
($5), NU
($6), $7, $8, NU
($9));
1489 | T_ELEMENTARC
'(' measure measure measure measure number number measure
')'
1491 CreateNewArcInElement
(yyElement
, OU
($3) + yyElement
->MarkX
,
1492 OU
($4) + yyElement
->MarkY
, OU
($5), OU
($6), $7, $8, OU
($9));
1494 |
{ attr_list
= & yyElement
->Attributes
; } attribute
1497 /* %start-doc pcbfile Pin
1500 Pin [rX rY Thickness Clearance Mask Drill "Name" "Number" SFlags]
1501 Pin (rX rY Thickness Clearance Mask Drill "Name" "Number" NFlags)
1502 Pin (aX aY Thickness Drill "Name" "Number" NFlags)
1503 Pin (aX aY Thickness Drill "Name" NFlags)
1504 Pin (aX aY Thickness "Name" NFlags)
1509 coordinates of center, relative to the element's mark
1511 absolute coordinates of center.
1513 outer diameter of copper annulus
1515 add to thickness to get clearance diameter
1517 diameter of solder mask opening
1525 symbolic or numerical flags
1527 numerical flags only
1533 /* x, y, thickness, clearance, mask, drilling hole, name,
1535 : T_PIN
'[' measure measure measure measure measure measure STRING STRING flags
']'
1537 CreateNewPin
(yyElement
, NU
($3) + yyElement
->MarkX
,
1538 NU
($4) + yyElement
->MarkY
, NU
($5), NU
($6), NU
($7), NU
($8), $9,
1545 /* x, y, thickness, clearance, mask, drilling hole, name,
1547 : T_PIN
'(' measure measure measure measure measure measure STRING STRING INTEGER
')'
1549 CreateNewPin
(yyElement
, OU
($3) + yyElement
->MarkX
,
1550 OU
($4) + yyElement
->MarkY
, OU
($5), OU
($6), OU
($7), OU
($8), $9,
1551 $10, OldFlags
($11));
1558 /* x, y, thickness, drilling hole, name, number, flags */
1559 : T_PIN
'(' measure measure measure measure STRING STRING INTEGER
')'
1561 CreateNewPin
(yyElement
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
1562 OU
($5) + 2*MASKFRAME
, OU
($6), $7, $8, OldFlags
($9));
1569 /* x, y, thickness, drilling hole, name, flags */
1570 : T_PIN
'(' measure measure measure measure STRING INTEGER
')'
1574 sprintf
(p_number
, "%d", pin_num
++);
1575 CreateNewPin
(yyElement
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
1576 OU
($5) + 2*MASKFRAME
, OU
($6), $7, p_number
, OldFlags
($8));
1583 /* old format: x, y, thickness, name, flags
1584 * drilling hole is 40% of the diameter
1586 : T_PIN
'(' measure measure measure STRING INTEGER
')'
1588 Coord hole
= OU
($5) * DEFAULT_DRILLINGHOLE
;
1591 /* make sure that there's enough copper left */
1592 if
(OU
($5) - hole
< MIN_PINORVIACOPPER
&&
1593 OU
($5) > MIN_PINORVIACOPPER
)
1594 hole
= OU
($5) - MIN_PINORVIACOPPER
;
1596 sprintf
(p_number
, "%d", pin_num
++);
1597 CreateNewPin
(yyElement
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
1598 OU
($5) + 2*MASKFRAME
, hole
, $6, p_number
, OldFlags
($7));
1603 /* %start-doc pcbfile Pad
1606 Pad [rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" SFlags]
1607 Pad (rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" NFlags)
1608 Pad (aX1 aY1 aX2 aY2 Thickness "Name" "Number" NFlags)
1609 Pad (aX1 aY1 aX2 aY2 Thickness "Name" NFlags)
1613 @item rX1 rY1 rX2 rY2
1614 Coordinates of the endpoints of the pad, relative to the element's
1615 mark. Note that the copper extends beyond these coordinates by half
1616 the thickness. To make a square or round pad, specify the same
1618 @item aX1 aY1 aX2 aY2
1619 Same, but absolute coordinates of the endpoints of the pad.
1623 add to thickness to get clearance width.
1625 width of solder mask opening.
1631 symbolic or numerical flags
1633 numerical flags only
1639 /* x1, y1, x2, y2, thickness, clearance, mask, name , pad number, flags */
1640 : T_PAD
'[' measure measure measure measure measure measure measure STRING STRING flags
']'
1642 CreateNewPad
(yyElement
, NU
($3) + yyElement
->MarkX
,
1643 NU
($4) + yyElement
->MarkY
,
1644 NU
($5) + yyElement
->MarkX
,
1645 NU
($6) + yyElement
->MarkY
, NU
($7), NU
($8), NU
($9),
1653 /* x1, y1, x2, y2, thickness, clearance, mask, name , pad number, flags */
1654 : T_PAD
'(' measure measure measure measure measure measure measure STRING STRING INTEGER
')'
1656 CreateNewPad
(yyElement
,OU
($3) + yyElement
->MarkX
,
1657 OU
($4) + yyElement
->MarkY
, OU
($5) + yyElement
->MarkX
,
1658 OU
($6) + yyElement
->MarkY
, OU
($7), OU
($8), OU
($9),
1659 $10, $11, OldFlags
($12));
1666 /* x1, y1, x2, y2, thickness, name , pad number, flags */
1667 : T_PAD
'(' measure measure measure measure measure STRING STRING INTEGER
')'
1669 CreateNewPad
(yyElement
,OU
($3),OU
($4),OU
($5),OU
($6),OU
($7), 2*GROUNDPLANEFRAME
,
1670 OU
($7) + 2*MASKFRAME
, $8, $9, OldFlags
($10));
1677 /* x1, y1, x2, y2, thickness, name and flags */
1678 : T_PAD
'(' measure measure measure measure measure STRING INTEGER
')'
1682 sprintf
(p_number
, "%d", pin_num
++);
1683 CreateNewPad
(yyElement
,OU
($3),OU
($4),OU
($5),OU
($6),OU
($7), 2*GROUNDPLANEFRAME
,
1684 OU
($7) + 2*MASKFRAME
, $8,p_number
, OldFlags
($9));
1689 flags
: INTEGER
{ $$
= OldFlags
($1); }
1690 | STRING
{ $$
= string_to_flags
($1, yyerror); }
1698 /* %start-doc pcbfile Symbol
1701 Symbol [Char Delta] (
1702 Symbol (Char Delta) (
1703 @ @ @ @dots{} symbol lines @dots{}
1709 The character or numerical character value this symbol represents.
1710 Characters must be in single quotes.
1712 Additional space to allow after this character.
1717 symbol
: symbolhead symboldata
')'
1719 symbolhead
: T_SYMBOL
'[' symbolid measure
']' '('
1721 if
($3 <= 0 ||
$3 > MAX_FONTPOSITION
)
1723 yyerror("fontposition out of range");
1726 Symbol
= &yyFont
->Symbol
[$3];
1729 yyerror("symbol ID used twice");
1732 Symbol
->Valid
= true
;
1733 Symbol
->Delta
= NU
($4);
1735 | T_SYMBOL
'(' symbolid measure
')' '('
1737 if
($3 <= 0 ||
$3 > MAX_FONTPOSITION
)
1739 yyerror("fontposition out of range");
1742 Symbol
= &yyFont
->Symbol
[$3];
1745 yyerror("symbol ID used twice");
1748 Symbol
->Valid
= true
;
1749 Symbol
->Delta
= OU
($4);
1760 | symboldata symboldefinition
1761 | symboldata hiressymbol
1764 /* %start-doc pcbfile SymbolLine
1767 SymbolLine [X1 Y1 X2 Y2 Thickness]
1768 SymbolLine (X1 Y1 X2 Y2 Thickness)
1773 The endpoints of this line.
1775 The width of this line.
1781 /* x1, y1, x2, y2, thickness */
1782 : T_SYMBOLLINE
'(' measure measure measure measure measure
')'
1784 CreateNewLineInSymbol
(Symbol
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7));
1788 /* x1, y1, x2, y2, thickness */
1789 : T_SYMBOLLINE
'[' measure measure measure measure measure
']'
1791 CreateNewLineInSymbol
(Symbol
, NU
($3), NU
($4), NU
($5), NU
($6), NU
($7));
1795 /* %start-doc pcbfile Netlist
1799 @ @ @ @dots{} nets @dots{}
1805 pcbnetlist
: pcbnetdef
1809 /* net(...) net(...) ... */
1810 : T_NETLIST
'(' ')' '('
1824 /* %start-doc pcbfile Net
1827 Net ("Name" "Style") (
1828 @ @ @ @dots{} connects @dots{}
1834 The name of this net.
1836 The routing style that should be used when autorouting this net.
1842 /* name style pin pin ... */
1843 : T_NET
'(' STRING STRING
')' '('
1845 Menu
= CreateNewNet
(&yyPCB
->NetlistLib
, $3, $4);
1862 /* %start-doc pcbfile Connect
1870 The name of a pin or pad which is included in this net. Pin and Pad
1871 names are named by the refdes and pin name, like @code{"U14-7"} for
1872 pin 7 of U14, or @code{"T4-E"} for pin E of T4.
1878 : T_CONN
'(' STRING
')'
1880 CreateNewConnection
(Menu
, $3);
1885 /* %start-doc pcbfile Attribute
1888 Attribute ("Name" "Value")
1891 Attributes allow boards and elements to have arbitrary data attached
1892 to them, which is not directly used by PCB itself but may be of use by
1893 other programs or users.
1897 The name of the attribute
1900 The value of the attribute. Values are always stored as strings, even
1901 if the value is interpreted as, for example, a number.
1908 : T_ATTRIBUTE
'(' STRING STRING
')'
1910 CreateNewAttribute
(attr_list
, $3, $4 ?
$4 : (char *)"");
1916 opt_string
: STRING
{ $$
= $1; }
1917 |
/* empty */ { $$
= 0; }
1921 : FLOATING
{ $$
= $1; }
1922 | INTEGER
{ $$
= $1; }
1926 /* Default unit (no suffix) is cmil */
1927 : number
{ do_measure
(&$$
, $1, MIL_TO_COORD
($1) / 100.0, 0); }
1928 | number T_UMIL
{ M
($$
, $1, MIL_TO_COORD
($1) / 1000000.0); }
1929 | number T_CMIL
{ M
($$
, $1, MIL_TO_COORD
($1) / 100.0); }
1930 | number T_MIL
{ M
($$
, $1, MIL_TO_COORD
($1)); }
1931 | number T_IN
{ M
($$
, $1, INCH_TO_COORD
($1)); }
1932 | number T_NM
{ M
($$
, $1, MM_TO_COORD
($1) / 1000000.0); }
1933 | number T_PX
{ M
($$
, $1, MM_TO_COORD
($1) / 1000000.0); }
1934 | number T_UM
{ M
($$
, $1, MM_TO_COORD
($1) / 1000.0); }
1935 | number T_MM
{ M
($$
, $1, MM_TO_COORD
($1)); }
1936 | number T_M
{ M
($$
, $1, MM_TO_COORD
($1) * 1000.0); }
1937 | number T_KM
{ M
($$
, $1, MM_TO_COORD
($1) * 1000000.0); }
1942 /* ---------------------------------------------------------------------------
1943 * error routine called by parser library
1945 int yyerror(const char * s
)
1947 Message
(_
("ERROR parsing file '%s'\n"
1949 " description: '%s'\n"),
1950 yyfilename
, yylineno
, s
);
1960 check_file_version
(int ver
)
1962 if
( ver
> PCB_FILE_VERSION
) {
1963 Message
(_
("ERROR: The file you are attempting to load is in a format\n"
1964 "which is too new for this version of pcb. To load this file\n"
1965 "you need a version of pcb which is >= %d. If you are\n"
1966 "using a version built from git source, the source date\n"
1967 "must be >= %d. This copy of pcb can only read files\n"
1968 "up to file version %d.\n"), ver
, ver
, PCB_FILE_VERSION
);
1976 do_measure
(PLMeasure
*m
, Coord i
, double d
, int u
)
1979 m
->bval
= round
(d
);
1985 integer_value
(PLMeasure m
)
1988 yyerror("units ignored here");
1993 old_units
(PLMeasure m
)
1997 return round
(MIL_TO_COORD
(m.ival
));
2001 new_units
(PLMeasure m
)
2005 return round
(MIL_TO_COORD
(m.ival
) / 100.0);