27#include <boost/property_tree/ptree.hpp> 
   51#include <fmt/ranges.h> 
   56                              bool aProcessFootprints, 
bool aProcessValues, 
bool aProcessReferences,
 
   57                              bool aProcessNetNames, 
bool aProcessAttributes, 
bool aProcessOtherFields,
 
   58                              bool aPreferUnitSwaps, 
bool aPreferPinSwaps, 
bool aDryRun ) :
 
 
  105                                         "stand-alone mode.\n" 
  106                                         "You must launch the KiCad project manager and create a project." ) );
 
  114        wxFileName fn( 
m_frame->Prj().GetProjectFullName() );
 
  115        fn.SetExt( FILEEXT::PcbFileExtension );
 
 
  128    std::string nullPayload;
 
 
  136    auto getStr = []( 
const PTREE& pt ) -> wxString
 
  138                      return UTF8( pt.front().first );
 
  148    Scan( &doc, &lexer );
 
  150    PTREE&   tree = doc.get_child( 
"pcb_netlist" );
 
  154    for( 
const std::pair<const std::string, PTREE>& item : tree )
 
  156        wxString 
path, value, footprint;
 
  157        bool     dnp = 
false, exBOM = 
false;
 
  158        std::map<wxString, wxString> pinNetMap, fieldsMap;
 
  159        wxASSERT( item.first == 
"ref" );
 
  160        wxString ref = getStr( item.second );
 
  167                path = getStr( item.second.get_child( 
"timestamp" ) );
 
  171                msg.Printf( 
_( 
"Footprint '%s' has no assigned symbol." ), 
DescribeRef( ref ) );
 
  176            footprint = getStr( item.second.get_child( 
"fpid" ) );
 
  177            value     = getStr( item.second.get_child( 
"value" ) );
 
  180            boost::optional<const PTREE&> fields = item.second.get_child_optional( 
"fields" );
 
  185                for( 
const std::pair<const std::string, PTREE>& field : fields.get() )
 
  187                    if( field.first != 
"field" )
 
  191                    const auto&        fieldName = field.second.get_child_optional( 
"name" );
 
  192                    const std::string& fieldValue = field.second.back().first;
 
  197                    fieldsMap[getStr( fieldName.get() )] = wxString::FromUTF8( fieldValue );
 
  203            for( 
const auto& child : item.second )
 
  205                if( child.first != 
"property" )
 
  208                auto property = child.second;
 
  209                auto name = 
property.get_child_optional( 
"name" );
 
  214                if( 
name.get().front().first == 
"dnp" )
 
  216                else if( 
name.get().front().first == 
"exclude_from_bom" )
 
  220            boost::optional<const PTREE&> nets = item.second.get_child_optional( 
"nets" );
 
  224                for( 
const std::pair<const std::string, PTREE>& pin_net : nets.get() )
 
  226                    wxASSERT( pin_net.first == 
"pin_net" );
 
  227                    wxString pinNumber = 
UTF8( pin_net.second.front().first );
 
  228                    wxString netName = 
