KiCad PCB EDA Suite
ee_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) 2019 CERN
5  * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef KICAD_SCH_SELECTION_TOOL_H
26 #define KICAD_SCH_SELECTION_TOOL_H
27 
28 #include <tool/tool_interactive.h>
29 #include <tool/action_menu.h>
30 #include <tool/tool_menu.h>
31 #include <tools/ee_selection.h>
32 #include <ee_collectors.h>
33 #include <sch_symbol.h>
34 #include <cursors.h>
35 
36 class SCH_BASE_FRAME;
37 class SCH_ITEM;
38 
39 namespace KIGFX
40 {
41  class GAL;
42 }
43 
44 
46 {
47 public:
52 };
53 
54 
56 {
57 public:
60 
62  bool Init() override;
63 
65  void Reset( RESET_REASON aReason ) override;
66 
67  int UpdateMenu( const TOOL_EVENT& aEvent );
68 
72  int Main( const TOOL_EVENT& aEvent );
73 
74  void OnIdle( wxIdleEvent& aEvent );
75 
80 
86 
102  bool SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList = EE_COLLECTOR::AllItems,
103  EDA_ITEM** aItem = nullptr, bool* aSelectionCancelledFlag = nullptr,
104  bool aCheckLocked = false, bool aAdd = false, bool aSubtract = false,
105  bool aExclusiveOr = false );
106 
107  int AddItemToSel( const TOOL_EVENT& aEvent );
108  void AddItemToSel( EDA_ITEM* aItem, bool aQuietMode = false );
109  int AddItemsToSel( const TOOL_EVENT& aEvent );
110  void AddItemsToSel( EDA_ITEMS* aList, bool aQuietMode = false );
111 
112  int RemoveItemFromSel( const TOOL_EVENT& aEvent );
113  void RemoveItemFromSel( EDA_ITEM* aItem, bool aQuietMode = false );
114  int RemoveItemsFromSel( const TOOL_EVENT& aEvent );
115  void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false );
116 
117  void BrightenItem( EDA_ITEM* aItem );
118  void UnbrightenItem( EDA_ITEM* aItem );
119 
120  void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); }
121 
123  EDA_ITEM* GetNode( VECTOR2I aPosition );
124 
126  int SelectNode( const TOOL_EVENT& aEvent );
127 
129  int SelectConnection( const TOOL_EVENT& aEvent );
130 
132  int ClearSelection( const TOOL_EVENT& aEvent );
133 
135  int SelectAll( const TOOL_EVENT& aEvent );
136 
137  void ClearSelection();
138 
144  bool Selectable( const EDA_ITEM* aItem, bool checkVisibilityOnly = false ) const;
145 
150  void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
151 
158  int SelectionMenu( const TOOL_EVENT& aEvent );
159 
166  void RebuildSelection();
167 
178  bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
179  const KICAD_T* aFilterList = EE_COLLECTOR::AllItems );
180 
181 private:
186  void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked );
187 
203  bool selectPoint( EE_COLLECTOR& aCollector, EDA_ITEM** aItem = nullptr,
204  bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
205  bool aSubtract = false, bool aExclusiveOr = false );
206 
212  bool selectMultiple();
213 
221  bool doSelectionMenu( EE_COLLECTOR* aItems );
222 
228  void select( EDA_ITEM* aItem );
229 
235  void unselect( EDA_ITEM* aItem );
236 
244  void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
245 
253  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
254 
258  void updateReferencePoint();
259 
263  bool selectionContains( const VECTOR2I& aPoint ) const;
264 
266  void setTransitions() override;
267 
268 private:
269  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
270  EE_SELECTION m_selection; // Current state of selection
271 
272  bool m_additive; // Items should be added to sel (instead of replacing)
273  bool m_subtractive; // Items should be removed from sel
274  bool m_exclusive_or; // Items' selection state should be toggled
275  bool m_multiple; // Multiple selection mode is active
276  bool m_skip_heuristics; // Show disambuguation menu for all items under the
277  // cursor rather than trying to narrow them down first
278  // using heuristics
279 
280  KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
281 
282  bool m_isSymbolEditor; // True when the symbol editor is the parent frame
283  bool m_isSymbolViewer; // True when the symbol browser is the parent frame
284  int m_unit; // Fixed unit filter (for symbol editor)
285  int m_convert; // Fixed DeMorgan filter (for symbol editor)
286 };
287 
288 #endif //KICAD_SCH_SELECTION_TOOL_H
void OnIdle(wxIdleEvent &aEvent)
bool selectionContains(const VECTOR2I &aPoint) const
Set up handlers for various events.
int UpdateMenu(const TOOL_EVENT &aEvent)
int SelectAll(const TOOL_EVENT &aEvent)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
static SELECTION_CONDITION SingleSymbol
bool selectMultiple()
Handle drawing a selection box that allows one to select many items at the same time.
Class that groups generic conditions for selected items.
EE_COLLECTOR.
Definition: ee_collectors.h:42
bool Selectable(const EDA_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
int AddItemsToSel(const TOOL_EVENT &aEvent)
void select(EDA_ITEM *aItem)
Take necessary action mark an item as selected.
KICURSOR
Definition: cursors.h:33
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
EE_SELECTION & GetSelection()
Return the set of currently selected items.
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Return either an existing selection (filtered), or the selection at the current cursor if the existin...
void updateReferencePoint()
Set the reference point to the anchor of the top-left item.
static SELECTION_CONDITION SingleDeMorganSymbol
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int SelectNode(const TOOL_EVENT &aEvent)
If node selected then expand to connection, otherwise select connection under cursor.
bool Init() override
Init() is called once upon a registration of the tool.
void BrightenItem(EDA_ITEM *aItem)
bool selectPoint(EE_COLLECTOR &aCollector, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This is the primary SelectPoint method that will prompt the user with a menu to disambiguate multiple...
void highlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Highlight the item visually.
void narrowSelection(EE_COLLECTOR &collector, const VECTOR2I &aWhere, bool aCheckLocked)
Apply rules to narrow the collection down to selectable objects, and then heuristics to try and narro...
void SelectHighlightItem(EDA_ITEM *aItem)
Find (but don't select) node under cursor.
#define SELECTED
Definition: eda_item.h:113
Generic, UI-independent tool event.
Definition: tool_event.h:173
int SelectConnection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:556
bool CollectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Select one or more items at the location given by parameter aWhere.
static SELECTION_CONDITION SingleMultiUnitSymbol
void UnbrightenItem(EDA_ITEM *aItem)
EDA_ITEM * GetNode(VECTOR2I aPosition)
Select node under cursor.
int RemoveItemFromSel(const TOOL_EVENT &aEvent)
void unselect(EDA_ITEM *aItem)
Take necessary action mark an item as unselected.
int AddItemToSel(const TOOL_EVENT &aEvent)
bool SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere before c...
int SelectionMenu(const TOOL_EVENT &aEvent)
Show a popup menu to trim the COLLECTOR passed as aEvent's parameter down to a single item.
bool doSelectionMenu(EE_COLLECTOR *aItems)
Allow the selection of a single item from a list via pop-up menu.
SCH_BASE_FRAME * m_frame
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
static const KICAD_T AllItems[]
Definition: ee_collectors.h:45
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
static SELECTION_CONDITION SingleSymbolOrPower
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
EE_SELECTION m_selection
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
int Main(const TOOL_EVENT &aEvent)
The main loop.