KiCad PCB EDA Suite
altium_parser_sch.cpp File Reference
#include <iostream>
#include <unordered_map>
#include <base_units.h>
#include <ki_exception.h>
#include <wx/log.h>
#include "plugins/altium/altium_parser.h"
#include "sch_plugins/altium/altium_parser_sch.h"

Go to the source code of this file.

Functions

ALTIUM_SCH_RECORD ReadRecord (const std::map< wxString, wxString > &aProps)
 
constexpr int Altium2KiCadUnit (const int val, const int frac)
 
int ReadKiCadUnitFrac (const std::map< wxString, wxString > &aProps, const wxString &aKey)
 
int ReadKiCadUnitFrac1 (const std::map< wxString, wxString > &aProps, const wxString &aKey)
 
int ReadOwnerIndex (const std::map< wxString, wxString > &aProperties)
 
int ReadOwnerPartId (const std::map< wxString, wxString > &aProperties)
 
template<typename T >
ReadEnum (const std::map< wxString, wxString > &aProps, const wxString &aKey, int aLower, int aUpper, T aDefault)
 
VECTOR2I ASchSheetGetSize (ASCH_SHEET_SIZE aSheetSize)
 

Function Documentation

◆ Altium2KiCadUnit()

constexpr int Altium2KiCadUnit ( const int  val,
const int  frac 
)
constexpr

Definition at line 44 of file altium_parser_sch.cpp.

45{
46 constexpr double int_limit = ( std::numeric_limits<int>::max() - 10 ) / 2.54;
47
48 double dbase = 10 * schIUScale.MilsToIU( val );
49 double dfrac = schIUScale.MilsToIU( frac ) / 10000.0;
50
51 return KiROUND( Clamp<double>( -int_limit, ( dbase + dfrac ) / 10.0, int_limit ) ) * 10;
52}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References KiROUND(), EDA_IU_SCALE::MilsToIU(), and schIUScale.

Referenced by ASCH_PIN::ASCH_PIN(), ReadKiCadUnitFrac(), and ReadKiCadUnitFrac1().

◆ ASchSheetGetSize()

VECTOR2I ASchSheetGetSize ( ASCH_SHEET_SIZE  aSheetSize)

Definition at line 762 of file altium_parser_sch.cpp.

763{
764 // From: https://github.com/vadmium/python-altium/blob/master/format.md#sheet
765 switch( aSheetSize )
766 {
767 default:
768 case ASCH_SHEET_SIZE::A4: return { 1150, 760 };
769 case ASCH_SHEET_SIZE::A3: return { 1550, 1110 };
770 case ASCH_SHEET_SIZE::A2: return { 2230, 1570 };
771 case ASCH_SHEET_SIZE::A1: return { 3150, 2230 };
772 case ASCH_SHEET_SIZE::A0: return { 4460, 3150 };
773 case ASCH_SHEET_SIZE::A: return { 950, 750 };
774 case ASCH_SHEET_SIZE::B: return { 1500, 950 };
775 case ASCH_SHEET_SIZE::C: return { 2000, 1500 };
776 case ASCH_SHEET_SIZE::D: return { 3200, 2000 };
777 case ASCH_SHEET_SIZE::E: return { 4200, 3200 };
778 case ASCH_SHEET_SIZE::LETTER: return { 1100, 850 };
779 case ASCH_SHEET_SIZE::LEGAL: return { 1400, 850 };
780 case ASCH_SHEET_SIZE::TABLOID: return { 1700, 1100 };
781 case ASCH_SHEET_SIZE::ORCAD_A: return { 990, 790 };
782 case ASCH_SHEET_SIZE::ORCAD_B: return { 1540, 990 };
783 case ASCH_SHEET_SIZE::ORCAD_C: return { 2060, 1560 };
784 case ASCH_SHEET_SIZE::ORCAD_D: return { 3260, 2060 };
785 case ASCH_SHEET_SIZE::ORCAD_E: return { 4280, 3280 };
786 }
787}

References A, A0, A1, A2, A3, A4, B, C, D, E, LEGAL, LETTER, ORCAD_A, ORCAD_B, ORCAD_C, ORCAD_D, ORCAD_E, and TABLOID.

◆ ReadEnum()

template<typename T >
T ReadEnum ( const std::map< wxString, wxString > &  aProps,
const wxString &  aKey,
int  aLower,
int  aUpper,
aDefault 
)

Definition at line 87 of file altium_parser_sch.cpp.

