58#include <wx/filename.h>
69 size_t sepPos = aRef.rfind(
'-' );
71 if( sepPos == std::string::npos )
72 sepPos = aRef.rfind(
'.' );
74 if( sepPos != std::string::npos
75 && sepPos + 1 < aRef.size()
76 && std::isdigit(
static_cast<unsigned char>( aRef[sepPos + 1] ) ) )
78 return aRef.substr( sepPos + 1 );
92 size_t sepPos = aRef.rfind(
'-' );
94 if( sepPos == std::string::npos )
95 sepPos = aRef.rfind(
'.' );
97 if( sepPos != std::string::npos
98 && sepPos + 1 < aRef.size()
99 && std::isdigit(
static_cast<unsigned char>( aRef[sepPos + 1] ) ) )
101 return aRef.substr( 0, sepPos );
114 size_t sepPos = aRef.rfind(
'-' );
116 if( sepPos == std::string::npos )
117 sepPos = aRef.rfind(
'.' );
119 if( sepPos != std::string::npos
120 && sepPos + 1 < aRef.size()
121 && std::isalpha(
static_cast<unsigned char>( aRef[sepPos + 1] ) ) )
123 return aRef.substr( 0, sepPos );
166 const VECTOR2I& aOpcPos,
bool aPinUp,
int aPageHeightIU )
169 std::string opcRef =
"@@@O" + aOpcId;
175 for(
const auto& wire : signal.wires )
177 if( wire.vertices.size() < 2 )
180 if( wire.endpoint_a == opcRef )
188 if( wire.endpoint_b == opcRef )
190 size_t last = wire.vertices.size() - 1;
206 int dx = adjPos.
x - aOpcPos.
x;
207 int dy = adjPos.
y - aOpcPos.
y;
245 SCH_IO( wxS(
"PADS Logic" ) )
314 else if( aPrim.
points.size() >= 2 )
316 for(
size_t p = 0; p + 1 < aPrim.
points.size(); p++ )
326 if( aPrim.
points[p].arc.has_value() )
364 const std::map<std::string, UTF8>* aProperties )
366 wxCHECK( !aFileName.IsEmpty() && aSchematic,
nullptr );
372 if( aProperties && aProperties->count(
"hierarchical_sheet_load" ) )
374 THROW_IO_ERROR( wxString::Format(
_(
"'%s' contains a complete PADS Logic schematic and "
375 "cannot be loaded as a hierarchical sheet. Use File > Import > "
376 "Non-KiCad Schematic... instead." ),
389 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
390 rootSheet = aAppendToMe;
412 wxCHECK( rootScreen,
nullptr );
423 std::string filename( aFileName.ToUTF8() );
425 if( !parser.
Parse( filename ) )
438 const std::string& ref = part.reference;
439 size_t dashPos = ref.rfind(
'-' );
440 size_t dotPos = ref.rfind(
'.' );
441 size_t sepPos = std::string::npos;
443 if( dashPos != std::string::npos )
445 else if( dotPos != std::string::npos )
448 if( sepPos != std::string::npos && sepPos + 1 < ref.size()
449 && std::isalpha(
static_cast<unsigned char>( ref[sepPos + 1] ) ) )
474 if( sheetNumbers.empty() )
475 sheetNumbers.insert( 1 );
477 bool isSingleSheet = ( sheetNumbers.size() == 1 );
487 std::map<int, SheetContext> sheetContexts;
491 int sheetNum = *sheetNumbers.begin();
493 ctx.sheet = rootSheet;
494 ctx.screen = rootScreen;
496 ctx.screen->SetPageSettings( pageInfo );
497 sheetContexts[sheetNum] = ctx;
502 int totalSheets =
static_cast<int>( sheetNumbers.size() );
504 for(
int sheetNum : sheetNumbers )
514 if( hdr.sheet_num == sheetNum && !hdr.sheet_name.empty() )
526 wxString pageNo = wxString::Format( wxT(
"%d" ), sheetNum );
535 ctx.sheet = subSheet;
538 ctx.screen->SetPageSettings( pageInfo );
539 sheetContexts[sheetNum] = ctx;
547 std::set<std::string> connectorBaseRefs;
551 struct ConnectorGroup
553 std::vector<std::string> pinNumbers;
554 std::map<std::string, int> pinToUnit;
555 std::string partType;
558 std::map<std::string, ConnectorGroup> connectorGroups;
560 for(
const auto& [sheetNum, ctx] : sheetContexts )
562 std::vector<PADS_SCH::PART_PLACEMENT> sheetParts = parser.
GetPartsOnSheet( sheetNum );
566 auto ptIt = parser.
GetPartTypes().find( part.part_type );
568 if( ptIt == parser.
GetPartTypes().end() || !ptIt->second.is_connector )
577 ConnectorGroup&
group = connectorGroups[baseRef];
578 group.partType = part.part_type;
579 group.pinNumbers.push_back( pinNum );
583 for(
auto& [baseRef,
group] : connectorGroups )
585 std::sort(
group.pinNumbers.begin(),
group.pinNumbers.end(),
586 [](
const std::string& a,
const std::string& b )
588 return std::stoi( a ) < std::stoi( b );
591 for(
size_t i = 0; i <
group.pinNumbers.size(); i++ )
592 group.pinToUnit[
group.pinNumbers[i]] =
static_cast<int>( i + 1 );
596 for(
auto& [sheetNum, ctx] : sheetContexts )
598 std::vector<PADS_SCH::PART_PLACEMENT> parts = parser.
GetPartsOnSheet( sheetNum );
602 auto ptIt = parser.
GetPartTypes().find( part.part_type );
605 bool isMultiGate =
false;
606 bool isConnector =
false;
607 bool isPower =
false;
608 std::string libItemName;
609 std::string connectorPinNumber;
615 if( ptDef.
gates.size() > 1 )
619 libItemName = ptDef.
name;
622 else if( !ptDef.
gates.empty() )
625 int idx = std::max( 0, part.gate_index );
626 std::string decalName;
628 if( idx <
static_cast<int>( gate.
decal_names.size() ) )
638 if( symDef && !connectorPinNumber.empty() )
643 auto groupIt = connectorGroups.find( baseRef );
645 if( groupIt != connectorGroups.end() )
647 std::string cacheKey = ptDef.
name +
":conn:" + baseRef;
650 groupIt->second.pinNumbers,
652 libItemName = ptDef.
name +
"_" + baseRef;
656 connectorBaseRefs.insert( baseRef );
662 libItemName = decalName;
668 int idx = std::max( 0, part.gate_index );
669 idx = std::min( idx,
static_cast<int>( ptDef.
special_variants.size() ) - 1 );
677 libItemName = decalName;
692 m_errorMessages.emplace( wxString::Format( wxT(
"PADS Import: symbol '%s' not found,"
693 " part '%s' skipped" ),
694 wxString::FromUTF8( part.symbol_name ),
695 wxString::FromUTF8( part.reference ) ),
701 libItemName = symDef->
name;
707 if( ptIt != parser.
GetPartTypes().end() && !ptIt->second.sigpins.empty() )
716 std::string powerStyle;
718 if( isPower && ptIt != parser.
GetPartTypes().end() && !ptIt->second.special_variants.empty() )
720 int varIdx = std::max( 0, part.gate_index );
721 varIdx = std::min( varIdx,
static_cast<int>( ptIt->second.special_variants.size() ) - 1 );
728 std::optional<LIB_ID> powerLibId;
732 std::string rawNetName = part.power_net_name.empty() ? part.symbol_name : part.power_net_name;
737 if( isPower && powerStyle.empty() )
740 powerStyle = std::string( powerLibId->GetLibItemName().c_str() );
743 auto symbolPtr = std::make_unique<SCH_SYMBOL>();
747 if( isPower && !powerStyle.empty() )
751 if( !powerLibId.has_value() )
752 powerLibId =
LIB_ID( wxT(
"power" ), wxString::FromUTF8( powerStyle ) );
754 symbol->
SetLibId( powerLibId.value() );
763 instanceSymbol =
new LIB_SYMBOL( *libSymbol );
775 if( part.rotation == 90.0 )
777 else if( part.rotation == 180.0 )
779 else if( part.rotation == 270.0 )
782 if( part.mirror_flags & 1 )
785 if( part.mirror_flags & 2 )
790 if( isConnector && !connectorPinNumber.empty() )
793 auto groupIt = connectorGroups.find( baseRef );
795 if( groupIt != connectorGroups.end() )
797 auto unitIt = groupIt->second.pinToUnit.find( connectorPinNumber );
799 if( unitIt != groupIt->second.pinToUnit.end() )
800 symbol->
SetUnit( unitIt->second );
809 else if( isMultiGate )
811 symbol->
SetUnit( part.gate_index + 1 );
822 bool isPrimaryUnit = isConnector ? ( symbol->
GetUnit() == 1 ) : ( !isMultiGate || part.gate_index == 0 );
824 if( !isPower && isPrimaryUnit )
826 std::string baseRef =
832 symbol->
SetRef( &ctx.path, wxString::FromUTF8( part.reference ) );
842 symbol->
SetRef( &ctx.path, wxString::FromUTF8( baseRef ) );
847 if( isMultiGate && !isConnector )
850 symbol->
SetRef( &ctx.path, wxString::FromUTF8( baseRef ) );
858 const std::string& cat = ptIt->second.category;
860 if( cat ==
"CAP" || cat ==
"RES" || cat ==
"IND" )
862 auto valIt = part.attr_overrides.find(
"VALUE" );
864 if( valIt == part.attr_overrides.end() )
865 valIt = part.attr_overrides.find(
"VALUE1" );
867 if( valIt != part.attr_overrides.end() && !valIt->second.empty() )
871 for(
const auto& attr : part.attributes )
873 if( attr.name ==
"VALUE" || attr.name ==
"VALUE1" || attr.name ==
"Value1" )
878 if( part.mirror_flags & 1 )
884 int fieldTextSize =
schIUScale.MilsToIU( 50 );
894 if( part.mirror_flags & 1 )
910 wxString netName = part.power_net_name.empty() ? wxString::FromUTF8( part.symbol_name )
911 : wxString::FromUTF8( part.power_net_name );
913 if( netName.StartsWith( wxT(
"/" ) ) )
914 netName = wxT(
"~{" ) + netName.Mid( 1 ) + wxT(
"}" );
925 else if( isMultiGate )
928 hierRef = part.reference;
938 if( isConnector && !connectorPinNumber.empty() )
941 wxString labelText = wxString::Format( wxT(
"%s.%s" ), wxString::FromUTF8( baseRef ),
942 wxString::FromUTF8( connectorPinNumber ) );
945 std::vector<SCH_PIN*> pins = symbol->
GetPins();
948 pinPos = pins[0]->GetPosition();
955 ctx.screen->Append( label );
958 ctx.screen->Append( symbolPtr.release() );
965 std::set<std::string> powerSignalNames;
969 if( opc.signal_name.empty() )
972 auto ptIt = parser.
GetPartTypes().find( opc.symbol_lib );
974 if( ptIt != parser.
GetPartTypes().end() && !ptIt->second.special_keyword.empty()
975 && ptIt->second.special_keyword !=
"OFF" && !ptIt->second.special_variants.empty() )
977 int idx = std::max( 0, opc.flags2 );
978 idx = std::min( idx,
static_cast<int>( ptIt->second.special_variants.size() ) - 1 );
984 powerSignalNames.insert( opc.signal_name );
992 std::set<std::string> signalOpcIds;
996 if( opc.signal_name.empty() || powerSignalNames.count( opc.signal_name ) )
999 signalOpcIds.insert(
"@@@O" + std::to_string( opc.id ) );
1004 std::map<std::string, PADS_SCH::NETNAME_LABEL> netNameLabels;
1008 if( !nn.anchor_ref.empty() )
1009 netNameLabels[nn.anchor_ref] = nn;
1017 for(
auto& [sheetNum, ctx] : sheetContexts )
1019 std::vector<PADS_SCH::SCH_SIGNAL> sheetSignals = parser.
GetSignalsOnSheet( sheetNum );
1030 for(
size_t v = 0; v + 1 < wire.
vertices.size(); v++ )
1043 ctx.screen->Append( line );
1057 if( wire.
endpoint_a.find(
'.' ) != std::string::npos
1058 && wire.
endpoint_a.find(
"@@@" ) == std::string::npos )
1061 std::string ref = wire.
endpoint_a.substr( 0, dotPos );
1063 if( connectorBaseRefs.count( ref ) )
1077 wxString labelText = wxString::FromUTF8( wire.
endpoint_a );
1083 ctx.screen->Append( label );
1088 if( wire.
endpoint_b.find(
'.' ) != std::string::npos
1089 && wire.
endpoint_b.find(
"@@@" ) == std::string::npos )
1092 std::string ref = wire.
endpoint_b.substr( 0, dotPos );
1094 if( connectorBaseRefs.count( ref ) )
1101 size_t lastIdx = wire.
vertices.size() - 1;
1109 wxString labelText = wxString::FromUTF8( wire.
endpoint_b );
1115 ctx.screen->Append( label );
1124 if( dot.sheet_number != sheetNum )
1131 ctx.screen->Append( junction );
1135 schBuilder.
CreateNetLabels( sheetSignals, ctx.screen, signalOpcIds, powerSignalNames, netNameLabels );
1141 if( opc.source_sheet != sheetNum )
1144 if( opc.signal_name.empty() )
1151 std::string powerStyle;
1152 auto opcPtIt = parser.
GetPartTypes().find( opc.symbol_lib );
1154 if( opcPtIt != parser.
GetPartTypes().end() && !opcPtIt->second.special_keyword.empty()
1155 && opcPtIt->second.special_keyword !=
"OFF" && !opcPtIt->second.special_variants.empty() )
1157 int idx = std::max( 0, opc.flags2 );
1158 idx = std::min( idx,
static_cast<int>( opcPtIt->second.special_variants.size() ) - 1 );
1165 if( !powerStyle.empty() )
1171 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1173 std::optional<LIB_ID> libId =
1176 if( !libId.has_value() )
1177 libId =
LIB_ID( wxT(
"power" ), wxString::FromUTF8( powerStyle ) );
1179 symbol->SetLibId( libId.value() );
1180 symbol->SetLibSymbol( pwrSym );
1181 symbol->SetPosition( pos );
1182 symbol->SetUnit( 1 );
1186 bool pinUp = ( powerStyle ==
"VCC" || powerStyle ==
"PWR_TRIANGLE" );
1190 symbol->SetOrientation( orient );
1192 wxString netName = wxString::FromUTF8( opc.signal_name );
1194 if( netName.StartsWith( wxT(
"/" ) ) )
1195 netName = wxT(
"~{" ) + netName.Mid( 1 ) + wxT(
"}" );
1200 wxString pwrRef = wxString::Format( wxT(
"#PWR%04d" ), pwrIndex++ );
1201 symbol->SetRef( &ctx.path, pwrRef );
1204 symbol->ClearFlags();
1205 ctx.screen->Append( symbol.release() );
1219 auto screenForSheet = [&](
int aSheetNumber ) ->
SCH_SCREEN*
1221 auto ctxIt = sheetContexts.find( aSheetNumber );
1223 return ctxIt != sheetContexts.end() ? ctxIt->second.screen : sheetContexts.begin()->second.screen;
1227 if( !sheetContexts.empty() )
1231 if( textItem.content.empty() )
1234 SCH_SCREEN* textScreen = screenForSheet( textItem.sheet_number );
1245 if( !sheetContexts.empty() )
1252 SCH_SCREEN* linesScreen = screenForSheet( linesItem.sheet_number );
1254 double ox = linesItem.origin.x;
1255 double oy = linesItem.origin.y;
1263 if( textItem.
content.empty() )
1296 const std::map<std::string, UTF8>* aProperties )
1298 std::vector<uint8_t> data;
1301 THROW_IO_ERROR( wxString::Format(
_(
"Cannot read file '%s'." ), aFileName ) );
1305 if( !reader.
Parse( data, aFileName ) )
1306 THROW_IO_ERROR( wxString::Format(
_(
"'%s' is not a valid PADS Logic binary schematic." ), aFileName ) );
1313 std::map<std::pair<wxString, SEVERITY>, std::pair<const DIAGNOSTIC*, size_t>> diagnostics;
1314 auto collectDiagnostics = [&](
const std::vector<DIAGNOSTIC>& aDiagnostics )
1316 for(
const DIAGNOSTIC& diagnostic : aDiagnostics )
1318 auto& [first, count] = diagnostics[{ diagnostic.message, diagnostic.severity }];
1321 first = &diagnostic;
1328 collectDiagnostics(
result.diagnostics );
1330 for(
const auto& [key,
group] : diagnostics )
1332 const auto& [message, severity] = key;
1333 const auto& [first, count] =
group;
1334 wxString report = message;
1337 report += wxString::Format(
_(
" (%zu occurrences)" ), count );
1343 wxS(
"Imported PADS Logic binary schematic '%s': %zu sheets, %zu symbols, %zu wires, %zu buses, "
1344 "%zu bus entries, %zu junctions, %zu labels, %zu texts, %zu graphics, %zu images." ),
1355 const std::map<std::string, UTF8>* aProperties )
1363 if( powerSymbolsOnly && !symbol->IsPower() )
1366 aSymbolNameList.Add(
name );
1372 const std::map<std::string, UTF8>* aProperties )
1380 if( powerSymbolsOnly && !symbol->IsPower() )
1383 aSymbolList.push_back( symbol.get() );
1389 const std::map<std::string, UTF8>* aProperties )
1396 return it->second.get();
1404 wxFileName fn( aLibraryPath );
1406 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
1407 return fn.GetModificationTime().GetValue().GetValue();
1428 THROW_IO_ERRORF(
_(
"'%s' is not a PADS Logic ASCII file." ), aLibraryPath );
1433 std::string filename( aLibraryPath.ToUTF8() );
1435 if( !parser.
Parse( filename ) )
1436 THROW_IO_ERRORF(
_(
"Failed to parse PADS Logic file '%s'." ), aLibraryPath );
1441 std::set<std::string> referencedDecals;
1446 for(
const auto& [ptName, ptDef] : parser.
GetPartTypes() )
1448 if( !ptDef.special_keyword.empty() && ptDef.special_keyword !=
"OFF" )
1452 wxString libName = wxString::FromUTF8( ptDef.name );
1454 if( ptDef.gates.size() > 1 )
1460 for(
const std::string& decalName : gate.
decal_names )
1461 referencedDecals.insert( decalName );
1464 else if( !ptDef.gates.empty() )
1467 std::string decalName;
1474 if( symDef && ptDef.is_connector && !gate.
pins.empty() )
1479 std::vector<std::string> pinNumbers;
1480 pinNumbers.reserve( gate.
pins.size() );
1483 pinNumbers.push_back(
pin.pin_id );
1486 referencedDecals.insert( decalName );
1497 referencedDecals.insert( decalName );
1506 if( !ptDef.sigpins.empty() )
1516 if( referencedDecals.count( symDef.name ) )
1519 wxString libName = wxString::FromUTF8( symDef.name );
1540 std::ifstream file( aFileName.fn_str() );
1542 if( !file.is_open() )
1547 if( std::getline( file, line ) )
1549 if( line.find(
"*PADS-POWERLOGIC" ) != std::string::npos )
1552 if( line.find(
"*PADS-LOGIC" ) != std::string::npos )
1570 std::vector<uint8_t> header;
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetFlags(EDA_ITEM_FLAGS aMask)
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual 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)
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual void SetVisible(bool aVisible)
virtual void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
void SetTextAngleDegrees(double aOrientation)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
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.
virtual void SetName(const wxString &aName)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Parser for PADS Logic ASCII schematic export files.
const std::vector< TEXT_ITEM > & GetTextItems() const
const std::vector< TIED_DOT > & GetTiedDots() const
const std::vector< OFF_PAGE_CONNECTOR > & GetOffPageConnectors() const
bool Parse(const std::string &aFileName)
const std::vector< SHEET_HEADER > & GetSheetHeaders() const
const std::vector< NETNAME_LABEL > & GetNetNameLabels() const
const std::vector< LINES_ITEM > & GetLinesItems() const
std::vector< SCH_SIGNAL > GetSignalsOnSheet(int aSheetNumber) const
std::set< int > GetSheetNumbers() const
const std::vector< SYMBOL_DEF > & GetSymbolDefs() const
const std::vector< PART_PLACEMENT > & GetPartPlacements() const
const std::map< std::string, PARTTYPE_DEF > & GetPartTypes() const
std::vector< PART_PLACEMENT > GetPartsOnSheet(int aSheetNumber) const
const SYMBOL_DEF * GetSymbolDef(const std::string &aName) const
const PARAMETERS & GetParameters() const
Builds KiCad schematic elements (wires, junctions, labels, fields, sheets) from parsed PADS data.
void ApplyPartAttributes(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
Set reference, value, footprint and other fields on a symbol from a part placement.
void CreateTitleBlock(SCH_SCREEN *aScreen)
Set the title block from PADS fields, checking custom names too because PADS designs often leave the ...
static SPIN_STYLE computeLabelOrientation(const VECTOR2I &aLabelPos, const VECTOR2I &aAdjacentPos)
Orient a label opposite to the wire direction at its position so it clears the wire.
int CreateCustomFields(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
Create KiCad user fields for PADS attributes that have no standard-field mapping.
SCH_SHEET * CreateHierarchicalSheet(int aSheetNumber, int aTotalSheets, SCH_SHEET *aParentSheet, const wxString &aBaseFilename)
Create a sub-sheet positioned on its parent and backed by its own screen.
int CreateNetLabels(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen, const std::set< std::string > &aSignalOpcIds, const std::set< std::string > &aSkipSignals={}, const std::map< std::string, NETNAME_LABEL > &aNetNameLabels={})
Create net labels for named signals.
Builds KiCad LIB_SYMBOL objects from parsed PADS symbol definitions.
LIB_SYMBOL * BuildMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Build a composite multi-unit symbol from a multi-gate PARTTYPE.
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.
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.
LIB_SYMBOL * BuildKiCadPowerSymbol(const std::string &aKiCadName)
Build a power symbol using hard-coded KiCad-standard graphics, or nullptr if the name is unrecognized...
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...
LIB_SYMBOL * GetOrCreateSymbol(const SYMBOL_DEF &aSymbolDef)
Return the cached symbol for the given definition, building and caching it if needed.
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 ...
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)
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.
static bool ReadFile(const wxString &aFileName, std::vector< uint8_t > &aData)
bool Parse(const std::vector< uint8_t > &aData, const wxString &aSourceName={})
const PADS_SCH_MODEL & GetModel() const
static bool IsBinaryFamily(const std::vector< uint8_t > &aData)
BUILD_RESULT BuildSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe, const wxString &aSourcePath) const
Describe the page size and margins of a paper page on which to eventually print or plot.
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
bool SetType(PAGE_SIZE_TYPE aPageSize, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Holds all the data relating to one schematic.
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET * GetTopLevelSheet(int aIndex=0) const
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
Replace the top level sheets, rebuilding the hierarchy and connectivity around them.
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_librarySymbols
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
long long getLibraryTimestamp(const wxString &aLibraryPath) const
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
bool isBinarySchematicFile(const wxString &aFileName) const
Recognize the PADS Logic binary family independently of version support so unsupported producer versi...
bool checkFileHeader(const wxString &aFileName) const
SCH_SHEET * loadBinarySchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe, const std::map< std::string, UTF8 > *aProperties)
void ensureLoadedLibrary(const wxString &aLibraryPath)
Parse the PADS Logic ASCII file and populate the library symbol cache.
wxString m_cachedLibraryPath
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
long long m_cachedLibraryTimestamp
std::unordered_map< wxString, SEVERITY > m_errorMessages
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
SCH_IO(const wxString &aName)
void SetConnectivityDirty(bool aDirty=true)
virtual void SetUnit(int aUnit)
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Segment description base class to describe items which have 2 end points (track, wire,...
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
void SetEndPoint(const VECTOR2I &aPosition)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
std::vector< SCH_SHEET_INSTANCE > m_sheetInstances
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
void SetPosition(const VECTOR2I &aPos) override
void SetStroke(const STROKE_PARAMS &aStroke) override
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
void SyncUuidToScreen()
Take the identity of the screen this sheet owns.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void SetLibId(const LIB_ID &aName)
void SetPosition(const VECTOR2I &aPosition) override
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
VECTOR2I GetPosition() const override
void SetValueFieldText(const wxString &aValue, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString)
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Simple container to manage line stroke parameters.
static const char * PropPowerSymsOnly
@ FILLED_SHAPE
Fill with object color.
#define IS_NEW
New item, just created.
@ 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.
const wxChar *const tracePadsIo
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
void DecodeJustification(int aJustification, GR_TEXT_H_ALIGN_T &aHJustify, GR_TEXT_V_ALIGN_T &aVJustify)
Decode a PADS text justification code into KiCad horizontal and vertical alignment.
LINE_STYLE PadsLineStyleToKiCad(int aPadsStyle)
Convert a PADS line style integer to a KiCad LINE_STYLE enum value.
KIID GenerateDeterministicUuid(const std::string &aIdentifier)
Generate a deterministic KIID from a PADS component identifier.
bool ReadFileHeader(const wxString &aFileName, std::vector< uint8_t > &aOut, size_t aCount)
Read at most aCount leading bytes of aFileName into aOut, which is sized to what was actually read.
wxString FormatParserError(const SOURCE_PROVENANCE &aSource, const wxString &aMessage)
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...
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
static int computePowerOrientation(const std::string &aOpcId, const std::vector< PADS_SCH::SCH_SIGNAL > &aSignals, const VECTOR2I &aOpcPos, bool aPinUp, int aPageHeightIU)
Determine the orientation for a power symbol at an OPC position based on the wire direction at that p...
static std::string extractConnectorBaseRef(const std::string &aRef)
Extract the base reference from a connector reference designator.
static SCH_TEXT * createSchText(const PADS_SCH::TEXT_ITEM &aText, const VECTOR2I &aPos)
static std::string extractConnectorPinNumber(const std::string &aRef)
Extract the numeric connector pin suffix from a reference designator.
static void appendGraphicPrimitive(SCH_SCREEN *aScreen, const PADS_SCH::SYMBOL_GRAPHIC &aPrim, double aOx, double aOy, int aPageHeightIU)
static std::string stripGateSuffix(const std::string &aRef)
Strip any alphabetic gate suffix (e.g.
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::string border_template
std::vector< GATE_DEF > gates
std::vector< SPECIAL_VARIANT > special_variants
std::string special_keyword
std::vector< GRAPHIC_POINT > points
Wire segment connecting two endpoints through coordinate vertices.
std::vector< POINT > vertices
std::vector< PARSER_DIAGNOSTIC > diagnostics
A simple container for sheet instance information.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
wxString result
Test unit parsing edge cases and error handling.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.