40using PIN_SET = std::set<std::pair<wxString, wxString>>;
42constexpr int MAX_REPORTED = 5;
46std::map<wxString, FOOTPRINT*> uniqueFootprints(
BOARD& aBoard )
48 std::map<wxString, FOOTPRINT*> footprints;
49 std::set<wxString> repeated;
53 if( footprint->GetReference().EndsWith( wxS(
"?" ) ) )
56 if( !footprints.emplace( footprint->GetReference(), footprint ).second )
57 repeated.insert( footprint->GetReference() );
60 for(
const wxString& ref : repeated )
61 footprints.erase( ref );
70 std::set<wxString> boardRefs;
73 boardRefs.insert( footprint->GetReference() );
75 std::set<wxString> schematicRefs;
78 std::map<wxString, std::pair<wxString, int>> orphans;
80 for(
unsigned i = 0; i < aNetlist.
GetCount(); i++ )
84 schematicRefs.insert( ref );
86 if( boardRefs.count( ref ) )
89 auto& orphan = orphans[ref.Upper()];
95 std::map<wxString, std::vector<FOOTPRINT*>> claims;
99 const wxString ref = footprint->GetReference();
101 if( ref.EndsWith( wxS(
"?" ) ) || schematicRefs.count( ref ) )
104 wxString key = ref.Upper();
107 const bool prefixed = key.StartsWith( wxS(
"UNK" ) ) && key.length() > 3 && !wxIsalpha( key[3] );
109 if( prefixed && orphans.count( key ) && orphans.count( key.Mid( 3 ) ) )
112 if( prefixed && !orphans.count( key ) )
115 if( orphans.count( key ) )
116 claims[key].push_back( footprint );
121 for(
const auto& [key, footprints] : claims )
123 const auto& orphan = orphans.at( key );
125 if( orphan.second != 1 || footprints.size() != 1 )
128 footprints.front()->SetReference( orphan.first );
140 std::map<wxString, FOOTPRINT*> footprints = uniqueFootprints( aBoard );
143 std::map<wxString, PIN_SET> schematicNets;
144 std::set<wxString> shared;
146 for(
unsigned i = 0; i < aNetlist.
GetCount(); i++ )
151 if( !footprints.count( ref ) )
154 shared.insert( ref );
156 for(
unsigned j = 0; j < component->
GetNetCount(); j++ )
160 if( !
pin.GetNetName().IsEmpty() )
161 schematicNets[
pin.GetNetName()].emplace( ref,
pin.GetPinName() );
165 std::map<PIN_SET, wxString> schematicNameByPins;
167 for(
const auto& [
name, pins] : schematicNets )
168 schematicNameByPins.emplace( pins,
name );
171 std::map<wxString, PIN_SET> boardNets;
172 std::map<std::pair<wxString, wxString>, std::vector<PAD*>> bareJoins;
174 for(
const wxString& ref : shared )
176 for(
PAD*
pad : footprints.at( ref )->Pads() )
178 std::pair<wxString, wxString> key( ref,
pad->GetNumber() );
180 if(
pad->GetNetCode() > 0 )
181 boardNets[
pad->GetNetname()].insert( key );
183 bareJoins[key].push_back(
pad );
187 std::map<wxString, wxString> renames;
189 for(
const auto& [boardName, pins] : boardNets )
191 auto match = schematicNameByPins.find( pins );
193 if( match == schematicNameByPins.end() )
197 if(
result.m_conflicting <= MAX_REPORTED )
199 aReporter.
Report( wxString::Format(
_(
"Board net '%s' does not match a single schematic net.\n" ),
207 if( match->second == boardName )
210 renames.emplace( boardName, match->second );
215 for(
bool removed =
true; removed; )
219 for(
auto it = renames.begin(); it != renames.end(); )
221 if( aBoard.
FindNet( it->second ) && !renames.count( it->second ) )
224 it = renames.erase( it );
235 result.m_renamed =
static_cast<int>( renames.size() );
238 for(
const auto& [
name, pins] : schematicNets )
240 if( pins.size() != 1 || !
name.StartsWith( wxS(
"unconnected-(" ) ) || aBoard.
FindNet(
name ) )
243 auto bare = bareJoins.find( *pins.begin() );
245 if( bare == bareJoins.end() )
251 for(
PAD*
pad : bare->second )
254 result.m_unconnectedAssigned++;
257 aReporter.
Report( wxString::Format(
_(
"Named %d board nets after the schematic, %d already matched, %d differ "
258 "and %d unconnected pads named.\n" ),
260 result.m_unconnectedAssigned ),
269 std::map<wxString, FOOTPRINT*> footprints = uniqueFootprints( aBoard );
276 wxS(
"Component Class" ) };
278 for(
unsigned i = 0; i < aNetlist.
GetCount(); i++ )
281 auto found = footprints.find( component->
GetReference() );
283 if( found == footprints.end() )
287 bool changed =
false;
297 if( skipped.count(
name ) )
303 if( existing->GetText().IsEmpty() && !value.IsEmpty() )
305 existing->SetText( value );
313 footprint->
Add( field );
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
const FOOTPRINTS & Footprints() const
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Store all of the related component information found in a netlist.
const COMPONENT_NET & GetNet(unsigned aIndex) const
const wxString & GetReference() const
const wxString & GetValue() const
const nlohmann::ordered_map< wxString, wxString > & GetFields() const
unsigned GetNetCount() const
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
Handle the data for a net.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
unsigned GetCount() const
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
void SetName(const wxString &aName)
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
void SetPosition(const VECTOR2I &aPos) override
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
bool ApplyImportedNetNameMap(BOARD &aBoard, const std::map< wxString, wxString > &aNames, REPORTER &aReporter)
Apply caller-selected imported net names without changing net identity or connectivity.
int ReconcileImportedReferences(BOARD &aBoard, NETLIST &aNetlist)
Give an imported board footprint the reference its schematic symbol uses.
int FillImportedFootprintFields(BOARD &aBoard, NETLIST &aNetlist)
Copy what an imported board footprint lacks from the schematic symbol it is linked to.
NET_RECONCILE_RESULT ReconcileImportedNetNames(BOARD &aBoard, NETLIST &aNetlist, REPORTER &aReporter)
Give each net of an imported board the name its schematic uses.
Outcome of naming the nets of an imported board after the nets of its schematic.
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".
wxString result
Test unit parsing edge cases and error handling.