KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_selection_tool.h
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 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef PCB_SELECTION_TOOL_H
25#define PCB_SELECTION_TOOL_H
26
27#include <functional>
28#include <memory>
29
30#include <tool/actions.h>
31#include <math/vector2d.h>
34#include <tool/action_menu.h>
35#include <tool/selection_tool.h>
36#include <tool/tool_menu.h>
38#include <tools/pcb_tool_base.h>
39#include <tools/pcb_selection.h>
40
41class PCB_BASE_FRAME;
42class BOARD_ITEM;
44class PCB_TABLE;
45class PCB_TABLECELL;
46
47namespace KIGFX
48{
49 class GAL;
50}
51
52
63{
64public:
66 using AREA_PREVIEW = std::function<void( KIGFX::PREVIEW::SELECTION_AREA& aArea )>;
67
70
72 bool Init() override;
73
75 void Reset( RESET_REASON aReason ) override;
76
77 void OnIdle( wxIdleEvent& aEvent );
78
80 {
82 }
83
87 int Main( const TOOL_EVENT& aEvent );
88
93
102
104 int CursorSelection( const TOOL_EVENT& aEvent );
105
106 int SelectColumns( const TOOL_EVENT& aEvent );
107 int SelectRows( const TOOL_EVENT& aEvent );
108 int SelectTable( const TOOL_EVENT& aEvent );
109
111 int ClearSelection( const TOOL_EVENT& aEvent );
112 void ClearSelection( bool aQuietMode = false );
113
115 int SelectAll( const TOOL_EVENT& aEvent );
116
118 int UnselectAll( const TOOL_EVENT& aEvent );
119
121 int SetSelectRect( const TOOL_EVENT& aEvent );
122 int SetSelectPoly( const TOOL_EVENT& aEvent );
123
129 int SelectRectArea( const TOOL_EVENT& aEvent );
130
141 bool DragSelectionArea( TOOL_INTERACTIVE& aTool, AREA_PREVIEW aPreview = nullptr );
142
149 int SelectPolyArea( const TOOL_EVENT& aEvent );
150
160 std::vector<BOARD_ITEM*> CollectPoint( const VECTOR2I& aWhere,
161 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
162
169 std::vector<BOARD_ITEM*> CollectMultiple( KIGFX::PREVIEW::SELECTION_AREA& aArea );
170
174 void SelectMultiple( KIGFX::PREVIEW::SELECTION_AREA& aArea, bool aSubtractive = false,
175 bool aExclusiveOr = false );
176
182 void FindItem( BOARD_ITEM* aItem );
183
189 void select( EDA_ITEM* aItem ) override;
190
194 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
195
202 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
203
211 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
212
219 void RebuildSelection();
220
222 {
223 return m_filter;
224 }
225
227 void setTransitions() override;
228
230 void zoomFitSelection();
231
233 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
234
238 void EnterGroup() override;
239
245 void ExitGroup( bool aSelectGroup = false ) override;
246
251
252 PCB_LAYER_ID GetActiveLayer() { return m_frame->GetActiveLayer(); }
253
270
276 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
277 STOP_CONDITION aStopCondition );
278
283
289 static bool HasLockedDescendant( const BOARD_ITEM* aItem );
290
292 static bool isWithinEnteredGroup( BOARD_ITEM* aItem, PCB_GROUP* aEnteredGroup, bool aIsFootprintEditor );
293
300
305 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
306
312 bool aForcePromotion = false ) const;
313
317 void FilterCollectorForTableCells( GENERAL_COLLECTOR& aCollector ) const;
318
322 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
323
327 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect,
328 PCB_SELECTION_FILTER_OPTIONS* aRejected = nullptr );
329
334 const VECTOR2I& aWhere ) const;
335
336protected:
338 {
339 return static_cast<KIGFX::PCB_VIEW*>( getView() );
340 }
341
343 {
344 return getViewControls();
345 }
346
348 {
350 }
351
356
357 BOARD* board() const
358 {
359 return getModel<BOARD>();
360 }
361
363 {
364 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
365 }
366
367 virtual bool ctrlClickHighlights() override;
368
369 SELECTION& selection() override { return m_selection; }
370
371private:
375 bool selectChartRow( const VECTOR2I& aPosition );
376
391 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
392 bool* aSelectionCancelledFlag = nullptr,
393 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
394
397 {
398 bool m_OnDrag = false;
399 bool m_SelectedOnly = false;
401 size_t m_PreFilterCount = 0;
402 };
403
416 bool collectAtPoint( const VECTOR2I& aWhere, GENERAL_COLLECTOR& aCollector,
417 POINT_COLLECT& aOptions, CLIENT_SELECTION_FILTER aClientFilter );
418
427 bool selectCursor( bool aForceSelect = false,
428 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
429
430 bool selectTableCells( PCB_TABLE* aTable );
431
437
443 void selectCellsBetween( const VECTOR2D& aStart, const VECTOR2D& aEnd, PCB_TABLE* aTable );
444
453 bool extendTableCellSelectionTo( const VECTOR2I& aPosition );
454
464 bool toggleTableCellSelection( const VECTOR2I& aPosition );
465
470 void collectTableCellsAt( const VECTOR2I& aPosition, GENERAL_COLLECTOR& aCollector );
471
477
481 int disambiguateCursor( const TOOL_EVENT& aEvent );
482
486 int expandConnection( const TOOL_EVENT& aEvent );
487
491 int unrouteSelected( const TOOL_EVENT& aEvent );
492
496 int unrouteSegment( const TOOL_EVENT& aEvent );
497
501 int selectNet( const TOOL_EVENT& aEvent );
502
506 int selectNetChain( const TOOL_EVENT& aEvent );
507
511 int selectUnconnected( const TOOL_EVENT& aEvent );
512
516 int grabUnconnected( const TOOL_EVENT& aEvent );
517
523 void selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems );
524
528 bool isExpandableGraphicShape( const EDA_ITEM* aItem ) const;
529
530 /*
531 * Select tracks and vias connected to specified board items.
532 */
533 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
534
540 void selectAllItemsOnSheet( wxString& aSheetPath );
541
543 int selectSheetContents( const TOOL_EVENT& aEvent );
544
547 int selectSameSheet( const TOOL_EVENT& aEvent );
548
551 int syncSelection( const TOOL_EVENT& aEvent );
552 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
553 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
554
556 int filterSelection( const TOOL_EVENT& aEvent );
557
559 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect,
560 PCB_SELECTION_FILTER_OPTIONS* aRejected = nullptr );
561
567 void unselect( EDA_ITEM* aItem ) override;
568
576 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
577
585 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
586
590 bool selectionContains( const VECTOR2I& aPoint ) const;
591
595 int hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
596
600 int updateSelection( const TOOL_EVENT& aEvent );
601
602 void pruneObscuredSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
603
605
606private:
607 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
608
609 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
610
611private:
612 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
614
615 PCB_SELECTION m_selection; // Current state of selection
616
617 PCB_SELECTION m_blockedSelection; // Empty selection returned when locked items
618 // block an action, real selection stays intact
619
621
622 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
623
624 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
625 // members of this group
626 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
627
628 SELECTION_MODE m_selectionMode; // Current selection mode
629
631
632 // Anchor cell for shift+click range selection in a PCB_TABLE
634
636 class PRIV;
637 std::unique_ptr<PRIV> m_priv;
638};
639
640#endif /* PCB_SELECTION_TOOL_H */
std::function< void(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)> CLIENT_SELECTION_FILTER
Definition actions.h:33
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
Abstract interface for drawing on a 2D-surface.
Represent a selection area (currently a rectangle) in a VIEW, drawn corner-to-corner between two poin...
An interface for classes handling user events controlling the view behavior such as zooming,...
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition view_group.h:39
Common, abstract interface for edit frames.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
Private implementation of firewalled private data.
void highlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Highlight the item visually.
int syncSelectionWithNets(const TOOL_EVENT &aEvent)
int SelectTable(const TOOL_EVENT &aEvent)
Clear current selection event handler.
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)
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)
Return true if the given item passes the current SELECTION_FILTER_OPTIONS.
void ZoomFitCrossProbeBBox(const BOX2I &bbox)
void EnterGroup() override
Enter the group at the head of the current selection.
void doSyncSelection(const std::vector< BOARD_ITEM * > &aItems, bool aWithNets)
Invoke filter dialog and modify current selection.
SELECTION_MODE m_selectionMode
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,...
static bool HasLockedDescendant(const BOARD_ITEM *aItem)
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 FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Drop any PCB_MARKERs from the collector.
int UnselectAll(const TOOL_EVENT &aEvent)
Change the selection mode.
void unhighlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
bool selectionContains(const VECTOR2I &aPoint) const
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)
int SelectColumns(const TOOL_EVENT &aEvent)
std::unique_ptr< PRIV > m_priv
PCB_TABLECELL * singleSelectedCell() const
int unrouteSelected(const TOOL_EVENT &aEvent)
Unroute the selected board connected items.
int unrouteSegment(const TOOL_EVENT &aEvent)
Unroute the selected track connected item.
SELECTION & selection() override
Return a reference to the selection.
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.
static bool isWithinEnteredGroup(BOARD_ITEM *aItem, PCB_GROUP *aEnteredGroup, bool aIsFootprintEditor)
True if aItem may be selected while aEnteredGroup is entered (24967).
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...
bool itemPassesFilter(BOARD_ITEM *aItem, bool aMultiSelect, PCB_SELECTION_FILTER_OPTIONS *aRejected=nullptr)
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).
PCB_GROUP * GetEnteredGroup()
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
Zoom the screen to center and fit the current selection.
PCB_BASE_EDIT_FRAME * editFrame() const
int expandConnection(const TOOL_EVENT &aEvent)
Expand the current connected-item selection to the next boundary (junctions, pads,...
PCB_SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
bool selectChartRow(const VECTOR2I &aPosition)
Select the drill chart row under a point, when the chart itself is what is selected.
PCB_LAYER_ID GetActiveLayer()
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 hierarchical sheet as the selected footprint (same sheet path...
int SelectRows(const TOOL_EVENT &aEvent)
int selectSameSheet(const TOOL_EVENT &aEvent)
Set selection to items passed by parameter and connected nets (optionally).
void zoomFitSelection()
Zoom the screen to fit the bounding box for cross probing/selection sync.
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.
KIGFX::VIEW_CONTROLS * controls() const
int CursorSelection(const TOOL_EVENT &aEvent)
int ClearSelection(const TOOL_EVENT &aEvent)
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
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
PCB_SELECTION m_blockedSelection
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
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)
Unselect 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.
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 ...
bool selectTableCells(PCB_TABLE *aTable)
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
SELECTION_TOOL(const std::string &aName)
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
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition tool_base.cpp:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
KICURSOR
Definition cursors.h:40
void Reset() override
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
SELECTION_MODE
This file contains data structures that are saved in the project file or project local settings file ...
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.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682