KiCad PCB EDA Suite
TRACKS_CLEANER Class Reference

Public Member Functions

 TRACKS_CLEANER (BOARD *aPcb, BOARD_COMMIT &aCommit)
 
bool CleanupBoard (bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected)
 the cleanup function. More...
 

Private Member Functions

bool removeBadTrackSegments ()
 
bool cleanupVias ()
 Removes redundant vias like vias at same location or on pad through. More...
 
void removeDuplicatesOfVia (const VIA *aVia, std::set< BOARD_ITEM * > &aToRemove)
 Removes all the following THT vias on the same position of the specified one. More...
 
void removeDuplicatesOfTrack (const TRACK *aTrack, std::set< BOARD_ITEM * > &aToRemove)
 Removes all the following duplicates tracks of the specified one. More...
 
bool deleteDanglingTracks ()
 Removes dangling tracks. More...
 
bool deleteNullSegments ()
 Delete null length track segments. More...
 
bool MergeCollinearTracks (TRACK *aSegment)
 Try to merge the segment to a following collinear one. More...
 
bool cleanupSegments ()
 Merge collinear segments and remove duplicated and null len segments. More...
 
void buildTrackConnectionInfo ()
 helper function Rebuild list of tracks, and connected tracks this info must be rebuilt when tracks are erased More...
 
TRACKmergeCollinearSegmentIfPossible (TRACK *aTrackRef, TRACK *aCandidate, ENDPOINT_T aEndType)
 helper function merge aTrackRef and aCandidate, when possible, i.e. More...
 
const ZONE_CONTAINERzoneForTrackEndpoint (const TRACK *aTrack, ENDPOINT_T aEndPoint)
 
bool testTrackEndpointDangling (TRACK *aTrack, ENDPOINT_T aEndPoint)
 Utility: does the endpoint unconnected processed for one endpoint of one track Returns true if the track must be deleted, false if not necessarily. More...
 
bool removeItems (std::set< BOARD_ITEM * > &aItems)
 

Private Attributes

BOARDm_brd
 
BOARD_COMMITm_commit
 

Detailed Description

Definition at line 44 of file clean.cpp.

Constructor & Destructor Documentation

TRACKS_CLEANER::TRACKS_CLEANER ( BOARD aPcb,
BOARD_COMMIT aCommit 
)

Definition at line 252 of file clean.cpp.

253  : m_brd( aPcb ), m_commit( aCommit )
254 {
255 
256 }
BOARD * m_brd
Definition: clean.cpp:120
BOARD_COMMIT & m_commit
Definition: clean.cpp:121

Member Function Documentation

void TRACKS_CLEANER::buildTrackConnectionInfo ( )
private

helper function Rebuild list of tracks, and connected tracks this info must be rebuilt when tracks are erased

Definition at line 170 of file clean.cpp.

References BUSY, END_ON_PAD, BOARD::GetConnectivity(), m_brd, START_ON_PAD, and BOARD::Tracks().

Referenced by CleanupBoard(), and cleanupSegments().

171 {
172  auto connectivity = m_brd->GetConnectivity();
173 
174  connectivity->Build(m_brd);
175 
176  // clear flags and variables used in cleanup
177  for( auto track : m_brd->Tracks() )
178  {
179  track->SetState( START_ON_PAD | END_ON_PAD | BUSY, false );
180  }
181 
182  for( auto track : m_brd->Tracks() )
183  {
184  // Mark track if connected to pads
185  for( auto pad : connectivity->GetConnectedPads( track ) )
186  {
187  if( pad->HitTest( track->GetStart() ) )
188  {
189  track->SetState( START_ON_PAD, true );
190  }
191 
192  if( pad->HitTest( track->GetEnd() ) )
193  {
194  track->SetState( END_ON_PAD, true );
195  }
196  }
197  }
198 }
BOARD * m_brd
Definition: clean.cpp:120
#define END_ON_PAD
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:134
#define START_ON_PAD
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
bool TRACKS_CLEANER::CleanupBoard ( bool  aCleanVias,
bool  aRemoveMisConnected,
bool  aMergeSegments,
bool  aDeleteUnconnected 
)

