KiCad PCB EDA Suite
altium_parser_pcb.cpp File Reference
#include <map>
#include <unordered_map>
#include <ki_exception.h>
#include <math/util.h>
#include "altium_parser_pcb.h"
#include "plugins/altium/altium_parser.h"

Go to the source code of this file.

Functions

ALTIUM_LAYER altium_layer_from_name (const wxString &aName)
 
void altium_parse_polygons (std::map< wxString, wxString > &aProperties, std::vector< ALTIUM_VERTICE > &aVertices)
 

Function Documentation

◆ altium_layer_from_name()

ALTIUM_LAYER altium_layer_from_name ( const wxString &  aName)

Definition at line 34 of file altium_parser_pcb.cpp.

35 {
36  static const std::unordered_map<std::string, ALTIUM_LAYER> hash_map = {
37  { "TOP", ALTIUM_LAYER::TOP_LAYER },
38  { "MID1", ALTIUM_LAYER::MID_LAYER_1 },
39  { "MID2", ALTIUM_LAYER::MID_LAYER_2 },
40  { "MID3", ALTIUM_LAYER::MID_LAYER_3 },
41  { "MID4", ALTIUM_LAYER::MID_LAYER_4 },
42  { "MID5", ALTIUM_LAYER::MID_LAYER_5 },
43  { "MID6", ALTIUM_LAYER::MID_LAYER_6 },
44  { "MID7", ALTIUM_LAYER::MID_LAYER_7 },
45  { "MID8", ALTIUM_LAYER::MID_LAYER_8 },
46  { "MID9", ALTIUM_LAYER::MID_LAYER_9 },
47  { "MID10", ALTIUM_LAYER::MID_LAYER_10 },
48  { "MID11", ALTIUM_LAYER::MID_LAYER_11 },
49  { "MID12", ALTIUM_LAYER::MID_LAYER_12 },
50  { "MID13", ALTIUM_LAYER::MID_LAYER_13 },
51  { "MID14", ALTIUM_LAYER::MID_LAYER_14 },
52  { "MID15", ALTIUM_LAYER::MID_LAYER_15 },
53  { "MID16", ALTIUM_LAYER::MID_LAYER_16 },
54  { "MID17", ALTIUM_LAYER::MID_LAYER_17 },
55  { "MID18", ALTIUM_LAYER::MID_LAYER_18 },
56  { "MID19", ALTIUM_LAYER::MID_LAYER_19 },
57  { "MID20", ALTIUM_LAYER::MID_LAYER_20 },
58  { "MID21", ALTIUM_LAYER::MID_LAYER_21 },
59  { "MID22", ALTIUM_LAYER::MID_LAYER_22 },
60  { "MID23", ALTIUM_LAYER::MID_LAYER_23 },
61  { "MID24", ALTIUM_LAYER::MID_LAYER_24 },
62  { "MID25", ALTIUM_LAYER::MID_LAYER_25 },
63  { "MID26", ALTIUM_LAYER::MID_LAYER_26 },
64  { "MID27", ALTIUM_LAYER::MID_LAYER_27 },
65  { "MID28", ALTIUM_LAYER::MID_LAYER_28 },
66  { "MID29", ALTIUM_LAYER::MID_LAYER_29 },
67  { "MID30", ALTIUM_LAYER::MID_LAYER_30 },
68  { "BOTTOM", ALTIUM_LAYER::BOTTOM_LAYER },
69 
70  { "TOPOVERLAY", ALTIUM_LAYER::TOP_OVERLAY },
71  { "BOTTOMOVERLAY", ALTIUM_LAYER::BOTTOM_OVERLAY },
72  { "TOPPASTE", ALTIUM_LAYER::TOP_PASTE },
73  { "BOTTOMPASTE", ALTIUM_LAYER::BOTTOM_PASTE },
74  { "TOPSOLDER", ALTIUM_LAYER::TOP_SOLDER },
75  { "BOTTOMSOLDER", ALTIUM_LAYER::BOTTOM_SOLDER },
76 
77  { "PLANE1", ALTIUM_LAYER::INTERNAL_PLANE_1 },
78  { "PLANE2", ALTIUM_LAYER::INTERNAL_PLANE_2 },
79  { "PLANE3", ALTIUM_LAYER::INTERNAL_PLANE_3 },
80  { "PLANE4", ALTIUM_LAYER::INTERNAL_PLANE_4 },
81  { "PLANE5", ALTIUM_LAYER::INTERNAL_PLANE_5 },
82  { "PLANE6", ALTIUM_LAYER::INTERNAL_PLANE_6 },
83  { "PLANE7", ALTIUM_LAYER::INTERNAL_PLANE_7 },
84  { "PLANE8", ALTIUM_LAYER::INTERNAL_PLANE_8 },
85  { "PLANE9", ALTIUM_LAYER::INTERNAL_PLANE_9 },
86  { "PLANE10", ALTIUM_LAYER::INTERNAL_PLANE_10 },
87  { "PLANE11", ALTIUM_LAYER::INTERNAL_PLANE_11 },
88  { "PLANE12", ALTIUM_LAYER::INTERNAL_PLANE_12 },
89  { "PLANE13", ALTIUM_LAYER::INTERNAL_PLANE_13 },
90  { "PLANE14", ALTIUM_LAYER::INTERNAL_PLANE_14 },
91  { "PLANE15", ALTIUM_LAYER::INTERNAL_PLANE_15 },
92  { "PLANE16", ALTIUM_LAYER::INTERNAL_PLANE_16 },
93 
94  { "DRILLGUIDE", ALTIUM_LAYER::DRILL_GUIDE },
95  { "KEEPOUT", ALTIUM_LAYER::KEEP_OUT_LAYER },
96 
97  { "MECHANICAL1", ALTIUM_LAYER::MECHANICAL_1 },
98  { "MECHANICAL2", ALTIUM_LAYER::MECHANICAL_2 },
99  { "MECHANICAL3", ALTIUM_LAYER::MECHANICAL_3 },
100  { "MECHANICAL4", ALTIUM_LAYER::MECHANICAL_4 },
101  { "MECHANICAL5", ALTIUM_LAYER::MECHANICAL_5 },
102  { "MECHANICAL6", ALTIUM_LAYER::MECHANICAL_6 },
103  { "MECHANICAL7", ALTIUM_LAYER::MECHANICAL_7 },
104  { "MECHANICAL8", ALTIUM_LAYER::MECHANICAL_8 },
105  { "MECHANICAL9", ALTIUM_LAYER::MECHANICAL_9 },
106  { "MECHANICAL10", ALTIUM_LAYER::MECHANICAL_10 },
107  { "MECHANICAL11", ALTIUM_LAYER::MECHANICAL_11 },
108  { "MECHANICAL12", ALTIUM_LAYER::MECHANICAL_12 },
109  { "MECHANICAL13", ALTIUM_LAYER::MECHANICAL_13 },
110  { "MECHANICAL14", ALTIUM_LAYER::MECHANICAL_14 },
111  { "MECHANICAL15", ALTIUM_LAYER::MECHANICAL_15 },
112  { "MECHANICAL16", ALTIUM_LAYER::MECHANICAL_16 },
113 
114  { "DRILLDRAWING", ALTIUM_LAYER::DRILL_DRAWING },
115  { "MULTILAYER", ALTIUM_LAYER::MULTI_LAYER },
116 
117  // FIXME: the following mapping is just a guess
118  { "CONNECTIONS", ALTIUM_LAYER::CONNECTIONS },
119  { "BACKGROUND", ALTIUM_LAYER::BACKGROUND },
120  { "DRCERRORMARKERS", ALTIUM_LAYER::DRC_ERROR_MARKERS },
121  { "SELECTIONS", ALTIUM_LAYER::SELECTIONS },
122  { "VISIBLEGRID1", ALTIUM_LAYER::VISIBLE_GRID_1 },
123  { "VISIBLEGRID2", ALTIUM_LAYER::VISIBLE_GRID_2 },
124  { "PADHOLES", ALTIUM_LAYER::PAD_HOLES },
125  { "VIAHOLES", ALTIUM_LAYER::VIA_HOLES },
126  };
127 
128  auto it = hash_map.find( std::string( aName.c_str() ) );
129  if( it == hash_map.end() )
130  {
131  wxLogError( wxString::Format(
132  "Unknown mapping of the Altium layer '%s'. Please report as issue.", aName ) );
133  return ALTIUM_LAYER::UNKNOWN;
134  }
135  else
136  {
137  return it->second;
138  }
139 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201

References BACKGROUND, BOTTOM_LAYER, BOTTOM_OVERLAY, BOTTOM_PASTE, BOTTOM_SOLDER, CONNECTIONS, DRC_ERROR_MARKERS, DRILL_DRAWING, DRILL_GUIDE, Format(), INTERNAL_PLANE_1, INTERNAL_PLANE_10, INTERNAL_PLANE_11, INTERNAL_PLANE_12, INTERNAL_PLANE_13, INTERNAL_PLANE_14, INTERNAL_PLANE_15, INTERNAL_PLANE_16, INTERNAL_PLANE_2, INTERNAL_PLANE_3, INTERNAL_PLANE_4, INTERNAL_PLANE_5, INTERNAL_PLANE_6, INTERNAL_PLANE_7, INTERNAL_PLANE_8, INTERNAL_PLANE_9, KEEP_OUT_LAYER, MECHANICAL_1, MECHANICAL_10, MECHANICAL_11, MECHANICAL_12, MECHANICAL_13, MECHANICAL_14, MECHANICAL_15, MECHANICAL_16, MECHANICAL_2, MECHANICAL_3, MECHANICAL_4, MECHANICAL_5, MECHANICAL_6, MECHANICAL_7, MECHANICAL_8, MECHANICAL_9, MID_LAYER_1, MID_LAYER_10, MID_LAYER_11, MID_LAYER_12, MID_LAYER_13, MID_LAYER_14, MID_LAYER_15, MID_LAYER_16, MID_LAYER_17, MID_LAYER_18, MID_LAYER_19, MID_LAYER_2, MID_LAYER_20, MID_LAYER_21, MID_LAYER_22, MID_LAYER_23, MID_LAYER_24, MID_LAYER_25, MID_LAYER_26, MID_LAYER_27, MID_LAYER_28, MID_LAYER_29, MID_LAYER_3, MID_LAYER_30, MID_LAYER_4, MID_LAYER_5, MID_LAYER_6, MID_LAYER_7, MID_LAYER_8, MID_LAYER_9, MULTI_LAYER, PAD_HOLES, SELECTIONS, TOP_LAYER, TOP_OVERLAY, TOP_PASTE, TOP_SOLDER, UNKNOWN, VIA_HOLES, VISIBLE_GRID_1, and VISIBLE_GRID_2.

Referenced by ACOMPONENT6::ACOMPONENT6(), ADIMENSION6::ADIMENSION6(), and APOLYGON6::APOLYGON6().

◆ altium_parse_polygons()

void altium_parse_polygons ( std::map< wxString, wxString > &  aProperties,
std::vector< ALTIUM_VERTICE > &  aVertices 
)

Definition at line 141 of file altium_parser_pcb.cpp.

143 {
144  for( size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
145  {
146  const wxString si = std::to_string( i );
147 
148  const wxString vxi = "VX" + si;
149  const wxString vyi = "VY" + si;
150 
151  if( aProperties.find( vxi ) == aProperties.end()
152  || aProperties.find( vyi ) == aProperties.end() )
153  {
154  break; // it doesn't seem like we know beforehand how many vertices are inside a polygon
155  }
156 
157  const bool isRound = ALTIUM_PARSER::PropertiesReadInt( aProperties, "KIND" + si, 0 ) != 0;
158  const int32_t radius =
159  ALTIUM_PARSER::PropertiesReadKicadUnit( aProperties, "R" + si, "0mil" );
160  const double sa = ALTIUM_PARSER::PropertiesReadDouble( aProperties, "SA" + si, 0. );
161  const double ea = ALTIUM_PARSER::PropertiesReadDouble( aProperties, "EA" + si, 0. );
162  const wxPoint vp =
163  wxPoint( ALTIUM_PARSER::PropertiesReadKicadUnit( aProperties, vxi, "0mil" ),
164  -ALTIUM_PARSER::PropertiesReadKicadUnit( aProperties, vyi, "0mil" ) );
165  const wxPoint cp =
166  wxPoint( ALTIUM_PARSER::PropertiesReadKicadUnit( aProperties, "CX" + si, "0mil" ),
167  -ALTIUM_PARSER::PropertiesReadKicadUnit( aProperties, "CY" + si, "0mil" ) );
168 
169  aVertices.emplace_back( isRound, radius, sa, ea, vp, cp );
170  }
171 }
static int PropertiesReadInt(const std::map< wxString, wxString > &aProperties, const wxString &aKey, int aDefault)
static int32_t PropertiesReadKicadUnit(const std::map< wxString, wxString > &aProperties, const wxString &aKey, const wxString &aDefault)
static double PropertiesReadDouble(const std::map< wxString, wxString > &aProperties, const wxString &aKey, double aDefault)

References ALTIUM_PARSER::PropertiesReadDouble(), ALTIUM_PARSER::PropertiesReadInt(), and ALTIUM_PARSER::PropertiesReadKicadUnit().

Referenced by ABOARD6::ABOARD6(), and APOLYGON6::APOLYGON6().