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 );
146 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PIN );
164 || symbolOuterEdgeInt == 4 || symbolOuterEdgeInt == 17 ) ?
166 ASCH_PIN_SYMBOL_OUTEREDGE::NO_SYMBOL;
169 symbolInnerEdge = ( symbolInnerEdgeInt == 0 || symbolInnerEdgeInt == 3 ) ?
171 ASCH_PIN_SYMBOL_INNEREDGE::NO_SYMBOL;
172 electrical = ReadEnum<ASCH_PIN_ELECTRICAL>( aProps,
"ELECTRICAL", 0, 7,
173 ASCH_PIN_ELECTRICAL::INPUT );
193 int kicadXfrac = xfrac;
195 int kicadYfrac = yfrac;
199 case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
204 case ASCH_RECORD_ORIENTATION::UPWARDS:
209 case ASCH_RECORD_ORIENTATION::LEFTWARDS:
214 case ASCH_RECORD_ORIENTATION::DOWNWARDS:
220 wxLogWarning(
"Pin has unexpected orientation" );
231 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LABEL );
244 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
245 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
247 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
248 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
254 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NOTE
255 ||
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::TEXT_FRAME );
268 Text.Replace(
"~1",
"\n",
true );
279 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
280 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
287 wxASSERT(
ReadRecord( aProperties ) == ALTIUM_SCH_RECORD::NOTE );
295 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BEZIER );
303 for(
int i = 1; i <= locationCount; i++ )
305 const wxString si = std::to_string( i );
316 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYLINE );
324 for(
int i = 1; i <= locationCount; i++ )
326 const wxString si = std::to_string( i );
338 LineStyle = linestyleVar >= 0 && linestyleVar <= 3 ?
340 ASCH_POLYLINE_LINESTYLE::SOLID;
346 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POLYGON );
354 for(
int i = 1; i <= locationCount; i++ )
356 const wxString si = std::to_string( i );
371 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ROUND_RECTANGLE );
420 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ELLIPSE );
439 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::LINE );
456 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SIGNAL_HARNESS );
462 for(
int i = 1; i <= locationCount; i++ )
464 const wxString si = std::to_string( i );
478 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_CONNECTOR );
497 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_ENTRY );
509 Side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
525 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::HARNESS_TYPE );
546 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::RECTANGLE );
568 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_SYMBOL );
584 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_ENTRY );
592 side = ReadEnum<ASCH_SHEET_ENTRY_SIDE>( aProps,
"SIDE", 0, 3, ASCH_SHEET_ENTRY_SIDE::LEFT );
596 iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
597 style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
603 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::POWER_PORT );
610 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
611 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
616 style = ReadEnum<ASCH_POWER_PORT_STYLE>( aProps,
"STYLE", 0, 10,
617 ASCH_POWER_PORT_STYLE::CIRCLE );
623 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PORT );
636 IOtype = ReadEnum<ASCH_PORT_IOTYPE>( aProps,
"IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
637 Style = ReadEnum<ASCH_PORT_STYLE>( aProps,
"STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
644 Alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps,
"ALIGNMENT", 1, 3,
645 ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
651 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NO_ERC );
663 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::NET_LABEL );
670 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
671 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
677 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS );
683 for(
int i = 1; i <= locationcount; i++ )
685 const wxString si = std::to_string( i );
696 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::WIRE );
702 for(
int i = 1; i <= locationcount; i++ )
704 const wxString si = std::to_string( i );
715 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::JUNCTION );
726 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMAGE );
746 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
748 const wxString sid = std::to_string( aId );
793 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET );
797 for(
int i = 1; i <= fontidcount; i++ )
798 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 );
808 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::SHEET_NAME );
815 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
816 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
827 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::FILE_NAME );
834 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
835 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
846 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::DESIGNATOR );
854 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
855 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
857 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
858 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
867 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION );
879 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::IMPLEMENTATION_LIST );
887 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::BUS_ENTRY );
898 wxASSERT(
ReadRecord( aProps ) == ALTIUM_SCH_RECORD::PARAMETER );
906 justification = ReadEnum<ASCH_LABEL_JUSTIFICATION>( aProps,
"JUSTIFICATION", 0, 8,
907 ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT );
909 orientation = ReadEnum<ASCH_RECORD_ORIENTATION>( aProps,
"ORIENTATION", 0, 3,
910 ASCH_RECORD_ORIENTATION::RIGHTWARDS );
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)
ASCH_PIN_SYMBOL_INNEREDGE
const int ALTIUM_COMPONENT_NONE
ASCH_PIN_SYMBOL_OUTEREDGE
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)
#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_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_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_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_LINE(const std::map< wxString, wxString > &aProps)
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_PARAMETER(const std::map< wxString, wxString > &aProps)
ASCH_RECORD_ORIENTATION orientation
ASCH_LABEL_JUSTIFICATION justification
ASCH_PIN_SYMBOL_INNEREDGE symbolInnerEdge
ASCH_PIN_SYMBOL_OUTEREDGE symbolOuterEdge
ASCH_PIN_SYMBOL_OUTER symbolOuter
ASCH_PIN_ELECTRICAL electrical
ASCH_PIN_SYMBOL_INNER symbolInner
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".