42 m_itemsList( nullptr ),
55 std::vector<std::shared_ptr<CLEANUP_ITEM> >* aItemsList,
56 bool aRemoveMisConnected,
bool aCleanVias,
bool aMergeSegments,
57 bool aDeleteUnconnected,
bool aDeleteTracksinPad,
58 bool aDeleteDanglingVias,
REPORTER* aReporter )
61 bool has_deleted =
false;
76 bool removeNullSegments = aMergeSegments || aRemoveMisConnected;
77 cleanup( aCleanVias, removeNullSegments, aMergeSegments , aMergeSegments );
91 cleanup(
false,
false,
true,
false );
93 if( aRemoveMisConnected )
108 if( aDeleteTracksinPad )
123 if( aDeleteUnconnected || aDeleteDanglingVias )
133 if( aDeleteUnconnected )
136 if( aDeleteDanglingVias )
146 if( has_deleted && aMergeSegments )
158 cleanup(
false,
false,
false,
true );
167 std::set<BOARD_ITEM *> toRemove;
172 if( segment->IsLocked() )
175 for(
PAD* testedPad : connectivity->GetConnectedPads( segment ) )
177 if( segment->GetNetCode() != testedPad->GetNetCode() )
179 std::shared_ptr<CLEANUP_ITEM> item;
186 item->SetItems( segment );
189 toRemove.insert( segment );
193 for(
PCB_TRACK* testedTrack : connectivity->GetConnectedTracks( segment ) )
195 if( segment->GetNetCode() != testedTrack->GetNetCode() )
197 std::shared_ptr<CLEANUP_ITEM> item;
204 item->SetItems( segment );
207 toRemove.insert( segment );
221 const std::list<CN_ITEM*>& items =
227 CN_ITEM* citem = items.front();
229 if( !citem->
Valid() )
232 const std::vector<std::shared_ptr<CN_ANCHOR>>& anchors = citem->
Anchors();
236 for(
const std::shared_ptr<CN_ANCHOR>&
anchor : anchors )
238 if(
anchor->Pos() != refpoint )
243 return anchor->ConnectedItemsCount() > 1;
252 bool item_erased =
false;
253 bool modified =
false;
255 if( !aTrack && !aVia )
265 std::deque<PCB_TRACK*> temp_tracks(
m_brd->
Tracks() );
269 if( track->IsLocked() || ( track->GetFlags() &
IS_DELETED ) > 0 )
272 if( !aVia && track->Type() ==
PCB_VIA_T )
281 std::shared_ptr<CLEANUP_ITEM> item;
288 item->SetItems( track );
304 }
while( item_erased );
312 std::set<BOARD_ITEM*> toRemove;
319 if( track->IsLocked() )
326 for(
PAD*
pad : connectivity->GetConnectedPads( track ) )
328 if(
pad->HitTest( track->GetStart() ) &&
pad->HitTest( track->GetEnd() ) )
331 track->TransformShapeToPolygon( poly, track->GetLayer(), 0,
ARC_HIGH_DEF,
340 item->SetItems( track );
343 toRemove.insert( track );
359 bool aDeleteDuplicateSegments,
bool aMergeSegments )
366 rtree.
Insert( track, track->GetLayer() );
369 std::set<BOARD_ITEM*> toRemove;
373 if( track->HasFlag(
IS_DELETED ) || track->IsLocked() )
376 if( aDeleteDuplicateVias && track->Type() ==
PCB_VIA_T )
380 if(
via->GetStart() !=
via->GetEnd() )
381 via->SetEnd(
via->GetStart() );
401 item->SetItems(
via );
405 toRemove.insert(
via );
417 if( (
pad->GetLayerSet() & all_cu ) == all_cu )
420 item->SetItems(
via,
pad );
424 toRemove.insert(
via );
432 if( aDeleteNullSegments && track->Type() !=
PCB_VIA_T )
434 if( track->IsNull() )
437 item->SetItems( track );
441 toRemove.insert( track );
445 if( aDeleteDuplicateSegments && track->Type() ==
PCB_TRACE_T && !track->IsNull() )
447 rtree.
QueryColliding( track, track->GetLayer(), track->GetLayer(),
451 return aItem->Type() == PCB_TRACE_T
452 && !aItem->HasFlag( SKIP_STRUCT )
453 && !aItem->HasFlag( IS_DELETED )
454 && !static_cast<PCB_TRACK*>( aItem )->IsNull();
459 PCB_TRACK* other = static_cast<PCB_TRACK*>( aItem );
461 if( track->IsPointOnEnds( other->GetStart() )
462 && track->IsPointOnEnds( other->GetEnd() )
463 && track->GetWidth() == other->GetWidth()
464 && track->GetLayer() == other->GetLayer() )
466 auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DUPLICATE_TRACK );
467 item->SetItems( track );
468 m_itemsList->push_back( item );
470 track->SetFlags( IS_DELETED );
471 toRemove.insert( track );
482 removeItems( toRemove );
485 [&]( std::shared_ptr<CN_CONNECTIVITY_ALGO> connectivity ) ->
bool
488 for(
PCB_TRACK* segment : m_brd->Tracks() )
498 for(
CN_ITEM* citem : connectivity->ItemEntry( segment ).GetItems() )
502 std::vector<PCB_TRACK*> sameWidthCandidates;
503 std::vector<PCB_TRACK*> differentWidthCandidates;
507 if( !connected->Valid() )
517 if( candidateSegment->
GetWidth() == segment->GetWidth() )
519 sameWidthCandidates.push_back( candidateSegment );
523 differentWidthCandidates.push_back( candidateSegment );
529 if( !differentWidthCandidates.empty() )
532 for(
PCB_TRACK* candidate : sameWidthCandidates )
534 if( segment->ApproxCollinear( *candidate )
535 && mergeCollinearSegments( segment, candidate ) )
550 while( !m_brd->BuildConnectivity() )
553 m_connectedItemsCache.clear();
554 }
while( mergeSegments( m_brd->GetConnectivity()->GetConnectivityAlgo() ) );
557 for(
PCB_TRACK* track : m_brd->Tracks() )
585 std::set<VECTOR2I> pts;
599 pts.emplace( aSeg1->
GetEnd() );
605 pts.emplace( aSeg2->
GetEnd() );
612 if( citem->HitTest( aSeg1->
GetEnd(), ( aSeg1->
GetWidth() + 1 ) / 2 ) )
613 pts.emplace( aSeg1->
GetEnd() );
618 if( citem->HitTest( aSeg2->
GetEnd(), ( aSeg2->
GetWidth() + 1 ) / 2 ) )
619 pts.emplace( aSeg2->
GetEnd() );
625 if( item != aSeg1 && item != aSeg2 )
631 if( item != aSeg1 && item != aSeg2 )
644 int min_x = std::min( aSeg1->
GetStart().
x,
646 int min_y = std::min( aSeg1->
GetStart().
y,
648 int max_x = std::max( aSeg1->
GetStart().
x,
650 int max_y = std::max( aSeg1->
GetStart().
y,
667 for(
auto& pt : pts )
696 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...
void SetParentGroup(PCB_GROUP *aGroup)
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...
const TRACKS & Tracks() const
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, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
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)
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
Return STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if point if near (dist = m...
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 difference For aFastMode meaning, see function booleanOp.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
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 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)
VECTOR2< int32_t > VECTOR2I