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-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
116 int UnselectAll( const TOOL_EVENT& aEvent );
117
123 void FindItem( BOARD_ITEM* aItem );
124
130 void select( EDA_ITEM* aItem ) override;
131
135 bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
136
143 void SelectAllItemsOnNet( int aNetCode, bool aSelect = true );
144
152 void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
153
160 void RebuildSelection();
161
163 {
164 return m_filter;
165 }
166
168 void setTransitions() override;
169
171 void zoomFitSelection();
172
174 void ZoomFitCrossProbeBBox( const BOX2I& bbox );
175
179 void EnterGroup();
180
186 void ExitGroup( bool aSelectGroup = false );
187
192
194
199 void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
200
206 bool aForcePromotion = false ) const;
207
211 void FilterCollectorForMarkers( GENERAL_COLLECTOR& aCollector ) const;
212
216 void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );
217
221 void FilterCollectorForFootprints( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
222
223protected:
225 {
226 return static_cast<KIGFX::PCB_VIEW*>( getView() );
227 }
228
230 {
231 return getViewControls();
232 }
233
235 {
236 return getEditFrame<PCB_BASE_EDIT_FRAME>();
237 }
238
239 BOARD* board() const
240 {
241 return getModel<BOARD>();
242 }
243
245 {
246 return static_cast<PCB_DRAW_PANEL_GAL*>( frame()->GetCanvas() );
247 }
248
249 virtual bool ctrlClickHighlights() override;
250
251 SELECTION& selection() override { return m_selection; }
252
253private:
268 bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
269 bool* aSelectionCancelledFlag = nullptr,
270 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
271
280 bool selectCursor( bool aForceSelect = false,
281 CLIENT_SELECTION_FILTER aClientFilter = nullptr );
282
288 bool selectMultiple();
289
293 int disambiguateCursor( const TOOL_EVENT& aEvent );
294
298 int expandConnection( const TOOL_EVENT& aEvent );
299
303 int unrouteSelected( const TOOL_EVENT& aEvent );
304
308 int selectNet( const TOOL_EVENT& aEvent );
309
313 int selectUnconnected( const TOOL_EVENT& aEvent );
314
318 int grabUnconnected( const TOOL_EVENT& aEvent );
319
321 {
333 };
334
340 void selectAllConnectedTracks( const std::vector<BOARD_CONNECTED_ITEM*>& aStartItems,
341 STOP_CONDITION aStopCondition );
342
347 void selectAllConnectedShapes( const std::vector<PCB_SHAPE*>& aStartItems );
348
352 bool isExpandableGraphicShape( const EDA_ITEM* aItem ) const;
353
354 /*
355 * Select tracks and vias connected to specified board items.
356 */
357 void selectConnections( const std::vector<BOARD_ITEM*>& aItems );
358
364 void selectAllItemsOnSheet( wxString& aSheetPath );
365
367 int selectSheetContents( const TOOL_EVENT& aEvent );
368
371 int selectSameSheet( const TOOL_EVENT& aEvent );
372
375 int syncSelection( const TOOL_EVENT& aEvent );
376 int syncSelectionWithNets( const TOOL_EVENT& aEvent );
377 void doSyncSelection( const std::vector<BOARD_ITEM*>& aItems, bool aWithNets );
378
380 int filterSelection( const TOOL_EVENT& aEvent );
381
383 bool itemPassesFilter( BOARD_ITEM* aItem, bool aMultiSelect );
384
390 void unselect( EDA_ITEM* aItem ) override;
391
399 void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
400
408 void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ) override;
409
413 bool selectionContains( const VECTOR2I& aPoint ) const;
414
418 int hitTestDistance( const VECTOR2I& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
419
423 int updateSelection( const TOOL_EVENT& aEvent );
424
426
427private:
428 void highlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
429
430 void unhighlightInternal( EDA_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
431
432private:
433 PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
435
436 PCB_SELECTION m_selection; // Current state of selection
437
439
440 KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
441
442 PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
443 // members of this group
444 KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
445
447 class PRIV;
448 std::unique_ptr<PRIV> m_priv;
449};
450
451#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:271
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:321
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 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.
PCB_BASE_EDIT_FRAME * frame() const
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).
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 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)
SELECTION_FILTER_OPTIONS m_filter
int hitTestDistance(const VECTOR2I &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
void selectAllConnectedShapes(const std::vector< PCB_SHAPE * > &aStartItems)
Selects 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.
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
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 ...