66 for(
const auto& graphic : aSymbolDef.
graphics )
68 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
75 for(
const auto&
pin : aSymbolDef.
pins )
84 for(
const auto&
text : aSymbolDef.
texts )
86 if(
text.content.empty() )
96 int charHeight =
static_cast<int>(
98 int charWidth =
static_cast<int>(
103 if(
text.rotation != 0.0 )
121 return it->second.get();
131 const PARTTYPE_DEF& aPartType,
const std::vector<SYMBOL_DEF>& aSymbolDefs )
134 std::map<std::string, const SYMBOL_DEF*> symDefByName;
136 for(
const auto& sd : aSymbolDefs )
137 symDefByName[sd.name] = &sd;
139 int gateCount =
static_cast<int>( aPartType.
gates.size() );
144 for(
int gi = 0; gi < gateCount; gi++ )
150 std::string decalName;
155 auto sdIt = symDefByName.find( decalName );
157 if( sdIt == symDefByName.end() )
163 for(
const auto& graphic : symDef.
graphics )
165 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
169 shape->SetUnit( unit );
175 for(
size_t p = 0; p < symDef.
pins.size(); p++ )
179 if( p < gate.
pins.size() )
181 pin.name = gate.
pins[p].pin_name;
182 pin.number = gate.
pins[p].pin_id;
184 if( gate.
pins[p].pin_type != 0 )
200 if(
text.content.empty() )
208 if(
text.size > 0.0 )
211 int charHeight =
static_cast<int>(
213 int charWidth =
static_cast<int>(
218 if(
text.rotation != 0.0 )
234 const PARTTYPE_DEF& aPartType,
const std::vector<SYMBOL_DEF>& aSymbolDefs )
238 std::string cacheKey =
"parttype:" + aPartType.
name;
242 return it->second.get();
245 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( newSymbol );
257 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name;
261 return it->second.get();
263 if( aPartType.
gates.empty() )
269 for(
const auto& graphic : aSymbolDef.
graphics )
271 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
279 for(
size_t p = 0; p < aSymbolDef.
pins.size(); p++ )
283 if( p < gate.
pins.size() )
285 pin.name = gate.
pins[p].pin_name;
286 pin.number = gate.
pins[p].pin_id;
288 if( gate.
pins[p].pin_type != 0 )
298 for(
const auto&
text : aSymbolDef.
texts )
300 if(
text.content.empty() )
308 if(
text.size > 0.0 )
311 int charHeight =
static_cast<int>(
313 int charWidth =
static_cast<int>(
318 if(
text.rotation != 0.0 )
325 bool hasPinNames =
false;
327 for(
const auto&
pin : gate.
pins )
329 if( !
pin.pin_name.empty() )
342 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
350 const std::string& aPinNumber )
352 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name +
":" + aPinNumber;
356 return it->second.get();
360 for(
const auto& graphic : aSymbolDef.
graphics )
362 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
369 for(
size_t p = 0; p < aSymbolDef.
pins.size(); p++ )
372 pin.number = aPinNumber;
374 if( !aPartType.
gates.empty() && p < aPartType.
gates[0].pins.size() )
376 pin.name = aPartType.
gates[0].pins[p].pin_name;
378 if( aPartType.
gates[0].pins[p].pin_type != 0 )
388 for(
const auto&
text : aSymbolDef.
texts )
390 if(
text.content.empty() )
398 if(
text.size > 0.0 )
401 int charHeight =
static_cast<int>(
403 int charWidth =
static_cast<int>(
408 if(
text.rotation != 0.0 )
417 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
425 const std::vector<std::string>& aPinNumbers )
427 int unitCount =
static_cast<int>( aPinNumbers.size() );
433 std::map<std::string, const PARTTYPE_PIN*> ptPinById;
435 if( !aPartType.
gates.empty() )
437 for(
const auto& ptPin : aPartType.
gates[0].pins )
438 ptPinById[ptPin.pin_id] = &ptPin;
441 for(
int u = 0; u < unitCount; u++ )
445 for(
const auto& graphic : aSymbolDef.
graphics )
447 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
451 shape->SetUnit( unit );
457 if( !aSymbolDef.
pins.empty() )
460 pin.number = aPinNumbers[u];
462 auto ptPinIt = ptPinById.find( aPinNumbers[u] );
464 if( ptPinIt != ptPinById.end() )
466 if( ptPinIt->second->pin_type != 0 )
469 if( !ptPinIt->second->pin_name.empty() )
470 pin.name = ptPinIt->second->pin_name;
482 for(
const auto&
text : aSymbolDef.
texts )
484 if(
text.content.empty() )
492 if(
text.size > 0.0 )
495 int charHeight =
static_cast<int>(
497 int charWidth =
static_cast<int>(
502 if(
text.rotation != 0.0 )
519 const std::vector<std::string>& aPinNumbers,
const std::string& aCacheKey )
524 return it->second.get();
527 m_symbolCache[aCacheKey] = std::unique_ptr<LIB_SYMBOL>( newSymbol );
544 return it->second.get();
554 switch( aGraphic.
type )
559 bool hasArcs =
false;
561 for(
const auto& pt : aGraphic.
points )
563 if( pt.arc.has_value() )
574 for(
const auto& pt : aGraphic.
points )
592 if( aGraphic.
points.size() >= 2 )
663 std::vector<SCH_SHAPE*>
result;
670 result.push_back( single );
682 for(
size_t i = 0; i + 1 < aGraphic.
points.size(); i++ )
690 if( cur.
arc.has_value() )
700 double sx = startPt.
x -
center.x;
701 double sy = startPt.
y -
center.y;
702 double ex = endPt.
x -
center.x;
703 double ey = endPt.
y -
center.y;
704 double radius = std::sqrt( sx * sx + sy * sy );
708 double mlen = std::sqrt( mx * mx + my * my );
745 if( startPt == endPt )
769 pin->SetName( wxString::FromUTF8( aPin.
name ) );
770 pin->SetNumber( wxString::FromUTF8( aPin.
number ) );
774 pin->SetPosition( pos );
778 pin->SetLength( length );
785 bool isVerticalDecal = ( aPin.
pin_decal_name.find(
"VRT" ) != std::string::npos );
786 int angle =
static_cast<int>( aPin.
rotation ) % 360;
788 if( isVerticalDecal )
793 else if( angle >= 45 && angle < 135 )
799 else if( angle >= 225 && angle < 315 )
804 else if( angle >= 135 && angle < 225 )
815 pin->SetOrientation( orientation );
819 pin->SetType( pinType );
826 else if( aPin.
clock )
829 pin->SetShape( pinShape );
832 pin->SetNumberTextSize( pinTextSize );
833 pin->SetNameTextSize( pinTextSize );
842 auto mm = [&](
double v ) {
return schIUScale.mmToIU( v ); };
850 std::string upper = aKiCadName;
851 std::transform( upper.begin(), upper.end(), upper.begin(),
852 [](
unsigned char c ) { return std::toupper( c ); } );
854 bool isGround = ( upper ==
"GND" || upper ==
"GNDA" || upper ==
"GNDPWR" );
855 bool isGNDD = ( upper ==
"GNDD" );
856 bool isPwrBar = ( upper ==
"PWR_BAR" );
857 bool isPwrTriangle = ( upper ==
"PWR_TRIANGLE" );
858 bool isVEE = ( upper ==
"VEE" || upper ==
"VSS" );
859 bool isEarth = ( upper ==
"EARTH" || upper ==
"CHASSIS" );
862 bool isVCC = !isGround && !isGNDD && !isPwrBar && !isPwrTriangle
863 && !isVEE && !isEarth;
879 pin->SetNumber( wxT(
"1" ) );
880 pin->SetName( wxString::FromUTF8( aKiCadName ) );
882 pin->SetVisible(
false );
905 pin->SetNumber( wxT(
"1" ) );
906 pin->SetName( wxString::FromUTF8( aKiCadName ) );
908 pin->SetVisible(
false );
933 pin->SetNumber( wxT(
"1" ) );
934 pin->SetName( wxString::FromUTF8( aKiCadName ) );
936 pin->SetVisible(
false );
942 else if( isPwrTriangle )
961 pin->SetNumber( wxT(
"1" ) );
962 pin->SetName( wxString::FromUTF8( aKiCadName ) );
964 pin->SetVisible(
false );
992 pin->SetNumber( wxT(
"1" ) );
993 pin->SetName( wxString::FromUTF8( aKiCadName ) );
995 pin->SetVisible(
false );
1029 pin->SetNumber( wxT(
"1" ) );
1030 pin->SetName( wxString::FromUTF8( aKiCadName ) );
1032 pin->SetVisible(
false );
1033 pin->SetLength( 0 );
1060 pin->SetNumber( wxT(
"1" ) );
1061 pin->SetName( wxString::FromUTF8( aKiCadName ) );
1063 pin->SetVisible(
false );
1064 pin->SetLength( 0 );
1078 const std::string& aPinType )
1080 std::string upper = aDecalName;
1081 std::transform( upper.begin(), upper.end(), upper.begin(),
1082 [](
unsigned char c ) { return std::toupper( c ); } );
1084 bool isPositive = !upper.empty() && upper[0] ==
'+';
1085 bool isGround = ( aPinType ==
"G" );
1087 if( upper.find(
"RAIL" ) != std::string::npos )
1088 return isPositive ?
"PWR_BAR" :
"GNDD";
1090 if( upper.find(
"ARROW" ) != std::string::npos )
1091 return isPositive ?
"PWR_TRIANGLE" :
"VEE";
1093 if( upper.find(
"BUBBLE" ) != std::string::npos )
1094 return isPositive ?
"VCC" :
"VEE";
1098 if( upper.find(
"CH" ) != std::string::npos )
1112 LIB_SYMBOL* aSymbol,
const std::vector<PARTTYPE_DEF::SIGPIN>& aSigpins )
1118 std::set<wxString> existingPins;
1123 existingPins.insert(
static_cast<const SCH_PIN&
>( item ).GetNumber() );
1126 for(
const auto& sp : aSigpins )
1128 wxString pinNum = wxString::FromUTF8( sp.pin_number );
1130 if( existingPins.count( pinNum ) )
1134 pin->SetNumber( pinNum );
1135 pin->SetName( wxString::FromUTF8( sp.net_name ) );
1137 pin->SetVisible(
false );
1138 pin->SetLength( 0 );
1143 existingPins.insert( pinNum );
1169 std::string upper = aName;
1170 std::transform( upper.begin(), upper.end(), upper.begin(),
1171 [](
unsigned char c ) { return std::toupper( c ); } );
1174 if( upper ==
"GND" || upper ==
"AGND" || upper ==
"DGND" || upper ==
"PGND" ||
1175 upper ==
"EARTH" || upper ==
"CHASSIS" || upper ==
"VSS" || upper ==
"0V" )
1181 if( upper ==
"VCC" || upper ==
"VDD" || upper ==
"VEE" || upper ==
"VPP" ||
1182 upper ==
"VBAT" || upper ==
"VBUS" || upper ==
"V+" || upper ==
"V-" )
1188 if( upper.length() >= 2 && ( upper[0] ==
'+' || upper[0] ==
'-' ) )
1198 std::string upper = aPadsName;
1199 std::transform( upper.begin(), upper.end(), upper.begin(),
1200 [](
unsigned char c ) { return std::toupper( c ); } );
1205 const char* padsName;
1206 const char* kicadSymbol;
1209 static const PowerMapping mappings[] = {
1213 {
"PGND",
"GNDPWR" },
1214 {
"EARTH",
"Earth" },
1215 {
"CHASSIS",
"Chassis" },
1229 {
"+3.3V",
"+3V3" },
1240 for(
const auto& mapping : mappings )
1242 if( upper == mapping.padsName )
1252 if( upper.length() >= 2 && upper[0] ==
'+' )
1260 if( upper.length() >= 2 && upper[0] ==
'-' )
1268 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)
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)
Map PADS pin type to KiCad electrical type.
LIB_SYMBOL * BuildMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Build a composite multi-unit LIB_SYMBOL from a multi-gate PARTTYPE.
bool HasSymbol(const std::string &aName) const
Check if a symbol with the given name already exists.
const PARAMETERS & m_params
void AddHiddenPowerPins(LIB_SYMBOL *aSymbol, const std::vector< PARTTYPE_DEF::SIGPIN > &aSigpins)
Add hidden power pins from PARTTYPE SIGPIN entries to an existing symbol.
SCH_PIN * createPin(const SYMBOL_PIN &aPin, LIB_SYMBOL *aParent)
Create a SCH_PIN from a PADS pin definition.
LIB_SYMBOL * GetSymbol(const std::string &aName) const
Get a cached symbol by name.
~PADS_SCH_SYMBOL_BUILDER()
int toKiCadUnits(double aPadsValue) const
Convert PADS coordinate to KiCad internal units.
LIB_SYMBOL * GetOrCreateMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Get or create a multi-unit symbol for the given PARTTYPE.
static std::optional< LIB_ID > GetKiCadPowerSymbolId(const std::string &aPadsName)
Get KiCad power library symbol ID for a PADS power symbol.
std::vector< SCH_SHAPE * > createShapes(const SYMBOL_GRAPHIC &aGraphic)
Create one or more SCH_SHAPEs from a PADS graphic element.
LIB_SYMBOL * BuildKiCadPowerSymbol(const std::string &aKiCadName)
Build a power symbol using hard-coded KiCad-standard graphics.
PADS_SCH_SYMBOL_BUILDER(const PARAMETERS &aParams)
static bool IsPowerSymbol(const std::string &aName)
Check if a symbol name indicates a power symbol.
static std::string GetPowerStyleFromVariant(const std::string &aDecalName, const std::string &aPinType)
Map a PADS special_variant to a power symbol style name.
SCH_SHAPE * createShape(const SYMBOL_GRAPHIC &aGraphic)
Create a SCH_SHAPE from a PADS graphic element.
LIB_SYMBOL * GetOrCreateSymbol(const SYMBOL_DEF &aSymbolDef)
Get or create a symbol for the given definition.
LIB_SYMBOL * GetOrCreateConnectorPinSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::string &aPinNumber)
Get or create a single-pin connector symbol with a specific pin number.
LIB_SYMBOL * GetOrCreateMultiUnitConnectorSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::vector< std::string > &aPinNumbers, const std::string &aCacheKey)
Get or create a multi-unit connector symbol, cached by base reference.
LIB_SYMBOL * BuildMultiUnitConnectorSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::vector< std::string > &aPinNumbers)
Build a multi-unit connector symbol where each unit represents one pin.
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.
LIB_SYMBOL * GetOrCreatePartTypeSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef)
Get or create a single-gate symbol with PARTTYPE-specific pin remapping.
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)
void SetStroke(const STROKE_PARAMS &aStroke) override
void AddPoint(const VECTOR2I &aPosition)
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.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ FILLED_SHAPE
Fill with object color.
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.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Common utilities and types for parsing PADS file formats.
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.
LINE_STYLE
Dashed line types.
Gate definition within a PARTTYPE.
std::vector< std::string > decal_names
std::vector< PARTTYPE_PIN > pins
std::optional< ARC_DATA > arc
General schematic parameters from SCH and FIELDS sections.
Part type definition from PARTTYPE section.
std::vector< GATE_DEF > gates
Symbol definition from CAEDECAL section.
std::vector< SYMBOL_GRAPHIC > graphics
std::vector< SYMBOL_PIN > pins
std::vector< SYMBOL_TEXT > texts
Graphic primitive from CAEDECAL or LINES sections (OPEN, CLOSED, CIRCLE, COPCLS).
std::vector< GRAPHIC_POINT > points
Pin T/P line pair from CAEDECAL.
std::string pin_decal_name
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I