the cleanup function.

return true if some item was modified

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

Definition at line 207 of file clean.cpp.

References buildTrackConnectionInfo(), cleanupSegments(), cleanupVias(), deleteDanglingTracks(), deleteNullSegments(), and removeBadTrackSegments().

Referenced by PCB_EDIT_FRAME::Clean_Pcb(), and PCB_EDIT_FRAME::RemoveMisConnectedTracks().

211 {
212 
213  bool modified = false;
214 
215  // delete redundant vias
216  if( aCleanVias )
217  modified |= cleanupVias();
218 
219  // Remove null segments and intermediate points on aligned segments
220  // If not asked, remove null segments only if remove misconnected is asked
221  if( aMergeSegments )
222  modified |= cleanupSegments();
223  else if( aRemoveMisConnected )
224  modified |= deleteNullSegments();
225 
227 
228  if( aRemoveMisConnected )
229  modified |= removeBadTrackSegments();
230 
231  // Delete dangling tracks
232  if( aDeleteUnconnected )
233  {
235 
236  if( deleteDanglingTracks() )
237  {
238  modified = true;
239 
240  // Removed tracks can leave aligned segments
241  // (when a T was formed by tracks and the "vertical" segment
242  // is removed)
243  if( aMergeSegments )
244  cleanupSegments();
245  }
246  }
247 
248  return modified;
249 }
bool deleteDanglingTracks()
Removes dangling tracks.
Definition: clean.cpp:382
bool removeBadTrackSegments()
Definition: clean.cpp:259
bool cleanupSegments()
Merge collinear segments and remove duplicated and null len segments.
Definition: clean.cpp:528
bool deleteNullSegments()
Delete null length track segments.
Definition: clean.cpp:432
void buildTrackConnectionInfo()
helper function Rebuild list of tracks, and connected tracks this info must be rebuilt when tracks ar...
Definition: clean.cpp:170
bool cleanupVias()
Removes redundant vias like vias at same location or on pad through.
Definition: clean.cpp:301
bool TRACKS_CLEANER::cleanupSegments ( )
private

Merge collinear segments and remove duplicated and null len segments.

Definition at line 528 of file clean.cpp.

References buildTrackConnectionInfo(), deleteNullSegments(), m_brd, BOARD::m_Track, MergeCollinearTracks(), TRACK::Next(), PCB_TRACE_T, removeDuplicatesOfTrack(), removeItems(), and BOARD::Tracks().

Referenced by CleanupBoard().

529 {
530  bool modified = false;
531 
532  // Easy things first
533  modified |= deleteNullSegments();
534 
536 
537  std::set<BOARD_ITEM*> toRemove;
538 
539  // Delete redundant segments, i.e. segments having the same end points and layers
540  // (can happens when blocks are copied on themselve)
541  for( auto segment : m_brd->Tracks() )
542  removeDuplicatesOfTrack( segment, toRemove );
543 
544  modified |= removeItems( toRemove );
545  modified = true;
546 
547  if( modified )
549 
550  // merge collinear segments:
551  TRACK* nextsegment;
552 
553  for( TRACK* segment = m_brd->m_Track; segment; segment = nextsegment )
554  {
555  nextsegment = segment->Next();
556 
557  if( segment->Type() == PCB_TRACE_T )
558  {
559  bool merged_this = MergeCollinearTracks( segment );
560 
561  if( merged_this ) // The current segment was modified, retry to merge it again
562  {
563  nextsegment = segment->Next();
564  modified = true;
565  }
566  }
567  }
568 
569  return modified;
570 }
BOARD * m_brd
Definition: clean.cpp:120
bool MergeCollinearTracks(TRACK *aSegment)
Try to merge the segment to a following collinear one.
Definition: clean.cpp:474
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
void removeDuplicatesOfTrack(const TRACK *aTrack, std::set< BOARD_ITEM * > &aToRemove)
Removes all the following duplicates tracks of the specified one.
Definition: clean.cpp:445
TRACK * Next() const
Definition: class_track.h:98
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
DLIST< TRACK > m_Track
Definition: class_board.h:246
bool deleteNullSegments()
Delete null length track segments.
Definition: clean.cpp:432
void buildTrackConnectionInfo()
helper function Rebuild list of tracks, and connected tracks this info must be rebuilt when tracks ar...
Definition: clean.cpp:170
bool removeItems(std::set< BOARD_ITEM * > &aItems)
Definition: clean.cpp:123
bool TRACKS_CLEANER::cleanupVias ( )
private

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

