KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_via_stitch.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <pcb_generator.h>
27#include <generators_mgr.h>
28#include <i18n_utility.h>
30#include <cstdint>
31#include <functional>
32#include <memory>
33#include <set>
34#include <vector>
35
36class ACTION_MENU;
38class PCB_VIA;
39
40
47
48
54
55
57{
58public:
59 static const wxString GENERATOR_TYPE;
60 static const wxString DISPLAY_NAME;
61
62 PCB_VIA_STITCH( BOARD_ITEM* aParent = nullptr );
63 PCB_VIA_STITCH( const PCB_VIA_STITCH& aOther );
64 PCB_VIA_STITCH( PCB_VIA_STITCH&& aOther ) noexcept;
65 PCB_VIA_STITCH& operator=( const PCB_VIA_STITCH& aOther );
67 ~PCB_VIA_STITCH() override;
68
69 wxString GetGeneratorType() const override { return wxS( "via_stitch" ); }
70
71 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
72 {
73 return wxString( _( "Via Stitching" ) );
74 }
75
76 wxString GetFriendlyName() const override { return wxString( _( "Via Stitching" ) ); }
77
78 wxString GetPluralName() const override { return wxString( _( "Via Stitching" ) ); }
79
80 void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override final;
81
82 std::vector<int> ViewGetLayers() const override
83 {
84 return std::vector<int>{ LAYER_VIAS, LAYER_VIA_HOLES, LAYER_ANCHOR, LAYER_VIA_STITCHING };
85 }
86 int GetNetCode() const;
87
88 void SetNetCode( int aNetCode );
89
90 const BOX2I GetBoundingBox() const override
91 {
92 return m_outline.BBox();
93 }
94
95 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
96 {
97 return m_outline.Collide( aPosition, aAccuracy );
98 }
99
100 VECTOR2I GetPosition() const override;
101
107 void Move( const VECTOR2I& aMoveVector ) override
108 {
109 m_outline.Move( aMoveVector );
110 m_origin += aMoveVector;
111 MarkDirty();
112 }
113
117 void InitializeDefaults( BOARD* aBoard );
118
119 void EditStart( GENERATOR_TOOL*, BOARD*, BOARD_COMMIT* ) override;
120 bool Update( GENERATOR_TOOL*, BOARD*, BOARD_COMMIT* ) override; // generate vias
121 void EditFinish( GENERATOR_TOOL*, BOARD*, BOARD_COMMIT* ) override;
122 void EditCancel( GENERATOR_TOOL*, BOARD*, BOARD_COMMIT* ) override;
123 void Remove( GENERATOR_TOOL*, BOARD*, BOARD_COMMIT* ) override;
124 wxString GetCommitMessage() const override { return _( "Stitching Update" ); }
125
126 // Properties
127 int GetViaSize() const;
128 void SetViaSize( int aVal );
129 int GetViaDrill() const;
130 void SetViaDrill( int aVal );
131 int GetPitch() const { return m_pitch; }
132 void SetPitch( int aVal ) { m_pitch = aVal; MarkDirty(); }
134
136 {
137 if( aVal != m_layout )
138 {
139 m_layout = aVal;
141 }
142
143 MarkDirty();
144 }
145
147
149 {
150 if( aVal != m_mode )
151 {
152 m_mode = aVal;
154 }
155
156 MarkDirty();
157 }
158
160 int GetGuardedNetCode() const;
161 void SetGuardedNetCode( int aNetCode );
162
163 uint32_t GetSeed() const { return m_seed; }
164 void SetSeed( uint32_t aVal ) { m_seed = aVal; MarkDirty(); }
165
166 PCB_VIA* ViaTemplate() { return m_viaTemplate.get(); }
167 const PCB_VIA* ViaTemplate() const { return m_viaTemplate.get(); }
168
169 std::vector<std::pair<wxString, const BOARD_ITEM*>> GetTemplateItems() const override;
170 void SetTemplateItem( const wxString& aName, std::unique_ptr<BOARD_ITEM> aItem ) override;
171
175 void ClearExclusion( const VECTOR2I& aPos );
176
182 void ExcludePosition( const VECTOR2I& aPos );
183
185 void ClearAllExclusions();
186
188 bool HasExclusions() const { return !m_excludedCells.empty() || !m_excludedPositions.empty(); }
189
190 const STRING_ANY_MAP GetProperties() const override;
191 void SetProperties( const STRING_ANY_MAP& aProps ) override;
192
193 EDA_ITEM* Clone() const override { return new PCB_VIA_STITCH( *this ); }
194
195 bool ChildrenAreIndividuallySelectable() const override { return true; }
196
197 ACTION_MENU* GetChildContextMenu( TOOL_INTERACTIVE* aTool ) const override;
198
199 void OnZoneFillChanged( const std::vector<ZONE*>& aZones ) override;
200
201 void ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) override;
202
204 std::vector<ZONE*> GetZonesNeedingRefillAfterUpdate() const override;
205
206protected:
207 void swapData( BOARD_ITEM* aImage ) override
208 {
209 wxASSERT( aImage->Type() == PCB_GENERATOR_T );
210 std::swap( *this, *static_cast<PCB_VIA_STITCH*>( aImage ) );
211 }
212
213private:
214 int defaultPitch( BOARD* aBoard ) const; // grid pitch
215 int defaultViaSize( BOARD* aBoard ) const; // via diameter
216 int defaultViaDrill( BOARD* aBoard ) const; // drill diameter
217
227
229 VECTOR2I cellForPosition( const VECTOR2I& aPos ) const;
230
235 VECTOR2I positionForCell( const VECTOR2I& aCell, int aPitch ) const;
236
242 std::set<VECTOR2I> buildPlacementCells( BOARD* aBoard ) const;
243
248 static std::vector<ZONE*> collectAllZones( const BOARD* aBoard );
249
250
251public:
257 static constexpr int POISSON_TILE_PITCHES = 8;
258
263 static constexpr uint32_t POISSON_TILE_SEED = 0x542c21fc;
264
268 static const std::vector<VECTOR2D>& bakedPoissonTile();
269
278 static std::vector<VECTOR2I>
279 SampleGuardEnvelope( const SHAPE_POLY_SET& aEnvelope, const SHAPE_POLY_SET& aGuarded,
280 int aPitch, const std::function<bool( const VECTOR2I& )>& aIsValid );
281
282private:
283 int m_pitch = 0; // center-to-center spacing
286 uint32_t m_seed = 0; // Tile random shift seed
287
288 std::unique_ptr<PCB_VIA> m_viaTemplate;
289
291 mutable int m_netCode = 0;
292
293 // GUARD-mode target net name
295 mutable int m_guardedNetCode = 0;
296
297 // Grid cells (col, row) the user has explicitly excluded, used by the grid layouts
298 std::set<VECTOR2I> m_excludedCells;
299
300 // Absolute board positions the user has explicitly excluded, used by POISSON layout and
301 // GUARD mode, where vias are not placed on a grid and so have no cell index to key on.
302 std::set<VECTOR2I> m_excludedPositions;
303
304 // The grid configuration that produced the currently attached child vias.
313
315
316 // Offset of the placement grid relative to the global (0,0) anchor, in [0, pitch) on each
317 // axis. Users can offset the grid by dragging a single stitched via
319
320 // Whether the last Update() actually added, moved, or removed any via.
322
323 // Vias in the current generator edit session that are pending removal.
324 std::set<PCB_VIA*> m_pendingRemovals;
325
326 // Right-click context menu for our child vias.
327 mutable std::unique_ptr<ACTION_MENU> m_childContextMenu;
328};
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
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:409
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
Handle actions specific to filling copper zones.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
Common, abstract interface for edit frames.
PCB_GENERATOR_POLY(BOARD_ITEM *aParent, PCB_LAYER_ID aLayer)
SHAPE_POLY_SET m_outline
VECTOR2I m_origin
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the parts of the object belonging to layer aLayer.
PCB_VIA_STITCH_MODE m_mode
int GetViaSize() const
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
~PCB_VIA_STITCH() override
static std::vector< VECTOR2I > SampleGuardEnvelope(const SHAPE_POLY_SET &aEnvelope, const SHAPE_POLY_SET &aGuarded, int aPitch, const std::function< bool(const VECTOR2I &)> &aIsValid)
Determine via positions around the perimeter of a guard envelope.
PCB_VIA * ViaTemplate()
void EditCancel(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
wxString GetCommitMessage() const override
void SetTemplateItem(const wxString &aName, std::unique_ptr< BOARD_ITEM > aItem) override
Insert a template item (from board file loading)
int GetViaDrill() const
wxString GetGeneratorType() const override
wxString GetPluralName() const override
std::set< VECTOR2I > m_excludedPositions
void SetGuardedNetCode(int aNetCode)
int GetNetCode() const
void SetMode(PCB_VIA_STITCH_MODE aVal)
void EditStart(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool usesGridCells() const
PCB_VIA_STITCH_LAYOUT GetLayout() const
std::vector< ZONE * > GetZonesNeedingRefillAfterUpdate() const override
List of zones that cross out stitch zone, they'll need to be refilled for the punches.
PCB_VIA_STITCH & operator=(PCB_VIA_STITCH &&aOther) noexcept
PCB_VIA_STITCH(PCB_VIA_STITCH &&aOther) noexcept
void SetViaSize(int aVal)
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
std::unique_ptr< PCB_VIA > m_viaTemplate
void SetPitch(int aVal)
PCB_VIA_STITCH & operator=(const PCB_VIA_STITCH &aOther)
std::vector< std::pair< wxString, const BOARD_ITEM * > > GetTemplateItems() const override
Named template items used by the generator.
PCB_VIA_STITCH(BOARD_ITEM *aParent=nullptr)
std::unique_ptr< ACTION_MENU > m_childContextMenu
static constexpr uint32_t POISSON_TILE_SEED
Fixed seed for baking the toroidal Poisson pattern.
int defaultPitch(BOARD *aBoard) const
void ShowPropertiesDialog(PCB_BASE_EDIT_FRAME *aEditFrame) override
std::vector< int > ViewGetLayers() const override
void ClearAllExclusions()
Drop all manual exclusions.
VECTOR2I cellForPosition(const VECTOR2I &aPos) const
Convert an absolute board position to a (col, row) grid cell index.
void ClearExclusion(const VECTOR2I &aPos)
Remove a board position from the exclusion list for the current layout/mode.
ACTION_MENU * GetChildContextMenu(TOOL_INTERACTIVE *aTool) const override
Get a context menu when interacting with a generator child.
bool HasExclusions() const
const STRING_ANY_MAP GetProperties() const override
void Move(const VECTOR2I &aMoveVector) override
This method is overrided to translate the stitch zone outline only on move.
const PCB_VIA * ViaTemplate() const
void SetViaDrill(int aVal)
PCB_VIA_STITCH_MODE GetMode() const
std::set< VECTOR2I > buildPlacementCells(BOARD *aBoard) const
Walk the placement grid, run DRC clearance tests, and return the set of (col, row) cells where a via ...
static std::vector< ZONE * > collectAllZones(const BOARD *aBoard)
Grabs all zones we need to consider for via placement.
static const std::vector< VECTOR2D > & bakedPoissonTile()
Helper method to cache the poisson tile we pattern.
VECTOR2I GetPosition() const override
static constexpr int POISSON_TILE_PITCHES
Tile size for the POISSON layout, in units of pitch.
VECTOR2I m_originOffset
bool Update(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
int defaultViaSize(BOARD *aBoard) const
int GetGuardedNetCode() const
Net being guarded in GUARD mode.
void SetNetCode(int aNetCode)
static const wxString GENERATOR_TYPE
int GetPitch() const
void EditFinish(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
void swapData(BOARD_ITEM *aImage) override
int defaultViaDrill(BOARD *aBoard) const
std::set< PCB_VIA * > m_pendingRemovals
void Remove(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
static const wxString DISPLAY_NAME
wxString m_lastGuardedNetName
uint32_t GetSeed() const
void SetProperties(const STRING_ANY_MAP &aProps) override
void SetLayout(PCB_VIA_STITCH_LAYOUT aVal)
PCB_VIA_STITCH_LAYOUT m_layout
void ExcludePosition(const VECTOR2I &aPos)
Add a board position to the exclusion set so the next Update() skips it.
void OnZoneFillChanged(const std::vector< ZONE * > &aZones) override
Callback to be informed zones have changed.
wxString m_lastNetName
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
bool ChildrenAreIndividuallySelectable() const override
void SetSeed(uint32_t aVal)
GRID_CONFIG m_childGridConfig
void InitializeDefaults(BOARD *aBoard)
Fill in any unset via-template and pitch values from the board's design settings.
std::set< VECTOR2I > m_excludedCells
wxString GetFriendlyName() const override
VECTOR2I positionForCell(const VECTOR2I &aCell, int aPitch) const
Convert a (col, row) grid cell index to an absolute board position, including any stagger shift on od...
Represent a set of closed polygons.
A name/value tuple with unique names and wxAny values.
#define _(s)
Some functions to handle hotkeys in KiCad.
@ LAYER_VIA_STITCHING
Outline of via stitching generators.
Definition layer_ids.h:326
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:244
@ LAYER_VIA_HOLES
Draw via holes (pad holes do not use this layer).
Definition layer_ids.h:270
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition layer_ids.h:228
PCB_VIA_STITCH_MODE
@ STITCH
Fill the outline with vias with a pattern.
@ GUARD
Place vias to guard a net contained within.
PCB_VIA_STITCH_LAYOUT
@ POISSON
Tiled poisson distribution.
@ PLAIN
Regular row/column grid.
bool operator==(const GRID_CONFIG &aOther) const =default
PCB_VIA_STITCH_LAYOUT layout
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683