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