Definition at line 301 of file clean.cpp.

References LSET::AllCuMask(), BOARD::GetConnectivity(), GetFirstVia(), m_brd, BOARD::m_Track, removeDuplicatesOfVia(), removeItems(), TRACK_LOCKED, and VIA_THROUGH.

Referenced by CleanupBoard().

302 {
303  std::set<BOARD_ITEM*> toRemove;
304 
305  for( VIA* via = GetFirstVia( m_brd->m_Track ); via != NULL;
306  via = GetFirstVia( via->Next() ) )
307  {
308  if( via->GetFlags() & TRACK_LOCKED )
309  continue;
310 
311  // Correct via m_End defects (if any), should never happen
312  if( via->GetStart() != via->GetEnd() )
313  {
314  wxFAIL_MSG( "Malformed via with mismatching ends" );
315  via->SetEnd( via->GetStart() );
316  }
317 
318  /* Important: these cleanups only do thru hole vias, they don't
319  * (yet) handle high density interconnects */
320  if( via->GetViaType() == VIA_THROUGH )
321  {
322  removeDuplicatesOfVia( via, toRemove );
323 
324  /* To delete through Via on THT pads at same location
325  * Examine the list of connected pads:
326  * if one through pad is found, the via can be removed */
327 
328  const auto pads = m_brd->GetConnectivity()->GetConnectedPads( via );
329  for( const auto pad : pads )
330  {
331  const LSET all_cu = LSET::AllCuMask();
332 
333  if( ( pad->GetLayerSet() & all_cu ) == all_cu )
334  {
335  // redundant: delete the via
336  toRemove.insert( via );
337  break;
338  }
339  }
340  }
341  }
342 
343  return removeItems( toRemove );
344 }
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:639
BOARD * m_brd
Definition: clean.cpp:120
Class LSET is a set of PCB_LAYER_IDs.
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: base_struct.h:128
DLIST< TRACK > m_Track
Definition: class_board.h:246
void removeDuplicatesOfVia(const VIA *aVia, std::set< BOARD_ITEM * > &aToRemove)
Removes all the following THT vias on the same position of the specified one.
Definition: clean.cpp:286
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
bool removeItems(std::set< BOARD_ITEM * > &aItems)
Definition: clean.cpp:123
VIA * GetFirstVia(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first VIA o NULL if not found (or NULL passed)
Definition: class_track.h:490
bool TRACKS_CLEANER::deleteDanglingTracks ( )
private

Removes dangling tracks.

Definition at line 382 of file clean.cpp.

References END_ON_PAD, ENDPOINT_END, ENDPOINT_START, m_brd, m_commit, BOARD::m_Track, TRACK::Next(), BOARD::Remove(), COMMIT::Removed(), START_ON_PAD, and testTrackEndpointDangling().

Referenced by CleanupBoard().

383 {
384  bool item_erased = false;
385  bool modified = false;
386 
387  do // Iterate when at least one track is deleted
388  {
389  item_erased = false;
390 
391  TRACK* next_track;
392 
393  for( TRACK *track = m_brd->m_Track; track != NULL; track = next_track )
394  {
395  next_track = track->Next();
396  bool flag_erase = false; // Start without a good reason to erase it
397 
398  /* if a track endpoint is not connected to a pad, test if
399  * the endpoint is connected to another track or to a zone.
400  * For via test, an enhancement could be to test if
401  * connected to 2 items on different layers. Currently
402  * a via must be connected to 2 items, that can be on the
403  * same layer */
404 
405  // Check if there is nothing attached on the start
406  if( !( track->GetState( START_ON_PAD ) ) )
407  flag_erase |= testTrackEndpointDangling( track, ENDPOINT_START );
408 
409  // If not sure about removal, then check if there is nothing attached on the end
410  if( !flag_erase && !track->GetState( END_ON_PAD ) )
411  flag_erase |= testTrackEndpointDangling( track, ENDPOINT_END );
412 
413  if( flag_erase )
414  {
415  m_brd->Remove( track );
416  m_commit.Removed( track );
417 
418  /* keep iterating, because a track connected to the deleted track
419  * now perhaps is not connected and should be deleted */
420  item_erased = true;
421  modified = true;
422  }
423  }
424  } while( item_erased );
425 
426 
427  return modified;
428 }
BOARD * m_brd
Definition: clean.cpp:120
#define END_ON_PAD
bool testTrackEndpointDangling(TRACK *aTrack, ENDPOINT_T aEndPoint)
Utility: does the endpoint unconnected processed for one endpoint of one track Returns true if the tr...
Definition: clean.cpp:349
#define START_ON_PAD
BOARD_COMMIT & m_commit
Definition: clean.cpp:121
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Definition: commit.h:96
TRACK * Next() const
Definition: class_track.h:98
DLIST< TRACK > m_Track
Definition: class_board.h:246
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
bool TRACKS_CLEANER::deleteNullSegments ( )
private

Delete null length track segments.

Definition at line 432 of file clean.cpp.

References m_brd, removeItems(), and BOARD::Tracks().

Referenced by CleanupBoard(), and cleanupSegments().

433 {
434  std::set<BOARD_ITEM *> toRemove;
435 
436  for( auto segment : m_brd->Tracks() )
437  {
438  if( segment->IsNull() ) // Length segment = 0; delete it
439  toRemove.insert( segment );
440  }
441 
442  return removeItems( toRemove );
443 }
BOARD * m_brd
Definition: clean.cpp:120
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
bool removeItems(std::set< BOARD_ITEM * > &aItems)
Definition: clean.cpp:123
TRACK * TRACKS_CLEANER::mergeCollinearSegmentIfPossible ( TRACK aTrackRef,
TRACK aCandidate,
ENDPOINT_T  aEndType 
)
private

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

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

Definition at line 631 of file clean.cpp.

References END_ON_PAD, ENDPOINT_START, BOARD::GetConnectivity(), TRACK::GetEnd(), TRACK::GetStart(), EDA_ITEM::GetState(), TRACK::GetWidth(), m_brd, m_commit, COMMIT::Modify(), parallelismTest(), PCB_TRACE_T, TRACK::SetEnd(), TRACK::SetStart(), EDA_ITEM::SetState(), START_ON_PAD, EDA_ITEM::Type(), updateConn(), wxPoint::x, and wxPoint::y.

Referenced by MergeCollinearTracks().

633 {
634  // First of all, they must be of the same width and must be both actual tracks
635  if( ( aTrackRef->GetWidth() != aCandidate->GetWidth() ) ||
636  ( aTrackRef->Type() != PCB_TRACE_T ) ||
637  ( aCandidate->Type() != PCB_TRACE_T ) )
638  return NULL;
639 
640  // Trivial case: exactly the same track
641  if( ( aTrackRef->GetStart() == aCandidate->GetStart() ) &&
642  ( aTrackRef->GetEnd() == aCandidate->GetEnd() ) )
643  return aCandidate;
644 
645  if( ( aTrackRef->GetStart() == aCandidate->GetEnd() ) &&
646  ( aTrackRef->GetEnd() == aCandidate->GetStart() ) )
647  return aCandidate;
648 
649  // Weed out non-parallel tracks
650  if( !parallelismTest( aTrackRef->GetEnd().x - aTrackRef->GetStart().x,
651  aTrackRef->GetEnd().y - aTrackRef->GetStart().y,
652  aCandidate->GetEnd().x - aCandidate->GetStart().x,
653  aCandidate->GetEnd().y - aCandidate->GetStart().y ) )
654  return NULL;
655 
656  auto connectivity = m_brd->GetConnectivity();
657 
658  updateConn( aTrackRef, connectivity );
659  updateConn( aCandidate, connectivity );
660 
661  if( aEndType == ENDPOINT_START )
662  {
663  // We do not have a pad, which is a always terminal point for a track
664  if( aTrackRef->GetState( START_ON_PAD ) )
665  return NULL;
666 
667  /* change the common point coordinate of pt_segm to use the other point
668  * of pt_segm (pt_segm will be removed later) */
669  if( aTrackRef->GetStart() == aCandidate->GetStart() )
670  {
671  m_commit.Modify( aTrackRef );
672  aTrackRef->SetStart( aCandidate->GetEnd() );
673  aTrackRef->SetState( START_ON_PAD, aCandidate->GetState( END_ON_PAD ) );
674  connectivity->Update( aTrackRef );
675  return aCandidate;
676  }
677  else
678  {
679  m_commit.Modify( aTrackRef );
680  aTrackRef->SetStart( aCandidate->GetStart() );
681  aTrackRef->SetState( START_ON_PAD, aCandidate->GetState( START_ON_PAD ) );
682  connectivity->Update( aTrackRef );
683  return aCandidate;
684  }
685  }
686  else // aEndType == END
687  {
688  // We do not have a pad, which is a always terminal point for a track
689  if( aTrackRef->GetState( END_ON_PAD ) )
690  return NULL;
691 
692  /* change the common point coordinate of pt_segm to use the other point
693  * of pt_segm (pt_segm will be removed later) */
694  if( aTrackRef->GetEnd() == aCandidate->GetStart() )
695  {
696  m_commit.Modify( aTrackRef );
697  aTrackRef->SetEnd( aCandidate->GetEnd() );
698  aTrackRef->SetState( END_ON_PAD, aCandidate->GetState( END_ON_PAD ) );
699  connectivity->Update( aTrackRef );
700 
701  return aCandidate;
702  }
703  else
704  {
705  m_commit.Modify( aTrackRef );
706  aTrackRef->SetEnd( aCandidate->GetStart() );
707  aTrackRef->SetState( END_ON_PAD, aCandidate->GetState( START_ON_PAD ) );
708  connectivity->Update( aTrackRef );
709  return aCandidate;
710  }
711  }
712 
713  return NULL;
714 }
BOARD * m_brd
Definition: clean.cpp:120
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
#define END_ON_PAD
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
static void updateConn(TRACK *track, std::shared_ptr< CONNECTIVITY_DATA > connectivity)
Function used by cleanupSegments.
Definition: clean.cpp:614
static bool parallelismTest(int dx1, int dy1, int dx2, int dy2)
Definition: clean.cpp:574
int GetState(int type) const
Definition: base_struct.h:237
#define START_ON_PAD
const wxPoint & GetEnd() const
Definition: class_track.h:118
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
BOARD_COMMIT & m_commit
Definition: clean.cpp:121
const wxPoint & GetStart() const
Definition: class_track.h:121
void SetState(int type, int state)
Definition: base_struct.h:242
int GetWidth() const
Definition: class_track.h:115
void SetStart(const wxPoint &aStart)
Definition: class_track.h:120
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
bool TRACKS_CLEANER::MergeCollinearTracks ( TRACK aSegment)
private

Try to merge the segment to a following collinear one.

Definition at line 474 of file clean.cpp.

References BUSY, ENDPOINT_END, ENDPOINT_START, TRACK::GetTrack(), TRACK::GetWidth(), m_brd, m_commit, BOARD::m_Track, mergeCollinearSegmentIfPossible(), TRACK::Next(), PCB_TRACE_T, BOARD::Remove(), COMMIT::Removed(), EDA_ITEM::SetState(), and EDA_ITEM::Type().

Referenced by cleanupSegments().

475 {
476  bool merged_this = false;
477 
478 
479  for( ENDPOINT_T endpoint = ENDPOINT_START; endpoint <= ENDPOINT_END;
480  endpoint = ENDPOINT_T( endpoint + 1 ) )
481  {
482  // search for a possible segment connected to the current endpoint of the current one
483  TRACK* other = aSegment->Next();
484 
485  if( other )
486  {
487  other = aSegment->GetTrack( other, NULL, endpoint, true, false );
488 
489  if( other )
490  {
491  // the two segments must have the same width and the other
492  // cannot be a via
493  if( ( aSegment->GetWidth() == other->GetWidth() ) &&
494  ( other->Type() == PCB_TRACE_T ) )
495  {
496  // There can be only one segment connected
497  other->SetState( BUSY, true );
498  TRACK* yet_another = aSegment->GetTrack( m_brd->m_Track, NULL,
499  endpoint, true, false );
500  other->SetState( BUSY, false );
501 
502  if( !yet_another )
503  {
504  // Try to merge them
505  TRACK* segDelete = mergeCollinearSegmentIfPossible( aSegment,
506  other, endpoint );
507 
508  // Merge succesful, the other one has to go away
509  if( segDelete )
510  {
511  m_brd->Remove( segDelete );
512  m_commit.Removed( segDelete );
513  merged_this = true;
514  }
515  }
516  }
517  }
518  }
519  }
520 
521 
522 
523  return merged_this;
524 }
BOARD * m_brd
Definition: clean.cpp:120
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
TRACK * GetTrack(TRACK *aStartTrace, TRACK *aEndTrace, ENDPOINT_T aEndPoint, bool aSameNetOnly, bool aSequential)
Function GetTrack returns the trace segment connected to the segment at aEndPoint from aStartTrace to...
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:134
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
BOARD_COMMIT & m_commit
Definition: clean.cpp:121
ENDPOINT_T
Flag used in locate routines (from which endpoint work)
Definition: pcbnew.h:54
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Definition: commit.h:96
TRACK * Next() const
Definition: class_track.h:98
TRACK * mergeCollinearSegmentIfPossible(TRACK *aTrackRef, TRACK *aCandidate, ENDPOINT_T aEndType)
helper function merge aTrackRef and aCandidate, when possible, i.e.
Definition: clean.cpp:631
void SetState(int type, int state)
Definition: base_struct.h:242
int GetWidth() const
Definition: class_track.h:115
DLIST< TRACK > m_Track
Definition: class_board.h:246
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
bool TRACKS_CLEANER::removeBadTrackSegments ( )
private

Definition at line 259 of file clean.cpp.

References FLAG0, BOARD::GetConnectivity(), m_brd, removeItems(), and BOARD::Tracks().

Referenced by CleanupBoard().

260 {
261  auto connectivity = m_brd->GetConnectivity();
262 
263  std::set<BOARD_ITEM *> toRemove;
264 
265  for( auto segment : m_brd->Tracks() )
266  {
267  segment->SetState( FLAG0, false );
268 
269  for( auto testedPad : connectivity->GetConnectedPads( segment ) )
270  {
271  if( segment->GetNetCode() != testedPad->GetNetCode() )
272  toRemove.insert( segment );
273  }
274 
275  for( auto testedTrack : connectivity->GetConnectedTracks( segment ) )
276  {
277  if( segment->GetNetCode() != testedTrack->GetNetCode() && !testedTrack->GetState( FLAG0 ) )
278  toRemove.insert( segment );
279  }
280  }
281 
282  return removeItems( toRemove );
283 }
BOARD * m_brd
Definition: clean.cpp:120
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:131
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
bool removeItems(std::set< BOARD_ITEM * > &aItems)
Definition: clean.cpp:123
void TRACKS_CLEANER::removeDuplicatesOfTrack ( const TRACK aTrack,
std::set< BOARD_ITEM * > &  aToRemove 
)
private

Removes all the following duplicates tracks of the specified one.

Definition at line 445 of file clean.cpp.

References TRACK::GetEnd(), BOARD_ITEM::GetLayer(), BOARD_CONNECTED_ITEM::GetNetCode(), TRACK::GetStart(), m_brd, BOARD::Tracks(), and EDA_ITEM::Type().

Referenced by cleanupSegments().

446 {
447 
448  for( auto other : m_brd->Tracks() )
449  {
450  // New netcode, break out (can't be there any other)
451  if( aTrack->GetNetCode() != other->GetNetCode() )
452  continue;
453 
454  if( aTrack == other )
455  continue;
456 
457  // Must be of the same type, on the same layer and the endpoints
458  // must be the same (maybe swapped)
459  if( ( aTrack->Type() == other->Type() ) &&
460  ( aTrack->GetLayer() == other->GetLayer() ) )
461  {
462  if( ( ( aTrack->GetStart() == other->GetStart() ) &&
463  ( aTrack->GetEnd() == other->GetEnd() ) ) ||
464  ( ( aTrack->GetStart() == other->GetEnd() ) &&
465  ( aTrack->GetEnd() == other->GetStart() ) ) )
466  {
467  aToRemove.insert( other );
468  }
469  }
470  }
471 }
BOARD * m_brd
Definition: clean.cpp:120
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
const wxPoint & GetEnd() const
Definition: class_track.h:118
const wxPoint & GetStart() const
Definition: class_track.h:121
int GetNetCode() const
Function GetNetCode.
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
void TRACKS_CLEANER::removeDuplicatesOfVia ( const VIA aVia,
std::set< BOARD_ITEM * > &  aToRemove 
)
private

Removes all the following THT vias on the same position of the specified one.

Definition at line 286 of file clean.cpp.

References GetFirstVia(), TRACK::GetStart(), TRACK::Next(), and VIA_THROUGH.

Referenced by cleanupVias().

287 {
288  VIA* next_via;
289 
290  for( VIA* alt_via = GetFirstVia( aVia->Next() ); alt_via != NULL; alt_via = next_via )
291  {
292  next_via = GetFirstVia( alt_via->Next() );
293 
294  if( ( alt_via->GetViaType() == VIA_THROUGH ) &&
295  ( alt_via->GetStart() == aVia->GetStart() ) )
296  aToRemove.insert ( alt_via );
297  }
298 }
const wxPoint & GetStart() const
Definition: class_track.h:121
TRACK * Next() const
Definition: class_track.h:98
VIA * GetFirstVia(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first VIA o NULL if not found (or NULL passed)
Definition: class_track.h:490
bool TRACKS_CLEANER::removeItems ( std::set< BOARD_ITEM * > &  aItems)
inlineprivate

Definition at line 123 of file clean.cpp.

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

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

124  {
125  bool isModified = false;
126 
127 
128  for( auto item : aItems )
129  {
130  isModified = true;
131  m_brd->Remove( item );
132  m_commit.Removed( item );
133  }
134 
135  return isModified;
136  }
BOARD * m_brd
Definition: clean.cpp:120
BOARD_COMMIT & m_commit
Definition: clean.cpp:121
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.
bool TRACKS_CLEANER::testTrackEndpointDangling ( TRACK aTrack,
ENDPOINT_T  aEndPoint 
)
private

Utility: does the endpoint unconnected processed for one endpoint of one track Returns true if the track must be deleted, false if not necessarily.

Definition at line 349 of file clean.cpp.

References BOARD::GetConnectivity(), TRACK::GetEndPoint(), TRACK::GetStart(), m_brd, PCB_TRACE_T, and EDA_ITEM::Type().

Referenced by deleteDanglingTracks().

350 {
351  auto connectivity = m_brd->GetConnectivity();
352  VECTOR2I endpoint ;
353 
354  if( aTrack->Type() == PCB_TRACE_T )
355  endpoint = aTrack->GetEndPoint( aEndPoint );
356  else
357  endpoint = aTrack->GetStart( );
358 
359  //wxASSERT ( connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ) != nullptr );
360  wxASSERT ( connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems().size() != 0 );
361  auto citem = connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems().front();
362 
363  if( !citem->Valid() )
364  return false;
365 
366  auto anchors = citem->Anchors();
367 
368  for( auto anchor : anchors )
369  {
370  if( anchor->Pos() == endpoint && anchor->IsDangling() )
371  return true;
372  }
373 
374  return false;
375 }
BOARD * m_brd
Definition: clean.cpp:120
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
const wxPoint & GetStart() const
Definition: class_track.h:121
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition: class_track.h:125
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
const ZONE_CONTAINER* TRACKS_CLEANER::zoneForTrackEndpoint ( const TRACK aTrack,
ENDPOINT_T  aEndPoint 
)
private

Member Data Documentation

BOARD_COMMIT& TRACKS_CLEANER::m_commit
private

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