KiCad PCB EDA Suite
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) 2022 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 <pcb_edit_frame.h>
29#include <board.h>
30#include <footprint.h>
31#include <pad.h>
32#include <pcb_track.h>
33#include <zone.h>
34#include "teardrop_parameters.h"
35
36#define MAGIC_TEARDROP_PADVIA_NAME "$teardrop_padvia$"
37#define MAGIC_TEARDROP_TRACK_NAME "$teardrop_track$"
38
39class TRACK_BUFFER;
40
44struct VIAPAD
45{
46 VIAPAD( PCB_VIA* aVia );
47 VIAPAD( PAD* aPad );
48 VIAPAD( PCB_TRACK* aTrack, ENDPOINT_T aEndPoint );
49
50 bool IsOnLayer( PCB_LAYER_ID aLayer ) const
51 {
52 return m_Parent->IsOnLayer( aLayer );
53 }
54
56 int m_Width; // The diameter of a round shape, or the min size for others
59 bool m_IsRound; // true for round shapes, false for any other shape
60 bool m_IsPad; // true for pads, false for vias and tracks
62};
63
64
80{
81 friend class TEARDROP_PARAMETERS;
82
83public:
85 {
86 TD_TYPE_PADVIA, // Specify a teardrop on a pad via
87 TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
88 };
89
90 TEARDROP_MANAGER( BOARD* aBoard, PCB_EDIT_FRAME* aFrame );
91
99 int SetTeardrops( BOARD_COMMIT* aCommitter,
100 bool aFollowTracks = true );
101
102
111 int RemoveTeardrops( BOARD_COMMIT* aCommitter, bool aCommitAfterRemove );
112
113
114private:
118 void collectVias( std::vector< VIAPAD >& aList ) const;
119
129 void collectPadsCandidate( std::vector< VIAPAD >& aList,
130 bool aDrilledViaPad,
131 bool aRoundShapesOnly,
132 bool aIncludeNotDrilled ) const;
133
138 void collectTeardrops( std::vector< ZONE* >& aList ) const;
139
143 int addTeardropsOnTracks( BOARD_COMMIT* aCommitter );
144
148 bool isViaAndTrackInSameZone( VIAPAD& aVia, PCB_TRACK* aTrack) const;
149
157 std::vector<VECTOR2I>& aPoly,
158 int aTrackHalfWidth,
159 VECTOR2D aTrackDir, VIAPAD& aViaPad,
160 std::vector<VECTOR2I>& aPts ) const;
161
162
169 std::vector<VECTOR2I>& aPoly, int aTdHeight,
170 int aTrackHalfWidth, VIAPAD& aViaPad,
171 std::vector<VECTOR2I>& aPts ) const;
172
179 std::vector<VECTOR2I>& aCorners,
180 PCB_TRACK* aTrack, VIAPAD& aVia,
181 bool aFollowTracks,
182 TRACK_BUFFER& aTrackLookupList) const;
197 PCB_TRACK* aTrack, VIAPAD& aViaPad,
198 std::vector<VECTOR2I>& aPts ) const;
199
208 PCB_TRACK* findTouchingTrack( EDA_ITEM_FLAGS& aMatchType, PCB_TRACK* aTrackRef,
209 const VECTOR2I& aEndPoint,
210 TRACK_BUFFER& aTrackLookupList ) const;
211
219 ZONE* createTeardrop( TEARDROP_VARIANT aTeardropVariant,
220 std::vector<VECTOR2I>& aPoints, PCB_TRACK* aTrack) const;
221
226
241 VECTOR2I& aStartPoint, VECTOR2I& aEndPoint,
242 PCB_TRACK*& aTrack, VIAPAD& aViaPad,
243 int* aEffectiveTeardropLen,
244 bool aFollowTracks, TRACK_BUFFER& aTrackLookupList ) const;
245
246private:
247 int m_tolerance; // max distance between a track end point and a pad/via center to
248 // see them connected to ut a teardrop
250 TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board design settings
251 std::vector<ZONE*> m_createdTdList; // list of new created teardrops
252};
253
254
255// A class to store tracks grouped by layer and netcode
257{
258public:
260
264 void AddTrack( PCB_TRACK* aTrack, int aLayer, int aNetcode );
265
269 std::vector<PCB_TRACK*>* GetTrackList( int aLayer, int aNetcode )
270 {
271 return m_map_tracks.at( idxFromLayNet( aLayer, aNetcode ) );
272 }
273
277 std::map< int, std::vector<PCB_TRACK*>* >& GetBuffer() { return m_map_tracks ; }
278
279 static void GetNetcodeAndLayerFromIndex( int aIdx, int* aLayer, int* aNetcode )
280 {
281 *aLayer = aIdx & 0xFF;
282 *aNetcode = aIdx >> 8;
283 }
284
285private:
286 // Build an index from the layer id and the netcode, to store a track in buffer
287 int idxFromLayNet( int aLayer, int aNetcode ) const
288 {
289 return ( aNetcode << 8 ) + ( aLayer & 0xFF );
290 }
291
292 // Track buffer, tracks are grouped by layer+netcode
293 std::map< int, std::vector<PCB_TRACK*>* > m_map_tracks;
294};
295
296#endif // ifndef TEARDROP_H
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:257
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
Definition: pad.h:59
The main frame for Pcbnew.
TEARDROP_MANAGER manage and build teardrop areas A teardrop area is a polygonal area (a copper ZONE) ...
Definition: teardrop.h:80
BOARD * m_board
Definition: teardrop.h:249
TEARDROP_MANAGER(BOARD *aBoard, PCB_EDIT_FRAME *aFrame)
Definition: teardrop.cpp:46
void collectTeardrops(std::vector< ZONE * > &aList) const
Build a list of all teardrops on the current board.
void collectVias(std::vector< VIAPAD > &aList) const
Collect and build the list of all vias from the given board.
void collectPadsCandidate(std::vector< VIAPAD > &aList, bool aDrilledViaPad, bool aRoundShapesOnly, bool aIncludeNotDrilled) const
Build a list of pads candidate for teardrops from the given board Pads with no net are not candidate ...
bool findAnchorPointsOnTrack(TEARDROP_PARAMETERS *aCurrParams, VECTOR2I &aStartPoint, VECTOR2I &aEndPoint, PCB_TRACK *&aTrack, VIAPAD &aViaPad, int *aEffectiveTeardropLen, bool aFollowTracks, TRACK_BUFFER &aTrackLookupList) const
void computeCurvedForRoundShape(TEARDROP_PARAMETERS *aCurrParams, std::vector< VECTOR2I > &aPoly, int aTrackHalfWidth, VECTOR2D aTrackDir, VIAPAD &aViaPad, std::vector< VECTOR2I > &aPts) const
Compute the curve part points for teardrops connected to a round shape The Bezier curve control point...
bool isViaAndTrackInSameZone(VIAPAD &aVia, PCB_TRACK *aTrack) const
int SetTeardrops(BOARD_COMMIT *aCommitter, bool aFollowTracks=true)
Set teardrops on a teardrop free board.
Definition: teardrop.cpp:93
void setTeardropPriorities()
Set priority of created teardrops.
Definition: teardrop.cpp:239
int RemoveTeardrops(BOARD_COMMIT *aCommitter, bool aCommitAfterRemove)
Remove all teardrops.
Definition: teardrop.cpp:410
bool computeTeardropPolygonPoints(TEARDROP_PARAMETERS *aCurrParams, std::vector< VECTOR2I > &aCorners, PCB_TRACK *aTrack, VIAPAD &aVia, bool aFollowTracks, TRACK_BUFFER &aTrackLookupList) const
Compute all teardrop points of the polygon shape.
TEARDROP_PARAMETERS_LIST * m_prmsList
Definition: teardrop.h:250
std::vector< ZONE * > m_createdTdList
Definition: teardrop.h:251
bool ComputePointsOnPadVia(TEARDROP_PARAMETERS *aCurrParams, PCB_TRACK *aTrack, VIAPAD &aViaPad, std::vector< VECTOR2I > &aPts) const
Compute the 2 points on pad/via of the teardrop shape.
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
PCB_TRACK * findTouchingTrack(EDA_ITEM_FLAGS &aMatchType, PCB_TRACK *aTrackRef, const VECTOR2I &aEndPoint, TRACK_BUFFER &aTrackLookupList) const
Find a track connected to the end of another track.
void computeCurvedForRectShape(TEARDROP_PARAMETERS *aCurrParams, std::vector< VECTOR2I > &aPoly, int aTdHeight, int aTrackHalfWidth, VIAPAD &aViaPad, std::vector< VECTOR2I > &aPts) const
Compute the curve part points for teardrops connected to a rectangular/polygonal shape The Bezier cur...
int addTeardropsOnTracks(BOARD_COMMIT *aCommitter)
Add teardrop on tracks of different sizes connected by their end.
Definition: teardrop.cpp:279
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...
int idxFromLayNet(int aLayer, int aNetcode) const
Definition: teardrop.h:287
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 * > * > m_map_tracks
Definition: teardrop.h:293
static void GetNetcodeAndLayerFromIndex(int aIdx, int *aLayer, int *aNetcode)
Definition: teardrop.h:279
std::vector< PCB_TRACK * > * GetTrackList(int aLayer, int aNetcode)
Definition: teardrop.h:269
std::map< int, std::vector< PCB_TRACK * > * > & GetBuffer()
Definition: teardrop.h:277
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
std::uint32_t EDA_ITEM_FLAGS
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
ENDPOINT_T
Definition: pcb_track.h:56
Stores info of a pad, via or track end to build a teardrop.
Definition: teardrop.h:45
int m_Width
Definition: teardrop.h:56
VIAPAD(PCB_VIA *aVia)
BOARD_CONNECTED_ITEM * m_Parent
Definition: teardrop.h:61
bool IsOnLayer(PCB_LAYER_ID aLayer) const
Definition: teardrop.h:50
int m_Drill
Definition: teardrop.h:57
VECTOR2I m_Pos
Definition: teardrop.h:55
bool m_IsPad
Definition: teardrop.h:60
bool m_IsRound
Definition: teardrop.h:59
int m_NetCode
Definition: teardrop.h:58