26#include <unordered_map>
39 static const std::unordered_map<std::string, ALTIUM_LAYER> hash_map = {
131 auto it = hash_map.find( std::string( aName.c_str() ) );
133 if( it == hash_map.end() )
135 wxLogError(
_(
"Unknown mapping of the Altium layer '%s'." ), aName );
145 std::vector<ALTIUM_VERTICE>& aVertices )
147 for(
size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
149 const wxString si = std::to_string( i );
151 const wxString vxi = wxT(
"VX" ) + si;
152 const wxString vyi = wxT(
"VY" ) + si;
154 if( aProps.find( vxi ) == aProps.end() || aProps.find( vyi ) == aProps.end() )
166 aVertices.emplace_back( isRound, radius, sa, ea, vp, cp );
176 if( mode == wxT(
"None" ) )
178 else if( mode == wxT(
"Rule" ) )
180 else if( mode == wxT(
"Manual" ) )
183 wxLogError(
_(
"Unknown Mode string: '%s'." ), mode );
193 if( record == wxT(
"Arc" ) )
195 else if( record == wxT(
"Pad" ) )
197 else if( record == wxT(
"Via" ) )
199 else if( record == wxT(
"Track" ) )
201 else if( record == wxT(
"Text" ) )
203 else if( record == wxT(
"Fill" ) )
205 else if( record == wxT(
"Region" ) )
207 else if( record == wxT(
"Model" ) )
210 wxLogError(
_(
"Unknown Record name string: '%s'." ), record );
217 const std::map<wxString, wxString>& aProps, wxString aKey )
221 if( parsedType == wxT(
"Mask" ) )
224 wxLogError(
_(
"Unknown Extended Primitive Information type: '%s'." ), parsedType );
231 const std::map<wxString, wxString> props = aReader.
ReadProperties();
234 THROW_IO_ERROR( wxT(
"ExtendedPrimitiveInformation stream has no properties!" ) );
242 props, wxT(
"PASTEMASKEXPANSION_MANUAL" ), wxT(
"0mil" ) );
246 props, wxT(
"SOLDERMASKEXPANSION_MANUAL" ), wxT(
"0mil" ) );
264 for(
size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
266 const wxString layeri = wxT(
"LAYER" ) + std::to_string( i );
267 const wxString layername = layeri + wxT(
"NAME" );
269 auto layernameit = props.find( layername );
271 if( layernameit == props.end() )
277 wxString originalName = l.
name;
282 l.
name = wxString::Format( wxT(
"%s %d" ), originalName, ii++ );
298 THROW_IO_ERROR( wxT(
"Board6 stream was not parsed correctly!" ) );
303 std::map<wxString, wxString> properties = aReader.
ReadProperties();
305 if( properties.empty() )
312 for(
size_t i = 0; i < std::numeric_limits<size_t>::max(); i++ )
314 auto mit = properties.find( wxT(
"M" ) + std::to_string( i ) );
316 if( mit == properties.end() )
319 names.push_back( mit->second );
323 THROW_IO_ERROR( wxT(
"Classes6 stream was not parsed correctly" ) );
355 THROW_IO_ERROR( wxT(
"Components6 stream was not parsed correctly" ) );
394 for(
int i = 0; i < refcount; i++ )
396 const std::string refi =
"REFERENCE" + std::to_string( i ) +
"POINT";
401 for(
size_t i = 1; i < std::numeric_limits<size_t>::max(); i++ )
403 const std::string texti =
"TEXT" + std::to_string( i );
404 const std::string textix = texti +
"X";
405 const std::string textiy = texti +
"Y";
407 if( props.find( textix ) == props.end() || props.find( textiy ) == props.end() )
416 if( dimensionunit == wxT(
"Inches" ) )
textunit = ALTIUM_UNIT::INCHES;
417 else if( dimensionunit == wxT(
"Mils" ) )
textunit = ALTIUM_UNIT::MILS;
418 else if( dimensionunit == wxT(
"Millimeters" ) )
textunit = ALTIUM_UNIT::MILLIMETERS;
419 else if( dimensionunit == wxT(
"Centimeters" ) )
textunit = ALTIUM_UNIT::CENTIMETER;
420 else textunit = ALTIUM_UNIT::UNKNOWN;
423 THROW_IO_ERROR( wxT(
"Dimensions6 stream was not parsed correctly" ) );
428 std::map<wxString, wxString> properties = aReader.
ReadProperties();
430 if( properties.empty() )
447 std::map<wxString, wxString> properties = aReader.
ReadProperties();
449 if( properties.empty() )
460 std::map<wxString, wxString> properties = aReader.
ReadProperties();
462 if( properties.empty() )
480 if( hatchstyleraw == wxT(
"Solid" ) )
hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::SOLID;
481 else if( hatchstyleraw == wxT(
"45Degree" ) )
hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::DEGREE_45;
482 else if( hatchstyleraw == wxT(
"90Degree" ) )
hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::DEGREE_90;
483 else if( hatchstyleraw == wxT(
"Horizontal" ) )
hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::HORIZONTAL;
484 else if( hatchstyleraw == wxT(
"Vertical" ) )
hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::VERTICAL;
485 else if( hatchstyleraw == wxT(
"None" ) )
hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::NONE;
486 else hatchstyle = ALTIUM_POLYGON_HATCHSTYLE::UNKNOWN;
491 THROW_IO_ERROR( wxT(
"Polygons6 stream was not parsed correctly" ) );
518 if( rulekind == wxT(
"Clearance" ) )
520 kind = ALTIUM_RULE_KIND::CLEARANCE;
523 else if( rulekind == wxT(
"DiffPairsRouting" ) )
525 kind = ALTIUM_RULE_KIND::DIFF_PAIR_ROUTINGS;
527 else if( rulekind == wxT(
"Height" ) )
529 kind = ALTIUM_RULE_KIND::HEIGHT;
531 else if( rulekind == wxT(
"HoleSize" ) )
533 kind = ALTIUM_RULE_KIND::HOLE_SIZE;
535 else if( rulekind == wxT(
"HoleToHoleClearance" ) )
537 kind = ALTIUM_RULE_KIND::HOLE_TO_HOLE_CLEARANCE;
539 else if( rulekind == wxT(
"Width" ) )
541 kind = ALTIUM_RULE_KIND::WIDTH;
543 else if( rulekind == wxT(
"PasteMaskExpansion" ) )
545 kind = ALTIUM_RULE_KIND::PASTE_MASK_EXPANSION;
548 else if( rulekind == wxT(
"SolderMaskExpansion" ) )
550 kind = ALTIUM_RULE_KIND::SOLDER_MASK_EXPANSION;
554 else if( rulekind == wxT(
"PlaneClearance" ) )
556 kind = ALTIUM_RULE_KIND::PLANE_CLEARANCE;
559 else if( rulekind == wxT(
"PolygonConnect" ) )
561 kind = ALTIUM_RULE_KIND::POLYGON_CONNECT;
575 kind = ALTIUM_RULE_KIND::UNKNOWN;
579 THROW_IO_ERROR( wxT(
"Rules6 stream was not parsed correctly" ) );
585 if( recordtype != ALTIUM_RECORD::ARC )
595 uint8_t flags1 = aReader.
Read<uint8_t>();
599 uint8_t flags2 = aReader.
Read<uint8_t>();
602 net = aReader.
Read<uint16_t>();
634 if( recordtype != ALTIUM_RECORD::MODEL )
635 THROW_IO_ERROR( wxT(
"ComponentsBodies6 stream has invalid recordtype" ) );
643 std::map<wxString, wxString> properties = aReader.
ReadProperties();
645 if( properties.empty() )
646 THROW_IO_ERROR( wxT(
"ComponentsBodies6 stream has no properties" ) );
667 THROW_IO_ERROR( wxT(
"Components6 stream was not parsed correctly" ) );
674 if( recordtype != ALTIUM_RECORD::PAD )
680 if( subrecord1 == 0 )
686 THROW_IO_ERROR( wxT(
"Pads6 stream has invalid subrecord1 length" ) );
705 if( subrecord5 < 114 )
706 THROW_IO_ERROR( wxT(
"Pads6 stream subrecord has length < 114, which is unexpected" ) );
709 tolayer = ALTIUM_LAYER::UNKNOWN;
712 uint8_t flags1 = aReader.
Read<uint8_t>();
718 uint8_t flags2 = aReader.
Read<uint8_t>();
721 net = aReader.
Read<uint16_t>();
749 if( subrecord5 >= 120 )
756 else if( subrecord5 == 171 )
766 if( subrecord6 >= 596 )
768 sizeAndShape = std::make_unique<APAD6_SIZE_AND_SHAPE>();
797 radius = aReader.
Read<uint8_t>();
799 else if( subrecord6 != 0 )
801 wxLogError(
_(
"Pads6 stream has unexpected length for subrecord 6: %d." ), subrecord6 );
814 if( recordtype != ALTIUM_RECORD::VIA )
822 uint8_t flags1 = aReader.
Read<uint8_t>();
828 uint8_t flags2 = aReader.
Read<uint8_t>();
831 net = aReader.
Read<uint16_t>();
840 if( subrecord1 <= 74 )
842 viamode = ALTIUM_PAD_MODE::SIMPLE;
860 if( recordtype != ALTIUM_RECORD::TRACK )
868 uint8_t flags1 = aReader.
Read<uint8_t>();
872 uint8_t flags2 = aReader.
Read<uint8_t>();
875 net = aReader.
Read<uint16_t>();
896 THROW_IO_ERROR( wxT(
"Tracks6 stream was not parsed correctly" ) );
903 if( recordtype != ALTIUM_RECORD::TEXT )
925 char fontData[64] = { 0 };
926 aReader.
ReadBytes( fontData,
sizeof( fontData ) );
927 fontname = wxString( fontData, wxMBConvUTF16LE(),
sizeof( fontData ) ).BeforeFirst(
'\0' );
931 uint32_t stringIndex = aReader.
Read<uint32_t>();
938 if( subrecord1 <= 230 )
949 auto entry = aStringTable.find( stringIndex );
951 if( entry != aStringTable.end() )
952 text = entry->second;
957 text.Replace( wxT(
"\r\n" ), wxT(
"\n" ) );
962 THROW_IO_ERROR( wxT(
"Texts6 stream was not parsed correctly" ) );
969 if( recordtype != ALTIUM_RECORD::FILL )
977 uint8_t flags1 = aReader.
Read<uint8_t>();
980 uint8_t flags2 = aReader.
Read<uint8_t>();
983 net = aReader.
Read<uint16_t>();
1004 THROW_IO_ERROR( wxT(
"Fills6 stream was not parsed correctly" ) );
1011 if( recordtype != ALTIUM_RECORD::REGION )
1012 THROW_IO_ERROR( wxT(
"Regions6 stream has invalid recordtype" ) );
1019 uint8_t flags1 = aReader.
Read<uint8_t>();
1022 uint8_t flags2 = aReader.
Read<uint8_t>();
1025 net = aReader.
Read<uint16_t>();
1032 std::map<wxString, wxString> properties = aReader.
ReadProperties();
1034 if( properties.empty() )
1053 kind = ALTIUM_REGION_KIND::BOARD_CUTOUT;
1057 kind = ALTIUM_REGION_KIND::COPPER;
1061 kind = ALTIUM_REGION_KIND::POLYGON_CUTOUT;
1064 kind = ALTIUM_REGION_KIND::DASHED_OUTLINE;
1067 kind = ALTIUM_REGION_KIND::UNKNOWN_3;
1070 kind = ALTIUM_REGION_KIND::CAVITY_DEFINITION;
1073 kind = ALTIUM_REGION_KIND::UNKNOWN;
1077 uint32_t num_outline_vertices = aReader.
Read<uint32_t>();
1079 if( aExtendedVertices )
1080 num_outline_vertices++;
1082 for( uint32_t i = 0; i < num_outline_vertices; i++ )
1084 if( aExtendedVertices )
1086 bool isRound = aReader.
Read<uint8_t>() != 0;
1090 double angle1 = aReader.
Read<
double>();
1091 double angle2 = aReader.
Read<
double>();
1092 outline.emplace_back( isRound, radius, angle1, angle2, position, center );
1104 for( uint16_t k = 0; k <
holecount; k++ )
1106 uint32_t num_hole_vertices = aReader.
Read<uint32_t>();
1107 holes.at( k ).reserve( num_hole_vertices );
1109 for( uint32_t i = 0; i < num_hole_vertices; i++ )
1120 THROW_IO_ERROR( wxT(
"Regions6 stream was not parsed correctly" ) );
void altium_parse_polygons(std::map< wxString, wxString > &aProps, std::vector< ALTIUM_VERTICE > &aVertices)
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
AEXTENDED_PRIMITIVE_INFORMATION_TYPE
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
size_t GetRemainingSubrecordBytes() const
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
size_t ReadAndSetSubrecordLength()
int ReadBytes(char *aOut, size_t aSize)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
VECTOR2I ReadVector2ISize()
static int32_t ConvertToKicadUnit(const double aValue)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
VECTOR2I ReadVector2IPos()
void Skip(size_t aLength)
static wxString ReadUnicodeString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
#define THROW_IO_ERROR(msg)
AARC6(ALTIUM_PARSER &aReader)
uint8_t keepoutrestrictions
wxString dielectricmaterial
ABOARD6(ALTIUM_PARSER &aReader)
std::set< wxString > layerNames
std::vector< ABOARD6_LAYER_STACKUP > stackup
std::vector< ALTIUM_VERTICE > board_vertices
std::vector< wxString > names
ACLASS6(ALTIUM_PARSER &aReader)
ALTIUM_TEXT_POSITION commentautoposition
ALTIUM_TEXT_POSITION nameautoposition
ACOMPONENT6(ALTIUM_PARSER &aReader)
wxString sourcefootprintlibrary
wxString sourcelibreference
wxString sourcedesignator
wxString sourcecomponentlibrary
ACOMPONENTBODY6(ALTIUM_PARSER &aReader)
ADIMENSION6(ALTIUM_PARSER &aReader)
std::vector< VECTOR2I > textPoint
ALTIUM_DIMENSION_KIND kind
std::vector< VECTOR2I > referencePoint
uint8_t keepoutrestrictions
AFILL6(ALTIUM_PARSER &aReader)
AMODEL(ALTIUM_PARSER &aReader)
ANET6(ALTIUM_PARSER &aReader)
int32_t soldermaskexpansionmanual
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
APAD6(ALTIUM_PARSER &aReader)
APOLYGON6(ALTIUM_PARSER &aReader)
std::vector< ALTIUM_VERTICE > vertices
ALTIUM_POLYGON_HATCHSTYLE hatchstyle
uint8_t keepoutrestrictions
AREGION6(ALTIUM_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_PARSER &aReader)
int32_t polygonconnectAirgapwidth
int polygonconnectReliefentries
ALTIUM_TEXT_POSITION textposition
ATEXT6(ALTIUM_PARSER &aReader, std::map< uint32_t, wxString > &aStringTable)
ALTIUM_TEXT_TYPE fonttype
uint8_t keepoutrestrictions
ATRACK6(ALTIUM_PARSER &aReader)
AVIA6(ALTIUM_PARSER &aReader)