KiCad PCB EDA Suite
TRACKS_CLEANER Class Reference

#include <tracks_cleaner.h>

Public Member Functions

 TRACKS_CLEANER (BOARD *aPcb, BOARD_COMMIT &aCommit)
 
void CleanupBoard (bool aDryRun, std::vector< CLEANUP_ITEM * > *aItemsList, bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad)
 the cleanup function. More...
 

Private Member Functions

void removeBadTrackSegments ()
 
void cleanupVias ()
 Removes redundant vias like vias at same location or on pad through. More...
 
bool deleteDanglingTracks ()
 
void deleteTracksInPads ()
 
void deleteNullSegments (TRACKS &aTracks)
 
void cleanupSegments ()
 Merge collinear segments and remove duplicated and null length segments. More...
 
void mergeCollinearSegments (TRACK *aSeg1, TRACK *aSeg2)
 helper function merge aTrackRef and aCandidate, when possible, i.e. More...
 
bool testTrackEndpointIsNode (TRACK *aTrack, bool aTstStart)
 
void removeItems (std::set< BOARD_ITEM * > &aItems)
 

Private Attributes

BOARDm_brd
 
BOARD_COMMITm_commit
 
bool m_dryRun
 
std::vector< CLEANUP_ITEM * > * m_itemsList
 

Detailed Description

Definition at line 35 of file tracks_cleaner.h.

Constructor & Destructor Documentation

◆ TRACKS_CLEANER()

TRACKS_CLEANER::TRACKS_CLEANER ( BOARD aPcb,
BOARD_COMMIT aCommit 
)

Definition at line 38 of file tracks_cleaner.cpp.

38  :
39  m_brd( aPcb ),
40  m_commit( aCommit ),
41  m_dryRun( true ),
42  m_itemsList( nullptr )
43 {
44 }
std::vector< CLEANUP_ITEM * > * m_itemsList
BOARD_COMMIT & m_commit

Member Function Documentation

◆ CleanupBoard()

void TRACKS_CLEANER::CleanupBoard ( bool  aDryRun,
std::vector< CLEANUP_ITEM * > *  aItemsList,
bool  aCleanVias,
bool  aRemoveMisConnected,
bool  aMergeSegments,
bool  aDeleteUnconnected,
bool  aDeleteTracksinPad 
)

the cleanup function.

Parameters
aCleanVias= true to remove superimposed vias
aRemoveMisConnected= true to remove segments connecting 2 different nets (short circuits)
aMergeSegments= true to merge collinear segmenst and remove 0 len segm
aDeleteUnconnected= true to remove dangling tracks
aDeleteTracksinPad= true to remove tracks fully inside pads

Definition at line 53 of file tracks_cleaner.cpp.

56 {
57  m_dryRun = aDryRun;
58  m_itemsList = aItemsList;
59 
60  // Clear the flag used to mark some segments as deleted, in dry run:
61  for( TRACK* segment : m_brd->Tracks() )
62  segment->ClearFlags( IS_DELETED );
63 
64  // delete redundant vias
65  if( aCleanVias )
66  cleanupVias();
67 
68  // Remove null segments and intermediate points on aligned segments
69  // If not asked, remove null segments only if remove misconnected is asked
70  if( aMergeSegments )
72  else if( aRemoveMisConnected )
74 
75  if( aRemoveMisConnected )
77 
78  if( aDeleteTracksinPad )
80 
81  // Delete dangling tracks
82  if( aDeleteUnconnected )
83  {
84  if( deleteDanglingTracks() )
85  {
86  // Removed tracks can leave aligned segments
87  // (when a T was formed by tracks and the "vertical" segment is removed)
88  if( aMergeSegments )
90  }
91  }
92 
93  // Clear the flag used to mark some segments:
94  for( TRACK* segment : m_brd->Tracks() )
95  segment->ClearFlags( IS_DELETED );
96 }
void deleteNullSegments(TRACKS &aTracks)
std::vector< CLEANUP_ITEM * > * m_itemsList
bool deleteDanglingTracks()
void cleanupVias()
Removes redundant vias like vias at same location or on pad through.
void cleanupSegments()
Merge collinear segments and remove duplicated and null length segments.
#define IS_DELETED
Definition: base_struct.h:120
void removeBadTrackSegments()
TRACKS & Tracks()
Definition: class_board.h:257

