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 
75  void OnIdle( wxIdleEvent& aEvent );
76 
80  int Main( const TOOL_EVENT& aEvent );
81 
86 
96  bool aConfirmLockedItems = false );
97 
99  int CursorSelection( const TOOL_EVENT& aEvent );
100 
102  int ClearSelection( const TOOL_EVENT& aEvent );
103  void ClearSelection( bool aQuietMode = false );
104 
106  int SelectItem( const TOOL_EVENT& aEvent );
107  void AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode = false );
108 
110  int SelectAll( const TOOL_EVENT& aEvent );
111 
113  int SelectItems( const TOOL_EVENT& aEvent );
114 
116  int UnselectItem( const TOOL_EVENT& aEvent );
117  void RemoveItemFromSel( BOARD_ITEM* aItem, bool aQuietMode = false );
118 
120  int UnselectItems( const TOOL_EVENT& aEvent );
121 
122  void BrightenItem( BOARD_ITEM* aItem );
123  void UnbrightenItem( BOARD_ITEM* aItem );
124 
130  void select( BOARD_ITEM* aItem );
131 
137  bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
138 
146  void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
147 
154  int SelectionMenu( const TOOL_EVENT& aEvent );
155 
162  void RebuildSelection();
163 
165  {
166  return m_filter;
167  }
168 
170  void setTransitions() override;
171 
173  void zoomFitSelection();
174 
175  BOARD* GetBoard() const
176  {
177  return board();
178  }
179 
180  void EnterGroup();
181 
187  void ExitGroup( bool aSelectGroup = false );
188 
190 
195  void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
196 
198  void FilterCollectedItems( GENERAL_COLLECTOR& aCollector );
199 
200 private:
206  void setModifiersState( bool aShiftState, bool aCtrlState, bool aAltState );
207 
222  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
223  bool* aSelectionCancelledFlag = NULL,
224  CLIENT_SELECTION_FILTER aClientFilter = NULL );
225 
234  bool selectCursor( bool aForceSelect = false,
235  CLIENT_SELECTION_FILTER aClientFilter = NULL );
236 
242  bool selectMultiple();
243 
252  bool doSelectionMenu( GENERAL_COLLECTOR* aItems );
253 
257  int expandConnection( const TOOL_EVENT& aEvent );
258 
262  int selectNet( const TOOL_EVENT& aEvent );
263 
265  {
277  };
278 
284  void selectConnectedTracks( BOARD_CONNECTED_ITEM& aSourceItem, STOP_CONDITION aStopCondition );
285 
292  void selectAllItemsOnNet( int aNetCode, bool aSelect = true );
293 
299  void selectAllItemsOnSheet( wxString& aSheetPath );
300 
302  int selectSheetContents( const TOOL_EVENT& aEvent );
303 
306  int selectSameSheet( const TOOL_EVENT& aEvent );
307 
309  void findCallback( BOARD_ITEM* aItem );
310 
312  int find( const TOOL_EVENT& aEvent );
313 
315  int filterSelection( const TOOL_EVENT& aEvent );
316 
318  bool itemPassesFilter( BOARD_ITEM* aItem );
319 
325  void unselect( BOARD_ITEM* aItem );
326 
334  void highlight( BOARD_ITEM* aItem, int aHighlightMode, PCB_SELECTION* aGroup = nullptr );
335 
343  void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, PCB_SELECTION* aGroup = nullptr );
344 
348  bool selectionContains( const VECTOR2I& aPoint ) const;
349 
350  int hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
351 
355  int updateSelection( const TOOL_EVENT& aEvent );
356 
360  int UpdateMenu( const TOOL_EVENT& aEvent );
361 
363 
364 private:
365  void highlightInternal( BOARD_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
366 
367  void unhighlightInternal( BOARD_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
368 
369 private:
370  PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
371  PCB_SELECTION m_selection; // Current state of selection
372 
374 
375  bool m_additive; // Add to selection (instead of replacing)
376  bool m_subtractive; // Remove from selection
377  bool m_exclusive_or; // Items' selection state should be toggled
378  bool m_multiple; // Multiple selection mode is active
379  bool m_skip_heuristics; // Heuristics are not allowed when choosing
380  // item under cursor
381  bool m_highlight_modifier; // select highlight net on left click
382 
383  KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
384 
385  PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
386  // members of this group
387  KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
388 
390  class PRIV;
391  std::unique_ptr<PRIV> m_priv;
392 };
393 
394 #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:194
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:80
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()
Private implementation of firewalled private data.
KICURSOR
Definition: cursors.h:33
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,...
void OnIdle(wxIdleEvent &aEvent)
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:152
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.
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.
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.
void setModifiersState(bool aShiftState, bool aCtrlState, bool aAltState)
Set the configuration of m_additive, m_subtractive, m_exclusive_or, m_skip_heuristics and m_highlight...
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:240
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:77
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.
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:377
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.