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 47 of file tracks_cleaner.cpp.

Constructor & Destructor Documentation

TRACKS_CLEANER::TRACKS_CLEANER ( BOARD aPcb,
BOARD_COMMIT aCommit 
)

Definition at line 258 of file tracks_cleaner.cpp.

259  : m_brd( aPcb ), m_commit( aCommit )
260 {
261 }
BOARD_COMMIT & m_commit

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 176 of file tracks_cleaner.cpp.

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

Referenced by CleanupBoard(), and cleanupSegments().

177 {
178  auto connectivity = m_brd->GetConnectivity();
179 
180  connectivity->Build(m_brd);
181 
182  // clear flags and variables used in cleanup
183  for( auto track : m_brd->Tracks() )
184  {
185  track->SetState( START_ON_PAD | END_ON_PAD | BUSY, false );
186  }
187 
188  for( auto track : m_brd->Tracks() )
189  {
190  // Mark track if connected to pads
191  for( auto pad : connectivity->GetConnectedPads( track ) )
192  {
193  if( pad->HitTest( track->GetStart() ) )
194  {
195  track->SetState( START_ON_PAD, true );
196  }
197 
198  if( pad->HitTest( track->GetEnd() ) )
199  {
200  track->SetState( END_ON_PAD, true );
201  }
202  }
203  }
204 }
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:148
#define START_ON_PAD
Definition: netinfo.h:582
#define END_ON_PAD
Definition: netinfo.h:583
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 213 of file tracks_cleaner.cpp.

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

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

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

Merge collinear segments and remove duplicated and null len segments.

Definition at line 539 of file tracks_cleaner.cpp.

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

Referenced by CleanupBoard().

540 {
541  bool modified = false;
542 
543  // Easy things first
544  modified |= deleteNullSegments();
545 
547 
548  std::set<BOARD_ITEM*> toRemove;
549 
550  // Delete redundant segments, i.e. segments having the same end points and layers
551  // (can happens when blocks are copied on themselve)
552  for( auto segment : m_brd->Tracks() )
553  removeDuplicatesOfTrack( segment, toRemove );
554 
555  modified |= removeItems( toRemove );
556  modified = true;
557 
558  if( modified )
560 
561  // merge collinear segments:
562  TRACK* nextsegment;
563 
564  for( TRACK* segment = m_brd->m_Track; segment; segment = nextsegment )
565  {
566  nextsegment = segment->Next();
567 
568  if( segment->Type() == PCB_TRACE_T )
569  {
570  bool merged_this = MergeCollinearTracks( segment );
571 
572  if( merged_this ) // The current segment was modified, retry to merge it again
573  {
574  nextsegment = segment->Next();
575  modified = true;
576  }
577  }
578  }
579 
580  return modified;
581 }
bool MergeCollinearTracks(TRACK *aSegment)
Try to merge the segment to a following collinear one.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
void removeDuplicatesOfTrack(const TRACK *aTrack, std::set< BOARD_ITEM * > &aToRemove)
Removes all the following duplicates tracks of the specified one.
TRACK * Next() const
Definition: class_track.h:99
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.
void buildTrackConnectionInfo()
helper function Rebuild list of tracks, and connected tracks this info must be rebuilt when tracks ar...
bool removeItems(std::set< BOARD_ITEM * > &aItems)
bool TRACKS_CLEANER::cleanupVias ( )
private

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

Definition at line 306 of file tracks_cleaner.cpp.

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

Referenced by CleanupBoard().

307 {
308  std::set<BOARD_ITEM*> toRemove;
309 
310  for( VIA* via = GetFirstVia( m_brd->m_Track ); via != NULL;
311  via = GetFirstVia( via->Next() ) )
312  {
313  if( via->GetFlags() & TRACK_LOCKED )
314  continue;
315 
316  // Correct via m_End defects (if any), should never happen
317  if( via->GetStart() != via->GetEnd() )
318  {
319  wxFAIL_MSG( "Malformed via with mismatching ends" );
320  via->SetEnd( via->GetStart() );
321  }
322 
323  /* Important: these cleanups only do thru hole vias, they don't
324  * (yet) handle high density interconnects */
325  if( via->GetViaType() == VIA_THROUGH )
326  {
327  removeDuplicatesOfVia( via, toRemove );
328 
329  /* To delete through Via on THT pads at same location
330  * Examine the list of connected pads:
331  * if one through pad is found, the via can be removed */
332 
333  const auto pads = m_brd->GetConnectivity()->GetConnectedPads( via );
334  for( const auto pad : pads )
335  {
336  const LSET all_cu = LSET::AllCuMask();
337 
338  if( ( pad->GetLayerSet() & all_cu ) == all_cu )
339  {
340  // redundant: delete the via
341  toRemove.insert( via );
342  break;
343  }
344  }
345  }
346  }
347 
348  return removeItems( toRemove );
349 }
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:673
Class LSET is a set of PCB_LAYER_IDs.
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: base_struct.h:142
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.
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)
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:508
bool TRACKS_CLEANER::deleteDanglingTracks ( )
private

Removes dangling tracks.

Definition at line 387 of file tracks_cleaner.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().

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

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

Referenced by CleanupBoard(), and cleanupSegments().

438 {
439  std::set<BOARD_ITEM *> toRemove;
440 
441  for( auto segment : m_brd->Tracks() )
442  {
443  if( segment->IsNull() ) // Length segment = 0; delete it
444  toRemove.insert( segment );
445  }
446 
447  return removeItems( toRemove );
448 }
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
bool removeItems(std::set< BOARD_ITEM * > &aItems)
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 642 of file tracks_cleaner.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().

644 {
645  // First of all, they must be of the same width and must be both actual tracks
646  if( ( aTrackRef->GetWidth() != aCandidate->GetWidth() ) ||
647  ( aTrackRef->Type() != PCB_TRACE_T ) ||
648  ( aCandidate->Type() != PCB_TRACE_T ) )
649  return NULL;
650 
651  // Trivial case: exactly the same track
652  if( ( aTrackRef->GetStart() == aCandidate->GetStart() ) &&
653  ( aTrackRef->GetEnd() == aCandidate->GetEnd() ) )
654  return aCandidate;
655 
656  if( ( aTrackRef->GetStart() == aCandidate->GetEnd() ) &&
657  ( aTrackRef->GetEnd() == aCandidate->GetStart() ) )
658  return aCandidate;
659 
660  // Weed out non-parallel tracks
661  if( !parallelismTest( aTrackRef->GetEnd().x - aTrackRef->GetStart().x,
662  aTrackRef->GetEnd().y - aTrackRef->GetStart().y,
663  aCandidate->GetEnd().x - aCandidate->GetStart().x,
664  aCandidate->GetEnd().y - aCandidate->GetStart().y ) )
665  return NULL;
666 
667  auto connectivity = m_brd->GetConnectivity();
668 
669  updateConn( aTrackRef, connectivity );
670  updateConn( aCandidate, connectivity );
671 
672  if( aEndType == ENDPOINT_START )
673  {
674  // We do not have a pad, which is a always terminal point for a track
675  if( aTrackRef->GetState( START_ON_PAD ) )
676  return NULL;
677 
678  /* change the common point coordinate of pt_segm to use the other point
679  * of pt_segm (pt_segm will be removed later) */
680  if( aTrackRef->GetStart() == aCandidate->GetStart() )
681  {
682  m_commit.Modify( aTrackRef );
683  aTrackRef->SetStart( aCandidate->GetEnd() );
684  aTrackRef->SetState( START_ON_PAD, aCandidate->GetState( END_ON_PAD ) );
685  connectivity->Update( aTrackRef );
686  return aCandidate;
687  }
688  else
689  {
690  m_commit.Modify( aTrackRef );
691  aTrackRef->SetStart( aCandidate->GetStart() );
692  aTrackRef->SetState( START_ON_PAD, aCandidate->GetState( START_ON_PAD ) );
693  connectivity->Update( aTrackRef );
694  return aCandidate;
695  }
696  }
697  else // aEndType == END
698  {
699  // We do not have a pad, which is a always terminal point for a track
700  if( aTrackRef->GetState( END_ON_PAD ) )
701  return NULL;
702 
703  /* change the common point coordinate of pt_segm to use the other point
704  * of pt_segm (pt_segm will be removed later) */
705  if( aTrackRef->GetEnd() == aCandidate->GetStart() )
706  {
707  m_commit.Modify( aTrackRef );
708  aTrackRef->SetEnd( aCandidate->GetEnd() );
709  aTrackRef->SetState( END_ON_PAD, aCandidate->GetState( END_ON_PAD ) );
710  connectivity->Update( aTrackRef );
711 
712  return aCandidate;
713  }
714  else
715  {
716  m_commit.Modify( aTrackRef );
717  aTrackRef->SetEnd( aCandidate->GetStart() );
718  aTrackRef->SetState( END_ON_PAD, aCandidate->GetState( START_ON_PAD ) );
719  connectivity->Update( aTrackRef );
720  return aCandidate;
721  }
722  }
723 
724  return NULL;
725 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:118
int GetState(int type) const
Definition: base_struct.h:266
const wxPoint & GetEnd() const
Definition: class_track.h:119
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD_COMMIT & m_commit
#define START_ON_PAD
Definition: netinfo.h:582
const wxPoint & GetStart() const
Definition: class_track.h:122
#define END_ON_PAD
Definition: netinfo.h:583
static void updateConn(TRACK *track, const std::shared_ptr< CONNECTIVITY_DATA > &connectivity)
Function used by cleanupSegments.
void SetState(int type, int state)
Definition: base_struct.h:271
int GetWidth() const
Definition: class_track.h:116
static bool parallelismTest(int dx1, int dy1, int dx2, int dy2)
void SetStart(const wxPoint &aStart)
Definition: class_track.h:121
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 485 of file tracks_cleaner.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().

486 {
487  bool merged_this = false;
488 
489 
490  for( ENDPOINT_T endpoint = ENDPOINT_START; endpoint <= ENDPOINT_END;
491  endpoint = ENDPOINT_T( endpoint + 1 ) )
492  {
493  // search for a possible segment connected to the current endpoint of the current one
494  TRACK* other = aSegment->Next();
495 
496  if( other )
497  {
498  other = aSegment->GetTrack( other, NULL, endpoint, true, false );
499 
500  if( other )
501  {
502  // the two segments must have the same width and the other
503  // cannot be a via
504  if( ( aSegment->GetWidth() == other->GetWidth() ) &&
505  ( other->Type() == PCB_TRACE_T ) )
506  {
507  // There can be only one segment connected
508  other->SetState( BUSY, true );
509  TRACK* yet_another = aSegment->GetTrack( m_brd->m_Track, NULL,
510  endpoint, true, false );
511  other->SetState( BUSY, false );
512 
513  if( !yet_another )
514  {
515  // Try to merge them
516  TRACK* segDelete = mergeCollinearSegmentIfPossible( aSegment,
517  other, endpoint );
518 
519  // Merge succesful, the other one has to go away
520  if( segDelete )
521  {
522  m_brd->Remove( segDelete );
523  m_commit.Removed( segDelete );
524  merged_this = true;
525  }
526  }
527  }
528  }
529  }
530  }
531 
532 
533 
534  return merged_this;
535 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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:148
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
BOARD_COMMIT & m_commit
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:99
TRACK * mergeCollinearSegmentIfPossible(TRACK *aTrackRef, TRACK *aCandidate, ENDPOINT_T aEndType)
helper function merge aTrackRef and aCandidate, when possible, i.e.
void SetState(int type, int state)
Definition: base_struct.h:271
int GetWidth() const
Definition: class_track.h:116
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 264 of file tracks_cleaner.cpp.

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

Referenced by CleanupBoard().

265 {
266  auto connectivity = m_brd->GetConnectivity();
267 
268  std::set<BOARD_ITEM *> toRemove;
269 
270  for( auto segment : m_brd->Tracks() )
271  {
272  segment->SetState( FLAG0, false );
273 
274  for( auto testedPad : connectivity->GetConnectedPads( segment ) )
275  {
276  if( segment->GetNetCode() != testedPad->GetNetCode() )
277  toRemove.insert( segment );
278  }
279 
280  for( auto testedTrack : connectivity->GetConnectedTracks( segment ) )
281  {
282  if( segment->GetNetCode() != testedTrack->GetNetCode() && !testedTrack->GetState( FLAG0 ) )
283  toRemove.insert( segment );
284  }
285  }
286 
287  return removeItems( toRemove );
288 }
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:145
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)
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 450 of file tracks_cleaner.cpp.

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

Referenced by cleanupSegments().

451 {
452  if( aTrack->GetFlags() & STRUCT_DELETED )
453  return;
454 
455  for( auto other : m_brd->Tracks() )
456  {
457  // New netcode, break out (can't be there any other)
458  if( aTrack->GetNetCode() != other->GetNetCode() )
459  continue;
460 
461  if( aTrack == other )
462  continue;
463 
464  if( other->GetFlags() & STRUCT_DELETED )
465  continue;
466 
467  // Must be of the same type, on the same layer and the endpoints
468  // must be the same (maybe swapped)
469  if( ( aTrack->Type() == other->Type() ) &&
470  ( aTrack->GetLayer() == other->GetLayer() ) )
471  {
472  if( ( ( aTrack->GetStart() == other->GetStart() ) &&
473  ( aTrack->GetEnd() == other->GetEnd() ) ) ||
474  ( ( aTrack->GetStart() == other->GetEnd() ) &&
475  ( aTrack->GetEnd() == other->GetStart() ) ) )
476  {
477  other->SetFlags( STRUCT_DELETED );
478  aToRemove.insert( other );
479  }
480  }
481  }
482 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:284
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const wxPoint & GetEnd() const
Definition: class_track.h:119
const wxPoint & GetStart() const
Definition: class_track.h:122
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:136
int GetNetCode() const
Function GetNetCode.
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 291 of file tracks_cleaner.cpp.

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

Referenced by cleanupVias().

292 {
293  VIA* next_via;
294 
295  for( VIA* alt_via = GetFirstVia( aVia->Next() ); alt_via != NULL; alt_via = next_via )
296  {
297  next_via = GetFirstVia( alt_via->Next() );
298 
299  if( ( alt_via->GetViaType() == VIA_THROUGH ) &&
300  ( alt_via->GetStart() == aVia->GetStart() ) )
301  aToRemove.insert ( alt_via );
302  }
303 }
const wxPoint & GetStart() const
Definition: class_track.h:122
TRACK * Next() const
Definition: class_track.h:99
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:508
bool TRACKS_CLEANER::removeItems ( std::set< BOARD_ITEM * > &  aItems)
inlineprivate

Definition at line 126 of file tracks_cleaner.cpp.

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

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

127  {
128  bool isModified = false;
129 
130 
131  for( auto item : aItems )
132  {
133  isModified = true;
134  m_brd->Remove( item );
135  m_commit.Removed( item );
136  }
137 
138  return isModified;
139  }
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.
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 354 of file tracks_cleaner.cpp.

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

Referenced by deleteDanglingTracks().

355 {
356  auto connectivity = m_brd->GetConnectivity();
357  VECTOR2I endpoint ;
358 
359  if( aTrack->Type() == PCB_TRACE_T )
360  endpoint = aTrack->GetEndPoint( aEndPoint );
361  else
362  endpoint = aTrack->GetStart( );
363 
364  //wxASSERT ( connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ) != nullptr );
365  wxASSERT ( connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems().size() != 0 );
366  auto citem = connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems().front();
367 
368  if( !citem->Valid() )
369  return false;
370 
371  auto anchors = citem->Anchors();
372 
373  for( const auto& anchor : anchors )
374  {
375  if( anchor->Pos() == endpoint && anchor->IsDangling() )
376  return true;
377  }
378 
379  return false;
380 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
const wxPoint & GetStart() const
Definition: class_track.h:122
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition: class_track.h:126
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: