KiCad PCB EDA Suite
altium_parser_pcb.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Thomas Pointhuber <[email protected]>
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef ALTIUM_PARSER_PCB_H
26 #define ALTIUM_PARSER_PCB_H
27 
28 #include <cstdint>
29 #include <cstring>
30 #include <memory>
31 #include <vector>
32 
33 #include <footprint.h>
34 #include <wx/gdicmn.h>
35 
36 // tthis constant specifies an unconnected net
37 const uint16_t ALTIUM_NET_UNCONNECTED = std::numeric_limits<uint16_t>::max();
38 
39 // this constant specifies a item which is not inside an component
40 const uint16_t ALTIUM_COMPONENT_NONE = std::numeric_limits<uint16_t>::max();
41 
42 // this constant specifies a item which does not define a polygon
43 const uint16_t ALTIUM_POLYGON_NONE = std::numeric_limits<uint16_t>::max();
44 
45 
46 enum class ALTIUM_UNIT
47 {
48  UNKNOWN = 0,
49 
50  INCHES = 1,
51  MILS = 2,
52  MILLIMETERS = 3,
53  CENTIMETER = 4
54 };
55 
57 {
58  UNKNOWN = -1,
59 
60  NET_CLASS = 0,
62  FROM_TO = 2,
63  PAD_CLASS = 3,
64  LAYER_CLASS = 4,
65  UNKNOWN_CLASS = 5,
66  DIFF_PAIR_CLASS = 6,
67  POLYGON_CLASS = 7
68 };
69 
71 {
72  UNKNOWN = 0,
73 
74  LINEAR = 1,
75  ANGULAR = 2,
76  RADIAL = 3,
77  LEADER = 4,
78  DATUM = 5,
79  BASELINE = 6,
80  CENTER = 7,
81  LINEAR_DIAMETER = 8,
82  RADIAL_DIAMETER = 9
83 };
84 
86 {
87  UNKNOWN = -1,
88 
89  COPPER = 0, // KIND=0
90  POLYGON_CUTOUT = 1, // KIND=1
91  UNKNOWN_2 = 2, // KIND=2
92  UNKNOWN_3 = 3, // KIND=3
93  CAVITY_DEFINITION = 4, // KIND=4
94  BOARD_CUTOUT = 5, // KIND=0 AND ISBOARDCUTOUT=TRUE
95 };
96 
97 enum class ALTIUM_RULE_KIND
98 {
99  UNKNOWN = 0,
100 
101  CLEARANCE = 1,
102  DIFF_PAIR_ROUTINGS = 2,
103  HEIGHT = 3,
104  HOLE_SIZE = 4,
106  WIDTH = 6,
108  PLANE_CLEARANCE = 8,
109  POLYGON_CONNECT = 9,
110 };
111 
113 {
114  UNKNOWN = 0,
115  DIRECT = 1,
116  RELIEF = 2,
117  NONE = 3
118 };
119 
120 enum class ALTIUM_RECORD
121 {
122  ARC = 1,
123  PAD = 2,
124  VIA = 3,
125  TRACK = 4,
126  TEXT = 5,
127  FILL = 6,
128  REGION = 11,
129  MODEL = 12
130 };
131 
133 {
134  UNKNOWN = 0,
135  CIRCLE = 1,
136  RECT = 2,
137  OCTAGONAL = 3
138 };
139 
141 {
142  UNKNOWN = 0,
143  CIRCLE = 1,
144  RECT = 2, // TODO: valid?
145  OCTAGONAL = 3, // TODO: valid?
146  ROUNDRECT = 9
147 };
148 
150 {
151  UNKNOWN = -1,
152  ROUND = 0,
153  SQUARE = 1,
154  SLOT = 2
155 };
156 
157 enum class ALTIUM_PAD_MODE
158 {
159  SIMPLE = 0,
160  TOP_MIDDLE_BOTTOM = 1,
161  FULL_STACK = 2
162 };
163 
164 enum class ALTIUM_PAD_RULE
165 {
166  UNKNOWN = 0,
167  RULE = 1,
168  MANUAL = 2
169 };
170 
172 {
173  UNKNOWN = 0,
174 
175  SOLID = 1,
176  DEGREE_45 = 2,
177  DEGREE_90 = 3,
178  HORIZONTAL = 4,
179  VERTICAL = 5,
180  NONE = 6
181 };
182 
184 {
185  MANUAL = 0, // only relevant for NAMEAUTOPOSITION and COMMENTAUTOPOSITION
186  LEFT_TOP = 1,
187  LEFT_CENTER = 2,
188  LEFT_BOTTOM = 3,
189  CENTER_TOP = 4,
190  CENTER_CENTER = 5,
191  CENTER_BOTTOM = 6,
192  RIGHT_TOP = 7,
193  RIGHT_CENTER = 8,
194  RIGHT_BOTTOM = 9
195 };
196 
198 {
199  UNKNOWN = -1,
200 
201  STROKE = 0,
202  TRUETYPE = 1,
203  BARCODE = 2
204 };
205 
207 {
208  const bool isRound;
209  const int32_t radius;
210  const double startangle;
211  const double endangle;
212  const wxPoint position;
213  const wxPoint center;
214 
215  explicit ALTIUM_VERTICE( const wxPoint& aPosition )
216  : isRound( false ),
217  radius( 0 ),
218  startangle( 0. ),
219  endangle( 0. ),
220  position( aPosition ),
221  center( wxPoint( 0, 0 ) )
222  {
223  }
224 
225  explicit ALTIUM_VERTICE( bool aIsRound, int32_t aRadius, double aStartAngle, double aEndAngle,
226  const wxPoint aPosition, const wxPoint aCenter )
227  : isRound( aIsRound ),
228  radius( aRadius ),
229  startangle( aStartAngle ),
230  endangle( aEndAngle ),
231  position( aPosition ),
232  center( aCenter )
233  {
234  }
235 };
236 
237 enum class ALTIUM_LAYER
238 {
239  UNKNOWN = 0,
240 
241  TOP_LAYER = 1,
242  MID_LAYER_1 = 2,
243  MID_LAYER_2 = 3,
244  MID_LAYER_3 = 4,
245  MID_LAYER_4 = 5,
246  MID_LAYER_5 = 6,
247  MID_LAYER_6 = 7,
248  MID_LAYER_7 = 8,
249  MID_LAYER_8 = 9,
250  MID_LAYER_9 = 10,
251  MID_LAYER_10 = 11,
252  MID_LAYER_11 = 12,
253  MID_LAYER_12 = 13,
254  MID_LAYER_13 = 14,
255  MID_LAYER_14 = 15,
256  MID_LAYER_15 = 16,
257  MID_LAYER_16 = 17,
258  MID_LAYER_17 = 18,
259  MID_LAYER_18 = 19,
260  MID_LAYER_19 = 20,
261  MID_LAYER_20 = 21,
262  MID_LAYER_21 = 22,
263  MID_LAYER_22 = 23,
264  MID_LAYER_23 = 24,
265  MID_LAYER_24 = 25,
266  MID_LAYER_25 = 26,
267  MID_LAYER_26 = 27,
268  MID_LAYER_27 = 28,
269  MID_LAYER_28 = 29,
270  MID_LAYER_29 = 30,
271  MID_LAYER_30 = 31,
272  BOTTOM_LAYER = 32,
273 
274  TOP_OVERLAY = 33,
275  BOTTOM_OVERLAY = 34,
276  TOP_PASTE = 35,
277  BOTTOM_PASTE = 36,
278  TOP_SOLDER = 37,
279  BOTTOM_SOLDER = 38,
280 
281  INTERNAL_PLANE_1 = 39,
282  INTERNAL_PLANE_2 = 40,
283  INTERNAL_PLANE_3 = 41,
284  INTERNAL_PLANE_4 = 42,
285  INTERNAL_PLANE_5 = 43,
286  INTERNAL_PLANE_6 = 44,
287  INTERNAL_PLANE_7 = 45,
288  INTERNAL_PLANE_8 = 46,
289  INTERNAL_PLANE_9 = 47,
290  INTERNAL_PLANE_10 = 48,
291  INTERNAL_PLANE_11 = 49,
292  INTERNAL_PLANE_12 = 50,
293  INTERNAL_PLANE_13 = 51,
294  INTERNAL_PLANE_14 = 52,
295  INTERNAL_PLANE_15 = 53,
296  INTERNAL_PLANE_16 = 54,
297 
298  DRILL_GUIDE = 55,
299  KEEP_OUT_LAYER = 56,
300 
301  MECHANICAL_1 = 57,
302  MECHANICAL_2 = 58,
303  MECHANICAL_3 = 59,
304  MECHANICAL_4 = 60,
305  MECHANICAL_5 = 61,
306  MECHANICAL_6 = 62,
307  MECHANICAL_7 = 63,
308  MECHANICAL_8 = 64,
309  MECHANICAL_9 = 65,
310  MECHANICAL_10 = 66,
311  MECHANICAL_11 = 67,
312  MECHANICAL_12 = 68,
313  MECHANICAL_13 = 69,
314  MECHANICAL_14 = 70,
315  MECHANICAL_15 = 71,
316  MECHANICAL_16 = 72,
317 
318  DRILL_DRAWING = 73,
319  MULTI_LAYER = 74,
320  CONNECTIONS = 75,
321  BACKGROUND = 76,
322  DRC_ERROR_MARKERS = 77,
323  SELECTIONS = 78,
324  VISIBLE_GRID_1 = 79,
325  VISIBLE_GRID_2 = 80,
326  PAD_HOLES = 81,
327  VIA_HOLES = 82,
328 };
329 
330 class ALTIUM_PARSER;
331 
333 {
334  wxString name;
335 
336  size_t nextId;
337  size_t prevId;
338 
339  int32_t copperthick;
340 
344 };
345 
346 struct ABOARD6
347 {
348  wxPoint sheetpos;
349  wxSize sheetsize;
350 
352  std::vector<ABOARD6_LAYER_STACKUP> stackup;
353 
354  std::vector<ALTIUM_VERTICE> board_vertices;
355 
356  explicit ABOARD6( ALTIUM_PARSER& aReader );
357 };
358 
359 struct ACLASS6
360 {
361  wxString name;
362  wxString uniqueid;
363 
365 
366  std::vector<wxString> names;
367 
368  explicit ACLASS6( ALTIUM_PARSER& aReader );
369 };
370 
372 {
374  wxPoint position;
375  double rotation;
376  bool locked;
377  bool nameon;
378  bool commenton;
381  wxString pattern;
384 
387 
388  explicit ACOMPONENT6( ALTIUM_PARSER& aReader );
389 };
390 
392 {
395 
396  wxString textformat;
397  wxString textprefix;
398  wxString textsuffix;
399 
400  int32_t height;
401  double angle;
402 
403  uint32_t linewidth;
404  uint32_t textheight;
405  uint32_t textlinewidth;
406  int32_t textprecision;
407  uint32_t textgap;
408  bool textbold;
410 
411  int32_t arrowsize;
412 
414 
415  wxPoint xy1;
416 
417  std::vector<wxPoint> referencePoint;
418  std::vector<wxPoint> textPoint;
419 
420  explicit ADIMENSION6( ALTIUM_PARSER& aReader );
421 };
422 
423 struct AMODEL
424 {
425  wxString name;
426  wxString id;
428 
430 
431  explicit AMODEL( ALTIUM_PARSER& aReader );
432 };
433 
434 struct ANET6
435 {
436  wxString name;
437 
438  explicit ANET6( ALTIUM_PARSER& aReader );
439 };
440 
441 struct APOLYGON6
442 {
444  uint16_t net;
445  bool locked;
446 
448 
449  int32_t gridsize;
450  int32_t trackwidth;
451  int32_t minprimlength;
453 
454  // Note: Altium pour index is the opposite of KiCad zone priority!
455  int32_t pourindex;
456 
457  std::vector<ALTIUM_VERTICE> vertices;
458 
459  explicit APOLYGON6( ALTIUM_PARSER& aReader );
460 };
461 
462 
463 struct ARULE6
464 {
465  wxString name;
466  int priority;
467 
469 
470  wxString scope1expr;
471  wxString scope2expr;
472 
473  // ALTIUM_RULE_KIND::CLEARANCE
475 
476  // ALTIUM_RULE_KIND::PLANE_CLEARANCE
478 
479  // ALTIUM_RULE_KIND::POLYGON_CONNECT
484 
485  // TODO: implement different types of rules we need to parse
486 
487  explicit ARULE6( ALTIUM_PARSER& aReader );
488 };
489 
490 struct AREGION6
491 {
492  bool is_locked;
494 
496 
498  uint16_t net;
499  uint16_t component;
500  uint16_t subpolyindex;
501  uint16_t holecount;
502 
503  ALTIUM_REGION_KIND kind; // I assume this means if normal or keepout?
504 
505  std::vector<ALTIUM_VERTICE> outline;
506  std::vector<std::vector<ALTIUM_VERTICE>> holes;
507 
508  explicit AREGION6( ALTIUM_PARSER& aReader, bool aExtendedVertices );
509 };
510 
511 struct AARC6
512 {
513  bool is_locked;
516 
518  uint16_t net;
519  uint16_t component;
520  uint16_t subpolyindex;
521 
522  wxPoint center;
523  uint32_t radius;
524  double startangle;
525  double endangle;
526  uint32_t width;
527 
528  explicit AARC6( ALTIUM_PARSER& aReader );
529 };
530 
532 {
533  uint16_t component;
534 
535  wxString modelName;
536  wxString modelId;
538 
541  double rotation;
542  double bodyOpacity;
543 
544  explicit ACOMPONENTBODY6( ALTIUM_PARSER& aReader );
545 };
546 
548 {
550  uint32_t slotsize;
551  double slotrotation;
552 
553  wxSize inner_size[29];
555  wxPoint holeoffset[32];
557  uint8_t cornerradius[32];
558 };
559 
560 struct APAD6
561 {
562  bool is_locked;
567 
568  wxString name;
569 
571  uint16_t net;
572  uint16_t component;
573 
574  wxPoint position;
575  wxSize topsize;
576  wxSize midsize;
577  wxSize botsize;
578  uint32_t holesize;
579 
583 
585 
586  double direction;
587  bool plated;
592  double holerotation;
593 
596 
597  std::unique_ptr<APAD6_SIZE_AND_SHAPE> sizeAndShape;
598 
599  explicit APAD6( ALTIUM_PARSER& aReader );
600 };
601 
602 struct AVIA6
603 {
604  bool is_locked;
609 
610  uint16_t net;
611 
612  wxPoint position;
613  uint32_t diameter;
614  uint32_t holesize;
615 
619 
620  explicit AVIA6( ALTIUM_PARSER& aReader );
621 };
622 
623 struct ATRACK6
624 {
625  bool is_locked;
628 
630  uint16_t net;
631  uint16_t component;
632  uint16_t subpolyindex;
633 
634  wxPoint start;
635  wxPoint end;
636  uint32_t width;
637 
638  explicit ATRACK6( ALTIUM_PARSER& aReader );
639 };
640 
641 struct ATEXT6
642 {
644  uint16_t component;
645 
646  wxPoint position;
647  uint32_t height;
648  double rotation;
649  uint32_t strokewidth;
651 
652  bool isBold;
653  bool isItalic;
656 
657  bool isComment;
659 
661 
662  wxString text;
663 
664  explicit ATEXT6( ALTIUM_PARSER& aReader, std::map<uint32_t, wxString>& aStringTable );
665 };
666 
667 struct AFILL6
668 {
669  bool is_locked;
671 
673  uint16_t component;
674  uint16_t net;
675 
676  wxPoint pos1;
677  wxPoint pos2;
678  double rotation;
679 
680  explicit AFILL6( ALTIUM_PARSER& aReader );
681 };
682 
683 
684 #endif //ALTIUM_PARSER_PCB_H
AREGION6(ALTIUM_PARSER &aReader, bool aExtendedVertices)
ADIMENSION6(ALTIUM_PARSER &aReader)
uint32_t textlinewidth
uint32_t linewidth
ALTIUM_LAYER tolayer
FP_3DMODEL::VECTOR3D modelPosition
int32_t soldermaskexpansionmanual
ALTIUM_RULE_KIND kind
double rotation
uint32_t holesize
uint32_t width
int planeclearanceClearance
ATEXT6(ALTIUM_PARSER &aReader, std::map< uint32_t, wxString > &aStringTable)
wxString name
bool isDesignator
bool is_locked
ALTIUM_TEXT_POSITION nameautoposition
ALTIUM_PAD_SHAPE topshape
wxPoint pos1
ALTIUM_LAYER layer
ALTIUM_DIMENSION_KIND
AMODEL(ALTIUM_PARSER &aReader)
wxPoint start
wxSize topsize
ALTIUM_LAYER layer
ALTIUM_DIMENSION_KIND kind
ALTIUM_VERTICE(const wxPoint &aPosition)
ARULE6(ALTIUM_PARSER &aReader)
ALTIUM_REGION_KIND kind
wxPoint position
double startangle
uint16_t component
bool is_test_fab_bottom
ALTIUM_TEXT_TYPE
ALTIUM_POLYGON_HATCHSTYLE
int32_t polygonconnectAirgapwidth
wxPoint center
ALTIUM_LAYER layer
std::vector< std::vector< ALTIUM_VERTICE > > holes
wxString sourcedesignator
const uint16_t ALTIUM_POLYGON_NONE
ALTIUM_LAYER layer
ALTIUM_RECORD
ALTIUM_LAYER layer_end
ALTIUM_PAD_SHAPE
ALTIUM_PAD_RULE soldermaskexpansionmode
ALTIUM_PAD_HOLE_SHAPE
ALTIUM_REGION_KIND
ALTIUM_LAYER layer
uint16_t net
wxString sourcefootprintlibrary
AVIA6(ALTIUM_PARSER &aReader)
uint16_t holecount
FP_3DMODEL::VECTOR3D rotation
const double startangle
wxString name
wxString sourcelibreference
wxString text
wxSize sheetsize
wxString scope2expr
bool is_tent_bottom
bool is_polygonoutline
uint32_t height
ALTIUM_PAD_SHAPE_ALT
ALTIUM_CONNECT_STYLE polygonconnectStyle
ALTIUM_PAD_SHAPE_ALT alt_shape[32]
std::vector< wxString > names
int32_t trackwidth
std::vector< wxPoint > textPoint
wxString textformat
wxString sourcecomponentlibrary
uint16_t subpolyindex
uint16_t net
ALTIUM_CLASS_KIND
APAD6(ALTIUM_PARSER &aReader)
ALTIUM_VERTICE(bool aIsRound, int32_t aRadius, double aStartAngle, double aEndAngle, const wxPoint aPosition, const wxPoint aCenter)
wxSize botsize
ALTIUM_PAD_RULE pastemaskexpansionmode
wxPoint position
uint16_t subpolyindex
double direction
ALTIUM_RULE_KIND
wxString textsuffix
double endangle
wxString id
const wxPoint position
ALTIUM_CLASS_KIND kind
ALTIUM_LAYER layer
const uint16_t ALTIUM_NET_UNCONNECTED
wxSize midsize
ALTIUM_PAD_MODE
wxString name
uint16_t component
ALTIUM_PAD_SHAPE inner_shape[29]
uint32_t holesize
bool is_test_fab_top
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:32
ACOMPONENTBODY6(ALTIUM_PARSER &aReader)
wxPoint sheetpos
wxString textprefix
ABOARD6(ALTIUM_PARSER &aReader)
const int32_t radius
uint16_t net
bool is_test_fab_bottom
bool is_keepout
const wxPoint center
FP_3DMODEL::VECTOR3D modelRotation
ALTIUM_UNIT
bool is_locked
double rotation
bool is_polygonoutline
AFILL6(ALTIUM_PARSER &aReader)
bool is_tent_bottom
uint16_t subpolyindex
ACLASS6(ALTIUM_PARSER &aReader)
wxString uniqueid
ALTIUM_PAD_SHAPE botshape
std::vector< ALTIUM_VERTICE > vertices
ANET6(ALTIUM_PARSER &aReader)
uint32_t width
ALTIUM_TEXT_POSITION textposition
ALTIUM_LAYER layer
uint16_t net
ALTIUM_LAYER layer_start
bool is_test_fab_top
ALTIUM_CONNECT_STYLE
ALTIUM_PAD_HOLE_SHAPE holeshape
bool is_tent_top
ATRACK6(ALTIUM_PARSER &aReader)
uint32_t radius
wxPoint position
std::vector< ALTIUM_VERTICE > outline
ALTIUM_PAD_MODE viamode
int32_t pastemaskexpansionmanual
wxString name
APOLYGON6(ALTIUM_PARSER &aReader)
ALTIUM_TEXT_POSITION
uint16_t net
uint16_t component
ALTIUM_LAYER
ALTIUM_PAD_MODE padmode
ALTIUM_LAYER layer
std::unique_ptr< APAD6_SIZE_AND_SHAPE > sizeAndShape
const double endangle
uint16_t component
std::vector< ALTIUM_VERTICE > board_vertices
ALTIUM_UNIT textunit
ALTIUM_LAYER layer
ALTIUM_TEXT_POSITION commentautoposition
uint16_t component
ALTIUM_PAD_SHAPE midshape
std::vector< wxPoint > referencePoint
Definition: pad.h:57
Text placement is manually set by the user.
std::vector< ABOARD6_LAYER_STACKUP > stackup
uint32_t strokewidth
const uint16_t ALTIUM_COMPONENT_NONE
bool is_tent_top
int32_t minprimlength
int32_t gridsize
ACOMPONENT6(ALTIUM_PARSER &aReader)
uint32_t textheight
ALTIUM_PAD_RULE
ALTIUM_POLYGON_HATCHSTYLE hatchstyle
uint16_t component
ALTIUM_TEXT_TYPE fonttype
int32_t textprecision
wxPoint pos2
uint32_t diameter
AARC6(ALTIUM_PARSER &aReader)
double holerotation
bool is_locked
ALTIUM_LAYER fromlayer
wxString name
uint16_t net
wxString scope1expr
int32_t polygonconnectReliefconductorwidth
int32_t pourindex
int polygonconnectReliefentries