KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_via_stack.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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <algorithm>
21#include <cmath>
22#include <map>
23#include <set>
24#include <tuple>
25#include <vector>
26
28#include <math/util.h>
29
30#include <board.h>
31#include <board_commit.h>
33#include <footprint.h>
34#include <layer_range.h>
35#include <netinfo.h>
36#include <netclass.h>
37#include <pad.h>
38#include <zone.h>
39#include <lset.h>
40#include <padstack.h>
41#include <pcb_base_edit_frame.h>
42#include <pcb_track.h>
43#include <pcbnew_settings.h>
44#include <scoped_set_reset.h>
45#include <wx/choicdlg.h>
46#include <tool/actions.h>
47#include <tool/tool_manager.h>
48#include <view/view.h>
50#include <trigo.h>
51#include <view/view_controls.h>
52#include <api/api_enums.h>
53#include <api/api_utils.h>
54#include <api/board/board_types.pb.h>
55#include <google/protobuf/any.pb.h>
56
57#include <properties/property.h>
59
62#include <generators_mgr.h>
63#include <drc/drc_engine.h>
64#include <router/router_tool.h>
65#include <router/pns_router.h>
67#include <widgets/wx_infobar.h>
68#include <tools/drawing_tool.h>
70#include <tools/pcb_actions.h>
72#include <tools/pcb_selection.h>
73
74
75const wxString PCB_VIA_STACK::DISPLAY_NAME = _HKI( "Microvia Stack" );
76const wxString PCB_VIA_STACK::GENERATOR_TYPE = wxS( "via_stack" );
77
78
79static wxString styleToString( VIA_STACK_STYLE aStyle )
80{
81 return aStyle == VIA_STACK_STYLE::STAGGERED ? wxS( "staggered" ) : wxS( "stacked" );
82}
83
84
85static VIA_STACK_STYLE styleFromString( const wxString& aStr )
86{
87 return aStr == wxS( "staggered" ) ? VIA_STACK_STYLE::STAGGERED : VIA_STACK_STYLE::STACKED;
88}
89
90
91// Resolve a canonical copper layer name back to its id without needing a board.
92static PCB_LAYER_ID layerFromName( const wxString& aName, PCB_LAYER_ID aFallback )
93{
94 wxString name = aName;
95 int layer = LSET::NameToLayer( name );
96
97 if( layer >= 0 && layer < PCB_LAYER_ID_COUNT && !( layer & 1 ) && IsCopperLayer( layer ) )
98 return ToLAYER_ID( layer );
99
100 return aFallback;
101}
102
103
105 PCB_GENERATOR( aParent, aLayer ),
106 m_startLayer( aLayer ),
109 m_pitch( 0 ),
110 m_filled( true ),
111 m_capped( false ),
112 m_viaSize( 0 ),
113 m_viaDrill( 0 ),
114 m_useNetclass( false ),
115 m_netCode( 0 )
116{
119}
120
121
123{
124 for( BOARD_ITEM* item : GetBoardItems() )
125 {
126 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
127 return bci->GetNetCode();
128 }
129
130 return m_netCode;
131}
132
133
135{
136 m_netCode = aNet;
137
138 for( BOARD_ITEM* item : GetBoardItems() )
139 {
140 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
141 bci->SetNetCode( aNet );
142 }
143}
144
145
147{
148 if( !aBoard )
149 return false;
150
151 LSET enabled = LSET::AllCuMask( aBoard->GetCopperLayerCount() );
152
153 auto present = [&]( PCB_LAYER_ID aLayer )
154 {
155 return aLayer >= 0 && aLayer < PCB_LAYER_ID_COUNT && enabled.test( aLayer );
156 };
157
158 return present( aStart ) && present( aEnd ) && aStart != aEnd;
159}
160
161
162void PCB_VIA_STACK::Move( const VECTOR2I& aMoveVector )
163{
164 PCB_GENERATOR::Move( aMoveVector );
165
166 if( m_hops )
167 m_hops->Move( aMoveVector );
168}
169
170
171void PCB_VIA_STACK::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
172{
173 PCB_GENERATOR::Rotate( aRotCentre, aAngle );
174
175 if( m_hops )
176 m_hops->Rotate( aAngle, aRotCentre );
177}
178
179
180void PCB_VIA_STACK::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
181{
182 PCB_GENERATOR::Flip( aCentre, aFlipDirection );
183
184 if( m_hops )
185 m_hops->Mirror( aCentre, aFlipDirection );
186
189}
190
191
192void PCB_VIA_STACK::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
193{
194 PCB_GENERATOR::Mirror( aCentre, aFlipDirection );
195
196 if( m_hops )
197 m_hops->Mirror( MIRROR_AXIS( aCentre, aFlipDirection ) );
198}
199
200
201void PCB_VIA_STACK::Mirror( const SEG& aAxis )
202{
203 PCB_GENERATOR::Mirror( aAxis );
204
205 if( m_hops )
206 m_hops->Mirror( aAxis );
207}
208
209
210std::vector<int> PCB_VIA_STACK::ViewGetLayers() const
211{
212 std::vector<int> layers = { LAYER_ANCHOR };
213 LSET cuMask = LSET::AllCuMask();
214
215 if( const BOARD* board = GetBoard() )
216 cuMask &= board->GetEnabledLayers();
217
219 {
220 if( cuMask.Contains( layer ) )
221 layers.push_back( layer );
222 }
223
224 return layers;
225}
226
227
228void PCB_VIA_STACK::addMember( BOARD* aBoard, BOARD_COMMIT* aCommit, BOARD_ITEM* aItem )
229{
230 if( aCommit )
231 aCommit->Add( aItem );
232 else
233 aBoard->Add( aItem, ADD_MODE::APPEND, false );
234
235 AddItem( aItem );
236}
237
238
239std::pair<int, int> PCB_VIA_STACK::GetNetclassViaSize( BOARD* aBoard, int aNetCode )
240{
242 NETINFO_ITEM* net = aBoard->FindNet( aNetCode );
243 NETCLASS* nc = net ? net->GetNetClass() : nullptr;
244
245 return { ( nc && nc->HasuViaDiameter() ) ? nc->GetuViaDiameter() : bds.GetCurrentViaSize(),
246 ( nc && nc->HasuViaDrill() ) ? nc->GetuViaDrill() : bds.GetCurrentViaDrill() };
247}
248
249
250std::vector<BOARD_ITEM*> PCB_VIA_STACK::BuildMembers( BOARD* aBoard, int aNetCode ) const
251{
252 std::vector<BOARD_ITEM*> members;
253
254 if( !IsSpanValid( aBoard, m_startLayer, m_endLayer ) )
255 return members;
256
257 // Copper layers spanned, in physical stackup order.
258 std::vector<PCB_LAYER_ID> layers;
259
261 layers.push_back( layer );
262
263 if( layers.size() < 2 )
264 return members;
265
266 const int nHops = (int) layers.size() - 1;
267
269 int viaSize;
270 int viaDrill;
271
272 if( m_useNetclass )
273 {
274 std::tie( viaSize, viaDrill ) = GetNetclassViaSize( aBoard, aNetCode );
275 }
276 else
277 {
278 viaSize = m_viaSize > 0 ? m_viaSize : bds.GetCurrentViaSize();
279 viaDrill = m_viaDrill > 0 ? m_viaDrill : bds.GetCurrentViaDrill();
280 }
281
282 auto hopPos = [&]( int aIndex ) -> VECTOR2I
283 {
285 {
286 if( m_hops && aIndex < (int) m_hops->PointCount() )
287 return m_hops->CPoint( aIndex );
288
289 if( m_hops && m_hops->PointCount() > 1 )
290 {
291 int last = m_hops->PointCount() - 1;
292 VECTOR2I step = ( m_hops->CPoint( last ) - m_hops->CPoint( last - 1 ) ).Resize( m_pitch );
293
294 if( step != VECTOR2I( 0, 0 ) )
295 return m_hops->CPoint( last ) + step * ( aIndex - last );
296 }
297
298 return GetPosition() + VECTOR2I( (long long int) m_pitch * aIndex, 0 );
299 }
300
301 return GetPosition(); // stacked hops are coaxial
302 };
303
304 // One microvia per adjacent copper pair.
305 for( int i = 0; i < nHops; ++i )
306 {
307 PCB_VIA* via = new PCB_VIA( aBoard );
308 via->SetNetCode( aNetCode );
309 via->SetViaType( VIATYPE::MICROVIA );
310 via->SetLayerPair( layers[i], layers[i + 1] );
311 via->SetWidth( PADSTACK::ALL_LAYERS, viaSize );
312 via->SetDrill( viaDrill );
313 via->SetPosition( hopPos( i ) );
314
315 // Net class sizes follow the via rules, which can depend on each hop's layers and position
316 if( m_useNetclass )
317 via->SetSizeFromRules( viaSize, viaDrill );
318
319 // Only a hop reaching an outer layer has a face to cap.
320 bool capped = m_capped && ( IsExternalCopperLayer( layers[i] ) || IsExternalCopperLayer( layers[i + 1] ) );
321
322 // Stacked hops land on filled copper, and capping needs a filled via under it.
323 bool filled = ( m_style == VIA_STACK_STYLE::STACKED ) || m_filled || capped;
324
325 via->Padstack().Drill().is_filled = filled;
326 via->Padstack().Drill().is_capped = capped;
327
328 members.push_back( via );
329 }
330
331 // Staggered stacks need a short trace on each shared landing layer.
333 {
334 // The trace takes the net's width, not whatever the toolbar shows.
335 NETINFO_ITEM* net = aBoard->FindNet( aNetCode );
336 NETCLASS* nc = net ? net->GetNetClass() : nullptr;
337
338 int trackWidth = ( nc && nc->HasTrackWidth() ) ? nc->GetTrackWidth() : bds.GetCurrentTrackWidth();
339
340 DRC_ENGINE* drcEngine = bds.m_DRCEngine.get();
341
342 for( int i = 0; i < nHops - 1; ++i )
343 {
344 VECTOR2I a = hopPos( i );
345 VECTOR2I b = hopPos( i + 1 );
346
347 if( a == b )
348 continue;
349
350 PCB_TRACK* trace = new PCB_TRACK( aBoard );
351 trace->SetNetCode( aNetCode );
352 trace->SetStart( a );
353 trace->SetEnd( b );
354 trace->SetLayer( layers[i + 1] );
355
356 // Width rules can depend on the layer and the net, as the router resolves them
357 DRC_CONSTRAINT width;
358
359 if( drcEngine )
360 {
361 // Rebuilds are freed on each drag step, so their pointers must not seed the geometry caches
362 trace->SetFlags( ROUTER_TRANSIENT );
363 width = drcEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, trace, nullptr, layers[i + 1] );
365 }
366
367 int layerWidth = trackWidth;
368
369 if( !width.IsNull() && width.GetSeverity() != RPT_SEVERITY_IGNORE )
370 layerWidth = width.GetValue().PinnedOpt();
371
372 trace->SetWidth( std::max( bds.m_TrackMinWidth, layerWidth ) );
373
374 members.push_back( trace );
375 }
376 }
377
378 return members;
379}
380
381
382// Identifies the hop a member implements. Two members with the same key are interchangeable.
383static std::optional<std::tuple<int, int, int>> memberKey( BOARD_ITEM* aItem )
384{
385 if( aItem->Type() == PCB_VIA_T )
386 {
387 PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
388
389 return std::make_tuple( (int) PCB_VIA_T, (int) via->TopLayer(), (int) via->BottomLayer() );
390 }
391
392 if( aItem->Type() == PCB_TRACE_T )
393 return std::make_tuple( (int) PCB_TRACE_T, (int) aItem->GetLayer(), 0 );
394
395 return std::nullopt;
396}
397
398
399bool PCB_VIA_STACK::reuseMembers( BOARD_COMMIT* aCommit, const std::vector<BOARD_ITEM*>& aRebuilt )
400{
401 if( aRebuilt.empty() || aRebuilt.size() != GetItems().size() )
402 return false;
403
404 std::map<std::tuple<int, int, int>, BOARD_ITEM*> live;
405
406 for( BOARD_ITEM* item : GetBoardItems() )
407 {
408 std::optional<std::tuple<int, int, int>> key = memberKey( item );
409
410 if( !key || !live.emplace( *key, item ).second )
411 return false;
412 }
413
414 std::vector<std::pair<BOARD_ITEM*, BOARD_ITEM*>> matched;
415
416 for( BOARD_ITEM* fresh : aRebuilt )
417 {
418 std::optional<std::tuple<int, int, int>> key = memberKey( fresh );
419
420 if( !key )
421 return false;
422
423 auto it = live.find( *key );
424
425 if( it == live.end() )
426 return false;
427
428 matched.emplace_back( it->second, fresh );
429 live.erase( it );
430 }
431
432 for( const auto& [item, fresh] : matched )
433 {
434 if( aCommit )
435 aCommit->Modify( item );
436
437 if( item->Type() == PCB_VIA_T )
438 {
439 PCB_VIA* via = static_cast<PCB_VIA*>( item );
440 PCB_VIA* src = static_cast<PCB_VIA*>( fresh );
441
442 via->SetNetCode( src->GetNetCode() );
443 via->SetPosition( src->GetPosition() );
445 via->SetDrill( src->GetDrillValue() );
446 via->Padstack().Drill().is_filled = src->Padstack().Drill().is_filled;
447 via->Padstack().Drill().is_capped = src->Padstack().Drill().is_capped;
448 }
449 else
450 {
451 PCB_TRACK* trace = static_cast<PCB_TRACK*>( item );
452 PCB_TRACK* src = static_cast<PCB_TRACK*>( fresh );
453
454 trace->SetNetCode( src->GetNetCode() );
455 trace->SetStart( src->GetStart() );
456 trace->SetEnd( src->GetEnd() );
457 trace->SetWidth( src->GetWidth() );
458 }
459 }
460
461 return true;
462}
463
464
466{
467 int net = GetNetCode();
468 std::vector<BOARD_ITEM*> rebuilt = BuildMembers( aBoard, net );
469
470 if( rebuilt.empty() && !GetItems().empty() )
471 return;
472
473 // A drag rebuilds on every motion event. Replacing the members each time would stage an
474 // add and a remove per generation in one commit, and undo brings all of them back.
475 if( reuseMembers( aCommit, rebuilt ) )
476 {
477 for( BOARD_ITEM* item : rebuilt )
478 delete item;
479
480 return;
481 }
482
483 // Remove any existing members. For the commit path the item must be snapshotted for undo
484 // (aCommit->Remove) while it is STILL in this group, otherwise the undo image is ungrouped
485 // and undoing an edit leaves the vias loose. RemoveItem() unlinks it afterwards.
486 for( BOARD_ITEM* item : GetBoardItems() )
487 {
488 if( aCommit )
489 {
490 aCommit->Unmodify( item, nullptr );
491
492 // A member added by an earlier motion event in this commit is freed, not orphaned
493 if( !aCommit->RemoveOrDiscard( item ) )
494 RemoveItem( item );
495 }
496 else
497 {
498 RemoveItem( item );
499 aBoard->Remove( item );
500 delete item;
501 }
502 }
503
504 for( BOARD_ITEM* member : rebuilt )
505 addMember( aBoard, aCommit, member );
506}
507
508
510{
511 if( aCommit )
512 {
513 if( IsNew() )
514 {
515 aCommit->Add( this );
516 }
517 else
518 {
519 // Members must be staged before the move, not after.
520 aCommit->Modify( this, nullptr, RECURSE_MODE::RECURSE );
521 }
522 }
523
524 SetFlags( IN_EDIT );
525}
526
527
529{
530 if( !( GetFlags() & IN_EDIT ) )
531 return false;
532
533 if( !aBoard || !aCommit )
534 return false;
535
536 Regenerate( aBoard, aCommit );
537 return true;
538}
539
540
545
546
551
552
554{
555 if( !aCommit )
556 return;
557
558 for( BOARD_ITEM* item : GetBoardItems() )
559 {
560 aCommit->Unmodify( item, nullptr );
561 aCommit->Remove( item );
562 }
563
564 aCommit->Remove( this );
565}
566
567
568int PCB_VIA_STACK::FindNetAtPosition( BOARD* aBoard, const VECTOR2I& aPosition, PCB_LAYER_ID aLayer )
569{
570 for( FOOTPRINT* footprint : aBoard->Footprints() )
571 {
572 for( PAD* pad : footprint->Pads() )
573 {
574 // A mechanical hole carries no net, and must not hide copper under it.
575 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
576 continue;
577
578 if( pad->IsOnLayer( aLayer ) && pad->HitTest( aPosition ) )
579 return pad->GetNetCode();
580 }
581 }
582
583 for( PCB_TRACK* track : aBoard->Tracks() )
584 {
585 if( track->IsOnLayer( aLayer ) && track->HitTest( aPosition ) )
586 return track->GetNetCode();
587 }
588
589 for( ZONE* zone : aBoard->Zones() )
590 {
591 if( !zone->GetIsRuleArea() && zone->IsOnLayer( aLayer ) && zone->HitTestFilledArea( aLayer, aPosition ) )
592 {
593 return zone->GetNetCode();
594 }
595 }
596
597 return 0;
598}
599
600
601int PCB_VIA_STACK::FindNetAtPosition( BOARD* aBoard, const VECTOR2I& aPosition, const LSET& aLayers )
602{
603 for( PCB_LAYER_ID layer : aLayers.CuStack() )
604 {
605 if( int net = FindNetAtPosition( aBoard, aPosition, layer ) )
606 return net;
607 }
608
609 return 0;
610}
611
612
614{
615 SetStartLayer( aPreset.m_StartLayer );
616 m_endLayer = aPreset.m_EndLayer;
618 m_viaSize = aPreset.m_ViaSize;
619 m_viaDrill = aPreset.m_ViaDrill;
621 m_filled = aPreset.m_Filled;
622 m_capped = aPreset.m_Capped;
623 m_pitch = aPreset.m_Pitch;
624 m_presetName = aPreset.m_Name;
625}
626
627
629{
630 VIA_STACK_PRESET preset;
631
632 preset.m_Name = m_presetName;
633 preset.m_StartLayer = m_startLayer;
634 preset.m_EndLayer = m_endLayer;
636 preset.m_ViaSize = m_viaSize;
637 preset.m_ViaDrill = m_viaDrill;
639 preset.m_Filled = m_filled;
640 preset.m_Capped = m_capped;
641 preset.m_Pitch = m_pitch;
642
643 return preset;
644}
645
646
647// Copper layers in physical stack order, plus a layer -> position lookup.
648static void layerOrder( BOARD* aBoard, std::vector<PCB_LAYER_ID>& aOrder, std::map<int, int>& aOrdinals )
649{
650 int n = 0;
651
652 for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, aBoard->GetCopperLayerCount() ) )
653 {
654 aOrder.push_back( layer );
655 aOrdinals[layer] = n++;
656 }
657}
658
659
660PCB_VIA_STACK* PCB_VIA_STACK::CreateFromItems( const std::vector<BOARD_ITEM*>& aItems, BOARD* aBoard,
661 std::vector<BOARD_ITEM*>* aMembers, wxString* aError )
662{
663 std::vector<PCB_VIA*> vias;
664 std::vector<PCB_TRACK*> traces;
665
666 for( BOARD_ITEM* item : aItems )
667 {
668 if( item->Type() == PCB_VIA_T )
669 {
670 PCB_VIA* via = static_cast<PCB_VIA*>( item );
671
672 if( via->GetViaType() != VIATYPE::MICROVIA )
673 return nullptr;
674
675 if( dynamic_cast<PCB_GENERATOR*>( via->GetParentGroup() ) )
676 return nullptr;
677
678 if( !vias.empty() && via->GetNetCode() != vias.front()->GetNetCode() )
679 return nullptr;
680
681 // A stack carries one size for every hop, so a mixed selection would be resized
682 // by the next regeneration.
683 if( !vias.empty()
684 && ( via->GetWidth( PADSTACK::ALL_LAYERS ) != vias.front()->GetWidth( PADSTACK::ALL_LAYERS )
685 || via->GetDrillValue() != vias.front()->GetDrillValue() ) )
686 {
687 if( aError )
688 {
689 *aError = _( "The selected microvias have different diameters or hole sizes. A "
690 "microvia stack uses one size for every hop." );
691 }
692
693 return nullptr;
694 }
695
696 vias.push_back( via );
697 }
698 else if( item->Type() == PCB_TRACE_T )
699 {
700 traces.push_back( static_cast<PCB_TRACK*>( item ) );
701 }
702 else
703 {
704 return nullptr;
705 }
706 }
707
708 if( vias.size() < 2 )
709 return nullptr;
710
711 std::vector<PCB_LAYER_ID> order;
712 std::map<int, int> ordinals;
713 layerOrder( aBoard, order, ordinals );
714
715 // Each via must span one hop and together they must tile a contiguous range.
716 std::map<int, PCB_VIA*> hopByUpper;
717
718 for( PCB_VIA* via : vias )
719 {
720 auto top = ordinals.find( via->TopLayer() );
721 auto bot = ordinals.find( via->BottomLayer() );
722
723 if( top == ordinals.end() || bot == ordinals.end() )
724 return nullptr;
725
726 if( std::abs( top->second - bot->second ) != 1 )
727 return nullptr;
728
729 int upper = std::min( top->second, bot->second );
730
731 if( hopByUpper.count( upper ) )
732 return nullptr;
733
734 hopByUpper[upper] = via;
735 }
736
737 int first = hopByUpper.begin()->first;
738 int last = hopByUpper.rbegin()->first;
739
740 if( (int) hopByUpper.size() != last - first + 1 )
741 return nullptr;
742
743 PCB_VIA* topVia = hopByUpper.begin()->second;
744
745 bool coaxial = true;
746
747 for( PCB_VIA* via : vias )
748 {
749 if( via->GetPosition() != topVia->GetPosition() )
750 coaxial = false;
751 }
752
753 PCB_VIA_STACK* stack = new PCB_VIA_STACK( aBoard, F_Cu );
754
755 stack->SetStartLayer( order[first] );
756 stack->SetEndLayer( order[last + 1] );
757 stack->SetViaSize( topVia->GetWidth( PADSTACK::ALL_LAYERS ) );
758 stack->SetViaDrill( topVia->GetDrillValue() );
759 stack->SetNetCode( topVia->GetNetCode() );
760 stack->SetFilled( topVia->Padstack().Drill().is_filled.value_or( aBoard->GetDesignSettings().m_FillVias ) );
761
762 // Only a hop reaching an outer layer carries capping, so only those can say the stack is capped.
763 bool capped = false;
764
765 for( PCB_VIA* via : vias )
766 {
767 if( IsExternalCopperLayer( via->TopLayer() ) || IsExternalCopperLayer( via->BottomLayer() ) )
768 capped = capped || via->Padstack().Drill().is_capped.value_or( false );
769 }
770
771 stack->SetCapped( capped );
772 stack->SetPosition( topVia->GetPosition() );
773
774 if( coaxial )
775 {
777 stack->SetFilled( true );
778 }
779 else
780 {
782
783 SHAPE_LINE_CHAIN hops;
784
785 for( const auto& [upper, via] : hopByUpper )
786 hops.Append( via->GetPosition(), true );
787
788 stack->SetHops( hops );
789 stack->SetPitch( ( hops.CPoint( 1 ) - hops.CPoint( 0 ) ).EuclideanNorm() );
790 }
791
792 // Only traces that connect hop positions on a shared landing layer belong to the stack,
793 // anything else must stay loose or the next regenerate would delete it.
794 if( aMembers )
795 {
796 std::set<int> landing;
797 std::set<VECTOR2I> viaPositions;
798
799 for( int i = first + 1; i <= last; ++i )
800 landing.insert( order[i] );
801
802 for( PCB_VIA* via : vias )
803 viaPositions.insert( via->GetPosition() );
804
805 for( PCB_VIA* via : vias )
806 aMembers->push_back( via );
807
808 for( PCB_TRACK* trace : traces )
809 {
810 if( landing.count( trace->GetLayer() ) && trace->GetStart() != trace->GetEnd()
811 && trace->GetNetCode() == stack->GetNetCode() && viaPositions.count( trace->GetStart() )
812 && viaPositions.count( trace->GetEnd() ) )
813 {
814 aMembers->push_back( trace );
815 }
816 }
817 }
818
819 return stack;
820}
821
822
823// A loose microvia crossing more than one layer step is what an expansion turns into a stack.
824static bool isExpandableMicrovia( const std::map<int, int>& aOrdinals, PCB_VIA* aVia )
825{
826 if( aVia->GetViaType() != VIATYPE::MICROVIA || aVia->GetParentGroup() )
827 return false;
828
829 auto top = aOrdinals.find( aVia->TopLayer() );
830 auto bot = aOrdinals.find( aVia->BottomLayer() );
831
832 if( top == aOrdinals.end() || bot == aOrdinals.end() )
833 return false;
834
835 return std::abs( top->second - bot->second ) > 1;
836}
837
838
840{
841 std::vector<PCB_LAYER_ID> order;
842 std::map<int, int> ordinals;
843 layerOrder( aBoard, order, ordinals );
844
845 std::set<KIID> ids;
846
847 for( PCB_TRACK* track : aBoard->Tracks() )
848 {
849 if( track->Type() == PCB_VIA_T && isExpandableMicrovia( ordinals, static_cast<PCB_VIA*>( track ) ) )
850 ids.insert( track->m_Uuid );
851 }
852
853 return ids;
854}
855
856
858 const std::function<const VIA_STACK_PRESET*( PCB_VIA* )>& aMatcher )
859{
860 std::vector<PCB_LAYER_ID> order;
861 std::map<int, int> ordinals;
862 layerOrder( aBoard, order, ordinals );
863
864 std::vector<std::pair<PCB_VIA*, const VIA_STACK_PRESET*>> candidates;
865
866 for( PCB_TRACK* track : aBoard->Tracks() )
867 {
868 if( track->Type() != PCB_VIA_T )
869 continue;
870
871 PCB_VIA* via = static_cast<PCB_VIA*>( track );
872
873 if( !isExpandableMicrovia( ordinals, via ) )
874 continue;
875
876 const VIA_STACK_PRESET* preset = nullptr;
877
878 if( aMatcher )
879 {
880 preset = aMatcher( via );
881
882 if( !preset )
883 continue;
884 }
885
886 candidates.push_back( { via, preset } );
887 }
888
889 for( const auto& [via, preset] : candidates )
890 {
892 PCB_LAYER_ID bottom;
893 via->LayerPair( &top, &bottom );
894
895 PCB_VIA_STACK* stack = new PCB_VIA_STACK( aBoard, F_Cu );
896
897 if( preset )
898 stack->ApplyPreset( *preset );
899
900 stack->SetStartLayer( top );
901 stack->SetEndLayer( bottom );
903 stack->SetViaSize( via->GetWidth( PADSTACK::ALL_LAYERS ) );
904 stack->SetViaDrill( via->GetDrillValue() );
905 stack->SetNetCode( via->GetNetCode() );
906 stack->SetFilled( true );
907 stack->SetPosition( via->GetPosition() );
908
909 if( aCommit )
910 {
911 aCommit->Remove( via );
912 aCommit->Add( stack );
913 }
914 else
915 {
916 aBoard->Remove( via );
917 delete via;
918 aBoard->Add( stack, ADD_MODE::APPEND, false );
919 }
920
921 stack->Regenerate( aBoard, aCommit );
922 }
923
924 return (int) candidates.size();
925}
926
927
929{
930 // Dialog edits a scratch copy so the undo snapshot below sees the pre-edit settings.
931 PCB_VIA_STACK temp( GetBoard(), GetLayer() );
932 temp.ApplyPreset( ToPreset() );
933 temp.SetNetCode( GetNetCode() );
934
935 DIALOG_MICROVIA_STACK dlg( aEditFrame, &temp );
936
937 if( dlg.ShowModal() != wxID_OK )
938 return;
939
940 BOARD_COMMIT commit( aEditFrame );
941 GENERATOR_TOOL* tool = aEditFrame->GetToolManager()->GetTool<GENERATOR_TOOL>();
942
943 commit.Modify( this );
944 ApplyPreset( temp.ToPreset() );
945
946 // A staggered stack stores explicit hop positions, so re-space them to the (possibly new)
947 // pitch while keeping each hop's direction. Without this, editing the pitch changes the
948 // value but not the distance between vias.
949 if( m_style == VIA_STACK_STYLE::STAGGERED && m_hops && m_hops->PointCount() >= 2 )
950 {
951 SHAPE_LINE_CHAIN rescaled;
952 rescaled.Append( m_hops->CPoint( 0 ) );
953
954 for( int i = 1; i < m_hops->PointCount(); ++i )
955 {
956 VECTOR2I dir = m_hops->CPoint( i ) - m_hops->CPoint( i - 1 );
957
958 if( dir.EuclideanNorm() > 0 )
959 dir = dir.Resize( m_pitch );
960
961 rescaled.Append( rescaled.CPoint( i - 1 ) + dir, true );
962 }
963
964 SetHops( rescaled );
965 }
966
967 EditStart( tool, GetBoard(), &commit );
968
969 // If the stack has no net, inherit it from the copper it now sits on. This is the
970 // supported way to net a stack, the connecting traces are generator owned and locked.
971 // SetNetCode writes through to the members, so it has to follow EditStart staging them.
973 {
974 LSET span;
975
976 for( PCB_LAYER_ID layer : LAYER_RANGE( m_startLayer, m_endLayer, GetBoard()->GetCopperLayerCount() ) )
977 span.set( layer );
978
980 }
981
982 Update( tool, GetBoard(), &commit );
983 EditFinish( tool, GetBoard(), &commit );
984
985 commit.Push( GetCommitMessage() );
986}
987
988
990{
992
993 props.set( "start_layer", LSET::Name( m_startLayer ) );
994 props.set( "end_layer", LSET::Name( m_endLayer ) );
995 props.set( "style", styleToString( m_style ) );
996 props.set( "filled", m_filled );
997 props.set( "capped", m_capped );
998 props.set( "use_netclass", m_useNetclass );
999 props.set( "preset", m_presetName );
1000
1001 props.set_iu( "pitch", m_pitch );
1002 props.set_iu( "via_size", m_viaSize );
1003 props.set_iu( "via_drill", m_viaDrill );
1004
1005 if( m_hops )
1006 props.set( "hops", wxAny( *m_hops ) );
1007
1008 return props;
1009}
1010
1011
1013{
1015
1016 wxString layerName;
1017
1018 if( aProps.get_to( "start_layer", layerName ) )
1019 SetStartLayer( layerFromName( layerName, m_startLayer ) );
1020
1021 if( aProps.get_to( "end_layer", layerName ) )
1022 m_endLayer = layerFromName( layerName, m_endLayer );
1023
1024 wxString style;
1025
1026 if( aProps.get_to( "style", style ) )
1027 m_style = styleFromString( style );
1028
1029 aProps.get_to( "filled", m_filled );
1030 aProps.get_to( "capped", m_capped );
1031 aProps.get_to( "use_netclass", m_useNetclass );
1032 aProps.get_to( "preset", m_presetName );
1033
1034 aProps.get_to_iu( "pitch", m_pitch );
1035 aProps.get_to_iu( "via_size", m_viaSize );
1036 aProps.get_to_iu( "via_drill", m_viaDrill );
1037
1038 if( auto hops = aProps.get_opt<SHAPE_LINE_CHAIN>( "hops" ) )
1039 m_hops = *hops;
1040}
1041
1042
1043void PCB_VIA_STACK::Serialize( google::protobuf::Any& aContainer ) const
1044{
1045 using namespace kiapi::board::types;
1046 using namespace kiapi::common::types;
1047
1048 ViaStack stack;
1049
1050 stack.mutable_id()->set_value( m_Uuid.AsStdString() );
1051 stack.set_start_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_startLayer ) );
1052 stack.set_end_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( m_endLayer ) );
1054 stack.mutable_pitch()->set_value_nm( pcbIUScale.IUToNm( m_pitch ) );
1055 stack.set_filled( m_filled );
1056 stack.set_capped( m_capped );
1057 stack.mutable_via_size()->set_value_nm( pcbIUScale.IUToNm( m_viaSize ) );
1058 stack.mutable_via_drill()->set_value_nm( pcbIUScale.IUToNm( m_viaDrill ) );
1059 stack.set_use_netclass( m_useNetclass );
1060
1061 if( !m_presetName.empty() )
1062 stack.set_preset_name( m_presetName.ToUTF8() );
1063
1064 if( m_hops )
1065 kiapi::common::PackPolyLine( *stack.mutable_hops(), *m_hops );
1066
1067 if( GetNetCode() != 0 && GetBoard() )
1068 {
1069 if( NETINFO_ITEM* net = GetBoard()->FindNet( GetNetCode() ) )
1070 stack.mutable_net()->set_name( net->GetNetname().ToUTF8() );
1071 }
1072
1073 stack.set_locked( IsLocked() ? LockedState::LS_LOCKED : LockedState::LS_UNLOCKED );
1074
1075 if( const BOARD* board = GetBoard() )
1076 stack.mutable_parent()->set_value( board->m_Uuid.AsStdString() );
1077
1078 for( EDA_ITEM* member : GetItems() )
1079 stack.add_members()->set_value( member->m_Uuid.AsStdString() );
1080
1081 kiapi::common::PackCustomProperties( stack.mutable_custom_properties(), *this );
1082
1083 if( !aContainer.PackFrom( stack ) )
1084 wxFAIL_MSG( wxT( "Failed to pack PCB_VIA_STACK" ) );
1085}
1086
1087
1088bool PCB_VIA_STACK::Deserialize( const google::protobuf::Any& aContainer )
1089{
1090 using namespace kiapi::board::types;
1091 using namespace kiapi::common::types;
1092
1093 kiapi::board::types::ViaStack stack;
1094
1095 if( !aContainer.UnpackTo( &stack ) )
1096 return false;
1097
1098 SetUuidDirect( ::KIID( stack.id().value() ) );
1099 SetStartLayer( FromProtoEnum<PCB_LAYER_ID>( stack.start_layer() ) );
1100 SetEndLayer( FromProtoEnum<PCB_LAYER_ID>( stack.end_layer() ) );
1101 m_style = FromProtoEnum<VIA_STACK_STYLE>( stack.style() );
1102 m_pitch = pcbIUScale.NmToIU( stack.pitch().value_nm() );
1103 m_filled = stack.filled();
1104 m_capped = stack.capped();
1105 m_useNetclass = stack.use_netclass();
1106
1107 if( stack.has_preset_name() )
1108 m_presetName = wxString( stack.preset_name().c_str(), wxConvUTF8 );
1109 else
1110 m_presetName.clear();
1111
1112 if( stack.has_hops() )
1113 m_hops = kiapi::common::UnpackPolyLine( stack.hops() );
1114 else
1115 m_hops.reset();
1116
1117 if( stack.net().name().empty() )
1118 m_netCode = 0;
1119
1120 SetLocked( stack.locked() == LockedState::LS_LOCKED );
1121 kiapi::common::UnpackCustomProperties( stack.custom_properties(), *this );
1122
1123 m_items.clear();
1124 m_deserializedItems.clear();
1125
1126 BOARD* board = GetBoard();
1127
1128 if( !board )
1129 return false;
1130
1131 for( const kiapi::common::types::KIID& memberId : stack.members() )
1132 {
1133 if( EDA_ITEM* item = board->ResolveItem( ::KIID( memberId.value() ), true ) )
1134 m_deserializedItems.insert( item );
1135 }
1136
1137 return true;
1138}
1139
1140
1142
1143
1145{
1146 // Consume any router handoff seed (a pre-anchored staggered stack).
1147 bool seeded = m_viaStackSeeded;
1148 VECTOR2I seedPos = m_viaStackSeedPos;
1151 m_viaStackSeeded = false;
1152
1154 return 0;
1155
1156 if( m_inDrawingTool )
1157 return 0;
1158
1160
1161 m_toolMgr->RunAction( ACTIONS::selectionClear );
1162 m_frame->PushTool( aEvent );
1163 Activate();
1164
1165 BOARD* board = m_frame->GetBoard();
1166 SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA );
1167
1168 PCB_VIA_STACK settings( board, F_Cu );
1169
1170 // Place silently with the preset currently selected in the toolbar, matching how via
1171 // placement uses the current via size. Only fall back to the properties dialog when no
1172 // presets are defined yet, so there is still a way to place and define one.
1173 const std::vector<VIA_STACK_PRESET>& presets = board->GetDesignSettings().m_ViaStackPresets;
1174 int idx = board->GetDesignSettings().GetViaStackIndex();
1175
1176 if( !presets.empty() )
1177 {
1178 settings.ApplyPreset( presets[std::clamp( idx, 0, (int) presets.size() - 1 )] );
1179 }
1180 else if( !seeded )
1181 {
1182 DIALOG_MICROVIA_STACK dlg( m_frame, &settings );
1183
1184 if( dlg.ShowModal() != wxID_OK )
1185 {
1186 m_frame->PopTool( aEvent );
1187 return 0;
1188 }
1189 }
1190
1191 // A router handoff anchors the span to the routed layers and is always a staggered walk.
1192 if( seeded )
1193 {
1194 settings.SetStartLayer( seedStart );
1195 settings.SetEndLayer( seedEnd );
1197 }
1198
1199 bool staggered = settings.GetStyle() == VIA_STACK_STYLE::STAGGERED;
1200
1201 if( !PCB_VIA_STACK::IsSpanValid( board, settings.GetStartLayer(), settings.GetEndLayer() ) )
1202 {
1203 m_frame->ShowInfoBarError( _( "The microvia stack layers are not present on this board." ) );
1204 m_frame->PopTool( aEvent );
1205 return 0;
1206 }
1207
1208 std::vector<PCB_LAYER_ID> spanLayers;
1209
1210 for( PCB_LAYER_ID layer :
1211 LAYER_RANGE( settings.GetStartLayer(), settings.GetEndLayer(), board->GetCopperLayerCount() ) )
1212 spanLayers.push_back( layer );
1213
1214 LSET spanSet;
1215
1216 for( PCB_LAYER_ID layer : spanLayers )
1217 spanSet.set( layer );
1218
1219 int nHops = (int) spanLayers.size() - 1;
1220
1221 // A zero pitch would pin the steering circle onto a single point.
1222 if( staggered && settings.GetPitch() <= 0 )
1223 {
1224 int dia = settings.GetViaSize() > 0 ? settings.GetViaSize() : board->GetDesignSettings().GetCurrentViaSize();
1225 settings.SetPitch( dia * 2 );
1226 }
1227
1228 if( nHops < 1 )
1229 {
1230 m_frame->PopTool( aEvent );
1231 return 0;
1232 }
1233
1234 PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
1235 PCB_SELECTION preview;
1236 std::vector<BOARD_ITEM*> previewItems;
1237 std::vector<VECTOR2I> hops;
1238 VECTOR2I lastDir( 1, 0 );
1239 bool resumeRouting = false; // seeded handoff places one and routes on
1240 VECTOR2I resumePos;
1241 VECTOR2I lastViaPos;
1242
1243 // Router handoff: the first hop is fixed at the routed head, the user steers the rest.
1244 if( seeded )
1245 hops.push_back( seedPos );
1246
1247 m_view->Add( &preview );
1248
1249 auto clearPreview = [&]()
1250 {
1251 preview.Clear();
1252
1253 for( BOARD_ITEM* item : previewItems )
1254 delete item;
1255
1256 previewItems.clear();
1257 };
1258
1259 // DRC context, shared with the plain via tool so a stack is refused over foreign copper the
1260 // same way (unless "Allow DRC violations" is enabled in the router settings).
1261 DRC_ENGINE* drcEngine = board->GetDesignSettings().m_DRCEngine.get();
1262 int drcEpsilon = board->GetDesignSettings().GetDRCEpsilon();
1263 int worstClearance = ComputeWorstViaClearance( m_frame, drcEngine );
1264 bool allowDRCViolations = false;
1265
1266 if( ROUTER_TOOL* router = m_toolMgr->GetTool<ROUTER_TOOL>() )
1267 allowDRCViolations = router->Router()->Settings().AllowDRCViolations();
1268
1269 auto updatePreview =
1270 [&]( const VECTOR2I& aCursor )
1271 {
1272 clearPreview();
1273
1274 if( staggered )
1275 {
1277
1278 for( const VECTOR2I& p : hops )
1279 chain.Append( p, true );
1280
1281 chain.Append( aCursor, true );
1282 settings.SetHops( chain );
1283 settings.SetPosition( hops.empty() ? aCursor : hops.front() );
1284
1285 // Only preview the placed hops plus the one being steered, not the
1286 // rest of the span extrapolated in a straight line.
1287 int previewHops = std::min( (int) hops.size() + 1, nHops );
1288 settings.SetEndLayer( spanLayers[previewHops] );
1289 }
1290 else
1291 {
1292 settings.SetPosition( aCursor );
1293 }
1294
1295 previewItems = settings.BuildMembers( board, 0 );
1296
1297 for( BOARD_ITEM* item : previewItems )
1298 preview.Add( item );
1299
1300 m_view->Update( &preview );
1301 };
1302
1303 auto placeStack =
1304 [&]( const VECTOR2I& aCursor ) -> bool
1305 {
1306 BOARD_COMMIT commit( m_frame );
1307 PCB_VIA_STACK* stack = static_cast<PCB_VIA_STACK*>( settings.Clone() );
1308 GENERATOR_TOOL* genTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
1309
1310 // Clone keeps the source uuid, each placed stack needs its own.
1311 stack->SetUuidDirect( KIID() );
1312 stack->SetParent( board );
1313
1314 // The preview may have truncated the span, place the full one.
1315 stack->SetEndLayer( spanLayers.back() );
1316
1317 if( staggered )
1318 {
1320
1321 for( const VECTOR2I& p : hops )
1322 chain.Append( p, true );
1323
1324 stack->SetHops( chain );
1325 stack->SetPosition( hops.front() );
1326 }
1327 else
1328 {
1329 stack->ClearHops();
1330 stack->SetPosition( aCursor );
1331 }
1332
1333 // Inherit the net of whatever the first hop lands on.
1334 stack->SetNetCode( PCB_VIA_STACK::FindNetAtPosition( board, stack->GetPosition(), spanSet ) );
1335 stack->SetFlags( IS_NEW );
1336
1337 // Refuse placement over foreign copper, matching the plain via tool. Build the
1338 // stack's vias off-board and check each before anything is committed.
1339 std::vector<BOARD_ITEM*> candidates = stack->BuildMembers( board, stack->GetNetCode() );
1340 bool violates = false;
1341
1342 for( BOARD_ITEM* item : candidates )
1343 {
1344 if( BOARD_CONNECTED_ITEM* copper = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
1345 {
1346 // Candidates are freed below, so their pointers must not seed the rule caches
1347 copper->SetFlags( ROUTER_TRANSIENT );
1348
1349 if( CheckItemDRCViolation( copper, m_frame, drcEngine, worstClearance, drcEpsilon ) )
1350 {
1351 violates = true;
1352 break;
1353 }
1354 }
1355 }
1356
1357 for( BOARD_ITEM* item : candidates )
1358 delete item;
1359
1360 if( violates && !allowDRCViolations )
1361 {
1362 m_frame->ShowInfoBarError( _( "Microvia stack location violates DRC." ), true,
1363 WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION );
1364 delete stack;
1365 return false;
1366 }
1367
1368 stack->EditStart( genTool, board, &commit );
1369 stack->Update( genTool, board, &commit );
1370 stack->EditFinish( genTool, board, &commit );
1371
1372 stack->ClearFlags( IS_NEW );
1373
1374 // Only the last hop reaches the end layer, and a staggered one is not at the cursor.
1375 for( BOARD_ITEM* item : stack->GetBoardItems() )
1376 {
1377 PCB_VIA* via = dynamic_cast<PCB_VIA*>( item );
1378
1379 if( via && via->IsOnLayer( stack->GetEndLayer() ) )
1380 {
1381 lastViaPos = via->GetPosition();
1382 break;
1383 }
1384 }
1385
1386 commit.Push( _( "Place Microvia Stack" ) );
1387 return true;
1388 };
1389
1390 // Snap the anchor onto nearby copper, using the plain via tool's routines so tracks,
1391 // arcs and pads all behave the same. A stack may land on any layer it spans, so the
1392 // probe carries the whole span rather than a single layer.
1393 int snapViaDia = settings.GetViaSize() > 0 ? settings.GetViaSize()
1394 : board->GetDesignSettings().GetCurrentViaSize();
1395
1396 PCB_VIA probe( board );
1398 probe.SetWidth( PADSTACK::ALL_LAYERS, snapViaDia );
1399 probe.SetLayerPair( settings.GetStartLayer(), settings.GetEndLayer() );
1400
1401 auto snapToCopper =
1402 [&]( const VECTOR2I& aCursor, bool aItemSnap ) -> VECTOR2I
1403 {
1404 MAGNETIC_SETTINGS* mag = m_frame->GetMagneticItemsSettings();
1405
1406 // The loop clears grid snap for the ResolveSnap base, re-enable it here so
1407 // AlignToSegment actually aligns, matching VIA_PLACER::SnapItem.
1408 grid.SetSnap( aItemSnap );
1409
1410 if( aItemSnap && mag )
1411 {
1413 {
1414 if( PCB_TRACK* track = FindSnapTrack( m_frame, &probe, aCursor, spanSet,
1415 ViaSnapRange( m_frame ) ) )
1416 {
1417 return grid.AlignToSegment( aCursor, SEG( track->GetStart(), track->GetEnd() ) );
1418 }
1419 }
1420
1421 if( mag->pads != MAGNETIC_OPTIONS::NO_EFFECT )
1422 {
1423 if( PAD* pad = FindSnapPad( m_frame, &probe, aCursor, spanSet, ViaSnapRange( m_frame ) ) )
1424 return pad->GetPosition();
1425 }
1426 }
1427
1428 return grid.ResolveSnap( aCursor, nullptr ).position;
1429 };
1430
1431 auto setCursor =
1432 [&]()
1433 {
1434 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
1435 };
1436
1437 m_controls->ShowCursor( true );
1438 m_controls->SetAutoPan( true );
1439 setCursor();
1440
1441 while( TOOL_EVENT* evt = Wait() )
1442 {
1443 setCursor();
1444
1445 // Match the via tool: item snaps are handled below, the grid helper only does
1446 // grid and anchor snapping against the GAL grid state.
1447 grid.SetSnap( false );
1448 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1449
1450 bool allowItemSnap = !evt->Modifier( MD_SHIFT );
1451 VECTOR2I rawCursor = m_controls->GetMousePosition();
1452 VECTOR2I cursorPos;
1453
1454 if( staggered && !hops.empty() )
1455 {
1456 // Cursor is locked onto a circle of radius = pitch around the previous hop.
1457 // It steers direction only, following the editor angle mode.
1458 VECTOR2I dir = rawCursor - hops.back();
1459
1460 if( dir.EuclideanNorm() < 1 )
1461 dir = VECTOR2I( 1, 0 );
1462
1463 LEADER_MODE angleSnap = GetAngleSnapMode();
1464
1465 if( evt->Modifier( MD_CTRL ) )
1466 angleSnap = LEADER_MODE::DIRECT;
1467
1468 if( angleSnap != LEADER_MODE::DIRECT )
1469 {
1470 double step = ( angleSnap == LEADER_MODE::DEG90 ) ? M_PI / 2 : M_PI / 4;
1471 double ang = atan2( (double) dir.y, (double) dir.x );
1472 ang = round( ang / step ) * step;
1473
1474 cursorPos = hops.back()
1475 + VECTOR2I( KiROUND( cos( ang ) * settings.GetPitch() ),
1476 KiROUND( sin( ang ) * settings.GetPitch() ) );
1477 }
1478 else
1479 {
1480 cursorPos = hops.back() + dir.Resize( settings.GetPitch() );
1481 }
1482
1483 lastDir = cursorPos - hops.back();
1484 }
1485 else
1486 {
1487 cursorPos = snapToCopper( rawCursor, allowItemSnap );
1488 }
1489
1490 // Only the staggered pitch circle locks the cursor. For the anchor and the
1491 // stacked case let the cross follow the mouse and snap the preview item instead,
1492 // exactly like plain via placement.
1493 if( staggered && !hops.empty() )
1494 m_controls->ForceCursorPosition( true, cursorPos );
1495 else
1496 m_controls->ForceCursorPosition( false );
1497
1498 if( evt->IsCancelInteractive() || evt->IsActivate() )
1499 {
1500 break;
1501 }
1502 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT )
1503 || evt->IsAction( &ACTIONS::cursorClick ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
1504 {
1505 // The tool stays active for repeated placement, Esc leaves. Rapid clicks
1506 // arrive as double clicks and must place hops too.
1507 if( staggered )
1508 {
1509 hops.push_back( cursorPos );
1510
1511 if( (int) hops.size() >= nHops )
1512 {
1513 if( !placeStack( cursorPos ) )
1514 {
1515 // Blocked by DRC, let the user reposition the final hop and retry.
1516 hops.pop_back();
1517 }
1518 else
1519 {
1520 hops.clear();
1521 clearPreview();
1522
1523 // A router handoff places exactly one stack, then returns to routing.
1524 if( seeded )
1525 {
1526 resumeRouting = true;
1527 resumePos = lastViaPos;
1528 break;
1529 }
1530 }
1531 }
1532 else
1533 {
1534 // Show the next hop right away, continuing in the last direction,
1535 // instead of waiting for the mouse to move.
1536 cursorPos = hops.back() + lastDir.Resize( settings.GetPitch() );
1537 m_controls->ForceCursorPosition( true, cursorPos );
1538 updatePreview( cursorPos );
1539 }
1540 }
1541 else
1542 {
1543 if( placeStack( cursorPos ) )
1544 {
1545 clearPreview();
1546
1547 if( seeded )
1548 {
1549 resumeRouting = true;
1550 resumePos = lastViaPos;
1551 break;
1552 }
1553 }
1554 }
1555 }
1556 else if( evt->IsAction( &ACTIONS::undo ) || evt->IsAction( &ACTIONS::doDelete ) )
1557 {
1558 // Swallowed for the whole loop like the router does, or it would undo the
1559 // route this placement was handed off from.
1560 if( staggered && hops.size() > ( seeded ? 1u : 0u ) )
1561 {
1562 hops.pop_back();
1563 lastDir = VECTOR2I( 1, 0 );
1564 updatePreview( cursorPos );
1565 }
1566 }
1567 else if( evt->IsClick( BUT_RIGHT ) )
1568 {
1569 m_toolMgr->VetoContextMenuMouseWarp();
1570 m_menu->ShowContextMenu( selection() );
1571 }
1572 else if( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) )
1573 {
1574 updatePreview( cursorPos );
1575 }
1576 else
1577 {
1578 evt->SetPassEvent();
1579 }
1580 }
1581
1582 clearPreview();
1583 m_view->Remove( &preview );
1584 m_controls->ForceCursorPosition( false );
1585 m_controls->SetAutoPan( false );
1586 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1587 m_frame->PopTool( aEvent );
1588
1589 // Return to routing from the last placed via when handed off from the router. Do not warp
1590 // the view (last arg false), recentering the canvas mid-workflow is jarring, unlike a via.
1591 // Priming starts the route at the via itself, not at whatever the next click snaps to.
1592 if( resumeRouting )
1593 {
1594 m_frame->SetActiveLayer( settings.GetEndLayer() );
1595
1596 if( ROUTER_TOOL* router = m_toolMgr->GetTool<ROUTER_TOOL>() )
1597 router->SetViaStackResumeLayer( settings.GetEndLayer() );
1598
1599 m_controls->WarpMouseCursor( resumePos, true, false );
1601 m_toolMgr->PrimeTool( resumePos );
1602 }
1603
1604 return 0;
1605}
1606
1607
1609
1610
1612
1613
1615{
1617 {
1619 .Map( VIA_STACK_STYLE::STACKED, _HKI( "Stacked" ) )
1620 .Map( VIA_STACK_STYLE::STAGGERED, _HKI( "Staggered" ) );
1621
1628
1630
1631 if( layerEnum.Choices().GetCount() == 0 )
1632 {
1633 layerEnum.Undefined( UNDEFINED_LAYER );
1634
1635 for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
1636 layerEnum.Map( layer, LSET::Name( layer ) );
1637 }
1638
1639 // A stack spans layers, so the single inherited layer is meaningless, as for a via.
1640 propMgr.Mask( TYPE_HASH( PCB_VIA_STACK ), TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) );
1641
1642 // Read-only: a stack's geometry is rebuilt from these, and the Properties panel has no
1643 // way to trigger that rebuild. Editing goes through the stack's own dialog.
1644 const wxString groupStack = _HKI( "Microvia Stack Properties" );
1645
1646 auto startLayer = new PROPERTY_ENUM<PCB_VIA_STACK, PCB_LAYER_ID>(
1648 startLayer->SetChoices( layerEnum.Choices() );
1649 propMgr.AddProperty( startLayer, groupStack );
1650
1653 endLayer->SetChoices( layerEnum.Choices() );
1654 propMgr.AddProperty( endLayer, groupStack );
1655
1656 propMgr.AddProperty(
1659 groupStack );
1660
1663
1664 propMgr.AddProperty( new PROPERTY<PCB_VIA_STACK, bool>( _HKI( "Use Netclass Values" ),
1665 NO_SETTER( PCB_VIA_STACK, bool ),
1667 groupStack );
1668
1669 propMgr.AddProperty( new PROPERTY<PCB_VIA_STACK, int>( _HKI( "Via Diameter" ), NO_SETTER( PCB_VIA_STACK, int ),
1671 groupStack );
1672
1673 propMgr.AddProperty( new PROPERTY<PCB_VIA_STACK, int>( _HKI( "Via Hole" ), NO_SETTER( PCB_VIA_STACK, int ),
1675 groupStack );
1676
1677 auto isStaggered = []( INSPECTABLE* aItem ) -> bool
1678 {
1679 if( PCB_VIA_STACK* stack = dynamic_cast<PCB_VIA_STACK*>( aItem ) )
1680 return stack->GetStyle() == VIA_STACK_STYLE::STAGGERED;
1681
1682 return false;
1683 };
1684
1685 propMgr.AddProperty( new PROPERTY<PCB_VIA_STACK, int>( _HKI( "Pitch" ), NO_SETTER( PCB_VIA_STACK, int ),
1687 groupStack )
1688 .SetAvailableFunc( isStaggered );
1689
1690 propMgr.AddProperty( new PROPERTY<PCB_VIA_STACK, bool>( _HKI( "Copper-filled" ),
1691 NO_SETTER( PCB_VIA_STACK, bool ),
1693 groupStack );
1694
1695 propMgr.AddProperty( new PROPERTY<PCB_VIA_STACK, bool>( _HKI( "Capped" ), NO_SETTER( PCB_VIA_STACK, bool ),
1697 groupStack );
1698 }
const char * name
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:56
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
SEG MIRROR_AXIS(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Definition board_item.h:85
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
static TOOL_ACTION cursorDblClick
Definition actions.h:178
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION cursorClick
Definition actions.h:177
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION refreshPreview
Definition actions.h:156
BASE_SET & set(size_t pos)
Definition base_set.h:126
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
bool RemoveOrDiscard(BOARD_ITEM *aItem)
Remove aItem, or free it if it was added earlier in this commit and never reached the board.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Container for design settings for a BOARD object.
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
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:101
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
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
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition board.cpp:1723
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
void Unmodify(EDA_ITEM *aItem, BASE_SCREEN *aScreen)
Definition commit.cpp:200
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
VECTOR2I m_viaStackSeedPos
PCB_LAYER_ID m_viaStackSeedStart
PCB_LAYER_ID m_viaStackSeedEnd
bool m_viaStackSeeded
KIGFX::VIEW_CONTROLS * m_controls
KIGFX::VIEW * m_view
int PlaceMicroviaStack(const TOOL_EVENT &aEvent)
Place a stacked or staggered microvia stack.
PCB_BASE_EDIT_FRAME * m_frame
SEVERITY GetSeverity() const
Definition drc_rule.h:181
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:129
bool IsNull() const
Definition drc_rule.h:122
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)
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
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:167
bool IsNew() const
Definition eda_item.h:131
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:817
static ENUM_MAP< T > & Instance()
Definition property.h:811
ENUM_MAP & Undefined(T aValue)
Definition property.h:824
wxPGChoices & Choices()
Definition property.h:862
Handle actions specific to filling copper zones.
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
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
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition lset.cpp:259
static int NameToLayer(wxString &aName)
Return the layer number from a layer name.
Definition lset.cpp:113
static const LSET & AllLayersMask()
Definition lset.cpp:637
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
T PinnedOpt() const
Definition minoptmax.h:32
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
bool HasuViaDrill() const
Definition netclass.h:181
int GetuViaDrill() const
Definition netclass.h:182
bool HasuViaDiameter() const
Definition netclass.h:173
int GetuViaDiameter() const
Definition netclass.h:174
bool HasTrackWidth() const
Definition netclass.h:149
int GetTrackWidth() const
Definition netclass.h:150
Handle the data for a net.
Definition netinfo.h:50
NETCLASS * GetNetClass()
Definition netinfo.h:101
DRILL_PROPS & Drill()
Definition padstack.h:363
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
static TOOL_ACTION routeSingleTrack
Activation of the Push and Shove router.
Common, abstract interface for edit frames.
virtual void SetProperties(const STRING_ANY_MAP &aProps)
wxString m_generatorType
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
PCB_GENERATOR(BOARD_ITEM *aParent, PCB_LAYER_ID aLayer)
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aMirrorDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
void SetPosition(const VECTOR2I &aPos) override
VECTOR2I GetPosition() const override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
virtual const STRING_ANY_MAP GetProperties() const
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
void SetLocked(bool aLocked) override
LEADER_MODE GetAngleSnapMode() const
Get the current angle snapping mode.
BOARD * board() const
const PCB_SELECTION & selection() const
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:96
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:99
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
const VECTOR2I & GetEnd() const
Definition pcb_track.h:97
virtual void SetWidth(int aWidth)
Definition pcb_track.h:93
virtual int GetWidth() const
Definition pcb_track.h:94
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
VIA_STACK_PRESET ToPreset() const
void SetHops(const SHAPE_LINE_CHAIN &aHops)
void EditCancel(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit) override
bool Update(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit) override
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void ApplyPreset(const VIA_STACK_PRESET &aPreset)
wxString m_presetName
static int ExpandMultiHopMicrovias(BOARD *aBoard, BOARD_COMMIT *aCommit, const std::function< const VIA_STACK_PRESET *(PCB_VIA *)> &aMatcher=nullptr)
Replace loose microvias spanning more than one hop with stacks of single hop microvias.
void SetProperties(const STRING_ANY_MAP &aProps) override
void SetPitch(int aPitch)
static PCB_VIA_STACK * CreateFromItems(const std::vector< BOARD_ITEM * > &aItems, BOARD *aBoard, std::vector< BOARD_ITEM * > *aMembers=nullptr, wxString *aError=nullptr)
Build a stack from existing board items (microvias plus optional connecting traces).
static std::set< KIID > CollectExpandableMicrovias(BOARD *aBoard)
Ids of the vias ExpandMultiHopMicrovias would consider right now.
static const wxString GENERATOR_TYPE
void EditStart(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit) override
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
PCB_LAYER_ID m_endLayer
static int FindNetAtPosition(BOARD *aBoard, const VECTOR2I &aPosition, PCB_LAYER_ID aLayer)
Net of the copper under a point on the given layer, pads first, then tracks, then filled zones.
VIA_STACK_STYLE m_style
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
std::optional< SHAPE_LINE_CHAIN > m_hops
void EditFinish(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit) override
void Remove(GENERATOR_TOOL *aTool, BOARD *aBoard, BOARD_COMMIT *aCommit) override
bool IsCapped() const
void Regenerate(BOARD *aBoard, BOARD_COMMIT *aCommit)
Rebuild the member vias (and, for a staggered stack, the connecting traces) from the current stack se...
void addMember(BOARD *aBoard, BOARD_COMMIT *aCommit, BOARD_ITEM *aItem)
int GetViaDrill() const
bool IsFilled() const
bool reuseMembers(BOARD_COMMIT *aCommit, const std::vector< BOARD_ITEM * > &aRebuilt)
static const wxString DISPLAY_NAME
VIA_STACK_STYLE GetStyle() const
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
void SetFilled(bool aFilled)
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
PCB_LAYER_ID m_startLayer
int GetNetCode() const
PCB_LAYER_ID GetStartLayer() const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetStartLayer(PCB_LAYER_ID aLayer)
PCB_LAYER_ID GetEndLayer() const
bool GetUseNetclass() const
std::vector< BOARD_ITEM * > BuildMembers(BOARD *aBoard, int aNetCode) const
Build the member vias/traces for the current settings and return them without adding them anywhere.
static bool IsSpanValid(BOARD *aBoard, PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd)
True when both span ends are copper layers within the board's copper layer count.
void SetViaSize(int aSize)
void SetCapped(bool aCapped)
void SetViaDrill(int aDrill)
int GetPitch() const
void ShowPropertiesDialog(PCB_BASE_EDIT_FRAME *aEditFrame) override
const STRING_ANY_MAP GetProperties() const override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void SetStyle(VIA_STACK_STYLE aStyle)
wxString GetCommitMessage() const override
PCB_VIA_STACK(BOARD_ITEM *aParent=nullptr, PCB_LAYER_ID aLayer=F_Cu)
int GetViaSize() const
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void SetEndLayer(PCB_LAYER_ID aLayer)
void SetNetCode(int aNet)
static std::pair< int, int > GetNetclassViaSize(BOARD *aBoard, int aNetCode)
The microvia diameter and drill that "use netclass values" gives hops on aNetCode,...
PCB_LAYER_ID BottomLayer() const
VECTOR2I GetPosition() const override
Definition pcb_track.h:615
const PADSTACK & Padstack() const
Definition pcb_track.h:435
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
For a via m_layer contains the top layer, the other layer is in m_bottomLayer/.
int GetWidth() const override
void SetViaType(VIATYPE aViaType)
Definition pcb_track.h:427
PCB_LAYER_ID TopLayer() const
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
VIATYPE GetViaType() const
Definition pcb_track.h:426
void SetWidth(int aWidth) override
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.
RAII class that sets an value at construction and resets it to the original value at destruction.
Definition seg.h:38
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
Definition selection.cpp:38
virtual void Clear() override
Remove all the stored items from the group.
Definition selection.h:97
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
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.
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
Generic, UI-independent tool event.
Definition tool_event.h:167
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
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
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:406
Handle a list of polygons defining a copper zone.
Definition zone.h:70
@ ARROW
Definition cursors.h:43
@ BULLSEYE
Definition cursors.h:55
static bool empty(const wxTextEntryBase *aCtrl)
int ComputeWorstViaClearance(PCB_BASE_EDIT_FRAME *aFrame, DRC_ENGINE *aEngine)
Shared placement DRC checks, used by the plain via tool and the microvia stack tool so both block pla...
PAD * FindSnapPad(PCB_BASE_EDIT_FRAME *aFrame, const PCB_VIA *aVia, const VECTOR2I &aPosition, const LSET &aLayers, int aSnapRange=0)
PCB_TRACK * FindSnapTrack(PCB_BASE_EDIT_FRAME *aFrame, const PCB_VIA *aVia, const VECTOR2I &aPosition, const LSET &aLayers, int aSnapRange=0)
int ViaSnapRange(PCB_BASE_EDIT_FRAME *aFrame)
Shared placement snapping, used by the plain via tool and the microvia stack tool.
bool CheckItemDRCViolation(BOARD_CONNECTED_ITEM *aItem, PCB_BASE_EDIT_FRAME *aFrame, DRC_ENGINE *aEngine, int aWorstClearance, int aEpsilon)
@ TRACK_WIDTH_CONSTRAINT
#define _(s)
@ RECURSE
Definition eda_item.h:51
#define IS_NEW
New item, just created.
#define ROUTER_TRANSIENT
transient items that should NOT be cached
#define IN_EDIT
Item currently edited.
SCOPED_SET_RESET< EE_GRAPHIC_TOOL::MODE > SCOPED_DRAW_MODE
a few functions useful in geometry calculations.
LEADER_MODE
The kind of the leader line.
@ DIRECT
Unconstrained point-to-point.
@ DEG90
90 Degree only
#define MAX_CU_LAYERS
Definition layer_ids.h:172
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:244
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
Definition layer_ids.h:755
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ In1_Cu
Definition layer_ids.h:62
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
@ F_Cu
Definition layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
FLIP_DIRECTION
Definition mirror.h:26
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API SHAPE_LINE_CHAIN UnpackPolyLine(const types::PolyLine &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
KICOMMON_API void PackPolyLine(types::PolyLine &aOutput, const SHAPE_LINE_CHAIN &aSlc, const EDA_IU_SCALE &aScale)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
#define _HKI(x)
Definition page_info.cpp:40
static GENERATORS_MGR::REGISTER< PCB_TUNING_PATTERN > registerMe
static VIA_STACK_STYLE styleFromString(const wxString &aStr)
static struct PCB_VIA_STACK_DESC _PCB_VIA_STACK_DESC
static PCB_LAYER_ID layerFromName(const wxString &aName, PCB_LAYER_ID aFallback)
static wxString styleToString(VIA_STACK_STYLE aStyle)
static void layerOrder(BOARD *aBoard, std::vector< PCB_LAYER_ID > &aOrder, std::map< int, int > &aOrdinals)
static std::optional< std::tuple< int, int, int > > memberKey(BOARD_ITEM *aItem)
static bool isExpandableMicrovia(const std::map< int, int > &aOrdinals, PCB_VIA *aVia)
VIA_STACK_STYLE
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition property.h:916
#define NO_SETTER(owner, type)
Macro to define read-only fields (no setter method available)
Definition property.h:923
@ 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.
@ RPT_SEVERITY_IGNORE
Static helper to register a generator.
MAGNETIC_OPTIONS tracks
MAGNETIC_OPTIONS pads
std::optional< bool > is_capped
True if the drill hole should be capped.
Definition padstack.h:284
std::optional< bool > is_filled
True if the drill hole should be filled completely.
Definition padstack.h:283
A named microvia stack definition, chosen while routing instead of entering the values each time.
KIBIS top(path, &reporter)
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
const SHAPE_LINE_CHAIN chain
#define M_PI
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708