KiCad PCB EDA Suite
Loading...
Searching...
No Matches
router_tool.cpp
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <wx/filedlg.h>
24#include <wx/filefn.h>
25#include <wx/hyperlink.h>
26#include <wx/valnum.h>
27#include <advanced_config.h>
28#include <kiplatform/ui.h>
29
30#include <functional>
31#include <iomanip>
32#include <sstream>
33
34using namespace std::placeholders;
35#include <tool/action_manager.h>
36#include <board.h>
38#include <board_item.h>
39#include <netclass.h>
40#include <netinfo.h>
41#include <collectors.h>
42#include <footprint.h>
44#include <pad.h>
45#include <zone.h>
46#include <pcb_edit_frame.h>
47#include <pcb_track.h>
48#include <pcbnew_id.h>
54#include <math/vector2wx.h>
55#include <paths.h>
57#include <confirm.h>
58#include <kidialog.h>
59#include <widgets/wx_infobar.h>
64#include <view/view_controls.h>
65#include <bitmaps.h>
66#include <string_utils.h>
67#include <gal/painter.h>
68#include <tool/tool_action.h>
69#include <tool/action_menu.h>
70#include <tool/tool_manager.h>
71#include <tool/tool_menu.h>
72#include <tools/pcb_actions.h>
74#include <board_commit.h>
76#include <tools/drawing_tool.h>
78#include <tools/drc_tool.h>
81
82#include <project.h>
85
86#include <io/io_utils.h>
87
88#include "router_tool.h"
90#include "pns_block_dragger.h"
91#include "pns_router.h"
92#include "pns_itemset.h"
93#include "pns_line.h"
94#include "pns_linked_item.h"
95#include "pns_logger.h"
96#include "pns_node.h"
97#include "pns_optimizer.h"
98#include "pns_placement_algo.h"
99#include "pns_segment.h"
100#include "pns_drag_algo.h"
101#include "pns_kicad_iface.h"
102
104
106
107using namespace KIGFX;
108
109
110const VIA_STACK_PRESET* MatchPendingStackExpansion( PCB_VIA* aVia, const std::set<KIID>& aPreRoute,
111 const std::vector<PENDING_STACK_EXPANSION>& aPending )
112{
113 if( aPreRoute.count( aVia->m_Uuid ) )
114 return nullptr;
115
116 for( const PENDING_STACK_EXPANSION& exp : aPending )
117 {
118 // Net and span alone cannot tell the drop's via from any other the route left behind.
119 if( !exp.m_Pos || *exp.m_Pos != aVia->GetPosition() )
120 continue;
121
122 if( aVia->GetNetCode() != exp.m_Net )
123 continue;
124
125 if( ( aVia->TopLayer() == exp.m_Start && aVia->BottomLayer() == exp.m_End )
126 || ( aVia->TopLayer() == exp.m_End && aVia->BottomLayer() == exp.m_Start ) )
127 {
128 return &exp.m_Preset;
129 }
130 }
131
132 return nullptr;
133}
134
135
137{
138 if( aStart == aEnd )
139 return UNDEFINED_LAYER;
140
141 if( aCurrent == aStart )
142 return aEnd;
143
144 // From the end layer the stack goes back the way it came.
145 if( aCurrent == aEnd )
146 return aStart;
147
148 return UNDEFINED_LAYER;
149}
150
151
152namespace
153{
154
155// Saves and restores the global wxUpdateUIEvent interval so it cannot leak on
156// early returns or exceptions.
157class UI_UPDATE_INTERVAL_GUARD
158{
159public:
160 UI_UPDATE_INTERVAL_GUARD( long aNewInterval ) :
161 m_saved( wxUpdateUIEvent::GetUpdateInterval() )
162 {
163 wxUpdateUIEvent::SetUpdateInterval( aNewInterval );
164 }
165
166 ~UI_UPDATE_INTERVAL_GUARD()
167 {
168 wxUpdateUIEvent::SetUpdateInterval( m_saved );
169 }
170
171private:
172 long m_saved;
173};
174
175} // anonymous namespace
176
181{
182 // Via type
183 VIA_MASK = 0x07,
184 VIA = 0x00,
185 BLIND_VIA = 0x01,
186 BURIED_VIA = 0x02,
187 MICROVIA = 0x04,
188
189 // Select layer
191};
192
193
194// Actions, being statically-defined, require specialized I18N handling. We continue to
195// use the _() macro so that string harvesting by the I18N framework doesn't have to be
196// specialized, but we don't translate on initialization and instead do it in the getters.
197
198#undef _
199#define _(s) s
200
201// Pass all the parameters as int to allow combining flags
203 .Name( "pcbnew.InteractiveRouter.PlaceVia" )
204 .Scope( AS_CONTEXT )
205 .DefaultHotkey( 'V' )
206 .LegacyHotkeyName( "Add Through Via" )
207 .FriendlyName( _( "Place Through Via" ) )
208 .Tooltip( _( "Adds a through-hole via at the end of currently routed track." ) )
209 .Icon( BITMAPS::via )
210 .Flags( AF_NONE )
211 .Parameter<int>( VIA_ACTION_FLAGS::VIA ) );
212
214 .Name( "pcbnew.InteractiveRouter.PlaceBlindVia" )
215 .Scope( AS_CONTEXT )
216 .DefaultHotkey( MD_ALT + MD_SHIFT + 'V' )
217 .LegacyHotkeyName( "Add Blind/Buried Via" )
218 .FriendlyName( _( "Place Blind/Buried Via" ) )
219 .Tooltip( _( "Adds a blind or buried via at the end of currently routed track.") )
220 .Icon( BITMAPS::via_buried )
221 .Flags( AF_NONE )
222 .Parameter<int>( VIA_ACTION_FLAGS::BLIND_VIA ) );
223
225 .Name( "pcbnew.InteractiveRouter.PlaceMicroVia" )
226 .Scope( AS_CONTEXT )
227 .DefaultHotkey( MD_CTRL + 'V' )
228 .LegacyHotkeyName( "Add MicroVia" )
229 .FriendlyName( _( "Place Microvia" ) )
230 .Tooltip( _( "Adds a microvia at the end of currently routed track." ) )
231 .Icon( BITMAPS::via_microvia )
232 .Flags( AF_NONE )
233 .Parameter<int>( VIA_ACTION_FLAGS::MICROVIA ) );
234
237 .Name( "pcbnew.InteractiveRouter.PlaceViaStack" )
238 .Scope( AS_CONTEXT )
239 .DefaultHotkey( MD_CTRL + MD_SHIFT + 'V' )
240 .FriendlyName( _( "Place Microvia Stack at Track End" ) )
241 .Tooltip( _( "Drops the active microvia stack preset at the end of the currently routed track "
242 "and continues on the target layer." ) )
244 .Flags( AF_NONE ) );
245
247 .Name( "pcbnew.InteractiveRouter.SelLayerAndPlaceVia" )
248 .Scope( AS_CONTEXT )
249 .DefaultHotkey( '<' )
250 .LegacyHotkeyName( "Select Layer and Add Through Via" )
251 .FriendlyName( _( "Select Layer and Place Through Via..." ) )
252 .Tooltip( _( "Select a layer, then add a through-hole via at the end of currently routed track." ) )
254 .Flags( AF_NONE )
256
258 .Name( "pcbnew.InteractiveRouter.SelLayerAndPlaceBlindVia" )
259 .Scope( AS_CONTEXT )
260 .DefaultHotkey( MD_ALT + '<' )
261 .LegacyHotkeyName( "Select Layer and Add Blind/Buried Via" )
262 .FriendlyName( _( "Select Layer and Place Blind/Buried Via..." ) )
263 .Tooltip( _( "Select a layer, then add a blind or buried via at the end of currently routed track." ) )
265 .Flags( AF_NONE )
267
269 .Name( "pcbnew.InteractiveRouter.SelLayerAndPlaceMicroVia" )
270 .Scope( AS_CONTEXT )
271 .FriendlyName( _( "Select Layer and Place Micro Via..." ) )
272 .Tooltip( _( "Select a layer, then add a micro via at the end of currently routed track." ) )
274 .Flags( AF_NONE )
276
278 .Name( "pcbnew.InteractiveRouter.CustomTrackViaSize" )
279 .Scope( AS_CONTEXT )
280 .DefaultHotkey( 'Q' )
281 .LegacyHotkeyName( "Custom Track/Via Size" )
282 .FriendlyName( _( "Custom Track/Via Size..." ) )
283 .Tooltip( _( "Shows a dialog for changing the track width and via size." ) )
284 .Icon( BITMAPS::width_track ) );
285
287 .Name( "pcbnew.InteractiveRouter.SpreadTracksSetDistance" )
288 .Scope( AS_CONTEXT )
289 .DefaultHotkey( 'E' )
290 .LegacyHotkeyName( "Set Spreading Distance" )
291 .FriendlyName( _( "Set Spreading Distance..." ) )
292 .Tooltip( _( "Sets the distance between the tracks for the Spread Tracks tool." ) )
293 );
294
296 .Name( "pcbnew.InteractiveRouter.IncreaseSpreadingDistance" )
297 .Scope( AS_CONTEXT )
298 .DefaultHotkey( ']' )
299 .LegacyHotkeyName( "Increase Spreading Distance" )
300 .FriendlyName( _( "Increase Spreading Distance..." ) )
301 .Tooltip( _( "Increases the distance between the tracks for the Spread Tracks tool by one grid unit." ) )
302 );
303
305 .Name( "pcbnew.InteractiveRouter.DecreaseSpreadingDistance" )
306 .Scope( AS_CONTEXT )
307 .DefaultHotkey( '[' )
308 .LegacyHotkeyName( "Decrease Spreading Distance" )
309 .FriendlyName( _( "Decrease Spreading Distance..." ) )
310 .Tooltip( _( "Decreases the distance between the tracks for the Spread Tracks tool by one grid unit." ) )
311 );
312
313
315 .Name( "pcbnew.InteractiveRouter.SwitchPosture" )
316 .Scope( AS_CONTEXT )
317 .DefaultHotkey( '/' )
318 .LegacyHotkeyName( "Switch Track Posture" )
319 .FriendlyName( _( "Switch Track Posture" ) )
320 .Tooltip( _( "Switches posture of the currently routed track." ) )
322
323 // This old command ( track corner switch mode) is now moved to a submenu with other corner mode options
325 .Name( "pcbnew.InteractiveRouter.SwitchRoundingToNext" )
326 .Scope( AS_CONTEXT )
327 .DefaultHotkey( MD_CTRL + '/' )
328 .FriendlyName( _( "Track Corner Mode Switch" ) )
329 .Tooltip( _( "Switches between sharp/rounded and 45°/90° corners when routing tracks." ) )
331
332// hotkeys W and Shift+W are used to switch to track width changes
334 .Name( "pcbnew.InteractiveRouter.SwitchRounding45" )
335 .Scope( AS_CONTEXT )
336 .DefaultHotkey( MD_CTRL + 'W' )
337 .FriendlyName( _( "Track Corner Mode 45" ) )
338 .Tooltip( _( "Switch to 45° corner when routing tracks." ) ) );
339
341 .Name( "pcbnew.InteractiveRouter.SwitchRounding90" )
342 .Scope( AS_CONTEXT )
343 .DefaultHotkey( MD_CTRL + MD_ALT + 'W' )
344 .FriendlyName( _( "Track Corner Mode 90" ) )
345 .Tooltip( _( "Switch to 90° corner when routing tracks." ) ) );
346
348 .Name( "pcbnew.InteractiveRouter.SwitchRoundingArc45" )
349 .Scope( AS_CONTEXT )
350 .DefaultHotkey( MD_CTRL + MD_SHIFT + 'W' )
351 .FriendlyName( _( "Track Corner Mode Arc 45" ) )
352 .Tooltip( _( "Switch to arc 45° corner when routing tracks." ) ) );
353
355 .Name( "pcbnew.InteractiveRouter.SwitchRoundingArc90" )
356 .Scope( AS_CONTEXT )
357 .DefaultHotkey( MD_ALT + 'W' )
358 .FriendlyName( _( "Track Corner Mode Arc 90" ) )
359 .Tooltip( _( "Switch to arc 90° corner when routing tracks." ) ) );
360
361#undef _
362#define _(s) wxGetTranslation((s))
363
364
374
375
377{
378public:
380 ACTION_MENU( true ),
381 m_frame( aFrame )
382 {
384 SetTitle( _( "Select Track/Via Width" ) );
385 }
386
387protected:
388 ACTION_MENU* create() const override
389 {
390 return new TRACK_WIDTH_MENU( m_frame );
391 }
392
393 void update() override
394 {
395 BOARD_DESIGN_SETTINGS& bds = m_frame.GetBoard()->GetDesignSettings();
396 bool useIndex = !bds.m_UseConnectedTrackWidth && !bds.UseCustomTrackViaSize();
397 wxString msg;
398
399 Clear();
400
401 Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Use Starting Track Width" ),
402 _( "Route using the width of the starting track." ), wxITEM_CHECK );
405
406 Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use Net Class Values" ),
407 _( "Use track and via sizes from the net class" ), wxITEM_CHECK );
409 useIndex && bds.GetTrackWidthIndex() == 0 && bds.GetViaSizeIndex() == 0 );
410
411 Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Use Custom Values..." ),
412 _( "Specify custom track and via sizes" ), wxITEM_CHECK );
414
415 AppendSeparator();
416
417 // Append the list of tracks & via sizes
418 for( unsigned i = 0; i < bds.m_TrackWidthList.size(); i++ )
419 {
420 int width = bds.m_TrackWidthList[i];
421
422 if( i == 0 )
423 msg = _( "Track netclass width" );
424 else
425 msg.Printf( _( "Track %s" ), m_frame.MessageTextFromValue( width ) );
426
427 int menuIdx = ID_POPUP_PCB_SELECT_WIDTH1 + i;
428 Append( menuIdx, msg, wxEmptyString, wxITEM_CHECK );
429 Check( menuIdx, useIndex && bds.GetTrackWidthIndex() == (int) i );
430 }
431
432 AppendSeparator();
433
434 for( unsigned i = 0; i < bds.m_ViasDimensionsList.size(); i++ )
435 {
437
438 if( i == 0 )
439 msg = _( "Via netclass values" );
440 else
441 {
442 if( via.m_Drill > 0 )
443 {
444 msg.Printf( _("Via %s, hole %s" ),
445 m_frame.MessageTextFromValue( via.m_Diameter ),
446 m_frame.MessageTextFromValue( via.m_Drill ) );
447 }
448 else
449 {
450 msg.Printf( _( "Via %s" ),
451 m_frame.MessageTextFromValue( via.m_Diameter ) );
452 }
453 }
454
455 int menuIdx = ID_POPUP_PCB_SELECT_VIASIZE1 + i;
456 Append( menuIdx, msg, wxEmptyString, wxITEM_CHECK );
457 Check( menuIdx, useIndex && bds.GetViaSizeIndex() == (int) i );
458 }
459 }
460
461 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
462 {
463 BOARD_DESIGN_SETTINGS& bds = m_frame.GetBoard()->GetDesignSettings();
464 int id = aEvent.GetId();
465
466 // On Windows, this handler can be called with an event ID not existing in any
467 // menuitem, so only set flags when we have an ID match.
468
470 {
471 bds.UseCustomTrackViaSize( true );
472 bds.m_TempOverrideTrackWidth = true;
473 m_frame.GetToolManager()->RunAction( ACT_CustomTrackWidth );
474 }
475 else if( id == ID_POPUP_PCB_SELECT_AUTO_WIDTH )
476 {
477 bds.UseCustomTrackViaSize( false );
478 bds.m_UseConnectedTrackWidth = true;
479 bds.m_TempOverrideTrackWidth = false;
480 }
482 {
483 bds.UseCustomTrackViaSize( false );
484 bds.m_UseConnectedTrackWidth = false;
485 bds.SetViaSizeIndex( 0 );
486 bds.SetTrackWidthIndex( 0 );
487 }
489 {
490 bds.UseCustomTrackViaSize( false );
492 }
494 {
495 bds.UseCustomTrackViaSize( false );
496 bds.m_TempOverrideTrackWidth = true;
498 }
499
501 }
502
503private:
505};
506
507
509{
510public:
512 ACTION_MENU( true ),
513 m_frame( aFrame )
514 {
516 SetTitle( _( "Select Differential Pair Dimensions" ) );
517 }
518
519protected:
520 ACTION_MENU* create() const override
521 {
522 return new DIFF_PAIR_MENU( m_frame );
523 }
524
525 void update() override
526 {
527 const BOARD_DESIGN_SETTINGS& bds = m_frame.GetBoard()->GetDesignSettings();
528
529 Clear();
530
531 Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_DIFFPAIR, _( "Use Net Class Values" ),
532 _( "Use differential pair dimensions from the net class" ), wxITEM_CHECK );
534 !bds.UseCustomDiffPairDimensions() && bds.GetDiffPairIndex() == 0 );
535
536 Append( ID_POPUP_PCB_SELECT_CUSTOM_DIFFPAIR, _( "Use Custom Values..." ),
537 _( "Specify custom differential pair dimensions" ), wxITEM_CHECK );
539
540 AppendSeparator();
541
542 // Append the list of differential pair dimensions
543
544 // Drop index 0 which is the current netclass dimensions (which are handled above)
545 for( unsigned i = 1; i < bds.m_DiffPairDimensionsList.size(); ++i )
546 {
548 wxString msg;
549
550 if( diffPair.m_Gap <= 0 )
551 {
552 if( diffPair.m_ViaGap <= 0 )
553 {
554 msg.Printf( _( "Width %s" ),
555 m_frame.MessageTextFromValue( diffPair.m_Width ) );
556 }
557 else
558 {
559 msg.Printf( _( "Width %s, via gap %s" ),
560 m_frame.MessageTextFromValue( diffPair.m_Width ),
561 m_frame.MessageTextFromValue( diffPair.m_ViaGap ) );
562 }
563 }
564 else
565 {
566 if( diffPair.m_ViaGap <= 0 )
567 {
568 msg.Printf( _( "Width %s, gap %s" ),
569 m_frame.MessageTextFromValue( diffPair.m_Width ),
570 m_frame.MessageTextFromValue( diffPair.m_Gap ) );
571 }
572 else
573 {
574 msg.Printf( _( "Width %s, gap %s, via gap %s" ),
575 m_frame.MessageTextFromValue( diffPair.m_Width ),
576 m_frame.MessageTextFromValue( diffPair.m_Gap ),
577 m_frame.MessageTextFromValue( diffPair.m_ViaGap ) );
578 }
579 }
580
581 int menuIdx = ID_POPUP_PCB_SELECT_DIFFPAIR1 + i - 1;
582 Append( menuIdx, msg, wxEmptyString, wxITEM_CHECK );
583 Check( menuIdx, !bds.UseCustomDiffPairDimensions() && bds.GetDiffPairIndex() == (int) i );
584 }
585 }
586
587 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
588 {
589 BOARD_DESIGN_SETTINGS& bds = m_frame.GetBoard()->GetDesignSettings();
590 int id = aEvent.GetId();
591
592 // On Windows, this handler can be called with an event ID not existing in any
593 // menuitem, so only set flags when we have an ID match.
594
596 {
597 bds.UseCustomDiffPairDimensions( true );
598 TOOL_MANAGER* toolManager = m_frame.GetToolManager();
600 }
602 {
603 bds.UseCustomDiffPairDimensions( false );
604 bds.SetDiffPairIndex( 0 );
605 }
607 {
608 bds.UseCustomDiffPairDimensions( false );
609 // remember that the menu doesn't contain index 0 (which is the netclass values)
611 }
612
614 }
615
616private:
618};
619
620
624
625
627{
629
631
632 wxASSERT( frame );
633
634 auto& menu = m_menu->GetMenu();
635 menu.SetUntranslatedTitle( _HKI( "Interactive Router" ) );
636
637 m_trackViaMenu = std::make_shared<TRACK_WIDTH_MENU>( *frame );
638 m_trackViaMenu->SetTool( this );
639 m_menu->RegisterSubMenu( m_trackViaMenu );
640
641 m_diffPairMenu = std::make_shared<DIFF_PAIR_MENU>( *frame );
642 m_diffPairMenu->SetTool( this );
643 m_menu->RegisterSubMenu( m_diffPairMenu );
644
645 ACTION_MANAGER* mgr = frame->GetToolManager()->GetActionManager();
646
647 auto haveHighlight =
648 [this]( const SELECTION& sel )
649 {
650 KIGFX::RENDER_SETTINGS* cfg = m_toolMgr->GetView()->GetPainter()->GetSettings();
651
652 return !cfg->GetHighlightNetCodes().empty();
653 };
654
655 auto notRoutingCond =
656 [this]( const SELECTION& )
657 {
658 return !m_router->RoutingInProgress();
659 };
660
661 auto spreadingTracksCond =
662 [this]( const SELECTION& )
663 {
664 return m_router->Mode() == PNS::PNS_MODE_SPREAD_TRACKS;
665 };
666
667 auto inRouteSelected =
668 [this]( const SELECTION& )
669 {
670 return m_inRouteSelected;
671 };
672
673 auto hasOtherEnd =
674 [this]( const SELECTION& )
675 {
676 std::vector<PNS::NET_HANDLE> currentNets = m_router->GetCurrentNets();
677
678 if( currentNets.empty() || currentNets[0] == nullptr )
679 return false;
680
681 // Need to have something unconnected to finish to
682 NETINFO_ITEM* netInfo = static_cast<NETINFO_ITEM*>( currentNets[0] );
683 int currentNet = netInfo->GetNetCode();
685 RN_NET* ratsnest = board->GetConnectivity()->GetRatsnestForNet( currentNet );
686
687 return ratsnest && !ratsnest->GetEdges().empty();
688 };
689
691 menu.AddItem( PCB_ACTIONS::cancelCurrentItem, inRouteSelected, 1 );
692 menu.AddSeparator( 1 );
693
694 menu.AddItem( PCB_ACTIONS::clearHighlight, haveHighlight, 2 );
695 menu.AddSeparator( haveHighlight, 2 );
696
697 menu.AddItem( PCB_ACTIONS::routeSingleTrack, notRoutingCond );
698 menu.AddItem( PCB_ACTIONS::routeDiffPair, notRoutingCond );
701 menu.AddItem( PCB_ACTIONS::routerContinueFromEnd, hasOtherEnd );
702 menu.AddItem( PCB_ACTIONS::routerAttemptFinish, hasOtherEnd );
703 menu.AddItem( PCB_ACTIONS::routerAutorouteSelected, notRoutingCond
705 menu.AddItem( PCB_ACTIONS::routerOptimizeSelected, notRoutingCond
707 menu.AddItem( PCB_ACTIONS::breakTrack, notRoutingCond );
708
709 menu.AddItem( PCB_ACTIONS::drag45Degree, notRoutingCond );
710 menu.AddItem( PCB_ACTIONS::dragFreeAngle, notRoutingCond );
711
720
721 // Add submenu for track corner mode handling
722 CONDITIONAL_MENU* submenuCornerMode = new CONDITIONAL_MENU( this );
723 submenuCornerMode->SetTitle( _( "Track Corner Mode" ) );
725
727 submenuCornerMode->AddSeparator( 1 );
732
733 menu.AddMenu( submenuCornerMode );
734
735 // Manage check/uncheck marks in this submenu items
736 auto cornerMode45Cond =
737 [this]( const SELECTION& )
738 {
739 return m_router->Settings().GetCornerMode() == DIRECTION_45::CORNER_MODE::MITERED_45;
740 };
741
742 auto cornerMode90Cond =
743 [this]( const SELECTION& )
744 {
745 return m_router->Settings().GetCornerMode() == DIRECTION_45::CORNER_MODE::MITERED_90;
746 };
747
748 auto cornerModeArc45Cond =
749 [this]( const SELECTION& )
750 {
751 return m_router->Settings().GetCornerMode() == DIRECTION_45::CORNER_MODE::ROUNDED_45;
752 };
753
754 auto cornerModeArc90Cond =
755 [this]( const SELECTION& )
756 {
757 return m_router->Settings().GetCornerMode() == DIRECTION_45::CORNER_MODE::ROUNDED_90;
758 };
759
760#define CHECK( x ) ACTION_CONDITIONS().Check( x )
761 mgr->SetConditions( ACT_SwitchCornerMode45, CHECK( cornerMode45Cond ) );
762 mgr->SetConditions( ACT_SwitchCornerMode90, CHECK( cornerMode90Cond ) );
763 mgr->SetConditions( ACT_SwitchCornerModeArc45, CHECK( cornerModeArc45Cond ) );
764 mgr->SetConditions( ACT_SwitchCornerModeArc90, CHECK( cornerModeArc90Cond ) );
765
766 auto diffPairCond =
767 [this]( const SELECTION& )
768 {
769 return m_router->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR;
770 };
771
772 menu.AddSeparator();
773
775 menu.AddMenu( m_diffPairMenu.get(), diffPairCond );
776
777 menu.AddItem( ACT_IncreaseSpreadingDistance, spreadingTracksCond );
778 menu.AddItem( ACT_DecreaseSpreadingDistance, spreadingTracksCond );
779 menu.AddItem( ACT_SpreadTracksSetDistance, spreadingTracksCond );
780
782
783 menu.AddSeparator();
784
785 frame->AddStandardSubMenus( *m_menu.get() );
786
787 return true;
788}
789
790
792{
793 if( aReason == RUN )
794 TOOL_BASE::Reset( aReason );
795}
796
797// Saves the complete event log and the dump of the PCB, allowing us to
798// recreate hard-to-find P&S quirks and bugs.
799
801{
802 wxString testCaseDir = ADVANCED_CFG::GetCfg().m_RouterTestCaseDirectory;
803 wxString logPath;
804 static size_t lastLoggerSize = 0;
805 static wxString mruPath;
806 PNS::LOGGER::LOG_DATA logData;
807
808 auto logger = m_router->Logger();
809
810 if( !logger || logger->GetEvents().size() == 0
811 || logger->GetEvents().size() == lastLoggerSize )
812 {
813 return;
814 }
815
816 if( !testCaseDir.IsEmpty() )
817 {
818 DIALOG_ROUTER_SAVE_TEST_CASE saveDlg( frame(), testCaseDir );
819 bool doExit = false;
820
821 if( saveDlg.ShowModal() == wxID_OK )
822 {
823 wxFileName path = wxFileName::DirName( testCaseDir );
824 path.AppendDir( saveDlg.getTestCaseName() );
825 logData.m_TestCaseType = saveDlg.getTestCaseType();
826
827 if( path.DirExists() )
828 {
829 doExit = !IsOK( frame(), wxString::Format( _("Test case in directory %s already exists. Overwrite?"), path.GetFullPath() ) );
830 }
831 else
832 {
833 path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
834 }
835
836 path.SetName( wxT("pns") );
837 logPath = path.GetFullPath();
838 }
839 else
840 {
841 doExit = true;
842 }
843
844 if( doExit )
845 {
846 lastLoggerSize = logger->GetEvents().size(); // prevent re-entry
847 return;
848 }
849 }
850 else
851 {
852 if ( mruPath.IsEmpty() )
853 {
855 }
856
857 wxFileDialog dlg( frame(), _( "Save router log" ), mruPath, "pns.log",
858 "PNS log files" + AddFileExtListToFilter( { "log" } ),
859 wxFD_OVERWRITE_PROMPT | wxFD_SAVE );
860
862
863 if( dlg.ShowModal() != wxID_OK )
864 {
865 lastLoggerSize = logger->GetEvents().size(); // prevent re-entry
866 return;
867 }
868
869 logPath = dlg.GetPath();
870 }
871
872
873 wxFileName fname_log( logPath );
874 mruPath = fname_log.GetPath();
875 fname_log.SetExt( "log" );
876 wxLogTrace( wxT( "PNS" ), wxT( "save log to: %s" ), fname_log.GetFullPath() );
877
878 wxFileName fname_dump( fname_log );
879 fname_dump.SetExt( "dump" );
880
881 wxFileName fname_settings( fname_log );
882 fname_settings.SetExt( "settings" );
883
884 FILE* settings_f = wxFopen( fname_settings.GetAbsolutePath(), "wb" );
885
886 if( !settings_f )
887 {
888 DisplayError( frame(), wxString::Format( _( "Unable to write '%s'." ), fname_settings.GetAbsolutePath() ) );
889 return;
890 }
891
892 std::string settingsStr = m_router->Settings().FormatAsString();
893 fprintf( settings_f, "%s\n", settingsStr.c_str() );
894 fclose( settings_f );
895
896 // Export as *.kicad_pcb format, using a strategy which is specifically chosen
897 // as an example on how it could also be used to send it to the system clipboard.
898
899 PCB_IO_KICAD_SEXPR pcb_io;
900
901 pcb_io.SaveBoard( fname_dump.GetAbsolutePath(), *m_iface->GetBoard(), nullptr );
902
903 PROJECT* prj = m_iface->GetBoard()->GetProject();
904 prj->GetProjectFile().SaveAs( fname_dump.GetPath(), fname_dump.GetName() );
905 prj->GetLocalSettings().SaveAs( fname_dump.GetPath(), fname_dump.GetName() );
906
907 // Copy the project's custom DRC rules
909 {
910 wxString srcRules = editFrame->GetBoard()->GetDesignRulesPath();
911
912 if( !srcRules.IsEmpty() && wxFileName::FileExists( srcRules ) )
913 {
914 wxFileName fname_rules( fname_dump );
915 fname_rules.SetExt( FILEEXT::DesignRulesFileExtension );
916 wxCopyFile( srcRules, fname_rules.GetAbsolutePath() );
917 }
918 }
919
920 // Build log file:
921 std::vector<PNS::ITEM*> removed;
922 m_router->GetUpdatedItems( removed, logData.m_AddedItems, logData.m_Heads );
923
924
925 for( auto item : removed )
926 {
927 if( item->OfKind( PNS::ITEM::HOLE_T ) )
928 continue;
929
930 wxASSERT_MSG( item->Parent() != nullptr, "removed an item with no parent uuid?" );
931
932 if( item->Parent() )
933 logData.m_RemovedItems.insert( item->Parent()->m_Uuid );
934 }
935
936 logData.m_BoardHash = IO_UTILS::fileHashMMH3( fname_dump.GetAbsolutePath() );
937
938 if( !logData.m_BoardHash ) // should never happen...
939 return;
940
941 logData.m_Mode = m_router->Mode();
942 logData.m_Events = logger->GetEvents();
943
944 FILE* log_f = wxFopen( fname_log.GetAbsolutePath(), "wb" );
945 wxString logString = PNS::LOGGER::FormatLogFileAsJSON( logData );
946
947 if( !log_f )
948 {
949 DisplayError( frame(), wxString::Format( _( "Unable to write '%s'." ),
950 fname_log.GetAbsolutePath() ) );
951 return;
952 }
953
954 fprintf( log_f, "%s\n", logString.c_str().AsChar() );
955 fclose( log_f );
956
957 logger->Clear(); // prevent re-entry
958 lastLoggerSize = 0;
959}
960
961
963{
964 if( aEvent.Category() == TC_VIEW || aEvent.Category() == TC_MOUSE )
965 {
966 BOX2D viewAreaD = getView()->GetGAL()->GetVisibleWorldExtents();
967 m_router->SetVisibleViewArea( BOX2ISafe( viewAreaD ) );
968 }
969
970 if( !ADVANCED_CFG::GetCfg().m_EnableRouterDump )
971 return;
972
973 if( !aEvent.IsKeyPressed() )
974 return;
975
976 switch( aEvent.KeyCode() )
977 {
978 case '0':
980 aEvent.SetPassEvent( false );
981 break;
982
983 default:
984 break;
985 }
986}
987
989{
990 bool asChanged = false;
991
992 if( aEvent.IsAction( &ACT_SwitchCornerModeToNext ) )
993 {
994 DIRECTION_45::CORNER_MODE curr_mode = m_router->Settings().GetCornerMode();
995
997 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::ROUNDED_45 );
998 else if( curr_mode == DIRECTION_45::CORNER_MODE::ROUNDED_45 )
999 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::MITERED_90 );
1000 else if( curr_mode == DIRECTION_45::CORNER_MODE::MITERED_90 )
1001 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::ROUNDED_90 );
1002 else if( curr_mode == DIRECTION_45::CORNER_MODE::ROUNDED_90 )
1003 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::MITERED_45 );
1004
1005 asChanged = true;
1006 }
1007 else if( aEvent.IsAction( &ACT_SwitchCornerMode45 ) )
1008 {
1009 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::MITERED_45 );
1010 asChanged = true;
1011 }
1012 else if( aEvent.IsAction( &ACT_SwitchCornerModeArc45 ) )
1013 {
1014 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::ROUNDED_45 );
1015 asChanged = true;
1016 }
1017 else if( aEvent.IsAction( &ACT_SwitchCornerMode90 ) )
1018 {
1019 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::MITERED_90 );
1020 asChanged = true;
1021 }
1022 else if( aEvent.IsAction( &ACT_SwitchCornerModeArc90 ) )
1023 {
1024 m_router->Settings().SetCornerMode( DIRECTION_45::CORNER_MODE::ROUNDED_90 );
1025 asChanged = true;
1026 }
1027
1028 if( asChanged )
1029 {
1031 updateEndItem( aEvent );
1032 m_router->Move( m_endSnapPoint, m_endItem ); // refresh
1033 }
1034
1035 return 0;
1036}
1037
1038
1040{
1041 PCB_LAYER_ID tl = static_cast<PCB_LAYER_ID>( getView()->GetTopLayer() );
1042
1043 if( m_startItem )
1044 {
1045 int startLayer = m_iface->GetPNSLayerFromBoardLayer( tl );
1046 const PNS_LAYER_RANGE& ls = m_startItem->Layers();
1047
1048 if( ls.Overlaps( startLayer ) )
1049 return tl;
1050 else
1051 return m_iface->GetBoardLayerFromPNSLayer( ls.Start() );
1052 }
1053
1054 return tl;
1055}
1056
1057
1059{
1060 int activeLayer = m_iface->GetPNSLayerFromBoardLayer( frame()->GetActiveLayer() );
1061 int currentLayer = m_router->GetCurrentLayer();
1062
1063 if( currentLayer != activeLayer )
1064 m_router->SwitchLayer( activeLayer );
1065
1066 std::optional<int> newLayer = m_router->Sizes().PairedLayer( currentLayer );
1067
1068 if( !newLayer )
1069 newLayer = m_router->Sizes().GetLayerTop();
1070
1071 m_router->SwitchLayer( *newLayer );
1072 m_lastTargetLayer = m_iface->GetBoardLayerFromPNSLayer( *newLayer );
1073
1076}
1077
1078
1079// N.B. aTargetLayer is a PNS layer, not a PCB_LAYER_ID
1080void ROUTER_TOOL::updateSizesAfterRouterEvent( int aTargetLayer, const VECTOR2I& aPos )
1081{
1082 std::vector<PNS::NET_HANDLE> nets = m_router->GetCurrentNets();
1083
1084 PNS::SIZES_SETTINGS sizes = m_router->Sizes();
1086 std::shared_ptr<DRC_ENGINE>& drcEngine = bds.m_DRCEngine;
1087 DRC_CONSTRAINT constraint;
1088 PCB_LAYER_ID targetLayer = m_iface->GetBoardLayerFromPNSLayer( aTargetLayer );
1089
1090 PCB_TRACK dummyTrack( board() );
1091 dummyTrack.SetFlags( ROUTER_TRANSIENT );
1092 dummyTrack.SetLayer( targetLayer );
1093 dummyTrack.SetNet( nets.empty() ? nullptr: static_cast<NETINFO_ITEM*>( nets[0] ) );
1094 dummyTrack.SetStart( aPos );
1095 dummyTrack.SetEnd( dummyTrack.GetStart() );
1096
1097 constraint = drcEngine->EvalRules( CLEARANCE_CONSTRAINT, &dummyTrack, nullptr, targetLayer );
1098
1099 if( constraint.m_Value.Min() >= bds.m_MinClearance )
1100 {
1101 sizes.SetClearance( constraint.m_Value.Min() );
1102 sizes.SetClearanceSource( constraint.GetName() );
1103 }
1104 else
1105 {
1106 sizes.SetClearance( bds.m_MinClearance );
1107 sizes.SetClearanceSource( _( "board minimum clearance" ) );
1108 }
1109
1110 if( bds.UseNetClassTrack() || !sizes.TrackWidthIsExplicit() )
1111 {
1112 constraint = drcEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, &dummyTrack, nullptr, targetLayer );
1113
1114 if( !constraint.IsNull() )
1115 {
1116 int width = sizes.TrackWidth();
1117
1118 // Only change the size if we're explicitly using the net class, or we're out of range
1119 // for our new constraints. Otherwise, just leave the track width alone so we don't
1120 // change for no reason.
1121 if( bds.UseNetClassTrack()
1122 || ( width < bds.m_TrackMinWidth )
1123 || ( width < constraint.m_Value.Min() )
1124 || ( width > constraint.m_Value.Max() ) )
1125 {
1126 sizes.SetTrackWidth( std::max( bds.m_TrackMinWidth, constraint.m_Value.PinnedOpt() ) );
1127 }
1128
1129 if( sizes.TrackWidth() == constraint.m_Value.PinnedOpt() )
1130 sizes.SetWidthSource( constraint.GetName() );
1131 else if( sizes.TrackWidth() == bds.m_TrackMinWidth )
1132 sizes.SetWidthSource( _( "board minimum track width" ) );
1133 else
1134 sizes.SetWidthSource( _( "existing track" ) );
1135 }
1136 }
1137
1138 if( nets.size() >= 2 && ( bds.UseNetClassDiffPair() || !sizes.TrackWidthIsExplicit() ) )
1139 {
1140 PCB_TRACK dummyTrackB( board() );
1141 dummyTrackB.SetFlags( ROUTER_TRANSIENT );
1142 dummyTrackB.SetLayer( targetLayer );
1143 dummyTrackB.SetNet( static_cast<NETINFO_ITEM*>( nets[1] ) );
1144 dummyTrackB.SetStart( aPos );
1145 dummyTrackB.SetEnd( dummyTrackB.GetStart() );
1146
1147 constraint = drcEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, &dummyTrack, &dummyTrackB, targetLayer );
1148
1149 if( !constraint.IsNull() )
1150 {
1151 if( bds.UseNetClassDiffPair()
1152 || ( sizes.DiffPairWidth() < bds.m_TrackMinWidth )
1153 || ( sizes.DiffPairWidth() < constraint.m_Value.Min() )
1154 || ( sizes.DiffPairWidth() > constraint.m_Value.Max() ) )
1155 {
1156 sizes.SetDiffPairWidth( std::max( bds.m_TrackMinWidth, constraint.m_Value.PinnedOpt() ) );
1157 }
1158
1159 if( sizes.DiffPairWidth() == constraint.m_Value.PinnedOpt() )
1160 sizes.SetDiffPairWidthSource( constraint.GetName() );
1161 else
1162 sizes.SetDiffPairWidthSource( _( "board minimum track width" ) );
1163 }
1164
1165 constraint = drcEngine->EvalRules( DIFF_PAIR_GAP_CONSTRAINT, &dummyTrack, &dummyTrackB, targetLayer );
1166
1167 if( !constraint.IsNull() )
1168 {
1169 if( bds.UseNetClassDiffPair()
1170 || ( sizes.DiffPairGap() < bds.m_MinClearance )
1171 || ( sizes.DiffPairGap() < constraint.m_Value.Min() )
1172 || ( sizes.DiffPairGap() > constraint.m_Value.Max() ) )
1173 {
1174 sizes.SetDiffPairGap( std::max( bds.m_MinClearance, constraint.m_Value.PinnedOpt() ) );
1175 }
1176
1177 if( sizes.DiffPairGap() == constraint.m_Value.PinnedOpt() )
1178 sizes.SetDiffPairGapSource( constraint.GetName() );
1179 else
1180 sizes.SetDiffPairGapSource( _( "board minimum clearance" ) );
1181 }
1182 }
1183
1184 m_router->UpdateSizes( sizes );
1185}
1186
1187
1188static VIATYPE getViaTypeFromFlags( int aFlags )
1189{
1190 switch( aFlags & VIA_ACTION_FLAGS::VIA_MASK )
1191 {
1193 return VIATYPE::THROUGH;
1195 return VIATYPE::BLIND;
1197 return VIATYPE::BURIED;
1199 return VIATYPE::MICROVIA;
1200 default:
1201 wxASSERT_MSG( false, wxT( "Unhandled via type" ) );
1202 return VIATYPE::THROUGH;
1203 }
1204}
1205
1206
1208{
1209 handleLayerSwitch( aEvent, false );
1211
1212 return 0;
1213}
1214
1215
1217{
1218 if( !m_router->IsPlacingVia() )
1219 {
1220 return handleLayerSwitch( aEvent, true );
1221 }
1222 else
1223 {
1224 m_router->ToggleViaPlacement();
1225 frame()->SetActiveLayer( m_iface->GetBoardLayerFromPNSLayer( m_router->GetCurrentLayer() ) );
1226 updateEndItem( aEvent );
1228 }
1229
1231 return 0;
1232}
1233
1234
1236{
1237 if( !IsToolActive() )
1238 return 0;
1239
1240 if( !m_router->RoutingInProgress() || !m_router->Placer() )
1241 return 0;
1242
1243 m_iface->SetBoard( board() );
1244
1246 const std::vector<VIA_STACK_PRESET>& presets = bds.m_ViaStackPresets;
1247
1248 if( presets.empty() )
1249 {
1250 frame()->GetInfoBar()->ShowMessageFor( _( "No microvia stack presets defined. Add one in Board Setup, "
1251 "Microvia Stacks." ),
1252 3000, wxICON_INFORMATION );
1253 return 0;
1254 }
1255
1256 int idx = std::clamp( bds.GetViaStackIndex(), 0, (int) presets.size() - 1 );
1257 const VIA_STACK_PRESET& preset = presets[idx];
1258
1259 PCB_LAYER_ID currentLayer = m_iface->GetBoardLayerFromPNSLayer( m_router->GetCurrentLayer() );
1260
1261 if( currentLayer == UNDEFINED_LAYER )
1262 return 0;
1263
1264 const LSET enabled = board()->GetEnabledLayers();
1265
1266 if( !enabled.Contains( preset.m_StartLayer ) || !enabled.Contains( preset.m_EndLayer ) )
1267 {
1268 frame()->GetInfoBar()->ShowMessageFor( _( "The microvia stack preset layers are not present on this board." ),
1269 3000, wxICON_ERROR );
1270 return 0;
1271 }
1272
1273 PCB_LAYER_ID targetLayer = ViaStackTargetLayer( preset.m_StartLayer, preset.m_EndLayer, currentLayer );
1274
1275 if( targetLayer == UNDEFINED_LAYER )
1276 {
1277 frame()->GetInfoBar()->ShowMessageFor( wxString::Format( _( "The microvia stack runs between %s and %s. "
1278 "Route on one of those layers to place it." ),
1279 board()->GetLayerName( preset.m_StartLayer ),
1280 board()->GetLayerName( preset.m_EndLayer ) ),
1281 3000, wxICON_ERROR );
1282 return 0;
1283 }
1284
1285 if( preset.m_Staggered )
1286 {
1287 if( m_router->IsPlacingVia() )
1288 m_router->ToggleViaPlacement();
1289
1290 // The router cannot route through a staggered stack (lateral walk + connecting traces).
1291 // Fix the track here and REMEMBER the stack, but build it only after routing tears down.
1292 // Committing to the board while the PNS world is live invalidates its nodes (crash).
1293 VECTOR2I head = m_endSnapPoint;
1294 const PNS::ITEM_SET traces = m_router->Placer()->Traces();
1295
1296 if( traces.Size() > 0 )
1297 {
1298 if( PNS::LINE* line = dynamic_cast<PNS::LINE*>( traces[0] ) )
1299 {
1300 if( line->PointCount() > 0 )
1301 head = line->CLine().CLastPoint();
1302 }
1303 }
1304
1305 if( !m_router->FixRoute( head, m_endItem, true, false ) )
1306 {
1307 frame()->GetInfoBar()->ShowMessageFor( _( "Could not end the track here for a microvia stack." ), 3000,
1308 wxICON_ERROR );
1310 return 0;
1311 }
1312
1313 m_pendingViaStack = true;
1314 m_pendingStackHead = head;
1315 m_pendingStackStart = currentLayer;
1316 m_pendingStackEnd = targetLayer;
1317
1319 return 0;
1320 }
1321
1322 // A via the route places with no net reports UNCONNECTED, not ORPHANED.
1323 int net = NETINFO_LIST::UNCONNECTED;
1324
1325 if( !m_router->GetCurrentNets().empty() )
1326 {
1327 if( NETINFO_ITEM* ni = static_cast<NETINFO_ITEM*>( m_router->GetCurrentNets()[0] ) )
1328 net = ni->GetNetCode();
1329 }
1330
1331 int viaSize;
1332 int viaDrill;
1333
1334 if( preset.m_UseNetclass )
1335 {
1336 NETINFO_ITEM* ni = board()->FindNet( net );
1337 NETCLASS* nc = ni ? ni->GetNetClass() : nullptr;
1338
1339 viaSize = ( nc && nc->HasuViaDiameter() ) ? nc->GetuViaDiameter() : bds.GetCurrentViaSize();
1340 viaDrill = ( nc && nc->HasuViaDrill() ) ? nc->GetuViaDrill() : bds.GetCurrentViaDrill();
1341
1342 // Route with the size the stack's hops will resolve to from the via rules
1343 PCB_VIA dummyVia( board() );
1344 dummyVia.SetFlags( ROUTER_TRANSIENT );
1345 dummyVia.SetViaType( VIATYPE::MICROVIA );
1346 dummyVia.SetLayerPair( currentLayer, targetLayer );
1347 dummyVia.SetNetCode( net );
1348 dummyVia.SetPosition( m_endSnapPoint );
1349 dummyVia.SetSizeFromRules( viaSize, viaDrill );
1350
1351 viaSize = dummyVia.GetWidth( PADSTACK::ALL_LAYERS );
1352 viaDrill = dummyVia.GetDrillValue();
1353 }
1354 else
1355 {
1356 viaSize = preset.m_ViaSize > 0 ? preset.m_ViaSize : bds.GetCurrentViaSize();
1357 viaDrill = preset.m_ViaDrill > 0 ? preset.m_ViaDrill : bds.GetCurrentViaDrill();
1358 }
1359
1360 // Routing to a non-adjacent layer leaves one multi-hop microvia that finishInteractive()
1361 // expands into a stack.
1362 if( m_pendingStackedExpansions.empty() )
1363 {
1365 }
1366
1367 m_pendingStackedExpansions.push_back( { currentLayer, targetLayer, net, preset, std::nullopt } );
1369
1370 PNS::SIZES_SETTINGS sizes = m_router->Sizes();
1371 sizes.ClearLayerPairs();
1372
1373 sizes.SetViaDiameter( viaSize );
1374 sizes.SetViaDrill( viaDrill );
1376 sizes.AddLayerPair( m_iface->GetPNSLayerFromBoardLayer( currentLayer ),
1377 m_iface->GetPNSLayerFromBoardLayer( targetLayer ) );
1378
1379 m_router->UpdateSizes( sizes );
1380
1381 if( !m_router->IsPlacingVia() )
1382 m_router->ToggleViaPlacement();
1383
1384 if( m_router->RoutingInProgress() )
1385 {
1386 updateEndItem( aEvent );
1388 }
1389
1391 return 0;
1392}
1393
1394
1396{
1397 if( !m_stackDropAwaitingVia || !m_router->IsPlacingVia() )
1398 return;
1399
1400 const PNS::ITEM_SET traces = m_router->Placer()->Traces();
1401
1402 if( traces.Size() == 0 )
1403 return;
1404
1405 // The via lands where the placer's trace ends, which is not where the cursor is once
1406 // the router has walked around or shoved.
1407 if( PNS::LINE* line = dynamic_cast<PNS::LINE*>( traces[0] ) )
1408 {
1409 if( line->EndsWithVia() )
1410 m_pendingStackedExpansions.back().m_Pos = line->Via().Pos();
1411 }
1412}
1413
1414
1416{
1417 m_pendingViaStack = false;
1418
1419 // Hand off to the interactive microvia stack placement, pre-anchored at the routed head, so
1420 // the user steers each staggered hop exactly like free-standing placement. Running this only
1421 // after the route has fully torn down keeps the board edit clear of the PNS world.
1422 if( DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>() )
1423 {
1424 drawingTool->SeedViaStackStart( m_pendingStackHead, m_pendingStackStart, m_pendingStackEnd );
1426 }
1427}
1428
1429
1430int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
1431{
1432 wxCHECK( m_router, 0 );
1433
1434 if( !IsToolActive() )
1435 return 0;
1436
1437 // Ensure PNS_KICAD_IFACE (m_iface) m_board member is up to date
1438 // For some reason, this is not always the case
1439 m_iface->SetBoard( board() );
1440
1441 // First see if this is one of the switch layer commands
1442 BOARD* brd = board();
1443 LSET enabledLayers = LSET::AllCuMask( brd->GetDesignSettings().GetCopperLayerCount() );
1444 LSEQ layers = enabledLayers.UIOrder();
1445
1446 // These layers are in Board Layer UI order not PNS layer order
1447 PCB_LAYER_ID currentLayer = m_iface->GetBoardLayerFromPNSLayer( m_router->GetCurrentLayer() );
1448 PCB_LAYER_ID targetLayer = UNDEFINED_LAYER;
1449
1450 if( aEvent.IsAction( &PCB_ACTIONS::layerNext ) )
1451 {
1452 size_t idx = 0;
1453 size_t target_idx = 0;
1454
1455 for( size_t i = 0; i < layers.size(); i++ )
1456 {
1457 if( layers[i] == currentLayer )
1458 {
1459 idx = i;
1460 break;
1461 }
1462 }
1463
1464 target_idx = ( idx + 1 ) % layers.size();
1465 // issue: #14480
1466 // idx + 1 layer may be invisible, switches to next visible layer
1467 for( size_t i = 0; i < layers.size() - 1; i++ )
1468 {
1469 if( brd->IsLayerVisible( layers[target_idx] ) )
1470 {
1471 targetLayer = layers[target_idx];
1472 break;
1473 }
1474 target_idx += 1;
1475
1476 if( target_idx >= layers.size() )
1477 {
1478 target_idx = 0;
1479 }
1480 }
1481
1482 if( targetLayer == UNDEFINED_LAYER )
1483 {
1484 // if there is no visible layers
1485 return 0;
1486 }
1487 }
1488 else if( aEvent.IsAction( &PCB_ACTIONS::layerPrev ) )
1489 {
1490 size_t idx = 0;
1491 size_t target_idx = 0;
1492
1493 for( size_t i = 0; i < layers.size(); i++ )
1494 {
1495 if( layers[i] == currentLayer )
1496 {
1497 idx = i;
1498 break;
1499 }
1500 }
1501
1502 target_idx = ( idx > 0 ) ? ( idx - 1 ) : ( layers.size() - 1 );
1503
1504 for( size_t i = 0; i < layers.size() - 1; i++ )
1505 {
1506 if( brd->IsLayerVisible( layers[target_idx] ) )
1507 {
1508 targetLayer = layers[target_idx];
1509 break;
1510 }
1511
1512 if( target_idx > 0 )
1513 target_idx -= 1;
1514 else
1515 target_idx = layers.size() - 1;
1516 }
1517
1518 if( targetLayer == UNDEFINED_LAYER )
1519 {
1520 // if there is no visible layers
1521 return 0;
1522 }
1523 }
1524 else if( aEvent.IsAction( &PCB_ACTIONS::layerToggle ) )
1525 {
1526 PCB_SCREEN* screen = frame()->GetScreen();
1527
1528 if( currentLayer == screen->m_Route_Layer_TOP )
1529 targetLayer = screen->m_Route_Layer_BOTTOM;
1530 else
1531 targetLayer = screen->m_Route_Layer_TOP;
1532 }
1534 {
1535 targetLayer = aEvent.Parameter<PCB_LAYER_ID>();
1536
1537 if( !enabledLayers.test( targetLayer ) )
1538 return 0;
1539 }
1540
1541 if( targetLayer != UNDEFINED_LAYER )
1542 {
1543 if( targetLayer == currentLayer )
1544 return 0;
1545
1546 if( !aForceVia && m_router && m_router->SwitchLayer( m_iface->GetPNSLayerFromBoardLayer( targetLayer ) ) )
1547 {
1548 updateEndItem( aEvent );
1549 updateSizesAfterRouterEvent( m_iface->GetPNSLayerFromBoardLayer( targetLayer ), m_endSnapPoint );
1550 m_router->Move( m_endSnapPoint, m_endItem ); // refresh
1551 return 0;
1552 }
1553 }
1554
1556
1557 PCB_LAYER_ID pairTop = frame()->GetScreen()->m_Route_Layer_TOP;
1558 PCB_LAYER_ID pairBottom = frame()->GetScreen()->m_Route_Layer_BOTTOM;
1559
1560 PNS::SIZES_SETTINGS sizes = m_router->Sizes();
1561
1562 VIATYPE viaType = VIATYPE::THROUGH;
1563 bool selectLayer = false;
1564
1565 // Otherwise it is one of the router-specific via commands
1566 if( targetLayer == UNDEFINED_LAYER )
1567 {
1568 const int actViaFlags = aEvent.Parameter<int>();
1569 selectLayer = actViaFlags & VIA_ACTION_FLAGS::SELECT_LAYER;
1570
1571 viaType = getViaTypeFromFlags( actViaFlags );
1572
1573 // ask the user for a target layer
1574 if( selectLayer )
1575 {
1576 // When the currentLayer is undefined, trying to place a via does not work
1577 // because it means there is no track in progress, and some other variables
1578 // values are not defined like m_endSnapPoint. So do not continue.
1579 if( currentLayer == UNDEFINED_LAYER )
1580 return 0;
1581
1582 wxPoint endPoint = ToWxPoint( view()->ToScreen( m_endSnapPoint ) );
1583 endPoint = frame()->GetCanvas()->ClientToScreen( endPoint );
1584
1585 // Build the list of not allowed layer for the target layer
1586 LSET not_allowed_ly = LSET::AllNonCuMask();
1587
1588 if( viaType != VIATYPE::THROUGH )
1589 not_allowed_ly.set( currentLayer );
1590
1591 targetLayer = frame()->SelectOneLayer( static_cast<PCB_LAYER_ID>( currentLayer ),
1592 not_allowed_ly, endPoint );
1593
1594 // Reset the cursor to the end of the track
1596
1597 if( targetLayer == UNDEFINED_LAYER ) // canceled by user
1598 return 0;
1599
1600 // One cannot place a blind/buried via on only one layer:
1601 if( viaType != VIATYPE::THROUGH )
1602 {
1603 if( currentLayer == targetLayer )
1604 return 0;
1605 }
1606 }
1607 }
1608
1609 // fixme: P&S supports more than one fixed layer pair. Update the dialog?
1610 sizes.ClearLayerPairs();
1611
1612 // Convert blind/buried via to a through hole one, if it goes through all layers
1613 if( viaType != VIATYPE::THROUGH
1614 && ( ( targetLayer == B_Cu && currentLayer == F_Cu )
1615 || ( targetLayer == F_Cu && currentLayer == B_Cu ) ) )
1616 {
1617 viaType = VIATYPE::THROUGH;
1618 }
1619
1620 if( targetLayer == UNDEFINED_LAYER )
1621 {
1622 // Implicit layer selection
1623 if( viaType == VIATYPE::THROUGH )
1624 {
1625 // Try to switch to the nearest ratnest item's layer if we have one
1626 VECTOR2I otherEnd;
1627 PNS_LAYER_RANGE otherEndLayers;
1628 PNS::ITEM* otherEndItem = nullptr;
1629
1630 if( !m_router->GetNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) )
1631 {
1632 // use the default layer pair
1633 currentLayer = pairTop;
1634 targetLayer = pairBottom;
1635 }
1636 else
1637 {
1638 // use the layer of the other end, unless it is the same layer as the currently active layer, in which
1639 // case use the layer pair (if applicable)
1640 PCB_LAYER_ID otherEndLayerPcbId = m_iface->GetBoardLayerFromPNSLayer( otherEndLayers.Start() );
1641 const std::optional<int> pairedLayerPns = m_router->Sizes().PairedLayer( m_router->GetCurrentLayer() );
1642
1643 const PNS_LAYER_RANGE allCopperLayers( m_iface->GetPNSLayerFromBoardLayer( F_Cu ),
1644 m_iface->GetPNSLayerFromBoardLayer( B_Cu ) );
1645
1646 // A through anchor connects on every copper layer, so it names no single target.
1647 // Test the hole rather than the copper range, which segmented padstacks
1648 // (FRONT_INNER_BACK, custom) can report as a single layer.
1649 const bool otherEndIsThrough =
1650 otherEndLayers == allCopperLayers
1651 || ( otherEndItem && otherEndItem->HasHole()
1652 && otherEndItem->Hole()->Layers() == allCopperLayers );
1653
1654 if( otherEndIsThrough )
1655 {
1656 // Honour the user's layer pair; the anchor span start is always the top
1657 // copper layer and would ignore it. Constrained anchors fall through below.
1658 if( currentLayer == pairBottom )
1659 targetLayer = pairTop;
1660 else if( currentLayer == pairTop )
1661 targetLayer = pairBottom;
1662 else
1663 targetLayer = pairTop;
1664 }
1665 else if( currentLayer == otherEndLayerPcbId && pairedLayerPns.has_value() )
1666 {
1667 // Closest ratsnest layer is the same as the active layer - assume the via is being placed for
1668 // other routing reasons and switch the layer
1669 targetLayer = m_iface->GetBoardLayerFromPNSLayer( *pairedLayerPns );
1670 }
1671 else
1672 {
1673 targetLayer = m_iface->GetBoardLayerFromPNSLayer( otherEndLayers.Start() );
1674 }
1675 }
1676 }
1677 else
1678 {
1679 if( currentLayer == pairTop || currentLayer == pairBottom )
1680 {
1681 // the current layer is on the defined layer pair,
1682 // swap to the other side
1683 currentLayer = pairTop;
1684 targetLayer = pairBottom;
1685 }
1686 else
1687 {
1688 // the current layer is not part of the current layer pair,
1689 // so fallback and swap to the top layer of the pair by default
1690 targetLayer = pairTop;
1691 }
1692
1693 // Do not create a broken via (i.e. a via on only one copper layer)
1694 if( currentLayer == targetLayer )
1695 {
1696 WX_INFOBAR* infobar = frame()->GetInfoBar();
1697 infobar->ShowMessageFor( _( "Via needs 2 different layers." ), 5000, wxICON_ERROR,
1698 WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION );
1699 return 0;
1700 }
1701 }
1702 }
1703
1704 sizes.SetViaDiameter( bds.m_ViasMinSize );
1705 sizes.SetViaDrill( bds.m_MinThroughDrill );
1706
1707 if( bds.UseNetClassVia() || viaType == VIATYPE::MICROVIA )
1708 {
1709 PCB_VIA dummyVia( board() );
1710 dummyVia.SetViaType( viaType );
1711 dummyVia.SetLayerPair( currentLayer, targetLayer );
1712
1713 if( !m_router->GetCurrentNets().empty() )
1714 dummyVia.SetNet( static_cast<NETINFO_ITEM*>( m_router->GetCurrentNets()[0] ) );
1715
1716 DRC_CONSTRAINT constraint;
1717
1718 constraint = bds.m_DRCEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, &dummyVia, nullptr, currentLayer );
1719
1720 if( !constraint.IsNull() )
1721 sizes.SetViaDiameter( constraint.m_Value.PinnedOpt() );
1722
1723 constraint = bds.m_DRCEngine->EvalRules( HOLE_SIZE_CONSTRAINT, &dummyVia, nullptr, currentLayer );
1724
1725 if( !constraint.IsNull() )
1726 sizes.SetViaDrill( constraint.m_Value.PinnedOpt() );
1727 }
1728 else
1729 {
1730 sizes.SetViaDiameter( bds.GetCurrentViaSize() );
1731 sizes.SetViaDrill( bds.GetCurrentViaDrill() );
1732 }
1733
1734 sizes.SetViaType( viaType );
1735 sizes.AddLayerPair( m_iface->GetPNSLayerFromBoardLayer( currentLayer ),
1736 m_iface->GetPNSLayerFromBoardLayer( targetLayer ) );
1737
1738 m_router->UpdateSizes( sizes );
1739
1740 if( !m_router->IsPlacingVia() )
1741 m_router->ToggleViaPlacement();
1742
1743 if( m_router->RoutingInProgress() )
1744 {
1745 updateEndItem( aEvent );
1747 }
1748 else
1749 {
1750 updateStartItem( aEvent );
1751 }
1752
1753 return 0;
1754}
1755
1756
1758{
1761
1762 // The stack handoff names the resume layer so snapping does not guess it from nearby copper.
1764 {
1765 pcbLayer = m_viaStackResumeLayer;
1767 }
1768
1769 int pnsLayer = m_iface->GetPNSLayerFromBoardLayer( pcbLayer );
1770
1771 if( !::IsCopperLayer( pcbLayer ) )
1772 {
1773 editFrame->ShowInfoBarError( _( "Tracks on Copper layers only." ) );
1774 return false;
1775 }
1776
1778 editFrame->SetActiveLayer( pcbLayer );
1779
1780 if( !getView()->IsLayerVisible( pcbLayer ) )
1781 {
1782 editFrame->GetAppearancePanel()->SetLayerVisible( pcbLayer, true );
1783 editFrame->GetCanvas()->Refresh();
1784 }
1785
1786 PNS::SIZES_SETTINGS sizes( m_router->Sizes() );
1787
1788 m_iface->SetStartLayerFromPCBNew( pcbLayer );
1789
1790 frame()->GetBoard()->GetDesignSettings().m_TempOverrideTrackWidth = false;
1791 m_iface->ImportSizes( sizes, m_startItem, nullptr, aStartPosition );
1792 sizes.AddLayerPair( m_iface->GetPNSLayerFromBoardLayer( frame()->GetScreen()->m_Route_Layer_TOP ),
1793 m_iface->GetPNSLayerFromBoardLayer( frame()->GetScreen()->m_Route_Layer_BOTTOM ) );
1794
1795 m_router->UpdateSizes( sizes );
1796
1797 if( m_startItem && m_startItem->Net() )
1798 {
1800 {
1801 if( PNS::NET_HANDLE coupledNet = m_router->GetRuleResolver()->DpCoupledNet( m_startItem->Net() ) )
1802 highlightNets( true, { m_startItem->Net(), coupledNet } );
1803 }
1804 else
1805 {
1806 highlightNets( true, { m_startItem->Net() } );
1807 }
1808 }
1809
1810 controls()->SetAutoPan( true );
1811
1812 if( !m_router->StartRouting( m_startSnapPoint, m_startItem, pnsLayer ) )
1813 {
1814 // It would make more sense to leave the net highlighted as the higher-contrast mode
1815 // makes the router clearances more visible. However, since we just started routing
1816 // the conversion of the screen from low contrast to high contrast is a bit jarring and
1817 // makes the infobar coming up less noticeable.
1818 highlightNets( false );
1819
1820 frame()->ShowInfoBarError( m_router->FailureReason(), true,
1821 [&]()
1822 {
1823 m_router->ClearViewDecorations();
1824 } );
1825
1826 controls()->SetAutoPan( false );
1827 return false;
1828 }
1829
1830 m_endItem = nullptr;
1832
1834 frame()->UndoRedoBlock( true );
1835
1836 return true;
1837}
1838
1839
1841{
1842 m_router->StopRouting();
1843
1844 m_stackDropAwaitingVia = false;
1845
1846 if( !m_pendingStackedExpansions.empty() )
1847 {
1848 BOARD_COMMIT commit( frame() );
1849
1850 auto matcher = [&]( PCB_VIA* aVia ) -> const VIA_STACK_PRESET*
1851 {
1853 };
1854
1855 if( PCB_VIA_STACK::ExpandMultiHopMicrovias( board(), &commit, matcher ) > 0 )
1856 commit.Push( _( "Expand Microvia Stacks" ), APPEND_UNDO );
1857
1860 }
1861
1862 m_startItem = nullptr;
1863 m_endItem = nullptr;
1864
1865 frame()->SetActiveLayer( m_originalActiveLayer );
1867 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1868 controls()->SetAutoPan( false );
1869 controls()->ForceCursorPosition( false );
1870 frame()->UndoRedoBlock( false );
1871 highlightNets( false );
1872
1873 return true;
1874}
1875
1876
1878{
1879 m_router->ClearViewDecorations();
1880
1881 if( !prepareInteractive( aStartPosition ) )
1882 return;
1883
1884 auto setCursor =
1885 [&]()
1886 {
1887 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
1888 };
1889
1890 auto syncRouterAndFrameLayer =
1891 [&]()
1892 {
1893 int pnsLayer = m_router->GetCurrentLayer();
1894 PCB_LAYER_ID pcbLayer = m_iface->GetBoardLayerFromPNSLayer( pnsLayer );
1896
1897 editFrame->SetActiveLayer( pcbLayer );
1898
1899 if( !getView()->IsLayerVisible( pcbLayer ) )
1900 {
1901 editFrame->GetAppearancePanel()->SetLayerVisible( pcbLayer, true );
1902 editFrame->GetCanvas()->Refresh();
1903 }
1904 };
1905
1906 // Set initial cursor
1907 setCursor();
1908
1909 // Throttle wxEVT_UPDATE_UI during routing. The idle sweep fires between every Wait()
1910 // iteration and its cost dominates at interactive frame rates.
1911 UI_UPDATE_INTERVAL_GUARD uiGuard( 200 );
1912
1913 while( TOOL_EVENT* evt = Wait() )
1914 {
1915 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Catch any visibility
1916 // changes while routing.
1917 m_toolMgr->GetView()->SyncLayerVisibilityCache();
1918
1919 setCursor();
1920
1921 // Don't crash if we missed an operation that canceled routing.
1922 if( !m_router->RoutingInProgress() )
1923 {
1924 if( evt->IsCancelInteractive() )
1925 m_cancelled = true;
1926
1927 break;
1928 }
1929
1930 handleCommonEvents( *evt );
1931
1932 if( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) )
1933 {
1934 updateEndItem( *evt );
1936 }
1937 else if( evt->IsAction( &PCB_ACTIONS::routerUndoLastSegment )
1938 || evt->IsAction( &ACTIONS::doDelete )
1939 || evt->IsAction( &ACTIONS::undo ) )
1940 {
1941 if( std::optional<VECTOR2I> last = m_router->UndoLastSegment() )
1942 {
1943 getViewControls()->WarpMouseCursor( last.value(), true );
1944 evt->SetMousePosition( last.value() );
1945 }
1946
1947 updateEndItem( *evt );
1949 }
1950 else if( evt->IsAction( &PCB_ACTIONS::routerAttemptFinish ) )
1951 {
1952 if( m_toolMgr->IsContextMenuActive() )
1953 m_toolMgr->WarpAfterContextMenu();
1954
1955 bool* autoRouted = evt->Parameter<bool*>();
1956
1957 if( m_router->Finish() )
1958 {
1959 // When we're routing a group of signals automatically we want
1960 // to break up the undo stack every time we have to manually route
1961 // so the user gets nice checkpoints. Remove the APPEND_UNDO flag.
1962 if( autoRouted != nullptr )
1963 *autoRouted = true;
1964
1965 break;
1966 }
1967 else
1968 {
1969 // This acts as check if we were called by the autorouter; we don't want
1970 // to reset APPEND_UNDO if we're auto finishing after route-other-end
1971 if( autoRouted != nullptr )
1972 {
1973 *autoRouted = false;
1974 m_iface->SetCommitFlags( 0 );
1975 }
1976
1977 // Warp the mouse so the user is at the point we managed to route to
1978 controls()->WarpMouseCursor( m_router->Placer()->CurrentEnd(), true, true );
1979 }
1980 }
1981 else if( evt->IsAction( &PCB_ACTIONS::routerContinueFromEnd ) )
1982 {
1983 bool needsAppend = m_router->Placer()->HasPlacedAnything();
1984
1985 if( m_router->ContinueFromEnd( &m_startItem ) )
1986 {
1987 syncRouterAndFrameLayer();
1988 m_startSnapPoint = m_router->Placer()->CurrentStart();
1989 updateEndItem( *evt );
1990
1991 // Warp the mouse to wherever we actually ended up routing to
1992 controls()->WarpMouseCursor( m_router->Placer()->CurrentEnd(), true, true );
1993
1994 // We want the next router commit to be one undo at the UI layer
1995 m_iface->SetCommitFlags( needsAppend ? APPEND_UNDO : 0 );
1996 }
1997 else
1998 {
1999 frame()->ShowInfoBarError( m_router->FailureReason(), true );
2000 }
2001 }
2002 else if( evt->IsClick( BUT_LEFT )
2003 || evt->IsAction( &ACTIONS::cursorClick )
2004 || evt->IsDrag( BUT_LEFT )
2005 || evt->IsAction( &PCB_ACTIONS::routeSingleTrack ) )
2006 {
2007 updateEndItem( *evt );
2008 bool needLayerSwitch = m_router->IsPlacingVia();
2009 bool forceCommit = false;
2010
2012
2013 if( m_router->FixRoute( m_endSnapPoint, m_endItem, false, forceCommit ) )
2014 break;
2015
2016 if( !m_router->IsPlacingVia() )
2017 m_stackDropAwaitingVia = false;
2018
2019 if( needLayerSwitch )
2020 {
2022 }
2023 else
2024 {
2026 }
2027
2028 // Synchronize the indicated layer
2029 syncRouterAndFrameLayer();
2030
2031 updateEndItem( *evt );
2033 m_startItem = nullptr;
2034 }
2035 else if( evt->IsAction( &ACT_PlaceViaStack ) )
2036 {
2037 onViaStackCommand( *evt );
2038
2039 // A staggered drop fixes the track and queues the stack, break so the normal
2040 // teardown runs (restores the cursor) and the generator is committed after the
2041 // PNS world is gone.
2042 if( m_pendingViaStack || !m_router->RoutingInProgress() )
2043 break;
2044
2045 updateEndItem( *evt );
2047 }
2048 else if( evt->IsAction( &ACT_SwitchPosture ) )
2049 {
2050 m_router->FlipPosture();
2051 updateEndItem( *evt );
2052 m_router->Move( m_endSnapPoint, m_endItem ); // refresh
2053 }
2054 else if( evt->IsAction( &PCB_ACTIONS::properties ) )
2055 {
2056 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
2057 controls()->SetAutoPan( false );
2058 {
2059 m_toolMgr->RunAction( ACT_CustomTrackWidth );
2060 }
2061 controls()->SetAutoPan( true );
2062 setCursor();
2064 }
2065 else if( evt->IsAction( &ACTIONS::finishInteractive )
2066 || evt->IsDblClick( BUT_LEFT )
2067 || evt->IsAction( &ACTIONS::cursorDblClick ) )
2068 {
2069 // Stop current routing:
2070 bool forceFinish = true;
2071 bool forceCommit = false;
2072
2073 m_router->FixRoute( m_endSnapPoint, m_endItem, forceFinish, forceCommit );
2074 break;
2075 }
2076 else if( evt->IsCancelInteractive() || evt->IsAction( &PCB_ACTIONS::cancelCurrentItem )
2077 || evt->IsActivate()
2078 || evt->IsAction( &PCB_ACTIONS::routerInlineDrag ) )
2079 {
2080 if( evt->IsCancelInteractive() && ( m_inRouteSelected || !m_router->RoutingInProgress() ) )
2081 m_cancelled = true;
2082
2083 if( evt->IsActivate() && !evt->IsMoveTool() )
2084 m_cancelled = true;
2085
2086 m_router->AbortPlacement();
2087
2088 break;
2089 }
2090 else if( evt->IsUndoRedo() )
2091 {
2092 // We're in an UndoRedoBlock. If we get here, something's broken.
2093 wxFAIL;
2094 break;
2095 }
2096 else if( evt->IsClick( BUT_RIGHT ) )
2097 {
2098 m_menu->ShowContextMenu( selection() );
2099 }
2100 // TODO: It'd be nice to be able to say "don't allow any non-trivial editing actions",
2101 // but we don't at present have that, so we just knock out some of the egregious ones.
2102 else if( ZONE_FILLER_TOOL::IsZoneFillAction( evt ) )
2103 {
2104 wxBell();
2105 }
2106 else
2107 {
2108 evt->SetPassEvent();
2109 }
2110 }
2111
2112 m_router->CommitRouting();
2113 // Reset to normal for next route
2114 m_iface->SetCommitFlags( 0 );
2115
2117
2118 // The PNS world is now torn down, so it is safe to add a queued staggered stack to the board.
2119 if( m_pendingViaStack )
2121}
2122
2123
2125{
2126 PNS::SIZES_SETTINGS sizes = m_router->Sizes();
2127 DIALOG_PNS_DIFF_PAIR_DIMENSIONS settingsDlg( frame(), sizes );
2128
2129 if( settingsDlg.ShowModal() == wxID_OK )
2130 {
2131 m_router->UpdateSizes( sizes );
2132 m_savedSizes = sizes;
2133
2134 BOARD_DESIGN_SETTINGS& bds = frame()->GetBoard()->GetDesignSettings();
2136 bds.SetCustomDiffPairGap( sizes.DiffPairGap() );
2138 }
2139
2140 return 0;
2141}
2142
2143
2145{
2146 DIALOG_PNS_SETTINGS settingsDlg( frame(), m_router->Settings() );
2147
2148 settingsDlg.ShowModal();
2149
2151
2152 return 0;
2153}
2154
2155
2157{
2158 PNS::PNS_MODE mode = aEvent.Parameter<PNS::PNS_MODE>();
2159 PNS::ROUTING_SETTINGS& settings = m_router->Settings();
2160
2161 settings.SetMode( mode );
2163
2164 return 0;
2165}
2166
2167
2169{
2170 PNS::ROUTING_SETTINGS& settings = m_router->Settings();
2171 PNS::PNS_MODE mode = settings.Mode();
2172
2173 switch( mode )
2174 {
2175 case PNS::RM_MarkObstacles: mode = PNS::RM_Shove; break;
2176 case PNS::RM_Shove: mode = PNS::RM_Walkaround; break;
2177 case PNS::RM_Walkaround: mode = PNS::RM_MarkObstacles; break;
2178 }
2179
2180 settings.SetMode( mode );
2182
2183 return 0;
2184}
2185
2186
2188{
2189 return m_router->Settings().Mode();
2190}
2191
2192
2194{
2195 return m_router->RoutingInProgress();
2196}
2197
2198
2200{
2201 if( !m_startItem )
2202 return;
2203
2204 // Never split a via stack's connecting trace. The stack manages it as a unit, and a
2205 // split fragment would drop out of the group. Other generators still allow splitting.
2206 if( BOARD_ITEM* parent = m_startItem->Parent() )
2207 {
2208 if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( parent->GetParentGroup() ) )
2209 {
2210 if( generator->GetGeneratorType() == PCB_VIA_STACK::GENERATOR_TYPE )
2211 return;
2212 }
2213 }
2214
2216 m_router->BreakSegmentOrArc( m_startItem, m_startSnapPoint );
2217}
2218
2219
2221{
2225 PCB_LAYER_ID originalLayer = frame->GetActiveLayer();
2226 bool autoRoute = aEvent.Matches( PCB_ACTIONS::routerAutorouteSelected.MakeEvent() );
2227 bool otherEnd = aEvent.Matches( PCB_ACTIONS::routerRouteSelectedFromEnd.MakeEvent() );
2228
2229 if( m_router->RoutingInProgress() )
2230 return 0;
2231
2232 // Save selection then clear it for interactive routing
2233 PCB_SELECTION selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
2234
2235 if( selection.Size() == 0 )
2236 return 0;
2237
2238 m_toolMgr->RunAction( ACTIONS::selectionClear );
2239
2240 SCOPED_TOOL_PUSHER raii( frame, aEvent );
2241
2242 auto setCursor =
2243 [&]()
2244 {
2245 frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
2246 };
2247
2248 Activate();
2249 m_inRouteSelected = true;
2250
2251 // Must be done after Activate() so that it gets set into the correct context
2252 controls->ShowCursor( true );
2253 controls->ForceCursorPosition( false );
2254 // Set initial cursor
2255 setCursor();
2256
2257 // Get all connected board items, adding pads for any footprints selected
2258 std::vector<BOARD_CONNECTED_ITEM*> itemList;
2259
2260 for( EDA_ITEM* item : selection.GetItemsSortedBySelectionOrder() )
2261 {
2262 if( item->Type() == PCB_FOOTPRINT_T )
2263 {
2264 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
2265 itemList.push_back( pad );
2266 }
2267 else if( dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) != nullptr )
2268 {
2269 itemList.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
2270 }
2271 }
2272
2273 std::shared_ptr<CONNECTIVITY_DATA> connectivity = frame->GetBoard()->GetConnectivity();
2274
2275 // For putting sequential tracks that successfully autoroute into one undo commit
2276 bool groupStart = true;
2277 m_cancelled = false;
2278
2279 for( BOARD_CONNECTED_ITEM* item : itemList )
2280 {
2281 // This code is similar to GetRatsnestForPad() but it only adds the anchor for
2282 // the side of the connectivity on this pad. It also checks for ratsnest points
2283 // inside the pad (like a trace end) and counts them.
2284 RN_NET* net = connectivity->GetRatsnestForNet( item->GetNetCode() );
2285
2286 if( !net )
2287 continue;
2288
2289 std::vector<std::shared_ptr<const CN_ANCHOR>> anchors;
2290
2291 for( const CN_EDGE& edge : net->GetEdges() )
2292 {
2293 std::shared_ptr<const CN_ANCHOR> target = edge.GetTargetNode();
2294 std::shared_ptr<const CN_ANCHOR> source = edge.GetSourceNode();
2295
2296 if( !source || source->Dirty() || !target || target->Dirty() )
2297 continue;
2298
2299 if( source->Parent() == item )
2300 anchors.push_back( source );
2301 else if( target->Parent() == item )
2302 anchors.push_back( target );
2303 }
2304
2305 // Route them
2306 for( std::shared_ptr<const CN_ANCHOR> anchor : anchors )
2307 {
2308 if( !anchor->Valid() )
2309 continue;
2310
2311 // Try to return to the original layer as indicating the user's preferred
2312 // layer for autorouting tracks. The layer can be changed by the user to
2313 // finish tracks that can't complete automatically, but should be changed
2314 // back after.
2315 if( frame->GetActiveLayer() != originalLayer )
2316 frame->SetActiveLayer( originalLayer );
2317
2318 m_startItem = m_router->GetWorld()->FindItemByParent( anchor->Parent() );
2319 m_startSnapPoint = anchor->Pos();
2320 m_router->SetMode( mode );
2321
2322 // Prime the interactive routing to attempt finish if we are autorouting
2323 bool autoRouted = false;
2324
2325 if( autoRoute )
2326 m_toolMgr->PostAction( PCB_ACTIONS::routerAttemptFinish, &autoRouted );
2327 else if( otherEnd )
2329
2330 // We want autorouted tracks to all be in one undo group except for
2331 // any tracks that need to be manually finished.
2332 // The undo appending for manually finished tracks is handled in peformRouting()
2333 if( groupStart )
2334 groupStart = false;
2335 else
2336 m_iface->SetCommitFlags( APPEND_UNDO );
2337
2338 // Start interactive routing. Will automatically finish if possible.
2340
2341 if( m_cancelled )
2342 break;
2343
2344 // Route didn't complete automatically, need to a new undo commit
2345 // for the next line so those can group as far as they autoroute
2346 if( !autoRouted )
2347 groupStart = true;
2348 }
2349
2350 if( m_cancelled )
2351 break;
2352 }
2353
2354 m_iface->SetCommitFlags( 0 );
2355 m_inRouteSelected = false;
2356 return 0;
2357}
2358
2359
2361{
2363 const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
2364
2365 if( selection.Size() == 0 )
2366 return 0;
2367
2368 std::vector<BOARD_CONNECTED_ITEM*> trackItems;
2369
2370 for( EDA_ITEM* item : selection.GetItemsSortedBySelectionOrder() )
2371 {
2372 if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
2373 trackItems.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
2374 }
2375
2376 if( trackItems.empty() )
2377 return 0;
2378
2379 m_toolMgr->RunAction( ACTIONS::selectionClear );
2380 Activate();
2381
2382 PNS::NODE* world = m_router->GetWorld();
2383
2384 // Differential pairs can't be optimized as individual lines
2385 // TODO once we have a differential pair line primitive, we could handle them...
2386 int dpSkipped = std::erase_if( trackItems,
2387 [&]( BOARD_CONNECTED_ITEM* aItem )
2388 {
2389 PNS::RULE_RESOLVER* rr = world->GetRuleResolver();
2390 return rr && rr->DpCoupledNet( aItem->GetNet() );
2391 } );
2392
2393 if( dpSkipped > 0 )
2394 frame->ShowInfoBarMsg( _( "Differential pair members cannot be optimized." ) );
2395
2396 bool groupStart = true;
2397
2398 for( BOARD_CONNECTED_ITEM* trackItem : trackItems )
2399 {
2400 PNS::ITEM* pnsItem = world->FindItemByParent( trackItem );
2401
2402 if( !pnsItem || !pnsItem->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::ARC_T ) )
2403 continue;
2404
2405 PNS::LINKED_ITEM* linkedItem = static_cast<PNS::LINKED_ITEM*>( pnsItem );
2406
2407 PNS::LINE originalLine = world->AssembleLine( linkedItem );
2408
2409 // TODO: could allow these once we have arc-aware drag/optimize
2410 if( originalLine.ArcCount() > 0 )
2411 continue;
2412
2413 PNS::NODE* branch = world->Branch();
2414 branch->Remove( originalLine );
2415
2416 PNS::LINE optimizedLine( originalLine );
2417 optimizedLine.ClearLinks();
2418
2424
2425 if( m_router->Settings().GetRestrictAngles() )
2427
2428 bool optimized = PNS::OPTIMIZER::Optimize( &optimizedLine, effort, branch );
2429
2430 if( !optimized || optimizedLine.CompareGeometry( originalLine ) )
2431 {
2432 delete branch;
2433 continue;
2434 }
2435
2436 if( branch->CheckColliding( &optimizedLine ) )
2437 {
2438 delete branch;
2439 continue;
2440 }
2441
2442 if( groupStart )
2443 groupStart = false;
2444 else
2445 m_iface->SetCommitFlags( APPEND_UNDO );
2446
2447 branch->Add( optimizedLine );
2448 m_router->CommitRouting( branch );
2449 }
2450
2451 m_iface->SetCommitFlags( 0 );
2452
2453 return 0;
2454}
2455
2456
2458{
2459 int value = m_router->Settings().GetSpreadTracksDistance();
2460 wxIntegerValidator<int> validator( &value );
2461 validator.SetRange( 0, 10000000 );
2462 WX_TEXT_ENTRY_DIALOG dlg( frame(), _( "Distance:" ), _( "Set Spreading Distance" ) );
2464 int modalResult = dlg.ShowModal();
2465 if( modalResult == wxID_OK )
2466 {
2467 int newSpreadDist = wxAtoi( dlg.GetValue() );
2468 m_router->Settings().SetSpreadTracksDistance( newSpreadDist );
2469 m_router->Move( aEvent.Position(), nullptr );
2470 }
2471
2472 return 0;
2473}
2474
2475
2477{
2478 VECTOR2I grid = m_gridHelper->GetGrid();
2479
2480 int dist = m_router->Settings().GetSpreadTracksDistance();
2481
2482 int remainder = dist % grid.x;
2483
2484 if( aInc )
2485 dist += ( grid.x - remainder ) + grid.x;
2486 else
2487 dist -= remainder + grid.x;
2488
2489 if( dist < 0 )
2490 dist = 0;
2491
2492 m_router->Settings().SetSpreadTracksDistance( dist );
2493 m_router->Move( aEvent.Position(), nullptr );
2494
2495 return 0;
2496}
2497
2498
2500{
2504
2505 const PCB_SELECTION curSelection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
2506
2507 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
2508 SCOPED_TOOL_PUSHER raii( frame, originalEvent );
2509
2510 m_toolMgr->RunAction( ACTIONS::selectionClear );
2511 Activate();
2512
2513 controls->ShowCursor( true );
2514 controls->ForceCursorPosition( false );
2515
2516 m_router->SetMode( mode );
2517 m_cancelled = false;
2518
2519 if( aEvent.HasPosition() )
2520 m_toolMgr->PrimeTool( aEvent.Position() );
2521
2522 bool pickingStartPoint = true;
2523
2525
2526 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Catch any visibility
2527 // changes while routing.
2528 m_toolMgr->GetView()->SyncLayerVisibilityCache();
2529
2530 PNS::ITEM_SET trackItems;
2531
2532 for( EDA_ITEM* item : curSelection.GetItemsSortedBySelectionOrder() )
2533 {
2534 if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
2535 {
2536 auto bitem = static_cast<BOARD_CONNECTED_ITEM*>( item );
2537 PNS::ITEM* ritem = m_router->GetWorld()->FindItemByParent( bitem );
2538 if( ritem )
2539 trackItems.Add( ritem );
2540 }
2541 }
2542
2543 if( trackItems.Empty() )
2544 {
2545 frame->ShowInfoBarError( _( "Please select a group of tracks you want to spread." ) );
2546 return 0;
2547 }
2548 frame->ShowInfoBarMsg( _( "Pick a track you want to spread other tracks around." ) );
2549
2550 // Main loop: keep receiving events
2551 while( TOOL_EVENT* evt = Wait() )
2552 {
2553 if( evt->IsCancelInteractive() )
2554 {
2555 m_cancelled = true;
2556 break;
2557 }
2558 else if( evt->IsActivate() )
2559 {
2560 if( evt->IsMoveTool() || evt->IsEditorTool() )
2561 {
2562 // Make sure we come back after the move tool runs
2563 frame->PushTool( originalEvent );
2564 }
2565
2566 break;
2567 }
2568 else if( evt->Action() == TA_UNDO_REDO_PRE )
2569 {
2570 m_router->ClearWorld();
2571 }
2572 else if( evt->Action() == TA_UNDO_REDO_POST || evt->Action() == TA_MODEL_CHANGE )
2573 {
2574 m_router->SyncWorld();
2575 }
2576 else if( evt->IsMotion() )
2577 {
2578 if( pickingStartPoint )
2579 {
2580 updateStartItem( *evt );
2581 }
2582 else
2583 {
2584 updateEndItem( *evt );
2585 m_router->Move( m_endSnapPoint, nullptr );
2586 }
2587 }
2588 else if( evt->IsClick( BUT_LEFT ) )
2589 {
2590 if( !pickingStartPoint )
2591 {
2592 m_router->FixRoute( evt->Position(), nullptr, true, true );
2593 break;
2594 }
2595 else if( m_startItem )
2596 {
2597 pickingStartPoint = false;
2598
2599 frame->GetInfoBar()->Dismiss();
2600 if( !m_router->StartRouting( m_startSnapPoint, m_startItem, m_startItem->Layer(), trackItems ) )
2601 {
2602 m_cancelled = true;
2603 break;
2604 }
2605 }
2606 }
2607 else if( evt->IsClick( BUT_RIGHT ) )
2608 {
2609 m_menu->ShowContextMenu( selection() );
2610 }
2611 else if( evt->IsAction( &ACT_SpreadTracksSetDistance ) )
2612 {
2614 }
2615 else if( evt->IsAction( &ACT_IncreaseSpreadingDistance ) )
2616 {
2617 onSpreadTracksIncDecDistance( *evt, true );
2618 }
2619 else if( evt->IsAction( &ACT_DecreaseSpreadingDistance ) )
2620 {
2621 onSpreadTracksIncDecDistance( *evt, false );
2622 }
2623 else
2624 {
2625 evt->SetPassEvent();
2626 }
2627
2628 handleCommonEvents( *evt );
2629
2630 if( m_cancelled )
2631 break;
2632 }
2633
2634 /*
2635 m_router->ClearViewDecorations();
2636
2637 view()->ClearPreview();
2638 view()->ShowPreview( false );
2639 */
2640
2641 frame->GetInfoBar()->Dismiss();
2642
2643 if( m_cancelled )
2644 {
2645 restoreSelection( curSelection );
2646 }
2647 else
2648 {
2649 m_router->CommitRouting();
2650 }
2651
2652 if( m_router->RoutingInProgress() )
2653 m_router->StopRouting();
2654
2655 m_startItem = nullptr;
2656
2657 controls->ForceCursorPosition( false );
2658 highlightNets( false );
2659
2660 return 0;
2661}
2662
2663
2665{
2666 if( m_inRouterTool )
2667 return 0;
2668
2670
2674
2675 if( m_router->RoutingInProgress() )
2676 {
2677 if( m_router->Mode() == mode )
2678 return 0;
2679 else
2680 m_router->StopRouting();
2681 }
2682
2683 // Deselect all items
2684 m_toolMgr->RunAction( ACTIONS::selectionClear );
2685
2686 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
2687 SCOPED_TOOL_PUSHER raii( frame, originalEvent );
2688
2689 auto setCursor =
2690 [&]()
2691 {
2692 frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
2693 };
2694
2695 Activate();
2696 // Must be done after Activate() so that it gets set into the correct context
2697 controls->ShowCursor( true );
2698 controls->ForceCursorPosition( false );
2699 // Set initial cursor
2700 setCursor();
2701
2702 m_router->SetMode( mode );
2703 m_cancelled = false;
2704
2705 if( aEvent.HasPosition() )
2706 m_toolMgr->PrimeTool( aEvent.Position() );
2707
2708 // Main loop: keep receiving events
2709 while( TOOL_EVENT* evt = Wait() )
2710 {
2711 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Catch any visibility
2712 // changes while routing.
2713 m_toolMgr->GetView()->SyncLayerVisibilityCache();
2714
2715 if( !evt->IsDrag() )
2716 setCursor();
2717
2718 if( evt->IsCancelInteractive() )
2719 {
2720 break;
2721 }
2722 else if( evt->IsActivate() )
2723 {
2724 if( evt->IsMoveTool() || evt->IsEditorTool() )
2725 {
2726 // Make sure we come back after the move tool runs
2727 frame->PushTool( originalEvent );
2728 }
2729
2730 break;
2731 }
2732 else if( evt->Action() == TA_UNDO_REDO_PRE )
2733 {
2734 m_router->ClearWorld();
2735 }
2736 else if( evt->Action() == TA_UNDO_REDO_POST || evt->Action() == TA_MODEL_CHANGE )
2737 {
2738 m_router->SyncWorld();
2739 }
2740 else if( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) )
2741 {
2742 updateStartItem( *evt );
2743 }
2744 else if( evt->IsAction( &PCB_ACTIONS::dragFreeAngle ) )
2745 {
2746 updateStartItem( *evt, true );
2748 }
2749 else if( evt->IsAction( &PCB_ACTIONS::drag45Degree ) )
2750 {
2751 updateStartItem( *evt, true );
2753 }
2754 else if( evt->IsAction( &PCB_ACTIONS::breakTrack ) )
2755 {
2756 updateStartItem( *evt, true );
2757 breakTrack( );
2758 evt->SetPassEvent( false );
2759 }
2760 else if( evt->IsClick( BUT_LEFT )
2761 || evt->IsAction( &ACTIONS::cursorClick )
2762 || evt->IsAction( &PCB_ACTIONS::routeSingleTrack )
2763 || evt->IsAction( &PCB_ACTIONS::routeDiffPair ) )
2764 {
2765 updateStartItem( *evt );
2766
2767 if( evt->HasPosition() )
2768 performRouting( evt->Position() );
2769 }
2770 else if( evt->IsAction( &ACT_PlaceThroughVia ) )
2771 {
2772 m_toolMgr->RunAction( PCB_ACTIONS::layerToggle );
2773 }
2774 else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) )
2775 {
2776 m_router->SwitchLayer( m_iface->GetPNSLayerFromBoardLayer( frame->GetActiveLayer() ) );
2777 updateStartItem( *evt );
2778 updateSizesAfterRouterEvent( m_iface->GetPNSLayerFromBoardLayer( frame->GetActiveLayer() ), m_startSnapPoint );
2779 }
2780 else if( evt->IsKeyPressed() )
2781 {
2782 // wxWidgets fails to correctly translate shifted keycodes on the wxEVT_CHAR_HOOK
2783 // event so we need to process the wxEVT_CHAR event that will follow as long as we
2784 // pass the event.
2785 evt->SetPassEvent();
2786 }
2787 else if( evt->IsClick( BUT_RIGHT ) )
2788 {
2789 m_menu->ShowContextMenu( selection() );
2790 }
2791 else
2792 {
2793 evt->SetPassEvent();
2794 }
2795
2796 if( m_cancelled )
2797 break;
2798 }
2799
2800 // Store routing settings till the next invocation
2801 m_savedSizes = m_router->Sizes();
2802 m_router->ClearViewDecorations();
2803
2804 return 0;
2805}
2806
2807
2809{
2810 m_router->ClearViewDecorations();
2811
2812 view()->ClearPreview();
2813 view()->InitPreview();
2814
2816
2817 if( m_startItem && m_startItem->IsLocked() )
2818 {
2819 KIDIALOG dlg( frame(), _( "The selected item is locked." ), _( "Confirmation" ),
2820 wxOK | wxCANCEL | wxICON_WARNING );
2821 dlg.SetOKLabel( _( "Drag Anyway" ) );
2822 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
2823
2824 if( dlg.ShowModal() == wxID_CANCEL )
2825 return;
2826 }
2827
2828 bool dragStarted = m_router->StartDragging( m_startSnapPoint, m_startItem, aMode );
2829
2830 if( !dragStarted )
2831 {
2832 if( !m_router->FailureReason().IsEmpty() )
2833 frame()->ShowInfoBarError( m_router->FailureReason(), true );
2834
2835 return;
2836 }
2837
2838 if( m_startItem && m_startItem->Net() )
2839 highlightNets( true, { m_startItem->Net() } );
2840
2841 ctls->SetAutoPan( true );
2842 m_gridHelper->SetAuxAxes( true, m_startSnapPoint );
2843 frame()->UndoRedoBlock( true );
2844
2845 UI_UPDATE_INTERVAL_GUARD uiGuard( 200 );
2846
2847 while( TOOL_EVENT* evt = Wait() )
2848 {
2849 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Catch any visibility
2850 // changes while dragging.
2851 m_toolMgr->GetView()->SyncLayerVisibilityCache();
2852
2853 ctls->ForceCursorPosition( false );
2854
2855 if( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) )
2856 {
2857 updateEndItem( *evt );
2859
2860 if( PNS::DRAG_ALGO* dragger = m_router->GetDragger() )
2861 {
2862 bool dragStatus;
2863
2864 if( dragger->GetForceMarkObstaclesMode( &dragStatus ) )
2865 {
2866 view()->ClearPreview();
2867
2868 if( !dragStatus )
2869 {
2870 wxString hint;
2871 hint.Printf( _( "(%s to commit anyway.)" ),
2873
2875 statusItem->SetMessage( _( "Track violates DRC." ) );
2876 statusItem->SetHint( hint );
2877 statusItem->SetPosition( frame()->GetToolManager()->GetMousePosition() );
2878 view()->AddToPreview( statusItem );
2879 }
2880 }
2881 }
2882 }
2883 else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::cursorClick ) )
2884 {
2885 bool forceFinish = false;
2886 bool forceCommit = evt->Modifier( MD_CTRL );
2887
2888 if( m_router->FixRoute( m_endSnapPoint, m_endItem, forceFinish, forceCommit ) )
2889 break;
2890 }
2891 else if( evt->IsClick( BUT_RIGHT ) )
2892 {
2893 m_menu->ShowContextMenu( selection() );
2894 }
2895 else if( evt->IsCancelInteractive() || evt->IsAction( &PCB_ACTIONS::cancelCurrentItem )
2896 || evt->IsActivate() )
2897 {
2898 if( evt->IsCancelInteractive() && !m_startItem )
2899 m_cancelled = true;
2900
2901 if( evt->IsActivate() && !evt->IsMoveTool() )
2902 m_cancelled = true;
2903
2904 break;
2905 }
2906 else if( evt->IsUndoRedo() )
2907 {
2908 // We're in an UndoRedoBlock. If we get here, something's broken.
2909 wxFAIL;
2910 break;
2911 }
2912 else if( evt->Category() == TC_COMMAND )
2913 {
2914 // TODO: It'd be nice to be able to say "don't allow any non-trivial editing actions",
2915 // but we don't at present have that, so we just knock out some of the egregious ones.
2916 if( evt->IsAction( &ACTIONS::cut )
2917 || evt->IsAction( &ACTIONS::copy )
2918 || evt->IsAction( &ACTIONS::paste )
2919 || evt->IsAction( &ACTIONS::pasteSpecial )
2921 {
2922 wxBell();
2923 }
2924 // treat an undo as an escape
2925 else if( evt->IsAction( &ACTIONS::undo ) )
2926 {
2927 if( m_startItem )
2928 break;
2929 else
2930 wxBell();
2931 }
2932 else
2933 {
2934 evt->SetPassEvent();
2935 }
2936 }
2937 else
2938 {
2939 evt->SetPassEvent();
2940 }
2941
2942 handleCommonEvents( *evt );
2943 }
2944
2945 view()->ClearPreview();
2946 view()->ShowPreview( false );
2947
2948 if( m_router->RoutingInProgress() )
2949 m_router->StopRouting();
2950
2951 m_startItem = nullptr;
2952
2953 m_gridHelper->SetAuxAxes( false );
2954 frame()->UndoRedoBlock( false );
2955 ctls->SetAutoPan( false );
2956 ctls->ForceCursorPosition( false );
2957 highlightNets( false );
2958}
2959
2960
2962 PCB_SELECTION_TOOL* aSelTool )
2963{
2964 /*
2965 * If the collection contains a trivial line corner (two connected segments)
2966 * or a non-fanout-via (a via with no more than two connected segments), then
2967 * trim the collection down to a single item (which one won't matter since
2968 * they're all connected).
2969 */
2970
2971 // First make sure we've got something that *might* match.
2972 int vias = aCollector.CountType( PCB_VIA_T );
2973 int traces = aCollector.CountType( PCB_TRACE_T );
2974 int arcs = aCollector.CountType( PCB_ARC_T );
2975
2976 // We eliminate arcs because they are not supported in the inline drag code.
2977 if( arcs > 0 )
2978 return;
2979
2980 // We need to have at least 1 via or track
2981 if( vias + traces == 0 )
2982 return;
2983
2984 // We cannot drag more than one via at a time
2985 if( vias > 1 )
2986 return;
2987
2988 // We cannot drag more than two track segments at a time
2989 if( traces > 2 )
2990 return;
2991
2992 // Fetch first PCB_TRACK (via or trace) as our reference
2993 PCB_TRACK* reference = nullptr;
2994
2995 for( int i = 0; !reference && i < aCollector.GetCount(); i++ )
2996 reference = dynamic_cast<PCB_TRACK*>( aCollector[i] );
2997
2998 // This should never happen, but just in case...
2999 if( !reference )
3000 return;
3001
3002 int refNet = reference->GetNetCode();
3003
3004 VECTOR2I refPoint( aPt.x, aPt.y );
3005 EDA_ITEM_FLAGS flags = reference->IsPointOnEnds( refPoint, -1 );
3006
3007 if( flags & STARTPOINT )
3008 refPoint = reference->GetStart();
3009 else if( flags & ENDPOINT )
3010 refPoint = reference->GetEnd();
3011
3012 // Check all items to ensure that any TRACKs are co-terminus with the reference and on
3013 // the same net.
3014 for( int i = 0; i < aCollector.GetCount(); i++ )
3015 {
3016 PCB_TRACK* neighbor = dynamic_cast<PCB_TRACK*>( aCollector[i] );
3017
3018 if( neighbor && neighbor != reference )
3019 {
3020 if( neighbor->GetNetCode() != refNet )
3021 return;
3022
3023 if( neighbor->GetStart() != refPoint && neighbor->GetEnd() != refPoint )
3024 return;
3025 }
3026 }
3027
3028 // Selection meets criteria; trim it to the reference item.
3029 aCollector.Empty();
3030 aCollector.Append( reference );
3031}
3032
3033
3034// Which drag a multi-item selection gets. CanInlineDrag() and InlineDrag() both use this.
3035enum class DRAG_KIND
3036{
3037 INVALID, // something in it the router cannot drag
3038 FOOTPRINTS_KIND, // footprints only
3039 TRACKS_KIND, // tracks only
3040 BLOCK // copper, pads and footprints mixed
3041};
3042
3043
3044static DRAG_KIND dragKindOf( const PCB_SELECTION& aSelection )
3045{
3046 bool allFootprints = true;
3047 bool allTracks = true;
3048
3049 for( EDA_ITEM* item : aSelection )
3050 {
3051 switch( item->Type() )
3052 {
3053 case PCB_FOOTPRINT_T: allTracks = false; break;
3054
3055 case PCB_TRACE_T: allFootprints = false; break;
3056
3057 case PCB_ARC_T:
3058 case PCB_VIA_T:
3059 case PCB_PAD_T:
3060 allFootprints = false;
3061 allTracks = false;
3062 break;
3063
3064 default: return DRAG_KIND::INVALID;
3065 }
3066 }
3067
3068 if( allFootprints )
3070
3071 if( allTracks )
3073
3074 return DRAG_KIND::BLOCK;
3075}
3076
3077
3078bool ROUTER_TOOL::CanInlineDrag( int aDragMode )
3079{
3081 const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
3082
3083 if( selection.Size() == 1 )
3084 {
3085 return selection.Front()->IsType( GENERAL_COLLECTOR::DraggableItems ) || selection.Front()->Type() == PCB_PAD_T;
3086 }
3087
3088 switch( dragKindOf( selection ) )
3089 {
3090 case DRAG_KIND::TRACKS_KIND: return true;
3091
3092 // Neither footprints nor a block drag free angle
3094 case DRAG_KIND::BLOCK: return !( aDragMode & PNS::DM_FREE_ANGLE );
3095
3096 default: return false;
3097 }
3098}
3099
3100
3101void ROUTER_TOOL::restoreSelection( const PCB_SELECTION& aOriginalSelection )
3102{
3103 EDA_ITEMS selItems;
3104 std::copy( aOriginalSelection.Items().begin(), aOriginalSelection.Items().end(), std::back_inserter( selItems ) );
3105 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &selItems );
3106}
3107
3108
3110{
3111 const PCB_SELECTION selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
3112
3113 if( selection.Empty() )
3115
3116 if( selection.Empty() || !selection.Front()->IsBOARD_ITEM() )
3117 return 0;
3118
3119 // selection gets cleared in the next action, we need a copy of the selected items.
3120 std::deque<EDA_ITEM*> selectedItems = selection.GetItems();
3121
3122 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
3123
3124 if( item->Type() != PCB_TRACE_T && item->Type() != PCB_VIA_T && item->Type() != PCB_ARC_T
3125 && item->Type() != PCB_FOOTPRINT_T && item->Type() != PCB_PAD_T )
3126 {
3127 return 0;
3128 }
3129
3130 std::set<FOOTPRINT*> footprints;
3131 std::set<PAD*> freePads;
3132 bool blockDrag = false;
3133
3134 if( item->Type() == PCB_FOOTPRINT_T )
3135 footprints.insert( static_cast<FOOTPRINT*>( item ) );
3136
3137 if( selection.Size() > 1 )
3138 {
3139 for( int idx = 0; idx < selection.Size(); ++idx )
3140 {
3141 if( !selection.GetItem( idx )->IsBOARD_ITEM() )
3142 return 0;
3143
3144 BOARD_ITEM* selItem = static_cast<BOARD_ITEM*>( selection.GetItem( idx ) );
3145
3146 if( selItem->Type() == PCB_FOOTPRINT_T )
3147 footprints.insert( static_cast<FOOTPRINT*>( selItem ) );
3148 }
3149
3150 DRAG_KIND kind = dragKindOf( selection );
3151
3152 if( kind == DRAG_KIND::INVALID )
3153 {
3154 // Refuse if a footprint led the selection, otherwise drop the footprints
3155 if( item->Type() == PCB_FOOTPRINT_T )
3156 {
3157 frame()->ShowInfoBarMsg( _( "The selection contains items that cannot be dragged." ) );
3158 return 0;
3159 }
3160
3161 footprints.clear();
3162 }
3163
3164 blockDrag = kind == DRAG_KIND::BLOCK;
3165 }
3166
3167 // If we overrode locks, we want to clear the flag from the source item before SyncWorld is
3168 // called so that virtual vias are not generated for the (now unlocked) track segment. Note in
3169 // this case the lock can't be reliably re-applied, because there is no guarantee that the end
3170 // state of the drag results in the same number of segments so it's not clear which segment to
3171 // apply the lock state to.
3172 //
3173 // A block drag leaves locks alone. The dragger exempts selected copper itself.
3174 bool wasLocked = false;
3175
3176 if( !blockDrag && item->Type() != PCB_PAD_T && item->IsLocked() )
3177 {
3178 wasLocked = true;
3179 item->SetLocked( false );
3180 }
3181
3182 m_toolMgr->RunAction( ACTIONS::selectionClear );
3183
3184 SCOPED_TOOL_PUSHER raii( frame(), aEvent );
3185 Activate();
3186
3187 m_startItem = nullptr;
3188
3189 PNS::ITEM_SET itemsToDrag;
3190
3191 bool showCourtyardConflicts = frame()->GetPcbNewSettings()->m_ShowCourtyardCollisions;
3192
3193 std::shared_ptr<DRC_ENGINE> drcEngine = m_toolMgr->GetTool<DRC_TOOL>()->GetDRCEngine();
3194 DRC_INTERACTIVE_COURTYARD_CLEARANCE courtyardClearanceDRC( drcEngine );
3195
3196 std::shared_ptr<CONNECTIVITY_DATA> connectivityData = board()->GetConnectivity();
3197 std::vector<BOARD_ITEM*> dynamicItems;
3198 std::unique_ptr<CONNECTIVITY_DATA> dynamicData = nullptr;
3199 VECTOR2I lastOffset;
3200 std::vector<PNS::ITEM*> leaderSegments;
3201 bool singleFootprintDrag = false;
3202
3203 // The PNS world may be stale if the board has been modified since the last sync (e.g. by
3204 // a Move operation). Sync it now so that FindItemByParent and joint lookups work correctly.
3205 m_router->SyncWorld();
3206
3207 // A footprint with no copper the router can see cannot be dragged, and showing it in the
3208 // preview would promise a move the commit will not make
3209 for( auto it = footprints.begin(); it != footprints.end(); )
3210 {
3211 bool hasSolid = false;
3212
3213 for( PAD* pad : ( *it )->Pads() )
3214 hasSolid |= !m_router->GetWorld()->FindItemsByParent( pad ).empty();
3215
3216 it = hasSolid ? std::next( it ) : footprints.erase( it );
3217 }
3218
3219 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Make sure it's up-to-date.
3220 m_toolMgr->GetView()->SyncLayerVisibilityCache();
3221
3222 if( !footprints.empty() )
3223 {
3224 // A block drag has its own algorithm, and the leader logic below assumes a lone footprint
3225 if( footprints.size() == 1 && !blockDrag )
3226 singleFootprintDrag = true;
3227
3228 if( showCourtyardConflicts )
3229 courtyardClearanceDRC.Init( board() );
3230
3231 for( FOOTPRINT* footprint : footprints )
3232 {
3233 for( PAD* pad : footprint->Pads() )
3234 {
3235 // A padstack with per-layer geometry is more than one router solid
3236 for( PNS::ITEM* solid : m_router->GetWorld()->FindItemsByParent( pad ) )
3237 itemsToDrag.Add( solid );
3238
3239 if( pad->GetLocalRatsnestVisible() || displayOptions().m_ShowModuleRatsnest )
3240 {
3241 if( connectivityData->GetRatsnestForPad( pad ).size() > 0 )
3242 dynamicItems.push_back( pad );
3243 }
3244 }
3245
3246 for( ZONE* zone : footprint->Zones() )
3247 {
3248 for( PNS::ITEM* solid : m_router->GetWorld()->FindItemsByParent( zone ) )
3249 itemsToDrag.Add( solid );
3250 }
3251
3252 for( BOARD_ITEM* shape : footprint->GraphicalItems() )
3253 {
3254 if( shape->GetLayer() == Edge_Cuts
3255 || shape->GetLayer() == Margin
3256 || IsCopperLayer( shape->GetLayer() ) )
3257 {
3258 for( PNS::ITEM* solid : m_router->GetWorld()->FindItemsByParent( shape ) )
3259 itemsToDrag.Add( solid );
3260 }
3261 }
3262
3263 if( showCourtyardConflicts )
3264 courtyardClearanceDRC.m_FpInMove.push_back( footprint );
3265 }
3266
3267 dynamicData = std::make_unique<CONNECTIVITY_DATA>( board()->GetConnectivity(), dynamicItems, true );
3268 connectivityData->BlockRatsnestItems( dynamicItems );
3269 }
3270
3271 if( footprints.empty() || blockDrag )
3272 {
3273 for( EDA_ITEM* selItem : selectedItems )
3274 {
3275 if( !selItem->IsBOARD_ITEM() )
3276 continue;
3277
3278 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( selItem );
3279 PNS::ITEM* pnsItem = m_router->GetWorld()->FindItemByParent( boardItem );
3280
3281 if( !pnsItem )
3282 continue;
3283
3284 if( pnsItem->OfKind( PNS::ITEM::SEGMENT_T )
3285 || pnsItem->OfKind( PNS::ITEM::VIA_T )
3286 || pnsItem->OfKind( PNS::ITEM::ARC_T ) )
3287 {
3288 itemsToDrag.Add( pnsItem );
3289 }
3290 else if( boardItem->Type() == PCB_PAD_T )
3291 {
3292 PAD* pad = static_cast<PAD*>( boardItem );
3293
3294 // A pad selected together with its footprint already travels with it
3295 if( footprints.count( pad->GetParentFootprint() ) )
3296 continue;
3297
3298 freePads.insert( pad );
3299
3300 // A padstack with per-layer geometry is more than one router solid
3301 for( PNS::ITEM* solid : m_router->GetWorld()->FindItemsByParent( pad ) )
3302 itemsToDrag.Add( solid );
3303 }
3304 }
3305 }
3306
3307 GAL* gal = m_toolMgr->GetView()->GetGAL();
3308 VECTOR2I p0 = GetClampedCoords( controls()->GetCursorPosition( false ), COORDS_PADDING );
3309 VECTOR2I p = p0;
3310
3311 m_gridHelper->SetUseGrid( gal->GetGridSnapping() && !aEvent.DisableGridSnapping() );
3312 m_gridHelper->SetSnap( !aEvent.Modifier( MD_SHIFT ) );
3313
3314 if( itemsToDrag.Count() >= 1 )
3315 {
3316 // Snap to closest item. Use the frame's active layer rather than m_originalActiveLayer,
3317 // which is only set during prepareInteractive() and remains UNDEFINED_LAYER for inline
3318 // drag operations.
3319 PCB_LAYER_ID activeLayer = frame()->GetActiveLayer();
3320 int layer = m_iface->GetPNSLayerFromBoardLayer( activeLayer );
3321 PNS::ITEM* closestItem = nullptr;
3322 SEG::ecoord closestDistSq = std::numeric_limits<SEG::ecoord>::max();
3323
3324 for( PNS::ITEM* pitem : itemsToDrag.Items() )
3325 {
3326 const SHAPE* shape = pitem->Shape( layer );
3327
3328 if( !shape )
3329 continue;
3330
3331 SEG::ecoord distSq = shape->SquaredDistance( p0, 0 );
3332
3333 if( distSq < closestDistSq )
3334 {
3335 closestDistSq = distSq;
3336 closestItem = pitem;
3337 }
3338 }
3339
3340 if( closestItem )
3341 {
3342 p = snapToItem( closestItem, p0 );
3343
3344 m_startItem = closestItem;
3345
3346 if( closestItem->Net() )
3347 highlightNets( true, { closestItem->Net() } );
3348 }
3349 }
3350
3351 if( !footprints.empty() && singleFootprintDrag )
3352 {
3353 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
3354
3355 // The mouse is going to be moved on grid before dragging begins.
3356 VECTOR2I tweakedMousePos;
3358
3359 // Check if user wants to warp the mouse to origin of moved object
3360
3361 if( editFrame->GetMoveWarpsCursor() )
3362 tweakedMousePos = footprint->GetPosition(); // Use footprint anchor to warp mouse
3363 else
3364 tweakedMousePos = GetClampedCoords( controls()->GetCursorPosition(),
3365 COORDS_PADDING ); // Just use current mouse pos
3366
3367 // We tweak the mouse position using the value from above, and then use that as the
3368 // start position to prevent the footprint from jumping when we start dragging.
3369 // First we move the visual cross hair cursor...
3370 controls()->ForceCursorPosition( true, tweakedMousePos );
3371 controls()->SetCursorPosition( tweakedMousePos ); // ...then the mouse pointer
3372
3373 // Now that the mouse is in the right position, get a copy of the position to use later
3374 p = controls()->GetCursorPosition();
3375 }
3376
3377 int dragMode = aEvent.Parameter<int> ();
3378
3379 if( !footprints.empty() || !freePads.empty() || blockDrag )
3380 dragMode &= ~PNS::DM_FREE_ANGLE;
3381
3382 if( blockDrag )
3383 dragMode |= PNS::DM_BLOCK;
3384
3385 m_iface->SetIndependentPads( freePads );
3386
3387 bool dragStarted = m_router->StartDragging( p, itemsToDrag, dragMode );
3388
3389 if( !dragStarted )
3390 {
3391 m_iface->SetIndependentPads( {} );
3392
3393 if( blockDrag )
3394 frame()->ShowInfoBarMsg( _( "Nothing in the selection can be dragged." ) );
3395
3396 if( wasLocked )
3397 item->SetLocked( true );
3398
3399 if( !footprints.empty() )
3400 connectivityData->ClearLocalRatsnest();
3401
3402 // Clear temporary COURTYARD_CONFLICT flag and ensure the conflict shadow is cleared
3403 courtyardClearanceDRC.ClearConflicts( getView() );
3404
3406 controls()->ForceCursorPosition( false );
3407 highlightNets( false );
3408 return 0;
3409 }
3410
3411 m_gridHelper->SetAuxAxes( true, p );
3412 controls()->ShowCursor( true );
3413 controls()->SetAutoPan( true );
3414 frame()->UndoRedoBlock( true );
3415
3416 if( auto* blockDragger = dynamic_cast<PNS::BLOCK_DRAGGER*>( m_router->GetDragger() ) )
3417 {
3418 size_t held = blockDragger->AnchoredLines().size();
3419
3420 if( held > 0 )
3421 {
3422 frame()->ShowInfoBarWarning(
3423 wxString::Format( wxPLURAL( "%zu selected arc cannot move because both ends are fixed.",
3424 "%zu selected arcs cannot move because both ends are fixed.", held ),
3425 held ) );
3426 }
3427 }
3428
3429 view()->ClearPreview();
3430 view()->InitPreview();
3431
3432 auto setCursor =
3433 [&]()
3434 {
3435 frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
3436 };
3437
3438 // Set initial cursor
3439 setCursor();
3440
3441 // Set the initial visible area
3442 BOX2D viewAreaD = getView()->GetGAL()->GetVisibleWorldExtents();
3443 m_router->SetVisibleViewArea( BOX2ISafe( viewAreaD ) );
3444
3445 // Send an initial movement to prime the collision detection
3446 m_router->Move( p, nullptr );
3447
3448 UI_UPDATE_INTERVAL_GUARD uiGuard( 200 );
3449
3450 bool hasMouseMoved = false;
3451 bool hasMultidragCancelled = false;
3452
3453 while( TOOL_EVENT* evt = Wait() )
3454 {
3455 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Catch any visibility
3456 // changes while dragging.
3457 m_toolMgr->GetView()->SyncLayerVisibilityCache();
3458
3459 setCursor();
3460
3461 if( evt->IsCancelInteractive()
3462 || evt->IsAction( &PCB_ACTIONS::cancelCurrentItem )
3463 || evt->IsActivate() )
3464 {
3465 if( wasLocked )
3466 item->SetLocked( true );
3467
3468 hasMultidragCancelled = true;
3469
3470 break;
3471 }
3472 else if( evt->IsMotion()
3473 || evt->IsAction( &ACTIONS::refreshPreview )
3474 || evt->IsDrag( BUT_LEFT ) )
3475 {
3476 hasMouseMoved = true;
3477 updateEndItem( *evt );
3479
3480 view()->ClearPreview();
3481
3482 if( !footprints.empty() )
3483 {
3484 VECTOR2I offset = m_endSnapPoint - p;
3485 BOARD_ITEM* previewItem;
3486
3487 for( FOOTPRINT* footprint : footprints )
3488 {
3489 for( BOARD_ITEM* drawing : footprint->GraphicalItems() )
3490 {
3491 previewItem = static_cast<BOARD_ITEM*>( drawing->Clone() );
3492 previewItem->Move( offset );
3493
3494 view()->AddToPreview( previewItem );
3495 view()->Hide( drawing, true );
3496 }
3497
3498 for( PAD* pad : footprint->Pads() )
3499 {
3500 if( ( pad->GetLayerSet() & LSET::AllCuMask() ).none()
3501 && pad->GetDrillSize().x == 0 )
3502 {
3503 previewItem = static_cast<BOARD_ITEM*>( pad->Clone() );
3504 previewItem->Move( offset );
3505
3506 view()->AddToPreview( previewItem );
3507 }
3508 else
3509 {
3510 // Pads with copper or holes are handled by the router
3511 }
3512
3513 view()->Hide( pad, true );
3514 }
3515
3516 previewItem = static_cast<BOARD_ITEM*>( footprint->Reference().Clone() );
3517 previewItem->Move( offset );
3518 view()->AddToPreview( previewItem );
3519 view()->Hide( &footprint->Reference() );
3520
3521 previewItem = static_cast<BOARD_ITEM*>( footprint->Value().Clone() );
3522 previewItem->Move( offset );
3523 view()->AddToPreview( previewItem );
3524 view()->Hide( &footprint->Value() );
3525
3526 if( showCourtyardConflicts )
3527 footprint->Move( offset );
3528 }
3529
3530 if( showCourtyardConflicts )
3531 {
3532 courtyardClearanceDRC.Run();
3533 courtyardClearanceDRC.UpdateConflicts( getView(), false );
3534
3535 for( FOOTPRINT* footprint : footprints )
3536 footprint->Move( -offset );
3537 }
3538
3539 // Update ratsnest
3540 dynamicData->Move( offset - lastOffset );
3541 lastOffset = offset;
3542 connectivityData->ComputeLocalRatsnest( dynamicItems, dynamicData.get(), offset );
3543 }
3544
3545 for( PAD* pad : freePads )
3546 view()->Hide( pad, true );
3547
3548 if( PNS::DRAG_ALGO* dragger = m_router->GetDragger() )
3549 {
3550 bool dragStatus;
3551
3552 if( dragger->GetForceMarkObstaclesMode( &dragStatus ) )
3553 {
3554 if( !dragStatus )
3555 {
3556 wxString hint;
3557 hint.Printf( _( "(%s to commit anyway.)" ), KeyNameFromKeyCode( MD_CTRL + PSEUDO_WXK_CLICK ) );
3558
3560 statusItem->SetMessage( _( "Track violates DRC." ) );
3561 statusItem->SetHint( hint );
3562 statusItem->SetPosition( frame()->GetToolManager()->GetMousePosition() );
3563 view()->AddToPreview( statusItem );
3564 }
3565 }
3566 }
3567 }
3568 else if( hasMouseMoved && ( evt->IsMouseUp( BUT_LEFT )
3569 || evt->IsClick( BUT_LEFT )
3570 || evt->IsAction( &ACTIONS::cursorClick ) ) )
3571 {
3572 bool forceFinish = false;
3573 bool forceCommit = evt->Modifier( MD_CTRL );
3574
3575 updateEndItem( *evt );
3576 m_router->FixRoute( m_endSnapPoint, m_endItem, forceFinish, forceCommit );
3577 leaderSegments = m_router->GetLastCommittedLeaderSegments();
3578
3579 break;
3580 }
3581 else if( evt->IsUndoRedo() )
3582 {
3583 // We're in an UndoRedoBlock. If we get here, something's broken.
3584 wxFAIL;
3585 break;
3586 }
3587 else if( evt->Category() == TC_COMMAND )
3588 {
3589 // TODO: It'd be nice to be able to say "don't allow any non-trivial editing actions",
3590 // but we don't at present have that, so we just knock out some of the egregious ones.
3591 if( evt->IsAction( &ACTIONS::cut )
3592 || evt->IsAction( &ACTIONS::copy )
3593 || evt->IsAction( &ACTIONS::paste )
3594 || evt->IsAction( &ACTIONS::pasteSpecial )
3596 {
3597 wxBell();
3598 }
3599 // treat an undo as an escape
3600 else if( evt->IsAction( &ACTIONS::undo ) )
3601 {
3602 if( wasLocked )
3603 item->SetLocked( true );
3604
3605 break;
3606 }
3607 else
3608 {
3609 evt->SetPassEvent();
3610 }
3611 }
3612 else
3613 {
3614 evt->SetPassEvent();
3615 }
3616
3617 handleCommonEvents( *evt );
3618 }
3619
3620 if( !footprints.empty() )
3621 {
3622 for( FOOTPRINT* footprint : footprints )
3623 {
3624 for( BOARD_ITEM* drawing : footprint->GraphicalItems() )
3625 view()->Hide( drawing, false );
3626
3627 view()->Hide( &footprint->Reference(), false );
3628 view()->Hide( &footprint->Value(), false );
3629
3630 for( PAD* pad : footprint->Pads() )
3631 view()->Hide( pad, false );
3632 }
3633
3634 view()->ClearPreview();
3635 view()->ShowPreview( false );
3636
3637 connectivityData->ClearLocalRatsnest();
3638 }
3639
3640 for( PAD* pad : freePads )
3641 view()->Hide( pad, false );
3642
3643 m_iface->SetIndependentPads( {} );
3644
3645 // Clear temporary COURTYARD_CONFLICT flag and ensure the conflict shadow is cleared
3646 courtyardClearanceDRC.ClearConflicts( getView() );
3647
3648 if( m_router->RoutingInProgress() )
3649 m_router->StopRouting();
3650
3651
3652 if( itemsToDrag.Size() && hasMultidragCancelled )
3653 {
3655 }
3656 else if( leaderSegments.size() )
3657 {
3658 std::vector<EDA_ITEM*> newItems;
3659
3660 for( PNS::ITEM* lseg : leaderSegments )
3661 newItems.push_back( lseg->Parent() );
3662
3663 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &newItems );
3664 }
3665
3666 m_gridHelper->SetAuxAxes( false );
3667 controls()->SetAutoPan( false );
3668 controls()->ForceCursorPosition( false );
3669 frame()->UndoRedoBlock( false );
3670 highlightNets( false );
3671 view()->ClearPreview();
3672 view()->ShowPreview( false );
3673
3674 return 0;
3675}
3676
3677
3679{
3680 const SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
3681
3682 if( selection.Size() != 1 )
3683 return 0;
3684
3685 const BOARD_CONNECTED_ITEM* item = static_cast<const BOARD_CONNECTED_ITEM*>( selection.Front() );
3686
3687 if( item->Type() != PCB_TRACE_T && item->Type() != PCB_ARC_T )
3688 return 0;
3689
3690 Activate();
3691
3692 // Snapping uses ViewGetLOD(), which uses the layerVisibilityCache. Make sure it's up-to-date.
3693 m_toolMgr->GetView()->SyncLayerVisibilityCache();
3694
3695 m_startItem = m_router->GetWorld()->FindItemByParent( item );
3696
3697 TOOL_MANAGER* toolManager = frame()->GetToolManager();
3698 GAL* gal = toolManager->GetView()->GetGAL();
3699
3700 m_gridHelper->SetUseGrid( gal->GetGridSnapping() && !aEvent.DisableGridSnapping() );
3701 m_gridHelper->SetSnap( !aEvent.Modifier( MD_SHIFT ) );
3702
3703 controls()->ForceCursorPosition( false );
3704
3705 if( toolManager->IsContextMenuActive() )
3706 {
3707 // If we're here from a context menu then we need to get the position of the
3708 // cursor when the context menu was invoked. This is used to figure out the
3709 // break point on the track.
3711 }
3712 else
3713 {
3714 // If we're here from a hotkey, then get the current mouse position so we know
3715 // where to break the track.
3716 m_startSnapPoint = snapToItem( m_startItem, controls()->GetCursorPosition() );
3717 }
3718
3719 if( m_startItem && m_startItem->IsLocked() )
3720 {
3721 KIDIALOG dlg( frame(), _( "The selected item is locked." ), _( "Confirmation" ),
3722 wxOK | wxCANCEL | wxICON_WARNING );
3723 dlg.SetOKLabel( _( "Break Track" ) );
3724 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
3725
3726 if( dlg.ShowModal() == wxID_CANCEL )
3727 return 0;
3728 }
3729
3730 m_toolMgr->RunAction( ACTIONS::selectionClear );
3731
3732 frame()->UndoRedoBlock( true );
3733 breakTrack();
3734
3735 if( m_router->RoutingInProgress() )
3736 m_router->StopRouting();
3737
3738 frame()->UndoRedoBlock( false );
3739
3740 return 0;
3741}
3742
3743
3745{
3747 DIALOG_TRACK_VIA_SIZE sizeDlg( frame(), bds );
3748
3749 if( sizeDlg.ShowModal() == wxID_OK )
3750 {
3751 bds.m_TempOverrideTrackWidth = true;
3752 bds.UseCustomTrackViaSize( true );
3753
3756 }
3757
3758 return 0;
3759}
3760
3761
3763{
3764 PNS::SIZES_SETTINGS sizes( m_router->Sizes() );
3765
3766 if( !m_router->GetCurrentNets().empty() )
3767 m_iface->ImportSizes( sizes, m_startItem, m_router->GetCurrentNets()[0], VECTOR2D() );
3768
3769 m_router->UpdateSizes( sizes );
3770
3771 // Changing the track width can affect the placement, so call the
3772 // move routine without changing the destination
3773 // Update end item first to avoid moving to an invalid/missing item
3774 updateEndItem( aEvent );
3776
3778
3779 return 0;
3780}
3781
3782
3784{
3785 std::vector<MSG_PANEL_ITEM> items;
3786
3787 if( m_router->GetState() == PNS::ROUTER::ROUTE_TRACK )
3788 {
3789 PNS::SIZES_SETTINGS sizes( m_router->Sizes() );
3790 PNS::RULE_RESOLVER* resolver = m_iface->GetRuleResolver();
3791 PNS::CONSTRAINT constraint;
3792 std::vector<PNS::NET_HANDLE> nets = m_router->GetCurrentNets();
3793 wxString description;
3794 wxString secondary;
3795 wxString mode;
3796
3798 {
3799 wxASSERT( nets.size() >= 2 );
3800
3801 NETINFO_ITEM* netA = static_cast<NETINFO_ITEM*>( nets[0] );
3802 NETINFO_ITEM* netB = static_cast<NETINFO_ITEM*>( nets[1] );
3803 wxASSERT( netA );
3804 wxASSERT( netB );
3805
3806 description = wxString::Format( _( "Routing Diff Pair: %s" ),
3807 netA->GetNetname() + wxT( ", " ) + netB->GetNetname() );
3808
3809 wxString netclass;
3810 NETCLASS* netclassA = netA->GetNetClass();
3811 NETCLASS* netclassB = netB->GetNetClass();
3812
3813 if( *netclassA == *netclassB )
3814 netclass = netclassA->GetHumanReadableName();
3815 else
3816 netclass = netclassA->GetHumanReadableName() + wxT( ", " )
3817 + netclassB->GetHumanReadableName();
3818
3819 secondary = wxString::Format( _( "Resolved Netclass: %s" ),
3820 UnescapeString( netclass ) );
3821 }
3822 else if( !nets.empty() && nets[0] )
3823 {
3824 NETINFO_ITEM* net = static_cast<NETINFO_ITEM*>( nets[0] );
3825
3826 description = wxString::Format( _( "Routing Track: %s" ),
3827 net->GetNetname() );
3828
3829 secondary = wxString::Format(
3830 _( "Resolved Netclass: %s" ),
3832 }
3833 else
3834 {
3835 description = _( "Routing Track" );
3836 secondary = _( "(no net)" );
3837 }
3838
3839 items.emplace_back( description, secondary );
3840
3841 wxString cornerMode;
3842
3843 if( m_router->Settings().GetFreeAngleMode() )
3844 {
3845 cornerMode = _( "Free-angle" );
3846 }
3847 else
3848 {
3849 switch( m_router->Settings().GetCornerMode() )
3850 {
3851 case DIRECTION_45::CORNER_MODE::MITERED_45: cornerMode = _( "45-degree" ); break;
3852 case DIRECTION_45::CORNER_MODE::ROUNDED_45: cornerMode = _( "45-degree rounded" ); break;
3853 case DIRECTION_45::CORNER_MODE::MITERED_90: cornerMode = _( "90-degree" ); break;
3854 case DIRECTION_45::CORNER_MODE::ROUNDED_90: cornerMode = _( "90-degree rounded" ); break;
3855 default: break;
3856 }
3857 }
3858
3859 items.emplace_back( _( "Corner Style" ), cornerMode );
3860
3861 switch( m_router->Settings().Mode() )
3862 {
3863 case PNS::PNS_MODE::RM_MarkObstacles: mode = _( "Highlight collisions" ); break;
3864 case PNS::PNS_MODE::RM_Walkaround: mode = _( "Walk around" ); break;
3865 case PNS::PNS_MODE::RM_Shove: mode = _( "Shove" ); break;
3866 default: break;
3867 }
3868
3869 items.emplace_back( _( "Mode" ), mode );
3870
3871#define FORMAT_VALUE( x ) frame()->MessageTextFromValue( x )
3872
3874 {
3875 items.emplace_back( wxString::Format( _( "Track Width: %s" ),
3876 FORMAT_VALUE( sizes.DiffPairWidth() ) ),
3877 wxString::Format( _( "(from %s)" ),
3878 sizes.GetDiffPairWidthSource() ) );
3879
3880 items.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
3881 FORMAT_VALUE( sizes.Clearance() ) ),
3882 wxString::Format( _( "(from %s)" ),
3883 sizes.GetClearanceSource() ) );
3884
3885 items.emplace_back( wxString::Format( _( "Diff Pair Gap: %s" ),
3886 FORMAT_VALUE( sizes.DiffPairGap() ) ),
3887 wxString::Format( _( "(from %s)" ),
3888 sizes.GetDiffPairGapSource() ) );
3889
3890 const PNS::ITEM_SET& traces = m_router->Placer()->Traces();
3891 wxASSERT( traces.Count() == 2 );
3892
3894 traces[1], m_router->GetCurrentLayer(), &constraint ) )
3895 {
3896 items.emplace_back( wxString::Format( _( "DP Max Uncoupled-length: %s" ),
3897 FORMAT_VALUE( constraint.m_Value.Max() ) ),
3898 wxString::Format( _( "(from %s)" ),
3899 constraint.m_RuleName ) );
3900 }
3901 }
3902 else
3903 {
3904 items.emplace_back( wxString::Format( _( "Track Width: %s" ),
3905 FORMAT_VALUE( sizes.TrackWidth() ) ),
3906 wxString::Format( _( "(from %s)" ),
3907 sizes.GetWidthSource() ) );
3908
3909 items.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
3910 FORMAT_VALUE( sizes.Clearance() ) ),
3911 wxString::Format( _( "(from %s)" ),
3912 sizes.GetClearanceSource() ) );
3913 }
3914
3915#undef FORMAT_VALUE
3916
3917 frame()->SetMsgPanel( items );
3918 }
3919 else
3920 {
3921 frame()->SetMsgPanel( board() );
3922 return;
3923 }
3924}
3925
3926
3928{
3930
3946
3954
3990
3993
3999}
std::function< void(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)> CLIENT_SELECTION_FILTER
Definition actions.h:33
@ add_via_stack
@ width_track_via
@ change_entry_orient
@ switch_corner_rounding_shape
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
Definition box2.h:924
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
static TOOL_ACTION paste
Definition actions.h:77
static TOOL_ACTION cancelInteractive
Definition actions.h:69
static TOOL_ACTION copy
Definition actions.h:75
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition actions.h:214
static TOOL_ACTION pasteSpecial
Definition actions.h:78
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 cut
Definition actions.h:74
static TOOL_ACTION refreshPreview
Definition actions.h:156
static TOOL_ACTION finishInteractive
Definition actions.h:70
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:229
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
void Clear()
Remove all the entries from the menu (as well as its title).
void SetTitle(const wxString &aTitle) override
Set title for the menu.
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetLayerVisible(int aLayer, bool isVisible)
Manually update visibility for a given layer.
BASE_SET & set(size_t pos)
Definition base_set.h:126
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,...
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
Container for design settings for a BOARD object.
void UseCustomTrackViaSize(bool aEnabled)
Enables/disables custom track/via size settings.
void SetCustomDiffPairWidth(int aWidth)
Sets custom track width for differential pairs (i.e.
void SetViaSizeIndex(int aIndex)
Set the current via size list index to aIndex.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
void SetCustomDiffPairGap(int aGap)
Sets custom gap for differential pairs (i.e.
bool UseNetClassVia() const
Return true if netclass values should be used to obtain appropriate via size.
bool UseNetClassTrack() const
Return true if netclass values should be used to obtain appropriate track width.
bool UseNetClassDiffPair() const
Return true if netclass values should be used to obtain appropriate diff pair dimensions.
void SetTrackWidthIndex(int aIndex)
Set the current track width list index to aIndex.
void UseCustomDiffPairDimensions(bool aEnabled)
Enables/disables custom differential pair dimensions.
std::vector< int > m_TrackWidthList
std::vector< VIA_STACK_PRESET > m_ViaStackPresets
std::vector< VIA_DIMENSION > m_ViasDimensionsList
void SetCustomDiffPairViaGap(int aGap)
Sets custom via gap for differential pairs (i.e.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
void SetLocked(bool aLocked) override
Definition board_item.h:441
bool IsLocked() const override
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:459
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
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition board.cpp:1208
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:758
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
void Empty()
Clear the list.
Definition collector.h:87
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
int CountType(KICAD_T aType)
Count the number of items matching aType.
Definition collector.h:221
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition collector.h:97
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a checked menu entry to run a TOOL_ACTION on selected items.
PNS::LOGGER::TEST_CASE_TYPE getTestCaseType() const
int ShowModal() override
Implementing DIALOG_TRACK_VIA_SIZE_BASE.
PCB_EDIT_FRAME & m_frame
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
DIFF_PAIR_MENU(PCB_EDIT_FRAME &aFrame)
void update() override
Update menu state stub.
CORNER_MODE
Corner modes.
Definition direction45.h:67
@ ROUNDED_90
H/V with filleted corners.
Definition direction45.h:71
@ MITERED_90
H/V only (90-degree corners)
Definition direction45.h:70
@ ROUNDED_45
H/V/45 with filleted corners.
Definition direction45.h:69
@ MITERED_45
H/V/45 with mitered corners (default)
Definition direction45.h:68
Tool responsible for drawing graphical elements like lines, arcs, circles, etc.
wxString GetName() const
Definition drc_rule.h:162
MINOPTMAX< int > m_Value
Definition drc_rule.h:206
bool IsNull() const
Definition drc_rule.h:122
DRC_CONSTRAINT EvalRules(DRC_CONSTRAINT_T aConstraintType, const BOARD_ITEM *a, const BOARD_ITEM *b, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
void UpdateConflicts(KIGFX::VIEW *aView, bool aHighlightMoved)
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=INFOBAR_MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
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
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
static const std::vector< KICAD_T > DraggableItems
A scan list for items that can be dragged.
Definition collectors.h:150
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:38
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:51
int ShowModal() override
Definition kidialog.cpp:89
Abstract interface for drawing on a 2D-surface.
BOX2D GetVisibleWorldExtents() const
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
void ShowPreview(bool aShow=true)
Definition view.cpp:2754
virtual int GetTopLayer() const
Definition view.cpp:1238
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
void InitPreview()
Definition view.cpp:2733
void ClearPreview()
Definition view.cpp:2718
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:2575
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
Definition view.cpp:2740
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
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 UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
T Min() const
Definition minoptmax.h:29
T PinnedOpt() const
Definition minoptmax.h:32
T Max() const
Definition minoptmax.h:30
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
const wxString GetHumanReadableName() const
Gets the consolidated name of this netclass (which may be an aggregate).
Definition netclass.cpp:348
int GetuViaDrill() const
Definition netclass.h:182
bool HasuViaDiameter() const
Definition netclass.h:173
int GetuViaDiameter() const
Definition netclass.h:174
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetname() const
Definition netinfo.h:110
NETCLASS * GetNetClass()
Definition netinfo.h:101
int GetNetCode() const
Definition netinfo.h:104
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:281
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 wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition paths.cpp:137
static TOOL_ACTION_GROUP layerDirectSwitchActions()
static TOOL_ACTION layerToggle
static TOOL_ACTION drag45Degree
static TOOL_ACTION layerInner12
static TOOL_ACTION routerUndoLastSegment
static TOOL_ACTION layerInner8
static TOOL_ACTION layerInner3
static TOOL_ACTION layerPrev
static TOOL_ACTION routerSettingsDialog
Activation of the Push and Shove settings dialogs.
static TOOL_ACTION layerInner2
static TOOL_ACTION routerAttemptFinish
static TOOL_ACTION routeDiffPair
Activation of the Push and Shove router (differential pair mode)
static TOOL_ACTION trackViaSizeChanged
static TOOL_ACTION layerChanged
static TOOL_ACTION layerInner25
static TOOL_ACTION breakTrack
Break a single track into two segments at the cursor.
static TOOL_ACTION routerRouteSelectedFromEnd
static TOOL_ACTION routerHighlightMode
Actions to enable switching modes via hotkey assignments.
static TOOL_ACTION routerWalkaroundMode
static TOOL_ACTION routerShoveMode
static TOOL_ACTION layerInner24
static TOOL_ACTION properties
Activation of the edit tool.
static TOOL_ACTION layerInner29
static TOOL_ACTION routerSpreadTracks
static TOOL_ACTION routerOptimizeSelected
static TOOL_ACTION routerAutorouteSelected
static TOOL_ACTION layerInner11
static TOOL_ACTION routerDiffPairDialog
static TOOL_ACTION routerContinueFromEnd
static TOOL_ACTION layerInner16
static TOOL_ACTION layerInner26
static TOOL_ACTION layerInner18
static TOOL_ACTION layerInner14
static TOOL_ACTION selectLayerPair
static TOOL_ACTION layerInner6
static TOOL_ACTION dragFreeAngle
static TOOL_ACTION clearHighlight
static TOOL_ACTION layerInner22
static TOOL_ACTION layerInner5
static TOOL_ACTION layerInner20
static TOOL_ACTION layerInner7
static TOOL_ACTION layerInner27
static TOOL_ACTION cancelCurrentItem
static TOOL_ACTION layerInner1
static TOOL_ACTION layerInner10
static TOOL_ACTION layerInner15
static TOOL_ACTION layerInner17
static TOOL_ACTION layerBottom
static TOOL_ACTION layerInner19
static TOOL_ACTION layerInner9
static TOOL_ACTION routerInlineDrag
Activation of the Push and Shove router (inline dragging mode)
static TOOL_ACTION layerInner30
static TOOL_ACTION layerTop
static TOOL_ACTION cycleRouterMode
static TOOL_ACTION layerInner4
static TOOL_ACTION routeSingleTrack
Activation of the Push and Shove router.
static TOOL_ACTION layerInner13
static TOOL_ACTION layerInner21
static TOOL_ACTION layerNext
static TOOL_ACTION routerRouteSelected
static TOOL_ACTION placeViaStack
static TOOL_ACTION layerInner23
static TOOL_ACTION layerInner28
Common, abstract interface for edit frames.
APPEARANCE_CONTROLS * GetAppearancePanel()
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual PCB_LAYER_ID GetActiveLayer() const
The main frame for Pcbnew.
void SetActiveLayer(PCB_LAYER_ID aLayer) override
Change the currently active layer to aLayer and also update the APPEARANCE_CONTROLS.
A PCB_IO derivation for saving and loading Pcbnew s-expression formatted files.
void SaveBoard(const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
PCB_LAYER_ID m_Route_Layer_TOP
Definition pcb_screen.h:39
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition pcb_screen.h:40
The selection tool: currently supports:
T * frame() const
KIGFX::PCB_VIEW * view() const
KIGFX::VIEW_CONTROLS * controls() const
BOARD * board() const
PCBNEW_SETTINGS::DISPLAY_OPTIONS & displayOptions() const
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() 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
EDA_ITEM_FLAGS IsPointOnEnds(const VECTOR2I &point, int min_dist=0) const
Return STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if point if near (dist = m...
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.
static std::set< KIID > CollectExpandableMicrovias(BOARD *aBoard)
Ids of the vias ExpandMultiHopMicrovias would consider right now.
static const wxString GENERATOR_TYPE
PCB_LAYER_ID BottomLayer() const
VECTOR2I GetPosition() const override
Definition pcb_track.h:615
void SetPosition(const VECTOR2I &aPoint) override
Definition pcb_track.h:616
void SetSizeFromRules(int aDiameter, int aDrill)
Give the via a uniform padstack sized from its diameter and hole rules.
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).
bool Empty() const
Definition pns_itemset.h:90
int Size() const
int Count(int aKindMask=-1) const
Definition pns_itemset.h:74
void Add(const LINE &aLine)
std::vector< ITEM * > & Items()
Definition pns_itemset.h:95
Base class for PNS router board items.
Definition pns_item.h:98
const PNS_LAYER_RANGE & Layers() const
Definition pns_item.h:212
virtual NET_HANDLE Net() const
Definition pns_item.h:210
bool OfKind(int aKindMask) const
Definition pns_item.h:181
virtual HOLE * Hole() const
Definition pns_item.h:308
virtual bool HasHole() const
Definition pns_item.h:307
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
int ArcCount() const
Definition pns_line.h:153
bool CompareGeometry(const LINE &aOther)
Return true if the line is geometrically identical as line aOther.
static wxString FormatLogFileAsJSON(const LOG_DATA &aLogData)
Keep the router "world" - i.e.
Definition pns_node.h:274
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition pns_node.cpp:174
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition pns_node.cpp:510
RULE_RESOLVER * GetRuleResolver() const
Definition pns_node.h:323
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition pns_node.cpp:765
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=nullptr, bool aStopAtLockedJoints=false, bool aFollowLockedSegments=false, bool aAllowSegmentSizeMismatch=true)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
ITEM * FindItemByParent(const BOARD_ITEM *aParent)
void Remove(ARC *aArc)
Remove an item from this branch.
static bool Optimize(LINE *aLine, int aEffortLevel, NODE *aWorld, const VECTOR2I &aV=VECTOR2I(0, 0))
A quick shortcut to optimize a line without creating and setting up an optimizer.
@ SMART_PADS
Reroute pad exits.
@ FANOUT_CLEANUP
Simplify pad-pad and pad-via connections if possible.
@ MERGE_SEGMENTS
Reduce corner cost iteratively.
@ MERGE_COLINEAR
Merge co-linear segments.
@ MERGE_OBTUSE
Reduce corner cost by merging obtuse segments.
@ REQUIRE_OBTUSE_ANGLES
Try to prevent 90-degree or acute corners in a drag.
Contain all persistent settings of the router, such as the mode, optimization effort,...
void SetMode(PNS_MODE aMode)
Set the routing mode.
PNS_MODE Mode() const
Return the routing mode.
virtual bool QueryConstraint(CONSTRAINT_TYPE aType, const ITEM *aItemA, const ITEM *aItemB, int aLayer, CONSTRAINT *aConstraint)=0
virtual NET_HANDLE DpCoupledNet(NET_HANDLE aNet)=0
void SetViaType(VIATYPE aViaType)
void SetTrackWidth(int aWidth)
void SetDiffPairWidth(int aWidth)
void SetDiffPairWidthSource(const wxString &aSource)
void SetDiffPairGapSource(const wxString &aSource)
void SetDiffPairGap(int aGap)
void SetViaDrill(int aDrill)
wxString GetClearanceSource() const
wxString GetDiffPairGapSource() const
wxString GetDiffPairWidthSource() const
void AddLayerPair(int aL1, int aL2)
void SetClearance(int aClearance)
bool TrackWidthIsExplicit() const
void SetViaDiameter(int aDiameter)
void SetClearanceSource(const wxString &aSource)
wxString GetWidthSource() const
void SetWidthSource(const wxString &aSource)
virtual void updateStartItem(const TOOL_EVENT &aEvent, bool aIgnorePads=false)
virtual void setSelectableItemMask(int aMask)
const VECTOR2I snapToItem(ITEM *aSnapToItem, const VECTOR2I &aP)
virtual void highlightNets(bool aEnabled, std::set< NET_HANDLE > aNetcodes={})
SIZES_SETTINGS m_savedSizes
PNS_KICAD_IFACE * m_iface
virtual void updateEndItem(const TOOL_EVENT &aEvent)
TOOL_BASE(const std::string &aToolName)
static const unsigned int COORDS_PADDING
ROUTER * m_router
VECTOR2I m_endSnapPoint
PCB_GRID_HELPER * m_gridHelper
VECTOR2I m_startSnapPoint
Represent a contiguous set of PCB layers.
int Start() const
bool Overlaps(const PNS_LAYER_RANGE &aOther) const
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
Container for project specific data.
Definition project.h:63
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:207
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
Describe ratsnest for a single net.
const std::vector< CN_EDGE > & GetEdges() const
void SetMessage(const wxString &aStatus)
void SetHint(const wxString &aHint)
void SetPosition(const VECTOR2I &aPos) override
int onViaCommand(const TOOL_EVENT &aEvent)
int onSpreadTracksIncDecDistance(const TOOL_EVENT &aEvent, bool aInc)
void commitPendingViaStack()
Build and commit a staggered via stack queued during routing (after the PNS world is gone).
int InlineDrag(const TOOL_EVENT &aEvent)
int onViaStackCommand(const TOOL_EVENT &aEvent)
std::shared_ptr< ACTION_MENU > m_trackViaMenu
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int onTrackViaSizeChanged(const TOOL_EVENT &aEvent)
int CustomTrackWidthDialog(const TOOL_EVENT &aEvent)
int handlePnSCornerModeChange(const TOOL_EVENT &aEvent)
static void NeighboringSegmentFilter(const VECTOR2I &aPt, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *aSelTool)
PNS::PNS_MODE GetRouterMode()
VECTOR2I m_pendingStackHead
PCB_LAYER_ID m_pendingStackEnd
void saveRouterDebugLog()
void recordPendingStackViaPos()
Remember where the placer is about to leave the newest drop's via.
void performDragging(int aMode=PNS::DM_ANY)
int onSpreadTracksSetDistance(const TOOL_EVENT &aEvent)
bool m_stackDropAwaitingVia
std::set< KIID > m_preRouteExpandableVias
PCB_LAYER_ID m_originalActiveLayer
int onLayerCommand(const TOOL_EVENT &aEvent)
PCB_LAYER_ID getStartLayer(const PNS::ITEM *aItem)
int SpreadTracks(const TOOL_EVENT &aEvent)
int CycleRouterMode(const TOOL_EVENT &aEvent)
void updateSizesAfterRouterEvent(int targetLayer, const VECTOR2I &aPos)
bool m_inRouteSelected
bool m_inRouterTool
int handleLayerSwitch(const TOOL_EVENT &aEvent, bool aForceVia)
void switchLayerOnViaPlacement()
int RouteSelected(const TOOL_EVENT &aEvent)
PCB_LAYER_ID m_pendingStackStart
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
bool finishInteractive()
int ChangeRouterMode(const TOOL_EVENT &aEvent)
std::shared_ptr< ACTION_MENU > m_diffPairMenu
PCB_LAYER_ID m_lastTargetLayer
void handleCommonEvents(TOOL_EVENT &evt)
void performRouting(VECTOR2D aStartPosition)
bool Init() override
Init() is called once upon a registration of the tool.
int OptimizeSelected(const TOOL_EVENT &aEvent)
int InlineBreakTrack(const TOOL_EVENT &aEvent)
bool prepareInteractive(VECTOR2D aStartPosition)
void restoreSelection(const PCB_SELECTION &aOriginalSelection)
bool RoutingInProgress()
Returns whether routing is currently active.
void UpdateMessagePanel()
int MainLoop(const TOOL_EVENT &aEvent)
bool m_pendingViaStack
bool CanInlineDrag(int aDragMode)
int SettingsDialog(const TOOL_EVENT &aEvent)
PCB_LAYER_ID m_viaStackResumeLayer
int DpDimensionsDialog(const TOOL_EVENT &aEvent)
std::vector< PENDING_STACK_EXPANSION > m_pendingStackedExpansions
int SelectCopperLayerPair(const TOOL_EVENT &aEvent)
VECTOR2I::extended_type ecoord
Definition seg.h:40
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
std::deque< EDA_ITEM * > & Items()
Definition selection.h:181
std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
An abstract shape on 2D plane.
Definition shape.h:124
virtual SEG::ecoord SquaredDistance(const VECTOR2I &aP, bool aOutlineOnly=false) const
Definition shape.cpp:111
bool GetMoveWarpsCursor() const
Indicate that a move operation should warp the mouse pointer to the origin of the move object.
Build up the properties of a TOOL_ACTION in an incremental manner that is static-construction safe.
Represent a single user action.
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
virtual void Reset(RESET_REASON aReason)=0
Bring the tool to a known, initial state.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
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
bool IsToolActive() const
Definition tool_base.cpp:28
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition tool_event.h:256
bool DisableGridSnapping() const
Definition tool_event.h:367
int KeyCode() const
Definition tool_event.h:372
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition tool_event.h:388
const VECTOR2D Position() const
Return mouse cursor position in world coordinates.
Definition tool_event.h:289
bool IsKeyPressed() const
Definition tool_event.h:377
TOOL_EVENT_CATEGORY Category() const
Return the category (eg. mouse/keyboard/action) of an event.
Definition tool_event.h:243
int Modifier(int aMask=MD_MODIFIER_MASK) const
Return information about key modifiers state (Ctrl, Alt, etc.).
Definition tool_event.h:362
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
bool IsActionInGroup(const TOOL_ACTION_GROUP &aGroup) const
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
void SetPassEvent(bool aPass=true)
Definition tool_event.h:252
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
friend class TOOL_MANAGER
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.
Master controller class:
VECTOR2D GetMenuCursorPos() const
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
bool IsContextMenuActive() const
True while processing a context menu.
KIGFX::VIEW * GetView() const
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
TRACK_WIDTH_MENU(PCB_EDIT_FRAME &aFrame)
void update() override
Update menu state stub.
PCB_EDIT_FRAME & m_frame
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
void SetTextValidator(const wxValidator &validator)
static bool IsZoneFillAction(const TOOL_EVENT *aEvent)
Handle a list of polygons defining a copper zone.
Definition zone.h:70
@ BLOCK
Cannot be represented at all, export to this target is not possible.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
@ ARROW
Definition cursors.h:43
@ PENCIL
Definition cursors.h:49
#define CHECK(x)
@ VIA_DIAMETER_CONSTRAINT
@ DIFF_PAIR_GAP_CONSTRAINT
@ TRACK_WIDTH_CONSTRAINT
@ CLEARANCE_CONSTRAINT
@ HOLE_SIZE_CONSTRAINT
#define _(s)
#define ROUTER_TRANSIENT
transient items that should NOT be cached
#define ENDPOINT
ends. (Used to support dragging.)
std::uint32_t EDA_ITEM_FLAGS
#define STARTPOINT
When a line is selected, these flags indicate which.
a few functions useful in geometry calculations.
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamp a vector to values that can be negated, respecting numeric limits of coordinates data type with...
wxString m_RouterTestCaseDirectory
Router test case directory.
static const std::string DesignRulesFileExtension
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
#define PSEUDO_WXK_CLICK
std::string source
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Cu
Definition layer_ids.h:61
@ Margin
Definition layer_ids.h:109
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
std::optional< wxString > fileHashMMH3(const wxString &aFilePath)
Calculates an MMH3 hash of a given file.
Definition io_utils.cpp:91
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
Push and Shove diff pair dimensions (gap) settings dialog.
PNS_MODE
Routing modes.
@ RM_MarkObstacles
Ignore collisions, mark obstacles.
@ RM_Walkaround
Only walk around.
@ RM_Shove
Only shove.
void * NET_HANDLE
Definition pns_item.h:55
ROUTER_MODE
Definition pns_router.h:68
@ PNS_MODE_ROUTE_DIFF_PAIR
Definition pns_router.h:70
@ PNS_MODE_SPREAD_TRACKS
Definition pns_router.h:74
@ DM_ANY
Definition pns_router.h:84
@ DM_FREE_ANGLE
Definition pns_router.h:82
@ DM_BLOCK
Definition pns_router.h:86
#define _HKI(x)
Definition page_info.cpp:40
VIATYPE
@ ID_POPUP_PCB_SELECT_WIDTH1
Definition pcbnew_id.h:25
@ ID_POPUP_PCB_SELECT_DIFFPAIR16
Definition pcbnew_id.h:77
@ ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES
Definition pcbnew_id.h:24
@ ID_POPUP_PCB_SELECT_WIDTH16
Definition pcbnew_id.h:40
@ ID_POPUP_PCB_SELECT_AUTO_WIDTH
Definition pcbnew_id.h:23
@ ID_POPUP_PCB_SELECT_CUSTOM_WIDTH
Definition pcbnew_id.h:22
@ ID_POPUP_PCB_SELECT_DIFFPAIR1
Definition pcbnew_id.h:62
@ ID_POPUP_PCB_SELECT_USE_NETCLASS_DIFFPAIR
Definition pcbnew_id.h:61
@ ID_POPUP_PCB_SELECT_VIASIZE1
Definition pcbnew_id.h:41
@ ID_POPUP_PCB_SELECT_CUSTOM_DIFFPAIR
Definition pcbnew_id.h:60
@ ID_POPUP_PCB_SELECT_VIASIZE16
Definition pcbnew_id.h:56
Class that computes missing connections on a PCB.
static const TOOL_ACTION ACT_SwitchCornerModeToNext(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SwitchRoundingToNext") .Scope(AS_CONTEXT) .DefaultHotkey(MD_CTRL+'/') .FriendlyName(_("Track Corner Mode Switch")) .Tooltip(_("Switches between sharp/rounded and 45°/90° corners when routing tracks.")) .Icon(BITMAPS::switch_corner_rounding_shape))
#define FORMAT_VALUE(x)
static const TOOL_ACTION ACT_SwitchCornerMode45(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SwitchRounding45") .Scope(AS_CONTEXT) .DefaultHotkey(MD_CTRL+ 'W') .FriendlyName(_("Track Corner Mode 45")) .Tooltip(_("Switch to 45° corner when routing tracks.")))
static const TOOL_ACTION ACT_PlaceBlindVia(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.PlaceBlindVia") .Scope(AS_CONTEXT) .DefaultHotkey(MD_ALT+MD_SHIFT+ 'V') .LegacyHotkeyName("Add Blind/Buried Via") .FriendlyName(_("Place Blind/Buried Via")) .Tooltip(_("Adds a blind or buried via at the end of currently routed track.")) .Icon(BITMAPS::via_buried) .Flags(AF_NONE) .Parameter< int >(VIA_ACTION_FLAGS::BLIND_VIA))
PCB_LAYER_ID ViaStackTargetLayer(PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aCurrent)
Layer a microvia stack drop lands on when invoked on aCurrent.
static VIATYPE getViaTypeFromFlags(int aFlags)
static const TOOL_ACTION ACT_SpreadTracksSetDistance(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SpreadTracksSetDistance") .Scope(AS_CONTEXT) .DefaultHotkey( 'E') .LegacyHotkeyName("Set Spreading Distance") .FriendlyName(_("Set Spreading Distance...")) .Tooltip(_("Sets the distance between the tracks for the Spread Tracks tool.")))
static const TOOL_ACTION ACT_IncreaseSpreadingDistance(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.IncreaseSpreadingDistance") .Scope(AS_CONTEXT) .DefaultHotkey(']') .LegacyHotkeyName("Increase Spreading Distance") .FriendlyName(_("Increase Spreading Distance...")) .Tooltip(_("Increases the distance between the tracks for the Spread Tracks tool by one grid unit.")))
static const TOOL_ACTION ACT_SwitchCornerModeArc90(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SwitchRoundingArc90") .Scope(AS_CONTEXT) .DefaultHotkey(MD_ALT+ 'W') .FriendlyName(_("Track Corner Mode Arc 90")) .Tooltip(_("Switch to arc 90° corner when routing tracks.")))
static const TOOL_ACTION ACT_SwitchCornerMode90(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SwitchRounding90") .Scope(AS_CONTEXT) .DefaultHotkey(MD_CTRL+MD_ALT+ 'W') .FriendlyName(_("Track Corner Mode 90")) .Tooltip(_("Switch to 90° corner when routing tracks.")))
static const TOOL_ACTION ACT_PlaceMicroVia(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.PlaceMicroVia") .Scope(AS_CONTEXT) .DefaultHotkey(MD_CTRL+ 'V') .LegacyHotkeyName("Add MicroVia") .FriendlyName(_("Place Microvia")) .Tooltip(_("Adds a microvia at the end of currently routed track.")) .Icon(BITMAPS::via_microvia) .Flags(AF_NONE) .Parameter< int >(VIA_ACTION_FLAGS::MICROVIA))
static const TOOL_ACTION ACT_DecreaseSpreadingDistance(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.DecreaseSpreadingDistance") .Scope(AS_CONTEXT) .DefaultHotkey('[') .LegacyHotkeyName("Decrease Spreading Distance") .FriendlyName(_("Decrease Spreading Distance...")) .Tooltip(_("Decreases the distance between the tracks for the Spread Tracks tool by one grid unit.")))
static const TOOL_ACTION ACT_PlaceViaStack(.Name("pcbnew.InteractiveRouter.PlaceViaStack") .Scope(AS_CONTEXT) .DefaultHotkey(MD_CTRL+MD_SHIFT+ 'V') .FriendlyName(_("Place Microvia Stack at Track End")) .Tooltip(_("Drops the active microvia stack preset at the end of the currently routed track " "and continues on the target layer.")) .Icon(BITMAPS::add_via_stack) .Flags(AF_NONE))
DRAG_KIND
static const TOOL_ACTION ACT_SelLayerAndPlaceBlindVia(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SelLayerAndPlaceBlindVia") .Scope(AS_CONTEXT) .DefaultHotkey(MD_ALT+'<') .LegacyHotkeyName("Select Layer and Add Blind/Buried Via") .FriendlyName(_("Select Layer and Place Blind/Buried Via...")) .Tooltip(_("Select a layer, then add a blind or buried via at the end of currently routed track.")) .Icon(BITMAPS::select_w_layer) .Flags(AF_NONE) .Parameter< int >(VIA_ACTION_FLAGS::BLIND_VIA|VIA_ACTION_FLAGS::SELECT_LAYER))
static const TOOL_ACTION ACT_SwitchPosture(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SwitchPosture") .Scope(AS_CONTEXT) .DefaultHotkey('/') .LegacyHotkeyName("Switch Track Posture") .FriendlyName(_("Switch Track Posture")) .Tooltip(_("Switches posture of the currently routed track.")) .Icon(BITMAPS::change_entry_orient))
VIA_ACTION_FLAGS
Flags used by via tool actions.
@ BLIND_VIA
blind via
@ BURIED_VIA
buried via
@ SELECT_LAYER
Ask user to select layer before adding via.
@ MICROVIA
Microvia.
@ VIA_MASK
@ VIA
Normal via.
static DRAG_KIND dragKindOf(const PCB_SELECTION &aSelection)
const VIA_STACK_PRESET * MatchPendingStackExpansion(PCB_VIA *aVia, const std::set< KIID > &aPreRoute, const std::vector< PENDING_STACK_EXPANSION > &aPending)
Preset a route's stacked drop wants for aVia, or nullptr when the via is not one of them.
static const TOOL_ACTION ACT_SelLayerAndPlaceThroughVia(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SelLayerAndPlaceVia") .Scope(AS_CONTEXT) .DefaultHotkey('<') .LegacyHotkeyName("Select Layer and Add Through Via") .FriendlyName(_("Select Layer and Place Through Via...")) .Tooltip(_("Select a layer, then add a through-hole via at the end of currently routed track.")) .Icon(BITMAPS::select_w_layer) .Flags(AF_NONE) .Parameter< int >(VIA_ACTION_FLAGS::VIA|VIA_ACTION_FLAGS::SELECT_LAYER))
static const TOOL_ACTION ACT_SwitchCornerModeArc45(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SwitchRoundingArc45") .Scope(AS_CONTEXT) .DefaultHotkey(MD_CTRL+MD_SHIFT+ 'W') .FriendlyName(_("Track Corner Mode Arc 45")) .Tooltip(_("Switch to arc 45° corner when routing tracks.")))
static const TOOL_ACTION ACT_SelLayerAndPlaceMicroVia(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.SelLayerAndPlaceMicroVia") .Scope(AS_CONTEXT) .FriendlyName(_("Select Layer and Place Micro Via...")) .Tooltip(_("Select a layer, then add a micro via at the end of currently routed track.")) .Icon(BITMAPS::select_w_layer) .Flags(AF_NONE) .Parameter< int >(VIA_ACTION_FLAGS::MICROVIA|VIA_ACTION_FLAGS::SELECT_LAYER))
static const TOOL_ACTION ACT_PlaceThroughVia(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.PlaceVia") .Scope(AS_CONTEXT) .DefaultHotkey( 'V') .LegacyHotkeyName("Add Through Via") .FriendlyName(_("Place Through Via")) .Tooltip(_("Adds a through-hole via at the end of currently routed track.")) .Icon(BITMAPS::via) .Flags(AF_NONE) .Parameter< int >(VIA_ACTION_FLAGS::VIA))
#define _(s)
static const TOOL_ACTION ACT_CustomTrackWidth(TOOL_ACTION_ARGS() .Name("pcbnew.InteractiveRouter.CustomTrackViaSize") .Scope(AS_CONTEXT) .DefaultHotkey( 'Q') .LegacyHotkeyName("Custom Track/Via Size") .FriendlyName(_("Custom Track/Via Size...")) .Tooltip(_("Shows a dialog for changing the track width and via size.")) .Icon(BITMAPS::width_track))
PCB_LAYER_ID ViaStackTargetLayer(PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd, PCB_LAYER_ID aCurrent)
Layer a microvia stack drop lands on when invoked on aCurrent.
const VIA_STACK_PRESET * MatchPendingStackExpansion(PCB_VIA *aVia, const std::set< KIID > &aPreRoute, const std::vector< PENDING_STACK_EXPANSION > &aPending)
Preset a route's stacked drop wants for aVia, or nullptr when the via is not one of them.
#define APPEND_UNDO
Definition sch_commit.h:39
std::vector< EDA_ITEM * > EDA_ITEMS
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
Container to handle a stock of specific differential pairs each with unique track width,...
An abstract function object, returning a design rule (clearance, diff pair gap, etc) required between...
Definition pns_node.h:83
wxString m_RuleName
Definition pns_node.h:87
MINOPTMAX< int > m_Value
Definition pns_node.h:85
std::optional< wxString > m_BoardHash
Definition pns_logger.h:102
std::optional< TEST_CASE_TYPE > m_TestCaseType
Definition pns_logger.h:107
std::vector< ITEM * > m_AddedItems
Definition pns_logger.h:103
std::vector< EVENT_ENTRY > m_Events
Definition pns_logger.h:106
std::set< KIID > m_RemovedItems
Definition pns_logger.h:104
std::vector< ITEM * > m_Heads
Definition pns_logger.h:105
Container to handle a stock of specific vias each with unique diameter and drill sizes in the BOARD c...
A named microvia stack definition, chosen while routing instead of entering the values each time.
JSON_SCHEMA_VALIDATOR validator(schema)
std::string path
@ AS_CONTEXT
Action belongs to a particular tool (i.e. a part of a pop-up menu)
Definition tool_action.h:43
@ AF_NONE
Definition tool_action.h:51
@ TA_MODEL_CHANGE
Model has changed (partial update).
Definition tool_event.h:117
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition tool_event.h:102
@ TA_UNDO_REDO_POST
This event is sent after undo/redo command is performed.
Definition tool_event.h:105
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition tool_event.h:652
@ MD_ALT
Definition tool_event.h:141
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ TC_COMMAND
Definition tool_event.h:53
@ TC_MOUSE
Definition tool_event.h:51
@ TC_VIEW
Definition tool_event.h:55
@ 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_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ 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
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
wxPoint ToWxPoint(const VECTOR2I &aSize)
Definition vector2wx.h:46
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
Definition of file extensions used in Kicad.