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 )
259 return it->second.get();
274 std::string cacheKey = aPartType.
name +
":" + aSymbolDef.
name;
278 return it->second.get();
280 if( aPartType.
gates.empty() )
286 for(
const auto& graphic : aSymbolDef.
graphics )
288 std::vector<SCH_SHAPE*> shapes =
createShapes( graphic );
296 for(
size_t p = 0; p < aSymbolDef.
pins.size(); p++ )
300 if( p < gate.
pins.size() )
302 pin.name = gate.
pins[p].pin_name;
303 pin.number = gate.
pins[p].pin_id;
305 if( gate.
pins[p].pin_type != 0 )
315 for(
const auto&
text : aSymbolDef.
texts )
317 if(
text.content.empty() )
325 if(
text.size > 0.0 )
328 int charHeight =
static_cast<int>(
330 int charWidth =
static_cast<int>(
335 if(
text.rotation != 0.0 )
342 bool hasPinNames =
false;
344 for(
const auto&
pin : gate.
pins )
346 if( !
pin.pin_name.empty() )
356 m_symbolCache[cacheKey] = std::unique_ptr<LIB_SYMBOL>( libSymbol );
373 return it->second.get();
383 switch( aGraphic.
type )
388 bool hasArcs =
false;
390 for(
const auto& pt : aGraphic.
points )
392 if( pt.arc.has_value() )
403 for(
const auto& pt : aGraphic.
points )
421 if( aGraphic.
points.size() >= 2 )
492 std::vector<SCH_SHAPE*>
result;
499 result.push_back( single );
511 for(
size_t i = 0; i + 1 < aGraphic.
points.size(); i++ )
519 if( cur.
arc.has_value() )
529 double sx = startPt.
x -
center.x;
530 double sy = startPt.
y -
center.y;
531 double ex = endPt.
x -
center.x;
532 double ey = endPt.
y -
center.y;
533 double radius = std::sqrt( sx * sx + sy * sy );
537 double mlen = std::sqrt( mx * mx + my * my );
574 if( startPt == endPt )
598 pin->SetName( wxString::FromUTF8( aPin.
name ) );
599 pin->SetNumber( wxString::FromUTF8( aPin.
number ) );
603 pin->SetPosition( pos );
607 pin->SetLength( length );
614 bool isVerticalDecal = ( aPin.
pin_decal_name.find(
"VRT" ) != std::string::npos );
615 int angle =
static_cast<int>( aPin.
rotation ) % 360;
617 if( isVerticalDecal )
622 else if( angle >= 45 && angle < 135 )
628 else if( angle >= 225 && angle < 315 )
633 else if( angle >= 135 && angle < 225 )
644 pin->SetOrientation( orientation );
648 pin->SetType( pinType );
655 else if( aPin.
clock )
658 pin->SetShape( pinShape );
661 pin->SetNumberTextSize( pinTextSize );
662 pin->SetNameTextSize( pinTextSize );
671 auto mm = [&](
double v ) {
return schIUScale.mmToIU( v ); };
679 std::string upper = aKiCadName;
680 std::transform( upper.begin(), upper.end(), upper.begin(),
681 [](
unsigned char c ) { return std::toupper( c ); } );
683 bool isGround = ( upper ==
"GND" || upper ==
"GNDA" || upper ==
"GNDPWR" );
684 bool isGNDD = ( upper ==
"GNDD" );
685 bool isPwrBar = ( upper ==
"PWR_BAR" );
686 bool isPwrTriangle = ( upper ==
"PWR_TRIANGLE" );
687 bool isVEE = ( upper ==
"VEE" || upper ==
"VSS" );
688 bool isEarth = ( upper ==
"EARTH" || upper ==
"CHASSIS" );
691 bool isVCC = !isGround && !isGNDD && !isPwrBar && !isPwrTriangle
692 && !isVEE && !isEarth;
708 pin->SetNumber( wxT(
"1" ) );
709 pin->SetName( wxString::FromUTF8( aKiCadName ) );
711 pin->SetVisible(
false );
734 pin->SetNumber( wxT(
"1" ) );
735 pin->SetName( wxString::FromUTF8( aKiCadName ) );
737 pin->SetVisible(
false );
762 pin->SetNumber( wxT(
"1" ) );
763 pin->SetName( wxString::FromUTF8( aKiCadName ) );
765 pin->SetVisible(
false );
771 else if( isPwrTriangle )
790 pin->SetNumber( wxT(
"1" ) );
791 pin->SetName( wxString::FromUTF8( aKiCadName ) );
793 pin->SetVisible(
false );
821 pin->SetNumber( wxT(
"1" ) );
822 pin->SetName( wxString::FromUTF8( aKiCadName ) );
824 pin->SetVisible(
false );
858 pin->SetNumber( wxT(
"1" ) );
859 pin->SetName( wxString::FromUTF8( aKiCadName ) );
861 pin->SetVisible(
false );
889 pin->SetNumber( wxT(
"1" ) );
890 pin->SetName( wxString::FromUTF8( aKiCadName ) );
892 pin->SetVisible(
false );
907 const std::string& aPinType )
909 std::string upper = aDecalName;
910 std::transform( upper.begin(), upper.end(), upper.begin(),
911 [](
unsigned char c ) { return std::toupper( c ); } );
913 bool isPositive = !upper.empty() && upper[0] ==
'+';
914 bool isGround = ( aPinType ==
"G" );
916 if( upper.find(
"RAIL" ) != std::string::npos )
917 return isPositive ?
"PWR_BAR" :
"GNDD";
919 if( upper.find(
"ARROW" ) != std::string::npos )
920 return isPositive ?
"PWR_TRIANGLE" :
"VEE";
922 if( upper.find(
"BUBBLE" ) != std::string::npos )
923 return isPositive ?
"VCC" :
"VEE";
927 if( upper.find(
"CH" ) != std::string::npos )
941 LIB_SYMBOL* aSymbol,
const std::vector<PARTTYPE_DEF::SIGPIN>& aSigpins )
947 std::set<wxString> existingPins;
952 existingPins.insert(
static_cast<const SCH_PIN&
>( item ).GetNumber() );
955 for(
const auto& sp : aSigpins )
957 wxString pinNum = wxString::FromUTF8( sp.pin_number );
959 if( existingPins.count( pinNum ) )
963 pin->SetNumber( pinNum );
964 pin->SetName( wxString::FromUTF8( sp.net_name ) );
966 pin->SetVisible(
false );
972 existingPins.insert( pinNum );
998 std::string upper = aName;
999 std::transform( upper.begin(), upper.end(), upper.begin(),
1000 [](
unsigned char c ) { return std::toupper( c ); } );
1003 if( upper ==
"GND" || upper ==
"AGND" || upper ==
"DGND" || upper ==
"PGND" ||
1004 upper ==
"EARTH" || upper ==
"CHASSIS" || upper ==
"VSS" || upper ==
"0V" )
1010 if( upper ==
"VCC" || upper ==
"VDD" || upper ==
"VEE" || upper ==
"VPP" ||
1011 upper ==
"VBAT" || upper ==
"VBUS" || upper ==
"V+" || upper ==
"V-" )
1017 if( upper.length() >= 2 && ( upper[0] ==
'+' || upper[0] ==
'-' ) )
1027 std::string upper = aPadsName;
1028 std::transform( upper.begin(), upper.end(), upper.begin(),
1029 [](
unsigned char c ) { return std::toupper( c ); } );
1034 const char* padsName;
1035 const char* kicadSymbol;
1038 static const PowerMapping mappings[] = {
1042 {
"PGND",
"GNDPWR" },
1043 {
"EARTH",
"Earth" },
1044 {
"CHASSIS",
"Chassis" },
1058 {
"+3.3V",
"+3V3" },
1069 for(
const auto& mapping : mappings )
1071 if( upper == mapping.padsName )
1081 if( upper.length() >= 2 && upper[0] ==
'+' )
1089 if( upper.length() >= 2 && upper[0] ==
'-' )
1097 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.
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