2021-11-02 09:18:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-02-19 13:44:37 +00:00
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-11-02 09:18:58 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <confirm.h>
|
|
|
|
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <pcb_track.h>
|
|
|
|
#include <pad.h>
|
|
|
|
#include <zone_filler.h>
|
|
|
|
#include <board_commit.h>
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
#include <teardrop/teardrop.h>
|
|
|
|
#include <drc/drc_rtree.h>
|
2021-11-02 09:18:58 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
2023-05-12 21:03:54 +00:00
|
|
|
#include <geometry/rtree.h>
|
2021-11-02 09:18:58 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <bezier_curves.h>
|
|
|
|
|
|
|
|
#include <wx/log.h>
|
|
|
|
|
2021-12-19 09:30:31 +00:00
|
|
|
// The first priority level of a teardrop area (arbitrary value)
|
|
|
|
#define MAGIC_TEARDROP_ZONE_ID 30000
|
|
|
|
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
TEARDROP_MANAGER::TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager ) :
|
|
|
|
m_board( aBoard ),
|
|
|
|
m_toolManager( aToolManager )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
2023-05-11 13:53:28 +00:00
|
|
|
m_prmsList = m_board->GetDesignSettings().GetTeadropParamsList();
|
2022-01-23 11:57:06 +00:00
|
|
|
m_tolerance = 0;
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZONE* TEARDROP_MANAGER::createTeardrop( TEARDROP_VARIANT aTeardropVariant,
|
2023-05-11 14:46:58 +00:00
|
|
|
std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack ) const
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
|
|
|
ZONE* teardrop = new ZONE( m_board );
|
|
|
|
|
2022-08-07 06:52:40 +00:00
|
|
|
// teardrop settings are the last zone settings used by a zone dialog.
|
|
|
|
// override them by default.
|
2023-06-10 10:03:18 +00:00
|
|
|
ZONE_SETTINGS::GetDefaultSettings().ExportSetting( *teardrop, false );
|
2022-08-07 06:52:40 +00:00
|
|
|
|
2021-11-02 09:18:58 +00:00
|
|
|
// Add zone properties (priority will be fixed later)
|
2023-05-12 21:03:54 +00:00
|
|
|
teardrop->SetTeardropAreaType( aTeardropVariant == TD_TYPE_PADVIA ? TEARDROP_TYPE::TD_VIAPAD
|
|
|
|
: TEARDROP_TYPE::TD_TRACKEND );
|
2021-11-02 09:18:58 +00:00
|
|
|
teardrop->SetLayer( aTrack->GetLayer() );
|
|
|
|
teardrop->SetNetCode( aTrack->GetNetCode() );
|
|
|
|
teardrop->SetLocalClearance( 0 );
|
2022-09-16 11:33:56 +00:00
|
|
|
teardrop->SetMinThickness( pcbIUScale.mmToIU( 0.0254 ) ); // The minimum zone thickness
|
2021-11-02 09:18:58 +00:00
|
|
|
teardrop->SetPadConnection( ZONE_CONNECTION::FULL );
|
|
|
|
teardrop->SetIsFilled( false );
|
2023-05-12 21:03:54 +00:00
|
|
|
teardrop->SetZoneName( aTeardropVariant == TD_TYPE_PADVIA ? MAGIC_TEARDROP_PADVIA_NAME
|
|
|
|
: MAGIC_TEARDROP_TRACK_NAME );
|
2021-11-02 09:18:58 +00:00
|
|
|
teardrop->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::NEVER );
|
2023-05-12 21:03:54 +00:00
|
|
|
teardrop->SetBorderDisplayStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL,
|
|
|
|
pcbIUScale.mmToIU( 0.1 ), true );
|
|
|
|
|
2021-11-02 09:18:58 +00:00
|
|
|
SHAPE_POLY_SET* outline = teardrop->Outline();
|
|
|
|
outline->NewOutline();
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( const VECTOR2I& pt: aPoints )
|
|
|
|
outline->Append( pt.x, pt.y );
|
|
|
|
|
|
|
|
// Until we know better (ie: pay for a potentially very expensive zone refill), the teardrop
|
|
|
|
// fill is the same as its outline.
|
|
|
|
teardrop->SetFilledPolysList( aTrack->GetLayer(), *teardrop->Outline() );
|
|
|
|
teardrop->SetIsFilled( true );
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2022-08-07 06:52:40 +00:00
|
|
|
// Used in priority calculations:
|
2021-11-02 09:18:58 +00:00
|
|
|
teardrop->CalculateFilledArea();
|
|
|
|
|
|
|
|
return teardrop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-15 09:46:31 +00:00
|
|
|
void TEARDROP_MANAGER::RemoveTeardrops( BOARD_COMMIT& aCommit,
|
2023-05-12 21:03:54 +00:00
|
|
|
const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
|
2023-08-15 09:46:31 +00:00
|
|
|
const std::set<PCB_TRACK*>* dirtyTracks )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
|
2023-08-15 09:46:31 +00:00
|
|
|
std::vector<ZONE*> stale_teardrops;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
if( zone->IsTeardropArea() )
|
|
|
|
{
|
2023-08-15 09:46:31 +00:00
|
|
|
bool stale = false;
|
2022-01-16 14:00:40 +00:00
|
|
|
|
2023-08-15 09:46:31 +00:00
|
|
|
std::vector<PAD*> connectedPads;
|
|
|
|
std::vector<PCB_VIA*> connectedVias;
|
2022-01-16 14:00:40 +00:00
|
|
|
|
2023-08-15 09:46:31 +00:00
|
|
|
connectivity->GetConnectedPadsAndVias( zone, &connectedPads, &connectedVias );
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-08-15 09:46:31 +00:00
|
|
|
for( PAD* pad : connectedPads )
|
|
|
|
{
|
|
|
|
if( alg::contains( *dirtyPadsAndVias, pad ) )
|
|
|
|
{
|
|
|
|
stale = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-08-15 09:46:31 +00:00
|
|
|
if( !stale )
|
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
for( PCB_VIA* via : connectedVias )
|
2023-08-15 09:46:31 +00:00
|
|
|
{
|
|
|
|
if( alg::contains( *dirtyPadsAndVias, via ) )
|
|
|
|
{
|
|
|
|
stale = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
2023-05-12 21:03:54 +00:00
|
|
|
|
|
|
|
if( stale )
|
|
|
|
stale_teardrops.push_back( zone );
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( ZONE* td : stale_teardrops )
|
|
|
|
{
|
|
|
|
m_board->Remove( td, REMOVE_MODE::BULK );
|
|
|
|
aCommit.Removed( td );
|
|
|
|
}
|
2023-08-15 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TEARDROP_MANAGER::UpdateTeardrops( BOARD_COMMIT& aCommit,
|
|
|
|
const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
|
|
|
|
const std::set<PCB_TRACK*>* dirtyTracks,
|
|
|
|
bool aForceFullUpdate )
|
|
|
|
{
|
|
|
|
if( m_board->LegacyTeardrops() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Init parameters:
|
|
|
|
m_tolerance = pcbIUScale.mmToIU( 0.01 );
|
|
|
|
|
|
|
|
buildTrackCaches();
|
|
|
|
|
|
|
|
// Old teardrops must be removed, to ensure a clean teardrop rebuild
|
|
|
|
if( aForceFullUpdate )
|
|
|
|
{
|
|
|
|
std::vector<ZONE*> teardrops;
|
|
|
|
|
|
|
|
for( ZONE* zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
if( zone->IsTeardropArea() )
|
|
|
|
teardrops.push_back( zone );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ZONE* td : teardrops )
|
|
|
|
{
|
|
|
|
m_board->Remove( td, REMOVE_MODE::BULK );
|
|
|
|
aCommit.Removed( td );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
|
2021-11-02 09:18:58 +00:00
|
|
|
|
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
if( ! ( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T ) )
|
2021-11-02 09:18:58 +00:00
|
|
|
continue;
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
std::vector<PAD*> connectedPads;
|
|
|
|
std::vector<PCB_VIA*> connectedVias;
|
|
|
|
|
|
|
|
connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
|
|
|
|
|
|
|
|
bool forceUpdate = aForceFullUpdate || alg::contains( *dirtyTracks, track );
|
|
|
|
|
|
|
|
for( PAD* pad : connectedPads )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !forceUpdate && !alg::contains( *dirtyPadsAndVias, pad ) )
|
2022-01-16 09:24:23 +00:00
|
|
|
continue;
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( pad->GetShape() == PAD_SHAPE::CUSTOM )
|
|
|
|
// A teardrop shape cannot be built
|
2021-11-02 09:18:58 +00:00
|
|
|
continue;
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
TEARDROP_PARAMETERS& tdParams = pad->GetTeardropParams();
|
|
|
|
int annularWidth = std::min( pad->GetSize().x, pad->GetSize().y );
|
2022-01-17 15:28:28 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !tdParams.m_Enabled )
|
|
|
|
continue;
|
2022-01-16 09:24:23 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// Ensure a teardrop shape can be built: track width must be < teardrop width and
|
|
|
|
// filter width
|
|
|
|
if( track->GetWidth() >= tdParams.m_TdMaxWidth
|
|
|
|
|| track->GetWidth() >= annularWidth * tdParams.m_BestWidthRatio
|
|
|
|
|| track->GetWidth() >= annularWidth * tdParams.m_WidthtoSizeFilterRatio )
|
2023-05-11 14:46:58 +00:00
|
|
|
{
|
2021-11-02 09:18:58 +00:00
|
|
|
continue;
|
2023-05-11 14:46:58 +00:00
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( pad->HitTest( track->GetStart() ) && pad->HitTest( track->GetEnd() ) )
|
|
|
|
// The track is entirely inside the pad; cannot create a teardrop
|
2022-01-30 14:32:38 +00:00
|
|
|
continue;
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// Skip case where pad and the track are within a copper zone with the same net
|
|
|
|
// (and the pad can be connected to the zone)
|
|
|
|
if( !tdParams.m_TdOnPadsInZones && areItemsInSameZone( pad, track ) )
|
2021-11-02 09:18:58 +00:00
|
|
|
continue;
|
|
|
|
|
2021-12-19 09:30:31 +00:00
|
|
|
std::vector<VECTOR2I> points;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( computeTeardropPolygon( tdParams, points, track, pad, pad->GetPosition() ) )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
|
|
|
ZONE* new_teardrop = createTeardrop( TD_TYPE_PADVIA, points, track );
|
|
|
|
m_board->Add( new_teardrop, ADD_MODE::BULK_INSERT );
|
|
|
|
m_createdTdList.push_back( new_teardrop );
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
aCommit.Added( new_teardrop );
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( PCB_VIA* via : connectedVias )
|
|
|
|
{
|
|
|
|
if( !forceUpdate && !alg::contains( *dirtyPadsAndVias, via ) )
|
|
|
|
continue;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
TEARDROP_PARAMETERS tdParams = via->GetTeardropParams();
|
|
|
|
int annularWidth = via->GetWidth();
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !tdParams.m_Enabled )
|
|
|
|
continue;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// Ensure a teardrop shape can be built: track width must be < teardrop width and
|
|
|
|
// filter width
|
|
|
|
if( track->GetWidth() >= tdParams.m_TdMaxWidth
|
|
|
|
|| track->GetWidth() >= annularWidth * tdParams.m_BestWidthRatio
|
|
|
|
|| track->GetWidth() >= annularWidth * tdParams.m_WidthtoSizeFilterRatio )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2023-05-11 14:46:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( via->HitTest( track->GetStart() ) && via->HitTest( track->GetEnd() ) )
|
|
|
|
// The track is entirely inside the via; cannot create a teardrop
|
|
|
|
continue;
|
2023-05-12 08:06:20 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
std::vector<VECTOR2I> points;
|
|
|
|
|
|
|
|
if( computeTeardropPolygon( tdParams, points, track, via, via->GetPosition() ) )
|
|
|
|
{
|
|
|
|
ZONE* new_teardrop = createTeardrop( TD_TYPE_PADVIA, points, track );
|
|
|
|
m_board->Add( new_teardrop, ADD_MODE::BULK_INSERT );
|
|
|
|
m_createdTdList.push_back( new_teardrop );
|
2023-05-12 08:06:20 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
aCommit.Added( new_teardrop );
|
|
|
|
}
|
2023-05-11 14:46:58 +00:00
|
|
|
}
|
2023-05-12 21:03:54 +00:00
|
|
|
}
|
2023-05-11 14:46:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( ( aForceFullUpdate || !dirtyTracks->empty() )
|
|
|
|
&& m_prmsList->GetParameters( TARGET_TRACK )->m_Enabled )
|
|
|
|
{
|
|
|
|
AddTeardropsOnTracks( aCommit, dirtyTracks, aForceFullUpdate );
|
|
|
|
}
|
2023-05-11 14:46:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// Now set priority of teardrops now all teardrops are added
|
|
|
|
setTeardropPriorities();
|
|
|
|
}
|
2023-05-11 14:46:58 +00:00
|
|
|
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
void TEARDROP_MANAGER::DeleteTrackToTrackTeardrops( BOARD_COMMIT& aCommit )
|
|
|
|
{
|
|
|
|
std::vector<ZONE*> stale_teardrops;
|
2023-05-12 08:06:20 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
if( zone->IsTeardropArea() && zone->GetTeardropAreaType() == TEARDROP_TYPE::TD_TRACKEND )
|
|
|
|
stale_teardrops.push_back( zone );
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( ZONE* td : stale_teardrops )
|
|
|
|
{
|
|
|
|
m_board->Remove( td, REMOVE_MODE::BULK );
|
|
|
|
aCommit.Removed( td );
|
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TEARDROP_MANAGER::setTeardropPriorities()
|
|
|
|
{
|
2022-03-11 10:02:45 +00:00
|
|
|
// Note: a teardrop area is on only one layer, so using GetFirstLayer() is OK
|
|
|
|
// to know the zone layer of a teardrop
|
|
|
|
|
2021-11-02 09:18:58 +00:00
|
|
|
int priority_base = MAGIC_TEARDROP_ZONE_ID;
|
|
|
|
|
|
|
|
// The sort function to sort by increasing copper layers. Group by layers.
|
|
|
|
// For same layers sort by decreasing areas
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
bool operator()(ZONE* a, ZONE* b) const
|
|
|
|
{
|
2022-03-11 10:02:45 +00:00
|
|
|
if( a->GetFirstLayer() == b->GetFirstLayer() )
|
2021-11-02 09:18:58 +00:00
|
|
|
return a->GetOutlineArea() > b->GetOutlineArea();
|
|
|
|
|
2022-03-11 10:02:45 +00:00
|
|
|
return a->GetFirstLayer() < b->GetFirstLayer();
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
} compareLess;
|
|
|
|
|
|
|
|
for( ZONE* td: m_createdTdList )
|
|
|
|
td->CalculateOutlineArea();
|
|
|
|
|
|
|
|
std::sort( m_createdTdList.begin(), m_createdTdList.end(), compareLess );
|
|
|
|
|
|
|
|
int curr_layer = -1;
|
|
|
|
|
|
|
|
for( ZONE* td: m_createdTdList )
|
|
|
|
{
|
2022-03-11 10:02:45 +00:00
|
|
|
if( td->GetFirstLayer() != curr_layer )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
2022-03-11 10:02:45 +00:00
|
|
|
curr_layer = td->GetFirstLayer();
|
2021-11-02 09:18:58 +00:00
|
|
|
priority_base = MAGIC_TEARDROP_ZONE_ID;
|
|
|
|
}
|
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
td->SetAssignedPriority( priority_base++ );
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
void TEARDROP_MANAGER::AddTeardropsOnTracks( BOARD_COMMIT& aCommit,
|
|
|
|
const std::set<PCB_TRACK*>* aTracks,
|
|
|
|
bool aForceFullUpdate )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
|
|
|
|
TEARDROP_PARAMETERS params = *m_prmsList->GetParameters( TARGET_TRACK );
|
2021-11-02 09:18:58 +00:00
|
|
|
|
|
|
|
// Explore groups (a group is a set of tracks on the same layer and the same net):
|
2023-05-12 21:03:54 +00:00
|
|
|
for( auto& grp : m_trackLookupList.GetBuffer() )
|
2021-11-02 09:18:58 +00:00
|
|
|
{
|
|
|
|
int layer, netcode;
|
|
|
|
TRACK_BUFFER::GetNetcodeAndLayerFromIndex( grp.first, &layer, &netcode );
|
|
|
|
|
|
|
|
std::vector<PCB_TRACK*>* sublist = grp.second;
|
|
|
|
|
|
|
|
if( sublist->size() <= 1 ) // We need at least 2 track segments
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// The sort function to sort by increasing track widths
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
bool operator()(PCB_TRACK* a, PCB_TRACK* b) const
|
|
|
|
{ return a->GetWidth() < b->GetWidth(); }
|
|
|
|
} compareLess;
|
|
|
|
|
|
|
|
std::sort( sublist->begin(), sublist->end(), compareLess );
|
|
|
|
int min_width = sublist->front()->GetWidth();
|
|
|
|
int max_width = sublist->back()->GetWidth();
|
|
|
|
|
|
|
|
// Skip groups having the same track thickness
|
|
|
|
if( max_width == min_width )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < sublist->size()-1; ii++ )
|
|
|
|
{
|
|
|
|
PCB_TRACK* track = (*sublist)[ii];
|
2023-05-12 21:03:54 +00:00
|
|
|
int track_len = (int) track->GetLength();
|
|
|
|
bool track_needs_update = aForceFullUpdate || alg::contains( *aTracks, track );
|
2021-11-02 09:18:58 +00:00
|
|
|
min_width = track->GetWidth();
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// to avoid creating a teardrop between 2 tracks having similar widths give a threshold
|
|
|
|
params.m_WidthtoSizeFilterRatio = std::max( params.m_WidthtoSizeFilterRatio, 0.1 );
|
|
|
|
const double th = 1.0 / params.m_WidthtoSizeFilterRatio;
|
|
|
|
min_width = KiROUND( min_width * th );
|
2021-11-02 09:18:58 +00:00
|
|
|
|
|
|
|
for( unsigned jj = ii+1; jj < sublist->size(); jj++ )
|
|
|
|
{
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
// Search candidates with thickness > curr thickness
|
2021-11-02 09:18:58 +00:00
|
|
|
PCB_TRACK* candidate = (*sublist)[jj];
|
|
|
|
|
|
|
|
if( min_width >= candidate->GetWidth() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Cannot build a teardrop on a too short track segment.
|
|
|
|
// The min len is > candidate radius
|
|
|
|
if( track_len <= candidate->GetWidth() /2 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Now test end to end connection:
|
|
|
|
EDA_ITEM_FLAGS match_points; // to return the end point EDA_ITEM_FLAGS:
|
|
|
|
// 0, STARTPOINT, ENDPOINT
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
VECTOR2I pos = candidate->GetStart();
|
|
|
|
match_points = track->IsPointOnEnds( pos, m_tolerance );
|
2021-11-02 09:18:58 +00:00
|
|
|
|
|
|
|
if( !match_points )
|
|
|
|
{
|
2023-05-12 21:03:54 +00:00
|
|
|
pos = candidate->GetEnd();
|
|
|
|
match_points = track->IsPointOnEnds( pos, m_tolerance );
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !match_points )
|
|
|
|
continue;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( !track_needs_update && alg::contains( *aTracks, candidate ) )
|
|
|
|
continue;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
// Pads/vias have priority for teardrops; ensure there isn't one at our position
|
|
|
|
bool existingPadOrVia = false;
|
|
|
|
std::vector<PAD*> connectedPads;
|
|
|
|
std::vector<PCB_VIA*> connectedVias;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( PAD* pad : connectedPads )
|
|
|
|
{
|
|
|
|
if( pad->HitTest( pos ) )
|
|
|
|
existingPadOrVia = true;
|
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
for( PCB_VIA* via : connectedVias )
|
|
|
|
{
|
|
|
|
if( via->HitTest( pos ) )
|
|
|
|
existingPadOrVia = true;
|
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( existingPadOrVia )
|
|
|
|
continue;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
std::vector<VECTOR2I> points;
|
2021-11-02 09:18:58 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
if( computeTeardropPolygon( params, points, track, candidate, pos ) )
|
|
|
|
{
|
|
|
|
ZONE* new_teardrop = createTeardrop( TD_TYPE_TRACKEND, points, track );
|
|
|
|
m_board->Add( new_teardrop, ADD_MODE::BULK_INSERT );
|
|
|
|
m_createdTdList.push_back( new_teardrop );
|
2022-09-29 16:07:42 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
aCommit.Added( new_teardrop );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-02 09:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
|