26#include <unordered_map>
48 constexpr double int_limit = ( std::numeric_limits<int>::max() - 10 ) / 2.54;
53 return KiROUND( std::clamp( ( dbase + dfrac ) / 10.0, -int_limit, int_limit ) ) * 10;
89T
ReadEnum(
const std::map<wxString, wxString>& aProps,
const wxString& aKey,
int aLower,
90 int aUpper, T aDefault )
94 if( value < aLower || value > aUpper )
97 return static_cast<T
>( value );
107 const size_t charCount = hexData.size();
109 if( charCount != dataSize * 2 )
111 THROW_IO_ERROR( wxString::Format(
"Invalid binary file hex data size. Chars expected: %d, "
112 "hex string length: %d",
113 int( dataSize * 2 ),
int( hexData.size() ) ) );
116 data.resize( dataSize );
122 for(
size_t inputId = 1; inputId < charCount; inputId += 2 )
124 str[0] = (char) hexData[inputId - 1];
125 str[1] = (char) hexData[inputId];
127 std::from_chars( str, str + 2, b, 16 );
139 uint32_t dataSize = aReader.
Read<uint32_t>();
151 uint32_t dataSize = aReader.
Read<uint32_t>();
161 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::COMPONENT );
183 if( displayModeStr.ToCLong( &v ) )
191 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEMPLATE );
200 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PIN );
220 electrical = ReadEnum<ASCH_PIN_ELECTRICAL>( aProps,
"ELECTRICAL", 0, 7,
221 ASCH_PIN_ELECTRICAL::INPUT );
226 hidden = ( pinconglomerate & 0x04 ) != 0;
230 locked = ( pinconglomerate & 0x40 ) != 0;
245 int kicadXfrac = xfrac;
247 int kicadYfrac = yfrac;
250 int offsetYfrac = pfrac;
254 case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
256 kicadXfrac += offsetYfrac;
259 case ASCH_RECORD_ORIENTATION::UPWARDS:
261 kicadYfrac += offsetYfrac;
264 case ASCH_RECORD_ORIENTATION::LEFTWARDS:
266 kicadXfrac -= offsetYfrac;
269 case ASCH_RECORD_ORIENTATION::DOWNWARDS:
271 kicadYfrac -= offsetYfrac;
275 wxLogWarning(
"Pin has unexpected orientation" );
318 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LABEL );
329 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
330 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
332 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
333 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
340 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NOTE
341 ||
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEXT_FRAME );
354 Text.Replace(
"~1",
"\n",
true );
368 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
369 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
376 wxASSERT(
ReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
386 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BEZIER );
390 for(
int i = 1; i <= locationCount; i++ )
392 const wxString si = std::to_string( i );
403 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYLINE );
407 for(
int i = 1; i <= locationCount; i++ )
409 const wxString si = std::to_string( i );
414 auto lineStyleExt =
ReadEnum( aProps,
"LINESTYLEEXT", 0, 3, ASCH_POLYLINE_LINESTYLE::SOLID );
424 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYGON );
428 for(
int i = 1; i <= locationCount; i++ )
430 const wxString si = std::to_string( i );
442 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
487 wxASSERT( record == ALTIUM_SCH_RECORD::ELLIPSE || record == ALTIUM_SCH_RECORD::ELLIPTICAL_ARC );
501 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LINE );
508 auto lineStyleExt =
ReadEnum( aProps,
"LINESTYLEEXT", 0, 3, ASCH_POLYLINE_LINESTYLE::SOLID );
516 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SIGNAL_HARNESS );
521 for(
int i = 1; i <= locationCount; i++ )
523 const wxString si = std::to_string( i );
536 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_CONNECTOR );
555 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_ENTRY );
564 Side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
581 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_TYPE );
603 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE );
616 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_SYMBOL );
633 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_ENTRY );
638 side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
642 iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
643 style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
650 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POWER_PORT );
656 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
657 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
662 style = ReadEnum<ASCH_POWER_PORT_STYLE>( aProps,
"STYLE", 0, 10,
663 ASCH_POWER_PORT_STYLE::CIRCLE );
670 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PORT );
682 IOtype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
683 Style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
690 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
691 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
697 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NO_ERC );
710 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NET_LABEL );
717 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
718 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
720 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
721 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
728 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS );
732 for(
int i = 1; i <= locationcount; i++ )
734 const wxString si = std::to_string( i );
746 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::WIRE );
750 for(
int i = 1; i <= locationcount; i++ )
752 const wxString si = std::to_string( i );
764 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::JUNCTION );
776 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMAGE );
793 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
795 const wxString sid = std::to_string( aId );
841 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
845 for(
int i = 1; i <= fontidcount; i++ )
846 fonts.emplace_back( aProps, i );
853 sheetSize = ReadEnum<ASCH_SHEET_SIZE>( aProps,
"SHEETSTYLE", 0, 17, ASCH_SHEET_SIZE::A4 );
855 aProps,
"WORKSPACEORIENTATION", 0, 1, ASCH_SHEET_WORKSPACEORIENTATION::LANDSCAPE );
862 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_NAME );
866 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
867 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
879 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::FILE_NAME );
883 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
884 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
896 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::DESIGNATOR );
902 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
903 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
905 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
906 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
916 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION );
930 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST );
937 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS_ENTRY );
949 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PARAMETER );
954 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
955 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
957 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
958 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
974 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HYPERLINK );
int ReadOwnerPartId(const std::map< wxString, wxString > &aProperties)
int ReadOwnerIndex(const std::map< wxString, wxString > &aProperties)
T ReadEnum(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aLower, int aUpper, T aDefault)
constexpr int Altium2KiCadUnit(const int val, const int frac)
VECTOR2I ASchSheetGetSize(ASCH_SHEET_SIZE aSheetSize)
int ReadKiCadUnitFrac1(const std::map< wxString, wxString > &aProps, const wxString &aKey)
int ReadKiCadUnitFrac(const std::map< wxString, wxString > &aProps, const wxString &aKey)
ALTIUM_SCH_RECORD ReadRecord(const std::map< wxString, wxString > &aProps)
const int ALTIUM_COMPONENT_NONE
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void Skip(size_t aLength)
std::vector< char > ReadVector(size_t aSize)
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool 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 PTYPE FromInt(int aInt)
#define THROW_IO_ERROR(msg)
ASCH_ADDITIONAL_FILE(ALTIUM_BINARY_PARSER &aReader)
ASCH_ARC(const std::map< wxString, wxString > &aProps)
ASCH_BEZIER(const std::map< wxString, wxString > &aProps)
std::vector< VECTOR2I > points
ASCH_BORDER_INTERFACE(const std::map< wxString, wxString > &aProps)
ASCH_BUS_ENTRY(const std::map< wxString, wxString > &aProps)
ASCH_BUS(const std::map< wxString, wxString > &aProps)
std::vector< VECTOR2I > points
ASCH_LABEL_JUSTIFICATION justification
ASCH_DESIGNATOR(const std::map< wxString, wxString > &aProps)
ASCH_RECORD_ORIENTATION orientation
ASCH_ELLIPSE(const std::map< wxString, wxString > &aProps)
ASCH_FILE_NAME(const std::map< wxString, wxString > &aProps)
ASCH_RECORD_ORIENTATION orientation
ASCH_FILL_INTERFACE(const std::map< wxString, wxString > &aProps)
ASCH_HARNESS_CONNECTOR(const std::map< wxString, wxString > &aProps)
int LocationPrimaryConnectionPosition
ASCH_HARNESS_ENTRY(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_ENTRY_SIDE Side
bool OwnerIndexAdditionalList
ASCH_HARNESS_TYPE(const std::map< wxString, wxString > &aProps)
bool OwnerIndexAdditionalList
ASCH_HYPERLINK(const std::map< wxString, wxString > &aProps)
ASCH_IMAGE(const std::map< wxString, wxString > &aProps)
ASCH_IMPLEMENTATION_LIST(const std::map< wxString, wxString > &aProps)
ASCH_IMPLEMENTATION(const std::map< wxString, wxString > &aProps)
ASCH_JUNCTION(const std::map< wxString, wxString > &aProps)
ASCH_RECORD_ORIENTATION orientation
ASCH_LABEL(const std::map< wxString, wxString > &aProps)
ASCH_LABEL_JUSTIFICATION justification
ASCH_POLYLINE_LINESTYLE LineStyle
ASCH_LINE(const std::map< wxString, wxString > &aProps)
ASCH_LABEL_JUSTIFICATION justification
ASCH_RECORD_ORIENTATION orientation
ASCH_NET_LABEL(const std::map< wxString, wxString > &aProps)
ASCH_NOTE(const std::map< wxString, wxString > &aProperties)
ASCH_NO_ERC(const std::map< wxString, wxString > &aProps)
ASCH_OWNER_INTERFACE(const std::map< wxString, wxString > &aProps)
ASCH_PARAMETER(const std::map< wxString, wxString > &aProps)
ASCH_RECORD_ORIENTATION orientation
ASCH_LABEL_JUSTIFICATION justification
ASCH_PIECHART(const std::map< wxString, wxString > &aProps)
ASCH_PIN_SYMBOL::PTYPE symbolOuterEdge
ASCH_PIN_SYMBOL::PTYPE symbolOuter
ASCH_PIN_ELECTRICAL electrical
ASCH_PIN_SYMBOL::PTYPE symbolInner
ASCH_PIN_SYMBOL::PTYPE symbolInnerEdge
ASCH_RECORD_ORIENTATION orientation
ASCH_PIN(const std::map< wxString, wxString > &aProps)
std::vector< VECTOR2I > points
ASCH_POLYGON(const std::map< wxString, wxString > &aProps)
ASCH_POLYLINE(const std::map< wxString, wxString > &aProps)
ASCH_POLYLINE_LINESTYLE LineStyle
std::vector< VECTOR2I > Points
ASCH_TEXT_FRAME_ALIGNMENT Alignment
ASCH_PORT(const std::map< wxString, wxString > &aProps)
ASCH_POWER_PORT(const std::map< wxString, wxString > &aProps)
ASCH_POWER_PORT_STYLE style
ASCH_RECORD_ORIENTATION orientation
ASCH_RECTANGLE(const std::map< wxString, wxString > &aProps)
ASCH_ROUND_RECTANGLE(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_ENTRY(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_ENTRY_SIDE side
ASCH_SHEET_FONT(const std::map< wxString, wxString > &aProps, int aId)
ASCH_SHEET_NAME(const std::map< wxString, wxString > &aProps)
ASCH_RECORD_ORIENTATION orientation
ASCH_SHEET_SYMBOL(const std::map< wxString, wxString > &aProps)
ASCH_SHEET_SIZE sheetSize
ASCH_SHEET_WORKSPACEORIENTATION sheetOrientation
ASCH_SHEET(const std::map< wxString, wxString > &aProps)
std::vector< ASCH_SHEET_FONT > fonts
ASCH_SIGNAL_HARNESS(const std::map< wxString, wxString > &aProps)
std::vector< VECTOR2I > Points
ASCH_STORAGE_FILE(const std::map< wxString, wxString > &aProps)
wxString componentdescription
ASCH_SYMBOL(const std::map< wxString, wxString > &aProps)
wxString sourcelibraryname
ASCH_TEMPLATE(const std::map< wxString, wxString > &aProps)
ASCH_TEXT_FRAME_ALIGNMENT Alignment
ASCH_TEXT_FRAME(const std::map< wxString, wxString > &aProps)
ASCH_WIRE(const std::map< wxString, wxString > &aProps)
std::vector< VECTOR2I > points
constexpr int MilsToIU(int mils) const
VECTOR2< int32_t > VECTOR2I