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 <tool/tool_manager.h>
25#include <drc/drc_rtree.h>
26#include "teardrop_parameters.h"
27
28class BOARD;
29class PCB_TRACK;
30class ZONE;
31
32
33// A class to store tracks grouped by layer and netcode
35{
36public:
38
42 void AddTrack( PCB_TRACK* aTrack, int aLayer, int aNetcode );
43
47 std::vector<PCB_TRACK*>* GetTrackList( int aLayer, int aNetcode ) const
48 {
49 return m_map_tracks.at( idxFromLayNet( aLayer, aNetcode ) );
50 }
51
55 const std::map< int, std::vector<PCB_TRACK*>* >& GetBuffer() const { return m_map_tracks; }
56
57 static void GetNetcodeAndLayerFromIndex( int aIdx, int* aLayer, int* aNetcode )
58 {
59 *aLayer = aIdx & 0xFF;
60 *aNetcode = aIdx >> 8;
61 }
62
63private:
64 // Build an index from the layer id and the netcode, to store a track in buffer
65 int idxFromLayNet( int aLayer, int aNetcode ) const
66 {
67 return ( aNetcode << 8 ) + ( aLayer & 0xFF );
68 }
69
70 // Track buffer, tracks are grouped by layer+netcode
71 std::map< int, std::vector<PCB_TRACK*>* > m_map_tracks;
72};
73
74
90{
91 friend class TEARDROP_PARAMETERS;
92
93public:
95 {
96 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
97 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
98 };
99
100 TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager );
101
108 void RemoveTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
109 const std::set<PCB_TRACK*>* dirtyTracks );
113 void UpdateTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
114 const std::set<PCB_TRACK*>* dirtyTracks, bool aForceFullUpdate = false );
115
119 void AddTeardropsOnTracks( BOARD_COMMIT& aCommit, const std::set<PCB_TRACK*>* aTracks,
120 bool aForceFullUpdate = false );
121
123
124 static int GetWidth( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
125 static bool IsRound( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
126
127 void BuildTrackCaches();
128
129private:
133 bool areItemsInSameZone( BOARD_ITEM* aPadOrVia, PCB_TRACK* aTrack) const;
134
142 int computeEmergingTrackLength( PCB_TRACK* aTrack, BOARD_ITEM* aOther,
143 PCB_LAYER_ID aLayer ) const;
144
152 std::vector<VECTOR2I>& aPoly, PCB_LAYER_ID aLayer,
153 int aTrackHalfWidth,
154 const VECTOR2D& aTrackDir, BOARD_ITEM* aOther,
155 const VECTOR2I& aOtherPos, std::vector<VECTOR2I>& aPts ) const;
156
157
165 std::vector<VECTOR2I>& aPoly, int aTdWidth,
166 int aTrackHalfWidth, std::vector<VECTOR2I>& aPts,
167 const VECTOR2I& aIntersection, BOARD_ITEM* aOther,
168 const VECTOR2I& aOtherPos, PCB_LAYER_ID aLayer ) const;
169
175 bool computeTeardropPolygon( const TEARDROP_PARAMETERS& aParams,
176 std::vector<VECTOR2I>& aCorners, PCB_TRACK* aTrack,
177 BOARD_ITEM* aOther, const VECTOR2I& aOtherPos ) const;
192 bool computeAnchorPoints( const TEARDROP_PARAMETERS& aParams, PCB_LAYER_ID aLayer,
193 BOARD_ITEM* aItem, const VECTOR2I& aPos,
194 std::vector<VECTOR2I>& aPts ) const;
195
204 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
205 const VECTOR2I& aEndPoint ) const;
206
215 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
216 PCB_TRACK* aTrack, BOARD_ITEM* aCandidate ) const;
217
218 ZONE* createTeardropMask( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
219 PCB_TRACK* aTrack, BOARD_ITEM* aCandidate ) const;
220
229 void createAndAddTeardropWithMask( BOARD_COMMIT& aCommit, TEARDROP_VARIANT aTeardropVariant,
230 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack,
231 BOARD_ITEM* aCandidate );
232
243 bool tryCreateTrackTeardrop( BOARD_COMMIT& aCommit, const TEARDROP_PARAMETERS& aParams,
244 TEARDROP_VARIANT aTeardropVariant, PCB_TRACK* aTrack,
245 BOARD_ITEM* aCandidate, const VECTOR2I& aPos );
246
251
267 bool findAnchorPointsOnTrack( const TEARDROP_PARAMETERS& aParams, VECTOR2I& aStartPoint,
268 VECTOR2I& aEndPoint, VECTOR2I& aIntersection,
269 PCB_TRACK*& aTrack, BOARD_ITEM* aOther, const VECTOR2I& aOtherPos,
270 int* aEffectiveTeardropLen ) const;
271
272private:
273 int m_tolerance; // max dist between track end point and pad/via
274 // center to see them connected to ut a teardrop
277 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
278
281 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
282};
283
284#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:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition drc_rtree.h:45
BOARD * m_board
Definition teardrop.h:275
static bool IsRound(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
ZONE * createTeardropMask(TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aTrack, BOARD_ITEM *aCandidate) const
Definition teardrop.cpp:96
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)
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)
Definition teardrop.cpp:43
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...
void createAndAddTeardropWithMask(BOARD_COMMIT &aCommit, TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aTrack, BOARD_ITEM *aCandidate)
Creates and adds a teardrop with optional mask to the board.
Definition teardrop.cpp:142
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:225
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...
PCB_TRACK * findTouchingTrack(EDA_ITEM_FLAGS &aMatchType, PCB_TRACK *aTrackRef, const VECTOR2I &aEndPoint) const
Find a track connected to the end of another track.
void setTeardropPriorities()
Set priority of created teardrops.
Definition teardrop.cpp:402
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.
Definition teardrop.cpp:446
bool tryCreateTrackTeardrop(BOARD_COMMIT &aCommit, const TEARDROP_PARAMETERS &aParams, TEARDROP_VARIANT aTeardropVariant, PCB_TRACK *aTrack, BOARD_ITEM *aCandidate, const VECTOR2I &aPos)
Attempts to create a track-to-track teardrop.
Definition teardrop.cpp:162
TRACK_BUFFER m_trackLookupList
Definition teardrop.h:280
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition teardrop.h:277
std::vector< ZONE * > m_createdTdList
Definition teardrop.h:281
void DeleteTrackToTrackTeardrops(BOARD_COMMIT &aCommit)
Definition teardrop.cpp:390
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
DRC_RTREE m_tracksRTree
Definition teardrop.h:279
friend class TEARDROP_PARAMETERS
Definition teardrop.h:91
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.
Definition teardrop.cpp:180
TOOL_MANAGER * m_toolManager
Definition teardrop.h:276
bool findAnchorPointsOnTrack(const TEARDROP_PARAMETERS &aParams, VECTOR2I &aStartPoint, VECTOR2I &aEndPoint, VECTOR2I &aIntersection, PCB_TRACK *&aTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, int *aEffectiveTeardropLen) const
int computeEmergingTrackLength(PCB_TRACK *aTrack, BOARD_ITEM *aOther, PCB_LAYER_ID aLayer) const
Return the length of the portion of aTrack that lies outside aOther's copper shape on aLayer.
ZONE * createTeardrop(TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aTrack, BOARD_ITEM *aCandidate) const
Creates a teardrop (a ZONE item) from its polygonal shape, track netcode and layer.
Definition teardrop.cpp:52
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:65
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::vector< PCB_TRACK * > * GetTrackList(int aLayer, int aNetcode) const
Definition teardrop.h:47
const std::map< int, std::vector< PCB_TRACK * > * > & GetBuffer() const
Definition teardrop.h:55
std::map< int, std::vector< PCB_TRACK * > * > m_map_tracks
Definition teardrop.h:71
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
Definition teardrop.h:57
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