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-2021 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
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/tool_menu.h>
38 #include <tools/pcb_tool_base.h>
39 #include <tools/pcb_selection.h>
40 
41 class PCB_BASE_FRAME;
42 class BOARD_ITEM;
43 class GENERAL_COLLECTOR;
44 
45 namespace KIGFX
46 {
47  class GAL;
48 }
49 
50 
52 
53 
64 {
65 public:
68 
70  bool Init() override;
71 
73  void Reset( RESET_REASON aReason ) override;
74 
78  int Main( const TOOL_EVENT& aEvent );
79 
84 
94  bool aConfirmLockedItems = false );
95 
97  int CursorSelection( const TOOL_EVENT& aEvent );
98 
100  int ClearSelection( const TOOL_EVENT& aEvent );
101  void ClearSelection( bool aQuietMode = false );
102 
104  int SelectItem( const TOOL_EVENT& aEvent );
105  void AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode = false );
106 
108  int SelectAll( const TOOL_EVENT& aEvent );
109 
111  int SelectItems( const TOOL_EVENT& aEvent );
112 
114  int UnselectItem( const TOOL_EVENT& aEvent );
115  void RemoveItemFromSel( BOARD_ITEM* aItem, bool aQuietMode = false );
116 
118  int UnselectItems( const TOOL_EVENT& aEvent );
119 
120  void BrightenItem( BOARD_ITEM* aItem );
121  void UnbrightenItem( BOARD_ITEM* aItem );
122 
128  void select( BOARD_ITEM* aItem );
129 
135  bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
136 
144  void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
145 
152  int SelectionMenu( const TOOL_EVENT& aEvent );
153 
160  void RebuildSelection();
161 
163  {
164  return m_filter;
165  }
166 
168  void setTransitions() override;
169 
171  void zoomFitSelection();
172 
173  BOARD* GetBoard() const
174  {
175  return board();
176  }
177 
178  void EnterGroup();
179 
185  void ExitGroup( bool aSelectGroup = false );
186 
187  void FilterCollectorForGroups( GENERAL_COLLECTOR& aCollector ) const;
188 
190 
192  void FilterCollectedItems( GENERAL_COLLECTOR& aCollector );
193 
194 private:
195 
210  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
211  bool* aSelectionCancelledFlag = NULL,
212  CLIENT_SELECTION_FILTER aClientFilter = NULL );
213 
222  bool selectCursor( bool aForceSelect = false,
223  CLIENT_SELECTION_FILTER aClientFilter = NULL );
224 
230  bool selectMultiple();
231 
240  bool doSelectionMenu( GENERAL_COLLECTOR* aItems );
241 
245  int expandConnection( const TOOL_EVENT& aEvent );
246 
250  int selectNet( const TOOL_EVENT& aEvent );
251 
253  {
265  };
266 
272  void selectConnectedTracks( BOARD_CONNECTED_ITEM& aSourceItem, STOP_CONDITION aStopCondition );
273 
280  void selectAllItemsOnNet( int aNetCode, bool aSelect = true );
281 
287  void selectAllItemsOnSheet( wxString& aSheetPath );
288 
290  int selectSheetContents( const TOOL_EVENT& aEvent );
291 
294  int selectSameSheet( const TOOL_EVENT& aEvent );
295 
297  void findCallback( BOARD_ITEM* aItem );
298 
300  int find( const TOOL_EVENT& aEvent );
301 
303  int filterSelection( const TOOL_EVENT& aEvent );
304 
306  bool itemPassesFilter( BOARD_ITEM* aItem );
307 
313  void unselect( BOARD_ITEM* aItem );
314 
322  void highlight( BOARD_ITEM* aItem, int aHighlightMode, PCB_SELECTION* aGroup = nullptr );
323 
331  void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, PCB_SELECTION* aGroup = nullptr );
332 
336  bool selectionContains( const VECTOR2I& aPoint ) const;
337 
338  int hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
339 
343  int updateSelection( const TOOL_EVENT& aEvent );
344 
348  int UpdateMenu( const TOOL_EVENT& aEvent );
349 
351 
352 private:
353  void highlightInternal( BOARD_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
354 
355  void unhighlightInternal( BOARD_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
356 
357  PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
358  PCB_SELECTION m_selection; // Current state of selection
359 
361 
362  bool m_additive; // Items should be added to selection (instead of replacing)
363  bool m_subtractive; // Items should be removed from selection
364  bool m_exclusive_or; // Items' selection state should be toggled
365  bool m_multiple; // Multiple selection mode is active
366  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
367 
368  PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
369  // members of this group
370  KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
371 
372 
374  class PRIV;
375  std::unique_ptr<PRIV> m_priv;
376 };
377 
378 #endif /* PCB_SELECTION_TOOL_H */
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
int selectSameSheet(const TOOL_EVENT &aEvent)
Find dialog callback.
int CursorSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
void select(BOARD_ITEM *aItem)
Take necessary action mark an item as selected.
BOARD * board() const
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
int find(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
Stop at any place where more than two traces meet.
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
Stop when reaching a pad.
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item pointed by the parameter aWhere.
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Highlight the item visually.
PCB_GROUP * GetEnteredGroup()
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
Private implementation of firewalled private data.
void setTransitions() override
Zoom the screen to center and fit the current selection.
int UnselectItem(const TOOL_EVENT &aEvent)
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &, PCB_SELECTION_TOOL *)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Select connected tracks and vias.
bool doSelectionMenu(GENERAL_COLLECTOR *aItems)
Allow the selection of a single item from a list via pop-up menu.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
int UnselectItems(const TOOL_EVENT &aEvent)
PCB_BASE_FRAME * m_frame
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
bool Init() override
Init() is called once upon a registration of the tool.
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
void UnbrightenItem(BOARD_ITEM *aItem)
int updateSelection(const TOOL_EVENT &aEvent)
Event handler to update the selection VIEW_ITEM.
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
#define NULL
int selectNet(const TOOL_EVENT &aEvent)
Select all copper connections belonging to the same net(s) as the items in the selection.
KIGFX::VIEW_GROUP m_enteredGroupOverlay
SELECTION_FILTER_OPTIONS m_filter
int expandConnection(const TOOL_EVENT &aEvent)
Expand the current track selection to the next boundary (junctions, pads, or all)
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Select all items on the board.
Generic, UI-independent tool event.
Definition: tool_event.h:173
void findCallback(BOARD_ITEM *aItem)
Find an item.
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition: view_group.h:46
void BrightenItem(BOARD_ITEM *aItem)
This file contains data structures that are saved in the project file or project local settings file ...
PCB_SELECTION m_selection
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
void unselect(BOARD_ITEM *aItem)
Take necessary action mark an item as unselected.
int selectSheetContents(const TOOL_EVENT &aEvent)
Select all footprints belonging to same hierarchical sheet as the selected footprint (same sheet path...
std::unique_ptr< PRIV > m_priv
int Main(const TOOL_EVENT &aEvent)
The main loop.
int SelectItems(const TOOL_EVENT &aEvent)
Item unselection event handler.
int SelectItem(const TOOL_EVENT &aEvent)
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Select an item under the cursor unless there is something already selected or aSelectAlways is true.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
int hitTestDistance(const wxPoint &aWhere, BOARD_ITEM *aItem, int aMaxDistance) const
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
BOARD * GetBoard() const
The selection tool: currently supports:
int UpdateMenu(const TOOL_EVENT &aEvent)
Pass the selection to a conditional menu for updating.
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
int SelectAll(const TOOL_EVENT &aEvent)
Multiple item selection event handler.
bool itemPassesFilter(BOARD_ITEM *aItem)
SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
void selectAllItemsOnNet(int aNetCode, bool aSelect=true)
Select all items with the given net code.
void RemoveItemFromSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Multiple item unselection event handler.
void FilterCollectorForGroups(GENERAL_COLLECTOR &aCollector) const
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:381
bool selectionContains(const VECTOR2I &aPoint) const
int ClearSelection(const TOOL_EVENT &aEvent)
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector)
void unhighlightInternal(BOARD_ITEM *aItem, int aHighlightMode, bool aUsingOverlay)
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...
void selectAllItemsOnSheet(wxString &aSheetPath)
Select all items with the given sheet timestamp/UUID name (the sheet path).
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCB_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int filterSelection(const TOOL_EVENT &aEvent)
Return true if the given item passes the current SELECTION_FILTER_OPTIONS.