KiCad PCB EDA Suite
Loading...
Searching...
No Matches
teardrop.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef TEARDROP_H
22#define TEARDROP_H
23
24#include <unordered_map>
25
26#include <tool/tool_manager.h>
27#include <board.h>
28#include <drc/drc_rtree.h>
30#include "teardrop_parameters.h"
31
32class BOARD;
33class PCB_TRACK;
34class ZONE;
35
36
37// A class to store tracks grouped by layer and netcode
39{
40public:
42
46 void AddTrack( PCB_TRACK* aTrack, int aLayer, int aNetcode );
47
51 std::map<int, std::vector<PCB_TRACK*>>& GetBuffer() { return m_map_tracks; }
52
53 static void GetNetcodeAndLayerFromIndex( int aIdx, int* aLayer, int* aNetcode )
54 {
55 *aLayer = aIdx & 0xFF;
56 *aNetcode = aIdx >> 8;
57 }
58
59private:
60 // Build an index from the layer id and the netcode, to store a track in buffer
61 int idxFromLayNet( int aLayer, int aNetcode ) const
62 {
63 return ( aNetcode << 8 ) + ( aLayer & 0xFF );
64 }
65
66 // Track buffer, tracks are grouped by layer+netcode
67 std::map<int, std::vector<PCB_TRACK*>> m_map_tracks;
68};
69
70
87{
88 friend class TEARDROP_PARAMETERS;
89
90public:
92 {
93 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
94 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
95 };
96
97 TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager );
98
103 void RemoveTeardrops( BOARD_COMMIT& aCommit, std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
104 std::set<PCB_TRACK*>* dirtyTracks,
105 const std::vector<BOARD_ITEM*>* dirtyCopper = nullptr );
109 void UpdateTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
110 const std::set<PCB_TRACK*>* dirtyTracks, bool aForceFullUpdate = false );
111
120 void AddTeardropsOnTracks( BOARD_COMMIT& aCommit, const std::set<PCB_TRACK*>* aTracks,
121 bool aForceFullUpdate = false, bool aSetPriorities = true );
122
124
125 static int GetWidth( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
126 static bool IsRound( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
127 static bool IsUniformlyRound( BOARD_ITEM* aItem );
128
129 void BuildTrackCaches();
130
131private:
135 bool areItemsInSameZone( BOARD_ITEM* aPadOrVia, PCB_TRACK* aTrack) const;
136
141 const std::vector<std::set<const BOARD_ITEM*>>& zoneConnections( ZONE* aZone,
142 PCB_LAYER_ID aLayer ) const;
143
146 static int copperNetcode( const BOARD_ITEM* aItem );
147
150 int pairClearance( PCB_TRACK* aSourceTrack, BOARD_ITEM* aItem,
151 PCB_LAYER_ID aLayer ) const;
152
155 void ensureCopperIndex() const;
156
165 bool collidesWithOtherNets( const std::vector<VECTOR2I>& aPoints, PCB_TRACK* aSourceTrack,
166 const std::vector<const BOARD_ITEM*>& aExempt ) const;
167
174 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack,
175 PCB_TRACK* aSourceTrack, BOARD_ITEM* aOther,
176 const VECTOR2I& aOtherPos ) const;
177
180 int computeChordThroughShape( PCB_TRACK* aTrack, BOARD_ITEM* aOther, PCB_LAYER_ID aLayer,
181 const VECTOR2I& aInsidePoint ) const;
182
190 std::vector<VECTOR2I>& aPoly, PCB_LAYER_ID aLayer,
191 int aTrackHalfWidth,
192 const VECTOR2D& aTrackDir, BOARD_ITEM* aOther,
193 const VECTOR2I& aOtherPos, std::vector<VECTOR2I>& aPts ) const;
194
195
203 std::vector<VECTOR2I>& aPoly, int aTdWidth,
204 int aTrackHalfWidth, std::vector<VECTOR2I>& aPts,
205 const VECTOR2I& aIntersection, BOARD_ITEM* aOther,
206 const VECTOR2I& aOtherPos, PCB_LAYER_ID aLayer ) const;
207
213 bool computeTeardropPolygon( const TEARDROP_PARAMETERS& aParams,
214 std::vector<VECTOR2I>& aCorners, PCB_TRACK* aTrack,
215 PCB_TRACK* aSourceTrack, BOARD_ITEM* aOther,
216 const VECTOR2I& aOtherPos ) const;
233 bool computeAnchorPoints( const TEARDROP_PARAMETERS& aParams, PCB_LAYER_ID aLayer,
234 BOARD_ITEM* aItem, const VECTOR2I& aPos,
235 std::vector<VECTOR2I>& aPts ) const;
236
245 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
246 PCB_TRACK* aSourceTrack, const VECTOR2I& aEndPoint ) const;
247
255 static KIID teardropUuid( const PCB_TRACK* aTrack, const BOARD_ITEM* aCandidate, int aSlot );
256
259 static KIID maskUuidFor( const KIID& aCopperUuid );
260
263 static void buildCrossingStub( PCB_TRACK& aStub, const PCB_TRACK* aTrack, const VECTOR2I& aCrossedPos );
264
272 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
273 PCB_TRACK* aSourceTrack, const KIID& aUuid ) const;
274
275 ZONE* createTeardropMask( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
276 PCB_TRACK* aSourceTrack, const KIID& aUuid ) const;
277
286 void createAndAddTeardropWithMask( BOARD_COMMIT& aCommit, TEARDROP_VARIANT aTeardropVariant,
287 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aSourceTrack,
288 const KIID& aUuid );
289
302 bool tryCreateTrackTeardrop( BOARD_COMMIT& aCommit, const TEARDROP_PARAMETERS& aParams,
303 TEARDROP_VARIANT aTeardropVariant, PCB_TRACK* aTrack,
304 PCB_TRACK* aSourceTrack, BOARD_ITEM* aCandidate,
305 const VECTOR2I& aPos, const KIID& aUuid );
306
311
326 bool findAnchorPointsOnTrack( const TEARDROP_PARAMETERS& aParams, VECTOR2I& aStartPoint,
327 VECTOR2I& aEndPoint, VECTOR2I& aIntersection,
328 PCB_TRACK*& aTrack, PCB_TRACK* aSourceTrack, BOARD_ITEM* aOther,
329 const VECTOR2I& aOtherPos, int* aEffectiveTeardropLen ) const;
330
331private:
332 int m_tolerance; // max dist between track end point and pad/via
333 // center to see them connected to ut a teardrop
336 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
337
340 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
341
343 std::map<PCB_LAYER_ID, KIRTREE::DYNAMIC_RTREE<ZONE*, int, 2>> m_createdTdRTree;
344
347 mutable bool m_copperIndexed;
348
349 mutable std::unordered_map<PTR_LAYER_CACHE_KEY, std::vector<std::set<const BOARD_ITEM*>>>
351
352 mutable std::unordered_map<PTR_PTR_LAYER_CACHE_KEY, int> m_pairClearanceCache;
353};
354
355#endif // ifndef TEARDROP_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition drc_rtree.h:46
Definition kiid.h:46
BOARD * m_board
Definition teardrop.h:334
PCB_TRACK * findTouchingTrack(EDA_ITEM_FLAGS &aMatchType, PCB_TRACK *aTrackRef, PCB_TRACK *aSourceTrack, const VECTOR2I &aEndPoint) const
Find a track connected to the end of another track.
std::map< PCB_LAYER_ID, KIRTREE::DYNAMIC_RTREE< ZONE *, int, 2 > > m_createdTdRTree
The teardrops of this pass by layer, since m_copperRTree cannot take inserts once built.
Definition teardrop.h:343
static bool IsRound(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
ZONE * createTeardropMask(TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aSourceTrack, const KIID &aUuid) const
Definition teardrop.cpp:149
static bool IsUniformlyRound(BOARD_ITEM *aItem)
bool computeAnchorPoints(const TEARDROP_PARAMETERS &aParams, PCB_LAYER_ID aLayer, BOARD_ITEM *aItem, const VECTOR2I &aPos, std::vector< VECTOR2I > &aPts) const
Compute the 2 points on pad/via of the teardrop shape.
static int GetWidth(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
std::unordered_map< PTR_PTR_LAYER_CACHE_KEY, int > m_pairClearanceCache
Definition teardrop.h:352
bool computeTeardropPolygon(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aCorners, PCB_TRACK *aTrack, PCB_TRACK *aSourceTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos) const
Compute all teardrop points of the polygon shape.
static int copperNetcode(const BOARD_ITEM *aItem)
TEARDROP_MANAGER(BOARD *aBoard, TOOL_MANAGER *aToolManager)
Definition teardrop.cpp:48
std::unordered_map< PTR_LAYER_CACHE_KEY, std::vector< std::set< const BOARD_ITEM * > > > m_zoneConnectionCache
Definition teardrop.h:350
DRC_RTREE m_copperRTree
Every copper item on the board before this pass, to keep teardrops off other nets.
Definition teardrop.h:346
void computeCurvedForRectShape(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aPoly, int aTdWidth, int aTrackHalfWidth, std::vector< VECTOR2I > &aPts, const VECTOR2I &aIntersection, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, PCB_LAYER_ID aLayer) const
Compute the curve part points for teardrops connected to a rectangular/polygonal shape The Bezier cur...
static KIID teardropUuid(const PCB_TRACK *aTrack, const BOARD_ITEM *aCandidate, int aSlot)
Build the UUID a teardrop is created with.
Definition teardrop.cpp:58
static KIID maskUuidFor(const KIID &aCopperUuid)
Build the UUID of the mask sibling of aCopperUuid.
Definition teardrop.cpp:72
ZONE * createTeardrop(TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aSourceTrack, const KIID &aUuid) const
Creates a teardrop (a ZONE item) from its polygonal shape, track netcode and layer.
Definition teardrop.cpp:107
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.
Definition teardrop.cpp:437
void computeCurvedForRoundShape(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aPoly, PCB_LAYER_ID aLayer, int aTrackHalfWidth, const VECTOR2D &aTrackDir, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, std::vector< VECTOR2I > &aPts) const
Compute the curve part points for teardrops connected to a round shape The Bezier curve control point...
void RemoveTeardrops(BOARD_COMMIT &aCommit, std::vector< BOARD_ITEM * > *dirtyPadsAndVias, std::set< PCB_TRACK * > *dirtyTracks, const std::vector< BOARD_ITEM * > *dirtyCopper=nullptr)
Remove teardrops on dirty pads, vias or tracks, and any whose neighbouring copper moved,...
Definition teardrop.cpp:243
void setTeardropPriorities()
Set priority of created teardrops.
Definition teardrop.cpp:631
int pairClearance(PCB_TRACK *aSourceTrack, BOARD_ITEM *aItem, PCB_LAYER_ID aLayer) const
TRACK_BUFFER m_trackLookupList
Definition teardrop.h:339
void AddTeardropsOnTracks(BOARD_COMMIT &aCommit, const std::set< PCB_TRACK * > *aTracks, bool aForceFullUpdate=false, bool aSetPriorities=true)
Add teardrop on tracks of different sizes connected by their end.
Definition teardrop.cpp:697
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition teardrop.h:336
std::vector< ZONE * > m_createdTdList
Definition teardrop.h:340
bool collidesWithOtherNets(const std::vector< VECTOR2I > &aPoints, PCB_TRACK *aSourceTrack, const std::vector< const BOARD_ITEM * > &aExempt) const
bool findAnchorPointsOnTrack(const TEARDROP_PARAMETERS &aParams, VECTOR2I &aStartPoint, VECTOR2I &aEndPoint, VECTOR2I &aIntersection, PCB_TRACK *&aTrack, PCB_TRACK *aSourceTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, int *aEffectiveTeardropLen) const
void DeleteTrackToTrackTeardrops(BOARD_COMMIT &aCommit)
Definition teardrop.cpp:619
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
bool tryCreateTrackTeardrop(BOARD_COMMIT &aCommit, const TEARDROP_PARAMETERS &aParams, TEARDROP_VARIANT aTeardropVariant, PCB_TRACK *aTrack, PCB_TRACK *aSourceTrack, BOARD_ITEM *aCandidate, const VECTOR2I &aPos, const KIID &aUuid)
Attempts to create a track-to-track teardrop.
Definition teardrop.cpp:224
bool computeFittedTeardropPolygon(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aTrack, PCB_TRACK *aSourceTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos) const
Widen a teardrop as far as the surrounding copper allows.
void ensureCopperIndex() const
Build the copper collision index, deferred so a commit with no teardrop candidate never pays for it.
DRC_RTREE m_tracksRTree
Definition teardrop.h:338
friend class TEARDROP_PARAMETERS
Definition teardrop.h:88
TOOL_MANAGER * m_toolManager
Definition teardrop.h:335
void createAndAddTeardropWithMask(BOARD_COMMIT &aCommit, TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aSourceTrack, const KIID &aUuid)
Creates and adds a teardrop with optional mask to the board.
Definition teardrop.cpp:196
int computeChordThroughShape(PCB_TRACK *aTrack, BOARD_ITEM *aOther, PCB_LAYER_ID aLayer, const VECTOR2I &aInsidePoint) const
Return the centerline chord length through aOther's copper span at aInsidePoint.
const std::vector< std::set< const BOARD_ITEM * > > & zoneConnections(ZONE *aZone, PCB_LAYER_ID aLayer) const
static void buildCrossingStub(PCB_TRACK &aStub, const PCB_TRACK *aTrack, const VECTOR2I &aCrossedPos)
Set aStub up as the segment from one end of aTrack to the point of aTrack nearest aCrossedPos,...
Definition teardrop.cpp:81
TEARDROP_PARAMETERS_LIST is a helper class to handle the list of TEARDROP_PARAMETERS needed to build ...
TEARDROP_PARAMETARS is a helper class to handle parameters needed to build teardrops for a board thes...
Master controller class:
int idxFromLayNet(int aLayer, int aNetcode) const
Definition teardrop.h:61
void AddTrack(PCB_TRACK *aTrack, int aLayer, int aNetcode)
Add a track in buffer, in space grouping tracks having the same netcode and the same layer.
std::map< int, std::vector< PCB_TRACK * > > & GetBuffer()
Definition teardrop.h:51
std::map< int, std::vector< PCB_TRACK * > > m_map_tracks
Definition teardrop.h:67
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
Definition teardrop.h:53
Handle a list of polygons defining a copper zone.
Definition zone.h:70
std::uint32_t EDA_ITEM_FLAGS
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707