KiCad PCB EDA Suite
BOARD_NETLIST_UPDATER Class Reference

Update 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)
 Update the board's components according to the new netlist. More...
 
void SetReporter (REPORTER *aReporter)
 Enable "delete single pad nets" option. More...
 
void SetDeleteSinglePadNets (bool aEnabled)
 Enable warning option if a connectable pad is not found in netlist connectable = pad with a name and on a copper layer. More...
 
void SetWarnPadNoNetInNetlist (bool aEnabled)
 Enable dry run mode (just report, no changes to PCB). More...
 
void SetIsDryRun (bool aEnabled)
 Enable replacing footprints with new ones. More...
 
void SetReplaceFootprints (bool aEnabled)
 Enable removing unused components. More...
 
void SetDeleteUnusedComponents (bool aEnabled)
 Enable component lookup by timestamp instead of reference. More...
 
void SetLookupByTimestamp (bool aEnabled)
 
std::vector< FOOTPRINT * > GetAddedComponents () const
 

Private Member Functions

void cacheNetname (PAD *aPad, const wxString &aNetname)
 
wxString getNetname (PAD *aPad)
 
void cachePinFunction (PAD *aPad, const wxString &aPinFunction)
 
wxString getPinFunction (PAD *aPad)
 
wxPoint estimateComponentInsertionPosition ()
 
FOOTPRINTaddNewComponent (COMPONENT *aComponent)
 
FOOTPRINTreplaceComponent (NETLIST &aNetlist, FOOTPRINT *aPcbComponent, COMPONENT *aNewComponent)
 
bool updateFootprintParameters (FOOTPRINT *aPcbFootprint, COMPONENT *aNetlistComponent)
 
bool updateComponentPadConnections (FOOTPRINT *aFootprint, COMPONENT *aNewComponent)
 
void cacheCopperZoneConnections ()
 
bool updateCopperZoneNets (NETLIST &aNetlist)
 
bool deleteUnusedComponents (NETLIST &aNetlist)
 
bool deleteSinglePadNets ()
 
bool testConnectivity (NETLIST &aNetlist, std::map< COMPONENT *, FOOTPRINT * > &aFootprintMap)
 

Private Attributes

PCB_EDIT_FRAMEm_frame
 
BOARD_COMMIT m_commit
 
BOARDm_board
 
REPORTERm_reporter
 
std::map< ZONE *, std::vector< PAD * > > m_zoneConnectionsCache
 
std::map< wxString, wxString > m_oldToNewNets
 
std::map< PAD *, wxString > m_padNets
 
std::map< PAD *, wxString > m_padPinFunctions
 
std::vector< FOOTPRINT * > 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

Update 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 71 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 48 of file board_netlist_updater.cpp.

48  :
49  m_frame( aFrame ),
50  m_commit( aFrame ),
51  m_board( aBoard )
52 {
54 
55  m_deleteSinglePadNets = true;
57  m_isDryRun = false;
58  m_replaceFootprints = true;
59  m_lookupByTimestamp = false;
60  m_warnForNoNetPads = false;
61 
62  m_warningCount = 0;
63  m_errorCount = 0;
65 }
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 68 of file board_netlist_updater.cpp.

69 {
70 }

Member Function Documentation

◆ addNewComponent()

FOOTPRINT * BOARD_NETLIST_UPDATER::addNewComponent ( COMPONENT aComponent)
private

Definition at line 134 of file board_netlist_updater.cpp.

135 {
136  wxString msg;
137 
138  if( aComponent->GetFPID().empty() )
139  {
140  msg.Printf( _( "Cannot add %s (no footprint assigned)." ),
141  aComponent->GetReference(),
142  aComponent->GetFPID().Format().wx_str() );
144  ++m_errorCount;
145  return nullptr;
146  }
147 
148  FOOTPRINT* footprint = m_frame->LoadFootprint( aComponent->GetFPID() );
149 
150  if( footprint == nullptr )
151  {
152  msg.Printf( _( "Cannot add %s (footprint \"%s\" not found)." ),
153  aComponent->GetReference(),
154  aComponent->GetFPID().Format().wx_str() );
156  ++m_errorCount;
157  return nullptr;
158  }
159 
160  if( m_isDryRun )
161  {
162  msg.Printf( _( "Add %s (footprint \"%s\")." ),
163  aComponent->GetReference(),
164  aComponent->GetFPID().Format().wx_str() );
165 
166  delete footprint;
167  footprint = nullptr;
168  }
169  else
170  {
171  for( PAD* pad : footprint->Pads() )
172  {
173  // Set the pads ratsnest settings to the global settings
174  pad->SetLocalRatsnestVisible( m_frame->GetDisplayOptions().m_ShowGlobalRatsnest );
175 
176  // Pads in the library all have orphaned nets. Replace with Default.
177  pad->SetNetCode( 0 );
178  }
179 
180  footprint->SetParent( m_board );
182 
183  m_addedComponents.push_back( footprint );
184  m_commit.Add( footprint );
185 
186  msg.Printf( _( "Added %s (footprint \"%s\")." ),
187  aComponent->GetReference(),
188  aComponent->GetFPID().Format().wx_str() );
189  }
190 
193  return footprint;
194 }
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
bool empty() const
Definition: lib_id.h:189
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:166
PADS & Pads()
Definition: footprint.h:164
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:132
std::vector< FOOTPRINT * > m_addedComponents
const wxString & GetReference() const
Definition: pcb_netlist.h:122
FOOTPRINT * LoadFootprint(const LIB_ID &aFootprintId)
Attempt to load aFootprintId from the footprint library table.
UTF8 Format() const
Definition: lib_id.cpp:233
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51
Definition: pad.h:60
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1438

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, pad, FOOTPRINT::Pads(), REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, EDA_ITEM::SetParent(), FOOTPRINT::SetPosition(), and UTF8::wx_str().

Referenced by UpdateNetlist().

◆ cacheCopperZoneConnections()

void BOARD_NETLIST_UPDATER::cacheCopperZoneConnections ( )
private

Definition at line 582 of file board_netlist_updater.cpp.

