26#include <unordered_map>
50 static const std::unordered_map<std::string, ALTIUM_LAYER> hash_map = {
142 auto it = hash_map.find( std::string( aName.c_str() ) );
144 if( it == hash_map.end() )
146 wxLogError(
_(
"Unknown mapping of the Altium layer '%s'." ), aName );
156 std::vector<ALTIUM_VERTICE>& aVertices )
158 for(
size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
160 const wxString si = std::to_string( i );
162 const wxString vxi = wxT(
"VX" ) + si;
163 const wxString vyi = wxT(
"VY" ) + si;
165 if( aProps.find( vxi ) == aProps.end() || aProps.find( vyi ) == aProps.end() )
177 aVertices.emplace_back( isRound,
radius, sa, ea, vp, cp );
187 if( mode == wxT(
"None" ) )
189 else if( mode == wxT(
"Rule" ) )
191 else if( mode == wxT(
"Manual" ) )
194 wxLogError(
_(
"Unknown Mode string: '%s'." ), mode );
204 if( record == wxT(
"Arc" ) )
206 else if( record == wxT(
"Pad" ) )
208 else if( record == wxT(
"Via" ) )
210 else if( record == wxT(
"Track" ) )
212 else if( record == wxT(
"Text" ) )
214 else if( record == wxT(
"Fill" ) )
216 else if( record == wxT(
"Region" ) )
218 else if( record == wxT(
"Model" ) )
221 wxLogError(
_(
"Unknown Record name string: '%s'." ), record );
228 const std::map<wxString, wxString>& aProps, wxString aKey )
232 if( parsedType == wxT(
"Mask" ) )
235 wxLogError(
_(
"Unknown Extended Primitive Information type: '%s'." ), parsedType );
249 const std::string& aSubrecordName,
size_t aExpectedLength,
250 size_t aActualLength )
252 if( aActualLength < aExpectedLength )
255 "which is unexpected (expected at least %d)",
256 aStreamType, aSubrecordName, aActualLength,
264 const std::map<wxString, wxString> props = aReader.
ReadProperties();
267 THROW_IO_ERROR( wxT(
"ExtendedPrimitiveInformation stream has no properties!" ) );
275 props, wxT(
"PASTEMASKEXPANSION_MANUAL" ), wxT(
"0mil" ) );
279 props, wxT(
"SOLDERMASKEXPANSION_MANUAL" ), wxT(
"0mil" ) );
297 for(
size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
299 const wxString layeri = wxT(
"LAYER" ) + wxString( std::to_string( i ) );
300 const wxString layername = layeri + wxT(
"NAME" );
302 auto layernameit = props.find( layername );
304 if( layernameit == props.end() )
310 wxString originalName = l.
name;
315 l.
name = wxString::Format( wxT(
"%s %d" ), originalName, ii++ );
331 THROW_IO_ERROR( wxT(
"Board6 stream was not parsed correctly!" ) );
336 std::map<wxString, wxString> properties = aReader.
ReadProperties();
338 if( properties.empty() )
345 for(
size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
347 auto mit = properties.find( wxT(
"M" ) + wxString( std::to_string( i ) ) );
349 if( mit == properties.end() )
352 names.push_back( mit->second );
356 THROW_IO_ERROR( wxT(
"Classes6 stream was not parsed correctly" ) );
395 THROW_IO_ERROR( wxT(
"Components6 stream was not parsed correctly" ) );
434 for(
int i = 0; i < refcount; i++ )
436 const std::string refi =
"REFERENCE" + std::to_string( i ) +
"POINT";
437 const wxString ref( refi );
442 for(
size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
444 const std::string texti =
"TEXT" + std::to_string( i );
445 const std::string textix = texti +
"X";
446 const std::string textiy = texti +
"Y";
448 if( props.find( textix ) == props.end() || props.find( textiy ) == props.end() )
464 THROW_IO_ERROR( wxT(
"Dimensions6 stream was not parsed correctly" ) );
469 std::map<wxString, wxString> properties = aReader.
ReadProperties();
471 if( properties.empty() )
491 std::map<wxString, wxString> properties = aReader.
ReadProperties();
493 if( properties.empty() )
504 std::map<wxString, wxString> properties = aReader.
ReadProperties();
506 if( properties.empty() )
535 THROW_IO_ERROR( wxT(
"Polygons6 stream was not parsed correctly" ) );
554 if( rulekind == wxT(
"Clearance" ) )
559 else if( rulekind == wxT(
"DiffPairsRouting" ) )
563 else if( rulekind == wxT(
"Height" ) )
567 else if( rulekind == wxT(
"HoleSize" ) )
573 else if( rulekind == wxT(
"HoleToHoleClearance" ) )
578 else if( rulekind == wxT(
"RoutingVias" ) )
588 else if( rulekind == wxT(
"Width" ) )
595 else if( rulekind == wxT(
"PasteMaskExpansion" ) )
600 else if( rulekind == wxT(
"SolderMaskExpansion" ) )
605 else if( rulekind == wxT(
"PlaneClearance" ) )
610 else if( rulekind == wxT(
"PolygonConnect" ) )
630 THROW_IO_ERROR( wxT(
"Rules6 stream was not parsed correctly" ) );
646 uint8_t flags1 = aReader.
Read<uint8_t>();
650 uint8_t flags2 = aReader.
Read<uint8_t>();
653 net = aReader.
Read<uint16_t>();
687 THROW_IO_ERROR( wxT(
"ComponentsBodies6 stream has invalid recordtype" ) );
695 std::map<wxString, wxString> properties = aReader.
ReadProperties();
697 if( properties.empty() )
698 THROW_IO_ERROR( wxT(
"ComponentsBodies6 stream has no properties" ) );
720 THROW_IO_ERROR( wxT(
"Components6 stream was not parsed correctly" ) );
733 if( subrecord1 == 0 )
739 THROW_IO_ERROR( wxT(
"Pads6 stream has invalid subrecord1 length" ) );
764 uint8_t flags1 = aReader.
Read<uint8_t>();
770 uint8_t flags2 = aReader.
Read<uint8_t>();
773 net = aReader.
Read<uint16_t>();
803 if( subrecord5 == 110 )
812 THROW_IO_ERROR( wxString::Format(
"Pads6 stream subrecord5 + 106 has value %d, "
813 "which is unexpected",
825 if( subrecord5 >= 120 )
832 else if( subrecord5 == 171 )
836 if( subrecord5 >= 202 )
850 if( subrecord6 >= 596 )
852 sizeAndShape = std::make_unique<APAD6_SIZE_AND_SHAPE>();
883 else if( subrecord6 != 0 )
885 wxLogError(
_(
"Pads6 stream has unexpected length for subrecord 6: %d." ), subrecord6 );
905 uint8_t flags1 = aReader.
Read<uint8_t>();
911 uint8_t flags2 = aReader.
Read<uint8_t>();
914 net = aReader.
Read<uint16_t>();
923 if( subrecord1 <= 74 )
929 uint8_t temp_byte = aReader.
Read<uint8_t>();
944 temp_byte = aReader.
Read<uint8_t>();
951 for(
int ii = 0; ii < 32; ++ii )
957 if( subrecord1 >= 246 )
964 if( subrecord1 >= 307 )
990 uint8_t flags1 = aReader.
Read<uint8_t>();
994 uint8_t flags2 = aReader.
Read<uint8_t>();
997 net = aReader.
Read<uint16_t>();
1019 THROW_IO_ERROR( wxT(
"Tracks6 stream was not parsed correctly" ) );
1045 if( subrecord1 < 123 )
1059 char fontData[64] = { 0 };
1060 aReader.
ReadBytes( fontData,
sizeof( fontData ) );
1061 fontname = wxString( fontData, wxMBConvUTF16LE(),
sizeof( fontData ) ).BeforeFirst(
'\0' );
1063 char tmpbyte = aReader.
Read<uint8_t>();
1079 if( remaining >= 103 )
1090 uint8_t unk8 = aReader.
Read<uint8_t>();
1096 aReader.
ReadBytes( fontData,
sizeof( fontData ) );
1097 barcode_fontname = wxString( fontData, wxMBConvUTF16LE(),
sizeof( fontData ) ).BeforeFirst(
'\0' );
1099 for(
size_t ii = 0; ii < 5; ++ii )
1101 uint8_t temp = aReader.
Peek<uint8_t>();
1103 wxLogTrace(
traceAltiumImport,
"2ATEXT6 %zu:\t Byte:%u, Kicad:%u\n", ii, temp, temp32 );
1113 for(
size_t ii = 0; ii < 8; ++ii )
1115 uint8_t temp = aReader.
Peek<uint8_t>();
1117 wxLogTrace(
traceAltiumImport,
"3ATEXT6 %zu:\t Byte:%u, Kicad:%u\n", ii, temp, temp32 );
1127 if( remaining >= 115 )
1145 if( entry != aStringTable.end() )
1146 text = entry->second;
1151 text.Replace( wxT(
"\r\n" ), wxT(
"\n" ) );
1163 THROW_IO_ERROR( wxT(
"Texts6 stream was not parsed correctly" ) );
1178 uint8_t flags1 = aReader.
Read<uint8_t>();
1181 uint8_t flags2 = aReader.
Read<uint8_t>();
1184 net = aReader.
Read<uint16_t>();
1205 THROW_IO_ERROR( wxT(
"Fills6 stream was not parsed correctly" ) );
1213 THROW_IO_ERROR( wxT(
"Regions6 stream has invalid recordtype" ) );
1220 uint8_t flags1 = aReader.
Read<uint8_t>();
1223 uint8_t flags2 = aReader.
Read<uint8_t>();
1226 net = aReader.
Read<uint16_t>();
1233 std::map<wxString, wxString> properties = aReader.
ReadProperties();
1235 if( properties.empty() )
1279 uint32_t num_outline_vertices = aReader.
Read<uint32_t>();
1281 if( aExtendedVertices )
1282 num_outline_vertices++;
1284 for( uint32_t i = 0; i < num_outline_vertices; i++ )
1286 if( aExtendedVertices )
1288 bool isRound = aReader.
Read<uint8_t>() != 0;
1292 double angle1 = aReader.
Read<
double>();
1293 double angle2 = aReader.
Read<
double>();
1306 for( uint16_t k = 0; k <
holecount; k++ )
1308 uint32_t num_hole_vertices = aReader.
Read<uint32_t>();
1309 holes.at( k ).reserve( num_hole_vertices );
1311 for( uint32_t i = 0; i < num_hole_vertices; i++ )
1322 THROW_IO_ERROR( wxT(
"Regions6 stream was not parsed correctly" ) );
void altium_parse_polygons(std::map< wxString, wxString > &aProps, std::vector< ALTIUM_VERTICE > &aVertices)
static void ExpectSubrecordLengthAtLeast(const std::string &aStreamType, const std::string &aSubrecordName, size_t aExpectedLength, size_t aActualLength)
Throw an IO_ERROR if the actual length is less than the expected length.
ALTIUM_LAYER altium_layer_from_name(const wxString &aName)
static AEXTENDED_PRIMITIVE_INFORMATION_TYPE ReadAltiumExtendedPrimitiveInformationTypeFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
static ALTIUM_MODE ReadAltiumModeFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
static ALTIUM_RECORD ReadAltiumRecordFromProperties(const std::map< wxString, wxString > &aProps, wxString aKey)
const uint16_t ALTIUM_NET_UNCONNECTED
const uint16_t ALTIUM_POLYGON_NONE
AEXTENDED_PRIMITIVE_INFORMATION_TYPE
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void Skip(size_t aLength)
size_t ReadAndSetSubrecordLength()
VECTOR2I ReadVector2ISize()
VECTOR2I ReadVector2IPos()
size_t GetRemainingSubrecordBytes() const
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
int ReadBytes(char *aOut, size_t aSize)
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
static int32_t ReadKicadUnit(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
static wxString ReadUnicodeString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
static int32_t ConvertToKicadUnit(const double aValue)
static const wxChar * traceAltiumImport
Flag to enable Altium importer logging.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
AARC6(ALTIUM_BINARY_PARSER &aReader)
uint8_t keepoutrestrictions
wxString dielectricmaterial
std::set< wxString > layerNames
ABOARD6(ALTIUM_BINARY_PARSER &aReader)
std::vector< ABOARD6_LAYER_STACKUP > stackup
std::vector< ALTIUM_VERTICE > board_vertices
std::vector< wxString > names
ACLASS6(ALTIUM_BINARY_PARSER &aReader)
wxString sourceHierachicalPath
ALTIUM_TEXT_POSITION commentautoposition
ALTIUM_TEXT_POSITION nameautoposition
ACOMPONENT6(ALTIUM_BINARY_PARSER &aReader)
wxString sourcefootprintlibrary
wxString sourcelibreference
wxString sourcedesignator
wxString sourcecomponentlibrary
ACOMPONENTBODY6(ALTIUM_BINARY_PARSER &aReader)
std::vector< VECTOR2I > textPoint
ALTIUM_DIMENSION_KIND kind
ADIMENSION6(ALTIUM_BINARY_PARSER &aReader)
std::vector< VECTOR2I > referencePoint
uint8_t keepoutrestrictions
AFILL6(ALTIUM_BINARY_PARSER &aReader)
AMODEL(ALTIUM_BINARY_PARSER &aReader)
ANET6(ALTIUM_BINARY_PARSER &aReader)
int32_t soldermaskexpansionmanual
APAD6(ALTIUM_BINARY_PARSER &aReader)
std::unique_ptr< APAD6_SIZE_AND_SHAPE > sizeAndShape
ALTIUM_PAD_SHAPE topshape
ALTIUM_MODE pastemaskexpansionmode
ALTIUM_MODE soldermaskexpansionmode
ALTIUM_PAD_SHAPE botshape
ALTIUM_PAD_SHAPE midshape
int32_t pastemaskexpansionmanual
int32_t pad_to_die_length
std::vector< ALTIUM_VERTICE > vertices
APOLYGON6(ALTIUM_BINARY_PARSER &aReader)
ALTIUM_POLYGON_HATCHSTYLE hatchstyle
uint8_t keepoutrestrictions
AREGION6(ALTIUM_BINARY_PARSER &aReader, bool aExtendedVertices)
std::vector< ALTIUM_VERTICE > outline
std::vector< std::vector< ALTIUM_VERTICE > > holes
ALTIUM_CONNECT_STYLE polygonconnectStyle
int planeclearanceClearance
int32_t polygonconnectReliefconductorwidth
ARULE6(ALTIUM_BINARY_PARSER &aReader)
int32_t polygonconnectAirgapwidth
int polygonconnectReliefentries
uint32_t text_offset_width
uint32_t textbox_rect_height
ALTIUM_TEXT_POSITION textbox_rect_justification
uint32_t widestring_index
uint32_t textbox_rect_width
uint32_t margin_border_width
bool isJustificationValid
ALTIUM_BARCODE_TYPE barcode_type
ALTIUM_TEXT_TYPE fonttype
STROKE_FONT_TYPE strokefonttype
wxString barcode_fontname
ATEXT6(ALTIUM_BINARY_PARSER &aReader, std::map< uint32_t, wxString > &aStringTable)
ATRACK6(ALTIUM_BINARY_PARSER &aReader)
uint8_t keepoutrestrictions
bool soldermask_expansion_linked
uint32_t thermal_relief_conductorcount
int32_t thermal_relief_airgap
int32_t soldermask_expansion_front
bool soldermask_expansion_manual
AVIA6(ALTIUM_BINARY_PARSER &aReader)
uint32_t thermal_relief_conductorwidth
int32_t soldermask_expansion_back
uint32_t diameter_by_layer[32]
VECTOR2< int32_t > VECTOR2I