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
 
PCB_EDIT_FRAMEm_frame
 
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.

52  :
53  m_commit( aFrame ),
54  m_frame( 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:71
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 103 of file board_netlist_updater.cpp.

References COMMIT::Add(), estimateComponentInsertionPosition(), LIB_ID::Format(), FROM_UTF8(), 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().

104 {
105  wxString msg;
106 
107  if( aComponent->GetModule() != NULL )
108  {
109  msg.Printf( _( "Adding new component \"%s:%s\" footprint \"%s\".\n" ),
110  GetChars( aComponent->GetReference() ),
111  GetChars( aComponent->GetTimeStamp() ),
112  GetChars( FROM_UTF8( aComponent->GetFPID().Format() ) ) );
114 
115  msg.Printf( _( "Add component %s, footprint: %s.\n" ),
116  GetChars( aComponent->GetReference() ),
117  GetChars( FROM_UTF8( aComponent->GetFPID().Format() ) ) );
119 
120 
121  if( !m_isDryRun )
122  {
123  // Owned by NETLIST, can only copy it.
124  MODULE* footprint = new MODULE( *aComponent->GetModule() );
125  footprint->SetParent( m_board );
127  footprint->SetTimeStamp( GetNewTimeStamp() );
128 
129  m_addedComponents.push_back( footprint );
130  m_commit.Add( footprint );
131 
132  return footprint;
133  }
134  }
135  else
136  {
137  msg.Printf( _( "Cannot add component %s due to missing footprint %s.\n" ),
138  GetChars( aComponent->GetReference() ),
139  GetChars( FROM_UTF8( aComponent->GetFPID().Format() ) ) );
140 
142 
143  msg.Printf( _( "Cannot add new component \"%s:%s\" due to missing "
144  "footprint \"%s\".\n" ),
145  GetChars( aComponent->GetReference() ),
146  GetChars( aComponent->GetTimeStamp() ),
147  GetChars( FROM_UTF8( aComponent->GetFPID().Format() ) ) );
148 
150  ++m_errorCount;
151  }
152 
153  return NULL;
154 }
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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 465 of file board_netlist_updater.cpp.

References BOARD::BuildListOfNets(), BOARD::GetArea(), BOARD::GetAreaCount(), GetChars(), ZONE_CONTAINER::GetIsKeepout(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_CONNECTED_ITEM::GetNetname(), D_PAD::GetPadName(), 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().

466 {
467  int count = 0;
468  wxString netname;
469  wxString msg;
470  D_PAD* pad = NULL;
471  D_PAD* previouspad = NULL;
472 
473  // We need the pad list, for next tests.
474  // padlist is the list of pads, sorted by netname.
475 
477 
478  if( m_isDryRun )
479  return false;
480 
481  std::vector<D_PAD*> padlist = m_board->GetPads();
482 
483  for( unsigned kk = 0; kk < padlist.size(); kk++ )
484  {
485  pad = padlist[kk];
486 
487  if( pad->GetNetname().IsEmpty() )
488  continue;
489 
490  if( netname != pad->GetNetname() ) // End of net
491  {
492  if( previouspad && count == 1 )
493  {
494  // First, see if we have a copper zone attached to this pad.
495  // If so, this is not really a single pad net
496 
497  for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
498  {
499  ZONE_CONTAINER* zone = m_board->GetArea( ii );
500 
501  if( !zone->IsOnCopperLayer() )
502  continue;
503 
504  if( zone->GetIsKeepout() )
505  continue;
506 
507  if( zone->GetNet() == previouspad->GetNet() )
508  {
509  count++;
510  break;
511  }
512  }
513 
514  if( count == 1 ) // Really one pad, and nothing else
515  {
516  msg.Printf( _( "Remove single pad net %s." ),
517  GetChars( previouspad->GetNetname() ) );
519 
520  msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad '%s'\n" ),
521  GetChars( previouspad->GetNetname() ),
522  GetChars( previouspad->GetParent()->GetReference() ),
523  GetChars( previouspad->GetPadName() ) );
525 
526  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
527  }
528  }
529 
530  netname = pad->GetNetname();
531  count = 1;
532  }
533  else
534  {
535  count++;
536  }
537 
538  previouspad = pad;
539  }
540 
541  // Examine last pad
542  if( pad && count == 1 )
544 
545  return true;
546 }
void BuildListOfNets()
Definition: class_board.h:762
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
const D_PADS & GetPads()
Function GetPads returns a reference to a list of all the pads.
Definition: class_board.h:760
MODULE * GetParent() const
Definition: class_pad.h:108
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:649
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
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:1022
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:408
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
wxString GetPadName() const
Definition: class_pad.cpp:433
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 422 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().

423 {
424  wxString msg;
425  MODULE* nextModule;
426  const COMPONENT* component;
427 
428  for( MODULE* module = m_board->m_Modules; module != NULL; module = nextModule )
429  {
430  nextModule = module->Next();
431 
432  if( m_lookupByTimestamp )
433  component = aNetlist.GetComponentByTimeStamp( module->GetPath() );
434  else
435  component = aNetlist.GetComponentByReference( module->GetReference() );
436 
437  if( component == NULL )
438  {
439  if( module->IsLocked() )
440  {
441  msg.Printf( _( "Component %s is locked, skipping removal.\n" ),
442  GetChars( module->GetReference() ) );
444  continue;
445  }
446 
447  msg.Printf( _( "Remove component %s." ),
448  GetChars( module->GetReference() ) );
450 
451  msg.Printf( _( "Removing unused component \"%s:%s\".\n" ),
452  GetChars( module->GetReference() ),
453  GetChars( module->GetPath() ) );
455 
456  if( !m_isDryRun )
457  m_commit.Remove( module );
458  }
459  }
460 
461  return true;
462 }
MODULE * Next() const
Definition: class_module.h:99
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:243
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 75 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().

76 {
77  wxPoint bestPosition;
78 
79  if( !m_board->IsEmpty() )
80  {
81  // Position new components below any existing board features.
83 
84  if( bbox.GetWidth() || bbox.GetHeight() )
85  {
86  bestPosition.x = bbox.Centre().x;
87  bestPosition.y = bbox.GetBottom() + Millimeter2iu( 10 );
88  }
89  }
90  else
91  {
92  // Position new components in the center of the page when the board is empty.
93  wxSize pageSize = m_board->GetPageSettings().GetSizeIU();
94 
95  bestPosition.x = pageSize.GetWidth() / 2;
96  bestPosition.y = pageSize.GetHeight() / 2;
97  }
98 
99  return bestPosition;
100 }
int GetHeight() const
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:837
bool IsEmpty() const
Definition: class_board.h:263
int GetBottom() const
wxPoint Centre() const
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:543
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 157 of file board_netlist_updater.cpp.

References COMMIT::Add(), MODULE::CopyNetlistSettings(), LIB_ID::empty(), LIB_ID::Format(), FROM_UTF8(), 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().

158 {
159  wxString msg;
160 
161  if( !m_replaceFootprints )
162  return NULL;
163 
164  // Test if the footprint has not changed
165  if( aNewComponent->GetFPID().empty() || aPcbComponent->GetFPID() == aNewComponent->GetFPID() )
166  return NULL;
167 
168  if( aNewComponent->GetModule() != NULL )
169  {
170  msg.Printf( _( "Change component %s footprint from %s to %s.\n"),
171  GetChars( aPcbComponent->GetReference() ),
172  GetChars( FROM_UTF8( aPcbComponent->GetFPID().Format() ) ),
173  GetChars( FROM_UTF8( aNewComponent->GetFPID().Format() ) ) );
174 
176 
177  msg.Printf( _( "Replacing component \"%s:%s\" footprint \"%s\" with "
178  "\"%s\".\n" ),
179  GetChars( aPcbComponent->GetReference() ),
180  GetChars( aPcbComponent->GetPath() ),
181  GetChars( FROM_UTF8( aPcbComponent->GetFPID().Format() ) ),
182  GetChars( FROM_UTF8( aNewComponent->GetFPID().Format() ) ) );
183 
185 
186  if( !m_isDryRun )
187  {
188  wxASSERT( aPcbComponent != NULL );
189 
190  MODULE* newFootprint = new MODULE( *aNewComponent->GetModule() );
191  newFootprint->SetParent( m_board );
192 
193  if( aNetlist.IsFindByTimeStamp() )
194  newFootprint->SetReference( aPcbComponent->GetReference() );
195  else
196  newFootprint->SetPath( aPcbComponent->GetPath() );
197 
198  aPcbComponent->CopyNetlistSettings( newFootprint, false );
199  m_commit.Remove( aPcbComponent );
200  m_commit.Add( newFootprint );
201 
202  return newFootprint;
203  }
204  }
205  else
206  {
207  msg.Printf( _( "Cannot change component %s footprint due to missing "
208  "footprint %s.\n" ),
209  GetChars( aPcbComponent->GetReference() ),
210  GetChars( FROM_UTF8( aNewComponent->GetFPID().Format() ) ) );
211 
213 
214  msg.Printf( _( "Cannot replace component \"%s:%s\" due to missing "
215  "footprint \"%s\".\n" ),
216  GetChars( aPcbComponent->GetReference() ),
217  GetChars( aPcbComponent->GetPath() ),
218  GetChars( FROM_UTF8( aNewComponent->GetFPID().Format() ) ) );
219 
221 
222  ++m_errorCount;
223  }
224 
225  return NULL;
226 }
bool empty() const
Function empty.
Definition: lib_id.h:198
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:164
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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:151
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:418
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:408
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:160
void SetPath(const wxString &aPath)
Definition: class_module.h:161
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 549 of file board_netlist_updater.cpp.

References BOARD::FindModuleByReference(), MODULE::FindPadByName(), LIB_ID::Format(), FROM_UTF8(), BOARD::GetArea(), BOARD::GetAreaCount(), GetChars(), NETLIST::GetComponent(), NETLIST::GetCount(), MODULE::GetFPID(), ZONE_CONTAINER::GetIsKeepout(), BOARD_CONNECTED_ITEM::GetNet(), COMPONENT::GetNet(), COMPONENT::GetNetCount(), NETINFO_ITEM::GetNetname(), NETINFO_ITEM::GetNodesCount(), 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().

550 {
551  // Last step: Some tests:
552  // verify all pads found in netlist:
553  // They should exist in footprints, otherwise the footprint is wrong
554  // note also references or time stamps are updated, so we use only
555  // the reference to find a footprint
556  //
557  // Also verify if zones have acceptable nets, i.e. nets with pads.
558  // Zone with no pad belongs to a "dead" net which happens after changes in schematic
559  // when no more pad use this net name.
560 
561  wxString msg;
562  wxString padname;
563 
564  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
565  {
566  const COMPONENT* component = aNetlist.GetComponent( i );
567  MODULE* footprint = m_board->FindModuleByReference( component->GetReference() );
568 
569  if( footprint == NULL ) // It can be missing in partial designs
570  continue;
571 
572  // Explore all pins/pads in component
573  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
574  {
575  COMPONENT_NET net = component->GetNet( jj );
576  padname = net.GetPinName();
577 
578  if( footprint->FindPadByName( padname ) )
579  continue; // OK, pad found
580 
581  // not found: bad footprint, report error
582  msg.Printf( _( "Component %s pad %s not found in footprint %s\n" ),
583  GetChars( component->GetReference() ),
584  GetChars( padname ),
585  GetChars( FROM_UTF8( footprint->GetFPID().Format() ) ) );
587  ++m_errorCount;
588  }
589  }
590 
591  // Test copper zones to detect "dead" nets (nets without any pad):
592  for( int i = 0; i < m_board->GetAreaCount(); i++ )
593  {
594  ZONE_CONTAINER* zone = m_board->GetArea( i );
595 
596  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
597  continue;
598 
599  int nc = zone->GetNet()->GetNodesCount();
600 
601  if( nc == 0 )
602  {
603  msg.Printf( _( "Copper zone (net name %s): net has no pads connected." ),
604  GetChars( zone->GetNet()->GetNetname() ) );
606  ++m_warningCount;
607  }
608  }
609 
610  return true;
611 }
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
int GetNodesCount() const
Function GetNodesCount.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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:649
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:151
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
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
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:1022
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
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(), COMPONENT_NET::IsValid(), m_addedNets, m_board, m_commit, m_isDryRun, m_reporter, COMMIT::Modified(), D_PAD::Next(), MODULE::Pads(), REPORTER::Report(), REPORTER::RPT_ACTION, REPORTER::RPT_INFO, and NETINFO_LIST::UNCONNECTED.

Referenced by UpdateNetlist().

314 {
315  wxString msg;
316 
317  bool changed = false;
318  MODULE* copy = (MODULE*) aPcbComponent->Clone();
319 
320  // At this point, the component footprint is updated. Now update the nets.
321  for( D_PAD* pad = aPcbComponent->Pads(); pad; pad = pad->Next() )
322  {
323  COMPONENT_NET net = aNewComponent->GetNet( pad->GetPadName() );
324 
325  if( !net.IsValid() ) // New footprint pad has no net.
326  {
327  if( !pad->GetNetname().IsEmpty() )
328  {
329  msg.Printf( _( "Disconnect component %s pin %s.\n" ),
330  GetChars( aPcbComponent->GetReference() ),
331  GetChars( pad->GetPadName() ) );
333 
334  msg.Printf( _( "Clearing component \"%s:%s\" pin \"%s\" net name.\n" ),
335  GetChars( aPcbComponent->GetReference() ),
336  GetChars( aPcbComponent->GetPath() ),
337  GetChars( pad->GetPadName() ) );
339  }
340 
341  if( !m_isDryRun )
342  {
343  changed = true;
344  pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
345  }
346  }
347  else // New footprint pad has a net.
348  {
349  if( net.GetNetName() != pad->GetNetname() )
350  {
351  const wxString& netName = net.GetNetName();
352  NETINFO_ITEM* netinfo = m_board->FindNet( netName );
353 
354  if( netinfo == nullptr )
355  {
356  // It might be a new net that has not been added to the board yet
357  auto netIt = m_addedNets.find( netName );
358 
359  if( netIt != m_addedNets.end() )
360  netinfo = netIt->second;
361  }
362 
363  if( netinfo == nullptr )
364  {
365  // It is a new net, we have to add it
366  if( !m_isDryRun )
367  {
368  changed = true;
369  netinfo = new NETINFO_ITEM( m_board, netName );
370  m_commit.Add( netinfo );
371  m_addedNets[netName] = netinfo;
372  }
373 
374  msg.Printf( _( "Add net %s.\n" ), GetChars( netName ) );
376  }
377 
378  if( !pad->GetNetname().IsEmpty() )
379  {
380  msg.Printf( _( "Reconnect component %s pin %s from net %s to net %s.\n"),
381  GetChars( aPcbComponent->GetReference() ),
382  GetChars( pad->GetPadName() ),
383  GetChars( pad->GetNetname() ),
384  GetChars( netName ) );
385 
386  } else {
387  msg.Printf( _( "Connect component %s pin %s to net %s.\n"),
388  GetChars( aPcbComponent->GetReference() ),
389  GetChars( pad->GetPadName() ),
390  GetChars( netName ) );
391  }
392 
394 
395  msg.Printf( _( "Changing component \"%s:%s\" pin \"%s\" net name from "
396  "\"%s\" to \"%s\".\n" ),
397  GetChars( aPcbComponent->GetReference() ),
398  GetChars( aPcbComponent->GetPath() ),
399  GetChars( pad->GetPadName() ),
400  GetChars( pad->GetNetname() ),
401  GetChars( netName ) );
403 
404  if( !m_isDryRun )
405  {
406  changed = true;
407  pad->SetNet( netinfo );
408  }
409  }
410  }
411  }
412 
413  if( changed )
414  m_commit.Modified( aPcbComponent, copy );
415  else
416  delete copy;
417 
418  return true;
419 }
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.cpp:83
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
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:106
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Class NETINFO_ITEM handles the data for a net.
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:408
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 > & Pads()
Definition: class_module.h:133
const wxString & GetPath() const
Definition: class_module.h:160
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 229 of file board_netlist_updater.cpp.

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

230 {
231  wxString msg;
232 
233  if( !aPcbComponent )
234  return false;
235 
236  bool changed = false;
237  MODULE* copy = (MODULE*) aPcbComponent->Clone();
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 )
305  m_commit.Modified( aPcbComponent, copy );
306  else
307  delete copy;
308 
309  return true;
310 }
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.cpp:83
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:436
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:418
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
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:408
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:445
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:160
void SetPath(const wxString &aPath)
Definition: class_module.h:161
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 614 of file board_netlist_updater.cpp.

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

615 {
616  wxString msg;
617  m_errorCount = 0;
618  m_warningCount = 0;
619 
620  if( !m_isDryRun )
621  {
622  m_board->SetStatus( 0 );
623  }
624 
625  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
626  {
627  COMPONENT* component = aNetlist.GetComponent( i );
628  MODULE* footprint = NULL;
629 
630  msg.Printf( _( "Processing component \"%s:%s:%s\".\n" ),
631  GetChars( component->GetReference() ),
632  GetChars( component->GetTimeStamp() ),
633  GetChars( FROM_UTF8( component->GetFPID().Format() ) ) );
635 
636  if( aNetlist.IsFindByTimeStamp() )
637  footprint = m_board->FindModule( component->GetTimeStamp(), true );
638  else
639  footprint = m_board->FindModule( component->GetReference() );
640 
641  if( footprint ) // An existing footprint.
642  {
643  MODULE* newFootprint = replaceComponent( aNetlist, footprint, component );
644 
645  if( newFootprint )
646  footprint = newFootprint;
647  }
648  else
649  {
650  footprint = addNewComponent( component );
651  }
652 
653  if( footprint )
654  {
655  updateComponentParameters( footprint, component );
656  updateComponentPadConnections( footprint, component );
657  }
658  }
659 
660  //aNetlist.GetDeleteExtraFootprints()
661 
663  deleteUnusedComponents( aNetlist );
664 
667 
668  if( !m_isDryRun )
669  {
670  m_commit.Push( _( "Update netlist" ) );
671  m_frame->Compile_Ratsnest( NULL, false );
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
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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
void ProcessBoard()
Function ProcessBoard() Prepares data for computing (computes a list of current nodes and connections...
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:304
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:168
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:285
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:165
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)
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 146 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 147 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
PCB_EDIT_FRAME* BOARD_NETLIST_UPDATER::m_frame
private

Definition at line 142 of file board_netlist_updater.h.

Referenced by UpdateNetlist().

bool BOARD_NETLIST_UPDATER::m_lookupByTimestamp
private
bool BOARD_NETLIST_UPDATER::m_replaceFootprints
private
int BOARD_NETLIST_UPDATER::m_warningCount
private

Definition at line 155 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: