23#include <boost/property_tree/ptree.hpp>
47#include <fmt/ranges.h>
52 const std::map<wxString, wxString>& aNetByPin )
54 std::vector<wxString> nets;
58 for(
const wxString& pinNum : aPins )
60 auto it = aNetByPin.find( pinNum );
61 nets.push_back( it != aNetByPin.end() ? it->second : wxString() );
66 for(
const std::pair<const wxString, wxString>&
kv : aNetByPin )
67 nets.push_back(
kv.second );
75 const std::vector<BACKANNOTATE_UNIT_SWAP_CANDIDATE>& aCandidates,
76 const std::map<wxString, wxString>& aPcbPinMap )
80 if( aCandidates.size() < 2 )
82 plan.m_mappingOk =
true;
86 std::map<size_t, size_t> desiredTarget;
87 std::set<size_t> usedTargets;
89 for(
size_t candidateIdx = 0; candidateIdx < aCandidates.size(); ++candidateIdx )
92 std::map<wxString, wxString> pcbNetsByPin;
96 auto it = aPcbPinMap.find( pinNum );
97 pcbNetsByPin[pinNum] = ( it != aPcbPinMap.end() ) ? it->second : wxString();
101 bool matched =
false;
103 for(
size_t matchIdx = 0; matchIdx < aCandidates.size(); ++matchIdx )
105 if( usedTargets.count( matchIdx ) )
109 std::vector<wxString> schNets =
112 if( pcbNets == schNets )
114 desiredTarget[candidateIdx] = matchIdx;
115 usedTargets.insert( matchIdx );
125 plan.m_mappingOk =
true;
126 plan.m_identity =
true;
128 for(
size_t candidateIdx = 0; candidateIdx < aCandidates.size(); ++candidateIdx )
130 auto it = desiredTarget.find( candidateIdx );
132 if( it == desiredTarget.end() || it->second != candidateIdx )
134 plan.m_identity =
false;
139 if(
plan.m_identity )
142 std::set<size_t> visited;
144 for(
size_t startIdx = 0; startIdx < aCandidates.size(); ++startIdx )
146 if( visited.count( startIdx ) )
149 std::vector<size_t> cycle;
150 size_t curIdx = startIdx;
152 while( !visited.count( curIdx ) )
154 visited.insert( curIdx );
155 cycle.push_back( curIdx );
157 auto nextIt = desiredTarget.find( curIdx );
159 if( nextIt == desiredTarget.end() || nextIt->second == curIdx )
162 curIdx = nextIt->second;
165 if( cycle.size() < 2 )
168 for(
size_t i = cycle.size() - 1; i > 0; --i )
170 size_t firstIdx = cycle[i - 1];
171 size_t secondIdx = cycle[i];
173 plan.m_steps.push_back( { firstIdx, secondIdx,
174 aCandidates[firstIdx].m_currentUnit,
175 aCandidates[secondIdx].m_currentUnit } );
176 plan.m_swappedCandidateIndices.insert( firstIdx );
177 plan.m_swappedCandidateIndices.insert( secondIdx );
186 bool aProcessFootprints,
bool aProcessValues,
bool aProcessReferences,
187 bool aProcessNetNames,
bool aProcessAttributes,
bool aProcessOtherFields,
188 bool aPreferUnitSwaps,
bool aPreferPinSwaps,
bool aDryRun ) :
235 "stand-alone mode.\n"
236 "You must launch the KiCad project manager and create a project." ) );
244 wxFileName fn(
m_frame->Prj().GetProjectFullName() );
245 fn.SetExt( FILEEXT::PcbFileExtension );
258 std::string nullPayload;
266 auto getStr = [](
const PTREE& pt ) -> wxString
268 return UTF8( pt.front().first );
278 Scan( &doc, &lexer );
280 PTREE& tree = doc.get_child(
"pcb_netlist" );
284 for(
const std::pair<const std::string, PTREE>& item : tree )
286 wxString
path, value, footprint;
287 bool dnp =
false, exBOM =
false, exSim =
false, exPosFiles =
false;
288 std::map<wxString, wxString> pinNetMap, fieldsMap;
289 wxASSERT( item.first ==
"ref" );
290 wxString ref = getStr( item.second );
297 path = getStr( item.second.get_child(
"timestamp" ) );
301 msg.Printf(
_(
"Footprint '%s' has no assigned symbol." ),
DescribeRef( ref ) );
306 footprint = getStr( item.second.get_child(
"fpid" ) );
307 value = getStr( item.second.get_child(
"value" ) );
310 boost::optional<const PTREE&> fields = item.second.get_child_optional(
"fields" );
315 for(
const std::pair<const std::string, PTREE>& field : fields.get() )
317 if( field.first !=
"field" )
321 const auto& fieldName = field.second.get_child_optional(
"name" );
322 const std::string& fieldValue = field.second.back().first;
327 fieldsMap[getStr( fieldName.get() )] = wxString::FromUTF8( fieldValue );
333 for(
const auto& child : item.second )
335 if( child.first !=
"property" )
338 auto property = child.second;
339 auto name =
property.get_child_optional(
"name" );
344 if(
name.get().front().first ==
"dnp" )
346 else if(
name.get().front().first ==
"exclude_from_bom" )
348 else if(
name.get().front().first ==
"exclude_from_sim" )
350 else if(
name.get().front().first ==
"exclude_from_pos_files" )
354 boost::optional<const PTREE&> nets = item.second.get_child_optional(
"nets" );
358 for(
const std::pair<const std::string, PTREE>& pin_net : nets.get() )
360 wxASSERT( pin_net.first ==
"pin_net" );
361 wxString pinNumber =
UTF8( pin_net.second.front().first );
362 wxString netName =
UTF8( pin_net.second.back().first );
363 pinNetMap[ pinNumber ] = netName;
369 wxLogWarning(
"Cannot parse PCB netlist for back-annotation." );
378 msg.Printf(
_(
"Footprints '%s' and '%s' linked to same symbol." ),
386 std::shared_ptr<PCB_FP_DATA> data = std::make_shared<PCB_FP_DATA>(
387 ref, footprint, value, dnp, exBOM, exSim, exPosFiles, pinNetMap, fieldsMap );
399 bool foundInMultiunit =
false;
404 refIndex = refList.FindRef( pcbPath );
406 refIndex = refList.FindRefByFullPath( pcbPath );
412 foundInMultiunit =
true;
414 for(
size_t i = 0; i < refList.GetCount(); ++i )
416 refList[ i ].GetSymbol()->ClearFlags(
SKIP_STRUCT );
424 if( foundInMultiunit )
428 refIndex =
m_refs.FindRef( pcbPath );
430 refIndex =
m_refs.FindRefByFullPath( pcbPath );
440 m_reporter.ReportTail( wxString::Format(
_(
"Cannot find symbol for footprint '%s'." ),
454 return SCH_REFERENCE_LIST::sortByTimeStamp( a.first, b.first );
463 while( i <
m_refs.GetCount() &&
m_refs[i].GetPath() != item.first.GetPath() )
469 m_reporter.ReportTail( wxString::Format(
_(
"Footprint '%s' is not present on PCB. "
470 "Corresponding symbols in schematic must be "
471 "manually deleted (if desired)." ),
483 "annotated schematic." ) ) )
495 std::set<CHANGELIST_ITEM*> unitSwapItems;
505 std::map<std::shared_ptr<PCB_FP_DATA>, std::vector<CHANGELIST_ITEM*>> changesPerFp;
507 msg.Printf( wxT(
"DEBUG(unit-swap): grouped changelist into %zu footprint(s) for unit-swap processing:" ),
508 changesPerFp.size() );
515 changesPerFp[item.second].push_back( &item );
516 msg += wxT(
" " ) + item.first.GetRef();
522 for(
auto& fpChangelistPair : changesPerFp )
524 std::set<SCH_SYMBOL*> swappedSymbols;
525 std::set<CHANGELIST_ITEM*> swappedItems;
526 std::shared_ptr<PCB_FP_DATA> fp = fpChangelistPair.first;
527 auto& changedFpItems = fpChangelistPair.second;
540 std::map<wxString, wxString> schNetsByPin;
541 std::map<wxString, wxString> pcbNetsByPin;
542 std::vector<wxString> unitPinNumbers;
543 std::vector<wxString> schNetsInUnitOrder;
544 std::vector<wxString> pcbNetsInUnitOrder;
548 std::vector<SYM_UNIT> symbolUnits;
550 std::map<LIB_SYMBOL*, std::vector<LIB_SYMBOL::UNIT_PIN_INFO>> unitPinsByLibSymbol;
553 [&](
SCH_SYMBOL* symbol,
int unitNumber ) -> std::vector<wxString>
555 if( unitNumber <= 0 )
566 auto found = unitPinsByLibSymbol.find( libSymbol );
568 if( found == unitPinsByLibSymbol.end() )
569 found = unitPinsByLibSymbol.emplace( libSymbol, libSymbol->
GetUnitPinInfo() ).first;
571 const std::vector<LIB_SYMBOL::UNIT_PIN_INFO>& unitInfos = found->second;
573 if( unitNumber >
static_cast<int>( unitInfos.size() ) )
576 return unitInfos[unitNumber - 1].m_pinNumbers;
591 symbolUnit.sym = symbol;
592 symbolUnit.screen = screen;
595 symbolUnit.changeItem = changedItem;
597 int currentUnit = ref.
GetUnit();
599 if( currentUnit <= 0 )
602 if( currentUnit <= 0 )
603 currentUnit = symbol->
GetUnit();
605 symbolUnit.currentUnit = currentUnit;
606 symbolUnit.unitPinNumbers = getUnitPins( symbol, symbolUnit.currentUnit );
612 const wxString& pinNum =
pin->GetNumber();
615 auto it = fp->m_pinMap.find( pinNum );
616 symbolUnit.pcbNetsByPin[pinNum] = ( it != fp->m_pinMap.end() ) ? it->second : wxString();
622 symbolUnit.schNetsByPin[pinNum] = connection->Name(
true );
624 symbolUnit.schNetsByPin[pinNum] = wxString();
627 symbolUnit.schNetsByPin[pinNum] = wxString();
630 symbolUnit.pcbNetsInUnitOrder =
netsInUnitOrder( symbolUnit.unitPinNumbers, symbolUnit.pcbNetsByPin );
631 symbolUnit.schNetsInUnitOrder =
netsInUnitOrder( symbolUnit.unitPinNumbers, symbolUnit.schNetsByPin );
633 symbolUnits.push_back( symbolUnit );
636 auto vectorToString =
637 [](
const std::vector<wxString>& values ) -> wxString
639 return fmt::format(
L"{}", fmt::join( values,
L", " ) );
643 [vectorToString](
const std::map<wxString, wxString>& pinMap ) -> wxString
645 std::vector<wxString> entries;
647 for(
const std::pair<const wxString, wxString>&
pin : pinMap )
648 entries.push_back(
pin.first +
'=' +
pin.second );
650 return vectorToString( entries );
653 msg.Printf( wxT(
"DEBUG(unit-swap): footprint %s processed (%zu units, dryRun=%d)." ), fp->m_ref,
654 symbolUnits.size(),
m_dryRun ? 1 : 0 );
658 std::sort( symbolUnits.begin(), symbolUnits.end(),
659 [](
const SYM_UNIT& a,
const SYM_UNIT& b )
661 return a.ref < b.ref;
664 for(
const SYM_UNIT& su : symbolUnits )
666 wxString pcbPins = mapToString( su.pcbNetsByPin );
667 wxString schPins = mapToString( su.schNetsByPin );
668 wxString unitPins = vectorToString( su.unitPinNumbers );
669 wxString pcbUnitNetSeq = vectorToString( su.pcbNetsInUnitOrder );
670 wxString schUnitNetSeq = vectorToString( su.schNetsInUnitOrder );
672 msg.Printf( wxT(
"DEBUG(unit-swap): unit %d: %s pcbPins[%s] schPins[%s] unitPins[%s] pcbUnitNets[%s] "
673 "schUnitNets[%s]." ),
674 su.currentUnit, su.ref, pcbPins, schPins, unitPins, pcbUnitNetSeq, schUnitNetSeq );
678 if( symbolUnits.size() < 2 )
681 std::vector<BACKANNOTATE_UNIT_SWAP_CANDIDATE> candidates;
683 for(
const SYM_UNIT& symbolUnit : symbolUnits )
686 candidate.
m_ref = symbolUnit.ref;
690 candidates.push_back( candidate );
695 if( !
plan.m_mappingOk )
697 msg.Printf( wxT(
"DEBUG(unit-swap): mapping failed for footprint %s." ), fp->m_ref );
702 if(
plan.m_identity )
704 msg.Printf( wxT(
"DEBUG(unit-swap): footprint %s already aligned (identity mapping)." ), fp->m_ref );
711 for(
size_t candidateIdx :
plan.m_swappedCandidateIndices )
712 commit.
Modify( symbolUnits[candidateIdx].sym, symbolUnits[candidateIdx].screen );
719 int aUnit = a.currentUnit;
720 int bUnit = b.currentUnit;
724 a.sym->SetUnit( bUnit );
725 b.sym->SetUnit( aUnit );
728 a.sym->SetUnitSelection( sheet, bUnit );
731 b.sym->SetUnitSelection( sheet, aUnit );
734 a.currentUnit = bUnit;
735 b.currentUnit = aUnit;
737 swappedSymbols.insert( a.sym );
738 swappedSymbols.insert( b.sym );
742 swappedItems.insert( a.changeItem );
743 unitSwapItems.insert( a.changeItem );
748 swappedItems.insert( b.changeItem );
749 unitSwapItems.insert( b.changeItem );
752 wxString baseRef = a.sym->GetRef( a.sheetPath,
false );
753 wxString unitAString = a.sym->SubReference( aUnit,
false );
754 wxString unitBString = b.sym->SubReference( bUnit,
false );
756 if( unitAString.IsEmpty() )
757 unitAString.Printf( wxT(
"%d" ), aUnit );
759 if( unitBString.IsEmpty() )
760 unitBString.Printf( wxT(
"%d" ), bUnit );
762 msg.Printf(
_(
"Swap %s unit %s with unit %s." ),
770 msg.Printf( wxT(
"DEBUG(unit-swap): applied %zu swap steps for footprint %s." ),
771 plan.m_steps.size(), fp->m_ref );
779 SCH_SYMBOL* symbol = changedItem->first.GetSymbol();
784 if( swappedItems.count( changedItem ) || swappedSymbols.count( symbol ) )
787 int updatedUnit = symbol->
GetUnitSelection( &changedItem->first.GetSheetPath() );
788 changedItem->first.SetUnit( updatedUnit );
808 bool skip = ( ref.
GetSymbol()->GetFlags() &
SKIP_STRUCT ) > 0 || unitSwapItems.count( &item ) > 0;
811 [](
bool b ) -> wxString
813 return b ?
_(
"true" ) :
_(
"false" );
823 msg.Printf(
_(
"Change %s reference designator to '%s'." ),
837 msg.Printf(
_(
"Change %s footprint assignment from '%s' to '%s'." ),
852 msg.Printf(
_(
"Change %s value from '%s' to '%s'." ),
866 msg.Printf(
_(
"Change %s 'Do not populate' from '%s' to '%s'." ),
868 boolString( oldDNP ),
869 boolString( fpData.
m_DNP ) );
880 msg.Printf(
_(
"Change %s 'Exclude from bill of materials' from '%s' to '%s'." ),
882 boolString( oldExBOM ),
894 msg.Printf(
_(
"Change %s 'Exclude from simulation' from '%s' to '%s'." ),
896 boolString( oldExSim ),
908 msg.Printf(
_(
"Change %s 'Exclude from position files' from '%s' to '%s'." ),
DescribeRef( ref.
GetRef() ),
917 std::set<wxString> swappedPins;
925 for(
const std::pair<const wxString, wxString>& entry : fpData.
m_pinMap )
927 const wxString& pinNumber = entry.first;
928 const wxString& shortNetName = entry.second;
932 if( swappedPins.count( pinNumber ) > 0 )
937 msg.Printf(
_(
"Cannot find %s pin '%s'." ),
947 if( connection && connection->
Name(
true ) != shortNetName )
950 connection->
Name(
true ), shortNetName );
958 for(
const std::pair<const wxString, wxString>& field : fpData.
m_fieldsMap )
960 const wxString& fpFieldName = field.first;
961 const wxString& fpFieldValue = field.second;
980 msg.Printf(
_(
"Change %s field '%s' value to '%s'." ),
986 symField->
SetText( fpFieldValue );
992 if( symField ==
nullptr )
995 msg.Printf(
_(
"Add %s field '%s' with value '%s'." ),
1003 newField.
SetText( fpFieldValue );
1016 std::vector<wxString> fieldsToDelete;
1020 if( field.IsMandatory() )
1026 msg.Printf(
_(
"Delete %s field '%s.'" ),
1030 fieldsToDelete.push_back( field.GetName() );
1037 for(
const wxString& fieldName : fieldsToDelete )
1045 unitSwapItems.erase( &item );
1053 m_frame->UpdateNetHighlightStatus();
1055 commit.
Push(
_(
"Update Schematic from PCB" ) );
1098 ORIENT o = orientations[ 0 ];
1107 for(
const ORIENT& i : orientations )
1109 if( i.flag == symbolOrientation )
1116 for(
int i = 0; i < o.n_rots; i++ )
1131 if( connectedItems.insert( aItem ).second )
1144 std::set<wxString> swappedPins;
1154 wxCHECK(
m_frame, swappedPins );
1161 wxString currentNet;
1165 std::vector<PIN_CHANGE> mismatches;
1168 std::map<wxString, std::vector<size_t>> pinsByCurrentNet;
1171 for(
const std::pair<const wxString, wxString>& entry : aFpData.
m_pinMap )
1173 const wxString& pinNumber = entry.first;
1174 const wxString& desiredNet = entry.second;
1183 if( !
pin ||
pin->IsPower() || !
pin->IsConnectable() )
1187 wxString currentNet = connection ? connection->
Name(
true ) : wxString();
1189 if( desiredNet.IsEmpty() || currentNet.IsEmpty() )
1192 if( desiredNet == currentNet )
1195 size_t idx = mismatches.size();
1196 mismatches.push_back( {
pin, pinNumber, currentNet, desiredNet } );
1197 pinsByCurrentNet[currentNet].push_back( idx );
1200 if( mismatches.size() < 2 )
1205 std::vector<bool> handled( mismatches.size(),
false );
1206 std::vector<SCH_PIN*> swappedPinObjects;
1207 bool swappedLibPins =
false;
1210 bool allowPinSwaps =
false;
1211 wxString currentProjectName =
m_frame->Prj().GetProjectName();
1214 allowPinSwaps =
m_frame->eeconfig()->m_Input.allow_unconstrained_pin_swaps;
1216 std::set<wxString> sharedSheetPaths;
1217 std::set<wxString> sharedProjectNames;
1219 &sharedSheetPaths, &sharedProjectNames );
1221 std::set<wxString> friendlySheetNames;
1223 if( sharedSheetSymbol && !sharedSheetPaths.empty() )
1228 for(
size_t i = 0; i < mismatches.size(); ++i )
1234 PIN_CHANGE& change = mismatches[i];
1237 auto range = pinsByCurrentNet.find( change.targetNet );
1240 if( range == pinsByCurrentNet.end() )
1244 size_t partnerIdx = std::numeric_limits<size_t>::max();
1247 for(
size_t candidateIdx : range->second )
1249 if( candidateIdx == i || handled[candidateIdx] )
1252 PIN_CHANGE& candidate = mismatches[candidateIdx];
1256 if( candidate.targetNet == change.currentNet )
1258 partnerIdx = candidateIdx;
1265 if( partnerIdx == std::numeric_limits<size_t>::max() )
1268 PIN_CHANGE&
partner = mismatches[partnerIdx];
1272 if( change.pin->GetParentSymbol() !=
partner.pin->GetParentSymbol() )
1275 if( !allowPinSwaps || sharedSheetSymbol )
1277 if( !sharedProjectNames.empty() )
1279 std::vector<wxString> otherProjects;
1281 for(
const wxString&
name : sharedProjectNames )
1283 if( !currentProjectName.IsEmpty() &&
name.IsSameAs( currentProjectName ) )
1286 otherProjects.push_back(
name );
1291 if( projects.IsEmpty() )
1293 msg.Printf(
_(
"Would swap %s pins %s and %s to match PCB, but the symbol is shared across other projects." ),
1300 msg.Printf(
_(
"Would swap %s pins %s and %s to match PCB, but the symbol is shared across other "
1306 else if( !friendlySheetNames.empty() )
1310 msg.Printf(
_(
"Would swap %s pins %s and %s to match PCB, but the symbol is used by multiple sheet "
1311 "instances (%s)." ),
1316 else if( sharedSheetSymbol )
1318 msg.Printf(
_(
"Would swap %s pins %s and %s to match PCB, but the symbol is shared." ),
1325 msg.Printf(
_(
"Would swap %s pins %s and %s to match PCB, but unconstrained pin swaps are disabled in "
1326 "the schematic preferences." ),
1334 handled[partnerIdx] =
true;
1340 wxCHECK2( aCommit,
continue );
1351 handled[partnerIdx] =
true;
1354 swappedPins.insert( change.pinNumber );
1355 swappedPins.insert(
partner.pinNumber );
1356 swappedPinObjects.push_back( change.pin );
1357 swappedPinObjects.push_back(
partner.pin );
1361 msg.Printf(
_(
"Swap %s pins %s and %s to match PCB." ),
1369 if( swappedPinObjects.empty() )
1374 if( swappedLibPins )
1377 m_frame->UpdateItem( aSymbol,
false,
true );
1386 for(
SCH_PIN* swappedPin : swappedPinObjects )
1387 cleanupSelection.
Add( swappedPin );
1389 lwbTool->TrimOverLappingWires( aCommit, &cleanupSelection );
1390 lwbTool->AddJunctionsIfNeeded( aCommit, &cleanupSelection );
1394 m_frame->Schematic().CleanUp( aCommit );
1403 const wxString& aOldName,
const wxString& aNewName )
1411 std::set<SCH_ITEM*> connectedItems;
1417 for(
SCH_ITEM* item : connectedItems )
1421 if( priority > driverPriority )
1424 driverPriority = priority;
1428 switch( driver->
Type() )
1436 msg.Printf(
_(
"Change %s pin %s net label from '%s' to '%s'." ),
1452 if(
static_cast<SCH_PIN*
>( driver )->IsPower() )
1454 msg.Printf(
_(
"Net %s cannot be changed to %s because it is driven by a power pin." ),
1474 msg.Printf(
_(
"Change %s pin %s net label from '%s' to '%s'." ),
DescribeRef( aRef ),
1490 static_cast<SCH_LABEL_BASE*
>( resolvedDriver )->SetText( aNewName );
1500 msg.Printf(
_(
"Add label '%s' to %s pin %s net." ),
1515 aCommit->
Add( label, screen );
static std::vector< wxString > netsInUnitOrder(const std::vector< wxString > &aPins, const std::map< wxString, wxString > &aNetByPin)
void addConnections(SCH_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath, std::set< SCH_ITEM * > &connectedItems)
static SPIN_STYLE orientLabel(SCH_PIN *aPin)
BACKANNOTATE_UNIT_SWAP_PLAN PlanBackannotateUnitSwaps(const std::vector< BACKANNOTATE_UNIT_SWAP_CANDIDATE > &aCandidates, const std::map< wxString, wxString > &aPcbPinMap)
Compute a pure unit-swap plan from schematic-side unit definitions and the final PCB pin map.
BACKANNOTATE_UNIT_SWAP_PLAN PlanBackannotateUnitSwaps(const std::vector< BACKANNOTATE_UNIT_SWAP_CANDIDATE > &aCandidates, const std::map< wxString, wxString > &aPcbPinMap)
Compute a pure unit-swap plan from schematic-side unit definitions and the final PCB pin map.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
bool BackAnnotateSymbols(const std::string &aNetlist)
Run back annotation algorithm.
SCH_MULTI_UNIT_REFERENCE_MAP m_multiUnitsRefs
std::deque< CHANGELIST_ITEM > m_changelist
std::pair< SCH_REFERENCE, std::shared_ptr< PCB_FP_DATA > > CHANGELIST_ITEM
bool m_processOtherFields
void getPcbModulesFromString(const std::string &aPayload)
Parse netlist sent over KiWay express mail interface and fill m_pcbModules.
void checkForUnusedSymbols()
Check if some symbols are not represented in PCB footprints and vice versa.
SCH_REFERENCE_LIST m_refs
bool FetchNetlistFromPCB(std::string &aNetlist)
Get netlist from the Pcbnew.
PCB_FOOTPRINTS_MAP m_pcbFootprints
void processNetNameChange(SCH_COMMIT *aCommit, const wxString &aRef, SCH_PIN *aPin, const SCH_CONNECTION *aConnection, const wxString &aOldName, const wxString &aNewName)
BACK_ANNOTATE(SCH_EDIT_FRAME *aFrame, REPORTER &aReporter, bool aRelinkFootprints, bool aProcessFootprints, bool aProcessValues, bool aProcessReferences, bool aProcessNetNames, bool aProcessAttributes, bool aProcessOtherFields, bool aPreferUnitSwaps, bool aPreferPinSwaps, bool aDryRun)
std::set< wxString > applyPinSwaps(SCH_SYMBOL *aSymbol, const SCH_REFERENCE &aReference, const PCB_FP_DATA &aFpData, SCH_COMMIT *aCommit)
Handle footprint pad net swaps with symbol pin swaps where possible.
void applyChangelist()
Apply changelist to the schematic.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Calculate the connectivity of a schematic and generate netlists.
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem) const
A subgraph is a set of items that are electrically connected on a single sheet.
PRIORITY GetDriverPriority()
const SCH_ITEM * GetDriver() const
static PRIORITY GetDriverPriority(SCH_ITEM *aDriver)
Return the priority (higher is more important) of a candidate driver.
const SCH_SHEET_PATH & GetSheet() const
Implement a lexical analyzer for the SPECCTRA DSN file format.
virtual VECTOR2I GetPosition() const
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual void SetParent(EDA_ITEM *aParent)
EDA_ITEM_FLAGS GetFlags() const
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual void SetTextPos(const VECTOR2I &aPoint)
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
virtual void SetVisible(bool aVisible)
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Define a library symbol object.
std::vector< UNIT_PIN_INFO > GetUnitPinInfo() const
Return pin-number lists for each unit, ordered consistently for gate swapping.
static REPORTER & GetInstance()
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the beginning of the list for objects that support ordering.
These are loaded from Eeschema settings but then overwritten by the project settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
SCH_SHEET_PATH Sheet() const
wxString Name(bool aIgnoreSheet=false) const
Schematic editor (Eeschema) main window.
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
const SYMBOL * GetParentSymbol() const
const std::vector< SCH_ITEM * > & ConnectedItems(const SCH_SHEET_PATH &aPath) const
Retrieve the set of items connected to this item on the given sheet.
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
SCH_PIN * GetLibPin() const
PIN_ORIENTATION GetOrientation() const
const wxString & GetShownNumber() const
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
const wxString GetFootprint() const
SCH_SYMBOL * GetSymbol() const
const wxString GetValue() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SYMBOL_FILTER aSymbolFilter) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the li...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
virtual void SetDNP(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
void SetExcludedFromSim(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
void SetFootprintFieldText(const wxString &aFootprint)
VECTOR2I GetPosition() const override
void SetExcludedFromPosFiles(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void SetValueFieldText(const wxString &aValue, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString)
bool GetExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
int GetOrientation() const override
Get the display symbol orientation.
void SetExcludedFromBOM(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
SPIN_STYLE MirrorX()
Mirror the label spin style across the X axis or simply swaps up and bottom.
SPIN_STYLE MirrorY()
Mirror the label spin style across the Y axis or simply swaps left and right.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
wxString DescribeRef(const wxString &aRef)
Returns a user-visible HTML string describing a footprint reference designator.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define IS_NEW
New item, just created.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
static std::vector< PENDING_PROPERTY > plan(const EDA_ITEM &aSource, const EDA_ITEM &aTarget, const std::set< wxString > &aEnabledKeys)
Target properties to write, paired with values read off the source.
@ 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.
void Scan(PTREE *aTree, DSNLEXER *aLexer)
Fill an empty PTREE with information from a KiCad s-expression stream.
boost::property_tree::ptree PTREE
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
wxString From_UTF8(const char *cstring)
void AccumulateDescriptions(wxString &aDesc, const T &aItemCollection)
Build a comma-separated list from a collection of wxStrings.
std::vector< wxString > m_unitPinNumbers
std::map< wxString, wxString > m_schNetsByPin
Container for Pcbnew footprint data.Map to hold NETLIST footprints data.
std::map< wxString, wxString > m_pinMap
bool m_excludeFromPosFiles
std::map< wxString, wxString > m_fieldsMap
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.