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/selection_tool.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 <gal/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 
121  void RemoveItemsFromSel( std::vector<KIID>* aList, bool aQuietMode = false );
122 
123  void BrightenItem( EDA_ITEM* aItem );
124  void UnbrightenItem( EDA_ITEM* aItem );
125 
126  void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); }
127 
129  EDA_ITEM* GetNode( VECTOR2I aPosition );
130 
132  int SelectNode( const TOOL_EVENT& aEvent );
133 
135  int SelectConnection( const TOOL_EVENT& aEvent );
136 
138  int ClearSelection( const TOOL_EVENT& aEvent );
139 
141  int SelectAll( const TOOL_EVENT& aEvent );
142 
143  void ClearSelection();
144 
150  bool Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos = nullptr,
151  bool checkVisibilityOnly = false ) const;
152 
157  void GuessSelectionCandidates( EE_COLLECTOR& collector, const VECTOR2I& aPos );
158 
165  int SelectionMenu( const TOOL_EVENT& aEvent );
166 
173  void RebuildSelection();
174 
185  bool CollectHits( EE_COLLECTOR& aCollector, const VECTOR2I& aWhere,
186  const KICAD_T* aFilterList = EE_COLLECTOR::AllItems );
187 
188 private:
193  void narrowSelection( EE_COLLECTOR& collector, const VECTOR2I& aWhere, bool aCheckLocked );
194 
210  bool selectPoint( EE_COLLECTOR& aCollector, EDA_ITEM** aItem = nullptr,
211  bool* aSelectionCancelledFlag = nullptr, bool aAdd = false,
212  bool aSubtract = false, bool aExclusiveOr = false );
213 
219  bool selectMultiple();
220 
228  bool doSelectionMenu( EE_COLLECTOR* aItems );
229 
235  void onDisambiguationExpire( wxTimerEvent& aEvent );
236 
240  int disambiguateCursor( const TOOL_EVENT& aEvent );
241 
247  void select( EDA_ITEM* aItem );
248 
254  void unselect( EDA_ITEM* aItem );
255 
263  void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
264 
272  void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr );
273 
277  void updateReferencePoint();
278 
282  bool selectionContains( const VECTOR2I& aPoint ) const;
283 
285  void setTransitions() override;
286 
287 private:
288 
289  SCH_BASE_FRAME* m_frame; // Pointer to the parent frame
290  EE_SELECTION m_selection; // Current state of selection
291 
292  KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt
293 
294  bool m_isSymbolEditor; // True when the symbol editor is the parent frame
295  bool m_isSymbolViewer; // True when the symbol browser is the parent frame
296  int m_unit; // Fixed unit filter (for symbol editor)
297  int m_convert; // Fixed DeMorgan filter (for symbol editor)
298 };
299 
300 #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:236
static SELECTION_CONDITION SingleSymbol
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
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.
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.
int disambiguateCursor(const TOOL_EVENT &aEvent)
Handle disambiguation actions including displaying the menu.
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.
Generic, UI-independent tool event.
Definition: tool_event.h:152
int SelectConnection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
#define SELECTED
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:507
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.
void onDisambiguationExpire(wxTimerEvent &aEvent)
Start the process to show our disambiguation menu once the user has kept the mouse down for the minim...
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:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
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:193
void unhighlight(EDA_ITEM *aItem, int aHighlightMode, EE_SELECTION *aGroup=nullptr)
Unhighlight the item visually.
int Main(const TOOL_EVENT &aEvent)
The main loop.