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 (C) 2017-2023 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, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#ifndef PCB_SELECTION_TOOL_H
29#define PCB_SELECTION_TOOL_H
30
31#include <functional>
32#include <memory>
33
34#include <math/vector2d.h>
36#include <tool/action_menu.h>
37#include <tool/selection_tool.h>
38#include <tool/tool_menu.h>
40#include <tools/pcb_tool_base.h>
41#include <tools/pcb_selection.h>
42
43class PCB_BASE_FRAME;
44class BOARD_ITEM;
46class PCB_TABLE;
47
48namespace KIGFX
49{
50 class GAL;
51}
52
53
55 std::function<void( const VECTOR2I&, GENERAL_COLLECTOR&, PCB_SELECTION_TOOL* )>;
56
57
68{
69public:
72
74 bool Init() override;
75
77 void Reset( RESET_REASON aReason ) override;
78
79 void OnIdle( wxIdleEvent& aEvent );
80
82 {
84 }
85
89 int Main( const TOOL_EVENT& aEvent );
90
95
106 bool aConfirmLockedItems = false );
107
109 int CursorSelection( const TOOL_EVENT& aEvent );
110
111 int SelectColumns( const TOOL_EVENT& aEvent );
112 int SelectRows( const TOOL_EVENT& aEvent );
113 int SelectTable( const TOOL_EVENT& aEvent );
114
116 int ClearSelection( const TOOL_EVENT& aEvent );
117 void ClearSelection( bool aQuietMode = false );
118
120 int SelectAll( const TOOL_EVENT& aEvent );
121
123 int UnselectAll( const TOOL_EVENT& aEvent );
124
130 void FindItem( BOARD_ITEM* aItem );
131
137 void select( EDA_ITEM* aItem ) override;
138
142 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
143
150 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
151
159 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
160
167 void RebuildSelection();
168
170 {
171 return m_filter;
172 }
173
175 void setTransitions() override;
176
178 void zoomFitSelection();
179
181 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
182
186 void EnterGroup();
187
193 void ExitGroup( bool aSelectGroup = false );
194
199
201
206 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
207
213 bool aForcePromotion = false ) const;
214
218 void FilterCollectorForTableCells( GENERAL_COLLECTOR& aCollector ) const;
219
223 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
224
228 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );
229
234 const VECTOR2I& aWhere ) const;
235
236protected:
238 {
239 return static_cast<KIGFX::PCB_VIEW*>( getView() );
240 }
241
243 {
244 return getViewControls();
245 }
246
248 {
249 return getEditFrame<PCB_BASE_FRAME>();
250 }
251
253 {
254 return getEditFrame<PCB_BASE_EDIT_FRAME>();
255 }
256
257 BOARD* board() const
258 {
259 return getModel<BOARD>();
260 }
261
263 {
264 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
265 }
266
267 virtual bool ctrlClickHighlights() override;
268
269 SELECTION& selection() override { return m_selection; }
270
271private:
286 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
287 bool* aSelectionCancelledFlag = nullptr,
288 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
289
298 bool selectCursor( bool aForceSelect = false,
299 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
300
306 bool selectMultiple();
307
308 bool selectTableCells( PCB_TABLE* aTable );
309
313 int disambiguateCursor( const TOOL_EVENT& aEvent );
314
318 int expandConnection( const TOOL_EVENT& aEvent );
319
323 int unrouteSelected( const TOOL_EVENT& aEvent );
324
328 int selectNet( const TOOL_EVENT& aEvent );
329
333 int selectUnconnected( const TOOL_EVENT& aEvent );
334
338 int grabUnconnected( const TOOL_EVENT& aEvent );
339
341 {
353 };
354
360 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
361 STOP_CONDITION aStopCondition );
362
368 void selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems );
369
373 bool isExpandableGraphicShape( const EDA_ITEM* aItem ) const;
374
375 /*
376 * Select tracks and vias connected to specified board items.
377 */
378 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
379
385 void selectAllItemsOnSheet( wxString& aSheetPath );
386
388 int selectSheetContents( const TOOL_EVENT& aEvent );
389
392 int selectSameSheet( const TOOL_EVENT& aEvent );
393
396 int syncSelection( const TOOL_EVENT& aEvent );
397 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
398 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
399
401 int filterSelection( const TOOL_EVENT& aEvent );
402
404 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect );
405
411 void unselect( EDA_ITEM* aItem ) override;
412
420 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
421
429 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
430
434 bool selectionContains( const VECTOR2I& aPoint ) const;
435
439 int hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
440
444 int updateSelection( const TOOL_EVENT& aEvent );
445
446 void pruneObscuredSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
447
449
450private:
451 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
452
453 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
454
455private:
456 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
458
459 PCB_SELECTION m_selection; // Current state of selection
460
462
463 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
464
465 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
466 // members of this group
467 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
468
470 class PRIV;
471 std::unique_ptr<PRIV> m_priv;
472};
473
474#endif /* PCB_SELECTION_TOOL_H */
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:319
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:202
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:48
Common, abstract interface for edit frames.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual PCB_LAYER_ID GetActiveLayer() const
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:52
Private implementation of firewalled private data.
The selection tool: currently supports:
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.
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 doSyncSelection(const std::vector< BOARD_ITEM * > &aItems, bool aWithNets)
Invoke filter dialog and modify current selection.
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...
bool itemPassesFilter(BOARD_ITEM *aItem, bool aMultiSelect)
bool isExpandableGraphicShape(const EDA_ITEM *aItem) const
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Drop any PCB_MARKERs from the collector.
int UnselectAll(const TOOL_EVENT &aEvent)
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.
int SelectColumns(const TOOL_EVENT &aEvent)
std::unique_ptr< PRIV > m_priv
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection, filtered according to aClientFilter.
int unrouteSelected(const TOOL_EVENT &aEvent)
Unroute the selected board connected items.
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.
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...
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector, bool aMultiSelect)
Apply the SELECTION_FITLER_OPTIONS to the collector.
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 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.
PCB_LAYER_ID GetActiveLayer()
int selectUnconnected(const TOOL_EVENT &aEvent)
Select nearest unconnected footprints on same net as selected items.
virtual bool ctrlClickHighlights() override
Determines 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 EnterGroup()
Enter the group at the head of the current selection.
void zoomFitSelection()
Zoom the screen to fit the bounding box for cross probing/selection sync.
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 highlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
PCB_BASE_FRAME * m_frame
PCB_SELECTION_FILTER_OPTIONS m_filter
PCB_SELECTION & GetSelection()
@ 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.
void FindItem(BOARD_ITEM *aItem)
Take necessary actions to mark an item as found.
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.
BOARD * board() const
KIGFX::VIEW_GROUP m_enteredGroupOverlay
void selectConnections(const std::vector< BOARD_ITEM * > &aItems)
int hitTestDistance(const VECTOR2I &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
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.
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
void ExitGroup(bool aSelectGroup=false)
Leave the currently-entered group.
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.
PCB_SELECTION m_selection
bool selectTableCells(PCB_TABLE *aTable)
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, SELECTION *aGroup=nullptr) override
Unhighlight the item visually.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:167
KICURSOR
Definition: cursors.h:34
void Reset() override
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
std::function< void(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)> CLIENT_SELECTION_FILTER
This file contains data structures that are saved in the project file or project local settings file ...