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>
29#include "teardrop_parameters.h"
30
31class BOARD;
32class PCB_TRACK;
33class ZONE;
34
35
36// A class to store tracks grouped by layer and netcode
38{
39public:
41
45 void AddTrack( PCB_TRACK* aTrack, int aLayer, int aNetcode );
46
50 std::map<int, std::vector<PCB_TRACK*>>& GetBuffer() { return m_map_tracks; }
51
52 static void GetNetcodeAndLayerFromIndex( int aIdx, int* aLayer, int* aNetcode )
53 {
54 *aLayer = aIdx & 0xFF;
55 *aNetcode = aIdx >> 8;
56 }
57
58private:
59 // Build an index from the layer id and the netcode, to store a track in buffer
60 int idxFromLayNet( int aLayer, int aNetcode ) const
61 {
62 return ( aNetcode << 8 ) + ( aLayer & 0xFF );
63 }
64
65 // Track buffer, tracks are grouped by layer+netcode
66 std::map<int, std::vector<PCB_TRACK*>> m_map_tracks;
67};
68
69
86{
87 friend class TEARDROP_PARAMETERS;
88
89public:
91 {
92 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
93 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
94 };
95
96 TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager );
97
102 void RemoveTeardrops( BOARD_COMMIT& aCommit, std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
103 std::set<PCB_TRACK*>* dirtyTracks,
104 const std::vector<BOARD_ITEM*>* dirtyCopper = nullptr );
108 void UpdateTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
109 const std::set<PCB_TRACK*>* dirtyTracks, bool aForceFullUpdate = false );
110
115 void AddTeardropsOnTracks( BOARD_COMMIT& aCommit, const std::set<PCB_TRACK*>* aTracks,
116 bool aForceFullUpdate = false, bool aSetPriorities = true );
117
119
120 static int GetWidth( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
121 static bool IsRound( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
122 static bool IsUniformlyRound( BOARD_ITEM* aItem );
123
124 void BuildTrackCaches();
125
126private:
130 bool areItemsInSameZone( BOARD_ITEM* aPadOrVia, PCB_TRACK* aTrack) const;
131
136 const std::vector<std::set<const BOARD_ITEM*>>& zoneConnections( ZONE* aZone,
137 PCB_LAYER_ID aLayer ) const;
138
141 static int copperNetcode( const BOARD_ITEM* aItem );
142
145 int pairClearance( PCB_TRACK* aSourceTrack, BOARD_ITEM* aItem,
146 PCB_LAYER_ID aLayer ) const;
147
150 void ensureCopperIndex() const;
151
157 bool collidesWithOtherNets( const std::vector<VECTOR2I>& aPoints, PCB_TRACK* aSourceTrack,
158 const std::vector<const BOARD_ITEM*>& aExempt ) const;
159
166 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack,
167 PCB_TRACK* aSourceTrack, BOARD_ITEM* aOther,
168 const VECTOR2I& aOtherPos ) const;
169
172 int computeChordThroughShape( PCB_TRACK* aTrack, BOARD_ITEM* aOther, PCB_LAYER_ID aLayer,
173 const VECTOR2I& aInsidePoint ) const;
174
182 std::vector<VECTOR2I>& aPoly, PCB_LAYER_ID aLayer,
183 int aTrackHalfWidth,
184 const VECTOR2D& aTrackDir, BOARD_ITEM* aOther,
185 const VECTOR2I& aOtherPos, std::vector<VECTOR2I>& aPts ) const;
186
187
195 std::vector<VECTOR2I>& aPoly, int aTdWidth,
196 int aTrackHalfWidth, std::vector<VECTOR2I>& aPts,
197 const VECTOR2I& aIntersection, BOARD_ITEM* aOther,
198 const VECTOR2I& aOtherPos, PCB_LAYER_ID aLayer ) const;
199
205 bool computeTeardropPolygon( const TEARDROP_PARAMETERS& aParams,
206 std::vector<VECTOR2I>& aCorners, PCB_TRACK* aTrack,
207 PCB_TRACK* aSourceTrack, BOARD_ITEM* aOther,
208 const VECTOR2I& aOtherPos ) const;
223 bool computeAnchorPoints( const TEARDROP_PARAMETERS& aParams, PCB_LAYER_ID aLayer,
224 BOARD_ITEM* aItem, const VECTOR2I& aPos,
225 std::vector<VECTOR2I>& aPts ) const;
226
236 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
237 PCB_TRACK* aSourceTrack, const VECTOR2I& aEndPoint ) const;
238
243 static KIID teardropUuid( const PCB_TRACK* aTrack, const BOARD_ITEM* aCandidate, int aSlot );
244
247 static KIID maskUuidFor( const KIID& aCopperUuid );
248
251 static void buildCrossingStub( PCB_TRACK& aStub, const PCB_TRACK* aTrack,
252 const VECTOR2I& aEnd );
253
261 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
262 PCB_TRACK* aSourceTrack, const KIID& aUuid ) const;
263
264 ZONE* createTeardropMask( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
265 PCB_TRACK* aSourceTrack, const KIID& aUuid ) const;
266
275 void createAndAddTeardropWithMask( BOARD_COMMIT& aCommit, TEARDROP_VARIANT aTeardropVariant,
276 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aSourceTrack,
277 const KIID& aUuid );
278
291 bool tryCreateTrackTeardrop( BOARD_COMMIT& aCommit, const TEARDROP_PARAMETERS& aParams,
292 TEARDROP_VARIANT aTeardropVariant, PCB_TRACK* aTrack,
293 PCB_TRACK* aSourceTrack, BOARD_ITEM* aCandidate,
294 const VECTOR2I& aPos, const KIID& aUuid );
295
300
316 bool findAnchorPointsOnTrack( const TEARDROP_PARAMETERS& aParams, VECTOR2I& aStartPoint,
317 VECTOR2I& aEndPoint, VECTOR2I& aIntersection,
318 PCB_TRACK*& aTrack, PCB_TRACK* aSourceTrack, BOARD_ITEM* aOther,
319 const VECTOR2I& aOtherPos, int* aEffectiveTeardropLen ) const;
320
321private:
322 int m_tolerance; // max dist between track end point and pad/via
323 // center to see them connected to ut a teardrop
326 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
327
330 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
331
334 mutable bool m_copperIndexed;
335
336 mutable std::unordered_map<PTR_LAYER_CACHE_KEY, std::vector<std::set<const BOARD_ITEM*>>>
338
339 mutable std::unordered_map<PTR_PTR_LAYER_CACHE_KEY, int> m_pairClearanceCache;
340};
341
342#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:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition drc_rtree.h:45
Definition kiid.h:46
BOARD * m_board
Definition teardrop.h:324
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.
static void buildCrossingStub(PCB_TRACK &aStub, const PCB_TRACK *aTrack, const VECTOR2I &aEnd)
Set aStub up as the segment from one end of aTrack to aEnd, for a track that crosses the pad or via i...
Definition teardrop.cpp:81
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:137
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:339
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:337
DRC_RTREE m_copperRTree
Every copper item plus the teardrops built so far, to keep teardrops off other nets.
Definition teardrop.h:333
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:95
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:422
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:228
void setTeardropPriorities()
Set priority of created teardrops.
Definition teardrop.cpp:616
int pairClearance(PCB_TRACK *aSourceTrack, BOARD_ITEM *aItem, PCB_LAYER_ID aLayer) const
TRACK_BUFFER m_trackLookupList
Definition teardrop.h:329
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:682
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition teardrop.h:326
std::vector< ZONE * > m_createdTdList
Definition teardrop.h:330
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:604
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:209
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:328
friend class TEARDROP_PARAMETERS
Definition teardrop.h:87
TOOL_MANAGER * m_toolManager
Definition teardrop.h:325
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:184
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
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:60
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:50
std::map< int, std::vector< PCB_TRACK * > > m_map_tracks
Definition teardrop.h:66
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
Definition teardrop.h:52
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:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682