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, 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 <tool/actions.h>
35#include <math/vector2d.h>
37#include <tool/action_menu.h>
38#include <tool/selection_tool.h>
39#include <tool/tool_menu.h>
41#include <tools/pcb_tool_base.h>
42#include <tools/pcb_selection.h>
43
44class PCB_BASE_FRAME;
45class BOARD_ITEM;
47class PCB_TABLE;
48
49namespace KIGFX
50{
51 class GAL;
52}
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
108 int SelectColumns( const TOOL_EVENT& aEvent );
109 int SelectRows( const TOOL_EVENT& aEvent );
110 int SelectTable( const TOOL_EVENT& aEvent );
111
113 int ClearSelection( const TOOL_EVENT& aEvent );
114 void ClearSelection( bool aQuietMode = false );
115
117 int SelectAll( const TOOL_EVENT& aEvent );
118
120 int UnselectAll( const TOOL_EVENT& aEvent );
121
127 void FindItem( BOARD_ITEM* aItem );
128
134 void select( EDA_ITEM* aItem ) override;
135
139 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
140
147 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
148
156 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
157
164 void RebuildSelection();
165
167 {
168 return m_filter;
169 }
170
172 void setTransitions() override;
173
175 void zoomFitSelection();
176
178 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
179
183 void EnterGroup() override;
184
190 void ExitGroup( bool aSelectGroup = false ) override;
191
196
198
203 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
204
210 bool aForcePromotion = false ) const;
211
215 void FilterCollectorForTableCells( GENERAL_COLLECTOR& aCollector ) const;
216
220 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
221
225 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );
226
231 const VECTOR2I& aWhere ) const;
232
233protected:
235 {
236 return static_cast<KIGFX::PCB_VIEW*>( getView() );
237 }
238
240 {
241 return getViewControls();
242 }
243
245 {
246 return getEditFrame<PCB_BASE_FRAME>();
247 }
248
250 {
251 return getEditFrame<PCB_BASE_EDIT_FRAME>();
252 }
253
254 BOARD* board() const
255 {
256 return getModel<BOARD>();
257 }
258
260 {
261 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
262 }
263
264 virtual bool ctrlClickHighlights() override;
265
266 SELECTION& selection() override { return m_selection; }
267
268private:
283 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
284 bool* aSelectionCancelledFlag = nullptr,
285 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
286
295 bool selectCursor( bool aForceSelect = false,
296 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
297
303 bool selectMultiple();
304
305 bool selectTableCells( PCB_TABLE* aTable );
306
310 int disambiguateCursor( const TOOL_EVENT& aEvent );
311
315 int expandConnection( const TOOL_EVENT& aEvent );
316
320 int unrouteSelected( const TOOL_EVENT& aEvent );
321
325 int selectNet( const TOOL_EVENT& aEvent );
326
330 int selectUnconnected( const TOOL_EVENT& aEvent );
331
335 int grabUnconnected( const TOOL_EVENT& aEvent );
336
338 {
350 };
351
357 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
358 STOP_CONDITION aStopCondition );
359
365 void selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems );
366
370 bool isExpandableGraphicShape( const EDA_ITEM* aItem ) const;
371
372 /*
373 * Select tracks and vias connected to specified board items.
374 */
375 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
376
382 void selectAllItemsOnSheet( wxString& aSheetPath );
383
385 int selectSheetContents( const TOOL_EVENT& aEvent );
386
389 int selectSameSheet( const TOOL_EVENT& aEvent );
390
393 int syncSelection( const TOOL_EVENT& aEvent );
394 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
395 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
396
398 int filterSelection( const TOOL_EVENT& aEvent );
399
401 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect );
402
408 void unselect( EDA_ITEM* aItem ) override;
409
417 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
418
426 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
427
431 bool selectionContains( const VECTOR2I& aPoint ) const;
432
436 int hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
437
441 int updateSelection( const TOOL_EVENT& aEvent );
442
443 void pruneObscuredSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
444
446
447private:
448 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
449
450 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
451
452private:
453 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
455
456 PCB_SELECTION m_selection; // Current state of selection
457
459
460 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
461
462 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
463 // members of this group
464 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
465
467 class PRIV;
468 std::unique_ptr<PRIV> m_priv;
469};
470
471#endif /* PCB_SELECTION_TOOL_H */
std::function< void(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)> CLIENT_SELECTION_FILTER
Definition: actions.h:38
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:96
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:53
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 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.
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)
void ExitGroup(bool aSelectGroup=false) override
Leave the currently-entered group.
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
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.
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 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:44
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:38
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:168
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: eda_group.h:32
This file contains data structures that are saved in the project file or project local settings file ...