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 <memory>
32
33#include <math/vector2d.h>
35#include <tool/action_menu.h>
36#include <tool/selection_tool.h>
37#include <tool/tool_menu.h>
39#include <tools/pcb_tool_base.h>
40#include <tools/pcb_selection.h>
41
42class PCB_BASE_FRAME;
43class BOARD_ITEM;
45class PCB_TABLE;
46
47namespace KIGFX
48{
49 class GAL;
50}
51
52
54
55
66{
67public:
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
104 bool aConfirmLockedItems = false );
105
107 int CursorSelection( const TOOL_EVENT& aEvent );
108
109 int SelectColumns( const TOOL_EVENT& aEvent );
110 int SelectRows( const TOOL_EVENT& aEvent );
111 int SelectTable( const TOOL_EVENT& aEvent );
112
114 int ClearSelection( const TOOL_EVENT& aEvent );
115 void ClearSelection( bool aQuietMode = false );
116
118 int SelectAll( const TOOL_EVENT& aEvent );
119
121 int UnselectAll( const TOOL_EVENT& aEvent );
122
128 void FindItem( BOARD_ITEM* aItem );
129
135 void select( EDA_ITEM* aItem ) override;
136
140 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
141
148 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
149
157 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
158
165 void RebuildSelection();
166
168 {
169 return m_filter;
170 }
171
173 void setTransitions() override;
174
176 void zoomFitSelection();
177
179 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
180
184 void EnterGroup();
185
191 void ExitGroup( bool aSelectGroup = false );
192
197
199
204 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
205
211 bool aForcePromotion = false ) const;
212
216 void FilterCollectorForTableCells( GENERAL_COLLECTOR& aCollector ) const;
217
221 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
222
226 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );
227
232 const VECTOR2I& aWhere ) const;
233
234protected:
236 {
237 return static_cast<KIGFX::PCB_VIEW*>( getView() );
238 }
239
241 {
242 return getViewControls();
243 }
244
246 {
247 return getEditFrame<PCB_BASE_FRAME>();
248 }
249
251 {
252 return getEditFrame<PCB_BASE_EDIT_FRAME>();
253 }
254
255 BOARD* board() const
256 {
257 return getModel<BOARD>();
258 }
259
261 {
262 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
263 }
264
265 virtual bool ctrlClickHighlights() override;
266
267 SELECTION& selection() override { return m_selection; }
268
269private:
284 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
285 bool* aSelectionCancelledFlag = nullptr,
286 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
287
296 bool selectCursor( bool aForceSelect = false,
297 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
298
304 bool selectMultiple();
305
306 bool selectTableCells( PCB_TABLE* aTable );
307
311 int disambiguateCursor( const TOOL_EVENT& aEvent );
312
316 int expandConnection( const TOOL_EVENT& aEvent );
317
321 int unrouteSelected( const TOOL_EVENT& aEvent );
322
326 int selectNet( const TOOL_EVENT& aEvent );
327
331 int selectUnconnected( const TOOL_EVENT& aEvent );
332
336 int grabUnconnected( const TOOL_EVENT& aEvent );
337
339 {
351 };
352
358 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
359 STOP_CONDITION aStopCondition );
360
366 void selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems );
367
371 bool isExpandableGraphicShape( const EDA_ITEM* aItem ) const;
372
373 /*
374 * Select tracks and vias connected to specified board items.
375 */
376 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
377
383 void selectAllItemsOnSheet( wxString& aSheetPath );
384
386 int selectSheetContents( const TOOL_EVENT& aEvent );
387
390 int selectSameSheet( const TOOL_EVENT& aEvent );
391
394 int syncSelection( const TOOL_EVENT& aEvent );
395 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
396 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
397
399 int filterSelection( const TOOL_EVENT& aEvent );
400
402 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect );
403
409 void unselect( EDA_ITEM* aItem ) override;
410
418 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
419
427 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
428
432 bool selectionContains( const VECTOR2I& aPoint ) const;
433
437 int hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
438
442 int updateSelection( const TOOL_EVENT& aEvent );
443
444 void pruneObscuredSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
445
447
448private:
449 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
450
451 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
452
453private:
454 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
456
457 PCB_SELECTION m_selection; // Current state of selection
458
460
461 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
462
463 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
464 // members of this group
465 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
466
468 class PRIV;
469 std::unique_ptr<PRIV> m_priv;
470};
471
472#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:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:323
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:206
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:51
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
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)
This file contains data structures that are saved in the project file or project local settings file ...