2019-03-31 09:37:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KICAD_TRACKS_CLEANER_H
|
|
|
|
#define KICAD_TRACKS_CLEANER_H
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
class BOARD_COMMIT;
|
2020-06-17 12:46:50 +00:00
|
|
|
class CLEANUP_ITEM;
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Helper class used to clean tracks and vias
|
|
|
|
class TRACKS_CLEANER
|
|
|
|
{
|
|
|
|
public:
|
2020-06-17 12:46:50 +00:00
|
|
|
TRACKS_CLEANER( BOARD* aPcb, BOARD_COMMIT& aCommit );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the cleanup function.
|
2021-06-01 15:13:43 +00:00
|
|
|
* @param aCleanVias = true to remove superimposed vias
|
|
|
|
* @param aRemoveMisConnected = true to remove segments connecting 2 different nets
|
|
|
|
* (short circuits)
|
|
|
|
* @param aMergeSegments = true to merge collinear segmenst and remove 0 len segm
|
|
|
|
* @param aDeleteUnconnected = true to remove dangling tracks
|
|
|
|
* @param aDeleteTracksinPad = true to remove tracks fully inside pads
|
|
|
|
* @param aDeleteDanglingVias = true to remove a via that is only connected to a single layer
|
2019-03-31 09:37:57 +00:00
|
|
|
*/
|
2021-06-01 15:13:43 +00:00
|
|
|
void CleanupBoard( bool aDryRun, std::vector<std::shared_ptr<CLEANUP_ITEM> >* aItemsList, bool aCleanVias,
|
|
|
|
bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected,
|
|
|
|
bool aDeleteTracksinPad, bool aDeleteDanglingVias );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-17 12:46:50 +00:00
|
|
|
/*
|
|
|
|
* Removes track segments which are connected to more than one net (short circuits).
|
2019-03-31 09:37:57 +00:00
|
|
|
*/
|
2020-08-18 18:32:43 +00:00
|
|
|
void removeShortingTrackSegments();
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-07-31 04:21:25 +00:00
|
|
|
/**
|
|
|
|
* Removes tracks or vias only connected on one end
|
2021-01-08 16:36:18 +00:00
|
|
|
* @param aTrack if true, clean dangling tracks
|
|
|
|
* @param aVia if true, clean dangling vias
|
2020-07-31 04:21:25 +00:00
|
|
|
* @return true if any items were deleted
|
|
|
|
*/
|
2021-01-08 16:36:18 +00:00
|
|
|
bool deleteDanglingTracks( bool aTrack, bool aVia );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void deleteTracksInPads();
|
2019-06-01 16:49:33 +00:00
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
/**
|
2020-10-26 18:36:25 +00:00
|
|
|
* Geometry-based cleanup: duplicate items, null items, colinear items.
|
2019-03-31 09:37:57 +00:00
|
|
|
*/
|
2020-10-26 18:36:25 +00:00
|
|
|
void cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegments,
|
|
|
|
bool aDeleteDuplicateSegments, bool aMergeSegments );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* helper function
|
|
|
|
* merge aTrackRef and aCandidate, when possible,
|
|
|
|
* i.e. when they are colinear, same width, and obviously same layer
|
2019-06-29 07:12:19 +00:00
|
|
|
* @return true if the segments are merged, false if not
|
|
|
|
* @param aSeg1 is the reference
|
|
|
|
* @param aSeg2 is the candidate, and after merging, the removed segment
|
2019-03-31 09:37:57 +00:00
|
|
|
*/
|
2021-06-11 21:07:02 +00:00
|
|
|
bool mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2 );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2019-06-28 18:23:09 +00:00
|
|
|
/**
|
|
|
|
* @return true if a track end position is a node, i.e. a end connected
|
|
|
|
* to more than one item.
|
|
|
|
* @param aTrack is the track to test.
|
2020-06-17 12:46:50 +00:00
|
|
|
* @param aTstStart = true ot test the start point of the track or false for end point
|
2019-06-28 18:23:09 +00:00
|
|
|
*/
|
2021-06-11 21:07:02 +00:00
|
|
|
bool testTrackEndpointIsNode( PCB_TRACK* aTrack, bool aTstStart );
|
2019-06-28 18:23:09 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void removeItems( std::set<BOARD_ITEM*>& aItems );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
private:
|
|
|
|
BOARD* m_brd;
|
|
|
|
BOARD_COMMIT& m_commit;
|
|
|
|
bool m_dryRun;
|
2020-08-11 13:33:16 +00:00
|
|
|
std::vector<std::shared_ptr<CLEANUP_ITEM> >* m_itemsList;
|
2019-03-31 09:37:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //KICAD_TRACKS_CLEANER_H
|