583 {
584  for( ZONE* zone : m_board->Zones() )
585  {
586  if( !zone->IsOnCopperLayer() || zone->GetIsRuleArea() )
587  continue;
588 
589  m_zoneConnectionsCache[ zone ] = m_board->GetConnectivity()->GetConnectedPads( zone );
590  }
591 }
ZONES & Zones()
Definition: board.h:311
std::map< ZONE *, std::vector< PAD * > > m_zoneConnectionsCache
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:416
Handle a list of polygons defining a copper zone.
Definition: zone.h:57

References BOARD::GetConnectivity(), m_board, m_zoneConnectionsCache, and BOARD::Zones().

Referenced by UpdateNetlist().

◆ cacheNetname()

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

Definition at line 76 of file board_netlist_updater.cpp.

77 {
78  m_padNets[ aPad ] = aNetname;
79 }
std::map< PAD *, wxString > m_padNets

References m_padNets.

Referenced by deleteSinglePadNets(), and updateComponentPadConnections().

◆ cachePinFunction()

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

Definition at line 91 of file board_netlist_updater.cpp.

92 {
93  m_padPinFunctions[ aPad ] = aPinFunction;
94 }
std::map< PAD *, wxString > m_padPinFunctions

References m_padPinFunctions.

Referenced by updateComponentPadConnections().

◆ deleteSinglePadNets()

bool BOARD_NETLIST_UPDATER::deleteSinglePadNets ( )
private

Definition at line 772 of file board_netlist_updater.cpp.

773 {
774  int count = 0;
775  wxString netname;
776  wxString msg;
777  PAD* previouspad = NULL;
778 
779  // We need the pad list for next tests.
780 
782 
783  std::vector<PAD*> padlist = m_board->GetPads();
784 
785  // Sort pads by netlist name
786  std::sort( padlist.begin(), padlist.end(),
787  [ this ]( PAD* a, PAD* b ) -> bool
788  {
789  return getNetname( a ) < getNetname( b );
790  } );
791 
792  for( PAD* pad : padlist )
793  {
794  if( getNetname( pad ).IsEmpty() )
795  continue;
796 
797  if( netname != getNetname( pad ) ) // End of net
798  {
799  if( previouspad && count == 1 )
800  {
801  // First, see if we have a copper zone attached to this pad.
802  // If so, this is not really a single pad net
803 
804  for( ZONE* zone : m_board->Zones() )
805  {
806  if( !zone->IsOnCopperLayer() )
807  continue;
808 
809  if( zone->GetIsRuleArea() )
810  continue;
811 
812  if( zone->GetNetname() == getNetname( previouspad ) )
813  {
814  count++;
815  break;
816  }
817  }
818 
819  if( count == 1 ) // Really one pad, and nothing else
820  {
821  if( m_isDryRun )
822  {
823  cacheNetname( previouspad, wxEmptyString );
824  msg.Printf( _( "Remove single pad net %s." ),
825  UnescapeString( getNetname( previouspad ) ) );
826  }
827  else
828  {
829  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
830  msg.Printf( _( "Removed single pad net %s." ),
831  UnescapeString( getNetname( previouspad ) ) );
832  }
833 
835  }
836  }
837 
838  netname = getNetname( pad );
839  count = 1;
840  }
841  else
842  {
843  count++;
844  }
845 
846  previouspad = pad;
847  }
848 
849  // Examine last pad
850  if( count == 1 )
851  {
852  if( !m_isDryRun )
853  previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
854  else
855  cacheNetname( previouspad, wxEmptyString );
856  }
857 
858  return true;
859 }
void BuildListOfNets()
Definition: board.h:735
ZONES & Zones()
Definition: board.h:311
wxString getNetname(PAD *aPad)
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
#define NULL
const std::vector< PAD * > GetPads() const
Return a reference to a list of all the pads.
Definition: board.cpp:1937
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
Definition: pad.h:60
void cacheNetname(PAD *aPad, const wxString &aNetname)
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:365

References _, BOARD::BuildListOfNets(), cacheNetname(), getNetname(), BOARD::GetPads(), m_board, m_isDryRun, m_reporter, NULL, pad, 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

◆ estimateComponentInsertionPosition()

wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition ( )
private

Definition at line 106 of file board_netlist_updater.cpp.

107 {
108  wxPoint bestPosition;
109 
110  if( !m_board->IsEmpty() )
111  {
112  // Position new components below any existing board features.
114 
115  if( bbox.GetWidth() || bbox.GetHeight() )
116  {
117  bestPosition.x = bbox.Centre().x;
118  bestPosition.y = bbox.GetBottom() + Millimeter2iu( 10 );
119  }
120  }
121  else
122  {
123  // Position new components in the center of the page when the board is empty.
124  wxSize pageSize = m_board->GetPageSettings().GetSizeIU();
125 
126  bestPosition.x = pageSize.GetWidth() / 2;
127  bestPosition.y = pageSize.GetHeight() / 2;
128  }
129 
130  return bestPosition;
131 }
const PAGE_INFO & GetPageSettings() const
Definition: board.h:608
const EDA_RECT GetBoardEdgesBoundingBox() const
Returns the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:812
int GetWidth() const
Definition: eda_rect.h:114
int GetBottom() const
Definition: eda_rect.h:119
int GetHeight() const
Definition: eda_rect.h:115
Handle the component boundary box.
Definition: eda_rect.h:42
wxPoint Centre() const
Definition: eda_rect.h:60
static constexpr int Millimeter2iu(double mm)
bool IsEmpty() const
Definition: board.h:353

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

Referenced by addNewComponent().

◆ GetAddedComponents()

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

Definition at line 130 of file board_netlist_updater.h.

131  {
132  return m_addedComponents;
133  }
std::vector< FOOTPRINT * > m_addedComponents

References m_addedComponents.

Referenced by PCB_EDIT_FRAME::OnNetlistChanged().

◆ getNetname()

wxString BOARD_NETLIST_UPDATER::getNetname ( PAD aPad)
private

Definition at line 82 of file board_netlist_updater.cpp.

83 {
84  if( m_isDryRun && m_padNets.count( aPad ) )
85  return m_padNets[ aPad ];
86  else
87  return aPad->GetNetname();
88 }
wxString GetNetname() const
std::map< 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 ( PAD aPad)
private

Definition at line 97 of file board_netlist_updater.cpp.

98 {
99  if( m_isDryRun && m_padPinFunctions.count( aPad ) )
100  return m_padPinFunctions[ aPad ];
101  else
102  return aPad->GetPinFunction();
103 }
std::map< PAD *, wxString > m_padPinFunctions
const wxString & GetPinFunction() const
Definition: pad.h:139

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

