KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef ALTIUM_PARSER_PCB_H
22#define ALTIUM_PARSER_PCB_H
23
24#include <cstdint>
25#include <cstring>
26#include <limits>
27#include <map>
28#include <memory>
29#include <set>
30#include <vector>
31
32#include <wx/gdicmn.h>
33
34#include <math/vector2d.h>
35#include <math/vector3.h>
36
37
38// tthis constant specifies an unconnected net
39const uint16_t ALTIUM_NET_UNCONNECTED = std::numeric_limits<uint16_t>::max();
40
41// this constant specifies a item which is not inside an component
42const uint16_t ALTIUM_COMPONENT_NONE = std::numeric_limits<uint16_t>::max();
43
44// this constant specifies a item which does not define a polygon
45const uint16_t ALTIUM_POLYGON_NONE = std::numeric_limits<uint16_t>::max();
46
47// 65534 seems to be belonging to board outline
48const uint16_t ALTIUM_POLYGON_BOARD = std::numeric_limits<uint16_t>::max() - 1;
49
50
51enum class ALTIUM_UNIT
52{
54
55 INCH = 1,
56 MILS = 2,
57 MM = 3,
58 CM = 4
59};
60
74
90
92{
93 UNKNOWN = -1,
94
95 COPPER = 0, // KIND=0
96 POLYGON_CUTOUT = 1, // KIND=1
97 DASHED_OUTLINE = 2, // KIND=2
98 UNKNOWN_3 = 3, // KIND=3
99 CAVITY_DEFINITION = 4, // KIND=4
100 BOARD_CUTOUT = 5, // KIND=0 AND ISBOARDCUTOUT=TRUE
101};
102
119
121{
126};
127
129{
131
132 ARC = 1,
133 PAD = 2,
134 VIA = 3,
135 TRACK = 4,
136 TEXT = 5,
137 FILL = 6,
138 REGION = 11,
139 MODEL = 12
140};
141
143{
146 RECT = 2,
148};
149
151{
154 RECT = 2, // TODO: valid?
155 OCTAGONAL = 3, // TODO: valid?
157};
158
160{
162 ROUND = 0,
165};
166
173
174enum class ALTIUM_MODE
175{
177 NONE = 0, // TODO: correct ID?
178 RULE = 1,
180};
181
193
195{
196 MANUAL = 0, // only relevant for NAMEAUTOPOSITION and COMMENTAUTOPOSITION
206};
207
209{
211
215};
216
218{
221};
222
224{
225 const bool isRound;
226 const int32_t radius;
227 const double startangle;
228 const double endangle;
231
232 explicit ALTIUM_VERTICE( const VECTOR2I& aPosition )
233 : isRound( false ),
234 radius( 0 ),
235 startangle( 0. ),
236 endangle( 0. ),
237 position( aPosition ),
238 center( VECTOR2I( 0, 0 ) )
239 {
240 }
241
242 explicit ALTIUM_VERTICE( bool aIsRound, int32_t aRadius, double aStartAngle, double aEndAngle,
243 const VECTOR2I aPosition, const VECTOR2I aCenter )
244 : isRound( aIsRound ),
245 radius( aRadius ),
246 startangle( aStartAngle ),
247 endangle( aEndAngle ),
248 position( aPosition ),
249 center( aCenter )
250 {
251 }
252};
253
254enum class ALTIUM_LAYER : uint32_t
255{
257
290
297
314
317
334
345
346 // V7 format layers
347 V7_START = 0x01000000,
348
349 V7_COPPER_BASE = 0x01000000,
352
353 V7_MECHANICAL_BASE = 0x01020000,
357
358 // V8 format layers
359 V8_OTHER_BASE = 0x01030000,
381};
382
383// Specifies values from LayerKindMapping
385{
387
390
392 BOARD = 0x04,
393
396
399
402
405
408
412
413 FAB_NOTES = 0x12,
414
417
420
421 VALUE_TOP = 0x17,
422 VALUE_BOT = 0x18,
423
424 V_CUT = 0x19,
425
428
430 SHEET = 0x1D,
432};
433
435
442
458
460{
461 uint32_t layerId = 0;
462 wxString name;
463
464 size_t nextId;
465 size_t prevId;
466
467 int32_t copperthick;
468
473
474 bool mechenabled = false;
476
477 explicit ABOARD6_LAYER_STACKUP( const std::map<wxString, wxString>& aProps, const wxString& aPrefix,
478 uint32_t aLayerIdFallback );
479};
480
482{
484 std::vector<ABOARD6_LAYER_STACKUP> stackup;
485 std::set<wxString> layerNames;
486
487 explicit ALIBRARY( ALTIUM_BINARY_PARSER& aReader );
488};
489
491{
493 wxSize sheetsize;
494
496 std::vector<ABOARD6_LAYER_STACKUP> stackup;
497 std::set<wxString> layerNames;
498
499 std::vector<ALTIUM_VERTICE> board_vertices;
500
501 explicit ABOARD6( ALTIUM_BINARY_PARSER& aReader );
502};
503
505{
506 wxString name;
507 wxString uniqueid;
508
510
511 std::vector<wxString> names;
512
513 explicit ACLASS6( ALTIUM_BINARY_PARSER& aReader );
514};
515
537
571
572struct AMODEL
573{
574 wxString name;
575 wxString id;
577
579 double z_offset;
580 int32_t checksum;
581
582 explicit AMODEL( ALTIUM_BINARY_PARSER& aReader );
583};
584
585struct ANET6
586{
587 wxString name;
588
589 explicit ANET6( ALTIUM_BINARY_PARSER& aReader );
590};
591
593{
597 uint16_t net;
598 bool locked;
599
601
602 int32_t gridsize;
603 int32_t trackwidth;
606
607 // Note: Altium pour index is the opposite of KiCad zone priority!
608 int32_t pourindex;
609
610 std::vector<ALTIUM_VERTICE> vertices;
611
612 explicit APOLYGON6( ALTIUM_BINARY_PARSER& aReader );
613};
614
615
616struct ARULE6
617{
618 wxString name;
619 int priority = 0;
620
622
623 wxString scope1expr;
624 wxString scope2expr;
625
626 // ALTIUM_RULE_KIND::CLEARANCE
627 // ALTIUM_RULE_KIND::HOLE_TO_HOLE_CLEARANCE
629
630 // ALTIUM_RULE_KIND::WIDTH
631 // ALTIUM_RULE_KIND::HOLE_SIZE
632 int minLimit = 0;
633 int maxLimit = 0;
634
635 // ALTIUM_RULE_KIND::WIDTH
637
638 // ALTIUM_RULE_KIND::ROUTING_VIAS
639 int width = 0;
640 int minWidth = 0;
641 int maxWidth = 0;
642 int holeWidth = 0;
645
646 // ALTIUM_RULE_KIND::PLANE_CLEARANCE
648
649 // ALTIUM_RULE_KIND::SOLDER_MASK_EXPANSION
651
652 // ALTIUM_RULE_KIND::PASTE_MASK_EXPANSION
654
655 // ALTIUM_RULE_KIND::POLYGON_CONNECT
660
661 // TODO: implement different types of rules we need to parse
662
663 ARULE6() = default;
664 explicit ARULE6( ALTIUM_BINARY_PARSER& aReader );
665};
666
668{
672
674
678 uint16_t net;
679 uint16_t component;
680 uint16_t polygon;
681 uint16_t subpolyindex;
683 uint16_t holecount;
684
685 ALTIUM_REGION_KIND kind; // I assume this means if normal or keepout?
686
687 std::vector<ALTIUM_VERTICE> outline;
688 std::vector<std::vector<ALTIUM_VERTICE>> holes;
689
690 explicit AREGION6( ALTIUM_BINARY_PARSER& aReader, bool aExtendedVertices );
691};
692
717
719{
720 uint16_t component = 0;
721
722 wxString body_name;
723 int kind = 0;
725 int unionindex = 0;
727 bool is_shape_based = false;
733 double body_opacity_3d = 0.0;
734 wxString identifier;
735 wxString texture;
741
742 wxString modelId;
744 bool modelIsEmbedded = false;
745 wxString modelName;
746 int modelType = 0;
747 int modelSource = 0;
749
752 double rotation = 0.0;
753
754 explicit ACOMPONENTBODY6( ALTIUM_BINARY_PARSER& aReader );
755};
756
769
816
817struct AVIA6
818{
819 bool is_locked = false;
820 bool is_tent_top = false;
821 bool is_tent_bottom = false;
822 bool is_test_fab_top = false;
823 bool is_test_fab_bottom = false;
824
825 uint16_t net = 0;
826
828 uint32_t pos_tolerance = 2147483640; // 2147483640 is N/A
829 uint32_t neg_tolerance = 2147483640; // 2147483640 is N/A
830 uint32_t diameter = 0;
831 uint32_t holesize = 0;
832
836
841
842 // When true, the manual solder mask expansion is measured outward from the hole edge rather
843 // than from the via land (copper) edge. Altium "Solder Mask Expansion From The Hole Edge".
845
849
850 // In PAD_MODE::SIMPLE, this is the same as the diameter
851 // In PAD_MODE::TOP_MIDDLE_BOTTOM, layer 0 is top, layer 1 is middle, layer 31 is bottom
852 // In PAD_MODE::FULL_STACK, layers correspond to the layer number
853 uint32_t diameter_by_layer[32]{ 0 };
854
855 explicit AVIA6( ALTIUM_BINARY_PARSER& aReader );
856};
857
880
881// Interactive length-tuning meander, stored in the SmartUnions stream and referenced by
882// copper primitives through their union index. Altium commits the tuned copper as ordinary
883// tracks and arcs, keeping the parametric meander definition here.
885{
886 int unionindex = 0;
887 bool is_tuning = false;
888 bool is_diffpair = false;
889
890 int style = 0;
891 int32_t gap = 0;
892 int32_t amplitude = 0;
893 int32_t minamplitude = 0;
894 double mitterradiusratio = 0.0;
895 bool singleside = false;
896
897 explicit ASMARTUNION6( ALTIUM_BINARY_PARSER& aReader );
898};
899
900struct ATEXT6
901{
903 {
907 };
908
909
913 uint16_t component = 0;
914
916 uint32_t height = 0;
917 double rotation = 0.0;
918 uint32_t strokewidth = 0;
920
921 bool isBold = false;
922 bool isItalic = false;
923 bool isMirrored = false;
924 bool isInverted = false;
925 bool isInvertedRect = false;
926 bool isFrame = false;
927 bool isOffsetBorder = false;
929
931 uint32_t textbox_rect_width = 0;
933 uint32_t text_offset_width = 0;
934
935 // Justification only applies when there is a text box size specified
936 // Then, the text is justified within the box
938
939 uint32_t widestring_index = 0;
940
941 bool isComment = false;
942 bool isDesignator = false;
943
945 wxString fontname;
947
948 // Barcode specific parameters
951 bool barcode_inverted = false;
952 wxString barcode_name;
953 bool barcode_show_text = false;
954
955 wxString text;
956
957 explicit ATEXT6( ALTIUM_BINARY_PARSER& aReader, std::map<uint32_t, wxString>& aStringTable );
958};
959
978
979
984bool altiumScopeExprMatchesPolygon( const wxString& aExpr );
985
986
996const ARULE6* selectAltiumPolygonRule( const std::vector<ARULE6>& aRulesByPriorityAsc );
997
998
1014bool altiumViaSideIsTented( bool aTentFlag, bool aManual, bool aFromHole, uint32_t aHoleSize,
1015 int32_t aMaskExpansion, int aLandDiameter );
1016
1017
1018#endif //ALTIUM_PARSER_PCB_H
bool altiumScopeExprMatchesPolygon(const wxString &aExpr)
Return true if an Altium rule scope expression targets polygon pour primitives (matches InPolygon,...
ALTIUM_REGION_KIND
ALTIUM_PAD_SHAPE_ALT
ALTIUM_TEXT_POSITION
ALTIUM_CONNECT_STYLE
ALTIUM_MECHKIND
ALTIUM_POLYGON_HATCHSTYLE
ALTIUM_PAD_MODE
ALTIUM_UNIT
ALTIUM_TEXT_TYPE
ALTIUM_RULE_KIND
ALTIUM_PAD_SHAPE
ALTIUM_BARCODE_TYPE
ALTIUM_DIMENSION_KIND
const ARULE6 * selectAltiumPolygonRule(const std::vector< ARULE6 > &aRulesByPriorityAsc)
Select the highest Altium-priority rule whose scope references polygons.
ALTIUM_PAD_HOLE_SHAPE
const uint16_t ALTIUM_NET_UNCONNECTED
ALTIUM_CLASS_KIND
const uint16_t ALTIUM_POLYGON_NONE
bool altiumViaSideIsTented(bool aTentFlag, bool aManual, bool aFromHole, uint32_t aHoleSize, int32_t aMaskExpansion, int aLandDiameter)
Decide whether one side of an Altium via should be tented when imported into KiCad.
AEXTENDED_PRIMITIVE_INFORMATION_TYPE
const uint16_t ALTIUM_POLYGON_BOARD
ALTIUM_RECORD
const int ALTIUM_COMPONENT_NONE
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
Represent basic circle geometry with utility geometry functions.
Definition circle.h:33
Definition pad.h:61
A round rectangle shape, based on a rectangle and a radius.
Definition roundrect.h:32
@ SOLID
Definition eda_shape.h:73
@ NONE
Definition eda_shape.h:72
@ DIRECT
Unconstrained point-to-point.
@ MANUAL
Text placement is manually set by the user.
#define MASK(x)
@ VIA
Normal via.
@ INCH
Definition rs274x.cpp:58
double startangle
uint16_t component
uint32_t unionindex
uint32_t width
ALTIUM_LAYER layer
AARC6(ALTIUM_BINARY_PARSER &aReader)
uint8_t keepoutrestrictions
uint16_t polygon
VECTOR2I center
uint32_t radius
uint16_t net
ALTIUM_LAYER layer_v6
ALTIUM_LAYER layer_v7
bool is_polygonoutline
double endangle
uint16_t subpolyindex
ABOARD6_LAYER_STACKUP(const std::map< wxString, wxString > &aProps, const wxString &aPrefix, uint32_t aLayerIdFallback)
VECTOR2I sheetpos
std::set< wxString > layerNames
ABOARD6(ALTIUM_BINARY_PARSER &aReader)
std::vector< ABOARD6_LAYER_STACKUP > stackup
std::vector< ALTIUM_VERTICE > board_vertices
wxString uniqueid
std::vector< wxString > names
ALTIUM_CLASS_KIND kind
wxString name
ACLASS6(ALTIUM_BINARY_PARSER &aReader)
wxString sourceHierachicalPath
ALTIUM_TEXT_POSITION commentautoposition
ALTIUM_TEXT_POSITION nameautoposition
ACOMPONENT6(ALTIUM_BINARY_PARSER &aReader)
wxString sourcefootprintlibrary
ALTIUM_LAYER layer
wxString sourcelibreference
wxString sourcedesignator
wxString sourceUniqueID
wxString sourcecomponentlibrary
ACOMPONENTBODY6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_UNIT textunit
uint32_t textlinewidth
ALTIUM_LAYER layer
ALTIUM_LAYER layer_v6
std::vector< VECTOR2I > textPoint
ALTIUM_DIMENSION_KIND kind
ALTIUM_LAYER layer_v7
ADIMENSION6(ALTIUM_BINARY_PARSER &aReader)
std::vector< VECTOR2I > referencePoint
AEXTENDED_PRIMITIVE_INFORMATION_TYPE type
AEXTENDED_PRIMITIVE_INFORMATION(ALTIUM_BINARY_PARSER &aReader)
VECTOR2I pos2
ALTIUM_LAYER layer
uint16_t net
VECTOR2I pos1
double rotation
uint8_t keepoutrestrictions
AFILL6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_LAYER layer_v6
uint16_t component
ALTIUM_LAYER layer_v7
std::set< wxString > layerNames
std::vector< ABOARD6_LAYER_STACKUP > stackup
ALIBRARY(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_VERTICE(const VECTOR2I &aPosition)
const int32_t radius
const VECTOR2I center
const VECTOR2I position
const double endangle
const double startangle
ALTIUM_VERTICE(bool aIsRound, int32_t aRadius, double aStartAngle, double aEndAngle, const VECTOR2I aPosition, const VECTOR2I aCenter)
double z_offset
wxString id
int32_t checksum
wxString name
VECTOR3D rotation
AMODEL(ALTIUM_BINARY_PARSER &aReader)
ANET6(ALTIUM_BINARY_PARSER &aReader)
wxString name
ALTIUM_PAD_SHAPE inner_shape[29]
ALTIUM_PAD_HOLE_SHAPE holeshape
ALTIUM_PAD_SHAPE_ALT alt_shape[32]
double holerotation
int32_t soldermaskexpansionmanual
uint16_t net
ALTIUM_LAYER layer
APAD6(ALTIUM_BINARY_PARSER &aReader)
std::unique_ptr< APAD6_SIZE_AND_SHAPE > sizeAndShape
ALTIUM_LAYER layer_v7
ALTIUM_LAYER tolayer
ALTIUM_PAD_SHAPE topshape
ALTIUM_LAYER layer_v6
ALTIUM_PAD_MODE padmode
ALTIUM_MODE pastemaskexpansionmode
uint32_t holesize
double direction
ALTIUM_MODE soldermaskexpansionmode
wxString name
bool is_test_fab_bottom
int32_t pad_to_die_delay
bool is_tent_bottom
VECTOR2I botsize
ALTIUM_PAD_SHAPE botshape
uint16_t component
VECTOR2I midsize
ALTIUM_PAD_SHAPE midshape
int32_t pastemaskexpansionmanual
ALTIUM_LAYER fromlayer
VECTOR2I position
VECTOR2I topsize
bool is_test_fab_top
int32_t pad_to_die_length
ALTIUM_LAYER layer_v6
int32_t minprimlength
std::vector< ALTIUM_VERTICE > vertices
APOLYGON6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_LAYER layer_v7
ALTIUM_POLYGON_HATCHSTYLE hatchstyle
ALTIUM_LAYER layer
uint8_t keepoutrestrictions
ALTIUM_LAYER layer
AREGION6(ALTIUM_BINARY_PARSER &aReader, bool aExtendedVertices)
ALTIUM_LAYER layer_v7
uint16_t holecount
ALTIUM_LAYER layer_v6
std::vector< ALTIUM_VERTICE > outline
uint16_t subpolyindex
std::vector< std::vector< ALTIUM_VERTICE > > holes
uint16_t component
uint16_t polygon
ALTIUM_REGION_KIND kind
ALTIUM_RULE_KIND kind
ALTIUM_CONNECT_STYLE polygonconnectStyle
wxString scope1expr
wxString name
int planeclearanceClearance
int32_t polygonconnectReliefconductorwidth
int pastemaskExpansion
ARULE6()=default
wxString scope2expr
int soldermaskExpansion
int32_t polygonconnectAirgapwidth
int polygonconnectReliefentries
ASMARTUNION6(ALTIUM_BINARY_PARSER &aReader)
uint32_t text_offset_width
VECTOR2I barcode_margin
uint32_t textbox_rect_height
uint16_t component
bool barcode_show_text
ALTIUM_LAYER layer_v6
ALTIUM_TEXT_POSITION textbox_rect_justification
bool isInvertedRect
wxString text
uint32_t widestring_index
uint32_t textbox_rect_width
double rotation
uint32_t margin_border_width
uint32_t height
wxString fontname
bool isJustificationValid
ALTIUM_BARCODE_TYPE barcode_type
ALTIUM_LAYER layer
VECTOR2I position
ALTIUM_LAYER layer_v7
ALTIUM_TEXT_TYPE fonttype
STROKE_FONT_TYPE strokefonttype
wxString barcode_fontname
bool isOffsetBorder
ATEXT6(ALTIUM_BINARY_PARSER &aReader, std::map< uint32_t, wxString > &aStringTable)
bool barcode_inverted
wxString barcode_name
uint32_t strokewidth
ALTIUM_LAYER layer_v6
uint32_t unionindex
ATRACK6(ALTIUM_BINARY_PARSER &aReader)
uint32_t width
bool is_polygonoutline
ALTIUM_LAYER layer_v7
uint16_t polygon
uint16_t subpolyindex
uint8_t keepoutrestrictions
VECTOR2I start
ALTIUM_LAYER layer
uint16_t component
bool soldermask_expansion_linked
uint32_t thermal_relief_conductorcount
uint32_t diameter
uint32_t neg_tolerance
uint16_t net
VECTOR2I position
int32_t thermal_relief_airgap
bool is_test_fab_top
bool soldermask_expansion_from_hole
int32_t soldermask_expansion_front
uint32_t pos_tolerance
bool is_tent_bottom
bool is_test_fab_bottom
bool soldermask_expansion_manual
ALTIUM_PAD_MODE viamode
AVIA6(ALTIUM_BINARY_PARSER &aReader)
uint32_t thermal_relief_conductorwidth
int32_t soldermask_expansion_back
uint32_t diameter_by_layer[32]
ALTIUM_LAYER layer_start
ALTIUM_LAYER layer_end
uint32_t holesize
static const long long MM
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR3< double > VECTOR3D
Definition vector3.h:230