KiCad PCB EDA Suite
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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  * Copyright (C) 2017-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef __SELECTION_TOOL_H
28 #define __SELECTION_TOOL_H
29 
30 #include <memory>
31 
32 #include <math/vector2d.h>
34 #include <tool/action_menu.h>
35 #include <tool/tool_menu.h>
37 #include <tools/pcb_tool_base.h>
38 #include <tools/pcbnew_selection.h>
39 
40 class PCB_BASE_FRAME;
41 class BOARD_ITEM;
42 class GENERAL_COLLECTOR;
43 
44 namespace KIGFX
45 {
46  class GAL;
47 }
48 
49 
51 
52 
65 {
66 public:
69 
71  bool Init() override;
72 
74  void Reset( RESET_REASON aReason ) override;
75 
81  int Main( const TOOL_EVENT& aEvent );
82 
89 
99  std::vector<BOARD_ITEM*>* aFiltered = nullptr, bool aConfirmLockedItems = false );
100 
103 
105  int CursorSelection( const TOOL_EVENT& aEvent );
106 
108  int ClearSelection( const TOOL_EVENT& aEvent );
109  void ClearSelection( bool aQuietMode = false );
110 
112  int SelectItem( const TOOL_EVENT& aEvent );
113  void AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode = false );
114 
116  int SelectAll( const TOOL_EVENT& aEvent );
117 
119  int SelectItems( const TOOL_EVENT& aEvent );
120 
122  int UnselectItem( const TOOL_EVENT& aEvent );
123  void RemoveItemFromSel( BOARD_ITEM* aItem, bool aQuietMode = false );
124 
126  int UnselectItems( const TOOL_EVENT& aEvent );
127 
128  void BrightenItem( BOARD_ITEM* aItem );
129  void UnbrightenItem( BOARD_ITEM* aItem );
130 
137  void select( BOARD_ITEM* aItem );
138 
145  bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
146 
154  void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
155 
163  int SelectionMenu( const TOOL_EVENT& aEvent );
164 
169  void RebuildSelection();
170 
172  {
173  return m_filter;
174  }
175 
177  void setTransitions() override;
178 
180  void zoomFitSelection();
181 
182  BOARD* GetBoard() const
183  {
184  return board();
185  }
186 
187  void EnterGroup();
188 
194  void ExitGroup( bool aSelectGroup = false );
195 
196  void FilterCollectorForGroups( GENERAL_COLLECTOR& aCollector ) const;
197 
199 
201  void FilterCollectedItems( GENERAL_COLLECTOR& aCollector );
202 
203 private:
204 
217  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
218  bool* aSelectionCancelledFlag = NULL,
219  CLIENT_SELECTION_FILTER aClientFilter = NULL );
220 
229  bool selectCursor( bool aForceSelect = false,
230  CLIENT_SELECTION_FILTER aClientFilter = NULL );
231 
239  bool selectMultiple();
240 
248  bool doSelectionMenu( GENERAL_COLLECTOR* aItems, const wxString& aTitle );
249 
253  int expandConnection( const TOOL_EVENT& aEvent );
254 
259  int selectNet( const TOOL_EVENT& aEvent );
260 
262  {
273  };
274 
280  void selectConnectedTracks( BOARD_CONNECTED_ITEM& aSourceItem, STOP_CONDITION aStopCondition );
281 
287  void selectAllItemsOnNet( int aNetCode, bool aSelect = true );
288 
294  void selectAllItemsOnSheet( wxString& aSheetPath );
295 
298  int selectSheetContents( const TOOL_EVENT& aEvent );
299 
302  int selectSameSheet( const TOOL_EVENT& aEvent );
303 
305  void findCallback( BOARD_ITEM* aItem );
306 
308  int find( const TOOL_EVENT& aEvent );
309 
311  int filterSelection( const TOOL_EVENT& aEvent );
312 
314  bool itemPassesFilter( BOARD_ITEM* aItem );
315 
323 
330  void unselect( BOARD_ITEM* aItem );
331 
339  void highlight( BOARD_ITEM* aItem, int aHighlightMode, PCBNEW_SELECTION* aGroup = nullptr );
340 
348  void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, PCBNEW_SELECTION* aGroup = nullptr );
349 
354  bool selectionContains( const VECTOR2I& aPoint ) const;
355 
359  int updateSelection( const TOOL_EVENT& aEvent );
360 
364  int UpdateMenu( const TOOL_EVENT& aEvent );
365 
367 
368 private:
369  void highlightInternal( BOARD_ITEM* aItem, int aHighlightMode, PCBNEW_SELECTION* aSelectionViewGroup,
370  bool isChild);
371 
372  void unhighlightInternal( BOARD_ITEM* aItem, int aHighlightMode, PCBNEW_SELECTION* aSelectionViewGroup,
373  bool isChild);
374 
375  PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
376  PCBNEW_SELECTION m_selection; // Current state of selection
377 
379 
380  bool m_additive; // Items should be added to selection (instead of replacing)
381  bool m_subtractive; // Items should be removed from selection
382  bool m_exclusive_or; // Items' selection state should be toggled
383  bool m_multiple; // Multiple selection mode is active
384  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
385  bool m_locked; // Other tools are not allowed to modify locked items
386 
387  PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
388  // members of this group
389  KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
390 
391 
393  class PRIV;
394  std::unique_ptr<PRIV> m_priv;
395 };
396 
397 #endif /* __SELECTION_TOOL_H */
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
int UnselectItem(const TOOL_EVENT &aEvent)
Item unselection event handler.
int Main(const TOOL_EVENT &aEvent)
Function Main()
int UpdateMenu(const TOOL_EVENT &aEvent)
Pass the selection to a conditional menu for updating.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void selectAllItemsOnSheet(wxString &aSheetPath)
Selects all items with the given sheet timestamp/UUID name (the sheet path) The path of the root shee...
int SelectAll(const TOOL_EVENT &aEvent)
Select all items on the board
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector)
Applies the SELECTION_FILTER_OPTIONS to a collection of items
BOARD * board() const
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
std::unique_ptr< PRIV > m_priv
void selectAllItemsOnNet(int aNetCode, bool aSelect=true)
Selects all items with the given net code.
int selectSameSheet(const TOOL_EVENT &aEvent)
Selects all footprints belonging to same hierarchical sheet as the selected footprint (same sheet pat...
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
SELECTION_TOOL.
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
Select the entire net.
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
int find(const TOOL_EVENT &aEvent)
Find an item.
SELECTION_FILTER_OPTIONS & GetFilter()
int UnselectItems(const TOOL_EVENT &aEvent)
Multiple item unselection event handler
BOARD * GetBoard() const
PCBNEW_SELECTION m_selection
Stop at any place where more than two traces meet.
PCB_GROUP * m_enteredGroup
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains()
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
bool itemPassesFilter(BOARD_ITEM *aItem)
Returns true if the given item passes the current SELECTION_FILTER_OPTIONS
BOARD_ITEM * pickSmallestComponent(GENERAL_COLLECTOR *aCollector)
Function pickSmallestComponent() Allows one to find the smallest (in terms of bounding box area) item...
Private implementation of firewalled private data.
void highlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function highlight() Highlights the item visually.
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
void findCallback(BOARD_ITEM *aItem)
Find dialog callback.
int filterSelection(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection
int expandConnection(const TOOL_EVENT &aEvent)
Expands the current track selection to the next boundary (junctions, pads, or all)
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=NULL, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectPoint() Selects an item pointed by the parameter aWhere.
bool selectCursor(bool aForceSelect=false, CLIENT_SELECTION_FILTER aClientFilter=NULL)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
void UnbrightenItem(BOARD_ITEM *aItem)
#define NULL
int updateSelection(const TOOL_EVENT &aEvent)
Event handler to update the selection VIEW_ITEM.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
void selectConnectedTracks(BOARD_CONNECTED_ITEM &aSourceItem, STOP_CONDITION aStopCondition)
Selects connecteed tracks and vias.
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
SELECTION_LOCK_FLAGS
Definition: selection.h:273
TOOL_EVENT.
Definition: tool_event.h:171
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)
void FilterCollectorForGroups(GENERAL_COLLECTOR &aCollector) const
Stop when reaching a pad.
void RemoveItemFromSel(BOARD_ITEM *aItem, bool aQuietMode=false)
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
PCB_BASE_FRAME * m_frame
This file contains data structures that are saved in the project file or project local settings file ...
int SelectionMenu(const TOOL_EVENT &aEvent)
Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down t...
int selectSheetContents(const TOOL_EVENT &aEvent)
Selects all footprints belonging to same sheet, from Eeschema, using crossprobing
void unhighlightInternal(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aSelectionViewGroup, bool isChild)
int SelectItem(const TOOL_EVENT &aEvent)
Item selection event handler.
int selectNet(const TOOL_EVENT &aEvent)
Selects all copper connections belonging to the same net(s) as the items in the selection.
void(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &, SELECTION_TOOL *)
void highlightInternal(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aSelectionViewGroup, bool isChild)
PCB_GROUP * GetEnteredGroup()
PCBNEW_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
Function RequestSelection()
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Function selectable() Checks conditions for an item to be selected.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
void RebuildSelection()
Rebuilds the selection from the EDA_ITEMs' selection flags.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
int SelectItems(const TOOL_EVENT &aEvent)
Multiple item selection event handler
void zoomFitSelection()
Zooms the screen to center and fit the current selection.
SELECTION_FILTER_OPTIONS m_filter
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
bool doSelectionMenu(GENERAL_COLLECTOR *aItems, const wxString &aTitle)
Allows the selection of a single item from a list via pop-up menu.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:390
void BrightenItem(BOARD_ITEM *aItem)
KIGFX::VIEW_GROUP m_enteredGroupOverlay
void setTransitions() override
Sets up handlers for various events.
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int CursorSelection(const TOOL_EVENT &aEvent)
Select a single item under cursor event handler.
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, PCBNEW_SELECTION *aGroup=nullptr)
Function unhighlight() Unhighlights the item visually.