26#include <unordered_map>
46 constexpr double int_limit = ( std::numeric_limits<int>::max() - 10 ) / 2.54;
51 return KiROUND( Clamp<double>( -int_limit, ( dbase + dfrac ) / 10.0, int_limit ) ) * 10;
87T
ReadEnum(
const std::map<wxString, wxString>& aProps,
const wxString& aKey,
int aLower,
88 int aUpper, T aDefault )
92 if( value < aLower || value > aUpper )
95 return static_cast<T
>( value );
103 uint32_t dataSize = aReader.
Read<uint32_t>();
115 uint32_t dataSize = aReader.
Read<uint32_t>();
125 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::COMPONENT );
147 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PIN );
168 electrical = ReadEnum<ASCH_PIN_ELECTRICAL>( aProps,
"ELECTRICAL", 0, 7,
169 ASCH_PIN_ELECTRICAL::INPUT );
174 hidden = ( pinconglomerate & 0x04 ) != 0;
178 locked = ( pinconglomerate & 0x40 ) != 0;
193 int kicadXfrac = xfrac;
195 int kicadYfrac = yfrac;
198 int offsetYfrac = pfrac;
203 offsetYfrac = -offsetYfrac;
208 case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
210 kicadXfrac += offsetYfrac;
213 case ASCH_RECORD_ORIENTATION::UPWARDS:
215 kicadYfrac += offsetYfrac;
218 case ASCH_RECORD_ORIENTATION::LEFTWARDS:
220 kicadXfrac -= offsetYfrac;
223 case ASCH_RECORD_ORIENTATION::DOWNWARDS:
225 kicadYfrac -= offsetYfrac;
229 wxLogWarning(
"Pin has unexpected orientation" );
271 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LABEL );
282 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
283 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
285 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
286 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
293 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NOTE
294 ||
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEXT_FRAME );
307 Text.Replace(
"~1",
"\n",
true );
321 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
322 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
329 wxASSERT(
ReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
339 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BEZIER );
343 for(
int i = 1; i <= locationCount; i++ )
345 const wxString si = std::to_string( i );
356 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYLINE );
360 for(
int i = 1; i <= locationCount; i++ )
362 const wxString si = std::to_string( i );
367 auto lineStyleExt =
ReadEnum( aProps,
"LINESTYLEEXT", 0, 3, ASCH_POLYLINE_LINESTYLE::SOLID );
377 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYGON );
381 for(
int i = 1; i <= locationCount; i++ )
383 const wxString si = std::to_string( i );
395 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
432 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ELLIPSE );
448 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LINE );
455 auto lineStyleExt =
ReadEnum( aProps,
"LINESTYLEEXT", 0, 3, ASCH_POLYLINE_LINESTYLE::SOLID );
463 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SIGNAL_HARNESS );
468 for(
int i = 1; i <= locationCount; i++ )
470 const wxString si = std::to_string( i );
483 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_CONNECTOR );
502 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_ENTRY );
511 Side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
528 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_TYPE );
550 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE );
563 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_SYMBOL );
580 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_ENTRY );
585 side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
589 iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
590 style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
597 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POWER_PORT );
603 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
604 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
609 style = ReadEnum<ASCH_POWER_PORT_STYLE>( aProps,
"STYLE", 0, 10,
610 ASCH_POWER_PORT_STYLE::CIRCLE );
617 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PORT );
629 IOtype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
630 Style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
637 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
638 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
644 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NO_ERC );
657 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NET_LABEL );
664 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
665 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
667 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
668 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
675 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS );
679 for(
int i = 1; i <= locationcount; i++ )
681 const wxString si = std::to_string( i );
693 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::WIRE );
697 for(
int i = 1; i <= locationcount; i++ )
699 const wxString si = std::to_string( i );
711 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::JUNCTION );
723 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMAGE );
740 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
742 const wxString sid = std::to_string( aId );
788 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
792 for(
int i = 1; i <= fontidcount; i++ )
793 fonts.emplace_back( aProps, i );
800 sheetSize = ReadEnum<ASCH_SHEET_SIZE>( aProps,
"SHEETSTYLE", 0, 17, ASCH_SHEET_SIZE::A4 );
802 aProps,
"WORKSPACEORIENTATION", 0, 1, ASCH_SHEET_WORKSPACEORIENTATION::LANDSCAPE );
809 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_NAME );
813 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
814 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
826 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::FILE_NAME );
830 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
831 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
843 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::DESIGNATOR );
849 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
850 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
852 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
853 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
863 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION );
877 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST );
884 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS_ENTRY );
896 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PARAMETER );
901 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
902 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
904 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
905 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
921 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
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)
static wxString ReadString(const std::map< wxString, wxString > &aProps, const wxString &aKey, const wxString &aDefault)
std::vector< char > ReadVector(size_t aSize)
static double ReadDouble(const std::map< wxString, wxString > &aProps, const wxString &aKey, double aDefault)
static bool ReadBool(const std::map< wxString, wxString > &aProps, const wxString &aKey, bool aDefault)
void Skip(size_t aLength)
static PTYPE FromInt(int aInt)
#define THROW_IO_ERROR(msg)
ASCH_ADDITIONAL_FILE(ALTIUM_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_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(ALTIUM_PARSER &aReader)
wxString componentdescription
ASCH_SYMBOL(const std::map< wxString, wxString > &aProps)
wxString sourcelibraryname
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
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".