◆ replaceComponent()

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

Definition at line 197 of file board_netlist_updater.cpp.

199 {
200  wxString msg;
201 
202  if( aNewComponent->GetFPID().empty() )
203  {
204  msg.Printf( _( "Cannot update %s (no footprint assigned)." ),
205  aNewComponent->GetReference(),
206  aNewComponent->GetFPID().Format().wx_str() );
208  ++m_errorCount;
209  return nullptr;
210  }
211 
212  FOOTPRINT* newFootprint = m_frame->LoadFootprint( aNewComponent->GetFPID() );
213 
214  if( newFootprint == nullptr )
215  {
216  msg.Printf( _( "Cannot update %s (footprint \"%s\" not found)." ),
217  aNewComponent->GetReference(),
218  aNewComponent->GetFPID().Format().wx_str() );
220  ++m_errorCount;
221  return nullptr;
222  }
223 
224  if( m_isDryRun )
225  {
226  msg.Printf( _( "Change %s footprint from '%s' to '%s'."),
227  aPcbComponent->GetReference(),
228  aPcbComponent->GetFPID().Format().wx_str(),
229  aNewComponent->GetFPID().Format().wx_str() );
230 
231  delete newFootprint;
232  newFootprint = nullptr;
233  }
234  else
235  {
236  m_frame->ExchangeFootprint( aPcbComponent, newFootprint, m_commit );
237 
238  msg.Printf( _( "Changed %s footprint from '%s' to '%s'."),
239  aPcbComponent->GetReference(),
240  aPcbComponent->GetFPID().Format().wx_str(),
241  aNewComponent->GetFPID().Format().wx_str() );
242  }
243 
246  return newFootprint;
247 }
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
bool empty() const
Definition: lib_id.h:189
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:132
void ExchangeFootprint(FOOTPRINT *aExisting, FOOTPRINT *aNew, BOARD_COMMIT &aCommit, bool deleteExtraTexts=true, bool resetTextLayers=true, bool resetTextEffects=true, bool resetFabricationAttrs=true, bool reset3DModels=true)
Replace aExisting footprint by aNew footprint using the Existing footprint settings (position,...
const wxString & GetReference() const
Definition: pcb_netlist.h:122
const wxString & GetReference() const
Definition: footprint.h:426
FOOTPRINT * LoadFootprint(const LIB_ID &aFootprintId)
Attempt to load aFootprintId from the footprint library table.
const LIB_ID & GetFPID() const
Definition: footprint.h:190
UTF8 Format() const
Definition: lib_id.cpp:233
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51

References _, LIB_ID::empty(), PCB_EDIT_FRAME::ExchangeFootprint(), LIB_ID::Format(), COMPONENT::GetFPID(), FOOTPRINT::GetFPID(), COMPONENT::GetReference(), FOOTPRINT::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

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

Definition at line 94 of file board_netlist_updater.h.

References m_deleteSinglePadNets.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

◆ SetDeleteUnusedComponents()

void BOARD_NETLIST_UPDATER::SetDeleteUnusedComponents ( bool  aEnabled)
inline

Enable component lookup by timestamp instead of reference.

Definition at line 119 of file board_netlist_updater.h.

References m_deleteUnusedComponents.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

◆ SetIsDryRun()

void BOARD_NETLIST_UPDATER::SetIsDryRun ( bool  aEnabled)
inline

Enable replacing footprints with new ones.

Definition at line 107 of file board_netlist_updater.h.

References m_isDryRun.

◆ SetLookupByTimestamp()

void BOARD_NETLIST_UPDATER::SetLookupByTimestamp ( bool  aEnabled)
inline

Definition at line 125 of file board_netlist_updater.h.

126  {
127  m_lookupByTimestamp = aEnabled;
128  }

References m_lookupByTimestamp.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

◆ SetReplaceFootprints()

void BOARD_NETLIST_UPDATER::SetReplaceFootprints ( bool  aEnabled)
inline

Enable removing unused components.

Definition at line 113 of file board_netlist_updater.h.

References m_replaceFootprints.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

◆ SetReporter()

void BOARD_NETLIST_UPDATER::SetReporter ( REPORTER aReporter)
inline

Enable "delete single pad nets" option.

Definition at line 88 of file board_netlist_updater.h.

References m_reporter.

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

◆ SetWarnPadNoNetInNetlist()

void BOARD_NETLIST_UPDATER::SetWarnPadNoNetInNetlist ( bool  aEnabled)
inline

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

Definition at line 101 of file board_netlist_updater.h.

References m_warnForNoNetPads.

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

◆ testConnectivity()

bool BOARD_NETLIST_UPDATER::testConnectivity ( NETLIST aNetlist,
std::map< COMPONENT *, FOOTPRINT * > &  aFootprintMap 
)
private

Definition at line 862 of file board_netlist_updater.cpp.

864 {
865  // Verify that board contains all pads in netlist: if it doesn't then footprints are
866  // wrong or missing.
867 
868  wxString msg;
869  wxString padname;
870 
871  for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
872  {
873  COMPONENT* component = aNetlist.GetComponent( i );
874  FOOTPRINT* footprint = aFootprintMap[component];
875 
876  if( !footprint ) // It can be missing in partial designs
877  continue;
878 
879  // Explore all pins/pads in component
880  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
881  {
882  const COMPONENT_NET& net = component->GetNet( jj );
883  padname = net.GetPinName();
884 
885  if( footprint->FindPadByName( padname ) )
886  continue; // OK, pad found
887 
888  // not found: bad footprint, report error
889  msg.Printf( _( "%s pad %s not found in %s." ),
890  component->GetReference(),
891  padname,
892  footprint->GetFPID().Format().wx_str() );
894  ++m_errorCount;
895  }
896  }
897 
898  return true;
899 }
unsigned GetCount() const
Definition: pcb_netlist.h:227
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:43
unsigned GetNetCount() const
Definition: pcb_netlist.h:108
const wxString & GetReference() const
Definition: pcb_netlist.h:122
const LIB_ID & GetFPID() const
Definition: footprint.h:190
PAD * FindPadByName(const wxString &aPadName) const
Return a PAD with a matching name.
Definition: footprint.cpp:957
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:110
UTF8 Format() const
Definition: lib_id.cpp:233
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:235
#define _(s)
Definition: 3d_actions.cpp:33
wxString wx_str() const
Definition: utf8.cpp:51
const wxString & GetPinName() const
Definition: pcb_netlist.h:62

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

Referenced by UpdateNetlist().

◆ updateComponentPadConnections()

bool BOARD_NETLIST_UPDATER::updateComponentPadConnections ( FOOTPRINT aFootprint,
COMPONENT aNewComponent 
)
private

Definition at line 401 of file board_netlist_updater.cpp.

403 {
404  wxString msg;
405 
406  // Create a copy only if the footprint has not been added during this update
407  FOOTPRINT* copy = m_commit.GetStatus( aFootprint ) ? nullptr : (FOOTPRINT*) aFootprint->Clone();
408  bool changed = false;
409 
410  // At this point, the component footprint is updated. Now update the nets.
411  for( PAD* pad : aFootprint->Pads() )
412  {
413  const COMPONENT_NET& net = aNewComponent->GetNet( pad->GetName() );
414 
415  wxString pinFunction;
416  wxString pinType;
417 
418  if( net.IsValid() ) // i.e. the pad has a name
419  {
420  pinFunction = net.GetPinFunction();
421  pinType = net.GetPinType();
422  }
423 
424  if( !m_isDryRun )
425  {
426  if( pad->GetPinFunction() != pinFunction )
427  {
428  changed = true;
429  pad->SetPinFunction( pinFunction );
430  }
431 
432  if( pad->GetPinType() != pinType )
433  {
434  changed = true;
435  pad->SetPinType( pinType );
436  }
437  }
438  else
439  cachePinFunction( pad, pinFunction );
440 
441  // Test if new footprint pad has no net (pads not on copper layers have no net).
442  if( !net.IsValid() || !pad->IsOnCopperLayer() )
443  {
444  if( !pad->GetNetname().IsEmpty() )
445  {
446  if( m_isDryRun )
447  {
448  msg.Printf( _( "Disconnect %s pin %s." ),
449  aFootprint->GetReference(),
450  pad->GetName() );
451  }
452  else
453  {
454  msg.Printf( _( "Disconnected %s pin %s." ),
455  aFootprint->GetReference(),
456  pad->GetName() );
457  }
458 
460  }
461  else if( m_warnForNoNetPads && pad->IsOnCopperLayer() && !pad->GetName().IsEmpty() )
462  {
463  // pad is connectable but has no net found in netlist
464  msg.Printf( _( "No net found for symbol %s pin %s." ),
465  aFootprint->GetReference(),
466  pad->GetName() );
468  }
469 
470  if( !m_isDryRun )
471  {
472  changed = true;
473  pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
474 
475  // If the pad has no net from netlist (i.e. not in netlist
476  // it cannot have a pin function
477  if( pad->GetNetname().IsEmpty() )
478  pad->SetPinFunction( wxEmptyString );
479 
480  }
481  else
482  cacheNetname( pad, wxEmptyString );
483  }
484  else // New footprint pad has a net.
485  {
486  const wxString& netName = net.GetNetName();
487  NETINFO_ITEM* netinfo = m_board->FindNet( netName );
488 
489  if( netinfo && !m_isDryRun )
490  netinfo->SetIsCurrent( true );
491 
492  if( pad->GetNetname() != netName )
493  {
494 
495  if( netinfo == nullptr )
496  {
497  // It might be a new net that has not been added to the board yet
498  if( m_addedNets.count( netName ) )
499  netinfo = m_addedNets[ netName ];
500  }
501 
502  if( netinfo == nullptr )
503  {
504  netinfo = new NETINFO_ITEM( m_board, netName );
505 
506  // It is a new net, we have to add it
507  if( !m_isDryRun )
508  {
509  changed = true;
510  m_commit.Add( netinfo );
511  }
512 
513  m_addedNets[netName] = netinfo;
514  msg.Printf( _( "Add net %s." ), UnescapeString( netName ) );
516  }
517 
518  if( !pad->GetNetname().IsEmpty() )
519  {
520  m_oldToNewNets[ pad->GetNetname() ] = netName;
521 
522  if( m_isDryRun )
523  {
524  msg.Printf( _( "Reconnect %s pin %s from %s to %s."),
525  aFootprint->GetReference(),
526  pad->GetName(),
527  UnescapeString( pad->GetNetname() ),
528  UnescapeString( netName ) );
529  }
530  else
531  {
532  msg.Printf( _( "Reconnected %s pin %s from %s to %s."),
533  aFootprint->GetReference(),
534  pad->GetName(),
535  UnescapeString( pad->GetNetname() ),
536  UnescapeString( netName ) );
537  }
538  }
539  else
540  {
541  if( m_isDryRun )
542  {
543  msg.Printf( _( "Connect %s pin %s to %s."),
544  aFootprint->GetReference(),
545  pad->GetName(),
546  UnescapeString( netName ) );
547  }
548  else
549  {
550  msg.Printf( _( "Connected %s pin %s to %s."),
551 
552  aFootprint->GetReference(),
553  pad->GetName(),
554  UnescapeString( netName ) );
555  }
556  }
557 
559 
560  if( !m_isDryRun )
561  {
562  changed = true;
563  pad->SetNet( netinfo );
564  }
565  else
566  {
567  cacheNetname( pad, netName );
568  }
569  }
570  }
571  }
572 
573  if( changed && copy )
574  m_commit.Modified( aFootprint, copy );
575  else
576  delete copy;
577 
578  return true;
579 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1289
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
void SetIsCurrent(bool isCurrent)
Definition: netinfo.h:141
const wxString & GetPinType() const
Definition: pcb_netlist.h:65
int GetStatus(EDA_ITEM *aItem)
Definition: commit.cpp:129
std::map< wxString, wxString > m_oldToNewNets
void cachePinFunction(PAD *aPad, const wxString &aPinFunction)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
PADS & Pads()
Definition: footprint.h:164
std::map< wxString, NETINFO_ITEM * > m_addedNets
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:43
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
const wxString & GetReference() const
Definition: footprint.h:426
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:110
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:64
bool IsValid() const
Definition: pcb_netlist.h:67
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Definition: commit.h:110
Handle the data for a net.
Definition: netinfo.h:64
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
Definition: pad.h:60
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: footprint.cpp:1169
void cacheNetname(PAD *aPad, const wxString &aNetname)
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:365

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

Referenced by UpdateNetlist().

◆ updateCopperZoneNets()

bool BOARD_NETLIST_UPDATER::updateCopperZoneNets ( NETLIST aNetlist)
private

Definition at line 594 of file board_netlist_updater.cpp.

595 {
596  wxString msg;
597  std::set<wxString> netlistNetnames;
598 
599  for( int ii = 0; ii < (int) aNetlist.GetCount(); ii++ )
600  {
601  const COMPONENT* component = aNetlist.GetComponent( ii );
602  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
603  {
604  const COMPONENT_NET& net = component->GetNet( jj );
605  netlistNetnames.insert( net.GetNetName() );
606  }
607  }
608 
609  for( TRACK* via : m_board->Tracks() )
610  {
611  if( via->Type() != PCB_VIA_T )
612  continue;
613 
614  if( netlistNetnames.count( via->GetNetname() ) == 0 )
615  {
616  wxString updatedNetname = wxEmptyString;
617 
618  // Take via name from name change map if it didn't match to a new pad
619  // (this is useful for stitching vias that don't connect to tracks)
620  if( m_oldToNewNets.count( via->GetNetname() ) )
621  {
622  updatedNetname = m_oldToNewNets[via->GetNetname()];
623  }
624 
625  if( !updatedNetname.IsEmpty() )
626  {
627  if( m_isDryRun )
628  {
629  msg.Printf( _( "Reconnect via from %s to %s." ),
630  UnescapeString( via->GetNetname() ),
631  UnescapeString( updatedNetname ) );
632 
634  }
635  else
636  {
637  NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
638 
639  if( !netinfo )
640  netinfo = m_addedNets[updatedNetname];
641 
642  if( netinfo )
643  {
644  m_commit.Modify( via );
645  via->SetNet( netinfo );
646 
647  msg.Printf( _( "Reconnected via from %s to %s." ),
648  UnescapeString( via->GetNetname() ),
649  UnescapeString( updatedNetname ) );
650 
652  }
653  }
654  }
655  else
656  {
657  msg.Printf( _( "Via connected to unknown net (%s)." ),
658  UnescapeString( via->GetNetname() ) );
660  ++m_warningCount;
661  }
662  }
663  }
664 
665  // Test copper zones to detect "dead" nets (nets without any pad):
666  for( ZONE* zone : m_board->Zones() )
667  {
668  if( !zone->IsOnCopperLayer() || zone->GetIsRuleArea() )
669  continue;
670 
671  if( netlistNetnames.count( zone->GetNetname() ) == 0 )
672  {
673  // Look for a pad in the zone's connected-pad-cache which has been updated to
674  // a new net and use that. While this won't always be the right net, the dead
675  // net is guaranteed to be wrong.
676  wxString updatedNetname = wxEmptyString;
677 
678  for( PAD* pad : m_zoneConnectionsCache[ zone ] )
679  {
680  if( getNetname( pad ) != zone->GetNetname() )
681  {
682  updatedNetname = getNetname( pad );
683  break;
684  }
685  }
686 
687  // Take zone name from name change map if it didn't match to a new pad
688  // (this is useful for zones on internal layers)
689  if( updatedNetname.IsEmpty() && m_oldToNewNets.count( zone->GetNetname() ) )
690  {
691  updatedNetname = m_oldToNewNets[ zone->GetNetname() ];
692  }
693 
694  if( !updatedNetname.IsEmpty() )
695  {
696  if( m_isDryRun )
697  {
698  if( !zone->GetZoneName().IsEmpty() )
699  {
700  msg.Printf( _( "Reconnect copper zone '%s' from %s to %s." ),
701  zone->GetZoneName(),
702  UnescapeString( zone->GetNetname() ),
703  UnescapeString( updatedNetname ) );
704  }
705  else
706  {
707  msg.Printf( _( "Reconnect copper zone from %s to %s." ),
708  UnescapeString( zone->GetNetname() ),
709  UnescapeString( updatedNetname ) );
710  }
711 
713  }
714  else
715  {
716  NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
717 
718  if( !netinfo )
719  netinfo = m_addedNets[ updatedNetname ];
720 
721  if( netinfo )
722  {
723  m_commit.Modify( zone );
724  zone->SetNet( netinfo );
725 
726  if( !zone->GetZoneName().IsEmpty() )
727  {
728  msg.Printf( _( "Reconnected copper zone '%s' from %s to %s." ),
729  zone->GetZoneName(),
730  UnescapeString( zone->GetNetname() ),
731  UnescapeString( updatedNetname ) );
732  }
733  else
734  {
735  msg.Printf( _( "Reconnected copper zone from %s to %s." ),
736  UnescapeString( zone->GetNetname() ),
737  UnescapeString( updatedNetname ) );
738  }
739 
741  }
742  }
743  }
744  else
745  {
746  if( !zone->GetZoneName().IsEmpty() )
747  {
748  msg.Printf( _( "Copper zone '%s' has no pads connected." ),
749  zone->GetZoneName() );
750  }
751  else
752  {
753  PCB_LAYER_ID layer = zone->GetLayer();
754  wxPoint pos = zone->GetPosition();
755 
756  msg.Printf( _( "Copper zone on layer %s at (%s, %s) has no pads connected." ),
757  m_board->GetLayerName( layer ),
760  }
761 
763  ++m_warningCount;
764  }
765  }
766  }
767 
768  return true;
769 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1289
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:90
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:342
ZONES & Zones()
Definition: board.h:311
wxString getNetname(PAD *aPad)
unsigned GetCount() const
Definition: pcb_netlist.h:227
std::map< wxString, wxString > m_oldToNewNets
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::map< wxString, NETINFO_ITEM * > m_addedNets
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:43
PCB_LAYER_ID
A quick note on layer IDs:
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
std::map< ZONE *, std::vector< PAD * > > m_zoneConnectionsCache
unsigned GetNetCount() const
Definition: pcb_netlist.h:108
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:110
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:235
Handle the data for a net.
Definition: netinfo.h:64
#define _(s)
Definition: 3d_actions.cpp:33
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:60
TRACKS & Tracks()
Definition: board.h:302
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
Definition: track.h:83

References _, BOARD::FindNet(), NETLIST::GetComponent(), NETLIST::GetCount(), BOARD::GetLayerName(), COMPONENT::GetNet(), COMPONENT::GetNetCount(), COMPONENT_NET::GetNetName(), getNetname(), EDA_BASE_FRAME::GetUserUnits(), m_addedNets, m_board, m_commit, m_frame, m_isDryRun, m_oldToNewNets, m_reporter, m_warningCount, m_zoneConnectionsCache, MessageTextFromValue(), COMMIT::Modify(), pad, PCB_VIA_T, REPORTER::Report(), RPT_SEVERITY_ACTION, RPT_SEVERITY_WARNING, BOARD::Tracks(), UnescapeString(), via, and BOARD::Zones().

Referenced by UpdateNetlist().

◆ updateFootprintParameters()

bool BOARD_NETLIST_UPDATER::updateFootprintParameters ( FOOTPRINT aPcbFootprint,
COMPONENT aNetlistComponent 
)
private

Definition at line 250 of file board_netlist_updater.cpp.

252 {
253  wxString msg;
254 
255  // Create a copy only if the footprint has not been added during this update
256  FOOTPRINT* copy = m_commit.GetStatus( aPcbFootprint ) ? nullptr
257  : (FOOTPRINT*) aPcbFootprint->Clone();
258  bool changed = false;
259 
260  // Test for reference designator field change.
261  if( aPcbFootprint->GetReference() != aNetlistComponent->GetReference() )
262  {
263  if( m_isDryRun )
264  {
265  msg.Printf( _( "Change %s reference designator to %s." ),
266  aPcbFootprint->GetReference(),
267  aNetlistComponent->GetReference() );
268  }
269  else
270  {
271  msg.Printf( _( "Changed %s reference designator to %s." ),
272  aPcbFootprint->GetReference(),
273  aNetlistComponent->GetReference() );
274 
275  changed = true;
276  aPcbFootprint->SetReference( aNetlistComponent->GetReference() );
277  }
278 
280  }
281 
282  // Test for value field change.
283  if( aPcbFootprint->GetValue() != aNetlistComponent->GetValue() )
284  {
285  if( m_isDryRun )
286  {
287  msg.Printf( _( "Change %s value from %s to %s." ),
288  aPcbFootprint->GetReference(),
289  aPcbFootprint->GetValue(),
290  aNetlistComponent->GetValue() );
291  }
292  else
293  {
294  msg.Printf( _( "Changed %s value from %s to %s." ),
295  aPcbFootprint->GetReference(),
296  aPcbFootprint->GetValue(),
297  aNetlistComponent->GetValue() );
298 
299  changed = true;
300  aPcbFootprint->SetValue( aNetlistComponent->GetValue() );
301  }
302 
304  }
305 
306  // Test for time stamp change.
307  KIID_PATH new_path = aNetlistComponent->GetPath();
308  new_path.push_back( aNetlistComponent->GetKIIDs().front() );
309 
310  if( aPcbFootprint->GetPath() != new_path )
311  {
312  if( m_isDryRun )
313  {
314  msg.Printf( _( "Update %s symbol association from %s to %s." ),
315  aPcbFootprint->GetReference(),
316  aPcbFootprint->GetPath().AsString(),
317  new_path.AsString() );
318  }
319  else
320  {
321  msg.Printf( _( "Updated %s symbol association from %s to %s." ),
322  aPcbFootprint->GetReference(),
323  aPcbFootprint->GetPath().AsString(),
324  new_path.AsString() );
325 
326  changed = true;
327  aPcbFootprint->SetPath( new_path );
328  }
329 
331  }
332 
333  if( aPcbFootprint->GetProperties() != aNetlistComponent->GetProperties() )
334  {
335  if( m_isDryRun )
336  {
337  msg.Printf( _( "Update %s properties." ),
338  aPcbFootprint->GetReference() );
339  }
340  else
341  {
342  msg.Printf( _( "Updated %s properties." ),
343  aPcbFootprint->GetReference() );
344 
345  changed = true;
346  aPcbFootprint->SetProperties( aNetlistComponent->GetProperties() );
347  }
348 
350  }
351 
352  if( ( aNetlistComponent->GetProperties().count( "exclude_from_bom" ) > 0 )
353  != ( ( aPcbFootprint->GetAttributes() & FP_EXCLUDE_FROM_BOM ) > 0 ) )
354  {
355  if( m_isDryRun )
356  {
357  if( aNetlistComponent->GetProperties().count( "exclude_from_bom" ) )
358  {
359  msg.Printf( _( "Add %s 'exclude from BOM' fabrication attribute." ),
360  aPcbFootprint->GetReference() );
361  }
362  else
363  {
364  msg.Printf( _( "Remove %s 'exclude from BOM' fabrication attribute." ),
365  aPcbFootprint->GetReference() );
366  }
367  }
368  else
369  {
370  int attributes = aPcbFootprint->GetAttributes();
371 
372  if( aNetlistComponent->GetProperties().count( "exclude_from_bom" ) )
373  {
374  attributes |= FP_EXCLUDE_FROM_BOM;
375  msg.Printf( _( "Added %s 'exclude from BOM' fabrication attribute." ),
376  aPcbFootprint->GetReference() );
377  }
378  else
379  {
380  attributes &= ~FP_EXCLUDE_FROM_BOM;
381  msg.Printf( _( "Removed %s 'exclude from BOM' fabrication attribute." ),
382  aPcbFootprint->GetReference() );
383  }
384 
385  changed = true;
386  aPcbFootprint->SetAttributes( attributes );
387  }
388 
390  }
391 
392  if( changed && copy )
393  m_commit.Modified( aPcbFootprint, copy );
394  else
395  delete copy;
396 
397  return true;
398 }
void SetReference(const wxString &aReference)
Definition: footprint.h:435
const wxString & GetValue() const
Definition: footprint.h:448
const KIID_PATH & GetPath() const
Definition: footprint.h:199
void SetPath(const KIID_PATH &aPath)
Definition: footprint.h:200
int GetStatus(EDA_ITEM *aItem)
Definition: commit.cpp:129
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetAttributes(int aAttributes)
Definition: footprint.h:232
const wxString & GetReference() const
Definition: pcb_netlist.h:122
const wxString & GetReference() const
Definition: footprint.h:426
void SetValue(const wxString &aValue)
Definition: footprint.h:456
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy)
Definition: commit.h:110
int GetAttributes() const
Definition: footprint.h:231
#define _(s)
Definition: 3d_actions.cpp:33
wxString AsString() const
Definition: kiid.cpp:256
const std::map< wxString, wxString > & GetProperties() const
Definition: footprint.h:469
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:129
const wxString & GetValue() const
Definition: pcb_netlist.h:123
void SetProperties(const std::map< wxString, wxString > &aProps)
Definition: footprint.h:470
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: footprint.cpp:1169
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:137
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:139

References _, KIID_PATH::AsString(), FOOTPRINT::Clone(), copy, FP_EXCLUDE_FROM_BOM, FOOTPRINT::GetAttributes(), COMPONENT::GetKIIDs(), COMPONENT::GetPath(), FOOTPRINT::GetPath(), COMPONENT::GetProperties(), FOOTPRINT::GetProperties(), COMPONENT::GetReference(), FOOTPRINT::GetReference(), COMMIT::GetStatus(), COMPONENT::GetValue(), FOOTPRINT::GetValue(), m_commit, m_isDryRun, m_reporter, COMMIT::Modified(), REPORTER::Report(), RPT_SEVERITY_ACTION, FOOTPRINT::SetAttributes(), FOOTPRINT::SetPath(), FOOTPRINT::SetProperties(), FOOTPRINT::SetReference(), and FOOTPRINT::SetValue().

Referenced by UpdateNetlist().

◆ UpdateNetlist()

bool BOARD_NETLIST_UPDATER::UpdateNetlist ( NETLIST aNetlist)

Update 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 successfullySet the reporter object.

Definition at line 902 of file board_netlist_updater.cpp.

903 {
904  FOOTPRINT* lastPreexistingFootprint = nullptr;
905  COMPONENT* component = nullptr;
906  wxString msg;
907 
908  m_errorCount = 0;
909  m_warningCount = 0;
911 
912  std::map<COMPONENT*, FOOTPRINT*> footprintMap;
913 
914  if( !m_board->Footprints().empty() )
915  lastPreexistingFootprint = m_board->Footprints().back();
916 
918 
919  // First mark all nets (except <no net>) as stale; we'll update those which are current
920  // in the following two loops.
921  //
922  if( !m_isDryRun )
923  {
924  m_board->SetStatus( 0 );
925 
926  for( NETINFO_ITEM* net : m_board->GetNetInfo() )
927  net->SetIsCurrent( net->GetNetCode() == 0 );
928  }
929 
930  // Next go through the netlist updating all board footprints which have matching component
931  // entries and adding new footprints for those that don't.
932  //
933  for( unsigned i = 0; i < aNetlist.GetCount(); i++ )
934  {
935  component = aNetlist.GetComponent( i );
936 
937  if( component->GetProperties().count( "exclude_from_board" ) )
938  continue;
939 
940  msg.Printf( _( "Processing symbol '%s:%s'." ),
941  component->GetReference(),
942  component->GetFPID().Format().wx_str() );
944 
945  int matchCount = 0;
946 
947  for( FOOTPRINT* footprint : m_board->Footprints() )
948  {
949  bool match = false;
950 
951  if( m_lookupByTimestamp )
952  {
953  for( auto& uuid : component->GetKIIDs() )
954  {
955  KIID_PATH base = component->GetPath();
956  base.push_back( uuid );
957 
958  if( footprint->GetPath() == base )
959  {
960  match = true;
961  break;
962  }
963  }
964  }
965  else
966  match = footprint->GetReference().CmpNoCase( component->GetReference() ) == 0;
967 
968  if( match )
969  {
970  FOOTPRINT* tmp = footprint;
971 
972  if( m_replaceFootprints && component->GetFPID() != footprint->GetFPID() )
973  tmp = replaceComponent( aNetlist, footprint, component );
974 
975  if( tmp )
976  {
977  footprintMap[ component ] = tmp;
978 
979  updateFootprintParameters( tmp, component );
980  updateComponentPadConnections( tmp, component );
981  }
982 
983  matchCount++;
984  }
985 
986  if( footprint == lastPreexistingFootprint )
987  {
988  // No sense going through the newly-created footprints: end of loop
989  break;
990  }
991  }
992 
993  if( matchCount == 0 )
994  {
995  FOOTPRINT* footprint = addNewComponent( component );
996 
997  if( footprint )
998  {
999  footprintMap[ component ] = footprint;
1000 
1001  updateFootprintParameters( footprint, component );
1002  updateComponentPadConnections( footprint, component );
1003  }
1004  }
1005  else if( matchCount > 1 )
1006  {
1007  msg.Printf( _( "Multiple footprints found for \"%s\"." ),
1008  component->GetReference() );
1010  }
1011  }
1012 
1013  updateCopperZoneNets( aNetlist );
1014 
1015  // Finally go through the board footprints and update all those that *don't* have matching
1016  // component entries.
1017  //
1018  for( FOOTPRINT* footprint : m_board->Footprints() )
1019  {
1020  bool doDelete = m_deleteUnusedComponents;
1021 
1022  if( ( footprint->GetAttributes() & FP_BOARD_ONLY ) > 0 )
1023  doDelete = false;
1024 
1025  if( doDelete )
1026  {
1027  if( m_lookupByTimestamp )
1028  component = aNetlist.GetComponentByPath( footprint->GetPath() );
1029  else
1030  component = aNetlist.GetComponentByReference( footprint->GetReference() );
1031 
1032  if( component && component->GetProperties().count( "exclude_from_board" ) == 0 )
1033  doDelete = false;
1034  }
1035 
1036  if( doDelete && footprint->IsLocked() )
1037  {
1038  if( m_isDryRun )
1039  {
1040  msg.Printf( _( "Cannot remove unused footprint %s (locked)." ),
1041  footprint->GetReference() );
1042  }
1043  else
1044  {
1045  msg.Printf( _( "Could not remove unused footprint %s (locked)." ),
1046  footprint->GetReference() );
1047  }
1048 
1050  doDelete = false;
1051  }
1052 
1053  if( doDelete )
1054  {
1055  if( m_isDryRun )
1056  {
1057  msg.Printf( _( "Remove unused footprint %s." ), footprint->GetReference() );
1058  }
1059  else
1060  {
1061  m_commit.Remove( footprint );
1062  msg.Printf( _( "Removed unused footprint %s." ), footprint->GetReference() );
1063  }
1064 
1066  }
1067  else if( !m_isDryRun )
1068  {
1069  for( PAD* pad : footprint->Pads() )
1070  {
1071  if( pad->GetNet() )
1072  pad->GetNet()->SetIsCurrent( true );
1073  }
1074  }
1075  }
1076 
1077  if( !m_isDryRun )
1078  {
1079  m_board->GetConnectivity()->Build( m_board );
1080  testConnectivity( aNetlist, footprintMap );
1081 
1082  // Now the connectivity data is rebuilt, we can delete single pads nets
1083  if( m_deleteSinglePadNets )
1085 
1086  for( NETINFO_ITEM* net : m_board->GetNetInfo() )
1087  {
1088  if( !net->IsCurrent() )
1089  {
1090  msg.Printf( _( "Removed unused net %s." ), net->GetNetname() );
1092  m_commit.Removed( net );
1093  }
1094  }
1095 
1098  m_commit.Push( _( "Update netlist" ) );
1099 
1102  }
1104  {
1105  // We can delete single net pads in dry run mode only if no new footprints
1106  // are added, because these new footprints are not actually added to the board
1107  // and the current pad list is wrong in this case.
1109  }
1110 
1111  if( m_isDryRun )
1112  {
1113  for( const std::pair<const wxString, NETINFO_ITEM*>& addedNet : m_addedNets )
1114  delete addedNet.second;
1115 
1116  m_addedNets.clear();
1117  }
1118 
1119  // Update the ratsnest
1120  m_reporter->ReportTail( wxT( "" ), RPT_SEVERITY_ACTION );
1121  m_reporter->ReportTail( wxT( "" ), RPT_SEVERITY_ACTION );
1122 
1123  msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
1125 
1126  return true;
1127 }
bool IsLocked() const override
Definition: footprint.h:282
COMPONENT * GetComponentByPath(const KIID_PATH &aPath)
Return a COMPONENT by aPath.
const KIID_PATH & GetPath() const
Definition: footprint.h:199
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
Definition: reporter.h:93
unsigned GetCount() const
Definition: pcb_netlist.h:227
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:754
bool updateCopperZoneNets(NETLIST &aNetlist)
void RemoveUnusedNets()
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
PADS & Pads()
Definition: footprint.h:164
std::map< wxString, NETINFO_ITEM * > m_addedNets
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:132
bool updateComponentPadConnections(FOOTPRINT *aFootprint, COMPONENT *aNewComponent)
COMMIT & Removed(EDA_ITEM *aItem)
Modify a given item in the model.
Definition: commit.h:96
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1434
FOOTPRINT * addNewComponent(COMPONENT *aComponent)
FOOTPRINTS & Footprints()
Definition: board.h:305
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
const wxString & GetReference() const
Definition: pcb_netlist.h:122
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:416
const wxString & GetReference() const
Definition: footprint.h:426
FOOTPRINT * replaceComponent(NETLIST &aNetlist, FOOTPRINT *aPcbComponent, COMPONENT *aNewComponent)
COMMIT & Remove(EDA_ITEM *aItem)
Notify observers that aItem has been removed.
Definition: commit.h:90
UTF8 Format() const
Definition: lib_id.cpp:233
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:235
Handle the data for a net.
Definition: netinfo.h:64
bool updateFootprintParameters(FOOTPRINT *aPcbFootprint, COMPONENT *aNetlistComponent)
int GetAttributes() const
Definition: footprint.h:231
#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
Revert the commit by restoring the modified items state.
void SetStatus(STATUS_FLAGS aStatus)
Definition: eda_item.h:201
const std::map< wxString, wxString > & GetProperties() const
Definition: pcb_netlist.h:129
COMPONENT * GetComponentByReference(const wxString &aReference)
Return a COMPONENT by aReference.
Definition: pad.h:60
bool testConnectivity(NETLIST &aNetlist, std::map< COMPONENT *, FOOTPRINT * > &aFootprintMap)
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:137
void SetResolveNetConflicts(bool aResolve=true)
Sets a flag that will cause Push() to resolve net conflicts on track/via clusters instead of the defa...
Definition: board_commit.h:62
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:139

References _, addNewComponent(), cacheCopperZoneConnections(), deleteSinglePadNets(), BOARD::Footprints(), LIB_ID::Format(), FP_BOARD_ONLY, NETLIST::GetComponent(), NETLIST::GetComponentByPath(), NETLIST::GetComponentByReference(), BOARD::GetConnectivity(), NETLIST::GetCount(), COMPONENT::GetFPID(), COMPONENT::GetKIIDs(), BOARD::GetNetInfo(), COMPONENT::GetPath(), COMPONENT::GetProperties(), COMPONENT::GetReference(), m_addedNets, m_board, m_commit, m_deleteSinglePadNets, m_deleteUnusedComponents, m_errorCount, m_frame, m_isDryRun, m_lookupByTimestamp, m_newFootprintsCount, m_replaceFootprints, m_reporter, m_warningCount, pad, BOARD_COMMIT::Push(), COMMIT::Remove(), COMMIT::Removed(), NETINFO_LIST::RemoveUnusedNets(), replaceComponent(), REPORTER::Report(), REPORTER::ReportTail(), RPT_SEVERITY_ACTION, RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, RPT_SEVERITY_WARNING, PCB_EDIT_FRAME::SaveProjectSettings(), BOARD_COMMIT::SetResolveNetConflicts(), EDA_ITEM::SetStatus(), BOARD::SynchronizeNetsAndNetClasses(), testConnectivity(), updateComponentPadConnections(), updateCopperZoneNets(), updateFootprintParameters(), and UTF8::wx_str().

Referenced by PCB_EDIT_FRAME::KiwayMailIn().

Member Data Documentation

◆ m_addedComponents

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

Definition at line 172 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

◆ 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 169 of file board_netlist_updater.h.

Referenced by updateComponentPadConnections(), and updateCopperZoneNets().

◆ m_padNets

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

Definition at line 170 of file board_netlist_updater.h.

Referenced by cacheNetname(), and getNetname().

◆ m_padPinFunctions

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

Definition at line 171 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*, std::vector<PAD*> > BOARD_NETLIST_UPDATER::m_zoneConnectionsCache
private

Definition at line 168 of file board_netlist_updater.h.

Referenced by cacheCopperZoneConnections(), and updateCopperZoneNets().


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