UTF8( pin_net.second.back().first );
 
  229                    pinNetMap[ pinNumber ] = netName;
 
  235            wxLogWarning( 
"Cannot parse PCB netlist for back-annotation." );
 
  244            msg.Printf( 
_( 
"Footprints '%s' and '%s' linked to same symbol." ),
 
  252            std::shared_ptr<PCB_FP_DATA> data = std::make_shared<PCB_FP_DATA>( ref, footprint, value, dnp,
 
  253                                                                               exBOM, pinNetMap, fieldsMap );
 
 
  265        bool foundInMultiunit = 
false;
 
  270                refIndex = refList.FindRef( pcbPath );
 
  272                refIndex = refList.FindRefByFullPath( pcbPath );
 
  278                foundInMultiunit = 
true;
 
  280                for( 
size_t i = 0; i < refList.GetCount(); ++i )
 
  282                    refList[ i ].GetSymbol()->ClearFlags(
SKIP_STRUCT );
 
  290        if( foundInMultiunit )
 
  294            refIndex = 
m_refs.FindRef( pcbPath );
 
  296            refIndex = 
m_refs.FindRefByFullPath( pcbPath );
 
  306            m_reporter.ReportTail( wxString::Format( 
_( 
"Cannot find symbol for footprint '%s'." ),
 
 
  320                   return SCH_REFERENCE_LIST::sortByTimeStamp( a.first, b.first );
 
  329        while( i < 
m_refs.GetCount() && 
m_refs[i].GetPath() != item.first.GetPath() )
 
  335                m_reporter.ReportTail( wxString::Format( 
_( 
"Footprint '%s' is not present on PCB. " 
  336                                                            "Corresponding symbols in schematic must be " 
  337                                                            "manually deleted (if desired)." ),
 
  349                                                           "annotated schematic." ) ) )
 
 
  361    std::set<CHANGELIST_ITEM*> unitSwapItems;
 
  371        std::map<std::shared_ptr<PCB_FP_DATA>, std::vector<CHANGELIST_ITEM*>> changesPerFp;
 
  373        msg.Printf( wxT( 
"DEBUG(unit-swap): grouped changelist into %zu footprint(s) for unit-swap processing:" ),
 
  374                    changesPerFp.size() );
 
  381            changesPerFp[item.second].push_back( &item );
 
  382            msg += wxT( 
" " ) + item.first.GetRef();
 
  388        for( 
auto& fpChangelistPair : changesPerFp )
 
  390            std::set<SCH_SYMBOL*>        swappedSymbols;
 
  391            std::set<CHANGELIST_ITEM*>   swappedItems;
 
  392            std::shared_ptr<PCB_FP_DATA> fp = fpChangelistPair.first;
 
  393            auto&                        changedFpItems = fpChangelistPair.second;
 
  406                std::map<wxString, wxString> schNetsByPin;   
 
  407                std::map<wxString, wxString> pcbNetsByPin;   
 
  408                std::vector<wxString>        unitPinNumbers; 
 
  409                std::vector<wxString>        schNetsInUnitOrder;
 
  410                std::vector<wxString>        pcbNetsInUnitOrder;
 
  414            std::vector<SYM_UNIT> symbolUnits;
 
  416            std::map<LIB_SYMBOL*, std::vector<LIB_SYMBOL::UNIT_PIN_INFO>> unitPinsByLibSymbol;
 
  419                [&]( 
SCH_SYMBOL* symbol, 
int unitNumber ) -> std::vector<wxString>
 
  421                    if( unitNumber <= 0 )
 
  432                    auto found = unitPinsByLibSymbol.find( libSymbol );
 
  434                    if( found == unitPinsByLibSymbol.end() )
 
  435                        found = unitPinsByLibSymbol.emplace( libSymbol, libSymbol->
GetUnitPinInfo() ).first;
 
  437                    const std::vector<LIB_SYMBOL::UNIT_PIN_INFO>& unitInfos = found->second;
 
  439                    if( unitNumber > 
static_cast<int>( unitInfos.size() ) )
 
  442                    return unitInfos[unitNumber - 1].m_pinNumbers;
 
  446            auto netsInUnitOrder =
 
  447                   []( 
const std::vector<wxString>& pins,
 
  448                       const std::map<wxString, wxString>& netByPin )
 
  450                       std::vector<wxString> nets;
 
  454                           nets.reserve( pins.size() );
 
  456                           for( 
const wxString& pinNum : pins )
 
  458                               auto it = netByPin.find( pinNum );
 
  459                               nets.push_back( it != netByPin.end() ? it->second : wxString() );
 
  464                           nets.reserve( netByPin.size() );
 
  466                           for( 
const std::pair<const wxString, wxString>& 
kv : netByPin )
 
  467                               nets.push_back( 
kv.second );
 
  485                symbolUnit.sym = symbol;
 
  486                symbolUnit.screen = screen;
 
  489                symbolUnit.changeItem = changedItem;
 
  491                int currentUnit = ref.
GetUnit();
 
  493                if( currentUnit <= 0 )
 
  496                if( currentUnit <= 0 )
 
  497                    currentUnit = symbol->
GetUnit();
 
  499                symbolUnit.currentUnit = currentUnit;
 
  500                symbolUnit.unitPinNumbers = getUnitPins( symbol, symbolUnit.currentUnit );
 
  506                    const wxString& pinNum = 
pin->GetNumber();
 
  509                    auto it = fp->m_pinMap.find( pinNum );
 
  510                    symbolUnit.pcbNetsByPin[pinNum] = ( it != fp->m_pinMap.end() ) ? it->second : wxString();
 
  516                            symbolUnit.schNetsByPin[pinNum] = connection->Name( 
true );
 
  518                            symbolUnit.schNetsByPin[pinNum] = wxString();
 
  521                        symbolUnit.schNetsByPin[pinNum] = wxString();
 
  524                symbolUnit.pcbNetsInUnitOrder = netsInUnitOrder( symbolUnit.unitPinNumbers, symbolUnit.pcbNetsByPin );
 
  525                symbolUnit.schNetsInUnitOrder = netsInUnitOrder( symbolUnit.unitPinNumbers, symbolUnit.schNetsByPin );
 
  527                symbolUnits.push_back( symbolUnit );
 
  530            auto vectorToString =
 
  531                    []( 
const std::vector<wxString>& values ) -> wxString
 
  533                        return fmt::format( 
L"{}", fmt::join( values, 
L", " ) );
 
  537                    [vectorToString]( 
const std::map<wxString, wxString>& pinMap ) -> wxString
 
  539                        std::vector<wxString> entries;
 
  541                        for( 
const std::pair<const wxString, wxString>& 
pin : pinMap )
 
  542                            entries.push_back( 
pin.first + 
'=' + 
pin.second );
 
  544                        return vectorToString( entries );
 
  547            msg.Printf( wxT( 
"DEBUG(unit-swap): footprint %s processed (%zu units, dryRun=%d)." ), fp->m_ref,
 
  548                        symbolUnits.size(), 
m_dryRun ? 1 : 0 );
 
  552            std::sort( symbolUnits.begin(), symbolUnits.end(),
 
  553                       []( 
const SYM_UNIT& a, 
const SYM_UNIT& b )
 
  555                           return a.ref < b.ref;
 
  559            std::vector<SYM_UNIT*> symbolUnitPtrs;
 
  561            for( SYM_UNIT& su : symbolUnits )
 
  562                symbolUnitPtrs.push_back( &su );
 
  564            for( 
const SYM_UNIT& su : symbolUnits )
 
  566                wxString pcbPins = mapToString( su.pcbNetsByPin );
 
  567                wxString schPins = mapToString( su.schNetsByPin );
 
  568                wxString unitPins = vectorToString( su.unitPinNumbers );
 
  569                wxString pcbUnitNetSeq = vectorToString( su.pcbNetsInUnitOrder );
 
  570                wxString schUnitNetSeq = vectorToString( su.schNetsInUnitOrder );
 
  572                msg.Printf( wxT( 
"DEBUG(unit-swap):   unit %d: %s pcbPins[%s] schPins[%s] unitPins[%s] pcbUnitNets[%s] " 
  573                                 "schUnitNets[%s]." ),
 
  574                            su.currentUnit, su.ref, pcbPins, schPins, unitPins, pcbUnitNetSeq, schUnitNetSeq );
 
  578            if( symbolUnits.size() < 2 )
 
  586            std::map<SYM_UNIT*, SYM_UNIT*> desiredTarget;
 
  587            std::set<SYM_UNIT*>            usedTargets;
 
  588            bool                           mappingOk = 
true;
 
  590            for( SYM_UNIT* symbolUnit : symbolUnitPtrs )
 
  592                SYM_UNIT* match = 
nullptr;
 
  594                for( SYM_UNIT* potentialMatch : symbolUnitPtrs )
 
  596                    if( usedTargets.count( potentialMatch ) )
 
  599                    if( symbolUnit->pcbNetsInUnitOrder == potentialMatch->schNetsInUnitOrder )
 
  601                        match = potentialMatch;
 
  608                    wxString pcbPins = mapToString( symbolUnit->pcbNetsByPin );
 
  609                    wxString schPins = mapToString( symbolUnit->schNetsByPin );
 
  610                    wxString unitPins = vectorToString( symbolUnit->unitPinNumbers );
 
  611                    wxString pcbUnitNetSeq = vectorToString( symbolUnit->pcbNetsInUnitOrder );
 
  612                    wxString schUnitNetSeq = vectorToString( symbolUnit->schNetsInUnitOrder );
 
  614                    msg.Printf( wxT( 
"DEBUG(unit-swap): no schematic match for %s (%s) pcbPins[%s] schPins[%s] " 
  615                                     "unitPins[%s] pcbUnitNets[%s] schUnitNets[%s]." ),
 
  616                                symbolUnit->ref, fp->m_ref, pcbPins, schPins, unitPins, pcbUnitNetSeq, schUnitNetSeq );
 
  622                msg.Printf( wxT( 
"DEBUG(unit-swap): %s matches %s for footprint %s." ), symbolUnit->ref, match->ref,
 
  625                desiredTarget[symbolUnit] = match;
 
  626                usedTargets.insert( match );
 
  631                msg.Printf( wxT( 
"DEBUG(unit-swap): mapping failed for footprint %s." ), fp->m_ref );
 
  637            bool isIdentity = 
true;
 
  639            for( SYM_UNIT* su : symbolUnitPtrs )
 
  641                auto it = desiredTarget.find( su );
 
  643                if( it == desiredTarget.end() || it->second != su )
 
  652                msg.Printf( wxT( 
"DEBUG(unit-swap): footprint %s already aligned (identity mapping)." ), fp->m_ref );
 
  658            std::set<SYM_UNIT*> visited;
 
  660            for( SYM_UNIT* symbolUnit : symbolUnitPtrs )
 
  662                SYM_UNIT* start = symbolUnit;
 
  664                if( visited.count( start ) )
 
  668                std::vector<SYM_UNIT*> cycle;
 
  669                SYM_UNIT*              cur = start;
 
  671                while( !visited.count( cur ) )
 
  673                    visited.insert( cur );
 
  674                    cycle.push_back( cur );
 
  676                    auto nextIt = desiredTarget.find( cur );
 
  678                    if( nextIt == desiredTarget.end() )
 
  681                    SYM_UNIT* nextSym = nextIt->second;
 
  683                    if( !nextSym || nextSym == cur )
 
  689                if( cycle.size() < 2 )
 
  691                    msg.Printf( wxT( 
"DEBUG(unit-swap): cycle length %zu for footprint %s starting at %s." ),
 
  692                                cycle.size(), fp->m_ref, start->ref );
 
  701                    for( SYM_UNIT* s : cycle )
 
  702                        commit.
Modify( s->sym, s->screen );
 
  705                for( 
size_t i = cycle.size() - 1; i > 0; --i )
 
  707                    SYM_UNIT* a = cycle[i - 1];
 
  708                    SYM_UNIT* b = cycle[i];
 
  709                    int       aUnit = a->currentUnit;
 
  710                    int       bUnit = b->currentUnit;
 
  715                        a->sym->SetUnit( bUnit );
 
  716                        b->sym->SetUnit( aUnit );
 
  719                            a->sym->SetUnitSelection( sheet, bUnit );
 
  722                            b->sym->SetUnitSelection( sheet, aUnit );
 
  725                    a->currentUnit = bUnit;
 
  726                    b->currentUnit = aUnit;
 
  728                    swappedSymbols.insert( a->sym );
 
  729                    swappedSymbols.insert( b->sym );
 
  734                        swappedItems.insert( a->changeItem );
 
  735                        unitSwapItems.insert( a->changeItem );
 
  740                        swappedItems.insert( b->changeItem );
 
  741                        unitSwapItems.insert( b->changeItem );
 
  744                    wxString baseRef = a->sym->GetRef( a->sheetPath, 
false );
 
  745                    wxString unitAString = a->sym->SubReference( aUnit, 
false );
 
  746                    wxString unitBString = b->sym->SubReference( bUnit, 
false );
 
  748                    if( unitAString.IsEmpty() )
 
  749                        unitAString.Printf( wxT( 
"%d" ), aUnit );
 
  751                    if( unitBString.IsEmpty() )
 
  752                        unitBString.Printf( wxT( 
"%d" ), bUnit );
 
  754                    msg.Printf( 
_( 
"Swap %s unit %s with unit %s." ),
 
  762                msg.Printf( wxT( 
"DEBUG(unit-swap): applied %zu swap steps for footprint %s." ), cycle.size() - 1,
 
  772                    SCH_SYMBOL* symbol = changedItem->first.GetSymbol();
 
  777                    if( swappedItems.count( changedItem ) || swappedSymbols.count( symbol ) )
 
  780                    int updatedUnit = symbol->
GetUnitSelection( &changedItem->first.GetSheetPath() );
 
  781                    changedItem->first.SetUnit( updatedUnit );
 
  799        bool skip = ( ref.
GetSymbol()->GetFlags() & 
SKIP_STRUCT ) > 0 || unitSwapItems.count( &item ) > 0;
 
  802                []( 
bool b ) -> wxString
 
  804                    return b ? 
_( 
"true" ) : 
_( 
"false" );
 
  814            msg.Printf( 
_( 
"Change %s reference designator to '%s'." ),
 
  828            msg.Printf( 
_( 
"Change %s footprint assignment from '%s' to '%s'." ),
 
  843            msg.Printf( 
_( 
"Change %s value from '%s' to '%s'." ),
 
  857            msg.Printf( 
_( 
"Change %s 'Do not populate' from '%s' to '%s'." ),
 
  859                        boolString( oldDNP ),
 
  860                        boolString( fpData.
m_DNP ) );
 
  871            msg.Printf( 
_( 
"Change %s 'Exclude from bill of materials' from '%s' to '%s'." ),
 
  873                        boolString( oldExBOM ),
 
  882        std::set<wxString> swappedPins;
 
  890            for( 
const std::pair<const wxString, wxString>& entry : fpData.
m_pinMap )
 
  892                const wxString& pinNumber = entry.first;
 
  893                const wxString& shortNetName = entry.second;
 
  897                if( swappedPins.count( pinNumber ) > 0 )
 
  902                    msg.Printf( 
_( 
"Cannot find %s pin '%s'." ),
 
  912                if( connection && connection->
Name( 
true ) != shortNetName )
 
  915                                          connection->
Name( 
true ), shortNetName );
 
  923            for( 
const std::pair<const wxString, wxString>& field : fpData.
m_fieldsMap )
 
  925                const wxString& fpFieldName = field.first;
 
  926                const wxString& fpFieldValue = field.second;
 
  945                    msg.Printf( 
_( 
"Change %s field '%s' value to '%s'." ),
 
  951                        symField->
SetText( fpFieldValue );
 
  957                if( symField == 
nullptr )
 
  960                    msg.Printf( 
_( 
"Add %s field '%s' with value '%s'." ),
 
  968                        newField.
SetText( fpFieldValue );
 
  983                if( field.IsMandatory() )
 
  990                    msg.Printf( 
_( 
"Delete %s field '%s.'" ),
 
 1005        unitSwapItems.erase( &item );
 
 1013        m_frame->UpdateNetHighlightStatus();
 
 1015        commit.
Push( 
_( 
"Update Schematic from PCB" ) );
 
 
 1058    ORIENT o = orientations[ 0 ];
 
 1067    for( 
const ORIENT& i : orientations )
 
 1069        if( i.flag == symbolOrientation )
 
 1076    for( 
int i = 0; i < o.n_rots; i++ )
 
 
 1091    if( connectedItems.insert( aItem ).second )
 
 
 1104    std::set<wxString> swappedPins;
 
 1114    wxCHECK( 
m_frame, swappedPins );
 
 1121        wxString currentNet;
 
 1125    std::vector<PIN_CHANGE> mismatches;
 
 1128    std::map<wxString, std::vector<size_t>> pinsByCurrentNet;
 
 1131    for( 
const std::pair<const wxString, wxString>& entry : aFpData.
m_pinMap )
 
 1133        const wxString& pinNumber = entry.first;
 
 1134        const wxString& desiredNet = entry.second;
 
 1143        if( !
pin || 
pin->IsPower() || !
pin->IsConnectable() )
 
 1147        wxString        currentNet = connection ? connection->
Name( 
true ) : wxString();
 
 1149        if( desiredNet.IsEmpty() || currentNet.IsEmpty() )
 
 1152        if( desiredNet == currentNet )
 
 1155        size_t idx = mismatches.size();
 
 1156        mismatches.push_back( { 
pin, pinNumber, currentNet, desiredNet } );
 
 1157        pinsByCurrentNet[currentNet].push_back( idx );
 
 1160    if( mismatches.size() < 2 )
 
 1165    std::vector<bool>     handled( mismatches.size(), 
false );
 
 1166    std::vector<SCH_PIN*> swappedPinObjects;
 
 1167    bool                  swappedLibPins = 
false;
 
 1170    bool allowPinSwaps = 
false;
 
 1171    wxString currentProjectName = 
m_frame->Prj().GetProjectName();
 
 1174        allowPinSwaps = 
m_frame->eeconfig()->m_Input.allow_unconstrained_pin_swaps;
 
 1176    std::set<wxString> sharedSheetPaths;
 
 1177    std::set<wxString> sharedProjectNames;
 
 1179                                                                    &sharedSheetPaths, &sharedProjectNames );
 
 1181    std::set<wxString> friendlySheetNames;
 
 1183    if( sharedSheetSymbol && !sharedSheetPaths.empty() )
 
 1188    for( 
size_t i = 0; i < mismatches.size(); ++i )
 
 1194        PIN_CHANGE& change = mismatches[i];
 
 1197        auto range = pinsByCurrentNet.find( change.targetNet );
 
 1200        if( range == pinsByCurrentNet.end() )
 
 1204        size_t partnerIdx = std::numeric_limits<size_t>::max();
 
 1207        for( 
size_t candidateIdx : range->second )
 
 1209            if( candidateIdx == i || handled[candidateIdx] )
 
 1212            PIN_CHANGE& candidate = mismatches[candidateIdx];
 
 1216            if( candidate.targetNet == change.currentNet )
 
 1218                partnerIdx = candidateIdx;
 
 1225        if( partnerIdx == std::numeric_limits<size_t>::max() )
 
 1228        PIN_CHANGE& partner = mismatches[partnerIdx];
 
 1232        if( change.pin->GetParentSymbol() != partner.pin->GetParentSymbol() )
 
 1235        if( !allowPinSwaps || sharedSheetSymbol )
 
 1237            if( !sharedProjectNames.empty() )
 
 1239                std::vector<wxString> otherProjects;
 
 1241                for( 
const wxString& 
name : sharedProjectNames )
 
 1243                    if( !currentProjectName.IsEmpty() && 
name.IsSameAs( currentProjectName ) )
 
 1246                    otherProjects.push_back( 
name );
 
 1251                if( projects.IsEmpty() )
 
 1253                    msg.Printf( 
_( 
"Would swap %s pins %s and %s to match PCB, but the symbol is shared across other projects." ),
 
 1256                                EscapeHTML( partner.pin->GetShownNumber() ) );
 
 1260                    msg.Printf( 
_( 
"Would swap %s pins %s and %s to match PCB, but the symbol is shared across other " 
 1263                                EscapeHTML( partner.pin->GetShownNumber() ), projects );
 
 1266            else if( !friendlySheetNames.empty() )
 
 1270                msg.Printf( 
_( 
"Would swap %s pins %s and %s to match PCB, but the symbol is used by multiple sheet " 
 1271                               "instances (%s)." ),
 
 1274                            EscapeHTML( partner.pin->GetShownNumber() ), sheets );
 
 1276            else if( sharedSheetSymbol )
 
 1278                msg.Printf( 
_( 
"Would swap %s pins %s and %s to match PCB, but the symbol is shared." ),
 
 1281                            EscapeHTML( partner.pin->GetShownNumber() ) );
 
 1285                msg.Printf( 
_( 
"Would swap %s pins %s and %s to match PCB, but unconstrained pin swaps are disabled in " 
 1286                               "the schematic preferences." ),
 
 1289                            EscapeHTML( partner.pin->GetShownNumber() ) );
 
 1294            handled[partnerIdx] = 
true;
 
 1300            wxCHECK2( aCommit, 
continue );
 
 1311        handled[partnerIdx] = 
true;
 
 1314        swappedPins.insert( change.pinNumber );
 
 1315        swappedPins.insert( partner.pinNumber );
 
 1316        swappedPinObjects.push_back( change.pin );
 
 1317        swappedPinObjects.push_back( partner.pin );
 
 1321        msg.Printf( 
_( 
"Swap %s pins %s and %s to match PCB." ),
 
 1324                    EscapeHTML( partner.pin->GetShownNumber() ) );
 
 1329    if( swappedPinObjects.empty() )
 
 1334        if( swappedLibPins )
 
 1337        m_frame->UpdateItem( aSymbol, 
false, 
true );
 
 1346                for( 
SCH_PIN* swappedPin : swappedPinObjects )
 
 1347                    cleanupSelection.
Add( swappedPin );
 
 1349                lwbTool->TrimOverLappingWires( aCommit, &cleanupSelection );
 
 1350                lwbTool->AddJunctionsIfNeeded( aCommit, &cleanupSelection );
 
 1354        m_frame->Schematic().CleanUp( aCommit );
 
 
 1363                                          const wxString& aOldName, 
const wxString& aNewName )
 
 1371    std::set<SCH_ITEM*>           connectedItems;
 
 1377    for( 
SCH_ITEM* item : connectedItems )
 
 1381        if( priority > driverPriority )
 
 1384            driverPriority = priority;
 
 1388    switch( driver->
Type() )
 
 1396        msg.Printf( 
_( 
"Change %s pin %s net label from '%s' to '%s'." ),
 
 1418            msg.Printf( 
_( 
"Net %s cannot be changed to %s because it is driven by a power pin." ),
 
 1427        msg.Printf( 
_( 
"Add label '%s' to %s pin %s net." ),
 
 1442            aCommit->
Add( label, screen );
 
 
void addConnections(SCH_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath, std::set< SCH_ITEM * > &connectedItems)
 
static SPIN_STYLE orientLabel(SCH_PIN *aPin)
 
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.
 
PRIORITY GetDriverPriority()
 
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
 
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
 
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 GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
 
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, 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 SCH_ITEM_VEC & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
 
const SYMBOL * GetParentSymbol() const
 
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
 
wxString GetShownNumber() const
 
SCH_PIN * GetLibPin() const
 
PIN_ORIENTATION GetOrientation() const
 
bool IsPower() const
Check if the pin is either a global or local power pin.
 
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, bool aIncludePowerSymbols=true) 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, bool aIncludePowerSymbols=true, 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()
 
virtual void SetDNP(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
 
void SetValueFieldText(const wxString &aValue)
 
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
 
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
 
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
 
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
 
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)
 
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.
 
bool GetExcludedFromBoard() const override
 
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
 
@ 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.
 
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.
 
Container for Pcbnew footprint data.Map to hold NETLIST footprints data.
 
std::map< wxString, wxString > m_pinMap
 
std::map< wxString, wxString > m_fieldsMap
 
@ 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".
 
wxString GetCanonicalFieldName(FIELD_T aFieldType)
 
VECTOR2< int32_t > VECTOR2I
 
Definition of file extensions used in Kicad.