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 );
184 if( displayModeStr.ToCLong( &v ) )
192 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEMPLATE );
201 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PIN );
221 electrical = ReadEnum<ASCH_PIN_ELECTRICAL>( aProps,
"ELECTRICAL", 0, 7,
222 ASCH_PIN_ELECTRICAL::INPUT );
227 hidden = ( pinconglomerate & 0x04 ) != 0;
231 locked = ( pinconglomerate & 0x40 ) != 0;
246 int kicadXfrac = xfrac;
248 int kicadYfrac = yfrac;
251 int offsetYfrac = pfrac;
255 case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
257 kicadXfrac += offsetYfrac;
260 case ASCH_RECORD_ORIENTATION::UPWARDS:
262 kicadYfrac += offsetYfrac;
265 case ASCH_RECORD_ORIENTATION::LEFTWARDS:
267 kicadXfrac -= offsetYfrac;
270 case ASCH_RECORD_ORIENTATION::DOWNWARDS:
272 kicadYfrac -= offsetYfrac;
276 wxLogWarning(
"Pin has unexpected orientation" );
319 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LABEL );
330 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
331 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
333 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
334 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
341 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NOTE
342 ||
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEXT_FRAME );
355 Text.Replace(
"~1",
"\n",
true );
369 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
370 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
377 wxASSERT(
ReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
387 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BEZIER );
391 for(
int i = 1; i <= locationCount; i++ )
393 const wxString si = std::to_string( i );
404 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYLINE );
408 for(
int i = 1; i <= locationCount; i++ )
410 const wxString si = std::to_string( i );
415 auto lineStyleExt =
ReadEnum( aProps,
"LINESTYLEEXT", 0, 3, ASCH_POLYLINE_LINESTYLE::SOLID );
425 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYGON );
429 for(
int i = 1; i <= locationCount; i++ )
431 const wxString si = std::to_string( i );
443 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
488 wxASSERT( record == ALTIUM_SCH_RECORD::ELLIPSE || record == ALTIUM_SCH_RECORD::ELLIPTICAL_ARC );
502 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LINE );
509 auto lineStyleExt =
ReadEnum( aProps,
"LINESTYLEEXT", 0, 3, ASCH_POLYLINE_LINESTYLE::SOLID );
517 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SIGNAL_HARNESS );
522 for(
int i = 1; i <= locationCount; i++ )
524 const wxString si = std::to_string( i );
537 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_CONNECTOR );
550 m_harnessConnectorSide = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::RIGHT );
558 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_ENTRY );
567 Side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
584 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_TYPE );
606 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE );
619 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_SYMBOL );
636 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_ENTRY );
641 side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
645 iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
646 style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
653 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POWER_PORT );
659 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
660 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
665 style = ReadEnum<ASCH_POWER_PORT_STYLE>( aProps,
"STYLE", 0, 10,
666 ASCH_POWER_PORT_STYLE::CIRCLE );
673 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PORT );
685 IOtype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
686 Style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
693 m_align = ReadEnum<ASCH_PORT_ALIGNMENT>( aProps,
"ALIGNMENT", 0, 2, ASCH_PORT_ALIGNMENT::CENTER );
699 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NO_ERC );
712 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NET_LABEL );
719 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
720 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
722 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
723 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
730 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS );
734 for(
int i = 1; i <= locationcount; i++ )
736 const wxString si = std::to_string( i );
748 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::WIRE );
752 for(
int i = 1; i <= locationcount; i++ )
754 const wxString si = std::to_string( i );
766 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::JUNCTION );
778 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMAGE );
795 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
797 const wxString sid = std::to_string( aId );
843 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
847 for(
int i = 1; i <= fontidcount; i++ )
848 fonts.emplace_back( aProps, i );
855 sheetSize = ReadEnum<ASCH_SHEET_SIZE>( aProps,
"SHEETSTYLE", 0, 17, ASCH_SHEET_SIZE::A4 );
857 aProps,
"WORKSPACEORIENTATION", 0, 1, ASCH_SHEET_WORKSPACEORIENTATION::LANDSCAPE );
864 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_NAME );
868 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
869 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
881 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::FILE_NAME );
885 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
886 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
898 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::DESIGNATOR );
904 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
905 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
907 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
908 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
918 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION );
932 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST );
939 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS_ENTRY );
951 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PARAMETER );
956 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
957 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
959 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
960 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
976 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 m_primaryConnectionPosition
ASCH_SHEET_ENTRY_SIDE m_harnessConnectorSide
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_PORT(const std::map< wxString, wxString > &aProps)
ASCH_PORT_ALIGNMENT m_align
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
std::vector< VECTOR2I > points
ASCH_SIGNAL_HARNESS(const std::map< wxString, wxString > &aProps)
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