58 double milsValue = aPadsValue;
63 milsValue = aPadsValue;
68 milsValue = aPadsValue * 39.3701;
73 milsValue = aPadsValue * 1000.0;
86 for(
const auto& graphic : aSymbolDef.
graphics )
88 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
95 for(
const auto&
pin : aSymbolDef.
pins )
104 for(
const auto&
text : aSymbolDef.
texts )
106 if(
text.content.empty() )
113 if(
text.size > 0.0 )
116 int charHeight =
static_cast<int>(
118 int charWidth =
static_cast<int>(
123 if(
text.rotation != 0.0 )
141 return it->second.get();
151 const PARTTYPE_DEF& aPartType,
const std::vector<SYMBOL_DEF>& aSymbolDefs )
154 std::map<std::string, const SYMBOL_DEF*> symDefByName;
156 for(
const auto& sd : aSymbolDefs )
157 symDefByName[sd.name] = &sd;
159 int gateCount =
static_cast<int>( aPartType.
gates.size() );
164 for(
int gi = 0; gi < gateCount; gi++ )
170 std::string decalName;
175 auto sdIt = symDefByName.find( decalName );
177 if( sdIt == symDefByName.end() )
183 for(
const auto& graphic : symDef.
graphics )
185 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
189 shape->SetUnit( unit );
195 for(
size_t p = 0; p < symDef.
pins.size(); p++ )
199 if( p < gate.
pins.size() )
201 pin.name = gate.
pins[p].pin_name;
202 pin.number = gate.
pins[p].pin_id;
204 if( gate.
pins[p].pin_type != 0 )
220 if(
text.content.empty() )
228 if(
text.size > 0.0 )
231 int charHeight =
static_cast<int>(
233 int charWidth =
static_cast<int>(
238 if(
text.rotation != 0.0 )
254 const PARTTYPE_DEF& aPartType,
const std::vector<SYMBOL_DEF>& aSymbolDefs )
258 std::string cacheKey =
"parttype:" + aPartType.
name;
262 return it->second.get();
265 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( newSymbol );
277 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name;
281 return it->second.get();
283 if( aPartType.
gates.empty() )
289 for(
const auto& graphic : aSymbolDef.
graphics )
291 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
299 for(
size_t p = 0; p < aSymbolDef.
pins.size(); p++ )
303 if( p < gate.
pins.size() )
305 pin.name = gate.
pins[p].pin_name;
306 pin.number = gate.
pins[p].pin_id;
308 if( gate.
pins[p].pin_type != 0 )
318 for(
const auto&
text : aSymbolDef.
texts )
320 if(
text.content.empty() )
328 if(
text.size > 0.0 )
331 int charHeight =
static_cast<int>(
333 int charWidth =
static_cast<int>(
338 if(
text.rotation != 0.0 )
345 bool hasPinNames =
false;
347 for(
const auto&
pin : gate.
pins )
349 if( !
pin.pin_name.empty() )
359 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
367 const std::string& aPinNumber )
369 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name +
":" + aPinNumber;
373 return it->second.get();
377 for(
const auto& graphic : aSymbolDef.
graphics )
379 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
386 for(
size_t p = 0; p < aSymbolDef.
pins.size(); p++ )
389 pin.number = aPinNumber;
391 if( !aPartType.
gates.empty() && p < aPartType.
gates[0].pins.size() )
393 pin.name = aPartType.
gates[0].pins[p].pin_name;
395 if( aPartType.
gates[0].pins[p].pin_type != 0 )
405 for(
const auto&
text : aSymbolDef.
texts )
407 if(
text.content.empty() )
415 if(
text.size > 0.0 )
418 int charHeight =
static_cast<int>(
420 int charWidth =
static_cast<int>(
425 if(
text.rotation != 0.0 )
434 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
442 const std::vector<std::string>& aPinNumbers )
444 int unitCount =
static_cast<int>( aPinNumbers.size() );
450 std::map<std::string, const PARTTYPE_PIN*> ptPinById;
452 if( !aPartType.
gates.empty() )
454 for(
const auto& ptPin : aPartType.
gates[0].pins )
455 ptPinById[ptPin.pin_id] = &ptPin;
458 for(
int u = 0; u < unitCount; u++ )
462 for(
const auto& graphic : aSymbolDef.
graphics )
464 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
468 shape->SetUnit( unit );
474 if( !aSymbolDef.
pins.empty() )
477 pin.number = aPinNumbers[u];
479 auto ptPinIt = ptPinById.find( aPinNumbers[u] );
481 if( ptPinIt != ptPinById.end() )
483 if( ptPinIt->second->pin_type != 0 )
486 if( !ptPinIt->second->pin_name.empty() )
487 pin.name = ptPinIt->second->pin_name;
499 for(
const auto&
text : aSymbolDef.
texts )
501 if(
text.content.empty() )
509 if(
text.size > 0.0 )
512 int charHeight =
static_cast<int>(
514 int charWidth =
static_cast<int>(
519 if(
text.rotation != 0.0 )
536 const std::vector<std::string>& aPinNumbers,
const std::string& aCacheKey )
541 return it->second.get();
544 m_symbolCache[aCacheKey] = std::unique_ptr<LIB_SYMBOL>( newSymbol );
561 return it->second.get();
571 switch( aGraphic.
type )
576 bool hasArcs =
false;
578 for(
const auto& pt : aGraphic.
points )
580 if( pt.arc.has_value() )
591 for(
const auto& pt : aGraphic.
points )
609 if( aGraphic.
points.size() >= 2 )
680 std::vector<SCH_SHAPE*>
result;
687 result.push_back( single );
699 for(
size_t i = 0; i + 1 < aGraphic.
points.size(); i++ )
707 if( cur.
arc.has_value() )
717 double sx = startPt.
x -
center.x;
718 double sy = startPt.
y -
center.y;
719 double ex = endPt.
x -
center.x;
720 double ey = endPt.
y -
center.y;
721 double radius = std::sqrt( sx * sx + sy * sy );
725 double mlen = std::sqrt( mx * mx + my * my );
762 if( startPt == endPt )
786 pin->SetName( wxString::FromUTF8( aPin.
name ) );
787 pin->SetNumber( wxString::FromUTF8( aPin.
number ) );
791 pin->SetPosition( pos );
795 pin->SetLength( length );
802 bool isVerticalDecal = ( aPin.
pin_decal_name.find(
"VRT" ) != std::string::npos );
803 int angle =
static_cast<int>( aPin.
rotation ) % 360;
805 if( isVerticalDecal )
810 else if( angle >= 45 && angle < 135 )
816 else if( angle >= 225 && angle < 315 )
821 else if( angle >= 135 && angle < 225 )
832 pin->SetOrientation( orientation );
836 pin->SetType( pinType );
843 else if( aPin.
clock )
846 pin->SetShape( pinShape );
849 pin->SetNumberTextSize( pinTextSize );
850 pin->SetNameTextSize( pinTextSize );
859 auto mm = [&](
double v ) {
return schIUScale.mmToIU( v ); };
867 std::string upper = aKiCadName;
868 std::transform( upper.begin(), upper.end(), upper.begin(),
869 [](
unsigned char c ) { return std::toupper( c ); } );
871 bool isGround = ( upper ==
"GND" || upper ==
"GNDA" || upper ==
"GNDPWR" );
872 bool isGNDD = ( upper ==
"GNDD" );
873 bool isPwrBar = ( upper ==
"PWR_BAR" );
874 bool isPwrTriangle = ( upper ==
"PWR_TRIANGLE" );
875 bool isVEE = ( upper ==
"VEE" || upper ==
"VSS" );
876 bool isEarth = ( upper ==
"EARTH" || upper ==
"CHASSIS" );
879 bool isVCC = !isGround && !isGNDD && !isPwrBar && !isPwrTriangle
880 && !isVEE && !isEarth;
896 pin->SetNumber( wxT(
"1" ) );
897 pin->SetName( wxString::FromUTF8( aKiCadName ) );
899 pin->SetVisible(
false );
922 pin->SetNumber( wxT(
"1" ) );
923 pin->SetName( wxString::FromUTF8( aKiCadName ) );
925 pin->SetVisible(
false );
950 pin->SetNumber( wxT(
"1" ) );
951 pin->SetName( wxString::FromUTF8( aKiCadName ) );
953 pin->SetVisible(
false );
959 else if( isPwrTriangle )
978 pin->SetNumber( wxT(
"1" ) );
979 pin->SetName( wxString::FromUTF8( aKiCadName ) );
981 pin->SetVisible(
false );
1009 pin->SetNumber( wxT(
"1" ) );
1010 pin->SetName( wxString::FromUTF8( aKiCadName ) );
1012 pin->SetVisible(
false );
1013 pin->SetLength( 0 );
1046 pin->SetNumber( wxT(
"1" ) );
1047 pin->SetName( wxString::FromUTF8( aKiCadName ) );
1049 pin->SetVisible(
false );
1050 pin->SetLength( 0 );
1077 pin->SetNumber( wxT(
"1" ) );
1078 pin->SetName( wxString::FromUTF8( aKiCadName ) );
1080 pin->SetVisible(
false );
1081 pin->SetLength( 0 );
1095 const std::string& aPinType )
1097 std::string upper = aDecalName;
1098 std::transform( upper.begin(), upper.end(), upper.begin(),
1099 [](
unsigned char c ) { return std::toupper( c ); } );
1101 bool isPositive = !upper.empty() && upper[0] ==
'+';
1102 bool isGround = ( aPinType ==
"G" );
1104 if( upper.find(
"RAIL" ) != std::string::npos )
1105 return isPositive ?
"PWR_BAR" :
"GNDD";
1107 if( upper.find(
"ARROW" ) != std::string::npos )
1108 return isPositive ?
"PWR_TRIANGLE" :
"VEE";
1110 if( upper.find(
"BUBBLE" ) != std::string::npos )
1111 return isPositive ?
"VCC" :
"VEE";
1115 if( upper.find(
"CH" ) != std::string::npos )
1129 LIB_SYMBOL* aSymbol,
const std::vector<PARTTYPE_DEF::SIGPIN>& aSigpins )
1135 std::set<wxString> existingPins;
1140 existingPins.insert(
static_cast<const SCH_PIN&
>( item ).GetNumber() );
1143 for(
const auto& sp : aSigpins )
1145 wxString pinNum = wxString::FromUTF8( sp.pin_number );
1147 if( existingPins.count( pinNum ) )
1151 pin->SetNumber( pinNum );
1152 pin->SetName( wxString::FromUTF8( sp.net_name ) );
1154 pin->SetVisible(
false );
1155 pin->SetLength( 0 );
1160 existingPins.insert( pinNum );
1186 std::string upper = aName;
1187 std::transform( upper.begin(), upper.end(), upper.begin(),
1188 [](
unsigned char c ) { return std::toupper( c ); } );
1191 if( upper ==
"GND" || upper ==
"AGND" || upper ==
"DGND" || upper ==
"PGND" ||
1192 upper ==
"EARTH" || upper ==
"CHASSIS" || upper ==
"VSS" || upper ==
"0V" )
1198 if( upper ==
"VCC" || upper ==
"VDD" || upper ==
"VEE" || upper ==
"VPP" ||
1199 upper ==
"VBAT" || upper ==
"VBUS" || upper ==
"V+" || upper ==
"V-" )
1205 if( upper.length() >= 2 && ( upper[0] ==
'+' || upper[0] ==
'-' ) )
1215 std::string upper = aPadsName;
1216 std::transform( upper.begin(), upper.end(), upper.begin(),
1217 [](
unsigned char c ) { return std::toupper( c ); } );
1222 const char* padsName;
1223 const char* kicadSymbol;
1226 static const PowerMapping mappings[] = {
1230 {
"PGND",
"GNDPWR" },
1231 {
"EARTH",
"Earth" },
1232 {
"CHASSIS",
"Chassis" },
1246 {
"+3.3V",
"+3V3" },
1257 for(
const auto& mapping : mappings )
1259 if( upper == mapping.padsName )
1269 if( upper.length() >= 2 && upper[0] ==
'+' )
1277 if( upper.length() >= 2 && upper[0] ==
'-' )
1285 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.
void SetCenter(const VECTOR2I &aCenter)
void SetStart(const VECTOR2I &aStart)
void SetEnd(const VECTOR2I &aEnd)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
void SetFillMode(FILL_T aFill)
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