KiCad PCB EDA Suite
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-2022 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;
45
46namespace KIGFX
47{
48 class GAL;
49}
50
51
53
54
65{
66public:
69
71 bool Init() override;
72
74 void Reset( RESET_REASON aReason ) override;
75
76 void OnIdle( wxIdleEvent& aEvent );
77
79 {
81 }
82
86 int Main( const TOOL_EVENT& aEvent );
87
92
103 bool aConfirmLockedItems = false );
104
106 int CursorSelection( const TOOL_EVENT& aEvent );
107
109 int ClearSelection( const TOOL_EVENT& aEvent );
110 void ClearSelection( bool aQuietMode = false );
111
113 int SelectAll( const TOOL_EVENT& aEvent );
114
120 void FindItem( BOARD_ITEM* aItem );
121
127 void select( EDA_ITEM* aItem ) override;
128
132 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
133
140 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
141
149 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
150
157 void RebuildSelection();
158
160 {
161 return m_filter;
162 }
163
165 void setTransitions() override;
166
168 void zoomFitSelection();
169
171 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
172
176 void EnterGroup();
177
183 void ExitGroup( bool aSelectGroup = false );
184
189
191
196 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
197
202 void FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector ) const;
203
207 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
208
212 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );
213
214protected:
216 {
217 return static_cast<KIGFX::PCB_VIEW*>( getView() );
218 }
219
221 {
222 return getViewControls();
223 }
224
226 {
227 return getEditFrame<PCB_BASE_EDIT_FRAME>();
228 }
229
230 BOARD* board() const
231 {
232 return getModel<BOARD>();
233 }
234
236 {
237 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
238 }
239
240 virtual bool ctrlClickHighlights() override;
241
242 SELECTION& selection() override { return m_selection; }
243
244private:
259 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
260 bool* aSelectionCancelledFlag = nullptr,
261 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
262
271 bool selectCursor( bool aForceSelect = false,
272 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
273
279 bool selectMultiple();
280
284 int disambiguateCursor( const TOOL_EVENT& aEvent );
285
289 int expandConnection( const TOOL_EVENT& aEvent );
290
294 int unrouteSelected( const TOOL_EVENT& aEvent );
295
299 int selectNet( const TOOL_EVENT& aEvent );
300
304 int selectUnconnected( const TOOL_EVENT& aEvent );
305
309 int grabUnconnected( const TOOL_EVENT& aEvent );
310
312 {
324 };
325
331 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
332 STOP_CONDITION aStopCondition );
333
334 /*
335 * Select tracks and vias connected to specified board items.
336 */
337 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
338
344 void selectAllItemsOnSheet( wxString& aSheetPath );
345
347 int selectSheetContents( const TOOL_EVENT& aEvent );
348
351 int selectSameSheet( const TOOL_EVENT& aEvent );
352
355 int syncSelection( const TOOL_EVENT& aEvent );
356 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
357 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
358
360 int filterSelection( const TOOL_EVENT& aEvent );
361
363 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect );
364
370 void unselect( EDA_ITEM* aItem ) override;
371
379 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
380
388 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
389
393 bool selectionContains( const VECTOR2I& aPoint ) const;
394
398 int hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
399
403 int updateSelection( const TOOL_EVENT& aEvent );
404
406
407private:
408 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
409
410 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
411
412private:
413 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
415
416 PCB_SELECTION m_selection; // Current state of selection
417
419
420 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
421
422 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
423 // members of this group
424 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
425
427 class PRIV;
428 std::unique_ptr<PRIV> m_priv;
429};
430
431#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:58
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
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:326
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:204
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:47
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 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 Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
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)
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.
PCB_BASE_EDIT_FRAME * frame() const
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.
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.
int hitTestDistance(const wxPoint &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
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 FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, replace any pads in the collector with their par...
void selectAllItemsOnSheet(wxString &aSheetPath)
Select all items with the given sheet timestamp/UUID name (the sheet path).
SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
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.
int expandConnection(const TOOL_EVENT &aEvent)
Expand the current connected-item selection to the next boundary (junctions, pads,...
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 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)
Clear current selection event handler.
int ClearSelection(const TOOL_EVENT &aEvent)
void highlightInternal(EDA_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
PCB_BASE_FRAME * m_frame
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 OnIdle(wxIdleEvent &aEvent)
PCB_DRAW_PANEL_GAL * canvas() const
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)
SELECTION_FILTER_OPTIONS m_filter
void SelectAllItemsOnNet(int aNetCode, bool aSelect=true)
Select all items with the given net code.
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)
PCB_SELECTION m_selection
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:156
KICURSOR
Definition: cursors.h:34
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
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 ...