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