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 )
104 std::vector<ZONE*> stale_teardrops;
108 if( zone->IsTeardropArea() )
112 std::vector<PAD*> connectedPads;
113 std::vector<PCB_VIA*> connectedVias;
115 connectivity->GetConnectedPadsAndVias( zone, &connectedPads, &connectedVias );
117 for(
PAD*
pad : connectedPads )
139 stale_teardrops.push_back( zone );
143 for(
ZONE* td : stale_teardrops )
152 const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
153 const std::set<PCB_TRACK*>* dirtyTracks,
154 bool aForceFullUpdate )
165 if( aForceFullUpdate )
167 std::vector<ZONE*> teardrops;
171 if( zone->IsTeardropArea() )
172 teardrops.push_back( zone );
175 for(
ZONE* td : teardrops )
189 std::vector<PAD*> connectedPads;
190 std::vector<PCB_VIA*> connectedVias;
192 connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
194 bool forceUpdate = aForceFullUpdate || dirtyTracks->contains( track );
196 for(
PAD*
pad : connectedPads )
202 VECTOR2I padSize =
pad->GetSize( track->GetLayer() );
203 int annularWidth = std::min( padSize.
x, padSize.
y );
217 if(
pad->HitTest( track->GetStart() ) &&
pad->HitTest( track->GetEnd() ) )
226 std::vector<VECTOR2I> points;
231 m_board->
Add( new_teardrop, ADD_MODE::BULK_INSERT );
234 aCommit.
Added( new_teardrop );
244 int annularWidth =
via->GetWidth( track->GetLayer() );
258 if(
via->HitTest( track->GetStart() ) &&
via->HitTest( track->GetEnd() ) )
262 std::vector<VECTOR2I> points;
267 m_board->
Add( new_teardrop, ADD_MODE::BULK_INSERT );
270 aCommit.
Added( new_teardrop );
275 if( ( aForceFullUpdate || !dirtyTracks->empty() )
288 std::vector<ZONE*> stale_teardrops;
292 if( zone->IsTeardropArea() && zone->GetTeardropAreaType() == TEARDROP_TYPE::TD_TRACKEND )
293 stale_teardrops.push_back( zone );
296 for(
ZONE* td : stale_teardrops )
315 bool operator()(
ZONE* a,
ZONE* b)
const
325 td->CalculateOutlineArea();
333 if( td->GetFirstLayer() != curr_layer )
335 curr_layer = td->GetFirstLayer();
339 td->SetAssignedPriority( priority_base++ );
345 const std::set<PCB_TRACK*>* aTracks,
346 bool aForceFullUpdate )
357 std::vector<PCB_TRACK*>* sublist = grp.second;
359 if( sublist->size() <= 1 )
369 std::sort( sublist->begin(), sublist->end(), compareLess );
370 int min_width = sublist->front()->GetWidth();
371 int max_width = sublist->back()->GetWidth();
374 if( max_width == min_width )
377 for(
unsigned ii = 0; ii < sublist->size()-1; ii++ )
380 int track_len = (int) track->
GetLength();
381 bool track_needs_update = aForceFullUpdate ||
alg::contains( *aTracks, track );
387 min_width =
KiROUND( min_width * th );
389 for(
unsigned jj = ii+1; jj < sublist->size(); jj++ )
394 if( min_width >= candidate->
GetWidth() )
399 if( track_len <= candidate->
GetWidth() /2 )
411 pos = candidate->
GetEnd();
418 if( !track_needs_update &&
alg::contains( *aTracks, candidate ) )
422 bool existingPadOrVia =
false;
423 std::vector<PAD*> connectedPads;
424 std::vector<PCB_VIA*> connectedVias;
426 connectivity->GetConnectedPadsAndVias( track, &connectedPads, &connectedVias );
428 for(
PAD*
pad : connectedPads )
430 if(
pad->HitTest( pos ) )
431 existingPadOrVia =
true;
436 if(
via->HitTest( pos ) )
437 existingPadOrVia =
true;
440 if( existingPadOrVia )
443 std::vector<VECTOR2I> points;
448 m_board->
Add( new_teardrop, ADD_MODE::BULK_INSERT );
451 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
const TRACKS & Tracks() const
bool LegacyTeardrops() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
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)
Remove a new item from the model.
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
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.
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)