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
110 int ClearSelection( const TOOL_EVENT& aEvent );
111 void ClearSelection( bool aQuietMode = false );
112
114 int SelectAll( const TOOL_EVENT& aEvent );
115
117 int UnselectAll( const TOOL_EVENT& aEvent );
118
124 void FindItem( BOARD_ITEM* aItem );
125
131 void select( EDA_ITEM* aItem ) override;
132
136 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
137
144 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
145
153 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
154
161 void RebuildSelection();
162
164 {
165 return m_filter;
166 }
167
169 void setTransitions() override;
170
172 void zoomFitSelection();
173
175 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
176
180 void EnterGroup();
181
187 void ExitGroup( bool aSelectGroup = false );
188
193
195
200 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
201
207 bool aForcePromotion = false ) const;
208
212 void FilterCollectorForTableCells( GENERAL_COLLECTOR& aCollector ) const;
213
217 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
218
222 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );
223
228 const VECTOR2I& aWhere ) const;
229
230protected:
232 {
233 return static_cast<KIGFX::PCB_VIEW*>( getView() );
234 }
235
237 {
238 return getViewControls();
239 }
240
242 {
243 return getEditFrame<PCB_BASE_FRAME>();
244 }
245
247 {
248 return getEditFrame<PCB_BASE_EDIT_FRAME>();
249 }
250
251 BOARD* board() const
252 {
253 return getModel<BOARD>();
254 }
255
257 {
258 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
259 }
260
261 virtual bool ctrlClickHighlights() override;
262
263 SELECTION& selection() override { return m_selection; }
264
265private:
280 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
281 bool* aSelectionCancelledFlag = nullptr,
282 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
283
292 bool selectCursor( bool aForceSelect = false,
293 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
294
300 bool selectMultiple();
301
302 bool selectTableCells( PCB_TABLE* aTable );
303
307 int disambiguateCursor( const TOOL_EVENT& aEvent );
308
312 int expandConnection( const TOOL_EVENT& aEvent );
313
317 int unrouteSelected( const TOOL_EVENT& aEvent );
318
322 int selectNet( const TOOL_EVENT& aEvent );
323
327 int selectUnconnected( const TOOL_EVENT& aEvent );
328
332 int grabUnconnected( const TOOL_EVENT& aEvent );
333
335 {
347 };
348
354 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
355 STOP_CONDITION aStopCondition );
356
362 void selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems );
363
367 bool isExpandableGraphicShape( const EDA_ITEM* aItem ) const;
368
369 /*
370 * Select tracks and vias connected to specified board items.
371 */
372 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
373
379 void selectAllItemsOnSheet( wxString& aSheetPath );
380
382 int selectSheetContents( const TOOL_EVENT& aEvent );
383
386 int selectSameSheet( const TOOL_EVENT& aEvent );
387
390 int syncSelection( const TOOL_EVENT& aEvent );
391 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
392 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
393
395 int filterSelection( const TOOL_EVENT& aEvent );
396
398 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect );
399
405 void unselect( EDA_ITEM* aItem ) override;
406
414 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
415
423 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
424
428 bool selectionContains( const VECTOR2I& aPoint ) const;
429
433 int hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
434
438 int updateSelection( const TOOL_EVENT& aEvent );
439
440 void pruneObscuredSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
441
443
444private:
445 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
446
447 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
448
449private:
450 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
452
453 PCB_SELECTION m_selection; // Current state of selection
454
456
457 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
458
459 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
460 // members of this group
461 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
462
464 class PRIV;
465 std::unique_ptr<PRIV> m_priv;
466};
467
468#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)
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.
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 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_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 ...