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/selection_tool.h>
37 #include <tool/tool_menu.h>
39 #include <tools/pcb_tool_base.h>
40 #include <tools/pcb_selection.h>
41 
42 class PCB_BASE_FRAME;
43 class BOARD_ITEM;
44 class GENERAL_COLLECTOR;
45 
46 namespace KIGFX
47 {
48  class GAL;
49 }
50 
51 
53 
54 
65 {
66 public:
69 
71  bool Init() override;
72 
74  void Reset( RESET_REASON aReason ) override;
75 
76  void OnIdle( wxIdleEvent& aEvent );
77 
81  int Main( const TOOL_EVENT& aEvent );
82 
87 
97  bool aConfirmLockedItems = false );
98 
100  int CursorSelection( const TOOL_EVENT& aEvent );
101 
103  int ClearSelection( const TOOL_EVENT& aEvent );
104  void ClearSelection( bool aQuietMode = false );
105 
107  int SelectItem( const TOOL_EVENT& aEvent );
108  void AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode = false );
109 
111  int SelectAll( const TOOL_EVENT& aEvent );
112 
114  int SelectItems( const TOOL_EVENT& aEvent );
115 
117  int UnselectItem( const TOOL_EVENT& aEvent );
118  void RemoveItemFromSel( BOARD_ITEM* aItem, bool aQuietMode = false );
119 
121  int UnselectItems( const TOOL_EVENT& aEvent );
122 
123  void BrightenItem( BOARD_ITEM* aItem );
124  void UnbrightenItem( BOARD_ITEM* aItem );
125 
132  void FindItem( BOARD_ITEM* aItem );
133 
139  void select( BOARD_ITEM* aItem );
140 
146  bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
147 
155  void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
156 
163  int SelectionMenu( const TOOL_EVENT& aEvent );
164 
171  void RebuildSelection();
172 
174  {
175  return m_filter;
176  }
177 
179  void setTransitions() override;
180 
182  void zoomFitSelection();
183 
184  BOARD* GetBoard() const
185  {
186  return board();
187  }
188 
189  void EnterGroup();
190 
196  void ExitGroup( bool aSelectGroup = false );
197 
199 
204  void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const;
205 
207  void FilterCollectedItems( GENERAL_COLLECTOR& aCollector );
208 
209 private:
210 
225  bool selectPoint( const VECTOR2I& aWhere, bool aOnDrag = false,
226  bool* aSelectionCancelledFlag = nullptr,
227  CLIENT_SELECTION_FILTER aClientFilter = nullptr );
228 
237  bool selectCursor( bool aForceSelect = false,
238  CLIENT_SELECTION_FILTER aClientFilter = nullptr );
239 
245  bool selectMultiple();
246 
255  bool doSelectionMenu( GENERAL_COLLECTOR* aItems );
256 
262  void onDisambiguationExpire( wxTimerEvent& aEvent );
263 
267  int disambiguateCursor( const TOOL_EVENT& aEvent );
268 
272  int expandConnection( const TOOL_EVENT& aEvent );
273 
277  int selectNet( const TOOL_EVENT& aEvent );
278 
280  {
292  };
293 
299  void selectConnectedTracks( BOARD_CONNECTED_ITEM& aSourceItem, STOP_CONDITION aStopCondition );
300 
307  void selectAllItemsOnNet( int aNetCode, bool aSelect = true );
308 
314  void selectAllItemsOnSheet( wxString& aSheetPath );
315 
317  int selectSheetContents( const TOOL_EVENT& aEvent );
318 
321  int selectSameSheet( const TOOL_EVENT& aEvent );
322 
324  int filterSelection( const TOOL_EVENT& aEvent );
325 
327  bool itemPassesFilter( BOARD_ITEM* aItem );
328 
334  void unselect( BOARD_ITEM* aItem );
335 
343  void highlight( BOARD_ITEM* aItem, int aHighlightMode, PCB_SELECTION* aGroup = nullptr );
344 
352  void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, PCB_SELECTION* aGroup = nullptr );
353 
357  bool selectionContains( const VECTOR2I& aPoint ) const;
358 
359  int hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aItem, int aMaxDistance ) const;
360 
364  int updateSelection( const TOOL_EVENT& aEvent );
365 
369  int UpdateMenu( const TOOL_EVENT& aEvent );
370 
372 
373 private:
374  void highlightInternal( BOARD_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
375 
376  void unhighlightInternal( BOARD_ITEM* aItem, int aHighlightMode, bool aUsingOverlay );
377 
378 private:
379  PCB_BASE_FRAME* m_frame; // Pointer to the parent frame
380  PCB_SELECTION m_selection; // Current state of selection
381 
383 
384  KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
385 
386  PCB_GROUP* m_enteredGroup; // If non-null, selections are limited to
387  // members of this group
388  KIGFX::VIEW_GROUP m_enteredGroupOverlay; // Overlay for the entered group's frame.
389 
391  class PRIV;
392  std::unique_ptr<PRIV> m_priv;
393 };
394 
395 #endif /* PCB_SELECTION_TOOL_H */
const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const
int selectSameSheet(const TOOL_EVENT &aEvent)
Invoke filter dialog and modify current selection.
int CursorSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
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:236
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.
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 FindItem(BOARD_ITEM *aItem)
Handle finding an item.
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 onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
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.
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.
bool selectPoint(const VECTOR2I &aWhere, bool aOnDrag=false, bool *aSelectionCancelledFlag=nullptr, CLIENT_SELECTION_FILTER aClientFilter=nullptr)
Select an item pointed by the parameter aWhere.
Generic, UI-independent tool event.
Definition: tool_event.h:152
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=nullptr)
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: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.