89{
90 int value = ALTIUM_PARSER::ReadInt( aProps, aKey, static_cast<int>( aDefault ) );
91
92 if( value < aLower || value > aUpper )
93 return aDefault;
94 else
95 return static_cast<T>( value );
96}
static int ReadInt(const std::map< wxString, wxString > &aProps, const wxString &aKey, int aDefault)

References ALTIUM_PARSER::ReadInt().

◆ ReadKiCadUnitFrac()

int ReadKiCadUnitFrac ( const std::map< wxString, wxString > &  aProps,
const wxString &  aKey 
)

◆ ReadKiCadUnitFrac1()

int ReadKiCadUnitFrac1 ( const std::map< wxString, wxString > &  aProps,
const wxString &  aKey 
)

Definition at line 64 of file altium_parser_sch.cpp.

65{
66 // a unit is stored using two fields, denoting the size in mils and a fraction size
67 // Dunno why Altium invents different units for the same purpose
68 int key = ALTIUM_PARSER::ReadInt( aProps, aKey, 0 );
69 int keyFrac = ALTIUM_PARSER::ReadInt( aProps, aKey + "_FRAC1", 0 );
70 return Altium2KiCadUnit( key * 10, keyFrac );
71}

References Altium2KiCadUnit(), and ALTIUM_PARSER::ReadInt().

Referenced by ASCH_HARNESS_ENTRY::ASCH_HARNESS_ENTRY(), and ASCH_SHEET_ENTRY::ASCH_SHEET_ENTRY().

◆ ReadOwnerIndex()

◆ ReadOwnerPartId()

◆ ReadRecord()

ALTIUM_SCH_RECORD ReadRecord ( const std::map< wxString, wxString > &  aProps)

Definition at line 37 of file altium_parser_sch.cpp.

38{
39 int recordId = ALTIUM_PARSER::ReadInt( aProps, "RECORD", 0 );
40 return static_cast<ALTIUM_SCH_RECORD>( recordId );
41}
ALTIUM_SCH_RECORD

References ALTIUM_PARSER::ReadInt().

Referenced by ASCH_ARC::ASCH_ARC(), ASCH_BEZIER::ASCH_BEZIER(), ASCH_BUS::ASCH_BUS(), ASCH_BUS_ENTRY::ASCH_BUS_ENTRY(), ASCH_DESIGNATOR::ASCH_DESIGNATOR(), ASCH_ELLIPSE::ASCH_ELLIPSE(), ASCH_FILE_NAME::ASCH_FILE_NAME(), ASCH_HARNESS_CONNECTOR::ASCH_HARNESS_CONNECTOR(), ASCH_HARNESS_ENTRY::ASCH_HARNESS_ENTRY(), ASCH_HARNESS_TYPE::ASCH_HARNESS_TYPE(), ASCH_IMAGE::ASCH_IMAGE(), ASCH_IMPLEMENTATION::ASCH_IMPLEMENTATION(), ASCH_IMPLEMENTATION_LIST::ASCH_IMPLEMENTATION_LIST(), ASCH_JUNCTION::ASCH_JUNCTION(), ASCH_LABEL::ASCH_LABEL(), ASCH_LINE::ASCH_LINE(), ASCH_NET_LABEL::ASCH_NET_LABEL(), ASCH_NO_ERC::ASCH_NO_ERC(), ASCH_NOTE::ASCH_NOTE(), ASCH_PARAMETER::ASCH_PARAMETER(), ASCH_PIN::ASCH_PIN(), ASCH_POLYGON::ASCH_POLYGON(), ASCH_POLYLINE::ASCH_POLYLINE(), ASCH_PORT::ASCH_PORT(), ASCH_POWER_PORT::ASCH_POWER_PORT(), ASCH_RECTANGLE::ASCH_RECTANGLE(), ASCH_ROUND_RECTANGLE::ASCH_ROUND_RECTANGLE(), ASCH_SHEET::ASCH_SHEET(), ASCH_SHEET_ENTRY::ASCH_SHEET_ENTRY(), ASCH_SHEET_FONT::ASCH_SHEET_FONT(), ASCH_SHEET_NAME::ASCH_SHEET_NAME(), ASCH_SHEET_SYMBOL::ASCH_SHEET_SYMBOL(), ASCH_SIGNAL_HARNESS::ASCH_SIGNAL_HARNESS(), ASCH_SYMBOL::ASCH_SYMBOL(), ASCH_TEXT_FRAME::ASCH_TEXT_FRAME(), and ASCH_WIRE::ASCH_WIRE().