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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef TEARDROP_H
26#define TEARDROP_H
27
28#include <tool/tool_manager.h>
29#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::vector<PCB_TRACK*>* GetTrackList( int aLayer, int aNetcode ) const
52 {
53 return m_map_tracks.at( idxFromLayNet( aLayer, aNetcode ) );
54 }
55
59 const std::map< int, std::vector<PCB_TRACK*>* >& GetBuffer() const { return m_map_tracks; }
60
61 static void GetNetcodeAndLayerFromIndex( int aIdx, int* aLayer, int* aNetcode )
62 {
63 *aLayer = aIdx & 0xFF;
64 *aNetcode = aIdx >> 8;
65 }
66
67private:
68 // Build an index from the layer id and the netcode, to store a track in buffer
69 int idxFromLayNet( int aLayer, int aNetcode ) const
70 {
71 return ( aNetcode << 8 ) + ( aLayer & 0xFF );
72 }
73
74 // Track buffer, tracks are grouped by layer+netcode
75 std::map< int, std::vector<PCB_TRACK*>* > m_map_tracks;
76};
77
78
94{
95 friend class TEARDROP_PARAMETERS;
96
97public:
99 {
100 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
101 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
102 };
103
104 TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager );
105
112 void RemoveTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
113 const std::set<PCB_TRACK*>* dirtyTracks );
117 void UpdateTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
118 const std::set<PCB_TRACK*>* dirtyTracks, bool aForceFullUpdate = false );
119
123 void AddTeardropsOnTracks( BOARD_COMMIT& aCommit, const std::set<PCB_TRACK*>* aTracks,
124 bool aForceFullUpdate = false );
125
127
128 static int GetWidth( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
129 static bool IsRound( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
130
131 void BuildTrackCaches();
132
133private:
137 bool areItemsInSameZone( BOARD_ITEM* aPadOrVia, PCB_TRACK* aTrack) const;
138
146 std::vector<VECTOR2I>& aPoly, PCB_LAYER_ID aLayer,
147 int aTrackHalfWidth,
148 const VECTOR2D& aTrackDir, BOARD_ITEM* aOther,
149 const VECTOR2I& aOtherPos, std::vector<VECTOR2I>& aPts ) const;
150
151
159 std::vector<VECTOR2I>& aPoly, int aTdWidth,
160 int aTrackHalfWidth, std::vector<VECTOR2I>& aPts,
161 const VECTOR2I& aIntersection, BOARD_ITEM* aOther,
162 const VECTOR2I& aOtherPos, PCB_LAYER_ID aLayer ) const;
163
169 bool computeTeardropPolygon( const TEARDROP_PARAMETERS& aParams,
170 std::vector<VECTOR2I>& aCorners, PCB_TRACK* aTrack,
171 BOARD_ITEM* aOther, const VECTOR2I& aOtherPos ) const;
186 bool computeAnchorPoints( const TEARDROP_PARAMETERS& aParams, PCB_LAYER_ID aLayer,
187 BOARD_ITEM* aItem, const VECTOR2I& aPos,
188 std::vector<VECTOR2I>& aPts ) const;
189
198 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
199 const VECTOR2I& aEndPoint ) const;
200
209 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
210 PCB_TRACK* aTrack, BOARD_ITEM* aCandidate ) const;
211
212 ZONE* createTeardropMask( TEARDROP_VARIANT aTeardropVariant, std::vector<VECTOR2I>& aPoints,
213 PCB_TRACK* aTrack, BOARD_ITEM* aCandidate ) const;
214
223 void createAndAddTeardropWithMask( BOARD_COMMIT& aCommit, TEARDROP_VARIANT aTeardropVariant,
224 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack,
225 BOARD_ITEM* aCandidate );
226
237 bool tryCreateTrackTeardrop( BOARD_COMMIT& aCommit, const TEARDROP_PARAMETERS& aParams,
238 TEARDROP_VARIANT aTeardropVariant, PCB_TRACK* aTrack,
239 BOARD_ITEM* aCandidate, const VECTOR2I& aPos );
240
245
261 bool findAnchorPointsOnTrack( const TEARDROP_PARAMETERS& aParams, VECTOR2I& aStartPoint,
262 VECTOR2I& aEndPoint, VECTOR2I& aIntersection,
263 PCB_TRACK*& aTrack, BOARD_ITEM* aOther, const VECTOR2I& aOtherPos,
264 int* aEffectiveTeardropLen ) const;
265
266private:
267 int m_tolerance; // max dist between track end point and pad/via
268 // center to see them connected to ut a teardrop
271 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
272
275 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
276};
277
278#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:322
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition drc_rtree.h:49
BOARD * m_board
Definition teardrop.h:269
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:101
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:48
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:147
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:230
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:389
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:429
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:167
TRACK_BUFFER m_trackLookupList
Definition teardrop.h:274
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition teardrop.h:271
std::vector< ZONE * > m_createdTdList
Definition teardrop.h:275
void DeleteTrackToTrackTeardrops(BOARD_COMMIT &aCommit)
Definition teardrop.cpp:377
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
DRC_RTREE m_tracksRTree
Definition teardrop.h:273
friend class TEARDROP_PARAMETERS
Definition teardrop.h:95
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:185
TOOL_MANAGER * m_toolManager
Definition teardrop.h:270
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:57
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:69
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:51
const std::map< int, std::vector< PCB_TRACK * > * > & GetBuffer() const
Definition teardrop.h:59
std::map< int, std::vector< PCB_TRACK * > * > m_map_tracks
Definition teardrop.h:75
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
Definition teardrop.h:61
Handle a list of polygons defining a copper zone.
Definition zone.h:73
std::uint32_t EDA_ITEM_FLAGS
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694