38#include <geometry/rtree.h>
45#define MAGIC_TEARDROP_ZONE_ID 30000
50 m_toolManager( aToolManager )
58 std::vector<VECTOR2I>& aPoints,
PCB_TRACK* aTrack )
const
68 : TEARDROP_TYPE::TD_TRACKEND );
85 outline->
Append( pt.x, pt.y );
100 const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
101 const std::set<PCB_TRACK*>* dirtyTracks )
108 std::vector<PAD*> connectedPads;
109 std::vector<PCB_VIA*> connectedVias;
111 connectivity->GetConnectedPadsAndVias( zone, &connectedPads, &connectedVias );
113 for(
PAD*
pad : connectedPads )
125 for(
PCB_TRACK* track : connectivity->GetConnectedTracks( zone ) )
136 if( zone->IsTeardropArea() && isStale( zone ) )
145 const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
146 const std::set<PCB_TRACK*>* dirtyTracks,
147 bool aForceFullUpdate )
158 if( aForceFullUpdate )
162 if( zone->IsTeardropArea() )
176 std::vector<PAD*> connectedPads;
177 std::vector<PCB_VIA*> connectedVias;
179 connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
181 bool forceUpdate = aForceFullUpdate || dirtyTracks->contains( track );
183 for(
PAD*
pad : connectedPads )
189 VECTOR2I padSize =
pad->GetSize( track->GetLayer() );
190 int annularWidth = std::min( padSize.
x, padSize.
y );
204 if(
pad->HitTest( track->GetStart() ) &&
pad->HitTest( track->GetEnd() ) )
213 std::vector<VECTOR2I> points;
218 m_board->
Add( new_teardrop, ADD_MODE::BULK_INSERT );
221 aCommit.
Added( new_teardrop );
231 int annularWidth =
via->GetWidth( track->GetLayer() );
245 if(
via->HitTest( track->GetStart() ) &&
via->HitTest( track->GetEnd() ) )
249 std::vector<VECTOR2I> points;
254 m_board->
Add( new_teardrop, ADD_MODE::BULK_INSERT );
257 aCommit.
Added( new_teardrop );
262 if( ( aForceFullUpdate || !dirtyTracks->empty() )
277 if( zone->IsTeardropArea() && zone->GetTeardropAreaType() == TEARDROP_TYPE::TD_TRACKEND )
296 bool operator()(
ZONE* a,
ZONE* b)
const
306 td->CalculateOutlineArea();
314 if( td->GetFirstLayer() != curr_layer )
316 curr_layer = td->GetFirstLayer();
320 td->SetAssignedPriority( priority_base++ );
326 const std::set<PCB_TRACK*>* aTracks,
327 bool aForceFullUpdate )
338 std::vector<PCB_TRACK*>* sublist = grp.second;
340 if( sublist->size() <= 1 )
350 std::sort( sublist->begin(), sublist->end(), compareLess );
351 int min_width = sublist->front()->GetWidth();
352 int max_width = sublist->back()->GetWidth();
355 if( max_width == min_width )
358 for(
unsigned ii = 0; ii < sublist->size()-1; ii++ )
361 int track_len = (int) track->
GetLength();
362 bool track_needs_update = aForceFullUpdate ||
alg::contains( *aTracks, track );
368 min_width =
KiROUND( min_width * th );
370 for(
unsigned jj = ii+1; jj < sublist->size(); jj++ )
375 if( min_width >= candidate->
GetWidth() )
380 if( track_len <= candidate->
GetWidth() /2 )
392 pos = candidate->
GetEnd();
399 if( !track_needs_update &&
alg::contains( *aTracks, candidate ) )
403 bool existingPadOrVia =
false;
404 std::vector<PAD*> connectedPads;
405 std::vector<PCB_VIA*> connectedVias;
407 connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
409 for(
PAD*
pad : connectedPads )
411 if(
pad->HitTest( pos ) )
412 existingPadOrVia =
true;
417 if(
via->HitTest( pos ) )
418 existingPadOrVia =
true;
421 if( existingPadOrVia )
424 std::vector<VECTOR2I> points;
429 m_board->
Add( new_teardrop, ADD_MODE::BULK_INSERT );
432 aCommit.
Added( new_teardrop );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
TEARDROP_PARAMETERS_LIST * GetTeadropParamsList()
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
const ZONES & Zones() const
void BulkRemoveStaleTeardrops(BOARD_COMMIT &aCommit)
Remove all teardrop zones with the STRUCT_DELETED flag set.
const TRACKS & Tracks() const
bool LegacyTeardrops() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
virtual double GetLength() const
Get the length of the track using the hypotenuse calculation.
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...
virtual int GetWidth() const
Represent a set of closed polygons.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
static int GetWidth(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
bool computeTeardropPolygon(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aCorners, PCB_TRACK *aTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos) const
Compute all teardrop points of the polygon shape.
TEARDROP_MANAGER(BOARD *aBoard, TOOL_MANAGER *aToolManager)
void UpdateTeardrops(BOARD_COMMIT &aCommit, const std::vector< BOARD_ITEM * > *dirtyPadsAndVias, const std::set< PCB_TRACK * > *dirtyTracks, bool aForceFullUpdate=false)
Update teardrops on a list of items.
void setTeardropPriorities()
Set priority of created teardrops.
void AddTeardropsOnTracks(BOARD_COMMIT &aCommit, const std::set< PCB_TRACK * > *aTracks, bool aForceFullUpdate=false)
Add teardrop on tracks of different sizes connected by their end.
TRACK_BUFFER m_trackLookupList
TEARDROP_PARAMETERS_LIST * m_prmsList
std::vector< ZONE * > m_createdTdList
ZONE * createTeardrop(TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aTrack) const
Creates a teardrop (a ZONE item) from its polygonal shape, track netcode and layer.
void DeleteTrackToTrackTeardrops(BOARD_COMMIT &aCommit)
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
void RemoveTeardrops(BOARD_COMMIT &aCommit, const std::vector< BOARD_ITEM * > *dirtyPadsAndVias, const std::set< PCB_TRACK * > *dirtyTracks)
Remove teardrops connected to any dirty pads, vias or tracks.
TEARDROP_PARAMETERS * GetParameters(TARGET_TD aTdType)
TEARDROP_PARAMETARS is a helper class to handle parameters needed to build teardrops for a board thes...
double m_BestWidthRatio
The height of a teardrop as ratio between height and size of pad/via.
int m_TdMaxWidth
max allowed height for teardrops in IU. <= 0 to disable
double m_WidthtoSizeFilterRatio
The ratio (H/D) between the via/pad size and the track width max value to create a teardrop 1....
bool m_TdOnPadsInZones
A filter to exclude pads inside zone fills.
bool m_Enabled
Flag to enable teardrops.
const std::map< int, std::vector< PCB_TRACK * > * > & GetBuffer() const
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
static const ZONE_SETTINGS & GetDefaultSettings()
Handle a list of polygons defining a copper zone.
double GetOutlineArea()
This area is cached from the most recent call to CalculateOutlineArea().
void SetLocalClearance(std::optional< int > aClearance)
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuilBorderdHatch)
Set all hatch parameters for the zone.
void SetMinThickness(int aMinThickness)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
SHAPE_POLY_SET * Outline()
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
void SetIsFilled(bool isFilled)
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
void SetPadConnection(ZONE_CONNECTION aPadConnection)
void SetZoneName(const wxString &aName)
void SetTeardropAreaType(TEARDROP_TYPE aType)
Set the type of teardrop if the zone is a teardrop area for non teardrop area, the type must be TEARD...
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
PCB_LAYER_ID GetFirstLayer() const
This file is part of the common library.
#define STRUCT_DELETED
flag indication structures to be erased
std::uint32_t EDA_ITEM_FLAGS
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
constexpr int mmToIU(double mm) const
#define MAGIC_TEARDROP_ZONE_ID
#define MAGIC_TEARDROP_TRACK_NAME
#define MAGIC_TEARDROP_PADVIA_NAME
@ 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)