41 m_itemsList( nullptr ),
54 std::vector<std::shared_ptr<CLEANUP_ITEM> >* aItemsList,
55 bool aRemoveMisConnected,
bool aCleanVias,
bool aMergeSegments,
56 bool aDeleteUnconnected,
bool aDeleteTracksinPad,
57 bool aDeleteDanglingVias,
REPORTER* aReporter )
60 bool has_deleted =
false;
75 bool removeNullSegments = aMergeSegments || aRemoveMisConnected;
76 cleanup( aCleanVias, removeNullSegments, aMergeSegments , aMergeSegments );
88 cleanup(
false,
false,
true, aMergeSegments );
90 if( aRemoveMisConnected )
105 if( aDeleteTracksinPad )
120 if( aDeleteUnconnected || aDeleteDanglingVias )
130 if( aDeleteUnconnected )
133 if( aDeleteDanglingVias )
143 if( has_deleted && aMergeSegments )
155 cleanup(
false,
false,
false,
true );
164 std::set<BOARD_ITEM *> toRemove;
169 if( segment->IsLocked() )
172 for(
PAD* testedPad : connectivity->GetConnectedPads( segment ) )
174 if( segment->GetNetCode() != testedPad->GetNetCode() )
176 std::shared_ptr<CLEANUP_ITEM> item;
183 item->SetItems( segment );
186 toRemove.insert( segment );
190 for(
PCB_TRACK* testedTrack : connectivity->GetConnectedTracks( segment ) )
192 if( segment->GetNetCode() != testedTrack->GetNetCode() )
194 std::shared_ptr<CLEANUP_ITEM> item;
201 item->SetItems( segment );
204 toRemove.insert( segment );
218 const std::list<CN_ITEM*>& items =
224 CN_ITEM* citem = items.front();
226 if( !citem->
Valid() )
229 const std::vector<std::shared_ptr<CN_ANCHOR>>& anchors = citem->
Anchors();
233 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : anchors )
235 if(
anchor->Pos() != refpoint )
240 return anchor->ConnectedItemsCount() > 1;
249 bool item_erased =
false;
250 bool modified =
false;
252 if( !aTrack && !aVia )
262 std::deque<PCB_TRACK*> temp_tracks(
m_brd->
Tracks() );
266 if( track->IsLocked() || ( track->GetFlags() &
IS_DELETED ) > 0 )
269 if( !aVia && track->Type() ==
PCB_VIA_T )
278 std::shared_ptr<CLEANUP_ITEM> item;
285 item->SetItems( track );
301 }
while( item_erased );
309 std::set<BOARD_ITEM*> toRemove;
316 if( track->IsLocked() )
323 for(
PAD*
pad : connectivity->GetConnectedPads( track ) )
325 if(
pad->HitTest( track->GetStart() ) &&
pad->HitTest( track->GetEnd() ) )
328 track->TransformShapeToPolygon( poly, track->GetLayer(), 0,
ARC_HIGH_DEF,
336 item->SetItems( track );
339 toRemove.insert( track );
355 bool aDeleteDuplicateSegments,
bool aMergeSegments )
362 rtree.
Insert( track, track->GetLayer() );
365 std::set<BOARD_ITEM*> toRemove;
369 if( track->HasFlag(
IS_DELETED ) || track->IsLocked() )
372 if( aDeleteDuplicateVias && track->Type() ==
PCB_VIA_T )
376 if(
via->GetStart() !=
via->GetEnd() )
377 via->SetEnd(
via->GetStart() );
397 item->SetItems(
via );
401 toRemove.insert(
via );
413 if( (
pad->GetLayerSet() & all_cu ) == all_cu )
416 item->SetItems(
via,
pad );
420 toRemove.insert(
via );
428 if( aDeleteNullSegments && track->Type() !=
PCB_VIA_T )
430 if( track->IsNull() )
433 item->SetItems( track );
437 toRemove.insert( track );
441 if( aDeleteDuplicateSegments && track->Type() ==
PCB_TRACE_T && !track->IsNull() )
443 rtree.
QueryColliding( track, track->GetLayer(), track->GetLayer(),
447 return aItem->Type() == PCB_TRACE_T
448 && !aItem->HasFlag( SKIP_STRUCT )
449 && !aItem->HasFlag( IS_DELETED )
450 && !static_cast<PCB_TRACK*>( aItem )->IsNull();
455 PCB_TRACK* other = static_cast<PCB_TRACK*>( aItem );
457 if( track->IsPointOnEnds( other->GetStart() )
458 && track->IsPointOnEnds( other->GetEnd() )
459 && track->GetWidth() == other->GetWidth()
460 && track->GetLayer() == other->GetLayer() )
462 auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DUPLICATE_TRACK );
463 item->SetItems( track );
464 m_itemsList->push_back( item );
466 track->SetFlags( IS_DELETED );
467 toRemove.insert( track );
478 removeItems( toRemove );
481 [&]( std::shared_ptr<CN_CONNECTIVITY_ALGO> connectivity ) ->
bool
483 for(
PCB_TRACK* segment : m_brd->Tracks() )
493 for(
CN_ITEM* citem : connectivity->ItemEntry( segment ).GetItems() )
497 std::vector<PCB_TRACK*> sameWidthCandidates;
498 std::vector<PCB_TRACK*> differentWidthCandidates;
502 if( !connected->Valid() )
512 if( candidateSegment->
GetWidth() == segment->GetWidth() )
514 sameWidthCandidates.push_back( candidateSegment );
518 differentWidthCandidates.push_back( candidateSegment );
524 if( !differentWidthCandidates.empty() )
527 for(
PCB_TRACK* candidate : sameWidthCandidates )
529 if( segment->ApproxCollinear( *candidate )
530 && mergeCollinearSegments( segment, candidate ) )
545 while( !m_brd->BuildConnectivity() )
548 m_connectedItemsCache.clear();
549 }
while( mergeSegments( m_brd->GetConnectivity()->GetConnectivityAlgo() ) );
552 for(
PCB_TRACK* track : m_brd->Tracks() )
578 std::set<VECTOR2I> pts;
592 pts.emplace( aSeg1->
GetEnd() );
598 pts.emplace( aSeg2->
GetEnd() );
605 if( citem->HitTest( aSeg1->
GetEnd(), ( aSeg1->
GetWidth() + 1 ) / 2 ) )
606 pts.emplace( aSeg1->
GetEnd() );
611 if( citem->HitTest( aSeg2->
GetEnd(), ( aSeg2->
GetWidth() + 1 ) / 2 ) )
612 pts.emplace( aSeg2->
GetEnd() );
618 if( item != aSeg1 && item != aSeg2 )
624 if( item != aSeg1 && item != aSeg2 )
637 int min_x = std::min( aSeg1->
GetStart().
x,
639 int min_y = std::min( aSeg1->
GetStart().
y,
641 int max_x = std::max( aSeg1->
GetStart().
x,
643 int max_y = std::max( aSeg1->
GetStart().
y,
661 for(
auto& pt : pts )
687 item->SetItems( aSeg1, aSeg2 );
constexpr int ARC_HIGH_DEF
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool IsLocked() const
Information pertinent to a Pcbnew printed circuit board.
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
const std::vector< CN_ITEM * > & ConnectedItems() const
std::vector< std::shared_ptr< CN_ANCHOR > > & Anchors()
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
COMMIT & Removed(EDA_ITEM *aItem)
Modify a given item in the model.
Implement an R-tree for fast spatial and layer indexing of connectable items.
void Insert(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, int aWorstClearance=0)
Insert an item into the tree on a particular layer with an optional worst clearance.
int QueryColliding(BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
void SetState(EDA_ITEM_FLAGS type, bool state)
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
EDA_ITEM_FLAGS IsPointOnEnds(const VECTOR2I &point, int min_dist=0) const
Function IsPointOnEnds returns STARTPOINT if point if near (dist = min_dist) start point,...
VECTOR2I GetPosition() const override
VIATYPE GetViaType() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Represent a set of closed polygons.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
const std::vector< BOARD_CONNECTED_ITEM * > & getConnectedItems(PCB_TRACK *aTrack)
void deleteTracksInPads()
void removeItems(std::set< BOARD_ITEM * > &aItems)
void cleanup(bool aDeleteDuplicateVias, bool aDeleteNullSegments, bool aDeleteDuplicateSegments, bool aMergeSegments)
Geometry-based cleanup: duplicate items, null items, colinear items.
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad, bool aDeleteDanglingVias, REPORTER *aReporter=nullptr)
the cleanup function.
bool testTrackEndpointIsNode(PCB_TRACK *aTrack, bool aTstStart)
bool mergeCollinearSegments(PCB_TRACK *aSeg1, PCB_TRACK *aSeg2)
helper function merge aTrackRef and aCandidate, when possible, i.e.
bool deleteDanglingTracks(bool aTrack, bool aVia)
Removes tracks or vias only connected on one end.
std::map< PCB_TRACK *, std::vector< BOARD_CONNECTED_ITEM * > > m_connectedItemsCache
std::vector< std::shared_ptr< CLEANUP_ITEM > > * m_itemsList
TRACKS_CLEANER(BOARD *aPcb, BOARD_COMMIT &aCommit)
void removeShortingTrackSegments()
@ CLEANUP_ZERO_LENGTH_TRACK
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)