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 (C) 2023 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 <board.h>
30#include <footprint.h>
31#include <pad.h>
32#include <pcb_track.h>
33#include <zone.h>
34#include <drc/drc_rtree.h>
35#include "teardrop_parameters.h"
36
37#define MAGIC_TEARDROP_PADVIA_NAME "$teardrop_padvia$"
38#define MAGIC_TEARDROP_TRACK_NAME "$teardrop_track$"
39
40// A class to store tracks grouped by layer and netcode
42{
43public:
45
49 void AddTrack( PCB_TRACK* aTrack, int aLayer, int aNetcode );
50
54 std::vector<PCB_TRACK*>* GetTrackList( int aLayer, int aNetcode ) const
55 {
56 return m_map_tracks.at( idxFromLayNet( aLayer, aNetcode ) );
57 }
58
62 const std::map< int, std::vector<PCB_TRACK*>* >& GetBuffer() const { return m_map_tracks; }
63
64 static void GetNetcodeAndLayerFromIndex( int aIdx, int* aLayer, int* aNetcode )
65 {
66 *aLayer = aIdx & 0xFF;
67 *aNetcode = aIdx >> 8;
68 }
69
70private:
71 // Build an index from the layer id and the netcode, to store a track in buffer
72 int idxFromLayNet( int aLayer, int aNetcode ) const
73 {
74 return ( aNetcode << 8 ) + ( aLayer & 0xFF );
75 }
76
77 // Track buffer, tracks are grouped by layer+netcode
78 std::map< int, std::vector<PCB_TRACK*>* > m_map_tracks;
79};
80
81
97{
98 friend class TEARDROP_PARAMETERS;
99
100public:
102 {
103 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
104 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
105 };
106
107 TEARDROP_MANAGER( BOARD* aBoard, TOOL_MANAGER* aToolManager );
108
115 void RemoveTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
116 const std::set<PCB_TRACK*>* dirtyTracks );
120 void UpdateTeardrops( BOARD_COMMIT& aCommit, const std::vector<BOARD_ITEM*>* dirtyPadsAndVias,
121 const std::set<PCB_TRACK*>* dirtyTracks, bool aForceFullUpdate = false );
122
126 void AddTeardropsOnTracks( BOARD_COMMIT& aCommit, const std::set<PCB_TRACK*>* aTracks,
127 bool aForceFullUpdate = false );
128
130
131 static int GetWidth( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
132 static bool IsRound( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer );
133
134private:
138 bool areItemsInSameZone( BOARD_ITEM* aPadOrVia, PCB_TRACK* aTrack) const;
139
147 std::vector<VECTOR2I>& aPoly, PCB_LAYER_ID aLayer,
148 int aTrackHalfWidth,
149 const VECTOR2D& aTrackDir, BOARD_ITEM* aOther,
150 const VECTOR2I& aOtherPos, std::vector<VECTOR2I>& aPts ) const;
151
152
159 std::vector<VECTOR2I>& aPoly, int aTdWidth,
160 int aTrackHalfWidth, std::vector<VECTOR2I>& aPts,
161 const VECTOR2I& aIntersection ) const;
162
168 bool computeTeardropPolygon( const TEARDROP_PARAMETERS& aParams,
169 std::vector<VECTOR2I>& aCorners, PCB_TRACK* aTrack,
170 BOARD_ITEM* aOther, const VECTOR2I& aOtherPos ) const;
185 bool computeAnchorPoints( const TEARDROP_PARAMETERS& aParams, PCB_LAYER_ID aLayer,
186 BOARD_ITEM* aItem, const VECTOR2I& aPos,
187 std::vector<VECTOR2I>& aPts ) const;
188
197 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
198 const VECTOR2I& aEndPoint ) const;
199
207 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant,
208 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack ) const;
209
214
230 bool findAnchorPointsOnTrack( const TEARDROP_PARAMETERS& aParams, VECTOR2I& aStartPoint,
231 VECTOR2I& aEndPoint, VECTOR2I& aIntersection,
232 PCB_TRACK*& aTrack, BOARD_ITEM* aOther, const VECTOR2I& aOtherPos,
233 int* aEffectiveTeardropLen ) const;
234
235 void buildTrackCaches();
236
237private:
238 int m_tolerance; // max dist between track end point and pad/via
239 // center to see them connected to ut a teardrop
242 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
243
246 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
247};
248
249#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:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:48
TEARDROP_MANAGER manage and build teardrop areas A teardrop area is a polygonal area (a copper ZONE) ...
Definition: teardrop.h:97
BOARD * m_board
Definition: teardrop.h:240
static bool IsRound(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer)
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.
void computeCurvedForRectShape(const TEARDROP_PARAMETERS &aParams, std::vector< VECTOR2I > &aPoly, int aTdWidth, int aTrackHalfWidth, std::vector< VECTOR2I > &aPts, const VECTOR2I &aIntersection) const
Compute the curve part points for teardrops connected to a rectangular/polygonal shape The Bezier cur...
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:151
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:304
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:344
TRACK_BUFFER m_trackLookupList
Definition: teardrop.h:245
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition: teardrop.h:242
std::vector< ZONE * > m_createdTdList
Definition: teardrop.h:246
ZONE * createTeardrop(TEARDROP_VARIANT aTeardropVariant, std::vector< VECTOR2I > &aPoints, PCB_TRACK *aTrack) const
Creates a teardrop (a ZONE item) from its polygonal shape, track netcode and layer.
Definition: teardrop.cpp:57
void DeleteTrackToTrackTeardrops(BOARD_COMMIT &aCommit)
Definition: teardrop.cpp:286
bool areItemsInSameZone(BOARD_ITEM *aPadOrVia, PCB_TRACK *aTrack) const
DRC_RTREE m_tracksRTree
Definition: teardrop.h:244
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:99
TOOL_MANAGER * m_toolManager
Definition: teardrop.h:241
bool findAnchorPointsOnTrack(const TEARDROP_PARAMETERS &aParams, VECTOR2I &aStartPoint, VECTOR2I &aEndPoint, VECTOR2I &aIntersection, PCB_TRACK *&aTrack, BOARD_ITEM *aOther, const VECTOR2I &aOtherPos, int *aEffectiveTeardropLen) 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:
Definition: tool_manager.h:62
int idxFromLayNet(int aLayer, int aNetcode) const
Definition: teardrop.h:72
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:54
const std::map< int, std::vector< PCB_TRACK * > * > & GetBuffer() const
Definition: teardrop.h:62
std::map< int, std::vector< PCB_TRACK * > * > m_map_tracks
Definition: teardrop.h:78
TRACK_BUFFER()
Definition: teardrop.h:44
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
Definition: teardrop.h:64
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