KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_via_stitch.cpp
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#include <pcb_via_stitch.h>
25
27#include <pcb_base_edit_frame.h>
28#include <tool/tool_manager.h>
30#include <board_commit.h>
31
32#include <cmath>
33#include <map>
34#include <vector>
35
36#include <boost/random/mersenne_twister.hpp>
37#include <boost/random/uniform_real_distribution.hpp>
38
40#include <geometry/seg.h>
42#include <geometry/shape_rect.h>
44#include <gal/painter.h>
45#include <tool/action_menu.h>
46#include <tools/pcb_actions.h>
47#include <view/view.h>
48#include <zone.h>
49#include <pad.h>
50#include <api/api_enums.h>
51#include <api/api_utils.h>
52#include <api/board/board_types.pb.h>
53#include <google/protobuf/any.pb.h>
54
55#include <pcb_track.h>
56#include <board.h>
59#include <footprint.h>
61#include <drc/drc_engine.h>
62#include <drc/drc_rtree.h>
63#include <drc/drc_rule.h>
64#include <properties/property.h>
67
68const wxString PCB_VIA_STITCH::DISPLAY_NAME = _HKI( "Via Stitching" );
69const wxString PCB_VIA_STITCH::GENERATOR_TYPE = wxS( "via_stitch" );
70
71
72const std::vector<VECTOR2D>& PCB_VIA_STITCH::bakedPoissonTile()
73{
74 static const std::vector<VECTOR2D> samples = POISSON_DISK::ToroidalUnitTile(
76 return samples;
77}
78
79
81 PCB_GENERATOR_POLY( aParent, F_Cu ),
82 m_viaTemplate( std::make_unique<PCB_VIA>( this ) )
83{
86
87
88 m_viaTemplate->SetIsFree( true );
89}
90
91
93 PCB_GENERATOR_POLY( aOther ),
94 m_pitch( aOther.m_pitch ),
95 m_layout( aOther.m_layout ),
96 m_mode( aOther.m_mode ),
97 m_seed( aOther.m_seed ),
98 m_viaTemplate( std::make_unique<PCB_VIA>( *aOther.m_viaTemplate ) ),
100 m_netCode( aOther.m_netCode ),
107{
108 // m_childContextMenu is intentionally not copied
109}
110
111
112PCB_VIA_STITCH::PCB_VIA_STITCH( PCB_VIA_STITCH&& aOther ) noexcept = default;
113
115{
116 if( this != &aOther )
117 {
119 m_pitch = aOther.m_pitch;
120 m_layout = aOther.m_layout;
121 m_mode = aOther.m_mode;
122 m_seed = aOther.m_seed;
123 m_viaTemplate = std::make_unique<PCB_VIA>( *aOther.m_viaTemplate );
125 m_netCode = aOther.m_netCode;
132 // m_childContextMenu is intentionally not copied.
133 m_childContextMenu.reset();
134 }
135 return *this;
136}
137
138PCB_VIA_STITCH& PCB_VIA_STITCH::operator=( PCB_VIA_STITCH&& aOther ) noexcept = default;
139
141
142
144{
145 return m_viaTemplate->GetWidth( PADSTACK::ALL_LAYERS );
146}
147
148
150{
151 m_viaTemplate->SetWidth( PADSTACK::ALL_LAYERS, aVal );
152 MarkDirty();
153}
154
155
157{
158 int d = m_viaTemplate->GetDrillValue();
159 return d > 0 ? d : 0;
160}
161
162
164{
165 m_viaTemplate->SetDrill( aVal );
166 MarkDirty();
167}
168
169
170std::vector<std::pair<wxString, const BOARD_ITEM*>> PCB_VIA_STITCH::GetTemplateItems() const
171{
172 return { { wxS( "via" ), m_viaTemplate.get() } };
173}
174
175
176void PCB_VIA_STITCH::SetTemplateItem( const wxString& aName, std::unique_ptr<BOARD_ITEM> aItem )
177{
178 if( aName != wxS( "via" ) || !aItem || aItem->Type() != PCB_VIA_T )
179 return;
180
181 m_viaTemplate.reset( static_cast<PCB_VIA*>( aItem.release() ) );
182 m_viaTemplate->SetParent( this );
183 m_viaTemplate->SetIsFree( true );
184}
185
186void PCB_VIA_STITCH::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
187{
188 if( m_outline.OutlineCount() == 0 )
189 return;
190
191 // Only paint on the outline layer. ViewGetLayers() also lists LAYER_VIAS /
192 // LAYER_VIA_HOLES / LAYER_ANCHOR for the produced vias' rendering, but those are
193 // handled by the via children themselves; we don't want to redraw the outline
194 // multiple times per frame.
195 if( aLayer != LAYER_VIA_STITCHING )
196 return;
197
198 KIGFX::GAL* gal = aView->GetGAL();
199
200 // We are drawing perpendicular ticks along the outline to indicate the stitch zone
201 // It kind of looks like a sewing pattern with the ticks, so it fits.
202 KIGFX::RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
203 const KIGFX::COLOR4D borderColor = settings->GetColor( this, LAYER_VIA_STITCHING );
204
205 const SHAPE_LINE_CHAIN& outline = m_outline.COutline( 0 );
206 const int n = outline.PointCount();
207
208 gal->SetIsFill( false );
209 gal->SetIsStroke( true );
210 gal->SetStrokeColor( borderColor );
211 gal->SetLineWidth( pcbIUScale.mmToIU( 0.1 ) );
212 gal->DrawPolyline( outline );
213
214 const double tickSpacing = pcbIUScale.mmToIU( 2.0 );
215 const double tickLength = pcbIUScale.mmToIU( 0.5 );
216
217 // Approximate centroid — used to resolve which perpendicular direction is inward
218 // regardless of polygon winding order.
219 VECTOR2D centroid( 0.0, 0.0 );
220 for( int i = 0; i < n; ++i )
221 {
222 centroid.x += outline.CPoint( i ).x;
223 centroid.y += outline.CPoint( i ).y;
224 }
225 centroid.x /= n;
226 centroid.y /= n;
227
228 gal->SetLineWidth( 1 ); // hairline ticks
229
230 for( int i = 0; i < n; ++i )
231 {
232 const VECTOR2D p1( outline.CPoint( i ) );
233 const VECTOR2D p2( outline.CPoint( ( i + 1 ) % n ) );
234
235 const VECTOR2D edgeVec = p2 - p1;
236 const double edgeLen = edgeVec.EuclideanNorm();
237
238 if( edgeLen < 1.0 )
239 continue;
240
241 const VECTOR2D edgeDir = edgeVec / edgeLen;
242
243 // Pick the perpendicular that points toward the centroid
244 const VECTOR2D edgeMid = ( p1 + p2 ) / 2.0;
245 const VECTOR2D perp = VECTOR2D( -edgeDir.y, edgeDir.x );
246 const VECTOR2D toCentr = centroid - edgeMid;
247 const bool perpToward = ( perp.x * toCentr.x + perp.y * toCentr.y >= 0.0 );
248 const VECTOR2D inward = perpToward ? perp : VECTOR2D( -perp.x, -perp.y );
249
250 for( double t = tickSpacing; t < edgeLen; t += tickSpacing )
251 {
252 const VECTOR2D base = p1 + edgeDir * t;
253 gal->DrawLine( base, base + inward * tickLength );
254 }
255 }
256}
257
258
260{
262
263 // An empty outline has no vertex 0 (e.g. a freshly constructed generator before the
264 // outline is set); fall back to the anchor origin rather than throwing.
265 if( !m_outline.GetRelativeIndices( 0, &index ) )
266 return m_origin;
267
268 return m_outline.CVertex( index );
269}
270
271
273{
274 if( m_viaTemplate->GetWidth( PADSTACK::ALL_LAYERS ) <= 0 )
275 m_viaTemplate->SetWidth( PADSTACK::ALL_LAYERS, defaultViaSize( aBoard ) );
276
277 if( m_viaTemplate->GetDrillValue() <= 0 )
278 m_viaTemplate->SetDrill( defaultViaDrill( aBoard ) );
279
280 if( m_pitch <= 0 )
281 {
282 m_pitch = defaultPitch( aBoard );
283
285 }
286}
287
288
290{
291 if( aCommit )
292 {
293 if( IsNew() )
294 aCommit->Add( this );
295 else
296 aCommit->Modify( this );
297 }
298
299 // Initialize property defaults on first edit
300 InitializeDefaults( aBoard );
301
302 // Resolve net code from saved name (SetProperties has no board reference)
303 if( m_netCode == 0 && !m_lastNetName.empty() && aBoard )
304 {
305 if( NETINFO_ITEM* net = aBoard->FindNet( m_lastNetName ) )
306 m_netCode = net->GetNetCode();
307 }
308
309 if( m_guardedNetCode == 0 && !m_lastGuardedNetName.empty() && aBoard )
310 {
311 if( NETINFO_ITEM* net = aBoard->FindNet( m_lastGuardedNetName ) )
312 m_guardedNetCode = net->GetNetCode();
313 }
314
315 SetFlags( IN_EDIT );
316}
317
318
319int PCB_VIA_STITCH::defaultPitch( const BOARD* aBoard ) const
320{
321 int mm2 = pcbIUScale.mmToIU( 2.0 );
322 int viaSize = m_viaTemplate->GetWidth( PADSTACK::TEMP_ALL_LAYERS ) > 0 ? m_viaTemplate->GetWidth( PADSTACK::TEMP_ALL_LAYERS )
323 : defaultViaSize( aBoard );
324 int pitch = std::max( mm2, viaSize * 2 );
325 return pitch;
326}
327
328
329int PCB_VIA_STITCH::defaultViaSize( const BOARD* aBoard ) const
330{
331 if( !aBoard )
332 return pcbIUScale.mmToIU( 0.6 );
333
334 int val = aBoard->GetDesignSettings().GetCurrentViaSize();
335
336 if( val <= 0 )
337 val = pcbIUScale.mmToIU( 0.6 );
338
339 return val;
340}
341
342int PCB_VIA_STITCH::defaultViaDrill( const BOARD* aBoard ) const
343{
344 if( !aBoard )
345 return pcbIUScale.mmToIU( 0.3 );
346
347 int val = aBoard->GetDesignSettings().GetCurrentViaDrill();
348
349 if( val <= 0 )
350 val = pcbIUScale.mmToIU( 0.3 );
351
352 return val;
353}
354
355
357{
358 if( !( GetFlags() & IN_EDIT ) )
359 return false;
360
361 if( !aBoard || !aCommit )
362 return false;
363
364 // Resolve net code from the saved name in case EditStart() was not called
365 // (e.g. programmatic regeneration after load)
366 if( m_netCode == 0 && !m_lastNetName.empty() )
367 {
368 if( NETINFO_ITEM* net = aBoard->FindNet( m_lastNetName ) )
369 m_netCode = net->GetNetCode();
370 }
371
372 if( m_guardedNetCode == 0 && !m_lastGuardedNetName.empty() )
373 {
374 if( NETINFO_ITEM* net = aBoard->FindNet( m_lastGuardedNetName ) )
375 m_guardedNetCode = net->GetNetCode();
376 }
377
378 int detectPitch = m_pitch > 0 ? m_pitch : defaultPitch( aBoard );
379
380 // Avoid accidentally calculating a grid offset change because we just changed layout modes
381 const GRID_CONFIG currentConfig{ m_layout, m_mode, detectPitch };
382 const bool childrenAreOnThisGrid = m_childGridConfig == currentConfig;
383
384 m_childGridConfig = currentConfig;
385
386 // Try to detect origin offset change due to moved via
387 if( usesGridCells() && childrenAreOnThisGrid )
388 {
389 for( BOARD_ITEM* it : GetBoardItems() )
390 {
391 if( it->Type() != PCB_VIA_T )
392 continue;
393
394 VECTOR2I p = static_cast<PCB_VIA*>( it )->GetPosition();
395 VECTOR2I expectedPos = positionForCell( cellForPosition( p ), detectPitch );
396
397 if( expectedPos != p )
398 {
399 int offsetY = ( ( p.y % detectPitch ) + detectPitch ) % detectPitch;
400
401 // The dragged via defines the new grid origin. On a staggered layout an odd
402 // row carries an extra half-pitch x shift, which must be removed before
403 // computing the origin offset or the whole grid re-anchors half a pitch off.
404 // (p.y - offsetY) is an exact multiple of the pitch, so this row index matches
405 // what cellForPosition()/positionForCell() will derive after the re-anchor.
406 int row = ( p.y - offsetY ) / detectPitch;
408 && ( ( row % 2 + 2 ) % 2 != 0 ) ) ? detectPitch / 2 : 0;
409
411 VECTOR2I( ( ( ( p.x - xShift ) % detectPitch ) + detectPitch ) % detectPitch,
412 offsetY );
413 break;
414 }
415 }
416 }
417
418 // Take snapshot of existing vias, we then selectively remove vias only if they should be removed
419 // we want to reduce file churn of KIIDs
420 std::vector<PCB_VIA*> existingVias;
421
422 for( BOARD_ITEM* item : GetBoardItems() )
423 {
424 if( item->Type() == PCB_VIA_T )
425 existingVias.push_back( static_cast<PCB_VIA*>( item ) );
426 }
427
428 bool changed = false;
429
430 auto removeVia =
431 [&]( PCB_VIA* aVia )
432 {
433 RemoveItem( aVia );
434 m_pendingRemovals.insert( aVia );
435 changed = true;
436 };
437
438 if( m_outline.IsEmpty() )
439 {
440 for( PCB_VIA* via : existingVias )
441 removeVia( via );
442
443 m_lastUpdateChangedVias = changed;
444 ClearDirty();
445 return false;
446 }
447
448 int pitch = m_pitch > 0 ? m_pitch : defaultPitch( aBoard );
449
450 if( m_viaTemplate->GetWidth( PADSTACK::ALL_LAYERS ) <= 0 )
451 m_viaTemplate->SetWidth( PADSTACK::ALL_LAYERS, defaultViaSize( aBoard ) );
452 if( m_viaTemplate->GetDrillValue() <= 0 )
453 m_viaTemplate->SetDrill( defaultViaDrill( aBoard ) );
454
455 // Compute the set of grid cells where a via fits cleanly (DRC + same-net zone overlap).
456 // TODO, we will use a cache grid
457 std::set<VECTOR2I> placementCells = buildPlacementCells( aBoard );
458
459 // Guard mode currently has to exclude by a proximity heuristic since we aren't using a grid.
460 const int64_t guardExcludeRadiusSq = ( (int64_t) pitch / 4 ) * ( pitch / 4 );
461
462 auto isExcluded =
463 [&]( const VECTOR2I& cell ) -> bool
464 {
465 // Guard vias are walked along the guarded net's envelope, so a stored position
466 // will rarely land exactly on a regenerated via. Match by proximity instead.
468 {
469 for( const VECTOR2I& excluded : m_excludedPositions )
470 {
471 VECTOR2I d = excluded - cell;
472
473 if( (int64_t) d.x * d.x + (int64_t) d.y * d.y < guardExcludeRadiusSq )
474 return true;
475 }
476
477 return false;
478 }
479
480 return usesGridCells() ? m_excludedCells.count( cell ) > 0
481 : m_excludedPositions.count( cell ) > 0;
482 };
483
484 // Get the new list of desired via cells
485 std::map<VECTOR2I, VECTOR2I> desired;
486
487 for( const VECTOR2I& cell : placementCells )
488 {
489 if( !isExcluded( cell ) )
490 desired.emplace( cell, positionForCell( cell, pitch ) );
491 }
492
493 // Determine existing vias we can keep
494 std::map<VECTOR2I, PCB_VIA*> kept;
495
496 for( PCB_VIA* via : existingVias )
497 {
498 VECTOR2I cell = cellForPosition( via->GetPosition() );
499
500 if( desired.count( cell ) && kept.emplace( cell, via ).second )
501 continue;
502
503 removeVia( via );
504 }
505
506 // Vias retired earlier may need to be unretired, this usually occurs when someone
507 // is shrinking the outline and then changes their mind in the same drag
508 std::map<VECTOR2I, PCB_VIA*> resurrectable;
509
511 resurrectable.try_emplace( cellForPosition( via->GetPosition() ), via );
512
513 // Now create a reference via to compare against, we need to see if existing vias need to be nuked
514 // anyway on a property change. In which case we will just regen rather than play games
515 std::unique_ptr<PCB_VIA> ref( static_cast<PCB_VIA*>( m_viaTemplate->Clone() ) );
516 ref->SetParent( aBoard );
517 ref->SetIsFree( true );
518
519 if( m_netCode )
520 ref->SetNetCode( m_netCode );
521
522 auto matchesRef =
523 [&]( const PCB_VIA* aVia ) -> bool
524 {
525 // The padstack carries size, drill, layer span, mask/paste attributes,
526 // backdrill and post-machining. That covers everything the via dialog
527 // can edit except the net and teardrop settings, checked separately.
528 return aVia->GetPosition() == ref->GetPosition()
529 && aVia->GetLayer() == ref->GetLayer()
530 && aVia->GetViaType() == ref->GetViaType()
531 && aVia->Padstack() == ref->Padstack()
532 && aVia->GetNetCode() == ref->GetNetCode()
533 && aVia->GetTeardropParams() == ref->GetTeardropParams();
534 };
535
536 for( const auto& [cell, pt] : desired )
537 {
538 auto it = kept.find( cell );
539
540 if( it != kept.end() )
541 {
542 PCB_VIA* via = it->second;
543
544 ref->SetPosition( pt );
545
546 if( matchesRef( via ) )
547 continue; // unchanged — no commit entry, UUID preserved
548
549 // Just nudge the via
550 ref->SetPosition( via->GetPosition() );
551
552 if( matchesRef( via ) )
553 {
554 aCommit->Modify( via );
555 via->SetPosition( pt );
556 changed = true;
557 continue;
558 }
559
560 removeVia( via );
561 }
562
563 // Resurrect a via retired earlier
564 auto rit = resurrectable.find( cell );
565
566 if( rit != resurrectable.end() )
567 {
568 PCB_VIA* via = rit->second;
569
570 ref->SetPosition( pt );
571
572 if( matchesRef( via ) )
573 {
574 m_pendingRemovals.erase( via );
575 AddItem( via );
576 changed = true;
577 continue;
578 }
579 }
580
581 PCB_VIA* via = static_cast<PCB_VIA*>( m_viaTemplate->Clone() );
582 via->ResetUuidDirect();
583
584 via->SetParent( aBoard );
585 via->SetPosition( pt );
586
587 if( m_netCode )
588 via->SetNetCode( m_netCode );
589
590 // Vias must be marked free to avoid connectivity stealing them away
591 via->SetIsFree( true );
592
593 // If the generator is selected (point editing), make sure to mark new vias
594 // as selected to match
595 if( IsSelected() )
596 via->SetSelected();
597
598 AddItem( via );
599 aCommit->Add( via );
600 changed = true;
601 }
602
603 m_lastUpdateChangedVias = changed;
604 ClearDirty();
605 return true;
606}
607
608
610{
612
613 props.set_iu( "pitch", m_pitch );
614 props.set( "layout", static_cast<int>( m_layout ) );
615 props.set( "mode", static_cast<int>( m_mode ) );
616 props.set( "seed", static_cast<int>( m_seed ) );
617 props.set_iu( "origin_offset_x", m_originOffset.x );
618 props.set_iu( "origin_offset_y", m_originOffset.y );
619
620 // Save the net by name so it survives across sessions (net codes are session-local)
621 if( !m_lastNetName.empty() )
622 props.set( "net_name", m_lastNetName );
623
624 if( !m_lastGuardedNetName.empty() )
625 props.set( "guarded_net_name", m_lastGuardedNetName );
626
627 if( !m_excludedCells.empty() )
628 {
629 std::vector<VECTOR2I> cells( m_excludedCells.begin(), m_excludedCells.end() );
630 props.set( "excluded_grid_cells", wxAny( cells ) );
631 }
632
633 if( !m_excludedPositions.empty() )
634 {
636 for( const VECTOR2I& pos : m_excludedPositions )
637 chain.Append( pos );
638 props.set( "excluded_positions", wxAny( chain ) );
639 }
640
641 // Serialize the single zone outline as a SHAPE_LINE_CHAIN.
642 // The file format natively supports SHAPE_LINE_CHAIN but not SHAPE_POLY_SET directly.
643 if( m_outline.OutlineCount() > 0 )
644 props.set( "outline", wxAny( m_outline.COutline( 0 ) ) );
645
646 return props;
647}
648
649
651{
653
654 aProps.get_to_iu( "pitch", m_pitch );
655
656 if( auto layout = aProps.get_opt<int>( "layout" ) )
657 m_layout = static_cast<PCB_VIA_STITCH_LAYOUT>( *layout );
658
659 if( auto mode = aProps.get_opt<int>( "mode" ) )
660 m_mode = static_cast<PCB_VIA_STITCH_MODE>( *mode );
661
662 if( auto seed = aProps.get_opt<int>( "seed" ) )
663 m_seed = static_cast<uint32_t>( *seed );
664
665 aProps.get_to_iu( "origin_offset_x", m_originOffset.x );
666 aProps.get_to_iu( "origin_offset_y", m_originOffset.y );
667
669
670 // Restore net name; net code is resolved from the board in EditStart()/Update()
671 aProps.get_to( "net_name", m_lastNetName );
672 aProps.get_to( "guarded_net_name", m_lastGuardedNetName );
673
674 m_excludedCells.clear();
675 m_excludedPositions.clear();
676
677
678 if( auto cells = aProps.get_opt<std::vector<VECTOR2I>>( "excluded_grid_cells" ) )
679 m_excludedCells.insert( cells->begin(), cells->end() );
680
681 if( auto chain = aProps.get_opt<SHAPE_LINE_CHAIN>( "excluded_positions" ) )
682 {
683 for( int i = 0; i < chain->PointCount(); ++i )
684 m_excludedPositions.insert( chain->CPoint( i ) );
685 }
686
687 // Restore the single zone outline
688 m_outline.RemoveAllContours();
689
690 if( auto outline = aProps.get_opt<SHAPE_LINE_CHAIN>( "outline" ) )
691 {
692 // A chain parsed from the file is a bare point list; the closed flag is not
693 // serialized and AddOutline() asserts on open chains
694 outline->SetClosed( true );
695 m_outline.AddOutline( *outline );
696 }
697}
698
699
700void PCB_VIA_STITCH::Serialize( google::protobuf::Any& aContainer ) const
701{
702 using namespace kiapi::board::types;
703 using namespace kiapi::common::types;
704
705 ViaStitchArea stitch;
706
707 stitch.mutable_id()->set_value( m_Uuid.AsStdString() );
708 stitch.set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( GetLayer() ) );
709 kiapi::common::PackPolySet( *stitch.mutable_outline(), m_outline );
710 stitch.mutable_pitch()->set_value_nm( pcbIUScale.IUToNm( m_pitch ) );
713
715 {
716 ViaStitchGuardSettings* guard = stitch.mutable_guard_settings();
717
718 if( !m_lastGuardedNetName.empty() )
719 guard->mutable_guarded_net()->set_name( m_lastGuardedNetName.ToUTF8() );
720 }
721 else
722 {
723 ViaStitchGridSettings* grid = stitch.mutable_grid_settings();
724 grid->mutable_origin_offset()->set_x_nm( pcbIUScale.IUToNm( m_originOffset.x ) );
725 grid->mutable_origin_offset()->set_y_nm( pcbIUScale.IUToNm( m_originOffset.y ) );
726 grid->set_seed( m_seed );
727
728 for( const VECTOR2I& cell : m_excludedCells )
729 {
730 GridCell* gridCell = grid->add_excluded_cells();
731 gridCell->set_i( cell.x );
732 gridCell->set_j( cell.y );
733 }
734 }
735
736 if( !m_lastNetName.empty() )
737 stitch.mutable_net()->set_name( m_lastNetName.ToUTF8() );
738
739 for( const VECTOR2I& pos : m_excludedPositions )
740 kiapi::common::PackVector2( *stitch.add_excluded_positions(), pos );
741
742 if( const PCB_VIA* viaTemplate = ViaTemplate() )
743 viaTemplate->Serialize( *stitch.mutable_via_template() );
744
745 stitch.set_locked( IsLocked() ? LockedState::LS_LOCKED : LockedState::LS_UNLOCKED );
746
747 if( const BOARD* board = GetBoard() )
748 stitch.mutable_parent()->set_value( board->m_Uuid.AsStdString() );
749
750 for( EDA_ITEM* member : GetItems() )
751 stitch.add_members()->set_value( member->m_Uuid.AsStdString() );
752
753 kiapi::common::PackCustomProperties( stitch.mutable_custom_properties(), *this );
754
755 if( !aContainer.PackFrom( stitch ) )
756 wxFAIL_MSG( wxT( "Failed to pack PCB_VIA_STITCH" ) );
757}
758
759
760bool PCB_VIA_STITCH::Deserialize( const google::protobuf::Any& aContainer )
761{
762 using namespace kiapi::board::types;
763 using namespace kiapi::common::types;
764
765 ViaStitchArea stitch;
766
767 if( !aContainer.UnpackTo( &stitch ) )
768 return false;
769
770 SetUuidDirect( ::KIID( stitch.id().value() ) );
771 SetLayer( FromProtoEnum<PCB_LAYER_ID>( stitch.layer() ) );
772 m_outline = kiapi::common::UnpackPolySet( stitch.outline() );
773 m_pitch = pcbIUScale.NmToIU( stitch.pitch().value_nm() );
776
777 m_lastNetName = wxString( stitch.net().name().c_str(), wxConvUTF8 );
778 m_lastGuardedNetName.clear();
779 m_netCode = 0;
781
782 m_excludedCells.clear();
783 m_excludedPositions.clear();
784
785 switch( stitch.mode_specific_settings_case() )
786 {
787 case ViaStitchArea::kGridSettings:
788 {
789 const ViaStitchGridSettings& grid = stitch.grid_settings();
790 m_originOffset.x = pcbIUScale.NmToIU( grid.origin_offset().x_nm() );
791 m_originOffset.y = pcbIUScale.NmToIU( grid.origin_offset().y_nm() );
792 m_seed = grid.seed();
793
794 for( const GridCell& cell : grid.excluded_cells() )
795 m_excludedCells.insert( VECTOR2I( cell.i(), cell.j() ) );
796
797 break;
798 }
799
800 case ViaStitchArea::kGuardSettings:
801 m_lastGuardedNetName = wxString( stitch.guard_settings().guarded_net().name().c_str(), wxConvUTF8 );
802 break;
803
804 case ViaStitchArea::MODE_SPECIFIC_SETTINGS_NOT_SET: break;
805 }
806
807 for( const kiapi::common::types::Vector2& pos : stitch.excluded_positions() )
809
810 if( stitch.has_via_template() )
811 {
812 std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( this );
813
814 if( !via->Deserialize( stitch.via_template() ) )
815 return false;
816
817 via->SetParent( this );
818 via->SetIsFree( true );
819 m_viaTemplate = std::move( via );
820 }
821
822 SetLocked( stitch.locked() == LockedState::LS_LOCKED );
823 kiapi::common::UnpackCustomProperties( stitch.custom_properties(), *this );
824
825 m_items.clear();
826 m_deserializedItems.clear();
827
828 BOARD* board = GetBoard();
829
830 if( !board )
831 return false;
832
833 for( const kiapi::common::types::KIID& memberId : stitch.members() )
834 {
835 if( EDA_ITEM* item = board->ResolveItem( ::KIID( memberId.value() ), true ) )
836 m_deserializedItems.insert( item );
837 }
838
840
841 return true;
842}
843
844
846{
847 if( !( GetFlags() & IN_EDIT ) )
848 return;
849
850 // The edit session is over, any vias still pending removal can now be committed
851 // for removal.
852 if( aCommit )
853 {
855 aCommit->Remove( via );
856 }
857
858 m_pendingRemovals.clear();
859
861}
862
863
865{
866 if( !( GetFlags() & IN_EDIT ) )
867 return;
868
869 // The commit is being reverted; re-attach retired vias so group membership matches
870 // the pre-edit state they revert to.
872 AddItem( via );
873
874 m_pendingRemovals.clear();
875
877}
878
879
881{
882 if( !m_childContextMenu )
883 {
884 m_childContextMenu = std::make_unique<ACTION_MENU>( true, aTool );
886 }
887
888 return m_childContextMenu.get();
889}
890
891
893{
894 if( !aCommit )
895 return;
896
897 for( BOARD_ITEM* item : GetBoardItems() )
898 aCommit->Remove( item );
899
900 // Retired-but-unpushed vias are detached from the group and would otherwise be
901 // orphaned on the board.
903 aCommit->Remove( via );
904
905 m_pendingRemovals.clear();
906
907 aCommit->Remove( this );
908}
909
910
912{
913 int pitch = m_pitch > 0 ? m_pitch : 1;
914
915 auto roundDiv = []( int a, int b ) -> int
916 {
917 return ( a >= 0 ) ? ( a + b / 2 ) / b : -( ( -a + b / 2 ) / b );
918 };
919
920 // Poisson layout and GUARD mode both place at arbitrary positions, not a grid —
921 // cell index == absolute position.
922 if( !usesGridCells() )
923 return aPos;
924
925 int row = roundDiv( aPos.y - m_originOffset.y, pitch );
926 int xShift = ( m_layout == PCB_VIA_STITCH_LAYOUT::STAGGERED && ( ( row % 2 + 2 ) % 2 != 0 ) )
927 ? pitch / 2
928 : 0;
929 int col = roundDiv( aPos.x - m_originOffset.x - xShift, pitch );
930
931 return VECTOR2I( col, row );
932}
933
934
935VECTOR2I PCB_VIA_STITCH::positionForCell( const VECTOR2I& aCell, int aPitch ) const
936{
937 if( !usesGridCells() )
938 return aCell;
939
940 int xShift = ( m_layout == PCB_VIA_STITCH_LAYOUT::STAGGERED && ( ( aCell.y % 2 + 2 ) % 2 != 0 ) )
941 ? aPitch / 2
942 : 0;
943 return VECTOR2I( aCell.x * aPitch + m_originOffset.x + xShift,
944 aCell.y * aPitch + m_originOffset.y );
945}
946
947
948std::set<VECTOR2I> PCB_VIA_STITCH::buildPlacementCells( BOARD* aBoard ) const
949{
950 std::set<VECTOR2I> cells;
951
952 if( !aBoard || m_outline.IsEmpty() )
953 return cells;
954
955 int pitch = m_pitch > 0 ? m_pitch : defaultPitch( aBoard );
956 int viaSize = m_viaTemplate->GetWidth( PADSTACK::ALL_LAYERS ) > 0 ? m_viaTemplate->GetWidth( PADSTACK::ALL_LAYERS )
957 : defaultViaSize( aBoard );
958
959 if( GetNetCode() == 0 )
960 return cells;
961
962 DRC_ENGINE* drcEngine = aBoard->GetDesignSettings().m_DRCEngine.get();
963
964 DRC_CACHE_GENERATOR cacheGenerator;
965 cacheGenerator.SetDRCEngine( drcEngine );
966 cacheGenerator.Run();
967
968 // Pre-clip every zone fill to the stitch outline bbox before adding it to perLayerFills.
969 // Without this, a board-wide GND zone would drag in an entire complex polygon when we may
970 // only be stitching part of it.
971 // This also helps us skip same net zones entirely if they aren't in here
972 BOX2I stitchBBox = m_outline.BBox();
973
974 SHAPE_POLY_SET stitchClip;
975 stitchClip.NewOutline();
976 stitchClip.Append( stitchBBox.GetLeft(), stitchBBox.GetTop() );
977 stitchClip.Append( stitchBBox.GetRight(), stitchBBox.GetTop() );
978 stitchClip.Append( stitchBBox.GetRight(), stitchBBox.GetBottom() );
979 stitchClip.Append( stitchBBox.GetLeft(), stitchBBox.GetBottom() );
980
981 std::map<PCB_LAYER_ID, SHAPE_POLY_SET> perLayerFills;
982
983 for( ZONE* zone : collectAllZones( aBoard ) )
984 {
985 if( zone->GetIsRuleArea() )
986 continue;
987
988 if( zone->GetNetCode() != GetNetCode() )
989 continue;
990
991 if( !zone->GetBoundingBox().Intersects( stitchBBox ) )
992 continue;
993
994 for( PCB_LAYER_ID layer : zone->GetLayerSet() )
995 {
996 SHAPE_POLY_SET clipped;
997
999 {
1000 clipped = zone->GetBoardOutline();
1001 }
1002 else
1003 {
1004 SHAPE_POLY_SET* fill = zone->GetFill( layer );
1005
1006 if( !fill || fill->IsEmpty() )
1007 continue;
1008
1009 clipped = *fill;
1010 }
1011
1012 if( clipped.IsEmpty() )
1013 continue;
1014
1015 clipped.BooleanIntersection( stitchClip );
1016
1017 if( clipped.OutlineCount() == 0 )
1018 continue;
1019
1020 perLayerFills[layer].BooleanAdd( clipped );
1021 }
1022 }
1023
1024 // Extract the via copper layers, the layer stack may contain the mask layers
1025 LSET boardCopperLayers = LSET::AllCuMask( aBoard->GetCopperLayerCount() );
1026 LSET viaCopperLayers = m_viaTemplate->GetLayerSet() & boardCopperLayers;
1027
1028 // Filter down to just those via layers that actually have same-net copper on them.
1029 std::vector<const SHAPE_POLY_SET*> viaLayerFills;
1030
1031 for( PCB_LAYER_ID layer : viaCopperLayers )
1032 {
1033 auto it = perLayerFills.find( layer );
1034
1035 if( it != perLayerFills.end() && !it->second.IsEmpty() )
1036 viaLayerFills.push_back( &it->second );
1037 }
1038
1039 // Is there even enough layers left to stitch?
1040 if( viaLayerFills.size() < 2 )
1041 return cells;
1042
1043 // Now build the region where a via would stitch at least two layers together.
1044 SHAPE_POLY_SET allowedRegion;
1045 SHAPE_POLY_SET coveredSoFar = *viaLayerFills[0];
1046
1047 for( size_t i = 1; i < viaLayerFills.size(); ++i )
1048 {
1049 SHAPE_POLY_SET overlap = *viaLayerFills[i];
1050 overlap.BooleanIntersection( coveredSoFar );
1051
1052 if( !overlap.IsEmpty() )
1053 allowedRegion.BooleanAdd( overlap );
1054
1055 if( i + 1 < viaLayerFills.size() )
1056 coveredSoFar.BooleanAdd( *viaLayerFills[i] );
1057 }
1058
1059 if( allowedRegion.OutlineCount() == 0 )
1060 return cells;
1061
1062 // Now intersect it with the via stitch outline
1063 allowedRegion.BooleanIntersection( m_outline );
1064
1065 if( allowedRegion.OutlineCount() == 0 )
1066 return cells;
1067
1068 // Generate a obstacle mask for via placement
1069 // Rather than DRC-probing every possible placement cell against the r-tree
1070 // to test for collisions. We instead create a keep-out polygon with obstacles
1071 // inflated by the via-radius and clearance we want. The result is now
1072 // we only have to do a point-in-polygon test for placement
1073
1074 const int polyApproxError = pcbIUScale.mmToIU( 0.005 );
1075
1076 // Require the whole via, not just its center, to land on same-net copper inside the
1077 // outline
1078 allowedRegion.Deflate( viaSize / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS, polyApproxError );
1079
1080 if( allowedRegion.OutlineCount() == 0 )
1081 return cells;
1082
1083 // Probe used for clearance evaluation; it must carry the stitch net because clearance
1084 // rules can key off the net class.
1085 std::unique_ptr<PCB_VIA> probe( static_cast<PCB_VIA*>( m_viaTemplate->Clone() ) );
1086 probe->SetParent( aBoard );
1087
1088 if( m_netCode )
1089 probe->SetNetCode( m_netCode );
1090
1091 const int worstClearance = aBoard->m_DRCMaxClearance;
1092
1093 BOX2I queryBBox = stitchBBox;
1094 queryBBox.Inflate( worstClearance + viaSize );
1095
1096 SHAPE_POLY_SET queryClip;
1097 queryClip.NewOutline();
1098 queryClip.Append( queryBBox.GetLeft(), queryBBox.GetTop() );
1099 queryClip.Append( queryBBox.GetRight(), queryBBox.GetTop() );
1100 queryClip.Append( queryBBox.GetRight(), queryBBox.GetBottom() );
1101 queryClip.Append( queryBBox.GetLeft(), queryBBox.GetBottom() );
1102
1103 SHAPE_POLY_SET obstacles;
1104
1105 int viaDrill = m_viaTemplate->GetDrillValue() > 0 ? m_viaTemplate->GetDrillValue()
1106 : defaultViaDrill( aBoard );
1107
1108 auto evalConstraint =
1109 [&]( DRC_CONSTRAINT_T aType, BOARD_ITEM* aOther, PCB_LAYER_ID aLayer ) -> int
1110 {
1111 if( !drcEngine )
1112 return 0;
1113
1114 DRC_CONSTRAINT constraint =
1115 drcEngine->EvalRules( aType, probe.get(), aOther, aLayer );
1116 return constraint.GetValue().Min();
1117 };
1118
1119 auto isSameNet =
1120 [&]( BOARD_ITEM* aOther ) -> bool
1121 {
1122 BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aOther );
1123 return cItem && cItem->GetNetCode() == GetNetCode();
1124 };
1125
1126 // Drilled holes are obstacles as we need to respect the hole to hole constraint
1127 std::set<BOARD_ITEM*> holeSeen;
1128
1129 auto addHoleObstacle =
1130 [&]( BOARD_ITEM* aOther, PCB_LAYER_ID aLayer )
1131 {
1132 if( !aOther->HasHole() || !holeSeen.insert( aOther ).second )
1133 return;
1134
1135 std::shared_ptr<SHAPE_SEGMENT> hole = aOther->GetEffectiveHoleShape();
1136
1137 if( !hole )
1138 return;
1139
1140 int margin = viaDrill / 2
1141 + evalConstraint( HOLE_TO_HOLE_CONSTRAINT, aOther, UNDEFINED_LAYER );
1142
1143 if( !isSameNet( aOther ) )
1144 {
1145 margin = std::max( margin,
1146 viaSize / 2 + evalConstraint( HOLE_CLEARANCE_CONSTRAINT,
1147 aOther, aLayer ) );
1148 }
1149
1150 TransformOvalToPolygon( obstacles, hole->GetSeg().A, hole->GetSeg().B,
1151 hole->GetWidth() + 2 * margin, polyApproxError,
1152 ERROR_OUTSIDE );
1153 };
1154
1155 SHAPE_RECT queryRect( queryBBox.GetPosition(), queryBBox.GetWidth(), queryBBox.GetHeight() );
1156
1157 for( PCB_LAYER_ID layer : viaCopperLayers )
1158 {
1159 std::set<BOARD_ITEM*> seen;
1160
1161 auto enumerate =
1162 [&]( BOARD_ITEM* aOther ) -> bool
1163 {
1164 if( !seen.insert( aOther ).second )
1165 return false;
1166
1167 // Our own children are regenerated along with us and must not block
1168 // their own cells.
1169 if( aOther->GetParentGroup() == static_cast<const EDA_GROUP*>( this ) )
1170 return false;
1171
1172 // Same for children retired during the same edit: they are
1173 // detached from the group but stay on the board until the commit is
1174 // pushed, and their cells must stay placeable so they can resurrect.
1175 if( aOther->Type() == PCB_VIA_T
1176 && m_pendingRemovals.count( static_cast<PCB_VIA*>( aOther ) ) )
1177 {
1178 return false;
1179 }
1180
1181 addHoleObstacle( aOther, layer );
1182
1183 bool sameNet = isSameNet( aOther );
1184
1185 if( aOther->Type() == PCB_PAD_T )
1186 {
1187 // A copper-zone can be placed with thermal reliefs turned off
1188 // We don't want to accidentally place vias on top of that pad
1189 // So process the PAD as a obstacle we need to clear
1190 PAD* pad = static_cast<PAD*>( aOther );
1191
1192 if( !pad->FlashLayer( layer ) )
1193 return false;
1194 }
1195 else if( aOther->Type() != PCB_VIA_T && sameNet )
1196 {
1197 return false;
1198 }
1199
1200 // Our copper against theirs.
1201 int margin = viaSize / 2 + evalConstraint( CLEARANCE_CONSTRAINT, aOther, layer );
1202
1203 // Our drill against their copper (hole clearance), cross-net only.
1204 if( !sameNet )
1205 {
1206 margin = std::max( margin,
1207 viaDrill / 2 + evalConstraint( HOLE_CLEARANCE_CONSTRAINT,
1208 aOther, layer ) );
1209 }
1210
1211 aOther->TransformShapeToPolygon( obstacles, layer, margin, polyApproxError,
1212 ERROR_OUTSIDE );
1213 return false;
1214 };
1215
1216 if( aBoard->m_CopperItemRTreeCache )
1217 {
1218 aBoard->m_CopperItemRTreeCache->CheckColliding( &queryRect, layer, worstClearance,
1219 enumerate );
1220 }
1221 }
1222
1223 // Add NPTH mounting holes which have no copper
1224 for( FOOTPRINT* footprint : aBoard->Footprints() )
1225 {
1226 if( !footprint->GetBoundingBox().Intersects( queryBBox ) )
1227 continue;
1228
1229 for( PAD* pad : footprint->Pads() )
1230 {
1231 if( pad->GetBoundingBox().Intersects( queryBBox ) )
1232 addHoleObstacle( pad, F_Cu );
1233 }
1234 }
1235
1236 obstacles.Simplify();
1237
1238 for( ZONE* zone : collectAllZones( aBoard ) )
1239 {
1240 if( !zone->GetBoundingBox().Intersects( queryBBox ) )
1241 continue;
1242
1243 if( zone->GetIsRuleArea() )
1244 {
1245 // Honor via keepouts (any net).
1246 if( !zone->GetDoNotAllowVias() || !( zone->GetLayerSet() & viaCopperLayers ).any() )
1247 continue;
1248
1249 SHAPE_POLY_SET area = zone->GetBoardOutline();
1250 area.BooleanIntersection( queryClip );
1251
1252 if( !area.IsEmpty() )
1253 {
1255 polyApproxError );
1256 obstacles.BooleanAdd( area );
1257 }
1258
1259 continue;
1260 }
1261
1262 if( zone->GetNetCode() == GetNetCode() )
1263 continue;
1264
1265 // A different-net zone only blocks near its fill outside its own outline.
1266 // A via dropped inside the zone is fine because the refill punches an anti-pad around it.
1267 for( PCB_LAYER_ID layer : LSET( zone->GetLayerSet() & viaCopperLayers ) )
1268 {
1269 SHAPE_POLY_SET* fill = zone->GetFill( layer );
1270
1271 if( !fill || fill->IsEmpty() )
1272 continue;
1273
1274 SHAPE_POLY_SET nearFill = *fill;
1275 nearFill.BooleanIntersection( queryClip );
1276
1277 if( nearFill.IsEmpty() )
1278 continue;
1279
1280 int zoneMargin = std::max(
1281 viaSize / 2 + evalConstraint( CLEARANCE_CONSTRAINT, zone, layer ),
1282 viaDrill / 2 + evalConstraint( HOLE_CLEARANCE_CONSTRAINT, zone, layer ) );
1283
1284 nearFill.Inflate( zoneMargin, CORNER_STRATEGY::ROUND_ALL_CORNERS, polyApproxError );
1285
1286 SHAPE_POLY_SET interior = zone->GetBoardOutline();
1287 interior.BooleanIntersection( queryClip );
1288 nearFill.BooleanSubtract( interior );
1289
1290 if( !nearFill.IsEmpty() )
1291 obstacles.BooleanAdd( nearFill );
1292 }
1293 }
1294
1295 allowedRegion.BooleanSubtract( obstacles );
1296
1297 if( allowedRegion.OutlineCount() == 0 )
1298 return cells;
1299
1300 allowedRegion.BuildBBoxCaches();
1301
1302 BOX2I bbox = allowedRegion.BBox();
1303
1304 auto isValid =
1305 [&]( const VECTOR2I& pt ) -> bool
1306 {
1307 return allowedRegion.Contains( pt, -1, 0, true );
1308 };
1309
1311 {
1312 // Walk the perimeter of each guarded-net item's clearance envelope, dropping
1313 // candidate vias every `pitch` of arc length. The envelope is the item's shape
1314 // inflated by (viaRadius + DRC clearance), so a via dropped on it sits at the
1315 // closest legal distance from the trace
1316 if( m_guardedNetCode == 0 )
1317 return cells;
1318
1319 // Merge every guarded-net item's clearance envelope into one polygon, and their bare
1320 // shapes into another so the sampler can tell facing vias from same-side ones.
1321 SHAPE_POLY_SET mergedEnvelope;
1322 SHAPE_POLY_SET mergedGuarded;
1323
1324 for( PCB_TRACK* track : aBoard->Tracks() )
1325 {
1326 if( track->GetNetCode() != m_guardedNetCode )
1327 continue;
1328
1329 if( !track->GetBoundingBox().Intersects( stitchBBox ) )
1330 continue;
1331
1332 PCB_LAYER_ID layer = track->GetLayer();
1333
1334 if( track->Type() == PCB_VIA_T )
1335 layer = F_Cu; // arbitrary copper layer for clearance evaluation
1336
1337 int requiredClearance = evalConstraint( CLEARANCE_CONSTRAINT, track, layer );
1338
1339 // Safety margin so envelope samples land outside the obstacle mask. The
1340 // guarded items are themselves obstacles, polygonized outward with up to
1341 // polyApproxError of overshoot, so the envelope must sit at least that much
1342 // further out; the extra 2µm absorbs the sample coordinates' integer rounding.
1343 const int safetyMargin = polyApproxError + pcbIUScale.mmToIU( 0.002 );
1344 int margin = viaSize / 2 + requiredClearance + safetyMargin;
1345
1346 SHAPE_POLY_SET envelope;
1347 track->TransformShapeToPolygon( envelope, layer, margin, polyApproxError,
1348 ERROR_OUTSIDE );
1349
1350 mergedEnvelope.BooleanAdd( envelope );
1351
1352 track->TransformShapeToPolygon( mergedGuarded, layer, 0, polyApproxError,
1353 ERROR_OUTSIDE );
1354 }
1355
1356 mergedEnvelope.Simplify();
1357 mergedGuarded.Simplify();
1358
1359 for( const VECTOR2I& pt : SampleGuardEnvelope( mergedEnvelope, mergedGuarded, pitch,
1360 isValid ) )
1361 {
1362 cells.insert( pt );
1363 }
1364
1365 return cells;
1366 }
1367
1369 {
1370 // We tile a one time generated toroidal Poisson pattern
1371 // across the bbox at (pitch * POISSON_TILE_PITCHES) per tile. The tiling is
1372 // anchored to the global (0, 0) origin plus a per-seed sub-tile shift.
1373 // This gives us a deterministic but non-grid distribution
1374 const std::vector<VECTOR2D>& tile = bakedPoissonTile();
1375 const int tileSize = std::max( 1, pitch * POISSON_TILE_PITCHES );
1376
1377 // Per-seed sub-tile origin shift in [0, tileSize).
1378 boost::random::mt19937 seedRng( m_seed );
1379 boost::random::uniform_real_distribution<double> uniform( 0.0, 1.0 );
1380 const double offsetX = uniform( seedRng ) * tileSize;
1381 const double offsetY = uniform( seedRng ) * tileSize;
1382
1383 // Range of tiles that intersect bbox. Tile (tx, ty) covers
1384 // [tx*tileSize + offset, (tx+1)*tileSize + offset).
1385 const int firstTileX = (int) std::floor( ( bbox.GetX() - offsetX ) / (double) tileSize );
1386 const int firstTileY = (int) std::floor( ( bbox.GetY() - offsetY ) / (double) tileSize );
1387 const int lastTileX = (int) std::floor( ( bbox.GetRight() - offsetX ) / (double) tileSize );
1388 const int lastTileY = (int) std::floor( ( bbox.GetBottom() - offsetY ) / (double) tileSize );
1389
1390 for( int ty = firstTileY; ty <= lastTileY; ++ty )
1391 {
1392 for( int tx = firstTileX; tx <= lastTileX; ++tx )
1393 {
1394 for( const VECTOR2D& s : tile )
1395 {
1396 VECTOR2I pt(
1397 (int) std::round( offsetX + ( tx + s.x ) * tileSize ),
1398 (int) std::round( offsetY + ( ty + s.y ) * tileSize ) );
1399
1400 if( !bbox.Contains( pt ) )
1401 continue;
1402
1403 if( isValid( pt ) )
1404 cells.insert( pt ); // Poisson "cell" == absolute position
1405 }
1406 }
1407 }
1408
1409 return cells;
1410 }
1411 else
1412 {
1413 // Anchor the grid to global (0, 0) + m_originOffset.
1414 int startRow = (int) std::floor( double( bbox.GetY() - m_originOffset.y ) / pitch );
1415 int startCol = (int) std::floor( double( bbox.GetX() - m_originOffset.x ) / pitch );
1416 VECTOR2I origin( startCol * pitch + m_originOffset.x, startRow * pitch + m_originOffset.y );
1417
1418 for( int row = startRow, y = origin.y; y <= bbox.GetBottom(); y += pitch, ++row )
1419 {
1420 // Odd rows are shifted right by half the pitch when stagger is enabled.
1421 int xOffset =
1422 ( m_layout == PCB_VIA_STITCH_LAYOUT::STAGGERED && ( ( row % 2 + 2 ) % 2 != 0 ) ) ? pitch / 2 : 0;
1423
1424 for( int col = startCol, x = origin.x + xOffset; x <= bbox.GetRight(); x += pitch, ++col )
1425 {
1426 VECTOR2I pt( x, y );
1427
1428 if( isValid( pt ) )
1429 cells.insert( VECTOR2I( col, row ) );
1430 }
1431 }
1432
1433 return cells;
1434 }
1435}
1436
1437
1439{
1440 std::vector<ZONE*> result;
1441
1442 // A regeneration that added, moved, or removed nothing can't have changed any
1443 // foreign-net anti-pads, so no refill is needed.
1445 return result;
1446
1447 const BOARD* brd = GetBoard();
1448
1449 if( !brd )
1450 return result;
1451
1452 BOX2I myBBox = GetBoundingBox();
1453
1454 // Lets return all intersecting zones with different nets
1455 for( ZONE* zone : collectAllZones( brd ) )
1456 {
1457 if( zone->GetIsRuleArea() )
1458 continue;
1459
1460 if( zone->GetNetCode() == m_netCode )
1461 continue;
1462
1463 if( !zone->GetBoundingBox().Intersects( myBBox ) )
1464 continue;
1465
1466 result.push_back( zone );
1467 }
1468
1469 return result;
1470}
1471
1472
1473void PCB_VIA_STITCH::OnZoneFillChanged( const std::vector<ZONE*>& aZones )
1474{
1475 if( m_netCode == 0 )
1476 return;
1477
1478 BOX2I myBBox = GetBoundingBox();
1479
1480 for( ZONE* zone : aZones )
1481 {
1482 if( zone->GetNetCode() != m_netCode )
1483 continue;
1484
1485 if( !zone->GetBoundingBox().Intersects( myBBox ) )
1486 continue;
1487
1488 MarkDirty();
1489 return;
1490 }
1491}
1492
1493
1495{
1496 BOARD_COMMIT commit( aEditFrame );
1497 GENERATOR_TOOL* genTool = aEditFrame->GetToolManager()->GetTool<GENERATOR_TOOL>();
1498
1499 commit.Modify( this );
1500
1501 DIALOG_VIA_STITCH_PROPERTIES dlg( aEditFrame, this );
1502
1503 if( dlg.ShowModal() != wxID_OK )
1504 return;
1505
1506 EditStart( genTool, GetBoard(), &commit );
1507 Update( genTool, GetBoard(), &commit );
1508 EditFinish( genTool, GetBoard(), &commit );
1509
1510 commit.Push( _( "Edit Via Stitching" ) );
1511}
1512
1513
1515{
1516 if( usesGridCells() )
1517 m_excludedCells.insert( cellForPosition( aPos ) );
1518 else
1519 m_excludedPositions.insert( aPos );
1520
1521 MarkDirty();
1522}
1523
1524
1526{
1527 if( usesGridCells() )
1528 m_excludedCells.erase( cellForPosition( aPos ) );
1529 else
1530 m_excludedPositions.erase( aPos );
1531
1532 MarkDirty();
1533}
1534
1535
1537{
1538 m_excludedCells.clear();
1539 m_excludedPositions.clear();
1540 MarkDirty();
1541}
1542
1543
1545{
1546 if( m_netCode == 0 && !m_lastNetName.empty() )
1547 {
1548 if( const BOARD* board = GetBoard() )
1549 {
1550 if( NETINFO_ITEM* net = board->FindNet( m_lastNetName ) )
1551 m_netCode = net->GetNetCode();
1552 }
1553 }
1554
1555 return m_netCode;
1556}
1557
1558
1560{
1561 if( m_guardedNetCode == 0 && !m_lastGuardedNetName.empty() )
1562 {
1563 if( const BOARD* board = GetBoard() )
1564 {
1565 if( NETINFO_ITEM* net = board->FindNet( m_lastGuardedNetName ) )
1566 m_guardedNetCode = net->GetNetCode();
1567 }
1568 }
1569
1570 return m_guardedNetCode;
1571}
1572
1573
1574void PCB_VIA_STITCH::SetNetCode( int aNetCode )
1575{
1576 m_netCode = aNetCode;
1577 if( BOARD* board = GetBoard() )
1578 {
1579 if( NETINFO_ITEM* net = board->FindNet( aNetCode ) )
1580 m_lastNetName = net->GetNetname();
1581 else
1582 m_lastNetName.clear();
1583 }
1584
1585 for( BOARD_ITEM* item : GetBoardItems() )
1586 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
1587 bci->SetNetCode( aNetCode );
1588
1589 MarkDirty();
1590}
1591
1592
1594{
1595 m_guardedNetCode = aNetCode;
1596
1597 if( BOARD* board = GetBoard() )
1598 {
1599 if( NETINFO_ITEM* net = board->FindNet( aNetCode ) )
1600 m_lastGuardedNetName = net->GetNetname();
1601 else
1602 m_lastGuardedNetName.clear();
1603 }
1604
1605 MarkDirty();
1606}
1607
1608
1609std::vector<ZONE*> PCB_VIA_STITCH::collectAllZones( const BOARD* aBoard )
1610{
1611 std::vector<ZONE*> zones;
1612
1613 if( !aBoard )
1614 return zones;
1615
1616 zones.reserve( aBoard->Zones().size() );
1617
1618 for( ZONE* zone : aBoard->Zones() )
1619 zones.push_back( zone );
1620
1621 for( FOOTPRINT* footprint : aBoard->Footprints() )
1622 {
1623 for( ZONE* zone : footprint->Zones() )
1624 zones.push_back( zone );
1625 }
1626
1627 return zones;
1628}
1629
1630
1631std::vector<VECTOR2I>
1633 const SHAPE_POLY_SET& aGuarded, int aPitch,
1634 const std::function<bool( const VECTOR2I& )>& aIsValid )
1635{
1636 std::vector<VECTOR2I> accepted;
1637
1638 if( aPitch <= 0 )
1639 return accepted;
1640
1641 // Keeps adjacent same-side vias from doubling up where the walk rounds a corner or an
1642 // end cap. Arc length will report back a larger than expected value in this case.
1643 const int64_t minDistSq = (int64_t) ( aPitch * 0.7 ) * (int64_t) ( aPitch * 0.7 );
1644
1645 auto farEnough =
1646 [&]( const VECTOR2I& pt ) -> bool
1647 {
1648 for( const VECTOR2I& other : accepted )
1649 {
1650 VECTOR2I d = other - pt;
1651
1652 if( (int64_t) d.x * d.x + (int64_t) d.y * d.y >= minDistSq )
1653 continue;
1654
1655 if( aGuarded.Collide( SEG( pt, other ) ) )
1656 continue;
1657
1658 return false;
1659 }
1660
1661 return true;
1662 };
1663
1664 auto walkChain =
1665 [&]( const SHAPE_LINE_CHAIN& chain )
1666 {
1667 double cursor = 0.0;
1668 double nextSample = aPitch / 2.0;
1669
1670 for( int i = 0; i < chain.SegmentCount(); ++i )
1671 {
1672 SEG seg = chain.CSegment( i );
1673 double segLen = ( VECTOR2D( seg.B ) - VECTOR2D( seg.A ) ).EuclideanNorm();
1674
1675 if( segLen < 1.0 )
1676 continue;
1677
1678 while( nextSample <= cursor + segLen )
1679 {
1680 double t = ( nextSample - cursor ) / segLen;
1681 VECTOR2I pt( (int) std::round( seg.A.x + t * ( seg.B.x - seg.A.x ) ),
1682 (int) std::round( seg.A.y + t * ( seg.B.y - seg.A.y ) ) );
1683
1684 nextSample += aPitch;
1685
1686 if( aIsValid( pt ) && farEnough( pt ) )
1687 accepted.push_back( pt );
1688 }
1689
1690 cursor += segLen;
1691 }
1692 };
1693
1694 for( int o = 0; o < aEnvelope.OutlineCount(); ++o )
1695 walkChain( aEnvelope.COutline( o ) );
1696
1697 return accepted;
1698}
1699
1700
1702{
1704 {
1711
1712 propMgr.AddProperty( new PROPERTY<PCB_VIA_STITCH, int>( _HKI( "Size" ),
1714
1715 propMgr.AddProperty( new PROPERTY<PCB_VIA_STITCH, int>( _HKI( "Drill" ),
1717
1718 propMgr.AddProperty( new PROPERTY<PCB_VIA_STITCH, int>( _HKI( "Pitch" ),
1720
1722 .Undefined( PCB_VIA_STITCH_LAYOUT::PLAIN )
1723 .Map( PCB_VIA_STITCH_LAYOUT::PLAIN, _HKI( "Plain grid" ) )
1724 .Map( PCB_VIA_STITCH_LAYOUT::STAGGERED, _HKI( "Staggered grid" ) )
1725 .Map( PCB_VIA_STITCH_LAYOUT::POISSON, _HKI( "Poisson disk" ) );
1726
1729 .SetAvailableFunc( []( INSPECTABLE* aItem ) -> bool
1730 {
1731 if( PCB_VIA_STITCH* stitch = dynamic_cast<PCB_VIA_STITCH*>( aItem ) )
1732 return stitch->GetMode() == PCB_VIA_STITCH_MODE::STITCH;
1733
1734 return true;
1735 } );
1736
1738 .Undefined( PCB_VIA_STITCH_MODE::STITCH )
1739 .Map( PCB_VIA_STITCH_MODE::STITCH, _HKI( "Stitch" ) )
1740 .Map( PCB_VIA_STITCH_MODE::GUARD, _HKI( "Guard" ) );
1741
1744
1745 propMgr.AddProperty( new PROPERTY<PCB_VIA_STITCH, uint32_t>( _HKI( "Seed" ),
1747 .SetAvailableFunc( []( INSPECTABLE* aItem ) -> bool
1748 {
1749 if( PCB_VIA_STITCH* stitch = dynamic_cast<PCB_VIA_STITCH*>( aItem ) )
1750 {
1751 return stitch->GetMode() == PCB_VIA_STITCH_MODE::STITCH
1752 && stitch->GetLayout() == PCB_VIA_STITCH_LAYOUT::POISSON;
1753 }
1754 return true;
1755 } );
1756
1759
1760 propMgr.AddProperty( new PROPERTY_ENUM<PCB_VIA_STITCH, int>( _HKI( "Guarded Net" ),
1762 .SetAvailableFunc( []( INSPECTABLE* aItem ) -> bool
1763 {
1764 if( PCB_VIA_STITCH* stitch = dynamic_cast<PCB_VIA_STITCH*>( aItem ) )
1765 return stitch->GetMode() == PCB_VIA_STITCH_MODE::GUARD;
1766
1767 return true;
1768 } );
1769
1770 // The stitch lives on its own GAL layer and the vias are multi-layer configured separately
1771 propMgr.Mask( TYPE_HASH( PCB_VIA_STITCH ), TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) );
1772 }
1774
1775
1778
1779
int index
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:56
@ ERROR_OUTSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
bool IsLocked() const override
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
Definition board_item.h:118
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2833
const ZONES & Zones() const
Definition board.h:469
int GetCopperLayerCount() const
Definition board.cpp:1155
const FOOTPRINTS & Footprints() const
Definition board.h:465
const TRACKS & Tracks() const
Definition board.h:463
std::shared_ptr< DRC_RTREE > m_CopperItemRTreeCache
Definition board.h:1810
int m_DRCMaxClearance
Definition board.h:1833
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
constexpr const Vec & GetPosition() const
Definition box2.h:214
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr coord_type GetY() const
Definition box2.h:211
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr coord_type GetX() const
Definition box2.h:210
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr coord_type GetBottom() const
Definition box2.h:225
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
int ShowModal() override
Modal properties editor for a PCB_VIA_STITCH generator.
virtual bool Run() override
Discard the board's run-time DRC caches and regenerate them from scratch.
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:129
Design Rule Checker object that performs all the DRC tests.
Definition drc_engine.h:129
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
bool CheckColliding(SHAPE *aRefShape, PCB_LAYER_ID aTargetLayer, int aClearance=0, std::function< bool(BOARD_ITEM *)> aFilter=nullptr) const
Definition drc_rtree.h:192
void SetDRCEngine(DRC_ENGINE *engine)
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
wxString m_name
Definition eda_group.h:106
std::unordered_set< EDA_ITEM * > m_items
Definition eda_group.h:105
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:78
void RemoveItem(EDA_ITEM *aItem)
Remove item from group.
Definition eda_group.cpp:77
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
std::unordered_set< EDA_ITEM * > m_deserializedItems
Definition eda_group.h:109
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:599
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
bool IsSelected() const
Definition eda_item.h:134
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:167
bool IsNew() const
Definition eda_item.h:131
static ENUM_MAP< T > & Instance()
Definition property.h:811
Handle actions specific to filling copper zones.
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Abstract interface for drawing on a 2D-surface.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
T Min() const
Definition minoptmax.h:29
Handle the data for a net.
Definition netinfo.h:50
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
static constexpr PCB_LAYER_ID TEMP_ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:181
Definition pad.h:61
static TOOL_ACTION excludeStitchVia
Exclude selected stitching vias from their parent via-stitch generator.
Common, abstract interface for edit frames.
PCB_GENERATOR_POLY(BOARD_ITEM *aParent, PCB_LAYER_ID aLayer)
SHAPE_POLY_SET m_outline
virtual void SetProperties(const STRING_ANY_MAP &aProps)
wxString m_generatorType
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
VECTOR2I m_origin
virtual const STRING_ANY_MAP GetProperties() const
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
void SetLocked(bool aLocked) override
int defaultViaDrill(const BOARD *aBoard) const
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
void SetTemplateItem(const wxString &aName, std::unique_ptr< BOARD_ITEM > aItem) override
Insert a template item (from board file loading)
int GetViaDrill() const
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
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.
void SetViaSize(int aVal)
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.
void ShowPropertiesDialog(PCB_BASE_EDIT_FRAME *aEditFrame) 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.
const STRING_ANY_MAP GetProperties() const override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
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.
int defaultPitch(const BOARD *aBoard) const
VECTOR2I m_originOffset
bool Update(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
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
std::set< PCB_VIA * > m_pendingRemovals
void Remove(GENERATOR_TOOL *, BOARD *, BOARD_COMMIT *) override
static const wxString DISPLAY_NAME
wxString m_lastGuardedNetName
int defaultViaSize(const BOARD *aBoard) const
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
void SetSeed(uint32_t aVal)
GRID_CONFIG m_childGridConfig
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void InitializeDefaults(BOARD *aBoard)
Fill in any unset via-template and pitch values from the board's design settings.
std::set< VECTOR2I > m_excludedCells
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...
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:275
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
void BuildBBoxCaches() const
Construct BBoxCaches for Contains(), below.
int OutlineCount() const
Return the number of outlines in the set.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
A name/value tuple with unique names and wxAny values.
void set_iu(const std::string &aKey, const T &aVar)
bool get_to(const std::string &aKey, T &aVar) const
std::optional< T > get_opt(const std::string &aKey) const
void set(const std::string &aKey, const T &aVar)
bool get_to_iu(const std::string &aKey, T &aVar) const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ROUND_ALL_CORNERS
All angles are rounded.
@ CLEARANCE_CONSTRAINT
@ HOLE_CLEARANCE_CONSTRAINT
@ HOLE_TO_HOLE_CONSTRAINT
#define _(s)
#define IN_EDIT
Item currently edited.
@ LAYER_VIA_STITCHING
Outline of via stitching generators.
Definition layer_ids.h:326
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
std::vector< VECTOR2D > ToroidalUnitTile(double aMinDist, uint32_t aSeed)
Bridson's "Fast Poisson Disk Sampling in Arbitrary Dimensions" with toroidal boundary conditions on t...
KICOMMON_API void PackPolySet(types::PolySet &aOutput, const SHAPE_POLY_SET &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
KICOMMON_API SHAPE_POLY_SET UnpackPolySet(const types::PolySet &aInput, const EDA_IU_SCALE &aScale)
STL namespace.
#define _HKI(x)
Definition page_info.cpp:40
static GENERATORS_MGR::REGISTER< PCB_TUNING_PATTERN > registerMe
static struct PCB_VIA_STITCH_DESC _PCB_VIA_STITCH_DESC
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.
@ STAGGERED
Odd rows shifted by half the pitch.
@ PLAIN
Regular row/column grid.
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define ENUM_TO_WXANY(type)
Definition property.h:918
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
@ PT_NET
Net selection property.
Definition property.h:70
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
Static helper to register a generator.
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
const SHAPE_LINE_CHAIN chain
wxString result
Test unit parsing edge cases and error handling.
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707