KiCad PCB EDA Suite
pcbnew/tools/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-2019 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>
33 #include <tools/pcb_tool.h>
34 #include <tool/context_menu.h>
35 #include <tool/selection.h>
36 
38 #include <tool/tool_menu.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 
64 class SELECTION_TOOL : public PCB_TOOL
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 = NULL, bool aConfirmLockedItems = false );
100 
101 
103  {
104  return m_menu;
105  }
106 
109 
111  int CursorSelection( const TOOL_EVENT& aEvent );
112 
114  int ClearSelection( const TOOL_EVENT& aEvent );
115 
117  int SelectItem( const TOOL_EVENT& aEvent );
118 
120  int SelectItems( const TOOL_EVENT& aEvent );
121 
123  int UnselectItem( const TOOL_EVENT& aEvent );
124 
126  int UnselectItems( const TOOL_EVENT& aEvent );
127 
135  int SelectionMenu( const TOOL_EVENT& aEvent );
136 
138  void setTransitions() override;
139 
141  void zoomFitSelection();
142 
143 private:
156  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
157  bool* aSelectionCancelledFlag = NULL,
158  CLIENT_SELECTION_FILTER aClientFilter = NULL );
159 
168  bool selectCursor( bool aForceSelect = false,
169  CLIENT_SELECTION_FILTER aClientFilter = NULL );
170 
178  bool selectMultiple();
179 
187  bool doSelectionMenu( GENERAL_COLLECTOR* aItems, const wxString& aTitle );
188 
190  int selectConnection( const TOOL_EVENT& aEvent );
191 
193  int expandSelectedConnection( const TOOL_EVENT& aEvent );
194 
196  int selectCopper( const TOOL_EVENT& aEvent );
197 
202  int selectNet( const TOOL_EVENT& aEvent );
203 
207  void selectAllItemsConnectedToTrack( TRACK& aSourceTrack );
208 
213 
217  void selectAllItemsOnNet( int aNetCode );
218 
223  void selectAllItemsOnSheet( wxString& aSheetpath );
224 
227  int selectOnSheetFromEeschema( const TOOL_EVENT& aEvent );
228 
231  int selectSameSheet( const TOOL_EVENT& aEvent );
232 
234  void findCallback( BOARD_ITEM* aItem );
235 
237  int find( const TOOL_EVENT& aEvent );
238 
240  int findMove( const TOOL_EVENT& aEvent );
241 
243  int filterSelection( const TOOL_EVENT& aEvent );
244 
249  void clearSelection();
250 
258 
266  void toggleSelection( BOARD_ITEM* aItem, bool aForce = false );
267 
274  bool selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
275 
282  void select( BOARD_ITEM* aItem );
283 
290  void unselect( BOARD_ITEM* aItem );
291 
299  void highlight( BOARD_ITEM* aItem, int aHighlightMode, SELECTION& aGroup );
300 
308  void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, SELECTION& aGroup );
309 
316  bool selectionContains( const VECTOR2I& aPoint ) const;
317 
325  void guessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
326 
330  int updateSelection( const TOOL_EVENT& aEvent );
331 
333 
334 private:
335  PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
336  SELECTION m_selection; // Current state of selection
337 
338  bool m_additive; // Items should be added to selection (instead of replacing)
339  bool m_subtractive; // Items should be removed from selection
340  bool m_multiple; // Multiple selection mode is active
341  bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor
342  bool m_locked; // Other tools are not allowed to modify locked items
343 
345 
347  class PRIV;
348  std::unique_ptr<PRIV> m_priv;
349 };
350 
351 #endif
int UnselectItem(const TOOL_EVENT &aEvent)
Item unselection event handler.
int Main(const TOOL_EVENT &aEvent)
Function Main()
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=NULL, bool aConfirmLockedItems=false)
Function RequestSelection()
std::unique_ptr< PRIV > m_priv
int selectSameSheet(const TOOL_EVENT &aEvent)
Selects all modules belonging to same hierarchical sheet as the selected footprint.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Class SELECTION_TOOL.
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
Class TOOL_MENU.
Definition: tool_menu.h:47
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
int find(const TOOL_EVENT &aEvent)
Find an item.
int findMove(const TOOL_EVENT &aEvent)
Find an item and start moving.
int UnselectItems(const TOOL_EVENT &aEvent)
Multiple item unselection event handler
void highlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function highlight() Highlights the item visually.
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains() Checks if the given point is placed within any of selected items' boundi...
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
int selectConnection(const TOOL_EVENT &aEvent)
Selects a trivial connection (between two junctions) of items in selection
void select(BOARD_ITEM *aItem)
Function select() Takes necessary action mark an item as selected.
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(* CLIENT_SELECTION_FILTER)(const VECTOR2I &, GENERAL_COLLECTOR &)
void findCallback(BOARD_ITEM *aItem)
Find dialog callback.
int selectCopper(const TOOL_EVENT &aEvent)
Selects items with a continuous copper connection to items in selection
int filterSelection(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection
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...
int expandSelectedConnection(const TOOL_EVENT &aEvent)
Expands the current selection to select a connection between two junctions
void selectAllItemsOnSheet(wxString &aSheetpath)
Selects all items with the given sheet timestamp name (the sheet path)
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.
bool selectMultiple()
Function selectMultiple() Handles drawing a selection box that allows one to select many items at the...
void selectAllItemsOnNet(int aNetCode)
Selects all items with the given net code.
int selectOnSheetFromEeschema(const TOOL_EVENT &aEvent)
Selects all modules belonging to same sheet, from Eeschema, using crossprobing
SELECTION_LOCK_FLAGS
Definition: selection.h:229
Class TOOL_EVENT.
Definition: tool_event.h:168
void unhighlight(BOARD_ITEM *aItem, int aHighlightMode, SELECTION &aGroup)
Function unhighlight() Unhighlights the item visually.
SELECTION & GetSelection()
Function GetSelection()
void toggleSelection(BOARD_ITEM *aItem, bool aForce=false)
Function toggleSelection() Changes selection status of a given item.
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
void clearSelection()
Function clearSelection() Clears the current selection.
int SelectionMenu(const TOOL_EVENT &aEvent)
Function SelectionMenu() Shows a popup menu to trim the COLLECTOR passed as aEvent's parameter down t...
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 selectAllItemsConnectedToTrack(TRACK &aSourceTrack)
Selects all items connected by copper tracks to the given TRACK.
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 guessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
int SelectItems(const TOOL_EVENT &aEvent)
Multiple item selection event handler
void zoomFitSelection()
Zooms the screen to center and fit the current selection.
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:386
void selectAllItemsConnectedToItem(BOARD_CONNECTED_ITEM &aSourceItem)
Selects all items connected (by copper) to the given item.
void setTransitions() override
Sets up handlers for various events.
class 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.