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  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __SELECTION_TOOL_H
27 #define __SELECTION_TOOL_H
28 
29 #include <memory>
30 
31 #include <math/vector2d.h>
32 #include <tools/pcb_tool.h>
33 #include <tool/context_menu.h>
34 #include <tool/selection.h>
35 
37 #include <tool/tool_menu.h>
38 
39 class PCB_BASE_FRAME;
40 class BOARD_ITEM;
41 class GENERAL_COLLECTOR;
42 
43 namespace KIGFX
44 {
45  class GAL;
46 }
47 
48 
60 class SELECTION_TOOL : public PCB_TOOL
61 {
62 public:
65 
67  bool Init() override;
68 
70  void Reset( RESET_REASON aReason ) override;
71 
77  int Main( const TOOL_EVENT& aEvent );
78 
85 
93 
94 
96  {
97  return m_menu;
98  }
99 
102 
104  int CursorSelection( const TOOL_EVENT& aEvent );
105 
107  int ClearSelection( const TOOL_EVENT& aEvent );
108 
111  bool SanitizeSelection();
112 
114  int SelectItem( const TOOL_EVENT& aEvent );
115 
117  int UnselectItem( const TOOL_EVENT& aEvent );
118 
120  static const TOOL_EVENT SelectedEvent;
121 
124 
126  static const TOOL_EVENT ClearedEvent;
127 
129  void SetTransitions() override;
130 
132  void zoomFitSelection( void );
133 
134 private:
145  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false );
146 
154  bool selectCursor( bool aSelectAlways = false );
155 
162  bool selectMultiple();
163 
165  int selectConnection( const TOOL_EVENT& aEvent );
166 
168  int selectCopper( const TOOL_EVENT& aEvent );
169 
174  int selectNet( const TOOL_EVENT& aEvent );
175 
179  void selectAllItemsConnectedToTrack( TRACK& aSourceTrack );
180 
185 
189  void selectAllItemsOnNet( int aNetCode );
190 
195  void selectAllItemsOnSheet( wxString& aSheetpath );
196 
199  int selectOnSheetFromEeschema( const TOOL_EVENT& aEvent );
200 
203  int selectSameSheet( const TOOL_EVENT& aEvent );
204 
206  void findCallback( BOARD_ITEM* aItem );
207 
209  int find( const TOOL_EVENT& aEvent );
210 
212  int findMove( const TOOL_EVENT& aEvent );
213 
215  int filterSelection( const TOOL_EVENT& aEvent );
216 
221  void clearSelection();
222 
231 
239 
246  void toggleSelection( BOARD_ITEM* aItem );
247 
254  bool selectable( const BOARD_ITEM* aItem ) const;
255 
263  bool modifiable( const BOARD_ITEM* aItem ) const;
264 
271  void select( BOARD_ITEM* aItem );
272 
279  void unselect( BOARD_ITEM* aItem );
280 
286  void selectVisually( BOARD_ITEM* aItem );
287 
293  void unselectVisually( BOARD_ITEM* aItem );
294 
301  bool selectionContains( const VECTOR2I& aPoint ) const;
302 
309  void guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
310 
314  int updateSelection( const TOOL_EVENT& aEvent );
315 
318 
321 
324 
327 
329  bool m_locked;
330 
333 
335  class PRIV;
336  std::unique_ptr<PRIV> m_priv;
337 };
338 
339 #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.
void zoomFitSelection(void)
Zooms the screen to center and fit the current selection.
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
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...
bool m_multiple
Flag saying if multiple selection mode is active.
void guessSelectionCandidates(GENERAL_COLLECTOR &aCollector) const
Function guessSelectionCandidates() Tries to guess best selection candidates in case multiple items a...
bool selectCursor(bool aSelectAlways=false)
Function selectCursor() Selects an item under the cursor unless there is something already selected o...
Class SELECTION_TOOL.
bool m_additive
Flag saying if items should be added to the current selection or rather replace it.
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MENU & GetToolMenu()
Class TOOL_MENU.
Definition: tool_menu.h:47
int find(const TOOL_EVENT &aEvent)
Find an item.
int findMove(const TOOL_EVENT &aEvent)
Find an item and start moving.
void unselectVisually(BOARD_ITEM *aItem)
Function unselectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
static const TOOL_EVENT ClearedEvent
Event sent after selection is cleared.
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.
bool modifiable(const BOARD_ITEM *aItem) const
Function modifiable() Checks if an item might be modified.
BOARD_ITEM * pickSmallestComponent(GENERAL_COLLECTOR *aCollector)
Function pickSmallestComponent() Allows to find the smallest (in terms of bounding box area) item fro...
Private implementation of firewalled private data.
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 selectable(const BOARD_ITEM *aItem) const
Function selectable() Checks conditions for an item to be selected.
void toggleSelection(BOARD_ITEM *aItem)
Function toggleSelection() Changes selection status of a given item.
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 to select many items at the sam...
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:177
Class TOOL_EVENT.
Definition: tool_event.h:162
BOARD_ITEM * disambiguationMenu(GENERAL_COLLECTOR *aItems)
Function disambiguationMenu() Handles the menu that allows to select one of many items in case there ...
SELECTION m_selection
Current state of selection.
SELECTION & GetSelection()
Function GetSelection()
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
void clearSelection()
Function clearSelection() Clears the current selection.
PCB_BASE_FRAME * m_frame
Pointer to the parent frame.
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
TOOL_MENU m_menu
Menu model displayed by the tool.
void selectVisually(BOARD_ITEM *aItem)
Function selectVisually() Marks item as selected, but does not add it to the ITEMS_PICKED_LIST.
Class PCB_TOOL.
Definition: pcb_tool.h:45
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.
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
void selectAllItemsConnectedToTrack(TRACK &aSourceTrack)
Selects all items connected by copper tracks to the given TRACK.
Class GENERAL_COLLECTOR is intended for use when the right click button is pressed, or when the plain "arrow" tool is in effect.
Definition: collectors.h:211
void unselect(BOARD_ITEM *aItem)
Function unselect() Takes necessary action mark an item as unselected.
bool selectionContains(const VECTOR2I &aPoint) const
Function selectionContains() Checks if the given point is placed within any of selected items' boundi...
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
bool m_locked
Can other tools modify locked items.
void SetTransitions() override
Sets up handlers for various events.
bool SanitizeSelection()
Makes sure a group selection does not contain items that would cause conflicts when moving/rotating t...
void selectAllItemsConnectedToItem(BOARD_CONNECTED_ITEM &aSourceItem)
Selects all items connected (by copper) to the given item.
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.