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
91{
92 friend class TEARDROP_PARAMETERS;
93
94public:
96 {
97 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
98 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
99 };
100
101 TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager );
102
109 void RemoveTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
110 const std::set<PCB_TRACK*>* dirtyTracks );
114 void UpdateTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
115 const std::set<PCB_TRACK*>* dirtyTracks, bool aForceFullUpdate = false );
116
120 void AddTeardropsOnTracks( BOARD_COMMIT& aCommit, const std::set<PCB_TRACK*>* aTracks,
121 bool aForceFullUpdate = false );
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
128 void BuildTrackCaches();
129
130private:
134 bool areItemsInSameZone( BOARD_ITEM* aPadOrVia, PCB_TRACK* aTrack) const;
135
138 int computeChordThroughShape( PCB_TRACK* aTrack, BOARD_ITEM* aOther, PCB_LAYER_ID aLayer,
139 const VECTOR2I& aInsidePoint ) const;
140
148 std::vector<VECTOR2I>& aPoly, PCB_LAYER_ID aLayer,
149 int aTrackHalfWidth,
150 const VECTOR2D& aTrackDir, BOARD_ITEM* aOther,
151 const VECTOR2I& aOtherPos, std::vector<VECTOR2I>& aPts ) const;
152
153
161 std::vector<VECTOR2I>& aPoly, int aTdWidth,
162 int aTrackHalfWidth, std::vector<VECTOR2I>& aPts,
163 const VECTOR2I& aIntersection, BOARD_ITEM* aOther,
164 const VECTOR2I& aOtherPos, PCB_LAYER_ID aLayer ) const;
165
171 bool computeTeardropPolygon( const TEARDROP_PARAMETERS& aParams,
172 std::vector<VECTOR2I>& aCorners, PCB_TRACK* aTrack,
173 BOARD_ITEM* aOther, const VECTOR2I& aOtherPos ) const;
188 bool computeAnchorPoints( const TEARDROP_PARAMETERS& aParams, PCB_LAYER_ID aLayer,
189 BOARD_ITEM* aItem, const VECTOR2I& aPos,
190 std::vector<VECTOR2I>& aPts ) const;
191
200 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
201 const VECTOR2I& aEndPoint ) const;
202
211 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
212 PCB_TRACK* aTrack, BOARD_ITEM* aCandidate ) const;
213
214 ZONE* createTeardropMask( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
215 PCB_TRACK* aTrack, BOARD_ITEM* aCandidate ) const;
216
225 void createAndAddTeardropWithMask( BOARD_COMMIT& aCommit, TEARDROP_VARIANT aTeardropVariant,
226 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack,
227 BOARD_ITEM* aCandidate );
228
239 bool tryCreateTrackTeardrop( BOARD_COMMIT& aCommit, const TEARDROP_PARAMETERS& aParams,
240 TEARDROP_VARIANT aTeardropVariant, PCB_TRACK* aTrack,
241 BOARD_ITEM* aCandidate, const VECTOR2I& aPos );
242
247
263 bool findAnchorPointsOnTrack( const TEARDROP_PARAMETERS& aParams, VECTOR2I& aStartPoint,
264 VECTOR2I& aEndPoint, VECTOR2I& aIntersection,
265 PCB_TRACK*& aTrack, BOARD_ITEM* aOther, const VECTOR2I& aOtherPos,
266 int* aEffectiveTeardropLen ) const;
267
268private:
269 int m_tolerance; // max dist between track end point and pad/via
270 // center to see them connected to ut a teardrop
273 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
274
277 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
278};
279
280#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:83
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition drc_rtree.h:45
BOARD * m_board
Definition teardrop.h:271
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:401
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:445
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:276
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition teardrop.h:273
std::vector< ZONE * > m_createdTdList
Definition teardrop.h:277
void DeleteTrackToTrackTeardrops(BOARD_COMMIT &aCommit)
Definition teardrop.cpp:389
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
DRC_RTREE m_tracksRTree
Definition teardrop.h:275
friend class TEARDROP_PARAMETERS
Definition teardrop.h:92
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:272
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.
bool findAnchorPointsOnTrack(const TEARDROP_PARAMETERS &aParams, VECTOR2I &aStartPoint, VECTOR2I &aEndPoint, VECTOR2I &aIntersection, PCB_TRACK *&aTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, int *aEffectiveTeardropLen) const
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