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

wxPoint estimateComponentInsertionPosition ()
 
MODULEaddNewComponent (COMPONENT *aComponent)
 
MODULEreplaceComponent (NETLIST &aNetlist, MODULE *aPcbComponent, COMPONENT *aNewComponent)
 
bool updateComponentParameters (MODULE *aPcbComponent, COMPONENT *aNewComponent)
 
bool updateComponentPadConnections (MODULE *aPcbComponent, COMPONENT *aNewComponent)
 
bool deleteUnusedComponents (NETLIST &aNetlist)
 
bool deleteSinglePadNets ()
 
bool testConnectivity (NETLIST &aNetlist)
 

Private Attributes

BOARD_COMMIT m_commit
 
BOARDm_board
 
REPORTERm_reporter
 
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.

BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER ( )

Definition at line 69 of file board_netlist_updater.cpp.

70 {
71 }

Member Function Documentation

MODULE * BOARD_NETLIST_UPDATER::addNewComponent ( COMPONENT aComponent)
private

Definition at line 102 of file board_netlist_updater.cpp.

References COMMIT::Add(), estimateComponentInsertionPosition(), LIB_ID::Format(), GetChars(), COMPONENT::GetFPID(), COMPONENT::GetModule(), GetNewTimeStamp(), COMPONENT::GetReference(), COMPONENT::GetTimeStamp(), m_addedComponents, m_board, m_commit, m_errorCount, m_isDryRun, m_reporter, REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, REPORTER::RPT_INFO, EDA_ITEM::SetParent(), MODULE::SetPosition(), and EDA_ITEM::SetTimeStamp().

Referenced by UpdateNetlist().

103 {
104  wxString msg;
105 
106  if( aComponent->GetModule() != NULL )
107  {
108  msg.Printf( _( "Adding new component \"%s:%s\" footprint \"%s\".\n" ),
109  GetChars( aComponent->GetReference() ),
110  GetChars( aComponent->GetTimeStamp() ),
111  GetChars( aComponent->GetFPID().Format() ) );
113 
114  msg.Printf( _( "Add component %s, footprint: %s.\n" ),
115  GetChars( aComponent->GetReference() ),
116  GetChars( aComponent->GetFPID().Format() ) );
118 
119 
120  if( !m_isDryRun )
121  {
122  // Owned by NETLIST, can only copy it.
123  MODULE* footprint = new MODULE( *aComponent->GetModule() );
124  footprint->SetParent( m_board );
126  footprint->SetTimeStamp( GetNewTimeStamp() );
127 
128  m_addedComponents.push_back( footprint );
129  m_commit.Add( footprint );
130 
131  return footprint;
132  }
133  }
134  else
135  {
136  msg.Printf( _( "Cannot add component %s due to missing footprint %s.\n" ),
137  GetChars( aComponent->GetReference() ),
138  GetChars( aComponent->GetFPID().Format() ) );
139 
141 
142  msg.Printf( _( "Cannot add new component \"%s:%s\" due to missing "
143  "footprint \"%s\".\n" ),
144  GetChars( aComponent->GetReference() ),
145  GetChars( aComponent->GetTimeStamp() ),
146  GetChars( aComponent->GetFPID().Format() ) );
147 
149  ++m_errorCount;
150  }
151 
152  return NULL;
153 }
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:177
time_t GetNewTimeStamp()
Definition: common.cpp:166
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
const wxString & GetReference() const
Definition: pcb_netlist.h:149
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:168
void SetPosition(const wxPoint &aPos) override
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
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
Function Format.
Definition: lib_id.cpp:263
std::vector< MODULE * > m_addedComponents
bool BOARD_NETLIST_UPDATER::deleteSinglePadNets ( )
private

Definition at line 466 of file board_netlist_updater.cpp.

References BOARD::BuildListOfNets(), BOARD::GetArea(), BOARD::GetAreaCount(), GetChars(), ZONE_CONTAINER::GetIsKeepout(), D_PAD::GetName(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_CONNECTED_ITEM::GetNetname(), BOARD::GetPads(), D_PAD::GetParent(), MODULE::GetReference(), ZONE_CONTAINER::IsOnCopperLayer(), m_board, m_isDryRun, m_reporter, REPORTER::Report(), REPORTER::RPT_ACTION, BOARD_CONNECTED_ITEM::SetNetCode(), and NETINFO_LIST::UNCONNECTED.

Referenced by UpdateNetlist().

467 {
468  int count = 0;
469  wxString netname;
470  wxString msg;
471  D_PAD* pad = NULL;
472  D_PAD* previouspad = NULL;
473 
474  // We need the pad list, for next tests.
475  // padlist is the list of pads, sorted by netname.
476 
478 
479  if( m_isDryRun )
480  return false;
481 
482  std::vector<D_PAD*> padlist = m_board->GetPads();
483 
484  for( unsigned kk = 0; kk < padlist.size(); kk++ )
485  {
486  pad = padlist[kk];
487 
488  if( pad->GetNetname().IsEmpty() )
489  continue;
490 
491  if( netname != pad->GetNetname() ) // End of net
492  {
493  if( previouspad && count == 1 )
494  {
495  // First, see if we have a copper zone attached to this pad.
496  // If so, this is not really a single pad net
497 
498  for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
499  {
500  ZONE_CONTAINER* zone = m_board->GetArea( ii );
501 
502  if( !zone->IsOnCopperLayer() )
503  continue;
504 
505  if( zone->GetIsKeepout() )
506  continue;
507 
508  if( zone->GetNet() == previouspad->GetNet() )
509  {
510  count++;
511  break;
512  }
513  }
514 
515  if( count == 1 ) // Really one pad, and nothing else
516  {
517  msg.Printf( _( "Remove single pad net %s." ),
518  GetChars( previouspad->GetNetname() ) );
520 
521  msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad '%s'\n" ),
522  GetChars( previouspad->GetNetname() ),
523  GetChars( previouspad->GetParent()->GetReference() ),
524  GetChars( previouspad->GetName() ) );
526 
527  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
528  }
529  }
530 
531  netname = pad->GetNetname();
532  count = 1;
533  }
534  else
535  {
536  count++;
537  }
538 
539  previouspad = pad;
540  }
541 
542  // Examine last pad
543  if( pad && count == 1 )
545 
546  return true;
547 }
void BuildListOfNets()
Definition: class_board.h:722
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
MODULE * GetParent() const
Definition: class_pad.h:147
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:654
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
const wxString & GetName() const
Definition: class_pad.h:175
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.h:179
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
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:982
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:419
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 ...
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
bool BOARD_NETLIST_UPDATER::deleteUnusedComponents ( NETLIST aNetlist)
private

Definition at line 423 of file board_netlist_updater.cpp.

References GetChars(), 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_INFO.

Referenced by UpdateNetlist().

424 {
425  wxString msg;
426  MODULE* nextModule;
427  const COMPONENT* component;
428 
429  for( MODULE* module = m_board->m_Modules; module != NULL; module = nextModule )
430  {
431  nextModule = module->Next();
432 
433  if( m_lookupByTimestamp )
434  component = aNetlist.GetComponentByTimeStamp( module->GetPath() );
435  else
436  component = aNetlist.GetComponentByReference( module->GetReference() );
437 
438  if( component == NULL )
439  {
440  if( module->IsLocked() )
441  {
442  msg.Printf( _( "Component %s is locked, skipping removal.\n" ),
443  GetChars( module->GetReference() ) );
445  continue;
446  }
447 
448  msg.Printf( _( "Remove component %s." ),
449  GetChars( module->GetReference() ) );
451 
452  msg.Printf( _( "Removing unused component \"%s:%s\".\n" ),
453  GetChars( module->GetReference() ),
454  GetChars( module->GetPath() ) );
456 
457  if( !m_isDryRun )
458  m_commit.Remove( module );
459  }
460  }
461 
462  return true;
463 }
MODULE * Next() const
Definition: class_module.h:100
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
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
DLIST< MODULE > m_Modules
Definition: class_board.h:245
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 74 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().

75 {
76  wxPoint bestPosition;
77 
78  if( !m_board->IsEmpty() )
79  {
80  // Position new components below any existing board features.
82 
83  if( bbox.GetWidth() || bbox.GetHeight() )
84  {
85  bestPosition.x = bbox.Centre().x;
86  bestPosition.y = bbox.GetBottom() + Millimeter2iu( 10 );
87  }
88  }
89  else
90  {
91  // Position new components in the center of the page when the board is empty.
92  wxSize pageSize = m_board->GetPageSettings().GetSizeIU();
93 
94  bestPosition.x = pageSize.GetWidth() / 2;
95  bestPosition.y = pageSize.GetHeight() / 2;
96  }
97 
98  return bestPosition;
99 }
int GetHeight() const
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:797
bool IsEmpty() const
Definition: class_board.h:268
int GetBottom() const
wxPoint Centre() const
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:547
Class EDA_RECT handles the component boundary box.
int GetWidth() const
std::vector<MODULE*> BOARD_NETLIST_UPDATER::GetAddedComponents ( ) const
inline

Definition at line 126 of file board_netlist_updater.h.

References m_addedComponents.

127  {
128  return m_addedComponents;
129  }
std::vector< MODULE * > m_addedComponents
MODULE * BOARD_NETLIST_UPDATER::replaceComponent ( NETLIST aNetlist,
MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 156 of file board_netlist_updater.cpp.

References COMMIT::Add(), MODULE::CopyNetlistSettings(), LIB_ID::empty(), LIB_ID::Format(), GetChars(), MODULE::GetFPID(), COMPONENT::GetFPID(), COMPONENT::GetModule(), MODULE::GetPath(), MODULE::GetReference(), NETLIST::IsFindByTimeStamp(), m_board, m_commit, m_errorCount, m_isDryRun, m_replaceFootprints, m_reporter, COMMIT::Remove(), REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, REPORTER::RPT_INFO, EDA_ITEM::SetParent(), MODULE::SetPath(), and MODULE::SetReference().

Referenced by UpdateNetlist().

157 {
158  wxString msg;
159 
160  if( !m_replaceFootprints )
161  return NULL;
162 
163  // Test if the footprint has not changed
164  if( aNewComponent->GetFPID().empty() || aPcbComponent->GetFPID() == aNewComponent->GetFPID() )
165  return NULL;
166 
167  if( aNewComponent->GetModule() != NULL )
168  {
169  msg.Printf( _( "Change component %s footprint from %s to %s.\n"),
170  GetChars( aPcbComponent->GetReference() ),
171  GetChars( aPcbComponent->GetFPID().Format() ),
172  GetChars( aNewComponent->GetFPID().Format() ) );
173 
175 
176  msg.Printf( _( "Replacing component \"%s:%s\" footprint \"%s\" with "
177  "\"%s\".\n" ),
178  GetChars( aPcbComponent->GetReference() ),
179  GetChars( aPcbComponent->GetPath() ),
180  GetChars( aPcbComponent->GetFPID().Format() ),
181  GetChars( aNewComponent->GetFPID().Format() ) );
182 
184 
185  if( !m_isDryRun )
186  {
187  wxASSERT( aPcbComponent != NULL );
188 
189  MODULE* newFootprint = new MODULE( *aNewComponent->GetModule() );
190  newFootprint->SetParent( m_board );
191 
192  if( aNetlist.IsFindByTimeStamp() )
193  newFootprint->SetReference( aPcbComponent->GetReference() );
194  else
195  newFootprint->SetPath( aPcbComponent->GetPath() );
196 
197  aPcbComponent->CopyNetlistSettings( newFootprint, false );
198  m_commit.Remove( aPcbComponent );
199  m_commit.Add( newFootprint );
200 
201  return newFootprint;
202  }
203  }
204  else
205  {
206  msg.Printf( _( "Cannot change component %s footprint due to missing "
207  "footprint %s.\n" ),
208  GetChars( aPcbComponent->GetReference() ),
209  GetChars( aNewComponent->GetFPID().Format() ) );
210 
212 
213  msg.Printf( _( "Cannot replace component \"%s:%s\" due to missing "
214  "footprint \"%s\".\n" ),
215  GetChars( aPcbComponent->GetReference() ),
216  GetChars( aPcbComponent->GetPath() ),
217  GetChars( aNewComponent->GetFPID().Format() ) );
218 
220 
221  ++m_errorCount;
222  }
223 
224  return NULL;
225 }
bool empty() const
Function empty.
Definition: lib_id.h:198
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:177
const LIB_ID & GetFPID() const
Definition: class_module.h:164
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:304
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:429
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:419
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
Function Format.
Definition: lib_id.cpp:263
void CopyNetlistSettings(MODULE *aModule, bool aCopyLocalSettings)
Function CopyNetlistSettings copies the netlist settings to aModule.
const wxString & GetPath() const
Definition: class_module.h:173
void SetPath(const wxString &aPath)
Definition: class_module.h:174
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.

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.

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.

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.

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 550 of file board_netlist_updater.cpp.

References BOARD::FindModuleByReference(), MODULE::FindPadByName(), LIB_ID::Format(), BOARD::GetArea(), BOARD::GetAreaCount(), GetChars(), NETLIST::GetComponent(), BOARD::GetConnectivity(), NETLIST::GetCount(), MODULE::GetFPID(), ZONE_CONTAINER::GetIsKeepout(), BOARD_CONNECTED_ITEM::GetNet(), COMPONENT::GetNet(), BOARD_CONNECTED_ITEM::GetNetCode(), COMPONENT::GetNetCount(), NETINFO_ITEM::GetNetname(), COMPONENT_NET::GetPinName(), COMPONENT::GetReference(), ZONE_CONTAINER::IsOnCopperLayer(), m_board, m_errorCount, m_reporter, m_warningCount, REPORTER::Report(), REPORTER::RPT_ERROR, and REPORTER::RPT_WARNING.

Referenced by UpdateNetlist().

551 {
552  // Last step: Some tests:
553  // verify all pads found in netlist:
554  // They should exist in footprints, otherwise the footprint is wrong
555  // note also references or time stamps are updated, so we use only
556  // the reference to find a footprint
557  //
558  // Also verify if zones have acceptable nets, i.e. nets with pads.
559  // Zone with no pad belongs to a "dead" net which happens after changes in schematic
560  // when no more pad use this net name.
561 
562  wxString msg;
563  wxString padname;
564 
565  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
566  {
567  const COMPONENT* component = aNetlist.GetComponent( i );
568  MODULE* footprint = m_board->FindModuleByReference( component->GetReference() );
569 
570  if( footprint == NULL ) // It can be missing in partial designs
571  continue;
572 
573  // Explore all pins/pads in component
574  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
575  {
576  COMPONENT_NET net = component->GetNet( jj );
577  padname = net.GetPinName();
578 
579  if( footprint->FindPadByName( padname ) )
580  continue; // OK, pad found
581 
582  // not found: bad footprint, report error
583  msg.Printf( _( "Component %s pad %s not found in footprint %s\n" ),
584  GetChars( component->GetReference() ),
585  GetChars( padname ),
586  GetChars( footprint->GetFPID().Format() ) );
588  ++m_errorCount;
589  }
590  }
591 
592  // Test copper zones to detect "dead" nets (nets without any pad):
593  for( int i = 0; i < m_board->GetAreaCount(); i++ )
594  {
595  ZONE_CONTAINER* zone = m_board->GetArea( i );
596 
597  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
598  continue;
599 
600  int nc = m_board->GetConnectivity()->GetPadCount( zone->GetNetCode() );
601 
602  if( nc == 0 )
603  {
604  msg.Printf( _( "Copper zone (net name %s): net has no pads connected." ),
605  GetChars( zone->GetNet()->GetNetname() ) );
607  ++m_warningCount;
608  }
609  }
610 
611  return true;
612 }
const wxString & GetPinName() const
Definition: pcb_netlist.h:61
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
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...
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:654
const wxString & GetReference() const
Definition: pcb_netlist.h:149
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:164
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
int GetNetCode() const
Function GetNetCode.
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:256
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.h:179
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
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
Function Format.
Definition: lib_id.cpp:263
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:137
const wxString & GetNetname() const
Function GetNetname.
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:247
unsigned GetNetCount() const
Definition: pcb_netlist.h:135
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections ( MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 313 of file board_netlist_updater.cpp.

References COMMIT::Add(), MODULE::Clone(), BOARD::FindNet(), GetChars(), COMPONENT::GetNet(), COMPONENT_NET::GetNetName(), MODULE::GetPath(), 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, REPORTER::RPT_INFO, and NETINFO_LIST::UNCONNECTED.

Referenced by UpdateNetlist().

314 {
315  wxString msg;
316 
317  // Create a copy only if the module has not been added during this update
318  MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
319  bool changed = false;
320 
321  // At this point, the component footprint is updated. Now update the nets.
322  for( D_PAD* pad = aPcbComponent->PadsList(); pad; pad = pad->Next() )
323  {
324  COMPONENT_NET net = aNewComponent->GetNet( pad->GetName() );
325 
326  if( !net.IsValid() ) // New footprint pad has no net.
327  {
328  if( !pad->GetNetname().IsEmpty() )
329  {
330  msg.Printf( _( "Disconnect component %s pin %s.\n" ),
331  GetChars( aPcbComponent->GetReference() ),
332  GetChars( pad->GetName() ) );
334 
335  msg.Printf( _( "Clearing component \"%s:%s\" pin \"%s\" net name.\n" ),
336  GetChars( aPcbComponent->GetReference() ),
337  GetChars( aPcbComponent->GetPath() ),
338  GetChars( pad->GetName() ) );
340  }
341 
342  if( !m_isDryRun )
343  {
344  changed = true;
345  pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
346  }
347  }
348  else // New footprint pad has a net.
349  {
350  if( net.GetNetName() != pad->GetNetname() )
351  {
352  const wxString& netName = net.GetNetName();
353  NETINFO_ITEM* netinfo = m_board->FindNet( netName );
354 
355  if( netinfo == nullptr )
356  {
357  // It might be a new net that has not been added to the board yet
358  auto netIt = m_addedNets.find( netName );
359 
360  if( netIt != m_addedNets.end() )
361  netinfo = netIt->second;
362  }
363 
364  if( netinfo == nullptr )
365  {
366  // It is a new net, we have to add it
367  if( !m_isDryRun )
368  {
369  changed = true;
370  netinfo = new NETINFO_ITEM( m_board, netName );
371  m_commit.Add( netinfo );
372  m_addedNets[netName] = netinfo;
373  }
374 
375  msg.Printf( _( "Add net %s.\n" ), GetChars( netName ) );
377  }
378 
379  if( !pad->GetNetname().IsEmpty() )
380  {
381  msg.Printf( _( "Reconnect component %s pin %s from net %s to net %s.\n"),
382  GetChars( aPcbComponent->GetReference() ),
383  GetChars( pad->GetName() ),
384  GetChars( pad->GetNetname() ),
385  GetChars( netName ) );
386 
387  } else {
388  msg.Printf( _( "Connect component %s pin %s to net %s.\n"),
389  GetChars( aPcbComponent->GetReference() ),
390  GetChars( pad->GetName() ),
391  GetChars( netName ) );
392  }
393 
395 
396  msg.Printf( _( "Changing component \"%s:%s\" pin \"%s\" net name from "
397  "\"%s\" to \"%s\".\n" ),
398  GetChars( aPcbComponent->GetReference() ),
399  GetChars( aPcbComponent->GetPath() ),
400  GetChars( pad->GetName() ),
401  GetChars( pad->GetNetname() ),
402  GetChars( netName ) );
404 
405  if( !m_isDryRun )
406  {
407  changed = true;
408  pad->SetNet( netinfo );
409  }
410  }
411  }
412  }
413 
414  if( changed && copy )
415  m_commit.Modified( aPcbComponent, copy );
416  else
417  delete copy;
418 
419  return true;
420 }
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:118
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:145
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: class_netinfo.h:69
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:419
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:137
DLIST< D_PAD > & PadsList()
Definition: class_module.h:134
const wxString & GetPath() const
Definition: class_module.h:173
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
bool BOARD_NETLIST_UPDATER::updateComponentParameters ( MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 228 of file board_netlist_updater.cpp.

References MODULE::Clone(), GetChars(), 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 UpdateNetlist().

229 {
230  wxString msg;
231 
232  if( !aPcbComponent )
233  return false;
234 
235  // Create a copy only if the module has not been added during this update
236  MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
237  bool changed = false;
238 
239  // Test for reference designator field change.
240  if( aPcbComponent->GetReference() != aNewComponent->GetReference() )
241  {
242  msg.Printf( _( "Change component %s reference to %s.\n" ),
243  GetChars( aPcbComponent->GetReference() ),
244  GetChars( aNewComponent->GetReference() ) );
245 
247 
248  msg.Printf( _( "Changing component \"%s:%s\" reference to \"%s\".\n" ),
249  GetChars( aPcbComponent->GetReference() ),
250  GetChars( aPcbComponent->GetPath() ),
251  GetChars( aNewComponent->GetReference() ) );
252 
254 
255  if ( !m_isDryRun )
256  {
257  changed = true;
258  aPcbComponent->SetReference( aNewComponent->GetReference() );
259  }
260  }
261 
262  // Test for value field change.
263  if( aPcbComponent->GetValue() != aNewComponent->GetValue() )
264  {
265  msg.Printf( _( "Change component %s value from %s to %s.\n" ),
266  GetChars( aPcbComponent->GetReference() ),
267  GetChars( aPcbComponent->GetValue() ),
268  GetChars( aNewComponent->GetValue() ) );
269 
271 
272  msg.Printf( _( "Changing component \"%s:%s\" value from \"%s\" to \"%s\".\n" ),
273  GetChars( aPcbComponent->GetReference() ),
274  GetChars( aPcbComponent->GetPath() ),
275  GetChars( aPcbComponent->GetValue() ),
276  GetChars( aNewComponent->GetValue() ) );
277 
279 
280  if( !m_isDryRun )
281  {
282  changed = true;
283  aPcbComponent->SetValue( aNewComponent->GetValue() );
284  }
285  }
286 
287  // Test for time stamp change.
288  if( aPcbComponent->GetPath() != aNewComponent->GetTimeStamp() )
289  {
290  msg.Printf( _( "Changing component path \"%s:%s\" to \"%s\".\n" ),
291  GetChars( aPcbComponent->GetReference() ),
292  GetChars( aPcbComponent->GetPath() ),
293  GetChars( aNewComponent->GetTimeStamp() ) );
294 
296 
297  if( !m_isDryRun )
298  {
299  changed = true;
300  aPcbComponent->SetPath( aNewComponent->GetTimeStamp() );
301  }
302  }
303 
304  if( changed && copy )
305  m_commit.Modified( aPcbComponent, copy );
306  else
307  delete copy;
308 
309  return true;
310 }
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:447
int GetStatus(EDA_ITEM *aItem)
Returns status of an item.
Definition: commit.cpp:118
const wxString & GetReference() const
Definition: pcb_netlist.h:149
const wxString & GetValue() const
Definition: pcb_netlist.h:151
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:429
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:168
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.h:110
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:419
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:456
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:173
void SetPath(const wxString &aPath)
Definition: class_module.h:174
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 615 of file board_netlist_updater.cpp.

References addNewComponent(), deleteSinglePadNets(), deleteUnusedComponents(), BOARD::FindModule(), LIB_ID::Format(), GetChars(), NETLIST::GetComponent(), BOARD::GetConnectivity(), NETLIST::GetCount(), COMPONENT::GetFPID(), COMPONENT::GetReference(), COMPONENT::GetTimeStamp(), NETLIST::IsFindByTimeStamp(), m_board, m_commit, m_deleteSinglePadNets, m_deleteUnusedComponents, m_errorCount, m_isDryRun, m_reporter, m_warningCount, BOARD_COMMIT::Push(), replaceComponent(), REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_ERROR, REPORTER::RPT_INFO, EDA_ITEM::SetStatus(), testConnectivity(), updateComponentPadConnections(), and updateComponentParameters().

616 {
617  wxString msg;
618  m_errorCount = 0;
619  m_warningCount = 0;
620 
621  if( !m_isDryRun )
622  {
623  m_board->SetStatus( 0 );
624  }
625 
626  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
627  {
628  COMPONENT* component = aNetlist.GetComponent( i );
629  MODULE* footprint = NULL;
630 
631  msg.Printf( _( "Processing component \"%s:%s:%s\".\n" ),
632  GetChars( component->GetReference() ),
633  GetChars( component->GetTimeStamp() ),
634  GetChars( component->GetFPID().Format() ) );
636 
637  if( aNetlist.IsFindByTimeStamp() )
638  footprint = m_board->FindModule( component->GetTimeStamp(), true );
639  else
640  footprint = m_board->FindModule( component->GetReference() );
641 
642  if( footprint ) // An existing footprint.
643  {
644  MODULE* newFootprint = replaceComponent( aNetlist, footprint, component );
645 
646  if( newFootprint )
647  footprint = newFootprint;
648  }
649  else
650  {
651  footprint = addNewComponent( component );
652  }
653 
654  if( footprint )
655  {
656  updateComponentParameters( footprint, component );
657  updateComponentPadConnections( footprint, component );
658  }
659  }
660 
661  //aNetlist.GetDeleteExtraFootprints()
662 
664  deleteUnusedComponents( aNetlist );
665 
668 
669  if( !m_isDryRun )
670  {
671  m_commit.Push( _( "Update netlist" ) );
672  m_board->GetConnectivity()->Build( m_board );
673  testConnectivity( aNetlist );
674  }
675 
676  // Update the ratsnest
677  m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION );
678  m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION );
679 
680  msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
682 
683  if( m_errorCount )
684  {
685  m_reporter->Report( _( "Errors occured during the netlist update. Unless you "
686  "fix them, your board will not be consistent with the schematics." ),
688 
689  return false;
690  }
691  else
692  {
693  m_reporter->Report( _( "Netlist update successful!" ), REPORTER::RPT_ACTION );
694  }
695 
696  return true;
697 }
MODULE * replaceComponent(NETLIST &aNetlist, MODULE *aPcbComponent, COMPONENT *aNewComponent)
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
bool updateComponentPadConnections(MODULE *aPcbComponent, COMPONENT *aNewComponent)
MODULE * FindModule(const wxString &aRefOrTimeStamp, bool aSearchByTimeStamp=false) const
Function FindModule searches for a module matching aRefOrTimeStamp depending on the state of aSearchB...
bool testConnectivity(NETLIST &aNetlist)
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
const wxString & GetReference() const
Definition: pcb_netlist.h:149
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:304
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:168
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:256
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
bool updateComponentParameters(MODULE *aPcbComponent, COMPONENT *aNewComponent)
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
Function Format.
Definition: lib_id.cpp:263
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:247
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:290
MODULE * addNewComponent(COMPONENT *aComponent)
bool BOARD_NETLIST_UPDATER::UpdateNetlist ( const wxString &  aNetlistFileName,
const wxString &  aCmpFileName 
)

Definition at line 700 of file board_netlist_updater.cpp.

702 {
703  return false;
704 }

Member Data Documentation

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

Definition at line 145 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 146 of file board_netlist_updater.h.

Referenced by updateComponentPadConnections().

bool BOARD_NETLIST_UPDATER::m_deleteSinglePadNets
private
bool BOARD_NETLIST_UPDATER::m_deleteUnusedComponents
private
int BOARD_NETLIST_UPDATER::m_errorCount
private
bool BOARD_NETLIST_UPDATER::m_lookupByTimestamp
private
bool BOARD_NETLIST_UPDATER::m_replaceFootprints
private
int BOARD_NETLIST_UPDATER::m_warningCount
private

Definition at line 154 of file board_netlist_updater.h.

Referenced by BOARD_NETLIST_UPDATER(), testConnectivity(), and UpdateNetlist().


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