KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_selection_tool.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU 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 <algorithm>
24#include <cmath>
25#include <functional>
26#include <stack>
27using namespace std::placeholders;
28
29#include <advanced_config.h>
30#include <macros.h>
31#include <board.h>
33#include <footprint.h>
34#include <pad.h>
35#include <pcb_point.h>
36#include <pcb_generated_table.h>
37#include <pcb_table.h>
38#include <pcb_tablecell.h>
39#include <pcb_track.h>
40#include <pcb_marker.h>
41#include <pad.h>
42#include <pcb_generator.h>
43#include <pcb_group.h>
44#include <pcb_base_edit_frame.h>
45#include <zone.h>
46#include <collectors.h>
48#include <view/view_controls.h>
49#include <gal/painter.h>
50#include <pcb_painter.h>
51#include <router/router_tool.h>
52#include <pcbnew_settings.h>
53#include <tool/action_menu.h>
54#include <tool/tool_event.h>
55#include <tool/tool_manager.h>
60#include <tools/pcb_actions.h>
63#include <trace_helpers.h>
65#include <wx/event.h>
66#include <wx/timer.h>
67#include <wx/log.h>
68#include <wx/debug.h>
69#include <wx/modalhook.h>
70#include <core/profile.h>
71#include <math/vector2wx.h>
72
79
80
82{
83public:
85 ACTION_MENU( true )
86 {
87 SetTitle( _( "Select" ) );
88
90
91 AppendSeparator();
92
96
97 // This could be enabled if we have better logic for picking the target net with the mouse
98 // Add( PCB_ACTIONS::deselectNet );
101
104 }
105
106private:
107 ACTION_MENU* create() const override
108 {
109 return new SELECT_MENU();
110 }
111};
112
113enum
114{
115 ID_REPLACE_TERMINAL_PAD_A = wxID_HIGHEST + 3000,
117};
118
120{
121public:
123 {
124 SetTitle( _( "Set terminal pad" ) );
125 }
126
127protected:
128 ACTION_MENU* create() const override { return new REPLACE_TERMINAL_PAD_MENU(); }
129
130 void update() override
131 {
132 Clear();
133
134 TOOL_MANAGER* toolMgr = getToolManager();
135 if( !toolMgr )
136 return;
137
138 PCB_SELECTION_TOOL* selTool = toolMgr->GetTool<PCB_SELECTION_TOOL>();
139 if( !selTool )
140 return;
141
142 const SELECTION& sel = selTool->GetSelection();
143 if( sel.Empty() )
144 return;
145
146 PAD* pad = dynamic_cast<PAD*>( sel.Front() );
147 PCB_EDIT_FRAME* frame = static_cast<PCB_EDIT_FRAME*>( toolMgr->GetToolHolder() );
148
149 if( !pad || !frame )
150 return;
151
152 NETINFO_ITEM* net = pad->GetNet();
153
154 if( !net || net->GetNetChain().IsEmpty() )
155 return;
156
157 PAD* oldA = net->GetTerminalPad( 0 );
158 PAD* oldB = net->GetTerminalPad( 1 );
159 KIID newId = pad->m_Uuid;
160
161 wxMenuItem* itemA = Append( ID_REPLACE_TERMINAL_PAD_A, _( "Terminal A" ) );
162 wxMenuItem* itemB = Append( ID_REPLACE_TERMINAL_PAD_B, _( "Terminal B" ) );
163
164 if( oldA && oldA->m_Uuid == newId )
165 itemA->Enable( false );
166
167 if( oldB && oldB->m_Uuid == newId )
168 itemB->Enable( false );
169
170 m_oldA = oldA ? oldA->m_Uuid : niluuid;
171 m_oldB = oldB ? oldB->m_Uuid : niluuid;
172 m_new = newId;
173 }
174
175 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
176 {
177 if( aEvent.GetId() == ID_REPLACE_TERMINAL_PAD_A )
178 {
180 te.SetParameter( std::make_pair( m_oldA.AsString(), m_new.AsString() ) );
181 return te;
182 }
183 else if( aEvent.GetId() == ID_REPLACE_TERMINAL_PAD_B )
184 {
186 te.SetParameter( std::make_pair( m_oldB.AsString(), m_new.AsString() ) );
187 return te;
188 }
189
190 return OPT_TOOL_EVENT();
191 }
192
193private:
197};
198
200{
201public:
203 {
204 SetTitle( _( "Net Chains..." ) );
208 }
209
210protected:
211 ACTION_MENU* create() const override { return new NET_CHAINS_MENU(); }
212
213private:
215};
216
217
226
227
229 SELECTION_TOOL( "common.InteractiveSelection" ),
230 m_frame( nullptr ),
231 m_isFootprintEditor( false ),
232 m_enteredGroup( nullptr ),
234 m_lockedItemsFiltered( false ),
235 m_previousFirstCell( nullptr ),
236 m_priv( std::make_unique<PRIV>() )
237{
238 m_filter.lockedItems = false;
239 m_filter.footprints = true;
240 m_filter.text = true;
241 m_filter.tracks = true;
242 m_filter.vias = true;
243 m_filter.pads = true;
244 m_filter.graphics = true;
245 m_filter.zones = true;
246 m_filter.keepouts = true;
247 m_filter.dimensions = true;
248 m_filter.points = true;
249 m_filter.gridItems = true;
250 m_filter.otherItems = true;
251}
252
253
255{
258
259 Disconnect( wxEVT_TIMER, wxTimerEventHandler( PCB_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
260}
261
262
264{
266
267 if( frame && frame->IsType( FRAME_FOOTPRINT_VIEWER ) )
268 {
269 frame->AddStandardSubMenus( *m_menu.get() );
270 return true;
271 }
272
273 std::shared_ptr<SELECT_MENU> selectMenu = std::make_shared<SELECT_MENU>();
274 selectMenu->SetTool( this );
275 m_menu->RegisterSubMenu( selectMenu );
276
277 std::shared_ptr<NET_CHAINS_MENU> netChainsMenu = std::make_shared<NET_CHAINS_MENU>();
278 netChainsMenu->SetTool( this );
279 m_menu->RegisterSubMenu( netChainsMenu );
280
281 static const std::vector<KICAD_T> tableCellTypes = { PCB_TABLECELL_T };
282
283 auto& menu = m_menu->GetMenu();
284
285 auto activeToolCondition =
286 [this] ( const SELECTION& aSel )
287 {
289 return pcbFrame && !pcbFrame->ToolStackIsEmpty();
290 };
291
292 auto haveHighlight =
293 [this]( const SELECTION& sel )
294 {
295 KIGFX::RENDER_SETTINGS* cfg = m_toolMgr->GetView()->GetPainter()->GetSettings();
296
297 return !cfg->GetHighlightNetCodes().empty();
298 };
299
300 auto groupEnterCondition =
302
303 auto applyDesignBlockLayoutCondition = []( const SELECTION& aSel )
304 {
305 for( EDA_ITEM* item : aSel )
306 {
307 if( item->Type() == PCB_GROUP_T && static_cast<PCB_GROUP*>( item )->HasDesignBlockLink() )
308 {
309 return true;
310 }
311 }
312
313 return false;
314 };
315
316 auto inGroupCondition =
317 [this] ( const SELECTION& )
318 {
319 return m_enteredGroup != nullptr;
320 };
321
322 auto tableCellSelection = SELECTION_CONDITIONS::MoreThan( 0 )
324
325 SELECTION_CONDITION referenceImageSelection = []( const SELECTION& aSel )
326 {
327 return aSel.GetSize() == 1 && static_cast<BOARD_ITEM*>( *aSel.begin() )->Type() == PCB_REFERENCE_IMAGE_T;
328 };
329
330 SELECTION_CONDITION netItemSelection = []( const SELECTION& aSel )
331 {
332 if( aSel.GetSize() != 1 )
333 return false;
334 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( *aSel.begin() );
335 return item->Type() == PCB_PAD_T || item->Type() == PCB_VIA_T || item->Type() == PCB_TRACE_T
336 || item->Type() == PCB_ARC_T;
337 };
338
339 if( frame && frame->IsType( FRAME_PCB_EDITOR ) )
340 {
341 menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
342 menu.AddMenu( netChainsMenu.get(), netItemSelection );
343 menu.AddSeparator( 1000 );
344 }
345
346 // "Cancel" goes at the top of the context menu when a tool is active
347 menu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
348 menu.AddItem( ACTIONS::groupEnter, groupEnterCondition, 1 );
349 menu.AddItem( ACTIONS::groupLeave, inGroupCondition, 1 );
350 menu.AddItem( PCB_ACTIONS::applyDesignBlockLayout, applyDesignBlockLayoutCondition, 1 );
351 menu.AddItem( PCB_ACTIONS::placeLinkedDesignBlock, groupEnterCondition, 1 );
352 menu.AddItem( PCB_ACTIONS::saveToLinkedDesignBlock, groupEnterCondition, 1 );
353 menu.AddItem( PCB_ACTIONS::convertImageToOutlines, referenceImageSelection, 1 );
354 menu.AddItem( PCB_ACTIONS::clearHighlight, haveHighlight, 1 );
355 menu.AddSeparator( haveHighlight, 1 );
356
357 menu.AddItem( ACTIONS::selectColumns, tableCellSelection, 2 );
358 menu.AddItem( ACTIONS::selectRows, tableCellSelection, 2 );
359 menu.AddItem( ACTIONS::selectTable, tableCellSelection, 2 );
360
361 menu.AddSeparator( 1 );
362
363 if( frame )
364 frame->AddStandardSubMenus( *m_menu.get() );
365
366 m_disambiguateTimer.SetOwner( this );
367 Connect( m_disambiguateTimer.GetId(), wxEVT_TIMER,
368 wxTimerEventHandler( PCB_SELECTION_TOOL::onDisambiguationExpire ), nullptr, this );
369
370 return true;
371}
372
373
375{
378
379 if( aReason != TOOL_BASE::REDRAW )
380 {
381 if( m_enteredGroup )
382 ExitGroup();
383
384 // Deselect any item being currently in edit, to avoid unexpected behavior and remove
385 // pointers to the selected items from containers.
386 ClearSelection( true );
387 }
388
389 if( aReason == TOOL_BASE::MODEL_RELOAD )
390 getView()->GetPainter()->GetSettings()->SetHighlight( false );
391
392 // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
393 view()->Remove( &m_selection );
394 view()->Add( &m_selection );
395
398}
399
400
401void PCB_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent )
402{
403 if( m_frame->IsActive() && m_frame->IsEnabled() && m_frame->ToolStackIsEmpty() && !m_inSelectMultiple )
404 {
405 bool dragSelected = m_frame->GetDragAction() == MOUSE_DRAG_ACTION::DRAG_SELECTED;
406 wxMouseState keyboardState = wxGetMouseState();
407
408 setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(), keyboardState.AltDown() );
409
410 if( m_additive )
411 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD );
412 else if( m_subtractive )
413 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT );
414 else if( m_exclusive_or )
415 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR );
416 else if( dragSelected && SelectionContains( m_toolMgr->GetMousePosition() ) )
417 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
418 else
419 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
420 }
421}
422
423
425{
426 // Main loop: keep receiving events
427 while( TOOL_EVENT* evt = Wait() )
428 {
429 MOUSE_DRAG_ACTION dragAction = m_frame->GetDragAction();
431
432 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
433 trackDragAction = cfg->m_TrackDragAction;
434
435 // on left click, a selection is made, depending on modifiers ALT, SHIFT, CTRL:
436 setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ), evt->Modifier( MD_ALT ) );
437
439 bool brd_editor = frame && frame->IsType( FRAME_PCB_EDITOR );
440 ROUTER_TOOL* router = m_toolMgr->GetTool<ROUTER_TOOL>();
441
442 // If the router tool is active, don't override
443 if( router && router->IsToolActive() && router->RoutingInProgress() )
444 {
445 evt->SetPassEvent();
446 }
447 else if( evt->IsMouseDown( BUT_LEFT ) )
448 {
449 // Avoid triggering when running under other tools. A click on a block handle
450 // belongs to the point editor, which stops this timer for every click it takes
451 PCB_POINT_EDITOR *pt_tool = m_toolMgr->GetTool<PCB_POINT_EDITOR>();
452
453 if( m_frame->ToolStackIsEmpty() && pt_tool && !pt_tool->HasPoint() && !pt_tool->HasBlockHandle() )
454 {
455 m_originalCursor = m_toolMgr->GetMousePosition();
456 m_disambiguateTimer.StartOnce( ADVANCED_CFG::GetCfg().m_DisambiguationMenuDelay );
457 }
458 }
459 else if( evt->IsClick( BUT_LEFT ) )
460 {
461 // If there is no disambiguation, this routine is still running and will
462 // register a `click` event when released
463 if( m_disambiguateTimer.IsRunning() )
464 {
465 m_disambiguateTimer.Stop();
466
467 // A click on a geometric-constraint badge selects that constraint instead of a
468 // board item (the badges have no selectable geometry of their own); a click that
469 // misses every badge clears any badge selection.
470 if( CONSTRAINT_EDIT_TOOL* constraintTool =
471 m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>() )
472 {
473 if( constraintTool->SelectConstraintAt( evt->Position() ) )
474 {
475 m_canceledMenu = false;
476 continue;
477 }
478
479 constraintTool->ClearConstraintSelection();
480 }
481
482 // Single click? Select single object
483 if( m_highlight_modifier && brd_editor )
484 {
485 if( !toggleTableCellSelection( evt->Position() ) )
487 }
488 else
489 {
490 m_frame->ClearFocus();
491
492 // Mirrors eeschema's SCH_TABLE shift+click range select.
493 if( !extendTableCellSelectionTo( evt->Position() ) )
494 {
495 selectPoint( evt->Position() );
496
497 // Anchor for a subsequent shift+click or shift+drag whose IsClick
498 // jitter could otherwise promote into IsDrag, collapsing the range
499 // rectangle to (DragOrigin, Position) at the press point.
501 }
502 }
503 }
504
505 m_canceledMenu = false;
506 }
507 else if( evt->IsClick( BUT_RIGHT ) )
508 {
509 m_disambiguateTimer.Stop();
510
511 // Right click? if there is any object - show the context menu
512 bool selectionCancelled = false;
513
514 if( m_selection.Empty() )
515 {
516 selectPoint( evt->Position(), false, &selectionCancelled );
517 m_selection.SetIsHover( true );
518 }
519
520 // Show selection before opening menu
521 m_frame->GetCanvas()->ForceRefresh();
522
523 if( !selectionCancelled )
524 {
525 m_toolMgr->VetoContextMenuMouseWarp();
526
527 // If every item in the selection shares the same generator parent and that
528 // generator provides a child context menu, show it instead of the standard
529 // selection menu. This lets a generator restrict what users can do to its
530 // (otherwise individually-selectable) children.
531 ACTION_MENU* genMenu = nullptr;
532 PCB_GENERATOR* sharedParent = nullptr;
533 bool allSameParent = !m_selection.Empty();
534
535 for( EDA_ITEM* item : m_selection )
536 {
537 if( !item->IsBOARD_ITEM() )
538 {
539 allSameParent = false;
540 break;
541 }
542
543 EDA_GROUP* parent = static_cast<BOARD_ITEM*>( item )->GetParentGroup();
544
545 if( !parent || parent->AsEdaItem()->Type() != PCB_GENERATOR_T )
546 {
547 allSameParent = false;
548 break;
549 }
550
551 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
552
553 if( !sharedParent )
554 sharedParent = gen;
555 else if( sharedParent != gen )
556 {
557 allSameParent = false;
558 break;
559 }
560 }
561
562 if( allSameParent && sharedParent )
563 genMenu = sharedParent->GetChildContextMenu( this );
564
565 if( genMenu )
566 SetContextMenu( genMenu, CMENU_NOW );
567 else
568 m_menu->ShowContextMenu( m_selection );
569 }
570 }
571 else if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
572 {
573 m_disambiguateTimer.Stop();
574
575 // Double clicks make no sense in the footprint viewer
576 if( frame && frame->IsType( FRAME_FOOTPRINT_VIEWER ) )
577 {
578 evt->SetPassEvent();
579 continue;
580 }
581
582 // A double-click on a constraint badge edits that relation's value.
583 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
584 constraintTool && constraintTool->EditConstraintAt( evt->Position() ) )
585 {
586 continue;
587 }
588
589 // Double click? Display the properties window
590 m_frame->ClearFocus();
591
592 if( m_selection.Empty() )
593 selectPoint( evt->Position() );
594
595 if( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T )
596 {
597 EnterGroup();
598 selectPoint( evt->Position() );
599 }
600 else if( !selectGeneratedTableRow( evt->Position() ) )
602 }
603 else if( evt->IsDblClick( BUT_MIDDLE ) )
604 {
605 // Middle double click? Do zoom to fit or zoom to objects
606 if( evt->Modifier( MD_CTRL ) ) // Is CTRL key down?
608 else
609 m_toolMgr->RunAction( ACTIONS::zoomFitScreen );
610 }
611 else if( evt->Action() == TA_MOUSE_WHEEL )
612 {
613 int field = -1;
614
615 if( evt->Modifier() == ( MD_SHIFT | MD_ALT ) )
616 field = 0;
617 else if( evt->Modifier() == ( MD_CTRL | MD_ALT ) )
618 field = 1;
619 // any more?
620
621 if( field >= 0 )
622 {
623 const int delta = evt->Parameter<int>();
624 ACTIONS::INCREMENT params { delta > 0 ? 1 : -1, field };
625
626 m_toolMgr->RunAction( ACTIONS::increment, params );
627 }
628 }
629 else if( evt->IsDrag( BUT_LEFT ) )
630 {
631 m_disambiguateTimer.Stop();
632
633 // Is another tool already moving a new object? Don't allow a drag start
634 if( !m_selection.Empty() && m_selection[0]->HasFlag( IS_NEW | IS_MOVING ) )
635 {
636 evt->SetPassEvent();
637 continue;
638 }
639
640 // Drag with LMB? Select multiple objects (or at least draw a selection box)
641 // or drag them
642 m_frame->ClearFocus();
644
645 GENERAL_COLLECTOR hoverCells;
646 collectTableCellsAt( evt->DragOrigin(), hoverCells );
647
648 if( hoverCells.GetCount() )
649 {
650 if( m_selection.Empty() || SELECTION_CONDITIONS::OnlyTypes( { PCB_TABLECELL_T } )( m_selection ) )
651 {
652 selectTableCells( static_cast<PCB_TABLE*>( hoverCells[0]->GetParent() ) );
653 }
654 else
655 {
656 m_toolMgr->RunAction( PCB_ACTIONS::move );
657 }
658 }
659 else if( ( hasModifier() || dragAction == MOUSE_DRAG_ACTION::SELECT )
660 || ( m_selection.Empty() && dragAction != MOUSE_DRAG_ACTION::DRAG_ANY ) )
661 {
664 {
665 SelectRectArea( aEvent );
666 }
669 {
670 SelectPolyArea( aEvent );
671 }
672 else
673 {
674 wxASSERT_MSG( false, wxT( "Unknown selection mode" ) );
675 SelectRectArea( aEvent );
676 }
677 }
678 else
679 {
680 // Don't allow starting a drag from a zone filled area that isn't already selected
681 auto zoneFilledAreaFilter =
682 []( const VECTOR2I& aWhere, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* aTool )
683 {
684 int accuracy = aCollector.GetGuide()->Accuracy();
685 std::set<EDA_ITEM*> remove;
686
687 for( EDA_ITEM* item : aCollector )
688 {
689 if( item->Type() == PCB_ZONE_T )
690 {
691 ZONE* zone = static_cast<ZONE*>( item );
692
693 if( !zone->HitTestForCorner( aWhere, accuracy * 2 )
694 && !zone->HitTestForEdge( aWhere, accuracy ) )
695 {
696 remove.insert( zone );
697 }
698 }
699 }
700
701 for( EDA_ITEM* item : remove )
702 aCollector.Remove( item );
703 };
704
705 // See if we can drag before falling back to SelectRectArea()
706 bool doDrag = false;
707
708 if( evt->HasPosition() )
709 {
710 if( m_selection.Empty()
711 && selectPoint( evt->DragOrigin(), false, nullptr, zoneFilledAreaFilter ) )
712 {
713 m_selection.SetIsHover( true );
714 doDrag = true;
715 }
716 // Check if dragging has started within any of selected items bounding box.
717 else if( evt->HasPosition() && SelectionContains( evt->DragOrigin() ) )
718 {
719 doDrag = true;
720 }
721 }
722
723 if( doDrag )
724 {
725 size_t segs = m_selection.CountType( PCB_TRACE_T );
726 size_t arcs = m_selection.CountType( PCB_ARC_T );
727 size_t vias = m_selection.CountType( PCB_VIA_T );
728 // Note: multi-track dragging is currently supported, but not multi-via
729 bool routable = ( segs >= 1 || arcs >= 1 || vias == 1 )
730 && ( segs + arcs + vias == m_selection.GetSize() );
731
732 // Vias that belong to a generator with individually-selectable children
733 // (e.g. via stitching) should use the plain move flow so the parent
734 // generator can react to the new child position. The PNS router would
735 // hijack the drag and skip that hook.
736 if( routable )
737 {
738 for( EDA_ITEM* item : m_selection )
739 {
740 if( !item->IsBOARD_ITEM() )
741 continue;
742
743 EDA_GROUP* parent = static_cast<BOARD_ITEM*>( item )->GetParentGroup();
744
745 if( !parent || parent->AsEdaItem()->Type() != PCB_GENERATOR_T )
746 continue;
747
748 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
749
751 {
752 routable = false;
753 break;
754 }
755 }
756 }
757
758 if( routable && trackDragAction == TRACK_DRAG_ACTION::DRAG )
760 else if( routable && trackDragAction == TRACK_DRAG_ACTION::DRAG_FREE_ANGLE )
762 else
763 m_toolMgr->RunAction( PCB_ACTIONS::move );
764 }
765 else
766 {
767 // Otherwise drag a selection box
770 {
771 SelectPolyArea( aEvent );
772 }
773 else
774 {
775 SelectRectArea( aEvent );
776 }
777 }
778 }
779 }
780 else if( evt->IsCancel() )
781 {
782 m_disambiguateTimer.Stop();
783 m_frame->ClearFocus();
784
785 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
786 constraintTool && constraintTool->ClearConstraintSelection() )
787 {
788 continue;
789 }
790
791 if( !GetSelection().Empty() )
792 {
794 }
795 else if( evt->FirstResponder() == this && evt->GetCommandId() == (int) WXK_ESCAPE )
796 {
797 if( m_enteredGroup )
798 {
799 ExitGroup();
800 }
801 else
802 {
803 BOARD_INSPECTION_TOOL* controller = m_toolMgr->GetTool<BOARD_INSPECTION_TOOL>();
804
805 try
806 {
807 if( controller && m_frame->GetPcbNewSettings()->m_ESCClearsNetHighlight )
808 controller->ClearHighlight( *evt );
809 }
810 catch( const std::runtime_error& e )
811 {
812 wxCHECK_MSG( false, 0, e.what() );
813 }
814 }
815 }
816 }
817 else
818 {
819 evt->SetPassEvent();
820 }
821 }
822
823 // Shutting down; clear the selection
824 m_previousFirstCell = nullptr;
825 m_selection.Clear();
826 m_disambiguateTimer.Stop();
827
828 return 0;
829}
830
831
833{
834 wxCHECK_RET( m_selection.GetSize() == 1 && m_selection[0]->Type() == PCB_GROUP_T,
835 wxT( "EnterGroup called when selection is not a single group" ) );
836 PCB_GROUP* aGroup = static_cast<PCB_GROUP*>( m_selection[0] );
837
838 if( m_enteredGroup != nullptr )
839 ExitGroup();
840
842 m_enteredGroup = aGroup;
843 m_enteredGroup->SetFlags( ENTERED );
844
845 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
846
847 // Processing the selection event can re-enter the tool and ExitGroup(), which clears
848 // m_enteredGroup. If that happened, don't operate on the now-stale (possibly null) group
849 // or we would hide/overlay a null item and crash (issue #24391).
850 if( m_enteredGroup != aGroup )
851 return;
852
853 view()->Hide( m_enteredGroup, true );
856
858}
859
860
862{
863 auto* painter = dynamic_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
864
865 if( !painter )
866 return;
867
868 auto* settings = painter->GetSettings();
869
870 if( settings->IsGroupEditModeActive() == aActive )
871 return;
872
873 settings->SetGroupEditModeActive( aActive );
874
875 if( settings->GetOutsideGroupOpacity() < 1.0 )
877}
878
879
880void PCB_SELECTION_TOOL::ExitGroup( bool aSelectGroup )
881{
882 // Only continue if there is a group entered
883 if( m_enteredGroup == nullptr )
884 return;
885
886 m_enteredGroup->ClearFlags( ENTERED );
887 view()->Hide( m_enteredGroup, false );
889
890 if( aSelectGroup )
891 {
893 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
894 }
895
896 m_enteredGroupOverlay.Clear();
897 m_enteredGroup = nullptr;
899
900 SetGroupEditModeActive( false );
901}
902
903
908
909
911{
912 bool selectionEmpty = m_selection.Empty();
913 m_selection.SetIsHover( selectionEmpty );
914 m_lockedItemsFiltered = false;
915
916 if( selectionEmpty )
917 {
918 m_toolMgr->RunAction( ACTIONS::selectionCursor, aClientFilter );
919 m_selection.ClearReferencePoint();
920 }
921
922 if( aClientFilter )
923 {
924 enum DISPOSITION { BEFORE = 1, AFTER, BOTH };
925
926 std::map<EDA_ITEM*, DISPOSITION> itemDispositions;
928 GENERAL_COLLECTOR collector;
929
930 collector.SetGuide( &guide );
931
932 for( EDA_ITEM* item : m_selection )
933 {
934 collector.Append( item );
935 itemDispositions[ item ] = BEFORE;
936 }
937
938 aClientFilter( VECTOR2I(), collector, this );
939
940 // Locked items were filtered with Override locks off. Keep the selection and return an
941 // empty one so the action does nothing. The banner then prompts to enable the override.
943 {
944 m_frame->GetCanvas()->ForceRefresh();
945 m_blockedSelection.Clear();
946 return m_blockedSelection;
947 }
948
949 for( EDA_ITEM* item : collector )
950 {
951 if( itemDispositions.count( item ) )
952 itemDispositions[ item ] = BOTH;
953 else
954 itemDispositions[ item ] = AFTER;
955 }
956
957 // Unhighlight the BEFORE items before highlighting the AFTER items.
958 // This is so that in the case of groups, if aClientFilter replaces a selection
959 // with the enclosing group, the unhighlight of the element doesn't undo the
960 // recursive highlighting of that element by the group.
961
962 for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
963 {
964 EDA_ITEM* item = itemDisposition.first;
965 DISPOSITION disposition = itemDisposition.second;
966
967 if( disposition == BEFORE )
969 }
970
971 for( std::pair<EDA_ITEM* const, DISPOSITION> itemDisposition : itemDispositions )
972 {
973 EDA_ITEM* item = itemDisposition.first;
974 DISPOSITION disposition = itemDisposition.second;
975
976 // Note that we must re-highlight even previously-highlighted items
977 // (ie: disposition BOTH) in case we removed any of their children.
978 if( disposition == AFTER || disposition == BOTH )
979 highlight( item, SELECTED, &m_selection );
980 }
981
982 m_frame->GetCanvas()->ForceRefresh();
983 }
984
985 return m_selection;
986}
987
988
990{
991 GENERAL_COLLECTORS_GUIDE guide( board()->GetVisibleLayers(), (PCB_LAYER_ID) view()->GetTopLayer(),
992 view() );
993
994 bool padsDisabled = !board()->IsElementVisible( LAYER_PADS );
995
996 // account for the globals
997 guide.SetIgnoreFPTextOnBack( !board()->IsElementVisible( LAYER_FP_TEXT ) );
998 guide.SetIgnoreFPTextOnFront( !board()->IsElementVisible( LAYER_FP_TEXT ) );
999 guide.SetIgnoreFootprintsOnBack( !board()->IsElementVisible( LAYER_FOOTPRINTS_BK ) );
1000 guide.SetIgnoreFootprintsOnFront( !board()->IsElementVisible( LAYER_FOOTPRINTS_FR ) );
1001 guide.SetIgnorePadsOnBack( padsDisabled );
1002 guide.SetIgnorePadsOnFront( padsDisabled );
1003 guide.SetIgnoreThroughHolePads( padsDisabled );
1004 guide.SetIgnoreFPValues( !board()->IsElementVisible( LAYER_FP_VALUES ) );
1005 guide.SetIgnoreFPReferences( !board()->IsElementVisible( LAYER_FP_REFERENCES ) );
1006 guide.SetIgnoreThroughVias( ! board()->IsElementVisible( LAYER_VIAS ) );
1007 guide.SetIgnoreBlindBuriedVias( ! board()->IsElementVisible( LAYER_VIAS ) );
1008 guide.SetIgnoreMicroVias( ! board()->IsElementVisible( LAYER_VIAS ) );
1009 guide.SetIgnoreTracks( ! board()->IsElementVisible( LAYER_TRACKS ) );
1010
1011 return guide;
1012}
1013
1014
1016{
1017 return m_frame && m_frame->GetPcbNewSettings() && m_frame->GetPcbNewSettings()->m_CtrlClickHighlight && !m_isFootprintEditor;
1018}
1019
1020
1021bool PCB_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, bool* aSelectionCancelledFlag,
1022 CLIENT_SELECTION_FILTER aClientFilter )
1023{
1024 GENERAL_COLLECTOR collector;
1026 POINT_COLLECT options;
1027
1028 rejected.SetAll( false );
1029 options.m_OnDrag = aOnDrag;
1030 options.m_SelectedOnly = m_subtractive;
1031 options.m_Rejected = &rejected;
1032
1033 if( m_enteredGroup && !m_enteredGroup->GetBoundingBox().Contains( aWhere ) )
1034 ExitGroup();
1035
1036 m_selection.ClearReferencePoint();
1037
1038 if( !collectAtPoint( aWhere, collector, options, aClientFilter ) )
1039 return false;
1040
1041 // Nothing survived a filter that had something to take. Every step after it leaves an
1042 // empty collector alone, so this reads the same here as it did before them.
1043 if( collector.GetCount() == 0 && options.m_PreFilterCount > 0 )
1044 {
1045 if( PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame ) )
1046 editFrame->HighlightSelectionFilter( rejected );
1047
1048 if( !m_additive && !m_subtractive && !m_exclusive_or && m_selection.GetSize() > 0 )
1049 {
1050 ClearSelection( true /*quiet mode*/ );
1051 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1052 }
1053
1054 return false;
1055 }
1056
1057 // If still more than one item we're going to have to ask the user.
1058 if( collector.GetCount() > 1 )
1059 {
1060 bool shutdown = aOnDrag && !Wait( TOOL_EVENT( TC_ANY, TA_MOUSE_UP, BUT_LEFT ) );
1061
1062 if( shutdown || !doSelectionMenu( &collector ) )
1063 {
1064 if( aSelectionCancelledFlag )
1065 *aSelectionCancelledFlag = true;
1066
1067 return false;
1068 }
1069 }
1070
1071 int addedCount = 0;
1072 bool anySubtracted = false;
1073
1075 {
1076 if( m_selection.GetSize() > 0 )
1077 {
1078 ClearSelection( true /*quiet mode*/ );
1079 anySubtracted = true;
1080 }
1081 }
1082
1083 if( collector.GetCount() > 0 )
1084 {
1085 for( int i = 0; i < collector.GetCount(); ++i )
1086 {
1087 if( m_subtractive || ( m_exclusive_or && collector[i]->IsSelected() ) )
1088 {
1089 unselect( collector[i] );
1090 anySubtracted = true;
1091 }
1092 else
1093 {
1094 select( collector[i] );
1095 addedCount++;
1096 }
1097 }
1098 }
1099
1100 if( addedCount == 1 )
1101 {
1102 m_toolMgr->ProcessEvent( EVENTS::PointSelectedEvent );
1103 return true;
1104 }
1105 else if( addedCount > 1 )
1106 {
1107 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1108 return true;
1109 }
1110 else if( anySubtracted )
1111 {
1112 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1113 return true;
1114 }
1115
1116 return false;
1117}
1118
1119
1120bool PCB_SELECTION_TOOL::selectCursor( bool aForceSelect, CLIENT_SELECTION_FILTER aClientFilter )
1121{
1122 if( aForceSelect || m_selection.Empty() )
1123 {
1124 ClearSelection( true /*quiet mode*/ );
1125 selectPoint( getViewControls()->GetCursorPosition( false ), false, nullptr, aClientFilter );
1126 }
1127
1128 return !m_selection.Empty();
1129}
1130
1131
1132// Some navigation actions are allowed in selectMultiple
1143
1144
1145static void passEvent( TOOL_EVENT* const aEvent, const TOOL_ACTION* const aAllowedActions[] )
1146{
1147 for( int i = 0; aAllowedActions[i]; ++i )
1148 {
1149 if( aEvent->IsAction( aAllowedActions[i] ) )
1150 {
1151 aEvent->SetPassEvent();
1152 break;
1153 }
1154 }
1155}
1156
1157
1159{
1160 for( PCB_TABLECELL* cell : aTable->GetCells() )
1161 {
1162 if( cell->IsSelected() )
1163 cell->SetFlags( CANDIDATE );
1164 else
1165 cell->ClearFlags( CANDIDATE );
1166 }
1167}
1168
1169
1171 PCB_TABLE* aTable )
1172{
1173 BOX2I selectionRect( aStart, aEnd );
1174 selectionRect.Normalize();
1175
1176 auto wasSelected =
1177 []( EDA_ITEM* aItem )
1178 {
1179 return ( aItem->GetFlags() & CANDIDATE ) > 0;
1180 };
1181
1182 for( PCB_TABLECELL* cell : aTable->GetCells() )
1183 {
1184 bool doSelect = false;
1185
1186 if( cell->HitTest( selectionRect, false ) )
1187 {
1188 if( m_subtractive )
1189 doSelect = false;
1190 else if( m_exclusive_or )
1191 doSelect = !wasSelected( cell );
1192 else
1193 doSelect = true;
1194 }
1195 else if( wasSelected( cell ) )
1196 {
1197 doSelect = m_additive || m_subtractive || m_exclusive_or;
1198 }
1199
1200 if( doSelect && !cell->IsSelected() )
1201 select( cell );
1202 else if( !doSelect && cell->IsSelected() )
1203 unselect( cell );
1204 }
1205}
1206
1207
1209{
1210 if( !m_additive || m_selection.GetSize() == 0
1211 || !dynamic_cast<PCB_TABLECELL*>( m_selection.GetItem( 0 ) ) )
1212 {
1213 return false;
1214 }
1215
1216 GENERAL_COLLECTOR clickCells;
1217 collectTableCellsAt( aPosition, clickCells );
1218
1219 if( clickCells.GetCount() != 1 )
1220 return false;
1221
1222 PCB_TABLECELL* clickedCell = static_cast<PCB_TABLECELL*>( clickCells[0] );
1223 PCB_TABLECELL* firstCell = static_cast<PCB_TABLECELL*>( m_selection.GetItem( 0 ) );
1224 PCB_TABLE* parentTable = static_cast<PCB_TABLE*>( clickedCell->GetParent() );
1225
1226 // Drop the cached anchor when the selection no longer holds only cells of the
1227 // clicked table, so it cannot survive into a later shift+drag on a different table.
1228 for( EDA_ITEM* item : m_selection )
1229 {
1230 if( !dynamic_cast<PCB_TABLECELL*>( item ) || item->GetParent() != parentTable )
1231 {
1232 m_previousFirstCell = nullptr;
1233 return false;
1234 }
1235 }
1236
1237 // Contains() prevents reading GetCenter() on a cell freed by an external mutation
1238 // that did not clear the cached anchor.
1240 m_previousFirstCell = firstCell;
1241
1242 if( m_previousFirstCell->GetParent() != parentTable )
1243 {
1244 m_previousFirstCell = nullptr;
1245 return false;
1246 }
1247
1248 // Snapshot the prior selection so we can fire SelectedEvent/UnselectedEvent based
1249 // on the net delta rather than on every range change.
1250 std::set<EDA_ITEM*> previousSelection;
1251
1252 for( EDA_ITEM* item : m_selection )
1253 previousSelection.insert( item );
1254
1255 // Restore main-view visibility of the previously-selected cells via the overlay
1256 // mechanism; ClearSelected() alone would leave them hidden because
1257 // highlightInternal/unhighlightInternal toggle view()->Hide.
1258 while( m_selection.GetSize() )
1259 unselect( m_selection.Front() );
1260
1261 initializeTableCellSelectionState( parentTable );
1262
1263 VECTOR2D start = m_previousFirstCell->GetCenter();
1264 VECTOR2D end = clickedCell->GetCenter();
1265 VECTOR2D topLeft( std::min( start.x, end.x ), std::min( start.y, end.y ) );
1266 VECTOR2D bottomRight( std::max( start.x, end.x ), std::max( start.y, end.y ) );
1267
1268 selectCellsBetween( topLeft, bottomRight - topLeft, parentTable );
1269
1270 bool anyAdded = false;
1271 bool anySubtracted = false;
1272
1273 for( PCB_TABLECELL* cell : parentTable->GetCells() )
1274 {
1275 bool wasInPrevious = previousSelection.count( cell ) > 0;
1276
1277 if( cell->IsSelected() && !wasInPrevious )
1278 anyAdded = true;
1279 else if( wasInPrevious && !cell->IsSelected() )
1280 anySubtracted = true;
1281 }
1282
1283 if( anyAdded )
1284 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1285
1286 if( anySubtracted )
1287 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1288
1289 return true;
1290}
1291
1292
1294 GENERAL_COLLECTOR& aCollector )
1295{
1297 ? static_cast<BOARD_ITEM*>( board()->GetFirstFootprint() )
1298 : static_cast<BOARD_ITEM*>( board() );
1299
1300 aCollector.Collect( scope, { PCB_TABLECELL_T }, aPosition, getCollectorsGuide() );
1301}
1302
1303
1305{
1306 if( m_selection.GetSize() != 1 )
1307 return nullptr;
1308
1309 return dynamic_cast<PCB_TABLECELL*>( m_selection.GetItem( 0 ) );
1310}
1311
1312
1314{
1315 if( m_selection.GetSize() == 0 )
1316 return false;
1317
1318 PCB_TABLECELL* firstCell = dynamic_cast<PCB_TABLECELL*>( m_selection.GetItem( 0 ) );
1319
1320 if( !firstCell )
1321 return false;
1322
1323 // Suppress highlightNet only when every selected item is a cell of the same table;
1324 // a mixed selection must fall through to the usual Ctrl+click action.
1325 PCB_TABLE* selectedTable = static_cast<PCB_TABLE*>( firstCell->GetParent() );
1326
1327 for( EDA_ITEM* item : m_selection )
1328 {
1329 PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item );
1330
1331 if( !cell || cell->GetParent() != selectedTable )
1332 return false;
1333 }
1334
1335 GENERAL_COLLECTOR clickCells;
1336 collectTableCellsAt( aPosition, clickCells );
1337
1338 if( clickCells.GetCount() != 1 )
1339 return false;
1340
1341 PCB_TABLECELL* clickedCell = static_cast<PCB_TABLECELL*>( clickCells[0] );
1342
1343 if( clickedCell->GetParent() != selectedTable )
1344 return false;
1345
1346 if( clickedCell->IsSelected() )
1347 {
1348 unselect( clickedCell );
1349 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1350 }
1351 else
1352 {
1353 select( clickedCell );
1354 m_toolMgr->ProcessEvent( EVENTS::PointSelectedEvent );
1355 }
1356
1357 // A toggle breaks the contiguous-rectangle invariant the anchor represents.
1358 m_previousFirstCell = nullptr;
1359
1360 return true;
1361}
1362
1363
1365{
1366 bool cancelled = false; // Was the tool canceled while it was running?
1367 m_inSelectMultiple = true; // Multiple selection mode is active
1368
1369 // Shift+click can jitter into IsDrag, collapsing DragOrigin..Position to the press
1370 // point; honour the cached anchor instead. Snapshot its coordinate so the drag loop
1371 // never dereferences a cell that an external mutation could free underneath us.
1372 bool haveAnchorStart = false;
1373 VECTOR2D anchorStart;
1374
1376 && m_previousFirstCell->GetParent() == aTable )
1377 {
1378 anchorStart = VECTOR2D( m_previousFirstCell->GetCenter() );
1379 haveAnchorStart = true;
1380 }
1381 else if( m_previousFirstCell && !m_selection.Contains( m_previousFirstCell ) )
1382 {
1383 m_previousFirstCell = nullptr;
1384 }
1385
1387
1388 auto wasSelected =
1389 []( EDA_ITEM* aItem )
1390 {
1391 return ( aItem->GetFlags() & CANDIDATE ) > 0;
1392 };
1393
1394 while( TOOL_EVENT* evt = Wait() )
1395 {
1396 if( evt->IsCancelInteractive() || evt->IsActivate() )
1397 {
1398 cancelled = true;
1399 break;
1400 }
1401 else if( evt->IsDrag( BUT_LEFT ) )
1402 {
1403 getViewControls()->SetAutoPan( true );
1404
1405 VECTOR2D start = haveAnchorStart ? anchorStart : VECTOR2D( evt->DragOrigin() );
1406 VECTOR2D end = VECTOR2D( evt->Position() );
1407
1408 selectCellsBetween( start, end - start, aTable );
1409 }
1410 else if( evt->IsMouseUp( BUT_LEFT ) )
1411 {
1412 m_selection.SetIsHover( false );
1413
1414 bool anyAdded = false;
1415 bool anySubtracted = false;
1416
1417 for( PCB_TABLECELL* cell : aTable->GetCells() )
1418 {
1419 if( cell->IsSelected() && !wasSelected( cell ) )
1420 anyAdded = true;
1421 else if( wasSelected( cell ) && !cell->IsSelected() )
1422 anySubtracted = true;
1423 }
1424
1425 // Inform other potentially interested tools
1426 if( anyAdded )
1427 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1428
1429 if( anySubtracted )
1430 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1431
1432 break; // Stop waiting for events
1433 }
1434 else
1435 {
1436 // Allow some actions for navigation
1437 passEvent( evt, allowedActions );
1438 }
1439 }
1440
1441 getViewControls()->SetAutoPan( false );
1442
1443 m_inSelectMultiple = false; // Multiple selection mode is inactive
1444
1445 if( !cancelled )
1446 m_selection.ClearReferencePoint();
1447
1448 return cancelled;
1449}
1450
1451
1453{
1454 return DragSelectionArea( *this );
1455}
1456
1457
1459{
1460 bool cancelled = false; // Was the tool canceled while it was running?
1461 m_inSelectMultiple = true; // Multiple selection mode is active
1463
1465 view->Add( &area );
1466
1467 while( TOOL_EVENT* evt = aTool.Wait() )
1468 {
1469 // Main() is not pumping events while another tool drives this loop. Track modifiers
1470 // here. On our own path Main() is awake and already latched them from the drag. Per
1471 // event there would drop a modifier released before the button. Command events carry
1472 // none.
1473 if( &aTool != this )
1474 setModifiersState( evt->Modifier( MD_SHIFT ), evt->Modifier( MD_CTRL ), evt->Modifier( MD_ALT ) );
1475
1476 /* Selection mode depends on direction of drag-selection:
1477 * Left > Right : Select objects that are fully enclosed by selection
1478 * Right > Left : Select objects that are crossed by selection
1479 */
1480 bool greedySelection = area.GetEnd().x < area.GetOrigin().x;
1481
1482 if( view->IsMirroredX() )
1483 greedySelection = !greedySelection;
1484
1485 m_frame->GetCanvas()->SetCurrentCursor( !greedySelection ? KICURSOR::SELECT_WINDOW
1487
1488 if( evt->IsCancelInteractive() || evt->IsActivate() )
1489 {
1490 cancelled = true;
1491 break;
1492 }
1493
1494 if( evt->IsDrag( BUT_LEFT ) )
1495 {
1497 {
1498 if( m_selection.GetSize() > 0 )
1499 {
1500 ClearSelection( true /*quiet mode*/ );
1501 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1502 }
1503 }
1504
1505 // Start drawing a selection box
1506 area.SetOrigin( evt->DragOrigin() );
1507 area.SetEnd( evt->Position() );
1510 area.SetExclusiveOr( false );
1512
1513 view->SetVisible( &area, true );
1514 view->Update( &area );
1515 getViewControls()->SetAutoPan( true );
1516
1517 if( aPreview )
1518 aPreview( area );
1519 }
1520
1521 if( evt->IsMouseUp( BUT_LEFT ) )
1522 {
1523 getViewControls()->SetAutoPan( false );
1524
1525 // End drawing the selection box
1526 view->SetVisible( &area, false );
1527
1529
1530 break; // Stop waiting for events
1531 }
1532
1533 // Allow some actions for navigation
1534 passEvent( evt, allowedActions );
1535 }
1536
1537 getViewControls()->SetAutoPan( false );
1538
1539 // Stop drawing the selection box
1540 view->Remove( &area );
1541 m_inSelectMultiple = false; // Multiple selection mode is inactive
1542
1543 if( !cancelled )
1544 m_selection.ClearReferencePoint();
1545
1547
1548 return cancelled;
1549}
1550
1551
1553{
1555 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SELECT_LASSO );
1556
1557 // This activation just cancels the tool on the stack. With an empty stack it would
1558 // cancel the point editor and clear the selection instead, and the anchor point
1559 // gesture needs both kept
1560 if( !keepsBlockHandles() )
1561 m_toolMgr->PostAction( ACTIONS::selectionTool );
1562
1563 return 0; // No need to wait for an event, just set the mode
1564}
1565
1566
1568{
1570 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1571
1572 if( !keepsBlockHandles() )
1573 m_toolMgr->PostAction( ACTIONS::selectionTool );
1574
1575 return 0; // No need to wait for an event, just set the mode
1576}
1577
1578
1580{
1581 bool cancelled = false; // Was the tool canceled while it was running?
1582
1584 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SELECT_LASSO );
1585
1586
1587 SHAPE_LINE_CHAIN points;
1588 points.SetClosed( true );
1589
1591 getView()->Add( &area );
1592 getView()->SetVisible( &area, true );
1593 getViewControls()->SetAutoPan( true );
1594
1595 while( TOOL_EVENT* evt = Wait() )
1596 {
1597 // Auto mode: clockwise = inside, counterclockwise = touching
1598 double shapeArea = area.GetPoly().Area( false );
1599 bool isClockwise = shapeArea > 0 ? true : false;
1600
1601 if( getView()->IsMirroredX() && shapeArea != 0 )
1602 isClockwise = !isClockwise;
1603
1604 selectionMode = isClockwise ? SELECTION_MODE::INSIDE_LASSO : SELECTION_MODE::TOUCHING_LASSO;
1605
1606 if( evt->IsCancelInteractive() || evt->IsActivate() )
1607 {
1608 cancelled = true;
1609 evt->SetPassEvent( false );
1610 break;
1611 }
1612 else if( evt->IsDrag( BUT_LEFT )
1613 || evt->IsClick( BUT_LEFT )
1614 || evt->IsAction( &ACTIONS::cursorClick ) )
1615 {
1616 points.Append( evt->Position() );
1617 }
1618 else if( evt->IsDblClick( BUT_LEFT )
1619 || evt->IsAction( &ACTIONS::cursorDblClick )
1620 || evt->IsAction( &ACTIONS::finishInteractive ) )
1621 {
1622 area.GetPoly().GenerateBBoxCache();
1624 evt->SetPassEvent( false );
1625 break;
1626 }
1627 else if( evt->IsAction( &ACTIONS::deleteLastPoint )
1628 || evt->IsAction( &ACTIONS::doDelete )
1629 || evt->IsAction( &ACTIONS::undo ) )
1630 {
1631 if( points.GetPointCount() > 0 )
1632 {
1634 points.Remove( points.GetPointCount() - 1 );
1635 }
1636 }
1637 else
1638 {
1639 // Allow navigation actions
1640 passEvent( evt, allowedActions );
1641 }
1642
1643 if( points.PointCount() > 0 )
1644 {
1646 {
1647 if( m_selection.GetSize() > 0 )
1648 {
1649 ClearSelection( true /*quiet mode*/ );
1650 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1651 }
1652 }
1653 }
1654
1655 area.SetPoly( points );
1656 area.GetPoly().Append( m_toolMgr->GetMousePosition() );
1657 area.SetAdditive( m_additive );
1659 area.SetExclusiveOr( false );
1660 area.SetMode( selectionMode );
1661 getView()->Update( &area );
1662 }
1663
1664 getViewControls()->SetAutoPan( false );
1665 getView()->SetVisible( &area, false );
1666 getView()->Remove( &area );
1667 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1668
1669 if( !cancelled )
1671
1673
1674 return cancelled;
1675}
1676
1677
1679 POINT_COLLECT& aOptions, CLIENT_SELECTION_FILTER aClientFilter )
1680{
1682 const PCB_DISPLAY_OPTIONS& displayOpts = m_frame->GetDisplayOptions();
1683
1684 // Without this a zone's fill answers for every point inside it, and nothing on top of a
1685 // zone can ever be picked.
1687
1690 aWhere, guide );
1691
1692 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1693 {
1694 if( !Selectable( aCollector[i] ) || ( aOptions.m_OnDrag && aCollector[i]->IsLocked() ) )
1695 aCollector.Remove( i );
1696 }
1697
1698 aOptions.m_PreFilterCount = aCollector.GetCount();
1699
1700 FilterCollectedItems( aCollector, false, aOptions.m_Rejected );
1701
1702 // Narrow to what the caller can use before the heuristics run, so that they choose among
1703 // usable items rather than picking one the caller then has to throw away.
1704 if( aClientFilter )
1705 aClientFilter( aWhere, aCollector, this );
1706
1707 FilterCollectorForHierarchy( aCollector, false );
1708 FilterCollectorForFootprints( aCollector, aWhere );
1709
1710 if( aOptions.m_SelectedOnly )
1711 {
1712 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1713 {
1714 if( !aCollector[i]->IsSelected() )
1715 aCollector.Remove( i );
1716 }
1717 }
1718
1719 // Apply some ugly heuristics to avoid disambiguation menus whenever possible
1720 if( aCollector.GetCount() > 1 && !m_skip_heuristics )
1721 {
1722 try
1723 {
1724 GuessSelectionCandidates( aCollector, aWhere );
1725 }
1726 catch( const std::exception& exc )
1727 {
1728 wxLogWarning( wxS( "Exception '%s' occurred attempting to guess selection candidates." ),
1729 exc.what() );
1730 return false;
1731 }
1732 }
1733
1734 return true;
1735}
1736
1737
1738std::vector<BOARD_ITEM*> PCB_SELECTION_TOOL::CollectPoint( const VECTOR2I& aWhere,
1739 CLIENT_SELECTION_FILTER aClientFilter )
1740{
1741 GENERAL_COLLECTOR collector;
1742 POINT_COLLECT options;
1743
1744 // A hover shows what it can even when the heuristics gave up narrowing.
1745 collectAtPoint( aWhere, collector, options, aClientFilter );
1746
1747 std::vector<BOARD_ITEM*> items;
1748
1749 for( int i = 0; i < collector.GetCount(); ++i )
1750 items.push_back( collector[i] );
1751
1752 return items;
1753}
1754
1755
1757{
1759
1760 SELECTION_MODE selectionMode = aArea.GetMode();
1761 bool containedMode = ( selectionMode == SELECTION_MODE::INSIDE_RECTANGLE
1762 || selectionMode == SELECTION_MODE::INSIDE_LASSO ) ? true : false;
1763 bool boxMode = ( selectionMode == SELECTION_MODE::INSIDE_RECTANGLE
1764 || selectionMode == SELECTION_MODE::TOUCHING_RECTANGLE ) ? true : false;
1765
1766 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> candidates;
1767 BOX2I selectionBox = aArea.ViewBBox();
1768 view->Query( selectionBox, candidates ); // Get the list of nearby items
1769
1770 GENERAL_COLLECTOR collector;
1771 GENERAL_COLLECTOR padsCollector;
1772 std::set<EDA_ITEM*> group_items;
1773
1774 for( PCB_GROUP* group : board()->Groups() )
1775 {
1776 // The currently entered group does not get limited
1777 if( m_enteredGroup == group )
1778 continue;
1779
1780 std::unordered_set<EDA_ITEM*>& newset = group->GetItems();
1781
1782 auto boxContained =
1783 [&]( const BOX2I& aBox )
1784 {
1785 return boxMode ? selectionBox.Contains( aBox )
1786 : KIGEOM::BoxHitTest( aArea.GetPoly(), aBox, true );
1787 };
1788
1789 // If we are not greedy and have selected the whole group, add just one item
1790 // to allow it to be promoted to the group later
1791 if( containedMode && boxContained( group->GetBoundingBox() ) && newset.size() )
1792 {
1793 for( EDA_ITEM* group_item : newset )
1794 {
1795 if( !group_item->IsBOARD_ITEM() )
1796 continue;
1797
1798 if( Selectable( static_cast<BOARD_ITEM*>( group_item ) ) )
1799 collector.Append( *newset.begin() );
1800 }
1801 }
1802
1803 for( EDA_ITEM* group_item : newset )
1804 group_items.emplace( group_item );
1805 }
1806
1807 auto hitTest =
1808 [&]( const EDA_ITEM* aItem )
1809 {
1810 return boxMode ? aItem->HitTest( selectionBox, containedMode )
1811 : aItem->HitTest( aArea.GetPoly(), containedMode );
1812 };
1813
1814 for( const auto& [item, layer] : candidates )
1815 {
1816 if( !item->IsBOARD_ITEM() )
1817 continue;
1818
1819 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
1820
1821 if( Selectable( boardItem ) && hitTest( boardItem )
1822 && ( !containedMode || !group_items.count( boardItem ) ) )
1823 {
1824 if( boardItem->Type() == PCB_PAD_T && !m_isFootprintEditor )
1825 padsCollector.Append( boardItem );
1826 else
1827 collector.Append( boardItem );
1828 }
1829 }
1830
1831 // Apply the stateful filter
1832 FilterCollectedItems( collector, true, nullptr );
1833
1834 FilterCollectorForHierarchy( collector, true );
1835
1836 // If we selected nothing but pads, allow them to be selected
1837 if( collector.GetCount() == 0 )
1838 {
1839 collector = padsCollector;
1840 FilterCollectedItems( collector, true, nullptr );
1841 FilterCollectorForHierarchy( collector, true );
1842 }
1843
1844 // Sort the filtered selection by rows and columns to have a nice default
1845 // for tools that can use it.
1846 std::sort( collector.begin(), collector.end(),
1847 []( EDA_ITEM* a, EDA_ITEM* b )
1848 {
1849 VECTOR2I aPos = a->GetPosition();
1850 VECTOR2I bPos = b->GetPosition();
1851
1852 if( aPos.y == bPos.y )
1853 return aPos.x < bPos.x;
1854
1855 return aPos.y < bPos.y;
1856 } );
1857
1858 std::vector<BOARD_ITEM*> items;
1859
1860 for( EDA_ITEM* i : collector )
1861 {
1862 if( i->IsBOARD_ITEM() )
1863 items.push_back( static_cast<BOARD_ITEM*>( i ) );
1864 }
1865
1866 return items;
1867}
1868
1869
1871 bool aExclusiveOr )
1872{
1873 bool anyAdded = false;
1874 bool anySubtracted = false;
1875
1876 for( BOARD_ITEM* item : CollectMultiple( aArea ) )
1877 {
1878 if( aSubtractive || ( aExclusiveOr && item->IsSelected() ) )
1879 {
1880 unselect( item );
1881 anySubtracted = true;
1882 }
1883 else
1884 {
1885 select( item );
1886 anyAdded = true;
1887 }
1888 }
1889
1890 m_selection.SetIsHover( false );
1891
1892 // Inform other potentially interested tools
1893 if( anyAdded )
1894 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1895 else if( anySubtracted )
1896 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1897}
1898
1899
1901{
1902 wxMouseState keyboardState = wxGetMouseState();
1903
1904 setModifiersState( keyboardState.ShiftDown(), keyboardState.ControlDown(), keyboardState.AltDown() );
1905
1906 m_skip_heuristics = true;
1908 m_skip_heuristics = false;
1909
1910 return 0;
1911}
1912
1913
1914
1916{
1918
1919 selectCursor( false, aClientFilter );
1920
1921 return 0;
1922}
1923
1924
1926{
1928
1929 return 0;
1930}
1931
1932
1934{
1935 GENERAL_COLLECTOR collection;
1936 BOX2I selectionBox;
1937
1938 selectionBox.SetMaximum();
1939
1940 getView()->Query( selectionBox,
1941 [&]( KIGFX::VIEW_ITEM* viewItem ) -> bool
1942 {
1943 if( viewItem->IsBOARD_ITEM() )
1944 {
1945 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( viewItem );
1946
1947 if( item && Selectable( item ) && itemPassesFilter( item, true, nullptr ) )
1948 collection.Append( item );
1949 }
1950
1951 return true;
1952 } );
1953
1954 FilterCollectorForHierarchy( collection, true );
1955
1956 for( EDA_ITEM* item : collection )
1957 select( item );
1958
1959 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1960
1961 m_frame->GetCanvas()->ForceRefresh();
1962
1963 return 0;
1964}
1965
1966
1968{
1969 BOX2I selectionBox;
1970
1971 selectionBox.SetMaximum();
1972
1973 getView()->Query( selectionBox,
1974 [&]( KIGFX::VIEW_ITEM* viewItem ) -> bool
1975 {
1976 if( viewItem->IsBOARD_ITEM() )
1977 {
1978 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( viewItem );
1979
1980 if( item && Selectable( item ) )
1981 unselect( item );
1982 }
1983
1984 return true;
1985 } );
1986
1987 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1988
1989 m_frame->GetCanvas()->ForceRefresh();
1990
1991 return 0;
1992}
1993
1994
1996{
1997 // Narrow the collection down to a single BOARD_CONNECTED_ITEM for each represented net.
1998 // All other items types are removed.
1999 std::set<int> representedNets;
2000
2001 for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2002 {
2003 BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( aCollector[i] );
2004
2005 if( !item )
2006 aCollector.Remove( i );
2007 else if ( representedNets.count( item->GetNetCode() ) )
2008 aCollector.Remove( i );
2009 else
2010 representedNets.insert( item->GetNetCode() );
2011 }
2012}
2013
2014
2016{
2017 std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
2018
2019 // Get all footprints and pads
2020 std::vector<BOARD_CONNECTED_ITEM*> toUnroute;
2021 std::set<EDA_ITEM*> toDelete;
2022
2023 for( EDA_ITEM* item : selectedItems )
2024 {
2025 if( item->Type() == PCB_FOOTPRINT_T )
2026 {
2027 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
2028 toUnroute.push_back( pad );
2029 }
2030 else if( item->Type() == PCB_GENERATOR_T )
2031 {
2032 toDelete.insert( item );
2033
2034 for( BOARD_ITEM* generatedItem : static_cast<PCB_GENERATOR*>( item )->GetBoardItems() )
2035 {
2036 if( BOARD_CONNECTED_ITEM::ClassOf( generatedItem ) )
2037 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( generatedItem ) );
2038 }
2039 }
2040 else if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
2041 {
2042 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
2043 }
2044 }
2045
2046 // Find generators connected to tracks and add their children to toUnroute
2047 // so selectAllConnectedTracks can traverse through meanders
2048 std::set<int> selectedNets;
2049
2050 for( BOARD_CONNECTED_ITEM* item : toUnroute )
2051 if( item->GetNetCode() > 0 )
2052 selectedNets.insert( item->GetNetCode() );
2053
2054 std::set<VECTOR2I> endpointSet;
2055
2056 for( BOARD_CONNECTED_ITEM* item : toUnroute )
2057 {
2058 if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item ) )
2059 {
2060 endpointSet.insert( track->GetStart() );
2061 endpointSet.insert( track->GetEnd() );
2062 }
2063 else if( item->Type() == PCB_VIA_T )
2064 {
2065 endpointSet.insert( item->GetPosition() );
2066 }
2067 else if( item->Type() == PCB_PAD_T )
2068 {
2069 endpointSet.insert( item->GetPosition() );
2070 }
2071 }
2072
2073 bool expanded = true;
2074
2075 while( expanded )
2076 {
2077 expanded = false;
2078
2079 for( PCB_GENERATOR* gen : board()->Generators() )
2080 {
2081 if( toDelete.count( gen ) )
2082 continue;
2083
2084 // Find this generator's external endpoints (meander entry/exit)
2085 std::map<VECTOR2I, int> epCount;
2086
2087 for( BOARD_ITEM* child : gen->GetBoardItems() )
2088 {
2089 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( child );
2090
2091 if( track && selectedNets.count( track->GetNetCode() ) )
2092 {
2093 epCount[track->GetStart()]++;
2094 epCount[track->GetEnd()]++;
2095 }
2096 }
2097
2098 // Check if any external endpoint matches our track endpoints
2099 bool connected = false;
2100
2101 for( auto& [pt, count] : epCount )
2102 {
2103 if( count == 1 && endpointSet.count( pt ) )
2104 {
2105 connected = true;
2106 break;
2107 }
2108 }
2109
2110 if( connected )
2111 {
2112 toDelete.insert( gen );
2113
2114 for( BOARD_ITEM* c : gen->GetBoardItems() )
2115 {
2117 continue;
2118
2119 if( !selectedNets.count( static_cast<BOARD_CONNECTED_ITEM*>( c )->GetNetCode() ) )
2120 continue;
2121
2122 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( c ) );
2123
2124 if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( c ) )
2125 {
2126 endpointSet.insert( track->GetStart() );
2127 endpointSet.insert( track->GetEnd() );
2128 }
2129
2130 expanded = true;
2131 }
2132 }
2133 }
2134 }
2135
2136 // Because selectAllConnectedTracks() use m_filter to collect connected tracks
2137 // to pads, enable filter for these items, regardless the curent filter options
2138 // via filter is not changed, because it can be useful to keep via filter disabled
2139 struct PCB_SELECTION_FILTER_OPTIONS save_filter = m_filter;
2140 m_filter.tracks = true;
2141 m_filter.pads = true;
2142
2143 // Clear selection so we don't delete our footprints/pads
2144 ClearSelection( true );
2145
2146 // Get the tracks on our list of pads, then delete them
2148
2149 BOARD_COMMIT commit( m_toolMgr );
2150 std::set<BOARD_ITEM*> removed;
2151
2152 for( EDA_ITEM* item : m_selection )
2153 {
2154 if( !item->IsBOARD_ITEM() )
2155 continue;
2156
2157 BOARD_ITEM* bi = static_cast<BOARD_ITEM*>( item );
2158
2159 if( bi->Type() == PCB_GENERATOR_T )
2160 toDelete.insert( bi );
2161
2162 commit.Remove( bi );
2163 removed.insert( bi );
2164 }
2165
2166 // Find generators whose children were removed
2167 for( PCB_GENERATOR* gen : board()->Generators() )
2168 {
2169 for( BOARD_ITEM* child : gen->GetBoardItems() )
2170 {
2171 if( removed.count( child ) )
2172 {
2173 toDelete.insert( gen );
2174 break;
2175 }
2176 }
2177 }
2178
2179 for( EDA_ITEM* item : toDelete )
2180 {
2181 if( !item->IsBOARD_ITEM() )
2182 continue;
2183
2184 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
2185
2186 boardItem->RunOnChildren(
2187 [&commit, &removed]( BOARD_ITEM* aItem )
2188 {
2189 if( removed.find( aItem ) == removed.end() )
2190 {
2191 commit.Remove( aItem );
2192 removed.insert( aItem );
2193 }
2194 },
2196
2197 if( removed.find( boardItem ) == removed.end() )
2198 commit.Remove( boardItem );
2199 }
2200
2201 ClearSelection( true );
2202 commit.Push( _( "Unroute Selected" ) );
2203
2204 m_filter = save_filter; // restore current filter options
2205
2206 // Reselect our footprint/pads as they were in our original selection
2207 for( EDA_ITEM* item : selectedItems )
2208 {
2209 if( item->Type() == PCB_FOOTPRINT_T || item->Type() == PCB_PAD_T )
2210 select( item );
2211 }
2212
2213 return 0;
2214}
2215
2216
2218{
2219 std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
2220
2221 // Get all footprints and pads
2222 std::vector<BOARD_CONNECTED_ITEM*> toUnroute;
2223
2224 std::set<EDA_ITEM*> toDelete;
2225
2226 for( EDA_ITEM* item : selectedItems )
2227 {
2228 if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T || item->Type() == PCB_VIA_T )
2229 {
2230 BOARD_ITEM* bi = static_cast<BOARD_ITEM*>( item );
2231 EDA_GROUP* parentGroup = bi->GetParentGroup();
2232
2233 if( parentGroup && parentGroup->AsEdaItem()->Type() == PCB_GENERATOR_T )
2234 {
2235 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parentGroup->AsEdaItem() );
2236
2237 if( !toDelete.count( gen ) )
2238 {
2239 toDelete.insert( gen );
2240
2241 for( BOARD_ITEM* generatedItem : gen->GetBoardItems() )
2242 {
2243 toDelete.insert( generatedItem );
2244
2245 if( BOARD_CONNECTED_ITEM::ClassOf( generatedItem ) )
2246 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( generatedItem ) );
2247 }
2248 }
2249 }
2250 else
2251 {
2252 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
2253 toDelete.insert( item );
2254 }
2255 }
2256 else if( item->Type() == PCB_GENERATOR_T )
2257 {
2258 toDelete.insert( item );
2259
2260 for( BOARD_ITEM* generatedItem : static_cast<PCB_GENERATOR*>( item )->GetBoardItems() )
2261 {
2262 toDelete.insert( generatedItem );
2263
2264 if( BOARD_CONNECTED_ITEM::ClassOf( generatedItem ) )
2265 toUnroute.push_back( static_cast<BOARD_CONNECTED_ITEM*>( generatedItem ) );
2266 }
2267 }
2268 }
2269
2270 // Get the tracks connecting to our starting objects
2273 std::deque<EDA_ITEM*> toSelectAfter;
2274 // This will select the unroute items too, so filter them out
2275 for( EDA_ITEM* item : m_selection.GetItemsSortedByTypeAndXY() )
2276 {
2277 if( !item->IsBOARD_ITEM() )
2278 continue;
2279
2280 if( toDelete.find( item ) == toDelete.end() )
2281 toSelectAfter.push_back( item );
2282 }
2283
2284 BOARD_COMMIT commit( m_toolMgr );
2285 std::set<BOARD_ITEM*> removed;
2286
2287 for( EDA_ITEM* item : toDelete )
2288 {
2289 if( !item->IsBOARD_ITEM() )
2290 continue;
2291
2292 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
2293
2294 if( item->Type() == PCB_GENERATOR_T )
2295 {
2296 boardItem->RunOnChildren(
2297 [&commit, &removed]( BOARD_ITEM* aItem )
2298 {
2299 if( removed.insert( aItem ).second )
2300 commit.Remove( aItem );
2301 },
2303
2304 if( removed.insert( boardItem ).second )
2305 commit.Remove( boardItem );
2306 }
2307 else
2308 {
2309 if( removed.insert( boardItem ).second )
2310 commit.Remove( boardItem );
2311 }
2312 }
2313
2314 commit.Push( _( "Unroute Segment" ) );
2315
2316 // Now our after tracks so the user can continue backing up as desired
2317 ClearSelection( true );
2318
2319 for( EDA_ITEM* item : toSelectAfter )
2320 {
2321 if( !toDelete.count( item ) )
2322 select( item );
2323 }
2324
2325 return 0;
2326}
2327
2328
2330{
2331 // expandConnection will get called no matter whether the user selected a connected item or a
2332 // non-connected shape (graphic on a non-copper layer). The algorithm for expanding to connected
2333 // items is different from graphics, so they need to be handled separately.
2334 unsigned initialCount = 0;
2335
2336 for( const EDA_ITEM* item : m_selection.GetItems() )
2337 {
2338 if( item->Type() == PCB_FOOTPRINT_T
2339 || item->Type() == PCB_GENERATOR_T
2340 || ( static_cast<const BOARD_ITEM*>( item )->IsConnected() ) )
2341 {
2342 initialCount++;
2343 }
2344 }
2345
2346 if( initialCount == 0 )
2347 {
2348 // First, process any graphic shapes we have
2349 std::vector<PCB_SHAPE*> startShapes;
2350
2351 for( EDA_ITEM* item : m_selection.GetItems() )
2352 {
2353 if( isExpandableGraphicShape( item ) )
2354 startShapes.push_back( static_cast<PCB_SHAPE*>( item ) );
2355 }
2356
2357 // If no non-copper shapes; fall back to looking for connected items
2358 if( !startShapes.empty() )
2359 selectAllConnectedShapes( startShapes );
2360 else
2362 }
2363
2364 m_frame->SetStatusText( _( "Select/Expand Connection..." ) );
2365
2366 for( STOP_CONDITION stopCondition : { STOP_AT_JUNCTION, STOP_AT_PAD, STOP_NEVER } )
2367 {
2368 std::deque<EDA_ITEM*> selectedItems = m_selection.GetItems();
2369
2370 for( EDA_ITEM* item : selectedItems )
2371 item->ClearTempFlags();
2372
2373 std::vector<BOARD_CONNECTED_ITEM*> startItems;
2374
2375 for( EDA_ITEM* item : selectedItems )
2376 {
2377 if( item->Type() == PCB_FOOTPRINT_T )
2378 {
2379 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
2380
2381 for( PAD* pad : footprint->Pads() )
2382 startItems.push_back( pad );
2383 }
2384 else if( item->Type() == PCB_GENERATOR_T )
2385 {
2386 for( BOARD_ITEM* generatedItem : static_cast<PCB_GENERATOR*>( item )->GetBoardItems() )
2387 {
2388 if( BOARD_CONNECTED_ITEM::ClassOf( generatedItem ) )
2389 startItems.push_back( static_cast<BOARD_CONNECTED_ITEM*>( generatedItem ) );
2390 }
2391 }
2392 else if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
2393 {
2394 startItems.push_back( static_cast<BOARD_CONNECTED_ITEM*>( item ) );
2395 }
2396 }
2397
2398 selectAllConnectedTracks( startItems, stopCondition );
2399
2400 if( m_selection.GetItems().size() > initialCount )
2401 break;
2402 }
2403
2404 m_frame->SetStatusText( wxEmptyString );
2405
2406 // Inform other potentially interested tools
2407 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
2408
2409 return 0;
2410}
2411
2412
2413void PCB_SELECTION_TOOL::selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
2414 STOP_CONDITION aStopCondition )
2415{
2416 PROF_TIMER refreshTimer;
2417 double refreshIntervalMs = 500; // Refresh display with this interval to indicate progress
2418 int lastSelectionSize = (int) m_selection.GetSize();
2419
2420 auto connectivity = board()->GetConnectivity();
2421
2422 // Don't let expansion select outside an entered group, or select() would ExitGroup mid-walk.
2423 const auto inScope = [this]( BOARD_ITEM* aItem )
2424 {
2426 };
2427
2428 std::set<PAD*> startPadSet;
2429 std::vector<BOARD_CONNECTED_ITEM*> cleanupItems;
2430
2431 for( BOARD_CONNECTED_ITEM* startItem : aStartItems )
2432 {
2433 // Register starting pads
2434 if( startItem->Type() == PCB_PAD_T )
2435 startPadSet.insert( static_cast<PAD*>( startItem ) );
2436
2437 // Select any starting track items
2438 if( startItem->IsType( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T } ) )
2439 {
2440 if( itemPassesFilter( startItem, true ) && inScope( startItem ) )
2441 select( startItem );
2442 }
2443 }
2444
2445 for( BOARD_CONNECTED_ITEM* startItem : aStartItems )
2446 {
2447 std::map<VECTOR2I, std::vector<PCB_TRACK*>> trackMap;
2448 std::map<VECTOR2I, std::vector<PCB_VIA*>> viaMap;
2449 std::map<VECTOR2I, PAD*> padMap;
2450 std::map<VECTOR2I, std::vector<PCB_SHAPE*>> shapeMap;
2451 std::vector<std::pair<VECTOR2I, LSET>> activePts;
2452
2453 if( startItem->HasFlag( SKIP_STRUCT ) ) // Skip already visited items
2454 continue;
2455
2456 auto connectedItems = connectivity->GetConnectedItems( startItem, EXCLUDE_ZONES | IGNORE_NETS );
2457
2458 // Build maps of connected items
2459 for( BOARD_CONNECTED_ITEM* item : connectedItems )
2460 {
2461 switch( item->Type() )
2462 {
2463 case PCB_ARC_T:
2464 case PCB_TRACE_T:
2465 {
2466 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
2467 trackMap[track->GetStart()].push_back( track );
2468 trackMap[track->GetEnd()].push_back( track );
2469 break;
2470 }
2471
2472 case PCB_VIA_T:
2473 {
2474 PCB_VIA* via = static_cast<PCB_VIA*>( item );
2475
2476 // The hops of a stacked microvia stack are coaxial, so one position can hold
2477 // several vias.
2478 viaMap[via->GetStart()].push_back( via );
2479 break;
2480 }
2481
2482 case PCB_PAD_T:
2483 {
2484 PAD* pad = static_cast<PAD*>( item );
2485 padMap[pad->GetPosition()] = pad;
2486 break;
2487 }
2488
2489 case PCB_SHAPE_T:
2490 {
2491 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
2492
2493 for( const auto& point : shape->GetConnectionPoints() )
2494 shapeMap[point].push_back( shape );
2495
2496 break;
2497 }
2498
2499 default:
2500 break;
2501 }
2502 }
2503
2504 // Set up the initial active points
2505 switch( startItem->Type() )
2506 {
2507 case PCB_ARC_T:
2508 case PCB_TRACE_T:
2509 {
2510 PCB_TRACK* track = static_cast<PCB_TRACK*>( startItem );
2511
2512 activePts.push_back( { track->GetStart(), track->GetLayerSet() } );
2513 activePts.push_back( { track->GetEnd(), track->GetLayerSet() } );
2514 break;
2515 }
2516
2517 case PCB_VIA_T:
2518 activePts.push_back( { startItem->GetPosition(), startItem->GetLayerSet() } );
2519 break;
2520
2521 case PCB_PAD_T:
2522 activePts.push_back( { startItem->GetPosition(), startItem->GetLayerSet() } );
2523 break;
2524
2525 case PCB_SHAPE_T:
2526 {
2527 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( startItem );
2528
2529 for( const auto& point : shape->GetConnectionPoints() )
2530 activePts.push_back( { point, startItem->GetLayerSet() } );
2531
2532 break;
2533 }
2534
2535 default:
2536 break;
2537 }
2538
2539 bool expand = true;
2540 int failSafe = 0;
2541
2542 // Iterative push from all active points
2543 while( expand && failSafe++ < 100000 )
2544 {
2545 expand = false;
2546
2547 for( int i = (int) activePts.size() - 1; i >= 0; --i )
2548 {
2549 VECTOR2I pt = activePts[i].first;
2550 LSET layerSetCu = activePts[i].second & LSET::AllCuMask();
2551
2552 PCB_VIA* hitVia = nullptr;
2553
2554 // Prefer an unvisited via so a stack is walked hop by hop.
2555 auto better = [&]( PCB_VIA* aCandidate )
2556 {
2557 return !hitVia || ( hitVia->HasFlag( SKIP_STRUCT ) && !aCandidate->HasFlag( SKIP_STRUCT ) );
2558 };
2559
2560 // An unvisited hit is the best there is, so stop looking for one.
2561 auto settled = [&]()
2562 {
2563 return hitVia && !hitVia->HasFlag( SKIP_STRUCT );
2564 };
2565
2566 // exact position match (common case)
2567 auto exactIt = viaMap.find( pt );
2568
2569 if( exactIt != viaMap.end() )
2570 {
2571 for( PCB_VIA* via : exactIt->second )
2572 {
2573 if( ( via->GetLayerSet() & layerSetCu ).any() && better( via ) )
2574 hitVia = via;
2575
2576 if( settled() )
2577 break;
2578 }
2579 }
2580
2581 if( !hitVia )
2582 {
2583 // off-center VIA connection
2584 for( auto& [pos, vias] : viaMap )
2585 {
2586 for( PCB_VIA* via : vias )
2587 {
2588 if( !( via->GetLayerSet() & layerSetCu ).any() || !better( via ) )
2589 continue;
2590
2591 for( PCB_LAYER_ID layer : LSET( via->GetLayerSet() & layerSetCu ).CuStack() )
2592 {
2593 int radius = via->GetWidth( layer ) / 2;
2594 int64_t radiusSq = static_cast<int64_t>( radius ) * radius;
2595
2596 if( ( pt - pos ).SquaredEuclideanNorm() <= radiusSq )
2597 {
2598 hitVia = via;
2599 break;
2600 }
2601 }
2602
2603 if( settled() )
2604 break;
2605 }
2606
2607 // The walk reaches the next hop by re-opening this position, so there is
2608 // no reason to keep scanning once something covers the point.
2609 if( hitVia )
2610 break;
2611 }
2612 }
2613
2614 auto padIt = padMap.find( pt );
2615
2616 bool gotVia = hitVia != nullptr;
2617 bool gotPad = padIt != padMap.end() && ( padIt->second->GetLayerSet() & layerSetCu ).any();
2618 bool gotNonStartPad = gotPad && ( startPadSet.find( padIt->second ) == startPadSet.end() );
2619
2620 if( gotPad && !itemPassesFilter( padIt->second, true ) )
2621 {
2622 activePts.erase( activePts.begin() + i );
2623 continue;
2624 }
2625
2626 if( gotVia && !itemPassesFilter( hitVia, true ) )
2627 {
2628 activePts.erase( activePts.begin() + i );
2629 continue;
2630 }
2631
2632 if( aStopCondition == STOP_AT_JUNCTION )
2633 {
2634 size_t pt_count = 0;
2635
2636 for( PCB_TRACK* track : trackMap[pt] )
2637 {
2638 if( track->GetStart() != track->GetEnd() && layerSetCu.Contains( track->GetLayer() ) )
2639 pt_count++;
2640 }
2641
2642 if( pt_count > 2 || gotVia || gotNonStartPad )
2643 {
2644 activePts.erase( activePts.begin() + i );
2645 continue;
2646 }
2647 }
2648 else if( aStopCondition == STOP_AT_PAD )
2649 {
2650 if( gotNonStartPad )
2651 {
2652 activePts.erase( activePts.begin() + i );
2653 continue;
2654 }
2655 }
2656
2657 if( gotPad )
2658 {
2659 PAD* pad = padIt->second;
2660
2661 if( !pad->HasFlag( SKIP_STRUCT ) )
2662 {
2663 pad->SetFlags( SKIP_STRUCT );
2664 cleanupItems.push_back( pad );
2665
2666 activePts.push_back( { pad->GetPosition(), pad->GetLayerSet() } );
2667 expand = true;
2668 }
2669 }
2670
2671 for( PCB_TRACK* track : trackMap[pt] )
2672 {
2673 if( !layerSetCu.Contains( track->GetLayer() ) )
2674 continue;
2675
2676 if( !itemPassesFilter( track, true ) )
2677 continue;
2678
2679 if( !track->IsSelected() && inScope( track ) )
2680 select( track );
2681
2682 if( !track->HasFlag( SKIP_STRUCT ) )
2683 {
2684 track->SetFlags( SKIP_STRUCT );
2685 cleanupItems.push_back( track );
2686
2687 if( track->GetStart() == pt )
2688 activePts.push_back( { track->GetEnd(), track->GetLayerSet() } );
2689 else
2690 activePts.push_back( { track->GetStart(), track->GetLayerSet() } );
2691
2692 if( aStopCondition != STOP_AT_SEGMENT )
2693 expand = true;
2694 }
2695 }
2696
2697 for( PCB_SHAPE* shape : shapeMap[pt] )
2698 {
2699 if( !layerSetCu.Contains( shape->GetLayer() ) )
2700 continue;
2701
2702 if( !itemPassesFilter( shape, true ) )
2703 continue;
2704
2705 if( !shape->IsSelected() && inScope( shape ) )
2706 select( shape );
2707
2708 if( !shape->HasFlag( SKIP_STRUCT ) )
2709 {
2710 shape->SetFlags( SKIP_STRUCT );
2711 cleanupItems.push_back( shape );
2712
2713 for( const VECTOR2I& newPoint : shape->GetConnectionPoints() )
2714 {
2715 if( newPoint == pt )
2716 continue;
2717
2718 activePts.push_back( { newPoint, shape->GetLayerSet() } );
2719 }
2720
2721 if( aStopCondition != STOP_AT_SEGMENT )
2722 expand = true;
2723 }
2724 }
2725
2726 if( hitVia )
2727 {
2728 if( !hitVia->IsSelected() && inScope( hitVia ) )
2729 select( hitVia );
2730
2731 if( !hitVia->HasFlag( SKIP_STRUCT ) )
2732 {
2733 hitVia->SetFlags( SKIP_STRUCT );
2734 cleanupItems.push_back( hitVia );
2735
2736 VECTOR2I viaPos = hitVia->GetPosition();
2737
2738 int maxRadius = 0;
2739
2740 for( PCB_LAYER_ID layer : hitVia->GetLayerSet().CuStack() )
2741 maxRadius = std::max( maxRadius, hitVia->GetWidth( layer ) / 2 );
2742
2743 int64_t maxRadiusSq = static_cast<int64_t>( maxRadius ) * maxRadius;
2744
2745 for( auto& [trkPt, tracks] : trackMap )
2746 {
2747 if( ( trkPt - viaPos ).SquaredEuclideanNorm() > maxRadiusSq )
2748 continue;
2749
2750 // Verify point is inside the VIA pad on at least one track layer
2751 bool inside = false;
2752
2753 for( PCB_TRACK* trk : tracks )
2754 {
2755 PCB_LAYER_ID trkLayer = trk->GetLayer();
2756
2757 if( !hitVia->GetLayerSet().Contains( trkLayer ) )
2758 continue;
2759
2760 int r = hitVia->GetWidth( trkLayer ) / 2;
2761 int64_t rSq = static_cast<int64_t>( r ) * r;
2762
2763 if( ( trkPt - viaPos ).SquaredEuclideanNorm() <= rSq )
2764 {
2765 inside = true;
2766 break;
2767 }
2768 }
2769
2770 if( inside )
2771 activePts.push_back( { trkPt, hitVia->GetLayerSet() } );
2772 }
2773
2774 // Re-open this position so the next hop of a stack is found.
2775 activePts.push_back( { viaPos, hitVia->GetLayerSet() } );
2776
2777 if( aStopCondition != STOP_AT_SEGMENT )
2778 expand = true;
2779 }
2780 }
2781
2782 activePts.erase( activePts.begin() + i );
2783 }
2784
2785 // Refresh display for the feel of progress
2786 if( refreshTimer.msecs() >= refreshIntervalMs )
2787 {
2788 if( m_selection.Size() != lastSelectionSize )
2789 {
2790 m_frame->GetCanvas()->ForceRefresh();
2791 lastSelectionSize = m_selection.Size();
2792 }
2793
2794 refreshTimer.Start();
2795 }
2796 }
2797 }
2798
2799 std::set<EDA_ITEM*> toDeselect;
2800 std::set<EDA_ITEM*> toSelect;
2801
2802 // Promote generated members to their PCB_GENERATOR parents. Generators that mark
2803 // their children as individually selectable are exempt.
2804 for( EDA_ITEM* item : m_selection )
2805 {
2806 if( !item->IsBOARD_ITEM() )
2807 continue;
2808
2809 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
2810 EDA_GROUP* parent = boardItem->GetParentGroup();
2811
2812 if( parent && parent->AsEdaItem()->Type() == PCB_GENERATOR_T )
2813 {
2814 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
2815
2817 continue;
2818
2819 toDeselect.insert( item );
2820
2821 if( !parent->AsEdaItem()->IsSelected() )
2822 toSelect.insert( parent->AsEdaItem() );
2823 }
2824 }
2825
2826 for( EDA_ITEM* item : toDeselect )
2827 unselect( item );
2828
2829 for( EDA_ITEM* item : toSelect )
2830 select( item );
2831
2832 for( BOARD_CONNECTED_ITEM* item : cleanupItems )
2833 item->ClearFlags( SKIP_STRUCT );
2834}
2835
2836
2838{
2839 if( aItem->Type() == PCB_SHAPE_T )
2840 {
2841 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
2842
2843 switch( shape->GetShape() )
2844 {
2845 case SHAPE_T::SEGMENT:
2846 case SHAPE_T::ARC:
2847 case SHAPE_T::BEZIER:
2848 return !shape->IsOnCopperLayer();
2849
2850 case SHAPE_T::POLY:
2851 return !shape->IsOnCopperLayer() && !shape->IsClosed();
2852
2853 default:
2854 return false;
2855 }
2856 }
2857
2858 return false;
2859}
2860
2861
2862void PCB_SELECTION_TOOL::selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems )
2863{
2864 std::stack<PCB_SHAPE*> toSearch;
2865 std::set<PCB_SHAPE*> toCleanup;
2866
2867 for( PCB_SHAPE* startItem : aStartItems )
2868 toSearch.push( startItem );
2869
2870 GENERAL_COLLECTOR collector;
2872
2873 auto searchPoint =
2874 [&]( const VECTOR2I& aWhere )
2875 {
2876 collector.Collect( board(), { PCB_SHAPE_T }, aWhere, guide );
2877
2878 for( EDA_ITEM* item : collector )
2879 {
2880 if( isExpandableGraphicShape( item ) )
2881 toSearch.push( static_cast<PCB_SHAPE*>( item ) );
2882 }
2883 };
2884
2885 while( !toSearch.empty() )
2886 {
2887 PCB_SHAPE* shape = toSearch.top();
2888 toSearch.pop();
2889
2890 if( shape->HasFlag( SKIP_STRUCT ) )
2891 continue;
2892
2893 shape->SetFlags( SKIP_STRUCT );
2894 toCleanup.insert( shape );
2895
2896 if( !itemPassesFilter( shape, true ) )
2897 continue;
2898
2899 select( shape );
2900 guide.SetLayerVisibleBits( shape->GetLayerSet() );
2901
2902 searchPoint( shape->GetStart() );
2903 searchPoint( shape->GetEnd() );
2904 }
2905
2906 for( PCB_SHAPE* shape : toCleanup )
2907 shape->ClearFlags( SKIP_STRUCT );
2908}
2909
2910
2912{
2913 // Get all pads
2914 std::vector<PAD*> pads;
2915
2916 for( EDA_ITEM* item : m_selection.GetItems() )
2917 {
2918 if( item->Type() == PCB_FOOTPRINT_T )
2919 {
2920 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
2921 pads.push_back( pad );
2922 }
2923 else if( item->Type() == PCB_PAD_T )
2924 {
2925 pads.push_back( static_cast<PAD*>( item ) );
2926 }
2927 }
2928
2929 // Select every footprint on the end of the ratsnest for each pad in our selection
2930 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
2931
2932 for( PAD* pad : pads )
2933 {
2934 for( const CN_EDGE& edge : conn->GetRatsnestForPad( pad ) )
2935 {
2936 wxCHECK2( edge.GetSourceNode() && !edge.GetSourceNode()->Dirty(), continue );
2937 wxCHECK2( edge.GetTargetNode() && !edge.GetTargetNode()->Dirty(), continue );
2938
2939 BOARD_CONNECTED_ITEM* sourceParent = edge.GetSourceNode()->Parent();
2940 BOARD_CONNECTED_ITEM* targetParent = edge.GetTargetNode()->Parent();
2941
2942 if( sourceParent == pad )
2943 {
2944 if( targetParent->Type() == PCB_PAD_T )
2945 select( static_cast<PAD*>( targetParent )->GetParent() );
2946 }
2947 else if( targetParent == pad )
2948 {
2949 if( sourceParent->Type() == PCB_PAD_T )
2950 select( static_cast<PAD*>( sourceParent )->GetParent() );
2951 }
2952 }
2953 }
2954
2955 return 0;
2956}
2957
2958
2960{
2961 // Get all connected items that can represent the source side of the ratsnest.
2962 std::vector<BOARD_CONNECTED_ITEM*> sourceItems;
2963 std::vector<FOOTPRINT*> nearestFootprints;
2964
2965 for( EDA_ITEM* item : m_selection.GetItems() )
2966 {
2967 if( item->Type() == PCB_FOOTPRINT_T )
2968 {
2969 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
2970 sourceItems.push_back( pad );
2971 }
2972 else if( BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
2973 {
2974 sourceItems.push_back( connItem );
2975 }
2976 }
2977
2978 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
2979 std::shared_ptr<CN_CONNECTIVITY_ALGO> connAlgo = conn->GetConnectivityAlgo();
2980
2981 for( BOARD_CONNECTED_ITEM* sourceItem : sourceItems )
2982 {
2983 RN_NET* net = conn->GetRatsnestForNet( sourceItem->GetNetCode() );
2984
2985 // Need to have something unconnected to grab
2986 if( !net || net->GetEdges().empty() || !connAlgo->ItemExists( sourceItem ) )
2987 continue;
2988
2989 std::vector<std::shared_ptr<CN_CLUSTER>> sourceClusters;
2990
2991 for( CN_ITEM* cnItem : connAlgo->ItemEntry( sourceItem ).GetItems() )
2992 {
2993 for( const std::shared_ptr<CN_ANCHOR>& anchor : cnItem->Anchors() )
2994 {
2995 if( anchor->GetCluster() )
2996 sourceClusters.push_back( anchor->GetCluster() );
2997 }
2998 }
2999
3000 if( sourceClusters.empty() )
3001 continue;
3002
3003 auto isSourceAnchor =
3004 [&]( const std::shared_ptr<const CN_ANCHOR>& aAnchor )
3005 {
3006 if( aAnchor->Parent() == sourceItem )
3007 return true;
3008
3009 return std::find( sourceClusters.begin(), sourceClusters.end(),
3010 aAnchor->GetCluster() ) != sourceClusters.end();
3011 };
3012
3013 double currentDistance = DBL_MAX;
3014 FOOTPRINT* nearest = nullptr;
3015
3016 // Check every ratsnest line for the nearest one
3017 for( const CN_EDGE& edge : net->GetEdges() )
3018 {
3019 const std::shared_ptr<const CN_ANCHOR>& source = edge.GetSourceNode();
3020 const std::shared_ptr<const CN_ANCHOR>& target = edge.GetTargetNode();
3021
3022 wxCHECK2( source && !source->Dirty() && target && !target->Dirty(), continue );
3023
3024 if( source->Parent()->GetParentFootprint() == target->Parent()->GetParentFootprint() )
3025 {
3026 continue; // This edge is a loop on the same footprint
3027 }
3028
3029 bool sourceMatches = isSourceAnchor( source );
3030 bool targetMatches = isSourceAnchor( target );
3031
3032 if( sourceMatches == targetMatches )
3033 continue;
3034
3035 const CN_ANCHOR* other = sourceMatches ? target.get() : source.get();
3036
3037 // We only want to grab footprints, so the ratnest has to point to a pad
3038 if( other->Parent()->Type() != PCB_PAD_T )
3039 continue;
3040
3041 if( edge.GetLength() < currentDistance )
3042 {
3043 currentDistance = edge.GetLength();
3044 nearest = other->Parent()->GetParentFootprint();
3045 }
3046 }
3047
3048 if( nearest != nullptr )
3049 nearestFootprints.push_back( nearest );
3050 }
3051
3052 if( nearestFootprints.empty() )
3053 return 0;
3054
3056
3057 for( FOOTPRINT* footprint : nearestFootprints )
3058 select( footprint );
3059
3061
3062 return 0;
3063}
3064
3065
3066void PCB_SELECTION_TOOL::SelectAllItemsOnNet( int aNetCode, bool aSelect )
3067{
3068 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
3069
3070 for( BOARD_ITEM* item : conn->GetNetItems( aNetCode, { PCB_TRACE_T,
3071 PCB_ARC_T,
3072 PCB_VIA_T,
3073 PCB_SHAPE_T } ) )
3074 {
3075 if( itemPassesFilter( item, true, nullptr ) )
3076 aSelect ? select( item ) : unselect( item );
3077 }
3078}
3079
3080
3082{
3083 bool select = aEvent.IsAction( &PCB_ACTIONS::selectNet );
3084
3085 // If we've been passed an argument, just select that netcode1
3086 int netcode = aEvent.Parameter<int>();
3087
3088 if( netcode > 0 )
3089 {
3090 SelectAllItemsOnNet( netcode, select );
3091
3092 // Inform other potentially interested tools
3093 if( m_selection.Size() > 0 )
3094 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3095 else
3096 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
3097
3098 return 0;
3099 }
3100
3101 if( !selectCursor() )
3102 return 0;
3103
3104 // copy the selection, since we're going to iterate and modify
3105 auto selection = m_selection.GetItems();
3106
3107 for( EDA_ITEM* i : selection )
3108 {
3109 BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
3110
3111 if( connItem )
3112 SelectAllItemsOnNet( connItem->GetNetCode(), select );
3113 }
3114
3115 // Inform other potentially interested tools
3116 if( m_selection.Size() > 0 )
3117 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3118 else
3119 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
3120
3121 return 0;
3122}
3123
3124
3126{
3127 if( !selectCursor() )
3128 return 0;
3129
3130 auto selection = m_selection.GetItems();
3131
3132 for( EDA_ITEM* i : selection )
3133 {
3134 BOARD_CONNECTED_ITEM* connItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( i );
3135
3136 if( !connItem )
3137 continue;
3138
3139 NETINFO_ITEM* netInfo = connItem->GetNet();
3140
3141 if( !netInfo )
3142 continue;
3143
3144 const wxString& chainName = netInfo->GetNetChain();
3145
3146 if( chainName.IsEmpty() )
3147 {
3148 // Net is not part of any chain; fall back to single-net behaviour.
3149 SelectAllItemsOnNet( connItem->GetNetCode(), true );
3150 continue;
3151 }
3152
3153 for( NETINFO_ITEM* candidate : board()->GetNetInfo() )
3154 {
3155 if( candidate && candidate->GetNetChain() == chainName )
3156 SelectAllItemsOnNet( candidate->GetNetCode(), true );
3157 }
3158 }
3159
3160 if( m_selection.Size() > 0 )
3161 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3162 else
3163 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
3164
3165 return 0;
3166}
3167
3168
3170{
3171 std::vector<BOARD_ITEM*> footprints;
3172
3173 // store all footprints that are on that sheet path
3174 for( FOOTPRINT* footprint : board()->Footprints() )
3175 {
3176 if( footprint == nullptr )
3177 continue;
3178
3179 wxString footprint_path = footprint->GetPath().AsString().BeforeLast( '/' );
3180
3181 if( footprint_path.IsEmpty() )
3182 footprint_path += '/';
3183
3184 if( footprint_path == aSheetPath )
3185 footprints.push_back( footprint );
3186 }
3187
3188 for( BOARD_ITEM* i : footprints )
3189 {
3190 if( i != nullptr )
3191 select( i );
3192 }
3193
3194 selectConnections( footprints );
3195}
3196
3197
3198void PCB_SELECTION_TOOL::selectConnections( const std::vector<BOARD_ITEM*>& aItems )
3199{
3200 // Generate a list of all pads, and of all nets they belong to.
3201 std::list<int> netcodeList;
3202 std::vector<BOARD_CONNECTED_ITEM*> padList;
3203
3204 for( BOARD_ITEM* item : aItems )
3205 {
3206 switch( item->Type() )
3207 {
3208 case PCB_FOOTPRINT_T:
3209 {
3210 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
3211 {
3212 if( pad->IsConnected() )
3213 {
3214 netcodeList.push_back( pad->GetNetCode() );
3215 padList.push_back( pad );
3216 }
3217 }
3218
3219 break;
3220 }
3221
3222 case PCB_PAD_T:
3223 {
3224 PAD* pad = static_cast<PAD*>( item );
3225
3226 if( pad->IsConnected() )
3227 {
3228 netcodeList.push_back( pad->GetNetCode() );
3229 padList.push_back( pad );
3230 }
3231
3232 break;
3233 }
3234
3235 default:
3236 break;
3237 }
3238 }
3239
3240 // Sort for binary search
3241 std::sort( padList.begin(), padList.end() );
3242
3243 // remove all duplicates
3244 netcodeList.sort();
3245 netcodeList.unique();
3246
3248
3249 // now we need to find all footprints that are connected to each of these nets then we need
3250 // to determine if these footprints are in the list of footprints
3251 std::vector<int> removeCodeList;
3252 std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
3253
3254 for( int netCode : netcodeList )
3255 {
3256 for( BOARD_CONNECTED_ITEM* pad : conn->GetNetItems( netCode, { PCB_PAD_T } ) )
3257 {
3258 if( !std::binary_search( padList.begin(), padList.end(), pad ) )
3259 {
3260 // if we cannot find the pad in the padList then we can assume that that pad
3261 // should not be used, therefore invalidate this netcode.
3262 removeCodeList.push_back( netCode );
3263 break;
3264 }
3265 }
3266 }
3267
3268 for( int removeCode : removeCodeList )
3269 netcodeList.remove( removeCode );
3270
3271 std::unordered_set<BOARD_ITEM*> localConnectionList;
3272
3273 for( int netCode : netcodeList )
3274 {
3275 for( BOARD_ITEM* item : conn->GetNetItems( netCode, { PCB_TRACE_T,
3276 PCB_ARC_T,
3277 PCB_VIA_T,
3278 PCB_SHAPE_T } ) )
3279 {
3280 localConnectionList.insert( item );
3281 }
3282 }
3283
3284 for( BOARD_ITEM* item : localConnectionList )
3285 select( item );
3286}
3287
3288
3290{
3291 std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
3292
3293 if( items )
3294 doSyncSelection( *items, false );
3295
3296 return 0;
3297}
3298
3299
3301{
3302 std::vector<BOARD_ITEM*>* items = aEvent.Parameter<std::vector<BOARD_ITEM*>*>();
3303
3304 if( items )
3305 doSyncSelection( *items, true );
3306
3307 return 0;
3308}
3309
3310
3311void PCB_SELECTION_TOOL::doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets )
3312{
3313 if( m_selection.Front() && m_selection.Front()->IsMoving() )
3314 return;
3315
3316 // Also check the incoming items. If the cross-probe flash timer cleared the selection
3317 // during a move, Front() would be null but the items are still being actively moved.
3318 for( const BOARD_ITEM* item : aItems )
3319 {
3320 if( item->IsMoving() )
3321 return;
3322 }
3323
3324 ClearSelection( true /*quiet mode*/ );
3325
3326 // Perform individual selection of each item before processing the event.
3327 for( BOARD_ITEM* item : aItems )
3328 select( item );
3329
3330 if( aWithNets )
3331 selectConnections( aItems );
3332
3333 BOX2I bbox = m_selection.GetBoundingBox();
3334
3335 if( bbox.GetWidth() != 0 && bbox.GetHeight() != 0 )
3336 {
3337 if( m_frame->GetPcbNewSettings()->m_CrossProbing.center_on_items )
3338 {
3339 if( m_frame->GetPcbNewSettings()->m_CrossProbing.zoom_to_fit )
3340 ZoomFitCrossProbeBBox( bbox );
3341
3342 m_frame->FocusOnLocation( bbox.Centre() );
3343 }
3344 }
3345
3346 m_frame->GetCanvas()->ForceRefresh();
3347
3348 if( m_selection.Size() > 0 )
3349 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3350}
3351
3352
3354{
3355 ClearSelection( true /*quiet mode*/ );
3356 wxString sheetPath = *aEvent.Parameter<wxString*>();
3357
3358 selectAllItemsOnSheet( sheetPath );
3359
3361
3362 if( m_selection.Size() > 0 )
3363 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3364
3365 return 0;
3366}
3367
3368
3370{
3371 // this function currently only supports footprints since they are only on one sheet.
3372 EDA_ITEM* item = m_selection.Front();
3373
3374 if( !item )
3375 return 0;
3376
3377 if( item->Type() != PCB_FOOTPRINT_T )
3378 return 0;
3379
3380 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
3381
3382 if( !footprint || footprint->GetPath().empty() )
3383 return 0;
3384
3385 ClearSelection( true /*quiet mode*/ );
3386
3387 // get the sheet path only.
3388 wxString sheetPath = footprint->GetPath().AsString().BeforeLast( '/' );
3389
3390 if( sheetPath.IsEmpty() )
3391 sheetPath += '/';
3392
3393 selectAllItemsOnSheet( sheetPath );
3394
3395 // Inform other potentially interested tools
3396 if( m_selection.Size() > 0 )
3397 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3398
3399 return 0;
3400}
3401
3402
3404{
3405 // Should recalculate the view to zoom in on the selection.
3406 BOX2I selectionBox = m_selection.GetBoundingBox();
3408
3409 VECTOR2D screenSize = view->ToWorld( ToVECTOR2D( m_frame->GetCanvas()->GetClientSize() ),
3410 false );
3411 screenSize.x = std::max( 10.0, screenSize.x );
3412 screenSize.y = std::max( 10.0, screenSize.y );
3413
3414 if( selectionBox.GetWidth() != 0 || selectionBox.GetHeight() != 0 )
3415 {
3416 VECTOR2D vsize = selectionBox.GetSize();
3417 double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
3418 fabs( vsize.y / screenSize.y ) );
3419 view->SetScale( scale );
3420 view->SetCenter( selectionBox.Centre() );
3421 view->Add( &m_selection );
3422 }
3423
3424 m_frame->GetCanvas()->ForceRefresh();
3425}
3426
3427
3429{
3430 // Should recalculate the view to zoom in on the bbox.
3432
3433 if( aBBox.GetWidth() == 0 )
3434 return;
3435
3436 BOX2I bbox = aBBox;
3437 bbox.Normalize();
3438
3439 //#define DEFAULT_PCBNEW_CODE // Un-comment for normal full zoom KiCad algorithm
3440#ifdef DEFAULT_PCBNEW_CODE
3441 auto bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
3442 auto screenSize = view->ToWorld( GetCanvas()->GetClientSize(), false );
3443
3444 // The "fabs" on x ensures the right answer when the view is flipped
3445 screenSize.x = std::max( 10.0, fabs( screenSize.x ) );
3446 screenSize.y = std::max( 10.0, screenSize.y );
3447 double ratio = std::max( fabs( bbSize.x / screenSize.x ), fabs( bbSize.y / screenSize.y ) );
3448
3449 // Try not to zoom on every cross-probe; it gets very noisy
3450 if( crossProbingSettings.zoom_to_fit && ( ratio < 0.5 || ratio > 1.0 ) )
3451 view->SetScale( view->GetScale() / ratio );
3452#endif // DEFAULT_PCBNEW_CODE
3453
3454#ifndef DEFAULT_PCBNEW_CODE // Do the scaled zoom
3455 auto bbSize = bbox.Inflate( KiROUND( bbox.GetWidth() * 0.2 ) ).GetSize();
3456 VECTOR2D screenSize = view->ToWorld( ToVECTOR2D( m_frame->GetCanvas()->GetClientSize() ), false );
3457
3458 // This code tries to come up with a zoom factor that doesn't simply zoom in
3459 // to the cross probed component, but instead shows a reasonable amount of the
3460 // circuit around it to provide context. This reduces or eliminates the need
3461 // to manually change the zoom because it's too close.
3462
3463 // Using the default text height as a constant to compare against, use the
3464 // height of the bounding box of visible items for a footprint to figure out
3465 // if this is a big footprint (like a processor) or a small footprint (like a resistor).
3466 // This ratio is not useful by itself as a scaling factor. It must be "bent" to
3467 // provide good scaling at varying component sizes. Bigger components need less
3468 // scaling than small ones.
3469 double currTextHeight = pcbIUScale.mmToIU( DEFAULT_TEXT_SIZE );
3470
3471 double compRatio = bbSize.y / currTextHeight; // Ratio of component to text height
3472
3473 // This will end up as the scaling factor we apply to "ratio".
3474 double compRatioBent = 1.0;
3475
3476 // This is similar to the original KiCad code that scaled the zoom to make sure
3477 // components were visible on screen. It's simply a ratio of screen size to
3478 // component size, and its job is to zoom in to make the component fullscreen.
3479 // Earlier in the code the component BBox is given a 20% margin to add some
3480 // breathing room. We compare the height of this enlarged component bbox to the
3481 // default text height. If a component will end up with the sides clipped, we
3482 // adjust later to make sure it fits on screen.
3483 //
3484 // The "fabs" on x ensures the right answer when the view is flipped
3485 screenSize.x = std::max( 10.0, fabs( screenSize.x ) );
3486 screenSize.y = std::max( 10.0, screenSize.y );
3487 double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
3488
3489 // Original KiCad code for how much to scale the zoom
3490 double kicadRatio = std::max( fabs( bbSize.x / screenSize.x ),
3491 fabs( bbSize.y / screenSize.y ) );
3492
3493 // LUT to scale zoom ratio to provide reasonable schematic context. Must work
3494 // with footprints of varying sizes (e.g. 0402 package and 200 pin BGA).
3495 // "first" is used as the input and "second" as the output
3496 //
3497 // "first" = compRatio (footprint height / default text height)
3498 // "second" = Amount to scale ratio by
3499 std::vector<std::pair<double, double>> lut {
3500 { 1, 8 },
3501 { 1.5, 5 },
3502 { 3, 3 },
3503 { 4.5, 2.5 },
3504 { 8, 2.0 },
3505 { 12, 1.7 },
3506 { 16, 1.5 },
3507 { 24, 1.3 },
3508 { 32, 1.0 },
3509 };
3510
3511
3512 std::vector<std::pair<double, double>>::iterator it;
3513
3514 compRatioBent = lut.back().second; // Large component default
3515
3516 if( compRatio >= lut.front().first )
3517 {
3518 // Use LUT to do linear interpolation of "compRatio" within "first", then
3519 // use that result to linearly interpolate "second" which gives the scaling
3520 // factor needed.
3521
3522 for( it = lut.begin(); it < lut.end() - 1; it++ )
3523 {
3524 if( it->first <= compRatio && next( it )->first >= compRatio )
3525 {
3526 double diffx = compRatio - it->first;
3527 double diffn = next( it )->first - it->first;
3528
3529 compRatioBent = it->second + ( next( it )->second - it->second ) * diffx / diffn;
3530 break; // We have our interpolated value
3531 }
3532 }
3533 }
3534 else
3535 {
3536 compRatioBent = lut.front().second; // Small component default
3537 }
3538
3539 // If the width of the part we're probing is bigger than what the screen width will be
3540 // after the zoom, then punt and use the KiCad zoom algorithm since it guarantees the
3541 // part's width will be encompassed within the screen. This will apply to parts that
3542 // are much wider than they are tall.
3543
3544 if( bbSize.x > screenSize.x * ratio * compRatioBent )
3545 {
3546 // Use standard KiCad zoom algorithm for parts too wide to fit screen/
3547 ratio = kicadRatio;
3548 compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
3549 wxLogTrace( "CROSS_PROBE_SCALE", "Part TOO WIDE for screen. Using normal KiCad zoom ratio: %1.5f", ratio );
3550 }
3551
3552 // Now that "compRatioBent" holds our final scaling factor we apply it to the original
3553 // fullscreen zoom ratio to arrive at the final ratio itself.
3554 ratio *= compRatioBent;
3555
3556 bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
3557
3558 // Try not to zoom on every cross-probe; it gets very noisy
3559 if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
3560 view->SetScale( view->GetScale() / ratio );
3561#endif // ifndef DEFAULT_PCBNEW_CODE
3562}
3563
3564
3566{
3567 bool cleared = false;
3568
3569 if( m_selection.GetSize() > 0 )
3570 {
3571 // Don't fire an event now; most of the time it will be redundant as we're about to
3572 // fire a SelectedEvent.
3573 cleared = true;
3574 ClearSelection( true /*quiet mode*/ );
3575 }
3576
3577 if( aItem )
3578 {
3579 switch( aItem->Type() )
3580 {
3581 case PCB_NETINFO_T:
3582 {
3583 int netCode = static_cast<NETINFO_ITEM*>( aItem )->GetNetCode();
3584
3585 if( netCode > 0 )
3586 {
3587 SelectAllItemsOnNet( netCode, true );
3588 m_frame->FocusOnLocation( aItem->GetCenter() );
3589 }
3590 break;
3591 }
3592
3593 default:
3594 select( aItem );
3595 m_frame->FocusOnLocation( aItem->GetPosition() );
3596 }
3597
3598 // If the item has a bounding box, then zoom out if needed
3599 if( aItem->GetBoundingBox().GetHeight() > 0 && aItem->GetBoundingBox().GetWidth() > 0 )
3600 {
3601 // This adds some margin
3602 double marginFactor = 2;
3603
3604 KIGFX::PCB_VIEW* pcbView = canvas()->GetView();
3605 BOX2D screenBox = pcbView->GetViewport();
3606 VECTOR2D screenSize = screenBox.GetSize();
3607 BOX2I screenRect = BOX2ISafe( screenBox.GetOrigin(), screenSize / marginFactor );
3608
3609 if( !screenRect.Contains( aItem->GetBoundingBox() ) )
3610 {
3611 double scaleX = screenSize.x / static_cast<double>( aItem->GetBoundingBox().GetWidth() );
3612 double scaleY = screenSize.y / static_cast<double>( aItem->GetBoundingBox().GetHeight() );
3613
3614 scaleX /= marginFactor;
3615 scaleY /= marginFactor;
3616
3617 double scale = scaleX > scaleY ? scaleY : scaleX;
3618
3619 if( scale < 1 ) // Don't zoom in, only zoom out
3620 {
3621 pcbView->SetScale( pcbView->GetScale() * ( scale ) );
3622
3623 //Let's refocus because there is an algorithm to avoid dialogs in there.
3624 m_frame->FocusOnLocation( aItem->GetCenter() );
3625 }
3626 }
3627 }
3628 // Inform other potentially interested tools
3629 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3630 }
3631 else if( cleared )
3632 {
3633 m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
3634 }
3635
3636 m_frame->GetCanvas()->ForceRefresh();
3637}
3638
3639
3645static bool itemIsIncludedByFilter( const BOARD_ITEM& aItem, const BOARD& aBoard,
3646 const DIALOG_FILTER_SELECTION::OPTIONS& aFilterOptions )
3647{
3648 switch( aItem.Type() )
3649 {
3650 case PCB_FOOTPRINT_T:
3651 {
3652 const FOOTPRINT& footprint = static_cast<const FOOTPRINT&>( aItem );
3653
3654 return aFilterOptions.includeFootprints && ( aFilterOptions.includeLockedFootprints
3655 || !footprint.IsLocked() );
3656 }
3657
3658 case PCB_TRACE_T:
3659 case PCB_ARC_T:
3660 return aFilterOptions.includeTracks;
3661
3662 case PCB_VIA_T:
3663 return aFilterOptions.includeVias;
3664
3665 case PCB_ZONE_T:
3666 return aFilterOptions.includeZones;
3667
3668 case PCB_SHAPE_T:
3669 case PCB_TARGET_T:
3670 case PCB_DIM_ALIGNED_T:
3671 case PCB_DIM_CENTER_T:
3672 case PCB_DIM_RADIAL_T:
3674 case PCB_DIM_LEADER_T:
3675 if( aItem.GetLayer() == Edge_Cuts )
3676 return aFilterOptions.includeBoardOutlineLayer;
3677 else
3678 return aFilterOptions.includeItemsOnTechLayers;
3679
3680 case PCB_GRID_ITEM_T:
3681 return aFilterOptions.includeItemsOnTechLayers;
3682
3683 case PCB_FIELD_T:
3684 case PCB_TEXT_T:
3685 case PCB_TEXTBOX_T:
3686 case PCB_TABLE_T:
3687 case PCB_DRILL_CHART_T:
3688 case PCB_DRILL_MAP_T:
3690 case PCB_TABLECELL_T:
3691 return aFilterOptions.includePcbTexts;
3692
3693 default:
3694 // Filter dialog is inclusive, not exclusive. If it's not included, then it doesn't
3695 // get selected.
3696 return false;
3697 }
3698}
3699
3700
3702{
3703 const BOARD& board = *getModel<BOARD>();
3704 DIALOG_FILTER_SELECTION::OPTIONS& opts = m_priv->m_filterOpts;
3705 DIALOG_FILTER_SELECTION dlg( m_frame, opts );
3706
3707 const int cmd = dlg.ShowModal();
3708
3709 if( cmd != wxID_OK )
3710 return 0;
3711
3712 // copy current selection
3713 std::deque<EDA_ITEM*> selection = m_selection.GetItems();
3714
3715 ClearSelection( true /*quiet mode*/ );
3716
3717 // re-select items from the saved selection according to the dialog options
3718 for( EDA_ITEM* i : selection )
3719 {
3720 if( !i->IsBOARD_ITEM() )
3721 continue;
3722
3723 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
3724 bool include = itemIsIncludedByFilter( *item, board, opts );
3725
3726 if( include )
3727 select( item );
3728 }
3729
3730 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
3731
3732 return 0;
3733}
3734
3735
3737 PCB_SELECTION_FILTER_OPTIONS* aRejected )
3738{
3739 if( aCollector.GetCount() == 0 )
3740 return;
3741
3742 std::set<BOARD_ITEM*> rejected;
3743
3744 for( EDA_ITEM* i : aCollector )
3745 {
3746 if( !i->IsBOARD_ITEM() )
3747 continue;
3748
3749 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
3750
3751 if( !itemPassesFilter( item, aMultiSelect, aRejected ) )
3752 rejected.insert( item );
3753 }
3754
3755 for( BOARD_ITEM* item : rejected )
3756 aCollector.Remove( item );
3757}
3758
3759
3760bool PCB_SELECTION_TOOL::itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect,
3761 PCB_SELECTION_FILTER_OPTIONS* aRejected )
3762{
3763 if( !m_filter.lockedItems )
3764 {
3765 if( aItem->IsLocked() || ( aItem->GetParent() && aItem->GetParent()->IsLocked() ) )
3766 {
3767 if( aItem->Type() == PCB_PAD_T && !aMultiSelect )
3768 {
3769 // allow a single pad to be selected -- there are a lot of operations that
3770 // require this so we allow this one inconsistency
3771 }
3772 else
3773 {
3774 if( aRejected )
3775 aRejected->lockedItems = true;
3776 return false;
3777 }
3778 }
3779 }
3780
3781 if( !aItem )
3782 return false;
3783
3784 KICAD_T itemType = aItem->Type();
3785
3786 if( itemType == PCB_GENERATOR_T )
3787 {
3788 if( static_cast<PCB_GENERATOR*>( aItem )->GetItems().empty() )
3789 {
3790 if( !m_filter.otherItems )
3791 {
3792 if( aRejected )
3793 aRejected->otherItems = true;
3794
3795 return false;
3796 }
3797 }
3798 else
3799 {
3800 itemType = ( *static_cast<PCB_GENERATOR*>( aItem )->GetItems().begin() )->Type();
3801 }
3802 }
3803
3804 switch( itemType )
3805 {
3806 case PCB_FOOTPRINT_T:
3807 if( !m_filter.footprints )
3808 {
3809 if( aRejected )
3810 aRejected->footprints = true;
3811
3812 return false;
3813 }
3814
3815 break;
3816
3817 case PCB_PAD_T:
3818 if( !m_filter.pads )
3819 {
3820 if( aRejected )
3821 aRejected->pads = true;
3822
3823 return false;
3824 }
3825
3826 break;
3827
3828 case PCB_TRACE_T:
3829 case PCB_ARC_T:
3830 if( !m_filter.tracks )
3831 {
3832 if( aRejected )
3833 aRejected->tracks = true;
3834
3835 return false;
3836 }
3837
3838 break;
3839
3840 case PCB_VIA_T:
3841 if( !m_filter.vias )
3842 {
3843 if( aRejected )
3844 aRejected->vias = true;
3845
3846 return false;
3847 }
3848
3849 break;
3850
3851 case PCB_ZONE_T:
3852 {
3853 ZONE* zone = static_cast<ZONE*>( aItem );
3854
3855 if( ( !m_filter.zones && !zone->GetIsRuleArea() )
3856 || ( !m_filter.keepouts && zone->GetIsRuleArea() ) )
3857 {
3858 if( aRejected )
3859 {
3860 if( zone->GetIsRuleArea() )
3861 aRejected->keepouts = true;
3862 else
3863 aRejected->zones = true;
3864 }
3865
3866 return false;
3867 }
3868
3869 // m_SolderMaskBridges zone is a special zone, only used to showsolder mask briges
3870 // after running DRC. it is not really a board item.
3871 // Never select it or delete by a Commit.
3872 if( zone == m_frame->GetBoard()->m_SolderMaskBridges )
3873 return false;
3874
3875 break;
3876 }
3877
3878 case PCB_SHAPE_T:
3879 case PCB_TARGET_T:
3880 if( !m_filter.graphics )
3881 {
3882 if( aRejected )
3883 aRejected->graphics = true;
3884
3885 return false;
3886 }
3887
3888 break;
3889
3891 if( !m_filter.graphics )
3892 {
3893 if( aRejected )
3894 aRejected->graphics = true;
3895
3896 return false;
3897 }
3898
3899 // a reference image living in a footprint must not be selected inside the board editor
3900 if( !m_isFootprintEditor && aItem->GetParentFootprint() )
3901 {
3902 if( aRejected )
3903 aRejected->text = true;
3904
3905 return false;
3906 }
3907
3908 break;
3909
3910 case PCB_FIELD_T:
3911 case PCB_TEXT_T:
3912 case PCB_TEXTBOX_T:
3913 case PCB_TABLE_T:
3914 case PCB_DRILL_CHART_T:
3916 case PCB_TABLECELL_T:
3917 if( !m_filter.text )
3918 return false;
3919
3920 break;
3921
3922 case PCB_DIM_ALIGNED_T:
3923 case PCB_DIM_CENTER_T:
3924 case PCB_DIM_RADIAL_T:
3926 case PCB_DIM_LEADER_T:
3927 if( !m_filter.dimensions )
3928 {
3929 if( aRejected )
3930 aRejected->dimensions = true;
3931
3932 return false;
3933 }
3934
3935 break;
3936
3937 case PCB_POINT_T:
3938 if( !m_filter.points )
3939 {
3940 if( aRejected )
3941 aRejected->points = true;
3942
3943 return false;
3944 }
3945
3946 break;
3947
3948 case PCB_GRID_ITEM_T:
3949 if( !m_filter.gridItems )
3950 {
3951 if( aRejected )
3952 aRejected->gridItems = true;
3953
3954 return false;
3955 }
3956
3957 break;
3958
3959 case PCB_BARCODE_T:
3960 default:
3961 if( !m_filter.otherItems )
3962 {
3963 if( aRejected )
3964 aRejected->otherItems = true;
3965
3966 return false;
3967 }
3968 }
3969
3970 return true;
3971}
3972
3973
3975{
3976 // Drop any table-cell range anchor along with the selection itself (do this even when the
3977 // selection is already empty so that the cached pointer is not left stranded)
3978 m_previousFirstCell = nullptr;
3979
3980 if( m_selection.Empty() )
3981 return;
3982
3983 while( m_selection.GetSize() )
3985
3986 view()->Update( &m_selection );
3987
3988 m_selection.SetIsHover( false );
3989 m_selection.ClearReferencePoint();
3990
3991 // Inform other potentially interested tools
3992 if( !aQuietMode )
3993 {
3994 m_toolMgr->ProcessEvent( EVENTS::ClearedEvent );
3996 }
3997}
3998
3999
4001{
4002 // The whole row goes in, because formatting one cell of a generated row and not its
4003 // neighbours is never what was meant
4004 if( m_selection.GetSize() != 1 || !IsGeneratedTableType( m_selection[0]->Type() ) )
4005 return false;
4006
4008 PCB_TABLECELL* clicked = nullptr;
4009
4010 for( PCB_TABLECELL* cell : table->GetCells() )
4011 {
4012 if( cell->HitTest( aPosition, 0 ) )
4013 {
4014 clicked = cell;
4015 break;
4016 }
4017 }
4018
4019 // The heading and trailer rows are configured from the table's own dialog, so a click there
4020 // falls through to it rather than offering to reformat a row the user cannot vary
4021 if( !clicked || !table->IsDataRow( clicked->GetRow() ) )
4022 return false;
4023
4024 ClearSelection( true );
4025
4026 for( PCB_TABLECELL* cell : table->GetCells() )
4027 {
4028 if( cell->GetRow() == clicked->GetRow() )
4029 select( cell );
4030 }
4031
4032 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
4033
4034 return true;
4035}
4036
4037
4039{
4040 // Drop the table-cell range anchor; the board may have been reloaded and any cached
4041 // pointer is no longer guaranteed to be valid.
4042 m_previousFirstCell = nullptr;
4043
4044 m_selection.Clear();
4045
4046 bool enteredGroupFound = false;
4047
4048 INSPECTOR_FUNC inspector =
4049 [&]( EDA_ITEM* item, void* testData )
4050 {
4051 if( item->IsSelected() )
4052 {
4053 EDA_ITEM* parent = item->GetParent();
4054
4055 // Let selected parents handle their children.
4056 if( parent && parent->IsSelected() )
4058
4059 highlight( item, SELECTED, &m_selection );
4060 }
4061
4062 if( item->Type() == PCB_GROUP_T )
4063 {
4064 if( item == m_enteredGroup )
4065 {
4066 item->SetFlags( ENTERED );
4067 enteredGroupFound = true;
4068 }
4069 else
4070 {
4071 item->ClearFlags( ENTERED );
4072 }
4073 }
4074
4076 };
4077
4080
4081 if( !enteredGroupFound )
4082 {
4083 m_enteredGroupOverlay.Clear();
4084 m_enteredGroup = nullptr;
4085
4086 SetGroupEditModeActive( false );
4087 }
4088}
4089
4090
4092 const LSET& aEnabledLayers )
4093{
4094 return aVisibleLayers & aEnabledLayers;
4095}
4096
4097
4098bool PCB_SELECTION_TOOL::isPadVisible( const PAD& aPad, const LSET& aVisibleLayers )
4099{
4100 if( aPad.GetAttribute() == PAD_ATTRIB::PTH || aPad.GetAttribute() == PAD_ATTRIB::NPTH )
4101 {
4102 // A hole is drawn on every layer the pad itself is drawn on plus many it is not, so
4103 // any visible physical layer shows it
4104 return ( aVisibleLayers & LSET::PhysicalLayersMask() ).any();
4105 }
4106
4107 return ( aPad.GetLayerSet() & aVisibleLayers ).any();
4108}
4109
4110
4111bool PCB_SELECTION_TOOL::isOnVisibleFootprintSide( const BOARD_ITEM& aItem, bool aFrontVisible,
4112 bool aBackVisible, bool aIsFootprintEditor )
4113{
4114 const FOOTPRINT* parentFP = aItem.GetParentFootprint();
4115
4116 if( aIsFootprintEditor || !parentFP )
4117 return true;
4118
4119 // Only these types implement the switches in their ViewGetLOD; the rest stay drawn
4120 switch( aItem.Type() )
4121 {
4122 case PCB_FIELD_T:
4123 case PCB_TEXT_T:
4124 case PCB_SHAPE_T:
4125 case PCB_ZONE_T:
4126 case PCB_PAD_T:
4127 case PCB_DIM_ALIGNED_T:
4128 case PCB_DIM_LEADER_T:
4129 case PCB_DIM_CENTER_T:
4130 case PCB_DIM_RADIAL_T:
4132 break;
4133
4134 default:
4135 return true;
4136 }
4137
4138 LSET layers = aItem.GetLayerSet();
4139 bool onFront = ( layers & LSET::FrontMask() ).any();
4140 bool onBack = ( layers & LSET::BackMask() ).any();
4141
4142 if( !onFront && !onBack )
4143 {
4144 // A pad off both sides stays drawn; everything else takes the footprint's side
4145 if( aItem.Type() == PCB_PAD_T )
4146 return true;
4147
4148 onFront = parentFP->GetLayer() == F_Cu;
4149 onBack = parentFP->GetLayer() == B_Cu;
4150 }
4151
4152 return ( onFront && aFrontVisible ) || ( onBack && aBackVisible );
4153}
4154
4155
4156bool PCB_SELECTION_TOOL::Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly ) const
4157{
4158 const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
4159 const PCB_DISPLAY_OPTIONS& options = frame()->GetDisplayOptions();
4160
4161 auto visibleLayers =
4162 [&]() -> LSET
4163 {
4165 {
4166 LSET set;
4167
4168 for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
4169 set.set( layer, view()->IsLayerVisible( layer ) );
4170
4171 return set;
4172 }
4173 else
4174 {
4175 return resolveVisibleLayers( board()->GetVisibleLayers(),
4176 board()->GetEnabledLayers() );
4177 }
4178 };
4179
4180 auto layerVisible =
4181 [&]( PCB_LAYER_ID aLayer )
4182 {
4184 return view()->IsLayerVisible( aLayer );
4185 else
4186 return board()->IsLayerVisible( aLayer );
4187 };
4188
4189 // Box-select never goes through the collectors guide, so the Render tab's footprint switches
4190 // have to be applied here too
4191 if( !isOnVisibleFootprintSide( *aItem, board()->IsElementVisible( LAYER_FOOTPRINTS_FR ),
4192 board()->IsElementVisible( LAYER_FOOTPRINTS_BK ),
4194 {
4195 return false;
4196 }
4197
4198 if( settings->GetHighContrast() )
4199 {
4200 const std::set<int> activeLayers = settings->GetHighContrastLayers();
4201 bool onActiveLayer = false;
4202
4203 for( int layer : activeLayers )
4204 {
4205 // NOTE: Only checking the regular layers (not GAL meta-layers)
4206 if( layer < PCB_LAYER_ID_COUNT && aItem->IsOnLayer( ToLAYER_ID( layer ) ) )
4207 {
4208 onActiveLayer = true;
4209 break;
4210 }
4211 }
4212
4213 if( !onActiveLayer && aItem->Type() != PCB_MARKER_T )
4214 {
4215 // We do not want to select items that are in the background
4216 return false;
4217 }
4218 }
4219
4220 if( aItem->Type() == PCB_FOOTPRINT_T )
4221 {
4222 const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
4223
4224 // In footprint editor, we do not want to select the footprint itself.
4226 return false;
4227
4228 // If the footprint has no items except the reference and value fields, include the
4229 // footprint in the selections.
4230 if( footprint->GraphicalItems().empty()
4231 && footprint->Pads().empty()
4232 && footprint->Zones().empty()
4233 && footprint->Points().empty() )
4234 {
4235 return board()->IsFootprintLayerVisible( footprint->GetLayer() );
4236 }
4237
4238 for( const BOARD_ITEM* item : footprint->GraphicalItems() )
4239 {
4240 if( Selectable( item, true ) )
4241 return true;
4242 }
4243
4244 for( const PAD* pad : footprint->Pads() )
4245 {
4246 if( Selectable( pad, true ) )
4247 return true;
4248 }
4249
4250 for( const ZONE* zone : footprint->Zones() )
4251 {
4252 if( Selectable( zone, true ) )
4253 return true;
4254 }
4255
4256 for( const PCB_POINT* point: footprint->Points() )
4257 {
4258 if( Selectable( point, true ) )
4259 return true;
4260 }
4261
4262 return false;
4263 }
4264 else if( aItem->Type() == PCB_GROUP_T )
4265 {
4266 PCB_GROUP* group = const_cast<PCB_GROUP*>( static_cast<const PCB_GROUP*>( aItem ) );
4267
4268 // Similar to logic for footprint, a group is selectable if any of its members are.
4269 // (This recurses.)
4270 for( BOARD_ITEM* item : group->GetBoardItems() )
4271 {
4272 if( Selectable( item, true ) )
4273 return true;
4274 }
4275
4276 return false;
4277 }
4278
4279 if( aItem->GetParentGroup() && aItem->GetParentGroup()->AsEdaItem()->Type() == PCB_GENERATOR_T )
4280 {
4281 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( aItem->GetParentGroup()->AsEdaItem() );
4282
4284 return false;
4285 }
4286
4287 const ZONE* zone = nullptr;
4288 const PCB_VIA* via = nullptr;
4289 const PAD* pad = nullptr;
4290 const PCB_TEXT* text = nullptr;
4291 const PCB_FIELD* field = nullptr;
4292 const PCB_MARKER* marker = nullptr;
4293 const PCB_TABLECELL* cell = nullptr;
4294
4295 // Most footprint children can only be selected in the footprint editor.
4296 if( aItem->GetParentFootprint() && !m_isFootprintEditor && !checkVisibilityOnly )
4297 {
4298 if( aItem->Type() != PCB_FIELD_T && aItem->Type() != PCB_PAD_T && aItem->Type() != PCB_TEXT_T )
4299 return false;
4300 }
4301
4302 switch( aItem->Type() )
4303 {
4304 case PCB_ZONE_T:
4305 if( !board()->IsElementVisible( LAYER_ZONES ) || ( options.m_ZoneOpacity == 0.00 ) )
4306 return false;
4307
4308 zone = static_cast<const ZONE*>( aItem );
4309
4310 // A teardrop is modelled as a property of a via, pad or the board (for track-to-track
4311 // teardrops). The underlying zone is only an implementation detail.
4312 if( zone->IsTeardropArea() && !board()->LegacyTeardrops() )
4313 return false;
4314
4315 // zones can exist on multiple layers!
4316 if( !( zone->GetLayerSet() & visibleLayers() ).any() )
4317 return false;
4318
4319 break;
4320
4321 case PCB_TRACE_T:
4322 case PCB_ARC_T:
4323 if( !board()->IsElementVisible( LAYER_TRACKS ) || ( options.m_TrackOpacity == 0.00 ) )
4324 return false;
4325
4326 if( !layerVisible( aItem->GetLayer() ) )
4327 return false;
4328
4329 break;
4330
4331 case PCB_VIA_T:
4332 if( !board()->IsElementVisible( LAYER_VIAS ) || ( options.m_ViaOpacity == 0.00 ) )
4333 return false;
4334
4335 via = static_cast<const PCB_VIA*>( aItem );
4336
4337 // For vias it is enough if only one of its layers is visible
4338 if( !( visibleLayers() & via->GetLayerSet() ).any() )
4339 return false;
4340
4341 break;
4342
4343 case PCB_FIELD_T:
4344 field = static_cast<const PCB_FIELD*>( aItem );
4345
4346 if( !field->IsVisible() )
4347 return false;
4348
4349 if( field->IsReference() && !view()->IsLayerVisible( LAYER_FP_REFERENCES ) )
4350 return false;
4351
4352 if( field->IsValue() && !view()->IsLayerVisible( LAYER_FP_VALUES ) )
4353 return false;
4354
4355 // Handle all other fields with normal text visibility controls
4357 case PCB_TEXT_T:
4358 text = static_cast<const PCB_TEXT*>( aItem );
4359
4360 if( !layerVisible( text->GetLayer() ) )
4361 return false;
4362
4363 // Apply the LOD visibility test as well
4364 if( !view()->IsVisible( text ) )
4365 return false;
4366
4367 if( aItem->GetParentFootprint() )
4368 {
4369 int controlLayer = LAYER_FP_TEXT;
4370
4371 if( text->GetText() == wxT( "${REFERENCE}" ) )
4372 controlLayer = LAYER_FP_REFERENCES;
4373 else if( text->GetText() == wxT( "${VALUE}" ) )
4374 controlLayer = LAYER_FP_VALUES;
4375
4376 if( !view()->IsLayerVisible( controlLayer ) )
4377 return false;
4378 }
4379
4380 break;
4381
4383 if( options.m_ImageOpacity == 0.00 )
4384 return false;
4385
4386 // Bitmap images on board are hidden if LAYER_DRAW_BITMAPS is not visible
4387 if( !view()->IsLayerVisible( LAYER_DRAW_BITMAPS ) )
4388 return false;
4389
4390 if( !layerVisible( aItem->GetLayer() ) )
4391 return false;
4392
4393 break;
4394
4395 case PCB_SHAPE_T:
4396 if( options.m_FilledShapeOpacity == 0.0 && static_cast<const PCB_SHAPE*>( aItem )->IsAnyFill() )
4397 return false;
4398
4399 if( !layerVisible( aItem->GetLayer() ) )
4400 return false;
4401
4402 break;
4403
4404 case PCB_BARCODE_T:
4405 if( !layerVisible( aItem->GetLayer() ) )
4406 return false;
4407
4408 break;
4409
4410 case PCB_TEXTBOX_T:
4411 case PCB_TABLE_T:
4412 case PCB_DRILL_CHART_T:
4414 if( !layerVisible( aItem->GetLayer() ) )
4415 return false;
4416
4417 break;
4418
4419 case PCB_TABLECELL_T:
4420 cell = static_cast<const PCB_TABLECELL*>( aItem );
4421
4422 if( !layerVisible( aItem->GetLayer() ) )
4423 return false;
4424
4425 if( cell->GetRowSpan() == 0 || cell->GetColSpan() == 0 )
4426 return false;
4427
4428 break;
4429
4430 case PCB_DIM_ALIGNED_T:
4431 case PCB_DIM_LEADER_T:
4432 case PCB_DIM_CENTER_T:
4433 case PCB_DIM_RADIAL_T:
4435 if( !layerVisible( aItem->GetLayer() ) )
4436 return false;
4437
4438 break;
4439
4440 case PCB_PAD_T:
4441 if( options.m_PadOpacity == 0.00 )
4442 return false;
4443
4444 pad = static_cast<const PAD*>( aItem );
4445
4446 if( !isPadVisible( *pad, visibleLayers() ) )
4447 return false;
4448
4449 break;
4450
4451 case PCB_MARKER_T:
4452 marker = static_cast<const PCB_MARKER*>( aItem );
4453
4454 if( marker && marker->IsExcluded() && !board()->IsElementVisible( LAYER_DRC_EXCLUSION ) )
4455 return false;
4456
4457 break;
4458
4459 case PCB_POINT_T:
4460 if( !layerVisible( aItem->GetLayer() ) )
4461 return false;
4462
4463 if( !board()->IsElementVisible( LAYER_POINTS ) )
4464 return false;
4465
4466 break;
4467
4468 case PCB_GRID_ITEM_T:
4469 if( !board()->IsElementVisible( LAYER_SUBGRIDS ) )
4470 return false;
4471
4472 break;
4473
4474 // These are not selectable
4475 case PCB_NETINFO_T:
4476 case PCB_CONSTRAINT_T: // geometry-free, never rendered or hit-tested (#2329)
4477 case NOT_USED:
4478 case TYPE_NOT_INIT:
4479 return false;
4480
4481 default: // Suppress warnings
4482 break;
4483 }
4484
4485 return true;
4486}
4487
4488
4490{
4491 if( !aItem || aItem->IsSelected() || !aItem->IsBOARD_ITEM() )
4492 return;
4493
4494 if( aItem->Type() == PCB_PAD_T )
4495 {
4496 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
4497
4498 if( m_selection.Contains( footprint ) )
4499 return;
4500 }
4501
4502 if( m_enteredGroup
4503 && !PCB_GROUP::WithinScope( *static_cast<BOARD_ITEM*>( aItem ), m_enteredGroup, m_isFootprintEditor ) )
4504 {
4505 ExitGroup();
4506 }
4507
4508 highlight( aItem, SELECTED, &m_selection );
4509}
4510
4511
4513{
4514 unhighlight( aItem, SELECTED, &m_selection );
4515}
4516
4517
4518void PCB_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
4519{
4520 if( aGroup )
4521 aGroup->Add( aItem );
4522
4523 highlightInternal( aItem, aMode, aGroup != nullptr );
4524 view()->Update( aItem, KIGFX::REPAINT );
4525
4526 // Many selections are very temporal and updating the display each time just
4527 // creates noise.
4528 if( aMode == BRIGHTENED )
4530}
4531
4532
4533void PCB_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
4534{
4535 if( aMode == SELECTED )
4536 aItem->SetSelected();
4537 else if( aMode == BRIGHTENED )
4538 aItem->SetBrightened();
4539
4540 if( aUsingOverlay && aMode != BRIGHTENED )
4541 view()->Hide( aItem, true ); // Hide the original item, so it is shown only on overlay
4542
4543 if( aItem->IsBOARD_ITEM() )
4544 {
4545 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
4546 boardItem->RunOnChildren( std::bind( &PCB_SELECTION_TOOL::highlightInternal, this, _1, aMode, aUsingOverlay ),
4548 }
4549}
4550
4551
4552void PCB_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup )
4553{
4554 if( aGroup )
4555 aGroup->Remove( aItem );
4556
4557 unhighlightInternal( aItem, aMode, aGroup != nullptr );
4558 view()->Update( aItem, KIGFX::REPAINT );
4559
4560 // Many selections are very temporal and updating the display each time just creates noise.
4561 if( aMode == BRIGHTENED )
4563}
4564
4565
4566void PCB_SELECTION_TOOL::unhighlightInternal( EDA_ITEM* aItem, int aMode, bool aUsingOverlay )
4567{
4568 if( aMode == SELECTED )
4569 aItem->ClearSelected();
4570 else if( aMode == BRIGHTENED )
4571 aItem->ClearBrightened();
4572
4573 if( aUsingOverlay && aMode != BRIGHTENED )
4574 {
4575 view()->Hide( aItem, false ); // Restore original item visibility...
4576 view()->Update( aItem ); // ... and make sure it's redrawn un-selected
4577 }
4578
4579 if( aItem->IsBOARD_ITEM() )
4580 {
4581 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
4582 boardItem->RunOnChildren( std::bind( &PCB_SELECTION_TOOL::unhighlightInternal, this, _1, aMode, aUsingOverlay ),
4584 }
4585}
4586
4587
4589{
4590 PCB_POINT_EDITOR* pointEditor = m_toolMgr->GetTool<PCB_POINT_EDITOR>();
4591
4592 return m_frame->ToolStackIsEmpty() && pointEditor && pointEditor->HasBlockHandles();
4593}
4594
4595
4597{
4598 const unsigned GRIP_MARGIN = 20;
4599 int margin = KiROUND( getView()->ToWorld( GRIP_MARGIN ) );
4600
4601 // Check if the point is located close to any of the currently selected items
4602 for( EDA_ITEM* item : m_selection )
4603 {
4604 if( !item->IsBOARD_ITEM() )
4605 continue;
4606
4607 BOX2I itemBox = item->ViewBBox();
4608 itemBox.Inflate( margin ); // Give some margin for gripping an item
4609
4610 if( itemBox.Contains( aPoint ) )
4611 {
4612 if( item->HitTest( aPoint, margin ) )
4613 return true;
4614
4615 bool found = false;
4616
4617 if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( item ) )
4618 {
4619 group->RunOnChildren(
4620 [&]( BOARD_ITEM* aItem )
4621 {
4622 if( aItem->HitTest( aPoint, margin ) )
4623 found = true;
4624 },
4626 }
4627
4628 if( found )
4629 return true;
4630 }
4631 }
4632
4633 return false;
4634}
4635
4636
4637int PCB_SELECTION_TOOL::hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const
4638{
4639 BOX2D viewportD = getView()->GetViewport();
4640 BOX2I viewport = BOX2ISafe( viewportD );
4641 int distance = INT_MAX;
4642 SEG loc( aWhere, aWhere );
4643
4644 switch( aItem->Type() )
4645 {
4646 case PCB_FIELD_T:
4647 case PCB_TEXT_T:
4648 {
4649 PCB_TEXT* text = static_cast<PCB_TEXT*>( aItem );
4650
4651 // Add a bit of slop to text-shapes
4652 if( text->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance ) )
4653 distance = std::clamp( distance - ( aMaxDistance / 2 ), 0, distance );
4654
4655 break;
4656 }
4657
4658 case PCB_TEXTBOX_T:
4659 {
4660 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( aItem );
4661
4662 // Add a bit of slop to text-shapes
4663 if( textbox->GetEffectiveTextShape()->Collide( loc, aMaxDistance, &distance ) )
4664 distance = std::clamp( distance - ( aMaxDistance / 2 ), 0, distance );
4665
4666 break;
4667 }
4668
4669 case PCB_TABLECELL_T:
4670 {
4671 PCB_TABLECELL* tablecell = static_cast<PCB_TABLECELL*>( aItem );
4672 auto shape = std::make_shared<SHAPE_COMPOUND>( tablecell->MakeEffectiveShapesForHitTesting() );
4673
4674 shape->Collide( loc, aMaxDistance, &distance );
4675
4676 break;
4677 }
4678
4679 case PCB_TABLE_T:
4680 case PCB_DRILL_CHART_T:
4682 {
4683 PCB_TABLE* table = static_cast<PCB_TABLE*>( aItem );
4684 distance = aMaxDistance;
4685
4686 for( PCB_TABLECELL* cell : table->GetCells() )
4687 distance = std::min( distance, hitTestDistance( aWhere, cell, aMaxDistance ) );
4688
4689 // Tables should defer to their table cells. Never consider them exact.
4690 distance = std::clamp( distance + ( aMaxDistance / 4 ), 0, aMaxDistance );
4691 break;
4692 }
4693
4694 case PCB_ZONE_T:
4695 {
4696 ZONE* zone = static_cast<ZONE*>( aItem );
4697
4698 // Zone borders are very specific
4699 if( zone->HitTestForEdge( aWhere, aMaxDistance / 2 ) )
4700 distance = 0;
4701 else if( zone->HitTestForEdge( aWhere, aMaxDistance ) )
4702 distance = aMaxDistance / 2;
4703 else
4704 aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
4705
4706 break;
4707 }
4708
4709 case PCB_FOOTPRINT_T:
4710 {
4711 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
4712 BOX2I bbox = footprint->GetBoundingBox( false );
4713
4714 try
4715 {
4716 footprint->GetBoundingHull().Collide( loc, aMaxDistance, &distance );
4717 }
4718 catch( const std::exception& e )
4719 {
4720 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
4721 }
4722
4723 // Consider footprints larger than the viewport only as a last resort
4724 if( bbox.GetHeight() > viewport.GetHeight() || bbox.GetWidth() > viewport.GetWidth() )
4725 distance = INT_MAX / 2;
4726
4727 break;
4728 }
4729
4730 case PCB_MARKER_T:
4731 {
4732 PCB_MARKER* marker = static_cast<PCB_MARKER*>( aItem );
4734
4735 marker->ShapeToPolygon( polygon );
4736 polygon.Move( marker->GetPos() );
4737 polygon.Collide( loc, aMaxDistance, &distance );
4738 break;
4739 }
4740
4741 case PCB_GROUP_T:
4742 case PCB_GENERATOR_T:
4743 {
4744 // Poly-outline generators (e.g. via stitching) define a region; measure distance
4745 // to that outline instead of to their generated children, otherwise clicks landing
4746 // inside the region but away from any child get a huge distance and the generator
4747 // gets pruned by the sloppiness heuristic.
4748 if( const PCB_GENERATOR_POLY* poly = dynamic_cast<const PCB_GENERATOR_POLY*>( aItem ) )
4749 {
4750 int actual = aMaxDistance;
4751
4752 if( poly->Outline().Collide( loc, aMaxDistance, &actual ) )
4753 distance = actual;
4754
4755 break;
4756 }
4757
4758 PCB_GROUP* group = static_cast<PCB_GROUP*>( aItem );
4759
4760 for( BOARD_ITEM* member : group->GetBoardItems() )
4761 distance = std::min( distance, hitTestDistance( aWhere, member, aMaxDistance ) );
4762
4763 break;
4764 }
4765
4766 case PCB_PAD_T:
4767 {
4768 static_cast<PAD*>( aItem )->Padstack().ForEachUniqueLayer(
4769 [&]( PCB_LAYER_ID aLayer )
4770 {
4771 int layerDistance = INT_MAX;
4772 aItem->GetEffectiveShape( aLayer )->Collide( loc, aMaxDistance, &layerDistance );
4773 distance = std::min( distance, layerDistance );
4774 } );
4775
4776 break;
4777 }
4778
4779 default:
4780 aItem->GetEffectiveShape()->Collide( loc, aMaxDistance, &distance );
4781 break;
4782 }
4783
4784 return distance;
4785}
4786
4787
4789{
4790 wxCHECK( m_frame, /* void */ );
4791
4792 if( aCollector.GetCount() < 2 )
4793 return;
4794
4795 const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
4796
4797 wxCHECK( settings, /* void */ );
4798
4799 PCB_LAYER_ID activeLayer = m_frame->GetActiveLayer();
4800 LSET visibleLayers = m_frame->GetBoard()->GetVisibleLayers();
4801 LSET enabledLayers = m_frame->GetBoard()->GetEnabledLayers();
4802 LSEQ enabledLayerStack = enabledLayers.SeqStackupTop2Bottom( activeLayer );
4803
4804 wxCHECK( !enabledLayerStack.empty(), /* void */ );
4805
4806 auto isZoneFillKeepout =
4807 []( const BOARD_ITEM* aItem ) -> bool
4808 {
4809 if( aItem->Type() == PCB_ZONE_T )
4810 {
4811 const ZONE* zone = static_cast<const ZONE*>( aItem );
4812
4813 if( zone->GetIsRuleArea() && zone->GetDoNotAllowZoneFills() )
4814 return true;
4815 }
4816
4817 return false;
4818 };
4819
4820 std::vector<LAYER_OPACITY_ITEM> opacityStackup;
4821
4822 for( int i = 0; i < aCollector.GetCount(); i++ )
4823 {
4824 const BOARD_ITEM* item = aCollector[i];
4825
4826 LSET itemLayers = item->GetLayerSet() & enabledLayers & visibleLayers;
4827 LSEQ itemLayerSeq = itemLayers.Seq( enabledLayerStack );
4828
4829 for( PCB_LAYER_ID layer : itemLayerSeq )
4830 {
4831 COLOR4D color = settings->GetColor( item, layer );
4832
4833 if( color.a == 0 )
4834 continue;
4835
4836 LAYER_OPACITY_ITEM opacityItem;
4837
4838 opacityItem.m_Layer = layer;
4839 opacityItem.m_Opacity = color.a;
4840 opacityItem.m_Item = item;
4841
4842 if( isZoneFillKeepout( item ) )
4843 opacityItem.m_Opacity = 0.0;
4844
4845 opacityStackup.emplace_back( opacityItem );
4846 }
4847 }
4848
4849 std::sort( opacityStackup.begin(), opacityStackup.end(),
4850 [&]( const LAYER_OPACITY_ITEM& aLhs, const LAYER_OPACITY_ITEM& aRhs ) -> bool
4851 {
4852 int retv = enabledLayerStack.TestLayers( aLhs.m_Layer, aRhs.m_Layer );
4853
4854 if( retv )
4855 return retv > 0;
4856
4857 return aLhs.m_Opacity > aRhs.m_Opacity;
4858 } );
4859
4860 std::set<const BOARD_ITEM*> visibleItems;
4861 std::set<const BOARD_ITEM*> itemsToRemove;
4862 double minAlphaLimit = ADVANCED_CFG::GetCfg().m_PcbSelectionVisibilityRatio;
4863 double currentStackupOpacity = 0.0;
4865
4866 for( const LAYER_OPACITY_ITEM& opacityItem : opacityStackup )
4867 {
4868 if( lastVisibleLayer == PCB_LAYER_ID::UNDEFINED_LAYER )
4869 {
4870 currentStackupOpacity = opacityItem.m_Opacity;
4871 lastVisibleLayer = opacityItem.m_Layer;
4872 visibleItems.emplace( opacityItem.m_Item );
4873 continue;
4874 }
4875
4876 // Objects to ignore and fallback to the old selection behavior.
4877 auto ignoreItem =
4878 [&]()
4879 {
4880 const BOARD_ITEM* item = opacityItem.m_Item;
4881
4882 wxCHECK( item, false );
4883
4884 // Check items that span multiple layers for visibility.
4885 if( visibleItems.count( item ) )
4886 return true;
4887
4888 // Don't prune child items of a footprint that is already visible.
4889 if( item->GetParent()
4890 && ( item->GetParent()->Type() == PCB_FOOTPRINT_T )
4891 && visibleItems.count( item->GetParent() ) )
4892 {
4893 return true;
4894 }
4895
4896 // Keepout zones are transparent but for some reason, PCB_PAINTER::GetColor()
4897 // returns the color of the zone it prevents from filling.
4898 if( isZoneFillKeepout( item ) )
4899 return true;
4900
4901 return false;
4902 };
4903
4904 // Everything on the currently selected layer is visible;
4905 if( opacityItem.m_Layer == enabledLayerStack[0] )
4906 {
4907 visibleItems.emplace( opacityItem.m_Item );
4908 }
4909 else
4910 {
4911 double itemVisibility = opacityItem.m_Opacity * ( 1.0 - currentStackupOpacity );
4912
4913 if( ( itemVisibility <= minAlphaLimit ) && !ignoreItem() )
4914 itemsToRemove.emplace( opacityItem.m_Item );
4915 else
4916 visibleItems.emplace( opacityItem.m_Item );
4917 }
4918
4919 if( opacityItem.m_Layer != lastVisibleLayer )
4920 {
4921 currentStackupOpacity += opacityItem.m_Opacity * ( 1.0 - currentStackupOpacity );
4922 currentStackupOpacity = std::min( currentStackupOpacity, 1.0 );
4923 lastVisibleLayer = opacityItem.m_Layer;
4924 }
4925 }
4926
4927 for( const BOARD_ITEM* itemToRemove : itemsToRemove )
4928 {
4929 wxCHECK( aCollector.GetCount() > 1, /* void */ );
4930 aCollector.Remove( itemToRemove );
4931 }
4932}
4933
4934
4935// The general idea here is that if the user clicks directly on a small item inside a larger
4936// one, then they want the small item. The quintessential case of this is clicking on a pad
4937// within a footprint, but we also apply it for text within a footprint, footprints within
4938// larger footprints, and vias within either larger pads or longer tracks.
4939//
4940// These "guesses" presume there is area within the larger item to click in to select it. If
4941// an item is mostly covered by smaller items within it, then the guesses are inappropriate as
4942// there might not be any area left to click to select the larger item. In this case we must
4943// leave the items in the collector and bring up a Selection Clarification menu.
4944//
4945// We currently check for pads and text mostly covering a footprint, but we don't check for
4946// smaller footprints mostly covering a larger footprint.
4947//
4949 const VECTOR2I& aWhere ) const
4950{
4951 static const LSET silkLayers( { B_SilkS, F_SilkS } );
4952 static const LSET courtyardLayers( { B_CrtYd, F_CrtYd } );
4953 static std::vector<KICAD_T> singleLayerSilkTypes = { PCB_FIELD_T,
4957 PCB_BARCODE_T };
4958
4959 if( ADVANCED_CFG::GetCfg().m_PcbSelectionVisibilityRatio != 1.0 )
4961
4962 if( aCollector.GetCount() == 1 )
4963 return;
4964
4965 std::set<BOARD_ITEM*> preferred;
4966 std::set<BOARD_ITEM*> rejected;
4967 VECTOR2I where( aWhere.x, aWhere.y );
4968 const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
4969 PCB_LAYER_ID activeLayer = m_frame->GetActiveLayer();
4970
4971 // A map's marks sit on the holes they mark, so a plain click falls through to the via or
4972 // pad under them. Holding the click skips these heuristics and reaches the map
4973 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
4974 {
4975 if( aCollector[i]->Type() != PCB_DRILL_MAP_T )
4976 continue;
4977
4978 if( aCollector[i]->GetLayer() == activeLayer )
4979 preferred.insert( aCollector[i] );
4980 else if( aCollector.GetCount() > 1 )
4981 aCollector.Remove( i );
4982 }
4983
4984 // A generated table says what the board says, so a click on it is a click on the table.
4985 // Its cells stay collectable for everything else, and a double-click still reaches them.
4986 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
4987 {
4988 if( IsGeneratedTableCell( aCollector[i] ) && aCollector.HasItem( aCollector[i]->GetParent() ) )
4989 {
4990 aCollector.Remove( i );
4991 }
4992 }
4993
4994 // If a silk layer is in front, we assume the user is working with silk and give preferential
4995 // treatment to single-layer items on *either* silk layer.
4996 if( silkLayers[activeLayer] )
4997 {
4998 for( int i = 0; i < aCollector.GetCount(); ++i )
4999 {
5000 BOARD_ITEM* item = aCollector[i];
5001
5002 if( item->IsType( singleLayerSilkTypes ) && silkLayers[ item->GetLayer() ] )
5003 preferred.insert( item );
5004 }
5005 }
5006 // Similarly, if a courtyard layer is in front, we assume the user is positioning footprints
5007 // and give preferential treatment to footprints on *both* top and bottom.
5008 else if( courtyardLayers[activeLayer] && settings->GetHighContrast() )
5009 {
5010 for( int i = 0; i < aCollector.GetCount(); ++i )
5011 {
5012 BOARD_ITEM* item = aCollector[i];
5013
5014 if( item->Type() == PCB_FOOTPRINT_T )
5015 preferred.insert( item );
5016 }
5017 }
5018
5019 if( preferred.size() > 0 )
5020 {
5021 aCollector.Empty();
5022
5023 for( BOARD_ITEM* item : preferred )
5024 aCollector.Append( item );
5025
5026 if( preferred.size() == 1 )
5027 return;
5028 }
5029
5030 // Prefer exact hits to sloppy ones
5031 constexpr int MAX_SLOP = 5;
5032
5033 int singlePixel = KiROUND( aCollector.GetGuide()->OnePixelInIU() );
5034 int maxSlop = KiROUND( MAX_SLOP * aCollector.GetGuide()->OnePixelInIU() );
5035 int minSlop = INT_MAX;
5036
5037 std::map<BOARD_ITEM*, int> itemsBySloppiness;
5038
5039 for( int i = 0; i < aCollector.GetCount(); ++i )
5040 {
5041 BOARD_ITEM* item = aCollector[i];
5042 int itemSlop = hitTestDistance( where, item, maxSlop );
5043
5044 itemsBySloppiness[ item ] = itemSlop;
5045
5046 if( itemSlop < minSlop )
5047 minSlop = itemSlop;
5048 }
5049
5050 // Prune sloppier items
5051 if( minSlop < INT_MAX )
5052 {
5053 for( std::pair<BOARD_ITEM*, int> pair : itemsBySloppiness )
5054 {
5055 if( pair.second > minSlop + singlePixel )
5056 aCollector.Transfer( pair.first );
5057 }
5058 }
5059
5060 // If the user clicked on a small item within a much larger one then it's pretty clear
5061 // they're trying to select the smaller one.
5062 constexpr double sizeRatio = 1.5;
5063
5064 std::vector<std::pair<BOARD_ITEM*, double>> itemsByArea;
5065
5066 for( int i = 0; i < aCollector.GetCount(); ++i )
5067 {
5068 BOARD_ITEM* item = aCollector[i];
5069 double area = 0.0;
5070
5071 if( item->Type() == PCB_ZONE_T
5072 && static_cast<ZONE*>( item )->HitTestForEdge( where, maxSlop / 2 ) )
5073 {
5074 // Zone borders are very specific, so make them "small"
5075 area = (double) SEG::Square( singlePixel ) * MAX_SLOP;
5076 }
5077 else if( item->Type() == PCB_VIA_T )
5078 {
5079 // Vias rarely hide other things, and we don't want them deferring to short track
5080 // segments underneath them -- so artificially reduce their size from πr² to r².
5081 area = (double) SEG::Square( static_cast<PCB_VIA*>( item )->GetDrill() / 2 );
5082 }
5083 else if( item->Type() == PCB_REFERENCE_IMAGE_T )
5084 {
5085 BOX2I box = item->GetBoundingBox();
5086 area = (double) box.GetWidth() * box.GetHeight();
5087 }
5088 else
5089 {
5090 try
5091 {
5092 area = item->GetCoverageArea( aCollector.GetGuide()->Accuracy() );
5093 }
5094 catch( const std::exception& e )
5095 {
5096 wxFAIL_MSG( wxString::Format( wxT( "Clipper exception occurred: %s" ), e.what() ) );
5097 }
5098 }
5099
5100 itemsByArea.emplace_back( item, area );
5101 }
5102
5103 std::sort( itemsByArea.begin(), itemsByArea.end(),
5104 []( const std::pair<BOARD_ITEM*, double>& lhs,
5105 const std::pair<BOARD_ITEM*, double>& rhs ) -> bool
5106 {
5107 return lhs.second < rhs.second;
5108 } );
5109
5110 bool rejecting = false;
5111
5112 for( int i = 1; i < (int) itemsByArea.size(); ++i )
5113 {
5114 if( itemsByArea[i].second > itemsByArea[i-1].second * sizeRatio )
5115 rejecting = true;
5116
5117 if( rejecting )
5118 rejected.insert( itemsByArea[i].first );
5119 }
5120
5121 // Special case: if a footprint is completely covered with other features then there's no
5122 // way to select it -- so we need to leave it in the list for user disambiguation.
5123 constexpr double maxCoverRatio = 0.70;
5124
5125 for( int i = 0; i < aCollector.GetCount(); ++i )
5126 {
5127 if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aCollector[i] ) )
5128 {
5129 if( footprint->CoverageRatio( aCollector ) > maxCoverRatio )
5130 rejected.erase( footprint );
5131 }
5132 }
5133
5134 // Hopefully we've now got what the user wanted.
5135 if( (unsigned) aCollector.GetCount() > rejected.size() ) // do not remove everything
5136 {
5137 for( BOARD_ITEM* item : rejected )
5138 aCollector.Transfer( item );
5139 }
5140
5141 // Finally, what we are left with is a set of items of similar coverage area. We now reject
5142 // any that are not on the active layer, to reduce the number of disambiguation menus shown.
5143 // If the user wants to force-disambiguate, they can either switch layers or use the modifier
5144 // key to force the menu.
5145 if( aCollector.GetCount() > 1 )
5146 {
5147 bool haveItemOnActive = false;
5148 rejected.clear();
5149
5150 for( int i = 0; i < aCollector.GetCount(); ++i )
5151 {
5152 if( !aCollector[i]->IsOnLayer( activeLayer ) )
5153 rejected.insert( aCollector[i] );
5154 else
5155 haveItemOnActive = true;
5156 }
5157
5158 if( haveItemOnActive )
5159 {
5160 for( BOARD_ITEM* item : rejected )
5161 aCollector.Transfer( item );
5162 }
5163 }
5164}
5165
5166
5168{
5170 {
5171 m_frame->ShowInfoBarWarning( _( "Selection contains locked items. "
5172 "Enable 'Override locks' to operate on them." ),
5173 true );
5174 }
5175
5176 return m_lockedItemsFiltered;
5177}
5178
5179
5181{
5182 bool lockedDescendant = false;
5183
5184 aItem.RunOnChildren(
5185 [&]( BOARD_ITEM* curr_item )
5186 {
5187 if( !curr_item->GetParentFootprint() && curr_item->IsLocked() )
5188 lockedDescendant = true;
5189 },
5191
5192 return lockedDescendant;
5193}
5194
5195
5197 bool aIsFootprintEditor )
5198{
5199 if( aEnteredGroup )
5200 return PCB_GROUP::WithinScope( aItem, aEnteredGroup, aIsFootprintEditor );
5201
5202 EDA_GROUP* parent = aItem.GetParentGroup();
5203
5204 // If the item has no parent group, it is considered selectable as connected.
5205 if( !parent )
5206 return true;
5207
5208 const PCB_GROUP& group = static_cast<const PCB_GROUP&>( *parent->AsEdaItem() );
5209
5210 // Some generators opt-in to select-through-connection (e.g. tuning patterns)
5211 if( group.Type() == PCB_GENERATOR_T )
5212 {
5213 const PCB_GENERATOR& generator = static_cast<const PCB_GENERATOR&>( group );
5214
5215 if( generator.IsSelectableAsConnected() )
5216 return true;
5217 }
5218
5219 // The item is not in an entered group, and not otherwise selectable via connection
5220 // Disallow, so that expansion cannot reach into a group and silently pull
5221 // the whole group into a later delete (issue 24967).
5222 return false;
5223}
5224
5225
5227{
5228 m_lockedItemsFiltered = false;
5229
5230 if( m_frame && m_frame->IsType( FRAME_PCB_EDITOR ) && !m_frame->GetOverrideLocks() )
5231 {
5232 // Iterate from the back so we don't have to worry about removals.
5233 for( int i = (int) aCollector.GetCount() - 1; i >= 0; --i )
5234 {
5235 BOARD_ITEM& item = *aCollector[i];
5236
5237 if( item.IsLocked() || HasLockedDescendant( item ) )
5238 {
5239 aCollector.Remove( &item );
5240 m_lockedItemsFiltered = true;
5241 }
5242 }
5243 }
5244}
5245
5246
5247void PCB_SELECTION_TOOL::FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const
5248{
5249 std::unordered_set<EDA_ITEM*> toAddSet;
5250
5251 // Groups are appended in the order found so the selection order does not depend on addresses
5252 std::vector<EDA_ITEM*> toAdd;
5253
5254 auto queueGroup =
5255 [&]( EDA_ITEM* aGroup )
5256 {
5257 if( toAddSet.insert( aGroup ).second )
5258 toAdd.push_back( aGroup );
5259 };
5260
5261 // Set CANDIDATE on all parents which are included in the GENERAL_COLLECTOR. This
5262 // algorithm is O(3n), whereas checking for the parent inclusion could potentially be O(n^2).
5263 for( int j = 0; j < aCollector.GetCount(); j++ )
5264 {
5265 if( aCollector[j]->GetParent() )
5266 aCollector[j]->GetParent()->ClearFlags( CANDIDATE );
5267
5268 if( aCollector[j]->GetParentFootprint() )
5269 aCollector[j]->GetParentFootprint()->ClearFlags( CANDIDATE );
5270 }
5271
5272 if( aMultiselect )
5273 {
5274 for( int j = 0; j < aCollector.GetCount(); j++ )
5275 aCollector[j]->SetFlags( CANDIDATE );
5276 }
5277
5278 for( int j = 0; j < aCollector.GetCount(); )
5279 {
5280 BOARD_ITEM* item = aCollector[j];
5281 FOOTPRINT* fp = item->GetParentFootprint();
5282 BOARD_ITEM* start = item;
5283
5284 if( !m_isFootprintEditor && fp )
5285 start = fp;
5286
5287 // If a group is entered, disallow selections of objects outside the group.
5289 {
5290 aCollector.Remove( item );
5291 continue;
5292 }
5293
5294 // If any element is a member of a group, replace those elements with the top containing
5295 // group. Exception: generators that mark their children as individually selectable
5296 // (e.g. via stitching) — keep the child and drop the parent generator from the
5297 // collector so the child wins over the surrounding generator shape.
5298 PCB_GENERATOR* selectableParent = nullptr;
5299
5300 if( EDA_GROUP* parent = item->GetParentGroup() )
5301 {
5302 if( parent->AsEdaItem()->Type() == PCB_GENERATOR_T )
5303 {
5304 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
5305
5307 selectableParent = gen;
5308 }
5309 }
5310
5311 if( !selectableParent )
5312 {
5314 {
5315 if( top->AsEdaItem() != item )
5316 {
5317 queueGroup( top->AsEdaItem() );
5318 top->AsEdaItem()->SetFlags( CANDIDATE );
5319
5320 aCollector.Remove( item );
5321 continue;
5322 }
5323 }
5324 }
5325 else
5326 {
5327 for( int k = aCollector.GetCount() - 1; k >= 0; --k )
5328 {
5329 if( aCollector[k] == selectableParent )
5330 {
5331 aCollector.Remove( k );
5332
5333 if( k < j )
5334 --j;
5335
5336 break;
5337 }
5338 }
5339 }
5340
5341 // Footprints are a bit easier as they can't be nested.
5342 if( fp && ( fp->GetFlags() & CANDIDATE ) )
5343 {
5344 // Remove children of selected items
5345 aCollector.Remove( item );
5346 continue;
5347 }
5348
5349 ++j;
5350 }
5351
5352 for( EDA_ITEM* item : toAdd )
5353 {
5354 if( !aCollector.HasItem( item ) )
5355 aCollector.Append( item );
5356 }
5357}
5358
5359
5361{
5362 std::set<BOARD_ITEM*> to_add;
5363
5364 // Iterate from the back so we don't have to worry about removals.
5365 for( int i = (int) aCollector.GetCount() - 1; i >= 0; --i )
5366 {
5367 BOARD_ITEM* item = aCollector[i];
5368
5369 if( item->Type() == PCB_TABLECELL_T )
5370 {
5371 if( !aCollector.HasItem( item->GetParent() ) )
5372 to_add.insert( item->GetParent() );
5373
5374 aCollector.Remove( item );
5375 }
5376 }
5377
5378 for( BOARD_ITEM* item : to_add )
5379 aCollector.Append( item );
5380}
5381
5382
5384 bool aForcePromotion ) const
5385{
5386 std::set<BOARD_ITEM*> to_add;
5387
5388 // Iterate from the back so we don't have to worry about removals.
5389 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
5390 {
5391 BOARD_ITEM* item = aCollector[i];
5392
5393 if( !m_isFootprintEditor && item->Type() == PCB_PAD_T
5394 && ( !frame()->GetPcbNewSettings()->m_AllowFreePads || aForcePromotion ) )
5395 {
5396 if( !aCollector.HasItem( item->GetParent() ) )
5397 to_add.insert( item->GetParent() );
5398
5399 aCollector.Remove( item );
5400 }
5401 }
5402
5403 for( BOARD_ITEM* item : to_add )
5404 aCollector.Append( item );
5405}
5406
5407
5409{
5410 // Iterate from the back so we don't have to worry about removals.
5411 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
5412 {
5413 BOARD_ITEM* item = aCollector[i];
5414
5415 if( item->Type() == PCB_MARKER_T )
5416 aCollector.Remove( item );
5417 }
5418}
5419
5420
5422 const VECTOR2I& aWhere ) const
5423{
5424 const RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
5425 BOX2D viewport = getView()->GetViewport();
5426 BOX2I extents = BOX2ISafe( viewport );
5427
5428 bool need_direct_hit = false;
5429 FOOTPRINT* single_fp = nullptr;
5430
5431 // If the designer is not modifying the existing selection AND we already have
5432 // a selection, then we only want to select items that are directly under the cursor.
5433 // This prevents us from being unable to clear the selection when zoomed into a footprint
5434 if( !m_additive && !m_subtractive && !m_exclusive_or && m_selection.GetSize() > 0 )
5435 {
5436 need_direct_hit = true;
5437
5438 for( EDA_ITEM* item : m_selection )
5439 {
5440 FOOTPRINT* fp = nullptr;
5441
5442 if( item->Type() == PCB_FOOTPRINT_T )
5443 fp = static_cast<FOOTPRINT*>( item );
5444 else if( item->IsBOARD_ITEM() )
5445 fp = static_cast<BOARD_ITEM*>( item )->GetParentFootprint();
5446
5447 // If the selection contains items that are not footprints, then don't restrict
5448 // whether we deselect the item or not.
5449 if( !fp )
5450 {
5451 single_fp = nullptr;
5452 break;
5453 }
5454 else if( !single_fp )
5455 {
5456 single_fp = fp;
5457 }
5458 // If the selection contains items from multiple footprints, then don't restrict
5459 // whether we deselect the item or not.
5460 else if( single_fp != fp )
5461 {
5462 single_fp = nullptr;
5463 break;
5464 }
5465 }
5466 }
5467
5468 auto visibleLayers =
5469 [&]() -> LSET
5470 {
5472 {
5473 LSET set;
5474
5475 for( PCB_LAYER_ID layer : LSET::AllLayersMask() )
5476 set.set( layer, view()->IsLayerVisible( layer ) );
5477
5478 return set;
5479 }
5480 else
5481 {
5482 // Unlike Selectable() this stays unmasked, since it only prunes candidates
5483 // and a pad hole is drawn whenever any physical layer shows
5484 return board()->GetVisibleLayers();
5485 }
5486 };
5487
5488 LSET layers = visibleLayers();
5489
5490 if( settings->GetHighContrast() )
5491 {
5492 layers.reset();
5493
5494 const std::set<int> activeLayers = settings->GetHighContrastLayers();
5495
5496 for( int layer : activeLayers )
5497 {
5498 if( layer >= 0 && layer < PCB_LAYER_ID_COUNT )
5499 layers.set( layer );
5500 }
5501 }
5502
5503 // Iterate from the back so we don't have to worry about removals.
5504 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
5505 {
5506 BOARD_ITEM* item = aCollector[i];
5507 FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( item );
5508
5509 if( !fp )
5510 continue;
5511
5512 // Make footprints not difficult to select in high-contrast modes.
5513 if( layers[fp->GetLayer()] )
5514 continue;
5515
5516 BOX2I bbox = fp->GetLayerBoundingBox( layers );
5517
5518 // If the point clicked is not inside the visible bounding box, we can also remove it.
5519 if( !bbox.Contains( aWhere) )
5520 aCollector.Remove( item );
5521
5522 bool has_hit = false;
5523
5524 for( PCB_LAYER_ID layer : layers )
5525 {
5526 if( fp->HitTestOnLayer( extents, false, layer ) )
5527 {
5528 has_hit = true;
5529 break;
5530 }
5531 }
5532
5533 // If the point is outside of the visible bounding box, we can remove it.
5534 if( !has_hit )
5535 {
5536 aCollector.Remove( item );
5537 }
5538 // Do not require a direct hit on this fp if the existing selection only contains
5539 // this fp's items. This allows you to have a selection of pads from a single
5540 // footprint and still click in the center of the footprint to select it.
5541 else if( single_fp )
5542 {
5543 if( fp == single_fp )
5544 continue;
5545 }
5546 else if( need_direct_hit )
5547 {
5548 has_hit = false;
5549
5550 for( PCB_LAYER_ID layer : layers )
5551 {
5552 if( fp->HitTestOnLayer( aWhere, layer ) )
5553 {
5554 has_hit = true;
5555 break;
5556 }
5557 }
5558
5559 if( !has_hit )
5560 aCollector.Remove( item );
5561 }
5562 }
5563}
5564
5565
5567{
5568 getView()->Update( &m_selection );
5570
5571 return 0;
5572}
5573
5574
5576{
5577 std::set<std::pair<PCB_TABLE*, int>> columns;
5578 bool added = false;
5579
5580 for( EDA_ITEM* item : m_selection )
5581 {
5582 if( PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item ) )
5583 {
5584 PCB_TABLE* table = static_cast<PCB_TABLE*>( cell->GetParent() );
5585 columns.insert( std::make_pair( table, cell->GetColumn() ) );
5586 }
5587 }
5588
5589 for( auto& [ table, col ] : columns )
5590 {
5591 for( int row = 0; row < table->GetRowCount(); ++row )
5592 {
5593 PCB_TABLECELL* cell = table->GetCell( row, col );
5594
5595 if( !cell->IsSelected() )
5596 {
5597 select( table->GetCell( row, col ) );
5598 added = true;
5599 }
5600 }
5601 }
5602
5603 if( added )
5604 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
5605
5606 return 0;
5607}
5608
5609
5611{
5612 std::set<std::pair<PCB_TABLE*, int>> rows;
5613 bool added = false;
5614
5615 for( EDA_ITEM* item : m_selection )
5616 {
5617 if( PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item ) )
5618 {
5619 PCB_TABLE* table = static_cast<PCB_TABLE*>( cell->GetParent() );
5620 rows.insert( std::make_pair( table, cell->GetRow() ) );
5621 }
5622 }
5623
5624 for( auto& [ table, row ] : rows )
5625 {
5626 for( int col = 0; col < table->GetColCount(); ++col )
5627 {
5628 PCB_TABLECELL* cell = table->GetCell( row, col );
5629
5630 if( !cell->IsSelected() )
5631 {
5632 select( table->GetCell( row, col ) );
5633 added = true;
5634 }
5635 }
5636 }
5637
5638 if( added )
5639 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
5640
5641 return 0;
5642}
5643
5644
5646{
5647 std::set<PCB_TABLE*> tables;
5648 bool added = false;
5649
5650 for( EDA_ITEM* item : m_selection )
5651 {
5652 if( PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item ) )
5653 tables.insert( static_cast<PCB_TABLE*>( cell->GetParent() ) );
5654 }
5655
5657
5658 for( PCB_TABLE* table : tables )
5659 {
5660 if( !table->IsSelected() )
5661 {
5662 select( table );
5663 added = true;
5664 }
5665 }
5666
5667 if( added )
5668 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
5669
5670 return 0;
5671}
5672
5673
5675{
5677
5681
5688
5707
5712
5714}
std::function< void(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)> CLIENT_SELECTION_FILTER
Definition actions.h:33
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
Definition box2.h:924
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
static TOOL_ACTION cancelInteractive
Definition actions.h:69
static TOOL_ACTION unselectAll
Definition actions.h:80
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition actions.h:224
static TOOL_ACTION cursorLeft
Definition actions.h:169
static TOOL_ACTION zoomOutCenter
Definition actions.h:133
static TOOL_ACTION unselectItem
Definition actions.h:225
static TOOL_ACTION zoomIn
Definition actions.h:130
static TOOL_ACTION cursorLeftFast
Definition actions.h:174
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition actions.h:214
static TOOL_ACTION selectSetLasso
Definition actions.h:218
static TOOL_ACTION selectSetRect
Set lasso selection mode.
Definition actions.h:217
static TOOL_ACTION groupEnter
Definition actions.h:240
static TOOL_ACTION selectColumns
Definition actions.h:99
static TOOL_ACTION cursorDown
Definition actions.h:168
static TOOL_ACTION zoomOut
Definition actions.h:131
static TOOL_ACTION cursorRightFast
Definition actions.h:175
static TOOL_ACTION deleteLastPoint
Definition actions.h:272
static TOOL_ACTION zoomCenter
Definition actions.h:138
static TOOL_ACTION panDown
Definition actions.h:182
static TOOL_ACTION cursorDblClick
Definition actions.h:178
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition actions.h:211
static TOOL_ACTION cursorDownFast
Definition actions.h:173
static TOOL_ACTION selectionMenu
Run a selection menu to select from a list of items.
Definition actions.h:233
static TOOL_ACTION reselectItem
Definition actions.h:226
static TOOL_ACTION selectRows
Definition actions.h:98
static TOOL_ACTION cursorUpFast
Definition actions.h:172
static TOOL_ACTION panLeft
Definition actions.h:183
static TOOL_ACTION updateMenu
Definition actions.h:268
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION selectionTool
Definition actions.h:248
static TOOL_ACTION cursorClick
Definition actions.h:177
static TOOL_ACTION zoomFitScreen
Definition actions.h:139
static TOOL_ACTION increment
Definition actions.h:91
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION panUp
Definition actions.h:181
static TOOL_ACTION zoomFitObjects
Definition actions.h:140
static TOOL_ACTION zoomInCenter
Definition actions.h:132
static TOOL_ACTION panRight
Definition actions.h:184
static TOOL_ACTION selectTable
Definition actions.h:100
static TOOL_ACTION cursorUp
Cursor control with keyboard.
Definition actions.h:167
static TOOL_ACTION groupLeave
Definition actions.h:241
static TOOL_ACTION finishInteractive
Definition actions.h:70
static TOOL_ACTION cursorRight
Definition actions.h:170
static TOOL_ACTION selectAll
Definition actions.h:79
static TOOL_ACTION unselectItems
Definition actions.h:230
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:229
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
TOOL_MANAGER * getToolManager() const
Return an instance of TOOL_MANAGER class.
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.
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
BASE_SET & reset(size_t pos)
Definition base_set.h:153
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,...
static bool ClassOf(const EDA_ITEM *aItem)
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
Tool for pcb inspection.
int ClearHighlight(const TOOL_EVENT &aEvent)
Clear all board highlights.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:187
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition board_item.h:165
virtual double GetCoverageArea(int aTextMargin) const
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:369
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition board_item.h:279
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:281
virtual bool IsOnCopperLayer() const
Definition board_item.h:204
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition board.cpp:2680
bool IsFootprintLayerVisible(PCB_LAYER_ID aLayer) const
Expect either of the two layers on which a footprint can reside, and returns whether that layer is vi...
Definition board.cpp:1307
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition board.cpp:1269
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1216
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:713
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
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:758
constexpr void SetMaximum()
Definition box2.h:77
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr Vec Centre() const
Definition box2.h:100
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr const SizeVec & GetSize() const
Definition box2.h:209
CN_ANCHOR represents a physical location that can be connected: a pad or a track/arc/via endpoint.
BOARD_CONNECTED_ITEM * Parent() const
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
CN_ITEM represents a BOARD_CONNECTED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
virtual double OnePixelInIU() const =0
virtual int Accuracy() const =0
void Transfer(int aIndex)
Move the item at aIndex (first position is 0) to the backup list.
Definition collector.h:149
void Empty()
Clear the list.
Definition collector.h:87
ITER begin()
Definition collector.h:71
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
bool HasItem(const EDA_ITEM *aItem) const
Tests if aItem has already been collected.
Definition collector.h:193
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition collector.h:107
ITER end()
Definition collector.h:72
void Append(EDA_ITEM *item)
Add an item to the end of the list.
Definition collector.h:97
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
Interactive authoring of geometric constraints (issue #2329).
bool ClearConstraintSelection()
Clear any badge-selected constraint. Returns true if a constraint was selected and is now cleared.
bool EditConstraintAt(const VECTOR2I &aPos)
Open the value dialog for the constraint badged at aPos; returns true if one was hit.
int ShowModal() override
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:78
bool HasDesignBlockLink() const
Definition eda_group.h:99
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:280
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearSelected()
Definition eda_item.h:153
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
bool IsSelected() const
Definition eda_item.h:134
void SetSelected()
Definition eda_item.h:150
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:214
void ClearBrightened()
Definition eda_item.h:154
void SetBrightened()
Definition eda_item.h:151
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition eda_item.h:309
EDA_ITEM * GetParent() const
Definition eda_item.h:112
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:168
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:167
SHAPE_T GetShape() const
Definition eda_shape.h:178
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
bool IsClosed() const
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
bool IsAnyFill() const
Definition eda_shape.h:121
virtual std::vector< SHAPE * > MakeEffectiveShapesForHitTesting() const
Definition eda_shape.h:586
virtual bool IsVisible() const
Definition eda_text.h:226
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
Build a list of segments (SHAPE_SEGMENT) to describe a text shape.
static const TOOL_EVENT DisambiguatePoint
Used to inform tool that it should display the disambiguation menu.
Definition actions.h:364
static const TOOL_EVENT ClearedEvent
Definition actions.h:349
static const TOOL_EVENT InhibitSelectionEditing
Used to inform tools that the selection should temporarily be non-editable.
Definition actions.h:360
static const TOOL_EVENT SelectedEvent
Definition actions.h:347
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
Definition actions.h:354
static const TOOL_EVENT UninhibitSelectionEditing
Definition actions.h:361
static const TOOL_EVENT PointSelectedEvent
Definition actions.h:346
static const TOOL_EVENT SelectedItemsMoved
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:357
static const TOOL_EVENT UnselectedEvent
Definition actions.h:348
ZONES & Zones()
Definition footprint.h:361
PCB_POINTS & Points()
Definition footprint.h:370
const BOX2I GetLayerBoundingBox(const LSET &aLayers) const
Return the bounding box of the footprint on a given set of layers.
std::deque< PAD * > & Pads()
Definition footprint.h:355
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition footprint.h:393
SHAPE_POLY_SET GetBoundingHull() const
Return a bounding polygon for the shapes and pads in the footprint.
bool HitTestOnLayer(const VECTOR2I &aPosition, PCB_LAYER_ID aLayer, int aAccuracy=0) const
Test if the point hits one or more of the footprint elements on a given layer.
const KIID_PATH & GetPath() const
Definition footprint.h:455
DRAWINGS & GraphicalItems()
Definition footprint.h:358
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
void SetIgnoreBlindBuriedVias(bool ignore)
Definition collectors.h:461
void SetIgnoreTracks(bool ignore)
Definition collectors.h:467
void SetIgnoreFootprintsOnFront(bool ignore)
Definition collectors.h:425
void SetIgnoreFPTextOnFront(bool ignore)
Definition collectors.h:413
void SetIgnoreMicroVias(bool ignore)
Definition collectors.h:464
void SetIgnoreZoneFills(bool ignore)
Definition collectors.h:470
void SetIgnorePadsOnBack(bool ignore)
Definition collectors.h:431
void SetIgnoreFPTextOnBack(bool ignore)
Definition collectors.h:407
void SetLayerVisibleBits(const LSET &aLayerBits)
Definition collectors.h:381
void SetIgnoreThroughVias(bool ignore)
Definition collectors.h:458
void SetIgnoreThroughHolePads(bool ignore)
Definition collectors.h:443
void SetIgnoreFPReferences(bool ignore)
Definition collectors.h:455
void SetIgnoreFPValues(bool ignore)
Definition collectors.h:449
void SetIgnorePadsOnFront(bool ignore)
Definition collectors.h:437
void SetIgnoreFootprintsOnBack(bool ignore)
Definition collectors.h:419
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
void SetGuide(const COLLECTORS_GUIDE *aGuide)
Record which COLLECTORS_GUIDE to use.
Definition collectors.h:287
const COLLECTORS_GUIDE * GetGuide() const
Definition collectors.h:289
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition collectors.h:38
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
static const std::vector< KICAD_T > FootprintItems
A scan list for primary footprint items.
Definition collectors.h:112
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double a
Alpha component.
Definition color4d.h:394
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
void SetGroupEditModeActive(bool aActive)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:87
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:70
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
void SetMode(SELECTION_MODE aMode)
void SetSubtractive(bool aSubtractive)
SELECTION_MODE GetMode() const
void SetAdditive(bool aAdditive)
void SetPoly(SHAPE_LINE_CHAIN &aPoly)
void SetOrigin(const VECTOR2I &aOrigin)
Set the origin of the rectangle (the fixed corner)
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
SHAPE_LINE_CHAIN & GetPoly()
void SetExclusiveOr(bool aExclusiveOr)
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the corner that moves with the cursor.
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.
const std::set< int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
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.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
bool IsBOARD_ITEM() const
Definition view_item.h:98
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
double GetScale() const
Definition view.h:298
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition view.cpp:860
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition view.cpp:900
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:365
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition view.cpp:488
int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
Definition view.cpp:743
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:2630
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:2474
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition view.cpp:2575
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition view.h:457
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:729
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition view.cpp:2551
wxString AsString() const
Definition kiid.cpp:423
Definition kiid.h:46
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 & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition lset.cpp:718
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:725
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition lset.cpp:259
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
LSEQ SeqStackupTop2Bottom(PCB_LAYER_ID aSelectedLayer=UNDEFINED_LAYER) const
Generate a sequence of layers that represent a top to bottom stack of this set of layers.
Definition lset.cpp:339
static const LSET & AllLayersMask()
Definition lset.cpp:637
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:693
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
bool IsExcluded() const
Definition marker_base.h:88
const VECTOR2I & GetPos() const
Definition marker_base.h:78
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetChain() const
Definition netinfo.h:122
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:125
REPLACE_TERMINAL_PAD_MENU * m_replaceMenu
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
Definition pad.h:61
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:579
PAD_ATTRIB GetAttribute() const
Definition pad.h:582
static TOOL_ACTION drag45Degree
static TOOL_ACTION selectNetChain
Select all connections belonging to every net in the current item's net chain.
Definition pcb_actions.h:88
static TOOL_ACTION unrouteSelected
Removes all tracks from the selected items to the first pad.
Definition pcb_actions.h:76
static TOOL_ACTION saveToLinkedDesignBlock
static TOOL_ACTION grabUnconnected
Select and move nearest unconnected footprint from ratsnest of selection.
Definition pcb_actions.h:94
static TOOL_ACTION filterSelection
Filter the items in the current selection (invokes dialog)
static TOOL_ACTION setTerminalPad
static TOOL_ACTION highlightNet
static TOOL_ACTION hideLocalRatsnest
static TOOL_ACTION properties
Activation of the edit tool.
static TOOL_ACTION highlightNetChain
static TOOL_ACTION selectOnSheetFromEeschema
Select all components on sheet from Eeschema crossprobing.
Definition pcb_actions.h:97
static TOOL_ACTION selectConnection
Select tracks between junctions or expands an existing selection to pads or the entire connection.
Definition pcb_actions.h:73
static TOOL_ACTION applyDesignBlockLayout
static TOOL_ACTION dragFreeAngle
static TOOL_ACTION clearHighlight
static TOOL_ACTION convertImageToOutlines
static TOOL_ACTION selectUnconnected
Select unconnected footprints from ratsnest of selection.
Definition pcb_actions.h:91
static TOOL_ACTION unrouteSegment
Removes track segment from the selected item to the next segment.
Definition pcb_actions.h:79
static TOOL_ACTION moveIndividually
move items one-by-one
static TOOL_ACTION syncSelection
Sets selection to specified items, zooms to fit, if enabled.
Definition pcb_actions.h:63
static TOOL_ACTION selectSameSheet
Select all components on the same sheet as the selected footprint.
static TOOL_ACTION selectNet
Select all connections belonging to a single net.
Definition pcb_actions.h:82
static TOOL_ACTION move
move or drag an item
static TOOL_ACTION syncSelectionWithNets
Sets selection to specified items with connected nets, zooms to fit, if enabled.
Definition pcb_actions.h:66
static TOOL_ACTION deselectNet
Remove all connections belonging to a single net from the active selection.
Definition pcb_actions.h:85
static TOOL_ACTION placeLinkedDesignBlock
static TOOL_ACTION selectOnSchematic
Select symbols/pins on schematic corresponding to selected footprints/pads.
Common, abstract interface for edit frames.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
double m_TrackOpacity
Opacity override for all tracks.
double m_FilledShapeOpacity
Opacity override for graphic shapes.
double m_ZoneOpacity
Opacity override for filled zone areas.
double m_ImageOpacity
Opacity override for user images.
double m_PadOpacity
Opacity override for SMD pads and PTHs.
double m_ViaOpacity
Opacity override for all types of via.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
The main frame for Pcbnew.
bool IsReference() const
Definition pcb_field.h:76
bool IsValue() const
Definition pcb_field.h:77
A table whose cell text is derived from the board and rebuilt whenever it goes stale.
virtual ACTION_MENU * GetChildContextMenu(TOOL_INTERACTIVE *aTool) const
Get a context menu when interacting with a generator child.
virtual bool IsSelectableAsConnected() const
Indicates whether the generator can be selected as a connected entity.
virtual bool ChildrenAreIndividuallySelectable() const
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
static EDA_GROUP * TopLevelGroup(const BOARD_ITEM &aItem, const EDA_GROUP *aScope, bool isFootprintEditor)
Search for highest level group inside of aScope, containing item.
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
static bool WithinScope(const BOARD_ITEM &aItem, const PCB_GROUP *aScope, bool isFootprintEditor)
Tool that displays edit points allowing to modify items by dragging the points.
bool HasBlockHandle() const
True when the cursor sits on a handle the user can pick.
bool HasPoint()
Indicate the cursor is over an edit point.
bool HasBlockHandles() const
True while handles are shown for the members of a multi-selection or group.
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:39
Private implementation of firewalled private data.
DIALOG_FILTER_SELECTION::OPTIONS m_filterOpts
The selection tool: currently supports:
void highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
static LSET resolveVisibleLayers(const LSET &aVisibleLayers, const LSET &aEnabledLayers)
Return the layers of aVisibleLayers which are actually shown.
int syncSelectionWithNets(const TOOL_EVENT &aEvent)
int SelectTable(const TOOL_EVENT &aEvent)
std::function< void(KIGFX::PREVIEW::SELECTION_AREA &aArea)> AREA_PREVIEW
Called with the drag box every time it changes, before anything is selected.
PCB_BASE_FRAME * frame() const
int syncSelection(const TOOL_EVENT &aEvent)
Set selection to items passed by parameter and connected nets (optionally).
int selectNet(const TOOL_EVENT &aEvent)
Select all copper connections belonging to the same net(s) as the items in the selection.
int filterSelection(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void ZoomFitCrossProbeBBox(const BOX2I &bbox)
Zoom the screen to fit the bounding box for cross probing/selection sync.
void EnterGroup() override
Enter the group at the head of the current selection.
void doSyncSelection(const std::vector< BOARD_ITEM * > &aItems, bool aWithNets)
SELECTION_MODE m_selectionMode
Current selection mode.
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Try to guess best selection candidates in case multiple items are clicked, by doing some brain-dead h...
int selectNetChain(const TOOL_EVENT &aEvent)
Select all copper connections belonging to every net in the selected item's net chain.
bool DragSelectionArea(TOOL_INTERACTIVE &aTool, AREA_PREVIEW aPreview=nullptr)
Drive the rectangle drag-selection loop from another tool's event loop.
void ExitGroup(bool aSelectGroup=false) override
Leave the currently-entered group.
bool isExpandableGraphicShape(const EDA_ITEM *aItem) const
bool toggleTableCellSelection(const VECTOR2I &aPosition)
When the user Ctrl-clicks inside a PCB_TABLE whose cells are already in the selection,...
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
int SelectPolyArea(const TOOL_EVENT &aEvent)
Handles drawing a lasso selection area that allows multiple items to be selected simultaneously.
void SetGroupEditModeActive(bool aActive)
Tell the painter whether items outside the entered group should be dimmed, and recolour the board if ...
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Drop any PCB_MARKERs from the collector.
int UnselectAll(const TOOL_EVENT &aEvent)
Unselect all items on the board.
void unhighlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
void select(EDA_ITEM *aItem) override
Take necessary action mark an item as selected.
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
Select an item under the cursor unless there is something already selected.
bool collectAtPoint(const VECTOR2I &aWhere, GENERAL_COLLECTOR &aCollector, POINT_COLLECT &aOptions, CLIENT_SELECTION_FILTER aClientFilter)
Collect the items at aWhere and narrow them the way a click does.
int SetSelectPoly(const TOOL_EVENT &aEvent)
int SetSelectRect(const TOOL_EVENT &aEvent)
Change the selection mode.
int SelectColumns(const TOOL_EVENT &aEvent)
std::unique_ptr< PRIV > m_priv
Private state (opaque pointer/compilation firewall)
static bool isPadVisible(const PAD &aPad, const LSET &aVisibleLayers)
PCB_TABLECELL * singleSelectedCell() const
int unrouteSelected(const TOOL_EVENT &aEvent)
Unroute the selected board connected items.
bool SelectionContains(const VECTOR2I &aPoint) const
int unrouteSegment(const TOOL_EVENT &aEvent)
Unroute the selected track connected item.
SELECTION & selection() override
Return a reference to the selection.
bool selectGeneratedTableRow(const VECTOR2I &aPosition)
Select the generated table row under a point, when the table itself is what is selected.
int grabUnconnected(const TOOL_EVENT &aEvent)
Select and move other nearest footprint unconnected on same net as selected items.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter)
Return the current selection, filtered according to aClientFilter.
bool ReportFilteredLockedItems()
If the most recent FilterCollectorForLockedItems call filtered a locked item, show an InfoBar warning...
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector, bool aForcePromotion=false) const
Check the "allow free pads" setting and if disabled, replace any pads in the collector with their par...
static bool itemIsSelectableAsConnected(const BOARD_ITEM &aItem, const PCB_GROUP *aEnteredGroup, bool aIsFootprintEditor)
True if an item may be selected by connection expansion.
bool itemPassesFilter(BOARD_ITEM *aItem, bool aMultiSelect, PCB_SELECTION_FILTER_OPTIONS *aRejected=nullptr)
Return true if the given item passes the current SELECTION_FILTER_OPTIONS.
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
std::vector< BOARD_ITEM * > CollectPoint(const VECTOR2I &aWhere, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
The items a click at aWhere would consider, best first.
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=nullptr, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
Select an item pointed by the parameter aWhere.
KIGFX::PCB_VIEW * view() const
void selectAllItemsOnSheet(wxString &aSheetPath)
Select all items with the given sheet timestamp/UUID name (the sheet path).
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
void SelectMultiple(KIGFX::PREVIEW::SELECTION_AREA &aArea, bool aSubtractive=false, bool aExclusiveOr=false)
Selects multiple PCB items within a specified area.
void setTransitions() override
Set up handlers for various events.
PCB_BASE_EDIT_FRAME * editFrame() const
int expandConnection(const TOOL_EVENT &aEvent)
Expand the current connected-item selection to the next boundary (junctions, pads,...
int selectUnconnected(const TOOL_EVENT &aEvent)
Select nearest unconnected footprints on same net as selected items.
virtual bool ctrlClickHighlights() override
Determine if ctrl-click is highlight net or XOR selection.
int selectSheetContents(const TOOL_EVENT &aEvent)
Select all footprints belonging to same sheet, from Eeschema using cross-probing.
int SelectRows(const TOOL_EVENT &aEvent)
int selectSameSheet(const TOOL_EVENT &aEvent)
Select all footprints belonging to same hierarchical sheet as the selected footprint (same sheet path...
void zoomFitSelection()
Zoom the screen to center and fit the current selection.
std::vector< BOARD_ITEM * > CollectMultiple(KIGFX::PREVIEW::SELECTION_AREA &aArea)
The items a drag over aArea would take, in the order SelectMultiple() would take them.
void selectAllConnectedTracks(const std::vector< BOARD_CONNECTED_ITEM * > &aStartItems, STOP_CONDITION aStopCondition)
Select connected tracks and vias.
bool keepsBlockHandles() const
True when a selection mode switch must keep the point editor's block handles alive.
int CursorSelection(const TOOL_EVENT &aEvent)
Select a single item under cursor event handler.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
void collectTableCellsAt(const VECTOR2I &aPosition, GENERAL_COLLECTOR &aCollector)
Collect PCB_TABLECELL items at aPosition into aCollector, scoped to either the active footprint (in t...
void highlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
PCB_BASE_FRAME * m_frame
Pointer to the parent frame.
PCB_SELECTION_FILTER_OPTIONS m_filter
void initializeTableCellSelectionState(PCB_TABLE *aTable)
Mark the existing selection state of table cells so that drag- and shift-click range selection can pr...
PCB_SELECTION & GetSelection()
@ STOP_AT_SEGMENT
Stop when reaching a segment (next track/arc/via).
@ STOP_AT_PAD
Stop when reaching a pad.
@ STOP_NEVER
Select the entire net.
@ STOP_AT_JUNCTION
Stop at any place where more than two traces meet.
int Main(const TOOL_EVENT &aEvent)
The main loop.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
void pruneObscuredSelectionCandidates(GENERAL_COLLECTOR &aCollector) const
void OnIdle(wxIdleEvent &aEvent)
PCB_DRAW_PANEL_GAL * canvas() const
void FilterCollectorForFootprints(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Drop footprints that are not directly selected.
PCB_TABLECELL * m_previousFirstCell
Anchor cell for shift+click range selection in a PCB_TABLE.
PCB_SELECTION m_blockedSelection
Empty selection returned when locked items block an action, real selection stays intact.
void FindItem(BOARD_ITEM *aItem)
Take necessary actions to mark an item as found.
void FilterCollectorForLockedItems(GENERAL_COLLECTOR &aCollector)
In the PCB editor strip out any locked items unless the OverrideLocks checkbox is set.
int SelectRectArea(const TOOL_EVENT &aEvent)
Handles drawing a selection box that allows multiple items to be selected simultaneously.
int updateSelection(const TOOL_EVENT &aEvent)
Event handler to update the selection VIEW_ITEM.
bool Init() override
Init() is called once upon a registration of the tool.
KIGFX::VIEW_GROUP m_enteredGroupOverlay
Overlay for the entered group's frame.
void selectConnections(const std::vector< BOARD_ITEM * > &aItems)
int hitTestDistance(const VECTOR2I &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
bool extendTableCellSelectionTo(const VECTOR2I &aPosition)
If the current selection holds one or more cells from a single PCB_TABLE and the cursor is over anoth...
void selectAllConnectedShapes(const std::vector< PCB_SHAPE * > &aStartItems)
Select all non-closed shapes that are graphically connected to the given start items.
void SelectAllItemsOnNet(int aNetCode, bool aSelect=true)
Select all items with the given net code.
void FilterCollectorForTableCells(GENERAL_COLLECTOR &aCollector) const
Promote any table cell selections to the whole table.
void unselect(EDA_ITEM *aItem) override
Take necessary action mark an item as unselected.
int SelectAll(const TOOL_EVENT &aEvent)
Select all items on the board.
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector, bool aMultiSelect, PCB_SELECTION_FILTER_OPTIONS *aRejected=nullptr)
Apply the SELECTION_FITLER_OPTIONS to the collector.
PCB_SELECTION m_selection
Current state of selection.
static bool isOnVisibleFootprintSide(const BOARD_ITEM &aItem, bool aFrontVisible, bool aBackVisible, bool aIsFootprintEditor)
True if the Render tab's Footprints Front/Back switches leave aItem drawn, mirroring the ViewGetLOD()...
void selectCellsBetween(const VECTOR2D &aStart, const VECTOR2D &aEnd, PCB_TABLE *aTable)
Select table cells contained within the rectangle defined by two corner points, combining the result ...
PCB_GROUP * m_enteredGroup
If non-null, selections are limited to members of this group.
static bool HasLockedDescendant(const BOARD_ITEM &aItem)
bool selectTableCells(PCB_TABLE *aTable)
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:80
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
std::vector< VECTOR2I > GetConnectionPoints() const
int GetRowSpan() const
int GetColSpan() const
int GetRow() const
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:165
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
const VECTOR2I & GetEnd() const
Definition pcb_track.h:97
VECTOR2I GetPosition() const override
Definition pcb_track.h:615
int GetWidth() const override
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
A small class to help profiling.
Definition profile.h:46
void Start()
Start or restart the counter.
Definition profile.h:74
double msecs(bool aSinceLast=false)
Definition profile.h:148
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
void update() override
Update menu state stub.
Describe ratsnest for a single net.
const std::vector< CN_EDGE > & GetEdges() const
bool RoutingInProgress()
Returns whether routing is currently active.
Definition seg.h:38
static SEG::ecoord Square(int a)
Definition seg.h:119
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
bool doSelectionMenu(COLLECTOR *aCollector)
wxTimer m_disambiguateTimer
Timer to show the disambiguate menu.
bool m_drag_additive
Add multiple items to selection.
bool m_exclusive_or
Items' selection state should be toggled.
int AddItemsToSel(const TOOL_EVENT &aEvent)
int AddItemToSel(const TOOL_EVENT &aEvent)
int UpdateMenu(const TOOL_EVENT &aEvent)
Update a menu's state based on the current selection.
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics from the state ...
VECTOR2I m_originalCursor
Location of original cursor when starting click.
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
bool m_subtractive
Items should be removed from selection.
SELECTION_TOOL(const std::string &aName)
bool m_highlight_modifier
Select highlight net on left click.
bool m_skip_heuristics
Show disambiguation menu for all items under the cursor rather than trying to narrow them down first ...
bool m_inSelectMultiple
A selection box is being dragged out.
int ReselectItem(const TOOL_EVENT &aEvent)
bool m_drag_subtractive
Remove multiple from selection.
bool m_additive
Items should be added to sel (instead of replacing).
bool hasModifier()
True if a selection modifier is enabled, false otherwise.
bool m_canceledMenu
Sets to true if the disambiguation menu was canceled.
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
Definition selection.cpp:38
virtual void Remove(EDA_ITEM *aItem)
Definition selection.cpp:60
EDA_ITEM * Front() const
Definition selection.h:176
void ClearReferencePoint()
bool Empty() const
Checks if there is anything selected.
Definition selection.h:114
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void GenerateBBoxCache() const
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
double Area(bool aAbsolute=true) const
Return the area of this chain.
virtual size_t GetPointCount() const override
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
void Remove(int aStartIndex, int aEndIndex)
Remove the range of points [start_index, end_index] from the line chain.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition shape.h:181
bool ToolStackIsEmpty()
Represent a single user action.
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:195
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
@ REDRAW
Full drawing refresh.
Definition tool_base.h:79
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
Generic, UI-independent tool event.
Definition tool_event.h:167
void SetParameter(T aParam)
Set a non-standard parameter assigned to the event.
Definition tool_event.h:539
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
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 SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Assign a context menu and tells when it should be activated.
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).
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
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.
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
TOOLS_HOLDER * GetToolHolder() const
Handle a list of polygons defining a copper zone.
Definition zone.h:70
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:834
bool HitTestForCorner(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a corner.
Definition zone.cpp:987
bool HitTestForEdge(const VECTOR2I &refPos, int aAccuracy, SHAPE_POLY_SET::VERTEX_INDEX *aCornerHit=nullptr) const
Test if the given VECTOR2I is near a segment defined by 2 corners.
Definition zone.cpp:998
bool IsTeardropArea() const
Definition zone.h:809
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
bool GetDoNotAllowZoneFills() const
Definition zone.h:851
A type-safe container of any type.
Definition ki_any.h:92
#define EXCLUDE_ZONES
#define IGNORE_NETS
Return a list of items connected to a source item aItem.
@ SUBTRACT
Definition cursors.h:69
@ SELECT_WINDOW
Definition cursors.h:83
@ SELECT_LASSO
Definition cursors.h:85
@ MOVING
Definition cursors.h:45
@ ARROW
Definition cursors.h:43
#define DEFAULT_TEXT_SIZE
The default text size in mils. (can be changed in preference menu)
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
@ RECURSE
Definition eda_item.h:51
std::function< INSPECT_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Used to inspect and possibly collect the (search) results of iterating over a list or tree of KICAD_T...
Definition eda_item.h:88
#define BRIGHTENED
item is drawn with a bright contour
#define IS_NEW
New item, just created.
#define SELECTED
Item was manually selected by the user.
#define ENTERED
indicates a group has been entered
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define CANDIDATE
flag indicating that the structure is connected
#define IS_MOVING
Item being moved.
@ SEGMENT
Definition eda_shape.h:57
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
a few functions useful in geometry calculations.
double m_PcbSelectionVisibilityRatio
Board object selection visibility limit.
std::string source
KIID niluuid(0)
@ LAYER_POINTS
PCB reference/manual snap points visibility.
Definition layer_ids.h:317
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:280
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition layer_ids.h:300
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
Definition layer_ids.h:291
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_TRACKS
Definition layer_ids.h:263
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
@ LAYER_SUBGRIDS
Routing/placement subgrids (PCB_GRID_ITEM) visibility and color.
Definition layer_ids.h:323
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition layer_ids.h:228
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Cu
Definition layer_ids.h:61
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ B_SilkS
Definition layer_ids.h:97
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
@ F_Cu
Definition layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition macros.h:79
MOUSE_DRAG_ACTION
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
@ COLOR
Color has changed.
Definition view_item.h:50
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:35
STL namespace.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ PTH
Plated through hole pad.
Definition padstack.h:99
Class to handle a set of BOARD_ITEMs.
void connectedItemFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
static void passEvent(TOOL_EVENT *const aEvent, const TOOL_ACTION *const aAllowedActions[])
static bool itemIsIncludedByFilter(const BOARD_ITEM &aItem, const BOARD &aBoard, const DIALOG_FILTER_SELECTION::OPTIONS &aFilterOptions)
Determine if an item is included by the filter specified.
@ ID_REPLACE_TERMINAL_PAD_A
@ ID_REPLACE_TERMINAL_PAD_B
bool IsGeneratedTableCell(const EDA_ITEM *aItem)
True for a cell whose text is generated from the board, so only its formatting is the user's.
Definition pcb_table.h:355
TRACK_DRAG_ACTION
CITER next(CITER it)
Definition ptree.cpp:120
Class that computes missing connections on a PCB.
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
static std::vector< KICAD_T > tableCellTypes
const TOOL_ACTION * allowedActions[]
static void passEvent(TOOL_EVENT *const aEvent, const TOOL_ACTION *const aAllowedActions[])
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
SELECTION_MODE
const int scale
Increment event parameters.
Definition actions.h:330
Struct that will be set with the result of the user choices in the dialog.
const BOARD_ITEM * m_Item
This file contains data structures that are saved in the project file or project local settings file ...
bool otherItems
Anything not fitting one of the above categories.
bool graphics
Graphic lines, shapes, polygons.
bool footprints
Allow selecting entire footprints.
bool text
Text (free or attached to a footprint)
bool lockedItems
Allow selecting locked items.
What one point collection needs beyond the point, and the one count it reports back.
bool m_SelectedOnly
Subtracting takes only selected.
size_t m_PreFilterCount
Count before that filter, out.
bool m_OnDrag
Locked items cannot be dragged.
PCB_SELECTION_FILTER_OPTIONS * m_Rejected
What the Selection Filter took.
const std::string table
std::vector< DATABASE_CONNECTION::ROW > rows
KIBIS top(path, &reporter)
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
int radius
VECTOR2I end
int actual
const int accuracy
int delta
@ TA_MOUSE_UP
Definition tool_event.h:65
@ TA_MOUSE_WHEEL
Definition tool_event.h:69
@ CMENU_NOW
Right now (after TOOL_INTERACTIVE::SetContextMenu).
Definition tool_event.h:152
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_ANY
Definition tool_event.h:56
@ BUT_MIDDLE
Definition tool_event.h:130
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_CONSTRAINT_T
a geometric constraint between board items
Definition typeinfo.h:237
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ TYPE_NOT_INIT
Definition typeinfo.h:73
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
Definition typeinfo.h:240
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:71
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:91
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:99
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ 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_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:102
@ PCB_STACKUP_TABLE_T
class PCB_STACKUP_TABLE, a live stackup table derived from PCB_TABLE
Definition typeinfo.h:242
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
Definition typeinfo.h:239
constexpr bool IsGeneratedTableType(const KICAD_T aType)
A PCB_TABLE subclass whose cells are generated from the board rather than typed by the user.
Definition typeinfo.h:328
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:55
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)
Definition vector2wx.h:36
static PIECE polygon(std::vector< VIA_CROSS_SECTION_GEOMETRY::POINT > aPoints, bool aMixed=false)