References cleanupSegments(), cleanupVias(), deleteDanglingTracks(), deleteNullSegments(), deleteTracksInPads(), IS_DELETED, m_brd, m_dryRun, m_itemsList, removeBadTrackSegments(), and BOARD::Tracks().

◆ cleanupSegments()

void TRACKS_CLEANER::cleanupSegments ( )
private

Merge collinear segments and remove duplicated and null length segments.

Definition at line 338 of file tracks_cleaner.cpp.

339 {
340  // Easy things first
342 
343  std::set<BOARD_ITEM*> toRemove;
344 
345  // Remove duplicate segments (2 superimposed identical segments):
346  for( auto it = m_brd->Tracks().begin(); it != m_brd->Tracks().end(); it++ )
347  {
348  TRACK* track1 = *it;
349 
350  if( track1->Type() != PCB_TRACE_T || track1->HasFlag( IS_DELETED ) || track1->IsLocked() )
351  continue;
352 
353  for( auto it2 = it + 1; it2 != m_brd->Tracks().end(); it2++ )
354  {
355  TRACK* track2 = *it2;
356 
357  if( track2->HasFlag( IS_DELETED ) )
358  continue;
359 
360  if( track1->IsPointOnEnds( track2->GetStart() )
361  && track1->IsPointOnEnds( track2->GetEnd() )
362  && track1->GetWidth() == track2->GetWidth()
363  && track1->GetLayer() == track2->GetLayer() )
364  {
366  item->SetItems( track2 );
367  m_itemsList->push_back( item );
368 
369  track2->SetFlags( IS_DELETED );
370  toRemove.insert( track2 );
371  }
372  }
373  }
374 
375  if( !m_dryRun )
376  removeItems( toRemove );
377 
378  // Keep a duplicate deque to all deleting in the primary
379  std::deque<TRACK*> temp_segments( m_brd->Tracks() );
380 
381  // merge collinear segments:
382  for( TRACK* segment : temp_segments )
383  {
384  if( segment->Type() != PCB_TRACE_T ) // one can merge only track collinear segments, not vias.
385  continue;
386 
387  if( segment->HasFlag( IS_DELETED ) ) // already taken in account
388  continue;
389 
390  auto connectivity = m_brd->GetConnectivity();
391 
392  auto& entry = connectivity->GetConnectivityAlgo()->ItemEntry( segment );
393 
394  for( CN_ITEM* citem : entry.GetItems() )
395  {
396  for( CN_ITEM* connected : citem->ConnectedItems() )
397  {
398  if( !connected->Valid() )
399  continue;
400 
401  BOARD_CONNECTED_ITEM* candidateItem = connected->Parent();
402 
403  if( candidateItem->Type() == PCB_TRACE_T && !candidateItem->HasFlag( IS_DELETED ) )
404  {
405  TRACK* candidateSegment = static_cast<TRACK*>( candidateItem );
406 
407  // Do not merge segments having different widths: it is a frequent case
408  // to draw a track between 2 pads:
409  if( candidateSegment->GetWidth() != segment->GetWidth() )
410  continue;
411 
412  if( segment->ApproxCollinear( *candidateSegment ) )
413  mergeCollinearSegments( segment, candidateSegment );
414  }
415  }
416  }
417  }
418 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:138
const CONNECTED_ITEMS & ConnectedItems() const
void deleteNullSegments(TRACKS &aTracks)
const wxPoint & GetStart() const
Definition: class_track.h:118
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
#define IS_DELETED
Definition: base_struct.h:120
void mergeCollinearSegments(TRACK *aSeg1, TRACK *aSeg2)
helper function merge aTrackRef and aCandidate, when possible, i.e.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void removeItems(std::set< BOARD_ITEM * > &aItems)
int GetWidth() const
Definition: class_track.h:112
STATUS_FLAGS IsPointOnEnds(const wxPoint &point, int min_dist=0) const
Function IsPointOnEnds returns STARTPOINT if point if near (dist = min_dist) start point,...
const wxPoint & GetEnd() const
Definition: class_track.h:115
bool HasFlag(STATUS_FLAGS aFlag)
Definition: base_struct.h:235
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
TRACKS & Tracks()
Definition: class_board.h:257
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References CLEANUP_DUPLICATE_TRACK, CN_ITEM::ConnectedItems(), deleteNullSegments(), BOARD::GetConnectivity(), TRACK::GetEnd(), BOARD_ITEM::GetLayer(), TRACK::GetStart(), TRACK::GetWidth(), EDA_ITEM::HasFlag(), IS_DELETED, TRACK::IsLocked(), TRACK::IsPointOnEnds(), m_brd, m_dryRun, m_itemsList, mergeCollinearSegments(), PCB_TRACE_T, removeItems(), EDA_ITEM::SetFlags(), RC_ITEM::SetItems(), BOARD::Tracks(), and EDA_ITEM::Type().

Referenced by CleanupBoard().

◆ cleanupVias()

void TRACKS_CLEANER::cleanupVias ( )
private

Removes redundant vias like vias at same location or on pad through.

Definition at line 137 of file tracks_cleaner.cpp.

138 {
139  std::set<BOARD_ITEM*> toRemove;
140  std::vector<VIA*> vias;
141 
142  for( TRACK* track : m_brd->Tracks() )
143  {
144  if( auto via = dyn_cast<VIA*>( track ) )
145  vias.push_back( via );
146  }
147 
148  for( auto via1_it = vias.begin(); via1_it != vias.end(); via1_it++ )
149  {
150  VIA* via1 = *via1_it;
151 
152  if( via1->IsLocked() )
153  continue;
154 
155  if( via1->GetStart() != via1->GetEnd() )
156  via1->SetEnd( via1->GetStart() );
157 
158  // To delete through Via on THT pads at same location
159  // Examine the list of connected pads:
160  // if a through pad is found, the via can be removed
161 
162  const std::vector<D_PAD*> pads = m_brd->GetConnectivity()->GetConnectedPads( via1 );
163 
164  for( D_PAD* pad : pads )
165  {
166  const LSET all_cu = LSET::AllCuMask();
167 
168  if( ( pad->GetLayerSet() & all_cu ) == all_cu )
169  {
171  item->SetItems( via1, pad );
172  m_itemsList->push_back( item );
173 
174  // redundant: delete the via
175  toRemove.insert( via1 );
176  break;
177  }
178  }
179 
180  for( auto via2_it = via1_it + 1; via2_it != vias.end(); via2_it++ )
181  {
182  VIA* via2 = *via2_it;
183 
184  if( via1->GetPosition() != via2->GetPosition() || via2->IsLocked() )
185  continue;
186 
187  if( via1->GetViaType() == via2->GetViaType() )
188  {
190  item->SetItems( via1, via2 );
191  m_itemsList->push_back( item );
192 
193  toRemove.insert( via2 );
194  break;
195  }
196  }
197  }
198 
199  if( !m_dryRun )
200  removeItems( toRemove );
201 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:138
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:712
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:114
const wxPoint & GetStart() const
Definition: class_track.h:118
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
LSET is a set of PCB_LAYER_IDs.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void removeItems(std::set< BOARD_ITEM * > &aItems)
VIATYPE GetViaType() const
Definition: class_track.h:373
const wxPoint & GetEnd() const
Definition: class_track.h:115
wxPoint GetPosition() const override
Definition: class_track.h:411
TRACKS & Tracks()
Definition: class_board.h:257

References LSET::AllCuMask(), CLEANUP_REDUNDANT_VIA, BOARD::GetConnectivity(), TRACK::GetEnd(), VIA::GetPosition(), TRACK::GetStart(), VIA::GetViaType(), TRACK::IsLocked(), m_brd, m_dryRun, m_itemsList, removeItems(), TRACK::SetEnd(), RC_ITEM::SetItems(), and BOARD::Tracks().

Referenced by CleanupBoard().

◆ deleteDanglingTracks()

bool TRACKS_CLEANER::deleteDanglingTracks ( )
private

Definition at line 237 of file tracks_cleaner.cpp.

238 {
239  bool item_erased = false;
240  bool modified = false;
241 
242  do // Iterate when at least one track is deleted
243  {
244  item_erased = false;
245  // Ensure the connectivity is up to date, especially after removind a dangling segment
247 
248  // Keep a duplicate deque to all deleting in the primary
249  std::deque<TRACK*> temp_tracks( m_brd->Tracks() );
250 
251  for( TRACK* track : temp_tracks )
252  {
253  bool flag_erase = false; // Start without a good reason to erase it
254  wxPoint pos;
255 
256  // Tst if a track (or a via) endpoint is not connected to another track or to a zone.
257  if( m_brd->GetConnectivity()->TestTrackEndpointDangling( track, &pos ) )
258  flag_erase = true;
259 
260  if( flag_erase )
261  {
262  int errorCode = track->IsTrack() ? CLEANUP_DANGLING_TRACK : CLEANUP_DANGLING_VIA;
263  CLEANUP_ITEM* item = new CLEANUP_ITEM( errorCode );
264  item->SetItems( track );
265  m_itemsList->push_back( item );
266 
267  if( !m_dryRun )
268  {
269  m_brd->Remove( track );
270  m_commit.Removed( track );
271 
272  /* keep iterating, because a track connected to the deleted track
273  * now perhaps is not connected and should be deleted */
274  item_erased = true;
275  modified = true;
276  }
277  // Fix me: In dry run we should disable the track to erase and retry with this disabled track
278  // However the connectivity algo does not handle disabled items.
279  }
280  }
281  } while( item_erased ); // A segment was erased: test for some new dangling segments
282 
283  return modified;
284 }
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
BOARD_COMMIT & m_commit
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Definition: commit.h:96
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
TRACKS & Tracks()
Definition: class_board.h:257

References BOARD::BuildConnectivity(), CLEANUP_DANGLING_TRACK, CLEANUP_DANGLING_VIA, BOARD::GetConnectivity(), m_brd, m_commit, m_dryRun, m_itemsList, BOARD::Remove(), COMMIT::Removed(), RC_ITEM::SetItems(), and BOARD::Tracks().

Referenced by CleanupBoard().

◆ deleteNullSegments()

void TRACKS_CLEANER::deleteNullSegments ( TRACKS &  aTracks)
private

Definition at line 288 of file tracks_cleaner.cpp.

289 {
290  std::set<BOARD_ITEM *> toRemove;
291 
292  for( TRACK* segment : aTracks )
293  {
294  if( segment->IsNull() && segment->Type() == PCB_TRACE_T && !segment->IsLocked() )
295  {
297  item->SetItems( segment );
298  m_itemsList->push_back( item );
299 
300  toRemove.insert( segment );
301  }
302  }
303 
304  if( !m_dryRun )
305  removeItems( toRemove );
306 }
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
void removeItems(std::set< BOARD_ITEM * > &aItems)

References CLEANUP_ZERO_LENGTH_TRACK, m_dryRun, m_itemsList, PCB_TRACE_T, removeItems(), and RC_ITEM::SetItems().

Referenced by CleanupBoard(), and cleanupSegments().

◆ deleteTracksInPads()

void TRACKS_CLEANER::deleteTracksInPads ( )
private

Definition at line 309 of file tracks_cleaner.cpp.

310 {
311  std::set<BOARD_ITEM*> toRemove;
312 
313  // Delete tracks that start and end on the same pad
314  std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_brd->GetConnectivity();
315 
316  for( TRACK* track : m_brd->Tracks() )
317  {
318  // Mark track if connected to pads
319  for( D_PAD* pad : connectivity->GetConnectedPads( track ) )
320  {
321  if( pad->HitTest( track->GetStart() ) && pad->HitTest( track->GetEnd() ) )
322  {
324  item->SetItems( track );
325  m_itemsList->push_back( item );
326 
327  toRemove.insert( track );
328  }
329  }
330  }
331 
332  if( !m_dryRun )
333  removeItems( toRemove );
334 }
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void removeItems(std::set< BOARD_ITEM * > &aItems)
TRACKS & Tracks()
Definition: class_board.h:257

References CLEANUP_TRACK_IN_PAD, BOARD::GetConnectivity(), m_brd, m_dryRun, m_itemsList, removeItems(), RC_ITEM::SetItems(), and BOARD::Tracks().

Referenced by CleanupBoard().

◆ mergeCollinearSegments()

void TRACKS_CLEANER::mergeCollinearSegments ( TRACK aSeg1,
TRACK aSeg2 
)
private

helper function merge aTrackRef and aCandidate, when possible, i.e.

when they are colinear, same width, and obviously same layer

Returns
true if the segments are merged, false if not
Parameters
aSeg1is the reference
aSeg2is the candidate, and after merging, the removed segment

Definition at line 421 of file tracks_cleaner.cpp.

422 {
423  if( aSeg1->IsLocked() || aSeg2->IsLocked() )
424  return;
425 
426  auto connectivity = m_brd->GetConnectivity();
427 
428  // Verify the removed point after merging is not a node.
429  // If it is a node (i.e. if more than one other item is connected, the segments cannot be merged
430  TRACK dummy_seg( *aSeg1 );
431 
432  // Calculate the new ends of the segment to merge, and store them to dummy_seg:
433  int min_x = std::min( aSeg1->GetStart().x,
434  std::min( aSeg1->GetEnd().x, std::min( aSeg2->GetStart().x, aSeg2->GetEnd().x ) ) );
435  int min_y = std::min( aSeg1->GetStart().y,
436  std::min( aSeg1->GetEnd().y, std::min( aSeg2->GetStart().y, aSeg2->GetEnd().y ) ) );
437  int max_x = std::max( aSeg1->GetStart().x,
438  std::max( aSeg1->GetEnd().x, std::max( aSeg2->GetStart().x, aSeg2->GetEnd().x ) ) );
439  int max_y = std::max( aSeg1->GetStart().y,
440  std::max( aSeg1->GetEnd().y, std::max( aSeg2->GetStart().y, aSeg2->GetEnd().y ) ) );
441 
442  if( ( aSeg1->GetStart().x > aSeg1->GetEnd().x )
443  == ( aSeg1->GetStart().y > aSeg1->GetEnd().y ) )
444  {
445  dummy_seg.SetStart( wxPoint( min_x, min_y ) );
446  dummy_seg.SetEnd( wxPoint( max_x, max_y ) );
447  }
448  else
449  {
450  dummy_seg.SetStart( wxPoint( min_x, max_y ) );
451  dummy_seg.SetEnd( wxPoint( max_x, min_y ) );
452  }
453 
454  // Now find the removed end(s) and stop merging if it is a node:
455  if( aSeg1->GetStart() != dummy_seg.GetStart() && aSeg1->GetStart() != dummy_seg.GetEnd() )
456  {
457  if( testTrackEndpointIsNode( aSeg1, true ) )
458  return;
459  }
460 
461  if( aSeg1->GetEnd() != dummy_seg.GetStart() && aSeg1->GetEnd() != dummy_seg.GetEnd() )
462  {
463  if( testTrackEndpointIsNode( aSeg1, false ) )
464  return;
465  }
466 
468  item->SetItems( aSeg1, aSeg2 );
469  m_itemsList->push_back( item );
470 
471  aSeg2->SetFlags( IS_DELETED );
472 
473  if( !m_dryRun )
474  {
475  m_commit.Modify( aSeg1 );
476  *aSeg1 = dummy_seg;
477 
478  connectivity->Update( aSeg1 );
479 
480  // Clear the status flags here after update.
481  for( auto pad : connectivity->GetConnectedPads( aSeg1 ) )
482  {
483  aSeg1->SetState( BEGIN_ONPAD, pad->HitTest( aSeg1->GetStart() ) );
484  aSeg1->SetState( END_ONPAD, pad->HitTest( aSeg1->GetEnd() ) );
485  }
486 
487  // Merge succesful, seg2 has to go away
488  m_brd->Remove( aSeg2 );
489  m_commit.Removed( aSeg2 );
490  }
491 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:138
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:136
const wxPoint & GetStart() const
Definition: class_track.h:118
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:135
BOARD_COMMIT & m_commit
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Definition: commit.h:96
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
#define IS_DELETED
Definition: base_struct.h:120
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void SetState(int type, int state)
Definition: base_struct.h:221
const wxPoint & GetEnd() const
Definition: class_track.h:115
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
bool testTrackEndpointIsNode(TRACK *aTrack, bool aTstStart)

References BEGIN_ONPAD, CLEANUP_MERGE_TRACKS, END_ONPAD, BOARD::GetConnectivity(), TRACK::GetEnd(), TRACK::GetStart(), IS_DELETED, TRACK::IsLocked(), m_brd, m_commit, m_dryRun, m_itemsList, COMMIT::Modify(), BOARD::Remove(), COMMIT::Removed(), TRACK::SetEnd(), EDA_ITEM::SetFlags(), RC_ITEM::SetItems(), TRACK::SetStart(), EDA_ITEM::SetState(), testTrackEndpointIsNode(), wxPoint::x, and wxPoint::y.

Referenced by cleanupSegments().

◆ removeBadTrackSegments()

void TRACKS_CLEANER::removeBadTrackSegments ( )
private

Definition at line 99 of file tracks_cleaner.cpp.

100 {
101  std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_brd->GetConnectivity();
102 
103  std::set<BOARD_ITEM *> toRemove;
104 
105  for( TRACK* segment : m_brd->Tracks() )
106  {
107  for( D_PAD* testedPad : connectivity->GetConnectedPads( segment ) )
108  {
109  if( segment->GetNetCode() != testedPad->GetNetCode() )
110  {
111  CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_SHORT );
112  item->SetItems( segment );
113  m_itemsList->push_back( item );
114 
115  toRemove.insert( segment );
116  }
117  }
118 
119  for( TRACK* testedTrack : connectivity->GetConnectedTracks( segment ) )
120  {
121  if( segment->GetNetCode() != testedTrack->GetNetCode() )
122  {
123  CLEANUP_ITEM* item = new CLEANUP_ITEM( CLEANUP_SHORT );
124  item->SetItems( segment );
125  m_itemsList->push_back( item );
126 
127  toRemove.insert( segment );
128  }
129  }
130  }
131 
132  if( !m_dryRun )
133  removeItems( toRemove );
134 }
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:119
std::vector< CLEANUP_ITEM * > * m_itemsList
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
void removeItems(std::set< BOARD_ITEM * > &aItems)
TRACKS & Tracks()
Definition: class_board.h:257

References CLEANUP_SHORT, BOARD::GetConnectivity(), m_brd, m_dryRun, m_itemsList, removeItems(), RC_ITEM::SetItems(), and BOARD::Tracks().

Referenced by CleanupBoard().

◆ removeItems()

void TRACKS_CLEANER::removeItems ( std::set< BOARD_ITEM * > &  aItems)
private

Definition at line 494 of file tracks_cleaner.cpp.

495 {
496  for( auto item : aItems )
497  {
498  m_brd->Remove( item );
499  m_commit.Removed( item );
500  }
501 }
BOARD_COMMIT & m_commit
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Definition: commit.h:96
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.

References m_brd, m_commit, BOARD::Remove(), and COMMIT::Removed().

Referenced by cleanupSegments(), cleanupVias(), deleteNullSegments(), deleteTracksInPads(), and removeBadTrackSegments().

◆ testTrackEndpointIsNode()

bool TRACKS_CLEANER::testTrackEndpointIsNode ( TRACK aTrack,
bool  aTstStart 
)
private
Returns
true if a track end position is a node, i.e. a end connected to more than one item.
Parameters
aTrackis the track to test.
aTstStart= true ot test the start point of the track or false for end point

Definition at line 204 of file tracks_cleaner.cpp.

205 {
206  // A node is a point where more than 2 items are connected.
207 
208  auto connectivity = m_brd->GetConnectivity();
209  auto items = connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems();
210 
211  if( items.empty() )
212  return false;
213 
214  auto citem = items.front();
215 
216  if( !citem->Valid() )
217  return false;
218 
219  auto anchors = citem->Anchors();
220 
221  VECTOR2I refpoint = aTstStart ? aTrack->GetStart() : aTrack->GetEnd();
222 
223  for( const auto& anchor : anchors )
224  {
225  if( anchor->Pos() != refpoint )
226  continue;
227 
228  // The right anchor point is found: if more than one other item
229  // (pad, via, track...) is connected, it is a node:
230  return anchor->ConnectedItemsCount() > 1;
231  }
232 
233  return false;
234 }
const wxPoint & GetStart() const
Definition: class_track.h:118
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:355
const wxPoint & GetEnd() const
Definition: class_track.h:115

References BOARD::GetConnectivity(), TRACK::GetEnd(), TRACK::GetStart(), and m_brd.

Referenced by mergeCollinearSegments().

Member Data Documentation

◆ m_brd

◆ m_commit

BOARD_COMMIT& TRACKS_CLEANER::m_commit
private

Definition at line 97 of file tracks_cleaner.h.

Referenced by deleteDanglingTracks(), mergeCollinearSegments(), and removeItems().

◆ m_dryRun

◆ m_itemsList


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