72 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
108 return it->second.get();
118 const std::vector<SYMBOL_DEF>& aSymbolDefs )
121 std::map<std::string, const SYMBOL_DEF*> symDefByName;
124 symDefByName[sd.name] = &sd;
126 int gateCount =
static_cast<int>( aPartType.
gates.size() );
131 for(
int gi = 0; gi < gateCount; gi++ )
137 std::string decalName;
142 auto sdIt = symDefByName.find( decalName );
144 if( sdIt == symDefByName.end() )
152 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
156 shape->SetUnit( unit );
192 const std::vector<SYMBOL_DEF>& aSymbolDefs )
196 std::string cacheKey =
"parttype:" + aPartType.
name;
200 return it->second.get();
203 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( newSymbol );
215 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name;
219 return it->second.get();
221 if( aPartType.
gates.empty() )
229 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
254 bool hasPinNames =
false;
258 if( !
pin.pin_name.empty() )
271 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
279 const std::string& aPinNumber )
281 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name +
":" + aPinNumber;
285 return it->second.get();
291 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
298 for(
size_t p = 0; p < aSymbolDef.
pins.size(); p++ )
301 pin.number = aPinNumber;
303 if( !aPartType.
gates.empty() && p < aPartType.
gates[0].pins.size() )
305 pin.name = aPartType.
gates[0].pins[p].pin_name;
307 if( aPartType.
gates[0].pins[p].pin_type != 0 )
326 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
334 const std::vector<std::string>& aPinNumbers )
336 int unitCount =
static_cast<int>( aPinNumbers.size() );
342 std::map<std::string, const PARTTYPE_PIN*> ptPinById;
344 if( !aPartType.
gates.empty() )
347 ptPinById[ptPin.
pin_id] = &ptPin;
350 for(
int u = 0; u < unitCount; u++ )
356 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
360 shape->SetUnit( unit );
366 if( !aSymbolDef.
pins.empty() )
369 pin.number = aPinNumbers[u];
371 auto ptPinIt = ptPinById.find( aPinNumbers[u] );
373 if( ptPinIt != ptPinById.end() )
375 if( ptPinIt->second->pin_type != 0 )
378 if( !ptPinIt->second->pin_name.empty() )
379 pin.name = ptPinIt->second->pin_name;
407 const std::vector<std::string>& aPinNumbers,
408 const std::string& aCacheKey )
413 return it->second.get();
416 m_symbolCache[aCacheKey] = std::unique_ptr<LIB_SYMBOL>( newSymbol );
433 return it->second.get();
443 switch( aGraphic.
type )
448 bool hasArcs =
false;
452 if( pt.
arc.has_value() )
463 for(
const auto& pt : aGraphic.
points )
480 if( aGraphic.
points.size() >= 2 )
547 std::vector<SCH_SHAPE*>
result;
554 result.push_back( single );
566 for(
size_t i = 0; i + 1 < aGraphic.
points.size(); i++ )
574 if( cur.
arc.has_value() )
604 if( startPt == endPt )
631 if( aText.
size > 0.0 )
652 std::vector<SYMBOL_PIN> pins = aDecalPins;
654 for(
size_t p = 0; p < pins.size() && p < aGate.
pins.size(); p++ )
656 pins[p].name = aGate.
pins[p].pin_name;
657 pins[p].number = aGate.
pins[p].pin_id;
659 if( aGate.
pins[p].pin_type != 0 )
669 if( aPins.size() != 2 )
677 if( !
pin.name.empty() )
680 if(
pin.number ==
"A" )
682 else if(
pin.number ==
"K" )
688 return haveA && haveK;
697 if( aMapDiodeAK && aPin.
number ==
"A" )
699 pin->SetName( wxString::FromUTF8( aPin.
number ) );
700 pin->SetNumber( wxT(
"2" ) );
702 else if( aMapDiodeAK && aPin.
number ==
"K" )
704 pin->SetName( wxString::FromUTF8( aPin.
number ) );
705 pin->SetNumber( wxT(
"1" ) );
709 pin->SetName( wxString::FromUTF8( aPin.
name ) );
710 pin->SetNumber( wxString::FromUTF8( aPin.
number ) );
715 pin->SetPosition( pos );
719 pin->SetLength( length );
726 bool isVerticalDecal = ( aPin.
pin_decal_name.find(
"VRT" ) != std::string::npos );
727 int angle =
static_cast<int>( aPin.
rotation ) % 360;
729 if( isVerticalDecal )
733 else if( angle >= 45 && angle < 135 )
738 else if( angle >= 225 && angle < 315 )
742 else if( angle >= 135 && angle < 225 )
751 pin->SetOrientation( orientation );
755 pin->SetType( pinType );
762 else if( aPin.
clock )
765 pin->SetShape( pinShape );
768 pin->SetNumberTextSize( pinTextSize );
769 pin->SetNameTextSize( pinTextSize );
789 if( aUpperName ==
"GND" || aUpperName ==
"GNDA" || aUpperName ==
"GNDPWR" || aUpperName ==
"EARTH"
790 || aUpperName ==
"CHASSIS" )
795 if( aUpperName ==
"GNDD" || aUpperName ==
"PWR_BAR" )
798 if( aUpperName ==
"PWR_TRIANGLE" )
801 if( aUpperName ==
"VEE" || aUpperName ==
"VSS" )
812 for(
const VECTOR2I& point : aPoints )
825 pin->SetNumber( wxT(
"1" ) );
826 pin->SetName( wxString::FromUTF8( aKiCadName ) );
828 pin->SetVisible(
false );
831 pin->SetOrientation( aOrientation );
839 auto mm = [&](
double v )
850 std::string upper = aKiCadName;
851 std::transform( upper.begin(), upper.end(), upper.begin(),
852 [](
unsigned char c )
854 return std::toupper( c );
861 const std::array<std::tuple<double, double, double>, 3> bars{ std::tuple{ -1.27, 1.27, -1.27 },
862 std::tuple{ -0.762, 0.762, -1.778 },
863 std::tuple{ -0.254, 0.254, -2.286 } };
865 for(
const auto& [x1, x2, y] : bars )
892 VECTOR2I( mm( -0.762 ), mm( 1.27 ) ),
894 VECTOR2I( mm( 0.762 ), mm( 1.27 ) ) } );
932 const std::string& aPinType )
934 std::string upper = aDecalName;
935 std::transform( upper.begin(), upper.end(), upper.begin(),
936 [](
unsigned char c )
938 return std::toupper( c );
941 bool isPositive = !upper.empty() && upper[0] ==
'+';
942 bool isGround = ( aPinType ==
"G" );
944 if( upper.find(
"RAIL" ) != std::string::npos )
945 return isPositive ?
"PWR_BAR" :
"GNDD";
947 if( upper.find(
"ARROW" ) != std::string::npos )
948 return isPositive ?
"PWR_TRIANGLE" :
"VEE";
950 if( upper.find(
"BUBBLE" ) != std::string::npos )
951 return isPositive ?
"VCC" :
"VEE";
955 if( upper.find(
"CH" ) != std::string::npos )
989 if(
static_cast<SCH_SYMBOL*
>( item )->GetRef( &
path ).StartsWith( wxS(
"#PWR" ), &digits )
990 && digits.ToLong( &ordinal ) )
992 next = std::max(
next,
static_cast<int>( ordinal ) + 1 );
1002 const std::vector<PARTTYPE_DEF::SIGPIN>& aSigpins )
1008 std::set<wxString> existingPins;
1013 existingPins.insert(
static_cast<const SCH_PIN&
>( item ).GetNumber() );
1018 wxString pinNum = wxString::FromUTF8( sp.pin_number );
1020 if( existingPins.count( pinNum ) )
1024 pin->SetNumber( pinNum );
1025 pin->SetName( wxString::FromUTF8( sp.net_name ) );
1027 pin->SetVisible(
false );
1028 pin->SetLength( 0 );
1033 existingPins.insert( pinNum );
1059 std::string upper = aName;
1060 std::transform( upper.begin(), upper.end(), upper.begin(),
1061 [](
unsigned char c )
1063 return std::toupper( c );
1067 if( upper ==
"GND" || upper ==
"AGND" || upper ==
"DGND" || upper ==
"PGND" || upper ==
"EARTH"
1068 || upper ==
"CHASSIS" || upper ==
"VSS" || upper ==
"0V" )
1074 if( upper ==
"VCC" || upper ==
"VDD" || upper ==
"VEE" || upper ==
"VPP" || upper ==
"VBAT" || upper ==
"VBUS"
1075 || upper ==
"V+" || upper ==
"V-" )
1081 if( upper.length() >= 2 && ( upper[0] ==
'+' || upper[0] ==
'-' ) )
1091 std::string upper = aPadsName;
1092 std::transform( upper.begin(), upper.end(), upper.begin(),
1093 [](
unsigned char c )
1095 return std::toupper( c );
1101 const char* padsName;
1102 const char* kicadSymbol;
1105 static const PowerMapping mappings[] = {
1106 {
"GND",
"GND" }, {
"AGND",
"GND" }, {
"DGND",
"GNDD" }, {
"PGND",
"GNDPWR" }, {
"EARTH",
"Earth" },
1107 {
"CHASSIS",
"Chassis" }, {
"VSS",
"VSS" }, {
"0V",
"GND" }, {
"VCC",
"VCC" }, {
"VDD",
"VDD" },
1108 {
"VEE",
"VEE" }, {
"VPP",
"VPP" }, {
"VBAT",
"VBAT" }, {
"VBUS",
"VBUS" }, {
"V+",
"VCC" },
1109 {
"V-",
"VEE" }, {
"+5V",
"+5V" }, {
"-5V",
"-5V" }, {
"+3V3",
"+3V3" }, {
"+3.3V",
"+3V3" },
1110 {
"+12V",
"+12V" }, {
"-12V",
"-12V" }, {
"+15V",
"+15V" }, {
"-15V",
"-15V" }, {
"+1V8",
"+1V8" },
1111 {
"+2V5",
"+2V5" }, {
"+9V",
"+9V" }, {
"+24V",
"+24V" },
1114 for(
const auto& mapping : mappings )
1116 if( upper == mapping.padsName )
1126 if( upper.length() >= 2 && upper[0] ==
'+' )
1134 if( upper.length() >= 2 && upper[0] ==
'-' )
1142 return std::nullopt;
constexpr EDA_IU_SCALE schIUScale
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual void SetEnd(const VECTOR2I &aEnd)
void SetCenter(const VECTOR2I &aCenter)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
void SetFillMode(FILL_T aFill)
virtual void SetStart(const VECTOR2I &aStart)
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual void SetVisible(bool aVisible)
void SetTextAngleDegrees(double aOrientation)
EE_TYPE OfType(KICAD_T aType) const
A logical library item identifier and consists of various portions much like a URI.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Define a library symbol object.
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
void SetUnitCount(int aCount, bool aDuplicateDrawItems)
Set the units per symbol count.
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
SCH_FIELD & GetReferenceField()
Return reference to the reference designator field.
static PIN_TYPE ParsePinTypeChar(char aTypeChar)
int mapPinType(PIN_TYPE aPadsType)
LIB_SYMBOL * BuildMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Build a composite multi-unit symbol from a multi-gate PARTTYPE.
bool HasSymbol(const std::string &aName) const
const PARAMETERS & m_params
void AddHiddenPowerPins(LIB_SYMBOL *aSymbol, const std::vector< PARTTYPE_DEF::SIGPIN > &aSigpins)
Add hidden PT_POWER_IN pins from PARTTYPE SIGPIN entries, skipping duplicate numbers.
static std::vector< SYMBOL_PIN > applyGateOverrides(const std::vector< SYMBOL_PIN > &aDecalPins, const GATE_DEF &aGate)
Return the decal's pins with the gate's name, number and type overrides applied.
LIB_SYMBOL * GetSymbol(const std::string &aName) const
~PADS_SCH_SYMBOL_BUILDER()
int toKiCadUnits(double aPadsValue) const
LIB_SYMBOL * GetOrCreateMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Return the cached multi-unit symbol for the PARTTYPE, building it if needed, so all instances of the ...
static std::optional< LIB_ID > GetKiCadPowerSymbolId(const std::string &aPadsName)
Map a PADS power symbol name to a KiCad power library LIB_ID, or nullopt if unmapped.
std::vector< SCH_SHAPE * > createShapes(const SYMBOL_GRAPHIC &aGraphic)
LIB_SYMBOL * BuildKiCadPowerSymbol(const std::string &aKiCadName)
Build a power symbol using hard-coded KiCad-standard graphics, or nullptr if the name is unrecognized...
PADS_SCH_SYMBOL_BUILDER(const PARAMETERS &aParams)
SCH_PIN * createPin(const SYMBOL_PIN &aPin, LIB_SYMBOL *aParent, bool aMapDiodeAK=false)
static bool IsPowerSymbol(const std::string &aName)
static std::string GetPowerStyleFromVariant(const std::string &aDecalName, const std::string &aPinType)
Map a PADS special_variant decal name and pin type to a power symbol style name for BuildKiCadPowerSy...
SCH_SHAPE * createShape(const SYMBOL_GRAPHIC &aGraphic)
Create a SCH_SHAPE from a PADS graphic element.
LIB_SYMBOL * GetOrCreateSymbol(const SYMBOL_DEF &aSymbolDef)
Return the cached symbol for the given definition, building and caching it if needed.
LIB_SYMBOL * GetOrCreateConnectorPinSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::string &aPinNumber)
Return a connector symbol variant carrying a specific pin number, since PADS connectors reuse one dec...
LIB_SYMBOL * GetOrCreateMultiUnitConnectorSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::vector< std::string > &aPinNumbers, const std::string &aCacheKey)
Return the cached multi-unit connector symbol, building it if needed.
LIB_SYMBOL * BuildMultiUnitConnectorSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::vector< std::string > &aPinNumbers)
Build a multi-unit connector symbol with one unit per pin, letting all of a connector's individually ...
std::map< std::string, std::unique_ptr< LIB_SYMBOL > > m_symbolCache
LIB_SYMBOL * BuildSymbol(const SYMBOL_DEF &aSymbolDef)
Build a KiCad LIB_SYMBOL from a PADS symbol definition.
static bool isDiodeAKPinSet(const std::vector< SYMBOL_PIN > &aPins)
True when aPins is a bare two-pin A/K pair, i.e.
SCH_TEXT * createSymbolText(const SYMBOL_TEXT &aText, int aUnit=0)
Build the configured SCH_TEXT for one symbol text field, or nullptr when its content is empty.
LIB_SYMBOL * GetOrCreatePartTypeSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef)
Return a single-gate symbol with PARTTYPE pin overrides applied at build time.
static int NextFreePowerOrdinal(SCH_SHEET *aSheet)
Return the first 1-based ordinal that no "#PWRnnnn" reference under aSheet uses.
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual void SetUnit(int aUnit)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
void SetStroke(const STROKE_PARAMS &aStroke) override
void AddPoint(const VECTOR2I &aPosition)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Simple container to manage line stroke parameters.
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
@ FILLED_SHAPE
Fill with object color.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
double m_PadsSchTextWidthScale
PADS text width scale factor for schematic imports.
double m_PadsSchTextHeightScale
PADS text height scale factor for schematic imports.
LINE_STYLE PadsLineStyleToKiCad(int aPadsStyle)
Convert a PADS line style integer to a KiCad LINE_STYLE enum value.
VECTOR2I padsSchArcMidpoint(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter)
Midpoint of the arc through aStart and aEnd about aCenter, on the minor-arc side (the perpendicular b...
POWER_STYLE
The distinct body shapes KiCad power symbols are drawn with.
static SCH_SHAPE * addPolyline(LIB_SYMBOL *aSymbol, const std::vector< VECTOR2I > &aPoints, int aWidth=0)
static void addPowerPin(LIB_SYMBOL *aSymbol, const std::string &aKiCadName, PIN_ORIENTATION aOrientation)
static POWER_STYLE powerStyleFromName(const std::string &aUpperName)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
@ PT_INPUT
usual pin input: must be connected
@ PT_TRISTATE
tri state bus pin
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_OPENEMITTER
pin type open emitter
@ PT_OPENCOLLECTOR
pin type open collector
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
PIN_ORIENTATION
The symbol library pin object orientations.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
LINE_STYLE
Dashed line types.
std::vector< std::string > decal_names
std::vector< PARTTYPE_PIN > pins
std::optional< ARC_DATA > arc
std::vector< GATE_DEF > gates
std::vector< SYMBOL_GRAPHIC > graphics
std::vector< SYMBOL_PIN > pins
std::vector< SYMBOL_TEXT > texts
std::vector< GRAPHIC_POINT > points
std::string pin_decal_name
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I