33 #include <class_drawpanel.h> 61 bool CleanupBoard(
bool aCleanVias,
bool aRemoveMisConnected,
62 bool aMergeSegments,
bool aDeleteUnconnected );
128 bool isModified =
false;
131 for(
auto item : aItems )
149 if( dlg.ShowModal() != wxID_OK )
169 commit.
Push( _(
"Board cleanup" ) );
180 connectivity->Build(
m_brd);
191 for(
auto pad : connectivity->GetConnectedPads( track ) )
193 if( pad->HitTest( track->GetStart() ) )
198 if( pad->HitTest( track->GetEnd() ) )
216 bool aDeleteUnconnected )
219 bool modified =
false;
229 else if( aRemoveMisConnected )
234 if( aRemoveMisConnected )
238 if( aDeleteUnconnected )
257 : m_brd( aPcb ), m_commit( aCommit )
266 std::set<BOARD_ITEM *> toRemove;
270 segment->SetState(
FLAG0,
false );
272 for(
auto testedPad : connectivity->GetConnectedPads( segment ) )
274 if( segment->GetNetCode() != testedPad->GetNetCode() )
275 toRemove.insert( segment );
278 for(
auto testedTrack : connectivity->GetConnectedTracks( segment ) )
280 if( segment->GetNetCode() != testedTrack->GetNetCode() && !testedTrack->GetState(
FLAG0 ) )
281 toRemove.insert( segment );
293 for(
VIA* alt_via =
GetFirstVia( aVia->
Next() ); alt_via != NULL; alt_via = next_via )
298 ( alt_via->GetStart() == aVia->
GetStart() ) )
299 aToRemove.insert ( alt_via );
306 std::set<BOARD_ITEM*> toRemove;
315 if( via->GetStart() != via->GetEnd() )
317 wxFAIL_MSG(
"Malformed via with mismatching ends" );
318 via->SetEnd( via->GetStart() );
332 for(
const auto pad : pads )
336 if( ( pad->GetLayerSet() & all_cu ) == all_cu )
339 toRemove.insert( via );
363 wxASSERT ( connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems().size() != 0 );
364 auto citem = connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems().front();
366 if( !citem->Valid() )
369 auto anchors = citem->Anchors();
371 for(
const auto& anchor : anchors )
373 if( anchor->Pos() == endpoint && anchor->IsDangling() )
387 bool item_erased =
false;
388 bool modified =
false;
399 next_track = track->
Next();
400 bool flag_erase =
false;
414 if( !flag_erase && !track->GetState(
END_ON_PAD ) )
428 }
while( item_erased );
438 std::set<BOARD_ITEM *> toRemove;
442 if( segment->IsNull() )
443 toRemove.insert( segment );
457 if( aTrack->
GetNetCode() != other->GetNetCode() )
460 if( aTrack == other )
468 if( ( aTrack->
Type() == other->Type() ) &&
469 ( aTrack->
GetLayer() == other->GetLayer() ) )
471 if( ( ( aTrack->
GetStart() == other->GetStart() ) &&
472 ( aTrack->
GetEnd() == other->GetEnd() ) ) ||
473 ( ( aTrack->
GetStart() == other->GetEnd() ) &&
474 ( aTrack->
GetEnd() == other->GetStart() ) ) )
477 aToRemove.insert( other );
486 bool merged_this =
false;
497 other = aSegment->
GetTrack( other, NULL, endpoint,
true,
false );
509 endpoint,
true,
false );
540 bool modified =
false;
547 std::set<BOARD_ITEM*> toRemove;
564 nextsegment = segment->
Next();
572 nextsegment = segment->
Next();
606 return ((
double)dy1 * dx2 == (
double)dx1 * dy2);
623 static void updateConn(
TRACK *track,
const std::shared_ptr<CONNECTIVITY_DATA>& connectivity )
625 for(
auto pad : connectivity->GetConnectedPads( track ) )
627 if( pad->HitTest( track->
GetStart() ) )
632 if( pad->HitTest( track->
GetEnd() ) )
683 connectivity->Update( aTrackRef );
691 connectivity->Update( aTrackRef );
708 connectivity->Update( aTrackRef );
717 connectivity->Update( aTrackRef );
733 bool isModified = cleaner.
CleanupBoard(
true,
false,
false,
false );
739 commit.
Push( _(
"Board cleanup" ) );
static TOOL_ACTION selectionClear
Clears the current selection.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
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...
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
int GetNetCode() const
Function GetNetCode.
bool MergeCollinearTracks(TRACK *aSegment)
Try to merge the segment to a following collinear one.
void SetEnd(const wxPoint &aEnd)
const wxPoint & GetStart() const
bool CleanupBoard(bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected)
the cleanup function.
Class BOARD to handle a board.
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool deleteDanglingTracks()
Removes dangling tracks.
#define BUSY
Pcbnew: flag indicating that the structure has.
TRACKS_CLEANER(BOARD *aPcb, BOARD_COMMIT &aCommit)
bool testTrackEndpointDangling(TRACK *aTrack, ENDPOINT_T aEndPoint)
Utility: does the endpoint unconnected processed for one endpoint of one track Returns true if the tr...
static bool m_deleteShortCircuits
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
ENDPOINT_T
Flag used in locate routines (from which endpoint work)
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
void removeDuplicatesOfTrack(const TRACK *aTrack, std::set< BOARD_ITEM * > &aToRemove)
Removes all the following duplicates tracks of the specified one.
COMMIT & Removed(EDA_ITEM *aItem)
Notifies observers that aItem has been removed
Class LSET is a set of PCB_LAYER_IDs.
static bool m_deleteUnconnectedSegm
bool RemoveMisConnectedTracks()
Function RemoveMisConnectedTracks finds all track segments which are mis-connected (to more than one ...
bool removeBadTrackSegments()
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
#define STRUCT_DELETED
flag indication structures to be erased
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
const ZONE_CONTAINER * zoneForTrackEndpoint(const TRACK *aTrack, ENDPOINT_T aEndPoint)
#define FLAG0
Pcbnew: flag used in local computations.
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
static void updateConn(TRACK *track, const std::shared_ptr< CONNECTIVITY_DATA > &connectivity)
Function used by cleanupSegments.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
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)
static bool m_mergeSegments
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
static bool parallelismTest(int dx1, int dy1, int dx2, int dy2)
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
const wxPoint & GetEnd() const
void SetStart(const wxPoint &aStart)
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
bool cleanupSegments()
Merge collinear segments and remove duplicated and null len segments.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
STATUS_FLAGS GetFlags() const
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
void removeDuplicatesOfVia(const VIA *aVia, std::set< BOARD_ITEM * > &aToRemove)
Removes all the following THT vias on the same position of the specified one.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
int GetState(int type) const
bool deleteNullSegments()
Delete null length track segments.
void Clean_Pcb()
Function Clean_Pcb Clean up the board (remove redundant vias, not connected tracks and merges colline...
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
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)
KICAD_T Type() const
Function Type()
bool cleanupVias()
Removes redundant vias like vias at same location or on pad through.
VIA * GetFirstVia(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first VIA o NULL if not found (or NULL passed)