KiCad PCB EDA Suite
BOARD_NETLIST_UPDATER Class Reference

Class BOARD_NETLIST_UPDATER updates the BOARD with a new netlist. More...

#include <board_netlist_updater.h>

Public Member Functions

 BOARD_NETLIST_UPDATER (PCB_EDIT_FRAME *aFrame, BOARD *aBoard)
 
 ~BOARD_NETLIST_UPDATER ()
 
bool UpdateNetlist (NETLIST &aNetlist)
 Function UpdateNetlist() More...
 
bool UpdateNetlist (const wxString &aNetlistFileName, const wxString &aCmpFileName)
 
void SetReporter (REPORTER *aReporter)
 

Sets the reporter object

More...
 
void SetDeleteSinglePadNets (bool aEnabled)
 

Enables "delete single pad nets" option

More...
 
void SetIsDryRun (bool aEnabled)
 

Enables dry run mode (just report, no changes to PCB)

More...
 
void SetReplaceFootprints (bool aEnabled)
 

Enables replacing footprints with new ones

More...
 
void SetDeleteUnusedComponents (bool aEnabled)
 

Enables removing unused components

More...
 
void SetLookupByTimestamp (bool aEnabled)
 

Enables component lookup by timestamp instead of reference

More...
 
std::vector< MODULE * > GetAddedComponents () const
 

Private Member Functions

void cacheNetname (D_PAD *aPad, const wxString &aNetname)
 
wxString getNetname (D_PAD *aPad)
 
wxPoint estimateComponentInsertionPosition ()
 
MODULEaddNewComponent (COMPONENT *aComponent)
 
MODULEreplaceComponent (NETLIST &aNetlist, MODULE *aPcbComponent, COMPONENT *aNewComponent)
 
bool updateComponentParameters (MODULE *aPcbComponent, COMPONENT *aNewComponent)
 
bool updateComponentPadConnections (MODULE *aPcbComponent, COMPONENT *aNewComponent)
 
void cacheCopperZoneConnections ()
 
bool updateCopperZoneNets (NETLIST &aNetlist)
 
bool deleteUnusedComponents (NETLIST &aNetlist)
 
bool deleteSinglePadNets ()
 
bool testConnectivity (NETLIST &aNetlist)
 

Private Attributes

PCB_EDIT_FRAMEm_frame
 
BOARD_COMMIT m_commit
 
BOARDm_board
 
REPORTERm_reporter
 
std::map< ZONE_CONTAINER *, std::vector< D_PAD * > > m_zoneConnectionsCache
 
std::map< D_PAD *, wxString > m_padNets
 
std::vector< MODULE * > m_addedComponents
 
std::map< wxString, NETINFO_ITEM * > m_addedNets
 
bool m_deleteSinglePadNets
 
bool m_deleteUnusedComponents
 
bool m_isDryRun
 
bool m_replaceFootprints
 
bool m_lookupByTimestamp
 
int m_warningCount
 
int m_errorCount
 

Detailed Description

Class BOARD_NETLIST_UPDATER updates the BOARD with a new netlist.

The changes are made to the board are as follows they are not disabled in the status settings in the NETLIST:

  • If a new component is found in the NETLIST and not in the BOARD, it is added to the BOARD.
  • If a the component in the NETLIST is already on the BOARD, then one or more of the following actions can occur:
    • If the footprint name in the NETLIST does not match the footprint name on the BOARD, the footprint on the BOARD is replaced with the footprint specified in the NETLIST and the proper parameters are copied from the existing footprint.
    • If the reference designator in the NETLIST does not match the reference designator on the BOARD, the reference designator is updated from the NETLIST.
    • If the value field in the NETLIST does not match the value field on the BOARD, the value field is updated from the NETLIST.
    • If the time stamp in the NETLIST does not match the time stamp on the BOARD, the time stamp is updated from the NETLIST.
  • After each footprint is added or update as described above, each footprint pad net name is compared and updated to the value defined in the NETLIST.
  • After all of the footprints have been added, updated, and net names properly set, any extra unlock footprints are removed from the BOARD.

Definition at line 71 of file board_netlist_updater.h.

Constructor & Destructor Documentation

BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER ( PCB_EDIT_FRAME aFrame,
BOARD aBoard 
)

Definition at line 52 of file board_netlist_updater.cpp.

References NULL_REPORTER::GetInstance(), m_deleteSinglePadNets, m_deleteUnusedComponents, m_errorCount, m_isDryRun, m_lookupByTimestamp, m_replaceFootprints, m_reporter, and m_warningCount.

52  :
53  m_frame( aFrame ),
54  m_commit( aFrame ),
55  m_board( aBoard )
56 {
58 
59  m_deleteSinglePadNets = true;
61  m_isDryRun = false;
62  m_replaceFootprints = true;
63  m_lookupByTimestamp = false;
64 
65  m_warningCount = 0;
66  m_errorCount = 0;
67 }
static REPORTER & GetInstance()
Definition: reporter.cpp:104
BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER ( )

Definition at line 70 of file board_netlist_updater.cpp.

71 {
72 }

Member Function Documentation

MODULE * BOARD_NETLIST_UPDATER::addNewComponent ( COMPONENT aComponent)
private

Definition at line 120 of file board_netlist_updater.cpp.

References COMMIT::Add(), LIB_ID::empty(), estimateComponentInsertionPosition(), LIB_ID::Format(), COMPONENT::GetFPID(), GetNewTimeStamp(), COMPONENT::GetReference(), PCB_BASE_FRAME::LoadFootprint(), m_addedComponents, m_board, m_commit, m_errorCount, m_frame, m_isDryRun, m_reporter, REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, EDA_ITEM::SetParent(), MODULE::SetPosition(), EDA_ITEM::SetTimeStamp(), and UTF8::wx_str().

Referenced by GetAddedComponents(), and UpdateNetlist().

121 {
122  wxString msg;
123 
124  if( aComponent->GetFPID().empty() )
125  {
126  msg.Printf( _( "Cannot add %s (no footprint assigned)." ),
127  aComponent->GetReference(),
128  aComponent->GetFPID().Format().wx_str() );
130  ++m_errorCount;
131  return nullptr;
132  }
133 
134  MODULE* footprint = m_frame->LoadFootprint( aComponent->GetFPID() );
135 
136  if( footprint == nullptr )
137  {
138  msg.Printf( _( "Cannot add %s (footprint \"%s\" not found)." ),
139  aComponent->GetReference(),
140  aComponent->GetFPID().Format().wx_str() );
142  ++m_errorCount;
143  return nullptr;
144  }
145 
146  msg.Printf( _( "Add %s (footprint \"%s\")." ),
147  aComponent->GetReference(),
148  aComponent->GetFPID().Format().wx_str() );
150 
151  if( !m_isDryRun )
152  {
153  footprint->SetParent( m_board );
155  footprint->SetTimeStamp( GetNewTimeStamp() );
156 
157  m_addedComponents.push_back( footprint );
158  m_commit.Add( footprint );
159 
160  return footprint;
161  }
162 
163  return NULL;
164 }
bool empty() const
Definition: lib_id.h:186
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:166
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
const wxString & GetReference() const
Definition: pcb_netlist.h:151
timestamp_t GetNewTimeStamp()
Definition: common.cpp:187
wxString wx_str() const
Definition: utf8.cpp:50
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
void SetPosition(const wxPoint &aPos) override
MODULE * LoadFootprint(const LIB_ID &aFootprintId)
Function LoadFootprint attempts to load aFootprintId from the footprint library table.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
UTF8 Format() const
Definition: lib_id.cpp:237
std::vector< MODULE * > m_addedComponents
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:203
void BOARD_NETLIST_UPDATER::cacheCopperZoneConnections ( )
private

Definition at line 373 of file board_netlist_updater.cpp.

References BOARD::GetArea(), BOARD::GetAreaCount(), BOARD::GetConnectivity(), ZONE_CONTAINER::GetIsKeepout(), ZONE_CONTAINER::IsOnCopperLayer(), m_board, and m_zoneConnectionsCache.

Referenced by GetAddedComponents(), and UpdateNetlist().

374 {
375  for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
376  {
377  ZONE_CONTAINER* zone = m_board->GetArea( ii );
378 
379  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
380  continue;
381 
382  m_zoneConnectionsCache[ zone ] = m_board->GetConnectivity()->GetConnectedPads( zone );
383  }
384 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
std::map< ZONE_CONTAINER *, std::vector< D_PAD * > > m_zoneConnectionsCache
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:608
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1020
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:991
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:296
void BOARD_NETLIST_UPDATER::cacheNetname ( D_PAD aPad,
const wxString &  aNetname 
)
private

Definition at line 78 of file board_netlist_updater.cpp.

References m_padNets.

Referenced by deleteSinglePadNets(), GetAddedComponents(), and updateComponentPadConnections().

79 {
80  m_padNets[ aPad ] = aNetname;
81 }
std::map< D_PAD *, wxString > m_padNets
bool BOARD_NETLIST_UPDATER::deleteSinglePadNets ( )
private

Definition at line 496 of file board_netlist_updater.cpp.

References BOARD::BuildListOfNets(), cacheNetname(), getNetname(), BOARD::GetPads(), m_board, m_isDryRun, m_reporter, REPORTER::Report(), REPORTER::RPT_ACTION, BOARD_CONNECTED_ITEM::SetNetCode(), NETINFO_LIST::UNCONNECTED, and BOARD::Zones().

Referenced by GetAddedComponents(), and UpdateNetlist().

497 {
498  int count = 0;
499  wxString netname;
500  wxString msg;
501  D_PAD* previouspad = NULL;
502 
503  // We need the pad list for next tests.
504 
506 
507  std::vector<D_PAD*> padlist = m_board->GetPads();
508 
509  // Sort pads by netlist name
510  std::sort( padlist.begin(), padlist.end(),
511  [ this ]( D_PAD* a, D_PAD* b ) -> bool { return getNetname( a ) < getNetname( b ); } );
512 
513  for( D_PAD* pad : padlist )
514  {
515  if( getNetname( pad ).IsEmpty() )
516  continue;
517 
518  if( netname != getNetname( pad ) ) // End of net
519  {
520  if( previouspad && count == 1 )
521  {
522  // First, see if we have a copper zone attached to this pad.
523  // If so, this is not really a single pad net
524 
525  for( ZONE_CONTAINER* zone : m_board->Zones() )
526  {
527  if( !zone->IsOnCopperLayer() )
528  continue;
529 
530  if( zone->GetIsKeepout() )
531  continue;
532 
533  if( zone->GetNetname() == getNetname( previouspad ) )
534  {
535  count++;
536  break;
537  }
538  }
539 
540  if( count == 1 ) // Really one pad, and nothing else
541  {
542  msg.Printf( _( "Remove single pad net %s." ), getNetname( previouspad ) );
544 
545  if( !m_isDryRun )
546  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
547  else
548  cacheNetname( previouspad, wxEmptyString );
549  }
550  }
551 
552  netname = getNetname( pad );
553  count = 1;
554  }
555  else
556  {
557  count++;
558  }
559 
560  previouspad = pad;
561  }
562 
563  // Examine last pad
564  if( count == 1 )
565  {
566  if( !m_isDryRun )
567  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
568  else
569  cacheNetname( previouspad, wxEmptyString );
570  }
571 
572  return true;
573 }
void BuildListOfNets()
Definition: class_board.h:729
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void cacheNetname(D_PAD *aPad, const wxString &aNetname)
wxString getNetname(D_PAD *aPad)
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
ZONE_CONTAINERS & Zones()
Definition: class_board.h:256
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
bool BOARD_NETLIST_UPDATER::deleteUnusedComponents ( NETLIST aNetlist)
private

Definition at line 460 of file board_netlist_updater.cpp.

References NETLIST::GetComponentByReference(), NETLIST::GetComponentByTimeStamp(), m_board, m_commit, m_isDryRun, m_lookupByTimestamp, BOARD::m_Modules, m_reporter, MODULE::Next(), COMMIT::Remove(), REPORTER::Report(), REPORTER::RPT_ACTION, and REPORTER::RPT_WARNING.

Referenced by GetAddedComponents(), and UpdateNetlist().

461 {
462  wxString msg;
463  MODULE* nextModule;
464  const COMPONENT* component;
465 
466  for( MODULE* module = m_board->m_Modules; module != NULL; module = nextModule )
467  {
468  nextModule = module->Next();
469 
470  if( m_lookupByTimestamp )
471  component = aNetlist.GetComponentByTimeStamp( module->GetPath() );
472  else
473  component = aNetlist.GetComponentByReference( module->GetReference() );
474 
475  if( component == NULL )
476  {
477  if( module->IsLocked() )
478  {
479  msg.Printf( _( "Cannot remove unused %s (locked)." ), module->GetReference() );
481  continue;
482  }
483 
484  msg.Printf( _( "Remove unused %s." ), module->GetReference() );
486 
487  if( !m_isDryRun )
488  m_commit.Remove( module );
489  }
490  }
491 
492  return true;
493 }
MODULE * Next() const
Definition: class_module.h:123
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
DLIST< MODULE > m_Modules
Definition: class_board.h:248
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.
COMPONENT * GetComponentByTimeStamp(const wxString &aTimeStamp)
Function GetComponentByTimeStamp returns a COMPONENT by aTimeStamp.
wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition ( )
private

Definition at line 92 of file board_netlist_updater.cpp.

References EDA_RECT::Centre(), BOARD::GetBoardEdgesBoundingBox(), EDA_RECT::GetBottom(), EDA_RECT::GetHeight(), BOARD::GetPageSettings(), EDA_RECT::GetWidth(), BOARD::IsEmpty(), m_board, wxPoint::x, and wxPoint::y.

Referenced by addNewComponent(), and GetAddedComponents().

93 {
94  wxPoint bestPosition;
95 
96  if( !m_board->IsEmpty() )
97  {
98  // Position new components below any existing board features.
100 
101  if( bbox.GetWidth() || bbox.GetHeight() )
102  {
103  bestPosition.x = bbox.Centre().x;
104  bestPosition.y = bbox.GetBottom() + Millimeter2iu( 10 );
105  }
106  }
107  else
108  {
109  // Position new components in the center of the page when the board is empty.
110  wxSize pageSize = m_board->GetPageSettings().GetSizeIU();
111 
112  bestPosition.x = pageSize.GetWidth() / 2;
113  bestPosition.y = pageSize.GetHeight() / 2;
114  }
115 
116  return bestPosition;
117 }
int GetHeight() const
Definition: eda_rect.h:118
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:804
bool IsEmpty() const
Definition: class_board.h:272
int GetBottom() const
Definition: eda_rect.h:122
wxPoint Centre() const
Definition: eda_rect.h:60
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:553
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetWidth() const
Definition: eda_rect.h:117
wxString BOARD_NETLIST_UPDATER::getNetname ( D_PAD aPad)
private

Definition at line 83 of file board_netlist_updater.cpp.

References BOARD_CONNECTED_ITEM::GetNetname(), m_isDryRun, and m_padNets.

Referenced by deleteSinglePadNets(), GetAddedComponents(), and updateCopperZoneNets().

84 {
85  if( m_isDryRun && m_padNets.count( aPad ) )
86  return m_padNets[ aPad ];
87  else
88  return aPad->GetNetname();
89 }
std::map< D_PAD *, wxString > m_padNets
const wxString & GetNetname() const
Function GetNetname.
MODULE * BOARD_NETLIST_UPDATER::replaceComponent ( NETLIST aNetlist,
MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 167 of file board_netlist_updater.cpp.

References LIB_ID::empty(), PCB_EDIT_FRAME::Exchange_Module(), LIB_ID::Format(), COMPONENT::GetFPID(), MODULE::GetFPID(), COMPONENT::GetReference(), MODULE::GetReference(), PCB_BASE_FRAME::LoadFootprint(), m_commit, m_errorCount, m_frame, m_isDryRun, m_reporter, REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, and UTF8::wx_str().

Referenced by GetAddedComponents(), and UpdateNetlist().

169 {
170  wxString msg;
171 
172  if( aNewComponent->GetFPID().empty() )
173  {
174  msg.Printf( _( "Cannot update %s (no footprint assigned)." ),
175  aNewComponent->GetReference(),
176  aNewComponent->GetFPID().Format().wx_str() );
178  ++m_errorCount;
179  return nullptr;
180  }
181 
182  MODULE* newFootprint = m_frame->LoadFootprint( aNewComponent->GetFPID() );
183 
184  if( newFootprint == nullptr )
185  {
186  msg.Printf( _( "Cannot update %s (footprint \"%s\" not found)." ),
187  aNewComponent->GetReference(),
188  aNewComponent->GetFPID().Format().wx_str() );
190  ++m_errorCount;
191  return nullptr;
192  }
193 
194  msg.Printf( _( "Change %s footprint from \"%s\" to \"%s\"."),
195  aPcbComponent->GetReference(),
196  aPcbComponent->GetFPID().Format().wx_str(),
197  aNewComponent->GetFPID().Format().wx_str() );
199 
200  if( !m_isDryRun )
201  {
202  m_frame->Exchange_Module( aPcbComponent, newFootprint, m_commit, true, true, true );
203  return newFootprint;
204  }
205 
206  return nullptr;
207 }
bool empty() const
Definition: lib_id.h:186
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:166
const wxString & GetReference() const
Definition: pcb_netlist.h:151
const LIB_ID & GetFPID() const
Definition: class_module.h:193
wxString wx_str() const
Definition: utf8.cpp:50
MODULE * LoadFootprint(const LIB_ID &aFootprintId)
Function LoadFootprint attempts to load aFootprintId from the footprint library table.
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:460
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
UTF8 Format() const
Definition: lib_id.cpp:237
void Exchange_Module(MODULE *aSrc, MODULE *aDest, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true)
Function Exchange_Module Replaces OldModule by NewModule, using OldModule settings: position...
void BOARD_NETLIST_UPDATER::SetDeleteSinglePadNets ( bool  aEnabled)
inline

Enables "delete single pad nets" option

Definition at line 97 of file board_netlist_updater.h.

References m_deleteSinglePadNets.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

98  {
99  m_deleteSinglePadNets = aEnabled;
100  }
void BOARD_NETLIST_UPDATER::SetDeleteUnusedComponents ( bool  aEnabled)
inline

Enables removing unused components

Definition at line 115 of file board_netlist_updater.h.

References m_deleteUnusedComponents.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

116  {
117  m_deleteUnusedComponents = aEnabled;
118  }
void BOARD_NETLIST_UPDATER::SetIsDryRun ( bool  aEnabled)
inline

Enables dry run mode (just report, no changes to PCB)

Definition at line 103 of file board_netlist_updater.h.

References m_isDryRun.

104  {
105  m_isDryRun = aEnabled;
106  }
void BOARD_NETLIST_UPDATER::SetLookupByTimestamp ( bool  aEnabled)
inline

Enables component lookup by timestamp instead of reference

Definition at line 121 of file board_netlist_updater.h.

References m_lookupByTimestamp.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

122  {
123  m_lookupByTimestamp = aEnabled;
124  }
void BOARD_NETLIST_UPDATER::SetReplaceFootprints ( bool  aEnabled)
inline

Enables replacing footprints with new ones

Definition at line 109 of file board_netlist_updater.h.

References m_replaceFootprints.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

110  {
111  m_replaceFootprints = aEnabled;
112  }
void BOARD_NETLIST_UPDATER::SetReporter ( REPORTER aReporter)
inline

Sets the reporter object

Definition at line 91 of file board_netlist_updater.h.

References m_reporter.

Referenced by DIALOG_UPDATE_PCB::PerformUpdate().

92  {
93  m_reporter = aReporter;
94  }
bool BOARD_NETLIST_UPDATER::testConnectivity ( NETLIST aNetlist)
private

Definition at line 576 of file board_netlist_updater.cpp.

References BOARD::FindModuleByReference(), MODULE::FindPadByName(), LIB_ID::Format(), NETLIST::GetComponent(), NETLIST::GetCount(), MODULE::GetFPID(), COMPONENT::GetNet(), COMPONENT::GetNetCount(), COMPONENT_NET::GetPinName(), COMPONENT::GetReference(), i, m_board, m_errorCount, m_reporter, REPORTER::Report(), REPORTER::RPT_ERROR, and UTF8::wx_str().

Referenced by GetAddedComponents(), and UpdateNetlist().

577 {
578  // Verify that board contains all pads in netlist: if it doesn't then footprints are
579  // wrong or missing.
580  // Note that we use references to find the footprints as they're already updated by this
581  // point (whether by-reference or by-timestamp).
582 
583  wxString msg;
584  wxString padname;
585 
586  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
587  {
588  const COMPONENT* component = aNetlist.GetComponent( i );
589  MODULE* footprint = m_board->FindModuleByReference( component->GetReference() );
590 
591  if( footprint == NULL ) // It can be missing in partial designs
592  continue;
593 
594  // Explore all pins/pads in component
595  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
596  {
597  const COMPONENT_NET& net = component->GetNet( jj );
598  padname = net.GetPinName();
599 
600  if( footprint->FindPadByName( padname ) )
601  continue; // OK, pad found
602 
603  // not found: bad footprint, report error
604  msg.Printf( _( "%s pad %s not found in %s." ),
605  component->GetReference(),
606  padname,
607  footprint->GetFPID().Format().wx_str() );
609  ++m_errorCount;
610  }
611  }
612 
613  return true;
614 }
const wxString & GetPinName() const
Definition: pcb_netlist.h:61
D_PAD * FindPadByName(const wxString &aPadName) const
Function FindPadByName returns a D_PAD* with a matching name.
MODULE * FindModuleByReference(const wxString &aReference) const
Function FindModuleByReference searches for a MODULE within this board with the given reference desig...
const wxString & GetReference() const
Definition: pcb_netlist.h:151
Class COMPONENT_NET is used to store the component pin name to net name associations stored in a netl...
Definition: pcb_netlist.h:48
const LIB_ID & GetFPID() const
Definition: class_module.h:193
wxString wx_str() const
Definition: utf8.cpp:50
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:265
size_t i
Definition: json11.cpp:597
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
UTF8 Format() const
Definition: lib_id.cpp:237
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:139
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
unsigned GetNetCount() const
Definition: pcb_netlist.h:137
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections ( MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 275 of file board_netlist_updater.cpp.

References COMMIT::Add(), cacheNetname(), MODULE::Clone(), BOARD::FindNet(), COMPONENT::GetNet(), COMPONENT_NET::GetNetName(), MODULE::GetReference(), COMMIT::GetStatus(), COMPONENT_NET::IsValid(), m_addedNets, m_board, m_commit, m_isDryRun, m_reporter, COMMIT::Modified(), D_PAD::Next(), MODULE::PadsList(), REPORTER::Report(), REPORTER::RPT_ACTION, and NETINFO_LIST::UNCONNECTED.

Referenced by GetAddedComponents(), and UpdateNetlist().

277 {
278  wxString msg;
279 
280  // Create a copy only if the module has not been added during this update
281  MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
282  bool changed = false;
283 
284  // At this point, the component footprint is updated. Now update the nets.
285  for( D_PAD* pad = aPcbComponent->PadsList(); pad; pad = pad->Next() )
286  {
287  COMPONENT_NET net = aNewComponent->GetNet( pad->GetName() );
288 
289  if( !net.IsValid() ) // New footprint pad has no net.
290  {
291  if( !pad->GetNetname().IsEmpty() )
292  {
293  msg.Printf( _( "Disconnect %s pin %s." ),
294  aPcbComponent->GetReference(),
295  pad->GetName() );
297  }
298 
299  if( !m_isDryRun )
300  {
301  changed = true;
302  pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
303  }
304  else
305  cacheNetname( pad, wxEmptyString );
306  }
307  else // New footprint pad has a net.
308  {
309  if( net.GetNetName() != pad->GetNetname() )
310  {
311  const wxString& netName = net.GetNetName();
312  NETINFO_ITEM* netinfo = m_board->FindNet( netName );
313 
314  if( netinfo == nullptr )
315  {
316  // It might be a new net that has not been added to the board yet
317  if( m_addedNets.count( netName ) )
318  netinfo = m_addedNets[ netName ];
319  }
320 
321  if( netinfo == nullptr )
322  {
323  // It is a new net, we have to add it
324  if( !m_isDryRun )
325  {
326  changed = true;
327  netinfo = new NETINFO_ITEM( m_board, netName );
328  m_commit.Add( netinfo );
329  m_addedNets[netName] = netinfo;
330  }
331 
332  msg.Printf( _( "Add net %s." ), netName );
334  }
335 
336  if( !pad->GetNetname().IsEmpty() )
337  {
338  msg.Printf( _( "Reconnect %s pin %s from %s to %s."),
339  aPcbComponent->GetReference(),
340  pad->GetName(),
341  pad->GetNetname(),
342  netName );
343  }
344  else
345  {
346  msg.Printf( _( "Connect %s pin %s to %s."),
347  aPcbComponent->GetReference(),
348  pad->GetName(),
349  netName );
350  }
352 
353  if( !m_isDryRun )
354  {
355  changed = true;
356  pad->SetNet( netinfo );
357  }
358  else
359  cacheNetname( pad, netName );
360  }
361  }
362  }
363 
364  if( changed && copy )
365  m_commit.Modified( aPcbComponent, copy );
366  else
367  delete copy;
368 
369  return true;
370 }
void cacheNetname(D_PAD *aPad, const wxString &aNetname)
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
int GetStatus(EDA_ITEM *aItem)
Returns status of an item.
Definition: commit.cpp:120
bool IsValid() const
Definition: pcb_netlist.h:65
std::map< wxString, NETINFO_ITEM * > m_addedNets
Class COMPONENT_NET is used to store the component pin name to net name associations stored in a netl...
Definition: pcb_netlist.h:48
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
D_PAD * Next() const
Definition: class_pad.h:160
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.h:110
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:460
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:139
DLIST< D_PAD > & PadsList()
Definition: class_module.h:163
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
bool BOARD_NETLIST_UPDATER::updateComponentParameters ( MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 210 of file board_netlist_updater.cpp.

References MODULE::Clone(), MODULE::GetPath(), COMPONENT::GetReference(), MODULE::GetReference(), COMMIT::GetStatus(), COMPONENT::GetTimeStamp(), COMPONENT::GetValue(), MODULE::GetValue(), m_commit, m_isDryRun, m_reporter, COMMIT::Modified(), REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_INFO, MODULE::SetPath(), MODULE::SetReference(), and MODULE::SetValue().

Referenced by GetAddedComponents(), and UpdateNetlist().

212 {
213  wxString msg;
214 
215  // Create a copy only if the module has not been added during this update
216  MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
217  bool changed = false;
218 
219  // Test for reference designator field change.
220  if( aPcbComponent->GetReference() != aNewComponent->GetReference() )
221  {
222  msg.Printf( _( "Change %s reference to %s." ),
223  aPcbComponent->GetReference(),
224  aNewComponent->GetReference() );
226 
227  if ( !m_isDryRun )
228  {
229  changed = true;
230  aPcbComponent->SetReference( aNewComponent->GetReference() );
231  }
232  }
233 
234  // Test for value field change.
235  if( aPcbComponent->GetValue() != aNewComponent->GetValue() )
236  {
237  msg.Printf( _( "Change %s value from %s to %s." ),
238  aPcbComponent->GetReference(),
239  aPcbComponent->GetValue(),
240  aNewComponent->GetValue() );
242 
243  if( !m_isDryRun )
244  {
245  changed = true;
246  aPcbComponent->SetValue( aNewComponent->GetValue() );
247  }
248  }
249 
250  // Test for time stamp change.
251  if( aPcbComponent->GetPath() != aNewComponent->GetTimeStamp() )
252  {
253  msg.Printf( _( "Change symbol path \"%s:%s\" to \"%s\"." ),
254  aPcbComponent->GetReference(),
255  aPcbComponent->GetPath(),
256  aNewComponent->GetTimeStamp() );
258 
259  if( !m_isDryRun )
260  {
261  changed = true;
262  aPcbComponent->SetPath( aNewComponent->GetTimeStamp() );
263  }
264  }
265 
266  if( changed && copy )
267  m_commit.Modified( aPcbComponent, copy );
268  else
269  delete copy;
270 
271  return true;
272 }
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:494
int GetStatus(EDA_ITEM *aItem)
Returns status of an item.
Definition: commit.cpp:120
const wxString & GetReference() const
Definition: pcb_netlist.h:151
const wxString & GetValue() const
Definition: pcb_netlist.h:153
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:470
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:170
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.h:110
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:460
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:503
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const wxString & GetPath() const
Definition: class_module.h:202
void SetPath(const wxString &aPath)
Definition: class_module.h:203
bool BOARD_NETLIST_UPDATER::updateCopperZoneNets ( NETLIST aNetlist)
private

Definition at line 387 of file board_netlist_updater.cpp.

References BOARD::FindNet(), BOARD::GetArea(), BOARD::GetAreaCount(), NETLIST::GetComponent(), NETLIST::GetCount(), ZONE_CONTAINER::GetIsKeepout(), COMPONENT::GetNet(), COMPONENT::GetNetCount(), COMPONENT_NET::GetNetName(), BOARD_CONNECTED_ITEM::GetNetname(), getNetname(), i, ZONE_CONTAINER::IsOnCopperLayer(), m_addedNets, m_board, m_commit, m_isDryRun, m_reporter, m_warningCount, m_zoneConnectionsCache, COMMIT::Modify(), REPORTER::Report(), REPORTER::RPT_ACTION, and REPORTER::RPT_WARNING.

Referenced by GetAddedComponents(), and UpdateNetlist().

388 {
389  wxString msg;
390  std::set<wxString> netlistNetnames;
391 
392  for( int ii = 0; ii < (int) aNetlist.GetCount(); ii++ )
393  {
394  const COMPONENT* component = aNetlist.GetComponent( ii );
395  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
396  {
397  const COMPONENT_NET& net = component->GetNet( jj );
398  netlistNetnames.insert( net.GetNetName() );
399  }
400  }
401 
402  // Test copper zones to detect "dead" nets (nets without any pad):
403  for( int i = 0; i < m_board->GetAreaCount(); i++ )
404  {
405  ZONE_CONTAINER* zone = m_board->GetArea( i );
406 
407  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
408  continue;
409 
410  if( netlistNetnames.count( zone->GetNetname() ) == 0 )
411  {
412  // Look for a pad in the zone's connected-pad-cache which has been updated to
413  // a new net and use that. While this won't always be the right net, the dead
414  // net is guaranteed to be wrong.
415  wxString updatedNetname = wxEmptyString;
416 
417  for( D_PAD* pad : m_zoneConnectionsCache[ zone ] )
418  {
419  if( getNetname( pad ) != zone->GetNetname() )
420  {
421  updatedNetname = getNetname( pad );
422  break;
423  }
424  }
425 
426  if( !updatedNetname.IsEmpty() )
427  {
428  msg.Printf( _( "Reconnect copper zone from %s to %s." ),
429  zone->GetNetname(),
430  updatedNetname );
432 
433  if( !m_isDryRun )
434  {
435  NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
436 
437  if( !netinfo )
438  netinfo = m_addedNets[ updatedNetname ];
439 
440  if( netinfo )
441  {
442  m_commit.Modify( zone );
443  zone->SetNet( netinfo );
444  }
445  }
446  }
447  else
448  {
449  msg.Printf( _( "Copper zone (%s) has no pads connected." ), zone->GetNetname() );
451  ++m_warningCount;
452  }
453  }
454  }
455 
456  return true;
457 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
std::map< ZONE_CONTAINER *, std::vector< D_PAD * > > m_zoneConnectionsCache
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:608
std::map< wxString, NETINFO_ITEM * > m_addedNets
Class COMPONENT_NET is used to store the component pin name to net name associations stored in a netl...
Definition: pcb_netlist.h:48
wxString getNetname(D_PAD *aPad)
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1020
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:265
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
const wxString & GetNetname() const
Function GetNetname.
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:991
size_t i
Definition: json11.cpp:597
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:139
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
unsigned GetNetCount() const
Definition: pcb_netlist.h:137
bool BOARD_NETLIST_UPDATER::UpdateNetlist ( NETLIST aNetlist)

Function UpdateNetlist()

Updates the board's components according to the new netlist. See BOARD_NETLIST_UPDATER class description for the details of the process.

Parameters
aNetlistthe new netlist
Returns
true if process was completed successfully

Definition at line 617 of file board_netlist_updater.cpp.

References addNewComponent(), cacheCopperZoneConnections(), deleteSinglePadNets(), deleteUnusedComponents(), LIB_ID::Format(), NETLIST::GetComponent(), BOARD::GetConnectivity(), NETLIST::GetCount(), COMPONENT::GetFPID(), DLIST< T >::GetLast(), COMPONENT::GetReference(), COMPONENT::GetTimeStamp(), i, NETLIST::IsFindByTimeStamp(), m_board, m_commit, m_deleteSinglePadNets, m_deleteUnusedComponents, m_errorCount, m_isDryRun, BOARD::m_Modules, m_replaceFootprints, m_reporter, m_warningCount, MODULE::Next(), BOARD_COMMIT::Push(), replaceComponent(), REPORTER::Report(), REPORTER::ReportTail(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, REPORTER::RPT_INFO, EDA_ITEM::SetStatus(), testConnectivity(), updateComponentPadConnections(), updateComponentParameters(), updateCopperZoneNets(), and UTF8::wx_str().

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

618 {
619  wxString msg;
620  m_errorCount = 0;
621  m_warningCount = 0;
622  MODULE* lastPreexistingFootprint = m_board->m_Modules.GetLast();
623 
625 
626  if( !m_isDryRun )
627  {
628  m_board->SetStatus( 0 );
629  }
630 
631  for( unsigned i = 0; i < aNetlist.GetCount(); i++ )
632  {
633  COMPONENT* component = aNetlist.GetComponent( i );
634  int matchCount = 0;
635  MODULE* tmp;
636 
637  msg.Printf( _( "Processing component \"%s:%s:%s\"." ),
638  component->GetReference(),
639  component->GetTimeStamp(),
640  component->GetFPID().Format().wx_str() );
642 
643  for( MODULE* footprint = m_board->m_Modules; footprint; footprint = footprint->Next() )
644  {
645  bool match = false;
646 
647  if( footprint )
648  {
649  if( aNetlist.IsFindByTimeStamp() )
650  match = footprint->GetPath() == component->GetTimeStamp();
651  else
652  match = footprint->GetReference().CmpNoCase( component->GetReference() ) == 0;
653  }
654 
655  if( match )
656  {
657  tmp = footprint;
658 
659  if( m_replaceFootprints && component->GetFPID() != footprint->GetFPID() )
660  tmp = replaceComponent( aNetlist, footprint, component );
661 
662  if( tmp )
663  {
664  updateComponentParameters( tmp, component );
665  updateComponentPadConnections( tmp, component );
666  }
667 
668  matchCount++;
669  }
670 
671  if( footprint == lastPreexistingFootprint )
672  {
673  // No sense going through the newly-created footprints: end of loop
674  break;
675  }
676  }
677 
678  if( matchCount == 0 )
679  {
680  tmp = addNewComponent( component );
681 
682  if( tmp )
683  {
684  updateComponentParameters( tmp, component );
685  updateComponentPadConnections( tmp, component );
686  }
687  }
688  else if( matchCount > 1 )
689  {
690  msg.Printf( _( "Multiple footprints found for \"%s\"." ),
691  component->GetReference() );
693  }
694  }
695 
696  updateCopperZoneNets( aNetlist );
697 
699  deleteUnusedComponents( aNetlist );
700 
703 
704  if( !m_isDryRun )
705  {
706  m_commit.Push( _( "Update netlist" ) );
707  m_board->GetConnectivity()->Build( m_board );
708  testConnectivity( aNetlist );
709  }
710 
711  // Update the ratsnest
714 
715  msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
717 
718  if( m_errorCount )
719  {
720  m_reporter->ReportTail( _( "Errors occurred during the netlist update. Unless you fix them "
721  "your board will not be consistent with the schematics." ),
723  return false;
724  }
725 
726  m_reporter->ReportTail( _( "Netlist update successful!" ), REPORTER::RPT_ACTION );
727  return true;
728 }
MODULE * replaceComponent(NETLIST &aNetlist, MODULE *aPcbComponent, COMPONENT *aNewComponent)
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:166
MODULE * Next() const
Definition: class_module.h:123
bool updateComponentPadConnections(MODULE *aPcbComponent, COMPONENT *aNewComponent)
bool updateCopperZoneNets(NETLIST &aNetlist)
bool testConnectivity(NETLIST &aNetlist)
const wxString & GetReference() const
Definition: pcb_netlist.h:151
wxString wx_str() const
Definition: utf8.cpp:50
T * GetLast() const
Function GetLast returns the last T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:170
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:109
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:313
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:170
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:265
bool updateComponentParameters(MODULE *aPcbComponent, COMPONENT *aNewComponent)
DLIST< MODULE > m_Modules
Definition: class_board.h:248
size_t i
Definition: json11.cpp:597
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
void SetStatus(STATUS_FLAGS aStatus)
Definition: base_struct.h:251
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
UTF8 Format() const
Definition: lib_id.cpp:237
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
bool deleteUnusedComponents(NETLIST &aNetlist)
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:296
MODULE * addNewComponent(COMPONENT *aComponent)
bool BOARD_NETLIST_UPDATER::UpdateNetlist ( const wxString &  aNetlistFileName,
const wxString &  aCmpFileName 
)

Definition at line 731 of file board_netlist_updater.cpp.

733 {
734  return false;
735 }

Member Data Documentation

std::vector<MODULE*> BOARD_NETLIST_UPDATER::m_addedComponents
private

Definition at line 153 of file board_netlist_updater.h.

Referenced by addNewComponent(), and GetAddedComponents().

std::map<wxString, NETINFO_ITEM*> BOARD_NETLIST_UPDATER::m_addedNets
private

Definition at line 154 of file board_netlist_updater.h.

Referenced by updateComponentPadConnections(), and updateCopperZoneNets().

bool BOARD_NETLIST_UPDATER::m_deleteSinglePadNets
private
bool BOARD_NETLIST_UPDATER::m_deleteUnusedComponents
private
int BOARD_NETLIST_UPDATER::m_errorCount
private
PCB_EDIT_FRAME* BOARD_NETLIST_UPDATER::m_frame
private

Definition at line 146 of file board_netlist_updater.h.

Referenced by addNewComponent(), and replaceComponent().

bool BOARD_NETLIST_UPDATER::m_lookupByTimestamp
private
std::map< D_PAD*, wxString > BOARD_NETLIST_UPDATER::m_padNets
private

Definition at line 152 of file board_netlist_updater.h.

Referenced by cacheNetname(), and getNetname().

bool BOARD_NETLIST_UPDATER::m_replaceFootprints
private
int BOARD_NETLIST_UPDATER::m_warningCount
private
std::map< ZONE_CONTAINER*, std::vector<D_PAD*> > BOARD_NETLIST_UPDATER::m_zoneConnectionsCache
private

Definition at line 151 of file board_netlist_updater.h.

Referenced by cacheCopperZoneConnections(), and updateCopperZoneNets().


The documentation for this class was generated from the following files: