KiCad PCB EDA Suite
BOARD_NETLIST_UPDATER Class Reference

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...
 
void SetReporter (REPORTER *aReporter)
 

Sets the reporter object

More...
 
void SetDeleteSinglePadNets (bool aEnabled)
 

Enables "delete single pad nets" option

More...
 
void SetWarnPadNoNetInNetlist (bool aEnabled)
 

Enables warning option if a connectable pad is not found in netlist connectable = pad with a name and on a copper layer

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)
 
void cachePinFunction (D_PAD *aPad, const wxString &aPinFunction)
 
wxString getPinFunction (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< wxString, wxString > m_oldToNewNets
 
std::map< D_PAD *, wxString > m_padNets
 
std::map< D_PAD *, wxString > m_padPinFunctions
 
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
 
bool m_warnForNoNetPads
 
int m_warningCount
 
int m_errorCount
 
int m_newFootprintsCount
 

Detailed Description

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 and pin function properly set, any extra unlock footprints are removed from the BOARD.

Definition at line 72 of file board_netlist_updater.h.

Constructor & Destructor Documentation

◆ BOARD_NETLIST_UPDATER()

BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER ( PCB_EDIT_FRAME aFrame,
BOARD aBoard 
)

Definition at line 53 of file board_netlist_updater.cpp.

53  :
54  m_frame( aFrame ),
55  m_commit( aFrame ),
56  m_board( aBoard )
57 {
59 
60  m_deleteSinglePadNets = true;
62  m_isDryRun = false;
63  m_replaceFootprints = true;
64  m_lookupByTimestamp = false;
65  m_warnForNoNetPads = false;
66 
67  m_warningCount = 0;
68  m_errorCount = 0;
70 }
static REPORTER & GetInstance()
Definition: reporter.cpp:105

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

◆ ~BOARD_NETLIST_UPDATER()

BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER ( )

Definition at line 73 of file board_netlist_updater.cpp.

74 {
75 }

Member Function Documentation

◆ addNewComponent()

MODULE * BOARD_NETLIST_UPDATER::addNewComponent ( COMPONENT aComponent)
private

Definition at line 139 of file board_netlist_updater.cpp.

140 {
141  wxString msg;
142 
143  if( aComponent->GetFPID().empty() )
144  {
145  msg.Printf( _( "Cannot add %s (no footprint assigned)." ),
146  aComponent->GetReference(),
147  aComponent->GetFPID().Format().wx_str() );
149  ++m_errorCount;
150  return nullptr;
151  }
152 
153  MODULE* footprint = m_frame->LoadFootprint( aComponent->GetFPID() );
154 
155  if( footprint == nullptr )
156  {
157  msg.Printf( _( "Cannot add %s (footprint \"%s\" not found)." ),
158  aComponent->GetReference(),
159  aComponent->GetFPID().Format().wx_str() );
161  ++m_errorCount;
162  return nullptr;
163  }
164 
165  msg.Printf( _( "Add %s (footprint \"%s\")." ),
166  aComponent->GetReference(),
167  aComponent->GetFPID().Format().wx_str() );
169 
170  // Set the pads ratsnest settings to the global settings
171  bool set_ratsnest = m_frame->GetDisplayOptions().m_ShowGlobalRatsnest;
172  for ( auto pad : footprint->Pads() )
173  pad->SetLocalRatsnestVisible( set_ratsnest );
174 
176 
177  if( !m_isDryRun )
178  {
179  footprint->SetParent( m_board );
181 
182  m_addedComponents.push_back( footprint );
183  m_commit.Add( footprint );
184 
185  return footprint;
186  }
187  else
188  delete footprint;
189 
190  return NULL;
191 }
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
PADS & Pads()
Definition: class_module.h:173
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions Display options control the way tracks, vias, outlines and other things ar...
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
bool empty() const
Definition: lib_id.h:186
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:149
#define NULL
const wxString & GetReference() const
Definition: pcb_netlist.h:144
void SetPosition(const wxPoint &aPos) override
UTF8 Format() const
Definition: lib_id.cpp:237
MODULE * LoadFootprint(const LIB_ID &aFootprintId)
Function LoadFootprint attempts to load aFootprintId from the footprint library table.
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51
std::vector< MODULE * > m_addedComponents

References _, COMMIT::Add(), LIB_ID::empty(), estimateComponentInsertionPosition(), LIB_ID::Format(), PCB_BASE_FRAME::GetDisplayOptions(), COMPONENT::GetFPID(), COMPONENT::GetReference(), PCB_BASE_FRAME::LoadFootprint(), m_addedComponents, m_board, m_commit, m_errorCount, m_frame, m_isDryRun, m_newFootprintsCount, m_reporter, PCB_DISPLAY_OPTIONS::m_ShowGlobalRatsnest, NULL, MODULE::Pads(), REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, EDA_ITEM::SetParent(), MODULE::SetPosition(), and UTF8::wx_str().

Referenced by UpdateNetlist().

◆ cacheCopperZoneConnections()

void BOARD_NETLIST_UPDATER::cacheCopperZoneConnections ( )
private

Definition at line 442 of file board_netlist_updater.cpp.

443 {
444  for( int ii = 0; ii < m_board->GetAreaCount(); ii++ )
445  {
446  ZONE_CONTAINER* zone = m_board->GetArea( ii );
447 
448  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
449  continue;
450 
451  m_zoneConnectionsCache[ zone ] = m_board->GetConnectivity()->GetConnectedPads( zone );
452  }
453 }
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
std::map< ZONE_CONTAINER *, std::vector< D_PAD * > > m_zoneConnectionsCache
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:934
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:713
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:899
bool IsOnCopperLayer() const override
Function IsOnCopperLayer.
Definition: class_zone.cpp:214

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

Referenced by UpdateNetlist().

◆ cacheNetname()

void BOARD_NETLIST_UPDATER::cacheNetname ( D_PAD aPad,
const wxString &  aNetname 
)
private

Definition at line 81 of file board_netlist_updater.cpp.

82 {
83  m_padNets[ aPad ] = aNetname;
84 }
std::map< D_PAD *, wxString > m_padNets

References m_padNets.

Referenced by deleteSinglePadNets(), and updateComponentPadConnections().

◆ cachePinFunction()

void BOARD_NETLIST_UPDATER::cachePinFunction ( D_PAD aPad,
const wxString &  aPinFunction 
)
private

Definition at line 96 of file board_netlist_updater.cpp.

97 {
98  m_padPinFunctions[ aPad ] = aPinFunction;
99 }
std::map< D_PAD *, wxString > m_padPinFunctions

References m_padPinFunctions.

Referenced by updateComponentPadConnections().

◆ deleteSinglePadNets()

bool BOARD_NETLIST_UPDATER::deleteSinglePadNets ( )
private

Definition at line 617 of file board_netlist_updater.cpp.

618 {
619  int count = 0;
620  wxString netname;
621  wxString msg;
622  D_PAD* previouspad = NULL;
623 
624  // We need the pad list for next tests.
625 
627 
628  std::vector<D_PAD*> padlist = m_board->GetPads();
629 
630  // Sort pads by netlist name
631  std::sort( padlist.begin(), padlist.end(),
632  [ this ]( D_PAD* a, D_PAD* b ) -> bool { return getNetname( a ) < getNetname( b ); } );
633 
634  for( D_PAD* pad : padlist )
635  {
636  if( getNetname( pad ).IsEmpty() )
637  continue;
638 
639  if( netname != getNetname( pad ) ) // End of net
640  {
641  if( previouspad && count == 1 )
642  {
643  // First, see if we have a copper zone attached to this pad.
644  // If so, this is not really a single pad net
645 
646  for( ZONE_CONTAINER* zone : m_board->Zones() )
647  {
648  if( !zone->IsOnCopperLayer() )
649  continue;
650 
651  if( zone->GetIsKeepout() )
652  continue;
653 
654  if( zone->GetNetname() == getNetname( previouspad ) )
655  {
656  count++;
657  break;
658  }
659  }
660 
661  if( count == 1 ) // Really one pad, and nothing else
662  {
663  msg.Printf( _( "Remove single pad net %s." ),
664  UnescapeString( getNetname( previouspad ) ) );
666 
667  if( !m_isDryRun )
668  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
669  else
670  cacheNetname( previouspad, wxEmptyString );
671  }
672  }
673 
674  netname = getNetname( pad );
675  count = 1;
676  }
677  else
678  {
679  count++;
680  }
681 
682  previouspad = pad;
683  }
684 
685  // Examine last pad
686  if( count == 1 )
687  {
688  if( !m_isDryRun )
689  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
690  else
691  cacheNetname( previouspad, wxEmptyString );
692  }
693 
694  return true;
695 }
void BuildListOfNets()
Definition: class_board.h:720
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
void cacheNetname(D_PAD *aPad, const wxString &aNetname)
bool SetNetCode(int aNetCode, bool aNoAssert)
Sets net using a net code.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
#define NULL
wxString getNetname(D_PAD *aPad)
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:280
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:125
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:478

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

Referenced by UpdateNetlist().

◆ deleteUnusedComponents()

bool BOARD_NETLIST_UPDATER::deleteUnusedComponents ( NETLIST aNetlist)
private

Definition at line 583 of file board_netlist_updater.cpp.

584 {
585  wxString msg;
586  const COMPONENT* component;
587 
588  for( auto module : m_board->Modules() )
589  {
590 
591  if( m_lookupByTimestamp )
592  component = aNetlist.GetComponentByPath( module->GetPath() );
593  else
594  component = aNetlist.GetComponentByReference( module->GetReference() );
595 
596  if( component == NULL )
597  {
598  if( module->IsLocked() )
599  {
600  msg.Printf( _( "Cannot remove unused footprint %s (locked)." ), module->GetReference() );
602  continue;
603  }
604 
605  msg.Printf( _( "Remove unused footprint %s." ), module->GetReference() );
607 
608  if( !m_isDryRun )
609  m_commit.Remove( module );
610  }
611  }
612 
613  return true;
614 }
COMPONENT * GetComponentByPath(const KIID_PATH &aPath)
Function GetComponentByPath returns a COMPONENT by aPath.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
#define NULL
MODULES & Modules()
Definition: class_board.h:266
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
#define _(s)
Definition: 3d_actions.cpp:33
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.

References _, NETLIST::GetComponentByPath(), NETLIST::GetComponentByReference(), m_board, m_commit, m_isDryRun, m_lookupByTimestamp, m_reporter, BOARD::Modules(), NULL, COMMIT::Remove(), REPORTER::Report(), RPT_SEVERITY_ACTION, and RPT_SEVERITY_WARNING.

Referenced by UpdateNetlist().

◆ estimateComponentInsertionPosition()

wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition ( )
private

Definition at line 111 of file board_netlist_updater.cpp.

112 {
113  wxPoint bestPosition;
114 
115  if( !m_board->IsEmpty() )
116  {
117  // Position new components below any existing board features.
119 
120  if( bbox.GetWidth() || bbox.GetHeight() )
121  {
122  bestPosition.x = bbox.Centre().x;
123  bestPosition.y = bbox.GetBottom() + Millimeter2iu( 10 );
124  }
125  }
126  else
127  {
128  // Position new components in the center of the page when the board is empty.
129  wxSize pageSize = m_board->GetPageSettings().GetSizeIU();
130 
131  bestPosition.x = pageSize.GetWidth() / 2;
132  bestPosition.y = pageSize.GetHeight() / 2;
133  }
134 
135  return bestPosition;
136 }
const PAGE_INFO & GetPageSettings() const
Definition: class_board.h:574
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:800
int GetWidth() const
Definition: eda_rect.h:119
int GetBottom() const
Definition: eda_rect.h:124
int GetHeight() const
Definition: eda_rect.h:120
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint Centre() const
Definition: eda_rect.h:62
static constexpr int Millimeter2iu(double mm)
bool IsEmpty() const
Definition: class_board.h:311

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

Referenced by addNewComponent().

◆ GetAddedComponents()

std::vector<MODULE*> BOARD_NETLIST_UPDATER::GetAddedComponents ( ) const
inline

Definition at line 131 of file board_netlist_updater.h.

132  {
133  return m_addedComponents;
134  }
std::vector< MODULE * > m_addedComponents

References m_addedComponents.

Referenced by PCB_EDIT_FRAME::OnNetlistChanged().

◆ getNetname()

wxString BOARD_NETLIST_UPDATER::getNetname ( D_PAD aPad)
private

Definition at line 87 of file board_netlist_updater.cpp.

88 {
89  if( m_isDryRun && m_padNets.count( aPad ) )
90  return m_padNets[ aPad ];
91  else
92  return aPad->GetNetname();
93 }
const wxString & GetNetname() const
Function GetNetname.
std::map< D_PAD *, wxString > m_padNets

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

Referenced by deleteSinglePadNets(), and updateCopperZoneNets().

◆ getPinFunction()

wxString BOARD_NETLIST_UPDATER::getPinFunction ( D_PAD aPad)
private

Definition at line 102 of file board_netlist_updater.cpp.

103 {
104  if( m_isDryRun && m_padPinFunctions.count( aPad ) )
105  return m_padPinFunctions[ aPad ];
106  else
107  return aPad->GetPinFunction();
108 }
const wxString & GetPinFunction() const
Definition: class_pad.h:138
std::map< D_PAD *, wxString > m_padPinFunctions

References D_PAD::GetPinFunction(), m_isDryRun, and m_padPinFunctions.

◆ replaceComponent()

MODULE * BOARD_NETLIST_UPDATER::replaceComponent ( NETLIST aNetlist,
MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 194 of file board_netlist_updater.cpp.

196 {
197  wxString msg;
198 
199  if( aNewComponent->GetFPID().empty() )
200  {
201  msg.Printf( _( "Cannot update %s (no footprint assigned)." ),
202  aNewComponent->GetReference(),
203  aNewComponent->GetFPID().Format().wx_str() );
205  ++m_errorCount;
206  return nullptr;
207  }
208 
209  MODULE* newFootprint = m_frame->LoadFootprint( aNewComponent->GetFPID() );
210 
211  if( newFootprint == nullptr )
212  {
213  msg.Printf( _( "Cannot update %s (footprint \"%s\" not found)." ),
214  aNewComponent->GetReference(),
215  aNewComponent->GetFPID().Format().wx_str() );
217  ++m_errorCount;
218  return nullptr;
219  }
220 
221  msg.Printf( _( "Change %s footprint from \"%s\" to \"%s\"."),
222  aPcbComponent->GetReference(),
223  aPcbComponent->GetFPID().Format().wx_str(),
224  aNewComponent->GetFPID().Format().wx_str() );
226 
228 
229  if( !m_isDryRun )
230  {
231  m_frame->Exchange_Module( aPcbComponent, newFootprint, m_commit );
232  return newFootprint;
233  }
234  else
235  delete newFootprint;
236 
237  return nullptr;
238 }
const LIB_ID & GetFPID() const
Definition: class_module.h:225
void Exchange_Module(MODULE *aSrc, MODULE *aDest, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true, bool reset3DModels=true)
Function Exchange_Module Replaces OldModule by NewModule, using OldModule settings: position,...
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
bool empty() const
Definition: lib_id.h:186
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:444
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:149
const wxString & GetReference() const
Definition: pcb_netlist.h:144
UTF8 Format() const
Definition: lib_id.cpp:237
MODULE * LoadFootprint(const LIB_ID &aFootprintId)
Function LoadFootprint attempts to load aFootprintId from the footprint library table.
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51

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_newFootprintsCount, m_reporter, REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, and UTF8::wx_str().

Referenced by UpdateNetlist().

◆ SetDeleteSinglePadNets()

void BOARD_NETLIST_UPDATER::SetDeleteSinglePadNets ( bool  aEnabled)
inline

Enables "delete single pad nets" option

Definition at line 95 of file board_netlist_updater.h.

96  {
97  m_deleteSinglePadNets = aEnabled;
98  }

References m_deleteSinglePadNets.

Referenced by PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), and PCB_EDIT_FRAME::KiwayMailIn().

◆ SetDeleteUnusedComponents()

void BOARD_NETLIST_UPDATER::SetDeleteUnusedComponents ( bool  aEnabled)
inline

Enables removing unused components

Definition at line 120 of file board_netlist_updater.h.

121  {
122  m_deleteUnusedComponents = aEnabled;
123  }

References m_deleteUnusedComponents.

Referenced by PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), and PCB_EDIT_FRAME::KiwayMailIn().

◆ SetIsDryRun()

void BOARD_NETLIST_UPDATER::SetIsDryRun ( bool  aEnabled)
inline

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

Definition at line 108 of file board_netlist_updater.h.

109  {
110  m_isDryRun = aEnabled;
111  }

References m_isDryRun.

◆ SetLookupByTimestamp()

void BOARD_NETLIST_UPDATER::SetLookupByTimestamp ( bool  aEnabled)
inline

Enables component lookup by timestamp instead of reference

Definition at line 126 of file board_netlist_updater.h.

127  {
128  m_lookupByTimestamp = aEnabled;
129  }

References m_lookupByTimestamp.

Referenced by PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), and PCB_EDIT_FRAME::KiwayMailIn().

◆ SetReplaceFootprints()

void BOARD_NETLIST_UPDATER::SetReplaceFootprints ( bool  aEnabled)
inline

Enables replacing footprints with new ones

Definition at line 114 of file board_netlist_updater.h.

115  {
116  m_replaceFootprints = aEnabled;
117  }

References m_replaceFootprints.

Referenced by PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), and PCB_EDIT_FRAME::KiwayMailIn().

◆ SetReporter()

void BOARD_NETLIST_UPDATER::SetReporter ( REPORTER aReporter)
inline

Sets the reporter object

Definition at line 89 of file board_netlist_updater.h.

90  {
91  m_reporter = aReporter;
92  }

References m_reporter.

Referenced by DIALOG_NETLIST::loadNetlist(), and DIALOG_UPDATE_PCB::PerformUpdate().

◆ SetWarnPadNoNetInNetlist()

void BOARD_NETLIST_UPDATER::SetWarnPadNoNetInNetlist ( bool  aEnabled)
inline

Enables warning option if a connectable pad is not found in netlist connectable = pad with a name and on a copper layer

Definition at line 102 of file board_netlist_updater.h.

103  {
104  m_warnForNoNetPads = aEnabled;
105  }

References m_warnForNoNetPads.

Referenced by PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), and PCB_EDIT_FRAME::KiwayMailIn().

◆ testConnectivity()

bool BOARD_NETLIST_UPDATER::testConnectivity ( NETLIST aNetlist)
private

Definition at line 698 of file board_netlist_updater.cpp.

699 {
700  // Verify that board contains all pads in netlist: if it doesn't then footprints are
701  // wrong or missing.
702  // Note that we use references to find the footprints as they're already updated by this
703  // point (whether by-reference or by-timestamp).
704 
705  wxString msg;
706  wxString padname;
707 
708  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
709  {
710  const COMPONENT* component = aNetlist.GetComponent( i );
711  MODULE* footprint = m_board->FindModuleByReference( component->GetReference() );
712 
713  if( footprint == NULL ) // It can be missing in partial designs
714  continue;
715 
716  // Explore all pins/pads in component
717  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
718  {
719  const COMPONENT_NET& net = component->GetNet( jj );
720  padname = net.GetPinName();
721 
722  if( footprint->FindPadByName( padname ) )
723  continue; // OK, pad found
724 
725  // not found: bad footprint, report error
726  msg.Printf( _( "%s pad %s not found in %s." ),
727  component->GetReference(),
728  padname,
729  footprint->GetFPID().Format().wx_str() );
731  ++m_errorCount;
732  }
733  }
734 
735  return true;
736 }
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:228
const LIB_ID & GetFPID() const
Definition: class_module.h:225
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
COMPONENT_NET is used to store the component pin name to net name (and pin function) associations sto...
Definition: pcb_netlist.h:44
D_PAD * FindPadByName(const wxString &aPadName) const
Function FindPadByName returns a D_PAD* with a matching name.
#define NULL
unsigned GetNetCount() const
Definition: pcb_netlist.h:130
const wxString & GetReference() const
Definition: pcb_netlist.h:144
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:132
UTF8 Format() const
Definition: lib_id.cpp:237
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:237
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51
MODULE * FindModuleByReference(const wxString &aReference) const
Function FindModuleByReference searches for a MODULE within this board with the given reference desig...
const wxString & GetPinName() const
Definition: pcb_netlist.h:59

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

Referenced by UpdateNetlist().

◆ updateComponentPadConnections()

bool BOARD_NETLIST_UPDATER::updateComponentPadConnections ( MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 306 of file board_netlist_updater.cpp.

308 {
309  wxString msg;
310 
311  // Create a copy only if the module has not been added during this update
312  MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
313  bool changed = false;
314 
315  // At this point, the component footprint is updated. Now update the nets.
316  for( auto pad : aPcbComponent->Pads() )
317  {
318  const COMPONENT_NET& net = aNewComponent->GetNet( pad->GetName() );
319 
320  wxString pinFunction;
321 
322  if( net.IsValid() ) // i.e. the pad has a name
323  pinFunction = net.GetPinFunction();
324 
325  if( !m_isDryRun )
326  {
327  if( pad->GetPinFunction() != pinFunction )
328  {
329  changed = true;
330  pad->SetPinFunction( pinFunction );
331  }
332  }
333  else
334  cachePinFunction( pad, pinFunction );
335 
336  // Test if new footprint pad has no net (pads not on copper layers have no net).
337  if( !net.IsValid() || !pad->IsOnCopperLayer() )
338  {
339  if( !pad->GetNetname().IsEmpty() )
340  {
341  msg.Printf( _( "Disconnect %s pin %s." ),
342  aPcbComponent->GetReference(),
343  pad->GetName() );
345  }
346  else if( m_warnForNoNetPads && pad->IsOnCopperLayer() && !pad->GetName().IsEmpty() )
347  {
348  // pad is connectable but has no net found in netlist
349  msg.Printf( _( "No net for component %s pin %s." ),
350  aPcbComponent->GetReference(),
351  pad->GetName() );
353  }
354 
355  if( !m_isDryRun )
356  {
357  changed = true;
358  pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
359 
360  // If the pad has no net from netlist (i.e. not in netlist
361  // it cannot have a pin function
362  if( pad->GetNetname().IsEmpty() )
363  pad->SetPinFunction( wxEmptyString );
364 
365  }
366  else
367  cacheNetname( pad, wxEmptyString );
368  }
369  else // New footprint pad has a net.
370  {
371  const wxString& netName = net.GetNetName();
372  NETINFO_ITEM* netinfo = m_board->FindNet( netName );
373 
374  if( netinfo && !m_isDryRun )
375  netinfo->SetIsCurrent( true );
376 
377  if( pad->GetNetname() != netName )
378  {
379 
380  if( netinfo == nullptr )
381  {
382  // It might be a new net that has not been added to the board yet
383  if( m_addedNets.count( netName ) )
384  netinfo = m_addedNets[ netName ];
385  }
386 
387  if( netinfo == nullptr )
388  {
389  netinfo = new NETINFO_ITEM( m_board, netName );
390 
391  // It is a new net, we have to add it
392  if( !m_isDryRun )
393  {
394  changed = true;
395  m_commit.Add( netinfo );
396  }
397 
398  m_addedNets[netName] = netinfo;
399  msg.Printf( _( "Add net %s." ), UnescapeString( netName ) );
401  }
402 
403  if( !pad->GetNetname().IsEmpty() )
404  {
405  m_oldToNewNets[ pad->GetNetname() ] = netName;
406 
407  msg.Printf( _( "Reconnect %s pin %s from %s to %s."),
408  aPcbComponent->GetReference(),
409  pad->GetName(),
410  UnescapeString( pad->GetNetname() ),
411  UnescapeString( netName ) );
412  }
413  else
414  {
415  msg.Printf( _( "Connect %s pin %s to %s."),
416  aPcbComponent->GetReference(),
417  pad->GetName(),
418  UnescapeString( netName ) );
419  }
421 
422  if( !m_isDryRun )
423  {
424  changed = true;
425  pad->SetNet( netinfo );
426  }
427  else
428  cacheNetname( pad, netName );
429  }
430  }
431  }
432 
433  if( changed && copy )
434  m_commit.Modified( aPcbComponent, copy );
435  else
436  delete copy;
437 
438  return true;
439 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
void cacheNetname(D_PAD *aPad, const wxString &aNetname)
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:256
PADS & Pads()
Definition: class_module.h:173
int GetStatus(EDA_ITEM *aItem)
Returns status of an item.
Definition: commit.cpp:132
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:444
std::map< wxString, NETINFO_ITEM * > m_addedNets
COMPONENT_NET is used to store the component pin name to net name (and pin function) associations sto...
Definition: pcb_netlist.h:44
const wxString & GetNetName() const
Definition: pcb_netlist.h:60
std::map< wxString, wxString > m_oldToNewNets
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:132
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:61
bool IsValid() const
Definition: pcb_netlist.h:63
void cachePinFunction(D_PAD *aPad, const wxString &aPinFunction)
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Creates an undo entry for an item that has been already modified.
Definition: commit.h:110
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:125
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:478

References _, COMMIT::Add(), cacheNetname(), cachePinFunction(), MODULE::Clone(), BOARD::FindNet(), COMPONENT::GetNet(), COMPONENT_NET::GetNetName(), COMPONENT_NET::GetPinFunction(), MODULE::GetReference(), COMMIT::GetStatus(), COMPONENT_NET::IsValid(), m_addedNets, m_board, m_commit, m_isDryRun, m_oldToNewNets, m_reporter, m_warnForNoNetPads, COMMIT::Modified(), MODULE::Pads(), REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_WARNING, NETINFO_ITEM::SetIsCurrent(), NETINFO_LIST::UNCONNECTED, and UnescapeString().

Referenced by UpdateNetlist().

◆ updateComponentParameters()

bool BOARD_NETLIST_UPDATER::updateComponentParameters ( MODULE aPcbComponent,
COMPONENT aNewComponent 
)
private

Definition at line 241 of file board_netlist_updater.cpp.

243 {
244  wxString msg;
245 
246  // Create a copy only if the module has not been added during this update
247  MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
248  bool changed = false;
249 
250  // Test for reference designator field change.
251  if( aPcbComponent->GetReference() != aNewComponent->GetReference() )
252  {
253  msg.Printf( _( "Change %s reference designator to %s." ),
254  aPcbComponent->GetReference(),
255  aNewComponent->GetReference() );
257 
258  if ( !m_isDryRun )
259  {
260  changed = true;
261  aPcbComponent->SetReference( aNewComponent->GetReference() );
262  }
263  }
264 
265  // Test for value field change.
266  if( aPcbComponent->GetValue() != aNewComponent->GetValue() )
267  {
268  msg.Printf( _( "Change %s value from %s to %s." ),
269  aPcbComponent->GetReference(),
270  aPcbComponent->GetValue(),
271  aNewComponent->GetValue() );
273 
274  if( !m_isDryRun )
275  {
276  changed = true;
277  aPcbComponent->SetValue( aNewComponent->GetValue() );
278  }
279  }
280 
281  // Test for time stamp change.
282  if( aPcbComponent->GetPath() != aNewComponent->GetPath() )
283  {
284  msg.Printf( _( "Update %s symbol association from %s to %s." ),
285  aPcbComponent->GetReference(),
286  aPcbComponent->GetPath().AsString(),
287  aNewComponent->GetPath().AsString() );
289 
290  if( !m_isDryRun )
291  {
292  changed = true;
293  aPcbComponent->SetPath( aNewComponent->GetPath() );
294  }
295  }
296 
297  if( changed && copy )
298  m_commit.Modified( aPcbComponent, copy );
299  else
300  delete copy;
301 
302  return true;
303 }
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:469
int GetStatus(EDA_ITEM *aItem)
Returns status of an item.
Definition: commit.cpp:132
const KIID_PATH & GetPath() const
Definition: class_module.h:234
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:444
const wxString & GetReference() const
Definition: pcb_netlist.h:144
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:454
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
#define _(s)
Definition: 3d_actions.cpp:33
wxString AsString() const
Definition: common.h:137
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:478
const wxString & GetValue() const
Definition: pcb_netlist.h:146
void SetPath(const KIID_PATH &aPath)
Definition: class_module.h:235
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:154

References _, KIID_PATH::AsString(), MODULE::Clone(), COMPONENT::GetPath(), MODULE::GetPath(), COMPONENT::GetReference(), MODULE::GetReference(), COMMIT::GetStatus(), COMPONENT::GetValue(), MODULE::GetValue(), m_commit, m_isDryRun, m_reporter, COMMIT::Modified(), REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_INFO, MODULE::SetPath(), MODULE::SetReference(), and MODULE::SetValue().

Referenced by UpdateNetlist().

◆ updateCopperZoneNets()

bool BOARD_NETLIST_UPDATER::updateCopperZoneNets ( NETLIST aNetlist)
private

Definition at line 456 of file board_netlist_updater.cpp.

457 {
458  wxString msg;
459  std::set<wxString> netlistNetnames;
460 
461  for( int ii = 0; ii < (int) aNetlist.GetCount(); ii++ )
462  {
463  const COMPONENT* component = aNetlist.GetComponent( ii );
464  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
465  {
466  const COMPONENT_NET& net = component->GetNet( jj );
467  netlistNetnames.insert( net.GetNetName() );
468  }
469  }
470 
471  for( auto via : m_board->Tracks() )
472  {
473  if( via->Type() != PCB_VIA_T )
474  continue;
475 
476  if( netlistNetnames.count( via->GetNetname() ) == 0 )
477  {
478  wxString updatedNetname = wxEmptyString;
479 
480  // Take via name from name change map if it didn't match to a new pad
481  // (this is useful for stitching vias that don't connect to tracks)
482  if( m_oldToNewNets.count( via->GetNetname() ) )
483  {
484  updatedNetname = m_oldToNewNets[via->GetNetname()];
485  }
486 
487  if( !updatedNetname.IsEmpty() )
488  {
489  msg.Printf( _( "Reconnect via from %s to %s." ),
490  UnescapeString( via->GetNetname() ), UnescapeString( updatedNetname ) );
492 
493  if( !m_isDryRun )
494  {
495  NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
496 
497  if( !netinfo )
498  netinfo = m_addedNets[updatedNetname];
499 
500  if( netinfo )
501  {
502  m_commit.Modify( via );
503  via->SetNet( netinfo );
504  }
505  }
506  }
507  else
508  {
509  msg.Printf( _( "Via connected to unknown net (%s)." ),
510  UnescapeString( via->GetNetname() ) );
512  ++m_warningCount;
513  }
514  }
515  }
516 
517  // Test copper zones to detect "dead" nets (nets without any pad):
518  for( int i = 0; i < m_board->GetAreaCount(); i++ )
519  {
520  ZONE_CONTAINER* zone = m_board->GetArea( i );
521 
522  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
523  continue;
524 
525  if( netlistNetnames.count( zone->GetNetname() ) == 0 )
526  {
527  // Look for a pad in the zone's connected-pad-cache which has been updated to
528  // a new net and use that. While this won't always be the right net, the dead
529  // net is guaranteed to be wrong.
530  wxString updatedNetname = wxEmptyString;
531 
532  for( D_PAD* pad : m_zoneConnectionsCache[ zone ] )
533  {
534  if( getNetname( pad ) != zone->GetNetname() )
535  {
536  updatedNetname = getNetname( pad );
537  break;
538  }
539  }
540 
541  // Take zone name from name change map if it didn't match to a new pad
542  // (this is useful for zones on internal layers)
543  if( updatedNetname.IsEmpty() && m_oldToNewNets.count( zone->GetNetname() ) )
544  {
545  updatedNetname = m_oldToNewNets[ zone->GetNetname() ];
546  }
547 
548  if( !updatedNetname.IsEmpty() )
549  {
550  msg.Printf( _( "Reconnect copper zone from %s to %s." ),
551  UnescapeString( zone->GetNetname() ),
552  UnescapeString( updatedNetname ) );
554 
555  if( !m_isDryRun )
556  {
557  NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
558 
559  if( !netinfo )
560  netinfo = m_addedNets[ updatedNetname ];
561 
562  if( netinfo )
563  {
564  m_commit.Modify( zone );
565  zone->SetNet( netinfo );
566  }
567  }
568  }
569  else
570  {
571  msg.Printf( _( "Copper zone (%s) has no pads connected." ),
572  UnescapeString( zone->GetNetname() ) );
574  ++m_warningCount;
575  }
576  }
577  }
578 
579  return true;
580 }
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
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
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:228
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
std::map< wxString, NETINFO_ITEM * > m_addedNets
COMPONENT_NET is used to store the component pin name to net name (and pin function) associations sto...
Definition: pcb_netlist.h:44
const wxString & GetNetName() const
Definition: pcb_netlist.h:60
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:934
wxString getNetname(D_PAD *aPad)
unsigned GetNetCount() const
Definition: pcb_netlist.h:130
std::map< wxString, wxString > m_oldToNewNets
const wxString & GetNetname() const
Function GetNetname.
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:132
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:713
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:237
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:125
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:899
TRACKS & Tracks()
Definition: class_board.h:257
bool IsOnCopperLayer() const override
Function IsOnCopperLayer.
Definition: class_zone.cpp:214

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(), ZONE_CONTAINER::IsOnCopperLayer(), m_addedNets, m_board, m_commit, m_isDryRun, m_oldToNewNets, m_reporter, m_warningCount, m_zoneConnectionsCache, COMMIT::Modify(), PCB_VIA_T, REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_WARNING, BOARD::Tracks(), and UnescapeString().

Referenced by UpdateNetlist().

◆ UpdateNetlist()

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

740 {
741  wxString msg;
742  m_errorCount = 0;
743  m_warningCount = 0;
745  MODULE* lastPreexistingFootprint = m_board->Modules().empty() ? NULL : m_board->Modules().back();
746 
748 
749  if( !m_isDryRun )
750  {
751  m_board->SetStatus( 0 );
752 
753  // Mark all nets (except <no net>) as stale; we'll update those to current that
754  // we find in the netlist
755  for( NETINFO_ITEM* net : m_board->GetNetInfo() )
756  net->SetIsCurrent( net->GetNet() == 0 );
757  }
758 
759  for( unsigned i = 0; i < aNetlist.GetCount(); i++ )
760  {
761  COMPONENT* component = aNetlist.GetComponent( i );
762  int matchCount = 0;
763  MODULE* tmp;
764 
765  msg.Printf( _( "Processing component \"%s:%s\"." ),
766  component->GetReference(),
767  component->GetFPID().Format().wx_str() );
769 
770  for( auto footprint : m_board->Modules() )
771  {
772  bool match = false;
773 
774  if( footprint )
775  {
776  if( m_lookupByTimestamp )
777  match = footprint->GetPath() == component->GetPath();
778  else
779  match = footprint->GetReference().CmpNoCase( component->GetReference() ) == 0;
780  }
781 
782  if( match )
783  {
784  tmp = footprint;
785 
786  if( m_replaceFootprints && component->GetFPID() != footprint->GetFPID() )
787  tmp = replaceComponent( aNetlist, footprint, component );
788 
789  if( tmp )
790  {
791  updateComponentParameters( tmp, component );
792  updateComponentPadConnections( tmp, component );
793  }
794 
795  matchCount++;
796  }
797 
798  if( footprint == lastPreexistingFootprint )
799  {
800  // No sense going through the newly-created footprints: end of loop
801  break;
802  }
803  }
804 
805  if( matchCount == 0 )
806  {
807  tmp = addNewComponent( component );
808 
809  if( tmp )
810  {
811  updateComponentParameters( tmp, component );
812  updateComponentPadConnections( tmp, component );
813  }
814  }
815  else if( matchCount > 1 )
816  {
817  msg.Printf( _( "Multiple footprints found for \"%s\"." ),
818  component->GetReference() );
820  }
821  }
822 
823  updateCopperZoneNets( aNetlist );
824 
826  deleteUnusedComponents( aNetlist );
827 
828  if( !m_isDryRun )
829  {
830  m_board->GetConnectivity()->Build( m_board );
831  testConnectivity( aNetlist );
832 
833  // Now the connectivity data is rebuilt, we can delete single pads nets
836 
837  for( NETINFO_ITEM* net : m_board->GetNetInfo() )
838  {
839  if( !net->IsCurrent() )
840  {
841  msg.Printf( _( "Remove unused net \"%s\"." ), net->GetNetname() );
843  m_commit.Removed( net );
844  }
845  }
846 
848  m_commit.Push( _( "Update netlist" ) );
849  }
851  // We can delete single net pads in dry run mode only if no new footprints
852  // are added, because these new footprints are not actually added to the board
853  // and the current pad list is wrong in this case.
855 
856  if( m_isDryRun )
857  {
858  for( const auto& it : m_addedNets )
859  delete it.second;
860 
861  m_addedNets.clear();
862  }
863 
864  // Update the ratsnest
867 
868  msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
870 
871  if( m_errorCount )
872  {
873  m_reporter->ReportTail( _( "Errors occurred during the netlist update. Unless you fix them "
874  "your board will not be consistent with the schematics." ),
876  return false;
877  }
878 
879  return true;
880 }
MODULE * replaceComponent(NETLIST &aNetlist, MODULE *aPcbComponent, COMPONENT *aNewComponent)
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:94
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:228
const NETINFO_LIST & GetNetInfo() const
Definition: class_board.h:741
bool updateComponentPadConnections(MODULE *aPcbComponent, COMPONENT *aNewComponent)
bool updateCopperZoneNets(NETLIST &aNetlist)
bool testConnectivity(NETLIST &aNetlist)
void RemoveUnusedNets()
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
std::map< wxString, NETINFO_ITEM * > m_addedNets
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:149
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Definition: commit.h:96
#define NULL
MODULES & Modules()
Definition: class_board.h:266
const wxString & GetReference() const
Definition: pcb_netlist.h:144
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
UTF8 Format() const
Definition: lib_id.cpp:237
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:237
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
bool updateComponentParameters(MODULE *aPcbComponent, COMPONENT *aNewComponent)
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51
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:230
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:154
bool deleteUnusedComponents(NETLIST &aNetlist)
MODULE * addNewComponent(COMPONENT *aComponent)

References _, addNewComponent(), cacheCopperZoneConnections(), deleteSinglePadNets(), deleteUnusedComponents(), LIB_ID::Format(), NETLIST::GetComponent(), BOARD::GetConnectivity(), NETLIST::GetCount(), COMPONENT::GetFPID(), BOARD::GetNetInfo(), COMPONENT::GetPath(), COMPONENT::GetReference(), m_addedNets, m_board, m_commit, m_deleteSinglePadNets, m_deleteUnusedComponents, m_errorCount, m_isDryRun, m_lookupByTimestamp, m_newFootprintsCount, m_replaceFootprints, m_reporter, m_warningCount, BOARD::Modules(), NULL, BOARD_COMMIT::Push(), COMMIT::Removed(), NETINFO_LIST::RemoveUnusedNets(), replaceComponent(), REPORTER::Report(), REPORTER::ReportTail(), RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, EDA_ITEM::SetStatus(), testConnectivity(), updateComponentPadConnections(), updateComponentParameters(), updateCopperZoneNets(), and UTF8::wx_str().

Referenced by PCB_EDIT_FRAME::DoUpdatePCBFromNetlist(), and PCB_EDIT_FRAME::KiwayMailIn().

Member Data Documentation

◆ m_addedComponents

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

Definition at line 163 of file board_netlist_updater.h.

Referenced by addNewComponent(), and GetAddedComponents().

◆ m_addedNets

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

◆ m_board

◆ m_commit

◆ m_deleteSinglePadNets

bool BOARD_NETLIST_UPDATER::m_deleteSinglePadNets
private

◆ m_deleteUnusedComponents

bool BOARD_NETLIST_UPDATER::m_deleteUnusedComponents
private

◆ m_errorCount

int BOARD_NETLIST_UPDATER::m_errorCount
private

◆ m_frame

PCB_EDIT_FRAME* BOARD_NETLIST_UPDATER::m_frame
private

Definition at line 154 of file board_netlist_updater.h.

Referenced by addNewComponent(), and replaceComponent().

◆ m_isDryRun

◆ m_lookupByTimestamp

bool BOARD_NETLIST_UPDATER::m_lookupByTimestamp
private

◆ m_newFootprintsCount

int BOARD_NETLIST_UPDATER::m_newFootprintsCount
private

◆ m_oldToNewNets

std::map< wxString, wxString> BOARD_NETLIST_UPDATER::m_oldToNewNets
private

Definition at line 160 of file board_netlist_updater.h.

Referenced by updateComponentPadConnections(), and updateCopperZoneNets().

◆ m_padNets

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

Definition at line 161 of file board_netlist_updater.h.

Referenced by cacheNetname(), and getNetname().

◆ m_padPinFunctions

std::map< D_PAD*, wxString > BOARD_NETLIST_UPDATER::m_padPinFunctions
private

Definition at line 162 of file board_netlist_updater.h.

Referenced by cachePinFunction(), and getPinFunction().

◆ m_replaceFootprints

bool BOARD_NETLIST_UPDATER::m_replaceFootprints
private

◆ m_reporter

◆ m_warnForNoNetPads

bool BOARD_NETLIST_UPDATER::m_warnForNoNetPads
private

◆ m_warningCount

int BOARD_NETLIST_UPDATER::m_warningCount
private

◆ m_zoneConnectionsCache

std::map< ZONE_CONTAINER*, std::vector<D_PAD*> > BOARD_NETLIST_UPDATER::m_zoneConnectionsCache
private

Definition at line 159 of file board_netlist_updater.h.

Referenced by cacheCopperZoneConnections(), and updateCopperZoneNets().


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