2011-12-12 14:02:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-02-04 13:34:17 +00:00
|
|
|
* Copyright (C) 2004-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-06-22 14:24:07 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2019-06-03 20:06:58 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-12 14:02:37 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2019-03-31 09:37:57 +00:00
|
|
|
#include <dialog_cleanup_tracks_and_vias.h>
|
|
|
|
#include <reporter.h>
|
2016-11-28 14:31:28 +00:00
|
|
|
#include <board_commit.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_algo.h>
|
|
|
|
#include <connectivity/connectivity_data.h>
|
2018-02-04 13:34:17 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include <tools/global_edit_tool.h>
|
2019-03-31 09:37:57 +00:00
|
|
|
#include <tracks_cleaner.h>
|
2007-10-19 23:02:11 +00:00
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2013-03-08 07:29:30 +00:00
|
|
|
/* Install the cleanup dialog frame to know what should be cleaned
|
2007-10-27 18:05:50 +00:00
|
|
|
*/
|
2019-06-03 20:06:58 +00:00
|
|
|
int GLOBAL_EDIT_TOOL::CleanupTracksAndVias( const TOOL_EVENT& aEvent )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2019-06-09 23:21:50 +00:00
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
DIALOG_CLEANUP_TRACKS_AND_VIAS dlg( editFrame );
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
dlg.ShowModal();
|
2019-06-03 20:06:58 +00:00
|
|
|
return 0;
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2016-09-30 16:33:46 +00:00
|
|
|
|
2015-09-22 15:55:10 +00:00
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
TRACKS_CLEANER::TRACKS_CLEANER( EDA_UNITS_T aUnits, BOARD* aPcb, BOARD_COMMIT& aCommit ) :
|
|
|
|
m_units( aUnits ),
|
|
|
|
m_brd( aPcb ),
|
|
|
|
m_commit( aCommit ),
|
|
|
|
m_dryRun( true ),
|
|
|
|
m_itemsList( nullptr )
|
|
|
|
{
|
2007-06-14 05:31:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
/* Main cleaning function.
|
|
|
|
* Delete
|
|
|
|
* - Redundant points on tracks (merge aligned segments)
|
|
|
|
* - vias on pad
|
2014-04-25 06:00:04 +00:00
|
|
|
* - null length segments
|
2007-10-27 18:05:50 +00:00
|
|
|
*/
|
2019-06-01 16:49:33 +00:00
|
|
|
bool TRACKS_CLEANER::CleanupBoard( bool aDryRun, DRC_LIST* aItemsList, bool aRemoveMisConnected,
|
|
|
|
bool aCleanVias, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad )
|
2007-06-14 05:31:55 +00:00
|
|
|
{
|
2019-03-31 09:37:57 +00:00
|
|
|
m_dryRun = aDryRun;
|
|
|
|
m_itemsList = aItemsList;
|
2012-09-07 19:29:44 +00:00
|
|
|
bool modified = false;
|
2010-11-21 18:28:32 +00:00
|
|
|
|
2012-09-07 19:29:44 +00:00
|
|
|
// delete redundant vias
|
2016-09-30 09:09:17 +00:00
|
|
|
if( aCleanVias )
|
2017-03-22 13:51:07 +00:00
|
|
|
modified |= cleanupVias();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2012-09-07 19:29:44 +00:00
|
|
|
// Remove null segments and intermediate points on aligned segments
|
2016-09-30 16:33:46 +00:00
|
|
|
// If not asked, remove null segments only if remove misconnected is asked
|
2016-09-30 09:09:17 +00:00
|
|
|
if( aMergeSegments )
|
2017-06-22 14:24:07 +00:00
|
|
|
modified |= cleanupSegments();
|
2016-09-30 16:33:46 +00:00
|
|
|
else if( aRemoveMisConnected )
|
2019-05-31 02:30:28 +00:00
|
|
|
modified |= deleteNullSegments( m_brd->Tracks() );
|
2016-09-30 09:09:17 +00:00
|
|
|
|
|
|
|
if( aRemoveMisConnected )
|
2017-03-28 11:18:15 +00:00
|
|
|
modified |= removeBadTrackSegments();
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
if( aDeleteTracksinPad )
|
|
|
|
modified |= deleteTracksInPads();
|
|
|
|
|
2016-09-30 16:33:46 +00:00
|
|
|
// Delete dangling tracks
|
|
|
|
if( aDeleteUnconnected )
|
2014-04-13 18:24:44 +00:00
|
|
|
{
|
2016-09-30 16:33:46 +00:00
|
|
|
if( deleteDanglingTracks() )
|
|
|
|
{
|
2016-12-07 15:52:48 +00:00
|
|
|
modified = true;
|
2016-09-30 16:33:46 +00:00
|
|
|
|
|
|
|
// Removed tracks can leave aligned segments
|
2019-06-03 20:06:58 +00:00
|
|
|
// (when a T was formed by tracks and the "vertical" segment is removed)
|
2016-09-30 16:33:46 +00:00
|
|
|
if( aMergeSegments )
|
2017-06-22 14:24:07 +00:00
|
|
|
cleanupSegments();
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
2014-04-13 18:24:44 +00:00
|
|
|
}
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2012-09-07 19:29:44 +00:00
|
|
|
return modified;
|
|
|
|
}
|
2007-06-14 05:31:55 +00:00
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2016-09-30 16:33:46 +00:00
|
|
|
bool TRACKS_CLEANER::removeBadTrackSegments()
|
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
auto connectivity = m_brd->GetConnectivity();
|
2016-09-30 16:33:46 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
std::set<BOARD_ITEM *> toRemove;
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( auto segment : m_brd->Tracks() )
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
|
|
|
segment->SetState( FLAG0, false );
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( auto testedPad : connectivity->GetConnectedPads( segment ) )
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
if( segment->GetNetCode() != testedPad->GetNetCode() )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
|
|
|
if( m_itemsList )
|
|
|
|
{
|
2019-06-01 16:49:33 +00:00
|
|
|
m_itemsList->emplace_back(
|
|
|
|
new DRC_ITEM( m_units, DRCE_SHORT, segment, segment->GetPosition() ) );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
toRemove.insert( segment );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:51:07 +00:00
|
|
|
for( auto testedTrack : connectivity->GetConnectedTracks( segment ) )
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
if( segment->GetNetCode() != testedTrack->GetNetCode() && !testedTrack->GetState( FLAG0 ) )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
|
|
|
if( m_itemsList )
|
|
|
|
{
|
|
|
|
m_itemsList->emplace_back( new DRC_ITEM( m_units, DRCE_SHORT,
|
|
|
|
segment, segment->GetPosition(),
|
|
|
|
nullptr, wxPoint() ) );
|
|
|
|
}
|
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
toRemove.insert( segment );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
return removeItems( toRemove );
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
bool TRACKS_CLEANER::cleanupVias()
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
std::set<BOARD_ITEM*> toRemove;
|
|
|
|
std::vector<VIA*> vias;
|
2016-12-07 15:52:48 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto track : m_brd->Tracks() )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( auto via = dyn_cast<VIA*>( track ) )
|
|
|
|
vias.push_back( via );
|
2014-05-10 12:48:17 +00:00
|
|
|
}
|
2010-11-21 18:28:32 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto via1_it = vias.begin(); via1_it != vias.end(); via1_it++ )
|
2010-11-21 18:28:32 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
auto via1 = *via1_it;
|
|
|
|
|
|
|
|
if( via1->IsLocked() )
|
2017-05-04 22:43:43 +00:00
|
|
|
continue;
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( via1->GetStart() != via1->GetEnd() )
|
|
|
|
via1->SetEnd( via1->GetStart() );
|
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
// To delete through Via on THT pads at same location
|
|
|
|
// Examine the list of connected pads:
|
|
|
|
// if one through pad is found, the via can be removed
|
2019-05-31 02:30:28 +00:00
|
|
|
|
|
|
|
const auto pads = m_brd->GetConnectivity()->GetConnectedPads( via1 );
|
|
|
|
for( const auto pad : pads )
|
2012-09-07 19:29:44 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
const LSET all_cu = LSET::AllCuMask();
|
|
|
|
|
|
|
|
if( ( pad->GetLayerSet() & all_cu ) == all_cu )
|
|
|
|
{
|
|
|
|
if( m_itemsList )
|
|
|
|
{
|
|
|
|
m_itemsList->emplace_back( new DRC_ITEM( m_units, DRCE_REDUNDANT_VIA, via1,
|
|
|
|
via1->GetPosition(), pad, pad->GetPosition() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// redundant: delete the via
|
|
|
|
toRemove.insert( via1 );
|
|
|
|
break;
|
|
|
|
}
|
2012-09-07 19:29:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto via2_it = via1_it + 1; via2_it != vias.end(); via2_it++ )
|
2010-11-21 18:28:32 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
auto via2 = *via2_it;
|
2010-11-21 18:28:32 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( via1->GetPosition() != via2->GetPosition() || via2->IsLocked() )
|
|
|
|
continue;
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( via1->GetViaType() == via2->GetViaType() )
|
2014-04-30 19:16:22 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( m_itemsList )
|
2014-04-30 19:16:22 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
m_itemsList->emplace_back( new DRC_ITEM( m_units, DRCE_REDUNDANT_VIA, via1,
|
|
|
|
via1->GetPosition(), via2, via2->GetPosition() ) );
|
2014-04-30 19:16:22 +00:00
|
|
|
}
|
2019-05-31 02:30:28 +00:00
|
|
|
|
|
|
|
toRemove.insert( via2 );
|
|
|
|
break;
|
2014-04-25 06:00:04 +00:00
|
|
|
}
|
2010-11-21 18:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
return removeItems( toRemove );
|
2014-04-30 19:16:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
bool TRACKS_CLEANER::testTrackHasPad( const TRACK* aTrack ) const
|
|
|
|
{
|
|
|
|
auto connectivity = m_brd->GetConnectivity();
|
|
|
|
|
|
|
|
// Mark track if connected to pads
|
|
|
|
for( auto pad : connectivity->GetConnectedPads( aTrack ) )
|
|
|
|
{
|
|
|
|
if( pad->HitTest( aTrack->GetStart() ) || pad->HitTest( aTrack->GetEnd() ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
bool TRACKS_CLEANER::testTrackEndpointDangling( TRACK* aTrack )
|
2014-04-30 19:16:22 +00:00
|
|
|
{
|
2017-05-04 22:43:43 +00:00
|
|
|
auto connectivity = m_brd->GetConnectivity();
|
2019-05-31 02:30:28 +00:00
|
|
|
auto items = connectivity->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems();
|
2012-09-07 19:29:44 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
// Not in the connectivity system. This is a bug!
|
|
|
|
if( items.empty() )
|
|
|
|
{
|
|
|
|
wxASSERT( !items.empty() );
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-30 19:16:22 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
auto citem = items.front();
|
2017-06-22 14:24:07 +00:00
|
|
|
|
|
|
|
if( !citem->Valid() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto anchors = citem->Anchors();
|
2014-04-30 19:16:22 +00:00
|
|
|
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const auto& anchor : anchors )
|
2017-05-04 22:43:43 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( anchor->IsDangling() )
|
2017-05-04 22:43:43 +00:00
|
|
|
return true;
|
2010-11-21 18:28:32 +00:00
|
|
|
}
|
2015-02-06 10:54:55 +00:00
|
|
|
|
2017-05-04 22:43:43 +00:00
|
|
|
return false;
|
2010-11-21 18:28:32 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2016-09-30 09:09:17 +00:00
|
|
|
bool TRACKS_CLEANER::deleteDanglingTracks()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-06-22 14:24:07 +00:00
|
|
|
bool item_erased = false;
|
2012-09-07 19:29:44 +00:00
|
|
|
bool modified = false;
|
2016-09-30 09:09:17 +00:00
|
|
|
|
2014-04-30 19:16:22 +00:00
|
|
|
do // Iterate when at least one track is deleted
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-07 19:29:44 +00:00
|
|
|
item_erased = false;
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
for( TRACK* track : m_brd->Tracks() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2014-04-30 19:16:22 +00:00
|
|
|
bool flag_erase = false; // Start without a good reason to erase it
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
if( track->Type() != PCB_TRACE_T )
|
|
|
|
continue;
|
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
// if a track endpoint is not connected to a pad, test if
|
|
|
|
// the endpoint is connected to another track or to a zone.
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
if( !testTrackHasPad( track ) )
|
2019-05-31 02:30:28 +00:00
|
|
|
flag_erase |= testTrackEndpointDangling( track );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-09-07 19:29:44 +00:00
|
|
|
if( flag_erase )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2019-03-31 09:37:57 +00:00
|
|
|
if( m_itemsList )
|
|
|
|
{
|
|
|
|
int code = track->IsTrack() ? DRCE_DANGLING_TRACK : DRCE_DANGLING_VIA;
|
2019-06-01 16:49:33 +00:00
|
|
|
m_itemsList->emplace_back(
|
|
|
|
new DRC_ITEM( m_units, code, track, track->GetPosition() ) );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2016-12-07 15:52:48 +00:00
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
if( !m_dryRun )
|
|
|
|
{
|
|
|
|
m_brd->Remove( track );
|
|
|
|
m_commit.Removed( track );
|
|
|
|
|
|
|
|
/* keep iterating, because a track connected to the deleted track
|
|
|
|
* now perhaps is not connected and should be deleted */
|
|
|
|
item_erased = true;
|
|
|
|
modified = true;
|
2019-06-25 19:40:04 +00:00
|
|
|
break;
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2014-04-30 19:16:22 +00:00
|
|
|
} while( item_erased );
|
2012-09-07 19:29:44 +00:00
|
|
|
|
|
|
|
return modified;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2014-05-10 12:48:17 +00:00
|
|
|
// Delete null length track segments
|
2019-05-31 02:30:28 +00:00
|
|
|
bool TRACKS_CLEANER::deleteNullSegments( TRACKS& aTracks )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-06-22 14:24:07 +00:00
|
|
|
std::set<BOARD_ITEM *> toRemove;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto segment : aTracks )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( segment->IsNull() && segment->Type() == PCB_TRACE_T && !segment->IsLocked() )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
|
|
|
if( m_itemsList )
|
|
|
|
{
|
2019-06-01 16:49:33 +00:00
|
|
|
m_itemsList->emplace_back( new DRC_ITEM(
|
|
|
|
m_units, DRCE_ZERO_LENGTH_TRACK, segment, segment->GetPosition() ) );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
toRemove.insert( segment );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
return removeItems( toRemove );
|
2014-05-10 12:48:17 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
bool TRACKS_CLEANER::deleteTracksInPads()
|
|
|
|
{
|
|
|
|
std::set<BOARD_ITEM*> toRemove;
|
|
|
|
|
|
|
|
// Delete tracks that start and end on the same pad
|
|
|
|
auto connectivity = m_brd->GetConnectivity();
|
|
|
|
|
|
|
|
for( auto track : m_brd->Tracks() )
|
|
|
|
{
|
|
|
|
// Mark track if connected to pads
|
|
|
|
for( auto pad : connectivity->GetConnectedPads( track ) )
|
|
|
|
{
|
|
|
|
if( pad->HitTest( track->GetStart() ) && pad->HitTest( track->GetEnd() ) )
|
|
|
|
{
|
|
|
|
if( m_itemsList )
|
|
|
|
{
|
|
|
|
m_itemsList->emplace_back( new DRC_ITEM(
|
|
|
|
m_units, DRCE_TRACK_IN_PAD, track, track->GetPosition() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
toRemove.insert( track );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return removeItems( toRemove );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
// Delete null length segments, and intermediate points ..
|
|
|
|
bool TRACKS_CLEANER::cleanupSegments()
|
|
|
|
{
|
|
|
|
bool modified = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
// Easy things first
|
|
|
|
modified |= deleteNullSegments( m_brd->Tracks() );
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
std::set<BOARD_ITEM*> toRemove;
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto it = m_brd->Tracks().begin(); it != m_brd->Tracks().end(); it++ )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
auto track1 = *it;
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( track1->Type() != PCB_TRACE_T || ( track1->GetFlags() & IS_DELETED )
|
|
|
|
|| track1->IsLocked() )
|
|
|
|
continue;
|
2014-05-17 17:36:02 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto it2 = it + 1; it2 != m_brd->Tracks().end(); it2++ )
|
|
|
|
{
|
|
|
|
auto track2 = *it2;
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( track2->GetFlags() & IS_DELETED )
|
|
|
|
continue;
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
if( track1->IsPointOnEnds( track2->GetStart() )
|
|
|
|
&& track1->IsPointOnEnds( track2->GetEnd() )
|
|
|
|
&& ( track1->GetWidth() == track2->GetWidth() )
|
|
|
|
&& ( track1->GetLayer() == track2->GetLayer() ) )
|
|
|
|
{
|
|
|
|
if( m_itemsList )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
m_itemsList->emplace_back( new DRC_ITEM( m_units, DRCE_DUPLICATE_TRACK, track2,
|
|
|
|
track2->GetPosition(), nullptr, wxPoint() ) );
|
2014-05-17 17:36:02 +00:00
|
|
|
}
|
2019-05-31 02:30:28 +00:00
|
|
|
|
|
|
|
track2->SetFlags( IS_DELETED );
|
|
|
|
toRemove.insert( track2 );
|
2014-05-17 17:36:02 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2014-05-10 12:48:17 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
modified |= removeItems( toRemove );
|
|
|
|
|
2014-05-10 12:48:17 +00:00
|
|
|
// merge collinear segments:
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto track_it = m_brd->Tracks().begin(); track_it != m_brd->Tracks().end(); track_it++ )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
auto segment = *track_it;
|
|
|
|
auto connectivity = m_brd->GetConnectivity();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
auto& entry = connectivity->GetConnectivityAlgo()->ItemEntry( segment );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto citem : entry.GetItems() )
|
|
|
|
{
|
|
|
|
for( auto connected : citem->ConnectedItems() )
|
2015-05-01 15:01:09 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( connected->Valid() && connected->Parent()->Type() == PCB_TRACE_T
|
|
|
|
&& !( connected->Parent()->GetFlags() & IS_DELETED ) )
|
|
|
|
{
|
|
|
|
if( segment->ApproxCollinear( *static_cast<TRACK*>( connected->Parent() ) ) )
|
|
|
|
{
|
|
|
|
modified |= mergeCollinearSegments(
|
|
|
|
segment, static_cast<TRACK*>( connected->Parent() ) );
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 15:01:09 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 19:29:44 +00:00
|
|
|
return modified;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
bool TRACKS_CLEANER::mergeCollinearSegments( TRACK* aSeg1, TRACK* aSeg2 )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
if( aSeg1->IsLocked() || aSeg2->IsLocked() )
|
|
|
|
return false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
auto connectivity = m_brd->GetConnectivity();
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
if( m_itemsList )
|
|
|
|
{
|
|
|
|
m_itemsList->emplace_back( new DRC_ITEM( m_units, DRCE_MERGE_TRACKS,
|
|
|
|
aSeg1, aSeg1->GetPosition(),
|
|
|
|
aSeg2, aSeg2->GetPosition() ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
if( !m_dryRun )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2019-03-31 09:37:57 +00:00
|
|
|
m_commit.Modify( aSeg1 );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
int min_x = std::min( aSeg1->GetStart().x,
|
|
|
|
std::min( aSeg1->GetEnd().x, std::min( aSeg2->GetStart().x, aSeg2->GetEnd().x ) ) );
|
|
|
|
int min_y = std::min( aSeg1->GetStart().y,
|
|
|
|
std::min( aSeg1->GetEnd().y, std::min( aSeg2->GetStart().y, aSeg2->GetEnd().y ) ) );
|
|
|
|
int max_x = std::max( aSeg1->GetStart().x,
|
|
|
|
std::max( aSeg1->GetEnd().x, std::max( aSeg2->GetStart().x, aSeg2->GetEnd().x ) ) );
|
|
|
|
int max_y = std::max( aSeg1->GetStart().y,
|
|
|
|
std::max( aSeg1->GetEnd().y, std::max( aSeg2->GetStart().y, aSeg2->GetEnd().y ) ) );
|
|
|
|
|
|
|
|
if( ( aSeg1->GetStart().x > aSeg1->GetEnd().x )
|
|
|
|
== ( aSeg1->GetStart().y > aSeg1->GetEnd().y ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
aSeg1->SetStart( wxPoint( min_x, min_y ) );
|
|
|
|
aSeg1->SetEnd( wxPoint( max_x, max_y ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2019-05-31 02:30:28 +00:00
|
|
|
else
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2019-05-31 02:30:28 +00:00
|
|
|
aSeg1->SetStart( wxPoint( min_x, max_y ) );
|
|
|
|
aSeg1->SetEnd( wxPoint( max_x, min_y ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
connectivity->Update( aSeg1 );
|
2019-06-01 16:49:33 +00:00
|
|
|
|
|
|
|
// Clear the status flags here after update.
|
|
|
|
for( auto pad : connectivity->GetConnectedPads( aSeg1 ) )
|
|
|
|
{
|
|
|
|
aSeg1->SetState( BEGIN_ONPAD, pad->HitTest( aSeg1->GetStart() ) );
|
|
|
|
aSeg1->SetState( END_ONPAD, pad->HitTest( aSeg1->GetEnd() ) );
|
|
|
|
}
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
|
|
|
|
// Merge succesful, seg2 has to go away
|
|
|
|
if( !m_dryRun && aSeg2 )
|
|
|
|
{
|
|
|
|
aSeg2->SetFlags( IS_DELETED );
|
|
|
|
m_brd->Remove( aSeg2 );
|
|
|
|
m_commit.Removed( aSeg2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!aSeg2;
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TRACKS_CLEANER::removeItems( std::set<BOARD_ITEM*>& aItems )
|
|
|
|
{
|
|
|
|
if( m_dryRun )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( auto item : aItems )
|
|
|
|
{
|
|
|
|
m_brd->Remove( item );
|
|
|
|
m_commit.Removed( item );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
return !aItems.empty();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|